5 #ifndef PET_SPAWNER_HPP 6 #define PET_SPAWNER_HPP 9 #include "spawner_base.hpp" 10 #include "player/player.hpp" 21 enum pet_replacement_strategy
55 template<
typename T,
typename O = player_t>
59 using create_fn_t = std::function<T*(O*)>;
60 using apply_fn_t = std::function<void(T*)>;
61 using check_arg_fn_t = std::function<bool(const T*)>;
62 using check_fn_t = std::function<bool(void)>;
63 using expr_fn_t = std::function<std::unique_ptr<expr_t>(util::span<const util::string_view>)>;
77 create_fn_t m_creator;
79 check_fn_t m_check_create;
81 std::vector<T*> m_pets, m_active_pets, m_inactive_pets;
85 pet_spawn_type m_type;
87 pet_replacement_strategy m_replacement_strategy;
92 std::vector<apply_fn_t> m_event_create;
95 std::unordered_map<std::string, expr_fn_t> m_expressions;
113 T* create_pet( create_phase phase );
119 T* replacement_pet();
121 pet_spawner_t( util::string_view
id, O* p, pet_spawn_type st = PET_SPAWN_DYNAMIC );
123 pet_spawn_type st = PET_SPAWN_DYNAMIC );
124 pet_spawner_t( util::string_view
id, O* p,
unsigned max_pets,
const create_fn_t& creator,
125 pet_spawn_type st = PET_SPAWN_DYNAMIC );
126 pet_spawner_t( util::string_view
id, O* p,
const create_fn_t& creator,
127 pet_spawn_type st = PET_SPAWN_DYNAMIC );
133 std::vector<T*>
spawn(
unsigned n );
139 size_t despawn(
const std::vector<T*>& obj );
141 size_t despawn(
const check_arg_fn_t& fn );
160 typename std::vector<T*>::iterator begin();
161 typename std::vector<T*>::iterator end();
162 typename std::vector<T*>::const_iterator cbegin();
163 typename std::vector<T*>::const_iterator cend();
188 std::vector<T*>
pets();
190 std::vector<const T*>
pets()
const;
194 T*
pet(
size_t index = 0 )
const;
213 std::unique_ptr<expr_t>
create_expression( util::span<const util::string_view> expr, util::string_view full_expression_str )
override;
219 void reset()
override;
226 #include "pet_spawner_impl.hpp" Definition: spawner_base.hpp:29
T * active_pet_min_remains(const check_arg_fn_t &fn=check_arg_fn_t())
Acccess the active pet with lowest remaining time left using an optional unary constraint.
Definition: pet_spawner_impl.hpp:473
void reset() override
Reset internal state.
Definition: pet_spawner_impl.hpp:658
pet_spawner_t< T, O > & add_expression(const std::string &name, const expr_fn_t &fn)
Registers custom expressions for the pet type.
Definition: pet_spawner_impl.hpp:167
void merge(base_actor_spawner_t *other) override
Merge dynamic pet information.
Definition: pet_spawner_impl.hpp:530
pet_spawner_t< T, O > & set_max_pets(unsigned v)
Sets the maximum number of active pets.
Definition: pet_spawner_impl.hpp:139
void datacollection_end() override
Collect statistical data.
Definition: pet_spawner_impl.hpp:665
void create_persistent_actors() override
Creates persistent pet objects during pet creation.
Definition: pet_spawner_impl.hpp:578
size_t n_active_pets() const
Number of active pets of type T.
Definition: pet_spawner_impl.hpp:77
pet_spawner_t< T, O > & set_replacement_strategy(pet_replacement_strategy new_)
Sets the replacement strategy of spawned pets if maximum is reached.
Definition: pet_spawner_impl.hpp:171
Definition: spell_data.hpp:398
pet_spawner_t< T, O > & set_creation_callback(const create_fn_t &fn)
Sets the creation callback for the pet.
Definition: pet_spawner_impl.hpp:143
size_t n_inactive_pets() const
Number of inactive pets of type T.
Definition: pet_spawner_impl.hpp:97
T * active_pet(size_t index=0)
Access the zero-indexth active pet, nullptr if no pet of index active.
Definition: pet_spawner_impl.hpp:446
pet_spawner_t< T, O > & set_default_duration(const spell_data_t *spell)
Set default duration based on a spell.
Definition: pet_spawner_impl.hpp:155
std::vector< T * > pets()
All pets.
Definition: pet_spawner_impl.hpp:434
std::unique_ptr< expr_t > create_expression(util::span< const util::string_view > expr, util::string_view full_expression_str) override
Returns a pet-related expression.
Definition: pet_spawner_impl.hpp:598
T * active_pet_max_remains(const check_arg_fn_t &fn=check_arg_fn_t())
Acccess the active pet with highest remaining time left using an optional unary constraint.
Definition: pet_spawner_impl.hpp:496
void extend_expiration(timespan_t adjustment)
Adjust the expiration time of active pets of type T.
Definition: pet_spawner_impl.hpp:248
T * pet(size_t index=0) const
Access the zero-indexth created pet, nullptr if no pets are created.
Definition: pet_spawner_impl.hpp:519
timespan_t iteration_uptime() const override
Returns total uptime of the spawned pet type.
Definition: pet_spawner_impl.hpp:652
size_t max_pets() const
Maximum number of active pets.
Definition: pet_spawner_impl.hpp:105
Class for representing InGame time.
Definition: timespan.hpp:37
timespan_t duration() const
Default spawning duration.
Definition: pet_spawner_impl.hpp:109
pet_spawner_t< T, O > & set_creation_check_callback(const check_fn_t &fn)
Set creation check callback for persistent pets. Dynamic spawns will always be created.
Definition: pet_spawner_impl.hpp:147
std::vector< T * > active_pets()
All currently active pets.
Definition: pet_spawner_impl.hpp:426
A wrapper object to enable dynamic pet spawns in simulationcraft.
Definition: pet_spawner.hpp:56
size_t n_pets() const
Total number of active and inactive pets of type T.
Definition: pet_spawner_impl.hpp:101
std::vector< T * > spawn(timespan_t duration=timespan_t::min(), unsigned n=0)
Spawn n new pets (defaults, 1 for dynamic, max_pets for persistent), return spawned pets as a vector ...
Definition: pet_spawner_impl.hpp:348
pet_spawner_t< T, O > & set_creation_event_callback(const apply_fn_t &fn)
Set (add) creation callback. Creation callbacks will be invoked for every new pet.
Definition: pet_spawner_impl.hpp:151
size_t despawn()
Despawn all active pets, return number of pets despawned.
Definition: pet_spawner_impl.hpp:177