Debian Codegraph @

Descent3/gamesave.h

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 --- HISTORICAL COMMENTS FOLLOW ---
19
20 * $Logfile: /DescentIII/main/gamesave.h $
21 * $Revision: 16 $
22 * $Date: 7/21/99 7:17p $
23 * $Author: Chris $
24 *
25 *
26 *
27 * $Log: /DescentIII/main/gamesave.h $
28 *
29 * 16 7/21/99 7:17p Chris
30 * Fixed an attach related crash in the load/save game code
31 *
32 * 15 4/20/99 11:45a Samir
33 * added autosave
34 *
35 * 14 4/14/99 3:56a Jeff
36 * fixed case mismatch in #includes
37 *
38 * 13 3/22/99 5:12p Samir
39 * added snapshot to savegame.
40 *
41 * 12 3/08/99 11:04a Jason
42 * added versioning for texture changes
43 *
44 * 11 3/04/99 6:30p Jeff
45 * saves out current waypoint and matcens
46 *
47 * 10 1/29/99 12:47p Matt
48 * Rewrote the doorway system
49 *
50 * 9 1/21/99 11:15p Jeff
51 * pulled out some structs and defines from header files and moved them
52 * into seperate header files so that multiplayer dlls don't require major
53 * game headers, just those new headers. Side effect is a shorter build
54 * time. Also cleaned up some header file #includes that weren't needed.
55 * This affected polymodel.h, object.h, player.h, vecmat.h, room.h,
56 * manage.h and multi.h
57 *
58 * 8 1/08/99 2:55p Samir
59 * Ripped out OSIRIS1.
60 *
61 * 7 10/08/98 12:00p Kevin
62 * Demo system work
63 *
64 * 6 10/06/98 5:45p Kevin
65 * Added new configuration for demo
66 *
67 * 5 8/20/98 10:52a Samir
68 * fixed some ui probs
69 *
70 * 4 8/19/98 5:35p Samir
71 * saved triggers, spew, viseffects, weapons, room data xcept texture per
72 * face changes, one real strange bug where robots in the same room as you
73 * don't appear but fire at you.
74 *
75 * 3 8/18/98 3:05p Samir
76 * save game with no weapons or fireballs.
77 *
78 * 2 8/18/98 1:12a Samir
79 * rudimentary savegame. pretty damn buggy when loading.
80 *
81 * $NoKeywords: $
82 */
83
84 #ifndef GAMESAVE_H
85 #define GAMESAVE_H
86
87 #include "pstypes.h"
88 #include "cfile.h"
89 #include "object.h"
90 #include "objinfo.h"
91
92 #include "gametexture.h"
93 #include "bitmap.h"
94 #include "ddio.h"
95 #include "door.h"
96 #include "doorway.h"
97 #include "ship.h"
98 #include "weapon.h"
99 #include "polymodel.h"
100
101 #define GAMESAVE_SLOTS 8 // maximum number of savegames
102 #define GAMESAVE_DESCLEN 31 // gamesave description maximum length.
103
104 struct gs_tables {
105 int16_t model_handles[MAX_POLY_MODELS];
106 int16_t obji_indices[MAX_OBJECT_IDS];
107 int16_t bm_handles[MAX_BITMAPS];
108 int16_t tex_handles[MAX_TEXTURES];
109 int16_t door_handles[MAX_DOORS];
110 int16_t ship_handles[MAX_SHIPS];
111 int16_t wpn_handles[MAX_WEAPONS];
112 };
113
114 // savegame version info.
115 // this should be handled like level file version, as to prevent invalidating old savegames
116 // please record a table of changes here.
117
118 // 0 samir-initial version
119 // 1 Added saving/loading of changed textures
120 // 2 Added correct saving and restoring of attach points
121
122 #define GAMESAVE_VERSION 2
123 #define GAMESAVE_OLDVER 0 // any version before this value is obsolete.
124
125 void SaveGameDialog();
126 bool LoadGameDialog(); // returns true if ok, false if canceled.
127 void QuickSaveGame();
128
129 bool LoadCurrentSaveGame(); // loads savegame as specified from LoadGameDialog (false fails)
130
131 extern int Quicksave_game_slot; // externed so gamesequencing can reset this value starting new game.
132
133 // internal.
134
135 // loads a game from a given slot. returns a code below.
136 #define LGS_OK 0
137 #define LGS_FILENOTFOUND 1
138 #define LGS_OUTDATEDVER 2
139 #define LGS_STARTLVLFAILED 3 // level failed to load or startup
140 #define LGS_MISSIONFAILED 4 // mission failed to load.
141 #define LGS_OBJECTSCORRUPT 5 // object list is corrupt (or out of date with level)
142 #define LGS_CORRUPTLEVEL 6 // either level is out of date, or list is corrupted.
143
144 int LoadGameState(const char *pathname);
145
146 // Easy IO routines for repetitive tasks.
147
148 #define gs_WriteVector(_f, _v) \
149 do { \
150 cf_WriteFloat((_f), (_v).x); \
151 cf_WriteFloat((_f), (_v).y); \
152 cf_WriteFloat((_f), (_v).z); \
153 } while (0)
154 #define gs_WriteMatrix(_f, _m) \
155 do { \
156 gs_WriteVector((_f), (_m).rvec); \
157 gs_WriteVector((_f), (_m).uvec); \
158 gs_WriteVector((_f), (_m).fvec); \
159 } while (0)
160 #define gs_WriteAngle(_f, _a) cf_WriteShort(_f, (int16_t)(_a))
161 #define gs_WriteByte(_f, _b) cf_WriteByte(_f, _b)
162 #define gs_WriteShort(_f, _s) cf_WriteShort(_f, _s)
163 #define gs_WriteInt(_f, _i) cf_WriteInt(_f, _i)
164 #define gs_WriteFloat(_f, _fl) cf_WriteFloat(_f, _fl)
165 #define gs_WriteBool(_f, _b) cf_WriteByte(_f, _b)
166
167 #define START_VERIFY_SAVEFILE(f) int cur_file_pos = cftell(f)
168 #define END_VERIFY_SAVEFILE(f, s) mprintf(0, "%s =%d bytes\n", s, cftell(f) - cur_file_pos)
169
170 #define gs_ReadVector(_f, _v) \
171 do { \
172 (_v).x = cf_ReadFloat(_f); \
173 (_v).y = cf_ReadFloat(_f); \
174 (_v).z = cf_ReadFloat(_f); \
175 } while (0)
176 #define gs_ReadMatrix(_f, _m) \
177 do { \
178 gs_ReadVector((_f), (_m).rvec); \
179 gs_ReadVector((_f), (_m).uvec); \
180 gs_ReadVector((_f), (_m).fvec); \
181 } while (0)
182 #define gs_ReadAngle(_f, _a) ((_a) = (angle)cf_ReadShort(_f))
183 #define gs_ReadBool(_f, _b) ((_b) = (bool)cf_ReadByte(_f))
184 #define gs_ReadByte(_f, _b) ((_b) = cf_ReadByte(_f))
185 #define gs_ReadShort(_f, _s) ((_s) = cf_ReadShort(_f))
186 #define gs_ReadInt(_f, _i) ((_i) = cf_ReadInt(_f))
187 #define gs_ReadFloat(_f, _fl) ((_fl) = cf_ReadFloat(_f))
188
189 // writes out translation tables.
190 void SGSXlateTables(CFILE *fp);
191
192 // initializes rooms
193 void SGSRooms(CFILE *fp);
194
195 // saves out events
196 void SGSEvents(CFILE *fp);
197
198 // saves out triggers
199 void SGSTriggers(CFILE *fp);
200
201 // save viseffects
202 void SGSVisEffects(CFILE *fp);
203
204 // players
205 void SGSPlayers(CFILE *fp);
206
207 // saves out objects
208 void SGSObjects(CFILE *fp);
209
210 // saves ai
211 void SGSObjAI(CFILE *fp, const ai_frame *ai);
212
213 // saves fx
214 void SGSObjEffects(CFILE *fp, const object *op);
215
216 // saves script
217 //@@void SGSScript(CFILE *fp, const script_info *script);
218
219 // saves wb
220 void SGSObjWB(CFILE *fp, object *op, int num_wbs);
221
222 // saves special object info
223 void SGSObjSpecial(CFILE *fp, const object *op);
224
225 // load spew
226 void SGSSpew(CFILE *fp);
227
228 //@@// saves ai goals
229 //@@void SGSObjAIGoal(CFILE *fp, const goal *g);
230
231 // load matcens
232 void SGSMatcens(CFILE *fp);
233
234 // give a description and slot number (0 to GAMESAVE_SLOTS-1)
235 bool SaveGameState(const char *pathname, const char *description);
236
237 // retreive gamesave file header info. description must be a buffer of length GAMESAVE_DESCLEN+1
238 // returns true if it's a valid savegame file. false if corrupted somehow
239 // pointer to bm_handle will return a bitmap handle to the snapshot for game. (*bm_handle) can be invalid.
240 bool GetGameStateInfo(const char *pathname, char *description, int *bm_handle = NULL);
241
242 ///////////////////////////////////////////////////////////////////////////////
243 // reads in translation tables
244 int LGSXlateTables(CFILE *fp);
245
246 // loads in level's mission and level.
247 int LGSMission(const char *msnname, int level);
248
249 // initializes rooms
250 int LGSRooms(CFILE *fp);
251
252 // loads in and sets these events
253 int LGSEvents(CFILE *fp);
254
255 // loads in and sets these triggers
256 int LGSTriggers(CFILE *fp);
257
258 // players
259 int LGSPlayers(CFILE *fp);
260
261 // loads in and sets these objects
262 int LGSObjects(CFILE *fp, int version);
263
264 // load viseffects
265 int LGSVisEffects(CFILE *fp);
266
267 // load spew
268 int LGSSpew(CFILE *fp);
269
270 // loads ai
271 int LGSObjAI(CFILE *fp, ai_frame **pai);
272
273 // saves ai goals
274 int LGSObjAIGoal(CFILE *fp, goal *g);
275
276 // loads fx
277 int LGSObjEffects(CFILE *fp, object *op);
278
279 // loads weapon batter info
280 int LGSObjWB(CFILE *fp, object *op);
281
282 // loads script
283 //@@vector *LGSScript(CFILE *fp, script_info *script, uint8_t *is_scripted, int *memsize);
284
285 // loads special object info
286 int LGSObjSpecial(CFILE *fp, object *op);
287
288 // load matcens
289 int LGSMatcens(CFILE *fp);
290
291 //////////////////////////////////////////////////////////////////////////////
292 // Game Save/Load User interface
293
294 #define SAVEGAMEDLG_WIDTH (512)
295 #define SAVEGAMEDLG_HEIGHT (384)
296 #define SAVEGAMEDLG_X ((Max_window_w - SAVEGAMEDLG_WIDTH) / 2)
297 #define SAVEGAMEDLG_Y ((Max_window_h - SAVEGAMEDLG_HEIGHT) / 2)
298 #define SAVEGAMELB_WIDTH (32 * 14)
299 #define SAVEGAMELB_HEIGHT (32 * 6)
300 #define SAVEGAMELB_X ((SAVEGAMEDLG_WIDTH - SAVEGAMELB_WIDTH) / 2)
301 #define SAVEGAMELB_Y ((SAVEGAMEDLG_HEIGHT - SAVEGAMELB_HEIGHT + 32) / 2)
302 #define SAVEGAMEBTN_W 96
303 #define SAVEGAMEBTN_X ((SAVEGAMEDLG_WIDTH / 4) - (SAVEGAMEBTN_W / 2))
304 #define SAVEGAMEBTN_X2 ((3 * SAVEGAMEDLG_WIDTH / 4) - (SAVEGAMEBTN_W / 2))
305 #define SAVEGAMEBTN_Y (SAVEGAMEDLG_HEIGHT - 64)
306
307 #define UID_SAVELB 100
308 #define UID_LOADLB 100
309
310 #endif