1 /*
2  * Copyright (C) 2006-2019 Christopho, Solarus - http://www.solarus-games.org
3  *
4  * Solarus is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * Solarus is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef SOLARUS_SAVEGAME_CONVERTER_V1_H
19 #define SOLARUS_SAVEGAME_CONVERTER_V1_H
20 
21 #include "solarus/core/Common.h"
22 #include <string>
23 
24 namespace Solarus {
25 
26 class Savegame;
27 
28 /**
29  * \brief Old format of savegames (version 1) kept for compatibility.
30  *
31  * The version 1 format was binary, not portable, not evolutive and hard to use.
32  * In particular, saved values were identified by integer indexes.
33  * This class is used to load version 1 savegames and convert them to version 2.
34  */
35 class SavegameConverterV1 {
36 
37   public:
38 
39     // creation and destruction
40     explicit SavegameConverterV1(const std::string& file_name);
41 
42     // data
43     std::string get_string(int index);
44     uint32_t get_integer(int index);
45     bool get_boolean(int index);
46 
47     // conversion to a savegame version 2
48     void convert_to_v2(Savegame& savegame_v2);
49 
50     /**
51      * \brief Index of each string saved in the file by the engine.
52      */
53     enum StringIndex {
54       PLAYER_NAME                       = 0,  /**< a name for this savegame */
55       STARTING_POINT                    = 1,  /**< the player appears on this destination point on the starting map */
56 
57       ITEM_SLOT_0                       = 2,  /**< current item associated to the first item slot
58                                                * (X button by default), an empty string means no item */
59       ITEM_SLOT_1                       = 3,  /**< current item associated to the second slot
60                                                * (V button by default), an empty string means no item */
61       STARTING_MAP                      = 4,  /**< id of the map where the player appears */
62 
63       /**
64        * \name Joypad customizable controls.
65        *
66        * Variables 1 to 9 indicate the joypad event
67        * of each game key: action, sword, item 1, item 2, pause,
68        * right, up, left and down.
69        * Examples: "button 1", "axis 1 +", "hat 1 left"
70        * \{
71        */
72       JOYPAD_ACTION_KEY                 = 10,
73       JOYPAD_SWORD_KEY                  = 11,
74       JOYPAD_ITEM_1_KEY                 = 12,
75       JOYPAD_ITEM_2_KEY                 = 13,
76       JOYPAD_PAUSE_KEY                  = 14,
77       JOYPAD_RIGHT_KEY                  = 15,
78       JOYPAD_UP_KEY                     = 16,
79       JOYPAD_LEFT_KEY                   = 17,
80       JOYPAD_DOWN_KEY                   = 18
81       /**
82        * \}
83        */
84 
85       // values above 32 are available to the quest
86     };
87 
88     /**
89      * \brief Index of each integer saved in the file.
90      *
91      * Do not change these numbers, otherwise you might break
92      * the existing savegames.
93      * Values before 1023 are used by the engine. Scripts only have a
94      * read-only access to them.
95      * Values above 1024 are available for the maps in reading and writing.
96      */
97     enum IntegerIndex {
98 
99       /**
100        * \name Last game status
101        * \{
102        */
103       STARTING_MAP_INT                  = 0,  /**< deprecated (maps are identified by strings now) */
104       PAUSE_LAST_SUBMENU                = 1,  /**< last submenu shown in the pause menu */
105       INVENTORY_LAST_ITEM_INDEX         = 2,  /**< index of the last item selected in the inventory */
106       EQUIPMENT_INITIALIZED             = 3,  /**< 1 if the initial items of the equipment have been set */
107       /**
108        * \}
109        */
110 
111       /**
112        * \name Current value of rupees, hearts and others
113        * \{
114        */
115       CURRENT_LIFE                      = 10,  /**< current level of life */
116       CURRENT_MONEY                     = 11,  /**< current amount of money */
117       CURRENT_MAGIC                     = 12,  /**< current level of magic */
118       /**
119        * \}
120        */
121 
122       /**
123        * \name Maximum values
124        * \{
125        */
126       MAX_LIFE                          = 20,  /**< maximum level of life */
127       MAX_MONEY                         = 21,  /**< maximum amount of money */
128       MAX_MAGIC                         = 22,  /**< maximum level of magic */
129       /**
130        * \}
131        */
132 
133       /**
134        * \name Keyboard customizable keys.
135        *
136        * Variables 35 to 49 indicate the keyboard key
137        * associated to each game key: action, sword, item 1, item 2, pause,
138        * right, up, left and down.
139        * Each integer corresponds to a value of the InputEvent::KeyboardKey
140        * enumeration.
141        * \{
142        */
143       KEYBOARD_ACTION_KEY               = 35,
144       KEYBOARD_SWORD_KEY                = 36,
145       KEYBOARD_ITEM_1_KEY               = 37,
146       KEYBOARD_ITEM_2_KEY               = 38,
147       KEYBOARD_PAUSE_KEY                = 39,
148       KEYBOARD_RIGHT_KEY                = 40,
149       KEYBOARD_UP_KEY                   = 41,
150       KEYBOARD_LEFT_KEY                 = 42,
151       KEYBOARD_DOWN_KEY                 = 43,
152       KEYBOARD_ENUM_VERSION             = 49,  /**< Indicates the version of the Input::KeyboardKey enumeration this savegame was created with.
153                                                 * If the version saved is different from Input::KEYBOARD_ENUM_VERSION, then
154                                                 * we know it is obsolete and the customization is reset to some default values. */
155       /**
156        * \}
157        */
158 
159       /**
160        * \name General abilities.
161        * \{
162        */
163       ABILITY_TUNIC                         = 50,
164       ABILITY_SWORD                         = 51,
165       ABILITY_SHIELD                        = 52,
166       ABILITY_LIFT                          = 53,
167       ABILITY_SWIM                          = 54,
168       ABILITY_SWORD_KNOWLEDGE               = 55,
169       ABILITY_DETECT_WEAK_WALLS             = 56,
170       ABILITY_SEE_OUTSIDE_WORLD_MINIMAP     = 57,
171       ABILITY_GET_BACK_FROM_DEATH           = 58,
172       ABILITY_RUN                           = 59,
173       /**
174        * \}
175        */
176 
177       /**
178        * \name Dungeon-specific abilities and information.
179        * Up to 40 dungeons can be saved.
180        */
181       DUNGEON_1_FINISHED                        = 200,
182       DUNGEON_1_ABILITY_SEE_MINIMAP_ROOMS       = 201,
183       DUNGEON_1_ABILITY_SEE_MINIMAP_ELEMENTS    = 202,
184       DUNGEON_1_ABILITY_OPEN_BIG_LOCKS          = 203,
185       DUNGEON_1_ABILITY_OPEN_BOSS_LOCKS         = 204,
186       DUNGEON_1_SMALL_KEYS                      = 205,  /**< small key counter in dungeon #1 */
187       DUNGEON_1_UNUSED_1                        = 206,  /**< empty place for future new data in dungeon #1 */
188       DUNGEON_1_UNUSED_2                        = 207,  /**< empty place for future new data in dungeon #1 */
189       DUNGEON_1_UNUSED_3                        = 208,  /**< empty place for future new data in dungeon #1 */
190       DUNGEON_1_UNUSED_4                        = 209,  /**< empty place for future new data in dungeon #1 */
191       // then, same thing for other dungeons
192       DUNGEON_40_UNUSED_4                       = 599,  /**< empty place for future new data in dungeon #40 */
193 
194 
195       SAVEGAME_COMPATIBILITY_FORMAT             = 1023  /**< Indicates the version of the savegame format this savegame was created with.
196                                                          * If the version saved is different from COMPATIBILITY_FORMAT, then
197                                                          * we know it is obsolete (not compatible anymore) and the savegame is destroyed. */
198 
199       // values above 1024 are available to the quest
200     };
201 
202   private:
203 
204     /**
205      * \brief Contains the data saved.
206      *
207      * This structure contains the data saved (16 Ko of data are stored).
208      * The system can save some strings, integers and boolean values.
209      * Some strings and integers are reserved to the engine.
210      * See StringIndex and IntegerIndex for the meaning of each string and
211      * integer defined by the engine.
212      */
213     struct SavedData {
214       char strings[64][64];     /**< 64 nullptr-terminated strings of 64 bytes each (4 Ko) */
215       uint32_t integers[2048];  /**< 2048 integers (8 Ko) */
216       uint32_t booleans[1024];  /**< 32768 boolean values (4 Ko) */
217     };
218 
219     SavedData saved_data;
220 
221 };
222 
223 }
224 
225 #endif
226 
227