Whiteboard: transform move/attack...

...to use pathfind::marked_route internally, step 1.
This commit is contained in:
Gabriel Morin 2010-07-22 00:31:48 +00:00
parent 3edcc8486f
commit 4111558f4f
8 changed files with 29 additions and 23 deletions

View file

@ -44,9 +44,9 @@ std::ostream& attack::print(std::ostream& s) const
return s;
}
attack::attack(const map_location& target_hex, int weapon_choice, const map_location& source_hex, const map_location& dest_hex,
attack::attack(const map_location& target_hex, int weapon_choice, const pathfind::marked_route& route,
arrow_ptr arrow, fake_unit_ptr fake_unit)
: move(source_hex, dest_hex, arrow, fake_unit)
: move(route, arrow, fake_unit)
, target_hex_(target_hex), weapon_choice_(weapon_choice)
{

View file

@ -36,7 +36,7 @@ public:
friend std::ostream& operator<<(std::ostream& s, attack const& attack);
///Future unit map must be valid during construction, so that attack can find its units
attack(const map_location& target_hex, int weapon_choice, const map_location& source_hex, const map_location& dest_hex,
attack(const map_location& target_hex, int weapon_choice, const pathfind::marked_route& route,
arrow_ptr arrow, fake_unit_ptr fake_unit);
virtual ~attack();

View file

@ -338,18 +338,16 @@ void manager::save_temp_move()
{
scoped_planned_unit_map planned_unit_map;
std::vector<map_location> steps;
arrow_ptr move_arrow;
fake_unit_ptr fake_unit;
steps = route_->steps;
move_arrow = arrow_ptr(move_arrow_);
fake_unit = fake_unit_ptr(fake_unit_);
on_deselect_hex();
fake_unit->set_disabled_ghosted(false);
viewer_actions()->queue_move(steps.front(), steps.back(), move_arrow, fake_unit);
viewer_actions()->queue_move(*route_, move_arrow, fake_unit);
}
}
@ -367,9 +365,8 @@ void manager::save_temp_attack(const map_location& attack_from, const map_locati
move_arrow = arrow_ptr(move_arrow_);
fake_unit = fake_unit_ptr(fake_unit_);
steps = route_->steps;
assert(steps.back() == attack_from);
source_hex = steps.front();
assert(route_->steps.back() == attack_from);
source_hex = route_->steps.front();
fake_unit->set_disabled_ghosted(false);
}
@ -390,7 +387,7 @@ void manager::save_temp_attack(const map_location& attack_from, const map_locati
if (weapon_choice >= 0)
{
viewer_actions()->queue_attack(target_hex, weapon_choice, source_hex, attack_from, move_arrow, fake_unit);
viewer_actions()->queue_attack(target_hex, weapon_choice, *route_, move_arrow, fake_unit);
}
resources::screen->invalidate(target_hex);

View file

@ -61,17 +61,21 @@ static team& get_current_team()
return current_team;
}
move::move(const map_location& source_hex, const map_location& target_hex,
move::move(const pathfind::marked_route& route,
arrow_ptr arrow, fake_unit_ptr fake_unit)
: unit_(NULL),
unit_id_(),
source_hex_(source_hex),
dest_hex_(target_hex),
route_(new pathfind::marked_route(route)),
source_hex_(),
dest_hex_(),
movement_cost_(0),
arrow_(arrow),
fake_unit_(fake_unit),
valid_(true)
{
assert(!route_->steps.empty());
source_hex_ = route_->steps.front();
dest_hex_ = route_->steps.back();
unit_ = resources::whiteboard->find_future_unit(source_hex_);
assert(unit_);

View file

@ -23,8 +23,6 @@
#include "map_location.hpp"
#include "typedefs.hpp"
#include <boost/enable_shared_from_this.hpp>
namespace wb {
/**
@ -44,7 +42,7 @@ public:
static const std::string ARROW_STYLE_INVALID;
///Future unit map must be valid during construction, so that move can find its unit
move(const map_location& source_hex, const map_location& target_hex, arrow_ptr arrow,
move(const pathfind::marked_route& route, arrow_ptr arrow,
fake_unit_ptr fake_unit);
virtual ~move();
@ -78,6 +76,7 @@ public:
protected:
unit* unit_;
std::string unit_id_;
boost::scoped_ptr<pathfind::marked_route> route_;
map_location source_hex_;
map_location dest_hex_;
int movement_cost_;

View file

@ -132,19 +132,18 @@ side_actions::iterator side_actions::execute(side_actions::iterator position)
// return insert_action(position, action);
//}
side_actions::iterator side_actions::queue_move(const map_location& source_hex,
const map_location& target_hex, arrow_ptr arrow, fake_unit_ptr fake_unit)
side_actions::iterator side_actions::queue_move(const pathfind::marked_route& route, arrow_ptr arrow, fake_unit_ptr fake_unit)
{
action_ptr action(new move(source_hex, target_hex, arrow, fake_unit));
action_ptr action(new move(route, arrow, fake_unit));
LOG_WB << "Created: " << *action <<"\n";
return queue_action(action);
}
side_actions::iterator side_actions::queue_attack(const map_location& target_hex, int weapon_choice,
const map_location& source_hex, const map_location& dest_hex,
const pathfind::marked_route& route,
arrow_ptr arrow, fake_unit_ptr fake_unit)
{
action_ptr action(new attack(target_hex, weapon_choice, source_hex, dest_hex, arrow, fake_unit));
action_ptr action(new attack(target_hex, weapon_choice, route, arrow, fake_unit));
LOG_WB << "Created: " << *action <<"\n";
return queue_action(action);
}

View file

@ -88,14 +88,14 @@ public:
* Queues a move to be executed last
* @return The queued move's position
*/
iterator queue_move(const map_location& source_hex, const map_location& target_hex,
iterator queue_move(const pathfind::marked_route& route,
arrow_ptr arrow, fake_unit_ptr fake_unit);
/**
* Queues an attack or attack-move to be executed last
* @return The queued attack's position
*/
iterator queue_attack(const map_location& target_hex, int weapon_choice, const map_location& source_hex, const map_location& dest_hex,
iterator queue_attack(const map_location& target_hex, int weapon_choice, const pathfind::marked_route& route,
arrow_ptr arrow, fake_unit_ptr fake_unit);
/**

View file

@ -28,8 +28,10 @@ static lg::log_domain log_whiteboard("whiteboard");
#define LOG_WB LOG_STREAM(info, log_whiteboard)
#define DBG_WB LOG_STREAM(debug, log_whiteboard)
#include <boost/scoped_ptr.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <deque>
#include <ostream> //used for << operators
@ -38,6 +40,11 @@ struct map_location; //not used in the typedefs, saves a few forward declaration
class unit;
class unit_map; //not used in the typedefs, saves a few forward declarations
namespace pathfind {
struct plain_route;
struct marked_route;
}
namespace wb {
class action;