Rename the unit copy function (and make it non-static)
This commit is contained in:
parent
a8f2500773
commit
afc60b9cc6
15 changed files with 28 additions and 28 deletions
|
@ -284,7 +284,7 @@ unit_ptr get_advanced_unit(const unit &u, const std::string& advance_to)
|
|||
throw game::game_error("Could not find the unit being advanced"
|
||||
" to: " + advance_to);
|
||||
}
|
||||
unit_ptr new_unit = unit::create(u);
|
||||
unit_ptr new_unit = u.clone();
|
||||
new_unit->set_experience(new_unit->experience_overflow());
|
||||
new_unit->advance_to(*new_type);
|
||||
new_unit->heal_fully();
|
||||
|
@ -302,7 +302,7 @@ unit_ptr get_advanced_unit(const unit &u, const std::string& advance_to)
|
|||
*/
|
||||
unit_ptr get_amla_unit(const unit &u, const config &mod_option)
|
||||
{
|
||||
unit_ptr amla_unit = unit::create(u);
|
||||
unit_ptr amla_unit = u.clone();
|
||||
amla_unit->set_experience(amla_unit->experience_overflow());
|
||||
amla_unit->add_modification("advancement", mod_option);
|
||||
return amla_unit;
|
||||
|
|
|
@ -180,7 +180,7 @@ public:
|
|||
, bound_unit_()
|
||||
{
|
||||
map_location loc(cfg["unit_x"], cfg["unit_y"], wml_loc()); // lua and c++ coords differ by one
|
||||
bound_unit_ = unit::create(*resources::gameboard->units().find(loc));
|
||||
bound_unit_ = (*resources::gameboard->units().find(loc)).clone();
|
||||
}
|
||||
|
||||
virtual double evaluate()
|
||||
|
|
|
@ -215,7 +215,7 @@ void helper_check_village(const map_location& loc, int side){
|
|||
}
|
||||
|
||||
void helper_place_unit(const unit& u, const map_location& loc){
|
||||
unit_ptr new_unit = unit::create(u);
|
||||
unit_ptr new_unit = u.clone();
|
||||
new_unit->set_movement(0, true);
|
||||
new_unit->set_attacks(0);
|
||||
new_unit->heal_fully();
|
||||
|
@ -248,7 +248,7 @@ void helper_advance_unit(const map_location& loc){
|
|||
int options_num = unit_helper::number_of_possible_advances(*advance_unit);
|
||||
|
||||
size_t advance_choice = randomness::generator->get_random_int(0, options_num-1);
|
||||
unit_ptr advanced_unit = unit::create(*advance_unit);
|
||||
unit_ptr advanced_unit = (*advance_unit).clone();
|
||||
|
||||
if(advance_choice < options.size()){
|
||||
std::string advance_unit_typename = options[advance_choice];
|
||||
|
|
|
@ -39,7 +39,7 @@ class editor_action_unit : public editor_action_location
|
|||
public:
|
||||
editor_action_unit(map_location loc, const unit& u)
|
||||
: editor_action_location(loc)
|
||||
, u_(unit::create(u))
|
||||
, u_(u.clone())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -364,14 +364,14 @@ void game_board::write_config(config & cfg) const
|
|||
temporary_unit_placer::temporary_unit_placer(unit_map& m, const map_location& loc, unit& u)
|
||||
: m_(m), loc_(loc), temp_(m_.extract(loc))
|
||||
{
|
||||
u.clone();
|
||||
u.mark_clone(true);
|
||||
m_.add(loc, u);
|
||||
}
|
||||
|
||||
temporary_unit_placer::temporary_unit_placer(game_board& b, const map_location& loc, unit& u)
|
||||
: m_(b.units_), loc_(loc), temp_(m_.extract(loc))
|
||||
{
|
||||
u.clone();
|
||||
u.mark_clone(true);
|
||||
m_.add(loc, u);
|
||||
}
|
||||
|
||||
|
|
|
@ -2228,7 +2228,7 @@ int game_lua_kernel::intf_extract_unit(lua_State *L)
|
|||
u->anim_comp().clear_haloes();
|
||||
} else if (int side = lu->on_recall_list()) {
|
||||
team &t = board().get_team(side);
|
||||
unit_ptr v = unit::create(*u);
|
||||
unit_ptr v = u->clone();
|
||||
t.recall_list().erase_if_matches_id(u->id());
|
||||
u = v;
|
||||
} else {
|
||||
|
@ -2313,7 +2313,7 @@ static int intf_create_unit(lua_State *L)
|
|||
static int intf_copy_unit(lua_State *L)
|
||||
{
|
||||
unit& u = luaW_checkunit(L, 1);
|
||||
luaW_pushunit(L, unit::create(u));
|
||||
luaW_pushunit(L, u.clone());
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,5 +25,5 @@ unit_ptr make_unit_ptr(const unit_type& t, int side, bool real_unit, unit_race::
|
|||
}
|
||||
unit_ptr make_unit_ptr(const unit& u)
|
||||
{
|
||||
return unit::create(u);
|
||||
return u.clone();
|
||||
}
|
||||
|
|
|
@ -80,7 +80,7 @@ unit_map::umap_retval_pair_t unit_map::add(const map_location& l, const unit& u)
|
|||
self_check();
|
||||
|
||||
// TODO: should this take a shared pointer to a unit rather than make a copy?
|
||||
unit_ptr p = unit::create(u);
|
||||
unit_ptr p = u.clone();
|
||||
p->set_location(l);
|
||||
|
||||
unit_map::umap_retval_pair_t res(insert(p));
|
||||
|
@ -172,7 +172,7 @@ unit_map::umap_retval_pair_t unit_map::insert(unit_ptr p)
|
|||
<< " (" << q->get_location()
|
||||
<< ").\n";
|
||||
|
||||
p->clone(false);
|
||||
p->mark_clone(false);
|
||||
ERR_NG << "The new unit was assigned underlying_id=" << p->underlying_id()
|
||||
<< " to prevent duplicate id conflicts.\n";
|
||||
|
||||
|
@ -189,7 +189,7 @@ unit_map::umap_retval_pair_t unit_map::insert(unit_ptr p)
|
|||
"\nThank you for your help in fixing this bug.\n";
|
||||
}
|
||||
|
||||
p->clone(false);
|
||||
p->mark_clone(false);
|
||||
uinsert = umap_.emplace(p->underlying_id(), upod);
|
||||
}
|
||||
|
||||
|
|
|
@ -206,7 +206,7 @@ void unit_mover::replace_temporary(unit_ptr u)
|
|||
was_hidden_ = u->get_hidden();
|
||||
|
||||
// Make our temporary unit mostly match u...
|
||||
temp_unit_ptr_ = fake_unit_ptr(unit::create(*u), resources::fake_units);
|
||||
temp_unit_ptr_ = fake_unit_ptr(u->clone(), resources::fake_units);
|
||||
|
||||
// ... but keep the temporary unhidden and hide the original.
|
||||
temp_unit_ptr_->set_hidden(false);
|
||||
|
|
|
@ -2407,7 +2407,7 @@ void unit::set_underlying_id(n_unit::id_manager& id_manager)
|
|||
}
|
||||
}
|
||||
|
||||
unit& unit::clone(bool is_temporary)
|
||||
unit& unit::mark_clone(bool is_temporary)
|
||||
{
|
||||
n_unit::id_manager& ids = resources::gameboard ? resources::gameboard->unit_id_manager() : n_unit::id_manager::global_instance();
|
||||
if(is_temporary) {
|
||||
|
|
|
@ -138,10 +138,10 @@ public:
|
|||
res->init(t, side, real_unit, gender);
|
||||
return res;
|
||||
}
|
||||
// maybe rename this to copy?
|
||||
static unit_ptr create(const unit& u)
|
||||
|
||||
unit_ptr clone() const
|
||||
{
|
||||
return unit_ptr(new unit(u));
|
||||
return unit_ptr(new unit(*this));
|
||||
}
|
||||
|
||||
virtual ~unit();
|
||||
|
@ -1572,7 +1572,7 @@ public:
|
|||
*
|
||||
* @returns self (for convenience)
|
||||
*/
|
||||
unit& clone(bool is_temporary = true);
|
||||
unit& mark_clone(bool is_temporary);
|
||||
|
||||
/** @} */
|
||||
|
||||
|
|
|
@ -726,7 +726,7 @@ void manager::create_temp_move()
|
|||
if(!fake_unit || fake_unit.get_unit_ptr()->id() != temp_moved_unit->id())
|
||||
{
|
||||
// Create temp ghost unit
|
||||
fake_unit = fake_unit_ptr(unit::create(*temp_moved_unit), resources::fake_units);
|
||||
fake_unit = fake_unit_ptr(temp_moved_unit->clone(), resources::fake_units);
|
||||
fake_unit->anim_comp().set_ghosted(true);
|
||||
}
|
||||
|
||||
|
|
|
@ -132,7 +132,7 @@ move::move(const config& cfg, bool hidden)
|
|||
arrow_->set_path(route_->steps);
|
||||
|
||||
// Construct fake_unit_
|
||||
fake_unit_ = fake_unit_ptr(unit::create(*get_unit()) , resources::fake_units );
|
||||
fake_unit_ = fake_unit_ptr(get_unit()->clone(), resources::fake_units );
|
||||
if(hidden)
|
||||
fake_unit_->set_hidden(true);
|
||||
fake_unit_->anim_comp().set_ghosted(true);
|
||||
|
|
|
@ -59,9 +59,9 @@ std::ostream& recall::print(std::ostream &s) const
|
|||
|
||||
recall::recall(size_t team_index, bool hidden, const unit& u, const map_location& recall_hex):
|
||||
action(team_index,hidden),
|
||||
temp_unit_(unit::create(u)),
|
||||
temp_unit_(u.clone()),
|
||||
recall_hex_(recall_hex),
|
||||
fake_unit_(unit::create(u))
|
||||
fake_unit_(u.clone())
|
||||
{
|
||||
this->init();
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ recall::recall(const config& cfg, bool hidden)
|
|||
{
|
||||
if(recall_unit->underlying_id()==underlying_id)
|
||||
{
|
||||
temp_unit_ = unit::create(*recall_unit); //TODO: is it necessary to make a copy?
|
||||
temp_unit_ = recall_unit->clone(); //TODO: is it necessary to make a copy?
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ recall::recall(const config& cfg, bool hidden)
|
|||
throw action::ctor_err("recall: Invalid underlying_id");
|
||||
}
|
||||
|
||||
fake_unit_.reset(unit::create(*temp_unit_)); //makes copy of temp_unit_
|
||||
fake_unit_.reset(temp_unit_->clone()); //makes copy of temp_unit_
|
||||
|
||||
this->init();
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ recruit::recruit(size_t team_index, bool hidden, const std::string& unit_name, c
|
|||
unit_name_(unit_name),
|
||||
recruit_hex_(recruit_hex),
|
||||
temp_unit_(create_corresponding_unit()), //auto-ptr ownership transfer
|
||||
fake_unit_(unit::create(*temp_unit_)), //temp_unit_ *copied* into new fake unit
|
||||
fake_unit_(temp_unit_->clone()), //temp_unit_ *copied* into new fake unit
|
||||
cost_(0)
|
||||
{
|
||||
this->init();
|
||||
|
@ -78,7 +78,7 @@ recruit::recruit(const config& cfg, bool hidden)
|
|||
|
||||
// Construct temp_unit_ and fake_unit_
|
||||
temp_unit_ = create_corresponding_unit(); //auto-ptr ownership transfer
|
||||
fake_unit_.reset(unit::create(*temp_unit_)); //temp_unit_ copied into new fake_unit
|
||||
fake_unit_.reset(temp_unit_->clone()); //temp_unit_ copied into new fake_unit
|
||||
|
||||
this->init();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue