/* $Id: wopsettings.hpp,v 1.36.2.1 2006/01/20 11:23:31 chfreund Exp $ */ #ifndef WOP_SETTINGS_CLASS_INCLUDED #define WOP_SETTINGS_CLASS_INCLUDED #include #include "settings.hpp" #include "string.hpp" #include "serializable.hpp" #include "pvector_t.hpp" /********************************************************** * A WoP-specialized version of class Settings. ********************************************************** * bool readSettings( const char** const CommandLine, * const int nargs ); * Reads settings, first from command line, then from configuration * file. Settings from command line overwrite the ones, that are * read from the configuration file. If the path of the config file * is specified in the command line, this path is used. Otherwise * the default paths, ./.woprc, then ~/.woprc are checked. ********************************************************** * * HOW TO ADD A NEW SETTING: * (1) add a new const static member variable for the default value * in wopsettings.hpp * (2) initialize this static member variable in wopsettings.cpp * (3) add the new setting in the static member array * WopSettings::m_basicSettings ABOVE the terminating empty one * (4) add a new const member function get() in * wopsettings.hpp * (5) implement this member function in wopsetting.cpp, so that it * returns the setted value, if present, the default value, * otherwise. * (6) if necessary, add a function to set this setting * **********************************************************/ //! specialized settings class for WoP class WopSettings : public SettingDataBase, public Serializable { public: virtual ~WopSettings(); //! \name read access to WoP settings //@{ //! game mode [SERVER,CLIENT,REPLAY] int getMode( const bool exitOnError = true ) const; //! returns the game mode [DEATHMATCH,TEAMPLAY,BALLGAME] int getGameMode() const; //! returns the path of the data directory const char* getData() const; //! returns the server address const char* getServer() const; //! returns the width of the game map int getWidth() const; //! returns the height of the game map int getHeight() const; //! returns the name of the used theme const char* getTheme() const; //! returns the view mode [FULLSCREEN,WINDOW] int getView() const; //! returns, if the sound is switched of bool getQuiet() const; //! returns the player's name const char* getName() const; //! returns the player's color Uint32 getPlayerColor() const; //! returns the team ID int getTeamID() const; //! returns the keyboard layout const char* getKeyboard() const; //! returns the number of balls int getNumBalls() const; //! returns the number of goals int getNumGoals() const; //! return the skwoerm zone creation probability real getSZProb() const; //! returns the debug mode flag bool getDebug() const; //! returns a path string to music directory bool getMusicDir( String& path ) const; //! returns the bot names const char* getBots( const Sint32 i ) const; //! returns the name of the replay log file bool getReplayFileName( String& path ) const; //@} //! \name read access to constants //@{ int getMinWidth() const; int getMaxWidth() const; int getMinHeight() const; int getMaxHeight() const; //@} //! \name write access to WoP settings //@{ //! sets the game mode (only in this class!) bool setGameMode( const int mode ); //! sets the data path (only in this class!) bool setData( const char* const path ); //! sets the server address (only in this class!) bool setServer( const char* const server ); //! sets the map's width in pixels (only in this class!) bool setWidth( const int width ); //!sets the map's height in pixels (only in this class!) bool setHeight( const int height ); //! sets the player's name (only in this class!) bool setName( const char* const ); //! sets the player's color (only in this class!) bool setPlayerColor( const Uint32 ); //! sets the team ID (only in this class!) bool setTeamID( const int teamID ); //! sets a specific key bool setKey( const char* name, const char* value ); //! sets the keyboard layout bool setKeyboard( const char* const layout ); //! sets the number of balls bool setNumBalls( const int nballs ); //! sets the number of goals bool setNumGoals( const int ngoals ); //@} //! \name methods concerning the themes //@{ //! bool isAvailableTheme( const String& name ) const; //! get a list of available theme names bool getAvailableThemes( PointerVector& themes ) const; //! prints a list of available themes void printAvailableThemes( ostream& out, const char *const head = 0x0, const char *const tail = 0x0 ) const; //@} //! \name (de)serialization of server settings //@{ void serializeServerSettings( Uint8*& bufferPointer ); void deserializeServerSettings( Uint8*& bufferPonter ); void serialize( Uint8*& bufferPointer ) const; void deserialize( Uint8*& bufferPointer ); Uint32 getSerializeBufferSize() const; bool enforcePresenceOfServerSettings(); //@} //! read settings form command line \b and config file bool readSettings( const char** const CommandLine, const int nargs ); //! get instance (singleton) static WopSettings* getInstance(); //! delete instance (signleton) static void deleteInstance(); //! writes the configuration file (needs an update (uwe)) bool writeConfigFile( String& path ); //! void printHelp( const int lowerHelpLevel = -1, const int upperHelpLevel = -1 ) const; protected: //! \name methods concerned with all kinds of paths //@{ bool getConfigFilePath( String& path, int &rank ); bool expandPath( String& path ) const; //@} bool m_writeConfigFile, m_pickySuccess; //! \name setting definitions and string mappings //@{ static const char* m_configPaths[]; static SettingDef m_basicSettings[]; static const char* m_serverSettingsIDs[]; static SettingStringMap m_mode_StringMap[]; static SettingStringMap m_view_StringMap[]; static SettingStringMap m_gamemode_StringMap[]; //@} // default values static const int m_DefaultMode; static const int m_DefaultGameMode; static const char m_DefaultData[]; static const char m_DefaultServer[]; static const int m_DefaultWidth; static const int m_DefaultHeight; static const char m_DefaultTheme[]; static const int m_DefaultView; static const bool m_DefaultQuiet; static const char m_DefaultConfig[]; static const char m_DefaultName[]; static const Uint32 m_DefaultPlayerColor; static const int m_DefaultTeamID; static const char m_DefaultKeyboard[]; static const int m_DefaultNumBalls; static const int m_DefaultNumGoals; static const real m_DefaultSZProb; static const bool m_DefaultDebug; private: //! privat constructor (class is singleton!) WopSettings( const bool verbose = true ); static WopSettings* m_settings; }; /**********************************************************/ #endif // WOP_SETTINGS_CLASS_INCLUDED