From df74d891d29a07a116e27fd004d7739b33c587b6 Mon Sep 17 00:00:00 2001 From: Chris Beck Date: Sun, 1 Jun 2014 10:04:07 -0400 Subject: [PATCH] give global fcn's (find/get)_visible_unit a home in game_board Unit tested and playtested after moving the functions decalarations, and definitions, adding links to play_controller::game_board from resources.?pp, and executing find and replace commands: git grep -lz 'find_visible_unit(' | xargs -0 perl -i'' -pE "s/find_visible_unit\(/resources::gameboard->find_visible_unit\(/g" git grep -lz 'get_visible_unit(' | xargs -0 perl -i'' -pE "s/get_visible_unit\(/resources::gameboard->get_visible_unit\(/g" --- src/actions/create.cpp | 3 +- src/actions/move.cpp | 2 +- src/actions/vision.cpp | 2 +- src/ai/contexts.cpp | 3 +- src/ai/testing/ca.cpp | 5 ++- src/game_board.cpp | 18 ++++++++ src/game_board.hpp | 4 ++ src/game_display.cpp | 13 +++--- src/menu_events.cpp | 4 +- src/mouse_events.cpp | 4 +- src/pathfind/pathfind.cpp | 7 +-- src/play_controller.cpp | 2 + src/reports.cpp | 92 ++++++++++++++++++++------------------ src/resources.cpp | 1 + src/resources.hpp | 2 + src/scripting/lua.cpp | 2 +- src/synced_commands.cpp | 2 +- src/unit.cpp | 20 --------- src/unit.hpp | 6 --- src/whiteboard/move.cpp | 2 +- src/whiteboard/utility.cpp | 2 +- 21 files changed, 103 insertions(+), 93 deletions(-) diff --git a/src/actions/create.cpp b/src/actions/create.cpp index b3df2944fbac..81e633e84d1f 100644 --- a/src/actions/create.cpp +++ b/src/actions/create.cpp @@ -25,6 +25,7 @@ #include "../config.hpp" #include "../config_assign.hpp" +#include "../game_board.hpp" #include "../game_display.hpp" #include "../game_events/pump.hpp" #include "../game_preferences.hpp" @@ -315,7 +316,7 @@ bool can_recruit_on(const map_location& leader_loc, const map_location& recruit_ if ( view_team.shrouded(recruit_loc) ) return false; - if ( get_visible_unit(recruit_loc, view_team) != NULL ) + if ( resources::gameboard->get_visible_unit(recruit_loc, view_team) != NULL ) return false; castle_cost_calculator calc(map, view_team); diff --git a/src/actions/move.cpp b/src/actions/move.cpp index 5a249b939263..514fa55f77b8 100644 --- a/src/actions/move.cpp +++ b/src/actions/move.cpp @@ -768,7 +768,7 @@ namespace { // Private helpers for move_unit() if ( !is_replay_ ) { // Avoiding stopping on a (known) unit. route_iterator min_end = start == begin_ ? start : start + 1; - while ( end != min_end && get_visible_unit(*(end-1), *current_team_) ) + while ( end != min_end && resources::gameboard->get_visible_unit(*(end-1), *current_team_) ) // Backtrack. --end; } diff --git a/src/actions/vision.cpp b/src/actions/vision.cpp index 754318dc4fb0..9fa1999a02df 100644 --- a/src/actions/vision.cpp +++ b/src/actions/vision.cpp @@ -284,7 +284,7 @@ bool shroud_clearer::clear_loc(team &tm, const map_location &loc, // Check for units? if ( result && check_units && loc != event_non_loc ) { // Uncovered a unit? - unit_map::const_iterator sight_it = find_visible_unit(loc, tm); + unit_map::const_iterator sight_it = resources::gameboard->find_visible_unit(loc, tm); if ( sight_it.valid() ) { record_sighting(*sight_it, loc, viewer_id, view_loc); diff --git a/src/ai/contexts.cpp b/src/ai/contexts.cpp index 1d22d9edb5a5..a50b039acc19 100644 --- a/src/ai/contexts.cpp +++ b/src/ai/contexts.cpp @@ -32,6 +32,7 @@ #include "../formula.hpp" #include "../formula_function.hpp" #include "../formula_fwd.hpp" +#include "../game_board.hpp" #include "../game_display.hpp" #include "../log.hpp" #include "../map.hpp" @@ -430,7 +431,7 @@ void readonly_context_impl::calculate_moves(const unit_map& units, std::mapend()) ) { + if(src != dst && (resources::gameboard->find_visible_unit(dst, current_team()) == resources::units->end()) ) { srcdst.insert(std::pair(src,dst)); dstsrc.insert(std::pair(dst,src)); } diff --git a/src/ai/testing/ca.cpp b/src/ai/testing/ca.cpp index 3e19201235a5..b5416db15dd2 100644 --- a/src/ai/testing/ca.cpp +++ b/src/ai/testing/ca.cpp @@ -23,6 +23,7 @@ #include "../composite/engine.hpp" #include "../composite/rca.hpp" #include "../composite/stage.hpp" +#include "../../game_board.hpp" #include "../../gamestatus.hpp" #include "../../log.hpp" #include "../../map.hpp" @@ -935,7 +936,7 @@ void get_villages_phase::execute() if(leader != units_.end() && leader->get_location() == i->second) { leader_move = *i; } else { - if (find_visible_unit(i->first, current_team()) == units_.end()) { + if (resources::gameboard->find_visible_unit(i->first, current_team()) == units_.end()) { move_result_ptr move_res = execute_move_action(i->second,i->first,true); if (!move_res->is_ok()) { return; @@ -961,7 +962,7 @@ void get_villages_phase::execute() } if(leader_move.second.valid()) { - if((find_visible_unit(leader_move.first , current_team()) == units_.end()) + if((resources::gameboard->find_visible_unit(leader_move.first , current_team()) == units_.end()) && resources::game_map->is_village(leader_move.first)) { move_result_ptr move_res = execute_move_action(leader_move.second,leader_move.first,true); if (!move_res->is_ok()) { diff --git a/src/game_board.cpp b/src/game_board.cpp index dda321b6de62..5fc2392b4311 100644 --- a/src/game_board.cpp +++ b/src/game_board.cpp @@ -41,6 +41,24 @@ void game_board::set_all_units_user_end_turn() { } } +unit_map::iterator game_board::find_visible_unit(const map_location &loc, + const team& current_team, bool see_all) +{ + if (!map_.on_board(loc)) return units_.end(); + unit_map::iterator u = units_.find(loc); + if (!u.valid() || !u->is_visible_to_team(current_team, see_all)) + return units_.end(); + return u; +} + +unit* game_board::get_visible_unit(const map_location &loc, + const team ¤t_team, bool see_all) +{ + unit_map::iterator ui = find_visible_unit(loc, current_team, see_all); + if (ui == units_.end()) return NULL; + return &*ui; +} + void game_board::write_config(config & cfg) const { for(std::vector::const_iterator t = teams_.begin(); t != teams_.end(); ++t) { int side_num = t - teams_.begin() + 1; diff --git a/src/game_board.hpp b/src/game_board.hpp index 9a2e49c66ee2..685ede5bcb15 100644 --- a/src/game_board.hpp +++ b/src/game_board.hpp @@ -58,6 +58,10 @@ class game_board { void end_turn(int pnum); void set_all_units_user_end_turn(); + // Global accessor from unit.hpp + + unit_map::iterator find_visible_unit(const map_location &loc, const team& current_team, bool see_all = false); + unit* get_visible_unit(const map_location &loc, const team ¤t_team, bool see_all = false); //TODO: can this not return a pointer? }; #endif diff --git a/src/game_display.cpp b/src/game_display.cpp index 3bebb05a3293..652c33ef6407 100644 --- a/src/game_display.cpp +++ b/src/game_display.cpp @@ -19,6 +19,7 @@ #include "global.hpp" +#include "game_board.hpp" #include "game_display.hpp" #include "gettext.hpp" #include "wesconfig.h" @@ -163,12 +164,12 @@ void game_display::highlight_hex(map_location hex) { wb::future_map future; /**< Lasts for whole method. */ - const unit *u = get_visible_unit(hex, (*teams_)[viewing_team()], !viewpoint_); + const unit *u = resources::gameboard->get_visible_unit(hex, (*teams_)[viewing_team()], !viewpoint_); if (u) { displayedUnitHex_ = hex; invalidate_unit(); } else { - u = get_visible_unit(mouseoverHex_, (*teams_)[viewing_team()], !viewpoint_); + u = resources::gameboard->get_visible_unit(mouseoverHex_, (*teams_)[viewing_team()], !viewpoint_); if (u) { // mouse moved from unit hex to non-unit hex if (units_->count(selectedHex_)) { @@ -190,7 +191,7 @@ void game_display::display_unit_hex(map_location hex) wb::future_map future; /**< Lasts for whole method. */ - const unit *u = get_visible_unit(hex, (*teams_)[viewing_team()], !viewpoint_); + const unit *u = resources::gameboard->get_visible_unit(hex, (*teams_)[viewing_team()], !viewpoint_); if (u) { displayedUnitHex_ = hex; invalidate_unit(); @@ -277,7 +278,7 @@ void game_display::draw_hex(const map_location& loc) if(on_map && loc == mouseoverHex_) { tdrawing_layer hex_top_layer = LAYER_MOUSEOVER_BOTTOM; - const unit *u = get_visible_unit(loc, (*teams_)[viewing_team()] ); + const unit *u = resources::gameboard->get_visible_unit(loc, (*teams_)[viewing_team()] ); if( u != NULL ) { hex_top_layer = LAYER_MOUSEOVER_TOP; } @@ -459,8 +460,8 @@ void game_display::draw_movement_info(const map_location& loc) // When out-of-turn, it's still interesting to check out the terrain defs of the selected unit else if (selectedHex_.valid() && loc == mouseoverHex_) { - const unit_map::const_iterator selectedUnit = find_visible_unit(selectedHex_,resources::teams->at(currentTeam_)); - const unit_map::const_iterator mouseoveredUnit = find_visible_unit(mouseoverHex_,resources::teams->at(currentTeam_)); + const unit_map::const_iterator selectedUnit = resources::gameboard->find_visible_unit(selectedHex_,resources::teams->at(currentTeam_)); + const unit_map::const_iterator mouseoveredUnit = resources::gameboard->find_visible_unit(mouseoverHex_,resources::teams->at(currentTeam_)); if(selectedUnit != units_->end() && mouseoveredUnit == units_->end()) { // Display the def% of this terrain int def = 100 - selectedUnit->defense_modifier(get_map().get_terrain(loc)); diff --git a/src/menu_events.cpp b/src/menu_events.cpp index eb5142571feb..115d68a74805 100644 --- a/src/menu_events.cpp +++ b/src/menu_events.cpp @@ -930,12 +930,12 @@ unit_map::iterator menu_handler::current_unit() { const mouse_handler& mousehandler = resources::controller->get_mouse_handler_base(); - unit_map::iterator res = find_visible_unit(mousehandler.get_last_hex(), + unit_map::iterator res = resources::gameboard->find_visible_unit(mousehandler.get_last_hex(), teams_[gui_->viewing_team()]); if(res != units_.end()) { return res; } else { - return find_visible_unit(mousehandler.get_selected_hex(), + return resources::gameboard->find_visible_unit(mousehandler.get_selected_hex(), teams_[gui_->viewing_team()]); } } diff --git a/src/mouse_events.cpp b/src/mouse_events.cpp index d5cba3c71080..df29028ae4ae 100644 --- a/src/mouse_events.cpp +++ b/src/mouse_events.cpp @@ -325,7 +325,7 @@ unit_map::iterator mouse_handler::selected_unit() unit_map::iterator mouse_handler::find_unit(const map_location& hex) { - unit_map::iterator it = find_visible_unit(hex, viewing_team()); + unit_map::iterator it = resources::gameboard->find_visible_unit(hex, viewing_team()); if (it.valid()) return it; else @@ -334,7 +334,7 @@ unit_map::iterator mouse_handler::find_unit(const map_location& hex) unit_map::const_iterator mouse_handler::find_unit(const map_location& hex) const { - return find_visible_unit(hex, viewing_team()); + return resources::gameboard->find_visible_unit(hex, viewing_team()); } map_location mouse_handler::current_unit_attacks_from(const map_location& loc) const diff --git a/src/pathfind/pathfind.cpp b/src/pathfind/pathfind.cpp index f7bf472870a3..413d60b218f4 100644 --- a/src/pathfind/pathfind.cpp +++ b/src/pathfind/pathfind.cpp @@ -23,6 +23,7 @@ #include "pathfind/pathfind.hpp" #include "pathfind/teleport.hpp" +#include "game_board.hpp" #include "game_display.hpp" #include "gettext.hpp" #include "log.hpp" @@ -140,7 +141,7 @@ bool enemy_zoc(team const ¤t_team, map_location const &loc, get_adjacent_tiles(loc,locs); for (int i = 0; i != 6; ++i) { - const unit *u = get_visible_unit(locs[i], viewing_team, see_all); + const unit *u = resources::gameboard->get_visible_unit(locs[i], viewing_team, see_all); if ( u && current_team.is_enemy(u->side()) && u->emits_zoc() ) return true; } @@ -388,7 +389,7 @@ static void find_routes( if ( current_team ) { // Account for enemy units. - const unit *v = get_visible_unit(next_hex, *viewing_team, see_all); + const unit *v = resources::gameboard->get_visible_unit(next_hex, *viewing_team, see_all); if ( v && current_team->is_enemy(v->side()) ) { // Cannot enter enemy hexes. if ( edges != NULL ) @@ -719,7 +720,7 @@ double shortest_path_calculator::cost(const map_location& loc, const double so_f int other_unit_subcost = 0; if (!ignore_unit_) { const unit *other_unit = - get_visible_unit(loc, viewing_team_, see_all_); + resources::gameboard->get_visible_unit(loc, viewing_team_, see_all_); // We can't traverse visible enemy and we also prefer empty hexes // (less blocking in multi-turn moves and better when exploring fog, diff --git a/src/play_controller.cpp b/src/play_controller.cpp index ef073dfce0ee..d10d790d38a5 100644 --- a/src/play_controller.cpp +++ b/src/play_controller.cpp @@ -72,6 +72,7 @@ static lg::log_domain log_enginerefac("enginerefac"); static void clear_resources() { resources::controller = NULL; + resources::gameboard = NULL; resources::gamedata = NULL; resources::game_map = NULL; resources::persist = NULL; @@ -135,6 +136,7 @@ play_controller::play_controller(const config& level, game_state& state_of_game, scope_() { resources::controller = this; + resources::gameboard = &gameboard_; resources::gamedata = &gamedata_; resources::game_map = &gameboard_.map_; resources::persist = &persist_; diff --git a/src/reports.cpp b/src/reports.cpp index a99e828823f8..47a94bde4ba2 100644 --- a/src/reports.cpp +++ b/src/reports.cpp @@ -119,20 +119,24 @@ struct report_generator_helper static char const *naps = ""; +namespace reports { + static const unit *get_visible_unit() { - return get_visible_unit(resources::screen->displayed_unit_hex(), + return resources::gameboard->get_visible_unit(resources::screen->displayed_unit_hex(), (*resources::teams)[resources::screen->viewing_team()], resources::screen->show_everything()); } static const unit *get_selected_unit() { - return get_visible_unit(resources::screen->selected_hex(), + return resources::gameboard->get_visible_unit(resources::screen->selected_hex(), (*resources::teams)[resources::screen->viewing_team()], resources::screen->show_everything()); } +} + static config gray_inactive(const std::string &str) { if ( (resources::screen && @@ -162,12 +166,12 @@ static config unit_name(const unit *u) REPORT_GENERATOR(unit_name) { - const unit *u = get_visible_unit(); + const unit *u = reports::get_visible_unit(); return unit_name(u); } REPORT_GENERATOR(selected_unit_name) { - const unit *u = get_selected_unit(); + const unit *u = reports::get_selected_unit(); return unit_name(u); } @@ -183,12 +187,12 @@ static config unit_type(const unit* u) } REPORT_GENERATOR(unit_type) { - const unit *u = get_visible_unit(); + const unit *u = reports::get_visible_unit(); return unit_type(u); } REPORT_GENERATOR(selected_unit_type) { - const unit *u = get_selected_unit(); + const unit *u = reports::get_selected_unit(); return unit_type(u); } @@ -202,12 +206,12 @@ static config unit_race(const unit* u) } REPORT_GENERATOR(unit_race) { - const unit *u = get_visible_unit(); + const unit *u = reports::get_visible_unit(); return unit_race(u); } REPORT_GENERATOR(selected_unit_race) { - const unit *u = get_selected_unit(); + const unit *u = reports::get_selected_unit(); return unit_race(u); } @@ -233,12 +237,12 @@ static config unit_side(const unit* u) } REPORT_GENERATOR(unit_side) { - const unit *u = get_visible_unit(); + const unit *u = reports::get_visible_unit(); return unit_side(u); } REPORT_GENERATOR(selected_unit_side) { - const unit *u = get_selected_unit(); + const unit *u = reports::get_selected_unit(); return unit_side(u); } @@ -258,18 +262,18 @@ static config unit_level(const unit* u) } REPORT_GENERATOR(unit_level) { - const unit *u = get_visible_unit(); + const unit *u = reports::get_visible_unit(); return unit_level(u); } REPORT_GENERATOR(selected_unit_level) { - const unit *u = get_selected_unit(); + const unit *u = reports::get_selected_unit(); return unit_level(u); } REPORT_GENERATOR(unit_amla) { - const unit *u = get_visible_unit(); + const unit *u = reports::get_visible_unit(); if (!u) return report(); config res; typedef std::pair pair_string; @@ -300,12 +304,12 @@ static config unit_traits(const unit* u) } REPORT_GENERATOR(unit_traits) { - const unit *u = get_visible_unit(); + const unit *u = reports::get_visible_unit(); return unit_traits(u); } REPORT_GENERATOR(selected_unit_traits) { - const unit *u = get_selected_unit(); + const unit *u = reports::get_selected_unit(); return unit_traits(u); } @@ -334,12 +338,12 @@ static config unit_status(const unit* u) } REPORT_GENERATOR(unit_status) { - const unit *u = get_visible_unit(); + const unit *u = reports::get_visible_unit(); return unit_status(u); } REPORT_GENERATOR(selected_unit_status) { - const unit *u = get_selected_unit(); + const unit *u = reports::get_selected_unit(); return unit_status(u); } @@ -366,12 +370,12 @@ static config unit_alignment(const unit* u) } REPORT_GENERATOR(unit_alignment) { - const unit *u = get_visible_unit(); + const unit *u = reports::get_visible_unit(); return unit_alignment(u); } REPORT_GENERATOR(selected_unit_alignment) { - const unit *u = get_selected_unit(); + const unit *u = reports::get_selected_unit(); return unit_alignment(u); } @@ -411,12 +415,12 @@ static config unit_abilities(const unit* u) } REPORT_GENERATOR(unit_abilities) { - const unit *u = get_visible_unit(); + const unit *u = reports::get_visible_unit(); return unit_abilities(u); } REPORT_GENERATOR(selected_unit_abilities) { - const unit *u = get_selected_unit(); + const unit *u = reports::get_selected_unit(); return unit_abilities(u); } @@ -465,12 +469,12 @@ static config unit_hp(const unit* u) } REPORT_GENERATOR(unit_hp) { - const unit *u = get_visible_unit(); + const unit *u = reports::get_visible_unit(); return unit_hp(u); } REPORT_GENERATOR(selected_unit_hp) { - const unit *u = get_selected_unit(); + const unit *u = reports::get_selected_unit(); return unit_hp(u); } @@ -487,12 +491,12 @@ static config unit_xp(const unit* u) } REPORT_GENERATOR(unit_xp) { - const unit *u = get_visible_unit(); + const unit *u = reports::get_visible_unit(); return unit_xp(u); } REPORT_GENERATOR(selected_unit_xp) { - const unit *u = get_selected_unit(); + const unit *u = reports::get_selected_unit(); return unit_xp(u); } @@ -508,12 +512,12 @@ static config unit_advancement_options(const unit* u) } REPORT_GENERATOR(unit_advancement_options) { - const unit *u = get_visible_unit(); + const unit *u = reports::get_visible_unit(); return unit_advancement_options(u); } REPORT_GENERATOR(selected_unit_advancement_options) { - const unit *u = get_selected_unit(); + const unit *u = reports::get_selected_unit(); return unit_advancement_options(u); } @@ -560,13 +564,13 @@ static config unit_defense(const unit* u, const map_location& displayed_unit_hex } REPORT_GENERATOR(unit_defense) { - const unit *u = get_visible_unit(); + const unit *u = reports::get_visible_unit(); const map_location& displayed_unit_hex = resources::screen->displayed_unit_hex(); return unit_defense(u, displayed_unit_hex); } REPORT_GENERATOR(selected_unit_defense) { - const unit *u = get_selected_unit(); + const unit *u = reports::get_selected_unit(); const map_location& selected_hex = resources::screen->selected_hex(); return unit_defense(u, selected_hex); } @@ -583,12 +587,12 @@ static config unit_vision(const unit* u) } REPORT_GENERATOR(unit_vision) { - const unit* u = get_visible_unit(); + const unit* u = reports::get_visible_unit(); return unit_vision(u); } REPORT_GENERATOR(selected_unit_vision) { - const unit* u = get_selected_unit(); + const unit* u = reports::get_selected_unit(); return unit_vision(u); } @@ -650,12 +654,12 @@ static config unit_moves(const unit* u) } REPORT_GENERATOR(unit_moves) { - const unit *u = get_visible_unit(); + const unit *u = reports::get_visible_unit(); return unit_moves(u); } REPORT_GENERATOR(selected_unit_moves) { - const unit *u = get_selected_unit(); + const unit *u = reports::get_selected_unit(); return unit_moves(u); } @@ -1011,15 +1015,15 @@ static config unit_weapons(const unit *u) } REPORT_GENERATOR(unit_weapons) { - const unit *u = get_visible_unit(); + const unit *u = reports::get_visible_unit(); if (!u) return config(); return unit_weapons(u); } REPORT_GENERATOR(highlighted_unit_weapons) { - const unit *u = get_selected_unit(); - const unit *sec_u = get_visible_unit(); + const unit *u = reports::get_selected_unit(); + const unit *sec_u = reports::get_visible_unit(); if (!u) return config(); if (!sec_u || u == sec_u) return unit_weapons(sec_u); @@ -1035,8 +1039,8 @@ REPORT_GENERATOR(highlighted_unit_weapons) } REPORT_GENERATOR(selected_unit_weapons) { - const unit *u = get_selected_unit(); - const unit *sec_u = get_visible_unit(); + const unit *u = reports::get_selected_unit(); + const unit *sec_u = reports::get_visible_unit(); if (!u) return config(); if (!sec_u || u == sec_u) return unit_weapons(u); @@ -1053,26 +1057,26 @@ REPORT_GENERATOR(selected_unit_weapons) REPORT_GENERATOR(unit_image) { - const unit *u = get_visible_unit(); + const unit *u = reports::get_visible_unit(); if (!u) return report(); return image_report(u->absolute_image() + u->image_mods()); } REPORT_GENERATOR(selected_unit_image) { - const unit *u = get_selected_unit(); + const unit *u = reports::get_selected_unit(); if (!u) return report(); return image_report(u->absolute_image() + u->image_mods()); } REPORT_GENERATOR(selected_unit_profile) { - const unit *u = get_selected_unit(); + const unit *u = reports::get_selected_unit(); if (!u) return report(); return image_report(u->small_profile()); } REPORT_GENERATOR(unit_profile) { - const unit *u = get_visible_unit(); + const unit *u = reports::get_visible_unit(); if (!u) return report(); return image_report(u->small_profile()); } @@ -1219,7 +1223,7 @@ static config unit_box_at(const map_location& mouseover_hex) bg_terrain_image = bg_terrain_image + "~CS(" + color.str() + ")"; - const unit *u = get_visible_unit(); + const unit *u = reports::get_visible_unit(); std::string unit_image; if (u) unit_image = "~BLIT(" + u->absolute_image() + u->image_mods() + ",35,22)"; @@ -1462,7 +1466,7 @@ REPORT_GENERATOR(position) std::ostringstream str; str << mouseover_hex; - const unit *u = get_visible_unit(); + const unit *u = reports::get_visible_unit(); const team &viewing_team = (*resources::teams)[resources::screen->viewing_team()]; if (!u || (displayed_unit_hex != mouseover_hex && diff --git a/src/resources.cpp b/src/resources.cpp index 48f743bd73f9..ae8c8d34d12f 100644 --- a/src/resources.cpp +++ b/src/resources.cpp @@ -17,6 +17,7 @@ namespace resources { + game_board *gameboard = NULL; game_config_manager *config_manager = NULL; play_controller *controller = NULL; game_data *gamedata = NULL; diff --git a/src/resources.hpp b/src/resources.hpp index 6874ccd3f52f..4192482f4d84 100644 --- a/src/resources.hpp +++ b/src/resources.hpp @@ -17,6 +17,7 @@ #include +class game_board; class game_config_manager; class game_display; class gamemap; @@ -41,6 +42,7 @@ namespace resources { extern game_config_manager *config_manager; extern play_controller *controller; + extern game_board *gameboard; extern game_data *gamedata; extern gamemap *game_map; extern LuaKernel *lua_kernel; // Set by game_events::manager. diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index 51310e010cd0..1bd645caa7e0 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -779,7 +779,7 @@ static int intf_get_unit(lua_State *L) */ static int intf_get_displayed_unit(lua_State *L) { - unit_map::const_iterator ui = find_visible_unit( + unit_map::const_iterator ui = resources::gameboard->find_visible_unit( resources::screen->displayed_unit_hex(), (*resources::teams)[resources::screen->viewing_team()], resources::screen->show_everything()); diff --git a/src/synced_commands.cpp b/src/synced_commands.cpp index 74e933c4cee8..c5bbbf6b8793 100644 --- a/src/synced_commands.cpp +++ b/src/synced_commands.cpp @@ -263,7 +263,7 @@ SYNCED_COMMAND_HANDLER_FUNCTION(move, child, use_undo, show, error_handler) } // The nominal destination should appear to be unoccupied. - unit_map::iterator u = find_visible_unit(dst, current_team); + unit_map::iterator u = resources::gameboard->find_visible_unit(dst, current_team); if ( u.valid() ) { WRN_REPLAY << "Warning: Move destination " << dst << " appears occupied." << std::endl; // We'll still proceed with this movement, though, since diff --git a/src/unit.cpp b/src/unit.cpp index 285ed1985987..b8c50f187e63 100644 --- a/src/unit.cpp +++ b/src/unit.cpp @@ -3022,26 +3022,6 @@ int side_upkeep(int side) return res; } -unit_map::iterator find_visible_unit(const map_location &loc, - const team& current_team, bool see_all) -{ - unit_map& units = *resources::units; - if (!resources::game_map->on_board(loc)) return units.end(); - unit_map::iterator u = units.find(loc); - if (!u.valid() || !u->is_visible_to_team(current_team, see_all)) - return units.end(); - return u; -} - -unit *get_visible_unit(const map_location &loc, - const team ¤t_team, bool see_all) -{ - unit_map::iterator ui = find_visible_unit(loc, - current_team, see_all); - if (ui == resources::units->end()) return NULL; - return &*ui; -} - void unit::refresh() { if (state_ == STATE_FORGET && anim_ && anim_->animation_finished_potential()) diff --git a/src/unit.hpp b/src/unit.hpp index ee621a7ffbd8..b5931e868ab9 100644 --- a/src/unit.hpp +++ b/src/unit.hpp @@ -577,12 +577,6 @@ int side_units_cost(int side_num); int side_upkeep(int side_num); -unit_map::iterator find_visible_unit(const map_location &loc, - const team ¤t_team, bool see_all = false); - -unit *get_visible_unit(const map_location &loc, - const team ¤t_team, bool see_all = false); - struct team_data { team_data() : diff --git a/src/whiteboard/move.cpp b/src/whiteboard/move.cpp index c211d98f7e2f..833ff294bcf4 100644 --- a/src/whiteboard/move.cpp +++ b/src/whiteboard/move.cpp @@ -459,7 +459,7 @@ action::error move::check_validity() const } //If the path has at least two hexes (it can have less with the attack subclass), ensure destination hex is free - if(get_route().steps.size() >= 2 && get_visible_unit(get_dest_hex(),resources::teams->at(viewer_team())) != NULL) { + if(get_route().steps.size() >= 2 && resources::gameboard->get_visible_unit(get_dest_hex(),resources::teams->at(viewer_team())) != NULL) { return LOCATION_OCCUPIED; } diff --git a/src/whiteboard/utility.cpp b/src/whiteboard/utility.cpp index 8bcf8dd1c2c7..ed76a770f40b 100644 --- a/src/whiteboard/utility.cpp +++ b/src/whiteboard/utility.cpp @@ -98,7 +98,7 @@ unit* future_visible_unit(map_location hex, int viewer_side) return NULL; } //use global method get_visible_unit - return get_visible_unit(hex, resources::teams->at(viewer_side - 1), false); + return resources::gameboard->get_visible_unit(hex, resources::teams->at(viewer_side - 1), false); } unit* future_visible_unit(int on_side, map_location hex, int viewer_side)