Skip to content

Commit

Permalink
finish removing resources::game_map
Browse files Browse the repository at this point in the history
The remaining uses are just, checking whether or not the pointer
is null, or resets to its value, or simply storing it in a local
variable.

It might be appropriate to add resources::game_map back as a
function taking no parameters, at least this is flexible
enough to be changed later easily.
  • Loading branch information
cbeck88 committed Jun 11, 2014
1 parent aab7edd commit 22cc827
Show file tree
Hide file tree
Showing 11 changed files with 13 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/actions/create.cpp
Expand Up @@ -844,15 +844,15 @@ namespace { // Helpers for place_recruit()
const map_location &recruit_loc, const map_location &leader_loc)
{
// Find closest enemy and turn towards it (level 2s count more than level 1s, etc.)
const gamemap *map = resources::game_map;
const gamemap *map = & resources::gameboard->map();
const unit_map & units = *resources::units;
unit_map::const_iterator unit_itor;
map_location min_loc;
int min_dist = INT_MAX;

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], resources::gameboard->map(), false)) {
unit_itor->is_visible_to_team((*resources::teams)[new_unit.side()-1], *map, false)) {
int dist = distance_between(unit_itor->get_location(),recruit_loc) - unit_itor->level();
if (dist < min_dist) {
min_dist = dist;
Expand Down
1 change: 0 additions & 1 deletion src/editor/editor_controller.cpp
Expand Up @@ -152,7 +152,6 @@ void editor_controller::init_music(const config& game_config)

editor_controller::~editor_controller()
{
resources::game_map = NULL;
resources::units = NULL;
resources::tod_manager = NULL;
resources::teams = NULL;
Expand Down
1 change: 0 additions & 1 deletion src/editor/map/context_manager.cpp
Expand Up @@ -75,7 +75,6 @@ class map_context_refresher
void refresh() {
context_manager_.gui().change_display_context(&context_manager_.get_map_context());

resources::game_map = &context_manager_.get_map();
resources::units = &context_manager_.get_map_context().get_units();
resources::teams = &context_manager_.get_map_context().get_teams();

Expand Down
4 changes: 2 additions & 2 deletions src/game_events/action_wml.cpp
Expand Up @@ -288,7 +288,7 @@ namespace { // Support functions

std::vector<map_location> fake_unit_path(const unit& fake_unit, const std::vector<std::string>& xvals, const std::vector<std::string>& yvals)
{
const gamemap *game_map = resources::game_map;
const gamemap *game_map = & resources::gameboard->map();
std::vector<map_location> path;
map_location src;
map_location dst;
Expand Down Expand Up @@ -1680,7 +1680,7 @@ WML_HANDLER_FUNCTION(replace_map, /*event_info*/, cfg)
* easier to do this as wanted by the author in WML.
*/

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

try {
Expand Down
4 changes: 2 additions & 2 deletions src/help.cpp
Expand Up @@ -1662,7 +1662,7 @@ class unit_topic_generator: public topic_generator
}
ss << generate_table(resistance_table);

if (resources::game_map != NULL) {
if (resources::gameboard != NULL) {
// Print the terrain modifier table of the unit.
ss << "\n\n<header>text='" << escape(_("Terrain Modifiers"))
<< "'</header>\n\n";
Expand Down Expand Up @@ -1900,7 +1900,7 @@ void generate_races_sections(const config *help_cfg, section &sec, int level)

void generate_terrain_sections(const config* /*help_cfg*/, section& sec, int /*level*/)
{
if (resources::game_map == NULL) return;
if (resources::gameboard == NULL) return;

std::map<std::string, section> base_map;

Expand Down
3 changes: 2 additions & 1 deletion src/map_location.cpp
Expand Up @@ -25,6 +25,7 @@

#include "config.hpp"
#include "formula_string_utils.hpp"
#include "game_board.hpp"
#include "map.hpp"
#include "resources.hpp"
#include "gettext.hpp"
Expand Down Expand Up @@ -317,7 +318,7 @@ std::vector<map_location> parse_location_range(const std::string &x, const std::
std::vector<map_location> res;
const std::vector<std::string> xvals = utils::split(x);
const std::vector<std::string> yvals = utils::split(y);
const gamemap *map = resources::game_map;
const gamemap *map = & resources::gameboard->map();
assert(map);
int xmin = 1, xmax = map->w(), ymin = 1, ymax = map->h();
if (with_border) {
Expand Down
2 changes: 0 additions & 2 deletions src/play_controller.cpp
Expand Up @@ -75,7 +75,6 @@ static void clear_resources()
resources::controller = NULL;
resources::gameboard = NULL;
resources::gamedata = NULL;
resources::game_map = NULL;
resources::persist = NULL;
resources::screen = NULL;
resources::soundsources = NULL;
Expand Down Expand Up @@ -143,7 +142,6 @@ play_controller::play_controller(const config& level, game_state& state_of_game,
resources::controller = this;
resources::gameboard = &gameboard_;
resources::gamedata = &gamedata_;
resources::game_map = &gameboard_.map_;
resources::persist = &persist_;
resources::teams = &gameboard_.teams_;
resources::tod_manager = &tod_manager_;
Expand Down
1 change: 0 additions & 1 deletion src/resources.cpp
Expand Up @@ -21,7 +21,6 @@ namespace resources
game_config_manager *config_manager = NULL;
play_controller *controller = NULL;
game_data *gamedata = NULL;
const gamemap *game_map = NULL;
LuaKernel *lua_kernel = NULL;
persist_manager *persist = NULL;
game_display *screen = NULL;
Expand Down
1 change: 0 additions & 1 deletion src/resources.hpp
Expand Up @@ -44,7 +44,6 @@ namespace resources
extern play_controller *controller;
extern game_board *gameboard;
extern game_data *gamedata;
extern const gamemap *game_map;
extern LuaKernel *lua_kernel; // Set by game_events::manager.
extern persist_manager *persist;
extern game_classification *classification;
Expand Down
8 changes: 4 additions & 4 deletions src/unit.cpp
Expand Up @@ -1323,7 +1323,7 @@ bool unit::internal_matches_filter(const vconfig& cfg, const map_location& loc,
}

if(cfg.has_child("filter_location")) {
assert(resources::game_map != NULL);
assert(resources::gameboard != NULL);
assert(resources::teams != NULL);
assert(resources::tod_manager != NULL);
assert(resources::units != NULL);
Expand All @@ -1347,8 +1347,8 @@ bool unit::internal_matches_filter(const vconfig& cfg, const map_location& loc,
if (!cfg_x.blank() || !cfg_y.blank()){
if(cfg_x == "recall" && cfg_y == "recall") {
//locations on the map are considered to not be on a recall list
if ((!resources::game_map && loc.valid()) ||
(resources::game_map && resources::gameboard->map().on_board(loc)))
if ((!resources::gameboard && loc.valid()) ||
(resources::gameboard && resources::gameboard->map().on_board(loc)))
{
return false;
}
Expand Down Expand Up @@ -1590,7 +1590,7 @@ bool unit::internal_matches_filter(const vconfig& cfg, const map_location& loc,
}

if (cfg.has_child("filter_adjacent")) {
assert(resources::units && resources::game_map);
assert(resources::units && resources::gameboard);
const unit_map& units = *resources::units;
map_location adjacent[6];
get_adjacent_tiles(loc, adjacent);
Expand Down
2 changes: 1 addition & 1 deletion src/unit_abilities.cpp
Expand Up @@ -292,7 +292,7 @@ std::vector<boost::tuple<t_string,t_string,t_string> > unit::ability_tooltips(st
bool unit::ability_active(const std::string& ability,const config& cfg,const map_location& loc) const
{
bool illuminates = ability == "illuminates";
assert(resources::units && resources::game_map && resources::teams && resources::tod_manager);
assert(resources::units && resources::gameboard && resources::teams && resources::tod_manager);

if (const config &afilter = cfg.child("filter"))
if ( !matches_filter(vconfig(afilter), loc, illuminates) )
Expand Down

0 comments on commit 22cc827

Please sign in to comment.