Skip to content

Commit

Permalink
remove resources::game_map (part 2)
Browse files Browse the repository at this point in the history
This the result of executing, in folder src/, the following

find . -type f -exec sed -i 's/\*resources\:\:game_map/resources\:\:gameboard->map()/g' '{}' \;

and carefully inspecting the result.

We also had to add game_board.hpp includes in various places,
and change the arguent order of unit::is_visible_to_team --
this function was taking *resources::game_map as its default
argument, and we do not want to include game_board in unit.hpp,
as it creates cyclic dependencies. This was resolved by
eliminating this as a default value -- this is an improvement,
since usually when this function was called it was in a context
where a game_map was available already locally anyways.
  • Loading branch information
cbeck88 committed Jun 11, 2014
1 parent 4830b8e commit aab7edd
Show file tree
Hide file tree
Showing 27 changed files with 80 additions and 78 deletions.
10 changes: 5 additions & 5 deletions src/actions/create.cpp
Expand Up @@ -267,7 +267,7 @@ void unit_creator::post_create(const map_location &loc, const unit &new_unit, bo
*/
bool can_recruit_from(const map_location& leader_loc, int side)
{
const gamemap& map = *resources::game_map;
const gamemap& map = resources::gameboard->map();

if( !map.is_keep(leader_loc) )
return false;
Expand All @@ -294,7 +294,7 @@ bool can_recruit_from(const map_location& leader_loc, int side)
*/
bool can_recruit_on(const map_location& leader_loc, const map_location& recruit_loc, int side)
{
const gamemap& map = *resources::game_map;
const gamemap& map = resources::gameboard->map();

if( !map.is_castle(recruit_loc) )
return false;
Expand Down Expand Up @@ -360,7 +360,7 @@ const std::set<std::string> get_recruits(int side, const map_location &recruit_l
local_result.insert(find_it->recruits().begin(),
find_it->recruits().end());
}
else if ( find_it->is_visible_to_team(current_team, false) )
else if ( find_it->is_visible_to_team(current_team, resources::gameboard->map(), false) )
{
// This hex is visibly occupied, so we cannot recruit here.
allow_local = false;
Expand Down Expand Up @@ -459,7 +459,7 @@ const std::vector<const unit*> get_recalls(int side, const map_location &recall_
add_leader_filtered_recalls(*find_it, result);
return result;
}
else if ( find_it->is_visible_to_team((*resources::teams)[side-1], false) )
else if ( find_it->is_visible_to_team((*resources::teams)[side-1], resources::gameboard->map(), false) )
{
// This hex is visibly occupied, so we cannot recall here.
allow_local = false;
Expand Down Expand Up @@ -852,7 +852,7 @@ namespace { // Helpers for place_recruit()

for ( unit_itor = units.begin(); unit_itor != units.end(); ++unit_itor ) {
if ((*resources::teams)[unit_itor->side()-1].is_enemy(new_unit.side()) &&
unit_itor->is_visible_to_team((*resources::teams)[new_unit.side()-1], false)) {
unit_itor->is_visible_to_team((*resources::teams)[new_unit.side()-1], resources::gameboard->map(), false)) {
int dist = distance_between(unit_itor->get_location(),recruit_loc) - unit_itor->level();
if (dist < min_dist) {
min_dist = dist;
Expand Down
2 changes: 1 addition & 1 deletion src/actions/heal.cpp
Expand Up @@ -353,7 +353,7 @@ void calculate_healing(int side, bool update_display)
const team & viewing_team =
(*resources::teams)[resources::screen->viewing_team()];
if (!recorder.is_skipping() && update_display &&
patient.is_visible_to_team(viewing_team, false) )
patient.is_visible_to_team(viewing_team, resources::gameboard->map(), false) )
{
unit_list.push_front(heal_unit(patient, healers, healing, curing == POISON_CURE));
}
Expand Down
4 changes: 2 additions & 2 deletions src/actions/move.cpp
Expand Up @@ -722,7 +722,7 @@ namespace { // Private helpers for move_unit()
unit_mover::route_iterator unit_mover::plot_turn(const route_iterator & start,
const route_iterator & stop)
{
const gamemap &map = *resources::game_map;
const gamemap &map = resources::gameboard->map();

// Handle null routes.
if ( start == stop )
Expand Down Expand Up @@ -1311,7 +1311,7 @@ bool unit_can_move(const unit &u)
return true;
}

if (u.movement_cost((*resources::game_map)[locs[n]]) <= u.movement_left()) {
if (u.movement_cost((resources::gameboard->map())[locs[n]]) <= u.movement_left()) {
return true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/actions/vision.cpp
Expand Up @@ -600,7 +600,7 @@ std::vector<int> get_sides_not_seeing(const unit & target)

size_t team_size = teams.size();
for ( size_t i = 0; i != team_size; ++i)
if ( !target.is_visible_to_team(teams[i], false) )
if ( !target.is_visible_to_team(teams[i], resources::gameboard->map(), false) )
// not_see contains side numbers; i is a team index, so add 1.
not_seeing.push_back(i+1);

Expand Down Expand Up @@ -646,7 +646,7 @@ bool actor_sighted(const unit & target, const std::vector<int> * cache)
needs_event[target.side()-1] = false;
// Exclude those teams that cannot see the target.
for ( size_t i = 0; i != teams_size; ++i )
needs_event[i] = needs_event[i] && target.is_visible_to_team(teams[i], false);
needs_event[i] = needs_event[i] && target.is_visible_to_team(teams[i], resources::gameboard->map(), false);

// Cache "jamming".
std::vector< std::map<map_location, int> > jamming_cache(teams_size);
Expand Down
2 changes: 1 addition & 1 deletion src/ai/actions.cpp
Expand Up @@ -364,7 +364,7 @@ bool move_result::test_route(const unit &un)
}

team &my_team = get_my_team();
const pathfind::shortest_path_calculator calc(un, my_team, *resources::teams, *resources::game_map);
const pathfind::shortest_path_calculator calc(un, my_team, *resources::teams, resources::gameboard->map());

//allowed teleports
pathfind::teleport_map allowed_teleports = pathfind::get_teleport_locations(un, my_team, true);///@todo 1.9: see_all -> false
Expand Down
4 changes: 2 additions & 2 deletions src/ai/default/ai.cpp
Expand Up @@ -288,7 +288,7 @@ struct protected_item {
class remove_wrong_targets {
public:
remove_wrong_targets(const readonly_context &context)
:avoid_(context.get_avoid()), map_(*resources::game_map)
:avoid_(context.get_avoid()), map_(resources::gameboard->map())
{
}

Expand Down Expand Up @@ -532,7 +532,7 @@ ai_default_recruitment_stage::~ai_default_recruitment_stage()
void ai_default_recruitment_stage::analyze_potential_recruit_movements()
{
const unit_map &units_ = *resources::units;
const gamemap &map_ = *resources::game_map;
const gamemap &map_ = resources::gameboard->map();

if(unit_movement_scores_.empty() == false ||
get_recruitment_ignore_bad_movement()) {
Expand Down
4 changes: 2 additions & 2 deletions src/ai/default/contexts.cpp
Expand Up @@ -98,7 +98,7 @@ default_ai_context& default_ai_context_impl::get_default_ai_context(){

int default_ai_context_impl::rate_terrain(const unit& u, const map_location& loc) const
{
const gamemap &map_ = *resources::game_map;
const gamemap &map_ = resources::gameboard->map();
const t_translation::t_terrain terrain = map_.get_terrain(loc);
const int defense = u.defense_modifier(terrain);
int rating = 100 - defense;
Expand Down Expand Up @@ -133,7 +133,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::iterator leader = units_.find_leader(get_side());
const gamemap &map_ = *resources::game_map;
const gamemap &map_ = resources::gameboard->map();
std::vector<team> teams_ = *resources::teams;
const bool has_leader = leader != units_.end();

Expand Down
4 changes: 2 additions & 2 deletions src/ai/formula/ai.cpp
Expand Up @@ -179,7 +179,7 @@ pathfind::plain_route formula_ai::shortest_path_calculator(const map_location &s
map_location destination = dst;

unit_map &units_ = *resources::units;
pathfind::shortest_path_calculator calc(*unit_it, current_team(), *resources::teams, *resources::game_map);
pathfind::shortest_path_calculator calc(*unit_it, current_team(), *resources::teams, resources::gameboard->map());

unit_map::const_iterator dst_un = units_.find(destination);

Expand Down Expand Up @@ -822,7 +822,7 @@ variant formula_ai::get_value(const std::string& key) const
return get_keeps();
} else if(key == "map")
{
return variant(new gamemap_callable(*resources::game_map));
return variant(new gamemap_callable(resources::gameboard->map()));
} else if(key == "villages")
{
return villages_from_set(resources::gameboard->map().villages());
Expand Down
24 changes: 12 additions & 12 deletions src/ai/formula/function_table.cpp
Expand Up @@ -200,7 +200,7 @@ class calculate_map_ownership_function : public function_expression {
{
const std::set<map_location>& teleports = allow_teleport ? ai_.current_team().villages() : std::set<map_location>();

const gamemap& map = *resources::game_map;
const gamemap& map = resources::gameboard->map();

std::vector<map_location> locs(6 + teleports.size());
std::copy(teleports.begin(), teleports.end(), locs.begin() + 6);
Expand Down Expand Up @@ -296,7 +296,7 @@ class calculate_map_ownership_function : public function_expression {
// for(unit_map::const_iterator i = resources::units->begin(); i != resources::units->end(); ++i) {
// unit_counter[i->second.side()-1]++;
// unit_adapter unit(i->second);
// find_movemap( *resources::game_map, *resources::units, unit, i->first, scores[i->second.side()-1], ai_.*resources::teams , true );
// find_movemap( resources::gameboard->map(), *resources::units, unit, i->first, scores[i->second.side()-1], ai_.*resources::teams , true );
// }

for(size_t side = 0 ; side < units_input.num_elements() ; ++side) {
Expand Down Expand Up @@ -1145,7 +1145,7 @@ class simplest_path_function : public function_expression {

pathfind::teleport_map allowed_teleports = ai_.get_allowed_teleports(unit_it);

pathfind::emergency_path_calculator em_calc(*unit_it, *resources::game_map);
pathfind::emergency_path_calculator em_calc(*unit_it, resources::gameboard->map());

pathfind::plain_route route = pathfind::a_star_search(src, dst, 1000.0, &em_calc, resources::gameboard->map().w(), resources::gameboard->map().h(), &allowed_teleports);

Expand All @@ -1154,7 +1154,7 @@ class simplest_path_function : public function_expression {
}

for (std::vector<map_location>::const_iterator loc_iter = route.steps.begin() + 1 ; loc_iter !=route.steps.end(); ++loc_iter) {
if (unit_it->movement_cost((*resources::game_map)[*loc_iter]) < movetype::UNREACHABLE )
if (unit_it->movement_cost((resources::gameboard->map())[*loc_iter]) < movetype::UNREACHABLE )
locations.push_back( variant( new location_callable(*loc_iter) ));
else
break;
Expand Down Expand Up @@ -1523,28 +1523,28 @@ class defense_on_function : public function_expression {
{
const unit& un = u_call->get_unit();

if( un.total_movement() < un.movement_cost( (*resources::game_map)[loc]) )
if( un.total_movement() < un.movement_cost( (resources::gameboard->map())[loc]) )
return variant();

if(!resources::gameboard->map().on_board(loc)) {
return variant();
}

return variant(100 - un.defense_modifier((*resources::game_map)[loc]));
return variant(100 - un.defense_modifier((resources::gameboard->map())[loc]));
}

if (u_type)
{
const unit_type& un = u_type->get_unit_type();

if( un.movement() < un.movement_type().movement_cost((*resources::game_map)[loc]) )
if( un.movement() < un.movement_type().movement_cost((resources::gameboard->map())[loc]) )
return variant();

if(!resources::gameboard->map().on_board(loc)) {
return variant();
}

return variant(100 - un.movement_type().defense_modifier((*resources::game_map)[loc]));
return variant(100 - un.movement_type().defense_modifier((resources::gameboard->map())[loc]));
}

return variant();
Expand Down Expand Up @@ -1577,7 +1577,7 @@ class chance_to_hit_function : public function_expression {
return variant();
}

return variant(un.defense_modifier((*resources::game_map)[loc]));
return variant(un.defense_modifier((resources::gameboard->map())[loc]));
}

if (u_type)
Expand All @@ -1588,7 +1588,7 @@ class chance_to_hit_function : public function_expression {
return variant();
}

return variant(un.movement_type().defense_modifier((*resources::game_map)[loc]));
return variant(un.movement_type().defense_modifier((resources::gameboard->map())[loc]));
}

return variant();
Expand Down Expand Up @@ -1621,7 +1621,7 @@ class movement_cost_function : public function_expression {
return variant();
}

return variant(un.movement_cost((*resources::game_map)[loc]));
return variant(un.movement_cost((resources::gameboard->map())[loc]));
}

if (u_type)
Expand All @@ -1632,7 +1632,7 @@ class movement_cost_function : public function_expression {
return variant();
}

return variant(un.movement_type().movement_cost((*resources::game_map)[loc]));
return variant(un.movement_type().movement_cost((resources::gameboard->map())[loc]));
}

return variant();
Expand Down
10 changes: 5 additions & 5 deletions src/ai/recruitment/recruitment.cpp
Expand Up @@ -197,7 +197,7 @@ void recruitment::execute() {
*/

const unit_map& units = *resources::units;
const gamemap& map = *resources::game_map;
const gamemap& map = resources::gameboard->map();
const std::vector<unit_map::const_iterator> leaders = units.find_leaders(get_side());

// This is the central datastructure with all score_tables in it.
Expand Down Expand Up @@ -600,7 +600,7 @@ void recruitment::compare_cost_maps_and_update_important_hexes(
const pathfind::full_cost_map& my_cost_map,
const pathfind::full_cost_map& enemy_cost_map) {

const gamemap& map = *resources::game_map;
const gamemap& map = resources::gameboard->map();

// First collect all hexes where the average costs are similar in important_hexes_candidates
// Then chose only those hexes where the average costs are relatively low.
Expand Down Expand Up @@ -746,7 +746,7 @@ void recruitment::update_average_lawful_bonus() {
*/
void recruitment::update_average_local_cost() {
average_local_cost_.clear();
const gamemap& map = *resources::game_map;
const gamemap& map = resources::gameboard->map();
const team& team = (*resources::teams)[get_side() - 1];

for(int x = 0; x < map.w(); ++x) {
Expand Down Expand Up @@ -780,7 +780,7 @@ void recruitment::update_important_hexes() {
own_units_in_combat_counter_ = 0;

update_average_local_cost();
const gamemap& map = *resources::game_map;
const gamemap& map = resources::gameboard->map();
const unit_map& units = *resources::units;

// Mark battle areas as important
Expand Down Expand Up @@ -1442,7 +1442,7 @@ double recruitment::get_estimated_unit_gain() const {
* Guess how many villages we will gain over the next turns per turn.
*/
double recruitment::get_estimated_village_gain() const {
const gamemap& map = *resources::game_map;
const gamemap& map = resources::gameboard->map();
int neutral_villages = 0;
BOOST_FOREACH(const map_location& village, map.villages()) {
if (village_owner(village) == -1) {
Expand Down
5 changes: 3 additions & 2 deletions src/ai/testing/aspect_attacks.cpp
Expand Up @@ -21,6 +21,7 @@

#include "../manager.hpp"
#include "../../actions/attack.hpp"
#include "../../game_board.hpp"
#include "../../log.hpp"
#include "../../map.hpp"
#include "../../team.hpp"
Expand Down Expand Up @@ -136,7 +137,7 @@ void aspect_attacks::do_attack_analysis(
//std::cerr << "ANALYSIS " << cur_analysis.movements.size() << " >= " << get_attack_depth() << "\n";
return;
}
const gamemap &map_ = *resources::game_map;
const gamemap &map_ = resources::gameboard->map();
unit_map &units_ = *resources::units;
std::vector<team> &teams_ = *resources::teams;

Expand Down Expand Up @@ -359,7 +360,7 @@ void aspect_attacks::do_attack_analysis(

int aspect_attacks::rate_terrain(const unit& u, const map_location& loc)
{
const gamemap &map_ = *resources::game_map;
const gamemap &map_ = resources::gameboard->map();
const t_translation::t_terrain terrain = map_.get_terrain(loc);
const int defense = u.defense_modifier(terrain);
int rating = 100 - defense;
Expand Down
14 changes: 7 additions & 7 deletions src/ai/testing/ca.cpp
Expand Up @@ -64,7 +64,7 @@ double goto_phase::evaluate()
// Execute goto-movements - first collect gotos in a list
std::vector<map_location> gotos;
unit_map &units_ = *resources::units;
const gamemap &map_ = *resources::game_map;
const gamemap &map_ = resources::gameboard->map();

for(unit_map::iterator ui = units_.begin(); ui != units_.end(); ++ui) {
if (ui->get_goto() == ui->get_location()) {
Expand All @@ -82,7 +82,7 @@ double goto_phase::evaluate()
}
// end of passive_leader

const pathfind::shortest_path_calculator calc(*ui, current_team(), *resources::teams, *resources::game_map);
const pathfind::shortest_path_calculator calc(*ui, current_team(), *resources::teams, resources::gameboard->map());

const pathfind::teleport_map allowed_teleports = pathfind::get_teleport_locations(*ui, current_team());

Expand Down Expand Up @@ -223,7 +223,7 @@ void recruitment_phase::execute()
unit_movement_scores_.clear();

const unit_map &units_ = *resources::units;
const gamemap &map_ = *resources::game_map;
const gamemap &map_ = resources::gameboard->map();
const std::vector<team> &teams_ = *resources::teams;

map_location start_pos = units_.find_leader(get_side())->get_location();
Expand Down Expand Up @@ -688,7 +688,7 @@ double move_leader_to_goals_phase::evaluate()
}
}

pathfind::shortest_path_calculator calc(*leader, current_team(), *resources::teams, *resources::game_map);
pathfind::shortest_path_calculator calc(*leader, current_team(), *resources::teams, resources::gameboard->map());
pathfind::plain_route route = a_star_search(leader->get_location(), dst_, 1000.0, &calc,
resources::gameboard->map().w(), resources::gameboard->map().h());
if(route.steps.empty()) {
Expand Down Expand Up @@ -803,7 +803,7 @@ double move_leader_to_keep_phase::evaluate()
continue;
}

const pathfind::shortest_path_calculator calc(*leader, current_team(), *resources::teams, *resources::game_map);
const pathfind::shortest_path_calculator calc(*leader, current_team(), *resources::teams, resources::gameboard->map());

const pathfind::teleport_map allowed_teleports = pathfind::get_teleport_locations(*leader, current_team());

Expand All @@ -825,7 +825,7 @@ double move_leader_to_keep_phase::evaluate()
const unit* leader = best_leader;
const map_location keep = best_keep;
const pathfind::paths leader_paths(*leader, false, true, current_team());
const pathfind::shortest_path_calculator calc(*leader, current_team(), *resources::teams, *resources::game_map);
const pathfind::shortest_path_calculator calc(*leader, current_team(), *resources::teams, resources::gameboard->map());
const pathfind::teleport_map allowed_teleports = pathfind::get_teleport_locations(*leader, current_team());

if (leader_paths.destinations.contains(keep) && units_.count(keep) == 0) {
Expand Down Expand Up @@ -1046,7 +1046,7 @@ void get_villages_phase::find_villages(
const bool passive_leader = get_passive_leader();

size_t min_distance = 100000;
const gamemap &map_ = *resources::game_map;
const gamemap &map_ = resources::gameboard->map();
std::vector<team> &teams_ = *resources::teams;

// When a unit is dispatched we need to make sure we don't
Expand Down

0 comments on commit aab7edd

Please sign in to comment.