diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c6e308930a94..fe97db1952c4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -728,6 +728,8 @@ set(wesnoth-main_SRC editor/editor_preferences.cpp editor/toolkit/editor_toolkit.cpp editor/map/context_manager.cpp + fake_unit.cpp + fake_unit_manager.cpp filechooser.cpp flg_manager.cpp floating_textbox.cpp diff --git a/src/SConscript b/src/SConscript index 90d420bd531d..fcb8dd32aa8b 100644 --- a/src/SConscript +++ b/src/SConscript @@ -261,6 +261,8 @@ wesnoth_sources = Split(""" editor/editor_preferences.cpp editor/toolkit/brush.cpp editor/toolkit/editor_toolkit.cpp + fake_unit.cpp + fake_unit_manager.cpp filechooser.cpp flg_manager.cpp floating_textbox.cpp diff --git a/src/ai/akihara/recruitment.cpp b/src/ai/akihara/recruitment.cpp index 2d07afc2a35d..5f3dc066f4a9 100644 --- a/src/ai/akihara/recruitment.cpp +++ b/src/ai/akihara/recruitment.cpp @@ -28,6 +28,7 @@ #include "../../log.hpp" #include "../../map.hpp" #include "../../team.hpp" +#include "../../unit.hpp" #include "../../unit_display.hpp" #include "../../unit_map.hpp" #include "../../unit_types.hpp" diff --git a/src/display.cpp b/src/display.cpp index 9285f8b9430a..4bbaf7cfd56d 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -19,6 +19,7 @@ #include "cursor.hpp" #include "display.hpp" +#include "fake_unit_manager.hpp" #include "game_preferences.hpp" #include "gettext.hpp" #include "halo.hpp" @@ -150,6 +151,7 @@ display::display(const display_context * dc, CVideo& video, boost::weak_ptrmap(), theme_.border().tile_image)), minimap_(NULL), minimap_location_(sdl::empty_rect), @@ -209,6 +211,8 @@ display::display(const display_context * dc, CVideo& video, boost::weak_ptr & display::get_fake_unit_list_for_invalidation() { - static const std::deque blah; - return blah; -} void display::invalidate_animations() { new_animation_frame(); @@ -3052,7 +3052,7 @@ void display::invalidate_animations() } } } - const std::deque & unit_list=get_fake_unit_list_for_invalidation(); + const std::deque & unit_list = fake_unit_man_->get_fake_unit_list_for_invalidation(); BOOST_FOREACH(const unit* u, unit_list) { u->refresh(); } diff --git a/src/display.hpp b/src/display.hpp index f43acca0bb58..fca374f5d79c 100644 --- a/src/display.hpp +++ b/src/display.hpp @@ -34,6 +34,7 @@ #define DISPLAY_H_INCLUDED class config; +class fake_unit_manager; class terrain_builder; struct time_of_day; class map_labels; @@ -419,11 +420,6 @@ class display * Function to invalidate animated terrains and units which may have changed. */ void invalidate_animations(); - /** - * helper function for invalidate_animations - * returns a list of units to check for invalidation - */ - virtual const std::deque & get_fake_unit_list_for_invalidation(); /** * Per-location invalidation called by invalidate_animations() @@ -740,6 +736,7 @@ class display theme theme_; int zoom_; static int last_zoom_; + boost::scoped_ptr fake_unit_man_; boost::scoped_ptr builder_; surface minimap_; SDL_Rect minimap_location_; diff --git a/src/fake_unit.cpp b/src/fake_unit.cpp new file mode 100644 index 000000000000..3fbb09442a1c --- /dev/null +++ b/src/fake_unit.cpp @@ -0,0 +1,84 @@ +/* + 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. +*/ + +#include "fake_unit.hpp" + +#include "fake_unit_manager.hpp" + +/** + * Assignment operator, taking a unit. + * If already in the queue, @a this will be moved to the end of the + * queue (drawn last). + * + * This function is unsuitable for derived classes and MUST be overridden. + * Furthermore, derived classes must not explicitly call this version. + * + * The overriding function can be almost the same, except "new (this)" should + * be followed by the derived class instead of "fake_unit(a)". + */ +fake_unit & fake_unit::operator=(unit const & a) +{ + if ( this != &a ) { + fake_unit_manager * mgr = my_manager_; + + // Use the copy constructor to make sure we are coherent. + // (Methodology copied from unit::operator=) + this->~fake_unit(); + new (this) fake_unit(a); + // Restore our old manager. + if ( mgr != NULL ) + place_on_fake_unit_manager(mgr); + } + return *this; +} + +/** + * Removes @a this from the fake_units_ list if necessary. + */ +fake_unit::~fake_unit() +{ + try { + // The fake_unit class exists for this one line, which removes the + // fake_unit from the managers's fake_units_ dequeue in the event of an + // exception. + if(my_manager_){remove_from_fake_unit_manager();} + + } catch (...) {} +} + +/** + * Place @a this on @a manager's fake_units_ dequeue. + * This will be added at the end (drawn last, over all other units). + * Duplicate additions are not allowed. + */ +void fake_unit::place_on_fake_unit_manager(fake_unit_manager * manager){ + assert(my_manager_ == NULL); //Can only be placed on 1 fake_unit_manager + my_manager_=manager; + my_manager_->place_temporary_unit(this); +} + +/** + * Removes @a this from whatever fake_units_ list it is on (if any). + * @returns the number of fake_units deleted, which should be 0 or 1 + * (any other number indicates an error). + */ +int fake_unit::remove_from_fake_unit_manager(){ + int ret(0); + if(my_manager_ != NULL){ + ret = my_manager_->remove_temporary_unit(this); + my_manager_=NULL; + } + return ret; +} + diff --git a/src/fake_unit.hpp b/src/fake_unit.hpp new file mode 100644 index 000000000000..85e0d6b5e65c --- /dev/null +++ b/src/fake_unit.hpp @@ -0,0 +1,57 @@ +/* + 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. +*/ + +#ifndef INCL_FAKE_UNIT_HPP_ +#define INCL_FAKE_UNIT_HPP_ + +#include "unit.hpp" + +class fake_unit_manager; + +/** A temporary unit that can be placed on the map. + Temporary units can overlap units. + Adding the same unit twice isn't allowed. + The fake_unit owns its underlying unit and when + it goes out of scope it removes itself from the fake_units list. + The intent is to provide exception safety when the code + creating the temp unit is unexpectedly forced out of scope. + */ +class fake_unit : public unit { +public: + explicit fake_unit(unit const & u) : unit(u), my_manager_(NULL) {} + fake_unit(fake_unit const & u) : unit(u), my_manager_(NULL) {} + fake_unit(const unit_type& t, int side, unit_race::GENDER gender = unit_race::NUM_GENDERS) + : unit(t, side, false, gender) + , my_manager_(NULL) + {} + /// Assignment operator, taking a fake_unit. + /// If already in the queue, @a this will be moved to the end of the + /// queue (drawn last). The queue (if any) of the parameter is ignored. + fake_unit & operator=(fake_unit const & u) + { return operator=(static_cast(u)); } + /// Assignment operator, taking a unit. + virtual fake_unit & operator=(unit const & u); + /// Removes @a this from the fake_units_ list if necessary. + ~fake_unit(); + + /// Place @a this on @a manager's fake_units_ dequeue. + void place_on_fake_unit_manager(fake_unit_manager * d); + /// Removes @a this from whatever fake_units_ list it is on (if any). + int remove_from_fake_unit_manager(); + + private : + fake_unit_manager * my_manager_; +}; + +#endif diff --git a/src/fake_unit_manager.cpp b/src/fake_unit_manager.cpp new file mode 100644 index 000000000000..9394dc1401e7 --- /dev/null +++ b/src/fake_unit_manager.cpp @@ -0,0 +1,53 @@ +/* + 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. +*/ + +#include "fake_unit_manager.hpp" + +#include "display.hpp" +#include "fake_unit.hpp" +#include "log.hpp" +#include "unit.hpp" + +static lg::log_domain log_engine("engine"); +#define ERR_NG LOG_STREAM(err, log_engine) + +void fake_unit_manager::place_temporary_unit(unit *u) +{ + if(std::find(fake_units_.begin(),fake_units_.end(), u) != fake_units_.end()) { + ERR_NG << "In fake_unit_manager::place_temporary_unit: attempt to add duplicate fake unit." << std::endl; + } else { + fake_units_.push_back(u); + my_display_.invalidate(u->get_location()); + } +} + +int fake_unit_manager::remove_temporary_unit(unit *u) +{ + int removed = 0; + std::deque::iterator it = + std::remove(fake_units_.begin(), fake_units_.end(), u); + if (it != fake_units_.end()) { + removed = std::distance(it, fake_units_.end()); + //std::remove doesn't remove anything without using erase afterwards. + fake_units_.erase(it, fake_units_.end()); + my_display_.invalidate(u->get_location()); + // Redraw with no location to get rid of haloes + u->clear_haloes(); + } + if (removed > 1) { + ERR_NG << "Error: duplicate temp unit found in fake_unit_manager::remove_temporary_unit" << std::endl; + } + return removed; +} + diff --git a/src/fake_unit_manager.hpp b/src/fake_unit_manager.hpp new file mode 100644 index 000000000000..ff8deb97c9be --- /dev/null +++ b/src/fake_unit_manager.hpp @@ -0,0 +1,51 @@ +/* + 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. +*/ + +#ifndef INCL_FAKE_UNIT_MGR_HPP_ +#define INCL_FAKE_UNIT_MGR_HPP_ + +#include + +class display; +class unit; +class fake_unit; + +class fake_unit_manager { +public: + fake_unit_manager(display & disp) : fake_units_(), my_display_(disp) {} + + //Anticipate making place_temporary_unit and remove_temporary_unit private to force exception safety + friend class fake_unit; + + const std::deque & get_fake_unit_list_for_invalidation() {return fake_units_; } + +private: + /** Temporarily place a unit on map (moving: can overlap others). + * The temp unit is added at the end of the temporary unit dequeue, + * and therefore gets drawn last, over other units and temp units. + * Adding the same unit twice isn't allowed. + */ + void place_temporary_unit(unit *u); + + /** Removes any instances of this temporary unit from the temporary unit vector. + * Returns the number of temp units deleted (0 or 1, any other number indicates an error). + */ + int remove_temporary_unit(unit *u); + + /// collection of units destined to be drawn but not put into the unit map + std::deque fake_units_; + display & my_display_; +}; + +#endif diff --git a/src/game_display.cpp b/src/game_display.cpp index 68ab8bd943f2..dfc27f46c4ea 100644 --- a/src/game_display.cpp +++ b/src/game_display.cpp @@ -18,9 +18,8 @@ */ #include "global.hpp" - -#include "game_board.hpp" #include "game_display.hpp" + #include "gettext.hpp" #include "wesconfig.h" @@ -35,6 +34,9 @@ Growl_Delegate growl_obj; #endif #include "cursor.hpp" +#include "fake_unit.hpp" +#include "fake_unit_manager.hpp" +#include "game_board.hpp" #include "game_preferences.hpp" #include "halo.hpp" #include "log.hpp" @@ -66,7 +68,6 @@ game_display::game_display(game_board& board, CVideo& video, boost::weak_ptrget_fake_unit_list_for_invalidation()) { const map_location& loc = temp_unit->get_location(); exclusive_unit_draw_requests_t::iterator request = exclusive_unit_draw_requests_.find(loc); if (invalidated_.find(loc) != invalidated_.end() && (request == exclusive_unit_draw_requests_.end() || request->second == temp_unit->id())) temp_unit->redraw_unit(); } - } void game_display::post_commit() @@ -624,113 +624,12 @@ void game_display::float_label(const map_location& loc, const std::string& text, font::add_floating_label(flabel); } -const std::deque & game_display::get_fake_unit_list_for_invalidation() { - return fake_units_; -} - - int& game_display::debug_highlight(const map_location& loc) { assert(game_config::debug); return debugHighlights_[loc]; } - -/** - * Assignment operator, taking a unit. - * If already in the queue, @a this will be moved to the end of the - * queue (drawn last). - * - * This function is unsuitable for derived classes and MUST be overridden. - * Furthermore, derived classes must not explicitly call this version. - * - * The overriding function can be almost the same, except "new (this)" should - * be followed by the derived class instead of "fake_unit(a)". - */ -game_display::fake_unit & game_display::fake_unit::operator=(unit const & a) -{ - if ( this != &a ) { - game_display * display = my_display_; - - // Use the copy constructor to make sure we are coherent. - // (Methodology copied from unit::operator=) - this->~fake_unit(); - new (this) fake_unit(a); - // Restore our old display. - if ( display != NULL ) - place_on_game_display(display); - } - return *this; -} - -/** - * Removes @a this from the fake_units_ list if necessary. - */ -game_display::fake_unit::~fake_unit() -{ - try { - // The fake_unit class exists for this one line, which removes the - // fake_unit from the display's fake_units_ dequeue in the event of an - // exception. - if(my_display_){remove_from_game_display();} - - } catch (...) {} -} - -/** - * Place @a this on @a display's fake_units_ dequeue. - * This will be added at the end (drawn last, over all other units). - * Duplicate additions are not allowed. - */ -void game_display::fake_unit::place_on_game_display(game_display * display){ - assert(my_display_ == NULL); //Can only be placed on 1 game_display - my_display_=display; - my_display_->place_temporary_unit(this); -} - -/** - * Removes @a this from whatever fake_units_ list it is on (if any). - * @returns the number of fake_units deleted, which should be 0 or 1 - * (any other number indicates an error). - */ -int game_display::fake_unit::remove_from_game_display(){ - int ret(0); - if(my_display_ != NULL){ - ret = my_display_->remove_temporary_unit(this); - my_display_=NULL; - } - return ret; -} - -void game_display::place_temporary_unit(unit *u) -{ - if(std::find(fake_units_.begin(),fake_units_.end(), u) != fake_units_.end()) { - ERR_NG << "In game_display::place_temporary_unit: attempt to add duplicate fake unit." << std::endl; - } else { - fake_units_.push_back(u); - invalidate(u->get_location()); - } -} - -int game_display::remove_temporary_unit(unit *u) -{ - int removed = 0; - std::deque::iterator it = - std::remove(fake_units_.begin(), fake_units_.end(), u); - if (it != fake_units_.end()) { - removed = std::distance(it, fake_units_.end()); - //std::remove doesn't remove anything without using erase afterwards. - fake_units_.erase(it, fake_units_.end()); - invalidate(u->get_location()); - // Redraw with no location to get rid of haloes - u->clear_haloes(); - } - if (removed > 1) { - ERR_NG << "Error: duplicate temp unit found in game_display::remove_temporary_unit" << std::endl; - } - return removed; -} - void game_display::set_attack_indicator(const map_location& src, const map_location& dst) { if (attack_indicator_src_ != src || attack_indicator_dst_ != dst) { @@ -750,9 +649,6 @@ void game_display::clear_attack_indicator() set_attack_indicator(map_location::null_location(), map_location::null_location()); } - - - std::string game_display::current_team_name() const { if (team_valid()) diff --git a/src/game_display.hpp b/src/game_display.hpp index 065178adf49d..5c59fe2d2cfc 100644 --- a/src/game_display.hpp +++ b/src/game_display.hpp @@ -154,63 +154,7 @@ class game_display : public display void draw_hex(const map_location& loc); - /** - * the list of units we need to look at, game_display adds fake units - */ - virtual const std::deque & get_fake_unit_list_for_invalidation(); - - -public: - /** A temporary unit that can be placed on the map. - Temporary units can overlap units. - Adding the same unit twice isn't allowed. - The fake_unit owns its underlying unit and when - it goes out of scope it removes itself from the fake_units list. - The intent is to provide exception safety when the code - creating the temp unit is unexpectedly forced out of scope. - */ - class fake_unit : public unit { - public: - explicit fake_unit(unit const & u) : unit(u), my_display_(NULL) {} - fake_unit(fake_unit const & u) : unit(u), my_display_(NULL) {} - fake_unit(const unit_type& t, int side, unit_race::GENDER gender = unit_race::NUM_GENDERS) - : unit(t, side, false, gender) - , my_display_(NULL) - {} - /// Assignment operator, taking a fake_unit. - /// If already in the queue, @a this will be moved to the end of the - /// queue (drawn last). The queue (if any) of the parameter is ignored. - fake_unit & operator=(fake_unit const & u) - { return operator=(static_cast(u)); } - /// Assignment operator, taking a unit. - virtual fake_unit & operator=(unit const & u); - /// Removes @a this from the fake_units_ list if necessary. - ~fake_unit(); - - /// Place @a this on @a display's fake_units_ dequeue. - void place_on_game_display(game_display * d); - /// Removes @a this from whatever fake_units_ list it is on (if any). - int remove_from_game_display(); - - private : - game_display * my_display_; - }; - - //Anticipate making place_temporary_unit and remove_temporary_unit private to force exception safety - friend class game_display::fake_unit; -private: - /** Temporarily place a unit on map (moving: can overlap others). - * The temp unit is added at the end of the temporary unit dequeue, - * and therefore gets drawn last, over other units and temp units. - * Adding the same unit twice isn't allowed. - */ - void place_temporary_unit(unit *u); - - /** Removes any instances of this temporary unit from the temporary unit vector. - * Returns the number of temp units deleted (0 or 1, any other number indicates an error). - */ - int remove_temporary_unit(unit *u); public: @@ -294,9 +238,6 @@ class game_display : public display overlay_map overlay_map_; - /// collection of units destined to be drawn but not put into the unit map - std::deque fake_units_; - // Locations of the attack direction indicator's parts map_location attack_indicator_src_; map_location attack_indicator_dst_; diff --git a/src/game_events/action_wml.cpp b/src/game_events/action_wml.cpp index 995b691083a2..7613cafe97d2 100644 --- a/src/game_events/action_wml.cpp +++ b/src/game_events/action_wml.cpp @@ -30,6 +30,8 @@ #include "../actions/vision.hpp" #include "../ai/manager.hpp" #include "../dialogs.hpp" +#include "../fake_unit.hpp" +#include "../fake_unit_manager.hpp" #include "../game_display.hpp" #include "../game_preferences.hpp" #include "../gettext.hpp" @@ -252,7 +254,7 @@ namespace { // Support functions return map_location(x, y); } - game_display::fake_unit *create_fake_unit(const vconfig& cfg) + fake_unit *create_fake_unit(const vconfig& cfg) { std::string type = cfg["type"]; std::string variation = cfg["variation"]; @@ -265,14 +267,14 @@ namespace { // Support functions unit_race::GENDER gender = string_gender(cfg["gender"]); const unit_type *ut = unit_types.find(type); if (!ut) return NULL; - game_display::fake_unit * fake_unit = new game_display::fake_unit(*ut, side_num, gender); + fake_unit * fake = new fake_unit(*ut, side_num, gender); if(!variation.empty()) { config mod; config &effect = mod.add_child("effect"); effect["apply_to"] = "variation"; effect["name"] = variation; - fake_unit->add_modification("variation",mod); + fake->add_modification("variation",mod); } if(!img_mods.empty()) { @@ -280,10 +282,10 @@ namespace { // Support functions config &effect = mod.add_child("effect"); effect["apply_to"] = "image_mod"; effect["add"] = img_mods; - fake_unit->add_modification("image_mod",mod); + fake->add_modification("image_mod",mod); } - return fake_unit; + return fake; } std::vector fake_unit_path(const unit& fake_unit, const std::vector& xvals, const std::vector& yvals) @@ -1380,11 +1382,10 @@ WML_HANDLER_FUNCTION(move_units_fake, /*event_info*/, cfg) const vconfig::child_list unit_cfgs = cfg.get_children("fake_unit"); size_t num_units = unit_cfgs.size(); - boost::scoped_array > units( - new util::unique_ptr[num_units]); + boost::scoped_array > units( + new util::unique_ptr[num_units]); std::vector > paths; paths.reserve(num_units); - game_display* disp = game_display::get_singleton(); LOG_NG << "Moving " << num_units << " units\n"; @@ -1394,7 +1395,7 @@ WML_HANDLER_FUNCTION(move_units_fake, /*event_info*/, cfg) const std::vector xvals = utils::split(config["x"]); const std::vector yvals = utils::split(config["y"]); int skip_steps = config["skip_steps"]; - game_display::fake_unit *u = create_fake_unit(config); + fake_unit *u = create_fake_unit(config); units[paths.size()].reset(u); paths.push_back(fake_unit_path(*u, xvals, yvals)); if(skip_steps > 0) @@ -1403,7 +1404,7 @@ WML_HANDLER_FUNCTION(move_units_fake, /*event_info*/, cfg) DBG_NG << "Path " << paths.size() - 1 << " has length " << paths.back().size() << '\n'; u->set_location(paths.back().front()); - u->place_on_game_display(disp); + u->place_on_fake_unit_manager(resources::fake_units); } LOG_NG << "Units placed, longest path is " << longest_path << " long\n"; @@ -1427,7 +1428,7 @@ WML_HANDLER_FUNCTION(move_units_fake, /*event_info*/, cfg) LOG_NG << "Units moved\n"; for(size_t un = 0; un < num_units; ++un) { - units[un]->remove_from_game_display(); + units[un]->remove_from_fake_unit_manager(); } LOG_NG << "Units removed\n"; diff --git a/src/resources.cpp b/src/resources.cpp index 022ed7867f76..7c5b6f3db610 100644 --- a/src/resources.cpp +++ b/src/resources.cpp @@ -27,6 +27,7 @@ namespace resources soundsource::manager *soundsources = NULL; std::vector *teams = NULL; ::tod_manager *tod_manager = NULL; + fake_unit_manager *fake_units = NULL; pathfind::manager *tunnels = NULL; actions::undo_list *undo_stack = NULL; unit_map *units = NULL; diff --git a/src/resources.hpp b/src/resources.hpp index 4714646b99fc..15bf982a98d2 100644 --- a/src/resources.hpp +++ b/src/resources.hpp @@ -26,6 +26,7 @@ class game_data; class LuaKernel; class play_controller; class team; +class fake_unit_manager; class tod_manager; class unit_map; class persist_manager; @@ -52,6 +53,7 @@ namespace resources extern const mp_game_settings *mp_settings; extern soundsource::manager *soundsources; extern std::vector *teams; + extern fake_unit_manager *fake_units; extern ::tod_manager *tod_manager; extern pathfind::manager *tunnels; extern actions::undo_list *undo_stack; diff --git a/src/team.cpp b/src/team.cpp index a5a38b2fb0d8..137e14ac3b7e 100644 --- a/src/team.cpp +++ b/src/team.cpp @@ -20,11 +20,14 @@ #include "team.hpp" #include "ai/manager.hpp" +#include "formula_string_utils.hpp" #include "game_events/pump.hpp" #include "gamestatus.hpp" #include "map.hpp" #include "resources.hpp" #include "game_preferences.hpp" +#include "sdl/utils.hpp" // Only needed for int_to_color (!) +#include "unit_types.hpp" #include "whiteboard/side_actions.hpp" #include diff --git a/src/unit_display.cpp b/src/unit_display.cpp index f519ef8f1c63..5de5413942b1 100644 --- a/src/unit_display.cpp +++ b/src/unit_display.cpp @@ -17,7 +17,10 @@ #include "global.hpp" #include "unit_display.hpp" +#include "fake_unit.hpp" +#include "fake_unit_manager.hpp" #include "game_board.hpp" +#include "game_display.hpp" #include "game_preferences.hpp" #include "log.hpp" #include "mouse_events.hpp" @@ -208,8 +211,8 @@ void unit_mover::replace_temporary(unit & u) // Make our temporary unit mostly match u... if ( temp_unit_ptr_ == NULL ) { - temp_unit_ptr_ = new game_display::fake_unit(u); - temp_unit_ptr_->place_on_game_display(disp_); + temp_unit_ptr_ = new fake_unit(u); + temp_unit_ptr_->place_on_fake_unit_manager(resources::fake_units); } else *temp_unit_ptr_ = u; diff --git a/src/unit_display.hpp b/src/unit_display.hpp index eb1512422dc9..15d45fa14d38 100644 --- a/src/unit_display.hpp +++ b/src/unit_display.hpp @@ -20,11 +20,14 @@ #ifndef UNIT_DISPLAY_HPP_INCLUDED #define UNIT_DISPLAY_HPP_INCLUDED -#include "game_display.hpp" #include "map_location.hpp" #include "unit_animation.hpp" class attack_type; +class fake_unit; +class fake_unit_manager; +class game_board; +class game_display; class unit; class vconfig; @@ -65,7 +68,7 @@ class unit_mover : public boost::noncopyable { unit * shown_unit_; /// The unit to be (re-)shown after an animation finishes. const std::vector& path_; size_t current_; - game_display::fake_unit * temp_unit_ptr_; + fake_unit * temp_unit_ptr_; bool was_hidden_; bool is_enemy_; }; diff --git a/src/whiteboard/action.cpp b/src/whiteboard/action.cpp index 67d9266d9f46..6654840e56b2 100644 --- a/src/whiteboard/action.cpp +++ b/src/whiteboard/action.cpp @@ -23,6 +23,7 @@ #include "recall.hpp" #include "suppose_dead.hpp" +#include "config.hpp" #include "game_board.hpp" #include "resources.hpp" #include "team.hpp" diff --git a/src/whiteboard/action.hpp b/src/whiteboard/action.hpp index 4e40b8f2648d..696f19dac203 100644 --- a/src/whiteboard/action.hpp +++ b/src/whiteboard/action.hpp @@ -20,6 +20,8 @@ #define WB_ACTION_HPP_ #include "typedefs.hpp" +#include "map_location.hpp" +#include "../game_errors.hpp" namespace wb { diff --git a/src/whiteboard/attack.cpp b/src/whiteboard/attack.cpp index b5c13a8e6f9a..dff4cc065c60 100644 --- a/src/whiteboard/attack.cpp +++ b/src/whiteboard/attack.cpp @@ -22,6 +22,8 @@ #include "utility.hpp" #include "arrow.hpp" +#include "config.hpp" +#include "fake_unit.hpp" #include "game_board.hpp" #include "play_controller.hpp" #include "resources.hpp" diff --git a/src/whiteboard/highlighter.cpp b/src/whiteboard/highlighter.cpp index 7964612928b5..e6aadee3e7b6 100644 --- a/src/whiteboard/highlighter.cpp +++ b/src/whiteboard/highlighter.cpp @@ -34,9 +34,14 @@ #include "utility.hpp" #include "arrow.hpp" +#include "config.hpp" +#include "fake_unit.hpp" #include "game_board.hpp" +#include "game_display.hpp" +#include "game_errors.hpp" #include "play_controller.hpp" #include "resources.hpp" +#include "unit.hpp" #include "unit_map.hpp" #include diff --git a/src/whiteboard/highlighter.hpp b/src/whiteboard/highlighter.hpp index b786266d20c5..f6e93b19e3b9 100644 --- a/src/whiteboard/highlighter.hpp +++ b/src/whiteboard/highlighter.hpp @@ -20,6 +20,7 @@ #define WB_HIGHLIGHTER_HPP_ #include "visitor.hpp" +#include "map_location.hpp" static lg::log_domain log_whiteboard_highlight("whiteboard/highlight"); #define ERR_WB_H LOG_STREAM(err, log_whiteboard_highlight) diff --git a/src/whiteboard/manager.cpp b/src/whiteboard/manager.cpp index cedd0c6eed55..bdcca51c26d9 100644 --- a/src/whiteboard/manager.cpp +++ b/src/whiteboard/manager.cpp @@ -32,6 +32,8 @@ #include "actions/undo.hpp" #include "arrow.hpp" #include "chat_events.hpp" +#include "fake_unit.hpp" +#include "fake_unit_manager.hpp" #include "formula_string_utils.hpp" #include "game_board.hpp" #include "game_preferences.hpp" @@ -710,8 +712,8 @@ void manager::create_temp_move() if(!fake_unit) { // Create temp ghost unit - fake_unit.reset(new game_display::fake_unit(*temp_moved_unit)); - fake_unit->place_on_game_display( resources::screen); + fake_unit.reset(new class fake_unit(*temp_moved_unit)); + fake_unit->place_on_fake_unit_manager( resources::fake_units); fake_unit->set_ghosted(true); } diff --git a/src/whiteboard/manager.hpp b/src/whiteboard/manager.hpp index 7977b097c9fc..3ab49f7568c1 100644 --- a/src/whiteboard/manager.hpp +++ b/src/whiteboard/manager.hpp @@ -21,6 +21,8 @@ #include "side_actions.hpp" +#include "../unit_map.hpp" + #include class CKey; diff --git a/src/whiteboard/move.cpp b/src/whiteboard/move.cpp index 3622e6b7f558..33bd61b36fe8 100644 --- a/src/whiteboard/move.cpp +++ b/src/whiteboard/move.cpp @@ -25,6 +25,8 @@ #include "arrow.hpp" #include "config.hpp" +#include "fake_unit.hpp" +#include "fake_unit_manager.hpp" #include "game_board.hpp" #include "game_end_exceptions.hpp" #include "mouse_events.hpp" @@ -129,10 +131,10 @@ move::move(config const& cfg, bool hidden) arrow_->set_path(route_->steps); // Construct fake_unit_ - fake_unit_.reset(new game_display::fake_unit(*get_unit()) ); + fake_unit_.reset(new fake_unit(*get_unit()) ); if(hidden) fake_unit_->set_hidden(true); - fake_unit_->place_on_game_display(resources::screen); + fake_unit_->place_on_fake_unit_manager(resources::fake_units); fake_unit_->set_ghosted(true); unit_display::move_unit(route_->steps, *fake_unit_, false); //get facing right fake_unit_->set_location(route_->steps.back()); diff --git a/src/whiteboard/move.hpp b/src/whiteboard/move.hpp index 248f969cbe94..72dca2a798b4 100644 --- a/src/whiteboard/move.hpp +++ b/src/whiteboard/move.hpp @@ -20,6 +20,7 @@ #define WB_MOVE_HPP_ #include "action.hpp" +#include "../game_errors.hpp" struct temporary_unit_mover; diff --git a/src/whiteboard/recall.cpp b/src/whiteboard/recall.cpp index f937058aef2c..0b1b96d9a1b4 100644 --- a/src/whiteboard/recall.cpp +++ b/src/whiteboard/recall.cpp @@ -24,10 +24,12 @@ #include "visitor.hpp" #include "actions/create.hpp" +#include "fake_unit.hpp" +#include "fake_unit_manager.hpp" #include "game_display.hpp" -#include "play_controller.hpp" #include "resources.hpp" #include "replay_helper.hpp" +#include "statistics.hpp" #include "synced_context.hpp" #include "team.hpp" #include "unit.hpp" @@ -58,7 +60,7 @@ recall::recall(size_t team_index, bool hidden, const unit& unit, const map_locat action(team_index,hidden), temp_unit_(new class unit(unit)), recall_hex_(recall_hex), - fake_unit_(new game_display::fake_unit(unit) ) + fake_unit_(new fake_unit(unit) ) { this->init(); } @@ -83,7 +85,7 @@ recall::recall(config const& cfg, bool hidden) throw action::ctor_err("recall: Invalid underlying_id"); } - fake_unit_.reset(new game_display::fake_unit(*temp_unit_)); //makes copy of temp_unit_ + fake_unit_.reset(new fake_unit(*temp_unit_)); //makes copy of temp_unit_ this->init(); } @@ -97,7 +99,7 @@ void recall::init() fake_unit_->set_movement(0, true); fake_unit_->set_attacks(0); fake_unit_->set_ghosted(false); - fake_unit_->place_on_game_display( resources::screen); + fake_unit_->place_on_fake_unit_manager( resources::fake_units); } recall::~recall() diff --git a/src/whiteboard/recall.hpp b/src/whiteboard/recall.hpp index adefd9a2e430..6447d651f308 100644 --- a/src/whiteboard/recall.hpp +++ b/src/whiteboard/recall.hpp @@ -20,6 +20,7 @@ #define WB_RECALL_HPP_ #include "action.hpp" +#include "map_location.hpp" namespace wb { diff --git a/src/whiteboard/recruit.cpp b/src/whiteboard/recruit.cpp index 680fb6a166af..0ad53fd79536 100644 --- a/src/whiteboard/recruit.cpp +++ b/src/whiteboard/recruit.cpp @@ -23,7 +23,8 @@ #include "utility.hpp" #include "visitor.hpp" -#include "game_display.hpp" +#include "fake_unit.hpp" +#include "fake_unit_manager.hpp" #include "menu_events.hpp" #include "play_controller.hpp" #include "resources.hpp" @@ -56,7 +57,7 @@ recruit::recruit(size_t team_index, bool hidden, const std::string& unit_name, c unit_name_(unit_name), recruit_hex_(recruit_hex), temp_unit_(create_corresponding_unit()), //auto-ptr ownership transfer - fake_unit_(new game_display::fake_unit(*temp_unit_)), //temp_unit_ *copied* into new fake unit + fake_unit_(new fake_unit(*temp_unit_)), //temp_unit_ *copied* into new fake unit cost_(0) { this->init(); @@ -76,7 +77,7 @@ recruit::recruit(config const& cfg, bool hidden) // Construct temp_unit_ and fake_unit_ temp_unit_ = create_corresponding_unit(); //auto-ptr ownership transfer - fake_unit_.reset(new game_display::fake_unit(*temp_unit_)), //temp_unit_ copied into new fake_unit + fake_unit_.reset(new class fake_unit(*temp_unit_)), //temp_unit_ copied into new fake_unit this->init(); } @@ -87,7 +88,7 @@ void recruit::init() fake_unit_->set_movement(0, true); fake_unit_->set_attacks(0); fake_unit_->set_ghosted(false); - fake_unit_->place_on_game_display(resources::screen); + fake_unit_->place_on_fake_unit_manager(resources::fake_units); cost_ = fake_unit_->type().cost(); } diff --git a/src/whiteboard/recruit.hpp b/src/whiteboard/recruit.hpp index 6b77d4969020..0f82455d1a06 100644 --- a/src/whiteboard/recruit.hpp +++ b/src/whiteboard/recruit.hpp @@ -19,8 +19,10 @@ #ifndef WB_RECRUIT_HPP_ #define WB_RECRUIT_HPP_ +#include #include "action.hpp" +#include "map_location.hpp" namespace wb { diff --git a/src/whiteboard/typedefs.hpp b/src/whiteboard/typedefs.hpp index 90807912a1a1..7626166289d8 100644 --- a/src/whiteboard/typedefs.hpp +++ b/src/whiteboard/typedefs.hpp @@ -37,9 +37,12 @@ static lg::log_domain log_whiteboard("whiteboard"); #include #include -#include "game_display.hpp" +#include "../unit_ptr.hpp" class arrow; +class config; +class fake_unit; +class fake_unit_manager; class game_board; struct map_location; //not used in the typedefs, saves a few forward declarations class unit; @@ -63,7 +66,7 @@ class side_actions; typedef boost::shared_ptr whiteboard_lock; typedef boost::shared_ptr arrow_ptr; -typedef boost::shared_ptr fake_unit_ptr; +typedef boost::shared_ptr fake_unit_ptr; typedef boost::shared_ptr action_ptr; typedef boost::shared_ptr action_const_ptr;