The Battle for Wesnoth  1.17.0-dev
side_actions.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 - 2021
3  by Gabriel Morin <gabrielmorin (at) gmail (dot) com>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 /**
17  * @file
18  */
19 
20 #pragma once
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, std::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(std::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(std::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  std::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  std::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  std::size_t get_turn(const_iterator it) const;
222 
223  /**
224  * Returns the position of a given iterator in its turn.
225  */
226  std::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(std::size_t turn_num);
232  const_iterator turn_begin(std::size_t turn_num) const;
233  reverse_iterator turn_rbegin(std::size_t turn_num){ return reverse_iterator(turn_end(turn_num)); }
234  const_reverse_iterator turn_rbegin(std::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(std::size_t turn_num){ return turn_begin(turn_num+1); }
240  const_iterator turn_end(std::size_t turn_num) const { return turn_begin(turn_num+1); }
241  reverse_iterator turn_rend(std::size_t turn_num){ return reverse_iterator(turn_begin(turn_num)); }
242  const_reverse_iterator turn_rend(std::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(std::size_t turn_num){ return range_t(turn_begin(turn_num),turn_end(turn_num)); }
248  rrange_t riter_turn(std::size_t turn_num){ return rrange_t(turn_rbegin(turn_num),turn_rend(turn_num)); }
249  crange_t iter_turn(std::size_t turn_num) const { return crange_t(turn_begin(turn_num),turn_end(turn_num)); }
250  crrange_t riter_turn(std::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  std::size_t turn_size(std::size_t turn_num) const { return turn_end(turn_num) - turn_begin(turn_num); }
254 
255  /** Get the underlying action container */
256  const action_set& actions() const { return actions_; }
257 
258  template<typename Modifier>
259  bool modify(iterator position, Modifier mod) { return actions_.modify(position, mod); }
260 private:
261  /**
262  * Binary search to find the occurring turn of the action pointed by an iterator.
263  */
264  std::size_t get_turn_impl(std::size_t begin, std::size_t end, const_iterator it) const;
265 
267 
268  /**
269  * Contains a list of iterator to the beginning of each turn.
270  *
271  * @invariant turn_beginnings_.front()==actions_.begin() || actions_.empty()
272  */
273  action_limits turn_beginnings_;
274 };
275 
276 
277 /**
278  * This internal whiteboard class holds the planned action queues for a team, and offers many
279  * utility methods to create and manipulate them.
280  * It also provides an interface to the underlying side_actions_container.
281  */
282 class side_actions: public std::enable_shared_from_this<side_actions>
283 {
284 public:
286 
291 
292  typedef std::pair<iterator,iterator> range_t;
293  typedef std::pair<reverse_iterator,reverse_iterator> rrange_t;
294  typedef std::pair<const_iterator,const_iterator> crange_t;
295  typedef std::pair<const_reverse_iterator,const_reverse_iterator> crrange_t;
296 
297 
298  side_actions();
299 
300  /** Must be called only once, right after the team that owns this side_actions is added to the teams vector */
301  void set_team_index(std::size_t team_index);
302 
303  /** Returns the team index this action queue belongs to */
304  std::size_t team_index() { assert(team_index_defined_); return team_index_; }
305 
306  struct numbers_t;
307  /** Gets called when display is drawing a hex to determine which numbers to draw on it */
308  void get_numbers(const map_location& hex, numbers_t& result);
309 
310  /**
311  * Executes the first action in the queue, and then deletes it.
312  * @return true if the action was completed successfully
313  */
314  bool execute_next();
315 
316  /**
317  * Executes the specified action, if it exists in the queue.
318  * If the action is not finished, it's moved at the end of the queue.
319  * @return true if the action was completed successfully
320  */
321  bool execute(iterator position);
322 
323 
324  /**
325  * Indicates whether the action queue is empty.
326  */
327  bool empty() const { return actions_.empty(); }
328 
329  /**
330  * Returns the number of actions in the action queue.
331  */
332  std::size_t size() const { return actions_.size(); }
333 
334  /**
335  * Returns the number of turns that have plans.
336  * If the container holds only one action on turn 1 (that is turn 0 is empty),
337  * this function will still returns 2. Indeed, turn 0 has an "empty" plan.
338  *
339  * @note The current turn is counted. That is if num_turns()==0 then empty()==true.
340  */
341  std::size_t num_turns() const { return actions_.num_turns(); }
342 
343  /** Returns the number of actions planned for turn turn_num */
344  std::size_t turn_size(std::size_t turn_num) const { return actions_.turn_size(turn_num); }
345 
346  /**
347  * Returns the turn of a given iterator planned execution.
348  *
349  * The value returned is the difference between the planned turn and the current turn.
350  *
351  * @retval 0 If the action is planned for the current turn.
352  */
353  std::size_t get_turn(const_iterator it) const { return actions_.get_turn(it); }
354 
355  /**
356  * Empties the action queue.
357  */
358  void clear() { actions_.clear(); }
359 
360  /** Sets whether or not the contents should be drawn on the screen. */
361  void hide();
362  void show();
363  bool hidden() const {return hidden_;}
364 
365  /**
366  * Inserts an action at the specified position. The begin() and end() functions might prove useful here.
367  * @return The inserted action's position.
368  */
369  iterator insert_action(iterator position, action_ptr action);
370 
371  /**
372  * Queues an action to be executed last
373  * @return The queued action's position
374  */
375  iterator queue_action(std::size_t turn_num, action_ptr action);
376 
377  /**
378  * Moves an action earlier in the execution order.
379  * i.e. at the front of the queue by one position.
380  * @return The action's new position.
381  */
382  iterator bump_earlier(iterator position, bool send_to_net = true);
383 
384  /**
385  * Moves an action later in the execution order.
386  * i.e. at the back of the queue by one position.
387  * @return The action's new position.
388  */
389  iterator bump_later(iterator position, bool send_to_net = true);
390 
391  /**
392  * Deletes the action at the specified position.
393  * @return The position of the element after the one deleted, or end() if the queue is empty.
394  */
395  iterator remove_action(iterator position, bool validate_after_delete = true);
396 
397  /**
398  * @param action The action whose position you're looking for
399  * @return The action's position within the queue, or end() if action wasn't found.
400  */
401  iterator get_position_of(action_ptr action){ return std::find(begin(), end(), action); }
402 
403  /**
404  * Returns the iterator for the first (executed earlier) action within the actions queue.
405  */
406  iterator begin(){ return actions_.begin(); }
407  /** reverse version of the above */
408  reverse_iterator rbegin(){ return actions_.rbegin(); }
409  /** const versions of the above */
410  const_iterator begin() const { return actions_.begin(); }
411  const_reverse_iterator rbegin() const { return actions_.rbegin(); }
412 
413  /**
414  * Returns the iterator for the position *after* the last executed action within the actions queue.
415  */
416  iterator end(){ return actions_.end(); }
417  /** reverse version of the above */
418  reverse_iterator rend(){ return actions_.rend(); }
419  /** const versions of the above */
420  const_iterator end() const { return actions_.end(); }
421  const_reverse_iterator rend() const { return actions_.rend(); }
422 
423  iterator turn_begin(std::size_t turn_num){ return actions_.turn_begin(turn_num); }
424  iterator turn_end(std::size_t turn_num){ return actions_.turn_end(turn_num); }
425  reverse_iterator turn_rbegin(std::size_t turn_num){ return actions_.turn_rbegin(turn_num); }
426  reverse_iterator turn_rend(std::size_t turn_num){ return actions_.turn_rend(turn_num); }
427  const_iterator turn_begin(std::size_t turn_num) const { return actions_.turn_begin(turn_num); }
428  const_iterator turn_end(std::size_t turn_num) const { return actions_.turn_end(turn_num); }
429  const_reverse_iterator turn_rbegin(std::size_t turn_num) const { return actions_.turn_rbegin(turn_num); }
430  const_reverse_iterator turn_rend(std::size_t turn_num) const { return actions_.turn_rend(turn_num); }
431 
432  /** Returns an iterator range corresponding to the requested turn. */
433  range_t iter_turn(std::size_t turn_num){ return actions_.iter_turn(turn_num); }
434  rrange_t riter_turn(std::size_t turn_num){ return actions_.riter_turn(turn_num); }
435  crange_t iter_turn(std::size_t turn_num) const { return actions_.iter_turn(turn_num); }
436  crrange_t riter_turn(std::size_t turn_num) const { return actions_.riter_turn(turn_num); }
437 
438 
439  /**
440  * 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.
441  *
442  * This function makes sense when T is a non-chronological iterator.
443  * If T is @ref iterator and Compare is std::less<iterator>,
444  * this function returns limit if limit is in [between.first, between.second)
445  * or between.first if between.first>limit or end() otherwise.
446  *
447  * @param between the two iterators between which the action will be searched.
448  * @param limit the lower bound to search from, that is the return value `it' will verify !comp(limit, it).
449  * @param comp the predicate to compare with.
450  * @return `it' so that for all values `x' in [between.first, between.second), chronologically, !comp(x, it) and !comp(it, limit).
451  * @retval end() if no such action exist.
452  */
453  template <typename T, typename Compare>
454  iterator find_first_action_of(std::pair<T,T> between, iterator limit, Compare comp);
455  template <typename T, typename Compare>
456  const_iterator find_first_action_of(std::pair<T,T> between, const_iterator limit, Compare comp) const;
457 
458  /**
459  * Find the first action occurring at a given hex.
460  *
461  * @retval end() if no action occurs at the given location.
462  */
463  iterator find_first_action_at(map_location hex);
464 
465  /**
466  * Finds the first action that belongs to this unit, starting the search at the specified position.
467  * @return The position, or end() if not found.
468  */
469  iterator find_first_action_of(const unit& unit, iterator start_position);
470  iterator find_first_action_of(size_t unit_id, iterator start_position);
471  /** Variant of this method that always start searching at the beginning of the queue */
472  iterator find_first_action_of(const unit& unit){ return find_first_action_of(unit, begin()); }
473  iterator find_first_action_of(size_t unit_id){ return find_first_action_of(unit_id, begin()); }
474 
475  /**
476  * Finds the last action that belongs to this unit, starting the search backwards from the specified position.
477  * @return The position, or end() if not found.
478  */
479  iterator find_last_action_of(const unit& unit, iterator start_position);
480  iterator find_last_action_of(size_t unit_id, iterator start_position);
481  /** const variant of the previous function */
482  const_iterator find_last_action_of(const unit& unit, const_iterator start_position) const;
483  const_iterator find_last_action_of(size_t unit_id, iterator start_position) const;
484  /** Variant of the previous method that always start searching at the end of the queue */
485  iterator find_last_action_of(const unit& unit);
486  iterator find_last_action_of(size_t unit_id);
487  /** const variant of the previous function */
488  const_iterator find_last_action_of(const unit& unit) const;
489  const_iterator find_last_action_of(size_t unit_id) const;
490 
491  bool unit_has_actions(const unit& unit);
492  std::size_t count_actions_of(const unit& unit);
493  std::deque<action_ptr> actions_of(const unit& unit);
494 
495  /**
496  * Determines the appropriate turn number for the next action planned for this unit
497  *
498  * @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.
499  *
500  * @retval 0 if the unit doesn't have any planned action
501  */
502  std::size_t get_turn_num_of(const unit&) const;
503 
504  /** Used to track gold spending by recruits/recalls when building the future unit map */
505  int get_gold_spent() const { return gold_spent_; }
506  /** Used to track gold spending by recruits/recalls when building the future unit map */
507  void change_gold_spent_by(int difference);
508  /** Set gold spent back to zero */
509  void reset_gold_spent();
510  /** After a recruit action was executed the id of the unit was changed so we need to update the unitid of all following actions on that unit*/
511  void update_recruited_unit(std::size_t old_id, unit& new_unit);
512 
513  void raw_turn_shift();
514  void synced_turn_shift();
515 
516  /**
517  * Queues a move to be executed last
518  * @return The queued move's position
519  */
520  iterator queue_move(std::size_t turn_num, unit& mover, const pathfind::marked_route& route,
521  arrow_ptr arrow, fake_unit_ptr fake_unit);
522 
523  /**
524  * Queues an attack or attack-move to be executed last
525  * @return The queued attack's position
526  */
527  iterator queue_attack(std::size_t turn_num, unit& mover, const map_location& target_hex, int weapon_choice, const pathfind::marked_route& route,
528  arrow_ptr arrow, fake_unit_ptr fake_unit);
529 
530  /**
531  * Queues a recruit to be executed last
532  * @return The queued recruit's position
533  */
534  iterator queue_recruit(std::size_t turn_num, const std::string& unit_name, const map_location& recruit_hex);
535 
536  /**
537  * Queues a recall to be executed last
538  * @return The queued recall's position
539  */
540  iterator queue_recall(std::size_t turn_num, const unit& unit, const map_location& recall_hex);
541 
542  /**
543  * Queues a suppose_dead to be executed last
544  * @return The queued suppose_dead's position (an iterator to it)
545  */
546  iterator queue_suppose_dead(std::size_t turn_num, unit& curr_unit, const map_location& loc);
547 
548  /**
549  * Network code. A net_cmd object (a config in disguise) represents a modification
550  * to a side_actions object. execute_net_cmd() translates one of these into
551  * a real modification of *this. The make_net_cmd_***() family of functions is
552  * convenient for building specific types of net_cmds.
553  */
554  typedef config net_cmd;
555  void execute_net_cmd(const net_cmd&);
556  net_cmd make_net_cmd_insert(std::size_t turn_num, std::size_t pos, action_const_ptr) const;
557  net_cmd make_net_cmd_insert(const const_iterator& pos, action_const_ptr) const;
558  net_cmd make_net_cmd_replace(const const_iterator& pos, action_const_ptr) const;
559  net_cmd make_net_cmd_remove(const const_iterator& pos) const;
560  net_cmd make_net_cmd_bump_later(const const_iterator& pos) const;
561  net_cmd make_net_cmd_clear() const;
562  net_cmd make_net_cmd_refresh() const;
563 
564 private:
565  iterator safe_insert(std::size_t turn_num, std::size_t pos, action_ptr to_insert);
566  iterator synced_erase(iterator itor);
567  iterator synced_insert(iterator itor, action_ptr to_insert);
568  iterator synced_enqueue(std::size_t turn_num, action_ptr to_insert);
569  iterator safe_erase(const iterator& itor);
570 
571  container actions_;
572 
573  std::size_t team_index_;
575 
576  /** Used to store gold "spent" in planned recruits/recalls when the future unit map is applied */
578 
579  bool hidden_;
580 };
581 
582 /** Dumps side_actions on a stream, for debug purposes. */
583 std::ostream& operator<<(std::ostream &out, const wb::side_actions& side_actions);
584 
586 {
587  std::vector<int> numbers_to_draw;
588  std::vector<std::size_t> team_numbers;
590  std::set<std::size_t> secondary_numbers;
591 
593  : numbers_to_draw()
594  , team_numbers()
595  , main_number(-1)
596  , secondary_numbers()
597  {}
598 };
599 
600 template <typename T, typename Compare>
601 side_actions::iterator side_actions::find_first_action_of(std::pair<T,T> between, iterator limit, Compare comp)
602 {
603  iterator first = actions_.end();
604  for(T it = between.first; it != between.second; ++it) {
605  iterator chrono_it = actions_.project<container::chronological>(it);
606  if((comp(chrono_it, first) || first==actions_.end()) && !comp(chrono_it, limit)) {
607  first = chrono_it;
608  }
609  }
610  return first;
611 }
612 
613 template <typename T, typename Compare>
614 side_actions::const_iterator side_actions::find_first_action_of(std::pair<T,T> between, const_iterator limit, Compare comp) const
615 {
616  const_iterator first = actions_.end();
617  for(T it = between.first; it != between.second; ++it) {
618  const_iterator chrono_it = actions_.project<container::chronological>(it);
619  if((comp(chrono_it, first) || first==actions_.end()) && !comp(chrono_it, limit)) {
620  first = chrono_it;
621  }
622  }
623  return first;
624 }
625 
626 } //end namespace wb
std::pair< reverse_iterator, reverse_iterator > rrange_t
container::iterator iterator
const_iterator end() const
const versions of the above
iterator end()
Returns the iterator for the position after the last executed action within the actions queue...
std::pair< reverse_iterator, reverse_iterator > rrange_t
This class represents a single unit of a specific type.
Definition: unit.hpp:121
action_limits turn_beginnings_
Contains a list of iterator to the beginning of each turn.
const_iterator turn_end(std::size_t turn_num) const
iterator push_front(std::size_t turn, action_ptr action)
Pushes an action in front of a given turn.
std::vector< int > numbers_to_draw
action_set::index< T >::type::const_iterator project(U it) const
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.
bool modify(iterator position, Modifier mod)
void turn_shift()
Shift turn.
iterator find_first_action_of(size_t unit_id)
const_iterator turn_begin(std::size_t turn_num) const
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.
const_reverse_iterator rbegin() const
const reverse versions of the above
crange_t iter_turn(std::size_t turn_num) const
config net_cmd
Network code.
static config unit_name(const unit *u)
Definition: reports.cpp:160
iterator bump_earlier(iterator position)
Moves an action earlier in the execution order.
std::pair< const_iterator, const_iterator > crange_t
side_actions_container container
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
range_t iter_turn(std::size_t turn_num)
Returns an iterator range corresponding to the requested turn.
reverse_iterator turn_rend(std::size_t turn_num)
iterator erase(iterator position)
Deletes the 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.
container::reverse_iterator reverse_iterator
Arrows destined to be drawn on the map.
Definition: arrow.hpp:30
action_set::index< chronological >::type::reverse_iterator reverse_iterator
int get_gold_spent() const
Used to track gold spending by recruits/recalls when building the future unit map.
Contains typedefs for the whiteboard.
const_iterator end() const
const versions of the above
bool empty() const
Indicates whether the action queue is empty.
std::shared_ptr< action > action_ptr
Definition: typedefs.hpp:62
bool empty() const
Indicates whether the action queue is empty.
std::pair< const_reverse_iterator, const_reverse_iterator > crrange_t
void clear()
Empties the action queue.
reverse_iterator rend()
reverse version of the above
Structure which holds a single route and marks for special events.
Definition: pathfind.hpp:141
const_iterator begin() const
const versions of the above
const_iterator begin() const
const versions of the above
iterator turn_begin(std::size_t turn_num)
Encapsulates the map of the game.
Definition: location.hpp:38
std::size_t size() const
Returns the number of actions in the action queue.
range_t iter_turn(std::size_t turn_num)
Returns an iterator range corresponding to the requested turn.
Tag for action_set&#39;s hashed_non_unique index.
std::size_t team_index()
Returns the team index this action queue belongs to.
std::deque< iterator > action_limits
const_reverse_iterator turn_rbegin(std::size_t turn_num) const
const_reverse_iterator rbegin() const
crange_t iter_turn(std::size_t turn_num) const
crrange_t riter_turn(std::size_t turn_num) const
std::size_t size() const
Returns the number of actions in the action queue.
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_rend(std::size_t turn_num)
std::pair< iterator, iterator > range_t
std::size_t turn_size(std::size_t turn_num) const
Returns the number of actions planned for turn turn_num.
bool hidden() const
reverse_iterator turn_rbegin(std::size_t turn_num)
const_reverse_iterator turn_rend(std::size_t turn_num) const
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.
const_reverse_iterator turn_rend(std::size_t turn_num) const
std::shared_ptr< arrow > arrow_ptr
Definition: typedefs.hpp:60
reverse_iterator turn_rbegin(std::size_t turn_num)
std::set< std::size_t > secondary_numbers
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, std::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.
rrange_t riter_turn(std::size_t turn_num)
iterator turn_end(std::size_t turn_num)
reverse_iterator rend()
reverse version of the above
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.
iterator insert(iterator position, action_ptr action)
Inserts an action at the specified position.
Tag for action_set&#39;s hashed_non_unique index.
container::const_reverse_iterator const_reverse_iterator
const_iterator turn_end(std::size_t turn_num) const
std::ostream & operator<<(std::ostream &s, action_ptr action)
Definition: action.cpp:34
std::size_t team_index_
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.
rrange_t riter_turn(std::size_t turn_num)
const_reverse_iterator turn_rbegin(std::size_t turn_num) const
const_reverse_iterator rend() const
Tag for action_set&#39;s random_access index.
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.
const_reverse_iterator rend() const
const reverse versions of the above
crrange_t riter_turn(std::size_t turn_num) const
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:61
const action_set & actions() const
Get the underlying action container.
std::pair< const_iterator, const_iterator > crange_t
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.
std::pair< iterator, iterator > range_t
This internal whiteboard class holds the planned action queues for a team, and offers many utility me...
std::string::const_iterator iterator
Definition: tokenizer.hpp:25
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
std::size_t num_turns() const
Returns the number of turns that have plans.
Definition: display.hpp:49
void clear()
Empties the action queue.
void show(const std::string &window_id, const t_string &message, const point &mouse, const SDL_Rect &source_rect)
Shows a tip.
Definition: tooltip.cpp:140
iterator bump_later(iterator position)
Moves an action later in the execution order.
iterator find_first_action_of(const unit &unit)
Variant of this method that always start searching at the beginning of the queue. ...
std::shared_ptr< action const > action_const_ptr
Definition: typedefs.hpp:63