Change the unit constructor based on a unit_type to take a reference...
...instead of a pointer that was assumed to be (and in fact always was) non-NULL.
This commit is contained in:
parent
8c83185317
commit
2da6f3cd3b
11 changed files with 18 additions and 18 deletions
|
@ -1002,7 +1002,7 @@ namespace {
|
|||
if (reanimator)
|
||||
{
|
||||
LOG_NG << "found unit type:" << reanimator->id() << '\n';
|
||||
unit newunit(reanimator, attacker.get_unit().side(),
|
||||
unit newunit(*reanimator, attacker.get_unit().side(),
|
||||
true, unit_race::MALE);
|
||||
newunit.set_attacks(0);
|
||||
newunit.set_movement(0, true);
|
||||
|
|
|
@ -820,7 +820,7 @@ namespace actions {
|
|||
void recruit_unit(const unit_type & u_type, int side_num, const map_location & loc,
|
||||
const map_location & from, bool show, bool is_ai)
|
||||
{
|
||||
const unit new_unit(&u_type, side_num, true);
|
||||
const unit new_unit(u_type, side_num, true);
|
||||
|
||||
// Place the recruit.
|
||||
bool mutated = place_recruit(new_unit, loc, from, u_type.cost(), false, show);
|
||||
|
|
|
@ -771,8 +771,8 @@ private:
|
|||
if ( att_type == NULL || def_type == NULL )
|
||||
return variant();
|
||||
|
||||
unit attacker(att_type, 3, false);
|
||||
unit defender(def_type, 2, false);
|
||||
unit attacker(*att_type, 3, false);
|
||||
unit defender(*def_type, 2, false);
|
||||
|
||||
|
||||
temporary_unit_placer att_place(*resources::units, att_loc, attacker);
|
||||
|
|
|
@ -78,7 +78,7 @@ editor_action* mouse_action_unit::up_left(editor_display& disp, int x, int y)
|
|||
const unit_type &ut = *new_unit_type;
|
||||
unit_race::GENDER gender = ut.genders().front();
|
||||
|
||||
unit new_unit(new_unit_type, disp.viewing_side(), true, gender);
|
||||
unit new_unit(ut, disp.viewing_side(), true, gender);
|
||||
editor_action* action = new editor_action_unit(hex, new_unit);
|
||||
return action;
|
||||
}
|
||||
|
|
|
@ -171,7 +171,7 @@ public:
|
|||
public:
|
||||
explicit fake_unit(unit const & u) : unit(u), my_display_(NULL) {}
|
||||
fake_unit(fake_unit const & u) : unit(u), my_display_(NULL) {}
|
||||
fake_unit(const unit_type* t, int side, unit_race::GENDER gender = unit_race::NUM_GENDERS)
|
||||
fake_unit(const unit_type& t, int side, unit_race::GENDER gender = unit_race::NUM_GENDERS)
|
||||
: unit(t, side, false, gender)
|
||||
, my_display_(NULL)
|
||||
{}
|
||||
|
|
|
@ -1182,7 +1182,7 @@ game_display::fake_unit *create_fake_unit(const vconfig& cfg)
|
|||
unit_race::GENDER gender = string_gender(cfg["gender"]);
|
||||
const unit_type *ut = unit_types.find(type);
|
||||
if (!ut) return NULL;
|
||||
game_display::fake_unit * fake_unit = new game_display::fake_unit(ut, side_num, gender);
|
||||
game_display::fake_unit * fake_unit = new game_display::fake_unit(*ut, side_num, gender);
|
||||
|
||||
if(!variation.empty()) {
|
||||
config mod;
|
||||
|
|
|
@ -1266,7 +1266,7 @@ void menu_handler::create_unit_2(mouse_handler& mousehandler)
|
|||
gender = ut.genders().front();
|
||||
}
|
||||
|
||||
unit chosen(&ut, 1, true, gender);
|
||||
unit chosen(ut, 1, true, gender);
|
||||
chosen.new_turn();
|
||||
|
||||
const map_location& loc = mousehandler.get_last_hex();
|
||||
|
@ -1351,9 +1351,9 @@ void menu_handler::create_unit(mouse_handler& mousehandler)
|
|||
last_selection = choice;
|
||||
random_gender = random_gender_choice;
|
||||
|
||||
const unit_type* type = unit_choices[choice];
|
||||
const unit_type& type = *unit_choices[choice];
|
||||
const unit_race::GENDER gender = random_gender ? unit_race::NUM_GENDERS :
|
||||
type->genders().front();
|
||||
type.genders().front();
|
||||
|
||||
unit chosen(type, 1, true, gender);
|
||||
chosen.new_turn();
|
||||
|
@ -3376,7 +3376,7 @@ void console_handler::do_create() {
|
|||
|
||||
menu_handler_.units_.erase(loc);
|
||||
|
||||
unit created(ut, 1, true);
|
||||
unit created(*ut, 1, true);
|
||||
created.new_turn();
|
||||
|
||||
menu_handler_.units_.add(loc, created);
|
||||
|
|
|
@ -1016,7 +1016,7 @@ bool do_replay_handle(int side_num, const std::string &do_untill)
|
|||
replay::process_error(errbuf.str());
|
||||
// Keep the bookkeeping right.
|
||||
current_team.spend_gold(u_type->cost());
|
||||
statistics::recruit_unit(unit(u_type, side_num, true));
|
||||
statistics::recruit_unit(unit(*u_type, side_num, true));
|
||||
}
|
||||
|
||||
if ( u_type->cost() > beginning_gold ) {
|
||||
|
|
|
@ -577,12 +577,12 @@ void unit::clear_status_caches()
|
|||
units_with_cache.clear();
|
||||
}
|
||||
|
||||
unit::unit(const unit_type *t, int side, bool real_unit,
|
||||
unit::unit(const unit_type &u_type, int side, bool real_unit,
|
||||
unit_race::GENDER gender) :
|
||||
cfg_(),
|
||||
loc_(),
|
||||
advances_to_(),
|
||||
type_(t),
|
||||
type_(&u_type),
|
||||
type_name_(),
|
||||
race_(&unit_race::null_race),
|
||||
id_(),
|
||||
|
@ -603,7 +603,7 @@ unit::unit(const unit_type *t, int side, bool real_unit,
|
|||
unrenamable_(false),
|
||||
side_(side),
|
||||
gender_(gender != unit_race::NUM_GENDERS ?
|
||||
gender : generate_gender(*t, real_unit, NULL)),
|
||||
gender : generate_gender(u_type, real_unit, NULL)),
|
||||
alpha_(),
|
||||
unit_formula_(),
|
||||
unit_loop_formula_(),
|
||||
|
@ -657,7 +657,7 @@ unit::unit(const unit_type *t, int side, bool real_unit,
|
|||
cfg_["upkeep"]="full";
|
||||
|
||||
// Apply the unit type's data to this unit.
|
||||
advance_to(*t, real_unit);
|
||||
advance_to(u_type, real_unit);
|
||||
|
||||
if(real_unit) {
|
||||
generate_name();
|
||||
|
|
|
@ -87,7 +87,7 @@ public:
|
|||
* only real_unit may have random traits, name and gender
|
||||
* (to prevent OOS caused by RNG calls)
|
||||
*/
|
||||
unit(const unit_type* t, int side, bool real_unit,
|
||||
unit(const unit_type& t, int side, bool real_unit,
|
||||
unit_race::GENDER gender = unit_race::NUM_GENDERS);
|
||||
virtual ~unit();
|
||||
virtual unit& operator=(const unit&);
|
||||
|
|
|
@ -172,7 +172,7 @@ std::auto_ptr<unit> recruit::create_corresponding_unit()
|
|||
int side_num = team_index() + 1;
|
||||
//real_unit = false needed to avoid generating random traits and causing OOS
|
||||
bool real_unit = false;
|
||||
std::auto_ptr<unit> result(new unit(type, side_num, real_unit));
|
||||
std::auto_ptr<unit> result(new unit(*type, side_num, real_unit));
|
||||
result->set_movement(0, true);
|
||||
result->set_attacks(0);
|
||||
return result; //ownership gets transferred to returned auto_ptr copy
|
||||
|
|
Loading…
Add table
Reference in a new issue