Author: sapient
Date: Mon Apr 16 03:52:41 2007
New Revision: 16859
URL: http://svn.gna.org/viewcvs/wesnoth?rev=16859&view=rev
Log:
*allow effect to filter on unit_gender
*add utility functions gender_string() and string_gender()
Modified:
trunk/changelog
trunk/src/game_events.cpp
trunk/src/race.cpp
trunk/src/race.hpp
trunk/src/unit.cpp
trunk/src/unit.hpp
trunk/src/unit_types.cpp
trunk/src/unit_types.hpp
Modified: trunk/changelog
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/changelog?rev=16859&r1=16858&r2=16859&view=diff
==============================================================================
--- trunk/changelog (original)
+++ trunk/changelog Mon Apr 16 03:52:41 2007
@@ -77,6 +77,7 @@
* new key for [set_variable], literal=, to avoid variable substitution
* [effect] can now toggle the zoc
* [effect] can now apply new portrait images and unit type descriptions
+ * [effect] can now filter on unit_gender
* new key for [variable], boolean_equals=, to test boolean equality
* remove some old backward compatibility support
* set_name in attack modification [effect] no longer change the weapon's
Modified: trunk/src/game_events.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/game_events.cpp?rev=16859&r1=16858&r2=16859&view=diff
==============================================================================
--- trunk/src/game_events.cpp (original)
+++ trunk/src/game_events.cpp Mon Apr 16 03:52:41 2007
@@ -765,7 +765,6 @@
else if(cmd == "move_unit_fake") {
std::string type = cfg["type"];
std::string side = cfg["side"];
- std::string gender_string = cfg["gender"];
std::string x = cfg["x"];
std::string y = cfg["y"];
wassert(state_of_game != NULL);
@@ -773,7 +772,7 @@
size_t side_num = lexical_cast_default<int>(side,1)-1;
if (side_num >= teams->size()) side_num = 0;
- const unit_race::GENDER gender = gender_string == "female" ?
unit_race::FEMALE : unit_race::MALE;
+ const unit_race::GENDER gender = string_gender(cfg["gender"]);
const game_data::unit_type_map::const_iterator itor =
game_data_ptr->unit_types.find(type);
if(itor != game_data_ptr->unit_types.end()) {
wassert(game_data_ptr != NULL);
Modified: trunk/src/race.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/race.cpp?rev=16859&r1=16858&r2=16859&view=diff
==============================================================================
--- trunk/src/race.cpp (original)
+++ trunk/src/race.cpp Mon Apr 16 03:52:41 2007
@@ -147,3 +147,24 @@
unsigned int unit_race::num_traits() const { return ntraits_; }
bool unit_race::not_living() const { return not_living_; }
+
+std::string const& gender_string(unit_race::GENDER gender) {
+ static const std::string female_string = "female";
+ static const std::string male_string = "male";
+ switch(gender) {
+ case unit_race::FEMALE:
+ return female_string;
+ default:
+ case unit_race::MALE:
+ return male_string;
+ }
+}
+
+unit_race::GENDER string_gender(const std::string& str, unit_race::GENDER def)
{
+ if(str == gender_string(unit_race::MALE)) {
+ return unit_race::MALE;
+ } else if(str == gender_string(unit_race::FEMALE)) {
+ return unit_race::FEMALE;
+ }
+ return def;
+}
Modified: trunk/src/race.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/race.hpp?rev=16859&r1=16858&r2=16859&view=diff
==============================================================================
--- trunk/src/race.hpp (original)
+++ trunk/src/race.hpp Mon Apr 16 03:52:41 2007
@@ -55,6 +55,9 @@
bool global_traits_;
};
+unit_race::GENDER string_gender(const std::string& str,unit_race::GENDER
def=unit_race::MALE);
+std::string const& gender_string(unit_race::GENDER gender);
+
typedef std::map<std::string,unit_race> race_map;
#endif
Modified: trunk/src/unit.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit.cpp?rev=16859&r1=16858&r2=16859&view=diff
==============================================================================
--- trunk/src/unit.cpp (original)
+++ trunk/src/unit.cpp Mon Apr 16 03:52:41 2007
@@ -814,8 +814,7 @@
}
if(gender.empty() == false) {
- const unit_race::GENDER gender_type = gender == "female" ?
unit_race::FEMALE : unit_race::MALE;
- if(gender_type != this->gender()) {
+ if(string_gender(gender) != this->gender()) {
return false;
}
}
@@ -920,12 +919,7 @@
max_experience_=0;
/* */
- const std::string& gender = cfg["gender"];
- if(gender == "female") {
- gender_ = unit_race::FEMALE;
- } else {
- gender_ = unit_race::MALE;
- }
+ gender_ = string_gender(cfg["gender"]);
variation_ = cfg["variation"];
@@ -1383,8 +1377,8 @@
sd << side_;
cfg["side"] = sd.str();
- cfg["gender"] = gender_ == unit_race::MALE ? "male" : "female";
- cfg["gender_id"] = gender_ == unit_race::MALE ? "male" : "female";
+ cfg["gender"] = gender_string(gender_);
+ cfg["gender_id"] = gender_string(gender_);
cfg["variation"] = variation_;
@@ -2388,6 +2382,15 @@
if(type_filter.empty() == false) {
const std::vector<std::string>& types =
utils::split(type_filter);
if(std::find(types.begin(),types.end(),id()) ==
types.end()) {
+ continue;
+ }
+ }
+ //see if the effect only applies to certain genders
+ const std::string& gender_filter = (**i.first)["unit_gender"];
+ if(gender_filter.empty() == false) {
+ const std::string& gender = gender_string(gender_);
+ const std::vector<std::string>& genders =
utils::split(gender_filter);
+ if(std::find(genders.begin(),genders.end(),gender) ==
genders.end()) {
continue;
}
}
Modified: trunk/src/unit.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit.hpp?rev=16859&r1=16858&r2=16859&view=diff
==============================================================================
--- trunk/src/unit.hpp (original)
+++ trunk/src/unit.hpp Mon Apr 16 03:52:41 2007
@@ -285,7 +285,7 @@
void remove_temporary_modifications();
void generate_traits();
void generate_traits_description();
- std::string generate_description() const { return
race_->generate_name(cfg_["gender"] == "female" ? unit_race::FEMALE :
unit_race::MALE); }
+ std::string generate_description() const { return
race_->generate_name(string_gender(cfg_["gender"])); }
bool invisible(const gamemap::location& loc,
const unit_map& units,const std::vector<team>& teams)
const;
Modified: trunk/src/unit_types.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit_types.cpp?rev=16859&r1=16858&r2=16859&view=diff
==============================================================================
--- trunk/src/unit_types.cpp (original)
+++ trunk/src/unit_types.cpp Mon Apr 16 03:52:41 2007
@@ -594,15 +594,9 @@
}
const std::vector<std::string> genders = utils::split(cfg["gender"]);
- for(std::vector<std::string>::const_iterator i = genders.begin();
- i != genders.end(); ++i) {
- if(*i == "male") {
- genders_.push_back(unit_race::MALE);
- } else if(*i == "female") {
- genders_.push_back(unit_race::FEMALE);
- }
- }
-
+ for(std::vector<std::string>::const_iterator i = genders.begin(); i !=
genders.end(); ++i) {
+ genders_.push_back(string_gender(*i));
+ }
if(genders_.empty()) {
genders_.push_back(unit_race::MALE);
}
Modified: trunk/src/unit_types.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit_types.hpp?rev=16859&r1=16858&r2=16859&view=diff
==============================================================================
--- trunk/src/unit_types.hpp (original)
+++ trunk/src/unit_types.hpp Mon Apr 16 03:52:41 2007
@@ -161,7 +161,7 @@
unsigned int num_traits() const { return (cfg_["num_traits"].size() ?
atoi(cfg_["num_traits"].c_str()) : race_->num_traits()); }
- std::string generate_description() const { return
race_->generate_name(cfg_["gender"] == "female" ? unit_race::FEMALE :
unit_race::MALE); }
+ std::string generate_description() const { return
race_->generate_name(string_gender(cfg_["gender"])); }
//the name of the unit in the current language setting
const t_string& language_name() const { return cfg_["name"]; }
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits