Debian Codegraph @

Descent3/loadstate.cpp

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/loadstate.cpp $
21 * $Revision: 74 $
22 * $Date: 9/05/01 12:19p $
23 * $Author: Matt $
24 *
25 * Load a saved game
26 *
27 * $Log: /DescentIII/Main/loadstate.cpp $
28 *
29 * 74 9/05/01 12:19p Matt
30 * When loading a saved game, load the add-on data before the level so the
31 * textures get mapped properly.
32 *
33 * 73 4/21/00 3:23p Matt
34 * Check for bad vis effect structure on load, which probably means a game
35 * saved with a prior to version 1.3. If found, convert old struct to new
36 * struct.
37 *
38 * 72 4/19/00 5:07p Matt
39 * From Duane for 1.4
40 * Added checks, asserts, and fixes for bad return values
41 *
42 * 71 4/07/00 5:51p Matt
43 * Do id translation on dummy objects that are really generics, etc.
44 *
45 * 70 3/20/00 12:13p Matt
46 * Merge of Duane's post-1.3 changes.
47 * Fixed mem leak.
48 * Added check for object type.
49 *
50 * 69 9/18/99 9:23p Jeff
51 * re initialize objects' position history (for motion blur)
52 *
53 * 68 7/22/99 11:47a Chris
54 *
55 * 67 7/21/99 7:17p Chris
56 * Fixed an attach related crash in the load/save game code
57 *
58 * 66 7/08/99 10:30a Kevin
59 * when loading a save game >level 4 from a minimal install, don't ask for
60 * CD1
61 *
62 * 65 5/21/99 11:15p Samir
63 * savegames save hud timer and special text states. restore too.
64 *
65 * 64 5/20/99 2:48a Matt
66 * Auto-waypoints now stored & used per player. Manual waypoints will all
67 * players, once Jason makes it work.
68 *
69 * 63 5/17/99 10:38a Samir
70 * reset player ship and reset camera views before starting new level. may
71 * fix some sequencing problems with ship reticle and inventory too.
72 *
73 * 62 5/12/99 6:02p Jeff
74 * flip order of saving/loading objects and players
75 *
76 * 61 5/12/99 12:25p Kevin
77 * save & restore Current_mission.game_state_flags
78 *
79 * 60 5/12/99 11:40a Matt
80 * Changed some arrays to be malloc'd instead of declared locally on the
81 * stack, because the Mac limits local data to 32K.
82 *
83 * 59 5/10/99 10:22p Ardussi
84 * changes to compile on Mac
85 *
86 * 58 5/06/99 6:11p Kevin
87 * fixes for save/load game syste. Also require CD again and added some
88 * heat.net stuff
89 *
90 * 57 4/30/99 3:03p Kevin
91 * improved times restored count
92 *
93 * 56 4/29/99 11:25a Kevin
94 * Added room damage to save game
95 *
96 * 55 4/28/99 2:14a Samir
97 * save and load Game messages in savegame.
98 *
99 * 54 4/23/99 10:23p Kevin
100 * Fixed savegame doorways bug!
101 *
102 * 53 4/23/99 8:28p Kevin
103 * trying to get doors working in save/load games
104 *
105 * 52 4/23/99 7:33p Kevin
106 * save weather effects and reset the HUD to show the correct ship
107 *
108 * 51 4/23/99 4:50p Jeff
109 * fixed page in polymodel problem
110 *
111 * 50 4/22/99 4:13p Matt
112 * Deleted sounds array from the object struct, since it was never used.
113 *
114 * 49 4/16/99 12:33a Matt
115 * Disable Soar on non-Windows systems.
116 *
117 * 48 4/15/99 5:41p Samir
118 * save current music region and restore it.
119 *
120 * 47 4/15/99 1:40a Jeff
121 * changes for linux compile
122 *
123 * 46 4/14/99 2:51a Jeff
124 * fixed some case mismatched #includes
125 *
126 * 45 4/05/99 10:54a Matt
127 * Added auto-waypoint system
128 *
129 * 44 3/23/99 6:09p Kevin
130 * Marker text saved
131 *
132 * 43 3/23/99 12:33p Kevin
133 * More post level results improvements
134 *
135 * 42 3/22/99 5:12p Samir
136 * added snapshot to savegame.
137 *
138 * 41 3/11/99 9:09p Jeff
139 * fixed remaining known bugs in demo system (DemoWriteObjCreate being
140 * called twice and </<= problems with
141 * Highest_room_index/Highest_object_index).
142 *
143 * 40 3/10/99 6:20p Jeff
144 * many fixes to demo system. Fixed IGC so cameras move...fixed osiris to
145 * be restored correctly, and it handles errors on restore
146 *
147 * 39 3/10/99 2:25p Kevin
148 * Save/Load and Demo file fixes
149 *
150 * 38 3/08/99 11:05a Jason
151 * added saving/loading of texture changes
152 *
153 * 37 3/04/99 6:58p Jeff
154 * fixed microwave assert
155 *
156 * 36 3/04/99 6:30p Jeff
157 * saves out current waypoint and matcens
158 *
159 * 35 3/03/99 7:20p Jeff
160 * save/restore some ai path information
161 *
162 * 34 3/02/99 6:39p Jeff
163 * level goals working in save/load game
164 *
165 * 33 3/02/99 4:42p Jeff
166 * Fixed inventory save/load
167 *
168 * 32 3/02/99 1:48p Kevin
169 * Fixed collision with external rooms
170 *
171 * 31 3/01/99 9:03p Kevin
172 * OEM Beta 4
173 *
174 * 30 3/01/99 11:41a Kevin
175 * More progress...
176 *
177 * 29 2/28/99 10:50p Kevin
178 *
179 * $NoKeywords: $
180 */
181
182 #include "gamesave.h"
183 #include "descent.h"
184 #include "cfile.h"
185 #include "Mission.h"
186 #include "gamesequence.h"
187 #include "gameevent.h"
188 #include "gameloop.h"
189 #include "game.h"
190 #include "object.h"
191 #include "objinfo.h"
192 #include "gametexture.h"
193 #include "bitmap.h"
194 #include "ship.h"
195 #include "door.h"
196 #include "stringtable.h"
197 #include "soar.h"
198 #include "weapon.h"
199 #include "vclip.h"
200 #include "viseffect.h"
201 #include "room.h"
202 #include "trigger.h"
203 #include "spew.h"
204 #include "doorway.h"
205 #include "AIMain.h"
206 #include "mem.h"
207 #include "osiris_dll.h"
208 #include "terrain.h"
209 #include <string.h>
210 #include "levelgoal.h"
211 #include "aistruct.h"
212 #include "matcen.h"
213 #include "pilot.h"
214 #include "marker.h"
215 #include "d3music.h"
216 #include "weather.h"
217 #include "cockpit.h"
218 #include "hud.h"
219
220 #include <algorithm>
221
222 extern void PageInAllData();
223
224 // dynamically allocated to be efficient (only needed during save/load)
225
226 static int LGSSnapshot(CFILE *fp);
227 static void IncreaseRestoreCount(const char *file);
228
229 int Times_game_restored = 0;
230 // static gs_tables *gs_Xlates = NULL;
231
232 gs_tables *gs_Xlates = NULL;
233 // int Gamesave_read_version=0;
234
235 void IncreaseRestoreCount(const char *file) {
236 // Open the file up in read more, read the current count, then incease it
237 // and write the increased value back out.
238
239 char countpath[_MAX_PATH * 2];
240 CFILE *cfp;
241
242 strcpy(countpath, file);
243 strcat(countpath, ".cnt");
244
245 cfp = cfopen(countpath, "rb");
246 if (cfp) {
247 Times_game_restored = cf_ReadInt(cfp);
248 cfclose(cfp);
249 } else {
250 Times_game_restored = 0;
251 }
252 Times_game_restored++;
253
254 cfp = cfopen(countpath, "wb");
255 if (cfp) {
256 cf_WriteInt(cfp, Times_game_restored);
257 cfclose(cfp);
258 }
259 }
260
261 extern bool IsRestoredGame;
262 ///////////////////////////////////////////////////////////////////////////////
263 // loads a game from a given slot.
264 int LoadGameState(const char *pathname) {
265 CFILE *fp;
266 int retval = LGS_OK;
267 char desc[GAMESAVE_DESCLEN + 1];
268 char path[_MAX_PATH];
269 uint16_t version;
270 uint16_t curlevel;
271 int16_t pending_music_region;
272 IsRestoredGame = true;
273 // load in stuff
274 fp = cfopen(pathname, "rb");
275 if (!fp) {
276 Int3();
277 return LGS_FILENOTFOUND;
278 }
279
280 START_VERIFY_SAVEFILE(fp);
281 gs_Xlates = new gs_tables;
282
283 // read in header and do version check.
284 cf_ReadBytes((uint8_t *)desc, sizeof(desc), fp);
285 version = (uint16_t)cf_ReadShort(fp);
286 if (version < GAMESAVE_OLDVER) {
287 Int3();
288 retval = LGS_OUTDATEDVER;
289 goto loadsg_error;
290 }
291
292 retval = LGSSnapshot(fp); // read and clear snapshot.
293 if (retval > 0) {
294 bm_FreeBitmap(retval);
295 }
296
297 // Gamesave_read_version=version;
298
299 // read translation tables
300 retval = LGSXlateTables(fp);
301 if (retval != LGS_OK)
302 goto loadsg_error;
303 // read in gamemode info.
304
305 // read in mission level info.
306 curlevel = (uint16_t)cf_ReadShort(fp);
307 cf_ReadString(path, sizeof(path), fp);
308
309 if ((curlevel > 4) && (stricmp(path, "d3.mn3") == 0)) {
310 strcpy(path, "d3_2.mn3");
311 }
312
313 // must load mission and initialize level before reading in other data.
314 retval = LGSMission(path, curlevel);
315 if (retval != LGS_OK)
316 goto loadsg_error;
317
318 Current_mission.game_state_flags = cf_ReadInt(fp);
319 // Increase count for how many times this file was restored
320 IncreaseRestoreCount(pathname);
321
322 // read in information after level's been loaded.
323 Gametime = cf_ReadFloat(fp);
324 FrameCount = cf_ReadInt(fp);
325 Current_waypoint = cf_ReadInt(fp);
326 pending_music_region = cf_ReadShort(fp);
327 D3MusicSetRegion(pending_music_region);
328
329 // Times_game_restored = cf_ReadInt(fp);
330 // Read Weather
331 {
332 int weather_size = cf_ReadInt(fp);
333 if (weather_size != sizeof(Weather)) {
334 Int3();
335 retval = LGS_OUTDATEDVER;
336 goto loadsg_error;
337 }
338 }
339 cf_ReadBytes((uint8_t *)&Weather, sizeof(Weather), fp);
340
341 // Restore active doorways
342 {
343 int num_active_dw = cf_ReadInt(fp);
344 Num_active_doorways = cf_ReadInt(fp);
345
346 for (int d = 0; d < num_active_dw; d++) {
347 Active_doorways[d] = cf_ReadInt(fp);
348 }
349 }
350
351 // read in room info
352 retval = LGSRooms(fp);
353 if (retval != LGS_OK)
354 goto loadsg_error;
355
356 // read in trigger info
357 retval = LGSTriggers(fp);
358 if (retval != LGS_OK)
359 goto loadsg_error;
360
361 // read in object info.
362 retval = LGSObjects(fp, version);
363 if (retval != LGS_OK)
364 goto loadsg_error;
365
366 // read in players info
367 retval = LGSPlayers(fp);
368 if (retval != LGS_OK)
369 goto loadsg_error;
370
371 // read in matcen info.
372 retval = LGSMatcens(fp);
373 if (retval != LGS_OK)
374 goto loadsg_error;
375
376 // read in viseffecsts
377 retval = LGSVisEffects(fp);
378 if (retval != LGS_OK)
379 goto loadsg_error;
380
381 // read in spew
382 retval = LGSSpew(fp);
383 if (retval != LGS_OK)
384 goto loadsg_error;
385
386 // Load OSIRIS Stuff
387 if (!Osiris_RestoreSystemState(fp)) {
388 goto loadsg_error;
389 }
390
391 // Load Level goal info
392 Level_goals.LoadLevelGoalInfo(fp);
393
394 // read in game messages for console. (must occur AFTER players are read in!!!)
395 LGSGameMessages(fp);
396
397 // loads and restores hud state.
398 if (!LGSHudState(fp)) {
399 retval = LGS_OBJECTSCORRUPT;
400 goto loadsg_error;
401 }
402
403 loadsg_error:
404 delete gs_Xlates;
405
406 END_VERIFY_SAVEFILE(fp, "Total load");
407 cfclose(fp);
408
409 // Page everything in here!
410 PageInAllData();
411
412 IncrementPilotRestoredGamesForMission(&Current_pilot, Current_mission.name);
413
414 return retval;
415 }
416
417 // retreive gamesave file header info. description must be a buffer of length GAMESAVE_DESCLEN+1
418 // returns true if it's a valid savegame file. false if corrupted somehow
419 bool GetGameStateInfo(const char *pathname, char *description, int *bm_handle) {
420 CFILE *fp;
421 int bitmap;
422 char desc[GAMESAVE_DESCLEN + 1];
423
424 fp = cfopen(pathname, "rb");
425 if (!fp)
426 return false;
427
428 if (!cf_ReadBytes((uint8_t *)desc, GAMESAVE_DESCLEN + 1, fp)) {
429 strcpy(description, TXT_ILLEGALSAVEGAME);
430 goto savesg_error;
431 }
432
433 strcpy(description, desc);
434
435 if (bm_handle) {
436 cf_ReadShort(fp); // skip version.
437 bitmap = LGSSnapshot(fp);
438 *bm_handle = bitmap;
439 }
440
441 cfclose(fp);
442 return true;
443
444 savesg_error:
445 cfclose(fp);
446 return false;
447 }
448
449 //////////////////////////////////////////////////////////////////////////////
450 #define BUILD_XLATE_TABLE(_table, _maxtable, _fn) \
451 do { \
452 gs_ReadShort(fp, num); \
453 for (i = 0; i < num; i++) { \
454 cf_ReadString(name, sizeof(name), fp); \
455 index = _fn(name); \
456 _table[i] = (index == -1) ? 0 : index; \
457 } \
458 for (; i < _maxtable; i++) \
459 _table[i] = 0; \
460 } while (0)
461
462 #define BUILD_MINI_XLATE_TABLE(_table, _fn) \
463 memset(_table, 0, sizeof(_table)); \
464 do { \
465 gs_ReadShort(fp, i); \
466 cf_ReadString(name, sizeof(name), fp); \
467 if (i == -1 && name[0] == 0) \
468 break; \
469 index = _fn(name); \
470 _table[i] = (index == -1) ? 0 : index; \
471 } while (1)
472
473 // reads in translation tables
474 int LGSXlateTables(CFILE *fp) {
475 START_VERIFY_SAVEFILE(fp);
476 int retval = LGS_OK;
477 int16_t i, num, index;
478 char name[64];
479
480 // load object info translation table
481 BUILD_XLATE_TABLE(gs_Xlates->obji_indices, MAX_OBJECT_IDS, FindObjectIDName);
482
483 // load polymodel translation list.
484 BUILD_XLATE_TABLE(gs_Xlates->model_handles, MAX_POLY_MODELS, FindPolyModelName);
485
486 // load doar translation list.
487 BUILD_XLATE_TABLE(gs_Xlates->door_handles, MAX_DOORS, FindDoorName);
488
489 // load ship translation list.
490 BUILD_XLATE_TABLE(gs_Xlates->ship_handles, MAX_SHIPS, FindShipName);
491
492 // build weapon translation list
493 BUILD_XLATE_TABLE(gs_Xlates->wpn_handles, MAX_WEAPONS, FindWeaponName);
494
495 // read in limited texture name list.
496 BUILD_XLATE_TABLE(gs_Xlates->tex_handles, MAX_TEXTURES, FindTextureName);
497
498 // read in limited bitmap name list. this is a slightly diff format than above to save space
499 BUILD_MINI_XLATE_TABLE(gs_Xlates->bm_handles, bm_FindBitmapName);
500
501 END_VERIFY_SAVEFILE(fp, "Xlate load");
502 return retval;
503 }
504
505 // loads in level's mission and level.
506 int LGSMission(const char *msnname, int level) {
507 // we will free the mission.
508 // Free any game objects/etc that needs to be done when ending a level here.
509 FreeScriptsForLevel();
510
511 Osiris_DisableCreateEvents();
512 if (LoadMission((const char *)msnname)) {
513 SetCurrentLevel(level);
514 Player_num = 0; // Reset player num
515 Players[Player_num].ship_index = FindShipName(DEFAULT_SHIP);
516 ASSERT(Players[Player_num].ship_index != -1);
517
518 // Load any addon data
519 mng_LoadAddonPages();
520
521 InitPlayerNewShip(Player_num, INVRESET_ALL);
522 InitCameraViews(1); // Turn off all camera views, including rear views
523
524 if (!LoadAndStartCurrentLevel()) {
525 Int3();
526 Osiris_EnableCreateEvents();
527 return LGS_STARTLVLFAILED;
528 }
529 } else {
530 Int3();
531 Osiris_EnableCreateEvents();
532 return LGS_MISSIONFAILED;
533 }
534 Osiris_EnableCreateEvents();
535 // mng_LoadAddonPages ();
536 return LGS_OK;
537 }
538
539 extern uint8_t AutomapVisMap[MAX_ROOMS];
540
541 // initializes rooms
542 int LGSRooms(CFILE *fp) {
543 int retval = LGS_OK;
544 int16_t i, p, highest_index;
545
546 gs_ReadShort(fp, highest_index);
547 if (highest_index != (int16_t)Highest_room_index) {
548 Int3();
549 return LGS_CORRUPTLEVEL;
550 }
551
552 int16_t num_rooms;
553 gs_ReadShort(fp, num_rooms);
554
555 for (i = 0; i < num_rooms; i++) {
556 gs_ReadByte(fp, AutomapVisMap[i]);
557 }
558
559 for (i = 0; i <= highest_index; i++) {
560 uint8_t used;
561 gs_ReadByte(fp, used);
562 if (used) {
563 // reset lists
564 Rooms[i].objects = -1;
565 Rooms[i].vis_effects = -1;
566
567 // we need to save some room info out.
568 gs_ReadInt(fp, Rooms[i].flags);
569 gs_ReadByte(fp, Rooms[i].pulse_time);
570 gs_ReadByte(fp, Rooms[i].pulse_offset);
571 gs_ReadVector(fp, Rooms[i].wind);
572 gs_ReadFloat(fp, Rooms[i].last_render_time);
573 gs_ReadFloat(fp, Rooms[i].fog_depth);
574 gs_ReadFloat(fp, Rooms[i].fog_r);
575 gs_ReadFloat(fp, Rooms[i].fog_g);
576 gs_ReadFloat(fp, Rooms[i].fog_b);
577 gs_ReadFloat(fp, Rooms[i].damage);
578 // gs_ReadInt(fp, Rooms[i].objects);
579 //?? gs_WriteFloat(fp, Rooms[i].ambient_sound); // need to save an index of sounds.
580
581 // Find out about texture changes
582 // if (Gamesave_read_version>=1)
583 //{
584 int num_changed = cf_ReadShort(fp);
585
586 for (int t = 0; t < num_changed; t++) {
587 int facenum = cf_ReadShort(fp);
588 Rooms[i].faces[facenum].tmap = gs_Xlates->tex_handles[cf_ReadShort(fp)];
589 Rooms[i].faces[facenum].flags |= FF_TEXTURE_CHANGED;
590 }
591 //}
592 for (p = 0; p < Rooms[i].num_portals; p++) {
593 gs_ReadInt(fp, Rooms[i].portals[p].flags);
594 }
595
596 // load doorway info
597 if (Rooms[i].flags & RF_DOOR) {
598 doorway *dp = Rooms[i].doorway_data;
599 ASSERT(dp != NULL);
600 gs_ReadByte(fp, dp->state);
601 gs_ReadByte(fp, dp->flags);
602 gs_ReadByte(fp, dp->keys_needed);
603 gs_ReadFloat(fp, dp->position);
604 gs_ReadFloat(fp, dp->dest_pos);
605 gs_ReadInt(fp, dp->sound_handle);
606 gs_ReadInt(fp, dp->activenum);
607 gs_ReadInt(fp, dp->doornum);
608 }
609 }
610 }
611
612 // Rebuild the active doorway list
613 // DoorwayRebuildActiveList();
614
615 return retval;
616 }
617
618 // TODO: MTS: unused?
619 // loads in and sets these events
620 int LGSEvents(CFILE *fp) {
621 int retval = LGS_OK;
622
623 // clear events
624 ClearAllEvents();
625
626 return retval;
627 }
628
629 // loads in and sets these triggers
630 int LGSTriggers(CFILE *fp) {
631 int16_t i, n_trigs = 0;
632
633 gs_ReadShort(fp, n_trigs);
634 if (n_trigs != (int16_t)Num_triggers) {
635 Int3();
636 return LGS_CORRUPTLEVEL;
637 }
638
639 for (i = 0; i < n_trigs; i++) {
640
641 // must free current trigger script if there's one allocated.
642 FreeTriggerScript(&Triggers[i]);
643
644 gs_ReadShort(fp, Triggers[i].flags);
645 gs_ReadShort(fp, Triggers[i].activator);
646
647 // read script info
648 //@@ script_info script;
649 //@@
650 //@@ scrmem = LGSScript(fp, &script, &is_scripted, &scrmemsize);
651 //@@ if (is_scripted) {
652 //@@ ReinitTriggerScripts(&Triggers[i], &script, scrmemsize, scrmem);
653 //@@ }
654 //@@ if (scrmem)
655 //@@ delete[] scrmem;
656 //@@ script.set_name(NULL);
657 //@@ script.set_parms(0, NULL);
658 }
659
660 return LGS_OK;
661 }
662
663 struct old_vis_attach_info {
664 int obj_handle, dest_objhandle;
665 uint8_t subnum, subnum2;
666
667 uint16_t modelnum;
668 uint16_t vertnum, end_vertnum;
669 };
670
671 struct old_vis_effect {
672 uint8_t type;
673 uint8_t id;
674
675 vector pos;
676
677 vector velocity;
678 float mass;
679 float drag;
680 float size;
681 float lifeleft;
682 float lifetime;
683 float creation_time;
684
685 int roomnum;
686 uint16_t flags;
687 int phys_flags;
688 uint8_t movement_type;
689 int16_t custom_handle;
690 uint16_t lighting_color;
691
692 vis_attach_info attach_info;
693 axis_billboard_info billboard_info;
694
695 vector end_pos;
696
697 int16_t next;
698 int16_t prev;
699 };
700
701 void CopyVisStruct(vis_effect *vis, old_vis_effect *old_vis) {
702 // Copy fields over
703 vis->type = old_vis->type;
704 vis->id = old_vis->id;
705 vis->pos = old_vis->pos;
706
707 vis->velocity = old_vis->velocity;
708 vis->mass = old_vis->mass;
709 vis->drag = old_vis->drag;
710 vis->size = old_vis->size;
711 vis->lifeleft = old_vis->lifeleft;
712 vis->lifetime = old_vis->lifetime;
713 vis->creation_time = old_vis->creation_time;
714
715 vis->roomnum = old_vis->roomnum;
716 vis->flags = old_vis->flags;
717 vis->phys_flags = old_vis->phys_flags;
718 vis->movement_type = old_vis->movement_type;
719 vis->custom_handle = old_vis->custom_handle;
720 vis->lighting_color = old_vis->lighting_color;
721
722 vis->attach_info.obj_handle = old_vis->attach_info.obj_handle;
723 vis->attach_info.dest_objhandle = old_vis->attach_info.dest_objhandle;
724 vis->attach_info.subnum = old_vis->attach_info.subnum;
725 vis->attach_info.subnum2 = old_vis->attach_info.subnum2;
726 vis->attach_info.modelnum = old_vis->attach_info.modelnum;
727 vis->attach_info.vertnum = old_vis->attach_info.vertnum;
728 vis->attach_info.end_vertnum = old_vis->attach_info.end_vertnum;
729
730 vis->billboard_info = old_vis->billboard_info;
731 vis->end_pos = old_vis->end_pos;
732 }
733
734 // save viseffects
735 int LGSVisEffects(CFILE *fp) {
736 int16_t i, count = 0;
737
738 gs_ReadShort(fp, count);
739
740 // reassemble viseffect list.
741 for (i = 0; i < count; i++) {
742 int roomnum, v;
743 vis_effect vis;
744
745 cf_ReadBytes((uint8_t *)&vis, sizeof(vis_effect), fp);
746 roomnum = vis.roomnum;
747
748 // Check for old struct, and if found, fix it
749 if ((vis.type != VIS_FIREBALL) || (roomnum == -1) ||
750 (!ROOMNUM_OUTSIDE(roomnum) && ((roomnum > Highest_room_index) || !Rooms[roomnum].used)) ||
751 ((ROOMNUM_OUTSIDE(roomnum) && (CELLNUM(roomnum) > 65535)))) {
752 old_vis_effect old_vis;
753
754 // Copy new into old
755 memcpy((uint8_t *)&old_vis, (uint8_t *)&vis, sizeof(vis_effect));
756
757 // Read extra data from old
758 cf_ReadBytes(((uint8_t *)&old_vis) + sizeof(vis_effect), sizeof(old_vis_effect) - sizeof(vis_effect), fp);
759
760 // Copy from old to new struct
761 CopyVisStruct(&vis, &old_vis);
762
763 // Reset new room number
764 roomnum = vis.roomnum;
765 }
766
767 vis.roomnum = vis.prev = vis.next = -1;
768 v = VisEffectAllocate();
769 if (v >= 0) { // DAJ -1FIX
770 memcpy(&VisEffects[v], &vis, sizeof(vis_effect));
771 VisEffectLink(v, roomnum);
772 }
773 }
774
775 return LGS_OK;
776 }
777
778 // players
779 int LGSPlayers(CFILE *fp) {
780 player *plr = &Players[0];
781 int16_t size;
782
783 // must do this if we read player struct as whole.
784 plr->inventory.Reset(false, INVRESET_ALL);
785 plr->counter_measures.Reset(false, INVRESET_ALL);
786
787 gs_ReadShort(fp, size);
788 if (size != sizeof(player)) {
789 Int3();
790 return LGS_OUTDATEDVER;
791 } else {
792 int guided_handle;
793 cf_ReadBytes((uint8_t *)plr, sizeof(player), fp);
794 if (plr->guided_obj) {
795 gs_ReadInt(fp, guided_handle);
796 plr->guided_obj = &Objects[guided_handle & HANDLE_OBJNUM_MASK];
797 }
798 // save inventory and countermeasures
799 // must do this if we read player struct as whole.
800 plr->inventory.ReadInventory(fp);
801 plr->counter_measures.ReadInventory(fp);
802 }
803
804 int ship_index = Players[Player_num].ship_index;
805
806 if (ship_index < 0)
807 ship_index = 0;
808
809 FreeCockpit();
810 CloseShipHUD();
811 InitShipHUD(ship_index);
812 InitCockpit(ship_index);
813
814 return LGS_OK;
815 }
816
817 extern int Physics_NumLinked;
818 extern int PhysicsLinkList[MAX_OBJECTS];
819
820 int inreadobj = 0;
821
822 void VerifySaveGame(CFILE *fp) {
823 int testint;
824 testint = cf_ReadInt(fp);
825 ASSERT(testint == 0xF00D4B0B);
826 }
827
828 #define VERIFY_SAVEFILE
829 // VerifySaveGame(fp)
830 extern char MarkerMessages[MAX_PLAYERS * 2][MAX_MARKER_MESSAGE_LENGTH];
831 extern int Marker_message;
832 // loads in and sets these objects
833 int LGSObjects(CFILE *fp, int version) {
834
835 inreadobj = 1;
836 int retval = LGS_OK;
837 vector pos, last_pos;
838 int roomnum;
839 int i, j, highest_index;
840 int max_terr;
841
842 matrix *objmat = (matrix *)mem_malloc(sizeof(*objmat) * MAX_OBJECTS);
843
844 Osiris_DisableCreateEvents();
845 // we must reset some data before continuing.
846 InitBigObjects();
847
848 START_VERIFY_SAVEFILE(fp);
849 Marker_message = cf_ReadInt(fp);
850 int num_marker_msgs = cf_ReadShort(fp);
851 for (i = 0; i < num_marker_msgs; i++) {
852 int msg_len = cf_ReadShort(fp);
853 cf_ReadBytes((uint8_t *)MarkerMessages[i], msg_len, fp);
854 }
855
856 highest_index = (int)cf_ReadShort(fp);
857
858 // load what objects are stuck to each other
859 int max_num_linked = cf_ReadInt(fp);
860 Physics_NumLinked = cf_ReadInt(fp);
861 for (i = 0; i < max_num_linked; i++) {
862 PhysicsLinkList[i] = cf_ReadInt(fp);
863 }
864
865 // load AI information
866 //////////////////////////////////
867 int num_read_max_dynamic_paths = cf_ReadInt(fp);
868 int num_read_max_nodes = cf_ReadInt(fp);
869
870 int num_dp_to_read = std::min(MAX_DYNAMIC_PATHS, num_read_max_dynamic_paths);
871 int num_dp_to_skip =
872 (MAX_DYNAMIC_PATHS < num_read_max_dynamic_paths) ? num_read_max_dynamic_paths - MAX_DYNAMIC_PATHS : 0;
873
874 int num_n_to_read = std::min(MAX_NODES, num_read_max_nodes);
875 int num_n_to_skip = (MAX_NODES < num_read_max_nodes) ? num_read_max_nodes - MAX_NODES : 0;
876
877 int s;
878 for (i = 0; i < num_dp_to_read; i++) {
879 AIDynamicPath[i].num_nodes = cf_ReadShort(fp);
880 AIDynamicPath[i].use_count = cf_ReadShort(fp);
881 AIDynamicPath[i].owner_handle = cf_ReadInt(fp);
882
883 for (s = 0; s < num_n_to_read; s++) {
884 AIDynamicPath[i].pos[s].x = cf_ReadFloat(fp);
885 AIDynamicPath[i].pos[s].y = cf_ReadFloat(fp);
886 AIDynamicPath[i].pos[s].z = cf_ReadFloat(fp);
887 AIDynamicPath[i].roomnum[s] = cf_ReadInt(fp);
888 }
889
890 for (s = 0; s < num_n_to_skip; s++) {
891 cf_ReadFloat(fp);
892 cf_ReadFloat(fp);
893 cf_ReadFloat(fp);
894 cf_ReadInt(fp);
895 }
896 }
897
898 for (i = 0; i < num_dp_to_skip; i++) {
899 cf_ReadShort(fp);
900 cf_ReadShort(fp);
901 cf_ReadInt(fp);
902
903 for (s = 0; s < num_n_to_read; s++) {
904 cf_ReadFloat(fp);
905 cf_ReadFloat(fp);
906 cf_ReadFloat(fp);
907 cf_ReadInt(fp);
908 }
909
910 for (s = 0; s < num_n_to_skip; s++) {
911 cf_ReadFloat(fp);
912 cf_ReadFloat(fp);
913 cf_ReadFloat(fp);
914 cf_ReadInt(fp);
915 }
916 }
917
918 int num_read_rooms = cf_ReadInt(fp);
919 int num_r_to_read = std::min(MAX_ROOMS, num_read_rooms);
920 int num_r_to_skip = (MAX_ROOMS < num_read_rooms) ? num_read_rooms - MAX_ROOMS : 0;
921
922 AIAltPathNumNodes = cf_ReadInt(fp);
923 for (i = 0; i < num_r_to_read; i++) {
924 AIAltPath[i] = cf_ReadInt(fp);
925 }
926
927 for (i = 0; i < num_r_to_skip; i++) {
928 cf_ReadInt(fp);
929 }
930
931 //////////////////////////////////
932
933 Osiris_DisableEvents(OEM_OBJECTS | OEM_TRIGGERS | OEM_LEVELS);
934 for (i = 0; i < MAX_OBJECTS; i++) {
935 if (Objects[i].lighting_render_type != LRT_LIGHTMAPS) {
936 if (Objects[i].type != OBJ_NONE) {
937 Objects[i].next = -1;
938 Objects[i].prev = -1;
939 ObjDelete(i);
940 }
941 } else {
942 Objects[i].next = -1;
943 Objects[i].prev = -1;
944 ObjUnlink(i);
945 }
946 }
947 Osiris_EnableEvents(OEM_OBJECTS | OEM_TRIGGERS | OEM_LEVELS);
948 for (i = 0; i <= highest_index; i++) {
949 object *op;
950 weapon *wpn;
951 ship *shp;
952 object_info *obji;
953 door *door;
954 int index, nattach, new_model, handle;
955 uint8_t type, dummy_type;
956 int16_t sindex, size;
957
958 // if((i==98)||(i==100))
959 // Int3();
960 int sig;
961 gs_ReadInt(fp, sig);
962
963 ASSERT(sig == 0xBADB0B);
964
965 gs_ReadByte(fp, type);
966
967 // skip rooms and deleted objects. if this slot currently contains a real object, it should be
968 // destroyed (unlinked, deallocated, etc) to match the new object list.
969 if (type == OBJ_NONE) {
970 Osiris_DisableEvents(OEM_OBJECTS | OEM_TRIGGERS | OEM_LEVELS);
971 if (Objects[i].type != OBJ_NONE)
972 ObjDelete(i);
973 Osiris_EnableEvents(OEM_OBJECTS | OEM_TRIGGERS | OEM_LEVELS);
974 continue;
975 }
976 uint8_t l_rend_type;
977 gs_ReadByte(fp, l_rend_type);
978
979 // See if the object has changed from it's original lightmap type
980 // DAJ added check for type
981 if ((Objects[i].type != OBJ_NONE) && (Objects[i].lighting_render_type == LRT_LIGHTMAPS) &&
982 (l_rend_type != LRT_LIGHTMAPS)) {
983 Osiris_DisableEvents(OEM_OBJECTS | OEM_TRIGGERS | OEM_LEVELS);
984 ObjDelete(i);
985 Osiris_EnableEvents(OEM_OBJECTS | OEM_TRIGGERS | OEM_LEVELS);
986 }
987
988 op = &Objects[i];
989 op->lighting_render_type = l_rend_type;
990
991 // Store whether or not we have a pointer to lighting_info
992 uint8_t has_lightinfo;
993 gs_ReadByte(fp, has_lightinfo);
994 if (has_lightinfo) {
995 if (!op->lighting_info) {
996 op->lighting_info = (light_info *)mem_malloc(sizeof(*op->lighting_info));
997 }
998 cf_ReadBytes((uint8_t *)op->lighting_info, sizeof(*op->lighting_info), fp);
999 }
1000
1001 // validate handle.
1002 gs_ReadInt(fp, handle);
1003 if ((handle & HANDLE_OBJNUM_MASK) != i) {
1004 Int3();
1005 retval = LGS_OBJECTSCORRUPT;
1006 goto done;
1007 }
1008
1009 // read in the rest.
1010 gs_ReadByte(fp, dummy_type);
1011
1012 // positional information (not assigned to object 'cause of Unlink)
1013 gs_ReadInt(fp, roomnum);
1014 gs_ReadVector(fp, pos);
1015 gs_ReadVector(fp, last_pos);
1016 gs_ReadMatrix(fp, objmat[i]);
1017
1018 // object name
1019 gs_ReadByte(fp, j);
1020 if (j > 0) {
1021 if (op->name)
1022 mem_free(op->name);
1023 op->name = (char *)mem_malloc(j + 1);
1024 if (!op->name)
1025 Error("Out of memory");
1026
1027 cf_ReadBytes((uint8_t *)op->name, j, fp);
1028 op->name[j] = '\0';
1029 } else {
1030 op->name = NULL;
1031 }
1032
1033 // Kill any script thread associated with this object.
1034
1035 if (op->type != OBJ_NONE) {
1036 if (Objects[i].lighting_render_type != LRT_LIGHTMAPS)
1037 FreeObjectScripts(op, false);
1038
1039 // Free up effects memory
1040 if (op->effect_info) {
1041 mem_free(op->effect_info);
1042 op->effect_info = NULL;
1043 }
1044 if (op->ai_info != NULL) {
1045 AIDestroyObj(op);
1046 mem_free(op->ai_info);
1047 op->ai_info = NULL;
1048 }
1049 if (op->dynamic_wb != NULL) {
1050 mem_free(op->dynamic_wb);
1051 op->dynamic_wb = NULL;
1052 }
1053 if (op->attach_children != NULL) {
1054 mem_free(op->attach_children);
1055 op->attach_children = NULL;
1056 }
1057 }
1058 op->type = type;
1059 op->handle = handle;
1060 op->dummy_type = dummy_type;
1061
1062 op->roomnum = roomnum;
1063 op->pos = pos;
1064 op->last_pos = last_pos;
1065
1066 // data universal to all objects
1067 gs_ReadShort(fp, op->id);
1068
1069 // Get type, and xlate if dummy
1070 if (type == OBJ_DUMMY)
1071 type = op->dummy_type;
1072
1073 // xlate id to new id.
1074 switch (type) {
1075 case OBJ_ROBOT:
1076 case OBJ_POWERUP:
1077 case OBJ_BUILDING:
1078 case OBJ_CLUTTER:
1079 op->id = gs_Xlates->obji_indices[op->id];
1080 obji = &Object_info[op->id];
1081 break;
1082 case OBJ_DOOR:
1083 op->id = gs_Xlates->door_handles[op->id];
1084 door = &Doors[op->id];
1085 break;
1086 case OBJ_WEAPON:
1087 op->id = gs_Xlates->wpn_handles[op->id];
1088 wpn = &Weapons[op->id];
1089 break;
1090 case OBJ_PLAYER:
1091 shp = &Ships[Players[op->id].ship_index];
1092 break;
1093 }
1094
1095 gs_ReadInt(fp, op->flags);
1096
1097 op->flags |= OF_SERVER_OBJECT;
1098
1099 gs_ReadByte(fp, op->control_type);
1100 gs_ReadByte(fp, op->movement_type);
1101 gs_ReadByte(fp, op->render_type);
1102
1103 gs_ReadShort(fp, op->renderframe);
1104 gs_ReadFloat(fp, op->size);
1105 gs_ReadFloat(fp, op->shields);
1106 gs_ReadByte(fp, op->contains_type);
1107 gs_ReadByte(fp, op->contains_id);
1108 gs_ReadByte(fp, op->contains_count);
1109 gs_ReadFloat(fp, op->creation_time);
1110 gs_ReadFloat(fp, op->lifeleft);
1111 gs_ReadFloat(fp, op->lifetime);
1112 gs_ReadInt(fp, op->parent_handle);
1113
1114 // attachment info. free old info and load in new.
1115 gs_ReadInt(fp, op->attach_ultimate_handle);
1116 gs_ReadInt(fp, op->attach_parent_handle);
1117
1118 gs_ReadInt(fp, nattach);
1119 if (nattach) {
1120 int f_allocated;
1121
1122 if (version >= 2)
1123 gs_ReadInt(fp, f_allocated);
1124 else
1125 f_allocated = 1;
1126
1127 if (f_allocated) {
1128 // mprintf(0,"Object %d has %d attach points.\n",i,nattach);
1129 op->attach_children = (int *)mem_malloc(sizeof(int) * nattach);
1130 for (j = 0; j < nattach; j++)
1131 gs_ReadInt(fp, op->attach_children[j]);
1132 }
1133 }
1134
1135 VERIFY_SAVEFILE;
1136
1137 gs_ReadByte(fp, op->attach_type);
1138 gs_ReadShort(fp, op->attach_index);
1139 gs_ReadFloat(fp, op->attach_dist);
1140 gs_ReadVector(fp, op->min_xyz);
1141 gs_ReadVector(fp, op->max_xyz);
1142 gs_ReadFloat(fp, op->impact_size);
1143 gs_ReadFloat(fp, op->impact_time);
1144 gs_ReadFloat(fp, op->impact_player_damage);
1145 gs_ReadFloat(fp, op->impact_generic_damage);
1146 gs_ReadFloat(fp, op->impact_force);
1147
1148 // custom default script info
1149 gs_ReadByte(fp, j);
1150 if (j > 0) {
1151 op->custom_default_script_name = (char *)mem_malloc(j + 1);
1152 if (!op->custom_default_script_name)
1153 Error("Out of memory");
1154
1155 cf_ReadBytes((uint8_t *)op->custom_default_script_name, j, fp);
1156 op->custom_default_script_name[j] = '\0';
1157 } else {
1158 op->custom_default_script_name = NULL;
1159 }
1160
1161 gs_ReadByte(fp, j);
1162 if (j > 0) {
1163 op->custom_default_module_name = (char *)mem_malloc(j + 1);
1164 if (!op->custom_default_module_name)
1165 Error("Out of memory");
1166
1167 cf_ReadBytes((uint8_t *)op->custom_default_module_name, j, fp);
1168 op->custom_default_module_name[j] = '\0';
1169 } else {
1170 op->custom_default_module_name = NULL;
1171 }
1172
1173 VERIFY_SAVEFILE;
1174
1175 gs_ReadShort(fp, op->position_counter);
1176
1177 VERIFY_SAVEFILE;
1178
1179 // write out all structures here.
1180 // movement info.
1181 gs_ReadShort(fp, size);
1182 if (size != sizeof(op->mtype)) {
1183 Int3();
1184 retval = LGS_OUTDATEDVER;
1185 goto done;
1186 }
1187 cf_ReadBytes((uint8_t *)&op->mtype, size, fp);
1188
1189 VERIFY_SAVEFILE;
1190 // Control info, determined by CONTROL_TYPE
1191 gs_ReadShort(fp, size);
1192 if (size != sizeof(op->ctype)) {
1193 Int3();
1194 retval = LGS_OUTDATEDVER;
1195 goto done;
1196 }
1197 cf_ReadBytes((uint8_t *)&op->ctype, size, fp);
1198
1199 VERIFY_SAVEFILE;
1200 // remap bitmap handle if this is a fireball!
1201 if (type == OBJ_FIREBALL) {
1202 index = op->ctype.blast_info.bm_handle;
1203 op->ctype.blast_info.bm_handle = (index > -1) ? gs_Xlates->bm_handles[index] : -1;
1204 }
1205
1206 // save ai information.
1207 retval = LGSObjAI(fp, &op->ai_info);
1208 if (retval != LGS_OK)
1209 goto lgsobjs_fail;
1210
1211 VERIFY_SAVEFILE;
1212
1213 // save out rendering information
1214 gs_ReadShort(fp, size);
1215 if (size != sizeof(op->rtype)) {
1216 Int3();
1217 retval = LGS_OUTDATEDVER;
1218 goto done;
1219 }
1220 cf_ReadBytes((uint8_t *)&op->rtype, size, fp);
1221
1222 op->size = cf_ReadFloat(fp);
1223
1224 // page in correct graphical data now.
1225 switch (op->render_type) {
1226 case RT_NONE:
1227 case RT_EDITOR_SPHERE:
1228 case RT_FIREBALL:
1229 case RT_LINE:
1230 case RT_PARTICLE:
1231 case RT_SPLINTER:
1232 case RT_ROOM:
1233 break;
1234 case RT_WEAPON:
1235 if (!(op->flags & OF_POLYGON_OBJECT)) {
1236 if (!(Weapons[op->id].flags & WF_IMAGE_BITMAP)) {
1237 PageInVClip(Weapons[op->id].fire_image_handle);
1238 }
1239 break;
1240 }
1241 break;
1242 case RT_POLYOBJ: // be sure to use translated handles for polyobjs and textures
1243 {
1244 // the paging mess. must update size of object accordingly.
1245 sindex = (int16_t)op->rtype.pobj_info.model_num;
1246 new_model = (sindex > -1) ? gs_Xlates->model_handles[sindex] : -1;
1247 if ((new_model != op->rtype.pobj_info.model_num) || (Poly_models[new_model].flags & PMF_NOT_RESIDENT)) {
1248 switch (type) {
1249 case OBJ_DOOR:
1250 PageInPolymodel(new_model);
1251 ComputeDefaultSize(OBJ_DOOR, new_model, &op->size);
1252 break;
1253 case OBJ_ROBOT:
1254 case OBJ_POWERUP:
1255 case OBJ_BUILDING:
1256 case OBJ_CLUTTER:
1257 PageInPolymodel(new_model, type, &obji->size);
1258 op->size = obji->size;
1259 break;
1260 case OBJ_WEAPON:
1261 PageInPolymodel(new_model, OBJ_WEAPON, &wpn->size);
1262 op->size = wpn->size;
1263 break;
1264 case OBJ_PLAYER:
1265 PageInPolymodel(new_model, OBJ_PLAYER, &shp->size);
1266 op->size = shp->size;
1267 break;
1268 case OBJ_ROOM:
1269 op->size = ComputeRoomBoundingSphere(&pos, &Rooms[op->id]);
1270 break;
1271
1272 default:
1273 PageInPolymodel(new_model);
1274 }
1275 }
1276 op->rtype.pobj_info.model_num = new_model;
1277
1278 sindex = (int16_t)op->rtype.pobj_info.dying_model_num;
1279 new_model = (sindex > -1) ? gs_Xlates->model_handles[sindex] : -1;
1280 if (new_model != op->rtype.pobj_info.dying_model_num) {
1281 switch (type) {
1282 case OBJ_PLAYER:
1283 PageInPolymodel(new_model, OBJ_PLAYER, &shp->size);
1284 op->size = shp->size;
1285 break;
1286 }
1287 }
1288 op->rtype.pobj_info.dying_model_num = new_model;
1289
1290 index = op->rtype.pobj_info.tmap_override;
1291 op->rtype.pobj_info.tmap_override = (index > -1) ? gs_Xlates->tex_handles[index] : -1;
1292
1293 memset(&op->rtype.pobj_info.multi_turret_info, 0, sizeof(multi_turret));
1294 poly_model *pm = &Poly_models[op->rtype.pobj_info.model_num];
1295
1296 if (pm->n_attach) {
1297 mprintf(0, "*Object %d has %d attach points.\n", i, pm->n_attach);
1298 }
1299
1300 polyobj_info *p_info = &op->rtype.pobj_info;
1301 int num_wbs = pm->num_wbs;
1302 int count = 0;
1303 for (int j = 0; j < num_wbs; j++) {
1304 ASSERT(pm->poly_wb[j].num_turrets >= 0 && pm->poly_wb[j].num_turrets <= 6400);
1305 count += pm->poly_wb[j].num_turrets;
1306 }
1307
1308 p_info->multi_turret_info.num_turrets = count;
1309
1310 if ((count > 0) && (p_info->multi_turret_info.keyframes == NULL)) {
1311 int cur = 0;
1312
1313 p_info->multi_turret_info.time = 0;
1314 p_info->multi_turret_info.keyframes = (float *)mem_malloc(sizeof(float) * count);
1315 p_info->multi_turret_info.last_keyframes = (float *)mem_malloc(sizeof(float) * count);
1316 p_info->multi_turret_info.flags = 0;
1317 }
1318 // Do Animation stuff
1319 custom_anim multi_anim_info;
1320 cf_ReadBytes((uint8_t *)&multi_anim_info, sizeof(multi_anim_info), fp);
1321 ObjSetAnimUpdate(i, &multi_anim_info);
1322 break;
1323 }
1324
1325 case RT_SHARD:
1326 sindex = (int16_t)op->rtype.shard_info.tmap;
1327 op->rtype.shard_info.tmap = (sindex > -1) ? gs_Xlates->tex_handles[sindex] : -1;
1328 break;
1329
1330 default:
1331 Int3();
1332 }
1333
1334 VERIFY_SAVEFILE;
1335
1336 //!! dynamic weapon battery info!!
1337 retval = LGSObjWB(fp, op);
1338 if (retval != LGS_OK)
1339 goto lgsobjs_fail;
1340
1341 VERIFY_SAVEFILE;
1342
1343 // save effect info!
1344 retval = LGSObjEffects(fp, op);
1345 if (retval != LGS_OK)
1346 goto lgsobjs_fail;
1347
1348 VERIFY_SAVEFILE;
1349
1350 // save script stuff.
1351 if (Objects[i].lighting_render_type != LRT_LIGHTMAPS) {
1352 // Don't init the scripts for an object with lightmaps, because it was never destroyed!
1353 InitObjectScripts(op);
1354 }
1355
1356 // special case saves
1357 retval = LGSObjSpecial(fp, op);
1358 if (retval != LGS_OK)
1359 goto lgsobjs_fail;
1360
1361 // link into mine.
1362 // turn off big object flags if its a big object. (ObjLink will take care of this.)
1363 if (op->flags & OF_BIG_OBJECT)
1364 op->flags &= (~OF_BIG_OBJECT);
1365
1366 op->roomnum = roomnum; //-1;
1367 // ObjLink(OBJNUM(op), roomnum);
1368 // ObjSetOrient(op, &objmat);
1369 }
1370 for (; i < MAX_OBJECTS; i++) {
1371 if (Objects[i].type != OBJ_NONE) {
1372 Osiris_DisableEvents(OEM_OBJECTS | OEM_TRIGGERS | OEM_LEVELS);
1373 ObjDelete(i);
1374 Osiris_EnableEvents(OEM_OBJECTS | OEM_TRIGGERS | OEM_LEVELS);
1375 }
1376 }
1377
1378 for (i = 0; i < MAX_OBJECTS; i++) {
1379 Objects[i].next = -1;
1380 Objects[i].prev = -1;
1381 }
1382 for (i = 0; i < MAX_ROOMS; i++) {
1383 Rooms[i].objects = -1;
1384 }
1385 max_terr = TERRAIN_WIDTH * TERRAIN_DEPTH;
1386 for (i = 0; i < max_terr; i++) {
1387 Terrain_seg[i].objects = -1;
1388 }
1389 inreadobj = 0;
1390 Highest_object_index = highest_index;
1391
1392 // CreateRoomObjects();
1393
1394 for (i = 0; i <= Highest_object_index; i++) {
1395 object *op = &Objects[i];
1396 if (Objects[i].type != OBJ_NONE) {
1397 int newroom = op->roomnum;
1398 op->roomnum = -1;
1399 ObjLink(OBJNUM(op), newroom);
1400 ObjSetOrient(op, &objmat[i]);
1401 if (op->type == OBJ_ROOM) {
1402 mprintf(0, "Object %d is a room and Is%s a big object. Size=%f\n", i, (op->flags & OF_BIG_OBJECT) ? "" : "n't", op->size);
1403 if ((op->size >= ((TERRAIN_SIZE * (float)1))) && !(op->flags & OF_BIG_OBJECT)) {
1404 BigObjAdd(i);
1405 }
1406
1407 ObjSetAABB(op);
1408 }
1409 }
1410 /*
1411 if ((op->attach_ultimate_handle) && (OBJECT_HANDLE_NONE != op->attach_ultimate_handle)) {
1412 mprintf(0, "Object %d has an ultimate parent of %d (%d)\n",
1413 i,
1414 OBJNUM(ObjGet(op->attach_ultimate_handle)),
1415 op->attach_parent_handle);
1416 ASSERT(op->flags & OF_ATTACHED);
1417 }
1418 if ((op->attach_ultimate_handle) && (OBJECT_HANDLE_NONE != op->attach_parent_handle)) {
1419 mprintf(0, "Object %d has a parent of %d (%d)\n",
1420 i,
1421 OBJNUM(ObjGet(op->attach_parent_handle)),
1422 op->attach_parent_handle);
1423 ASSERT(op->flags & OF_ATTACHED);
1424 }
1425 */
1426 }
1427 mprintf(0, "Objects[121].prev=%d\n", Objects[121].prev);
1428 ResetFreeObjects();
1429 mprintf(0, "highest obj index = %d, ", Highest_object_index);
1430 ObjReInitPositionHistory();
1431
1432 END_VERIFY_SAVEFILE(fp, "Objects load");
1433 lgsobjs_fail:
1434
1435 Osiris_EnableCreateEvents();
1436
1437 done:;
1438
1439 mem_free(objmat);
1440
1441 return retval;
1442 }
1443
1444 // loads ai
1445 int LGSObjAI(CFILE *fp, ai_frame **pai) {
1446 ai_frame *ai;
1447 int16_t size;
1448 int8_t read_ai;
1449
1450 *pai = NULL;
1451
1452 gs_ReadByte(fp, read_ai);
1453 if (!read_ai)
1454 return LGS_OK;
1455
1456 gs_ReadShort(fp, size);
1457 if (size != sizeof(ai_frame))
1458 return LGS_OUTDATEDVER;
1459
1460 *pai = (ai_frame *)mem_malloc(size);
1461 ai = *pai;
1462
1463 cf_ReadBytes((uint8_t *)ai, size, fp);
1464
1465 return LGS_OK;
1466 }
1467
1468 // loads fx
1469 int LGSObjEffects(CFILE *fp, object *op) {
1470 int16_t size;
1471 int8_t do_read;
1472
1473 op->effect_info = NULL;
1474
1475 gs_ReadByte(fp, do_read);
1476 if (do_read) {
1477 gs_ReadShort(fp, size);
1478 if (size != sizeof(effect_info_s))
1479 return LGS_OUTDATEDVER;
1480
1481 op->effect_info = (effect_info_s *)mem_malloc(size);
1482 effect_info_s *ei = op->effect_info;
1483
1484 cf_ReadBytes((uint8_t *)ei, size, fp);
1485 }
1486
1487 return LGS_OK;
1488 }
1489
1490 //@@// loads script
1491 //@@vector *LGSScript(CFILE *fp, script_info *script, uint8_t *is_scripted, int *memsize)
1492 //@@{
1493 //@@ int i;
1494 //@@ char name[64];
1495 //@@ uint16_t nparms;
1496 //@@ tScriptParm *parms = NULL;
1497 //@@
1498 //@@// ugh, write out script info.
1499 //@@ gs_ReadByte(fp, (*is_scripted));
1500 //@@
1501 //@@ cf_ReadString(name, sizeof(name), fp);
1502 //@@ if (name[0])
1503 //@@ script->set_name(name);
1504 //@@
1505 //@@ gs_ReadShort(fp, nparms);
1506 //@@ gs_ReadShort(fp, script->is_custom);
1507 //@@ if (nparms)
1508 //@@ parms = new tScriptParm[nparms];
1509 //@@
1510 //@@ for (i = 0; i < nparms; i++)
1511 //@@ {
1512 //@@ gs_ReadByte(fp, parms[i].type);
1513 //@@ gs_ReadFloat(fp, parms[i].val.x);
1514 //@@ gs_ReadFloat(fp, parms[i].val.y);
1515 //@@ gs_ReadFloat(fp, parms[i].val.z);
1516 //@@ }
1517 //@@
1518 //@@ script->set_parms(nparms, parms);
1519 //@@ if (parms)
1520 //@@ delete[] parms;
1521 //@@
1522 //@@// write out thread data if necessary
1523 //@@ vector *mem = NULL;
1524 //@@ *memsize = 0;
1525 //@@ if (*is_scripted) {
1526 //@@ int mem_size=0,j;
1527 //@@
1528 //@@ gs_ReadShort(fp, mem_size);
1529 //@@ *memsize = mem_size;
1530 //@@
1531 //@@ if (mem_size) {
1532 //@@ mem = new vector[mem_size];
1533 //@@ for (j = 0; j < mem_size; j++)
1534 //@@ gs_ReadVector(fp, mem[j]);
1535 //@@ }
1536 //@@ }
1537 //@@
1538 //@@ return mem;
1539 //@@}
1540
1541 // loads fx
1542 int LGSObjWB(CFILE *fp, object *op) {
1543 dynamic_wb_info *dwba = NULL;
1544 int i;
1545 int8_t num_wbs;
1546
1547 gs_ReadByte(fp, num_wbs);
1548 if (!num_wbs)
1549 return LGS_OK;
1550
1551 dwba = (dynamic_wb_info *)mem_malloc(sizeof(dynamic_wb_info) * num_wbs);
1552
1553 for (i = 0; i < num_wbs; i++) {
1554 dynamic_wb_info *dwb = &dwba[i];
1555 cf_ReadBytes((uint8_t *)dwb, sizeof(dynamic_wb_info), fp);
1556 }
1557 op->dynamic_wb = dwba;
1558
1559 return LGS_OK;
1560 }
1561
1562 // loads special object info
1563 int LGSObjSpecial(CFILE *fp, object *op) {
1564 int retval = LGS_OK;
1565
1566 return retval;
1567 }
1568
1569 // load spew
1570 int LGSSpew(CFILE *fp) {
1571 int i, count = 0;
1572
1573 // read GLOBAL value
1574 gs_ReadShort(fp, spew_count);
1575
1576 for (i = 0; i < MAX_SPEW_EFFECTS; i++) {
1577 uint8_t used;
1578 gs_ReadByte(fp, used);
1579 if (used)
1580 cf_ReadBytes((uint8_t *)&SpewEffects[i], sizeof(spewinfo), fp);
1581 }
1582
1583 return LGS_OK;
1584 }
1585
1586 int LGSMatcens(CFILE *fp) {
1587 int num_matcens = cf_ReadInt(fp);
1588
1589 for (int i = 0; i < num_matcens; i++) {
1590 Matcen[i]->LoadData(fp);
1591 }
1592
1593 return LGS_OK;
1594 }
1595
1596 int LGSSnapshot(CFILE *fp) {
1597 int bm_handle = -1;
1598 int8_t valid_snapshot = 0;
1599
1600 // get snapshot byte
1601 valid_snapshot = cf_ReadByte(fp);
1602
1603 // if valid, read it in, otherwise just return
1604 if (valid_snapshot) {
1605 bm_handle = bm_AllocLoadBitmap(fp, 0);
1606 }
1607
1608 return bm_handle;
1609 }
1610
1611 //@@ // movement info.
1612 //@@ switch (op->movement_type)
1613 //@@ {
1614 //@@ case MT_SHOCKWAVE:
1615 //@@ {
1616 //@@ int16_t bound;
1617 //@@ gs_ReadShort(fp, bound);
1618 //@@ if (bound < (sizeof(op_wave->damaged_list)/sizeof(uint32_t))) {
1619 //@@ Int3();
1620 //@@ retval = LGS_OUTDATEDVER;
1621 //@@ goto lgsobjs_fail;
1622 //@@ }
1623 //@@ for (j = 0; j < sizeof(op_wave->damaged_list)/sizeof(uint32_t); j++)
1624 //@@ gs_ReadInt(fp, (uint32_t)op_wave->damaged_list[j]);
1625 //@@ }
1626 //@@ break;
1627 //@@ default:
1628 //@@ gs_ReadVector(fp, op_phys->velocity);
1629 //@@ gs_ReadVector(fp, op_phys->thrust);
1630 //@@ gs_ReadVector(fp, op_phys->rotvel);
1631 //@@ gs_ReadVector(fp, op_phys->rotthrust);
1632 //@@ gs_ReadAngle(fp, op_phys->turnroll);
1633 //@@ gs_ReadFloat(fp, op_phys->last_still_time);
1634 //@@ gs_ReadInt(fp, op_phys->num_bounces);
1635 //@@ gs_ReadFloat(fp, op_phys->coeff_restitution);
1636 //@@ gs_ReadFloat(fp, op_phys->mass);
1637 //@@ gs_ReadFloat(fp, op_phys->drag);
1638 //@@ gs_ReadFloat(fp, op_phys->rotdrag);
1639 //@@ gs_ReadFloat(fp, op_phys->full_thrust);
1640 //@@ gs_ReadFloat(fp, op_phys->full_rotthrust);
1641 //@@ gs_ReadFloat(fp, op_phys->max_turnroll_rate);
1642 //@@ gs_ReadFloat(fp, op_phys->turnroll_ratio);
1643 //@@ gs_ReadFloat(fp, op_phys->wiggle_amplitude);
1644 //@@ gs_ReadFloat(fp, op_phys->wiggles_per_sec);
1645 //@@ gs_ReadVector(fp, op_phys->dest_pos);
1646 //@@ gs_ReadFloat(fp, op_phys->hit_die_dot);
1647 //@@ gs_ReadFloat(fp, op_phys->max_speed_time);
1648 //@@ gs_ReadInt(fp, op_phys->flags);
1649 //@@ }
1650 //@@
1651 //@@ // don't need to load lightmap infomation. should be in object already at loadtime
1652 //@@
1653 //@@ //Control info, determined by CONTROL_TYPE
1654 //@@ switch (op->control_type)
1655 //@@ {
1656 //@@ case CT_NONE:
1657 //@@ case CT_AI:
1658 //@@ case CT_FLYING: //the player is flying
1659 //@@ case CT_FLYTHROUGH: //the flythrough system
1660 //@@ case CT_SLEW: //slewing
1661 //@@ case CT_PARTICLE: //Particle
1662 //@@ break;
1663 //@@ case CT_EXPLOSION: //explosion sequencer
1664 //@@ gs_ReadFloat(fp, op_expl->spawn_time);
1665 //@@ gs_ReadFloat(fp, op_expl->delete_time);
1666 //@@ gs_ReadShort(fp, op_expl->delete_objnum);
1667 //@@ gs_ReadShort(fp, op_expl->attach_parent);
1668 //@@ gs_ReadShort(fp, op_expl->prev_attach);
1669 //@@ gs_ReadShort(fp, op_expl->next_attach);
1670 //@@ break;
1671 //@@ case CT_DEBRIS: //this is a piece of debris
1672 //@@ gs_ReadFloat(fp, op->ctype.dying_info.delay_time);
1673 //@@ gs_ReadBool(fp, op->ctype.dying_info.f_death_anim);
1674 //@@ break;
1675 //@@ case CT_POWERUP: //animating powerup blob
1676 //@@ gs_ReadInt(fp, op->ctype.powerup_info.count);
1677 //@@ gs_ReadInt(fp, op->ctype.powerup_info.flags);
1678 //@@ break;
1679 //@@ case CT_SPLINTER: //Splinter
1680 //@@ gs_ReadByte(fp, op_splint->subobj_num);
1681 //@@ gs_ReadShort(fp, op_splint->facenum);
1682 //@@ for (j = 0; j < MAX_VERTS_PER_SPLINTER; j++)
1683 //@@ gs_ReadVector(fp, op_splint->verts[j]);
1684 //@@ gs_ReadVector(fp, op_splint->center);
1685 //@@ break;
1686 //@@ case CT_WEAPON: //laser, etc.
1687 //@@ gs_ReadShort(fp, op_wpn->parent_type);
1688 //@@ gs_ReadShort(fp, op_wpn->src_gun_num);
1689 //@@ gs_ReadInt(fp, op_wpn->last_hit_handle);
1690 //@@ gs_ReadInt(fp, op_wpn->track_handle);
1691 //@@ gs_ReadInt(fp, op_wpn->hit_status);
1692 //@@ gs_ReadVector(fp, op_wpn->hit_pnt);
1693 //@@ gs_ReadVector(fp, op_wpn->hit_wall_pnt);
1694 //@@ gs_ReadVector(fp, op_wpn->hit_wall_normal);
1695 //@@ gs_ReadInt(fp, op_wpn->hit_room);
1696 //@@ gs_ReadInt(fp, op_wpn->hit_pnt_room);
1697 //@@ gs_ReadShort(fp, op_wpn->hit_face);
1698 //@@ gs_ReadFloat(fp, op_wpn->multiplier);
1699 //@@ gs_ReadFloat(fp, op_wpn->thrust_left);
1700 //@@ gs_ReadFloat(fp, op_wpn->last_drop_time);
1701 //@@ break;
1702 //@@
1703 //@@ default:
1704 //@@ Int3();
1705 //@@ }
1706 //@@
1707 //@@ if (op->type == OBJ_FIREBALL) {
1708 //@@ gs_ReadFloat(fp,op->ctype.blast_info.max_size);
1709 //@@ gs_ReadInt(fp,index);
1710 //@@ op->ctype.blast_info.bm_handle = (index > -1) ? gs_Xlates->bm_handles[index] : -1;
1711 //@@ }
1712
1713 // RENDER
1714 //@@ const int N_SHARD_VERTS = 3;
1715 //@@ switch (op->render_type)
1716 //@@ {
1717 //@@ case RT_NONE:
1718 //@@ case RT_EDITOR_SPHERE:
1719 //@@ case RT_FIREBALL:
1720 //@@ case RT_LINE:
1721 //@@ case RT_PARTICLE:
1722 //@@ case RT_SPLINTER:
1723 //@@ case RT_ROOM:
1724 //@@ break;
1725 //@@ case RT_WEAPON:
1726 //@@ if (!(op->flags & OF_POLYGON_OBJECT)) {
1727 //@@ PageInVClip (Weapons[op->id].fire_image_handle);
1728 //@@ break;
1729 //@@ }
1730 //@@ case RT_POLYOBJ: // be sure to use translated handles for
1731 // polyobjs and textures
1732 //@@ gs_ReadShort(fp, sindex);
1733 //@@ new_model = (sindex > -1) ? gs_Xlates->model_handles[sindex] : -1;
1734 //@@ if (new_model != pobji->model_num)
1735 //@@ PageInPolymodel (new_model, op->type, &op->size);
1736 //@@ pobji->model_num = new_model;
1737 //@@
1738 //@@ gs_ReadShort(fp, sindex);
1739 //@@ new_model = (sindex > -1) ? gs_Xlates->model_handles[sindex] : -1;
1740 //@@ if (new_model != pobji->dying_model_num)
1741 //@@ PageInPolymodel (new_model, op->type, &op->size);
1742 //@@ pobji->dying_model_num = new_model;
1743 //@@
1744 //@@ gs_ReadFloat(fp, pobji->anim_start_frame);
1745 //@@ gs_ReadFloat(fp, pobji->anim_frame);
1746 //@@ gs_ReadFloat(fp, pobji->anim_end_frame);
1747 //@@ gs_ReadFloat(fp, pobji->anim_time);
1748 //@@ gs_ReadInt(fp, pobji->anim_flags);
1749 //@@ gs_ReadFloat(fp, pobji->max_speed);
1750 //@@ gs_ReadInt(fp, pobji->subobj_flags);
1751 //@@
1752 //@@ gs_ReadInt(fp, index);
1753 //@@ pobji->tmap_override = (index>-1) ? gs_Xlates->tex_handles[index] : -1;
1754 //@@
1755 //@@ //!! multi_anim_save here
1756 //@@ // !@$()*# SAVE MULTI ANIM TURRET INFORMATION HERE $*#)(*)(!
1757 //@@ break;
1758 //@@
1759 //@@ case RT_SHARD:
1760 //@@ for (j = 0; j < N_SHARD_VERTS; j++)
1761 //@@ gs_ReadVector(fp, op->rtype.shard_info.points[j]);
1762 //@@ for (j = 0; j < N_SHARD_VERTS; j++)
1763 //@@ gs_ReadFloat(fp, op->rtype.shard_info.u[j]);
1764 //@@ for (j = 0; j < N_SHARD_VERTS; j++)
1765 //@@ gs_ReadFloat(fp, op->rtype.shard_info.v[j]);
1766 //@@ gs_ReadVector(fp, op->rtype.shard_info.normal);
1767 //@@ gs_ReadShort(fp, sindex);
1768 //@@ op->rtype.shard_info.tmap = (sindex>-1) ? gs_Xlates->tex_handles[sindex] : -1;
1769 //@@ break;
1770 //@@
1771 //@@ default:
1772 //@@ Int3();
1773 //@@ }
1774 //@@
1775
1776 // AI
1777 //@@// the FUN begins.
1778 //@@ gs_ReadByte(fp, ai->ai_class);
1779 //@@ gs_ReadByte(fp, ai->ai_type);
1780 //@@
1781 //@@// write path info
1782 //@@ ai_path_info *path = &ai->path;
1783 //@@ gs_ReadInt(fp, path->flags);
1784 //@@ gs_ReadShort(fp, path->cur_path);
1785 //@@ gs_ReadShort(fp, path->cur_node);
1786 //@@ gs_ReadShort(fp, path->num_paths);
1787 //@@ gs_ReadShort(fp, path->goal_index);
1788 //@@
1789 //@@ for (i = 0; i < MAX_JOINED_PATHS; i++)
1790 //@@ {
1791 //@@ gs_ReadByte(fp, path->path_id[i]);
1792 //@@ gs_ReadByte(fp, path->path_type[i]);
1793 //@@ gs_ReadShort(fp, path->path_start_node[i]);
1794 //@@ gs_ReadShort(fp, path->path_end_node[i]);
1795 //@@ gs_ReadShort(fp, path->path_flags[i]);
1796 //@@ }
1797 //@@
1798 //@@// continue
1799 //@@ gs_ReadFloat(fp, ai->max_velocity);
1800 //@@ gs_ReadFloat(fp, ai->max_delta_velocity);
1801 //@@ gs_ReadFloat(fp, ai->max_turn_rate);
1802 //@@ gs_ReadFloat(fp, ai->max_delta_turn_rate);
1803 //@@ gs_ReadFloat(fp, ai->attack_vel_percent);
1804 //@@ gs_ReadFloat(fp, ai->flee_vel_percent);
1805 //@@ gs_ReadFloat(fp, ai->dodge_vel_percent);
1806 //@@ gs_ReadFloat(fp, ai->circle_distance);
1807 //@@ gs_ReadFloat(fp, ai->dodge_percent);
1808 //@@
1809 //@@ for (i = 0; i < 2; i++)
1810 //@@ {
1811 //@@ gs_ReadFloat(fp, ai->melee_damage[i]);
1812 //@@ gs_ReadFloat(fp, ai->melee_latency[i]);
1813 //@@ }
1814 //@@
1815 //@@ for (i = 0; i < MAX_AI_SOUNDS; i++)
1816 //@@ {
1817 //@@ gs_ReadInt(fp, ai->sound[i]);
1818 //@@ gs_ReadFloat(fp, ai->last_sound_time[i]);
1819 //@@ }
1820 //@@ gs_ReadShort(fp, ai->last_played_sound_index);
1821 //@@
1822 //@@ gs_ReadByte(fp, ai->movement_type);
1823 //@@ gs_ReadByte(fp, ai->movement_subtype);
1824 //@@ gs_ReadByte(fp, ai->animation_type);
1825 //@@ gs_ReadByte(fp, ai->next_animation_type);
1826 //@@ gs_ReadByte(fp, ai->next_movement);
1827 //@@ gs_ReadByte(fp, ai->current_wb_firing);
1828 //@@ gs_ReadByte(fp, ai->last_wb_firing);
1829 //@@
1830 //@@// goals
1831 //@@ for (i = 0;i < MAX_GOALS; i++)
1832 //@@ {
1833 //@@ retval = LGSObjAIGoal(fp, &ai->goals[i]);
1834 //@@ if (retval != LGS_OK) goto lgsaigoal_fail;
1835 //@@ }
1836 //@@
1837 //@@// continue
1838 //@@ gs_ReadInt(fp, ai->target_handle);
1839 //@@ gs_ReadFloat(fp, ai->next_target_update_time);
1840 //@@ gs_ReadFloat(fp, ai->dist_to_target);
1841 //@@ gs_ReadVector(fp, ai->vec_to_target);
1842 //@@ gs_ReadFloat(fp, ai->last_check_see_target_time);
1843 //@@ gs_ReadVector(fp, ai->last_see_target_pos);
1844 //@@ gs_ReadFloat(fp, ai->last_see_target_time);
1845 //@@ gs_ReadFloat(fp, ai->weapon_speed);
1846 //@@ gs_ReadFloat(fp, ai->next_melee_time);
1847 //@@ gs_ReadFloat(fp, ai->last_render_time);
1848 //@@ gs_ReadFloat(fp, ai->next_flinch_time);
1849 //@@ gs_ReadInt(fp, ai->status_reg);
1850 //@@ gs_ReadInt(fp, ai->flags);
1851 //@@ gs_ReadInt(fp, ai->notify_flags);
1852 //@@
1853 //@@// notify events (MUST BE WRITTEN OUT AT A LATER DATE)
1854 //@@
1855 //@@// Normalized movement and facing information
1856 //@@ gs_ReadVector(fp, ai->movement_dir);
1857 //@@ gs_ReadVector(fp, ai->rot_thrust_vector);
1858 //@@ gs_ReadFloat(fp, ai->fov);
1859 //@@ gs_ReadInt(fp, ai->anim_sound_handle);
1860 //@@ gs_ReadFloat(fp, ai->frustration);
1861 //@@ gs_ReadFloat(fp, ai->curiousity);
1862 //@@ gs_ReadFloat(fp, ai->fire_spread);
1863 //@@ gs_ReadFloat(fp, ai->agression);
1864 //@@ gs_ReadFloat(fp, ai->night_vision);
1865 //@@ gs_ReadFloat(fp, ai->fog_vision);
1866 //@@ gs_ReadFloat(fp, ai->lead_accuracy);
1867 //@@ gs_ReadFloat(fp, ai->lead_varience);
1868 //@@ gs_ReadFloat(fp, ai->fight_team);
1869 //@@ gs_ReadFloat(fp, ai->fight_same);
1870 //@@ gs_ReadFloat(fp, ai->hearing);
1871 //@@ gs_ReadFloat(fp, ai->roaming);
1872 //@@ gs_ReadFloat(fp, ai->life_preservation);
1873 //@@ gs_ReadShort(fp, ai->awareness);
1874 //@@
1875
1876 // saves ai goals
1877 //@@int LGSObjAIGoal(CFILE *fp, goal *g)
1878 //@@{
1879 //@@ int i;
1880 //@@ int8_t used;
1881 //@@
1882 //@@ gs_ReadByte(fp, used);
1883 //@@ g->used = used ? true : false;
1884 //@@ if (!g->used)
1885 //@@ return LGS_OK;
1886 //@@
1887 //@@ gs_ReadInt(fp, g->type);
1888 //@@ gs_ReadByte(fp, g->activation_level);
1889 //@@ gs_ReadShort(fp, g->influence);
1890 //@@
1891 //@@// write goal info
1892 //@@ switch (g->type)
1893 //@@ {
1894 //@@ case AIG_HIDE_FROM_OBJ:
1895 //@@ gs_ReadInt(fp, g->g_info.handle);
1896 //@@ gs_ReadFloat(fp, g->g_info.time);
1897 //@@ break;
1898 //@@
1899 //@@ case AIG_WANDER_AROUND:
1900 //@@ gs_ReadInt(fp, g->g_info.roomnum);
1901 //@@ break;
1902 //@@
1903 //@@ case AIG_DODGE_OBJ:
1904 //@@ case AIG_MOVE_RELATIVE_OBJ:
1905 //@@ gs_ReadInt(fp, g->g_info.handle);
1906 //@@ break;
1907 //@@
1908 //@@ case AIG_MOVE_RELATIVE_OBJ_VEC:
1909 //@@ gs_ReadInt(fp, g->g_info.handle);
1910 //@@ gs_ReadInt(fp, g->g_info.subtype);
1911 //@@ break;
1912 //@@
1913 //@@ case AIG_GUARD_AREA:
1914 //@@ gs_ReadVector(fp, g->g_info.pos);
1915 //@@ break;
1916 //@@
1917 //@@ case AIG_GET_TO_OBJ:
1918 //@@ gs_ReadInt(fp, g->g_info.handle);
1919 //@@ gs_ReadVector(fp, g->g_info.pos);
1920 //@@ break;
1921 //@@
1922 //@@ case AIG_GET_TO_POS:
1923 //@@ gs_ReadInt(fp, g->g_info.roomnum);
1924 //@@ gs_ReadVector(fp, g->g_info.pos);
1925 //@@ break;
1926 //@@
1927 //@@ case AIG_FOLLOW_PATH: // This must be fixed -- chrishack
1928 //@@ gs_ReadInt(fp, g->g_info.id);
1929 //@@ break;
1930 //@@ }
1931 //@@
1932 //@@// write goal enabler
1933 //@@ gs_ReadByte(fp, g->num_enablers);
1934 //@@ for (i = 0; i < g->num_enablers; i++)
1935 //@@ {
1936 //@@ gs_ReadByte(fp, g->enabler[i].enabler_type);
1937 //@@
1938 //@@ switch (g->enabler[i].enabler_type)
1939 //@@ {
1940 //@@ case AIE_AI_STATUS_FLAG:
1941 //@@ gs_ReadInt(fp, g->enabler[i].flags);
1942 //@@ break;
1943 //@@ }
1944 //@@
1945 //@@ gs_ReadFloat(fp, g->enabler[i].percent_enable);
1946 //@@ gs_ReadFloat(fp, g->enabler[i].check_interval);
1947 //@@ gs_ReadFloat(fp, g->enabler[i].last_check_time);
1948 //@@ gs_ReadByte(fp, g->enabler[i].bool_next_enabler_op);
1949 //@@ }
1950 //@@
1951 //@@// continue
1952 //@@ gs_ReadFloat(fp, g->circle_distance);
1953 //@@ gs_ReadInt(fp, g->status_reg);
1954 //@@ gs_ReadFloat(fp, g->start_time);
1955 //@@ gs_ReadFloat(fp, g->next_path_time);
1956 //@@ gs_ReadFloat(fp, g->dist_to_goal);
1957 //@@ gs_ReadVector(fp, g->vec_to_target);
1958 //@@ gs_ReadFloat(fp, g->last_check_see_target_time);
1959 //@@ gs_ReadVector(fp, g->last_see_target_pos);
1960 //@@ gs_ReadFloat(fp, g->last_see_target_time);
1961 //@@ gs_ReadFloat(fp, g->next_target_update_time);
1962 //@@ gs_ReadShort(fp, g->flags);
1963 //@@
1964 //@@ return LGS_OK;
1965 //@@}
1966
1967 // Object effect_info
1968 //@@ gs_ReadInt(fp, ei->type_flags);
1969 //@@ gs_ReadFloat(fp, ei->alpha);
1970 //@@
1971 //@@// if (op->type == OBJ_POWERUP) {
1972 //@@ gs_ReadFloat(fp, ei->last_object_hit_time);
1973 //@@ gs_ReadInt(fp, ei->last_object_hit);
1974 //@@// }
1975 //@@// if (ei->type_flags & EF_DEFORM) {
1976 //@@ gs_ReadFloat(fp, ei->deform_range);
1977 //@@ gs_ReadFloat(fp, ei->deform_time);
1978 //@@// }
1979 //@@// if (ei->type_flags & EF_VOLUME_CHANGING) {
1980 //@@ gs_ReadFloat(fp, ei->volume_change_time);
1981 //@@ gs_ReadVector(fp, ei->volume_old_pos);
1982 //@@ gs_ReadFloat(fp, ei->volume_old_room);
1983 //@@// }
1984 //@@// if (ei->type_flags & EF_VOLUME_LIT) {
1985 //@@ gs_ReadByte(fp, ei->dynamic_this_frame);
1986 //@@ gs_ReadFloat(fp, ei->dynamic_red);
1987 //@@ gs_ReadFloat(fp, ei->dynamic_green);
1988 //@@ gs_ReadFloat(fp, ei->dynamic_blue);
1989 //@@// }
1990 //@@// if (ei->type_flags & EF_CLOAKED) {
1991 //@@ gs_ReadFloat(fp, ei->cloak_time);
1992 //@@// }
1993 //@@// if (ei->type_flags & EF_COLORED) {
1994 //@@ gs_ReadFloat(fp, ei->color_time);
1995 //@@ gs_ReadFloat(fp, ei->r);
1996 //@@ gs_ReadFloat(fp, ei->g);
1997 //@@ gs_ReadFloat(fp, ei->b);
1998 //@@// }
1999 //@@// if (ei->type_flags & EF_NAPALMED) {
2000 //@@ gs_ReadFloat(fp, ei->damage_time);
2001 //@@ gs_ReadFloat(fp, ei->damage_per_second);
2002 //@@ gs_ReadFloat(fp, ei->last_damage_time);
2003 //@@ gs_ReadInt(fp, ei->damage_handle);
2004 //@@// }
2005 //@@// if (ei->type_flags & EF_FREEZE) {
2006 //@@ gs_ReadFloat(fp, ei->freeze_scalar);
2007 //@@// }
2008 //@@// if (ei->type_flags & EF_LINE_ATTACH) {
2009 //@@ gs_ReadInt(fp, ei->attach_line_handle);
2010 //@@// }
2011 //@@ }
2012
2013 // Object WBs
2014 //@@ gs_ReadFloat(fp, dwb->last_fire_time);
2015 //@@ gs_ReadByte(fp, dwb->cur_firing_mask);
2016 //@@
2017 //@@ for (j = 0; j < MAX_WB_TURRETS;j++)
2018 //@@ {
2019 //@@ gs_ReadFloat(fp, dwb->norm_turret_angle[j]);
2020 //@@ gs_ReadFloat(fp, dwb->turret_next_think_time[j]);
2021 //@@ gs_ReadByte(fp, dwb->turret_direction[j]);
2022 //@@ }
2023 //@@
2024 //@@ gs_ReadByte(fp, dwb->wb_anim_mask);
2025 //@@ gs_ReadFloat(fp, dwb->wb_anim_frame);
2026 //@@ gs_ReadVector(fp, dwb->cur_target);
2027 //@@ gs_ReadByte(fp, dwb->upgrade_level);
2028 //@@ gs_ReadInt(fp, dwb->flags);