/* core/module.h This file is part of the Osirion project and is distributed under the terms of the GNU General Public License version 2 */ #ifndef __INCLUDED_CORE_MODULE_H__ #define __INCLUDED_CORE_MODULE_H__ #include #include "filesystem/inifile.h" #include "core/player.h" namespace core { /// abstract base class for a game module class Module { public: Module(const char *name, bool interactive = true); virtual ~Module(); /*----- inspectors ------------------------------------------------ */ /// return true if the game module can run a timeframe inline bool running() const { return module_running; } /// return true if the game module can not run a timeframe inline bool error() const { return !module_running; } /// label of the module inline std::string const & label() const { return module_label; } /// return the name of the module inline std::string const & name() const { return module_name; } /// indicates if this is an interactive module or not inline bool interactive() const { return module_interactive; } /*----- mutators -------------------------------------------------- */ /// run one game frame virtual void frame(float seconds) = 0; /// is called when a player connects virtual void player_connect(Player *player) = 0; /// is called when a player disconnects virtual void player_disconnect(Player *player) = 0; /// is called when player data needs to be saved virtual void player_save(Player *player); /// is called when player data needs to be loaded virtual void player_load(Player *player); /// set the module label void set_label(const std::string &label); static inline Module *instance() { return module_instance; } /// singleplayer load game function virtual void game_load(core::Player *player, filesystem::IniFile & inifile); /// singleplayer save game function virtual void game_save(core::Player *player, std::ostream & os); protected: /// abort a running module void abort(); private: bool module_interactive; bool module_running; std::string module_label; std::string module_name; static Module* module_instance; }; } #endif // __INCLUDED_CORE_MODULE_H__