Simplify one unit constructor by removing most of its messy bool parameters.
Also make :create spawn (randomly) male and female. I noticed an error causing plague to only create male. I keep that behavior for the moment but make it more clear.
This commit is contained in:
parent
a5ba61e6ed
commit
4a6fbd5565
6 changed files with 19 additions and 18 deletions
|
@ -1257,7 +1257,7 @@ attack::attack(const map_location &attacker, const map_location &defender,
|
|||
LOG_NG << "found unit type:" << reanimitor->second.id() << std::endl;
|
||||
if(reanimitor != unit_type_data::types().end()) {
|
||||
unit newunit(&units_, &reanimitor->second,
|
||||
a_.get_unit().side(), true, true);
|
||||
a_.get_unit().side(), true, unit_race::MALE);
|
||||
newunit.set_attacks(0);
|
||||
// Apply variation
|
||||
if(strcmp(undead_variation.c_str(), "null")) {
|
||||
|
@ -1530,7 +1530,7 @@ attack::attack(const map_location &attacker, const map_location &defender,
|
|||
LOG_NG << "found unit type:" << reanimitor->second.id() << std::endl;
|
||||
if(reanimitor != unit_type_data::types().end()) {
|
||||
unit newunit(&units_, &reanimitor->second,
|
||||
d_.get_unit().side(), true, true);
|
||||
d_.get_unit().side(), true, unit_race::MALE);
|
||||
// Apply variation
|
||||
if(strcmp(undead_variation.c_str(),"null")){
|
||||
config mod;
|
||||
|
|
|
@ -1081,7 +1081,7 @@ WML_HANDLER_FUNCTION(move_unit_fake, /*event_info*/, cfg)
|
|||
const unit_race::GENDER gender = string_gender(cfg["gender"]);
|
||||
const unit_type_data::unit_type_map::const_iterator itor = unit_type_data::types().find_unit_type(type);
|
||||
if(itor != unit_type_data::types().end()) {
|
||||
unit dummy_unit(resources::units, &itor->second, side_num + 1, false, true, gender, variation);
|
||||
unit dummy_unit(resources::units, &itor->second, side_num + 1, false, gender, variation);
|
||||
const std::vector<std::string> xvals = utils::split(x);
|
||||
const std::vector<std::string> yvals = utils::split(y);
|
||||
std::vector<map_location> path;
|
||||
|
|
|
@ -1382,7 +1382,10 @@ void menu_handler::create_unit_2(mouse_handler& mousehandler)
|
|||
gender = ut.genders().front();
|
||||
}
|
||||
|
||||
unit chosen(&units_, &ut, 1, false, false, gender, "", true, generate_name);
|
||||
unit chosen(&units_, &ut, 1, false, gender, "");
|
||||
if(generate_name)
|
||||
chosen.generate_name();
|
||||
|
||||
chosen.new_turn();
|
||||
|
||||
const map_location& loc = mousehandler.get_last_hex();
|
||||
|
@ -1471,11 +1474,9 @@ void menu_handler::create_unit(mouse_handler& mousehandler)
|
|||
last_selection = choice;
|
||||
random_gender = random_gender_choice;
|
||||
|
||||
const std::vector<unit_race::GENDER>& genders = (*unit_choices[choice]).genders();
|
||||
const unit_race::GENDER gender =
|
||||
(!genders.empty() ? genders[gamestate_.rng().get_random() % genders.size()] : unit_race::MALE);
|
||||
const unit_race::GENDER gender = random_gender ? unit_race::NUM_GENDERS : unit_race::MALE;
|
||||
|
||||
unit chosen(&units_, unit_choices[choice], 1, false, false, gender, "", random_gender);
|
||||
unit chosen(&units_, unit_choices[choice], 1, false, gender, "");
|
||||
chosen.new_turn();
|
||||
|
||||
const map_location& loc = mousehandler.get_last_hex();
|
||||
|
|
|
@ -943,7 +943,7 @@ bool do_replay_handle(int side_num, const std::string &do_untill)
|
|||
}
|
||||
|
||||
const std::string res = find_recruit_location(side_num, loc);
|
||||
const unit new_unit(resources::units, &u_type->second, side_num, true, false);
|
||||
const unit new_unit(resources::units, &u_type->second, side_num, true);
|
||||
if (res.empty()) {
|
||||
place_recruit(new_unit, loc, false, !get_replay_source().is_skipping());
|
||||
} else {
|
||||
|
|
12
src/unit.cpp
12
src/unit.cpp
|
@ -353,7 +353,7 @@ unit_race::GENDER unit::generate_gender(const unit_type& type, bool gen, game_st
|
|||
}
|
||||
|
||||
unit::unit(unit_map *unitmap, const unit_type *t, int side,
|
||||
bool use_traits, bool dummy_unit, unit_race::GENDER gender, std::string variation, bool force_gender, bool force_generate_name) :
|
||||
bool use_traits, unit_race::GENDER gender, std::string variation) :
|
||||
cfg_(),
|
||||
loc_(),
|
||||
advances_to_(),
|
||||
|
@ -375,7 +375,7 @@ unit::unit(unit_map *unitmap, const unit_type *t, int side,
|
|||
image_mods_(),
|
||||
unrenamable_(false),
|
||||
side_(side),
|
||||
gender_(dummy_unit||force_gender ? gender : generate_gender(*t,use_traits)),
|
||||
gender_(gender != unit_race::NUM_GENDERS ? gender : generate_gender(*t,true)),
|
||||
alpha_(),
|
||||
unit_formula_(),
|
||||
unit_loop_formula_(),
|
||||
|
@ -424,12 +424,12 @@ unit::unit(unit_map *unitmap, const unit_type *t, int side,
|
|||
{
|
||||
cfg_["upkeep"]="full";
|
||||
advance_to(t);
|
||||
if(dummy_unit == false) validate_side(side_);
|
||||
if(use_traits || force_generate_name) {
|
||||
|
||||
if(use_traits) {
|
||||
// Units that don't have traits generated are just
|
||||
// generic units, so they shouldn't get a description
|
||||
// either.
|
||||
name_ = generate_name();
|
||||
generate_name();
|
||||
}
|
||||
generate_traits(!use_traits);
|
||||
reset_modifications();
|
||||
|
@ -1518,7 +1518,7 @@ void unit::read(const config& cfg, bool use_traits, game_state* state)
|
|||
alignment_ = unit_type::NEUTRAL;
|
||||
}
|
||||
if(utils::string_bool(cfg["generate_name"])) {
|
||||
name_ = generate_name(state ? &(state->rng()) : 0);
|
||||
generate_name(state ? &(state->rng()) : 0);
|
||||
cfg_["generate_name"] = "";
|
||||
}
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@ public:
|
|||
unit(unit_map* unitmap,
|
||||
const config& cfg, bool use_traits=false, game_state* state = 0);
|
||||
/** Initializes a unit from a unit type */
|
||||
unit(unit_map* unitmap, const unit_type* t, int side, bool use_traits=false, bool dummy_unit=false, unit_race::GENDER gender=unit_race::MALE, std::string variation="", bool force_gender=false, bool force_generate_name=false);
|
||||
unit(unit_map* unitmap, const unit_type* t, int side, bool use_traits=false, unit_race::GENDER gender=unit_race::NUM_GENDERS, std::string variation="");
|
||||
virtual ~unit();
|
||||
unit& operator=(const unit&);
|
||||
|
||||
|
@ -312,8 +312,8 @@ public:
|
|||
void remove_temporary_modifications();
|
||||
void generate_traits(bool musthaveonly=false, game_state* state = 0);
|
||||
void generate_traits_description();
|
||||
std::string generate_name(rand_rng::simple_rng *rng = 0) const
|
||||
{ return race_->generate_name(gender_, rng); }
|
||||
void generate_name(rand_rng::simple_rng *rng = 0)
|
||||
{ name_ = race_->generate_name(gender_, rng); }
|
||||
|
||||
// Only see_all=true use caching
|
||||
bool invisible(const map_location& loc,
|
||||
|
|
Loading…
Add table
Reference in a new issue