54 out <<
"Content of side_actions:";
56 out <<
"\n Turn " << turn;
60 out <<
"\n (" << count++ <<
") " << *it;
85 ERR_WB <<
"get_turn: begin >= end";
88 ERR_WB <<
"get_turn failed";
134 bool current_turn_unplanned =
turn_size(0) == 0;
137 if(current_turn_unplanned && turn == 1) {
146 assert(position <=
end());
148 bool first = position ==
begin();
165 bool future_only = turn_num == 1 &&
num_turns() == 0;
167 bool current_turn_unplanned =
turn_size(0) == 0;
170 assert(turn_num <=
num_turns() || future_only);
183 }
else if(current_turn_unplanned && turn_num == 0) {
193 assert(position >
begin());
194 assert(position <
end());
200 actions_.replace(position - 1, rhs);
212 assert(position <
end());
216 bool deleting_last_element = next ==
end();
221 if(deleting_last_element) {
232 if (it == position) {
237 std::size_t turn_of_position = std::distance(
turn_beginnings_.begin(), beginning);
239 if(
get_turn(next) == turn_of_position) {
242 assert(turn_of_position == 0);
258 for(
iterator it = last-1; it>first; --it) {
268 , team_index_defined_(false)
288 std::vector<std::size_t>& team_numbers = result.
team_numbers;
294 if((*it)->is_numbering_hex(hex)) {
296 std::size_t number = (it -
begin()) + 1;
297 std::size_t
index = numbers_to_draw.size();
298 numbers_to_draw.push_back(number);
302 if(hlighter->get_main_highlight().lock() == *it) {
307 if(
action.lock() == *it) {
308 secondary_numbers.insert(
index);
328 ERR_WB <<
"Modifying action queue while temp modifiers are applied!!!";
337 LOG_WB <<
"Before execution, " << *
this;
342 LOG_WB <<
"Invalid action sent to execution, deleting.";
347 bool action_successful;
349 bool action_complete;
354 LOG_WB <<
"End turn exception caught during execution, deleting action. " << *
this;
365 WRN_WB <<
"not clearing undo stack because dsu is active";
369 std::stringstream ss;
370 ss <<
"After " << (action_successful?
"successful":
"failed") <<
" execution ";
371 if(action_complete) {
372 ss <<
"with deletion, ";
376 ss <<
"without deletion, ";
387 return action_successful;
418 ERR_WB <<
"Modifying action queue while temp modifiers are applied!!!";
421 LOG_WB <<
"Inserted into turn #" <<
get_turn(valid_position) <<
" at position #"
424 return valid_position;
430 ERR_WB <<
"Modifying action queue while temp modifiers are applied!!!";
433 LOG_WB <<
"Queue into turn #" << turn_num <<
" : " <<
action;
443 struct swapable_with_move:
public visitor
447 bool valid()
const {
return valid_; }
450 valid_ = second_->get_dest_hex() != first->get_source_hex();
454 visit(std::static_pointer_cast<move>(first));
458 check_recruit_recall(first->get_recruit_hex());
462 check_recruit_recall(first->get_recall_hex());
480 if(!(it == sa_.end() || position_ < it)) {
496 ERR_WB <<
"Modifying action queue while temp modifiers are applied!!!";
499 assert(position <=
end());
512 if(previous_ptr && current_ptr && previous_ptr.get() == current_ptr.get()) {
516 if(
move_ptr second = std::dynamic_pointer_cast<move>(*position)) {
517 swapable_with_move check(*
this, position, second);
518 (*previous)->accept(check);
524 LOG_WB <<
"Before bumping earlier, " << *
this;
526 int turn_number =
get_turn(position);
528 int last_position =
turn_size(turn_number) - 1;
529 LOG_WB <<
"In turn #" << turn_number
530 <<
", bumping action #" << action_number <<
"/" << last_position
531 <<
" to position #" << action_number - 1 <<
"/" << last_position
539 LOG_WB <<
"After bumping earlier, " << *
this;
546 assert(position <
end());
549 if(position ==
end()) {
553 if(position ==
end()) {
562 ERR_WB <<
"Modifying action queue while temp modifiers are applied!!!";
565 assert(position <
end());
582 if(validate_after_delete) {
669 std::deque<action_ptr>
actions (action_its.first, action_its.second);
684 DBG_WB <<
"Changing gold spent for side " << (
team_index() + 1) <<
"; old value: "
691 DBG_WB <<
"Resetting gold spent for side " << (
team_index() + 1) <<
" to 0.";
698 if(
move_ptr mp = std::dynamic_pointer_cast<move>(*it)) {
699 if(
mp->raw_uid() == old_id) {
735 if(result !=
end()) {
782 std::string
type = cmd[
"type"];
785 std::size_t turn = cmd[
"turn"].to_int();
786 std::size_t pos = cmd[
"pos"].to_int();
789 ERR_WB <<
"side_actions::execute_network_command(): received invalid action data!";
795 ERR_WB <<
"side_actions::execute_network_command(): received invalid insertion position!";
799 LOG_WB <<
"Command received: action inserted on turn #" << turn <<
", position #" << pos <<
": " << act;
803 for(
iterator end_itor =
end(); itor != end_itor; ++itor) {
806 }
else if(
type==
"replace") {
807 std::size_t turn = cmd[
"turn"].to_int();
808 std::size_t pos = cmd[
"pos"].to_int();
811 ERR_WB <<
"side_actions::execute_network_command(): received invalid action data!";
817 ERR_WB <<
"side_actions::execute_network_command(): received invalid pos!";
822 ERR_WB <<
"side_actions::execute_network_command(): replace failed!";
826 LOG_WB <<
"Command received: action replaced on turn #" << turn <<
", position #" << pos <<
": " << act;
827 }
else if(
type==
"remove") {
828 std::size_t turn = cmd[
"turn"].to_int();
829 std::size_t pos = cmd[
"pos"].to_int();
833 ERR_WB <<
"side_actions::execute_network_command(): received invalid pos!";
839 LOG_WB <<
"Command received: action removed on turn #" << turn <<
", position #" << pos;
842 for(
iterator end_itor =
end(); itor != end_itor; ++itor) {
845 }
else if(
type==
"bump_later") {
846 std::size_t turn = cmd[
"turn"].to_int();
847 std::size_t pos = cmd[
"pos"].to_int();
851 ERR_WB <<
"side_actions::execute_network_command(): received invalid pos!";
859 LOG_WB <<
"Command received: action bumped later from turn #" << turn <<
", position #" << pos;
864 }
else if(
type==
"clear") {
865 LOG_WB <<
"Command received: clear";
867 }
else if(
type==
"refresh") {
868 LOG_WB <<
"Command received: refresh";
873 ERR_WB <<
"side_actions::execute_network_command(): received invalid type!";
883 result[
"type"] =
"insert";
884 result[
"turn"] =
static_cast<int>(turn_num);
885 result[
"pos"] =
static_cast<int>(pos);
886 result.
add_child(
"action", act->to_config());
901 result[
"type"] =
"replace";
902 result[
"turn"] =
static_cast<int>(
get_turn(pos));
904 result.
add_child(
"action", act->to_config());
910 result[
"type"] =
"remove";
911 result[
"turn"] =
static_cast<int>(
get_turn(pos));
918 result[
"type"] =
"bump_later";
919 result[
"turn"] =
static_cast<int>(
get_turn(pos));
926 result[
"type"] =
"clear";
932 result[
"type"] =
"refresh";
944 std::set<unit_const_ptr> lazy_units;
948 lazy_units.insert(u);
955 while(itor !=
begin()) {
959 if(lazy_units.find(act->get_unit()) != lazy_end) {
void clear()
Clears the stack of undoable (and redoable) actions.
Arrows destined to be drawn on the map.
A config object defines a single node in a WML file, with access to child nodes.
config & mandatory_child(config_key_type key, int n=0)
Returns the nth child with the given key, or throws an error if there is none.
child_itors child_range(config_key_type key)
config & add_child(config_key_type key)
bool invalidate(const map_location &loc)
Function to invalidate a specific tile for redrawing.
static display * get_singleton()
Returns the display object if a display object exists.
Holds a temporary unit that can be drawn on the map without being placed in the unit_map.
bool can_recruit_on(const map_location &leader_loc, const map_location &recruit_loc, int side) const
Checks to see if a leader at leader_loc could recruit on recruit_loc.
Exception used to escape form the ai or ui code to playsingle_controller::play_side.
This class represents a single unit of a specific type.
Abstract base class for all the whiteboard planned actions.
bool valid()
Returns whether this action is valid or not.
static action_ptr from_config(const config &, bool hidden)
Constructs an object of a subclass of wb::action using a config.
virtual void execute(bool &success, bool &complete)=0
Output parameters: success: Whether or not to continue an execute-all after this execution complete: ...
A planned move, represented on the map by an arrow and a ghosted unit in the destination hex.
void modify_unit(unit &new_unit)
bool modify(iterator position, Modifier mod)
iterator turn_end(std::size_t turn_num)
action_set::index< chronological >::type::iterator iterator
action_limits turn_beginnings_
Contains a list of iterator to the beginning of each turn.
iterator end()
Returns the iterator for the position after the last executed action within the actions queue.
std::size_t get_turn(const_iterator it) const
Returns the turn of a given iterator planned execution.
iterator bump_later(iterator position)
Moves an action later in the execution order.
bool replace(iterator it, action_ptr act)
Replaces the action at a given position with another action.
iterator push_front(std::size_t turn, action_ptr action)
Pushes an action in front of a given turn.
bool empty() const
Indicates whether the action queue is empty.
iterator queue(std::size_t turn_num, action_ptr action)
Queues an action to be executed last.
action_set::index< chronological >::type::const_iterator const_iterator
iterator turn_begin(std::size_t turn_num)
Returns the iterator for the first (executed earlier) action of a given turn within the actions queue...
action_set::index< T >::type & get()
Returns a given index.
std::size_t size() const
Returns the number of actions in the action queue.
iterator erase(iterator position)
Deletes the action at the specified position.
iterator begin()
Returns the iterator for the first (executed earlier) action within the actions queue.
iterator bump_earlier(iterator position)
Moves an action earlier in the execution order.
std::size_t turn_size(std::size_t turn_num) const
Returns the number of actions planned for turn turn_num.
std::size_t get_turn_impl(std::size_t begin, std::size_t end, const_iterator it) const
Binary search to find the occurring turn of the action pointed by an iterator.
void turn_shift()
Shift turn.
std::size_t position_in_turn(const_iterator it) const
Returns the position of a given iterator in its turn.
iterator insert(iterator position, action_ptr action)
Inserts an action at the specified position.
std::size_t num_turns() const
Returns the number of turns that have plans.
This internal whiteboard class holds the planned action queues for a team, and offers many utility me...
std::size_t team_index()
Returns the team index this action queue belongs to.
iterator find_first_action_at(map_location hex)
Find the first action occurring at a given hex.
iterator queue_move(std::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 queue_recruit(std::size_t turn_num, const std::string &unit_name, const map_location &recruit_hex)
Queues a recruit to be executed last.
iterator queue_recall(std::size_t turn_num, const unit &unit, const map_location &recall_hex)
Queues a recall to be executed last.
net_cmd make_net_cmd_remove(const const_iterator &pos) const
std::size_t num_turns() const
Returns the number of turns that have plans.
net_cmd make_net_cmd_replace(const const_iterator &pos, action_const_ptr) const
iterator find_last_action_of(const unit &unit, iterator start_position)
Finds the last action that belongs to this unit, starting the search backwards from the specified pos...
bool empty() const
Indicates whether the action queue is empty.
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....
iterator queue_suppose_dead(std::size_t turn_num, unit &curr_unit, const map_location &loc)
Queues a suppose_dead to be executed last.
std::deque< action_ptr > actions_of(const unit &unit)
void hide()
Sets whether or not the contents should be drawn on the screen.
void reset_gold_spent()
Set gold spent back to zero.
iterator turn_begin(std::size_t turn_num)
iterator bump_earlier(iterator position, bool send_to_net=true)
Moves an action earlier in the execution order.
std::size_t get_turn_num_of(const unit &) const
Determines the appropriate turn number for the next action planned for this unit.
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.
std::size_t turn_size(std::size_t turn_num) const
Returns the number of actions planned for turn turn_num.
void change_gold_spent_by(int difference)
Used to track gold spending by recruits/recalls when building the future unit map.
iterator safe_insert(std::size_t turn_num, std::size_t pos, action_ptr to_insert)
iterator begin()
Returns the iterator for the first (executed earlier) action within the actions queue.
iterator synced_enqueue(std::size_t turn_num, action_ptr to_insert)
int gold_spent_
Used to store gold "spent" in planned recruits/recalls when the future unit map is applied.
container::const_iterator const_iterator
net_cmd make_net_cmd_clear() const
iterator remove_action(iterator position, bool validate_after_delete=true)
Deletes the action at the specified position.
bool execute(iterator position)
Executes the specified action, if it exists in the queue.
container::iterator iterator
void update_recruited_unit(std::size_t old_id, unit &new_unit)
After a recruit action was executed the id of the unit was changed so we need to update the unitid of...
std::size_t get_turn(const_iterator it) const
Returns the turn of a given iterator planned execution.
iterator bump_later(iterator position, bool send_to_net=true)
Moves an action later in the execution order.
iterator synced_insert(iterator itor, action_ptr to_insert)
void clear()
Empties the action queue.
iterator synced_erase(iterator itor)
std::size_t count_actions_of(const unit &unit)
iterator safe_erase(const iterator &itor)
bool execute_next()
Executes the first action in the queue, and then deletes it.
iterator end()
Returns the iterator for the position after the last executed action within the actions queue.
bool unit_has_actions(const unit &unit)
void execute_net_cmd(const net_cmd &)
net_cmd make_net_cmd_bump_later(const const_iterator &pos) const
range_t iter_turn(std::size_t turn_num)
Returns an iterator range corresponding to the requested turn.
void set_team_index(std::size_t team_index)
Must be called only once, right after the team that owns this side_actions is added to the teams vect...
net_cmd make_net_cmd_refresh() const
iterator insert_action(iterator position, action_ptr action)
Inserts an action at the specified position.
iterator queue_attack(std::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.
iterator turn_end(std::size_t turn_num)
net_cmd make_net_cmd_insert(std::size_t turn_num, std::size_t pos, action_const_ptr) const
iterator queue_action(std::size_t turn_num, action_ptr action)
Queues an action to be executed last.
Abstract base class for all the visitors (cf GoF Visitor Design Pattern) the whiteboard uses.
Various functions related to the creation of units (recruits, recalls, and placed units).
Contains the exception interfaces used to signal completion of a scenario, campaign or turn.
std::size_t underlying_id() const
This unit's unique internal ID.
Main entry points of multiplayer mode.
actions::undo_list * undo_stack
play_controller * controller
filter_context * filter_con
std::shared_ptr< wb::manager > whiteboard
std::size_t index(const std::string &str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
std::shared_ptr< recruit > recruit_ptr
std::weak_ptr< action > weak_action_ptr
std::shared_ptr< suppose_dead > suppose_dead_ptr
std::ostream & operator<<(std::ostream &s, action_ptr action)
std::shared_ptr< move > move_ptr
std::shared_ptr< action > action_ptr
std::shared_ptr< attack > attack_ptr
std::shared_ptr< arrow > arrow_ptr
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::shared_ptr< action const > action_const_ptr
std::shared_ptr< recall > recall_ptr
std::string::const_iterator iterator
std::shared_ptr< const unit > unit_const_ptr
std::shared_ptr< attack_type > attack_ptr
static config unit_name(const unit *u)
Encapsulates the map of the game.
Structure which holds a single route and marks for special events.
std::set< std::size_t > secondary_numbers
std::vector< int > numbers_to_draw
std::vector< std::size_t > team_numbers
Tag for action_set's hashed_non_unique index.
Tag for action_set's hashed_non_unique index.
Various functions that implement the undoing (and redoing) of in-game commands.