From 13fca9a35894047ae7da30cd3da516b94a0aca46 Mon Sep 17 00:00:00 2001 From: Chris Beck Date: Tue, 10 Jun 2014 17:16:11 -0400 Subject: [PATCH 1/4] fixup play_controller initialization order --- src/play_controller.cpp | 2 +- src/play_controller.hpp | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/play_controller.cpp b/src/play_controller.cpp index 358beda3c78e..f92008f3ba8b 100644 --- a/src/play_controller.cpp +++ b/src/play_controller.cpp @@ -107,6 +107,7 @@ play_controller::play_controller(const config& level, game_state& state_of_game, halo_manager_(), labels_manager_(), help_manager_(&game_config), + gameboard_(game_config, level), mouse_handler_(NULL, gameboard_), menu_handler_(NULL, gameboard_, level, game_config), soundsources_manager_(), @@ -118,7 +119,6 @@ play_controller::play_controller(const config& level, game_state& state_of_game, level_(level), gamestate_(state_of_game), gamedata_(level), - gameboard_(game_config, level), undo_stack_(new actions::undo_list(level.child("undo_stack"))), whiteboard_manager_(), xp_mod_(level["experience_modifier"].to_int(100)), diff --git a/src/play_controller.hpp b/src/play_controller.hpp index b60abd5314e6..bc12b9f3e363 100644 --- a/src/play_controller.hpp +++ b/src/play_controller.hpp @@ -223,6 +223,11 @@ class play_controller : public controller_base, public events::observer, public boost::scoped_ptr halo_manager_; font::floating_label_context labels_manager_; help::help_manager help_manager_; + + //this must be before mouse_handler and menu_handler or we segfault + game_board gameboard_; + + //more managers events::mouse_handler mouse_handler_; events::menu_handler menu_handler_; boost::scoped_ptr soundsources_manager_; @@ -236,7 +241,6 @@ class play_controller : public controller_base, public events::observer, public const config& level_; game_state& gamestate_; game_data gamedata_; - game_board gameboard_; /// undo_stack_ is never NULL. It is implemented as a pointer so that /// undo_list can be an incomplete type at this point (which reduces the /// number of files that depend on actions/undo.hpp). From d9b3289355e8bd02c95098d9a4424b84a4f3ddb3 Mon Sep 17 00:00:00 2001 From: Chris Beck Date: Tue, 10 Jun 2014 14:50:04 -0400 Subject: [PATCH 2/4] define display_context interface, implement in game_board --- src/display_context.hpp | 40 ++++++++++++++++++++++++++++++++++++++++ src/game_board.hpp | 12 +++++++----- 2 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 src/display_context.hpp diff --git a/src/display_context.hpp b/src/display_context.hpp new file mode 100644 index 000000000000..b25079d46094 --- /dev/null +++ b/src/display_context.hpp @@ -0,0 +1,40 @@ +/* + Copyright (C) 2014 by Chris Beck + 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. +*/ + +/** + * + * This class is an abstract base class designed to simplify the use + * of the display object. + * + **/ + +#ifndef DISPLAY_CONTEXT_HPP_INCLUDED +#define DISPLAY_CONTEXT_HPP_INCLUDED + +#include + +class team; +class gamemap; +class unit_map; + +class display_context { +public: + virtual const std::vector & teams() const = 0; + virtual const gamemap & map() const = 0; + virtual const unit_map & units() const = 0; + + virtual ~display_context() {} +}; + +#endif diff --git a/src/game_board.hpp b/src/game_board.hpp index 4bdf4e771729..fc3278301e5c 100644 --- a/src/game_board.hpp +++ b/src/game_board.hpp @@ -17,6 +17,7 @@ #include "global.hpp" +#include "display_context.hpp" #include "map.hpp" #include "team.hpp" #include "unit_map.hpp" @@ -46,7 +47,7 @@ namespace events { * **/ -class game_board { +class game_board : public display_context { std::vector teams_; @@ -82,13 +83,14 @@ class game_board { public: - // Constructors and const accessors + // Constructors, trivial dtor, and const accessors game_board(const config & game_config, const config & level) : teams_(), map_(game_config, level), units_() {} + virtual ~game_board() {} - const std::vector & teams() const { return teams_; } - const gamemap & map() const { return map_; } - const unit_map & units() const { return units_; } + virtual const std::vector & teams() const { return teams_; } + virtual const gamemap & map() const { return map_; } + virtual const unit_map & units() const { return units_; } // Saving From 90e5d9206b29c33044a414a5e9cef710e17ca6b1 Mon Sep 17 00:00:00 2001 From: Chris Beck Date: Tue, 10 Jun 2014 14:51:16 -0400 Subject: [PATCH 3/4] editor map context implements display_context interface --- src/editor/map/map_context.hpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/editor/map/map_context.hpp b/src/editor/map/map_context.hpp index ae617b4db7d0..f30746c4d240 100644 --- a/src/editor/map/map_context.hpp +++ b/src/editor/map/map_context.hpp @@ -22,6 +22,7 @@ #include "tod_manager.hpp" #include "unit_map.hpp" #include "overlay.hpp" +#include "../../display_context.hpp" #include #include @@ -35,7 +36,7 @@ namespace editor { * as e.g. the undo stack is part of the map, not the editor as a whole. This might allow many * maps to be open at the same time. */ -class map_context : private boost::noncopyable +class map_context : public display_context, private boost::noncopyable { public: /** @@ -58,7 +59,7 @@ class map_context : private boost::noncopyable /** * Map context destructor */ - ~map_context(); + virtual ~map_context(); /** * Select the nth tod area. @@ -122,6 +123,19 @@ class map_context : private boost::noncopyable void replace_schedule(const std::vector& schedule); + /** + * Const accessor names needed to implement "display_context" interface + */ + virtual const unit_map & units() const { + return units_; + } + virtual const std::vector& teams() const { + return teams_; + } + virtual const gamemap & map() const { + return map_; + } + /** * Replace the [time]s of the currently active area. */ From 43ade4615ae158a761df8301ec0d7e998ef607d7 Mon Sep 17 00:00:00 2001 From: Chris Beck Date: Tue, 10 Jun 2014 16:06:01 -0400 Subject: [PATCH 4/4] display uses display_context internally, not 3 private pointers Also refactor editor and game_display to use this. To achieve this it turns out we also have to add a "dummy display context" unique to the editor code, which it can use to initalize editor display, because after refactor NULL doesn't cut it anymore. This appears in src/editor/editor_display.?pp, might want to branch into its own file later. --- src/display.cpp | 74 +++++++++++++----------------- src/display.hpp | 21 ++++----- src/editor/editor_controller.cpp | 7 +-- src/editor/editor_display.cpp | 34 ++++++++++++-- src/editor/editor_display.hpp | 6 ++- src/editor/map/context_manager.cpp | 8 ++-- src/game_display.cpp | 38 +++++++-------- 7 files changed, 98 insertions(+), 90 deletions(-) diff --git a/src/display.cpp b/src/display.cpp index f34e11ae9858..2d1ec061f68a 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -78,8 +78,8 @@ int display::last_zoom_ = SmallZoom; void display::parse_team_overlays() { - const team& curr_team = (*teams_)[playing_team()]; - const team& prev_team = (*teams_)[playing_team()-1 < teams_->size() ? playing_team()-1 : teams_->size()-1]; + const team& curr_team = dc_->teams()[playing_team()]; + const team& prev_team = dc_->teams()[playing_team()-1 < dc_->teams().size() ? playing_team()-1 : dc_->teams().size()-1]; BOOST_FOREACH(const game_display::overlay_map::value_type i, *overlays_) { const overlay& ov = i.second; if (!ov.team_name.empty() && @@ -136,13 +136,11 @@ void display::remove_single_overlay(const map_location& loc, const std::string& -display::display(unit_map* units, CVideo& video, const gamemap* map, const std::vector* t,const config& theme_cfg, const config& level) : - units_(units), +display::display(const display_context * dc, CVideo& video, const config& theme_cfg, const config& level) : + dc_(dc), exclusive_unit_draw_requests_(), screen_(video), - map_(map), currentTeam_(0), - teams_(t), viewpoint_(NULL), energy_bar_rects_(), xpos_(0), @@ -150,7 +148,7 @@ display::display(unit_map* units, CVideo& video, const gamemap* map, const std:: view_locked_(false), theme_(theme_cfg, screen_area()), zoom_(DefaultZoom), - builder_(new terrain_builder(level, map, theme_.border().tile_image)), + builder_(new terrain_builder(level, &dc_->map(), theme_.border().tile_image)), minimap_(NULL), minimap_location_(sdl::empty_rect), redrawMinimap_(false), @@ -252,13 +250,13 @@ display::~display() void display::init_flags() { flags_.clear(); - if (!teams_) return; - flags_.resize(teams_->size()); + if (!dc_) return; + flags_.resize(dc_->teams().size()); std::vector side_colors; - side_colors.reserve(teams_->size()); + side_colors.reserve(dc_->teams().size()); - for(size_t i = 0; i != teams_->size(); ++i) { + for(size_t i = 0; i != dc_->teams().size(); ++i) { std::string side_color = team::get_side_color_index(i+1); side_colors.push_back(side_color); init_flags_for_side_internal(i, side_color); @@ -268,7 +266,7 @@ void display::init_flags() { void display::reinit_flags_for_side(size_t side) { - if (!teams_ || side >= teams_->size()) { + if (!dc_ || side >= dc_->teams().size()) { ERR_DP << "Cannot rebuild flags for inexistent or unconfigured side " << side << '\n'; return; } @@ -278,11 +276,11 @@ void display::reinit_flags_for_side(size_t side) void display::init_flags_for_side_internal(size_t n, const std::string& side_color) { - assert(teams_ != NULL); - assert(n < teams_->size()); + assert(dc_ != NULL); + assert(n < dc_->teams().size()); assert(n < flags_.size()); - std::string flag = (*teams_)[n].flag(); + std::string flag = dc_->teams()[n].flag(); std::string old_rgb = game_config::flag_rgb; std::string new_rgb = side_color; @@ -336,9 +334,9 @@ surface display::get_flag(const map_location& loc) return surface(NULL); } - for(size_t i = 0; i != teams_->size(); ++i) { - if((*teams_)[i].owns_village(loc) && - (!fogged(loc) || !(*teams_)[currentTeam_].is_enemy(i+1))) + for(size_t i = 0; i != dc_->teams().size(); ++i) { + if(dc_->teams()[i].owns_village(loc) && + (!fogged(loc) || !dc_->teams()[currentTeam_].is_enemy(i+1))) { flags_[i].update_last_draw_time(); const image::locator &image_flag = animate_map_ ? @@ -352,12 +350,12 @@ surface display::get_flag(const map_location& loc) void display::set_team(size_t teamindex, bool show_everything) { - assert(teamindex < teams_->size()); + assert(teamindex < dc_->teams().size()); currentTeam_ = teamindex; if (!show_everything) { - labels().set_team(&(*teams_)[teamindex]); - viewpoint_ = &(*teams_)[teamindex]; + labels().set_team(&dc_->teams()[teamindex]); + viewpoint_ = &dc_->teams()[teamindex]; } else { @@ -371,7 +369,7 @@ void display::set_team(size_t teamindex, bool show_everything) void display::set_playing_team(size_t teamindex) { - assert(teamindex < teams_->size()); + assert(teamindex < dc_->teams().size()); activeTeam_ = teamindex; invalidate_game_status(); } @@ -563,20 +561,10 @@ void display::reload_map() builder_->reload_map(); } -void display::change_map(const gamemap* m) +void display::change_display_context(const display_context * dc) { - map_ = m; - builder_->change_map(m); -} - -void display::change_units(const unit_map* umap) -{ - units_ = umap; -} - -void display::change_teams(const std::vector* teams) -{ - teams_ = teams; + dc_ = dc; + builder_->change_map(&dc_->map()); //TODO: Should display_context own and initalize the builder object? } void display::blindfold(bool value) @@ -1911,9 +1899,9 @@ void display::draw_minimap_units() double xscaling = 1.0 * minimap_location_.w / get_map().w(); double yscaling = 1.0 * minimap_location_.h / get_map().h(); - for(unit_map::const_iterator u = units_->begin(); u != units_->end(); ++u) { + for(unit_map::const_iterator u = dc_->units().begin(); u != dc_->units().end(); ++u) { if (fogged(u->get_location()) || - ((*teams_)[currentTeam_].is_enemy(u->side()) && + (dc_->teams()[currentTeam_].is_enemy(u->side()) && u->invisible(u->get_location())) || u->get_hidden()) { continue; @@ -1924,7 +1912,7 @@ void display::draw_minimap_units() if (preferences::minimap_movement_coding()) { - if ((*teams_)[currentTeam_].is_enemy(side)) { + if (dc_->teams()[currentTeam_].is_enemy(side)) { col = int_to_color(game_config::color_info(preferences::enemy_color()).rep()); } else { @@ -2554,9 +2542,9 @@ void display::draw_invalidated() { invalidated_hexes_ += invalidated_.size(); BOOST_FOREACH(const map_location& loc, invalidated_) { - unit_map::const_iterator u_it = units_->find(loc); + unit_map::const_iterator u_it = dc_->units().find(loc); exclusive_unit_draw_requests_t::iterator request = exclusive_unit_draw_requests_.find(loc); - if (u_it != units_->end() + if (u_it != dc_->units().end() && (request == exclusive_unit_draw_requests_.end() || request->second == u_it->id())) u_it->redraw_unit(); } @@ -2596,7 +2584,7 @@ void display::draw_hex(const map_location& loc) { std::pair overlays = overlays_->equal_range(loc); for( ; overlays.first != overlays.second; ++overlays.first) { if ((overlays.first->second.team_name == "" || - overlays.first->second.team_name.find((*teams_)[playing_team()].team_name()) != std::string::npos) + overlays.first->second.team_name.find(dc_->teams()[playing_team()].team_name()) != std::string::npos) && !(fogged(loc) && !overlays.first->second.visible_in_fog)) { drawing_buffer_add(LAYER_TERRAIN_BG, loc, xpos, ypos, @@ -3027,7 +3015,7 @@ void display::invalidate_animations_location(const map_location& loc) { if (get_map().is_village(loc)) { const int owner = village_owner(loc); if (owner >= 0 && flags_[owner].need_update() - && (!fogged(loc) || !(*teams_)[currentTeam_].is_enemy(owner+1))) { + && (!fogged(loc) || !dc_->teams()[currentTeam_].is_enemy(owner+1))) { invalidate(loc); } } @@ -3036,7 +3024,7 @@ void display::invalidate_animations_location(const map_location& loc) { std::vector display::get_unit_list_for_invalidation() { std::vector unit_list; - BOOST_FOREACH(const unit &u, *units_) { + BOOST_FOREACH(const unit &u, dc_->units()) { unit_list.push_back(&u); } return unit_list; diff --git a/src/display.hpp b/src/display.hpp index 8f4b5fc5b3a0..dcb08e8c8a9c 100644 --- a/src/display.hpp +++ b/src/display.hpp @@ -39,6 +39,7 @@ struct time_of_day; class map_labels; class arrow; +#include "display_context.hpp" #include "font.hpp" #include "key.hpp" #include "team.hpp" @@ -62,19 +63,21 @@ class gamemap; class display { public: - display(unit_map* units, CVideo& video, const gamemap* map, const std::vector* t, + display(const display_context * dc, CVideo& video, const config& theme_cfg, const config& level); virtual ~display(); static display* get_singleton() { return singleton_ ;} bool show_everything() const { return !viewpoint_ && !is_blindfolded(); } - const std::vector& get_teams() const {return *teams_;} + const gamemap& get_map() const { return dc_->map(); } + + const std::vector& get_teams() const {return dc_->teams();} /** The playing team is the team whose turn it is. */ size_t playing_team() const { return activeTeam_; } - bool team_valid() const { return currentTeam_ < teams_->size(); } + bool team_valid() const { return currentTeam_ < dc_->teams().size(); } /** The viewing team is the team currently viewing the game. */ size_t viewing_team() const { return currentTeam_; } @@ -96,7 +99,7 @@ class display * Cancels all the exclusive draw requests. */ void clear_exclusive_draws() { exclusive_unit_draw_requests_.clear(); } - const unit_map& get_units() const {return *units_;} + const unit_map& get_units() const {return dc_->units();} /** * Allows a unit to request to be the only one drawn in its hex. Useful for situations where @@ -152,9 +155,7 @@ class display */ void reload_map(); - void change_map(const gamemap* m); - void change_teams(const std::vector* teams); - void change_units(const unit_map* units); + void change_display_context(const display_context * dc); static Uint32 rgb(Uint8 red, Uint8 green, Uint8 blue) { return 0xFF000000 | (red << 16) | (green << 8) | blue; } @@ -418,8 +419,6 @@ class display */ void invalidate_animations_location(const map_location& loc); - const gamemap& get_map() const { return *map_; } - /** * mouseover_hex_overlay_ require a prerendered surface * and is drawn underneath the mouse's location @@ -627,7 +626,7 @@ class display protected: //TODO sort - const unit_map* units_; + const display_context * dc_; typedef std::map exclusive_unit_draw_requests_t; /// map of hexes where only one unit should be drawn, the one identified by the associated id string @@ -720,9 +719,7 @@ class display const std::string& get_variant(const std::vector& variants, const map_location &loc) const; CVideo& screen_; - const gamemap* map_; size_t currentTeam_; - const std::vector* teams_; const team *viewpoint_; std::map energy_bar_rects_; int xpos_, ypos_; diff --git a/src/editor/editor_controller.cpp b/src/editor/editor_controller.cpp index c804fb518945..30a5611891b9 100644 --- a/src/editor/editor_controller.cpp +++ b/src/editor/editor_controller.cpp @@ -56,12 +56,11 @@ static std::vector saved_windows_; namespace editor { - editor_controller::editor_controller(const config &game_config, CVideo& video) : controller_base(SDL_GetTicks(), game_config, video) , mouse_handler_base() , active_menu_(editor::MAP) - , gui_(new editor_display(NULL, video, NULL, NULL, get_theme(game_config, "editor"), config())) + , gui_(new editor_display(editor::get_dummy_display_context(), video, get_theme(game_config, "editor"), config())) , tods_() , context_manager_(new context_manager(*gui_.get(), game_config_)) , toolkit_(NULL) @@ -90,9 +89,7 @@ editor_controller::editor_controller(const config &game_config, CVideo& video) void editor_controller::init_gui() { - gui_->change_map(&context_manager_->get_map()); - gui_->change_units(&context_manager_->get_map_context().get_units()); - gui_->change_teams(&context_manager_->get_map_context().get_teams()); + gui_->change_display_context(&context_manager_->get_map_context()); gui_->set_grid(preferences::grid()); prefs_disp_manager_.reset(new preferences::display_manager(&gui())); gui_->add_redraw_observer(boost::bind(&editor_controller::display_redraw_callback, this, _1)); diff --git a/src/editor/editor_display.cpp b/src/editor/editor_display.cpp index a98850e62449..ca72cb8f3d59 100644 --- a/src/editor/editor_display.cpp +++ b/src/editor/editor_display.cpp @@ -19,9 +19,35 @@ namespace editor { -editor_display::editor_display(unit_map* units, CVideo& video, const editor_map* map, - const std::vector* t, const config& theme_cfg, const config& level) - : display(units, video, map, t, theme_cfg, level) +// Define dummy display context; + +class dummy_editor_display_context : public display_context +{ + config dummy_cfg1; + + editor_map em; + unit_map u; + std::vector t; + +public: + dummy_editor_display_context() : dummy_cfg1(), em(dummy_cfg1), u(), t() {} + virtual ~dummy_editor_display_context(){} + + virtual const gamemap & map() const { return em; } + virtual const unit_map & units() const { return u; } + virtual const std::vector & teams() const { return t; } +}; + +const display_context * get_dummy_display_context() { + static const dummy_editor_display_context dedc = dummy_editor_display_context(); + return &dedc; +} + +// End dummy display context + +editor_display::editor_display(const display_context * dc, CVideo& video, + const config& theme_cfg, const config& level) + : display(dc, video, theme_cfg, level) , brush_locations_() , palette_report_() { @@ -110,7 +136,7 @@ void editor_display::draw_sidebar() refresh_report("position", &element); } - if (teams_->empty()) { + if (dc_->teams().empty()) { text = int(get_map().villages().size()); refresh_report("villages", &element); } else { diff --git a/src/editor/editor_display.hpp b/src/editor/editor_display.hpp index bc72883f972a..147efbb5ca63 100644 --- a/src/editor/editor_display.hpp +++ b/src/editor/editor_display.hpp @@ -20,11 +20,13 @@ namespace editor { +const display_context * get_dummy_display_context(); + class editor_display : public display { public: - editor_display(unit_map* units, CVideo& video, const editor_map* map, - const std::vector* t, const config& theme_cfg, const config& level); + editor_display(const display_context * dc, CVideo& video, + const config& theme_cfg, const config& level); bool in_editor() const { return true; } diff --git a/src/editor/map/context_manager.cpp b/src/editor/map/context_manager.cpp index dba7241be1aa..0959139a0ff2 100644 --- a/src/editor/map/context_manager.cpp +++ b/src/editor/map/context_manager.cpp @@ -73,19 +73,17 @@ class map_context_refresher if (!refreshed_) refresh(); } void refresh() { - context_manager_.gui().change_map(&context_manager_.get_map()); - resources::game_map = &context_manager_.get_map(); + context_manager_.gui().change_display_context(&context_manager_.get_map_context()); - context_manager_.gui().change_units(&context_manager_.get_map_context().get_units()); + 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(); // TODO register the tod_manager with the gui? resources::tod_manager = context_manager_.get_map_context().get_time_manager(); - context_manager_.gui().change_teams(&context_manager_.get_map_context().get_teams()); context_manager_.gui().replace_overlay_map(&context_manager_.get_map_context().get_overlays()); - resources::teams = &context_manager_.get_map_context().get_teams(); resources::classification = &context_manager_.get_map_context().get_game_state().classification(); resources::mp_settings = &context_manager_.get_map_context().get_game_state().mp_settings(); diff --git a/src/game_display.cpp b/src/game_display.cpp index 5a3f7f484e57..3e2614dc45da 100644 --- a/src/game_display.cpp +++ b/src/game_display.cpp @@ -64,7 +64,7 @@ std::map game_display::debugHighlights_; game_display::game_display(game_board& board, CVideo& video, const tod_manager& tod, const config& theme_cfg, const config& level) : - display(&board.units_, video, & board.map(), & board.teams(), theme_cfg, level), + display(&board, video, theme_cfg, level), overlay_map_(), fake_units_(), attack_indicator_src_(), @@ -165,15 +165,15 @@ void game_display::highlight_hex(map_location hex) { wb::future_map future; /**< Lasts for whole method. */ - const unit *u = resources::gameboard->get_visible_unit(hex, (*teams_)[viewing_team()], !viewpoint_); + const unit *u = resources::gameboard->get_visible_unit(hex, dc_->teams()[viewing_team()], !viewpoint_); if (u) { displayedUnitHex_ = hex; invalidate_unit(); } else { - u = resources::gameboard->get_visible_unit(mouseoverHex_, (*teams_)[viewing_team()], !viewpoint_); + u = resources::gameboard->get_visible_unit(mouseoverHex_, dc_->teams()[viewing_team()], !viewpoint_); if (u) { // mouse moved from unit hex to non-unit hex - if (units_->count(selectedHex_)) { + if (dc_->units().count(selectedHex_)) { displayedUnitHex_ = selectedHex_; invalidate_unit(); } @@ -192,7 +192,7 @@ void game_display::display_unit_hex(map_location hex) wb::future_map future; /**< Lasts for whole method. */ - const unit *u = resources::gameboard->get_visible_unit(hex, (*teams_)[viewing_team()], !viewpoint_); + const unit *u = resources::gameboard->get_visible_unit(hex, dc_->teams()[viewing_team()], !viewpoint_); if (u) { displayedUnitHex_ = hex; invalidate_unit(); @@ -209,7 +209,7 @@ void game_display::invalidate_unit_after_move(const map_location& src, const map void game_display::scroll_to_leader(int side, SCROLL_TYPE scroll_type,bool force) { - unit_map::const_iterator leader = units_->find_leader(side); + unit_map::const_iterator leader = dc_->units().find_leader(side); if(leader.valid()) { // YogiHH: I can't see why we need another key_handler here, @@ -279,7 +279,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 = resources::gameboard->get_visible_unit(loc, (*teams_)[viewing_team()] ); + const unit *u = resources::gameboard->get_visible_unit(loc, dc_->teams()[viewing_team()] ); if( u != NULL ) { hex_top_layer = LAYER_MOUSEOVER_TOP; } @@ -288,12 +288,12 @@ void game_display::draw_hex(const map_location& loc) image::get_image("misc/hover-hex-top.png~RC(magenta>gold)", image::SCALED_TO_HEX)); drawing_buffer_add(LAYER_MOUSEOVER_BOTTOM, loc, xpos, ypos, image::get_image("misc/hover-hex-bottom.png~RC(magenta>gold)", image::SCALED_TO_HEX)); - } else if((*teams_)[currentTeam_].is_enemy(u->side())) { + } else if(dc_->teams()[currentTeam_].is_enemy(u->side())) { drawing_buffer_add( hex_top_layer, loc, xpos, ypos, image::get_image("misc/hover-hex-enemy-top.png~RC(magenta>red)", image::SCALED_TO_HEX)); drawing_buffer_add(LAYER_MOUSEOVER_BOTTOM, loc, xpos, ypos, image::get_image("misc/hover-hex-enemy-bottom.png~RC(magenta>red)", image::SCALED_TO_HEX)); - } else if((*teams_)[currentTeam_].side() == u->side()) { + } else if(dc_->teams()[currentTeam_].side() == u->side()) { drawing_buffer_add( hex_top_layer, loc, xpos, ypos, image::get_image("misc/hover-hex-top.png~RC(magenta>green)", image::SCALED_TO_HEX)); drawing_buffer_add(LAYER_MOUSEOVER_BOTTOM, loc, xpos, ypos, @@ -416,8 +416,8 @@ void game_display::draw_movement_info(const map_location& loc) && !route_.steps.empty() && route_.steps.front() != loc) { const unit_map::const_iterator un = resources::whiteboard->get_temp_move_unit().valid() ? - resources::whiteboard->get_temp_move_unit() : units_->find(route_.steps.front()); - if(un != units_->end()) { + resources::whiteboard->get_temp_move_unit() : dc_->units().find(route_.steps.front()); + if(un != dc_->units().end()) { // Display the def% of this terrain int def = 100 - un->defense_modifier(get_map().get_terrain(loc)); std::stringstream def_text; @@ -463,7 +463,7 @@ void game_display::draw_movement_info(const map_location& loc) { 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()) { + if(selectedUnit != dc_->units().end() && mouseoveredUnit == dc_->units().end()) { // Display the def% of this terrain int def = 100 - selectedUnit->defense_modifier(get_map().get_terrain(loc)); std::stringstream def_text; @@ -503,8 +503,8 @@ std::vector game_display::footsteps_images(const map_location& loc) // Check which footsteps images of game_config we will use int move_cost = 1; - const unit_map::const_iterator u = units_->find(route_.steps.front()); - if(u != units_->end()) { + const unit_map::const_iterator u = dc_->units().find(route_.steps.front()); + if(u != dc_->units().end()) { move_cost = u->movement_cost(get_map().get_terrain(loc)); } int image_number = std::min(move_cost, game_config::foot_speed_prefix.size()); @@ -757,7 +757,7 @@ std::string game_display::current_team_name() const { if (team_valid()) { - return (*teams_)[currentTeam_].team_name(); + return dc_->teams()[currentTeam_].team_name(); } return std::string(); } @@ -989,12 +989,12 @@ void game_display::send_notification(const std::string& /*owner*/, const std::st void game_display::set_team(size_t teamindex, bool show_everything) { - assert(teamindex < teams_->size()); + assert(teamindex < dc_->teams().size()); currentTeam_ = teamindex; if (!show_everything) { - labels().set_team(&(*teams_)[teamindex]); - viewpoint_ = &(*teams_)[teamindex]; + labels().set_team(&dc_->teams()[teamindex]); + viewpoint_ = &dc_->teams()[teamindex]; } else { @@ -1008,7 +1008,7 @@ void game_display::set_team(size_t teamindex, bool show_everything) void game_display::set_playing_team(size_t teamindex) { - assert(teamindex < teams_->size()); + assert(teamindex < dc_->teams().size()); activeTeam_ = teamindex; invalidate_game_status(); }