Debian Codegraph @

Descent3/gamesequence.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/gamesequence.cpp $
21 * $Revision: 313 $
22 * $Date: 8/30/01 12:20p $
23 * $Author: Matt $
24 *
25 * Game Sequencer
26 *
27 * $Log: /DescentIII/main/gamesequence.cpp $
28 *
29 * 313 8/30/01 12:20p Matt
30 * Removed Int3
31 *
32 * 312 7/09/01 4:22p Matt
33 * Fixed code that was supposed to find an allowed ship in a netgame but
34 * did so using the AllowedShips[] array instead of the Ships[] array, so
35 * it would never find the add-on ships.
36 *
37 * 311 4/20/00 12:29p Matt
38 * From Duane for 1.4
39 * Added checks, asserts, and fixes for bad return values
40 * Free the BSP tree when freeing a level
41 * On Mac, free all sounds when flushing the data cache
42 * Mac-only controller changes
43 *
44 * 310 4/06/00 9:25a Matt
45 * Fixed a screen clear problem on at ATI Rage Fury Maxx in dual-chip mode
46 * by forcing the screen to clear four times (instead of three).
47 *
48 * 309 3/20/00 12:09p Matt
49 * Merge of Duane's post-1.3 changes.
50 * Mac controller stuff
51 * Fixed mem leaks with game paths
52 * Message for PageDown pause
53 * Removed dynamic lightmap info system
54 *
55 * 308 1/26/00 9:20p Jeff
56 * added support for IntelliVIBE DLL
57 *
58 * 307 10/29/99 5:01p Jeff
59 * fixed bug where ending a cinematic on FreeThisLevel() hosed
60 * resume/suspend controls
61 *
62 * 306 10/22/99 10:51p Matt
63 * Mac merge
64 *
65 * 305 10/22/99 3:40p Kevin
66 * Mac merge fixes
67 *
68 * 304 7/20/99 1:18p Samir
69 * save state of rearviews between game through the pilot file.
70 *
71 * 303 6/14/99 4:04p Matt
72 * Fixed problem where goal couldn't be found by the Dallas init function
73 * because it was searching for the English name and the goals had been
74 * translated. Now we load the English text, init the scripts, and then
75 * load the correct language.
76 *
77 * A simpler way of doing this would have been to *not* load the localized
78 * version when the level is loaded, and just loaded it after the script
79 * had been initialized.
80 *
81 * 302 6/08/99 1:00p Jason
82 * changes for bumpmapping
83 *
84 * 301 5/21/99 7:07p Jason
85 * fixed some weird multiplayer rejoin anomalies
86 *
87 * 300 5/20/99 3:40p Jason
88 * made mission looping work correctly in multiplayer
89 *
90 * 299 5/20/99 12:17a Jason
91 * automatically delete all ambient objects if in multiplayer
92 *
93 * 298 5/19/99 5:39p Jason
94 * made level failing work in coop
95 *
96 * 297 5/19/99 11:46a Kevin
97 * fixed problem with level not being loaded and client not able to join
98 * further games.
99 *
100 * 296 5/18/99 7:02p Jeff
101 * created new callback for UI so that game states get set properly (only
102 * really affects music, but fixes a problem for multiplayer games with
103 * music.)
104 *
105 * 295 5/17/99 10:15p Matt
106 * Added system for having ambient objects that get deleted at low detail
107 * levels.
108 *
109 * 294 5/17/99 2:39p Kevin
110 * fixed bug with current_mission.filename and not using strdup to
111 * allocate enough room for the mn3
112 *
113 * 293 5/12/99 1:57p Jason
114 * fixed yet more buggy/ugly code
115 *
116 * 292 5/12/99 1:18p Samir
117 * play music during game too when in menus.
118 *
119 * 291 5/11/99 10:59a Kevin
120 * ship allow/disallow in multi works now
121 *
122 * 290 5/10/99 9:25p Jeff
123 * first phase of Rock 'n' Ride support added
124 *
125 * 289 5/10/99 10:29a Samir
126 * moved StopAllSounds in EndLevel so that both single and multiplayer
127 * stop sounds at the end of a level. (interplay bug).
128 *
129 * 288 5/10/99 3:37a Matt
130 * When starting a level, delete all the viewer objects in the level.
131 *
132 * 287 5/09/99 2:34p Jason
133 * fixed hanging of clients when dedicated server quits
134 *
135 * 286 5/08/99 4:30a Jeff
136 * fixed sequencing bug where clients never got a level end event for the
137 * multiplayer games
138 *
139 * 285 5/07/99 5:39p Samir
140 * better error checking for CheckAndForceDataAlloc for PageInSound.
141 *
142 * 284 5/07/99 5:06p Jason
143 * some dedicated server memory optimizations
144 *
145 * 283 5/07/99 2:50p Jason
146 * fixed a bunch of endlevel multiplayer issues
147 *
148 * 282 5/06/99 4:12p Jason
149 * fixed automap getting cleared after loading a savegame
150 *
151 * 281 5/05/99 6:48p Samir
152 * made pause key take down the pause window as well.
153 *
154 * 280 5/05/99 12:23p Jason
155 * fixed some problems with ending levels
156 *
157 * 279 5/05/99 12:02p Kevin
158 * fixed bug with branching missions and scripts
159 *
160 * 278 5/05/99 1:32a Jeff
161 * save/restore player energy also
162 *
163 * 277 5/05/99 1:28a Jeff
164 * save/restore player's shields in single player game if they are over
165 * 100
166 *
167 * 276 5/04/99 10:47p Samir
168 * added secret level screen.
169 *
170 * 275 5/04/99 4:34p Jason
171 * changes for bumpmapping
172 *
173 * 274 5/03/99 3:35p Kevin
174 * bug fixes
175 *
176 * 273 5/01/99 5:52p Samir
177 * removed RenderHudMessages, and redid RenderHUDMessages so it did what
178 * RenderHudMessages did, resets on screen hud messages. The HUD message
179 * console is resetted in ResetGameMessages.
180 *
181 * 272 4/30/99 12:02p Matt
182 * Keep the rear view up between levels, but close the other camera views.
183 *
184 * 271 4/29/99 11:46p Jason
185 * added ability to set the next level in a multiplayer game
186 *
187 * 270 4/29/99 4:59p Jason
188 * fixed some preuploaded texture problems
189 *
190 * 269 4/28/99 3:33a Jeff
191 * reset IGC system on level load, just for sanity
192 *
193 * 268 4/27/99 6:09p Samir
194 * SetCurrentLevel called for secret levels too.
195 *
196 * 267 4/25/99 6:14p Kevin
197 * added "-timetest file.dem" to behave like gamegauge does
198 *
199 * 266 4/25/99 3:35a Jeff
200 * added a please wait popup dialog when entering telcom
201 *
202 * 265 4/23/99 10:34p Kevin
203 * fixed bad things with multiple CD code
204 *
205 * 264 4/23/99 8:26p Samir
206 * fixed stupid clearscreen bug in endlevel
207 *
208 * 263 4/22/99 9:53a Kevin
209 * Fixed some dedicated server crashes
210 *
211 * 262 4/20/99 6:55p Matt
212 * Added code to keep a bitmask of all keys held by all players, and to
213 * allow a robot to open a door if any player has the key(s) for that
214 * door.
215 *
216 * 261 4/20/99 3:32p Kevin
217 * new prepare for descent behaivor
218 *
219 * 260 4/20/99 2:59p Jeff
220 * fixed SimpleStartLevel
221 *
222 * 259 4/20/99 11:45a Samir
223 * added autosave
224 *
225 * 258 4/17/99 3:44p Kevin
226 * Demo2 changes & fixes
227 *
228 * 257 4/16/99 4:30p Kevin
229 * New Training mission exit code
230 *
231 * 256 4/16/99 12:33a Matt
232 * Disable Soar on non-Windows systems.
233 *
234 * 255 4/15/99 3:26p Samir
235 * stop all sounds when quitting game, so that resume game doesn't
236 * playback any sounds.
237 *
238 * 254 4/15/99 2:47p Kevin
239 * doh! I forgot args.h
240 *
241 * 253 4/15/99 2:43p Kevin
242 * Added some things that I put into the demo for HEAT.NET
243 *
244 * 252 4/15/99 2:37p Kevin
245 * Fixed multi-cd problem going from cd 2 - 1
246 *
247 * 251 4/15/99 1:39a Jeff
248 * changes for linux compile
249 *
250 * 250 4/14/99 6:55p Matt
251 * Fixed secret level sequencing bug
252 *
253 * 249 4/14/99 3:07p Kevin
254 * Fixed some multiple CD bugs
255 *
256 * 248 4/14/99 2:50a Jeff
257 * fixed some case mismatched #includes
258 *
259 * 247 4/12/99 7:15p Samir
260 * prioritization pass 1
261 *
262 * 246 4/12/99 5:57p Kevin
263 * Fixed a sequencing bug with branching levels
264 *
265 * 245 4/08/99 4:21p Samir
266 * clear screen before ending level.
267 *
268 * 244 4/08/99 3:12p Matt
269 * Finished cleaning up level sequencing code. Got rid of all the "level
270 * minus one" stuff.
271 *
272 * 243 4/07/99 3:40p Kevin
273 * Fixes for Beta 1
274 *
275 * 242 4/07/99 12:30p Matt
276 * Added code for failed missions.
277 *
278 * 241 4/06/99 10:44p Samir
279 * Always stop music system when loading new level.
280 *
281 * 240 4/05/99 10:54a Matt
282 * Added auto-waypoint system
283 *
284 * 239 4/04/99 8:15p Jeff
285 * added debug graph stuff
286 *
287 * 238 4/03/99 5:05p Samir
288 * added ENDMISSION keyword to end a mission after a certain level.
289 *
290 * 237 3/25/99 4:57p Jason
291 * fixed resetplayerobject bug
292 *
293 * 236 3/25/99 11:57a Jason
294 * changed some sequencing bugs
295 *
296 * 235 3/24/99 11:55a Jason
297 * added S3 texture compression
298 *
299 * 234 3/24/99 10:54a Kevin
300 * Fixed some problems related to splitting up the main d3.mn3 file across
301 * 2 CDs
302 *
303 * 233 3/23/99 11:52a Jason
304 * added preliminary S3 texture compression support
305 *
306 * 232 3/19/99 4:08p Kevin
307 * Multiple CD installation support
308 *
309 * 231 3/11/99 12:06p Jason
310 * fixed triple buffering problem
311 *
312 * 230 3/10/99 7:12p Jason
313 * added smooth specular shading for curved surfaces
314 *
315 * 229 3/08/99 4:31p Kevin
316 * Fixed interlevel sequencing problem with branching multiplayer
317 * missions.
318 *
319 * 228 3/08/99 3:24p Jeff
320 * fixed end level sequencing where if the level ended while the player
321 * was dead.
322 *
323 * 227 3/05/99 7:42p Kevin
324 * Doh! we weren't resetting timers!!
325 *
326 * 226 3/03/99 2:35a Jeff
327 * clear hud messages at the end of level
328 *
329 * 225 3/03/99 12:56a Kevin
330 * removed assert that was causing problems
331 *
332 * 224 2/28/99 3:24a Samir
333 * call OptionsMenu.
334 *
335 * 223 2/25/99 8:54p Jeff
336 * Inventory supports level change persistant items. Inventory supports
337 * time-out objects. Inventory Reset changed (takes a level of reset
338 * now). Quad lasers stay across level change (single player). Guidebot
339 * bug fixed (now back in ship on level start). Quads time out when
340 * spewed. Invulnerability and cloak powerups no longer use game
341 * event/callbacks, so they can be saved in game saves (moved to
342 * MakePlayerInvulnerable and MakeObjectInvisible)
343 *
344 * 222 2/24/99 3:15p Kevin
345 * OEM menu changes, and bug fixes for the save/load system
346 *
347 * 221 2/24/99 9:57a Kevin
348 * Added error messages if you try to save a game while in multi
349 *
350 * 220 2/21/99 12:18p Chris
351 * Improving the level goal system... Not done.
352 *
353 * 219 2/21/99 4:20p Matt
354 * Added SoundSource objects (and reformatted parts of the object header
355 * files).
356 *
357 * 218 2/21/99 12:28p Matt
358 * Added terrain sound system
359 *
360 * 217 2/20/99 9:22p Jeff
361 * finished telcom level goals screen. Made it so if you go into the
362 * telcom from the game it goes to main menu instead of briefings.
363 *
364 * 216 2/20/99 4:11p Jeff
365 * fixed cockpit selection bug again (which cockpit to use depending on
366 * multi or single)
367 *
368 * 215 2/20/99 2:31p Kevin
369 * Made multiplayer DLLs return to the game list after a game.
370 *
371 * 214 2/20/99 2:17p Matt
372 * Added texture sounds
373 *
374 * 213 2/19/99 12:01p Jason
375 * took out sky band
376 *
377 * 211 2/16/99 12:38p Kevin
378 * Improved paging data progress indicator
379 *
380 * 210 2/16/99 11:13a Jason
381 * fixed bug in cockpit initialization code
382 *
383 * 209 2/15/99 7:49p Jeff
384 * new pilot file class and read/write system checked in...should be more
385 * robust than old
386 *
387 * 208 2/14/99 8:06p Jeff
388 * start of new pilot read/write...not working yet, still needs work
389 *
390 * 207 2/12/99 3:54a Jeff
391 * added function to restart a level, and a cheat key to do so (del-alt-e)
392 *
393 * 205 2/10/99 4:56p Kevin
394 * Better progress indicator & prepare for Descent message
395 *
396 * 204 2/10/99 3:47p Jason
397 * table filter changes
398 *
399 * 203 2/10/99 1:47p Matt
400 * Changed object handle symbolic constants
401 *
402 * 202 2/10/99 10:58a Kevin
403 * doh!
404 *
405 * 201 2/10/99 10:56a Kevin
406 * Took out loadlevelcb calls for now
407 *
408 * 200 2/09/99 7:01p Kevin
409 * First work for new and improved progress screen while loading a level.
410 * Note that this is a hack at this point, while I get the details worked
411 * out, then I'll make it cleaner.
412 *
413 * 199 2/05/99 7:23p Kevin
414 * OEM Changes
415 *
416 * 198 2/04/99 12:35p Jeff
417 * free in-game cinematics when level ends
418 *
419 * 197 2/01/99 6:14p Kevin
420 * Moved InitLevelScripts to later in the sequence
421 *
422 * 196 2/01/99 3:57p Samir
423 * fixed bug in secret levels.
424 *
425 * 195 2/01/99 12:44p Jason
426 * added another bumpmapping pass
427 *
428 * 194 2/01/99 10:35a Matt
429 * Fixed the initial player position in the game when playing from the
430 * editor.
431 *
432 * 193 1/31/99 7:25p Matt
433 * Renamed a bunch of functions to have HUD capitalized
434 *
435 * 192 1/31/99 3:44p Matt
436 * Streamlined game sequencing
437 *
438 * 191 1/29/99 6:29p Jason
439 * first pass at adding bumpmaps
440 *
441 * 190 1/29/99 2:08p Jeff
442 * localization
443 *
444 * 189 1/29/99 12:48p Matt
445 * Rewrote the doorway system
446 *
447 * 188 1/28/99 11:32a Jason
448 * added marker cameras
449 *
450 * 187 1/22/99 3:59p Jason
451 * added 256x256 textures to help with terrain skies
452 *
453 * 186 1/21/99 11:15p Jeff
454 * pulled out some structs and defines from header files and moved them
455 * into seperate header files so that multiplayer dlls don't require major
456 * game headers, just those new headers. Side effect is a shorter build
457 * time. Also cleaned up some header file #includes that weren't needed.
458 * This affected polymodel.h, object.h, player.h, vecmat.h, room.h,
459 * manage.h and multi.h
460 *
461 * 185 1/20/99 4:20p Samir
462 * finished secret level implementation.
463 *
464 * 184 1/20/99 10:50a Jason
465 * added new terrain
466 *
467 * 183 1/19/99 11:25a Jason
468 * added room (fog and wind) changing functions
469 *
470 * 182 1/15/99 7:16p Kevin
471 * Added GameGauge Configuration & code
472 *
473 * 181 1/14/99 3:08p Jason
474 * more cache changes
475 *
476 * 180 1/14/99 3:05p Jason
477 * fixed stupid texture data bug
478 *
479 * 179 1/14/99 2:26p Jason
480 * made data tracking more reliable
481 *
482 * 178 1/13/99 2:28a Chris
483 * Massive AI, OSIRIS update
484 *
485 * 177 1/08/99 2:55p Samir
486 * Ripped out OSIRIS1.
487 *
488 * 176 1/04/99 6:45p Jason
489 * took out paging return
490 *
491 * 175 12/29/98 4:30p Jason
492 * added add-on data functionality
493 *
494 * 174 12/28/98 5:56p Jason
495 * don't page in data if editor
496 *
497 * 173 12/23/98 1:25p Chris
498 * Got the FIRST AI working!!!!!!!! I need to rearrange the sequencing so
499 * that the AIInitAll wouldn't reset objects AFTER there EVT_AI_INIT was
500 * called.
501 *
502 * 172 12/21/98 3:33p Samir
503 * level warp fully implemented.
504 *
505 * 171 12/21/98 9:44a Chris
506 * Ambient life stuff is all tied in to game sequencing
507 *
508 * 170 12/18/98 5:40p Chris
509 * Ambient life is now all sequenced up
510 *
511 * 169 12/15/98 4:28p Jeff
512 * added mission data information to the pilot files to save what the
513 * highest level they achieved on a mission is. Added level select dialog
514 * (not hooked up) and level warp cheat.
515 *
516 * 168 12/14/98 11:57a Jason
517 * changes for visibile automap
518 *
519 * 167 12/03/98 12:50p Samir
520 * music file loaded at beginning of level.
521 *
522 * 166 11/19/98 5:40p Kevin
523 * Demo system
524 *
525 * 165 11/16/98 12:19p Samir
526 * pause and resume sounds until first frame of level.
527 *
528 * 164 11/13/98 2:28p Samir
529 * new music system.
530 *
531 * 163 11/09/98 3:08p Kevin
532 * Added demo code
533 *
534 * 162 11/05/98 7:36p Samir
535 * rearranged some sequencing so that common editor/game code gets called,
536 * and moved redundant game screen init code to StartNewLevel.
537 *
538 * 161 11/05/98 5:54p Kevin
539 * Demo system work
540 *
541 * 160 10/30/98 3:44p Samir
542 * reset multi_ui_bail.
543 *
544 * 159 10/23/98 12:51p Samir
545 * added call to SetHudMode so that level sequencing maintains the hud.
546 *
547 * 158 10/22/98 8:31p Chris
548 * Sounds use GlobalAlloc and GlobalFree
549 *
550 * 157 10/22/98 5:46p Jason
551 * took care of remaining page-in issues
552 *
553 * 156 10/22/98 4:11p Samir
554 * took out ifdef DEMO for inventory.
555 *
556 * 155 10/22/98 3:30p Samir
557 * fixed for editor the hud.
558 *
559 * 154 10/22/98 2:40p Samir
560 * redid HUD sequencing so multiplayer hud stuff works.
561 *
562 * 153 10/22/98 1:30a Jeff
563 * (Samir) ifdefed out guidebot interface for demo
564 *
565 * 152 10/21/98 9:28p Jason
566 * Made no lightmaps work globally
567 *
568 * 151 10/21/98 7:04p Samir
569 * moved init hud and cockpit to init level
570 *
571 * 150 10/21/98 6:53p Jason
572 * changes for shitty direct3d cards
573 *
574 * 149 10/21/98 4:52p Jeff
575 * disallow Automap for Demo
576 *
577 * 148 10/21/98 1:37p Jason
578 * fixed naming bug
579 *
580 * 147 10/21/98 12:05p Jason
581 * changes for data paging
582 *
583 * 146 10/21/98 10:35a Samir
584 * cleaned up GameInterface code.
585 *
586 * 145 10/20/98 8:48p Sean
587 * Don't call ResetPlayerObject() when playing from the editor, since that
588 * caused the player to move to the start position. (MattT on Sean's
589 * machine.)
590 *
591 * 144 10/20/98 6:50p Matt
592 * Fixed small bug paging in object animation sounds.
593 *
594 * 143 10/20/98 2:53a Kevin
595 * gunboy crap
596 *
597 * 142 10/20/98 12:11a Chris
598 *
599 * 141 10/19/98 11:22p Samir
600 * clear screen after UI.
601 *
602 * 140 10/19/98 11:06p Kevin
603 *
604 * 139 10/19/98 8:51p Matt
605 * Added missing period in pause message.
606 *
607 * 138 10/19/98 7:45p Matt
608 *
609 * 137 10/19/98 5:40p Samir
610 * added loading level callback.
611 *
612 * 136 10/19/98 12:12p Samir
613 * call ResetPlayerObject from StartNewLevel.
614 *
615 * 135 10/19/98 11:57a Chris
616 * Update the sound system to use the import volume
617 *
618 * 134 10/18/98 11:11p Matt
619 * Added call to ClearTransientObjects() and cleaned up some sequencing
620 * stuff.
621 *
622 * 133 10/18/98 7:27p Samir
623 * flush controller at start of every level.
624 *
625 * 132 10/16/98 4:03p Matt
626 * Fixed run-on in pause message.
627 *
628 * 131 10/15/98 8:32p Matt
629 * Fixed bug with starting abient sounds that caused rooms & other
630 * non-generic objects to have ambient sounds.
631 *
632 * 130 10/14/98 6:40p Samir
633 * write pilot files out at quitting game.
634 *
635 * 129 10/12/98 3:02p Jeff
636 * moved DEFAULT_SHIP #define into ship.h
637 *
638 * 128 10/12/98 11:15a Samir
639 * changed some sequencing stuff in GAMESTATE_LVLSTART.
640 *
641 * 127 10/09/98 4:13p Matt
642 * Use different default ship for the demo
643 *
644 * 126 10/08/98 8:01p Nate
645 * got rid of warning.
646 *
647 * 125 10/08/98 7:29p Samir
648 * revamped sequencing.
649 *
650 * 124 10/08/98 2:33p Kevin
651 *
652 * 123 10/08/98 2:29p Kevin
653 * fixed bad if statement
654 *
655 * 122 10/08/98 12:00p Kevin
656 * Demo system work
657 *
658 * 121 10/07/98 12:22p Jason
659 *
660 * 120 10/06/98 5:45p Kevin
661 * Added new configuration for demo
662 *
663 * 119 10/06/98 2:38p Jeff
664 * fixed paused message
665 *
666 * 118 10/05/98 12:09p Kevin
667 * Converted projects to VC6 and demo file stuff added
668 *
669 * 117 10/02/98 3:40p Chris
670 * Improved the level goal code
671 *
672 * 116 9/28/98 2:15p Kevin
673 * Changed calls to network idle function
674 *
675 * 115 9/28/98 11:02a Kevin
676 * added Networking defer, and fixed some UI issues
677 *
678 * 114 9/28/98 10:55a Jason
679 * fixed some bugs that VC6 caught
680 *
681 * 113 9/25/98 4:55p Jason
682 * flush all multiplayer buffers at the start of a new level
683 *
684 * 112 9/17/98 3:31p Samir
685 * if level is ending, freethislevel gets called twice (at EndLevel, and
686 * QuitToMenu), so make sure we don't freelevel in latter case.
687 *
688 * 111 9/16/98 5:10p Jason
689 * added first pass at thrid-person camera system
690 *
691 * 110 9/15/98 4:31p Jason
692 * added more functionality for the dedicated server
693 *
694 * 109 9/10/98 3:07p Chris
695 * Improved matcen sequencing code and test effect1
696 *
697 * 108 9/10/98 12:55p Chris
698 * Added pre-level initialization for matcens :)
699 *
700 * 107 9/09/98 1:08p Jeff
701 * commented out call to FlushDataCache in FreeThisLevel
702 *
703 * 106 9/08/98 3:25p Matt
704 * Fixed, hopefully, problems with getting the the player position &
705 * orientation back to the editor when playing from the editor.
706 *
707 * 105 9/08/98 12:05p Jason
708 * moved doorway.h out of room.h
709 *
710 * 104 9/08/98 10:28a Samir
711 * added function to deinitialize a level.
712 *
713 * 103 9/03/98 12:11p Chris
714 * Adding matcen support
715 *
716 * 102 8/29/98 6:53p Jeff
717 * added single-player ship selection
718 *
719 * 101 8/28/98 1:34p Matt
720 * Added code to reset the waypoint when starting a new level, and while I
721 * was at it cleaned up the new level start sequencing.
722 *
723 * 100 8/27/98 2:51p Jeff
724 * made it so SHIFT-ESC exits the TelCom back to Main Menu
725 *
726 * 99 8/26/98 1:48a Chris
727 * Fixed odd non-stopping sounds when ESC out of the game - etc.
728 *
729 * 98 8/24/98 2:45p Jason
730 * tweaks to the data cache stuff
731 *
732 * 97 8/24/98 10:42a Jason
733 * more memory paging issues dealt with
734 *
735 * 96 8/21/98 8:28p Samir
736 * made FlushDataCache bail if in the editor
737 *
738 * 95 8/21/98 5:14p Jason
739 * made better memory use of primitives
740 *
741 * 94 8/21/98 3:02p Jason
742 * better paging in of weapons stuff
743 *
744 * 93 8/20/98 10:52a Samir
745 * added load game(restore game) functionality from main menu.
746 *
747 * 92 8/19/98 6:39p Samir
748 * took out null of Current_level.
749 *
750 * 91 8/19/98 5:36p Samir
751 * pause game when in load game state.
752 *
753 * 90 8/18/98 3:02p Samir
754 * new sequencing for LoadGameState and PLEASE define Current_level some
755 * other way (or at least keep the definition in StartNewLebvel)
756 *
757 * 89 8/18/98 1:50p Matt
758 * Added missing ambient sound init
759 *
760 * 88 8/18/98 1:05a Samir
761 *
762 * 87 8/17/98 6:40p Matt
763 * Added ambient sound system
764 *
765 * 86 8/16/98 5:56p Jeff
766 * added game interface for multiplayer dll ui stuff
767 *
768 * 85 8/10/98 6:19p Jason
769 * Reset all doorways at the beginning of a level
770 *
771 * 84 8/10/98 2:21p Jeff
772 * changes made due to adding flag for inventory reset
773 *
774 * 83 8/04/98 2:32p Chris
775 * Improved attach code added more fixes to the AABB partial computation
776 * patch
777 *
778 * 82 7/31/98 5:19p Samir
779 * mission filenames are dynamically allocated now to allow for pathnames
780 * (since we'd have too many 256 char arrays per level.
781 *
782 * 81 7/28/98 5:41p Samir
783 * music system hooks.
784 *
785 * 80 7/20/98 12:04p Jason
786 * added per level satellite lighting
787 *
788 * 79 6/29/98 6:42p Samir
789 * Properly handle controller pausing and resumption.
790 *
791 * 78 6/25/98 5:22p Kevin
792 * Req/Send gametime to clients
793 *
794 * 77 6/25/98 12:43p Jeff
795 * Added exit game confirmation
796 *
797 * 76 6/24/98 5:18p Matt
798 * Added code for user pausing
799 *
800 * 75 6/23/98 11:10p Matt
801 * Simplified some code
802 *
803 * 74 6/19/98 3:03p Chris
804 * Made CheckAndForceSoundDataAlloc a SoundSystem function - useful for
805 * multiple mixers. Added IsSoundPlaying to the high level sound lib.
806 *
807 * 73 6/16/98 10:38a Jeff
808 * localization, strings pulled out to stringtable.h and d3.str
809 *
810 * 72 6/15/98 10:54a Chris
811 * All sounds stop at the end of a level
812 *
813 * 71 5/27/98 12:36a Samir
814 * print out message saying demo will restart in x minutes for E3.
815 *
816 * 70 5/26/98 11:03p Chris
817 *
818 * 69 5/26/98 10:54p Chris
819 * Ooops again
820 *
821 * 68 5/26/98 10:49p Samir
822 * reset level timer limit for E3.
823 *
824 * 67 5/26/98 10:42p Chris
825 * Fixed door sound paging
826 *
827 * 66 5/26/98 10:21p Chris
828 * Added door sound paging
829 *
830 * 65 5/26/98 10:16p Jason
831 * Precache terrain lod bitmaps
832 *
833 * 64 5/26/98 5:04p Samir
834 * took out calls to SetHudMode (called in SetScreenMode)
835 *
836 * 63 5/26/98 2:49p Jason
837 * fixed FOV bug
838 *
839 * 62 5/25/98 8:29p Samir
840 * moved call to postlevel results to EndLevel function.
841 *
842 * 61 5/25/98 3:46p Jason
843 * added better light glows
844 *
845 * 60 5/24/98 2:55a Jeff
846 * added paramter to MenuOptions()
847 *
848 * 59 5/22/98 12:34p Matt
849 * Added scorch mark/bullet hole system.
850 *
851 * 58 5/21/98 2:32p Samir
852 * added full support for intra-mission level branching.
853 *
854 * 57 5/18/98 4:36p Jeff
855 * TelCom uses Game_interface_mode variable now
856 *
857 * 56 5/17/98 4:08p Chris
858 * Fixed bugs with initial sound loading. :)
859 *
860 * 55 5/15/98 5:18p Chris
861 * Working on sound paging
862 *
863 * 54 5/15/98 5:07p Chris
864 * Fixed some bugs in sound paging
865 *
866 * 53 5/14/98 3:18p Jason
867 * finished multiplayer sequencing issues
868 *
869 * 52 5/14/98 11:49a Chris
870 * Bettered the sound paging system
871 *
872 * 51 5/12/98 4:18p Jason
873 * added better level sequencing for multiplayer
874 *
875 * 50 5/12/98 12:33p Jason
876 * got level sequencing working in multiplayer
877 *
878 * 49 5/11/98 6:19p Samir
879 * hide cursor when entering game.
880 *
881 * 48 5/11/98 4:14p Samir
882 * set ui callback to NULL when just entering game....
883 *
884 * 47 5/11/98 11:31a Jason
885 * added some events for level sequencing
886 *
887 * 46 5/05/98 5:16p Samir
888 * moved loading level message to this file.
889 *
890 * 45 5/01/98 4:24p Samir
891 * open cockpit fully if current hud mode is cockpit at start of level.
892 *
893 * 44 4/24/98 5:31p Samir
894 * reset reticle at game start
895 *
896 * 43 4/24/98 1:53a Samir
897 * took care of a lot of scripting memory leaks.
898 *
899 * 42 4/21/98 4:16a Samir
900 * clear out obj_text array in level node for simple start level.
901 *
902 * 41 4/20/98 10:02a Chris
903 * Working on fixing AI/OSIRIS integration bugs
904 *
905 * 40 4/16/98 2:56p Chris
906 * Updated buddy support and intergrated scripting and AI
907 *
908 * 39 4/16/98 6:52a Samir
909 * took out cockpit init.free code
910 *
911 * 38 4/14/98 9:18p Samir
912 * redid post level results.
913 *
914 * 37 4/10/98 2:58p Chris
915 * Redid where the buddy gets allocated, not all the way done yet.
916 *
917 * 36 4/09/98 7:02p Chris
918 *
919 * 35 4/09/98 6:57p Craig
920 * FIxed a sequencing bug
921 *
922 * 34 4/07/98 4:25p Chris
923 * Added support for buddy bot
924 *
925 * 33 4/06/98 5:13p Chris
926 * Sounds page in at the beginning of a level
927 *
928 * 32 4/06/98 12:14p Jason
929 * changes to multiplayer
930 *
931 * 31 4/03/98 3:36p Chris
932 * Added the start of the buddy menu
933 *
934 * 30 4/02/98 11:11a Samir
935 * Error checking for level load/misison init fail.
936 *
937 * 29 3/31/98 3:49p Jason
938 * added memory lib
939 *
940 * 28 3/27/98 5:06p Samir
941 * took out unnecessary mprintfs.
942 *
943 * 27 3/23/98 7:06p Chris
944 *
945 * 26 3/23/98 6:16p Chris
946 * added some soar_helpers and some debug mprintf's
947 *
948 * 25 3/17/98 2:40p Samir
949 * reorg of hud/gauge system.
950 *
951 * 24 3/13/98 12:37p Jeff
952 * start level at 0 for simplestartlevel.
953 *
954 * 23 3/13/98 12:08p Samir
955 * Added SimpleStartLevel.
956 *
957 * 22 3/05/98 2:51p Jeff
958 * Added Help interface
959 *
960 * 21 3/05/98 2:50p Chris
961 * A bunch of SOAR updates
962 *
963 * 20 3/03/98 12:10p Samir
964 * Added simple pausing.
965 *
966 * 19 3/02/98 5:52p Samir
967 * Added game interface system.
968 *
969 * 18 2/23/98 1:59p Jason
970 * touch terrain textures when initting a level
971 *
972 * 17 2/18/98 3:25p Samir
973 * Added test systems code.
974 *
975 * 16 2/18/98 1:19a Samir
976 * DoLevelIntro now bails at the right place if we're in multiplayer mode.
977 *
978 * 15 2/17/98 8:26p Chris
979 *
980 * 14 2/17/98 7:48p Chris
981 *
982 * 13 2/17/98 7:47p Chris
983 *
984 * 12 2/17/98 4:42p Samir
985 * Current_level is now defined after calling DoLevelIntro.
986 *
987 * 11 2/17/98 2:22p Jason
988 * fixed multiplayer sequencing with briefings
989 *
990 * 10 2/17/98 12:20p Chris
991 * Made sounds not get paged out at end/beginning of level
992 *
993 * 9 2/13/98 6:43p Samir
994 * ifdef out editor code iin GameSequencer.
995 *
996 * 8 2/13/98 12:40p Jason
997 * added functions to touch all data in a level when the level is loaded
998 *
999 * 7 2/13/98 10:57a Samir
1000 * Changed some gamescript initialization.
1001 *
1002 * 6 2/12/98 6:51p Matt
1003 * Renamed GameLoop() to be GameFrame(), cleaned up the StartTime/StopTime
1004 * system, and moved the interval script call to GameFrame().
1005 *
1006 * 5 2/12/98 5:08p Matt
1007 * Reset cockpit mode when starting a level. Unfortunately, this involved
1008 * some semi-major mucking with game sequencing.
1009 *
1010 * 4 2/11/98 4:36p Samir
1011 * Call SetGameMode to modify game mode.
1012 *
1013 * 3 2/09/98 3:58p Matt
1014 * Initialize small views and camera views at level start
1015 *
1016 * 2 2/08/98 5:01p Samir
1017 * New game sequencing changes.
1018 *
1019 * 1 2/08/98 3:54p Samir
1020 * Initial revision.
1021 *
1022 * $NoKeywords: $
1023 */
1024 #ifdef USE_PROFILER
1025 #include <profiler.h>
1026 #endif
1027
1028 #include "gamesequence.h"
1029
1030 #include "game.h"
1031 #include "gameloop.h"
1032 #include "descent.h"
1033 #include "player.h"
1034 #include "Mission.h"
1035 #include "BOA.h"
1036 #include "gameevent.h"
1037 #include "AIMain.h"
1038
1039 #include "soar_helpers.h"
1040
1041 #include "terrain.h"
1042 #include "hlsoundlib.h"
1043 #include "SmallViews.h"
1044 #include "polymodel.h"
1045 #include "gametexture.h"
1046 #include "hud.h"
1047 #include "findintersection.h"
1048 #include "menu.h"
1049 #include "newui.h"
1050 #include "cockpit.h"
1051 #include "help.h"
1052 #include "buddymenu.h"
1053 #include "mem.h"
1054 #include "soundload.h"
1055 #include "robot.h"
1056 #include "screens.h"
1057 #include "game2dll.h"
1058 #include "ship.h"
1059 #include "TelCom.h"
1060 #include "scorch.h"
1061 #include "render.h"
1062 #include "stringtable.h"
1063 #include "ddio_common.h"
1064 #include "gamesave.h"
1065 #include "sounds.h"
1066 #include "ambient.h"
1067 #include "vclip.h"
1068 #include "pilot.h"
1069 #include "doorway.h"
1070 #include "matcen.h"
1071 #include "dedicated_server.h"
1072 #include "networking.h"
1073 #include "levelgoal.h"
1074 #include "demofile.h"
1075 #include "lightmap_info.h"
1076 #include "lightmap.h"
1077 #include "fireball.h"
1078 #include "d3music.h"
1079 #include "TelComAutoMap.h"
1080 #include "aiambient.h"
1081 #include "ObjScript.h"
1082 #include "marker.h"
1083 #include "gamecinematics.h"
1084 #include "osiris_dll.h"
1085 #include "debuggraph.h"
1086 #include "multi_dll_mgr.h"
1087 #include "multi_ui.h"
1088 #include "gamepath.h"
1089 #include "vclip.h"
1090 #include "bsp.h"
1091
1092 #include "args.h"
1093 void ResetHudMessages(void);
1094
1095 // Variables
1096 tGameState Game_state = GAMESTATE_IDLE; // current game state.
1097 tGameState Last_game_state = GAMESTATE_IDLE; // previous frame game state.
1098 int Game_interface_mode = GAME_INTERFACE; // game interface mode (options menu?)
1099
1100 extern bool FirstGame;
1101
1102 static bool Level_started = false;
1103 static int Level_warp_next = 0;
1104
1105 #ifdef E3_DEMO
1106 extern float E3_TIME_LIMIT;
1107 extern bool E3_enforce_level_restart;
1108 #endif
1109
1110 extern float Multi_Game_time_start;
1111
1112 extern bool Demo_looping;
1113 extern bool IsRestoredGame;
1114
1115 // internal functions
1116 bool StartNewGame(); // We start a game by using the current mission in memory.
1117 bool DoLevelIntro(); // shows movie and briefing
1118 void StartGameFromEditor(); // set up new game/new level stuff when playing from editor
1119 void EndLevel(int state); // ends the current level.
1120 void RestartLevel(); // restarts the current level.
1121 void RunGameMenu(); // executes a game menu.
1122 void FreeThisLevel(); // frees any data/esc that was created for that level.
1123 void FlushDataCache(); // Clears out all the level specific stuff from memory
1124 void SetNextLevel(); // advances to the next level
1125 void CheckHogfile(); // make sure we have the right hogfile
1126
1127 // Data paging functions
1128 void PageInAllData();
1129 void PageInLevelTexture(int);
1130 bool PageInSound(int);
1131 void PageInDoor(int);
1132 void PageInWeapon(int);
1133 void PageInGeneric(int);
1134 void PageInShip(int);
1135
1136 // Data allocation arrays, for keeping track of what textures/sounds are level specific
1137 uint8_t Models_to_free[MAX_POLY_MODELS];
1138 uint8_t Textures_to_free[MAX_TEXTURES];
1139 uint8_t Sounds_to_free[MAX_TEXTURES];
1140
1141 #ifdef EDITOR
1142 extern vector editor_player_pos;
1143 extern matrix editor_player_orient;
1144 extern int editor_player_roomnum;
1145 #endif
1146
1147 extern bool mn3_Open(const char *mn3file);
1148 extern void mn3_Close();
1149
1150 extern bool Game_gauge_do_time_test;
1151 extern char Game_gauge_usefile[_MAX_PATH];
1152
1153 ///////////////////////////////////////////////////////////////////////////////
1154 // Sequences game events
1155 ///////////////////////////////////////////////////////////////////////////////
1156 bool GameSequencer() {
1157 bool in_editor = (GetFunctionMode() == EDITOR_GAME_MODE);
1158 tGameState old_game_state;
1159
1160 // interpret current function mode.
1161 switch (GetFunctionMode()) {
1162 case INIT_MODE:
1163 case GAME_MODE:
1164 case EDITOR_MODE:
1165 case EDITOR_GAME_MODE:
1166 case MENU_MODE:
1167 case QUIT_MODE:
1168 case CREDITS_MODE:
1169 case GAMEGAUGE_MODE:
1170 break;
1171 case RESTORE_GAME_MODE:
1172 case LOADDEMO_MODE:
1173 SetFunctionMode(GAME_MODE); // need to do so sequencer thiks we're in game.
1174 break;
1175 }
1176
1177 // The main game sequencer
1178 while ((GetFunctionMode() == GAME_MODE) || (GetFunctionMode() == EDITOR_GAME_MODE)) {
1179 old_game_state = Game_state;
1180
1181 switch (Game_state) {
1182 case GAMESTATE_IDLE:
1183 break;
1184 case GAMESTATE_NEW:
1185 StartNewGame();
1186 SetGameState(GAMESTATE_LVLSTART);
1187 break;
1188
1189 case GAMESTATE_LVLSTART:
1190 CheckHogfile(); // make sure we have the right hogfile
1191
1192 if (in_editor) { // start in editor
1193 #ifdef EDITOR
1194 StartGameFromEditor();
1195 #endif
1196 } else { // start in game
1197 if (!DoLevelIntro() || !LoadAndStartCurrentLevel()) {
1198 if (Game_mode & GM_MULTI)
1199 MultiLeaveGame();
1200 MultiDLLGameStarting = 0;
1201 Multi_bail_ui_menu = false;
1202 SetFunctionMode(MENU_MODE); // return to main menu
1203 break;
1204 }
1205 }
1206
1207 SetGameState(GAMESTATE_LVLPLAYING);
1208 break;
1209
1210 case GAMESTATE_LVLPLAYING:
1211 // must do to display main menu interfaces
1212 if (Last_game_state == GAMESTATE_LVLSTART) {
1213 // 1st frame resume sounds.
1214 Sound_system.ResumeSounds();
1215 }
1216
1217 if (Game_interface_mode != GAME_INTERFACE) {
1218 RunGameMenu();
1219 } else {
1220 Descent->defer();
1221 GameFrame();
1222 }
1223 break;
1224
1225 case GAMESTATE_LOADDEMO:
1226 if (DemoPlaybackFile(Demo_fname)) {
1227 SetGameState(GAMESTATE_LVLPLAYING);
1228 } else {
1229 SetFunctionMode(MENU_MODE);
1230 }
1231 break;
1232 case GAMESTATE_LOADGAME:
1233 if (Game_mode & GM_MULTI) {
1234 DoMessageBox(TXT_ERROR, TXT_CANT_LOAD_MULTI, MSGBOX_OK);
1235 break;
1236 }
1237 D3MusicStop(); // make sure all music streams are stopped before restoring game.
1238 PauseGame();
1239 if (!LoadCurrentSaveGame()) {
1240 SetFunctionMode(MENU_MODE);
1241 } else {
1242 SetGameState(GAMESTATE_LVLPLAYING);
1243 SetScreenMode(SM_GAME);
1244 SetHUDMode(GetHUDMode());
1245 }
1246 ResumeGame();
1247 break;
1248
1249 case GAMESTATE_LVLEND:
1250 SuspendControls();
1251 EndLevel(1);
1252 SetGameState(GAMESTATE_LVLNEXT);
1253
1254 // This is for HEAT.NET and their tournement mode stuff
1255 // if(FindArg("-doonelevel"))
1256 // SetGameState(GAMESTATE_LVLSTART);
1257 if (FindArg("-doonelevel")) {
1258 SetFunctionMode(QUIT_MODE);
1259 }
1260
1261 break;
1262
1263 case GAMESTATE_LVLNEXT:
1264 SetNextLevel();
1265 SetGameState(GAMESTATE_LVLSTART);
1266 break;
1267
1268 case GAMESTATE_LVLWARP:
1269 SuspendControls();
1270 EndLevel(-1);
1271 SetCurrentLevel(Level_warp_next);
1272 SetGameState(GAMESTATE_LVLSTART);
1273 break;
1274
1275 case GAMESTATE_LVLFAILED:
1276 SuspendControls();
1277 EndLevel(0);
1278 SetGameState(GAMESTATE_LVLSTART); // restart same level
1279 break;
1280 }
1281 Last_game_state = old_game_state;
1282 }
1283
1284 #ifdef EDITOR // Ugly hack to get play position back to the editor
1285 if (Player_object && (Player_object->type == OBJ_PLAYER)) {
1286 editor_player_pos = Player_object->pos;
1287 editor_player_orient = Player_object->orient;
1288 editor_player_roomnum = Player_object->roomnum;
1289 } else
1290 editor_player_roomnum = -1;
1291 #endif
1292
1293 // free up scripts.
1294 PltWriteFile(&Current_pilot);
1295 FreeThisLevel();
1296
1297 SetGameMode(GM_NONE);
1298
1299 return true;
1300 }
1301
1302 // Make sure we have the correct hogfile
1303 void CheckHogfile() {
1304 char hogpath[_MAX_PATH * 2];
1305 mprintf(0, "Checking to see if we need to open another hog off of disk or CDROM\n");
1306
1307 if (Current_mission.filename && (stricmp(Current_mission.filename, "d3.mn3") == 0) &&
1308 (Current_mission.cur_level > 4)) {
1309 // close the mission hog file and open d3_2.mn3
1310 mn3_Close();
1311 ddio_MakePath(hogpath, D3MissionsDir, "d3_2.mn3", nullptr);
1312 if (cfexist(hogpath)) {
1313 mn3_Open(hogpath);
1314 mem_free(Current_mission.filename);
1315 Current_mission.filename = mem_strdup("d3_2.mn3");
1316 } else {
1317 SetFunctionMode(MENU_MODE);
1318 }
1319 } else if (Current_mission.filename && (stricmp(Current_mission.filename, "d3_2.mn3") == 0) &&
1320 (Current_mission.cur_level <= 4)) {
1321 // Part 2 of the mission is d3_2.mn3
1322 // close the mission hog file and open d3.mn3
1323 mn3_Close();
1324 ddio_MakePath(hogpath, D3MissionsDir, "d3.mn3", nullptr);
1325 if (cfexist(hogpath)) {
1326 mn3_Open(hogpath);
1327 mem_free(Current_mission.filename);
1328 Current_mission.filename = mem_strdup("d3.mn3");
1329 } else {
1330 SetFunctionMode(MENU_MODE);
1331 }
1332 }
1333 }
1334
1335 ///////////////////////////////////////////////////////////////////////////////
1336 // quickly sets up a mission of 1 level, and doesn't do any
1337 // fancy intro stuff
1338 bool SimpleStartLevel(char *level_name) {
1339 // this initializes a mini one level mission with no frills.
1340
1341 Current_mission.cur_level = 1;
1342 Current_mission.num_levels = 1;
1343 Current_mission.levels = (tLevelNode *)mem_malloc(sizeof(tLevelNode));
1344 memset(Current_mission.levels, 0, sizeof(tLevelNode));
1345
1346 Current_level = NULL;
1347 Current_mission.levels[0].filename = mem_strdup(level_name);
1348 InitMissionScript();
1349
1350 return true;
1351 }
1352
1353 ///////////////////////////////////////////////////////////////////////////////
1354 // We start a game by using the current mission in memory.
1355 // First we display the mission briefing (the intro movie for Descent 3, if not an add on)
1356 // Then we start level
1357 ///////////////////////////////////////////////////////////////////////////////
1358
1359 bool StartNewGame() {
1360 SetCurrentLevel(Current_mission.cur_level);
1361
1362 ResetGamemode();
1363
1364 if (!(Game_mode & GM_MULTI)) {
1365 Player_num = 0; // Reset player num
1366 Players[Player_num].ship_index = FindShipName(DEFAULT_SHIP);
1367 ASSERT(Players[Player_num].ship_index != -1);
1368 }
1369
1370 if (Game_mode & GM_MULTI)
1371 CallGameDLL(EVT_GAMECREATED, &DLLInfo);
1372
1373 // Load any addon data
1374 mng_LoadAddonPages();
1375
1376 InitPlayerNewShip(Player_num, INVRESET_ALL);
1377 InitPlayerNewGame(Player_num);
1378
1379 InitCameraViews(1); // Turn off all camera views, including rear views
1380
1381 Quicksave_game_slot = -1; // reset so that quicksave key will always go to savegame menu first
1382
1383 return true;
1384 }
1385
1386 // Shows the intro movie and briefing for a level
1387 bool DoLevelIntro() {
1388 tLevelNode *lvl = Current_level;
1389
1390 mprintf(0, "In DoLevelIntro()\n");
1391
1392 // multiplayer stuff (we skip the movie and briefings)
1393 if (Game_mode & GM_MULTI) {
1394 if (Netgame.local_role == LR_CLIENT) {
1395 // Clear out residual junk
1396 MultiFlushAllIncomingBuffers();
1397
1398 if (!MultiPollForLevelInfo()) {
1399 return false;
1400 }
1401 }
1402 return true;
1403 }
1404
1405 #ifdef STEALTH // DAJ just get started
1406 return true;
1407 #endif
1408 // if this level has a movie:
1409 if (lvl->flags & LVLFLAG_STARTMOVIE) {
1410 DoMissionMovie(Current_mission.levels[Current_mission.cur_level - 1].moviename);
1411 }
1412
1413 // if this level has a briefing:
1414 if (lvl->flags & LVLFLAG_BRIEFING) {
1415 if (!DoMissionBriefing(Current_mission.cur_level - 1)) {
1416 // quit exit to main menu
1417 return false;
1418 }
1419 }
1420 return true;
1421 }
1422
1423 // Sets the current level for subsequent level loads, movies, or briefings
1424 void SetCurrentLevel(int level) {
1425 ASSERT(level > 0 && level <= Current_mission.num_levels);
1426
1427 // Set this level as the mission's current level
1428 Current_mission.cur_level = level;
1429
1430 // Set pointer to this level
1431 Current_level = &Current_mission.levels[level - 1];
1432 }
1433
1434 void StartLevelSounds();
1435
1436 // Get rid of any viewer objects in the level
1437 void ClearViewerObjects() {
1438 int i;
1439 object *objp;
1440
1441 for (i = 0, objp = Objects; i <= Highest_object_index; i++, objp++)
1442 if (objp->type == OBJ_VIEWER) {
1443 mprintf(0, "Deleting viewer object %d\n", i);
1444 ObjDelete(i);
1445 }
1446 }
1447
1448 // If low or medium detail, delete all or some ambient objects
1449 void DeleteAmbientObjects() {
1450 int i, count;
1451 object *objp;
1452
1453 if (!(Game_mode & GM_MULTI) && Detail_settings.Object_complexity == 2) // high
1454 return;
1455
1456 for (i = 0, objp = Objects, count = 0; i <= Highest_object_index; i++, objp++) {
1457 if (IS_GENERIC(objp->type) && (Object_info[objp->id].flags & OIF_AMBIENT_OBJECT)) {
1458 if ((Detail_settings.Object_complexity == 0) || (count & 1) || (Game_mode & GM_MULTI))
1459 ObjDelete(i);
1460 count++;
1461 }
1462 }
1463 }
1464
1465 void Localization_SetLanguage(int type);
1466 int Localization_GetLanguage(void);
1467 void LoadLevelText(const char *level_filename);
1468
1469 // Starts the level, which has already been loaded
1470 void StartLevel() {
1471 extern void RestoreCameraRearviews(); // gameloop.cpp
1472
1473 // Init time
1474 Gametime = 0.0f;
1475
1476 // Make sure all sounds have stopped
1477 Sound_system.StopAllSounds();
1478
1479 // Get the data for this level
1480 PageInAllData();
1481
1482 // TEMP HACK
1483 if (rend_SupportsBumpmapping())
1484 Detail_settings.Bumpmapping_enabled = 1;
1485 else
1486 Detail_settings.Bumpmapping_enabled = 0;
1487
1488 // Initialize a bunch of stuff for this level
1489 MakeBOA();
1490 ComputeAABB(true);
1491
1492 // Clear/reset objects & events
1493 ClearAllEvents();
1494 ClearRoomChanges();
1495 ResetMarkers();
1496 ResetScorches();
1497 ResetWaypoint();
1498 ResetLightGlows();
1499 DoorwayDeactivateAll();
1500 ClearViewerObjects();
1501 DeleteAmbientObjects();
1502
1503 // AI, scripting, & Soar
1504 AIInitAll();
1505
1506 // Set up the player object
1507 ResetPlayerObject(Player_num);
1508
1509 DSSoarInit();
1510
1511 InitMatcensForLevel();
1512
1513 // What is this?
1514 a_life.InitForLevel();
1515
1516 // Start sound & music
1517 StartLevelSounds();
1518 Sound_system.PauseSounds(); // HACK!! pause sounds started up to now.
1519 D3MusicStart(Current_level->score);
1520
1521 // Get the list of waypoints from the waypoint objects
1522 MakeAtuoWaypointList();
1523
1524 // Test stuff
1525 #ifdef _DEBUG
1526 InitTestSystems();
1527 #endif
1528
1529 // Set screen mode
1530 SetScreenMode(SM_GAME);
1531
1532 // Init HUD and cockpit
1533 int ship_index;
1534
1535 if (Game_mode & GM_MULTI) {
1536 char ship_model[PAGENAME_LEN];
1537 Current_pilot.get_ship(ship_model);
1538 ship_index = FindShipName(ship_model);
1539 ASSERT(ship_index != -1); // DAJ -1FIX
1540 if (Netgame.local_role == LR_SERVER) {
1541 if (PlayerIsShipAllowed(Player_num, ship_model)) {
1542 Players[Player_num].ship_index = FindShipName(ship_model);
1543 ASSERT(Players[Player_num].ship_index != -1); // DAJ -1FIX
1544 } else {
1545 mprintf(0, "Player %d wanted to use a ship (%s) which wasn't allowed.\n", Player_num, ship_model);
1546 int i;
1547 bool found_one = false;
1548
1549 // Loop through ships, looking for one that's allowed
1550 for (i = 0; i < MAX_SHIPS && !found_one; i++) {
1551 if (Ships[i].used && PlayerIsShipAllowed(Player_num, i)) {
1552 Players[Player_num].ship_index = i;
1553 found_one = true;
1554 }
1555 }
1556
1557 // We should have found one
1558 ASSERT(found_one == true);
1559 }
1560 ship_index = Players[Player_num].ship_index;
1561 PlayerChangeShip(Player_num, ship_index);
1562 }
1563 } else {
1564 ship_index = Players[Player_num].ship_index;
1565 }
1566
1567 if (ship_index < 0)
1568 ship_index = 0;
1569 InitShipHUD(ship_index);
1570 InitCockpit(ship_index);
1571 if (GetHUDMode() == HUD_COCKPIT) // make sure cockpit is open, if hud mode is cockpit
1572 QuickOpenCockpit();
1573 ResetHUDMessages();
1574 ResetGameMessages();
1575 ResetReticle();
1576 ResetSmallViews(); // ResetSmallViews() must come before InitCameraViews()
1577 InitCameraViews(0); // ResetSmallViews() must come before InitCameraViews()
1578 RestoreCameraRearviews();
1579 SetHUDMode(GetHUDMode()); // what does this do?
1580
1581 // Init zoom
1582 Render_zoom = D3_DEFAULT_ZOOM;
1583
1584 // flush controller system.
1585 ResumeControls();
1586 Controller->flush();
1587
1588 Level_goals.InitLevel();
1589
1590 // Do multiplayer & player stuff
1591 if (Game_mode & GM_MULTI) {
1592 MultiStartNewLevel(Current_mission.cur_level);
1593 } else { // Init player for single-player
1594 DeleteMultiplayerObjects();
1595 InitPlayerNewLevel(Player_num);
1596 }
1597
1598 // Set flags
1599 Level_started = true;
1600 Multi_bail_ui_menu = false;
1601
1602 // Clear robot keys
1603 Global_keys = 0;
1604
1605 // Clear OSIRIS stuff
1606 Osiris_ResetAllTimers();
1607
1608 // Initialize IGC
1609 Cinematic_LevelInit();
1610
1611 // Bash the language to english
1612 int save_lang = Localization_GetLanguage();
1613 Localization_SetLanguage(LANGUAGE_ENGLISH);
1614
1615 // Load the English text so the goal stuff will initialize correctly
1616 LoadLevelText(Current_mission.levels[Current_mission.cur_level - 1].filename);
1617
1618 // Restore the correct language
1619 Localization_SetLanguage(save_lang);
1620
1621 // Init the level scripts
1622 InitLevelScript();
1623
1624 // Load the localized text
1625 LoadLevelText(Current_mission.levels[Current_mission.cur_level - 1].filename);
1626
1627 Gametime = 0.0f;
1628 // Start the clock
1629 InitFrameTime();
1630
1631 LoadLevelProgress(LOAD_PROGRESS_DONE, 0);
1632
1633 }
1634
1635 // Loads a level and starts everything up
1636 bool LoadAndStartCurrentLevel() {
1637 char hogpath[_MAX_PATH * 2];
1638 // This is a bit redundant because we just did it in most cases, but we need to be sure that it always happens,
1639 // and this code is here for weird systems, like save/load and demo, etc.
1640 if (Current_mission.filename && (stricmp(Current_mission.filename, "d3.mn3") == 0) &&
1641 (Current_mission.cur_level > 4)) {
1642 // close the mission hog file and open d3_2.mn3
1643 mn3_Close();
1644 ddio_MakePath(hogpath, D3MissionsDir, "d3_2.mn3", nullptr);
1645 if (cfexist(hogpath)) {
1646 mn3_Open(hogpath);
1647 mem_free(Current_mission.filename);
1648 Current_mission.filename = mem_strdup("d3_2.mn3");
1649 } else {
1650 SetFunctionMode(MENU_MODE);
1651 }
1652 } else if (Current_mission.filename && (stricmp(Current_mission.filename, "d3_2.mn3") == 0) &&
1653 (Current_mission.cur_level <= 4)) {
1654 // Part 2 of the mission is d3_2.mn3
1655 // close the mission hog file and open d3.mn3
1656 mn3_Close();
1657 ddio_MakePath(hogpath, D3MissionsDir, "d3.mn3", nullptr);
1658 if (cfexist(hogpath)) {
1659 mn3_Open(hogpath);
1660 mem_free(Current_mission.filename);
1661 Current_mission.filename = mem_strdup("d3.mn3");
1662 } else {
1663 SetFunctionMode(MENU_MODE);
1664 }
1665 }
1666
1667 // load the level. if fails, then bail out
1668 // ShowProgressScreen (TXT_LOADINGLEVEL);
1669 if (!LoadMissionLevel(Current_mission.cur_level))
1670 return false;
1671
1672 AutomapClearVisMap();
1673
1674 // Now start the level
1675 StartLevel();
1676
1677 // Done!
1678 return true;
1679 }
1680
1681 #ifdef EDITOR
1682 // Called to do game initialization stuff when playing from the editor
1683 // Mostly, this will be the same stuff as StartNewLevel()
1684 void StartGameFromEditor() {
1685 // Set up the player ship
1686 InitPlayerNewShip(Player_num, INVRESET_ALL);
1687
1688 // Start the level
1689 StartLevel();
1690
1691 // Move the player to the editor viewer position
1692 ObjSetPos(Player_object, &editor_player_pos, editor_player_roomnum, &editor_player_orient, false);
1693 }
1694 #endif
1695
1696 void ComputeCenterPointOnFace(vector *vp, room *rp, int facenum);
1697
1698 // Start object ambient sounds
1699 void StartObjectSounds() {
1700 for (int i = 0; i < MAX_OBJECTS; i++) {
1701 object *objp = &Objects[i];
1702
1703 // If generic object, check for ambient sound
1704 switch (objp->type) {
1705
1706 case OBJ_CLUTTER:
1707 case OBJ_BUILDING:
1708 case OBJ_ROBOT:
1709 case OBJ_POWERUP: {
1710 int ambient_sound = Object_info[objp->id].sounds[GSI_AMBIENT];
1711 if (ambient_sound != SOUND_NONE_INDEX)
1712 Sound_system.Play3dSound(ambient_sound, SND_PRIORITY_LOWEST, objp);
1713 break;
1714 }
1715
1716 case OBJ_SOUNDSOURCE:
1717 ASSERT(objp->control_type == CT_SOUNDSOURCE);
1718 if (objp->name) // if has name, attach sound to object
1719 Sound_system.Play3dSound(objp->ctype.soundsource_info.sound_index, SND_PRIORITY_NORMAL, objp,
1720 objp->ctype.soundsource_info.volume);
1721 else { // no name, so attach to 3D position & delete object
1722 pos_state ps;
1723 ps.position = &objp->pos;
1724 ps.roomnum = objp->roomnum;
1725 ps.orient = (matrix *)&Identity_matrix;
1726 Sound_system.Play3dSound(objp->ctype.soundsource_info.sound_index, SND_PRIORITY_NORMAL, &ps,
1727 objp->ctype.soundsource_info.volume);
1728 ObjDelete(i);
1729 }
1730 break;
1731 }
1732 }
1733 }
1734
1735 // Go through the level and start and sounds associated with textures
1736 void StartTextureSounds() {
1737 int r, f;
1738 room *rp;
1739 face *fp;
1740
1741 for (r = 0, rp = Rooms; r <= Highest_room_index; r++, rp++) {
1742 if (rp->used) {
1743 for (f = 0, fp = rp->faces; f < rp->num_faces; f++, fp++) {
1744 int sound = GameTextures[fp->tmap].sound;
1745 if ((sound != -1) && (sound != SOUND_NONE_INDEX)) {
1746 vector pos;
1747 pos_state ps;
1748 ComputeCenterPointOnFace(&pos, rp, f);
1749 ps.position = &pos;
1750 ps.roomnum = r;
1751 ps.orient = (matrix *)&Identity_matrix;
1752 Sound_system.Play3dSound(sound, SND_PRIORITY_LOWEST, &ps);
1753 }
1754 }
1755 }
1756 }
1757 }
1758
1759 // Starts all the sounds on this level
1760 void StartLevelSounds() {
1761 StartObjectSounds();
1762 StartTextureSounds();
1763 StartTerrainSound();
1764 InitAmbientSounds();
1765 }
1766
1767 // frees any data/esc that was created for that level
1768 void FreeThisLevel() {
1769 if (!Level_started)
1770 return;
1771
1772 bool original_controls = Control_poll_flag;
1773
1774 Cinematic_Stop();
1775
1776 // make sure our controls are correct (this is needed for failed missions)
1777 if (Control_poll_flag != original_controls) {
1778 if (Control_poll_flag)
1779 SuspendControls();
1780 else
1781 ResumeControls();
1782 }
1783
1784 Multi_bail_ui_menu = false;
1785
1786 DemoAbort();
1787
1788 // closes hud.
1789 FreeCockpit();
1790 CloseShipHUD();
1791
1792 // end music sequencer's run.
1793 D3MusicStop();
1794
1795 FreeScriptsForLevel();
1796 ClearAllEvents();
1797
1798 // Resets the ambient life controller
1799 a_life.ALReset();
1800
1801 DestroyAllMatcens();
1802 Level_goals.CleanupAfterLevel();
1803
1804 Sound_system.StopAllSounds();
1805
1806 // Clear out all memory that was used for this past level
1807 FlushDataCache();
1808
1809 InitGamePaths(); // DAJ LEAKFIX
1810
1811 DSSoarEnd();
1812
1813 // Reset the camera if need be
1814 if (Player_camera_objnum != -1) {
1815 SetObjectDeadFlag(&Objects[Player_camera_objnum]);
1816 Player_camera_objnum = -1;
1817 Viewer_object = &Objects[Players[Player_num].objnum];
1818 }
1819
1820 ResetHUDMessages();
1821
1822 DestroyDefaultBSPTree();
1823
1824 Level_started = false;
1825 IsRestoredGame = false;
1826 }
1827
1828 extern void FreeTextureBumpmaps(int);
1829 // Clears out all the level specific stuff from memory
1830 void FlushDataCache() {
1831 int i;
1832
1833 // This must be done before we free polymodels
1834 FreeAllObjects();
1835
1836 #ifdef EDITOR
1837 if (Network_up)
1838 return;
1839 #endif
1840
1841 int texfreed = 0;
1842 int modelsfreed = 0;
1843 int soundsfreed = 0;
1844
1845 for (i = 0; i < MAX_TEXTURES; i++) {
1846 if (Textures_to_free[i] != 0) {
1847 if (!(GameTextures[i].flags & TF_ANIMATED)) {
1848 if (GameTextures[i].bumpmap != -1)
1849 FreeTextureBumpmaps(i);
1850
1851 bm_FreeBitmapData(GameTextures[i].bm_handle);
1852 }
1853
1854 texfreed++;
1855 }
1856 }
1857 for (i = 0; i < MAX_POLY_MODELS; i++) {
1858 if (Models_to_free[i] != 0) {
1859 FreePolymodelData(i);
1860 modelsfreed++;
1861 }
1862 }
1863
1864 for (i = 0; i < MAX_SOUNDS; i++) {
1865 if (Sounds_to_free[i] != 0)
1866 {
1867 soundsfreed++;
1868 int index = Sounds[i].sample_index;
1869 if (SoundFiles[index].sample_16bit) {
1870 mem_free(SoundFiles[index].sample_16bit);
1871 SoundFiles[index].sample_16bit = NULL;
1872 }
1873 if (SoundFiles[index].sample_8bit) {
1874 mem_free(SoundFiles[index].sample_8bit);
1875 SoundFiles[index].sample_8bit = NULL;
1876 }
1877 }
1878 }
1879
1880 mprintf(0, "Freed %d textures, %d models, and %d sounds.\n", texfreed, modelsfreed, soundsfreed);
1881 // the renderer is never initialized in dedicated server mode, so don't try to reset things either
1882 if (!Dedicated_server) {
1883 rend_ResetCache();
1884 }
1885 }
1886
1887 ///////////////////////////////////////////////////////////////////////////////
1888 // Runs any possible end movie and stats screen, as well as loads in the next level
1889 ///////////////////////////////////////////////////////////////////////////////
1890
1891 // Parameter: state - 1 = success, 0 = failure, -1 = abort
1892 void EndLevel(int state) {
1893 tLevelNode *lvl = &Current_mission.levels[Current_mission.cur_level - 1];
1894
1895 // Tells all the clients to end the level
1896 if ((Game_mode & GM_MULTI) && Netgame.local_role == LR_SERVER) {
1897 MultiSendLevelEnded(state, Multi_next_level);
1898 CallGameDLL(EVT_CLIENT_GAMELEVELEND, &DLLInfo);
1899 CallMultiDLL(MT_EVT_GAME_OVER);
1900 }
1901
1902 if (!(Game_mode & GM_MULTI)) {
1903
1904 // report the information to the pilot's mission data
1905 CurrentPilotUpdateMissionStatus();
1906 // Sound_system.StopAllSounds(); -- moved to below because bug was reported that sounds were
1907 // playing in performance screen
1908
1909 // save our shields (in case this call is due to starting a new level
1910 // in InitPlayerNewLevel, we'll determine if we should restore them
1911 // this function ALWAYS gets called right before InitPlayerNewLevel from StartLevel
1912 Player_shields_saved_from_last_level = Objects[Players[Player_num].objnum].shields;
1913 Player_energy_saved_from_last_level = Players[Player_num].energy;
1914 } else {
1915 // Stop all player sounds
1916 for (int i = 0; i < MAX_PLAYERS; i++) {
1917 if (NetPlayers[i].flags & NPF_CONNECTED) {
1918 PlayerStopSounds(i);
1919 Players[i].flags &= ~(PLAYER_FLAGS_THRUSTED | PLAYER_FLAGS_AFTERBURN_ON);
1920 }
1921 }
1922 }
1923
1924 // clear screen now.
1925 if (!Dedicated_server) {
1926 StartFrame();
1927 rend_ClearScreen(GR_BLACK);
1928 EndFrame();
1929 rend_Flip();
1930 Sound_system.StopAllSounds();
1931 }
1932
1933 // Sequencing here.
1934 // if this level has an endmovie
1935 if ((state == 1) && (lvl->flags & LVLFLAG_ENDMOVIE) && !(Game_mode & GM_MULTI)) {
1936 DoMissionMovie(lvl->endmovie);
1937 }
1938
1939 // display postlevel results.
1940 if ((state != -1) && (GetFunctionMode() != EDITOR_GAME_MODE))
1941 PostLevelResults(state == 1);
1942
1943 // check for dead players
1944 if (Game_mode & GM_MULTI) {
1945 // in multiplayer check all players
1946 for (int i = 0; i < MAX_PLAYERS; i++) {
1947 if ((NetPlayers[i].flags & NPF_CONNECTED) && (NetPlayers[i].sequence >= NETSEQ_PLAYING)) {
1948 // check to see if player is dying
1949 if ((Players[i].flags & PLAYER_FLAGS_DYING) || (Players[i].flags & PLAYER_FLAGS_DEAD)) {
1950 mprintf(0, "Prematurely ending death for player %d\n", i);
1951 EndPlayerDeath(i);
1952 }
1953 }
1954 }
1955
1956 } else {
1957 // in single player, check Player_num
1958 if ((Players[Player_num].flags & PLAYER_FLAGS_DYING) || (Players[Player_num].flags & PLAYER_FLAGS_DEAD)) {
1959 mprintf(0, "Prematurely ending death for player\n");
1960 EndPlayerDeath(Player_num);
1961 }
1962 }
1963
1964 // Free any game objects/etc that needs to be done when ending a level here.
1965 FreeThisLevel();
1966
1967 // This option is used for HEAT.NET. They have their dedicated server shut down after the
1968 // kill goal or time limit is reached.
1969 if (Dedicated_server) {
1970 if (FindArg("-quitongoal")) {
1971 SetFunctionMode(QUIT_MODE);
1972 }
1973 }
1974 }
1975
1976 // Advances to the next level. If we were on the last level, end the game
1977 void SetNextLevel() {
1978 ASSERT(Current_mission.cur_level > 0);
1979
1980 tLevelNode *lvl = &Current_mission.levels[Current_mission.cur_level - 1];
1981
1982 if (Game_mode & GM_MULTI && Multi_next_level != -1) {
1983 SetCurrentLevel(Multi_next_level);
1984 Multi_next_level = -1;
1985 } else if (lvl->flags & LVLFLAG_BRANCH) {
1986 // jump to brached level
1987 mprintf(0, "Branching...\n");
1988 Current_mission.cur_level = lvl->lvlbranch0;
1989 SetCurrentLevel(Current_mission.cur_level);
1990 } else if ((Current_mission.cur_level == Current_mission.num_levels) || (lvl->flags & LVLFLAG_FINAL)) {
1991 // in this case we are done with the mission!
1992 DoEndMission();
1993
1994 if (!(Game_mode & GM_MULTI)) // Multiplayer loops its levels and never ends
1995 {
1996 SetFunctionMode(MENU_MODE);
1997 }
1998 } else if (Current_mission.game_state_flags & MSN_STATE_SECRET_LEVEL) {
1999 if (lvl->flags & LVLFLAG_SPAWNSECRET) {
2000 // display secret level screen?
2001 ShowProgressScreen(TXT_ENTERSECRETLVL, NULL, true);
2002 Descent->delay(1.0f);
2003 Current_mission.game_state_flags &= (~MSN_STATE_SECRET_LEVEL);
2004 SetCurrentLevel(lvl->secretlvl);
2005 } else {
2006 Int3(); // Game says go to secret level, but there's none to go to.
2007 SetCurrentLevel(Current_mission.cur_level + 1);
2008 }
2009 } else {
2010 // nothing special
2011 SetCurrentLevel(Current_mission.cur_level + 1);
2012 }
2013 }
2014
2015 void GameFrameUI() {
2016 GameFrame();
2017 Last_game_state = Game_state;
2018 }
2019
2020 void RunGameMenu() {
2021 bool pause_game = false;
2022
2023 if (Game_interface_mode != GAME_INTERFACE) {
2024 NewUIWindow_alpha = 226;
2025 SetUICallback(GameFrameUI);
2026 SuspendControls();
2027
2028 // reset bail flag.
2029 Multi_bail_ui_menu = false;
2030
2031 if (!(Game_mode & GM_MULTI)) {
2032 pause_game = true;
2033 PauseGame();
2034 D3MusicResume();
2035 }
2036
2037 switch (Game_interface_mode) {
2038 case GAME_OPTIONS_INTERFACE: {
2039 extern void OptionsMenu();
2040 ui_ShowCursor();
2041 OptionsMenu();
2042 ui_HideCursor();
2043 } break;
2044 case GAME_HELP_INTERFACE: {
2045 ui_ShowCursor();
2046 HelpDisplay();
2047 ui_HideCursor();
2048 } break;
2049 case GAME_TOGGLE_DEMO: {
2050 ui_ShowCursor();
2051 DemoToggleRecording();
2052 ui_HideCursor();
2053 } break;
2054 case GAME_BUDDY_INTERFACE: {
2055 // #ifdef DEMO
2056 // DoMessageBox(TXT_ERROR, TXT_WRONGVERSION, MSGBOX_OK);
2057 // #else
2058 ui_ShowCursor();
2059 BuddyDisplay();
2060 ui_HideCursor();
2061 // #endif
2062 } break;
2063 case GAME_TELCOM_CARGO: {
2064 // #ifndef DEMO
2065 DoWaitPopup(true, TXT_TELCOMLOAD);
2066 ui_ShowCursor();
2067 TelComShow(TS_CARGO);
2068 ui_HideCursor();
2069 DoWaitPopup(false);
2070 // #else
2071 // DoMessageBox(TXT_ERROR, TXT_WRONGVERSION, MSGBOX_OK);
2072 // #endif
2073 } break;
2074 case GAME_TELCOM_BRIEFINGS: {
2075 DoWaitPopup(true, TXT_TELCOMLOAD);
2076 ui_ShowCursor();
2077 TelComShow(TS_MAINMENU);
2078 ui_HideCursor();
2079 DoWaitPopup(false);
2080 } break;
2081 case GAME_TELCOM_AUTOMAP: {
2082 // #ifndef DEMO
2083 DoWaitPopup(true, TXT_TELCOMLOAD);
2084 ui_ShowCursor();
2085 TelComShow(TS_MAP);
2086 ui_HideCursor();
2087 DoWaitPopup(false);
2088 // #else
2089 // DoMessageBox(TXT_ERROR, TXT_WRONGVERSION, MSGBOX_OK);
2090 // #endif
2091 } break;
2092 case GAME_PAUSE_INTERFACE:
2093 if (Game_mode & GM_MULTI)
2094 AddHUDMessage(TXT_NOPAUSEINMULTI);
2095 else {
2096 DoMessageBoxAdvanced(TXT(TXI_HLPPAUSE), TXT_PRESSOKTOCONT, TXT_OK, KEY_PAUSE, NULL);
2097 // DoMessageBox(TXT(TXI_HLPPAUSE),TXT_PRESSOKTOCONT, MSGBOX_OK);
2098 }
2099 break;
2100 case GAME_LEVEL_WARP:
2101 Level_warp_next = DisplayLevelWarpDlg(-1);
2102 if (Level_warp_next != -1)
2103 SetGameState(GAMESTATE_LVLWARP);
2104 break;
2105 case GAME_EXIT_CONFIRM: {
2106 int ret = 0;
2107 ui_ShowCursor();
2108 // Weird code for the training mission and the first time you play...
2109 if (Current_mission.filename && (stricmp(Current_mission.filename, "training.mn3") == 0) && (FirstGame)) {
2110 ret = DoMessageBoxAdvanced(TXT_TRAININGABORTTITLE, TXT_TRAININGABORTTEXT, TXT_SKIP, KEY_S, TXT_ABORT, KEY_A,
2111 TXT_CANCEL, KEY_ESC, NULL);
2112 if (ret == 2) {
2113 // Cancel
2114 ret = 0;
2115 } else if (ret == 1) {
2116 // Abort -- back to the main menu
2117 FirstGame = false;
2118 } else if (ret == 0) {
2119 // Skip
2120 ret = 1;
2121 }
2122
2123 } else {
2124 ret = DoMessageBox(TXT_CONFIRM, TXT_CONFIRMEXIT, MSGBOX_YESNO);
2125 }
2126 if (ret) {
2127 Demo_looping = false;
2128 if ((Players[Player_num].flags & PLAYER_FLAGS_DYING) || (Players[Player_num].flags & PLAYER_FLAGS_DEAD)) {
2129 EndPlayerDeath(Player_num);
2130 if (Game_mode & GM_MULTI) {
2131 MultiSendEndPlayerDeath();
2132 MultiLeaveGame();
2133 }
2134 SetFunctionMode(MENU_MODE);
2135 } else {
2136 if (Game_mode & GM_MULTI)
2137 MultiLeaveGame();
2138 SetFunctionMode(MENU_MODE);
2139 }
2140 Sound_system.StopAllSounds();
2141 }
2142 } break;
2143 case GAME_DLL_INTERFACE: {
2144 DLLInfo.me_handle = DLLInfo.it_handle = OBJECT_HANDLE_NONE;
2145 ui_ShowCursor();
2146 CallGameDLL(EVT_CLIENT_SHOWUI, &DLLInfo);
2147 ui_HideCursor();
2148 } break;
2149
2150 case GAME_DEBUGGRAPH_INTERFACE: {
2151 DebugGraph_DisplayOptions();
2152 } break;
2153
2154 case GAME_SAVE_INTERFACE:
2155 ui_ShowCursor();
2156 #ifdef EDITOR
2157 if (GetFunctionMode() == EDITOR_GAME_MODE)
2158 DoMessageBox("Silly", "You can't save while playing from the editor!", MSGBOX_OK);
2159 else
2160 #endif
2161 SaveGameDialog(); // link to above endif!
2162 ui_HideCursor();
2163 break;
2164
2165 case GAME_LOAD_INTERFACE:
2166 ui_ShowCursor();
2167 #ifdef EDITOR
2168 if (GetFunctionMode() == EDITOR_GAME_MODE)
2169 DoMessageBox("Silly", "You can't load while playing from the editor!", MSGBOX_OK);
2170 else
2171 #endif
2172 LoadGameDialog();
2173 ui_HideCursor();
2174 break;
2175
2176 case GAME_POST_DEMO:
2177 DemoPostPlaybackMenu();
2178 SetFunctionMode(MENU_MODE);
2179 break;
2180 case GAME_DEMO_LOOP:
2181 SetFunctionMode(MENU_MODE);
2182 break;
2183 default:
2184 Int3(); // unhandled game interface mode
2185 }
2186
2187 if (pause_game) {
2188 ResumeGame();
2189 pause_game = false;
2190 }
2191
2192 ResumeControls();
2193 SetUICallback(NULL);
2194 Game_interface_mode = GAME_INTERFACE;
2195 NewUIWindow_alpha = 192;
2196 Clear_screen = 4;
2197 }
2198 }
2199
2200 void PageInLevelTexture(int id) {
2201 if (id == -1 || id == 0)
2202 return;
2203
2204 if (Dedicated_server)
2205 return;
2206
2207 TouchTexture(id);
2208
2209 // Upload all these textures to the card
2210 if (GameTextures[id].flags & TF_ANIMATED) {
2211 vclip *vc = &GameVClips[GameTextures[id].bm_handle];
2212 for (int i = 0; i < vc->num_frames; i++) {
2213 if (!(GameTextures[id].flags & TF_PROCEDURAL) && !(GameTextures[id].flags & TF_SPECULAR))
2214 GameBitmaps[vc->frames[i]].flags |= BF_COMPRESSABLE;
2215 else
2216 GameBitmaps[vc->frames[i]].flags &= ~BF_COMPRESSABLE;
2217
2218 if (!Dedicated_server && GameBitmaps[vc->frames[i]].cache_slot == -1)
2219 rend_PreUploadTextureToCard(vc->frames[i], MAP_TYPE_BITMAP);
2220 }
2221 } else {
2222 if (!(GameTextures[id].flags & TF_PROCEDURAL) && !(GameTextures[id].flags & TF_SPECULAR))
2223 GameBitmaps[GameTextures[id].bm_handle].flags |= BF_COMPRESSABLE;
2224 else
2225 GameBitmaps[GameTextures[id].bm_handle].flags &= ~BF_COMPRESSABLE;
2226
2227 if (!Dedicated_server && GameBitmaps[GameTextures[id].bm_handle].cache_slot == -1)
2228 rend_PreUploadTextureToCard(GameTextures[id].bm_handle, MAP_TYPE_BITMAP);
2229 }
2230
2231 if (GameTextures[id].flags & TF_DESTROYABLE && GameTextures[id].destroy_handle != -1)
2232 PageInLevelTexture(GameTextures[id].destroy_handle);
2233
2234 Textures_to_free[id] = 1;
2235 }
2236
2237 bool PageInSound(int id) {
2238 if (id == -1)
2239 return false;
2240
2241 if (Dedicated_server)
2242 return false;
2243
2244 // sometimes, id passed was 0xffff which seems like a int16_t -1. The if statement
2245 // ensures that the array Sounds_to_free is dealt with properly.
2246 if (Sound_system.CheckAndForceSoundDataAlloc(id)) {
2247 Sounds_to_free[id] = 1;
2248 return true;
2249 }
2250
2251 return false;
2252 }
2253
2254 void PageInDoor(int id) {
2255 // Set sounds
2256 door *doorpointer = &Doors[id];
2257
2258 PageInPolymodel(doorpointer->model_handle);
2259 Models_to_free[doorpointer->model_handle] = 1;
2260
2261 poly_model *pm = &Poly_models[doorpointer->model_handle];
2262 for (int t = 0; t < pm->n_textures; t++)
2263 PageInLevelTexture(pm->textures[t]);
2264
2265 if (doorpointer->open_sound != -1 && doorpointer->open_sound != SOUND_NONE_INDEX)
2266 PageInSound(doorpointer->open_sound);
2267 if (doorpointer->close_sound != -1 && doorpointer->close_sound != SOUND_NONE_INDEX)
2268 PageInSound(doorpointer->close_sound);
2269 }
2270
2271 void PageInWeapon(int id) {
2272 weapon *weaponpointer = &Weapons[id];
2273
2274 if (id == -1)
2275 return;
2276
2277 int i;
2278
2279 if (!(weaponpointer->flags & (WF_IMAGE_BITMAP | WF_IMAGE_VCLIP))) {
2280 PageInPolymodel(weaponpointer->fire_image_handle);
2281 Models_to_free[weaponpointer->fire_image_handle] = 1;
2282
2283 poly_model *pm = &Poly_models[weaponpointer->fire_image_handle];
2284 for (int t = 0; t < pm->n_textures; t++)
2285 PageInLevelTexture(pm->textures[t]);
2286 }
2287
2288 // Load the various textures associated with this weapon
2289 if (weaponpointer->explode_image_handle != -1) {
2290 PageInLevelTexture(weaponpointer->explode_image_handle);
2291 }
2292
2293 if (weaponpointer->particle_handle != -1) {
2294 PageInLevelTexture(weaponpointer->particle_handle);
2295 }
2296
2297 if (weaponpointer->smoke_handle != -1) {
2298 PageInLevelTexture(weaponpointer->smoke_handle);
2299 }
2300
2301 if (weaponpointer->scorch_handle != -1) {
2302 PageInLevelTexture(weaponpointer->scorch_handle);
2303 }
2304
2305 if (weaponpointer->icon_handle != -1) {
2306 PageInLevelTexture(weaponpointer->icon_handle);
2307 }
2308
2309 // Try to load spawn weapons
2310 if (weaponpointer->spawn_handle != -1 && weaponpointer->spawn_count > 0 && weaponpointer->spawn_handle != id) {
2311 PageInWeapon(weaponpointer->spawn_handle);
2312 }
2313
2314 if (weaponpointer->alternate_spawn_handle != -1 && weaponpointer->spawn_count > 0 &&
2315 weaponpointer->alternate_spawn_handle != id) {
2316 PageInWeapon(weaponpointer->alternate_spawn_handle);
2317 }
2318
2319 if (weaponpointer->robot_spawn_handle != -1) {
2320 PageInGeneric(weaponpointer->robot_spawn_handle);
2321 }
2322
2323 // Try and load the various sounds
2324 for (i = 0; i < MAX_WEAPON_SOUNDS; i++) {
2325 if (weaponpointer->sounds[i] != SOUND_NONE_INDEX) {
2326 PageInSound(weaponpointer->sounds[i]);
2327 }
2328 }
2329 }
2330 int paged_in_count = 0;
2331 extern int need_to_page_in;
2332 extern int need_to_page_num;
2333 int paged_in_num = 0;
2334
2335 // #define PAGED_IN_CALC paged_in_count ? (float)paged_in_count/(float)need_to_page_in : 0.0f
2336 #define PAGED_IN_CALC paged_in_num ? (float)paged_in_num / (float)need_to_page_num : 0.0f
2337 void PageInShip(int id) {
2338 int i, t;
2339
2340 ship *shippointer = &Ships[id];
2341
2342 // Page in all textures for this object
2343
2344 PageInPolymodel(shippointer->model_handle);
2345 Models_to_free[shippointer->model_handle] = 1;
2346
2347 poly_model *pm = &Poly_models[shippointer->model_handle];
2348
2349 for (t = 0; t < pm->n_textures; t++) {
2350 PageInLevelTexture(pm->textures[t]);
2351 // Create bumps if neccessary
2352 if (rend_SupportsBumpmapping()) {
2353 if (GameTextures[pm->textures[t]].bumpmap == -1) {
2354 mprintf(0, "Trying to make bumpmap!\n");
2355 BuildTextureBumpmaps(pm->textures[t]);
2356 }
2357 }
2358 }
2359
2360 LoadLevelProgress(LOAD_PROGRESS_PAGING_DATA, PAGED_IN_CALC);
2361 if (shippointer->med_render_handle != -1) {
2362 PageInPolymodel(shippointer->med_render_handle);
2363 Models_to_free[shippointer->med_render_handle] = 1;
2364
2365 pm = &Poly_models[shippointer->med_render_handle];
2366 for (t = 0; t < pm->n_textures; t++)
2367 PageInLevelTexture(pm->textures[t]);
2368 }
2369 LoadLevelProgress(LOAD_PROGRESS_PAGING_DATA, PAGED_IN_CALC);
2370 if (shippointer->lo_render_handle != -1) {
2371 PageInPolymodel(shippointer->lo_render_handle);
2372 Models_to_free[shippointer->lo_render_handle] = 1;
2373
2374 pm = &Poly_models[shippointer->lo_render_handle];
2375 for (t = 0; t < pm->n_textures; t++)
2376 PageInLevelTexture(pm->textures[t]);
2377 }
2378 LoadLevelProgress(LOAD_PROGRESS_PAGING_DATA, PAGED_IN_CALC);
2379 if (shippointer->dying_model_handle != -1) {
2380 PageInPolymodel(shippointer->dying_model_handle);
2381 Models_to_free[shippointer->dying_model_handle] = 1;
2382
2383 pm = &Poly_models[shippointer->dying_model_handle];
2384 for (t = 0; t < pm->n_textures; t++)
2385 PageInLevelTexture(pm->textures[t]);
2386 }
2387 LoadLevelProgress(LOAD_PROGRESS_PAGING_DATA, PAGED_IN_CALC);
2388 // Try and load the various weapons
2389 int j;
2390 if (shippointer->static_wb) {
2391 for (i = 0; i < MAX_PLAYER_WEAPONS; i++) {
2392 for (j = 0; j < MAX_WB_GUNPOINTS; j++) {
2393 if (shippointer->static_wb[i].gp_weapon_index[j] != LASER_INDEX) {
2394 PageInWeapon(shippointer->static_wb[i].gp_weapon_index[j]);
2395 LoadLevelProgress(LOAD_PROGRESS_PAGING_DATA, PAGED_IN_CALC);
2396 }
2397 }
2398 }
2399 }
2400 LoadLevelProgress(LOAD_PROGRESS_PAGING_DATA, PAGED_IN_CALC);
2401 // Try and load the various weapons
2402 for (i = 0; i < MAX_PLAYER_WEAPONS; i++) {
2403 for (j = 0; j < MAX_WB_FIRING_MASKS; j++) {
2404 if ((j % 5) == 0)
2405 LoadLevelProgress(LOAD_PROGRESS_PAGING_DATA, PAGED_IN_CALC);
2406 if (shippointer->static_wb[i].fm_fire_sound_index[j] != SOUND_NONE_INDEX)
2407 PageInSound(shippointer->static_wb[i].fm_fire_sound_index[j]);
2408 }
2409 }
2410
2411 for (i = 0; i < MAX_PLAYER_WEAPONS; i++) {
2412 if ((i % 5) == 0)
2413 LoadLevelProgress(LOAD_PROGRESS_PAGING_DATA, PAGED_IN_CALC);
2414 if (shippointer->firing_sound[i] != -1)
2415 PageInSound(shippointer->firing_sound[i]);
2416
2417 if (shippointer->firing_release_sound[i] != -1)
2418 PageInSound(shippointer->firing_release_sound[i]);
2419
2420 if (shippointer->spew_powerup[i] != -1)
2421 PageInGeneric(shippointer->spew_powerup[i]);
2422 }
2423 }
2424
2425 void PageInGeneric(int id) {
2426 int i, t;
2427
2428 if (id == -1)
2429 return;
2430
2431 object_info *objinfopointer = &Object_info[id];
2432
2433 // Page in all textures for this object
2434
2435 PageInPolymodel(objinfopointer->render_handle);
2436 Models_to_free[objinfopointer->render_handle] = 1;
2437
2438 poly_model *pm = &Poly_models[objinfopointer->render_handle];
2439
2440 for (t = 0; t < pm->n_textures; t++) {
2441 PageInLevelTexture(pm->textures[t]);
2442
2443 // Create bumps if neccessary
2444 if (objinfopointer->type == OBJ_ROBOT && rend_SupportsBumpmapping()) {
2445 if (GameTextures[pm->textures[t]].bumpmap == -1)
2446 BuildTextureBumpmaps(pm->textures[t]);
2447 }
2448 }
2449
2450 if (objinfopointer->med_render_handle != -1) {
2451 PageInPolymodel(objinfopointer->med_render_handle);
2452 Models_to_free[objinfopointer->med_render_handle] = 1;
2453
2454 pm = &Poly_models[objinfopointer->med_render_handle];
2455 for (t = 0; t < pm->n_textures; t++)
2456 PageInLevelTexture(pm->textures[t]);
2457 }
2458
2459 if (objinfopointer->lo_render_handle != -1) {
2460 PageInPolymodel(objinfopointer->lo_render_handle);
2461 Models_to_free[objinfopointer->lo_render_handle] = 1;
2462
2463 pm = &Poly_models[objinfopointer->lo_render_handle];
2464 for (t = 0; t < pm->n_textures; t++)
2465 PageInLevelTexture(pm->textures[t]);
2466 }
2467
2468 // Process all sounds for this object
2469 for (i = 0; i < MAX_OBJ_SOUNDS; i++) {
2470 if (objinfopointer->sounds[i] != SOUND_NONE_INDEX) {
2471 PageInSound(objinfopointer->sounds[i]);
2472 }
2473 }
2474
2475 if (objinfopointer->ai_info) {
2476 for (i = 0; i < MAX_AI_SOUNDS; i++) {
2477 if (objinfopointer->ai_info->sound[i] != SOUND_NONE_INDEX) {
2478 PageInSound(objinfopointer->ai_info->sound[i]);
2479 }
2480 }
2481 }
2482 // Try and load the various wb sounds
2483 int j;
2484 if (objinfopointer->static_wb) {
2485 for (i = 0; i < MAX_WBS_PER_OBJ; i++) {
2486 for (j = 0; j < MAX_WB_FIRING_MASKS; j++) {
2487 if (objinfopointer->static_wb[i].fm_fire_sound_index[j] != SOUND_NONE_INDEX) {
2488 PageInSound(objinfopointer->static_wb[i].fm_fire_sound_index[j]);
2489 }
2490 }
2491 }
2492 }
2493 // Try and load the various wb sounds
2494 if (objinfopointer->anim) {
2495 for (i = 0; i < NUM_MOVEMENT_CLASSES; i++) {
2496 for (j = 0; j < NUM_ANIMS_PER_CLASS; j++) {
2497 if (objinfopointer->anim[i].elem[j].anim_sound_index != SOUND_NONE_INDEX) {
2498 PageInSound(objinfopointer->anim[i].elem[j].anim_sound_index);
2499 }
2500 }
2501 }
2502 }
2503
2504 // Load the spew types
2505 for (i = 0; i < MAX_DSPEW_TYPES; i++) {
2506 if (objinfopointer->dspew_number[i] > 0 && objinfopointer->dspew[i] != 0 && objinfopointer->dspew[i] != id) {
2507 PageInGeneric(objinfopointer->dspew[i]);
2508 }
2509 }
2510
2511 // Try and load the various weapons
2512
2513 // Automatically include laser
2514 PageInWeapon(LASER_INDEX);
2515
2516 if (objinfopointer->static_wb) {
2517 for (i = 0; i < MAX_WBS_PER_OBJ; i++) {
2518 for (j = 0; j < MAX_WB_GUNPOINTS; j++) {
2519 if (objinfopointer->static_wb[i].gp_weapon_index[j] != LASER_INDEX) {
2520 PageInWeapon(objinfopointer->static_wb[i].gp_weapon_index[j]);
2521 }
2522 }
2523 }
2524 }
2525 }
2526
2527 extern const char *Static_sound_names[];
2528
2529 void PageInAllData() {
2530 int i;
2531 paged_in_count = 0;
2532 paged_in_num = 0;
2533 memset(Textures_to_free, 0, MAX_TEXTURES);
2534 memset(Sounds_to_free, 0, MAX_SOUNDS);
2535 memset(Models_to_free, 0, MAX_POLY_MODELS);
2536
2537 PageInShip(Players[Player_num].ship_index);
2538 LoadLevelProgress(LOAD_PROGRESS_PAGING_DATA, PAGED_IN_CALC);
2539 /*
2540 $$TABLE_TEXTURE "LightFlareStare"
2541 $$TABLE_TEXTURE "LightFlare"
2542 */
2543 PageInLevelTexture(FindTextureName(IGNORE_TABLE("LightFlareStar")));
2544 PageInLevelTexture(FindTextureName(IGNORE_TABLE("LightFlare")));
2545
2546 LoadLevelProgress(LOAD_PROGRESS_PAGING_DATA, PAGED_IN_CALC);
2547
2548 if (PreferredRenderer == RENDERER_DIRECT3D) {
2549 if (LightmapInfo && !Dedicated_server) {
2550 if (!NoLightmaps) {
2551 for (i = 0; i < MAX_LIGHTMAP_INFOS; i++) {
2552 if (LightmapInfo[i].used && LightmapInfo[i].type != LMI_DYNAMIC) {
2553 if (!Dedicated_server && GameLightmaps[LightmapInfo[i].lm_handle].cache_slot == -1) {
2554 rend_PreUploadTextureToCard(LightmapInfo[i].lm_handle, MAP_TYPE_LIGHTMAP);
2555 }
2556 }
2557 }
2558 }
2559 }
2560 }
2561
2562 // Get static fireballs
2563 for (i = 0; i < NUM_FIREBALLS; i++) {
2564 char name[PAGENAME_LEN];
2565 strcpy(name, Fireballs[i].name);
2566
2567 name[strlen(name) - 4] = 0;
2568 int id = FindTextureName(name);
2569 if (id != -1)
2570 PageInLevelTexture(id);
2571 }
2572 LoadLevelProgress(LOAD_PROGRESS_PAGING_DATA, PAGED_IN_CALC);
2573 // Get static sounds
2574 for (i = 0; i < NUM_STATIC_SOUNDS; i++) {
2575 int sid = FindSoundName(Static_sound_names[i]);
2576
2577 if (sid != -1)
2578 PageInSound(sid);
2579 }
2580 LoadLevelProgress(LOAD_PROGRESS_PAGING_DATA, PAGED_IN_CALC);
2581
2582 // First get textures
2583 for (i = 0; i <= Highest_room_index; i++) {
2584 if ((i % 15) == 0)
2585 LoadLevelProgress(LOAD_PROGRESS_PAGING_DATA, PAGED_IN_CALC);
2586
2587 if (!Rooms[i].used)
2588 continue;
2589
2590 room *rp = &Rooms[i];
2591 for (int t = 0; t < rp->num_faces; t++) {
2592 PageInLevelTexture(rp->faces[t].tmap);
2593 }
2594 }
2595 LoadLevelProgress(LOAD_PROGRESS_PAGING_DATA, PAGED_IN_CALC);
2596
2597 // Touch all terrain textures
2598 for (i = 0; i < TERRAIN_TEX_WIDTH * TERRAIN_TEX_DEPTH; i++) {
2599 PageInLevelTexture(Terrain_tex_seg[i].tex_index);
2600 }
2601 LoadLevelProgress(LOAD_PROGRESS_PAGING_DATA, PAGED_IN_CALC);
2602 if (Terrain_sky.textured) {
2603 PageInLevelTexture(Terrain_sky.dome_texture);
2604 }
2605 LoadLevelProgress(LOAD_PROGRESS_PAGING_DATA, PAGED_IN_CALC);
2606 for (i = 0; i < Terrain_sky.num_satellites; i++)
2607 PageInLevelTexture(Terrain_sky.satellite_texture[i]);
2608
2609 // Touch all objects
2610 for (i = 0; i <= Highest_object_index; i++) {
2611 if ((i % 20) == 0)
2612 LoadLevelProgress(LOAD_PROGRESS_PAGING_DATA, PAGED_IN_CALC);
2613 object *obj = &Objects[i];
2614 if (obj->type == OBJ_POWERUP || obj->type == OBJ_ROBOT || obj->type == OBJ_CLUTTER || obj->type == OBJ_BUILDING) {
2615 PageInGeneric(obj->id);
2616 continue;
2617 }
2618
2619 if (obj->type == OBJ_DOOR) {
2620 PageInDoor(obj->id);
2621 continue;
2622 }
2623 }
2624 LoadLevelProgress(LOAD_PROGRESS_PREPARE, 0);
2625 }