Skip to content

Commit

Permalink
partially remove resources::game_map (part 1)
Browse files Browse the repository at this point in the history
This is the result of running, in src/ directory, the following:

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

and carefully inspecting the result, and adding "game_board.hpp"
  • Loading branch information
cbeck88 committed Jun 11, 2014
1 parent 3c93463 commit 4830b8e
Show file tree
Hide file tree
Showing 29 changed files with 169 additions and 158 deletions.
4 changes: 2 additions & 2 deletions src/actions/attack.cpp
Expand Up @@ -134,7 +134,7 @@ battle_context_unit_stats::battle_context_unit_stats(const unit &u,
// Handle plague.
unit_ability_list plague_specials = weapon->get_specials("plague");
plagues = !opp.get_state("unplagueable") && !plague_specials.empty() &&
strcmp(opp.undead_variation().c_str(), "null") && !resources::game_map->is_village(opp_loc);
strcmp(opp.undead_variation().c_str(), "null") && !resources::gameboard->map().is_village(opp_loc);

if (plagues) {
plague_type = (*plague_specials.front().first)["type"].str();
Expand All @@ -144,7 +144,7 @@ battle_context_unit_stats::battle_context_unit_stats(const unit &u,

// Compute chance to hit.
chance_to_hit = opp.defense_modifier(
resources::game_map->get_terrain(opp_loc)) + weapon->accuracy() -
resources::gameboard->map().get_terrain(opp_loc)) + weapon->accuracy() -
(opp_weapon ? opp_weapon->parry() : 0);
if(chance_to_hit > 100) {
chance_to_hit = 100;
Expand Down
20 changes: 10 additions & 10 deletions src/actions/create.cpp
Expand Up @@ -161,13 +161,13 @@ map_location unit_creator::find_location(const config &cfg, const unit* pass_che
loc = map_location(cfg,resources::gamedata);
}

if(loc.valid() && resources::game_map->on_board(loc)) {
if(loc.valid() && resources::gameboard->map().on_board(loc)) {
const bool pass((place == "leader_passable") || (place == "map_passable"));
if ( place != "map_overwrite" ) {
loc = find_vacant_tile(loc, pathfind::VACANT_ANY,
pass ? pass_check : NULL);
}
if(loc.valid() && resources::game_map->on_board(loc)) {
if(loc.valid() && resources::gameboard->map().on_board(loc)) {
return loc;
}
}
Expand Down Expand Up @@ -239,7 +239,7 @@ void unit_creator::post_create(const map_location &loc, const unit &new_unit, bo
bool animate = show && anim;

if (get_village_) {
if (resources::game_map->is_village(loc)) {
if (resources::gameboard->map().is_village(loc)) {
actions::get_village(loc, new_unit.side());
}
}
Expand Down Expand Up @@ -344,15 +344,15 @@ const std::set<std::string> get_recruits(int side, const map_location &recruit_l
u_end = resources::units->end();

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


// Check for a leader at recruit_loc (means we are recruiting from there,
// rather than to there).
unit_map::const_iterator find_it = resources::units->find(recruit_loc);
if ( find_it != u_end ) {
if ( find_it->can_recruit() && find_it->side() == side &&
resources::game_map->is_keep(recruit_loc) )
resources::gameboard->map().is_keep(recruit_loc) )
{
// We have been requested to get the recruit list for this
// particular leader.
Expand Down Expand Up @@ -444,15 +444,15 @@ const std::vector<const unit*> get_recalls(int side, const map_location &recall_
*/

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


// Check for a leader at recall_loc (means we are recalling from there,
// rather than to there).
unit_map::const_iterator find_it = resources::units->find(recall_loc);
if ( find_it != resources::units->end() ) {
if ( find_it->can_recruit() && find_it->side() == side &&
resources::game_map->is_keep(recall_loc) )
resources::gameboard->map().is_keep(recall_loc) )
{
// We have been requested to get the recalls for this
// particular leader.
Expand Down Expand Up @@ -523,7 +523,7 @@ namespace { // Helpers for check_recall_location()
return RECRUIT_NO_ABLE_LEADER;

// Make sure the unit is on a keep.
if ( !resources::game_map->is_keep(recaller.get_location()) )
if ( !resources::gameboard->map().is_keep(recaller.get_location()) )
return RECRUIT_NO_KEEP_LEADER;

// Make sure there is a permissible location to which to recruit.
Expand Down Expand Up @@ -653,7 +653,7 @@ namespace { // Helpers for check_recruit_location()
}

// Make sure the unit is on a keep.
if ( !resources::game_map->is_keep(recruiter.get_location()) )
if ( !resources::gameboard->map().is_keep(recruiter.get_location()) )
return RECRUIT_NO_KEEP_LEADER;

// Make sure there is a permissible location to which to recruit.
Expand Down Expand Up @@ -932,7 +932,7 @@ bool place_recruit(const unit &u, const map_location &recruit_location, const ma
}

// Village capturing.
if ( resources::game_map->is_village(current_loc) ) {
if ( resources::gameboard->map().is_village(current_loc) ) {
mutated |= actions::get_village(current_loc, new_unit_itor->side());
if ( !validate_recruit_iterator(new_unit_itor, current_loc) )
return true;
Expand Down
5 changes: 3 additions & 2 deletions src/actions/heal.cpp
Expand Up @@ -19,6 +19,7 @@

#include "heal.hpp"

#include "../game_board.hpp"
#include "../game_display.hpp"
#include "../gettext.hpp"
#include "../log.hpp"
Expand Down Expand Up @@ -93,7 +94,7 @@ namespace {
if ( patient.side() == side )
{
// Village healing?
if ( resources::game_map->gives_healing(patient.get_location()) )
if ( resources::gameboard->map().gives_healing(patient.get_location()) )
return POISON_CURE;

// Regeneration?
Expand Down Expand Up @@ -191,7 +192,7 @@ namespace {
{
// Village healing?
update_healing(healing, harming,
resources::game_map->gives_healing(patient.get_location()));
resources::gameboard->map().gives_healing(patient.get_location()));

// Regeneration?
unit_ability_list regen_list = patient.get_abilities("regenerate");
Expand Down
6 changes: 3 additions & 3 deletions src/actions/move.cpp
Expand Up @@ -564,7 +564,7 @@ namespace { // Private helpers for move_unit()
return false;

// We can reasonably stop if the hex is not an unowned village.
return !resources::game_map->is_village(hex) ||
return !resources::gameboard->map().is_village(hex) ||
current_team_->owns_village(hex);
}

Expand Down Expand Up @@ -1048,7 +1048,7 @@ namespace { // Private helpers for move_unit()
move_it_->set_movement(0, true);

// Village capturing.
if ( resources::game_map->is_village(final_loc) ) {
if ( resources::gameboard->map().is_village(final_loc) ) {
// Is this a capture?
orig_village_owner = village_owner(final_loc);
if ( orig_village_owner != current_side_-1 ) {
Expand Down Expand Up @@ -1304,7 +1304,7 @@ bool unit_can_move(const unit &u)
map_location locs[6];
get_adjacent_tiles(u.get_location(), locs);
for(int n = 0; n != 6; ++n) {
if (resources::game_map->on_board(locs[n])) {
if (resources::gameboard->map().on_board(locs[n])) {
const unit_map::const_iterator i = resources::units->find(locs[n]);
if (i.valid() && !i->incapacitated() &&
current_team.is_enemy(i->side())) {
Expand Down
4 changes: 2 additions & 2 deletions src/actions/undo.cpp
Expand Up @@ -720,7 +720,7 @@ bool undo_list::move_action::undo(int side, undo_list & /*undos*/)
return false;
}

if ( resources::game_map->is_village(rev_route.front()) ) {
if ( resources::gameboard->map().is_village(rev_route.front()) ) {
get_village(rev_route.front(), original_village_owner + 1);
//MP_COUNTDOWN take away capture bonus
if ( countdown_time_bonus )
Expand Down Expand Up @@ -964,7 +964,7 @@ bool undo_list::move_action::redo(int side)
u->set_movement(saved_moves, true);
u->set_standing();

if ( resources::game_map->is_village(route.back()) ) {
if ( resources::gameboard->map().is_village(route.back()) ) {
get_village(route.back(), u->side());
//MP_COUNTDOWN restore capture bonus
if ( countdown_time_bonus )
Expand Down
6 changes: 3 additions & 3 deletions src/ai/actions.cpp
Expand Up @@ -370,7 +370,7 @@ bool move_result::test_route(const unit &un)
pathfind::teleport_map allowed_teleports = pathfind::get_teleport_locations(un, my_team, true);///@todo 1.9: see_all -> false

//do an A*-search
route_ = boost::shared_ptr<pathfind::plain_route>( new pathfind::plain_route(pathfind::a_star_search(un.get_location(), to_, 10000.0, &calc, resources::game_map->w(), resources::game_map->h(), &allowed_teleports)));
route_ = boost::shared_ptr<pathfind::plain_route>( new pathfind::plain_route(pathfind::a_star_search(un.get_location(), to_, 10000.0, &calc, resources::gameboard->map().w(), resources::gameboard->map().h(), &allowed_teleports)));
if (route_->steps.empty()) {
set_error(E_NO_ROUTE);
return false;
Expand Down Expand Up @@ -565,7 +565,7 @@ void recall_result::do_check_before()

void recall_result::do_check_after()
{
if (!resources::game_map->on_board(recall_location_)){
if (!resources::gameboard->map().on_board(recall_location_)){
set_error(AI_ACTION_FAILURE);
return;
}
Expand Down Expand Up @@ -709,7 +709,7 @@ void recruit_result::do_check_before()

void recruit_result::do_check_after()
{
if (!resources::game_map->on_board(recruit_location_)) {
if (!resources::gameboard->map().on_board(recruit_location_)) {
set_error(AI_ACTION_FAILURE);
return;
}
Expand Down
19 changes: 10 additions & 9 deletions src/ai/akihara/recruitment.cpp
Expand Up @@ -23,6 +23,7 @@

#include "../../actions/attack.hpp"
#include "../../attack_prediction.hpp"
#include "../../game_board.hpp"
#include "../../resources.hpp"
#include "../../log.hpp"
#include "../../map.hpp"
Expand Down Expand Up @@ -60,11 +61,11 @@ field_couple::field_couple(const map_location& first, const map_location& second
number(1) {
first_location.first = first.x;
first_location.second = first.y;
first_field_type = resources::game_map->get_terrain_string(first);
first_field_type = resources::gameboard->map().get_terrain_string(first);

second_location.first = second.x;
second_location.second = second.y;
second_field_type = resources::game_map->get_terrain_string(second);
second_field_type = resources::gameboard->map().get_terrain_string(second);

}

Expand All @@ -82,11 +83,11 @@ void terrain_analyze::analyze() {
}

void terrain_analyze::search() {
for (int x = 0; x < resources::game_map->w(); x++) {
for(int y = 0; y < resources::game_map->h(); y++) {
for (int x = 0; x < resources::gameboard->map().w(); x++) {
for(int y = 0; y < resources::gameboard->map().h(); y++) {
const map_location loc(x,y);
if (resources::game_map->is_keep(loc)) {
} else if (resources::game_map->is_village(loc)) {
if (resources::gameboard->map().is_keep(loc)) {
} else if (resources::gameboard->map().is_village(loc)) {
village_location_.push_back(loc);
}
}
Expand Down Expand Up @@ -123,8 +124,8 @@ void terrain_analyze::add_terrain(const std::string& terrain) {

void terrain_analyze::add_village_battle(const map_location& village, const map_location& adj) {
// If the battle is already stored, increment the number
std::string village_field = resources::game_map->get_terrain_string(village);
std::string adj_field = resources::game_map->get_terrain_string(adj);
std::string village_field = resources::gameboard->map().get_terrain_string(village);
std::string adj_field = resources::gameboard->map().get_terrain_string(adj);

BOOST_FOREACH(field_couple &couple, couple_field_list_) {
if (compareFieldCouple(couple, village_field, adj_field)) {
Expand Down Expand Up @@ -380,7 +381,7 @@ double recruitment::evaluate()
const map_location &keep = leader->get_location();
checked_hexes.insert(keep);

if (resources::game_map->is_keep(leader->get_location()) && count_free_hexes_in_castle(leader->get_location(), checked_hexes) != 0) {
if (resources::gameboard->map().is_keep(leader->get_location()) && count_free_hexes_in_castle(leader->get_location(), checked_hexes) != 0) {
return get_score();
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/ai/contexts.cpp
Expand Up @@ -414,7 +414,7 @@ void readonly_context_impl::calculate_moves(const unit_map& units, std::map<map_
bool friend_owns = false;

// Don't take friendly villages
if(!enemy && resources::game_map->is_village(dst)) {
if(!enemy && resources::gameboard->map().is_village(dst)) {
for(size_t n = 0; n != resources::teams->size(); ++n) {
if((*resources::teams)[n].owns_village(dst)) {
int side = n + 1;
Expand Down Expand Up @@ -489,7 +489,7 @@ const defensive_position& readonly_context_impl::best_defensive_position(const m
typedef move_map::const_iterator Itor;
const std::pair<Itor,Itor> itors = srcdst.equal_range(loc);
for(Itor i = itors.first; i != itors.second; ++i) {
const int defense = itor->defense_modifier(resources::game_map->get_terrain(i->second));
const int defense = itor->defense_modifier(resources::gameboard->map().get_terrain(i->second));
if(defense > pos.chance_to_hit) {
continue;
}
Expand Down Expand Up @@ -1260,7 +1260,7 @@ void readonly_context_impl::set_src_dst_enemy_valid_lua()
}

const map_location& readonly_context_impl::suitable_keep(const map_location& leader_location, const pathfind::paths& leader_paths){
if (resources::game_map->is_keep(leader_location)) {
if (resources::gameboard->map().is_keep(leader_location)) {
return leader_location; //if leader already on keep, then return leader_location
}

Expand Down
9 changes: 5 additions & 4 deletions src/ai/default/ai.cpp
Expand Up @@ -25,6 +25,7 @@

#include "../../array.hpp"
#include "../../dialogs.hpp"
#include "../../game_board.hpp"
#include "../../game_events/pump.hpp"
#include "../../gamestatus.hpp"
#include "../../log.hpp"
Expand Down Expand Up @@ -320,7 +321,7 @@ int ai_default_recruitment_stage::average_resistance_against(const unit_type& a,
{
int weighting_sum = 0, defense = 0;
const std::map<t_translation::t_terrain, size_t>& terrain =
resources::game_map->get_weighted_terrain_frequencies();
resources::gameboard->map().get_weighted_terrain_frequencies();

for (std::map<t_translation::t_terrain, size_t>::const_iterator j = terrain.begin(),
j_end = terrain.end(); j != j_end; ++j)
Expand Down Expand Up @@ -584,7 +585,7 @@ void ai_default_recruitment_stage::analyze_potential_recruit_movements()
for(std::vector<target>::const_iterator t = targets.begin(); t != targets.end(); ++t) {
LOG_AI << "analyzing '" << *i << "' getting to target...\n";
pathfind::plain_route route = a_star_search(start, t->loc, 100.0, &calc,
resources::game_map->w(), resources::game_map->h());
resources::gameboard->map().w(), resources::gameboard->map().h());

if (!route.steps.empty()) {
LOG_AI << "made it: " << route.move_cost << "\n";
Expand Down Expand Up @@ -826,7 +827,7 @@ bool ai_default_recruitment_stage::do_play_stage()
// We recruit the initial allocation of scouts
// based on how many neutral villages there are
// that are closer to us than to other keeps.
const std::vector<map_location>& villages = resources::game_map->villages();
const std::vector<map_location>& villages = resources::gameboard->map().villages();
for(std::vector<map_location>::const_iterator v = villages.begin(); v != villages.end(); ++v) {
const int owner = village_owner(*v);
if(owner == -1) {
Expand All @@ -835,7 +836,7 @@ bool ai_default_recruitment_stage::do_play_stage()
bool closest = true;
for(std::vector<team>::const_iterator i = resources::teams->begin(); i != resources::teams->end(); ++i) {
const int index = i - resources::teams->begin() + 1;
const map_location& loc = resources::game_map->starting_position(index);
const map_location& loc = resources::gameboard->map().starting_position(index);
if(loc != start_pos && distance_between(loc,*v) < distance) {
closest = false;
break;
Expand Down
3 changes: 2 additions & 1 deletion src/ai/default/contexts.cpp
Expand Up @@ -20,6 +20,7 @@

#include "contexts.hpp"

#include "../../game_board.hpp"
#include "../../log.hpp"
#include "../../map.hpp"
#include "../../resources.hpp"
Expand Down Expand Up @@ -74,7 +75,7 @@ int default_ai_context_impl::count_free_hexes_in_castle(const map_location &loc,
if (checked_hexes.find(adj[n]) != checked_hexes.end())
continue;
checked_hexes.insert(adj[n]);
if (resources::game_map->is_castle(adj[n])) {
if (resources::gameboard->map().is_castle(adj[n])) {
const unit_map::const_iterator u = units_.find(adj[n]);
ret += count_free_hexes_in_castle(adj[n], checked_hexes);
if (u == units_.end()
Expand Down

0 comments on commit 4830b8e

Please sign in to comment.