Skip to content

Commit

Permalink
Convert uses of resources::units to resources::gameboard->units()
Browse files Browse the repository at this point in the history
This mirrors the similar conversion of resources::teams in 6235e18.
  • Loading branch information
Vultraz committed Dec 2, 2016
1 parent 32f6ef3 commit ed15163
Show file tree
Hide file tree
Showing 55 changed files with 287 additions and 292 deletions.
23 changes: 11 additions & 12 deletions src/actions/advancement.cpp
Expand Up @@ -38,7 +38,6 @@
#include "units/animation_component.hpp"
#include "units/udisplay.hpp"
#include "units/helper.hpp" //number_of_possible_advances
#include "units/map.hpp" //resources::units
#include "whiteboard/manager.hpp"

static lg::log_domain log_engine("engine");
Expand All @@ -58,7 +57,7 @@ namespace
{
int advance_unit_dialog(const map_location &loc)
{
const unit& u = *resources::units->find(loc);
const unit& u = *resources::gameboard->units().find(loc);
std::vector<unit_const_ptr> previews;

for (const std::string& advance : u.advances_to()) {
Expand Down Expand Up @@ -96,8 +95,8 @@ namespace
{
const events::command_disabler cmd_disabler;

unit_map::iterator u = resources::units->find(loc);
if (u == resources::units->end()) {
unit_map::iterator u = resources::gameboard->units().find(loc);
if (u == resources::gameboard->units().end()) {
LOG_DP << "animate_unit_advancement suppressed: invalid unit\n";
return false;
}
Expand Down Expand Up @@ -135,10 +134,10 @@ namespace
::advance_unit(loc, &mod_option, fire_event);
}

u = resources::units->find(loc);
u = resources::gameboard->units().find(loc);
resources::screen->invalidate_unit();

if (animate && u != resources::units->end() && !resources::screen->video().update_locked()) {
if (animate && u != resources::gameboard->units().end() && !resources::screen->video().update_locked()) {
unit_animator animator;
animator.add_animation(&*u, "levelin", u->get_location(), map_location(), 0, true);
animator.start_animations();
Expand Down Expand Up @@ -191,7 +190,7 @@ namespace
//have no effect because get_advancements returns an empty list.
if(ai_advancement_ != nullptr)
{
unit_map::iterator u = resources::units->find(loc_);
unit_map::iterator u = resources::gameboard->units().find(loc_);
const std::vector<std::string>& options = u->advances_to();
const std::vector<std::string>& allowed = ai_advancement_->get_advancements(u);

Expand Down Expand Up @@ -245,7 +244,7 @@ void advance_unit_at(const advance_unit_params& params)
// the 20 is picked rather randomly.
for(int advacment_number = 0; advacment_number < 20; advacment_number++)
{
unit_map::iterator u = resources::units->find(params.loc_);
unit_map::iterator u = resources::gameboard->units().find(params.loc_);
//this implies u.valid()
if(!unit_helper::will_certainly_advance(u)) {
return;
Expand All @@ -256,7 +255,7 @@ void advance_unit_at(const advance_unit_params& params)
LOG_NG << "Firing pre advance event at " << params.loc_ <<".\n";
resources::game_events->pump().fire("pre_advance", params.loc_);
//TODO: maybe use id instead of location here ?.
u = resources::units->find(params.loc_);
u = resources::gameboard->units().find(params.loc_);
if(!unit_helper::will_certainly_advance(u))
{
LOG_NG << "pre advance event aborted advancing.\n";
Expand All @@ -271,7 +270,7 @@ void advance_unit_at(const advance_unit_params& params)
bool result = animate_unit_advancement(params.loc_, selected["value"], params.fire_events_, params.animate_);

DBG_NG << "animate_unit_advancement result = " << result << std::endl;
u = resources::units->find(params.loc_);
u = resources::gameboard->units().find(params.loc_);
// level 10 unit gives 80 XP and the highest mainline is level 5
if (u.valid() && u->experience() > 80)
{
Expand Down Expand Up @@ -315,7 +314,7 @@ unit_ptr get_amla_unit(const unit &u, const config &mod_option)

void advance_unit(map_location loc, const advancement_option &advance_to, bool fire_event)
{
unit_map::unit_iterator u = resources::units->find(loc);
unit_map::unit_iterator u = resources::gameboard->units().find(loc);
if(!u.valid()) {
return;
}
Expand Down Expand Up @@ -353,7 +352,7 @@ void advance_unit(map_location loc, const advancement_option &advance_to, bool f
preferences::encountered_units().insert(new_unit->type_id());
LOG_CF << "Added '" << new_unit->type_id() << "' to the encountered units.\n";
}
u = resources::units->replace(loc, *new_unit).first;
u = resources::gameboard->units().replace(loc, *new_unit).first;

// Update fog/shroud.
actions::shroud_clearer clearer;
Expand Down
14 changes: 7 additions & 7 deletions src/actions/attack.cpp
Expand Up @@ -809,9 +809,9 @@ namespace {
update_att_fog_(false),
update_def_fog_(false),
update_minimap_(false),
a_(attacker, attack_with, *resources::units),
d_(defender, defend_with, *resources::units),
units_(*resources::units),
a_(attacker, attack_with, resources::gameboard->units()),
d_(defender, defend_with, resources::gameboard->units()),
units_(resources::gameboard->units()),
errbuf_(),
update_display_(update_display),
OOS_error_(false)
Expand Down Expand Up @@ -1404,13 +1404,13 @@ void attack_unit_and_advance(const map_location &attacker, const map_location &d
const ai::unit_advancements_aspect& ai_advancement)
{
attack_unit(attacker, defender, attack_with, defend_with, update_display);
unit_map::const_iterator atku = resources::units->find(attacker);
if (atku != resources::units->end()) {
unit_map::const_iterator atku = resources::gameboard->units().find(attacker);
if (atku != resources::gameboard->units().end()) {
advance_unit_at(advance_unit_params(attacker).ai_advancements(ai_advancement));
}

unit_map::const_iterator defu = resources::units->find(defender);
if (defu != resources::units->end()) {
unit_map::const_iterator defu = resources::gameboard->units().find(defender);
if (defu != resources::gameboard->units().end()) {
advance_unit_at(advance_unit_params(defender).ai_advancements(ai_advancement));
}
}
Expand Down
34 changes: 17 additions & 17 deletions src/actions/create.cpp
Expand Up @@ -65,16 +65,16 @@ const std::set<std::string> get_recruits(int side, const map_location &recruit_l

std::set<std::string> local_result;
std::set<std::string> global_result;
unit_map::const_iterator u = resources::units->begin(),
u_end = resources::units->end();
unit_map::const_iterator u = resources::gameboard->units().begin(),
u_end = resources::gameboard->units().end();

bool leader_in_place = false;
bool allow_local = resources::gameboard->map().is_castle(recruit_loc);


// Check for a leader at recruit_loc (means we are recruiting from there,
// rather than to there).
unit_map::const_iterator find_it = resources::units->find(recruit_loc);
unit_map::const_iterator find_it = resources::gameboard->units().find(recruit_loc);
if ( find_it != u_end ) {
if ( find_it->can_recruit() && find_it->side() == side &&
resources::gameboard->map().is_keep(recruit_loc) )
Expand Down Expand Up @@ -176,8 +176,8 @@ std::vector<unit_const_ptr > get_recalls(int side, const map_location &recall_lo

// Check for a leader at recall_loc (means we are recalling from there,
// rather than to there).
const unit_map::const_iterator find_it = resources::units->find(recall_loc);
if ( find_it != resources::units->end() ) {
const unit_map::const_iterator find_it = resources::gameboard->units().find(recall_loc);
if ( find_it != resources::gameboard->units().end() ) {
if ( find_it->can_recruit() && find_it->side() == side &&
resources::gameboard->map().is_keep(recall_loc) )
{
Expand All @@ -195,8 +195,8 @@ std::vector<unit_const_ptr > get_recalls(int side, const map_location &recall_lo

if ( allow_local )
{
unit_map::const_iterator u = resources::units->begin(),
u_end = resources::units->end();
unit_map::const_iterator u = resources::gameboard->units().begin(),
u_end = resources::gameboard->units().end();
std::set<size_t> valid_local_recalls;

for(; u != u_end; ++u) {
Expand All @@ -217,7 +217,7 @@ std::vector<unit_const_ptr > get_recalls(int side, const map_location &recall_lo
{
std::set<size_t> valid_local_recalls;

for(auto u = resources::units->begin(); u != resources::units->end(); ++u) {
for(auto u = resources::gameboard->units().begin(); u != resources::gameboard->units().end(); ++u) {
//We only consider leaders on our side.
if(!u->can_recruit() || u->side() != side) {
continue;
Expand Down Expand Up @@ -279,14 +279,14 @@ RECRUIT_CHECK check_recall_location(const int side, map_location& recall_locatio
map_location& recall_from,
const unit &unit_recall)
{
const unit_map & units = *resources::units;
const unit_map & units = resources::gameboard->units();
const unit_map::const_iterator u_end = units.end();

map_location check_location = recall_location;
map_location alternative; // Set by check_unit_recall_location().

// If the specified location is occupied, proceed as if no location was specified.
if ( resources::units->count(recall_location) != 0 )
if ( resources::gameboard->units().count(recall_location) != 0 )
check_location = map_location::null_location();

// If the check location is not valid, we will never get an "OK" result.
Expand Down Expand Up @@ -409,15 +409,15 @@ RECRUIT_CHECK check_recruit_location(const int side, map_location &recruit_locat
map_location& recruited_from,
const std::string& unit_type)
{
const unit_map & units = *resources::units;
const unit_map & units = resources::gameboard->units();
const unit_map::const_iterator u_end = units.end();

map_location check_location = recruit_location;
std::string check_type = unit_type;
map_location alternative; // Set by check_unit_recruit_location().

// If the specified location is occupied, proceed as if no location was specified.
if ( resources::units->count(recruit_location) != 0 )
if ( resources::gameboard->units().count(recruit_location) != 0 )
check_location = map_location::null_location();

// If the specified unit type is in the team's recruit list, there is no
Expand Down Expand Up @@ -538,7 +538,7 @@ namespace { // Helpers for place_recruit()
const map_location & find_recruit_leader(int side,
const map_location &recruit_location, const map_location &recruited_from)
{
const unit_map & units = *resources::units;
const unit_map & units = resources::gameboard->units();

// See if the preferred location is an option.
unit_map::const_iterator leader = units.find(recruited_from);
Expand Down Expand Up @@ -566,8 +566,8 @@ namespace { // Helpers for place_recruit()
{
if ( !un_it.valid() ) {
// Maybe WML provided a replacement?
un_it = resources::units->find(current_loc);
if ( un_it == resources::units->end() )
un_it = resources::gameboard->units().find(current_loc);
if ( un_it == resources::gameboard->units().end() )
// The unit is gone.
return false;
}
Expand All @@ -580,7 +580,7 @@ namespace { // Helpers for place_recruit()
{
// Find closest enemy and turn towards it (level 2s count more than level 1s, etc.)
const gamemap *map = & resources::gameboard->map();
const unit_map & units = *resources::units;
const unit_map & units = resources::gameboard->units();
unit_map::const_iterator unit_itor;
map_location min_loc;
int min_dist = INT_MAX;
Expand Down Expand Up @@ -629,7 +629,7 @@ place_recruit_result place_recruit(unit_ptr u, const map_location &recruit_locat
find_recruit_leader(u->side(), recruit_location, recruited_from);
u->set_location(recruit_location);
// Add the unit to the board.
std::pair<unit_map::iterator, bool> add_result = resources::units->insert(u);
std::pair<unit_map::iterator, bool> add_result = resources::gameboard->units().insert(u);
assert(add_result.second);
unit_map::iterator & new_unit_itor = add_result.first;
map_location current_loc = recruit_location;
Expand Down
6 changes: 3 additions & 3 deletions src/actions/heal.cpp
Expand Up @@ -83,7 +83,7 @@ namespace {
std::vector<unit *> & healers)
{
const std::vector<team> &teams = resources::gameboard->teams();
unit_map &units = *resources::units;
unit_map &units = resources::gameboard->units();

POISON_STATUS curing = POISON_NORMAL;

Expand Down Expand Up @@ -178,7 +178,7 @@ namespace {
*/
int heal_amount(int side, const unit & patient, std::vector<unit *> & healers)
{
unit_map &units = *resources::units;
unit_map &units = resources::gameboard->units();

int healing = 0;
int harming = 0;
Expand Down Expand Up @@ -296,7 +296,7 @@ void calculate_healing(int side, bool update_display)
std::list<heal_unit> unit_list;

// We look for all allied units, then we see if our healer is near them.
for (unit &patient : *resources::units) {
for (unit &patient : resources::gameboard->units()) {

if ( patient.get_state("unhealable") || patient.incapacitated() ) {
if ( patient.side() == side )
Expand Down
26 changes: 13 additions & 13 deletions src/actions/move.cpp
Expand Up @@ -360,8 +360,8 @@ namespace { // Private helpers for move_unit()
obstructed_(full_end_),
real_end_(begin_),
// Unit information:
move_it_(resources::units->find(*begin_)),
orig_side_(( assert(move_it_ != resources::units->end()),
move_it_(resources::gameboard->units().find(*begin_)),
orig_side_(( assert(move_it_ != resources::gameboard->units().end()),
move_it_->side() )),
orig_moves_(move_it_->movement_left()),
orig_dir_(move_it_->facing()),
Expand Down Expand Up @@ -420,7 +420,7 @@ namespace { // Private helpers for move_unit()
*/
inline void unit_mover::check_for_ambushers(const map_location & hex)
{
const unit_map &units = *resources::units;
const unit_map &units = resources::gameboard->units();

// Need to check each adjacent hex for hidden enemies.
map_location adjacent[6];
Expand Down Expand Up @@ -451,10 +451,10 @@ namespace { // Private helpers for move_unit()
inline bool unit_mover::check_for_obstructing_unit(const map_location & hex,
const map_location & prev_hex)
{
const unit_map::const_iterator blocking_unit = resources::units->find(hex);
const unit_map::const_iterator blocking_unit = resources::gameboard->units().find(hex);

// If no unit, then the path is not obstructed.
if ( blocking_unit == resources::units->end() )
if ( blocking_unit == resources::gameboard->units().end() )
return false;

// Check for units blocking a teleport exit. This can now only happen
Expand Down Expand Up @@ -527,7 +527,7 @@ namespace { // Private helpers for move_unit()
// Attempt actually moving.
// (Fails if *step_to is occupied).
std::pair<unit_map::iterator, bool> move_result =
resources::units->move(*move_loc_, *step_to);
resources::gameboard->units().move(*move_loc_, *step_to);
if ( move_result.second )
{
// Update the moving unit.
Expand Down Expand Up @@ -632,7 +632,7 @@ namespace { // Private helpers for move_unit()
*/
inline void unit_mover::validate_ambushers()
{
const unit_map &units = *resources::units;
const unit_map &units = resources::gameboard->units();

// Loop through the previously-detected ambushers.
size_t i = 0;
Expand Down Expand Up @@ -816,8 +816,8 @@ namespace { // Private helpers for move_unit()
bool unit_mover::post_wml(const route_iterator & step)
{
// Re-find the moving unit.
move_it_ = resources::units->find(*move_loc_);
const bool found = move_it_ != resources::units->end();
move_it_ = resources::gameboard->units().find(*move_loc_);
const bool found = move_it_ != resources::gameboard->units().end();

// Update the current unit data.
current_side_ = found ? move_it_->side() : orig_side_;
Expand Down Expand Up @@ -889,7 +889,7 @@ namespace { // Private helpers for move_unit()
void unit_mover::reveal_ambusher(const map_location & hex, bool update_alert)
{
// Convenient alias:
unit_map &units = *resources::units;
unit_map &units = resources::gameboard->units();
game_display &disp = *resources::screen;

// Find the unit at the indicated location.
Expand Down Expand Up @@ -1055,7 +1055,7 @@ namespace { // Private helpers for move_unit()
if ( ambushed_ || blocked() )
reveal_ambushers();
else if ( teleport_failed_ && spectator_ )
spectator_->set_failed_teleport(resources::units->find(*obstructed_));
spectator_->set_failed_teleport(resources::gameboard->units().find(*obstructed_));
unit::clear_status_caches();

if ( move_it_.valid() ) {
Expand Down Expand Up @@ -1266,10 +1266,10 @@ size_t move_unit_and_record(const std::vector<map_location> &steps,
return 0;
}
//if we have no fog activated then we always skip sighted
if(resources::units->find(steps.front()) != resources::units->end())
if(resources::gameboard->units().find(steps.front()) != resources::gameboard->units().end())
{
const team &current_team = resources::gameboard->teams()[
resources::units->find(steps.front())->side() - 1];
resources::gameboard->units().find(steps.front())->side() - 1];
continued_move |= !current_team.fog_or_shroud();
}
const bool skip_ally_sighted = !preferences::interrupt_when_ally_sighted();
Expand Down
9 changes: 5 additions & 4 deletions src/actions/undo_action.cpp
@@ -1,4 +1,5 @@
#include "actions/undo_action.hpp"
#include "game_board.hpp"
#include "scripting/game_lua_kernel.hpp"
#include "resources.hpp"
#include "variable.hpp" // vconfig
Expand Down Expand Up @@ -73,8 +74,8 @@ undo_action::undo_action(const config& cfg)

namespace {
unit_ptr get_unit(size_t uid, const std::string& id) {
assert(resources::units);
auto iter = resources::units->find(uid);
assert(resources::gameboard);
auto iter = resources::gameboard->units().find(uid);
if(!iter.valid() || iter->id() != id) {
return nullptr;
}
Expand All @@ -94,10 +95,10 @@ namespace {

std::unique_ptr<scoped_xy_unit> u1, u2;
if(unit_ptr who = get_unit(e.uid1, e.id1)) {
u1.reset(new scoped_xy_unit("unit", who->get_location(), *resources::units));
u1.reset(new scoped_xy_unit("unit", who->get_location(), resources::gameboard->units()));
}
if(unit_ptr who = get_unit(e.uid2, e.id2)) {
u2.reset(new scoped_xy_unit("unit", who->get_location(), *resources::units));
u2.reset(new scoped_xy_unit("unit", who->get_location(), resources::gameboard->units()));
}

scoped_weapon_info w1("weapon", e.data.child("first"));
Expand Down

0 comments on commit ed15163

Please sign in to comment.