mirror of
https://github.com/wesnoth/wesnoth
synced 2025-04-28 14:03:55 +00:00
Removed redundant fields map_ and teams_ from class unit.
This commit is contained in:
parent
c7fbcd2ce1
commit
ea2cfb043d
@ -1298,7 +1298,7 @@ attack::attack(game_display& gui, const gamemap& map,
|
||||
reanimitor = unit_type_data::types().find_unit_type(a_stats_->plague_type);
|
||||
LOG_NG << "found unit type:" << reanimitor->second.id() << std::endl;
|
||||
if(reanimitor != unit_type_data::types().end()) {
|
||||
unit newunit(&units_, &map_, &tod_manager_, &teams_, &reanimitor->second,
|
||||
unit newunit(&units_, &tod_manager_, &reanimitor->second,
|
||||
a_.get_unit().side(), true, true);
|
||||
newunit.set_attacks(0);
|
||||
// Apply variation
|
||||
@ -1569,7 +1569,7 @@ attack::attack(game_display& gui, const gamemap& map,
|
||||
reanimitor = unit_type_data::types().find_unit_type(d_stats_->plague_type);
|
||||
LOG_NG << "found unit type:" << reanimitor->second.id() << std::endl;
|
||||
if(reanimitor != unit_type_data::types().end()) {
|
||||
unit newunit(&units_, &map_, &tod_manager_, &teams_, &reanimitor->second,
|
||||
unit newunit(&units_, &tod_manager_, &reanimitor->second,
|
||||
d_.get_unit().side(), true, true);
|
||||
// Apply variation
|
||||
if(strcmp(undead_variation.c_str(),"null")){
|
||||
|
@ -665,7 +665,7 @@ void recruit_result::do_execute()
|
||||
recorder.add_recruit(num_,recruit_location_);
|
||||
replay_undo replay_guard(recorder);
|
||||
unit_type_data::unit_type_map::const_iterator u = unit_type_data::types().find_unit_type(unit_name_);
|
||||
unit new_unit(&info.units,&info.map,&info.tod_manager_,&info.teams,&u->second,get_side(),true);
|
||||
unit new_unit(&info.units, &info.tod_manager_, &u->second, get_side(), true);
|
||||
std::string recruit_err = recruit_unit(info.map,get_side(),info.units,new_unit,recruit_location_,false,preferences::show_ai_moves());
|
||||
if(recruit_err.empty()) {
|
||||
statistics::recruit_unit(new_unit);
|
||||
|
@ -182,7 +182,7 @@ bool readwrite_context_impl::recruit(const std::string& unit_name, map_location
|
||||
" gold=" << (current_team().gold()) <<
|
||||
" (-> " << (current_team().gold()-u->second.cost()) << ")\n";
|
||||
|
||||
unit new_unit(&get_info().units,&get_info().map,&get_info().tod_manager_,&get_info().teams,&u->second,get_side(),true);
|
||||
unit new_unit(&get_info().units, &get_info().tod_manager_, &u->second, get_side(), true);
|
||||
|
||||
// See if we can actually recruit (i.e. have enough room etc.)
|
||||
std::string recruit_err = recruit_unit(get_info().map,get_side(),get_info().units,new_unit,loc,false,preferences::show_ai_moves());
|
||||
|
@ -1400,8 +1400,8 @@ void ai_default::analyze_potential_recruit_movements()
|
||||
continue;
|
||||
}
|
||||
|
||||
const unit temp_unit(&get_info().units,&get_info().map,
|
||||
&get_info().tod_manager_, &get_info().teams, &info->second, get_side());
|
||||
const unit temp_unit(&get_info().units,
|
||||
&get_info().tod_manager_, &info->second, get_side());
|
||||
// since we now use the ignore_units switch, no need to use a empty unit_map
|
||||
// unit_map units;
|
||||
// const temporary_unit_placer placer(units,start,temp_unit);
|
||||
|
@ -1048,7 +1048,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, resources::game_map, &resources::controller->get_tod_manager(), resources::teams, &itor->second, side_num + 1, false, true, gender, variation);
|
||||
unit dummy_unit(resources::units, &resources::controller->get_tod_manager(), &itor->second, side_num + 1, false, true, 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;
|
||||
@ -1765,7 +1765,7 @@ 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, resources::game_map, &resources::controller->get_tod_manager(), resources::teams);
|
||||
u.set_game_context(resources::units, &resources::controller->get_tod_manager());
|
||||
scoped_recall_unit auto_store("this_unit", player_id, i);
|
||||
if(game_events::unit_matches_filter(u, filter, map_location())) {
|
||||
u.set_role(cfg["role"]);
|
||||
@ -1959,7 +1959,7 @@ static bool try_add_unit_to_recall_list(const map_location& loc, const unit& u)
|
||||
WML_HANDLER_FUNCTION(unit, /*event_info*/, cfg)
|
||||
{
|
||||
const config& parsed_cfg = cfg.get_parsed_config();
|
||||
unit new_unit(resources::units, resources::game_map, &resources::controller->get_tod_manager(), resources::teams, parsed_cfg, true, resources::state_of_game);
|
||||
unit new_unit(resources::units, &resources::controller->get_tod_manager(), parsed_cfg, true, resources::state_of_game);
|
||||
if(cfg.has_attribute("to_variable")) {
|
||||
config &var = resources::state_of_game->get_variable_cfg(parsed_cfg["to_variable"]);
|
||||
new_unit.write(var);
|
||||
@ -2032,7 +2032,7 @@ 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, resources::game_map, &resources::controller->get_tod_manager(), resources::teams);
|
||||
u->set_game_context(resources::units, &resources::controller->get_tod_manager());
|
||||
scoped_recall_unit auto_store("this_unit", player_id, u - avail.begin());
|
||||
if(game_events::unit_matches_filter(*u, unit_filter, map_location())) {
|
||||
map_location loc = cfg_to_loc(cfg);
|
||||
@ -2266,7 +2266,7 @@ 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, resources::game_map, &resources::controller->get_tod_manager(), resources::teams);
|
||||
j->set_game_context(resources::units, &resources::controller->get_tod_manager());
|
||||
scoped_recall_unit auto_store("this_unit", pi->save_id(), j - avail_units.begin());
|
||||
if(game_events::unit_matches_filter(*j, cfg,map_location())) {
|
||||
j = avail_units.erase(j);
|
||||
@ -2414,7 +2414,7 @@ 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, resources::game_map, &resources::controller->get_tod_manager(), resources::teams);
|
||||
j->set_game_context(resources::units, &resources::controller->get_tod_manager());
|
||||
scoped_recall_unit auto_store("this_unit", pi->save_id(), j - avail_units.begin());
|
||||
if(game_events::unit_matches_filter(*j, filter,map_location()) == false) {
|
||||
++j;
|
||||
@ -2444,7 +2444,7 @@ WML_HANDLER_FUNCTION(unstore_unit, /*event_info*/, cfg)
|
||||
const config &var = resources::state_of_game->get_variable_cfg(cfg["variable"]);
|
||||
|
||||
try {
|
||||
const unit u(resources::units, resources::game_map, &resources::controller->get_tod_manager(), resources:: teams, var, false);
|
||||
const unit u(resources::units, &resources::controller->get_tod_manager(), var, false);
|
||||
|
||||
preferences::encountered_units().insert(u.type_id());
|
||||
map_location loc = cfg_to_loc(
|
||||
|
@ -773,7 +773,7 @@ void game_state::get_player_info(const config& side_cfg,
|
||||
|
||||
// If this side tag describes the leader of the side
|
||||
if(!utils::string_bool(side_cfg["no_leader"]) && side_cfg["controller"] != "null") {
|
||||
unit new_unit(&units, &map, &tod_mng, &teams, side_cfg, true);
|
||||
unit new_unit(&units, &tod_mng, side_cfg, true);
|
||||
|
||||
// Search the recall list for leader units, and if there is one,
|
||||
// use it in place of the config-described unit
|
||||
@ -792,7 +792,7 @@ void game_state::get_player_info(const config& side_cfg,
|
||||
it != teams.back().recall_list().end(); ++it) {
|
||||
if(it->can_recruit()) {
|
||||
new_unit = *it;
|
||||
new_unit.set_game_context(&units, &map, &tod_mng, &teams);
|
||||
new_unit.set_game_context(&units, &tod_mng);
|
||||
teams.back().recall_list().erase(it);
|
||||
break;
|
||||
}
|
||||
@ -852,7 +852,7 @@ void game_state::get_player_info(const config& side_cfg,
|
||||
teams.back().recall_list().clear();
|
||||
}
|
||||
for(config::child_list::const_iterator su = starting_units.begin(); su != starting_units.end(); ++su) {
|
||||
unit new_unit(&units, &map, &tod_mng, &teams,**su,true);
|
||||
unit new_unit(&units, &tod_mng, **su, true);
|
||||
|
||||
new_unit.set_side(side);
|
||||
|
||||
|
@ -781,7 +781,7 @@ private:
|
||||
|
||||
//create a unit with traits
|
||||
recorder.add_recruit(recruit_num, last_hex);
|
||||
unit new_unit(&units_, &map_, &tod_manager_, &teams_, &u_type->second, side_num, true);
|
||||
unit new_unit(&units_, &tod_manager_, &u_type->second, side_num, true);
|
||||
map_location loc = last_hex;
|
||||
const std::string &msg = recruit_unit(map_, side_num, units_,
|
||||
new_unit, loc, false, gui_ != NULL);
|
||||
@ -939,7 +939,7 @@ private:
|
||||
unit& un = recall_list_team[res];
|
||||
map_location loc = last_hex;
|
||||
recorder.add_recall(res,loc);
|
||||
un.set_game_context(&units_,&map_,&tod_manager_,&teams_);
|
||||
un.set_game_context(&units_, &tod_manager_);
|
||||
const std::string &err = recruit_unit(map_, side_num, units_,
|
||||
un, loc, true, gui_ != NULL);
|
||||
if(!err.empty()) {
|
||||
@ -1109,7 +1109,7 @@ private:
|
||||
unit un = current_team.recall_list()[action.recall_pos];
|
||||
|
||||
recorder.add_recall(action.recall_pos,action.recall_loc);
|
||||
un.set_game_context(&units_,&map_,&tod_manager_,&teams_);
|
||||
un.set_game_context(&units_, &tod_manager_);
|
||||
const std::string &msg = recruit_unit(map_, side_num,
|
||||
units_, un, action.recall_loc, true, gui_ != NULL);
|
||||
if(msg.empty()) {
|
||||
@ -1433,7 +1433,7 @@ private:
|
||||
const unit_race::GENDER gender =
|
||||
(!genders.empty() ? genders[gamestate_.rng().get_random() % genders.size()] : unit_race::MALE);
|
||||
|
||||
unit chosen(&units_,&map_,&tod_manager_,&teams_,unit_choices[choice],1,false,false,gender,"",random_gender);
|
||||
unit chosen(&units_, &tod_manager_, unit_choices[choice], 1, false, false, gender, "", random_gender);
|
||||
chosen.new_turn();
|
||||
|
||||
const map_location& loc = mousehandler.get_last_hex();
|
||||
@ -3059,8 +3059,8 @@ private:
|
||||
|
||||
menu_handler_.units_.erase(loc);
|
||||
menu_handler_.units_.add(loc,
|
||||
unit(&menu_handler_.units_, &menu_handler_.map_, &menu_handler_.tod_manager_,
|
||||
&menu_handler_.teams_, &i->second, 1, false));
|
||||
unit(&menu_handler_.units_, &menu_handler_.tod_manager_,
|
||||
&i->second, 1, false));
|
||||
menu_handler_.gui_->invalidate(loc);
|
||||
menu_handler_.gui_->invalidate_unit();
|
||||
} else {
|
||||
|
@ -929,7 +929,7 @@ bool do_replay_handle(game_display& disp, const gamemap& map,
|
||||
replay::throw_error(errbuf.str());
|
||||
}
|
||||
|
||||
unit new_unit(&units,&map,&tod_mng,&teams,&(u_type->second),team_num,true, false);
|
||||
unit new_unit(&units, &tod_mng, &u_type->second, team_num, true, false);
|
||||
const std::string& res = recruit_unit(map,team_num,units,new_unit,loc,false,!get_replay_source().is_skipping());
|
||||
if(!res.empty()) {
|
||||
std::stringstream errbuf;
|
||||
@ -970,7 +970,7 @@ bool do_replay_handle(game_display& disp, const gamemap& map,
|
||||
|
||||
if(val >= 0 && val < int(current_team.recall_list().size())) {
|
||||
statistics::recall_unit(current_team.recall_list()[val]);
|
||||
current_team.recall_list()[val].set_game_context(&units,&map,&tod_mng,&teams);
|
||||
current_team.recall_list()[val].set_game_context(&units, &tod_mng);
|
||||
recruit_unit(map,team_num,units,current_team.recall_list()[val],loc,true,!get_replay_source().is_skipping());
|
||||
current_team.recall_list().erase(current_team.recall_list().begin()+val);
|
||||
current_team.spend_gold(game_config::recall_cost);
|
||||
|
48
src/unit.cpp
48
src/unit.cpp
@ -31,6 +31,7 @@
|
||||
#include "gettext.hpp"
|
||||
#include "halo.hpp"
|
||||
#include "log.hpp"
|
||||
#include "resources.hpp"
|
||||
#include "unit_id.hpp"
|
||||
#include "unit_abilities.hpp"
|
||||
#include "terrain_filter.hpp"
|
||||
@ -162,15 +163,12 @@ unit::unit(const unit& o):
|
||||
|
||||
modifications_(o.modifications_),
|
||||
units_(o.units_),
|
||||
map_(o.map_),
|
||||
tod_manager_(o.tod_manager_),
|
||||
teams_(o.teams_),
|
||||
invisibility_cache_()
|
||||
{
|
||||
}
|
||||
|
||||
unit::unit(unit_map* unitmap, const gamemap* map, const tod_manager* tod_mng,
|
||||
const std::vector<team>* teams,const config& cfg,
|
||||
unit::unit(unit_map* unitmap, const tod_manager* tod_mng, const config& cfg,
|
||||
bool use_traits, game_state* state) :
|
||||
cfg_(),
|
||||
advances_to_(),
|
||||
@ -238,9 +236,7 @@ unit::unit(unit_map* unitmap, const gamemap* map, const tod_manager* tod_mng,
|
||||
draw_bars_(false),
|
||||
modifications_(),
|
||||
units_(unitmap),
|
||||
map_(map),
|
||||
tod_manager_(tod_mng),
|
||||
teams_(teams),
|
||||
invisibility_cache_()
|
||||
{
|
||||
read(cfg, use_traits, state);
|
||||
@ -319,9 +315,7 @@ unit::unit(const config& cfg,bool use_traits) :
|
||||
draw_bars_(false),
|
||||
modifications_(),
|
||||
units_(NULL),
|
||||
map_(NULL),
|
||||
tod_manager_(NULL),
|
||||
teams_(NULL),
|
||||
invisibility_cache_()
|
||||
{
|
||||
read(cfg,use_traits);
|
||||
@ -359,8 +353,7 @@ unit_race::GENDER unit::generate_gender(const unit_type& type, bool gen, game_st
|
||||
}
|
||||
}
|
||||
|
||||
unit::unit(unit_map* unitmap, const gamemap* map, const tod_manager* tod_mng,
|
||||
const std::vector<team>* teams, const unit_type* t, int side,
|
||||
unit::unit(unit_map *unitmap, const tod_manager *tod_mng, const unit_type *t, int side,
|
||||
bool use_traits, bool dummy_unit, unit_race::GENDER gender, std::string variation, bool force_gender) :
|
||||
cfg_(),
|
||||
advances_to_(),
|
||||
@ -428,9 +421,7 @@ unit::unit(unit_map* unitmap, const gamemap* map, const tod_manager* tod_mng,
|
||||
draw_bars_(false),
|
||||
modifications_(),
|
||||
units_(unitmap),
|
||||
map_(map),
|
||||
tod_manager_(tod_mng),
|
||||
teams_(teams),
|
||||
invisibility_cache_()
|
||||
{
|
||||
cfg_["upkeep"]="full";
|
||||
@ -529,7 +520,6 @@ unit::unit(const unit_type* t, int side, bool use_traits, bool dummy_unit,
|
||||
draw_bars_(false),
|
||||
modifications_(),
|
||||
units_(NULL),
|
||||
map_(NULL),
|
||||
tod_manager_(NULL),
|
||||
invisibility_cache_()
|
||||
{
|
||||
@ -589,12 +579,10 @@ unit& unit::operator=(const unit& u)
|
||||
|
||||
|
||||
|
||||
void unit::set_game_context(unit_map* unitmap, const gamemap* map, const tod_manager* tod_mng, const std::vector<team>* teams)
|
||||
void unit::set_game_context(unit_map *unitmap, const tod_manager *tod_mng)
|
||||
{
|
||||
units_ = unitmap;
|
||||
map_ = map;
|
||||
tod_manager_ = tod_mng;
|
||||
teams_ = teams;
|
||||
|
||||
// In case the unit carries EventWML, apply it now
|
||||
game_events::add_events(cfg_.child_range("event"), type_);
|
||||
@ -1135,12 +1123,12 @@ bool unit::internal_matches_filter(const vconfig& cfg, const map_location& loc,
|
||||
}
|
||||
|
||||
if(cfg.has_child("filter_location")) {
|
||||
assert(map_ != NULL);
|
||||
assert(teams_ != NULL);
|
||||
assert(resources::game_map != NULL);
|
||||
assert(resources::teams != NULL);
|
||||
assert(tod_manager_ != NULL);
|
||||
assert(units_ != NULL);
|
||||
const vconfig& t_cfg = cfg.child("filter_location");
|
||||
terrain_filter t_filter(t_cfg, *map_, *tod_manager_, *teams_, *units_, use_flat_tod);
|
||||
terrain_filter t_filter(t_cfg, *resources::game_map, *tod_manager_, *resources::teams, *units_, use_flat_tod);
|
||||
if(!t_filter.match(loc)) {
|
||||
return false;
|
||||
}
|
||||
@ -1151,7 +1139,9 @@ bool unit::internal_matches_filter(const vconfig& cfg, const map_location& loc,
|
||||
const t_string& cfg_y = cfg["y"];
|
||||
if(cfg_x == "recall" && cfg_y == "recall") {
|
||||
//locations on the map are considered to not be on a recall list
|
||||
if((!map_ && loc.valid()) || (map_ && map_->on_board(loc))) {
|
||||
if ((!resources::game_map && loc.valid()) ||
|
||||
(resources::game_map && resources::game_map->on_board(loc)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
} else if(cfg_x.empty() && cfg_y.empty()) {
|
||||
@ -1267,11 +1257,11 @@ bool unit::internal_matches_filter(const vconfig& cfg, const map_location& loc,
|
||||
return false;
|
||||
}
|
||||
|
||||
if(cfg.has_attribute("defense") && defense_modifier(map_->get_terrain(loc)) != lexical_cast_default<int>(cfg["defense"],-1)) {
|
||||
if(cfg.has_attribute("defense") && defense_modifier(resources::game_map->get_terrain(loc)) != lexical_cast_default<int>(cfg["defense"],-1)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(cfg.has_attribute("movement_cost") && movement_cost(map_->get_terrain(loc)) != lexical_cast_default<int>(cfg["movement_cost"],-1)) {
|
||||
if(cfg.has_attribute("movement_cost") && movement_cost(resources::game_map->get_terrain(loc)) != lexical_cast_default<int>(cfg["movement_cost"],-1)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1331,7 +1321,7 @@ bool unit::internal_matches_filter(const vconfig& cfg, const map_location& loc,
|
||||
}
|
||||
|
||||
if (cfg.has_child("filter_adjacent")) {
|
||||
assert(units_ && map_);
|
||||
assert(units_ && resources::game_map);
|
||||
map_location adjacent[6];
|
||||
get_adjacent_tiles(loc, adjacent);
|
||||
vconfig::child_list::const_iterator i, i_end;
|
||||
@ -2141,9 +2131,9 @@ int unit::movement_cost_internal(const t_translation::t_terrain terrain, const i
|
||||
return i->second;
|
||||
}
|
||||
|
||||
assert(map_ != NULL);
|
||||
assert(resources::game_map != NULL);
|
||||
// If this is an alias, then select the best of all underlying terrains
|
||||
const t_translation::t_list& underlying = map_->underlying_mvt_terrain(terrain);
|
||||
const t_translation::t_list& underlying = resources::game_map->underlying_mvt_terrain(terrain);
|
||||
|
||||
assert(!underlying.empty());
|
||||
if(underlying.size() != 1 || underlying.front() != terrain) { // We fail here, but first test underlying_mvt_terrain
|
||||
@ -2182,7 +2172,7 @@ int unit::movement_cost_internal(const t_translation::t_terrain terrain, const i
|
||||
<< underlying.size() << " underlying names - 0 expected\n";
|
||||
return impassable;
|
||||
}
|
||||
const std::string& id = map_->get_terrain_info(underlying.front()).id();
|
||||
const std::string& id = resources::game_map->get_terrain_info(underlying.front()).id();
|
||||
const std::string &val = movement_costs[id];
|
||||
if (!val.empty()) {
|
||||
res = atoi(val.c_str());
|
||||
@ -2215,11 +2205,11 @@ int unit::defense_modifier(t_translation::t_terrain terrain, int recurse_count)
|
||||
return d->second;
|
||||
}
|
||||
|
||||
assert(map_ != NULL);
|
||||
assert(resources::game_map != NULL);
|
||||
int res = 100;
|
||||
|
||||
// If this is an alias, then select the best of all underlying terrains
|
||||
const t_translation::t_list& underlying = map_->underlying_def_terrain(terrain);
|
||||
const t_translation::t_list& underlying = resources::game_map->underlying_def_terrain(terrain);
|
||||
assert(underlying.size() > 0);
|
||||
if(underlying.size() != 1 || underlying.front() != terrain) {
|
||||
bool revert = (underlying.front() == t_translation::MINUS ? true : false);
|
||||
@ -2260,7 +2250,7 @@ int unit::defense_modifier(t_translation::t_terrain terrain, int recurse_count)
|
||||
return res;
|
||||
}
|
||||
|
||||
const std::string& id = map_->get_terrain_info(underlying.front()).id();
|
||||
const std::string& id = resources::game_map->get_terrain_info(underlying.front()).id();
|
||||
const std::string &val = defense[id];
|
||||
if (!val.empty()) {
|
||||
res = atoi(val.c_str());
|
||||
|
10
src/unit.hpp
10
src/unit.hpp
@ -68,16 +68,16 @@ public:
|
||||
unit(const unit& u);
|
||||
/** Initilizes a unit from a config */
|
||||
unit(const config& cfg, bool use_traits=false);
|
||||
unit(unit_map* unitmap, const gamemap* map,
|
||||
const tod_manager* tod_mng, const std::vector<team>* teams,
|
||||
unit(unit_map* unitmap,
|
||||
const tod_manager* tod_mng,
|
||||
const config& cfg, bool use_traits=false, game_state* state = 0);
|
||||
/** Initializes a unit from a unit type */
|
||||
unit(const unit_type* t, int side, bool use_traits=false, bool dummy_unit=false, unit_race::GENDER gender=unit_race::MALE, std::string variation="");
|
||||
unit(unit_map* unitmap, const gamemap* map, const tod_manager* tod_mng, const std::vector<team>* teams, 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);
|
||||
unit(unit_map* unitmap, const tod_manager* tod_mng, 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);
|
||||
virtual ~unit();
|
||||
unit& operator=(const unit&);
|
||||
|
||||
void set_game_context(unit_map* unitmap, const gamemap* map, const tod_manager* tod_mng, const std::vector<team>* teams);
|
||||
void set_game_context(unit_map* unitmap, const tod_manager* tod_mng);
|
||||
|
||||
/** Advances this unit to another type */
|
||||
void advance_to(const unit_type* t, bool use_traits=false, game_state* state = 0);
|
||||
@ -457,9 +457,7 @@ private:
|
||||
|
||||
friend void attack_type::set_specials_context(const map_location& loc, const map_location&, const unit& un, bool) const;
|
||||
const unit_map* units_;
|
||||
const gamemap* map_;
|
||||
const tod_manager* tod_manager_;
|
||||
const std::vector<team>* teams_;
|
||||
|
||||
/** Hold the visibility status cache for a unit, mutable since it's a cache. */
|
||||
mutable std::map<map_location, bool> invisibility_cache_;
|
||||
|
@ -18,10 +18,11 @@
|
||||
*/
|
||||
|
||||
#include "foreach.hpp"
|
||||
#include "gamestatus.hpp"
|
||||
#include "resources.hpp"
|
||||
#include "terrain_filter.hpp"
|
||||
#include "unit.hpp"
|
||||
#include "unit_abilities.hpp"
|
||||
#include "terrain_filter.hpp"
|
||||
#include "gamestatus.hpp"
|
||||
|
||||
|
||||
|
||||
@ -244,7 +245,7 @@ static bool cache_illuminates(int &cache, std::string const &ability)
|
||||
bool unit::ability_active(const std::string& ability,const config& cfg,const map_location& loc) const
|
||||
{
|
||||
int illuminates = -1;
|
||||
assert(units_ && map_ && teams_ && tod_manager_);
|
||||
assert(units_ && resources::game_map && resources::teams && tod_manager_);
|
||||
|
||||
if (const config &afilter = cfg.child("filter"))
|
||||
if (!matches_filter(vconfig(afilter), loc, cache_illuminates(illuminates, ability)))
|
||||
@ -278,7 +279,7 @@ bool unit::ability_active(const std::string& ability,const config& cfg,const map
|
||||
if (index == map_location::NDIRECTIONS) {
|
||||
continue;
|
||||
}
|
||||
terrain_filter adj_filter(vconfig(i), *map_, *tod_manager_, *teams_, *units_);
|
||||
terrain_filter adj_filter(vconfig(i), *resources::game_map, *tod_manager_, *resources::teams, *units_);
|
||||
adj_filter.flatten(cache_illuminates(illuminates, ability));
|
||||
if(!adj_filter.match(adjacent[index])) {
|
||||
return false;
|
||||
@ -760,9 +761,9 @@ void attack_type::set_specials_context(const map_location& loc, const map_locati
|
||||
aloc_ = loc;
|
||||
dloc_ = dloc;
|
||||
unitmap_ = un.units_;
|
||||
map_ = un.map_;
|
||||
map_ = resources::game_map;
|
||||
tod_manager_ = un.tod_manager_;
|
||||
teams_ = un.teams_;
|
||||
teams_ = resources::teams;
|
||||
attacker_ = attacker;
|
||||
other_attack_ = NULL;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user