/* $Id: mapstuff.hpp,v 1.7 2005/06/28 13:55:20 chfreund Exp $ */ #ifndef _MAPSTUFF_HPP_ #define _MAPSTUFF_HPP_ /**********************************************************/ #include "mapstuffset.hpp" /**********************************************************/ //! class, that represents the map stuff for one them /*! This class represents the combound map stuff for one theme. * It is a collection on several map stuff sets (class MapStuffSet) * of arbitrary materials (see class MapStuffSet). It provides the * administration of these sets and their random selection, and * therefore the random selection of single map stuff graphics. * Each theme (class Theme) has got one map stuff object for the * real map stuff, and one for the structure maps, that are only * applied on the basic map filled with some plain earth. */ class MapStuff { public: MapStuff( const Uint32 randomseed ); ~MapStuff(); //! \name access to the map stuff items //@{ //! returns true, if there are any items present (only random items) bool hasData() const { return m_randomSets.getSize() > 0 || m_fixedSets.getSize() > 0; } //! returns true, if a map stuff set of the passed material is present bool hasItemOfMaterial( const int material ) const { if( material <= MapStuffSet::UNDEFINED || material >= MapStuffSet::NUM_MATERIALS ) { return false; } return m_MaterialPresent[material]; } //! returns a randomly chosen item /*! Chooses randomly an item and returns its address at the * passed pointer "item". * \param item address of a pointer to a Sprite object. This * pointer will be set to the selected map stuff item. * \param material the material, the selected map stuff item * should have. If material is specified as * MapStuffSet::UNDEFINED, an arbitrary material is * selected. If the demanded material is not present * in this map stuff object, parameter *item is set * to NULL and MapStuffSet::UNDEFINED is returned. * \return the material of the selected item. * MapStuffSet::UNDEFINED, if the demanded item could * not be selected. */ int getRandomItem( const Sprite** item, int material = MapStuffSet::UNDEFINED ); //! returns number of loaded fixed items int getNumFixedItems() const { return m_fixedDefs.getSize(); } //! returns the next fixed item /*! */ int getFixedItem( const int index, const Uint32 mapWidth, const Uint32 mapHeight, const Sprite** item, Sint32& x, Sint32& y ); //@} //! loads the map stuff from the specified configuration file bool load( const String& path, const String& configfile ); //! resets the object to the state after creation void reset(); protected: //! enumeration constants for access to the setting definitions enum { RND_SETS_SSDEFS = 0, RND_ODDS_SSDEFS, RND_NUM_SSDEFS }; //! enumeration constants for access to the setting definitions enum { FXD_SETS_SSDEFS = 0, FXD_ITEMS_SSDEFS, FXD_NUM_SSDEFS }; //! auxiliary class to keep fixed map stuff items class FixedMapStuffDef { public: FixedMapStuffDef( const Uint32 index, const Sint32 x, const Sint32 y, const Sint32 dx, const Sint32 dy ) : m_Index(index), m_x(x), m_y(y), m_dx(dx), m_dy(dy) {} //! \name member access //!@{ Sint32 getIndex() const { return m_Index; } Sint32 getX() const { return m_x; } Sint32 getY() const { return m_y; } Sint32 getDX() const { return m_dx; } Sint32 getDY() const { return m_dy; } //@} protected: Uint32 m_Index; Sint32 m_x, m_y, m_dx, m_dy; }; //! loads the random map stuff sets bool loadRandomSets( const String& path, const String& configfile ); //! loads the fixed map stuff sets bool loadFixedSets( const String& path, const String& configfile ); //! vector with random map stuff sets PointerVector m_randomSets; //! vector with fixed map stuff sets PointerVector m_fixedSets; //! PointerVector m_fixedDefs; WeightedRandom m_Random; //!< random number generator bool m_MaterialPresent[MapStuffSet::NUM_MATERIALS]; //! setting definitions for random sets static const SettingDef m_rndSettingDef[RND_NUM_SSDEFS+1]; //! setting definitions for random sets static const SettingDef m_fxdSettingDef[FXD_NUM_SSDEFS+1]; }; /**********************************************************/ #endif // _MAPSTUFF_HPP_