/* $Id$ */ #ifndef _BONUSMANAGER_HPP_ #define _BONUSMANAGER_HPP_ /**********************************************************/ #include "settings.hpp" #include "constants.hpp" #include "serializable.hpp" #include "weightedrandom.hpp" #include "bonus.hpp" /**********************************************************/ class World; /**********************************************************/ //! administrates the generation an placement of boni in the world class BonusManager : public Serializable { public: BonusManager( World* const world, const unsigned int seed = 0 ); virtual ~BonusManager(); //! resets the object to the state after creation void reset(); //! loads the configuration for the bonus management bool loadSettings( const char* const filename ); //! \name selection, creation, registration of bonus objects //@{ //! selects a random object ID of a bonus object /*! This function selects randomly an object ID of a bonus * object using the probability weights loaded in loadSettings. * This is tried only once, which means, if the weighted random * call returns the ID of a bonus type, that has already reached * its maximal number in the world, -1 is returned. In this case * the return value is not a valid object ID. */ int selectRandomBonusID(); //! places a new bonus in the world void updatePlacement(); //! register the passed bonus at the manager void registerBonusEntrance( Bonus &bonus ); //! "unregister" the passed bonus at the manager void registerBonusExit( Bonus &bonus ); //@} //! \name (de)serialization //@{ virtual Uint32 getSerializeBufferSize() const; virtual void serialize( Uint8*& bufferPointer ) const; virtual void deserialize( Uint8*& bufferPointer ); //@} protected: //! creates the setting definitions needed in loadSettings /*! To read the settings for the bonus manager we need an array * of type SettingDef to pass it to SettingDataBase::readSettings. * This array is created dynamically in order to automize its * adaption to changes in the list of possible bonus types * defined in constants.hpp and constants.cpp. */ SettingDef* createSettingDefinitions(); //! enumeration constants as access indices in the array of setting definitions enum { ACTIV_FLAG_DEF = 0, SPAWN_DELAY_INTERVAL_DEF, NUM_SETTING_DEFS }; //! pointer to the used world World* const m_world; //! internal random number generator for bonus selection and placement WeightedRandom m_rand; bool m_active; Sint32 m_minDelay, m_maxDelay; Sint32 m_delayCounter; Sint32 *m_Limits; Sint32 *m_numExisting; //! definitions for general settings static const SettingDef m_SettingDef[NUM_SETTING_DEFS+1]; }; /**********************************************************/ #endif // _BONUSMANAGER_HPP_