Restricted unit_map setting to unit_map itself.
This commit is contained in:
parent
2d2f9299c4
commit
0db47ab563
9 changed files with 26 additions and 36 deletions
|
@ -261,7 +261,7 @@ void unit_creator::add_unit(const config &cfg)
|
|||
if(add_to_recall_) {
|
||||
if (recall_list_element==team_.recall_list().end()) {
|
||||
//add to recall list
|
||||
unit new_unit(resources::units, temp_cfg, true,resources::state_of_game);
|
||||
unit new_unit(temp_cfg, true, resources::state_of_game);
|
||||
team_.recall_list().push_back(new_unit);
|
||||
DBG_NG << "inserting unit with id=["<<id<<"] on recall list for side " << new_unit.side() << "\n";
|
||||
} else {
|
||||
|
@ -275,14 +275,13 @@ void unit_creator::add_unit(const config &cfg)
|
|||
temp_cfg.remove_attribute("animate");
|
||||
if (recall_list_element==team_.recall_list().end()) {
|
||||
//new unit
|
||||
unit new_unit(resources::units, temp_cfg, true, resources::state_of_game);
|
||||
unit new_unit(temp_cfg, true, resources::state_of_game);
|
||||
resources::units->add(loc, new_unit);
|
||||
LOG_NG << "inserting unit for side " << new_unit.side() << "\n";
|
||||
post_create(loc,new_unit,animate);
|
||||
} else {
|
||||
//get unit from recall list
|
||||
unit recalled_unit = *recall_list_element;
|
||||
recalled_unit.set_game_context(resources::units);
|
||||
team_.recall_list().erase(recall_list_element);
|
||||
resources::units->add(loc, recalled_unit);
|
||||
LOG_NG << "inserting unit from recall list for side " << recalled_unit.side()<< " with id="<< id << "\n";
|
||||
|
@ -1439,8 +1438,8 @@ bool attack::perform_hit(bool attacker_turn, statistics::attack_context &stats)
|
|||
if (reanimator)
|
||||
{
|
||||
LOG_NG << "found unit type:" << reanimator->id() << '\n';
|
||||
unit newunit(&units_, reanimator,
|
||||
attacker.get_unit().side(), true, unit_race::MALE);
|
||||
unit newunit(reanimator, attacker.get_unit().side(),
|
||||
true, unit_race::MALE);
|
||||
newunit.set_attacks(0);
|
||||
newunit.set_movement(0);
|
||||
// Apply variation
|
||||
|
|
|
@ -751,7 +751,6 @@ void recall_result::do_execute()
|
|||
|
||||
unit &un = *rec;
|
||||
recorder.add_recall(un.id(), recall_location_);
|
||||
un.set_game_context(&info.units);
|
||||
place_recruit(un, recall_location_, true, true);
|
||||
statistics::recall_unit(un);
|
||||
my_team.spend_gold(game_config::recall_cost);
|
||||
|
@ -986,7 +985,7 @@ void recruit_result::do_execute()
|
|||
const events::command_disabler disable_commands;
|
||||
const std::string recruit_err = find_recruit_location(get_side(), recruit_location_);
|
||||
if(recruit_err.empty()) {
|
||||
const unit new_unit(&info.units, u, get_side(), true);
|
||||
const unit new_unit(u, get_side(), true);
|
||||
place_recruit(new_unit, recruit_location_, false, preferences::show_ai_moves());
|
||||
statistics::recruit_unit(new_unit);
|
||||
get_my_team(info).spend_gold(u->cost());
|
||||
|
|
|
@ -1037,7 +1037,7 @@ WML_HANDLER_FUNCTION(move_unit_fake, /*event_info*/, cfg)
|
|||
unit_race::GENDER gender = string_gender(cfg["gender"]);
|
||||
const unit_type *ut = unit_types.find(type);
|
||||
if (!ut) return;
|
||||
unit dummy_unit(resources::units, ut, side_num + 1, false, gender);
|
||||
unit dummy_unit(ut, side_num + 1, false, gender);
|
||||
|
||||
config mod;
|
||||
config &effect = mod.add_child("effect");
|
||||
|
@ -1549,7 +1549,6 @@ WML_HANDLER_FUNCTION(role, /*event_info*/, cfg)
|
|||
// Iterate over the player's recall list to find a match
|
||||
for(size_t i=0; i < pi->recall_list().size(); ++i) {
|
||||
unit& u = pi->recall_list()[i];
|
||||
u.set_game_context(resources::units);
|
||||
scoped_recall_unit auto_store("this_unit", player_id, i);
|
||||
if (u.matches_filter(filter, map_location())) {
|
||||
u.set_role(cfg["role"]);
|
||||
|
@ -1734,7 +1733,7 @@ WML_HANDLER_FUNCTION(unit, /*event_info*/, cfg)
|
|||
const config& parsed_cfg = cfg.get_parsed_config();
|
||||
|
||||
if (cfg.has_attribute("to_variable")) {
|
||||
unit new_unit(resources::units, parsed_cfg, true, resources::state_of_game);
|
||||
unit new_unit(parsed_cfg, true, resources::state_of_game);
|
||||
config &var = resources::state_of_game->get_variable_cfg(parsed_cfg["to_variable"]);
|
||||
var.clear();
|
||||
new_unit.write(var);
|
||||
|
@ -1798,7 +1797,6 @@ WML_HANDLER_FUNCTION(recall, /*event_info*/, cfg)
|
|||
|
||||
for(std::vector<unit>::iterator u = avail.begin(); u != avail.end(); ++u) {
|
||||
DBG_NG << "checking unit against filter...\n";
|
||||
u->set_game_context(resources::units);
|
||||
scoped_recall_unit auto_store("this_unit", player_id, u - avail.begin());
|
||||
if (u->matches_filter(unit_filter, map_location())) {
|
||||
map_location loc = cfg_to_loc(cfg);
|
||||
|
@ -2034,7 +2032,6 @@ WML_HANDLER_FUNCTION(kill, event_info, cfg)
|
|||
{
|
||||
std::vector<unit>& avail_units = pi->recall_list();
|
||||
for(std::vector<unit>::iterator j = avail_units.begin(); j != avail_units.end();) {
|
||||
j->set_game_context(resources::units);
|
||||
scoped_recall_unit auto_store("this_unit", pi->save_id(), j - avail_units.begin());
|
||||
if (j->matches_filter(cfg, map_location())) {
|
||||
j = avail_units.erase(j);
|
||||
|
@ -2182,7 +2179,6 @@ WML_HANDLER_FUNCTION(store_unit, /*event_info*/, cfg)
|
|||
pi != resources::teams->end(); ++pi) {
|
||||
std::vector<unit>& avail_units = pi->recall_list();
|
||||
for(std::vector<unit>::iterator j = avail_units.begin(); j != avail_units.end();) {
|
||||
j->set_game_context(resources::units);
|
||||
scoped_recall_unit auto_store("this_unit", pi->save_id(), j - avail_units.begin());
|
||||
if (!j->matches_filter(filter, map_location())) {
|
||||
++j;
|
||||
|
@ -2213,7 +2209,7 @@ WML_HANDLER_FUNCTION(unstore_unit, /*event_info*/, cfg)
|
|||
|
||||
try {
|
||||
config tmp_cfg(var);
|
||||
const unit u(resources::units, tmp_cfg, false);
|
||||
const unit u(tmp_cfg, false);
|
||||
|
||||
preferences::encountered_units().insert(u.type_id());
|
||||
map_location loc = cfg_to_loc(
|
||||
|
|
|
@ -843,7 +843,7 @@ protected:
|
|||
//seen before
|
||||
config u_tmp = u;
|
||||
u_tmp["side"] = str_cast(side_);
|
||||
unit new_unit(&units_, u_tmp, true);
|
||||
unit new_unit(u_tmp, true);
|
||||
t_->recall_list().push_back(new_unit);
|
||||
} else {
|
||||
//not seen before
|
||||
|
|
|
@ -777,7 +777,7 @@ void menu_handler::do_recruit(const std::string &name, int side_num,
|
|||
|
||||
//create a unit with traits
|
||||
recorder.add_recruit(recruit_num, loc);
|
||||
const unit new_unit(&units_, u_type, side_num, true);
|
||||
const unit new_unit(u_type, side_num, true);
|
||||
place_recruit(new_unit, loc, false, true);
|
||||
current_team.spend_gold(u_type->cost());
|
||||
statistics::recruit_unit(new_unit);
|
||||
|
@ -955,7 +955,6 @@ void menu_handler::recall(int side_num, const map_location &last_hex)
|
|||
}
|
||||
unit un = recall_list_team[res];
|
||||
recorder.add_recall(un.id(), loc);
|
||||
un.set_game_context(&units_);
|
||||
place_recruit(un, loc, true, true);
|
||||
statistics::recall_unit(un);
|
||||
current_team.spend_gold(game_config::recall_cost);
|
||||
|
@ -1126,7 +1125,6 @@ void menu_handler::redo(int side_num)
|
|||
const std::string &msg = find_recruit_location(side_num, loc);
|
||||
if(msg.empty()) {
|
||||
unit un = action.affected_unit;
|
||||
un.set_game_context(&units_);
|
||||
place_recruit(un, loc, true, true);
|
||||
statistics::recall_unit(un);
|
||||
current_team.spend_gold(game_config::recall_cost);
|
||||
|
@ -1404,7 +1402,7 @@ void menu_handler::create_unit_2(mouse_handler& mousehandler)
|
|||
gender = ut.genders().front();
|
||||
}
|
||||
|
||||
unit chosen(&units_, &ut, 1, true, gender);
|
||||
unit chosen(&ut, 1, true, gender);
|
||||
chosen.new_turn();
|
||||
|
||||
//FIXME: the generate name option seems useless now, remove it
|
||||
|
@ -1498,7 +1496,7 @@ void menu_handler::create_unit(mouse_handler& mousehandler)
|
|||
|
||||
const unit_race::GENDER gender = random_gender ? unit_race::NUM_GENDERS : unit_race::MALE;
|
||||
|
||||
unit chosen(&units_, unit_choices[choice], 1, true, gender);
|
||||
unit chosen(unit_choices[choice], 1, true, gender);
|
||||
chosen.new_turn();
|
||||
|
||||
const map_location& loc = mousehandler.get_last_hex();
|
||||
|
@ -3274,7 +3272,7 @@ void console_handler::do_unit() {
|
|||
const map_location loc = i->get_location();
|
||||
menu_handler_.units_.erase(loc);
|
||||
cfg[name] = value;
|
||||
unit new_u(&menu_handler_.units_, cfg, true);
|
||||
unit new_u(cfg, true);
|
||||
menu_handler_.units_.add(loc, new_u);
|
||||
}
|
||||
menu_handler_.gui_->invalidate(i->get_location());
|
||||
|
@ -3321,7 +3319,7 @@ void console_handler::do_create() {
|
|||
|
||||
menu_handler_.units_.erase(loc);
|
||||
|
||||
unit created(&menu_handler_.units_, ut, 1, true);
|
||||
unit created(ut, 1, true);
|
||||
created.new_turn();
|
||||
|
||||
menu_handler_.units_.add(loc, created);
|
||||
|
|
|
@ -947,7 +947,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, side_num, true);
|
||||
const unit new_unit(u_type, side_num, true);
|
||||
if (res.empty()) {
|
||||
place_recruit(new_unit, loc, false, !get_replay_source().is_skipping());
|
||||
} else {
|
||||
|
@ -984,7 +984,6 @@ bool do_replay_handle(int side_num, const std::string &do_untill)
|
|||
|
||||
if (recall_unit != current_team.recall_list().end()) {
|
||||
statistics::recall_unit(*recall_unit);
|
||||
(*recall_unit).set_game_context(resources::units);
|
||||
place_recruit(*recall_unit, loc, true, !get_replay_source().is_skipping());
|
||||
current_team.recall_list().erase(recall_unit);
|
||||
current_team.spend_gold(game_config::recall_cost);
|
||||
|
|
|
@ -1957,7 +1957,7 @@ static int intf_put_unit(lua_State *L)
|
|||
goto error_call_destructors_3;
|
||||
}
|
||||
try {
|
||||
u = new unit(resources::units, cfg, true, resources::state_of_game);
|
||||
u = new unit(cfg, true, resources::state_of_game);
|
||||
} catch (const game::error &e) {
|
||||
error_buffer = "broken unit WML [" + e.message + "]";
|
||||
goto error_call_destructors_2;
|
||||
|
@ -1998,7 +1998,7 @@ static int intf_find_vacant_tile(lua_State *L)
|
|||
if (!luaW_toconfig(L, 3, cfg))
|
||||
goto error_call_destructors;
|
||||
try {
|
||||
u = new unit(resources::units, cfg, false, resources::state_of_game);
|
||||
u = new unit(cfg, false, resources::state_of_game);
|
||||
} catch (const game::error &) {
|
||||
goto error_call_destructors;
|
||||
}
|
||||
|
@ -2057,7 +2057,7 @@ static int intf_create_unit(lua_State *L)
|
|||
if (!luaW_toconfig(L, 1, cfg))
|
||||
goto error_call_destructors_1;
|
||||
try {
|
||||
unit *u = new unit(resources::units, cfg, true, resources::state_of_game);
|
||||
unit *u = new unit(cfg, true, resources::state_of_game);
|
||||
new(lua_newuserdata(L, sizeof(lua_unit))) lua_unit(u);
|
||||
lua_pushlightuserdata(L, (void *)&getunitKey);
|
||||
lua_rawget(L, LUA_REGISTRYINDEX);
|
||||
|
|
11
src/unit.cpp
11
src/unit.cpp
|
@ -204,8 +204,7 @@ unit::unit(const unit& o):
|
|||
{
|
||||
}
|
||||
|
||||
unit::unit(unit_map* unitmap, const config& cfg,
|
||||
bool use_traits, game_state* state) :
|
||||
unit::unit(const config &cfg, bool use_traits, game_state* state) :
|
||||
cfg_(cfg),
|
||||
loc_(),
|
||||
advances_to_(),
|
||||
|
@ -272,7 +271,7 @@ unit::unit(unit_map* unitmap, const config& cfg,
|
|||
hidden_(false),
|
||||
draw_bars_(false),
|
||||
modifications_(),
|
||||
units_(unitmap),
|
||||
units_(NULL),
|
||||
invisibility_cache_()
|
||||
{
|
||||
set_state(STATE_HIDDEN,true);
|
||||
|
@ -550,8 +549,8 @@ void unit::clear_status_caches()
|
|||
units_with_cache.clear();
|
||||
}
|
||||
|
||||
unit::unit(unit_map *unitmap, const unit_type *t, int side,
|
||||
bool real_unit, unit_race::GENDER gender) :
|
||||
unit::unit(const unit_type *t, int side, bool real_unit,
|
||||
unit_race::GENDER gender) :
|
||||
cfg_(),
|
||||
loc_(),
|
||||
advances_to_(),
|
||||
|
@ -619,7 +618,7 @@ unit::unit(unit_map *unitmap, const unit_type *t, int side,
|
|||
hidden_(false),
|
||||
draw_bars_(false),
|
||||
modifications_(),
|
||||
units_(unitmap),
|
||||
units_(NULL),
|
||||
invisibility_cache_()
|
||||
{
|
||||
|
||||
|
|
|
@ -63,14 +63,14 @@ public:
|
|||
// Copy constructor
|
||||
unit(const unit& u);
|
||||
/** Initilizes a unit from a config */
|
||||
unit(unit_map* unitmap,
|
||||
const config& cfg, bool use_traits=false, game_state* state = 0);
|
||||
unit(const config& cfg, bool use_traits = false, game_state *state = NULL);
|
||||
/**
|
||||
* Initializes a unit from a unit type
|
||||
* only real_unit may have random traits, name and gender
|
||||
* (to prevent OOS caused by RNG calls)
|
||||
*/
|
||||
unit(unit_map* unitmap, const unit_type* t, int side, bool real_unit, unit_race::GENDER gender=unit_race::NUM_GENDERS);
|
||||
unit(const unit_type* t, int side, bool real_unit,
|
||||
unit_race::GENDER gender = unit_race::NUM_GENDERS);
|
||||
virtual ~unit();
|
||||
unit& operator=(const unit&);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue