got rid of the dummy_unit and simplified code along the way
This commit is contained in:
parent
c96c2ce0ed
commit
556725df5d
8 changed files with 38 additions and 56 deletions
|
@ -575,7 +575,7 @@ const std::string &recruit_result::get_available_for_recruiting(const team &my_t
|
|||
const unit_type *recruit_result::get_unit_type_known(const std::string &recruit, bool)
|
||||
{
|
||||
unit_type_data::unit_type_map::const_iterator type = unit_type_data::types().find_unit_type(recruit);
|
||||
if (type == unit_type_data::types().end() || type->first == "dummy_unit") {
|
||||
if (type == unit_type_data::types().end()) {
|
||||
set_error(E_UNKNOWN_OR_DUMMY_UNIT_TYPE);
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -1298,7 +1298,7 @@ void ai_default_recruitment_stage::analyze_potential_recruit_combat()
|
|||
std::set<std::string>::const_iterator i;
|
||||
for(i = recruits.begin(); i != recruits.end(); ++i) {
|
||||
const unit_type_data::unit_type_map::const_iterator info = unit_type_data::types().find_unit_type(*i);
|
||||
if(info == unit_type_data::types().end() || info->first == "dummy_unit" || not_recommended_units_.count(*i)) {
|
||||
if(info == unit_type_data::types().end() || not_recommended_units_.count(*i)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -1336,7 +1336,7 @@ void ai_default_recruitment_stage::analyze_potential_recruit_combat()
|
|||
// the best unit of that usage type.
|
||||
for(i = recruits.begin(); i != recruits.end(); ++i) {
|
||||
const unit_type_data::unit_type_map::const_iterator info = unit_type_data::types().find_unit_type(*i);
|
||||
if(info == unit_type_data::types().end() || info->first == "dummy_unit" || not_recommended_units_.count(*i)) {
|
||||
if(info == unit_type_data::types().end() || not_recommended_units_.count(*i)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -1416,7 +1416,7 @@ void ai_default_recruitment_stage::analyze_potential_recruit_movements()
|
|||
|
||||
for(std::set<std::string>::const_iterator i = recruits.begin(); i != recruits.end(); ++i) {
|
||||
const unit_type_data::unit_type_map::const_iterator info = unit_type_data::types().find_unit_type(*i);
|
||||
if(info == unit_type_data::types().end() || info->first == "dummy_unit") {
|
||||
if(info == unit_type_data::types().end()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -1468,7 +1468,7 @@ void ai_default_recruitment_stage::analyze_potential_recruit_movements()
|
|||
const unit_type_data::unit_type_map::const_iterator info =
|
||||
unit_type_data::types().find_unit_type(j->first);
|
||||
|
||||
if(info == unit_type_data::types().end() || info->first == "dummy_unit") {
|
||||
if(info == unit_type_data::types().end()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -309,7 +309,7 @@ void recruitment_phase::analyze_potential_recruit_movements()
|
|||
|
||||
for(std::set<std::string>::const_iterator i = recruits.begin(); i != recruits.end(); ++i) {
|
||||
const unit_type_data::unit_type_map::const_iterator info = unit_type_data::types().find_unit_type(*i);
|
||||
if(info == unit_type_data::types().end() || info->first == "dummy_unit") {
|
||||
if(info == unit_type_data::types().end()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -362,7 +362,7 @@ void recruitment_phase::analyze_potential_recruit_movements()
|
|||
const unit_type_data::unit_type_map::const_iterator info =
|
||||
unit_type_data::types().find_unit_type(j->first);
|
||||
|
||||
if(info == unit_type_data::types().end() || info->first == "dummy_unit") {
|
||||
if(info == unit_type_data::types().end()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -492,7 +492,7 @@ void recruitment_phase::analyze_potential_recruit_combat()
|
|||
std::set<std::string>::const_iterator i;
|
||||
for(i = recruits.begin(); i != recruits.end(); ++i) {
|
||||
const unit_type_data::unit_type_map::const_iterator info = unit_type_data::types().find_unit_type(*i);
|
||||
if(info == unit_type_data::types().end() || info->first == "dummy_unit" || not_recommended_units_.count(*i)) {
|
||||
if(info == unit_type_data::types().end() || not_recommended_units_.count(*i)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -530,7 +530,7 @@ void recruitment_phase::analyze_potential_recruit_combat()
|
|||
// the best unit of that usage type.
|
||||
for(i = recruits.begin(); i != recruits.end(); ++i) {
|
||||
const unit_type_data::unit_type_map::const_iterator info = unit_type_data::types().find_unit_type(*i);
|
||||
if(info == unit_type_data::types().end() || info->first == "dummy_unit" || not_recommended_units_.count(*i)) {
|
||||
if(info == unit_type_data::types().end() || not_recommended_units_.count(*i)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -362,7 +362,7 @@ void save_preview_pane::draw_contents()
|
|||
int ypos = area.y;
|
||||
|
||||
const unit_type_data::unit_type_map::const_iterator leader = unit_type_data::types().find_unit_type(summary["leader"]);
|
||||
if(unit_type_data::types().unit_type_exists(summary["leader"])) {
|
||||
if (leader != unit_type_data::types().end()) {
|
||||
|
||||
#ifdef LOW_MEM
|
||||
const surface image(image::get_image(leader->second.image()));
|
||||
|
|
|
@ -2382,8 +2382,10 @@ WML_HANDLER_FUNCTION(store_unit_type, /*event_info*/, cfg)
|
|||
|
||||
resources::state_of_game->clear_variable_cfg(variable);
|
||||
for(unsigned int i=0; i < types_to_store.size() && i < game_config::max_loop; ++i) {
|
||||
if(ut_map.unit_type_exists(types_to_store[i])) {
|
||||
resources::state_of_game->add_variable_cfg(variable, ut_map.find_unit_type(types_to_store[i], unit_type::NOT_BUILT)->second.get_cfg());
|
||||
const unit_type_data::unit_type_map::const_iterator
|
||||
ut = ut_map.find_unit_type(types_to_store[i], unit_type::NOT_BUILT);
|
||||
if(ut != ut_map.end()) {
|
||||
resources::state_of_game->add_variable_cfg(variable, ut->second.get_cfg());
|
||||
} else {
|
||||
lg::wml_error << "attempt to store nonexistent unit_type \""
|
||||
<< types_to_store[i] << "\"\n";
|
||||
|
@ -3414,8 +3416,11 @@ WML_HANDLER_FUNCTION(unit_worth, /*event_info*/, cfg)
|
|||
const std::vector<std::string>& advances = u->second.advances_to();
|
||||
int best_advance = cost;
|
||||
foreach(const std::string new_type, advances) {
|
||||
unit_type t = unit_type_data::types().find_unit_type(new_type)->second;
|
||||
best_advance = std::max(best_advance, t.cost());
|
||||
const unit_type_data::unit_type_map::const_iterator
|
||||
t = unit_type_data::types().find_unit_type(new_type);
|
||||
if (t != unit_type_data::types().end()) {
|
||||
best_advance = std::max(best_advance, t->second.cost());
|
||||
}
|
||||
}
|
||||
|
||||
const int hp_based = cost * hp / 1000;
|
||||
|
|
|
@ -88,25 +88,19 @@ void wait::leader_preview_pane::draw_contents()
|
|||
std::string leader = leaders_.get_leader();
|
||||
std::string gender = leaders_.get_gender();
|
||||
|
||||
unit_type_data::unit_type_map_wrapper& utypes = unit_type_data::types();
|
||||
std::string leader_name;
|
||||
std::string image;
|
||||
|
||||
const unit_type* ut;
|
||||
const unit_type* utg;
|
||||
const unit_type_data::unit_type_map_wrapper& utypes = unit_type_data::types();
|
||||
const unit_type_data::unit_type_map::const_iterator
|
||||
ut = utypes.find_unit_type(leader);
|
||||
|
||||
if (utypes.unit_type_exists(leader) && leader != "random") {
|
||||
ut = &(utypes.find_unit_type(leader)->second);
|
||||
if (!gender.empty()) {
|
||||
if (gender == "female")
|
||||
utg = &(ut->get_gender_unit_type(unit_race::FEMALE));
|
||||
else
|
||||
utg = &(ut->get_gender_unit_type(unit_race::MALE));
|
||||
} else
|
||||
utg = ut;
|
||||
if (ut != utypes.end()) {
|
||||
unit_race::GENDER g = (gender == "female" ? unit_race::FEMALE : unit_race::MALE);
|
||||
const unit_type& utg = ut->second.get_gender_unit_type(g);
|
||||
|
||||
leader_name = utg->type_name();
|
||||
image = utg->image() + leaders_.get_RC_suffix(utg->flag_rgb());
|
||||
leader_name = utg.type_name();
|
||||
image = utg.image() + leaders_.get_RC_suffix(utg.flag_rgb());
|
||||
}
|
||||
|
||||
for(std::vector<std::string>::const_iterator itor = recruit_list.begin();
|
||||
|
@ -474,30 +468,23 @@ void wait::generate_menu()
|
|||
|
||||
std::string leader_name;
|
||||
std::string leader_image;
|
||||
unit_type_data::unit_type_map_wrapper& utypes = unit_type_data::types();
|
||||
const unit_type* ut;
|
||||
const unit_type* utg;
|
||||
|
||||
if (utypes.unit_type_exists(leader_type) && leader_type != "random") {
|
||||
ut = &(utypes.find_unit_type(leader_type)->second);
|
||||
if (!gender_id.empty()) {
|
||||
if (gender_id == "female")
|
||||
utg = &(ut->get_gender_unit_type(unit_race::FEMALE));
|
||||
else
|
||||
// FIXME: this will make it look male, even if it's random. But all this
|
||||
// code will be wiped out when the MP UI gets unified, anyway.
|
||||
utg = &(ut->get_gender_unit_type(unit_race::MALE));
|
||||
} else
|
||||
utg = ut;
|
||||
const unit_type_data::unit_type_map_wrapper& utypes = unit_type_data::types();
|
||||
const unit_type_data::unit_type_map::const_iterator
|
||||
ut = utypes.find_unit_type(leader_type);
|
||||
|
||||
leader_name = utg->type_name();
|
||||
if (ut != utypes.end()) {
|
||||
unit_race::GENDER g = (gender_id == "female" ? unit_race::FEMALE : unit_race::MALE);
|
||||
const unit_type& utg = ut->second.get_gender_unit_type(g);
|
||||
|
||||
leader_name = utg.type_name();
|
||||
#ifdef LOW_MEM
|
||||
leader_image = utg->image();
|
||||
leader_image = utg.image();
|
||||
#else
|
||||
std::string RCcolor = sd["colour"];
|
||||
if (RCcolor.empty())
|
||||
RCcolor = sd["side"];
|
||||
leader_image = utg->image() + std::string("~RC(") + std::string(utg->flag_rgb() + ">" + RCcolor + ")");
|
||||
leader_image = utg.image() + std::string("~RC(") + std::string(utg.flag_rgb() + ">" + RCcolor + ")");
|
||||
#endif
|
||||
} else {
|
||||
leader_image = leader_list_manager::random_enemy_picture;
|
||||
|
|
|
@ -1126,7 +1126,6 @@ unit_type_data::unit_type_data() :
|
|||
|
||||
unit_type_data::unit_type_map_wrapper::unit_type_map_wrapper() :
|
||||
types_(),
|
||||
dummy_unit_map_(),
|
||||
movement_types_(),
|
||||
races_(),
|
||||
hide_help_all_(false),
|
||||
|
@ -1134,7 +1133,6 @@ unit_type_data::unit_type_map_wrapper::unit_type_map_wrapper() :
|
|||
hide_help_race_(),
|
||||
unit_cfg_(NULL)
|
||||
{
|
||||
dummy_unit_map_.insert(std::pair<const std::string,unit_type>("dummy_unit", unit_type()));
|
||||
}
|
||||
|
||||
void unit_type_data::unit_type_map_wrapper::set_config(config &cfg)
|
||||
|
@ -1217,19 +1215,15 @@ unit_type_data::unit_type_map::const_iterator unit_type_data::unit_type_map_wrap
|
|||
if (key.empty() || (key == "random"))
|
||||
return types_.end();
|
||||
|
||||
unit_type_map::iterator itor = types_.find(key);
|
||||
|
||||
DBG_CF << "trying to find " << key << " in unit_type list (unit_type_data.unit_types)\n";
|
||||
const unit_type_map::const_iterator itor = types_.find(key);
|
||||
|
||||
//This might happen if units of another era are requested (for example for savegames)
|
||||
if (itor == types_.end()){
|
||||
LOG_CONFIG << "key not found, returning dummy_unit\n";
|
||||
/*
|
||||
for (unit_type_map::const_iterator ut = types_.begin(); ut != types_.end(); ut++)
|
||||
DBG_UT << "Known unit_types: key = '" << ut->first << "', id = '" << ut->second.id() << "'\n";
|
||||
*/
|
||||
itor = dummy_unit_map_.find("dummy_unit");
|
||||
assert(itor != dummy_unit_map_.end());
|
||||
return itor;
|
||||
}
|
||||
|
||||
|
@ -1279,9 +1273,6 @@ unit_type& unit_type_data::unit_type_map_wrapper::build_unit_type(const std::str
|
|||
{
|
||||
unit_type_map::iterator ut = types_.find(key);
|
||||
|
||||
if (key == "dummy_unit")
|
||||
return ut->second;
|
||||
|
||||
DBG_UT << "Building unit type " << ut->first << ", level " << status << "\n";
|
||||
|
||||
switch (status){
|
||||
|
|
|
@ -372,7 +372,6 @@ public:
|
|||
void add_advancement(unit_type& to_unit) const;
|
||||
|
||||
mutable unit_type_map types_;
|
||||
mutable unit_type_map dummy_unit_map_;
|
||||
movement_type_map movement_types_;
|
||||
race_map races_;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue