The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
side_actions.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 - 2016 by Gabriel Morin <gabrielmorin (at) gmail (dot) com>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13  */
14 
15 /**
16  * @file
17  */
18 
19 #ifndef WB_SIDE_ACTIONS_HPP_
20 #define WB_SIDE_ACTIONS_HPP_
21 
22 #include <deque>
23 
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>
28 
29 #include "action.hpp"
30 #include "typedefs.hpp"
31 
32 namespace wb
33 {
34 
35 class move;
36 
37 /**
38  * Datastructure holding the actions of a side on multiple turns.
39  *
40  * @invariant forall(t>0) if turn_size(t)==0 then turn_size(t+1)==0
41  */
43 {
44 public:
45 
47 
48  //! Tag for action_set's random_access index.
49  struct chronological{};
50 
51  //! Tag for action_set's hashed_non_unique index.
52  struct by_unit{};
53 
54  //! Tag for action_set's hashed_non_unique index.
55  struct by_hex{};
56 
57  //! Underlying container
58  typedef boost::multi_index::multi_index_container <
59  action_ptr,
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 > >
69  >
71 
73  typedef action_set::index<chronological>::type::const_iterator const_iterator;
74  typedef action_set::index<chronological>::type::reverse_iterator reverse_iterator;
75  typedef action_set::index<chronological>::type::const_reverse_iterator const_reverse_iterator;
76 
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;
81 
82  typedef std::deque<iterator> action_limits;
83 
84 
85  /**
86  * Inserts an action at the specified position.
87  *
88  * The planned turn of the inserted action is the same as the planned turn of position-1 before the insertion.
89  * If position == begin(), the new action will became the first action of the current turn.
90  *
91  * @param position The iterator before which action will be inserted.
92  * @param action The action to insert.
93  *
94  * @return The inserted action's position.
95  * @retval end() When the action can't be inserted.
96  */
97  iterator insert(iterator position, action_ptr action);
98 
99  /**
100  * Queues an action to be executed last
101  * @return The queued action's position
102  * @retval end() when the action can't be inserted
103  */
104  iterator queue(size_t turn_num, action_ptr action);
105 
106  /**
107  * Pushes an action in front of a given turn.
108  * @return The inserted action's position
109  */
110  iterator push_front(size_t turn, action_ptr action);
111 
112  /**
113  * Moves an action earlier in the execution order.
114  * i.e. at the front of the queue by one position.
115  * @return The action's new position.
116  */
117  iterator bump_earlier(iterator position);
118 
119  /**
120  * Moves an action later in the execution order.
121  * i.e. at the back of the queue by one position.
122  * @return The action's new position.
123  */
124  iterator bump_later(iterator position);
125 
126  /**
127  * Deletes the action at the specified position.
128  * @return The position of the element after the one deleted, or end() if the queue is empty.
129  */
130  iterator erase(iterator position);
131 
132  /**
133  * Deletes the action at the specified position.
134  * @return last
135  */
136  iterator erase(iterator first, iterator last);
137 
138  /**
139  * Empties the action queue.
140  */
141  void clear() { actions_.clear(); turn_beginnings_.clear(); }
142 
143  /**
144  * Shift turn.
145  *
146  * The turn 0 is deleted, the actions of turn n are moved to turn n-1.
147  * @pre turn_size(0)==0
148  */
149  void turn_shift() { assert(turn_size(0)==0); turn_beginnings_.pop_front(); }
150 
151  /**
152  * Replaces the action at a given position with another action.
153  */
154  bool replace(iterator it, action_ptr act){ return actions_.replace(it, act); }
155 
156 
157  /**
158  * Returns a given index.
159  */
160  template <typename T>
161  typename action_set::index<T>::type& get(){ return actions_.get<T>(); }
162  template <typename T>
163  typename action_set::index<T>::type const& get() const { return actions_.get<T>(); }
164 
165  /**
166  * Projects an iterator on a given index.
167  */
168  template <typename T, typename U>
169  typename action_set::index<T>::type::iterator project(U it){ return actions_.project<T>(it); }
170  template <typename T, typename U>
171  typename action_set::index<T>::type::const_iterator project(U it) const { return actions_.project<T>(it); }
172 
173  /**
174  * Returns the iterator for the first (executed earlier) action within the actions queue.
175  */
176  iterator begin(){ return actions_.get<chronological>().begin(); }
177  /** reverse version of the above */
178  reverse_iterator rbegin(){ return actions_.get<chronological>().rbegin(); }
179  /** const versions of the above */
180  const_iterator begin() const { return actions_.get<chronological>().cbegin(); }
181  /** const reverse versions of the above */
182  const_reverse_iterator rbegin() const { return actions_.get<chronological>().crbegin(); }
183 
184  /**
185  * Returns the iterator for the position *after* the last executed action within the actions queue.
186  */
187  iterator end(){ return actions_.get<chronological>().end(); }
188  /** reverse version of the above */
189  reverse_iterator rend(){ return actions_.get<chronological>().rend(); }
190  /** const versions of the above */
191  const_iterator end() const { return actions_.get<chronological>().cend(); }
192  /** const reverse versions of the above */
193  const_reverse_iterator rend() const { return actions_.get<chronological>().crend(); }
194 
195  /**
196  * Indicates whether the action queue is empty.
197  */
198  bool empty() const { return actions_.empty(); }
199 
200  /**
201  * Returns the number of actions in the action queue.
202  */
203  size_t size() const { return actions_.size(); }
204 
205  /**
206  * Returns the number of turns that have plans.
207  * If the container holds only one action on turn 1 (that is turn 0 is empty),
208  * this function will still returns 2. Indeed, turn 0 has an "empty" plan.
209  *
210  * @note The current turn is counted. That is if num_turns()==0 then empty()==true.
211  */
212  size_t num_turns() const { return turn_beginnings_.size(); }
213 
214  /**
215  * Returns the turn of a given iterator planned execution.
216  *
217  * The value returned is the difference between the planned turn and the current turn.
218  *
219  * @retval 0 If the action is planned for the current turn.
220  */
221  size_t get_turn(const_iterator it) const;
222 
223  /**
224  * Returns the position of a given iterator in its turn.
225  */
226  size_t position_in_turn(const_iterator it) const;
227 
228  /**
229  * Returns the iterator for the first (executed earlier) action of a given turn within the actions queue.
230  */
231  iterator turn_begin(size_t turn_num);
232  const_iterator turn_begin(size_t turn_num) const;
233  reverse_iterator turn_rbegin(size_t turn_num){ return reverse_iterator(turn_end(turn_num)); }
234  const_reverse_iterator turn_rbegin(size_t turn_num) const { return reverse_iterator(turn_end(turn_num)); }
235 
236  /*
237  * Returns the iterator for the position *after* the last executed action of a given turn within the actions queue.
238  */
239  iterator turn_end(size_t turn_num){ return turn_begin(turn_num+1); }
240  const_iterator turn_end(size_t turn_num) const { return turn_begin(turn_num+1); }
241  reverse_iterator turn_rend(size_t turn_num){ return reverse_iterator(turn_begin(turn_num)); }
242  const_reverse_iterator turn_rend(size_t turn_num) const { return reverse_iterator(turn_begin(turn_num)); }
243 
244  /**
245  * Returns an iterator range corresponding to the requested turn.
246  */
247  range_t iter_turn(size_t turn_num){ return range_t(turn_begin(turn_num),turn_end(turn_num)); }
248  rrange_t riter_turn(size_t turn_num){ return rrange_t(turn_rbegin(turn_num),turn_rend(turn_num)); }
249  crange_t iter_turn(size_t turn_num) const { return crange_t(turn_begin(turn_num),turn_end(turn_num)); }
250  crrange_t riter_turn(size_t turn_num) const { return crrange_t(turn_rbegin(turn_num),turn_rend(turn_num)); }
251 
252  /** Returns the number of actions planned for turn turn_num */
253  size_t turn_size(size_t turn_num) const { return turn_end(turn_num) - turn_begin(turn_num); }
254 
255  /** Get the underlying action container */
256  action_set const& actions() const { return actions_; }
257 
258 
259 private:
260  /**
261  * Binary search to find the occuring turn of the action pointed by an iterator.
262  */
263  size_t get_turn_impl(size_t begin, size_t end, const_iterator it) const;
264 
266 
267  /**
268  * Contains a list of iterator to the beginning of each turn.
269  *
270  * @invariant turn_beginnings_.front()==actions_.begin() || actions_.empty()
271  */
272  action_limits turn_beginnings_;
273 };
274 
275 
276 /**
277  * This internal whiteboard class holds the planned action queues for a team, and offers many
278  * utility methods to create and manipulate them.
279  * It also provides an interface to the underlying side_actions_container.
280  */
281 class side_actions: public boost::enable_shared_from_this<side_actions>
282 {
283 public:
285 
290 
291  typedef std::pair<iterator,iterator> range_t;
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;
295 
296 
297  side_actions();
298 
299  /** Must be called only once, right after the team that owns this side_actions is added to the teams vector */
300  void set_team_index(size_t team_index);
301 
302  /** Returns the team index this action queue belongs to */
303  size_t team_index() { assert(team_index_defined_); return team_index_; }
304 
305  struct numbers_t;
306  /** Gets called when display is drawing a hex to determine which numbers to draw on it */
307  void get_numbers(const map_location& hex, numbers_t& result);
308 
309  /**
310  * Executes the first action in the queue, and then deletes it.
311  * @return true if the action was completed successfully
312  */
313  bool execute_next();
314 
315  /**
316  * Executes the specified action, if it exists in the queue.
317  * If the action is not finished, it's moved at the end of the queue.
318  * @return true if the action was completed successfully
319  */
320  bool execute(iterator position);
321 
322 
323  /**
324  * Indicates whether the action queue is empty.
325  */
326  bool empty() const { return actions_.empty(); }
327 
328  /**
329  * Returns the number of actions in the action queue.
330  */
331  size_t size() const { return actions_.size(); }
332 
333  /**
334  * Returns the number of turns that have plans.
335  * If the container holds only one action on turn 1 (that is turn 0 is empty),
336  * this function will still returns 2. Indeed, turn 0 has an "empty" plan.
337  *
338  * @note The current turn is counted. That is if num_turns()==0 then empty()==true.
339  */
340  size_t num_turns() const { return actions_.num_turns(); }
341 
342  /** Returns the number of actions planned for turn turn_num */
343  size_t turn_size(size_t turn_num) const { return actions_.turn_size(turn_num); }
344 
345  /**
346  * Returns the turn of a given iterator planned execution.
347  *
348  * The value returned is the difference between the planned turn and the current turn.
349  *
350  * @retval 0 If the action is planned for the current turn.
351  */
352  size_t get_turn(const_iterator it) const { return actions_.get_turn(it); }
353 
354  /**
355  * Empties the action queue.
356  */
357  void clear() { actions_.clear(); }
358 
359  /** Sets whether or not the contents should be drawn on the screen. */
360  void hide();
361  void show();
362  bool hidden() const {return hidden_;}
363 
364  /**
365  * Inserts an action at the specified position. The begin() and end() functions might prove useful here.
366  * @return The inserted action's position.
367  */
368  iterator insert_action(iterator position, action_ptr action);
369 
370  /**
371  * Queues an action to be executed last
372  * @return The queued action's position
373  */
374  iterator queue_action(size_t turn_num, action_ptr action);
375 
376  /**
377  * Moves an action earlier in the execution order.
378  * i.e. at the front of the queue by one position.
379  * @return The action's new position.
380  */
381  iterator bump_earlier(iterator position);
382 
383  /**
384  * Moves an action later in the execution order.
385  * i.e. at the back of the queue by one position.
386  * @return The action's new position.
387  */
388  iterator bump_later(iterator position);
389 
390  /**
391  * Deletes the action at the specified position.
392  * @return The position of the element after the one deleted, or end() if the queue is empty.
393  */
394  iterator remove_action(iterator position, bool validate_after_delete = true);
395 
396  /**
397  * @param action The action whose position you're looking for
398  * @return The action's position within the queue, or end() if action wasn't found.
399  */
400  iterator get_position_of(action_ptr action){ return std::find(begin(), end(), action); }
401 
402  /**
403  * Returns the iterator for the first (executed earlier) action within the actions queue.
404  */
405  iterator begin(){ return actions_.begin(); }
406  /** reverse version of the above */
407  reverse_iterator rbegin(){ return actions_.rbegin(); }
408  /** const versions of the above */
409  const_iterator begin() const { return actions_.begin(); }
410  const_reverse_iterator rbegin() const { return actions_.rbegin(); }
411 
412  /**
413  * Returns the iterator for the position *after* the last executed action within the actions queue.
414  */
415  iterator end(){ return actions_.end(); }
416  /** reverse version of the above */
417  reverse_iterator rend(){ return actions_.rend(); }
418  /** const versions of the above */
419  const_iterator end() const { return actions_.end(); }
420  const_reverse_iterator rend() const { return actions_.rend(); }
421 
422  iterator turn_begin(size_t turn_num){ return actions_.turn_begin(turn_num); }
423  iterator turn_end(size_t turn_num){ return actions_.turn_end(turn_num); }
424  reverse_iterator turn_rbegin(size_t turn_num){ return actions_.turn_rbegin(turn_num); }
425  reverse_iterator turn_rend(size_t turn_num){ return actions_.turn_rend(turn_num); }
426  const_iterator turn_begin(size_t turn_num) const { return actions_.turn_begin(turn_num); }
427  const_iterator turn_end(size_t turn_num) const { return actions_.turn_end(turn_num); }
428  const_reverse_iterator turn_rbegin(size_t turn_num) const { return actions_.turn_rbegin(turn_num); }
429  const_reverse_iterator turn_rend(size_t turn_num) const { return actions_.turn_rend(turn_num); }
430 
431  /** Returns an iterator range corresponding to the requested turn. */
432  range_t iter_turn(size_t turn_num){ return actions_.iter_turn(turn_num); }
433  rrange_t riter_turn(size_t turn_num){ return actions_.riter_turn(turn_num); }
434  crange_t iter_turn(size_t turn_num) const { return actions_.iter_turn(turn_num); }
435  crrange_t riter_turn(size_t turn_num) const { return actions_.riter_turn(turn_num); }
436 
437 
438  /**
439  * 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.
440  *
441  * This function makes sense when T is a non-chronological iterator.
442  * If T is @ref iterator and Compare is std::less<iterator>,
443  * this function returns limit if limit is in [between.first, between.second)
444  * or between.first if between.first>limit or end() otherwise.
445  *
446  * @param between the two iterators between which the action will be searched.
447  * @param limit the lower bound to search from, that is the return value `it' will verify !comp(limit, it).
448  * @param comp the predicate to compare with.
449  * @return `it' so that for all values `x' in [between.first, between.second), chronologically, !comp(x, it) and !comp(it, limit).
450  * @retval end() if no such action exist.
451  */
452  template <typename T, typename Compare>
453  iterator find_first_action_of(std::pair<T,T> between, iterator limit, Compare comp);
454  template <typename T, typename Compare>
455  const_iterator find_first_action_of(std::pair<T,T> between, const_iterator limit, Compare comp) const;
456 
457  /**
458  * Find the first action occurring at a given hex.
459  *
460  * @retval end() if no action occurs at the given location.
461  */
462  iterator find_first_action_at(map_location hex);
463 
464  /**
465  * Finds the first action that belongs to this unit, starting the search at the specified position.
466  * @return The position, or end() if not found.
467  */
468  iterator find_first_action_of(unit const& unit, iterator start_position);
469  /** Variant of this method that always start searching at the beginning of the queue */
470  iterator find_first_action_of(unit const& unit){ return find_first_action_of(unit, begin()); }
471 
472  /**
473  * Finds the last action that belongs to this unit, starting the search backwards from the specified position.
474  * @return The position, or end() if not found.
475  */
476  iterator find_last_action_of(unit const& unit, iterator start_position);
477  /** const variant of the previous function */
478  const_iterator find_last_action_of(unit const& unit, const_iterator start_position) const;
479  /** Variant of the previous method that always start searching at the end of the queue */
480  iterator find_last_action_of(unit const& unit);
481  /** const variant of the previous function */
482  const_iterator find_last_action_of(unit const& unit) const;
483 
484  bool unit_has_actions(unit const& unit);
485  size_t count_actions_of(unit const& unit);
486  std::deque<action_ptr> actions_of(unit const& unit);
487 
488  /**
489  * Determines the appropriate turn number for the next action planned for this unit
490  *
491  * @warning A return value of 0 can mean that the unit has one action planned on turn 0 or that the unit doesn't have any action planned on any turn.
492  *
493  * @retval 0 if the unit doesn't have any planned action
494  */
495  size_t get_turn_num_of(unit const&) const;
496 
497  /** Used to track gold spending by recruits/recalls when building the future unit map */
498  int get_gold_spent() const { return gold_spent_; }
499  /** Used to track gold spending by recruits/recalls when building the future unit map */
500  void change_gold_spent_by(int difference);
501  /** Set gold spent back to zero */
502  void reset_gold_spent();
503 
504  void raw_turn_shift();
505  void synced_turn_shift();
506 
507  /**
508  * Queues a move to be executed last
509  * @return The queued move's position
510  */
511  iterator queue_move(size_t turn_num, unit& mover, const pathfind::marked_route& route,
512  arrow_ptr arrow, fake_unit_ptr fake_unit);
513 
514  /**
515  * Queues an attack or attack-move to be executed last
516  * @return The queued attack's position
517  */
518  iterator queue_attack(size_t turn_num, unit& mover, const map_location& target_hex, int weapon_choice, const pathfind::marked_route& route,
519  arrow_ptr arrow, fake_unit_ptr fake_unit);
520 
521  /**
522  * Queues a recruit to be executed last
523  * @return The queued recruit's position
524  */
525  iterator queue_recruit(size_t turn_num, const std::string& unit_name, const map_location& recruit_hex);
526 
527  /**
528  * Queues a recall to be executed last
529  * @return The queued recall's position
530  */
531  iterator queue_recall(size_t turn_num, const unit& unit, const map_location& recall_hex);
532 
533  /**
534  * Queues a suppose_dead to be executed last
535  * @return The queued suppose_dead's position (an iterator to it)
536  */
537  iterator queue_suppose_dead(size_t turn_num, unit& curr_unit, map_location const& loc);
538 
539  /**
540  * Network code. A net_cmd object (a config in disguise) represents a modification
541  * to a side_actions object. execute_net_cmd() translates one of these into
542  * a real modification of *this. The make_net_cmd_***() family of functions is
543  * convenient for building specific types of net_cmds.
544  */
545  typedef config net_cmd;
546  void execute_net_cmd(net_cmd const&);
547  net_cmd make_net_cmd_insert(size_t turn_num, size_t pos, action_const_ptr) const;
548  net_cmd make_net_cmd_insert(const_iterator const& pos, action_const_ptr) const;
549  net_cmd make_net_cmd_replace(const_iterator const& pos, action_const_ptr) const;
550  net_cmd make_net_cmd_remove(const_iterator const& pos) const;
551  net_cmd make_net_cmd_bump_later(const_iterator const& pos) const;
552  net_cmd make_net_cmd_clear() const;
553  net_cmd make_net_cmd_refresh() const;
554 
555 private:
556  iterator safe_insert(size_t turn_num, size_t pos, action_ptr to_insert);
557  iterator synced_erase(iterator itor);
558  iterator synced_insert(iterator itor, action_ptr to_insert);
559  iterator synced_enqueue(size_t turn_num, action_ptr to_insert);
560  iterator safe_erase(iterator const& itor);
561 
562  container actions_;
563 
564  size_t team_index_;
566 
567  /** Used to store gold "spent" in planned recruits/recalls when the future unit map is applied */
569 
570  bool hidden_;
571 };
572 
573 /** Dumps side_actions on a stream, for debug purposes. */
574 std::ostream& operator<<(std::ostream &out, wb::side_actions const &side_actions);
575 
577 {
578  std::vector<int> numbers_to_draw;
579  std::vector<size_t> team_numbers;
581  std::set<size_t> secondary_numbers;
582 
584  : numbers_to_draw()
585  , team_numbers()
586  , main_number(-1)
587  , secondary_numbers()
588  {}
589 };
590 
591 template <typename T, typename Compare>
593 {
595  for(T it = between.first; it != between.second; ++it) {
597  if((comp(chrono_it, first) || first==actions_.end()) && !comp(chrono_it, limit)) {
598  first = chrono_it;
599  }
600  }
601  return first;
602 }
603 
604 template <typename T, typename Compare>
606 {
608  for(T it = between.first; it != between.second; ++it) {
610  if((comp(chrono_it, first) || first==actions_.end()) && !comp(chrono_it, limit)) {
611  first = chrono_it;
612  }
613  }
614  return first;
615 }
616 
617 } //end namespace wb
618 
619 #endif /* WB_SIDE_ACTIONS_HPP_ */
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
Definition: unit.hpp:95
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
Definition: typedefs.hpp:70
int pos
Definition: formula.cpp:800
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)
Definition: reports.cpp:133
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
GLuint GLuint end
Definition: glew.h:1221
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.
GLuint64EXT * result
Definition: glew.h:10727
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.
Definition: arrow.hpp:30
GLint limit
Definition: glew.h:10112
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.
Definition: pathfind.hpp:141
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.
Definition: location.hpp:38
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
Definition: filter.cpp:199
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
bool hidden() const
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
GLint * first
Definition: glew.h:1496
std::ostream & operator<<(std::ostream &s, action_ptr action)
Definition: action.cpp:33
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...
std::string::const_iterator iterator
Definition: tokenizer.hpp:21
Abstract base class for all the whiteboard planned actions.
Definition: action.hpp:33
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
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
Definition: glew.h:4503
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.
Definition: display.hpp:47
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.