/* $Id: theme.hpp,v 1.16.2.1 2006/01/20 11:23:31 chfreund Exp $ */
#ifndef _THEME_HPP_
#define _THEME_HPP_
/**********************************************************/
#include "mapstuff.hpp"
#include "objectitem.hpp"
#include "areaitem.hpp"
/**********************************************************/
//! class for a theme of a WoP map
/*! A WoP theme must be defined in the theme configuration file
* THEME_CONFIG (see constants.hpp) placed in path THEME_CONFIG_PATH
* (see constants.hpp).
* Inside this file the theme is defined inside a section (see class
* SettingDataBase) with a name, that matches the one of the theme,
* passed to the constructor.
*
* (Possible) components of a map theme:
* - \b name [string]: The theme's name. It must be specified as
* setting "name" and must coincide with the section's name and
* the name passed to the constructor
* - \b description [string]: Short description of the theme
* (optional).
* - \b size [string]: The map size (optional). If the setting "size"
* defines two integers (>= 100), these map dimensions (height,
* width) overwrite the settings global game settings "width" and
* "height", passed on the command line or fixed in the WoP
* configuration file.
* - \b earth [boolean]: if \b true (== default), the theme is filled
* with earth
* - \b waveground [boolean]: the oszillating ground (optional). Per
* default an indestructible ground with the shape of two superposed
* harmonic oszillations is set in each theme. To switch off this
* ground, set "waveground" to "false/no/0".
* - \b mapstuff [2 strings]: map stuff (optional). As setting
* "mapstuff" the configuration file for the used map stuff (see
* class MapStuff) is specified. This is done by giving the path,
* the configuration file can be found (relative to the full path
* of the theme configuration file), and the name of the configuration
* file.
* - \b structure [2 strings]: structure maps for the base earth.
* The base earth of the map is drawn as a randomly disturbed area.
* Since this might look too plain, there is the possibility to draw
* some maps on that plain earth, before any other map stuff
* is drawn on the map. These structure maps are usually some alpha
* blended nearly transparent pictures. The difference between a
* structure map and a map stuff with material DIGGABLE is that the
* structure map is assured to be drawn before any other map stuff.
* A map stuff of DIGGABLE material in contrary might also be drawn
* over any other map stuff of arbitrary material. The structure map
* simply is a map stuff, too, and therefore also defined like the
* setting "mapstuff", but with the name "structure".
* - \b density [float]: The density of the map stuff (optional).
* With the setting "density" the number of map stuff items per
* reference area is fixed. This number is an average number and
* therefore a realing point number. This reference area is 100x100
* pixels and fixed in as constant DENSITY_REFERENCE_AEREA in
* function Map::createFromTheme.
* - \b sdensity [float]: The density of the \b structure maps. The
* structure maps are distributed randomly like the map stuff. But
* its density is determined differently. The map stuff's density
* must be specified as "number of items per reference area". The
* structure maps' density is defined as fraction of the whole map
* surface, that should be covered by structure maps. This means,
* that the mapping algorithm cares about the sizes of the drawn
* structure maps. If we have a map of size 1000 x 1000 pixels, and
* the structure's density is 0.75, the mapping algorithm will draw
* randomly structure maps, until at least 1000*1000*0.75 pixels of
* structure maps. Since the maps will also overlap, this does not
* mean, that 75% of the map are covered by structure maps. The
* structure's density is set by "sdensity", and might also be
* larger than 1.0.
* - \b bonusconfig [string]: Path of the configuration file for the
* bonus management.
* - \b objectconfig [2 strings]: Path of a file containing an
* optional list of initially placed objects and the containing
* section. This list must be defined in a section (-> class
* SettingDataBase) in a separate file. In option "objectconfig"
* as first parameter this file is specified (path relative to the
* theme file), followed by the name of the section. Note that this
* definition makes it possible to place the object list in
* arbitrary files.
* - \b background [string]: Path of a file containing a
* background image
*/
class Theme
{
public:
//! constructor
/*! Constructor for a WoP theme. Its name is fixed at creation
* time. "Sieht komisch aus, is' aber so.".
* \param name the name of the theme (the possible names are
* defined in the themes' configuration file (see
* THEME_CONFIG, defined in constants.hpp)
* \param randomseed the seed for the class intern random
* number generator. Do not pass arbitrarily large
* values here, since the seed is implemented as
* the number of random numbers, that are generated
* and trashed at creation time of the number generator.
*/
Theme( const char* const name,
const Uint32 randomseed = 42 );
//! destructor
~Theme();
//! \name data access
//@{
//! returns a reference to the name of the theme
const String& getName() const { return m_Name; }
//! returns a reference to the short description
const String& getDescription() const { return m_Description; }
//! returns a pointer to the illustrating image of the theme
/* With the optional setting "thumbnail" in the theme definition
* section of the configuration file a small picture can be
* loaded to illustrate the theme. If this picture could be
* loaded successfully in Theme::loadSettings, this picture
* is accessable as Sprite pointer. If no picture was specified
* or the specified one could not be loaded, a Null pointer is
* returned.
*/
const Sprite* getThumbNail() const { return m_ThumbNail; }
//! returns true, if this theme defines its own map size
bool definesOwnSize() const { return m_Width > 0 && m_Height > 0; }
//! return map width (for validity call Theme::definesOwnSize)
Sint32 getWidth() const { return m_Width; }
//! return map height (for validity call Theme::definesOwnSize)
Sint32 getHeight() const { return m_Height; }
//! returns, if the theme has an oszillating ground
bool hasOszillatingGround() const { return m_useWaveGround; }
//! true, if some map stuff is loaded
bool hasMapStuff() const { return m_MapStuff.hasData(); }
//! returns map stuff object
MapStuff& getMapStuff() { return m_MapStuff; }
//! returns the map stuff density [# items per 100x100 pixels]
real getDensity() { return m_Density; }
//! true, if earth structure maps are loaded
bool hasEarthStructure() const { return m_EarthStructure.hasData(); }
//! returns earth structure object
MapStuff& getEarthStructure() { return m_EarthStructure; }
//! true, if threre are objects in the object list
bool hasObjectSet() const { return m_Objects.getNumItems() > 0; }
//! returns the object list
const ObjectSet& getObjectSet() const { return m_Objects; }
//! returns the object list
ObjectSet& getObjectSet() { return m_Objects; }
//! true, if threre are objects in the list of locked ares
bool hasLockedAreaSet() const { return m_lockedAreas.getNumItems() > 0; }
//! returns the list of locked areas
const AreaSet& getLockedAreaSet() const { return m_lockedAreas; }
//! returns the list of locked areas
AreaSet& getLockedAreaSet() { return m_lockedAreas; }
//! returns the structure map density
real getStructureDensity() const { return m_sDensity; }
//! returns, whether the theme is filled with earth
bool isEarthFilled() const { return m_fillWithEarth; }
//! returns the path to the bonus configuration file
const String& getBonusConfigPath() const { return m_BonusConfig; }
//! returns true, if a object configuration path was loaded
bool hasObjectConfigPath() const { return m_ObjectConfig.getLength() > 0; }
//! returns the path to the object configuration file
const String& getObjectConfigPath() const { return m_ObjectConfig; }
//! returns true, if a background path was loaded
bool hasBackgroundPath() const { return m_Background.getLength() > 0; }
//! returns the path to the background file
const String& getBackgroundPath() const { return m_Background; }
//@}
//! load the theme
/*! Load the theme from the configuration file "configfile",
* placed in the directory "configpath".
* \return true, if loading was successfull
*/
bool load( const char* const configpath,
const char* const configfile );
//! loads and returns the theme's description
String& loadDescription( const char* const configfile );
//! resets the object to the state after creation
void reset();
protected:
//! loads the settings
bool loadSettings( const char* const configfile,
SettingDataBase& settings );
//! enumeration types for convenient settings access
enum { NAME_SETTING_DEF = 0,
DESCRIPTION_SETTING_DEF,
THUMBNAIL_SETTING_DEF,
SIZE_SETTING_DEF,
EARTH_SETTING_DEF,
WAVEGROUND_SETTING_DEF,
MAPSTUFF_SETTING_DEF,
EARTH_STRUCTURE_DEF,
DENSITY_SETTING_DEF,
SDENSITY_SETTING_DEF,
BONUS_CONFIG_DEF,
OBJECT_CONFIG_DEF,
LOCKED_AREAS_DEF,
BACKGROUND_DEF,
NUM_SETTING_DEFS };
String m_Name, //!< name of the theme
m_Description; //!< short description of the theme
Sprite *m_ThumbNail; //!< small picture illustrating the theme
Sint32 m_Width, //!< width (might overwrite config settings)
m_Height; //!< height (might overwrite config settings)
MapStuff m_MapStuff, //!< map stuff
m_EarthStructure; //!< structure maps for basic earth
//! set of object definitions for the world's initialisation
/*! A list of objects that should be put into the world at its
* creation time. For definition of and more information about
* type ObjectSet see class ObjectItem and class ItemSet.
*/
ObjectSet m_Objects;
AreaSet m_lockedAreas; //!< set of areas, locked for random mapstuff
real m_Density, //!< density of map stuff
m_sDensity; //!< density of structure maps
bool m_fillWithEarth, //!< true -> theme is filled with earth
m_useWaveGround; //!< true -> oszillating ground
String m_BonusConfig; //!< path to bonus configuration file
String m_ObjectConfig; //!< path to object configuration file
String m_Background; //!< path to background file
//! setting definitions
static const SettingDef m_SettingDef[NUM_SETTING_DEFS+1];
};
/**********************************************************/
#endif // _THEME_HPP_