add fake_unit_manager, split off from game_display object

This commit adds two classes -- fake_unit, and fake_unit_manager,
both split off from code contained in game_display. The display
object is reconfigured to hold a pointer to the manager and
display the units it contains. The rest of the code is configured
to add fake units to the manager, not the display.

This improves encapsulation and helps to reduce the game_display
class.
This commit is contained in:
Chris Beck 2014-06-16 13:20:59 -04:00
parent 13155c4f41
commit 06f02b52c5
31 changed files with 332 additions and 208 deletions

View file

@ -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

View file

@ -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

View file

@ -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"

View file

@ -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_ptr<wb::
view_locked_(false),
theme_(theme_cfg, screen_area()),
zoom_(DefaultZoom),
fake_unit_man_(new fake_unit_manager(*this)),
builder_(new terrain_builder(level, &dc_->map(), 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<wb::
{
singleton_ = this;
resources::fake_units = fake_unit_man_.get();
blindfold_ctr_ = 0;
read(level.child_or_empty("display"));
@ -246,6 +250,7 @@ display::display(const display_context * dc, CVideo& video, boost::weak_ptr<wb::
display::~display()
{
singleton_ = NULL;
resources::fake_units = NULL;
}
@ -3032,11 +3037,6 @@ void display::invalidate_animations_location(const map_location& loc) {
}
}
const std::deque<unit*> & display::get_fake_unit_list_for_invalidation() {
static const std::deque<unit*> blah;
return blah;
}
void display::invalidate_animations()
{
new_animation_frame();
@ -3052,7 +3052,7 @@ void display::invalidate_animations()
}
}
}
const std::deque<unit*> & unit_list=get_fake_unit_list_for_invalidation();
const std::deque<unit*> & unit_list = fake_unit_man_->get_fake_unit_list_for_invalidation();
BOOST_FOREACH(const unit* u, unit_list) {
u->refresh();
}

View file

@ -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 @@ public:
* 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<unit*> & get_fake_unit_list_for_invalidation();
/**
* Per-location invalidation called by invalidate_animations()
@ -740,6 +736,7 @@ protected:
theme theme_;
int zoom_;
static int last_zoom_;
boost::scoped_ptr<fake_unit_manager> fake_unit_man_;
boost::scoped_ptr<terrain_builder> builder_;
surface minimap_;
SDL_Rect minimap_location_;

84
src/fake_unit.cpp Normal file
View file

@ -0,0 +1,84 @@
/*
Copyright (C) 2014 by Chris Beck <render787@gmail.com>
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;
}

57
src/fake_unit.hpp Normal file
View file

@ -0,0 +1,57 @@
/*
Copyright (C) 2014 by Chris Beck <render787@gmail.com>
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<unit const &>(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

53
src/fake_unit_manager.cpp Normal file
View file

@ -0,0 +1,53 @@
/*
Copyright (C) 2014 by Chris Beck <render787@gmail.com>
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<unit*>::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;
}

51
src/fake_unit_manager.hpp Normal file
View file

@ -0,0 +1,51 @@
/*
Copyright (C) 2014 by Chris Beck <render787@gmail.com>
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 <deque>
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<unit*> & 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<unit*> fake_units_;
display & my_display_;
};
#endif

View file

@ -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_ptr<wb:
const config& theme_cfg, const config& level) :
display(&board, video, wb, theme_cfg, level),
overlay_map_(),
fake_units_(),
attack_indicator_src_(),
attack_indicator_dst_(),
route_(),
@ -245,14 +246,13 @@ void game_display::draw_invalidated()
halo::unrender(invalidated_);
display::draw_invalidated();
BOOST_FOREACH(unit* temp_unit, fake_units_) {
BOOST_FOREACH(unit* temp_unit, fake_unit_man_->get_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<unit*> & 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<unit*>::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())

View file

@ -154,63 +154,7 @@ protected:
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<unit*> & 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<unit const &>(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 @@ private:
overlay_map overlay_map_;
/// collection of units destined to be drawn but not put into the unit map
std::deque<unit*> fake_units_;
// Locations of the attack direction indicator's parts
map_location attack_indicator_src_;
map_location attack_indicator_dst_;

View file

@ -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<map_location> fake_unit_path(const unit& fake_unit, const std::vector<std::string>& xvals, const std::vector<std::string>& 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<util::unique_ptr<game_display::fake_unit> > units(
new util::unique_ptr<game_display::fake_unit>[num_units]);
boost::scoped_array<util::unique_ptr<fake_unit> > units(
new util::unique_ptr<fake_unit>[num_units]);
std::vector<std::vector<map_location> > 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<std::string> xvals = utils::split(config["x"]);
const std::vector<std::string> 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";

View file

@ -27,6 +27,7 @@ namespace resources
soundsource::manager *soundsources = NULL;
std::vector<team> *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;

View file

@ -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<team> *teams;
extern fake_unit_manager *fake_units;
extern ::tod_manager *tod_manager;
extern pathfind::manager *tunnels;
extern actions::undo_list *undo_stack;

View file

@ -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 <boost/foreach.hpp>

View file

@ -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;

View file

@ -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 @@ private: // data
unit * shown_unit_; /// The unit to be (re-)shown after an animation finishes.
const std::vector<map_location>& path_;
size_t current_;
game_display::fake_unit * temp_unit_ptr_;
fake_unit * temp_unit_ptr_;
bool was_hidden_;
bool is_enemy_;
};

View file

@ -23,6 +23,7 @@
#include "recall.hpp"
#include "suppose_dead.hpp"
#include "config.hpp"
#include "game_board.hpp"
#include "resources.hpp"
#include "team.hpp"

View file

@ -20,6 +20,8 @@
#define WB_ACTION_HPP_
#include "typedefs.hpp"
#include "map_location.hpp"
#include "../game_errors.hpp"
namespace wb {

View file

@ -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"

View file

@ -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 <boost/foreach.hpp>

View file

@ -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)

View file

@ -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);
}

View file

@ -21,6 +21,8 @@
#include "side_actions.hpp"
#include "../unit_map.hpp"
#include <boost/noncopyable.hpp>
class CKey;

View file

@ -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());

View file

@ -20,6 +20,7 @@
#define WB_MOVE_HPP_
#include "action.hpp"
#include "../game_errors.hpp"
struct temporary_unit_mover;

View file

@ -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()

View file

@ -20,6 +20,7 @@
#define WB_RECALL_HPP_
#include "action.hpp"
#include "map_location.hpp"
namespace wb
{

View file

@ -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();
}

View file

@ -19,8 +19,10 @@
#ifndef WB_RECRUIT_HPP_
#define WB_RECRUIT_HPP_
#include <string>
#include "action.hpp"
#include "map_location.hpp"
namespace wb
{

View file

@ -37,9 +37,12 @@ static lg::log_domain log_whiteboard("whiteboard");
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
#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<bool> whiteboard_lock;
typedef boost::shared_ptr<arrow> arrow_ptr;
typedef boost::shared_ptr<game_display::fake_unit> fake_unit_ptr;
typedef boost::shared_ptr<fake_unit> fake_unit_ptr;
typedef boost::shared_ptr<action> action_ptr;
typedef boost::shared_ptr<action const> action_const_ptr;