Remove units_ from unit class, and always use resources::units instead.
(some polishing are still needed)
This commit is contained in:
parent
f7af21b693
commit
3fe15b2346
3 changed files with 23 additions and 27 deletions
24
src/unit.cpp
24
src/unit.cpp
|
@ -200,7 +200,6 @@ unit::unit(const unit& o):
|
|||
draw_bars_(o.draw_bars_),
|
||||
|
||||
modifications_(o.modifications_),
|
||||
units_(o.units_),
|
||||
invisibility_cache_()
|
||||
{
|
||||
}
|
||||
|
@ -273,7 +272,6 @@ unit::unit(const config &cfg, bool use_traits, game_state* state) :
|
|||
hidden_(false),
|
||||
draw_bars_(false),
|
||||
modifications_(),
|
||||
units_(resources::units),
|
||||
invisibility_cache_()
|
||||
{
|
||||
if (type_.empty()) {
|
||||
|
@ -621,7 +619,6 @@ unit::unit(const unit_type *t, int side, bool real_unit,
|
|||
hidden_(false),
|
||||
draw_bars_(false),
|
||||
modifications_(),
|
||||
units_(resources::units),
|
||||
invisibility_cache_()
|
||||
{
|
||||
|
||||
|
@ -681,10 +678,8 @@ unit& unit::operator=(const unit& u)
|
|||
|
||||
|
||||
|
||||
void unit::set_game_context(unit_map *unitmap)
|
||||
void unit::set_game_context(unit_map* /*unitmap*/)
|
||||
{
|
||||
units_ = unitmap;
|
||||
|
||||
// In case the unit carries EventWML, apply it now
|
||||
game_events::add_events(cfg_.child_range("event"), type_);
|
||||
cfg_.clear_children("event");
|
||||
|
@ -1209,8 +1204,8 @@ bool unit::matches_filter(const vconfig& cfg, const map_location& loc, bool use_
|
|||
bool matches = true;
|
||||
|
||||
if(loc.valid()) {
|
||||
assert(units_ != NULL);
|
||||
scoped_xy_unit auto_store("this_unit", loc.x, loc.y, *units_);
|
||||
assert(resources::units != NULL);
|
||||
scoped_xy_unit auto_store("this_unit", loc.x, loc.y, *resources::units);
|
||||
matches = internal_matches_filter(cfg, loc, use_flat_tod);
|
||||
} else {
|
||||
// If loc is invalid, then this is a recall list unit (already been scoped)
|
||||
|
@ -1263,9 +1258,9 @@ bool unit::internal_matches_filter(const vconfig& cfg, const map_location& loc,
|
|||
assert(resources::game_map != NULL);
|
||||
assert(resources::teams != NULL);
|
||||
assert(resources::tod_manager != NULL);
|
||||
assert(units_ != NULL);
|
||||
assert(resources::units != NULL);
|
||||
const vconfig& t_cfg = cfg.child("filter_location");
|
||||
terrain_filter t_filter(t_cfg, *units_, use_flat_tod);
|
||||
terrain_filter t_filter(t_cfg, *resources::units, use_flat_tod);
|
||||
if(!t_filter.match(loc)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -1447,7 +1442,7 @@ bool unit::internal_matches_filter(const vconfig& cfg, const map_location& loc,
|
|||
std::set<int>::const_iterator viewer, viewer_end = viewers.end();
|
||||
for (viewer = viewers.begin(); viewer != viewer_end; ++viewer) {
|
||||
bool not_fogged = !teams_manager::get_teams()[*viewer - 1].fogged(loc);
|
||||
bool not_hiding = !this->invisible(loc, *units_, teams_manager::get_teams()/*, false(?) */);
|
||||
bool not_hiding = !this->invisible(loc, *resources::units, teams_manager::get_teams()/*, false(?) */);
|
||||
if (visible != not_fogged && not_hiding) {
|
||||
return false;
|
||||
}
|
||||
|
@ -1456,7 +1451,8 @@ bool unit::internal_matches_filter(const vconfig& cfg, const map_location& loc,
|
|||
}
|
||||
|
||||
if (cfg.has_child("filter_adjacent")) {
|
||||
assert(units_ && resources::game_map);
|
||||
assert(resources::units && resources::game_map);
|
||||
const unit_map& units = *resources::units;
|
||||
map_location adjacent[6];
|
||||
get_adjacent_tiles(loc, adjacent);
|
||||
vconfig::child_list::const_iterator i, i_end;
|
||||
|
@ -1469,8 +1465,8 @@ bool unit::internal_matches_filter(const vconfig& cfg, const map_location& loc,
|
|||
? map_location::parse_directions((*i)["adjacent"]) : default_dirs;
|
||||
std::vector<map_location::DIRECTION>::const_iterator j, j_end = dirs.end();
|
||||
for (j = dirs.begin(); j != j_end; ++j) {
|
||||
unit_map::const_iterator unit_itor = units_->find(adjacent[*j]);
|
||||
if (unit_itor == units_->end()
|
||||
unit_map::const_iterator unit_itor = units.find(adjacent[*j]);
|
||||
if (unit_itor == units.end()
|
||||
|| !unit_itor->matches_filter(*i, unit_itor->get_location(), use_flat_tod)) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -441,7 +441,6 @@ private:
|
|||
config modifications_;
|
||||
|
||||
friend void attack_type::set_specials_context(const map_location& loc, const map_location&, const unit& un, bool) const;
|
||||
const unit_map* units_;
|
||||
|
||||
/** Hold the visibility status cache for a unit, mutable since it's a cache. */
|
||||
mutable std::map<map_location, bool> invisibility_cache_;
|
||||
|
|
|
@ -126,12 +126,12 @@ bool unit::get_ability_bool(const std::string& ability, const map_location& loc)
|
|||
}
|
||||
}
|
||||
|
||||
assert(units_);
|
||||
const unit_map& units = *resources::units;
|
||||
map_location adjacent[6];
|
||||
get_adjacent_tiles(loc,adjacent);
|
||||
for(int i = 0; i != 6; ++i) {
|
||||
const unit_map::const_iterator it = units_->find(adjacent[i]);
|
||||
if (it == units_->end() || it->incapacitated())
|
||||
const unit_map::const_iterator it = units.find(adjacent[i]);
|
||||
if (it == units.end() || it->incapacitated())
|
||||
continue;
|
||||
const config &adj_abilities = it->cfg_.child("abilities");
|
||||
if (!adj_abilities)
|
||||
|
@ -160,12 +160,12 @@ unit_ability_list unit::get_abilities(const std::string& ability, const map_loca
|
|||
}
|
||||
}
|
||||
|
||||
assert(units_ != NULL);
|
||||
const unit_map& units = *resources::units;
|
||||
map_location adjacent[6];
|
||||
get_adjacent_tiles(loc,adjacent);
|
||||
for(int i = 0; i != 6; ++i) {
|
||||
const unit_map::const_iterator it = units_->find(adjacent[i]);
|
||||
if (it == units_->end() || it->incapacitated())
|
||||
const unit_map::const_iterator it = units.find(adjacent[i]);
|
||||
if (it == units.end() || it->incapacitated())
|
||||
continue;
|
||||
const config &adj_abilities = it->cfg_.child("abilities");
|
||||
if (!adj_abilities)
|
||||
|
@ -246,7 +246,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_ && resources::game_map && resources::teams && resources::tod_manager);
|
||||
assert(resources::units && resources::game_map && resources::teams && resources::tod_manager);
|
||||
|
||||
if (const config &afilter = cfg.child("filter"))
|
||||
if (!matches_filter(vconfig(afilter), loc, cache_illuminates(illuminates, ability)))
|
||||
|
@ -254,6 +254,7 @@ bool unit::ability_active(const std::string& ability,const config& cfg,const map
|
|||
|
||||
map_location adjacent[6];
|
||||
get_adjacent_tiles(loc,adjacent);
|
||||
const unit_map& units = *resources::units;
|
||||
|
||||
foreach (const config &i, cfg.child_range("filter_adjacent"))
|
||||
{
|
||||
|
@ -263,8 +264,8 @@ bool unit::ability_active(const std::string& ability,const config& cfg,const map
|
|||
map_location::parse_direction(j);
|
||||
if (index == map_location::NDIRECTIONS)
|
||||
continue;
|
||||
unit_map::const_iterator unit = units_->find(adjacent[index]);
|
||||
if (unit == units_->end())
|
||||
unit_map::const_iterator unit = units.find(adjacent[index]);
|
||||
if (unit == units.end())
|
||||
return false;
|
||||
if (!unit->matches_filter(vconfig(i), unit->get_location(),
|
||||
cache_illuminates(illuminates, ability)))
|
||||
|
@ -280,7 +281,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), *units_);
|
||||
terrain_filter adj_filter(vconfig(i), units);
|
||||
adj_filter.flatten(cache_illuminates(illuminates, ability));
|
||||
if(!adj_filter.match(adjacent[index])) {
|
||||
return false;
|
||||
|
@ -752,11 +753,11 @@ void attack_type::set_specials_context(const map_location& aloc,const map_locati
|
|||
other_attack_ = other_attack;
|
||||
}
|
||||
|
||||
void attack_type::set_specials_context(const map_location& loc, const map_location& dloc, const unit& un, bool attacker) const
|
||||
void attack_type::set_specials_context(const map_location& loc, const map_location& dloc, const unit& /*un*/, bool attacker) const
|
||||
{
|
||||
aloc_ = loc;
|
||||
dloc_ = dloc;
|
||||
unitmap_ = un.units_;
|
||||
unitmap_ = resources::units;
|
||||
attacker_ = attacker;
|
||||
other_attack_ = NULL;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue