1 /** 2 * @file 3 * @brief Provide a way to iterator over all actors, subject to a few common restrictions. 4 **/ 5 6 #pragma once 7 8 #include "los-type.h" 9 10 class actor_near_iterator 11 { 12 public: 13 actor_near_iterator(coord_def c, los_type los = LOS_DEFAULT); 14 actor_near_iterator(const actor* a, los_type los = LOS_DEFAULT); 15 16 operator bool() const; 17 actor* operator*() const; 18 actor* operator->() const; 19 actor_near_iterator& operator++(); 20 actor_near_iterator operator++(int); 21 22 protected: 23 const coord_def center; 24 los_type _los; 25 const actor* viewer; 26 int i; 27 28 bool valid(const actor* a) const; 29 void advance(); 30 }; 31 32 class monster_near_iterator 33 { 34 public: 35 monster_near_iterator(coord_def c, los_type los = LOS_DEFAULT); 36 monster_near_iterator(const actor* a, los_type los = LOS_DEFAULT); 37 38 operator bool() const; 39 monster* operator*() const; 40 monster* operator->() const; 41 monster_near_iterator& operator++(); 42 monster_near_iterator operator++(int); 43 bool operator==(const monster_near_iterator &other); 44 bool operator!=(const monster_near_iterator &other); 45 monster_near_iterator begin(); 46 monster_near_iterator end(); 47 48 protected: 49 const coord_def center; 50 los_type _los; 51 const actor* viewer; 52 int i; 53 int begin_point; 54 55 bool valid(const monster* a) const; 56 void advance(); 57 }; 58 59 class monster_iterator 60 { 61 public: 62 monster_iterator(); 63 64 operator bool() const; 65 monster* operator*() const; 66 monster* operator->() const; 67 monster_iterator& operator++(); 68 monster_iterator operator++(int); 69 70 protected: 71 int i; 72 void advance(); 73 }; 74 75 // Actor sorters for combination with the above 76 // Compare two actors, sorting farthest to nearest from {pos} 77 struct far_to_near_sorter 78 { 79 coord_def pos; 80 bool operator()(const actor* a, const actor* b); 81 }; 82 83 // Compare two actors, sorting nearest to farthest from {pos} 84 struct near_to_far_sorter 85 { 86 coord_def pos; 87 bool operator()(const actor* a, const actor* b); 88 }; 89