50 out <<
"Content of side_actions:";
52 out <<
"\n Turn " << turn;
56 out <<
"\n (" << count++ <<
") " << *it;
81 ERR_WB <<
"get_turn: begin >= end";
84 ERR_WB <<
"get_turn failed";
130 bool current_turn_unplanned =
turn_size(0) == 0;
133 if(current_turn_unplanned && turn == 1) {
142 assert(position <=
end());
144 bool first = position ==
begin();
161 bool future_only = turn_num == 1 &&
num_turns() == 0;
163 bool current_turn_unplanned =
turn_size(0) == 0;
166 assert(turn_num <=
num_turns() || future_only);
179 }
else if(current_turn_unplanned && turn_num == 0) {
189 assert(position >
begin());
190 assert(position <
end());
196 actions_.replace(position - 1, rhs);
208 assert(position <
end());
212 bool deleting_last_element = next ==
end();
217 if(deleting_last_element) {
228 if (it == position) {
233 std::size_t turn_of_position = std::distance(
turn_beginnings_.begin(), beginning);
235 if(
get_turn(next) == turn_of_position) {
238 assert(turn_of_position == 0);
254 for(
iterator it = last-1; it>first; --it) {
264 , team_index_defined_(false)
284 std::vector<std::size_t>& team_numbers = result.
team_numbers;
290 if((*it)->is_numbering_hex(hex)) {
292 std::size_t number = (it -
begin()) + 1;
293 std::size_t
index = numbers_to_draw.size();
294 numbers_to_draw.push_back(number);
298 if(hlighter->get_main_highlight().lock() == *it) {
303 if(
action.lock() == *it) {
304 secondary_numbers.insert(
index);
324 ERR_WB <<
"Modifying action queue while temp modifiers are applied!!!";
333 LOG_WB <<
"Before execution, " << *
this;
338 LOG_WB <<
"Invalid action sent to execution, deleting.";
343 bool action_successful;
345 bool action_complete;
350 LOG_WB <<
"End turn exception caught during execution, deleting action. " << *
this;
361 WRN_WB <<
"not clearing undo stack because dsu is active";
365 std::stringstream ss;
366 ss <<
"After " << (action_successful?
"successful":
"failed") <<
" execution ";
367 if(action_complete) {
368 ss <<
"with deletion, ";
372 ss <<
"without deletion, ";
383 return action_successful;
414 ERR_WB <<
"Modifying action queue while temp modifiers are applied!!!";
417 LOG_WB <<
"Inserted into turn #" <<
get_turn(valid_position) <<
" at position #"
420 return valid_position;
426 ERR_WB <<
"Modifying action queue while temp modifiers are applied!!!";
429 LOG_WB <<
"Queue into turn #" << turn_num <<
" : " <<
action;
439 struct swapable_with_move:
public visitor
443 bool valid()
const {
return valid_; }
446 valid_ = second_->get_dest_hex() != first->get_source_hex();
450 visit(std::static_pointer_cast<move>(first));
454 check_recruit_recall(first->get_recruit_hex());
458 check_recruit_recall(first->get_recall_hex());
476 if(!(it == sa_.end() || position_ < it)) {
492 ERR_WB <<
"Modifying action queue while temp modifiers are applied!!!";
495 assert(position <=
end());
508 if(previous_ptr && current_ptr && previous_ptr.get() == current_ptr.get()) {
512 if(
move_ptr second = std::dynamic_pointer_cast<move>(*position)) {
513 swapable_with_move check(*
this, position, second);
514 (*previous)->accept(check);
520 LOG_WB <<
"Before bumping earlier, " << *
this;
522 int turn_number =
get_turn(position);
524 int last_position =
turn_size(turn_number) - 1;
525 LOG_WB <<
"In turn #" << turn_number
526 <<
", bumping action #" << action_number <<
"/" << last_position
527 <<
" to position #" << action_number - 1 <<
"/" << last_position
535 LOG_WB <<
"After bumping earlier, " << *
this;
542 assert(position <
end());
545 if(position ==
end()) {
549 if(position ==
end()) {
558 ERR_WB <<
"Modifying action queue while temp modifiers are applied!!!";
561 assert(position <
end());
578 if(validate_after_delete) {
665 std::deque<action_ptr>
actions (action_its.first, action_its.second);
680 DBG_WB <<
"Changing gold spent for side " << (
team_index() + 1) <<
"; old value: "
687 DBG_WB <<
"Resetting gold spent for side " << (
team_index() + 1) <<
" to 0.";
694 if(
move_ptr mp = std::dynamic_pointer_cast<move>(*it)) {
695 if(
mp->raw_uid() == old_id) {
731 if(result !=
end()) {
778 std::string
type = cmd[
"type"];
781 std::size_t turn = cmd[
"turn"].to_int();
782 std::size_t pos = cmd[
"pos"].to_int();
785 ERR_WB <<
"side_actions::execute_network_command(): received invalid action data!";
791 ERR_WB <<
"side_actions::execute_network_command(): received invalid insertion position!";
795 LOG_WB <<
"Command received: action inserted on turn #" << turn <<
", position #" << pos <<
": " << act;
799 for(
iterator end_itor =
end(); itor != end_itor; ++itor) {
802 }
else if(
type==
"replace") {
803 std::size_t turn = cmd[
"turn"].to_int();
804 std::size_t pos = cmd[
"pos"].to_int();
807 ERR_WB <<
"side_actions::execute_network_command(): received invalid action data!";
813 ERR_WB <<
"side_actions::execute_network_command(): received invalid pos!";
818 ERR_WB <<
"side_actions::execute_network_command(): replace failed!";
822 LOG_WB <<
"Command received: action replaced on turn #" << turn <<
", position #" << pos <<
": " << act;
823 }
else if(
type==
"remove") {
824 std::size_t turn = cmd[
"turn"].to_int();
825 std::size_t pos = cmd[
"pos"].to_int();
829 ERR_WB <<
"side_actions::execute_network_command(): received invalid pos!";
835 LOG_WB <<
"Command received: action removed on turn #" << turn <<
", position #" << pos;
838 for(
iterator end_itor =
end(); itor != end_itor; ++itor) {
841 }
else if(
type==
"bump_later") {
842 std::size_t turn = cmd[
"turn"].to_int();
843 std::size_t pos = cmd[
"pos"].to_int();
847 ERR_WB <<
"side_actions::execute_network_command(): received invalid pos!";
855 LOG_WB <<
"Command received: action bumped later from turn #" << turn <<
", position #" << pos;
860 }
else if(
type==
"clear") {
861 LOG_WB <<
"Command received: clear";
863 }
else if(
type==
"refresh") {
864 LOG_WB <<
"Command received: refresh";
869 ERR_WB <<
"side_actions::execute_network_command(): received invalid type!";
879 result[
"type"] =
"insert";
880 result[
"turn"] =
static_cast<int>(turn_num);
881 result[
"pos"] =
static_cast<int>(pos);
882 result.
add_child(
"action", act->to_config());
897 result[
"type"] =
"replace";
898 result[
"turn"] =
static_cast<int>(
get_turn(pos));
900 result.
add_child(
"action", act->to_config());
906 result[
"type"] =
"remove";
907 result[
"turn"] =
static_cast<int>(
get_turn(pos));
914 result[
"type"] =
"bump_later";
915 result[
"turn"] =
static_cast<int>(
get_turn(pos));
922 result[
"type"] =
"clear";
928 result[
"type"] =
"refresh";
940 std::set<unit_const_ptr> lazy_units;
944 lazy_units.insert(u);
951 while(itor !=
begin()) {
955 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.
map_display and display: classes which take care of displaying the map and game-data on the screen.
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.