1 /***************************************************************************
2                        persist.h  -  Savegame objects
3                              -------------------
4     begin                : Sat May 3 2003
5     copyright            : (C) 2003 by Gabor Torok
6     email                : cctorok@yahoo.com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17 
18 #ifndef PERSIST_H
19 #define PERSIST_H
20 #pragma once
21 
22 #include "rpg/rpg.h"
23 
24 class File;
25 
26 #define PERSIST_VERSION 41
27 
28 #define OLDEST_HANDLED_VERSION 15
29 
30 // -=K=- since this header declares classes it is  C++ header
31 // C++ does "typedef struct StructName StructName;" implicitly
32 
33 /// Dice info for savegame.
34 struct DiceInfo {
35 	Uint32 version;
36 	Uint32 count, sides, mod;
37 };
38 
39 /// Item info for savegame.
40 struct ItemInfo {
41 	Uint32 version;
42 	Uint32 level;
43 	Uint8 rpgItem_name[255];
44 	Uint8 shape_name[255];
45 	Uint32 blocking, currentCharges, weight;
46 	Uint32 quality;
47 	Uint32 price;
48 	Uint32 identifiedBits;
49 	Uint8 spell_name[255];
50 	Uint32 containedItemCount;
51 	ItemInfo *containedItems[MAX_CONTAINED_ITEMS];
52 
53 	Uint32 bonus, damageMultiplier, cursed, magicLevel;
54 	Uint8 monster_type[255];
55 	Uint8 magic_school_name[255];
56 	DiceInfo *magicDamage;
57 	Uint8 stateMod[StateMod::STATE_MOD_COUNT];
58 	Uint8 skillBonus[Skill::SKILL_COUNT];
59 	Uint32 missionId;
60 	Uint32 missionObjectiveIndex;
61 
62 };
63 
64 /// NPC info for savegame.
65 struct NpcInfoInfo {
66 	Uint32 version;
67 	Uint32 x, y, level, type;
68 	Uint8 name[255];
69 	Uint8 subtype[255];
70 };
71 
72 /// Creature info for savegame.
73 struct CreatureInfo {
74 	Uint32 version;
75 	Uint8 name[255];
76 	Uint8 character_name[255];
77 	Uint32 character_model_info_index;
78 	Uint32 deityIndex;
79 	Uint8 monster_name[255];
80 	Uint32 hp, mp, exp, level, money, stateMod, protStateMod, x, y, z, dir;
81 	Uint32 speed, motion, armor, bonusArmor, thirst, hunger;
82 	Uint8 sex;
83 	Uint32 availableSkillPoints;
84 	Uint32 skills[Skill::SKILL_COUNT];
85 	Uint32 skillMod[Skill::SKILL_COUNT];
86 	Uint32 skillBonus[Skill::SKILL_COUNT];
87 	Uint32 skillsUsed[Skill::SKILL_COUNT];
88 	Uint32 portraitTextureIndex;
89 
90 	// backpack
91 	Uint32 backpack_count;
92 	ItemInfo *backpack[MAX_BACKPACK_SIZE];
93 	//ContainedItemInfo containedItems[MAX_BACKPACK_SIZE];
94   Uint32 equipped[Constants::EQUIP_LOCATION_COUNT];
95 
96 	// spells memorized ([school][spell]
97 	Uint32 spell_count;
98 	Uint8 spell_name[100][255];
99 	Uint8 quick_spell[12][255];
100 
101 	Uint8 boss;
102 	Uint8 mission;
103 	NpcInfoInfo *npcInfo;
104 };
105 
106 /// Level map location info for savegame.
107 struct LocationInfo {
108 	Uint16 x, y, z;
109 	Uint8 floor_shape_name[255];
110 	Uint8 shape_name[255];
111 	Uint8 item_name[255];
112 	ItemInfo *item;
113 	Uint8 monster_name[255];
114 	CreatureInfo *creature;
115 	Uint8 item_pos_name[255];
116 	ItemInfo *item_pos;
117 	Uint8 magic_school_name[255]; // the deity at this location
118 };
119 
120 /// Rug info for savegame.
121 struct RugInfo {
122 	Uint32 texture;
123 	Uint8 isHorizontal;
124 	Uint32 angle;
125 	Uint16 cx, cy;
126 };
127 
128 /// "Object locked" status for savegame.
129 struct LockedInfo {
130 	Uint32 key;
131 	Uint8 value;
132 };
133 
134 /// Door info for savegame.
135 struct DoorInfo {
136 	Uint32 key;
137 	Uint32 value;
138 };
139 
140 /// Fog info for savegame.
141 struct FogInfo {
142 	Uint8 fog[MAP_WIDTH][MAP_DEPTH];
143 	Uint8 players[MAP_WIDTH * MAP_DEPTH][4];
144 };
145 
146 #define REF_TYPE_NAME 0
147 #define REF_TYPE_OBJECT 1
148 
149 /// Trap info for savegame.
150 struct TrapInfo {
151 	Uint32 version;
152 	Uint16 x, y, w, h;
153 	Uint8 type, discovered, enabled;
154 };
155 
156 /// Info on the ground texturing at an outdoor map position.
157 struct OutdoorTextureInfo {
158 	Uint16 x, y;
159 	Uint32 offsetX, offsetY; // measured in map units
160 	Uint32 angle;
161 	Uint8 horizFlip, vertFlip;
162 	Uint16 outdoorThemeRef;
163 	Uint8 z;
164 };
165 
166 /// Level map info for savegame.
167 struct MapInfo {
168 	Uint32 version;
169 	Uint8 map_type;
170 	Uint16 start_x, start_y;
171 	Uint16 grid_x, grid_y;
172 	Uint32 pos_count;
173 	Uint8 theme_name[255];
174 	Uint8 reference_type;
175 	LocationInfo *pos[ MAP_WIDTH * MAP_DEPTH * MAP_VIEW_HEIGHT ];
176 	Uint32 rug_count;
177 	RugInfo *rugPos[ ( MAP_CHUNKS_X ) * ( MAP_CHUNKS_Y ) ];
178 	Uint8 hasWater;
179 	Uint32 locked_count;
180 	LockedInfo *locked[ MAP_WIDTH * MAP_DEPTH * MAP_VIEW_HEIGHT ];
181 	Uint32 door_count;
182 	DoorInfo *door[ MAP_WIDTH * MAP_DEPTH * MAP_VIEW_HEIGHT ];
183 	Uint32 secret_count;
184 	LockedInfo *secret[ MAP_WIDTH * MAP_DEPTH ];
185 	FogInfo fog_info;
186 	Uint8 edited;
187 	Uint8 heightMapEnabled;
188 	Uint32 ground[ MAP_TILES_X ][ MAP_TILES_Y ];
189 	Uint8 trapCount;
190 	TrapInfo *trap[ 255 ];
191 	Uint32 outdoorTextureInfoCount;
192 	OutdoorTextureInfo *outdoorTexture[ ( MAP_TILES_X ) * ( MAP_TILES_Y ) ];
193 };
194 
195 /// Mission info for savegame.
196 struct MissionInfo {
197 	Uint32 version;
198 	Uint8 level;
199 	Uint8 depth;
200 	Uint8 completed;
201 	Uint8 mapName[80];
202 	Uint8 templateName[80];
203 	Uint8 itemCount;
204 	Uint8 itemName[100][255];
205 	Uint8 itemDone[100];
206 	Uint8 monsterCount;
207 	Uint8 monsterName[100][255];
208 	Uint8 monsterDone[100];
209 	Uint32 missionId;
210 };
211 
212 namespace Persist {
213 LocationInfo *createLocationInfo( Uint16 x, Uint16 y, Uint16 z );
214 RugInfo *createRugInfo( Uint16 cx, Uint16 cy );
215 TrapInfo *createTrapInfo( int x, int y, int w, int h, int type, bool discovered, bool enabled );
216 LockedInfo *createLockedInfo( Uint32 key, Uint8 value );
217 DoorInfo *createDoorInfo( Uint32 key, Uint32 value );
218 void saveMap( File *file, MapInfo *info );
219 MapInfo *loadMap( File *file );
220 void loadMapHeader( File *file, Uint16 *gridX, Uint16 *gridY );
221 void deleteMapInfo( MapInfo *info );
222 
223 void saveCreature( File *file, CreatureInfo *info );
224 CreatureInfo *loadCreature( File *file );
225 void deleteCreatureInfo( CreatureInfo *info );
226 
227 void saveMission( File *file, MissionInfo *info );
228 MissionInfo *loadMission( File *file );
229 void deleteMissionInfo( MissionInfo *info );
230 };
231 
232 
233 #endif
234