Commit accidentally missing files from patch #2640...
...without gabba's changes to them.
This commit is contained in:
parent
df4ba3108c
commit
d90db3a55c
2 changed files with 181 additions and 0 deletions
115
src/whiteboard/suppose_dead.cpp
Normal file
115
src/whiteboard/suppose_dead.cpp
Normal file
|
@ -0,0 +1,115 @@
|
|||
#include "suppose_dead.hpp"
|
||||
|
||||
#include "visitor.hpp"
|
||||
#include "manager.hpp"
|
||||
#include "side_actions.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
#include "arrow.hpp"
|
||||
#include "config.hpp"
|
||||
#include "foreach.hpp"
|
||||
#include "game_display.hpp"
|
||||
#include "game_end_exceptions.hpp"
|
||||
#include "mouse_events.hpp"
|
||||
#include "play_controller.hpp"
|
||||
#include "replay.hpp"
|
||||
#include "resources.hpp"
|
||||
#include "team.hpp"
|
||||
#include "unit.hpp"
|
||||
#include "unit_display.hpp"
|
||||
#include "unit_map.hpp"
|
||||
|
||||
namespace wb
|
||||
{
|
||||
|
||||
std::ostream& operator<<(std::ostream &s, suppose_dead_ptr sup_d)
|
||||
{
|
||||
assert(sup_d);
|
||||
return sup_d->print(s);
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream &s, suppose_dead_const_ptr sup_d)
|
||||
{
|
||||
assert(sup_d);
|
||||
return sup_d->print(s);
|
||||
}
|
||||
|
||||
std::ostream& suppose_dead::print(std::ostream &s) const
|
||||
{
|
||||
s << "Suppose-dead for unit " << get_unit()->name() << " [" << get_unit()->id() << "] "
|
||||
<< "at (" << loc_ << ")";
|
||||
return s;
|
||||
}
|
||||
|
||||
suppose_dead::suppose_dead(size_t team_index, unit& curr_unit)
|
||||
: action(team_index)
|
||||
, unit_(&curr_unit)
|
||||
, unit_id_(curr_unit.id())
|
||||
, loc_(curr_unit.get_location())
|
||||
, valid_(true)
|
||||
{
|
||||
assert(unit_);
|
||||
}
|
||||
|
||||
suppose_dead::~suppose_dead()
|
||||
{
|
||||
}
|
||||
|
||||
void suppose_dead::accept(visitor& v)
|
||||
{
|
||||
v.visit_suppose_dead(shared_from_this());
|
||||
}
|
||||
|
||||
bool suppose_dead::execute()
|
||||
{
|
||||
valid_=false;
|
||||
return false;
|
||||
}
|
||||
|
||||
void suppose_dead::apply_temp_modifier(unit_map& unit_map)
|
||||
{
|
||||
// Remove the unit
|
||||
unit const* removed_unit = unit_map.extract(get_source_hex());
|
||||
DBG_WB << "Suppose dead: Temporarily removing unit " << removed_unit->name() << " [" << removed_unit->id()
|
||||
<< "] from (" << get_source_hex() << ")\n";
|
||||
|
||||
// Just check to make sure we removed the unit we expected to remove
|
||||
assert(get_unit() == removed_unit);
|
||||
}
|
||||
|
||||
void suppose_dead::remove_temp_modifier(unit_map& unit_map)
|
||||
{
|
||||
// Just check to make sure the hex is empty
|
||||
unit_map::iterator unit_it = resources::units->find(get_source_hex());
|
||||
assert(unit_it == resources::units->end());
|
||||
|
||||
// Restore the unit
|
||||
unit_map.insert(unit_);
|
||||
}
|
||||
|
||||
void suppose_dead::draw_hex(const map_location& hex)
|
||||
{
|
||||
if(hex == loc_) //add symbol to hex
|
||||
{
|
||||
//@todo: Possibly use a different layer
|
||||
const display::tdrawing_layer layer = display::LAYER_ARROWS;
|
||||
|
||||
int xpos = resources::screen->get_location_x(loc_);
|
||||
int ypos = resources::screen->get_location_y(loc_);
|
||||
|
||||
resources::screen->drawing_buffer_add(layer, loc_, xpos, ypos,
|
||||
image::get_image("whiteboard/suppose_dead.png", image::SCALED_TO_HEX));
|
||||
}
|
||||
}
|
||||
|
||||
bool suppose_dead::is_numbering_hex(const map_location& hex) const
|
||||
{
|
||||
return hex == get_source_hex();
|
||||
}
|
||||
|
||||
void suppose_dead::set_valid(bool valid)
|
||||
{
|
||||
valid_ = valid;
|
||||
}
|
||||
|
||||
} // end namespace wb
|
66
src/whiteboard/suppose_dead.hpp
Normal file
66
src/whiteboard/suppose_dead.hpp
Normal file
|
@ -0,0 +1,66 @@
|
|||
#ifndef WB_SUPPOSE_DEAD_HPP_
|
||||
#define WB_SUPPOSE_DEAD_HPP_
|
||||
|
||||
#include "action.hpp"
|
||||
#include "map_location.hpp"
|
||||
|
||||
namespace wb {
|
||||
|
||||
/**
|
||||
* A planned action that temporarily removes a unit from the map
|
||||
* for planning purposes
|
||||
*/
|
||||
class suppose_dead
|
||||
: public action
|
||||
, public boost::enable_shared_from_this<suppose_dead>
|
||||
{
|
||||
friend class validate_visitor;
|
||||
friend class highlight_visitor;
|
||||
|
||||
public:
|
||||
///Future unit map must be valid during construction, so that suppose_dead can find its unit
|
||||
suppose_dead(size_t team_index, unit& curr_unit);
|
||||
virtual ~suppose_dead();
|
||||
|
||||
/** Return the unit targeted by this action. Null if unit doesn't exist. */
|
||||
virtual unit* get_unit() const { return unit_; }
|
||||
/** Return the location at which this action was planned. */
|
||||
virtual map_location get_source_hex() const { return loc_; }
|
||||
|
||||
// Inherits from action
|
||||
// {
|
||||
virtual std::ostream& print(std::ostream& s) const;
|
||||
|
||||
virtual void accept(visitor& v);
|
||||
|
||||
virtual bool execute();
|
||||
|
||||
/** Applies temporarily the result of this action to the specified unit map. */
|
||||
virtual void apply_temp_modifier(unit_map& unit_map);
|
||||
/** Removes the result of this action from the specified unit map. */
|
||||
virtual void remove_temp_modifier(unit_map& unit_map);
|
||||
|
||||
/** Gets called by display when drawing a hex, to allow actions to draw to the screen. */
|
||||
virtual void draw_hex(const map_location& hex);
|
||||
|
||||
virtual bool is_numbering_hex(const map_location& hex) const;
|
||||
|
||||
virtual void set_valid(bool valid);
|
||||
virtual bool is_valid() { return valid_; }
|
||||
// } End Inherits from action
|
||||
|
||||
protected:
|
||||
unit* unit_;
|
||||
std::string unit_id_;
|
||||
map_location loc_;
|
||||
|
||||
bool valid_;
|
||||
};
|
||||
|
||||
/** Dumps a suppose_dead on a stream, for debug purposes. */
|
||||
std::ostream &operator<<(std::ostream &s, suppose_dead_ptr sup_d);
|
||||
std::ostream &operator<<(std::ostream &s, suppose_dead_const_ptr sup_d);
|
||||
} // end namespace wb
|
||||
|
||||
#endif /* WB_SUPPOSE_DEAD_HPP_ */
|
||||
|
Loading…
Add table
Reference in a new issue