51 out <<
"Content of side_actions:";
52 for(
size_t turn = 0; turn < side_actions.
num_turns(); ++turn) {
53 out <<
"\n Turn " << turn;
57 out <<
"\n (" << count++ <<
") " << *it;
65 if(side_actions.
empty()) {
83 size_t mid = (begin+
end) / 2;
122 return queue(turn, action);
127 bool current_turn_unplanned =
turn_size(0) == 0;
130 if(current_turn_unplanned && turn == 1) {
139 assert(position <=
end());
143 std::pair<iterator,bool>
res =
actions_.insert(position, action);
158 bool future_only = turn_num == 1 &&
num_turns() == 0;
160 bool current_turn_unplanned =
turn_size(0) == 0;
163 assert(turn_num <=
num_turns() || future_only);
176 }
else if(current_turn_unplanned && turn_num == 0) {
186 assert(position >
begin());
187 assert(position <
end());
205 assert(position <
end());
209 bool deleting_last_element = next ==
end();
214 if(deleting_last_element) {
225 if(
get_turn(next) == turn_of_position) {
228 assert(turn_of_position == 0);
253 , team_index_defined_(false)
273 std::vector<size_t>& team_numbers = result.
team_numbers;
279 if((*it)->is_numbering_hex(hex)) {
282 size_t index = numbers_to_draw.size();
283 numbers_to_draw.push_back(number);
287 if(hlighter->get_main_highlight().lock() == *it) {
292 if(
action.lock() == *it) {
293 secondary_numbers.insert(index);
313 ERR_WB <<
"Modifying action queue while temp modifiers are applied!!!" << std::endl;
322 LOG_WB <<
"Before execution, " << *
this <<
"\n";
326 if(!action->valid()) {
327 LOG_WB <<
"Invalid action sent to execution, deleting.\n";
332 bool action_successful;
334 bool action_complete;
336 action->execute(action_successful, action_complete);
337 }
catch (return_to_play_side_exception&) {
339 LOG_WB <<
"End turn exception caught during execution, deleting action. " << *
this <<
"\n";
349 std::stringstream ss;
350 ss <<
"After " << (action_successful?
"successful":
"failed") <<
" execution ";
351 if(action_complete) {
352 ss <<
"with deletion, ";
356 ss <<
"without deletion, ";
367 return action_successful;
398 ERR_WB <<
"Modifying action queue while temp modifiers are applied!!!" << std::endl;
401 LOG_WB <<
"Inserted into turn #" <<
get_turn(valid_position) <<
" at position #"
404 return valid_position;
410 ERR_WB <<
"Modifying action queue while temp modifiers are applied!!!" << std::endl;
413 LOG_WB <<
"Queue into turn #" << turn_num <<
" : " << action <<
"\n";
423 struct swapable_with_move:
public visitor
427 bool valid()
const {
return valid_; }
430 valid_ = second_->get_dest_hex() != first->get_source_hex();
434 visit(boost::static_pointer_cast<move>(first));
438 check_recruit_recall(first->get_recruit_hex());
442 check_recruit_recall(first->get_recall_hex());
460 if(!(it == sa_.end() || position_ < it)) {
476 ERR_WB <<
"Modifying action queue while temp modifiers are applied!!!" << std::endl;
479 assert(position <=
end());
492 if(previous_ptr && current_ptr && previous_ptr.get() == current_ptr.get()) {
496 if(
move_ptr second = boost::dynamic_pointer_cast<move>(*position)) {
497 swapable_with_move
check(*
this, position, second);
498 (*previous)->accept(check);
504 LOG_WB <<
"Before bumping earlier, " << *
this <<
"\n";
506 int turn_number =
get_turn(position);
508 int last_position =
turn_size(turn_number) - 1;
509 LOG_WB <<
"In turn #" << turn_number
510 <<
", bumping action #" << action_number <<
"/" << last_position
511 <<
" to position #" << action_number - 1 <<
"/" << last_position <<
".\n";
517 LOG_WB <<
"After bumping earlier, " << *
this <<
"\n";
524 assert(position <
end());
527 if(position ==
end()) {
531 if(position ==
end()) {
540 ERR_WB <<
"Modifying action queue while temp modifiers are applied!!!" << std::endl;
543 assert(position <
end());
549 if(validate_after_delete) {
600 std::deque<action_ptr>
actions (action_its.first, action_its.second);
615 DBG_WB <<
"Changing gold spent for side " << (
team_index() + 1) <<
"; old value: "
622 DBG_WB <<
"Resetting gold spent for side " << (
team_index() + 1) <<
" to 0.\n";
653 if(result !=
end()) {
703 size_t turn = cmd[
"turn"].to_int();
704 size_t pos = cmd[
"pos"].to_int();
707 ERR_WB <<
"side_actions::execute_network_command(): received invalid action data!" << std::endl;
713 ERR_WB <<
"side_actions::execute_network_command(): received invalid insertion position!" << std::endl;
717 LOG_WB <<
"Command received: action inserted on turn #" << turn <<
", position #" << pos <<
": " << act <<
"\n";
724 }
else if(type==
"replace") {
725 size_t turn = cmd[
"turn"].to_int();
726 size_t pos = cmd[
"pos"].to_int();
729 ERR_WB <<
"side_actions::execute_network_command(): received invalid action data!" << std::endl;
735 ERR_WB <<
"side_actions::execute_network_command(): received invalid pos!" << std::endl;
740 ERR_WB <<
"side_actions::execute_network_command(): replace failed!" << std::endl;
744 LOG_WB <<
"Command received: action replaced on turn #" << turn <<
", position #" << pos <<
": " << act <<
"\n";
745 }
else if(type==
"remove") {
746 size_t turn = cmd[
"turn"].to_int();
747 size_t pos = cmd[
"pos"].to_int();
751 ERR_WB <<
"side_actions::execute_network_command(): received invalid pos!" << std::endl;
757 LOG_WB <<
"Command received: action removed on turn #" << turn <<
", position #" << pos <<
"\n";
763 }
else if(type==
"bump_later") {
764 size_t turn = cmd[
"turn"].to_int();
765 size_t pos = cmd[
"pos"].to_int();
769 ERR_WB <<
"side_actions::execute_network_command(): received invalid pos!" << std::endl;
777 LOG_WB <<
"Command received: action bumped later from turn #" << turn <<
", position #" << pos <<
"\n";
782 }
else if(type==
"clear") {
783 LOG_WB <<
"Command received: clear\n";
785 }
else if(type==
"refresh") {
786 LOG_WB <<
"Command received: refresh\n";
791 ERR_WB <<
"side_actions::execute_network_command(): received invalid type!" << std::endl;
801 result[
"type"] =
"insert";
802 result[
"turn"] =
static_cast<int>(turn_num);
803 result[
"pos"] =
static_cast<int>(
pos);
804 result.
add_child(
"action", act->to_config());
819 result[
"type"] =
"replace";
820 result[
"turn"] =
static_cast<int>(
get_turn(pos));
822 result.
add_child(
"action", act->to_config());
828 result[
"type"] =
"remove";
829 result[
"turn"] =
static_cast<int>(
get_turn(pos));
836 result[
"type"] =
"bump_later";
837 result[
"turn"] =
static_cast<int>(
get_turn(pos));
844 result[
"type"] =
"clear";
850 result[
"type"] =
"refresh";
862 std::set<unit_const_ptr> lazy_units;
866 lazy_units.insert(u);
873 while(itor !=
begin()) {
877 if(lazy_units.find(act->get_unit()) != lazy_end) {
void clear()
Clears the stack of undoable (and redoable) actions.
container::iterator iterator
child_itors child_range(const std::string &key)
iterator end()
Returns the iterator for the position after the last executed action within the actions queue...
net_cmd make_net_cmd_insert(size_t turn_num, size_t pos, action_const_ptr) const
net_cmd make_net_cmd_replace(const_iterator const &pos, action_const_ptr) const
static void check(LexState *ls, int c)
size_t position_in_turn(const_iterator it) const
Returns the position of a given iterator in its turn.
bool invalidate(const map_location &loc)
Function to invalidate a specific tile for redrawing.
net_cmd make_net_cmd_refresh() const
size_t underlying_id() const
The unique internal ID of the unit.
boost::shared_ptr< attack > attack_ptr
action_limits turn_beginnings_
Contains a list of iterator to the beginning of each turn.
GLuint GLuint GLsizei GLenum type
iterator push_front(size_t turn, action_ptr action)
Pushes an action in front of a given turn.
std::vector< int > numbers_to_draw
iterator turn_begin(size_t turn_num)
size_t get_turn(const_iterator it) const
Returns the turn of a given iterator planned execution.
size_t turn_size(size_t turn_num) const
Returns the number of actions planned for turn turn_num.
size_t num_turns() const
Returns the number of turns that have plans.
void turn_shift()
Shift turn.
size_t get_turn(const_iterator it) const
Returns the turn of a given iterator planned execution.
action_set::index< chronological >::type::iterator iterator
bool replace(iterator it, action_ptr act)
Replaces the action at a given position with another action.
iterator synced_erase(iterator itor)
Contains the exception interfaces used to signal completion of a scenario, campaign or turn...
static config unit_name(const unit *u)
const std::string number
template to number regex
iterator bump_earlier(iterator position)
Moves an action earlier in the execution order.
iterator bump_earlier(iterator position)
Moves an action earlier in the execution order.
iterator queue_suppose_dead(size_t turn_num, unit &curr_unit, map_location const &loc)
Queues a suppose_dead to be executed last.
std::set< size_t > secondary_numbers
boost::weak_ptr< action > weak_action_ptr
int gold_spent_
Used to store gold "spent" in planned recruits/recalls when the future unit map is applied...
iterator find_last_action_of(unit const &unit, iterator start_position)
Finds the last action that belongs to this unit, starting the search backwards from the specified pos...
net_cmd make_net_cmd_remove(const_iterator const &pos) const
iterator remove_action(iterator position, bool validate_after_delete=true)
Deletes the action at the specified position.
void get_numbers(const map_location &hex, numbers_t &result)
Gets called when display is drawing a hex to determine which numbers to draw on it.
boost::shared_ptr< suppose_dead > suppose_dead_ptr
iterator queue_recruit(size_t turn_num, const std::string &unit_name, const map_location &recruit_hex)
Queues a recruit to be executed last.
iterator find_first_action_at(map_location hex)
Find the first action occurring at a given hex.
size_t get_turn_impl(size_t begin, size_t end, const_iterator it) const
Binary search to find the occuring turn of the action pointed by an iterator.
std::deque< action_ptr > actions_of(unit const &unit)
size_t count_actions_of(unit const &unit)
std::vector< size_t > team_numbers
iterator queue_move(size_t turn_num, unit &mover, const pathfind::marked_route &route, arrow_ptr arrow, fake_unit_ptr fake_unit)
Queues a move to be executed last.
iterator erase(iterator position)
Deletes the action at the specified position.
size_t num_turns() const
Returns the number of turns that have plans.
Arrows destined to be drawn on the map.
filter_context * filter_con
iterator queue_action(size_t turn_num, action_ptr action)
Queues an action to be executed last.
bool execute(iterator position)
Executes the specified action, if it exists in the queue.
iterator queue_recall(size_t turn_num, const unit &unit, const map_location &recall_hex)
Queues a recall to be executed last.
range_t iter_turn(size_t turn_num)
Returns an iterator range corresponding to the requested turn.
config & add_child(const std::string &key)
iterator insert_action(iterator position, action_ptr action)
Inserts an action at the specified position.
iterator queue_attack(size_t turn_num, unit &mover, const map_location &target_hex, int weapon_choice, const pathfind::marked_route &route, arrow_ptr arrow, fake_unit_ptr fake_unit)
Queues an attack or attack-move to be executed last.
net_cmd make_net_cmd_bump_later(const_iterator const &pos) const
Structure which holds a single route and marks for special events.
GLuint GLuint GLsizei count
size_t get_turn_num_of(unit const &) const
Determines the appropriate turn number for the next action planned for this unit. ...
bool empty() const
Indicates whether the action queue is empty.
Encapsulates the map of the game.
Various functions related to the creation of units (recruits, recalls, and placed units)...
size_t team_index()
Returns the team index this action queue belongs to.
Tag for action_set's hashed_non_unique index.
void execute_net_cmd(net_cmd const &)
static action_ptr from_config(config const &, bool hidden)
Constructs an object of a subclass of wb::action using a config.
iterator bump_later(iterator position)
Moves an action later in the execution order.
std::map< std::string, tfilter >::iterator itor
iterator synced_enqueue(size_t turn_num, action_ptr to_insert)
iterator synced_insert(iterator itor, action_ptr to_insert)
iterator begin()
Returns the iterator for the first (executed earlier) action within the actions queue.
void hide()
Sets whether or not the contents should be drawn on the screen.
iterator turn_begin(size_t turn_num)
Returns the iterator for the first (executed earlier) action of a given turn within the actions queue...
iterator turn_end(size_t turn_num)
net_cmd make_net_cmd_clear() const
iterator begin()
Returns the iterator for the first (executed earlier) action within the actions queue.
iterator turn_end(size_t turn_num)
action_set::index< T >::type & get()
Returns a given index.
void reset_gold_spent()
Set gold spent back to zero.
bool empty() const
Indicates whether the action queue is empty.
iterator safe_insert(size_t turn_num, size_t pos, action_ptr to_insert)
void change_gold_spent_by(int difference)
Used to track gold spending by recruits/recalls when building the future unit map.
bool find(E event, F functor)
Tests whether an event handler is available.
boost::shared_ptr< move > move_ptr
config & child(const std::string &key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
container::const_iterator const_iterator
Various functions that implement the undoing (and redoing) of in-game commands.
iterator insert(iterator position, action_ptr action)
Inserts an action at the specified position.
Tag for action_set's hashed_non_unique index.
unit_const_ptr find_backup_leader(const unit &leader)
For a given leader on a keep, find another leader on another keep in the same castle.
std::ostream & operator<<(std::ostream &s, action_ptr action)
iterator end()
Returns the iterator for the position after the last executed action within the actions queue...
iterator find_first_action_of(std::pair< T, T > between, iterator limit, Compare comp)
Find the (chronologically) first action between the iterators between.first and between.second but after or equals to limit with respect to the predicate comp.
boost::shared_ptr< wb::manager > whiteboard
actions::undo_list * undo_stack
iterator safe_erase(iterator const &itor)
size_t size() const
Returns the number of actions in the action queue.
void set_team_index(size_t team_index)
Must be called only once, right after the team that owns this side_actions is added to the teams vect...
boost::shared_ptr< recall > recall_ptr
Abstract base class for all the whiteboard planned actions.
A config object defines a single node in a WML file, with access to child nodes.
iterator queue(size_t turn_num, action_ptr action)
Queues an action to be executed last.
GLsizei const GLcharARB ** string
This internal whiteboard class holds the planned action queues for a team, and offers many utility me...
bool execute_next()
Executes the first action in the queue, and then deletes it.
Holds a temporary unit that can be drawn on the map without being placed in the unit_map.
action_set::index< chronological >::type::const_iterator const_iterator
size_t turn_size(size_t turn_num) const
Returns the number of actions planned for turn turn_num.
boost::shared_ptr< recruit > recruit_ptr
bool unit_has_actions(unit const &unit)
Abstract base class for all the visitors (cf GoF Visitor Design Pattern) the whiteboard uses...
void clear()
Empties the action queue.
iterator bump_later(iterator position)
Moves an action later in the execution order.
const std::string valid
Little parts of regex templates used to parse Wml annoations.