Convert uses of resources::units to resources::gameboard->units()

This mirrors the similar conversion of resources::teams in 6235e18bbd.
This commit is contained in:
Charles Dang 2016-12-02 11:58:38 +11:00
parent 32f6ef3bea
commit ed15163b95
55 changed files with 287 additions and 292 deletions

View file

@ -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");
@ -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()) {
@ -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;
}
@ -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();
@ -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);
@ -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;
@ -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";
@ -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)
{
@ -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;
}
@ -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;

View file

@ -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)
@ -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));
}
}

View file

@ -65,8 +65,8 @@ 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);
@ -74,7 +74,7 @@ const std::set<std::string> get_recruits(int side, const map_location &recruit_l
// 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) )
@ -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) )
{
@ -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) {
@ -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;
@ -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.
@ -409,7 +409,7 @@ 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;
@ -417,7 +417,7 @@ RECRUIT_CHECK check_recruit_location(const int side, map_location &recruit_locat
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
@ -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);
@ -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;
}
@ -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;
@ -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;

View file

@ -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;
@ -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;
@ -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 )

View file

@ -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()),
@ -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];
@ -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
@ -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.
@ -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;
@ -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_;
@ -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.
@ -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() ) {
@ -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();

View file

@ -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
@ -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;
}
@ -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"));

View file

@ -42,7 +42,7 @@ void move_action::write(config & cfg) const
bool move_action::undo(int)
{
game_display & gui = *resources::screen;
unit_map & units = *resources::units;
unit_map & units = resources::gameboard->units();
// Copy some of our stored data.
const int saved_moves = starting_moves;
@ -86,7 +86,7 @@ bool move_action::undo(int)
bool move_action::redo(int)
{
game_display & gui = *resources::screen;
unit_map & units = *resources::units;
unit_map & units = resources::gameboard->units();
// Check units.
unit_map::iterator u = units.find(route.front());

View file

@ -39,7 +39,7 @@ void recall_action::write(config & cfg) const
bool recall_action::undo(int side)
{
game_display & gui = *resources::screen;
unit_map & units = *resources::units;
unit_map & units = resources::gameboard->units();
team &current_team = resources::gameboard->teams()[side-1];
const map_location & recall_loc = route.front();

View file

@ -40,7 +40,7 @@ void recruit_action::write(config & cfg) const
bool recruit_action::undo(int side)
{
game_display & gui = *resources::screen;
unit_map & units = *resources::units;
unit_map & units = resources::gameboard->units();
team &current_team = resources::gameboard->teams()[side-1];
const map_location & recruit_loc = route.front();

View file

@ -56,7 +56,7 @@ static void create_jamming_map(std::map<map_location, int> & jamming,
jamming.clear();
// Build the map.
for (const unit &u : *resources::units)
for (const unit &u : resources::gameboard->units())
{
if ( u.jamming() < 1 || !view_team.is_enemy(u.side()) )
continue;
@ -433,8 +433,8 @@ bool shroud_clearer::clear_unit(const map_location &view_loc, team &view_team,
const clearer_info &viewer, bool instant)
{
// Locate the unit in question.
unit_map::const_iterator find_it = resources::units->find(viewer.underlying_id);
const map_location & real_loc = find_it == resources::units->end() ?
unit_map::const_iterator find_it = resources::gameboard->units().find(viewer.underlying_id);
const map_location & real_loc = find_it == resources::gameboard->units().end() ?
map_location::null_location() :
find_it->get_location();
@ -547,7 +547,7 @@ void shroud_clearer::drop_events()
*/
bool shroud_clearer::fire_events()
{
const unit_map & units = *resources::units;
const unit_map & units = resources::gameboard->units();
// Possible/probable quick abort.
if ( sightings_.empty() )
@ -659,7 +659,7 @@ bool actor_sighted(const unit & target, const std::vector<int> * cache)
// Look for units that can be used as the second unit in sighted events.
std::vector<const unit *> second_units(teams_size, nullptr);
std::vector<size_t> distances(teams_size, UINT_MAX);
for (const unit & viewer : *resources::units) {
for (const unit & viewer : resources::gameboard->units()) {
const size_t index = viewer.side() - 1;
// Does viewer belong to a team for which we still need a unit?
if ( needs_event[index] && distances[index] != 0 ) {
@ -713,7 +713,7 @@ void recalculate_fog(int side)
// Exclude currently seen units from sighted events.
std::set<map_location> visible_locs;
for (const unit &u : *resources::units) {
for (const unit &u : resources::gameboard->units()) {
const map_location & u_location = u.get_location();
if ( !tm.fogged(u_location) )
@ -726,7 +726,7 @@ void recalculate_fog(int side)
resources::screen->invalidate_all();
shroud_clearer clearer;
for (const unit &u : *resources::units)
for (const unit &u : resources::gameboard->units())
{
if ( u.side() == side )
clearer.clear_unit(u.get_location(), u, tm, &visible_locs);
@ -762,7 +762,7 @@ bool clear_shroud(int side, bool reset_fog, bool fire_events)
bool result = false;
shroud_clearer clearer;
for (const unit &u : *resources::units)
for (const unit &u : resources::gameboard->units())
{
if ( u.side() == side )
result |= clearer.clear_unit(u.get_location(), u, tm);

View file

@ -178,17 +178,17 @@ attack_result::attack_result( side_number side, const map_location& attacker_loc
void attack_result::do_check_before()
{
LOG_AI_ACTIONS << " check_before " << *this << std::endl;
const unit_map::const_iterator attacker = resources::units->find(attacker_loc_);
const unit_map::const_iterator defender = resources::units->find(defender_loc_);
const unit_map::const_iterator attacker = resources::gameboard->units().find(attacker_loc_);
const unit_map::const_iterator defender = resources::gameboard->units().find(defender_loc_);
if(attacker==resources::units->end())
if(attacker==resources::gameboard->units().end())
{
LOG_AI_ACTIONS << "attempt to attack without attacker\n";
set_error(E_EMPTY_ATTACKER);
return;
}
if (defender==resources::units->end())
if (defender==resources::gameboard->units().end())
{
LOG_AI_ACTIONS << "attempt to attack without defender\n";
set_error(E_EMPTY_DEFENDER);
@ -263,7 +263,7 @@ void attack_result::do_execute()
// Stop the user from issuing any commands while the unit is attacking
const events::command_disabler disable_commands;
//@note: yes, this is a decision done here. It's that way because we want to allow a simpler attack 'with whatever weapon is considered best', and because we want to allow the defender to pick it's weapon. That's why aggression is needed. a cleaner solution is needed.
battle_context bc(*resources::units, attacker_loc_,
battle_context bc(resources::gameboard->units(), attacker_loc_,
defender_loc_, attacker_weapon_, -1, aggression_);
int attacker_weapon = bc.get_attacker_stats().attack_num;
@ -274,8 +274,8 @@ void attack_result::do_execute()
return;
}
const unit_map::const_iterator a_ = resources::units->find(attacker_loc_);
const unit_map::const_iterator d_ = resources::units->find(defender_loc_);
const unit_map::const_iterator a_ = resources::gameboard->units().find(attacker_loc_);
const unit_map::const_iterator d_ = resources::gameboard->units().find(defender_loc_);
if(resources::simulation_){
bool gamestate_changed = simulated_attack(attacker_loc_, defender_loc_, bc.get_attacker_combatant().average_hp(), bc.get_defender_combatant().average_hp());
@ -340,8 +340,8 @@ move_result::move_result(side_number side, const map_location& from,
const unit *move_result::get_unit()
{
unit_map::const_iterator un = resources::units->find(from_);
if (un==resources::units->end()){
unit_map::const_iterator un = resources::gameboard->units().find(from_);
if (un==resources::gameboard->units().end()){
set_error(E_NO_UNIT);
return nullptr;
}
@ -456,7 +456,7 @@ void move_result::do_execute()
assert(remove_movement_);
}
unit_map::const_iterator un = resources::units->find(unit_location_);
unit_map::const_iterator un = resources::gameboard->units().find(unit_location_);
if(remove_movement_ && un->movement_left() > 0 && unit_location_ == to_){
gamestate_changed = simulated_stopunit(unit_location_, true, false);
}
@ -466,8 +466,8 @@ void move_result::do_execute()
return;
}
::actions::move_unit_spectator move_spectator(*resources::units);
move_spectator.set_unit(resources::units->find(from_));
::actions::move_unit_spectator move_spectator(resources::gameboard->units());
move_spectator.set_unit(resources::gameboard->units().find(from_));
if (from_ != to_) {
size_t num_steps = ::actions::move_unit_and_record(
@ -605,8 +605,8 @@ void recall_result::do_check_after()
return;
}
unit_map::const_iterator unit = resources::units->find(recall_location_);
if (unit==resources::units->end()){
unit_map::const_iterator unit = resources::gameboard->units().find(recall_location_);
if (unit==resources::gameboard->units().end()){
set_error(AI_ACTION_FAILURE);
return;
}
@ -757,8 +757,8 @@ void recruit_result::do_check_after()
return;
}
unit_map::const_iterator unit = resources::units->find(recruit_location_);
if (unit==resources::units->end()) {
unit_map::const_iterator unit = resources::gameboard->units().find(recruit_location_);
if (unit==resources::gameboard->units().end()) {
set_error(AI_ACTION_FAILURE);
return;
}
@ -831,8 +831,8 @@ stopunit_result::stopunit_result( side_number side, const map_location& unit_loc
const unit *stopunit_result::get_unit()
{
unit_map::const_iterator un = resources::units->find(unit_location_);
if (un==resources::units->end()){
unit_map::const_iterator un = resources::gameboard->units().find(unit_location_);
if (un==resources::gameboard->units().end()){
set_error(E_NO_UNIT);
return nullptr;
}
@ -859,8 +859,8 @@ void stopunit_result::do_check_before()
void stopunit_result::do_check_after()
{
unit_map::const_iterator un = resources::units->find(unit_location_);
if (un==resources::units->end()){
unit_map::const_iterator un = resources::gameboard->units().find(unit_location_);
if (un==resources::gameboard->units().end()){
set_error(AI_ACTION_FAILURE);
return;
}
@ -897,7 +897,7 @@ void stopunit_result::do_execute()
{
LOG_AI_ACTIONS << "start of execution of: " << *this << std::endl;
assert(is_success());
unit_map::iterator un = resources::units->find(unit_location_);
unit_map::iterator un = resources::gameboard->units().find(unit_location_);
if(resources::simulation_){
bool gamestate_changed = simulated_stopunit(unit_location_, remove_movement_, remove_attacks_);

View file

@ -147,7 +147,7 @@ void target_unit_goal::add_targets(std::back_insert_iterator< std::vector< targe
//find the enemy leaders and explicit targets
const unit_filter ufilt(vconfig(criteria), resources::filter_con);
for (const unit &u : *resources::units) {
for (const unit &u : resources::gameboard->units()) {
if (ufilt( u )) {
LOG_AI_GOAL << "found explicit target unit at ... " << u.get_location() << " with value: " << value() << "\n";
*target_list = target(u.get_location(), value(), target::TYPE::EXPLICIT);
@ -258,7 +258,7 @@ void protect_goal::add_targets(std::back_insert_iterator< std::vector< target >
DBG_AI_GOAL << "side " << get_side() << ": "<< goal_type << " goal with criteria" << std::endl << cfg_.child("criteria") << std::endl;
}
unit_map &units = *resources::units;
unit_map &units = resources::gameboard->units();
std::set<map_location> items;
if (protect_unit_) {

View file

@ -110,7 +110,7 @@ team& readwrite_context_impl::current_team_w()
}
attack_result_ptr readwrite_context_impl::execute_attack_action(const map_location& attacker_loc, const map_location& defender_loc, int attacker_weapon){
unit_map::iterator i = resources::units->find(attacker_loc);
unit_map::iterator i = resources::gameboard->units().find(attacker_loc);
double m_aggression = i.valid() && i->can_recruit() ? get_leader_aggression() : get_aggression();
const unit_advancements_aspect& m_advancements = get_advancements();
return actions::execute_attack_action(get_side(),true,attacker_loc,defender_loc,attacker_weapon, m_aggression, m_advancements);
@ -118,7 +118,7 @@ attack_result_ptr readwrite_context_impl::execute_attack_action(const map_locati
attack_result_ptr readonly_context_impl::check_attack_action(const map_location& attacker_loc, const map_location& defender_loc, int attacker_weapon){
unit_map::iterator i = resources::units->find(attacker_loc);
unit_map::iterator i = resources::gameboard->units().find(attacker_loc);
double m_aggression = i.valid() && i->can_recruit() ? get_leader_aggression() : get_aggression();
const unit_advancements_aspect& m_advancements = get_advancements();
return actions::execute_attack_action(get_side(),false,attacker_loc,defender_loc,attacker_weapon, m_aggression, m_advancements);
@ -352,7 +352,7 @@ void readonly_context_impl::calculate_possible_moves(std::map<map_location,pathf
move_map& dstsrc, bool enemy, bool assume_full_movement,
const terrain_filter* remove_destinations) const
{
calculate_moves(*resources::units,res,srcdst,dstsrc,enemy,assume_full_movement,remove_destinations);
calculate_moves(resources::gameboard->units(),res,srcdst,dstsrc,enemy,assume_full_movement,remove_destinations);
}
void readonly_context_impl::calculate_moves(const unit_map& units, std::map<map_location,pathfind::paths>& res, move_map& srcdst,
@ -393,10 +393,10 @@ void readonly_context_impl::calculate_moves(const unit_map& units, std::map<map_
/**
* @todo This is where support for a speculative unit map is incomplete.
* There are several places (deep) within the paths constructor
* where *resources::units is assumed to be the unit map. Rather
* where resources::gameboard->units() is assumed to be the unit map. Rather
* than introduce a new parameter to numerous functions, a better
* solution may be for the creator of the speculative map (if one
* is used in the future) to cause resources::units to point to
* is used in the future) to cause resources::gameboard->units() to point to
* that map (and restore the "real" pointer when the speculating
* is completed). If that approach is adopted, calculate_moves()
* and calculate_possible_moves() become redundant, and one of
@ -443,7 +443,7 @@ void readonly_context_impl::calculate_moves(const unit_map& units, std::map<map_
continue;
}
if(src != dst && (resources::gameboard->find_visible_unit(dst, current_team()) == resources::units->end()) ) {
if(src != dst && (resources::gameboard->find_visible_unit(dst, current_team()) == resources::gameboard->units().end()) ) {
srcdst.insert(std::pair<map_location,map_location>(src,dst));
dstsrc.insert(std::pair<map_location,map_location>(dst,src));
}
@ -478,8 +478,8 @@ void readonly_context_impl::add_facet(const std::string &id, const config &cfg)
const defensive_position& readonly_context_impl::best_defensive_position(const map_location& loc,
const move_map& dstsrc, const move_map& srcdst, const move_map& enemy_dstsrc) const
{
const unit_map::const_iterator itor = resources::units->find(loc);
if(itor == resources::units->end()) {
const unit_map::const_iterator itor = resources::gameboard->units().find(loc);
if(itor == resources::gameboard->units().end()) {
static defensive_position pos;
pos.chance_to_hit = 0;
pos.vulnerability = pos.support = 0;
@ -1004,8 +1004,8 @@ const std::set<map_location>& keeps_cache::get()
bool readonly_context_impl::leader_can_reach_keep() const
{
const unit_map::iterator leader = resources::units->find_leader(get_side());
if(leader == resources::units->end() || leader->incapacitated()) {
const unit_map::iterator leader = resources::gameboard->units().find_leader(get_side());
if(leader == resources::gameboard->units().end() || leader->incapacitated()) {
return false;
}
@ -1066,7 +1066,7 @@ double readonly_context_impl::power_projection(const map_location& loc, const mo
get_adjacent_tiles(loc,locs);
const gamemap& map_ = resources::gameboard->map();
unit_map& units_ = *resources::units;
unit_map& units_ = resources::gameboard->units();
int res = 0;
@ -1174,7 +1174,7 @@ void readonly_context_impl::recalculate_move_maps() const
srcdst_ = move_map();
calculate_possible_moves(possible_moves_,srcdst_,dstsrc_,false,false,&get_avoid());
if (get_passive_leader()||get_passive_leader_shares_keep()) {
unit_map::iterator i = resources::units->find_leader(get_side());
unit_map::iterator i = resources::gameboard->units().find_leader(get_side());
if (i.valid()) {
map_location loc = i->get_location();
srcdst_.erase(loc);
@ -1246,7 +1246,7 @@ const map_location& readonly_context_impl::suitable_keep(const map_location& lea
if (keeps().find(loc)!=keeps().end()){
const int move_left_at_loc = dest.move_left;
if (resources::units->count(loc) == 0) {
if (resources::gameboard->units().count(loc) == 0) {
if ((*best_free_keep==map_location::null_location())||(move_left_at_loc>move_left_at_best_free_keep)){
best_free_keep = &loc;
move_left_at_best_free_keep = move_left_at_loc;

View file

@ -78,7 +78,7 @@ std::shared_ptr<attacks_vector> aspect_attacks_base::analyze_targets() const
const move_map& enemy_dstsrc = get_enemy_dstsrc();
std::shared_ptr<attacks_vector> res(new attacks_vector());
unit_map& units_ = *resources::units;
unit_map& units_ = resources::gameboard->units();
std::vector<map_location> unit_locs;
for(unit_map::const_iterator i = units_.begin(); i != units_.end(); ++i) {
@ -146,7 +146,7 @@ void aspect_attacks_base::do_attack_analysis(
return;
}
const gamemap &map_ = resources::gameboard->map();
unit_map &units_ = *resources::units;
unit_map &units_ = resources::gameboard->units();
std::vector<team> &teams_ = resources::gameboard->teams();

View file

@ -66,7 +66,7 @@ double goto_phase::evaluate()
{
// Execute goto-movements - first collect gotos in a list
std::vector<map_location> gotos;
unit_map &units_ = *resources::units;
unit_map &units_ = resources::gameboard->units();
const gamemap &map_ = resources::gameboard->map();
for(unit_map::iterator ui = units_.begin(); ui != units_.end(); ++ui) {
@ -280,7 +280,7 @@ double move_leader_to_goals_phase::evaluate()
return BAD_SCORE;
}
const unit_map::iterator leader = resources::units->find_leader(get_side());
const unit_map::iterator leader = resources::gameboard->units().find_leader(get_side());
if (!leader.valid() || leader->incapacitated()) {
WRN_AI_TESTING_AI_DEFAULT << "Leader not found" << std::endl;
return BAD_SCORE;
@ -387,7 +387,7 @@ double move_leader_to_keep_phase::evaluate()
// 6. Save move_ for execution
// 1.
const unit_map &units_ = *resources::units;
const unit_map &units_ = resources::gameboard->units();
const std::vector<unit_map::const_iterator> leaders = units_.find_leaders(get_side());
if (leaders.empty()) {
return BAD_SCORE;
@ -527,7 +527,7 @@ get_villages_phase::~get_villages_phase()
double get_villages_phase::evaluate()
{
moves_.clear();
unit_map::const_iterator leader = resources::units->find_leader(get_side());
unit_map::const_iterator leader = resources::gameboard->units().find_leader(get_side());
get_villages(get_dstsrc(),get_enemy_dstsrc(),leader);
if (!moves_.empty()) {
return get_score();
@ -538,7 +538,7 @@ double get_villages_phase::evaluate()
void get_villages_phase::execute()
{
unit_map &units_ = *resources::units;
unit_map &units_ = resources::gameboard->units();
unit_map::const_iterator leader = units_.find_leader(get_side());
// Move all the units to get villages, however move the leader last,
// so that the castle will be cleared if it wants to stop to recruit along the way.
@ -592,7 +592,7 @@ void get_villages_phase::get_villages(
unit_map::const_iterator &leader)
{
DBG_AI_TESTING_AI_DEFAULT << "deciding which villages we want...\n";
unit_map &units_ = *resources::units;
unit_map &units_ = resources::gameboard->units();
const int ticks = SDL_GetTicks();
best_leader_loc_ = map_location::null_location();
if(leader != units_.end()) {
@ -723,8 +723,8 @@ void get_villages_phase::find_villages(
vulnerability.insert(std::pair<map_location,double>(current_loc,threat));
}
const unit_map::const_iterator u = resources::units->find(j->second);
if (u == resources::units->end() || u->get_state("guardian")) {
const unit_map::const_iterator u = resources::gameboard->units().find(j->second);
if (u == resources::gameboard->units().end() || u->get_state("guardian")) {
continue;
}
@ -1318,7 +1318,7 @@ get_healing_phase::~get_healing_phase()
double get_healing_phase::evaluate()
{
// Find units in need of healing.
unit_map &units_ = *resources::units;
unit_map &units_ = resources::gameboard->units();
unit_map::iterator u_it = units_.begin();
for(; u_it != units_.end(); ++u_it) {
unit &u = *u_it;
@ -1396,7 +1396,7 @@ double retreat_phase::evaluate()
// Get versions of the move map that assume that all units are at full movement
const unit_map& units_ = *resources::units;
const unit_map& units_ = resources::gameboard->units();
//unit_map::const_iterator leader = units_.find_leader(get_side());
std::vector<unit_map::const_iterator> leaders = units_.find_leaders(get_side());
@ -1591,7 +1591,7 @@ double leader_shares_keep_phase::evaluate()
bool allied_leaders_available = false;
for(team &tmp_team : resources::gameboard->teams()) {
if(!current_team().is_enemy(tmp_team.side())){
std::vector<unit_map::unit_iterator> allied_leaders = resources::units->find_leaders(get_side());
std::vector<unit_map::unit_iterator> allied_leaders = resources::gameboard->units().find_leaders(get_side());
if (!allied_leaders.empty()){
allied_leaders_available = true;
break;
@ -1607,13 +1607,13 @@ double leader_shares_keep_phase::evaluate()
void leader_shares_keep_phase::execute()
{
//get all AI leaders
std::vector<unit_map::unit_iterator> ai_leaders = resources::units->find_leaders(get_side());
std::vector<unit_map::unit_iterator> ai_leaders = resources::gameboard->units().find_leaders(get_side());
//calculate all possible moves (AI + allies)
typedef std::map<map_location, pathfind::paths> path_map;
path_map possible_moves;
move_map friends_srcdst, friends_dstsrc;
calculate_moves(*resources::units, possible_moves, friends_srcdst, friends_dstsrc, false, true);
calculate_moves(resources::gameboard->units(), possible_moves, friends_srcdst, friends_dstsrc, false, true);
//check for each ai leader if he should move away from his keep
for (unit_map::unit_iterator &ai_leader : ai_leaders) {
@ -1630,9 +1630,9 @@ void leader_shares_keep_phase::execute()
//for each leader, check if he's allied and can reach our keep
for(path_map::const_iterator i = possible_moves.begin(); i != possible_moves.end(); ++i){
const unit_map::const_iterator itor = resources::units->find(i->first);
const unit_map::const_iterator itor = resources::gameboard->units().find(i->first);
team &leader_team = resources::gameboard->teams()[itor->side() - 1];
if(itor != resources::units->end() && itor->can_recruit() && itor->side() != get_side() && (leader_team.total_income() + leader_team.gold() > leader_team.minimum_recruit_price())){
if(itor != resources::gameboard->units().end() && itor->can_recruit() && itor->side() != get_side() && (leader_team.total_income() + leader_team.gold() > leader_team.minimum_recruit_price())){
pathfind::paths::dest_vect::const_iterator tokeep = i->second.destinations.find(keep);
if(tokeep != i->second.destinations.end()){
friend_can_reach_keep = true;

View file

@ -136,7 +136,7 @@ double move_to_targets_phase::evaluate()
void move_to_targets_phase::execute()
{
unit_map::const_iterator leader = resources::units->find_leader(get_side());
unit_map::const_iterator leader = resources::gameboard->units().find_leader(get_side());
LOG_AI << "finding targets...\n";
std::vector<target> targets;
for(;;) {
@ -273,7 +273,7 @@ std::pair<map_location,map_location> move_to_targets_phase::choose_move(std::vec
log_scope2(log_ai_testing_ca_move_to_targets, "choosing move");
raise_user_interact();
unit_map &units_ = *resources::units;
unit_map &units_ = resources::gameboard->units();
const gamemap &map_ = resources::gameboard->map();
unit_map::iterator u;
@ -629,7 +629,7 @@ std::pair<map_location,map_location> move_to_targets_phase::choose_move(std::vec
void move_to_targets_phase::access_points(const move_map& srcdst, const map_location& u, const map_location& dst, std::vector<map_location>& out)
{
unit_map &units_ = *resources::units;
unit_map &units_ = resources::gameboard->units();
const gamemap &map_ = resources::gameboard->map();
const unit_map::const_iterator u_it = units_.find(u);
if(u_it == units_.end()) {
@ -678,7 +678,7 @@ void move_to_targets_phase::enemies_along_path(const std::vector<map_location>&
map_location move_to_targets_phase::form_group(const std::vector<map_location>& route, const move_map& dstsrc, std::set<map_location>& res)
{
unit_map &units_ = *resources::units;
unit_map &units_ = resources::gameboard->units();
if(route.empty()) {
return map_location();
}
@ -721,7 +721,7 @@ map_location move_to_targets_phase::form_group(const std::vector<map_location>&
bool move_to_targets_phase::move_group(const map_location& dst, const std::vector<map_location>& route, const std::set<map_location>& units)
{
unit_map &units_ = *resources::units;
unit_map &units_ = resources::gameboard->units();
const gamemap &map_ = resources::gameboard->map();
const std::vector<map_location>::const_iterator itor = std::find(route.begin(),route.end(),dst);
@ -823,7 +823,7 @@ bool move_to_targets_phase::move_group(const map_location& dst, const std::vecto
double move_to_targets_phase::rate_group(const std::set<map_location>& group, const std::vector<map_location>& battlefield) const
{
unit_map &units_ = *resources::units;
unit_map &units_ = resources::gameboard->units();
const gamemap &map_ = resources::gameboard->map();
double strength = 0.0;

View file

@ -69,7 +69,7 @@ default_ai_context_impl::~default_ai_context_impl()
int default_ai_context_impl::count_free_hexes_in_castle(const map_location &loc, std::set<map_location> &checked_hexes)
{
int ret = 0;
unit_map &units_ = *resources::units;
unit_map &units_ = resources::gameboard->units();
map_location adj[6];
get_adjacent_tiles(loc,adj);
for(size_t n = 0; n != 6; ++n) {
@ -132,7 +132,7 @@ std::vector<target> default_ai_context_impl::find_targets(const move_map& enemy_
{
log_scope2(log_ai, "finding targets...");
unit_map &units_ = *resources::units;
unit_map &units_ = resources::gameboard->units();
unit_map::iterator leader = units_.find_leader(get_side());
const gamemap &map_ = resources::gameboard->map();
std::vector<team> teams_ = resources::gameboard->teams();

View file

@ -165,11 +165,11 @@ double recruitment::evaluate() {
return BAD_SCORE;
}
const unit_map& units = *resources::units;
const unit_map& units = resources::gameboard->units();
const std::vector<unit_map::const_iterator> leaders = units.find_leaders(get_side());
for (const unit_map::const_iterator& leader : leaders) {
if (leader == resources::units->end()) {
if (leader == resources::gameboard->units().end()) {
return BAD_SCORE;
}
// Check Gold. But proceed if there is a unit with cost <= 0 (WML can do that)
@ -197,7 +197,7 @@ void recruitment::execute() {
* Check which leaders can recruit and collect them in leader_data.
*/
const unit_map& units = *resources::units;
const unit_map& units = resources::gameboard->units();
const gamemap& map = resources::gameboard->map();
const std::vector<unit_map::const_iterator> leaders = units.find_leaders(get_side());
@ -676,7 +676,7 @@ double recruitment::get_average_defense(const std::string& u_type) const {
* for all units of side.
*/
const pathfind::full_cost_map recruitment::get_cost_map_of_side(int side) const {
const unit_map& units = *resources::units;
const unit_map& units = resources::gameboard->units();
const team& team = resources::gameboard->teams()[side - 1];
pathfind::full_cost_map cost_map(true, true, team, true, true);
@ -782,7 +782,7 @@ void recruitment::update_important_hexes() {
update_average_local_cost();
const gamemap& map = resources::gameboard->map();
const unit_map& units = *resources::units;
const unit_map& units = resources::gameboard->units();
// Mark battle areas as important
// This are locations where one of my units is adjacent
@ -919,7 +919,7 @@ double recruitment::compare_unit_types(const std::string& a, const std::string&
* the scores.
*/
void recruitment::do_combat_analysis(std::vector<data>* leader_data) {
const unit_map& units = *resources::units;
const unit_map& units = resources::gameboard->units();
// Collect all enemy units (and their hp) we want to take into account in enemy_units.
typedef std::vector<std::pair<std::string, int> > unit_hp_vector;
@ -1455,7 +1455,7 @@ double recruitment::get_estimated_village_gain() const {
* Returns our_total_unit_costs / enemy_total_unit_costs.
*/
double recruitment::get_unit_ratio() const {
const unit_map& units = *resources::units;
const unit_map& units = resources::gameboard->units();
double own_total_value = 0.;
double team_total_value = 0.;
double enemy_total_value = 0.;
@ -1657,7 +1657,7 @@ void recruitment::handle_recruitment_more(std::vector<data>* leader_data) const
* Returns true if there is a enemy within the radius.
*/
bool recruitment::is_enemy_in_radius(const map_location& loc, int radius) const {
const unit_map& units = *resources::units;
const unit_map& units = resources::gameboard->units();
std::vector<map_location> surrounding;
get_tiles_in_radius(loc, radius, surrounding);
if (surrounding.empty()) {
@ -1684,7 +1684,7 @@ bool recruitment::is_enemy_in_radius(const map_location& loc, int radius) const
void recruitment::update_own_units_count() {
own_units_count_.clear();
total_own_units_ = 0;
const unit_map& units = *resources::units;
const unit_map& units = resources::gameboard->units();
for (const unit& unit : units) {
if (unit.side() != get_side() || unit.can_recruit() ||
unit.incapacitated() || unit.total_movement() <= 0) {

View file

@ -210,7 +210,7 @@ pathfind::plain_route formula_ai::shortest_path_calculator(const map_location &s
{
map_location destination = dst;
unit_map &units_ = *resources::units;
unit_map &units_ = resources::gameboard->units();
pathfind::shortest_path_calculator calc(*unit_it, current_team(), resources::gameboard->teams(), resources::gameboard->map());
unit_map::const_iterator dst_un = units_.find(destination);
@ -279,7 +279,7 @@ variant formula_ai::execute_variant(const variant& var, ai_context &ai_, bool co
variant error;
unit_map& units = *resources::units;
unit_map& units = resources::gameboard->units();
while( !vars.empty() ) {
@ -577,7 +577,7 @@ variant villages_from_set(const Container& villages,
variant formula_ai::get_value(const std::string& key) const
{
const unit_map& units = *resources::units;
const unit_map& units = resources::gameboard->units();
if(key == "aggression")
{
@ -966,7 +966,7 @@ void formula_ai::on_create(){
void formula_ai::evaluate_candidate_action(ca_ptr fai_ca)
{
fai_ca->evaluate(this,*resources::units);
fai_ca->evaluate(this,resources::gameboard->units());
}

View file

@ -115,8 +115,8 @@ void outcome_callable::get_inputs(std::vector<game_logic::formula_input>* inputs
attack_callable::attack_callable(const map_location& move_from,
const map_location& src, const map_location& dst, int weapon)
: move_from_(move_from), src_(src), dst_(dst),
bc_(*resources::units, src, dst, weapon, -1, 1.0, nullptr,
&*resources::units->find(move_from))
bc_(resources::gameboard->units(), src, dst, weapon, -1, 1.0, nullptr,
&*resources::gameboard->units().find(move_from))
{
type_ = ATTACK_C;
}
@ -179,7 +179,7 @@ variant attack_map_callable::get_value(const std::string& key) const {
}
}
/* special case, when unit moved toward enemy and can only attack */
for(unit_map::const_iterator i = resources::units->begin(); i != resources::units->end(); ++i) {
for(unit_map::const_iterator i = resources::gameboard->units().begin(); i != resources::gameboard->units().end(); ++i) {
if (i->side() == ai_.get_side() && i->attacks_left() > 0) {
collect_possible_attacks(vars, i->get_location(), i->get_location());
}

View file

@ -276,10 +276,10 @@ private:
for( size_t i = 0; i< number_of_teams; ++i)
scores[i].resize(w*h);
// for(unit_map::const_iterator i = resources::units->begin(); i != resources::units->end(); ++i) {
// for(unit_map::const_iterator i = resources::gameboard->units().begin(); i != resources::gameboard->units().end(); ++i) {
// unit_counter[i->second.side()-1]++;
// unit_adapter unit(i->second);
// find_movemap( resources::gameboard->map(), *resources::units, unit, i->first, scores[i->second.side()-1], ai_.resources::gameboard->teams() , true );
// find_movemap( resources::gameboard->map(), resources::gameboard->units(), unit, i->first, scores[i->second.side()-1], ai_.resources::gameboard->teams() , true );
// }
for(size_t side = 0 ; side < units_input.num_elements() ; ++side) {
@ -646,7 +646,7 @@ public:
private:
variant execute(const formula_callable& variables, formula_debugger *fdb) const {
const map_location loc = convert_variant<location_callable>(args()[0]->evaluate(variables,add_debug_info(fdb,0,"suitable_keep:location")))->loc();
const unit_map& units = *resources::units;
const unit_map& units = resources::gameboard->units();
const unit_map::const_iterator u = units.find(loc);
if (u == units.end()){
return variant();
@ -708,8 +708,8 @@ private:
range_s = 0;
}
size_t range = static_cast<size_t>(range_s);
unit_map::const_iterator un = resources::units->begin();
unit_map::const_iterator end = resources::units->end();
unit_map::const_iterator un = resources::gameboard->units().begin();
unit_map::const_iterator end = resources::gameboard->units().end();
while (un != end) {
if (distance_between(loc, un->get_location()) <= range) {
if (un->side() != ai_.get_side()) {//fixme: ignores allied units
@ -738,7 +738,7 @@ private:
if (args().size() > 3) weapon = args()[3]->evaluate(variables,add_debug_info(fdb,3,"calculate_outcome:weapon")).as_int();
else weapon = -1;
const unit_map& units = *resources::units;
const unit_map& units = resources::gameboard->units();
map_location attacker_location =
convert_variant<location_callable>(args()[0]->evaluate(variables,add_debug_info(fdb,0,"calculate_outcome:attacker_current_location")))->loc();
if(units.count(attacker_location) == 0) {
@ -819,7 +819,7 @@ private:
variant execute(const formula_callable& variables, formula_debugger *fdb) const {
variant attack = args()[0]->evaluate(variables,add_debug_info(fdb,0,"outcomes:attack"));
ai::attack_analysis* analysis = convert_variant<ai::attack_analysis>(attack);
//unit_map units_with_moves(*resources::units);
//unit_map units_with_moves(resources::gameboard->units());
//typedef std::pair<map_location, map_location> mv;
//for(const mv &m : analysis->movements) {
// units_with_moves.move(m.first, m.second);
@ -956,9 +956,9 @@ private:
else
unit_loc = src;
unit_map::iterator unit_it = resources::units->find(unit_loc);
unit_map::iterator unit_it = resources::gameboard->units().find(unit_loc);
if( unit_it == resources::units->end() ) {
if( unit_it == resources::gameboard->units().end() ) {
std::ostringstream str;
str << "shortest_path function: expected unit at location (" << (unit_loc.wml_x()) << "," << (unit_loc.wml_y()) << ")";
throw formula_error( str.str(), "", "", 0);
@ -1006,9 +1006,9 @@ private:
else
unit_loc = src;
unit_map::iterator unit_it = resources::units->find(unit_loc);
unit_map::iterator unit_it = resources::gameboard->units().find(unit_loc);
if( unit_it == resources::units->end() ) {
if( unit_it == resources::gameboard->units().end() ) {
std::ostringstream str;
str << "simplest_path function: expected unit at location (" << (unit_loc.wml_x()) << "," << (unit_loc.wml_y()) << ")";
throw formula_error( str.str(), "", "", 0);
@ -1060,9 +1060,9 @@ private:
else
unit_loc = src;
unit_map::iterator unit_it = resources::units->find(unit_loc);
unit_map::iterator unit_it = resources::gameboard->units().find(unit_loc);
if( unit_it == resources::units->end() ) {
if( unit_it == resources::gameboard->units().end() ) {
std::ostringstream str;
str << "next_hop function: expected unit at location (" << (unit_loc.wml_x()) << "," << (unit_loc.wml_y()) << ")";
throw formula_error( str.str(), "", "", 0);
@ -1182,7 +1182,7 @@ private:
const map_location src = convert_variant<location_callable>(args()[1]->evaluate(variables,add_debug_info(fdb,1,"attack:src")))->loc();
const map_location dst = convert_variant<location_callable>(args()[2]->evaluate(variables,add_debug_info(fdb,2,"attack:dst")))->loc();
const int weapon = args().size() == 4 ? args()[3]->evaluate(variables,add_debug_info(fdb,3,"attack:weapon")).as_int() : -1;
if(resources::units->count(move_from) == 0 || resources::units->count(dst) == 0) {
if(resources::gameboard->units().count(move_from) == 0 || resources::gameboard->units().count(dst) == 0) {
ERR_AI << "AI ERROR: Formula produced illegal attack: " << move_from << " -> " << src << " -> " << dst << std::endl;
return variant();
}
@ -1311,8 +1311,8 @@ private:
return variant();
}
const location_callable* loc = convert_variant<location_callable>(loc_var);
const unit_map::const_iterator i = resources::units->find(loc->loc());
if(i != resources::units->end()) {
const unit_map::const_iterator i = resources::gameboard->units().find(loc->loc());
if(i != resources::gameboard->units().end()) {
return variant(new unit_callable(*i));
} else {
return variant();
@ -1363,8 +1363,8 @@ private:
std::pair<ai::move_map::const_iterator,ai::move_map::const_iterator> range =
dstsrc.equal_range(convert_variant<location_callable>(args()[1]->evaluate(variables,add_debug_info(fdb,1,"units_can_reach:possible_move_list")))->loc());
while(range.first != range.second) {
unit_map::const_iterator un = resources::units->find(range.first->second);
assert(un != resources::units->end());
unit_map::const_iterator un = resources::gameboard->units().find(range.first->second);
assert(un != resources::gameboard->units().end());
vars.push_back(variant(new unit_callable(*un)));
++range.first;
}

View file

@ -23,6 +23,7 @@
#include "formula/formula.hpp"
#include "formula/function.hpp"
#include "game_board.hpp"
#include "log.hpp"
#include "resources.hpp"
#include "units/unit.hpp"
@ -54,7 +55,7 @@ bool stage_unit_formulas::do_play_stage()
//execute units formulas first
game_logic::unit_formula_set units_with_formulas;
unit_map &units_ = *resources::units;
unit_map &units_ = resources::gameboard->units();
for(unit_map::unit_iterator i = units_.begin() ; i != units_.end() ; ++i)
{

View file

@ -824,7 +824,7 @@ static int impl_ai_aspect_get(lua_State* L)
}
int my_side = get_engine(L).get_readonly_context().get_side();
std::vector<unit_const_ptr> attackers, enemies;
for(unit_map::const_iterator u = resources::units->begin(); u != resources::units->end(); ++u) {
for(unit_map::const_iterator u = resources::gameboard->units().begin(); u != resources::gameboard->units().end(); ++u) {
if(!u.valid()) {
continue;
}
@ -853,7 +853,7 @@ static int impl_ai_aspect_get(lua_State* L)
int my_side = get_engine(L).get_readonly_context().get_side();
lua_newtable(L);
std::hash<map_location> lhash;
for (unit_map::const_iterator u = resources::units->begin(); u != resources::units->end(); ++u) {
for (unit_map::const_iterator u = resources::gameboard->units().begin(); u != resources::gameboard->units().end(); ++u) {
if (!u.valid() || u->side() != my_side) {
continue;
}

View file

@ -30,6 +30,7 @@
#include "resources.hpp"
#include "ai/lua/core.hpp"
#include "ai/lua/lua_object.hpp"
#include "game_board.hpp"
#include "scripting/game_lua_kernel.hpp"
#include "util.hpp"
#include "units/unit.hpp"
@ -180,12 +181,12 @@ public:
, bound_unit_()
{
map_location loc(cfg["unit_x"], cfg["unit_y"], wml_loc()); // lua and c++ coords differ by one
bound_unit_ = unit_ptr(new unit(*resources::units->find(loc)));
bound_unit_ = unit_ptr(new unit(*resources::gameboard->units().find(loc)));
}
virtual double evaluate()
{
if (resources::units->find(bound_unit_->underlying_id()).valid())
if (resources::gameboard->units().find(bound_unit_->underlying_id()).valid())
{
return lua_candidate_action_wrapper_base::evaluate();
}

View file

@ -46,8 +46,8 @@ void helper_advance_unit(const map_location& loc);
bool simulated_attack(const map_location& attacker_loc, const map_location& defender_loc, double attacker_hp, double defender_hp){
LOG_AI_SIM_ACTIONS << "Simulated attack" << std::endl;
unit_map::iterator attack_unit = resources::units->find(attacker_loc);
unit_map::iterator defend_unit = resources::units->find(defender_loc);
unit_map::iterator attack_unit = resources::gameboard->units().find(attacker_loc);
unit_map::iterator defend_unit = resources::gameboard->units().find(defender_loc);
LOG_AI_SIM_ACTIONS << attack_unit->type_name() << " at " << attacker_loc << " attack "
<< defend_unit->type_name() << " at " << defender_loc << std::endl;
@ -67,14 +67,14 @@ bool simulated_attack(const map_location& attacker_loc, const map_location& defe
if(attack_unit->hitpoints() <= 0){
attacker_xp = 0;
defender_xp = game_config::kill_xp(attack_unit->level());
(*resources::units).erase(attacker_loc);
(resources::gameboard->units()).erase(attacker_loc);
attacker_died = true;
}
if(defend_unit->hitpoints() <= 0){
defender_xp = 0;
attacker_xp = game_config::kill_xp(defend_unit->level());
(*resources::units).erase(defender_loc);
(resources::gameboard->units()).erase(defender_loc);
defender_died = true;
}
@ -97,7 +97,7 @@ bool simulated_move(int side, const map_location& from, const map_location& to,
LOG_AI_SIM_ACTIONS << "Simulated move" << std::endl;
// In simulation, AI should not know if there is a enemy's ambusher.
std::pair<unit_map::unit_iterator, bool> unit_move = resources::units->move(from, to);
std::pair<unit_map::unit_iterator, bool> unit_move = resources::gameboard->units().move(from, to);
bool is_ok = unit_move.second;
if(!is_ok){
unit_location = to; // This happened because in some CAs like get_village_phase and move_leader_to_keep phase,
@ -152,7 +152,7 @@ bool simulated_recruit(int side, const unit_type* u, const map_location& recruit
bool simulated_stopunit(const map_location& unit_location, bool remove_movement, bool remove_attacks){
LOG_AI_SIM_ACTIONS << "Simulated stopunit" << std::endl;
unit_map::iterator stop_unit = resources::units->find(unit_location);
unit_map::iterator stop_unit = resources::gameboard->units().find(unit_location);
bool changed = false;
if(remove_movement){
stop_unit->set_movement(0, true);
@ -184,7 +184,7 @@ void helper_check_village(const map_location& loc, int side){
return;
}
bool has_leader = resources::units->find_leader(side).valid();
bool has_leader = resources::gameboard->units().find_leader(side).valid();
// Strip the village off all other sides.
int old_owner_side = 0;
@ -214,7 +214,7 @@ void helper_place_unit(const unit& u, const map_location& loc){
new_unit.set_attacks(0);
new_unit.heal_all();
std::pair<unit_map::iterator, bool> add_result = resources::units->add(loc, new_unit);
std::pair<unit_map::iterator, bool> add_result = resources::gameboard->units().add(loc, new_unit);
assert(add_result.second);
unit_map::iterator& new_unit_itor = add_result.first;
@ -229,7 +229,7 @@ void helper_advance_unit(const map_location& loc){
// Then get all possible options, include modification advancements, like {AMLA DEFAULT} in cfg.
// And then randomly choose one to advanced to.
unit_map::iterator advance_unit = resources::units->find(loc);
unit_map::iterator advance_unit = resources::gameboard->units().find(loc);
if(!unit_helper::will_certainly_advance(advance_unit))
return;
@ -260,7 +260,7 @@ void helper_advance_unit(const map_location& loc){
advanced_unit.add_modification("advancement", mod_option);
}
resources::units->replace(loc, advanced_unit);
resources::gameboard->units().replace(loc, advanced_unit);
LOG_AI_SIM_ACTIONS << advance_unit->type_name() << " at " << loc << " advanced to " << advanced_unit.type_name() << std::endl;
}

View file

@ -53,8 +53,8 @@ battle_prediction_pane::battle_prediction_pane(battle_context &bc,
gui::preview_pane(resources::screen->video()),
attacker_loc_(attacker_loc),
defender_loc_(defender_loc),
attacker_(*resources::units->find(attacker_loc)),
defender_(*resources::units->find(defender_loc)),
attacker_(*resources::gameboard->units().find(attacker_loc)),
defender_(*resources::gameboard->units().find(defender_loc)),
attacker_label_(),
defender_label_(),
attacker_label_width_(0),
@ -221,7 +221,7 @@ void battle_prediction_pane::get_unit_strings(const battle_context_unit_stats& s
// Leadership bonus.
int leadership_bonus = 0;
under_leadership(*resources::units, u_loc, &leadership_bonus);
under_leadership(resources::gameboard->units(), u_loc, &leadership_bonus);
if(leadership_bonus != 0) {
left_strings.push_back(_("Leadership"));
str.str("");

View file

@ -162,7 +162,6 @@ void editor_controller::init_music(const config& game_config)
editor_controller::~editor_controller()
{
resources::units = nullptr;
resources::tod_manager = nullptr;
resources::gameboard = nullptr;
@ -581,8 +580,8 @@ hotkey::ACTION_STATE editor_controller::get_action_state(hotkey::HOTKEY_COMMAND
case editor::UNIT_FACING:
{
unit_map::const_unit_iterator un =
resources::units->find(gui_->mouseover_hex());
assert(un != resources::units->end());
resources::gameboard->units().find(gui_->mouseover_hex());
assert(un != resources::gameboard->units().end());
return un->facing() == index ? ACTION_SELECTED : ACTION_DESELECTED;
}
}
@ -683,8 +682,8 @@ bool editor_controller::execute_command(const hotkey::hotkey_command& cmd, int i
case UNIT_FACING:
{
unit_map::unit_iterator un =
resources::units->find(gui_->mouseover_hex());
assert(un != resources::units->end());
resources::gameboard->units().find(gui_->mouseover_hex());
assert(un != resources::gameboard->units().end());
un->set_facing(map_location::DIRECTION(index));
un->anim_comp().set_standing();
return true;

View file

@ -78,9 +78,8 @@ public:
void refresh() {
context_manager_.gui().change_display_context(&context_manager_.get_map_context());
resources::units = &context_manager_.get_map_context().get_units();
if(resources::gameboard) {
resources::gameboard->units() = context_manager_.get_map_context().get_units();
resources::gameboard->teams() = context_manager_.get_map_context().get_teams();
}

View file

@ -449,7 +449,7 @@ WML_HANDLER_FUNCTION(recall,, cfg)
}
recall_list_manager & avail = resources::gameboard->teams()[index].recall_list();
std::vector<unit_map::unit_iterator> leaders = resources::units->find_leaders(index + 1);
std::vector<unit_map::unit_iterator> leaders = resources::gameboard->units().find_leaders(index + 1);
const unit_filter ufilt(unit_filter_cfg, resources::filter_con);
const unit_filter lfilt(leader_filter, resources::filter_con); // Note that if leader_filter is null, this correctly gives a null filter that matches all units.
@ -472,7 +472,7 @@ WML_HANDLER_FUNCTION(recall,, cfg)
DBG_NG << "...matched the leader filter and is able to recall the unit.\n";
if(!resources::gameboard->map().on_board(loc))
loc = leader->get_location();
if(pass_check || (resources::units->count(loc) > 0))
if(pass_check || (resources::gameboard->units().count(loc) > 0))
loc = pathfind::find_vacant_tile(loc, pathfind::VACANT_ANY, pass_check);
if(resources::gameboard->map().on_board(loc)) {
DBG_NG << "...valid location for the recall found. Recalling.\n";
@ -486,7 +486,7 @@ WML_HANDLER_FUNCTION(recall,, cfg)
}
if (resources::gameboard->map().on_board(cfg_loc)) {
map_location loc = cfg_loc;
if(pass_check || (resources::units->count(loc) > 0))
if(pass_check || (resources::gameboard->units().count(loc) > 0))
loc = pathfind::find_vacant_tile(loc, pathfind::VACANT_ANY, pass_check);
// Check if we still have a valid location
if (resources::gameboard->map().on_board(loc)) {

View file

@ -48,14 +48,14 @@ namespace builtin_conditions {
bool have_unit(const vconfig& cfg)
{
if(resources::units == nullptr) {
if(!resources::gameboard) {
return false;
}
std::vector<std::pair<int,int> > counts = cfg.has_attribute("count")
? utils::parse_ranges(cfg["count"]) : default_counts;
int match_count = 0;
const unit_filter ufilt(cfg, resources::filter_con);
for(const unit &i : *resources::units) {
for(const unit &i : resources::gameboard->units()) {
if(i.hitpoints() > 0 && ufilt(i)) {
++match_count;
if(counts == default_counts) {

View file

@ -20,6 +20,7 @@
#include "global.hpp"
#include "game_events/entity_location.hpp"
#include "game_board.hpp"
#include "resources.hpp"
#include "units/unit.hpp"
#include "units/filter.hpp"
@ -106,17 +107,17 @@ bool entity_location::matches_unit_filter(const unit_map::const_iterator & un_it
unit_const_ptr entity_location::get_unit() const
{
if(resources::units == nullptr) {
if(!resources::gameboard) {
return nullptr;
}
if(id_ == 0) {
auto un_it = resources::units->find(*this);
auto un_it = resources::gameboard->units().find(*this);
if(un_it.valid()) {
return un_it.get_shared_ptr();
}
return nullptr;
}
return resources::units->find(id_).get_shared_ptr();
return resources::gameboard->units().find(id_).get_shared_ptr();
}
} // end namespace game_events

View file

@ -175,9 +175,9 @@ namespace { // Support functions
*/
bool wml_event_pump::filter_event(const event_handler& handler, const queued_event& ev)
{
const unit_map *units = resources::units;
unit_map::const_iterator unit1 = units->find(ev.loc1);
unit_map::const_iterator unit2 = units->find(ev.loc2);
const unit_map& units = resources::gameboard->units();
unit_map::const_iterator unit1 = units.find(ev.loc1);
unit_map::const_iterator unit2 = units.find(ev.loc2);
vconfig filters(handler.get_config());
for (const vconfig &condition : filters.get_children("filter_condition"))
@ -203,7 +203,7 @@ namespace { // Support functions
vconfig::child_list special_filters = filters.get_children("filter_attack");
bool special_matches = special_filters.empty();
if ( !special_matches && unit1 != units->end() )
if ( !special_matches && unit1 != units.end() )
{
const bool matches_unit = ev.loc1.matches_unit(unit1);
const config & attack = ev.data.child("first");
@ -231,7 +231,7 @@ namespace { // Support functions
special_filters = filters.get_children("filter_second_attack");
special_matches = special_filters.empty();
if ( !special_matches && unit2 != units->end() )
if ( !special_matches && unit2 != units.end() )
{
const bool matches_unit = ev.loc2.matches_unit(unit2);
const config & attack = ev.data.child("second");
@ -274,9 +274,9 @@ namespace { // Support functions
if ( !handler_p )
return false;
unit_map *units = resources::units;
scoped_xy_unit first_unit("unit", ev.loc1, *units);
scoped_xy_unit second_unit("second_unit", ev.loc2, *units);
unit_map& units = resources::gameboard->units();
scoped_xy_unit first_unit("unit", ev.loc1, units);
scoped_xy_unit second_unit("second_unit", ev.loc2, units);
scoped_weapon_info first_weapon("weapon", ev.data.child("first"));
scoped_weapon_info second_weapon("second_weapon", ev.data.child("second"));

View file

@ -121,11 +121,11 @@ static std::string format_cost_string(int unit_recall_cost, const int team_recal
static std::string get_title_suffix(int side_num)
{
if(!resources::gameboard || !resources::units) {
if(!resources::gameboard) {
return "";
}
unit_map& units = *resources::units;
unit_map& units = resources::gameboard->units();
int controlled_recruiters = 0;
for(const auto& team : resources::gameboard->teams()) {
@ -136,8 +136,8 @@ static std::string get_title_suffix(int side_num)
std::stringstream msg;
if(controlled_recruiters >= 2) {
unit_map::const_iterator leader = resources::units->find_leader(side_num);
if(leader != resources::units->end() && !leader->name().empty()) {
unit_map::const_iterator leader = resources::gameboard->units().find_leader(side_num);
if(leader != resources::gameboard->units().end() && !leader->name().empty()) {
msg << " (" << leader->name(); msg << ")";
}
}

View file

@ -587,7 +587,7 @@ vision_path::vision_path(const movetype::terrain_costs & view_costs, bool slowed
// The three nullptr parameters indicate (in order):
// ignore units, ignore ZoC (no effect), and don't build a cost_map.
team const& viewing_team = resources::gameboard->teams()[resources::screen->viewing_team()];
const unit_map::const_iterator u = resources::units->find(loc);
const unit_map::const_iterator u = resources::gameboard->units().find(loc);
find_routes(loc, view_costs, slowed, sight_range, sight_range, 0,
destinations, &edges, u.valid() ? &*u : nullptr, nullptr, nullptr, &viewing_team, &jamming_map, nullptr, true);
}
@ -631,8 +631,8 @@ marked_route mark_route(const plain_route &rt)
if (rt.steps.empty()) return marked_route();
res.route = rt;
unit_map::const_iterator it = resources::units->find(rt.steps.front());
if (it == resources::units->end()) return marked_route();
unit_map::const_iterator it = resources::gameboard->units().find(rt.steps.front());
if (it == resources::gameboard->units().end()) return marked_route();
unit const& u = *it;
int turns = 0;

View file

@ -124,7 +124,7 @@ void teleport_group::get_teleport_pair(
const unit_filter ufilt(filter, resources::filter_con); //Note: Don't use the ignore units filter context here, only for the terrain filters. (That's how it worked before the filter contexts were introduced)
if (ufilt.matches(u, loc)) {
scoped_xy_unit teleport_unit("teleport_unit", loc, *resources::units);
scoped_xy_unit teleport_unit("teleport_unit", loc, resources::gameboard->units());
terrain_filter source_filter(source, fc);
source_filter.get_locations(reversed_ ? loc_pair.second : loc_pair.first);
@ -202,11 +202,11 @@ teleport_map::teleport_map(
while(loc != locations.second.end()) {
unit_map::iterator u;
if (see_all) {
u = resources::units->find(*loc);
u = resources::gameboard->units().find(*loc);
} else {
u = resources::gameboard->find_visible_unit(*loc, viewing_team);
}
if (u != resources::units->end()) {
if (u != resources::gameboard->units().end()) {
loc = locations.second.erase(loc);
} else {
++loc;

View file

@ -130,7 +130,6 @@ static void clear_resources()
resources::tunnels = nullptr;
resources::undo_stack = nullptr;
resources::recorder = nullptr;
resources::units = nullptr;
resources::whiteboard.reset();
resources::classification = nullptr;
resources::mp_settings = nullptr;
@ -224,7 +223,6 @@ void play_controller::init(CVideo& video, const config& level)
resources::gameboard = &gamestate().board_;
resources::gamedata = &gamestate().gamedata_;
resources::tod_manager = &gamestate().tod_manager_;
resources::units = &gamestate().board_.units_;
resources::filter_con = &gamestate();
resources::undo_stack = &undo_stack();
resources::game_events = gamestate().events_manager_.get();
@ -308,7 +306,6 @@ void play_controller::reset_gamestate(const config& level, int replay_pos)
resources::gameboard = nullptr;
resources::gamedata = nullptr;
resources::tod_manager = nullptr;
resources::units = nullptr;
resources::filter_con = nullptr;
resources::lua_kernel = nullptr;
resources::game_events = nullptr;
@ -321,7 +318,6 @@ void play_controller::reset_gamestate(const config& level, int replay_pos)
resources::gameboard = &gamestate().board_;
resources::gamedata = &gamestate().gamedata_;
resources::tod_manager = &gamestate().tod_manager_;
resources::units = &gamestate().board_.units_;
resources::filter_con = &gamestate();
resources::undo_stack = &undo_stack();
resources::game_events = gamestate().events_manager_.get();

View file

@ -207,7 +207,7 @@ void replay::add_unit_checksum(const map_location& loc,config& cfg)
}
config& cc = cfg.add_child("checksum");
loc.write(cc);
unit_map::const_iterator u = resources::units->find(loc);
unit_map::const_iterator u = resources::gameboard->units().find(loc);
assert(u.valid());
cc["value"] = get_checksum(*u);
}
@ -742,7 +742,7 @@ REPLAY_RETURN do_replay_handle(bool one_move)
const map_location loc(rename);
const std::string &name = rename["name"];
unit_map::iterator u = resources::units->find(loc);
unit_map::iterator u = resources::gameboard->units().find(loc);
if (u.valid() && !u->unrenamable()) {
u->rename(name);
} else {
@ -787,7 +787,7 @@ REPLAY_RETURN do_replay_handle(bool one_move)
else
{
if (const config &cfg_verify = cfg->child("verify")) {
verify(*resources::units, cfg_verify);
verify(resources::gameboard->units(), cfg_verify);
}
return REPLAY_FOUND_END_TURN;
@ -862,7 +862,7 @@ REPLAY_RETURN do_replay_handle(bool one_move)
}
if (const config &child = cfg->child("verify")) {
verify(*resources::units, child);
verify(resources::gameboard->units(), child);
}
}
}

View file

@ -31,7 +31,6 @@ namespace resources
fake_unit_manager *fake_units = nullptr;
pathfind::manager *tunnels = nullptr;
actions::undo_list *undo_stack = nullptr;
unit_map *units = nullptr;
std::shared_ptr<wb::manager> whiteboard = std::shared_ptr<wb::manager>();
game_classification *classification = nullptr;
const mp_game_settings *mp_settings = nullptr;

View file

@ -28,7 +28,6 @@ class game_lua_kernel;
class play_controller;
class fake_unit_manager;
class tod_manager;
class unit_map;
class persist_manager;
class game_classification;
struct mp_game_settings;
@ -63,7 +62,6 @@ namespace resources
extern ::tod_manager *tod_manager;
extern pathfind::manager *tunnels;
extern actions::undo_list *undo_stack;
extern unit_map *units;
extern std::shared_ptr<wb::manager> whiteboard;
extern bool simulation_;
}

View file

@ -1,13 +1,13 @@
/*
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
@ -15,6 +15,7 @@
#include "boost/variant/static_visitor.hpp"
#include "game_board.hpp"
#include "scripting/game_lua_kernel.hpp"
#include "scripting/lua_unit.hpp"
#include "scripting/lua_common.hpp"
@ -141,7 +142,7 @@ void luaW_pushfaivariant(lua_State* L, variant val) {
// First try a few special cases
if(unit_callable* u_ref = val.try_convert<unit_callable>()) {
const unit& u = u_ref->get_unit();
unit_map::iterator un_it = resources::units->find(u.get_location());
unit_map::iterator un_it = resources::gameboard->units().find(u.get_location());
if(&*un_it == &u) {
luaW_pushunit(L, u.underlying_id());
} else {
@ -286,6 +287,6 @@ std::string lua_formula_bridge::register_metatables(lua_State* L)
lua_setfield(L, -2, "__call");
lua_pushstring(L, "formula");
lua_setfield(L, -2, "__metatable");
return "Adding formula metatable...\n";
}

View file

@ -47,7 +47,7 @@ unit* lua_unit::get()
if (side) {
return resources::gameboard->teams()[side - 1].recall_list().find_if_matches_underlying_id(uid).get();
}
unit_map::unit_iterator ui = resources::units->find(uid);
unit_map::unit_iterator ui = resources::gameboard->units().find(uid);
if (!ui.valid()) return nullptr;
return ui.get_shared_ptr().get(); //&*ui would not be legal, must get new shared_ptr by copy ctor because the unit_map itself is holding a boost shared pointer.
}
@ -57,7 +57,7 @@ unit_ptr lua_unit::get_shared()
if (side) {
return resources::gameboard->teams()[side - 1].recall_list().find_if_matches_underlying_id(uid);
}
unit_map::unit_iterator ui = resources::units->find(uid);
unit_map::unit_iterator ui = resources::gameboard->units().find(uid);
if (!ui.valid()) return unit_ptr();
return ui.get_shared_ptr(); //&*ui would not be legal, must get new shared_ptr by copy ctor because the unit_map itself is holding a boost shared pointer.
}
@ -70,8 +70,8 @@ bool lua_unit::put_map(const map_location &loc)
{
if (ptr) {
ptr->set_location(loc);
resources::units->erase(loc);
std::pair<unit_map::unit_iterator, bool> res = resources::units->insert(ptr);
resources::gameboard->units().erase(loc);
std::pair<unit_map::unit_iterator, bool> res = resources::gameboard->units().insert(ptr);
if (res.second) {
ptr.reset();
uid = res.first->underlying_id();
@ -84,18 +84,18 @@ bool lua_unit::put_map(const map_location &loc)
if (it) {
side = 0;
// uid may be changed by unit_map on insertion
uid = resources::units->replace(loc, *it).first->underlying_id();
uid = resources::gameboard->units().replace(loc, *it).first->underlying_id();
} else {
ERR_LUA << "Could not find unit " << uid << " on recall list of side " << side << '\n';
return false;
}
} else { // on map
unit_map::unit_iterator ui = resources::units->find(uid);
if (ui != resources::units->end()) {
unit_map::unit_iterator ui = resources::gameboard->units().find(uid);
if (ui != resources::gameboard->units().end()) {
map_location from = ui->get_location();
if (from != loc) { // This check is redundant in current usage
resources::units->erase(loc);
resources::units->move(from, loc);
resources::gameboard->units().erase(loc);
resources::gameboard->units().move(from, loc);
}
// No need to change our contents
} else {

View file

@ -79,7 +79,7 @@ SYNCED_COMMAND_HANDLER_FUNCTION(recruit, child, use_undo, show, error_handler)
// EDIT: we borke compability with 1.11.2 anyway so we should give an error.
error_handler("Missing leader location for recruitment.\n", false);
}
else if ( resources::units->find(from) == resources::units->end() ) {
else if ( resources::gameboard->units().find(from) == resources::gameboard->units().end() ) {
// Sync problem?
std::stringstream errbuf;
errbuf << "Recruiting leader not found at " << from << ".\n";
@ -181,7 +181,7 @@ SYNCED_COMMAND_HANDLER_FUNCTION(attack, child, /*use_undo*/, show, error_handler
def_weapon_num = -1;
}
unit_map::iterator u = resources::units->find(src);
unit_map::iterator u = resources::gameboard->units().find(src);
if (!u.valid()) {
error_handler("unfound location for source of attack\n", true);
return false;
@ -199,7 +199,7 @@ SYNCED_COMMAND_HANDLER_FUNCTION(attack, child, /*use_undo*/, show, error_handler
return false;
}
unit_map::const_iterator tgt = resources::units->find(dst);
unit_map::const_iterator tgt = resources::gameboard->units().find(dst);
if (!tgt.valid()) {
std::stringstream errbuf;
@ -289,7 +289,7 @@ SYNCED_COMMAND_HANDLER_FUNCTION(move, child, use_undo, show, error_handler)
// 'event' doesn't mean wml event but rather it means 'hidden' units form the movers point of view.
}
u = resources::units->find(src);
u = resources::gameboard->units().find(src);
if (!u.valid()) {
std::stringstream errbuf;
errbuf << "unfound location for source of movement: "
@ -406,8 +406,8 @@ SYNCED_COMMAND_HANDLER_FUNCTION(debug_unit, child, use_undo, /*show*/, /*error_
const std::string name = child["name"];
const std::string value = child["value"];
unit_map::iterator i = resources::units->find(loc);
if (i == resources::units->end()) {
unit_map::iterator i = resources::gameboard->units().find(loc);
if (i == resources::gameboard->units().end()) {
return false;
}
if (name == "advances" ) {
@ -416,7 +416,7 @@ SYNCED_COMMAND_HANDLER_FUNCTION(debug_unit, child, use_undo, /*show*/, /*error_
i->set_experience(i->max_experience());
advance_unit_at(advance_unit_params(loc).force_dialog(true));
i = resources::units->find(loc);
i = resources::gameboard->units().find(loc);
if (!i.valid()) {
break;
}
@ -436,10 +436,10 @@ SYNCED_COMMAND_HANDLER_FUNCTION(debug_unit, child, use_undo, /*show*/, /*error_
} else {
config cfg;
i->write(cfg);
resources::units->erase(loc);
resources::gameboard->units().erase(loc);
cfg[name] = value;
unit new_u(cfg, true);
resources::units->add(loc, new_u);
resources::gameboard->units().add(loc, new_u);
}
if (name == "fail") { //testcase for bug #18488
assert(i.valid());
@ -472,7 +472,7 @@ SYNCED_COMMAND_HANDLER_FUNCTION(debug_create_unit, child, use_undo, /*show*/, e
created.new_turn();
// Add the unit to the board.
std::pair<unit_map::iterator, bool> add_result = resources::units->replace(loc, created);
std::pair<unit_map::iterator, bool> add_result = resources::gameboard->units().replace(loc, created);
resources::screen->invalidate_unit();
resources::game_events->pump().fire("unit_placed", loc);
unit_display::unit_recruited(loc);
@ -511,8 +511,8 @@ SYNCED_COMMAND_HANDLER_FUNCTION(debug_kill, child, use_undo, /*show*/, /*error_h
debug_notification("kill debug command was used during turn of $player");
const map_location loc(child["x"].to_int(), child["y"].to_int(), wml_loc());
const unit_map::iterator i = resources::units->find(loc);
if (i != resources::units->end()) {
const unit_map::iterator i = resources::gameboard->units().find(loc);
if (i != resources::gameboard->units().end()) {
const int dying_side = i->side();
resources::controller->pump().fire("last_breath", loc, loc);
if (i.valid()) {
@ -522,7 +522,7 @@ SYNCED_COMMAND_HANDLER_FUNCTION(debug_kill, child, use_undo, /*show*/, /*error_h
i->set_hitpoints(0);
resources::controller->pump().fire("die", loc, loc);
if (i.valid()) {
resources::units->erase(i);
resources::gameboard->units().erase(i);
}
actions::recalculate_fog(dying_side);
}

View file

@ -138,7 +138,7 @@ bool unit::get_ability_bool(const std::string& tag_name, const map_location& loc
}
}
const unit_map& units = *resources::units;
const unit_map& units = resources::gameboard->units();
map_location adjacent[6];
get_adjacent_tiles(loc,adjacent);
for(int i = 0; i != 6; ++i) {
@ -179,7 +179,7 @@ unit_ability_list unit::get_abilities(const std::string& tag_name, const map_loc
}
}
const unit_map& units = *resources::units;
const unit_map& units = resources::gameboard->units();
map_location adjacent[6];
get_adjacent_tiles(loc,adjacent);
for(int i = 0; i != 6; ++i) {
@ -309,7 +309,7 @@ std::vector<std::tuple<t_string, t_string, t_string> > unit::ability_tooltips(bo
bool unit::ability_active(const std::string& ability,const config& cfg,const map_location& loc) const
{
bool illuminates = ability == "illuminates";
assert(resources::units && resources::gameboard && resources::tod_manager);
assert(resources::gameboard && resources::tod_manager);
if (const config &afilter = cfg.child("filter"))
if ( !unit_filter(vconfig(afilter), resources::filter_con, illuminates).matches(*this, loc) )
@ -317,7 +317,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;
const unit_map& units = resources::gameboard->units();
for (const config &i : cfg.child_range("filter_adjacent"))
{
@ -891,7 +891,7 @@ bool attack_type::special_active(const config& special, AFFECTS whom,
}
// Get the units involved.
const unit_map & units = *resources::units;
const unit_map & units = resources::gameboard->units();
unit_map::const_iterator self = units.find(self_loc_);
unit_map::const_iterator other = units.find(other_loc_);

View file

@ -784,7 +784,7 @@ void wml_animation_internal(unit_animator &animator, const vconfig &cfg, const m
{
unit_const_ptr u;
unit_map::const_iterator u_it = resources::units->find(default_location);
unit_map::const_iterator u_it = resources::gameboard->units().find(default_location);
if (u_it.valid()) {
u = u_it.get_shared_ptr();
}

View file

@ -2396,10 +2396,10 @@ unit_movement_resetter::unit_movement_resetter(const unit &u, bool operate) :
unit_movement_resetter::~unit_movement_resetter()
{
assert(resources::units);
assert(resources::gameboard);
try {
if(!resources::units->has_unit(&u_)) {
if(!resources::gameboard->units().has_unit(&u_)) {
/*
* It might be valid that the unit is not in the unit map.
* It might also mean a no longer valid unit will be assigned to.

View file

@ -137,7 +137,7 @@ void attack::execute(bool& success, bool& complete)
complete = true;
//check that attacking unit is still alive, if not, consider the attack a failure
unit_map::const_iterator survivor = resources::units->find(get_dest_hex());
unit_map::const_iterator survivor = resources::gameboard->units().find(get_dest_hex());
if(!survivor.valid() || survivor->id() != unit_id_)
{
success = false;
@ -234,7 +234,7 @@ action::error attack::check_validity() const
return INVALID_LOCATION;
}
// Verify that the target hex isn't empty
if(resources::units->find(target_hex_) == resources::units->end()){
if(resources::gameboard->units().find(target_hex_) == resources::gameboard->units().end()){
return NO_TARGET;
}
// Verify that the attacking unit has attacks left
@ -242,7 +242,7 @@ action::error attack::check_validity() const
return NO_ATTACK_LEFT;
}
// Verify that the attacker and target are enemies
if(!resources::gameboard->teams()[get_unit()->side() - 1].is_enemy(resources::units->find(target_hex_)->side())){
if(!resources::gameboard->teams()[get_unit()->side() - 1].is_enemy(resources::gameboard->units().find(target_hex_)->side())){
return NOT_AN_ENEMY;
}
//@todo: (maybe) verify that the target hex contains the same unit that before,

View file

@ -367,8 +367,8 @@ void highlighter::unhighlight_visitor::visit(recall_ptr recall)
}
unit_map& highlighter::get_unit_map()
{
assert(resources::units);
return *resources::units;
assert(resources::gameboard);
return resources::gameboard->units();
}
} // end namespace wb

View file

@ -520,7 +520,7 @@ void manager::pre_draw()
units_owning_moves_ = move_finder.get_units_owning_moves();
for (size_t unit_id : units_owning_moves_) {
unit_map::iterator unit_iter = resources::units->find(unit_id);
unit_map::iterator unit_iter = resources::gameboard->units().find(unit_id);
assert(unit_iter.valid());
ghost_owner_unit(&*unit_iter);
}
@ -531,7 +531,7 @@ void manager::post_draw()
{
for (size_t unit_id : units_owning_moves_)
{
unit_map::iterator unit_iter = resources::units->find(unit_id);
unit_map::iterator unit_iter = resources::gameboard->units().find(unit_id);
if (unit_iter.valid()) {
unghost_owner_unit(&*unit_iter);
}
@ -571,7 +571,7 @@ void manager::on_mouseover_change(const map_location& hex)
map_location selected_hex = resources::controller->get_mouse_handler_base().get_selected_hex();
bool hex_has_unit;
{ wb::future_map future; // start planned unit map scope
hex_has_unit = resources::units->find(selected_hex) != resources::units->end();
hex_has_unit = resources::gameboard->units().find(selected_hex) != resources::gameboard->units().end();
} // end planned unit map scope
if (!((selected_hex.valid() && hex_has_unit)
|| has_temp_move() || wait_for_side_init_ || executing_actions_))
@ -794,7 +794,7 @@ void manager::save_temp_move()
unit_map::iterator manager::get_temp_move_unit() const
{
return resources::units->find(temp_move_unit_underlying_id_);
return resources::gameboard->units().find(temp_move_unit_underlying_id_);
}
void manager::save_temp_attack(const map_location& attacker_loc, const map_location& defender_loc, int weapon_choice)
@ -1149,7 +1149,7 @@ void manager::set_planned_unit_map()
}
log_scope2("whiteboard", "Building planned unit map");
mapbuilder_.reset(new mapbuilder(*resources::units));
mapbuilder_.reset(new mapbuilder(resources::gameboard->units()));
mapbuilder_->build_map();
planned_unit_map_active_ = true;

View file

@ -139,7 +139,7 @@ public:
/** Creates a move action for the current side, and erases the temp move.
* The move action is inserted at the end of the queue, to be executed last. */
void save_temp_move();
/** @return an iterator to the unit that owns the temp move, resources::units->end() if there's none. */
/** @return an iterator to the unit that owns the temp move, resources::gameboard->units().end() if there's none. */
unit_map::iterator get_temp_move_unit() const;
/** Creates an attack or attack-move action for the current side */

View file

@ -62,14 +62,14 @@ void mapbuilder::pre_build()
}
int current_side = resources::controller->current_side();
for (unit& u : *resources::units) {
for (unit& u : resources::gameboard->units()) {
bool on_current_side = (u.side() == current_side);
//Remove any unit the current side cannot see to avoid their detection by planning
//Units will be restored to the unit map by destruction of removers_
if(!on_current_side && !u.is_visible_to_team(resources::gameboard->teams()[viewer_team()], *resources::gameboard, false)) {
removers_.push_back(new temporary_unit_remover(*resources::units, u.get_location()));
removers_.push_back(new temporary_unit_remover(resources::gameboard->units(), u.get_location()));
//Don't do anything else to the removed unit!
continue;

View file

@ -100,8 +100,8 @@ move::move(config const& cfg, bool hidden)
, fake_unit_hidden_(false)
{
// Construct and validate unit_
unit_map::iterator unit_itor = resources::units->find(cfg["unit_"]);
if(unit_itor == resources::units->end())
unit_map::iterator unit_itor = resources::gameboard->units().find(cfg["unit_"]);
if(unit_itor == resources::gameboard->units().end())
throw action::ctor_err("move: Invalid underlying_id");
unit_underlying_id_ = unit_itor->underlying_id();
@ -237,7 +237,7 @@ void move::execute(bool& success, bool& complete)
throw; // we rely on the caller to delete this action
}
const map_location & final_location = steps[num_steps];
unit_map::const_iterator unit_it = resources::units->find(final_location);
unit_map::const_iterator unit_it = resources::gameboard->units().find(final_location);
if ( num_steps == 0 )
{
@ -245,7 +245,7 @@ void move::execute(bool& success, bool& complete)
success = false;
complete = true;
}
else if ( unit_it == resources::units->end() || unit_it->id() != unit_id_ )
else if ( unit_it == resources::gameboard->units().end() || unit_it->id() != unit_id_ )
{
WRN_WB << "Unit disappeared from map during move execution." << std::endl;
success = false;
@ -286,7 +286,7 @@ void move::execute(bool& success, bool& complete)
unit_ptr move::get_unit() const
{
unit_map::iterator itor = resources::units->find(unit_underlying_id_);
unit_map::iterator itor = resources::gameboard->units().find(unit_underlying_id_);
if (itor.valid())
return itor.get_shared_ptr();
else
@ -371,8 +371,8 @@ void move::remove_temp_modifier(unit_map&)
{
unit* unit;
{
unit_map::iterator unit_it = resources::units->find(get_dest_hex());
assert(unit_it != resources::units->end());
unit_map::iterator unit_it = resources::gameboard->units().find(get_dest_hex());
assert(unit_it != resources::gameboard->units().end());
unit = &*unit_it;
}
DBG_WB << "Move: Movement points for unit " << unit->name() << " [" << unit->id()
@ -459,8 +459,8 @@ action::error move::check_validity() const
//Check that the unit still exists in the source hex
unit_map::iterator unit_it;
unit_it = resources::units->find(get_source_hex());
if(unit_it == resources::units->end()) {
unit_it = resources::gameboard->units().find(get_source_hex());
if(unit_it == resources::gameboard->units().end()) {
return NO_UNIT;
}

View file

@ -204,7 +204,7 @@ void recall::redraw()
action::error recall::check_validity() const
{
//Check that destination hex is still free
if(resources::units->find(recall_hex_) != resources::units->end()) {
if(resources::gameboard->units().find(recall_hex_) != resources::gameboard->units().end()) {
return LOCATION_OCCUPIED;
}
//Check that unit to recall is still in side's recall list

View file

@ -182,7 +182,7 @@ unit_ptr recruit::create_corresponding_unit()
action::error recruit::check_validity() const
{
//Check that destination hex is still free
if(resources::units->find(recruit_hex_) != resources::units->end()) {
if(resources::gameboard->units().find(recruit_hex_) != resources::gameboard->units().end()) {
return LOCATION_OCCUPIED;
}
//Check that unit to recruit is still in side's recruit list

View file

@ -73,8 +73,8 @@ suppose_dead::suppose_dead(config const& cfg, bool hidden)
, loc_(cfg.child("loc_")["x"],cfg.child("loc_")["y"], wml_loc())
{
// Construct and validate unit_
unit_map::iterator unit_itor = resources::units->find(cfg["unit_"]);
if(unit_itor == resources::units->end())
unit_map::iterator unit_itor = resources::gameboard->units().find(cfg["unit_"]);
if(unit_itor == resources::gameboard->units().end())
throw action::ctor_err("suppose_dead: Invalid underlying_id");
unit_underlying_id_ = unit_itor->underlying_id();
@ -97,7 +97,7 @@ suppose_dead::~suppose_dead()
unit_ptr suppose_dead::get_unit() const
{
unit_map::iterator itor = resources::units->find(unit_underlying_id_);
unit_map::iterator itor = resources::gameboard->units().find(unit_underlying_id_);
if (itor.valid())
return itor.get_shared_ptr();
else
@ -126,8 +126,8 @@ void suppose_dead::apply_temp_modifier(unit_map& unit_map)
void suppose_dead::remove_temp_modifier(unit_map& unit_map)
{
// Just check to make sure the hex is empty
unit_map::iterator unit_it = resources::units->find(loc_);
assert(unit_it == resources::units->end());
unit_map::iterator unit_it = resources::gameboard->units().find(loc_);
assert(unit_it == resources::gameboard->units().end());
// Restore the unit
unit_map.insert(get_unit());
@ -158,8 +158,8 @@ action::error suppose_dead::check_validity() const
return INVALID_LOCATION;
}
//Check that the unit still exists in the source hex
unit_map::const_iterator unit_it = resources::units->find(get_source_hex());
if(unit_it == resources::units->end()) {
unit_map::const_iterator unit_it = resources::gameboard->units().find(get_source_hex());
if(unit_it == resources::gameboard->units().end()) {
return NO_UNIT;
}
//check if the unit in the source hex has the same unit id as before,

View file

@ -65,7 +65,7 @@ unit_const_ptr find_backup_leader(const unit & leader)
{
assert(leader.can_recruit());
assert(resources::gameboard->map().is_keep(leader.get_location()));
for (unit_map::const_iterator unit = resources::units->begin(); unit != resources::units->end(); unit++)
for (unit_map::const_iterator unit = resources::gameboard->units().begin(); unit != resources::gameboard->units().end(); unit++)
{
if (unit->can_recruit() && unit->id() != leader.id())
{
@ -81,7 +81,7 @@ unit* find_recruiter(size_t team_index, map_location const& hex)
if ( !resources::gameboard->map().is_castle(hex) )
return nullptr;
for(unit& u : *resources::units)
for(unit& u : resources::gameboard->units())
if(u.can_recruit()
&& u.side() == static_cast<int>(team_index+1)
&& dynamic_cast<game_state*>(resources::filter_con)->can_recruit_on(u, hex))