home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 February / maximum-cd-2009-02.iso / DiscContents / SMC_1.6_win32.exe / src / user / savegame.h < prev   
Encoding:
C/C++ Source or Header  |  2008-07-01  |  5.7 KB  |  224 lines

  1. /***************************************************************************
  2.  * savegame.h  -  header for the corresponding cpp file
  3.  *
  4.  * Copyright (C) 2003 - 2008 Florian Richter
  5.  ***************************************************************************/
  6. /*
  7.    This program is free software; you can redistribute it and/or modify
  8.    it under the terms of the GNU General Public License as published by
  9.    the Free Software Foundation; either version 3 of the License, or
  10.    (at your option) any later version.
  11.    
  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  14. */
  15.  
  16. #ifndef SMC_SAVEGAME_H
  17. #define SMC_SAVEGAME_H
  18.  
  19. #include "../core/globals.h"
  20. #include "../objects/sprite.h"
  21.  
  22. /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
  23.  
  24. #define SAVEGAME_VERSION 8
  25. #define SAVEGAME_VERSION_UNSUPPORTED 5
  26.  
  27. /* *** *** *** *** *** *** *** cSave_Overworld_Waypoint *** *** *** *** *** *** *** *** *** *** */
  28. /* Overworld Waypoint save data
  29.  *
  30. */
  31. class cSave_Overworld_Waypoint
  32. {
  33. public:
  34.     cSave_Overworld_Waypoint( void );
  35.     ~cSave_Overworld_Waypoint( void );
  36.  
  37.     string destination;
  38.     bool access;
  39. };
  40.  
  41. typedef vector<cSave_Overworld_Waypoint *> Save_Overworld_WaypointList;
  42.  
  43.  
  44. /* *** *** *** *** *** *** *** cSave_Overworld *** *** *** *** *** *** *** *** *** *** */
  45. /* Overworld save data
  46.  *
  47. */
  48. class cSave_Overworld
  49. {
  50. public:
  51.     cSave_Overworld( void );
  52.     ~cSave_Overworld( void );
  53.  
  54.     string name;
  55.  
  56.     // waypoint data
  57.     Save_Overworld_WaypointList Waypoints;
  58. };
  59.  
  60. typedef vector<cSave_Overworld *> Save_OverworldList;
  61.  
  62. /* *** *** *** *** *** *** *** cSave_Level_Object_Property *** *** *** *** *** *** *** *** *** *** */
  63. /* Level object string property
  64. */
  65. class cSave_Level_Object_Property
  66. {
  67. public:
  68.     cSave_Level_Object_Property( string nName = "", string nValue = "" );
  69.  
  70.     string Name;
  71.     string Value;
  72. };
  73.  
  74. typedef vector<cSave_Level_Object_Property> Save_Level_Object_ProprtyList;
  75.  
  76. /* *** *** *** *** *** *** *** cSave_Level_Object *** *** *** *** *** *** *** *** *** *** */
  77. /* Level object save data
  78.  *
  79. */
  80. class cSave_Level_Object
  81. {
  82. public:
  83.     cSave_Level_Object( void );
  84.     ~cSave_Level_Object( void );
  85.  
  86.     // Check if property exists
  87.     bool exists( string val_name );
  88.  
  89.     // Returns the Value
  90.     string Get_Value( string val_name );
  91.  
  92.     SpriteType type;
  93.  
  94.     // object properties
  95.     Save_Level_Object_ProprtyList properties;
  96. };
  97.  
  98. typedef vector<cSave_Level_Object *> Save_Level_ObjectList;
  99.  
  100. /* *** *** *** *** *** *** *** cSave *** *** *** *** *** *** *** *** *** *** */
  101. /* Save data
  102.  *
  103. */
  104. class cSave
  105. {
  106. public:
  107.     cSave( void );
  108.     ~cSave( void );
  109.  
  110.     // Set data to default/empty values
  111.     void Clear( void );
  112.  
  113.     // ## Save Information
  114.     // description
  115.     string description;
  116.     // savegame version
  117.     int version;
  118.     // time  ( seconds since 1970 )
  119.     time_t save_time;
  120.  
  121.     // ## Player Information
  122.     // lives
  123.     unsigned int lives;
  124.     // points
  125.     unsigned int points;
  126.     // goldpieces
  127.     unsigned int goldpieces;
  128.     // player type
  129.     unsigned int player_type;
  130.     // player state
  131.     unsigned int player_state;
  132.     // item in the itembox
  133.     unsigned int itembox_item;
  134.  
  135.     // ## Level Information
  136.     /* level name
  137.      * only saved if player is in a level
  138.     */
  139.     string level_name;
  140.     // level position
  141.     float level_posx, level_posy;
  142.     // objects data
  143.     Save_Level_ObjectList level_objects;
  144.  
  145.     // ## Overworld Information
  146.     // active Overworld
  147.     string overworld_active;
  148.     // current Waypoint
  149.     unsigned int overworld_current_waypoint;
  150.  
  151.     // overworld data
  152.     Save_OverworldList Overworlds;
  153. };
  154.  
  155. /* *** *** *** *** *** *** *** cSavegame *** *** *** *** *** *** *** *** *** *** */
  156.  
  157. class cSavegame : public CEGUI::XMLHandler
  158. {
  159. public:
  160.     cSavegame( void );
  161.     virtual ~cSavegame( void );
  162.  
  163.     /* Load a Save
  164.      * Returns 0 if failed 
  165.      * 1 if ingame save
  166.      * 2 if Overworld save
  167.     */
  168.     int Load_Game( unsigned int save_slot );
  169.     // Save the game with the given description
  170.     bool Save_Game( unsigned int save_slot, string description );
  171.  
  172.     // Load a Save
  173.     cSave *Load( unsigned int save_slot );
  174.     // Save a Save
  175.     int Save( unsigned int save_slot, cSave *Save_info );
  176.  
  177.     // Returns only the Savegame Description
  178.     string Get_Description( unsigned int save_slot, bool only_description = 0 );
  179.  
  180.     // Returns true if the Savegame is valid
  181.     bool Is_Valid( unsigned int save_slot );
  182.  
  183.     // debug messages enabled
  184.     bool debug;
  185.  
  186.     // current error count
  187.     unsigned int error_count;
  188.  
  189.     // savegame directory
  190.     string savegame_dir;
  191. private:
  192.     // XML element start
  193.     virtual void elementStart( const CEGUI::String &element, const CEGUI::XMLAttributes &attributes );
  194.     // XML element end
  195.     virtual void elementEnd( const CEGUI::String &element );
  196.  
  197.     void Handle_Level( const CEGUI::XMLAttributes &attributes );
  198.     void Handle_Level_Object( const CEGUI::XMLAttributes &attributes );
  199.     void Handle_Player( const CEGUI::XMLAttributes &attributes );
  200.     void Handle_Overworld_Data( const CEGUI::XMLAttributes &attributes );
  201.     void Handle_Overworld( const CEGUI::XMLAttributes &attributes );
  202.     void Handle_Overworld_Level( const CEGUI::XMLAttributes &attributes );
  203.  
  204.     // XML element Item Tag list
  205.     CEGUI::XMLAttributes xml_attributes;
  206.  
  207.     // current savegame overworld waypoints for overworld parsing
  208.     Save_Overworld_WaypointList active_waypoints;
  209.     // current savegame level objects for level parsing
  210.     Save_Level_ObjectList level_objects;
  211.  
  212.     // temp Save used for loading
  213.     cSave *save_temp;
  214. };
  215.  
  216. /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
  217.  
  218. // The Savegame Handler
  219. extern cSavegame *pSavegame;
  220.  
  221. /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
  222.  
  223. #endif
  224.