53 out <<
"Content of side_actions:";
54 for(std::size_t turn = 0; turn < side_actions.
num_turns(); ++turn) {
55 out <<
"\n Turn " << turn;
59 out <<
"\n (" << count++ <<
") " << *it;
67 if(side_actions.
empty()) {
84 ERR_WB <<
"get_turn: begin >= end\n";
87 ERR_WB <<
"get_turn failed\n";
91 std::size_t mid = (begin+
end) / 2;
128 return queue(turn, action);
133 bool current_turn_unplanned =
turn_size(0) == 0;
136 if(current_turn_unplanned && turn == 1) {
145 assert(position <=
end());
147 bool first = position ==
begin();
149 std::pair<iterator,bool> res =
actions_.insert(position, action);
164 bool future_only = turn_num == 1 &&
num_turns() == 0;
166 bool current_turn_unplanned =
turn_size(0) == 0;
169 assert(turn_num <=
num_turns() || future_only);
182 }
else if(current_turn_unplanned && turn_num == 0) {
192 assert(position >
begin());
193 assert(position <
end());
199 actions_.replace(position - 1, rhs);
211 assert(position <
end());
215 bool deleting_last_element = next ==
end();
220 if(deleting_last_element) {
231 if (it == position) {
236 std::size_t turn_of_position = std::distance(turn_beginnings_.begin(), beginning);
238 if(
get_turn(next) == turn_of_position) {
241 assert(turn_of_position == 0);
257 for(
iterator it = last-1; it>first; --it) {
267 , team_index_defined_(false)
287 std::vector<std::size_t>& team_numbers = result.
team_numbers;
293 if((*it)->is_numbering_hex(hex)) {
295 std::size_t number = (it -
begin()) + 1;
296 std::size_t
index = numbers_to_draw.size();
297 numbers_to_draw.push_back(number);
301 if(hlighter->get_main_highlight().lock() == *it) {
306 if(
action.lock() == *it) {
307 secondary_numbers.insert(index);
327 ERR_WB <<
"Modifying action queue while temp modifiers are applied!!!" << std::endl;
336 LOG_WB <<
"Before execution, " << *
this <<
"\n";
340 if(!action->valid()) {
341 LOG_WB <<
"Invalid action sent to execution, deleting.\n";
346 bool action_successful;
348 bool action_complete;
350 action->execute(action_successful, action_complete);
353 LOG_WB <<
"End turn exception caught during execution, deleting action. " << *
this <<
"\n";
364 WRN_WB <<
"not clearing undo stack because dsu is active\n";
368 std::stringstream ss;
369 ss <<
"After " << (action_successful?
"successful":
"failed") <<
" execution ";
370 if(action_complete) {
371 ss <<
"with deletion, ";
375 ss <<
"without deletion, ";
386 return action_successful;
417 ERR_WB <<
"Modifying action queue while temp modifiers are applied!!!" << std::endl;
420 LOG_WB <<
"Inserted into turn #" <<
get_turn(valid_position) <<
" at position #" 423 return valid_position;
429 ERR_WB <<
"Modifying action queue while temp modifiers are applied!!!" << std::endl;
432 LOG_WB <<
"Queue into turn #" << turn_num <<
" : " << action <<
"\n";
442 struct swapable_with_move:
public visitor 446 bool valid()
const {
return valid_; }
449 valid_ = second_->get_dest_hex() != first->get_source_hex();
453 visit(std::static_pointer_cast<move>(first));
457 check_recruit_recall(first->get_recruit_hex());
461 check_recruit_recall(first->get_recall_hex());
479 if(!(it == sa_.
end() || position_ < it)) {
495 ERR_WB <<
"Modifying action queue while temp modifiers are applied!!!" << std::endl;
498 assert(position <=
end());
511 if(previous_ptr && current_ptr && previous_ptr.get() == current_ptr.get()) {
515 if(
move_ptr second = std::dynamic_pointer_cast<move>(*position)) {
516 swapable_with_move
check(*
this, position, second);
517 (*previous)->accept(check);
523 LOG_WB <<
"Before bumping earlier, " << *
this <<
"\n";
525 int turn_number =
get_turn(position);
527 int last_position =
turn_size(turn_number) - 1;
528 LOG_WB <<
"In turn #" << turn_number
529 <<
", bumping action #" << action_number <<
"/" << last_position
530 <<
" to position #" << action_number - 1 <<
"/" << last_position <<
".\n";
537 LOG_WB <<
"After bumping earlier, " << *
this <<
"\n";
544 assert(position <
end());
547 if(position ==
end()) {
551 if(position ==
end()) {
560 ERR_WB <<
"Modifying action queue while temp modifiers are applied!!!" << std::endl;
563 assert(position <
end());
580 if(validate_after_delete) {
667 std::deque<action_ptr>
actions (action_its.first, action_its.second);
682 DBG_WB <<
"Changing gold spent for side " << (
team_index() + 1) <<
"; old value: " 689 DBG_WB <<
"Resetting gold spent for side " << (
team_index() + 1) <<
" to 0.\n";
696 if(
move_ptr mp = std::dynamic_pointer_cast<move>(*it)) {
697 if(
mp->raw_uid() == old_id) {
733 if(result !=
end()) {
756 attack_ptr new_attack(std::make_shared<attack>(
team_index(),
hidden_, std::ref(mover), target_hex, weapon_choice, route, arrow, std::move(fake_unit)));
780 std::string
type = cmd[
"type"];
783 std::size_t turn = cmd[
"turn"].to_int();
784 std::size_t pos = cmd[
"pos"].to_int();
787 ERR_WB <<
"side_actions::execute_network_command(): received invalid action data!" << std::endl;
793 ERR_WB <<
"side_actions::execute_network_command(): received invalid insertion position!" << std::endl;
797 LOG_WB <<
"Command received: action inserted on turn #" << turn <<
", position #" << pos <<
": " << act <<
"\n";
801 for(
iterator end_itor =
end(); itor != end_itor; ++itor) {
804 }
else if(type==
"replace") {
805 std::size_t turn = cmd[
"turn"].to_int();
806 std::size_t pos = cmd[
"pos"].to_int();
809 ERR_WB <<
"side_actions::execute_network_command(): received invalid action data!" << std::endl;
815 ERR_WB <<
"side_actions::execute_network_command(): received invalid pos!" << std::endl;
820 ERR_WB <<
"side_actions::execute_network_command(): replace failed!" << std::endl;
824 LOG_WB <<
"Command received: action replaced on turn #" << turn <<
", position #" << pos <<
": " << act <<
"\n";
825 }
else if(type==
"remove") {
826 std::size_t turn = cmd[
"turn"].to_int();
827 std::size_t pos = cmd[
"pos"].to_int();
831 ERR_WB <<
"side_actions::execute_network_command(): received invalid pos!" << std::endl;
837 LOG_WB <<
"Command received: action removed on turn #" << turn <<
", position #" << pos <<
"\n";
840 for(
iterator end_itor =
end(); itor != end_itor; ++itor) {
843 }
else if(type==
"bump_later") {
844 std::size_t turn = cmd[
"turn"].to_int();
845 std::size_t pos = cmd[
"pos"].to_int();
849 ERR_WB <<
"side_actions::execute_network_command(): received invalid pos!" << std::endl;
857 LOG_WB <<
"Command received: action bumped later from turn #" << turn <<
", position #" << pos <<
"\n";
862 }
else if(type==
"clear") {
863 LOG_WB <<
"Command received: clear\n";
865 }
else if(type==
"refresh") {
866 LOG_WB <<
"Command received: refresh\n";
871 ERR_WB <<
"side_actions::execute_network_command(): received invalid type!" << std::endl;
881 result[
"type"] =
"insert";
882 result[
"turn"] =
static_cast<int>(turn_num);
883 result[
"pos"] =
static_cast<int>(pos);
884 result.
add_child(
"action", act->to_config());
899 result[
"type"] =
"replace";
900 result[
"turn"] =
static_cast<int>(
get_turn(pos));
902 result.
add_child(
"action", act->to_config());
908 result[
"type"] =
"remove";
909 result[
"turn"] =
static_cast<int>(
get_turn(pos));
916 result[
"type"] =
"bump_later";
917 result[
"turn"] =
static_cast<int>(
get_turn(pos));
924 result[
"type"] =
"clear";
930 result[
"type"] =
"refresh";
942 std::set<unit_const_ptr> lazy_units;
946 lazy_units.insert(u);
953 while(itor !=
begin()) {
957 if(lazy_units.find(act->get_unit()) != lazy_end) {
void clear()
Clears the stack of undoable (and redoable) actions.
container::iterator iterator
play_controller * controller
config & child(config_key_type key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
iterator end()
Returns the iterator for the position after the last executed action within the actions queue...
net_cmd make_net_cmd_remove(const const_iterator &pos) const
static display * get_singleton()
Returns the display object if a display object exists.
static void check(LexState *ls, int c)
bool invalidate(const map_location &loc)
Function to invalidate a specific tile for redrawing.
This class represents a single unit of a specific type.
bool unit_has_actions(const unit &unit)
net_cmd make_net_cmd_refresh() const
action_limits turn_beginnings_
Contains a list of iterator to the beginning of each turn.
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.
iterator push_front(std::size_t turn, action_ptr action)
Pushes an action in front of a given turn.
Exception used to escape form the ai or ui code to playsingle_controller::play_side.
std::vector< int > numbers_to_draw
child_itors child_range(config_key_type key)
std::shared_ptr< attack > attack_ptr
bool modify(iterator position, Modifier mod)
void turn_shift()
Shift turn.
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...
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.
action_set::index< chronological >::type::iterator iterator
bool replace(iterator it, action_ptr act)
Replaces the action at a given position with another action.
static action_ptr from_config(const config &, bool hidden)
Constructs an object of a subclass of wb::action using a config.
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)
iterator bump_earlier(iterator position)
Moves an action earlier in the execution order.
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.
std::size_t get_turn(const_iterator it) const
Returns the turn of a given iterator planned execution.
int gold_spent_
Used to store gold "spent" in planned recruits/recalls when the future unit map is applied...
std::vector< std::size_t > team_numbers
iterator bump_later(iterator position, bool send_to_net=true)
Moves an action later in the execution order.
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.
Main entry points of multiplayer mode.
std::shared_ptr< const unit > unit_const_ptr
iterator find_first_action_at(map_location hex)
Find the first action occurring at a given hex.
std::size_t count_actions_of(const unit &unit)
void execute_net_cmd(const net_cmd &)
iterator erase(iterator position)
Deletes the action at the specified position.
std::shared_ptr< recruit > recruit_ptr
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 bump_earlier(iterator position, bool send_to_net=true)
Moves an action earlier in the execution order.
iterator safe_erase(const iterator &itor)
Arrows destined to be drawn on the map.
bool execute(iterator position)
Executes the specified action, if it exists in the queue.
iterator synced_enqueue(std::size_t turn_num, action_ptr to_insert)
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.
bool empty() const
Indicates whether the action queue is empty.
std::shared_ptr< action > action_ptr
bool empty() const
Indicates whether the action queue is empty.
iterator insert_action(iterator position, action_ptr action)
Inserts an action at the specified position.
iterator queue_recall(std::size_t turn_num, const unit &unit, const map_location &recall_hex)
Queues a recall to be executed last.
map_display and display: classes which take care of displaying the map and game-data on the screen...
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...
iterator queue_suppose_dead(std::size_t turn_num, unit &curr_unit, const map_location &loc)
Queues a suppose_dead to be executed last.
Structure which holds a single route and marks for special events.
iterator turn_begin(std::size_t turn_num)
Encapsulates the map of the game.
std::size_t size() const
Returns the number of actions in the action queue.
std::shared_ptr< wb::manager > whiteboard
Various functions related to the creation of units (recruits, recalls, and placed units)...
range_t iter_turn(std::size_t turn_num)
Returns an iterator range corresponding to the requested turn.
Tag for action_set's hashed_non_unique index.
std::size_t get_turn_num_of(const unit &) const
Determines the appropriate turn number for the next action planned for this unit. ...
std::size_t team_index()
Returns the team index this action queue belongs to.
net_cmd make_net_cmd_clear() const
iterator synced_insert(iterator itor, action_ptr to_insert)
iterator begin()
Returns the iterator for the first (executed earlier) action within the actions queue.
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< suppose_dead > suppose_dead_ptr
void hide()
Sets whether or not the contents should be drawn on the screen.
std::size_t turn_size(std::size_t turn_num) const
Returns the number of actions planned for turn turn_num.
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< move > move_ptr
config & add_child(config_key_type key)
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...
iterator begin()
Returns the iterator for the first (executed earlier) action within the actions queue.
std::weak_ptr< action > weak_action_ptr
std::shared_ptr< arrow > arrow_ptr
std::set< std::size_t > secondary_numbers
action_set::index< T >::type & get()
Returns a given index.
void reset_gold_spent()
Set gold spent back to zero.
void change_gold_spent_by(int difference)
Used to track gold spending by recruits/recalls when building the future unit map.
iterator turn_end(std::size_t turn_num)
net_cmd make_net_cmd_replace(const const_iterator &pos, action_const_ptr) const
std::size_t position_in_turn(const_iterator it) const
Returns the position of a given iterator in its turn.
container::const_iterator const_iterator
std::size_t get_turn(const_iterator it) const
Returns the turn of a given iterator planned execution.
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.
std::ostream & operator<<(std::ostream &s, action_ptr action)
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...
iterator queue_action(std::size_t turn_num, action_ptr action)
Queues an action to be executed last.
iterator end()
Returns the iterator for the position after the last executed action within the actions queue...
iterator safe_insert(std::size_t turn_num, std::size_t pos, action_ptr to_insert)
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.
std::shared_ptr< recall > recall_ptr
actions::undo_list * undo_stack
net_cmd make_net_cmd_bump_later(const const_iterator &pos) const
void modify_unit(unit &new_unit)
std::size_t num_turns() const
Returns the number of turns that have plans.
std::size_t turn_size(std::size_t turn_num) const
Returns the number of actions planned for turn turn_num.
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.
std::deque< action_ptr > actions_of(const unit &unit)
iterator turn_end(std::size_t turn_num)
iterator queue(std::size_t turn_num, action_ptr action)
Queues an action to be executed last.
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.
std::string::const_iterator iterator
Holds a temporary unit that can be drawn on the map without being placed in the unit_map.
A planned move, represented on the map by an arrow and a ghosted unit in the destination hex...
action_set::index< chronological >::type::const_iterator const_iterator
std::size_t num_turns() const
Returns the number of turns that have plans.
std::size_t underlying_id() const
This unit's unique internal ID.
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.
net_cmd make_net_cmd_insert(std::size_t turn_num, std::size_t pos, action_const_ptr) const
std::shared_ptr< action const > action_const_ptr