1 /* $Id$ */ 2 3 #ifndef _BONUSMANAGER_HPP_ 4 #define _BONUSMANAGER_HPP_ 5 6 /**********************************************************/ 7 8 #include "settings.hpp" 9 #include "constants.hpp" 10 #include "serializable.hpp" 11 #include "weightedrandom.hpp" 12 #include "bonus.hpp" 13 14 /**********************************************************/ 15 class World; 16 /**********************************************************/ 17 18 //! administrates the generation an placement of boni in the world 19 class BonusManager : public Serializable 20 { 21 public: 22 23 BonusManager( World* const world, 24 const unsigned int seed = 0 ); 25 virtual ~BonusManager(); 26 27 //! resets the object to the state after creation 28 void reset(); 29 30 //! loads the configuration for the bonus management 31 bool loadSettings( const char* const filename ); 32 33 //! \name selection, creation, registration of bonus objects 34 //@{ 35 //! selects a random object ID of a bonus object 36 37 /*! This function selects randomly an object ID of a bonus 38 * object using the probability weights loaded in loadSettings. 39 * This is tried only once, which means, if the weighted random 40 * call returns the ID of a bonus type, that has already reached 41 * its maximal number in the world, -1 is returned. In this case 42 * the return value is not a valid object ID. 43 */ 44 int selectRandomBonusID(); 45 46 //! places a new bonus in the world 47 void updatePlacement(); 48 49 //! register the passed bonus at the manager 50 void registerBonusEntrance( Bonus &bonus ); 51 //! "unregister" the passed bonus at the manager 52 void registerBonusExit( Bonus &bonus ); 53 //@} 54 55 //! \name (de)serialization 56 //@{ 57 virtual Uint32 getSerializeBufferSize() const; 58 virtual void serialize( Uint8*& bufferPointer ) const; 59 virtual void deserialize( Uint8*& bufferPointer ); 60 //@} 61 62 protected: 63 64 //! creates the setting definitions needed in loadSettings 65 66 /*! To read the settings for the bonus manager we need an array 67 * of type SettingDef to pass it to SettingDataBase::readSettings. 68 * This array is created dynamically in order to automize its 69 * adaption to changes in the list of possible bonus types 70 * defined in constants.hpp and constants.cpp. 71 */ 72 SettingDef* createSettingDefinitions(); 73 74 //! enumeration constants as access indices in the array of setting definitions 75 enum { ACTIV_FLAG_DEF = 0, 76 SPAWN_DELAY_INTERVAL_DEF, 77 NUM_SETTING_DEFS }; 78 79 //! pointer to the used world 80 World* const m_world; 81 //! internal random number generator for bonus selection and placement 82 WeightedRandom m_rand; 83 bool m_active; 84 Sint32 m_minDelay, m_maxDelay; 85 Sint32 m_delayCounter; 86 Sint32 *m_Limits; 87 Sint32 *m_numExisting; 88 89 //! definitions for general settings 90 static const SettingDef m_SettingDef[NUM_SETTING_DEFS+1]; 91 }; 92 93 /**********************************************************/ 94 95 #endif // _BONUSMANAGER_HPP_ 96