51 out <<
"Content of side_actions:";
53 out <<
"\n Turn " << turn;
57 out <<
"\n (" << count++ <<
") " << *it;
82 ERR_WB <<
"get_turn: begin >= end";
85 ERR_WB <<
"get_turn failed";
131 bool current_turn_unplanned =
turn_size(0) == 0;
134 if(current_turn_unplanned && turn == 1) {
143 assert(position <=
end());
145 bool first = position ==
begin();
162 bool future_only = turn_num == 1 &&
num_turns() == 0;
164 bool current_turn_unplanned =
turn_size(0) == 0;
167 assert(turn_num <=
num_turns() || future_only);
180 }
else if(current_turn_unplanned && turn_num == 0) {
190 assert(position >
begin());
191 assert(position <
end());
197 actions_.replace(position - 1, rhs);
209 assert(position <
end());
213 bool deleting_last_element = next ==
end();
218 if(deleting_last_element) {
229 if (it == position) {
234 std::size_t turn_of_position = std::distance(
turn_beginnings_.begin(), beginning);
236 if(
get_turn(next) == turn_of_position) {
239 assert(turn_of_position == 0);
255 for(
iterator it = last-1; it>first; --it) {
265 , team_index_defined_(false)
285 std::vector<std::size_t>& team_numbers = result.
team_numbers;
291 if((*it)->is_numbering_hex(hex)) {
293 std::size_t number = (it -
begin()) + 1;
294 std::size_t
index = numbers_to_draw.size();
295 numbers_to_draw.push_back(number);
299 if(hlighter->get_main_highlight().lock() == *it) {
304 if(
action.lock() == *it) {
305 secondary_numbers.insert(
index);
325 ERR_WB <<
"Modifying action queue while temp modifiers are applied!!!";
334 LOG_WB <<
"Before execution, " << *
this;
339 LOG_WB <<
"Invalid action sent to execution, deleting.";
344 bool action_successful;
346 bool action_complete;
351 LOG_WB <<
"End turn exception caught during execution, deleting action. " << *
this;
362 WRN_WB <<
"not clearing undo stack because dsu is active";
366 std::stringstream ss;
367 ss <<
"After " << (action_successful?
"successful":
"failed") <<
" execution ";
368 if(action_complete) {
369 ss <<
"with deletion, ";
373 ss <<
"without deletion, ";
384 return action_successful;
415 ERR_WB <<
"Modifying action queue while temp modifiers are applied!!!";
418 LOG_WB <<
"Inserted into turn #" <<
get_turn(valid_position) <<
" at position #"
421 return valid_position;
427 ERR_WB <<
"Modifying action queue while temp modifiers are applied!!!";
430 LOG_WB <<
"Queue into turn #" << turn_num <<
" : " <<
action;
440 struct swapable_with_move:
public visitor
444 bool valid()
const {
return valid_; }
447 valid_ = second_->get_dest_hex() != first->get_source_hex();
451 visit(std::static_pointer_cast<move>(first));
455 check_recruit_recall(first->get_recruit_hex());
459 check_recruit_recall(first->get_recall_hex());
477 if(!(it == sa_.end() || position_ < it)) {
493 ERR_WB <<
"Modifying action queue while temp modifiers are applied!!!";
496 assert(position <=
end());
509 if(previous_ptr && current_ptr && previous_ptr.get() == current_ptr.get()) {
513 if(
move_ptr second = std::dynamic_pointer_cast<move>(*position)) {
514 swapable_with_move check(*
this, position, second);
515 (*previous)->accept(check);
521 LOG_WB <<
"Before bumping earlier, " << *
this;
523 int turn_number =
get_turn(position);
525 int last_position =
turn_size(turn_number) - 1;
526 LOG_WB <<
"In turn #" << turn_number
527 <<
", bumping action #" << action_number <<
"/" << last_position
528 <<
" to position #" << action_number - 1 <<
"/" << last_position
536 LOG_WB <<
"After bumping earlier, " << *
this;
543 assert(position <
end());
546 if(position ==
end()) {
550 if(position ==
end()) {
559 ERR_WB <<
"Modifying action queue while temp modifiers are applied!!!";
562 assert(position <
end());
579 if(validate_after_delete) {
666 std::deque<action_ptr>
actions (action_its.first, action_its.second);
681 DBG_WB <<
"Changing gold spent for side " << (
team_index() + 1) <<
"; old value: "
688 DBG_WB <<
"Resetting gold spent for side " << (
team_index() + 1) <<
" to 0.";
695 if(
move_ptr mp = std::dynamic_pointer_cast<move>(*it)) {
696 if(
mp->raw_uid() == old_id) {
732 if(result !=
end()) {
779 std::string
type = cmd[
"type"];
782 std::size_t turn = cmd[
"turn"].to_int();
783 std::size_t pos = cmd[
"pos"].to_int();
786 ERR_WB <<
"side_actions::execute_network_command(): received invalid action data!";
792 ERR_WB <<
"side_actions::execute_network_command(): received invalid insertion position!";
796 LOG_WB <<
"Command received: action inserted on turn #" << turn <<
", position #" << pos <<
": " << act;
800 for(
iterator end_itor =
end(); itor != end_itor; ++itor) {
803 }
else if(
type==
"replace") {
804 std::size_t turn = cmd[
"turn"].to_int();
805 std::size_t pos = cmd[
"pos"].to_int();
808 ERR_WB <<
"side_actions::execute_network_command(): received invalid action data!";
814 ERR_WB <<
"side_actions::execute_network_command(): received invalid pos!";
819 ERR_WB <<
"side_actions::execute_network_command(): replace failed!";
823 LOG_WB <<
"Command received: action replaced on turn #" << turn <<
", position #" << pos <<
": " << act;
824 }
else if(
type==
"remove") {
825 std::size_t turn = cmd[
"turn"].to_int();
826 std::size_t pos = cmd[
"pos"].to_int();
830 ERR_WB <<
"side_actions::execute_network_command(): received invalid pos!";
836 LOG_WB <<
"Command received: action removed on turn #" << turn <<
", position #" << pos;
839 for(
iterator end_itor =
end(); itor != end_itor; ++itor) {
842 }
else if(
type==
"bump_later") {
843 std::size_t turn = cmd[
"turn"].to_int();
844 std::size_t pos = cmd[
"pos"].to_int();
848 ERR_WB <<
"side_actions::execute_network_command(): received invalid pos!";
856 LOG_WB <<
"Command received: action bumped later from turn #" << turn <<
", position #" << pos;
861 }
else if(
type==
"clear") {
862 LOG_WB <<
"Command received: clear";
864 }
else if(
type==
"refresh") {
865 LOG_WB <<
"Command received: refresh";
870 ERR_WB <<
"side_actions::execute_network_command(): received invalid type!";
880 result[
"type"] =
"insert";
881 result[
"turn"] =
static_cast<int>(turn_num);
882 result[
"pos"] =
static_cast<int>(pos);
883 result.
add_child(
"action", act->to_config());
898 result[
"type"] =
"replace";
899 result[
"turn"] =
static_cast<int>(
get_turn(pos));
901 result.
add_child(
"action", act->to_config());
907 result[
"type"] =
"remove";
908 result[
"turn"] =
static_cast<int>(
get_turn(pos));
915 result[
"type"] =
"bump_later";
916 result[
"turn"] =
static_cast<int>(
get_turn(pos));
923 result[
"type"] =
"clear";
929 result[
"type"] =
"refresh";
941 std::set<unit_const_ptr> lazy_units;
945 lazy_units.insert(u);
952 while(itor !=
begin()) {
956 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 queue(std::size_t turn_num, const action_ptr &action)
Queues an action to be executed last.
bool empty() const
Indicates whether the action queue is empty.
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.
iterator insert(iterator position, const action_ptr &action)
Inserts an action at the specified position.
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.
iterator push_front(std::size_t turn, const action_ptr &action)
Pushes an action in front of a given turn.
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.
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 queue_move(std::size_t turn_num, unit &mover, const pathfind::marked_route &route, const arrow_ptr &arrow, fake_unit_ptr fake_unit)
Queues a move to be executed last.
iterator queue_attack(std::size_t turn_num, unit &mover, const map_location &target_hex, int weapon_choice, const pathfind::marked_route &route, const arrow_ptr &arrow, fake_unit_ptr fake_unit)
Queues an attack or attack-move to be executed last.
iterator find_first_action_at(map_location hex)
Find the first action occurring at a given hex.
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.
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 queue_action(std::size_t turn_num, const action_ptr &action)
Queues an action to be executed last.
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 synced_enqueue(std::size_t turn_num, const action_ptr &to_insert)
iterator synced_insert(iterator itor, const action_ptr &to_insert)
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 begin()
Returns the iterator for the first (executed earlier) action within the actions queue.
int gold_spent_
Used to store gold "spent" in planned recruits/recalls when the future unit map is applied.
container::const_iterator const_iterator
iterator insert_action(iterator position, const action_ptr &action)
Inserts an action at the specified position.
net_cmd make_net_cmd_insert(std::size_t turn_num, std::size_t pos, const action_const_ptr &) const
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...
net_cmd make_net_cmd_replace(const const_iterator &pos, const action_const_ptr &) const
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.
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 turn_end(std::size_t turn_num)
iterator safe_insert(std::size_t turn_num, std::size_t pos, const action_ptr &to_insert)
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(std::string_view str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
auto * find(Container &container, const Value &value)
Convenience wrapper for using find on a container without needing to comare to end()
std::shared_ptr< recruit > recruit_ptr
std::weak_ptr< action > weak_action_ptr
std::shared_ptr< suppose_dead > suppose_dead_ptr
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::ostream & operator<<(std::ostream &s, const action_ptr &action)
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.