19 #ifndef WB_SIDE_ACTIONS_HPP_
20 #define WB_SIDE_ACTIONS_HPP_
24 #include <boost/multi_index/hashed_index.hpp>
25 #include <boost/multi_index/mem_fun.hpp>
26 #include <boost/multi_index/random_access_index.hpp>
27 #include <boost/multi_index_container.hpp>
58 typedef boost::multi_index::multi_index_container <
60 boost::multi_index::indexed_by<
61 boost::multi_index::random_access<
62 boost::multi_index::tag< chronological > >,
63 boost::multi_index::hashed_non_unique<
64 boost::multi_index::tag< by_unit >,
65 boost::multi_index::const_mem_fun< action, size_t, &action::get_unit_id > >,
66 boost::multi_index::hashed_non_unique<
67 boost::multi_index::tag< by_hex >,
68 boost::multi_index::const_mem_fun< action, map_location, &action::get_numbering_hex > >
73 typedef action_set::index<chronological>::type::const_iterator
const_iterator;
77 typedef std::pair<iterator,iterator>
range_t;
78 typedef std::pair<reverse_iterator,reverse_iterator>
rrange_t;
79 typedef std::pair<const_iterator,const_iterator>
crange_t;
80 typedef std::pair<const_reverse_iterator,const_reverse_iterator>
crrange_t;
104 iterator
queue(
size_t turn_num, action_ptr
action);
130 iterator
erase(iterator position);
136 iterator
erase(iterator
first, iterator last);
160 template <
typename T>
162 template <
typename T>
168 template <
typename T,
typename U>
170 template <
typename T,
typename U>
171 typename action_set::index<T>::type::const_iterator
project(U it)
const {
return actions_.project<T>(it); }
221 size_t get_turn(const_iterator it)
const;
232 const_iterator
turn_begin(
size_t turn_num)
const;
281 class side_actions:
public boost::enable_shared_from_this<side_actions>
292 typedef std::pair<reverse_iterator,reverse_iterator>
rrange_t;
293 typedef std::pair<const_iterator,const_iterator>
crange_t;
294 typedef std::pair<const_reverse_iterator,const_reverse_iterator>
crrange_t;
320 bool execute(iterator position);
394 iterator
remove_action(iterator position,
bool validate_after_delete =
true);
452 template <
typename T,
typename Compare>
454 template <
typename T,
typename Compare>
587 , secondary_numbers()
591 template <
typename T,
typename Compare>
595 for(T it = between.first; it != between.second; ++it) {
597 if((comp(chrono_it, first) || first==
actions_.
end()) && !comp(chrono_it, limit)) {
604 template <
typename T,
typename Compare>
608 for(T it = between.first; it != between.second; ++it) {
610 if((comp(chrono_it, first) || first==
actions_.
end()) && !comp(chrono_it, limit)) {
std::pair< reverse_iterator, reverse_iterator > rrange_t
container::iterator iterator
const_reverse_iterator turn_rbegin(size_t turn_num) const
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
std::pair< reverse_iterator, reverse_iterator > rrange_t
size_t position_in_turn(const_iterator it) const
Returns the position of a given iterator in its turn.
const_iterator end() const
const versions of the above
net_cmd make_net_cmd_refresh() const
action_limits turn_beginnings_
Contains a list of iterator to the beginning of each turn.
boost::shared_ptr< action > action_ptr
int get_gold_spent() const
Used to track gold spending by recruits/recalls when building the future unit map.
const_iterator begin() const
const versions of the above
iterator push_front(size_t turn, action_ptr action)
Pushes an action in front of a given turn.
std::vector< int > numbers_to_draw
crange_t iter_turn(size_t turn_num) const
iterator turn_begin(size_t turn_num)
size_t get_turn(const_iterator it) const
Returns the turn of a given iterator planned execution.
reverse_iterator rbegin()
reverse version of the above
iterator get_position_of(action_ptr action)
action_set::index< T >::type::iterator project(U it)
Projects an iterator on a given index.
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.
std::pair< const_reverse_iterator, const_reverse_iterator > crrange_t
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)
size_t size() const
Returns the number of actions in the action queue.
config net_cmd
Network code.
static config unit_name(const unit *u)
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.
const_reverse_iterator turn_rend(size_t turn_num) const
std::pair< const_iterator, const_iterator > crange_t
const_reverse_iterator rbegin() const
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
side_actions_container container
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.
rrange_t riter_turn(size_t turn_num)
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)
const_iterator turn_end(size_t turn_num) const
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.
const_reverse_iterator turn_rbegin(size_t turn_num) const
container::reverse_iterator reverse_iterator
Arrows destined to be drawn on the map.
const_iterator turn_end(size_t turn_num) const
action_set::index< chronological >::type::reverse_iterator reverse_iterator
iterator queue_action(size_t turn_num, action_ptr action)
Queues an action to be executed last.
Contains typedefs for the whiteboard.
bool execute(iterator position)
Executes the specified action, if it exists in the queue.
const_iterator turn_begin(size_t turn_num) const
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.
std::pair< const_reverse_iterator, const_reverse_iterator > crrange_t
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.
void clear()
Empties the action queue.
reverse_iterator rend()
reverse version of the above
net_cmd make_net_cmd_bump_later(const_iterator const &pos) const
Structure which holds a single route and marks for special events.
iterator find_first_action_of(unit const &unit)
Variant of this method that always start searching at the beginning of the queue. ...
action_set const & actions() const
Get the underlying action container.
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.
const_iterator begin() const
const versions of the above
Encapsulates the map of the game.
const_reverse_iterator rend() const
const reverse versions of the above
crrange_t riter_turn(size_t turn_num) const
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 &)
iterator bump_later(iterator position)
Moves an action later in the execution order.
std::deque< iterator > action_limits
std::map< std::string, tfilter >::iterator itor
reverse_iterator turn_rend(size_t turn_num)
crange_t iter_turn(size_t turn_num) const
iterator synced_enqueue(size_t turn_num, action_ptr to_insert)
iterator synced_insert(iterator itor, action_ptr to_insert)
Datastructure holding the actions of a side on multiple turns.
iterator begin()
Returns the iterator for the first (executed earlier) action within the actions queue.
reverse_iterator turn_rbegin(size_t turn_num)
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...
std::pair< iterator, iterator > range_t
reverse_iterator turn_rend(size_t turn_num)
const_iterator end() const
const versions of the above
const_reverse_iterator rbegin() const
const reverse versions of the above
boost::multi_index::multi_index_container< action_ptr, boost::multi_index::indexed_by< boost::multi_index::random_access< boost::multi_index::tag< chronological > >, boost::multi_index::hashed_non_unique< boost::multi_index::tag< by_unit >, boost::multi_index::const_mem_fun< action, size_t,&action::get_unit_id > >, boost::multi_index::hashed_non_unique< boost::multi_index::tag< by_hex >, boost::multi_index::const_mem_fun< action, map_location,&action::get_numbering_hex > > > > action_set
Underlying container.
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)
void reset_gold_spent()
Set gold spent back to zero.
crrange_t riter_turn(size_t turn_num) const
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.
reverse_iterator rend()
reverse version of the above
container::const_iterator const_iterator
iterator insert(iterator position, action_ptr action)
Inserts an action at the specified position.
Tag for action_set's hashed_non_unique index.
container::const_reverse_iterator const_reverse_iterator
std::ostream & operator<<(std::ostream &s, action_ptr action)
action_set::index< chronological >::type::const_reverse_iterator const_reverse_iterator
iterator end()
Returns the iterator for the position after the last executed action within the actions queue...
reverse_iterator rbegin()
reverse version of the above
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.
reverse_iterator turn_rbegin(size_t turn_num)
iterator safe_erase(iterator const &itor)
Tag for action_set's random_access index.
action_set::index< T >::type::const_iterator project(U it) const
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...
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::pair< const_iterator, const_iterator > crange_t
iterator queue(size_t turn_num, action_ptr action)
Queues an action to be executed last.
const_reverse_iterator turn_rend(size_t turn_num) const
GLsizei const GLcharARB ** string
std::pair< iterator, iterator > range_t
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
const_reverse_iterator rend() const
size_t turn_size(size_t turn_num) const
Returns the number of actions planned for turn turn_num.
bool unit_has_actions(unit const &unit)
void clear()
Empties the action queue.
iterator bump_later(iterator position)
Moves an action later in the execution order.
rrange_t riter_turn(size_t turn_num)
range_t iter_turn(size_t turn_num)
Returns an iterator range corresponding to the requested turn.