Debian Codegraph @

Descent3/Mission.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/Mission.cpp $
21 * $Revision: 193 $
22 * $Date: 10/21/01 4:19p $
23 * $Author: Kevin $
24 *
25 * Mission level sequencing and management.
26 *
27 * $Log: /DescentIII/Main/Mission.cpp $
28 *
29 * 193 10/21/01 4:19p Kevin
30 * Fix for bug 5566. Reset the URL structure on mission init
31 *
32 * 192 10/08/01 4:21p Matt
33 * If the mission has data errors, tell the user on the loading screen.
34 *
35 * 191 3/20/00 12:17p Matt
36 * Merge of Duane's post-1.3 changes.
37 * Mission name changes (Mac only)
38 *
39 * 190 11/05/99 12:18p Jay
40 * Fixed bugs with Jeff's fix
41 *
42 * 189 11/05/99 11:05a Jeff
43 * fixed mission movie playing
44 *
45 * 188 11/04/99 12:35a Chris
46 * Added support for Merc
47 *
48 * 187 10/25/99 9:52a Matt
49 * Mac merge
50 *
51 * 186 10/12/99 11:05a Jeff
52 * new msn keyword "SHIP" to override default ship to something else
53 *
54 * 185 10/04/99 9:58a Kevin
55 * Demo fixes for mac demo
56 *
57 * 184 8/10/99 5:12p Jeff
58 * fixed memory leak
59 *
60 * 183 7/28/99 4:03p Kevin
61 * Macintosh!
62 *
63 * 182 7/08/99 10:30a Kevin
64 * when loading a save game >level 4 from a minimal install, don't ask for
65 * CD1
66 *
67 * 181 6/16/99 12:03p Kevin
68 * Fix a stupid bug where minimal installs won't open d3voicex.hog
69 *
70 * 180 6/10/99 4:12p Kevin
71 * Fixed SetLevel in dedicated server for HEAT.NET, and added
72 * level_names.str for level name localization.
73 *
74 * 179 6/03/99 8:48a Kevin
75 * fixes for new OEM version....
76 *
77 * 178 5/20/99 6:21p Kevin
78 * Fixed HOARD keyword thingy
79 *
80 * 177 5/20/99 4:54p Jason
81 * added heartbeats to server
82 *
83 * 176 5/20/99 4:10p Jason
84 * added heartbeat to multiplayer so clients wouldn't time out, also
85 * various multiplayer fixes
86 *
87 * 175 5/20/99 3:40p Jason
88 * made mission looping work correctly in multiplayer
89 *
90 * 174 5/07/99 5:06p Jason
91 * display level name on loading screen
92 *
93 * 173 5/03/99 5:12p Jason
94 * fixing BOA vis problem...
95 *
96 * 172 5/03/99 3:35p Kevin
97 * bug fixes
98 *
99 * 171 5/02/99 2:32p Kevin
100 * fixed various dedicated server problems.
101 *
102 * 170 5/01/99 5:12p Jason
103 * put BOA check back in
104 *
105 * 169 5/01/99 4:06p Jeff
106 * fixed #include for linux
107 *
108 * 168 5/01/99 12:42p Kevin
109 * removed BOA warning. It was showing up for all levels with no terrain
110 *
111 * 167 4/30/99 5:41p Jason
112 * fixed some boa/terrain level issues
113 *
114 * 166 4/30/99 3:03p Kevin
115 * improved times restored count
116 *
117 * 165 4/30/99 2:21p Jason
118 * changes to verify level completeness
119 *
120 * 164 4/25/99 2:18p Kevin
121 * moved d3 main mission voice files into seperate hogs
122 *
123 * 163 4/23/99 10:34p Kevin
124 * fixed bad things with multiple CD code
125 *
126 * 162 4/23/99 5:32p Kevin
127 * Fixed a few mission bugs.
128 *
129 * 161 4/23/99 3:33p Kevin
130 * mission file/multiplayer mod keyword system
131 *
132 * 160 4/23/99 10:35a Kevin
133 * minor cosmetic changes to the load level screen
134 *
135 * 159 4/22/99 8:29p Kevin
136 * made psrand.h come after stdlib.h
137 *
138 * 158 4/22/99 9:53a Kevin
139 * Fixed some dedicated server crashes
140 *
141 * 157 4/21/99 2:15p Samir
142 * table file filter fixes.
143 *
144 * 156 4/20/99 3:32p Kevin
145 * new prepare for descent behaivor
146 *
147 * 155 4/20/99 2:47p Matt
148 * When playing from the editor, set the level number to 1.
149 *
150 * 154 4/20/99 12:44a Matt
151 * Use briefing font instead of HUD font for level loading messages.
152 *
153 * 153 4/19/99 6:10p Kevin
154 * Demo now only has one multiplayer level
155 *
156 * 152 4/18/99 1:56p Kevin
157 * Movie player fixes to avoid crashes running under the editor
158 *
159 * 151 4/17/99 6:15p Samir
160 * replaced gr.h with grdefs.h and fixed resulting compile bugs.
161 *
162 * 150 4/17/99 3:44p Kevin
163 * Demo2 changes & fixes
164 *
165 * 149 4/16/99 6:00p Kevin
166 * Bunches of Demo stuff
167 *
168 * 148 4/15/99 1:40a Jeff
169 * changes for linux compile
170 *
171 * 147 4/14/99 3:07p Kevin
172 * Fixed some multiple CD bugs
173 *
174 * 146 4/14/99 12:35p Samir
175 * localization issues.
176 *
177 * 145 4/14/99 2:51a Jeff
178 * fixed some case mismatched #includes
179 *
180 * 144 4/13/99 6:15p Kevin
181 * added TXT_PREPARE_FOR_DESCENT
182 *
183 * 143 4/11/99 4:45p Matt
184 * Added code for localization of level goal text.
185 *
186 * 142 4/08/99 3:13p Matt
187 * Finished cleaning up level sequencing code. Got rid of all the "level
188 * minus one" stuff.
189 *
190 * 141 4/07/99 3:40p Kevin
191 * Fixes for Beta 1
192 *
193 * 140 4/07/99 12:30p Matt
194 * Added code for failed missions.
195 *
196 * 139 4/05/99 2:54p Samir
197 * display more errors for mission file load failures.
198 *
199 * 138 4/03/99 5:23p Matt
200 * Removed name, author, & description from the mission level structure.
201 *
202 * 137 4/03/99 5:05p Samir
203 * added ENDMISSION keyword to end a mission after a certain level.
204 *
205 * 136 3/31/99 10:28a Samir
206 * I think this is abug in DoMissionMovie. Passed the parameter
207 * (filename) to GetMultiCDPath.
208 *
209 * 135 3/29/99 5:32p Kevin
210 * Build fixes
211 *
212 * 134 3/24/99 3:54p Jeff
213 * much prettier dedicated server load progress indicators
214 *
215 * 133 3/24/99 2:56p Kevin
216 * Fixed level specific progress indicator to have a default for single
217 * player missions, and fixed the default mission name (put it in the
218 * stringtable)
219 *
220 * 132 3/24/99 1:23p Kevin
221 * Support for level specific progress screens.
222 *
223 * 131 3/24/99 11:42a Kevin
224 * Fixed multiplayer missions
225 *
226 * 130 3/24/99 10:54a Kevin
227 * Fixed some problems related to splitting up the main d3.mn3 file across
228 * 2 CDs
229 *
230 * 129 3/19/99 4:08p Kevin
231 * Multiple CD installation support
232 *
233 * 128 3/18/99 12:51p Samir
234 * debug info.
235 *
236 * 127 3/09/99 6:34p Kevin
237 * Made the training mission not be branching, and fixed the crash with
238 * people dying in the demo playback
239 *
240 * 126 3/05/99 5:24p Jeff
241 * fixed mission names for multiplayer levels in oem
242 *
243 * 125 3/04/99 5:24p Kevin
244 * Added filenames for OEM
245 *
246 * 124 3/03/99 7:20p Jeff
247 * music score added for oem levels
248 *
249 * 123 3/03/99 12:33a Kevin
250 * Minor OEM changes
251 *
252 * 122 3/02/99 7:20p Kevin
253 *
254 * 121 3/02/99 1:18p Samir
255 * reset srclinenum in LoadMission so error box reports correct line num.
256 *
257 * 120 3/02/99 11:52a Kevin
258 * Fixes for OEM Beta 4.1
259 *
260 * 119 3/02/99 1:23a Kevin
261 *
262 * 117 3/02/99 12:32a Kevin
263 *
264 * 116 3/01/99 11:47p Kevin
265 *
266 * 115 3/01/99 11:38p Kevin
267 *
268 * 113 3/01/99 9:39p Kevin
269 * Doh! #elseif should have been #else
270 *
271 * 112 3/01/99 9:03p Kevin
272 * OEM Beta 4
273 *
274 * 111 2/28/99 3:26a Samir
275 * redid newgame dialog.
276 *
277 * 110 2/26/99 2:11a Samir
278 * messagebox if misison load failed.
279 *
280 * 109 2/24/99 3:15p Kevin
281 * OEM menu changes, and bug fixes for the save/load system
282 *
283 * 108 2/24/99 2:03p Kevin
284 * fixed bug with flickering status bar
285 *
286 * 107 2/17/99 8:33p Samir
287 * fixed potential bugs with mission files that fail top open.
288 *
289 * 106 2/16/99 12:39p Kevin
290 * Improved paging data progress indicator
291 *
292 * 105 2/16/99 12:36a Kevin
293 * Fixes for release builds of OEM V3 and KAtmai
294 *
295 * 104 2/13/99 1:56p Kevin
296 *
297 * 103 2/10/99 4:56p Kevin
298 * Better progress indicator & prepare for Descent message
299 *
300 * 102 2/10/99 11:25a Kevin
301 *
302 * 101 2/09/99 7:01p Kevin
303 * First work for new and improved progress screen while loading a level.
304 * Note that this is a hack at this point, while I get the details worked
305 * out, then I'll make it cleaner.
306 *
307 * 100 2/04/99 9:28a Kevin
308 * Added a few OEM #ifdefs
309 *
310 * 99 2/03/99 4:20p Kevin
311 * Got multiplayer working with .mn3 files, and setup autodownloading
312 *
313 * 98 2/03/99 2:54p Jeff
314 * display telcom if there is a briefing and/or ships to choose from
315 *
316 * 97 1/29/99 5:22p Jeff
317 * localization
318 *
319 * 96 1/21/99 11:15p Jeff
320 * pulled out some structs and defines from header files and moved them
321 * into seperate header files so that multiplayer dlls don't require major
322 * game headers, just those new headers. Side effect is a shorter build
323 * time. Also cleaned up some header file #includes that weren't needed.
324 * This affected polymodel.h, object.h, player.h, vecmat.h, room.h,
325 * manage.h and multi.h
326 *
327 * 95 1/19/99 1:15p Samir
328 * add on missions.
329 *
330 * 94 1/16/99 10:39a Jeff
331 * added mission memory management to Osiris...only slightly tested. Need
332 * to solve game save/restore problem still
333 *
334 * 93 1/13/99 12:43p Jason
335 * fixed flickering exit menu screen
336 *
337 * 92 1/11/99 12:47p Jason
338 * misc changes for polishing
339 *
340 * 91 1/08/99 2:55p Samir
341 * Ripped out OSIRIS1.
342 *
343 * 90 1/04/99 5:44p Samir
344 * added game state flags.
345 *
346 * 89 12/30/98 12:15p Kevin
347 * Auto Mission Download system
348 *
349 * 88 12/17/98 12:08p Jeff
350 * first checkin of new implementation of OSIRIS (old OSIRIS no longer
351 * works)
352 *
353 * 87 12/16/98 3:24p Samir
354 * new way to get info on a mission (used to determine training mission
355 * too.)
356 *
357 * 86 12/16/98 1:57p Samir
358 * Replaced CleanupString2 with CleanupStr
359 *
360 * 85 12/03/98 12:51p Samir
361 * music score specified per level.
362 *
363 * 84 11/02/98 6:00p Jeff
364 * began adding single player ship selection
365 *
366 * 83 10/23/98 8:28p Samir
367 * enhanced load level screen.
368 *
369 * 82 10/23/98 12:52p Samir
370 * added gray backbar for non splash loading screens.
371 *
372 * 81 10/22/98 10:49p Samir
373 * print out real messages for loadlevel and clear bar when collating.
374 *
375 * 80 10/22/98 12:46a Matt
376 * Got rid of the loading screen before the briefing. Instead, menu.cpp
377 * shows the menu background screen (without the menu).
378 *
379 * 79 10/20/98 6:34p Jeff
380 * changes made to get dedicated server working
381 *
382 * 78 10/19/98 10:35p Kevin
383 *
384 * 77 10/19/98 7:51p Kevin
385 * performance testing
386 *
387 * 76 10/19/98 5:41p Samir
388 * fixed booboo.
389 *
390 * 75 10/19/98 5:39p Samir
391 * added loading level screen.
392 *
393 * 74 10/18/98 2:58p Jason
394 * fixes for beta4
395 *
396 * 73 10/18/98 12:14p Jeff
397 * demo multiplayer mission loops
398 *
399 * 72 10/14/98 7:30p Matt
400 * Fixed compile warning
401 *
402 * 71 10/14/98 7:19p Kevin
403 * More dsp changes...
404 *
405 * 70 10/14/98 6:40p Samir
406 * ShowProgressScreen uses Max_window_w, and height.
407 *
408 * 69 10/13/98 3:48p Samir
409 * added error checking if script failed to load (default).
410 *
411 * 68 10/11/98 3:04a Jeff
412 * for the demo, new was being used to alloc the level node, when it
413 * should have been mem_malloc
414 *
415 * 67 10/09/98 6:58p Kevin
416 * changed demo level to polaris.d3l
417 *
418 * 66 10/08/98 7:29p Samir
419 * revamped sequencing.
420 *
421 * 65 10/08/98 4:23p Kevin
422 * Changed code to comply with memory library usage. Always use mem_malloc
423 * , mem_free and mem_strdup
424 *
425 * 64 10/07/98 11:34a Kevin
426 *
427 * 63 10/06/98 10:36a Kevin
428 * updated level names for demo
429 *
430 * 62 10/06/98 10:34a Kevin
431 * Put in demo code for multi
432 *
433 * 61 10/02/98 5:46p Samir
434 * took out mission file objective text and replaced with level goals.
435 *
436 * 60 9/22/98 3:56p Samir
437 * special demo code doesn't allow pilot and mission stuff.
438 *
439 * 59 9/15/98 4:31p Jason
440 * added more functionality for the dedicated server
441 *
442 * 58 9/14/98 6:28p Jason
443 * first pass at getting dedicated server working
444 *
445 * 57 8/28/98 12:57p Jeff
446 * parm added to TelComShow
447 *
448 * 56 8/27/98 2:51p Jeff
449 * made it so SHIFT-ESC exits the TelCom back to Main Menu
450 *
451 * 55 8/24/98 5:04p Kevin
452 * Made msn files have the option to not be playable in multiplayer
453 *
454 * 54 8/20/98 10:53a Samir
455 * check Current_level pointer for validity.
456 *
457 * 53 8/18/98 1:10a Samir
458 * some reorg of scripting and intrasave mission managment.
459 *
460 * 52 7/31/98 5:19p Samir
461 * mission filenames are dynamically allocated now to allow for pathnames
462 * (since we'd have too many 256 char arrays per level.
463 *
464 * 51 6/18/98 4:49p Kevin
465 * Updated multiplayer menus
466 *
467 * 50 6/16/98 10:54a Jeff
468 *
469 * 49 5/25/98 8:19p Samir
470 * skip telcom if no briefing file and other stuff.
471 *
472 * 48 5/21/98 2:32p Samir
473 * added full support for intra-mission level branching.
474 *
475 * 47 5/18/98 3:56p Samir
476 * added D3_FAST mode to quickly enter and exit games.
477 *
478 * 46 5/05/98 5:17p Samir
479 * took out loading level message.
480 *
481 * 45 4/24/98 1:53a Samir
482 * took care of a lot of scripting memory leaks.
483 *
484 * 44 4/21/98 4:15a Samir
485 * memory stuf.
486 *
487 * 43 4/20/98 11:30a Jason
488 * Added ShowProgressScreen function
489 *
490 * 42 4/18/98 7:17a Samir
491 * Added level objective descriptions to mission file.
492 *
493 * 41 4/14/98 7:50p Matt
494 * Added system to keep info for each level
495 *
496 * 40 4/02/98 11:11a Samir
497 * Error checking for level load/misison init fail.
498 *
499 * 39 3/31/98 3:49p Jason
500 * added memory lib
501 *
502 * 38 3/30/98 6:29p Samir
503 * Load default null script.
504 *
505 * 37 2/17/98 6:54p Samir
506 * clear screen.
507 *
508 * 36 2/17/98 6:13p Jeff
509 * Changed it so TelCom is forced to go into Briefings when called
510 *
511 * 35 2/17/98 4:42p Samir
512 * Current_level is now defined after calling DoLevelIntro.
513 *
514 * 34 2/13/98 10:57a Samir
515 * Changed some gamescript initialization.
516 *
517 * 33 2/12/98 5:08p Matt
518 * Reset cockpit mode when starting a level. Unfortunately, this involved
519 * some semi-major mucking with game sequencing.
520 *
521 * 32 2/08/98 5:01p Samir
522 * New game sequencing changes.
523 *
524 * 31 1/21/98 5:27p Jason
525 * Don't reposition player object if going from editor to game
526 *
527 * 30 1/21/98 1:11p Jason
528 * incremental checkin for multiplayer
529 *
530 * 29 1/20/98 6:01p Jason
531 * first pass at getting multiplayer deaths working
532 *
533 * 28 1/15/98 11:10a Jeff
534 * Added call to set font color before 'loading level' so its white, also
535 * turned back on Telcom
536 *
537 * 27 1/08/98 12:32p Samir
538 * Initialize new player ship when quick starting mission.
539 *
540 * 26 12/29/97 5:51p Samir
541 * Use new text system to draw "loading" screen.
542 *
543 * 25 12/19/97 12:33p Samir
544 * Dont call telcom for now.
545 *
546 * 24 11/16/97 3:43p Samir
547 * Briefing filename now defined in mission level structure.
548 *
549 * 23 11/10/97 12:37p Samir
550 * When leaving telcom, restore to cinematics mode for simple 2d message.
551 *
552 * 22 10/16/97 4:41p Samir
553 * Set initial level state to start when quick starting mission.
554 *
555 * 21 10/03/97 11:58a Samir
556 * Added mission name
557 *
558 * 20 10/02/97 12:36p Samir
559 * Redid game sequencing flow.
560 *
561 * 19 9/30/97 5:33p Samir
562 * Added GameSequencer.
563 *
564 * 18 9/22/97 5:59p Samir
565 * Changed ObjCScript system, so everything is broken, but it shouldn't
566 * crash the game.
567 *
568 * 17 9/15/97 6:26p Samir
569 * Added loading level message.
570 *
571 * 16 9/12/97 4:07p Samir
572 * Simplified movie playing.
573 *
574 * 15 9/10/97 4:40p Samir
575 * Fixed a boo-boo
576 *
577 * 14 9/10/97 3:59p Samir
578 * Inititalize a mini mission when playing from editor, and compile level
579 * script when playing from editor always.
580 *
581 * 13 9/10/97 1:56p Samir
582 * Added more scripting initialization.
583 *
584 * 12 9/05/97 1:21p Samir
585 * Moved around a bunch of initialization code to InitThisLevel which is
586 * located in game.cpp. This is called every time you die, start a
587 * level, etc.
588 *
589 * 11 8/21/97 5:57p Samir
590 * Added some scripti loading/saving calls and took out some useless
591 * interface stuff
592 *
593 * 10 8/15/97 6:33p Samir
594 * Changes reflecting enhanced editor scripting.
595 *
596 * 9 8/12/97 5:31p Jason
597 * nulled out pointer when quitting mission.
598 *
599 * 8 8/12/97 3:22p Samir
600 * Initialize scripts at start of level.
601 *
602 * 7 8/06/97 10:38a Samir
603 * Fixed call to D3XReallocProgram
604 *
605 * 6 8/05/97 9:59a Samir
606 * Scripting stuff.
607 *
608 * 5 7/23/97 3:55p Jeff
609 * fixed TeleCom* calls to TelCom
610 *
611 * 4 7/23/97 3:53p Jeff
612 *
613 * 3 7/23/97 3:43p Samir
614 * Added telecom stuff.
615 *
616 * 7 6/11/97 2:20p Samir
617 * Changed gameos to new system.
618 *
619 * 6 6/05/97 12:21p Samir
620 * Added more mission commands.
621 *
622 * 5 5/16/97 6:13p Samir
623 * Check for EOF in mission file this time.
624 *
625 * 4 5/16/97 3:11p Samir
626 * Added a mission name and mission initializer.
627 *
628 * 3 5/15/97 6:58p Samir
629 * Small briefing changes.
630 *
631 * 2 5/15/97 2:09p Samir
632 * Added a bunch of sequencing from level to level, loading mission.
633 *
634 * 1 4/29/97 11:57a Samir
635 * Initial revision
636 *
637 * $NoKeywords: $
638 */
639
640 #include <cstring>
641 #include <cstdlib>
642 #include <filesystem>
643
644 #include "Mission.h"
645 #include "3d.h"
646 #include "LoadLevel.h"
647 #include "pserror.h"
648 #include "cfile.h"
649 #include "gamefont.h"
650 #include "grdefs.h"
651 #include "descent.h"
652 #include "ddio.h"
653 #include "d3movie.h"
654 #include "program.h"
655 #include "object.h"
656 #include "objinit.h"
657 #include "ObjScript.h"
658 #include "application.h"
659 #include "TelCom.h"
660 #include "game.h"
661 #include "cinematics.h"
662 #include "player.h"
663 #include "gamesequence.h"
664 #include "mem.h"
665 #include "newui.h"
666 #include "stringtable.h"
667 #include "AppConsole.h"
668 #include "pstring.h"
669 #include "dedicated_server.h"
670 #include "osiris_dll.h"
671 #include "mission_download.h"
672 #include "manage.h"
673 #include "ship.h"
674 #include "BOA.h"
675 #include "terrain.h"
676 #include "multi.h"
677 #include "hud.h"
678 // ---------------------------------------------------------------------------
679 // Data
680 // ---------------------------------------------------------------------------
681 // Info about the current level
682 level_info Level_info;
683 tMission Current_mission;
684 tLevelNode *Current_level = NULL;
685 char D3MissionsDir[_MAX_PATH];
686 extern int Times_game_restored;
687 extern msn_urls Net_msn_URLs;
688
689 // ---------------------------------------------------------------------------
690 // Function prototypes
691 // ---------------------------------------------------------------------------
692 bool InitMissionScript();
693 void DoEndMission();
694 void DoMissionMovie(const char *movie);
695 void FreeMission();
696 // used in load level callback
697 void LoadLevelCB(const char *chunk, int curlen, int filelen);
698 // MN3 based mission functions.
699 // loads the msn file from the mn3 file specified, specifies the hog and table file.
700 bool mn3_Open(const char *mn3file);
701 // returns mission information given the mn3 file.
702 bool mn3_GetInfo(const char *mn3file, tMissionInfo *msn);
703 // closes the current mn3 file
704 void mn3_Close();
705
706 static inline bool IS_MN3_FILE(const char *fname) {
707 char name[PSFILENAME_LEN + 1];
708 char ext[PSFILENAME_LEN + 1];
709 ddio_SplitPath(fname, NULL, name, ext);
710 return (stricmp(ext, ".mn3") == 0) ? true : false;
711 }
712
713 static inline char *MN3_TO_MSN_NAME(const char *mn3name, char *msnname) {
714 char fname[PSFILENAME_LEN + 1];
715 ddio_SplitPath(mn3name, NULL, fname, NULL);
716
717 if (stricmp(fname, "d3_2") == 0) {
718 strcpy(fname, "d3");
719 }
720 strcat(fname, ".msn");
721 strcpy(msnname, fname);
722 return msnname;
723 }
724
725 // ---------------------------------------------------------------------------
726 // Functions
727 // ---------------------------------------------------------------------------
728
729 ///////////////////////////////////////////////////////////////////////////////
730 // High level mission stuff
731 ///////////////////////////////////////////////////////////////////////////////
732 void InitMission() {
733 mprintf(0, "In InitMission()\n");
734 Current_mission.num_levels = 0;
735 Current_mission.cur_level = 0;
736 memset(Current_mission.desc, 0, sizeof(Current_mission.desc));
737 memset(Current_mission.name, 0, MSN_NAMELEN);
738 memset(Current_mission.author, 0, MSN_NAMELEN);
739 memset(Current_mission.email, 0, MSN_URLLEN);
740 memset(Current_mission.web, 0, MSN_URLLEN);
741 Current_mission.hog = NULL;
742 Current_mission.levels = NULL;
743 Current_mission.filename = NULL;
744 Current_mission.game_state_flags = 0;
745 Current_mission.mn3_handle = 0;
746 // create add on mission directory
747 ddio_MakePath(D3MissionsDir, LocalD3Dir, "missions", NULL);
748 std::error_code ec;
749 std::filesystem::create_directories(D3MissionsDir, ec);
750 if (ec) {
751 Error(TXT_MSN_FAILEDCREATEDIR);
752 }
753 atexit(ResetMission);
754 }
755 // reset all states for a mission
756 void ResetMission() {
757 mprintf(0, "In ResetMission()\n");
758 FreeMission();
759 Current_mission.num_levels = 0;
760 Current_mission.cur_level = 0;
761 memset(Current_mission.desc, 0, sizeof(Current_mission.desc));
762 memset(Current_mission.name, 0, MSN_NAMELEN);
763 memset(Current_mission.author, 0, MSN_NAMELEN);
764 memset(Current_mission.email, 0, MSN_URLLEN);
765 memset(Current_mission.web, 0, MSN_URLLEN);
766 Current_mission.hog = NULL;
767 Current_mission.levels = NULL;
768 Current_mission.filename = NULL;
769 Current_mission.game_state_flags = 0;
770
771 // clear out old URLs from memory
772 for (int a = 0; a < MAX_MISSION_URL_COUNT; a++) {
773 Net_msn_URLs.URL[a][0] = '\0';
774 }
775 }
776 #if (defined(OEM) || defined(DEMO))
777 bool DemoMission(int mode = 0) {
778 tMission *msn = &Current_mission;
779 tLevelNode *lvls = (tLevelNode *)mem_malloc(sizeof(tLevelNode) * 5);
780 msn->cur_level = 1;
781 msn->num_levels = 1;
782 msn->levels = lvls;
783
784 msn->multiplayable = true;
785 msn->singleplayable = true;
786
787 memset(lvls, 0, sizeof(tLevelNode) * msn->num_levels);
788 strncpy(msn->author, "Outrage", MSN_NAMELEN - 1);
789 if (!mode) {
790 strcpy(msn->name, "Descent 3: Sol Ascent");
791 msn->num_levels = 5;
792 memset(lvls, 0, sizeof(tLevelNode) * msn->num_levels);
793 #ifdef DEMO
794 msn->multiplayable = false;
795 strcpy(msn->name, "Descent 3: Demo2");
796 msn->num_levels = 1;
797 msn->filename = mem_strdup("d3demo.mn3");
798 #else
799 strcpy(msn->name, "Descent 3: Sol Ascent");
800 msn->num_levels = 5;
801 msn->filename = mem_strdup("d3oem.mn3");
802 #endif
803 // strncpy(lvls[0].name, "Search for Sweitzer", MSN_NAMELEN-1);
804 lvls[0].flags = LVLFLAG_BRIEFING | LVLFLAG_SCORE;
805 lvls[0].filename = mem_strdup("level1.d3l");
806 lvls[0].briefname = mem_strdup("level1.brf");
807 lvls[0].score = mem_strdup("level1.omf");
808 lvls[0].progress = mem_strdup("l1load.ogf");
809 lvls[0].moviename = mem_strdup("level1.mve");
810 #ifndef DEMO
811 // strncpy(lvls[0].name, "Into the Heart of the Ship", MSN_NAMELEN-1);
812 lvls[1].flags = LVLFLAG_BRIEFING | LVLFLAG_SCORE;
813 lvls[1].filename = mem_strdup("level3.d3l");
814 lvls[1].briefname = mem_strdup("level2o.brf");
815 lvls[1].score = mem_strdup("level3.omf");
816 lvls[1].progress = mem_strdup("l3load.ogf");
817 // strncpy(lvls[0].name, "The Nomad Caves", MSN_NAMELEN-1);
818 lvls[2].flags = LVLFLAG_BRIEFING | LVLFLAG_SCORE;
819 lvls[2].filename = mem_strdup("level6.d3l");
820 lvls[2].briefname = mem_strdup("level3o.brf");
821 lvls[2].score = mem_strdup("level6.omf");
822 lvls[2].progress = mem_strdup("l6load.ogf");
823 // strncpy(lvls[0].name, "The Transmode Virus", MSN_NAMELEN-1);
824 lvls[3].flags = LVLFLAG_BRIEFING | LVLFLAG_SCORE;
825 lvls[3].filename = mem_strdup("level7.d3l");
826 lvls[3].briefname = mem_strdup("level4o.brf");
827 lvls[3].score = mem_strdup("level7.omf");
828 lvls[3].progress = mem_strdup("l7load.ogf");
829 // strncpy(lvls[0].name, "The Rescue", MSN_NAMELEN-1);
830 lvls[4].flags = LVLFLAG_BRIEFING | LVLFLAG_SCORE;
831 lvls[4].filename = mem_strdup("level11.d3l");
832 lvls[4].briefname = mem_strdup("level5o.brf");
833 lvls[4].score = mem_strdup("level11.omf");
834 lvls[4].progress = mem_strdup("l11load.ogf");
835 mn3_Open("d3oem.mn3");
836 #endif
837
838 }
839
840 else if (mode == 1) {
841 strcpy(msn->name, "Polaris");
842 msn->filename = mem_strdup("Polaris.d3l");
843 // strncpy(lvls[0].name, "Polaris", MSN_NAMELEN-1);
844 lvls[0].filename = mem_strdup("polaris.d3l");
845 lvls[0].flags |= LVLFLAG_BRANCH;
846 lvls[0].lvlbranch0 = 1;
847 lvls[0].progress = mem_strdup("polaris.ogf");
848 } else if (mode == 2) {
849 strcpy(msn->name, "The Core");
850 msn->filename = mem_strdup("TheCore.d3l");
851 // strncpy(lvls[0].name, "The Core", MSN_NAMELEN-1);
852 lvls[0].filename = mem_strdup("thecore.d3l");
853 lvls[0].flags |= LVLFLAG_BRANCH;
854 lvls[0].lvlbranch0 = 1;
855 lvls[0].progress = mem_strdup("thecore.ogf");
856 } else if (mode == 3) {
857 strcpy(msn->name, "Taurus");
858 msn->filename = mem_strdup("Taurus.d3l");
859 // strncpy(lvls[0].name, "Taurus", MSN_NAMELEN-1);
860 lvls[0].filename = mem_strdup("taurus.d3l");
861 lvls[0].flags |= LVLFLAG_BRANCH;
862 lvls[0].lvlbranch0 = 1;
863 lvls[0].progress = mem_strdup("taurus.ogf");
864 }
865 #ifndef DEMO
866 else if (mode == 4) {
867 strcpy(msn->name, "Pilot Training");
868 msn->filename = mem_strdup("training.mn3");
869 // strncpy(lvls[0].name, "Training", MSN_NAMELEN-1);
870 lvls[0].filename = mem_strdup("trainingmission.d3l");
871 lvls[0].briefname = NULL; // mem_strdup("training.brf");
872 lvls[0].flags = 0;
873 lvls[0].lvlbranch0 = 0;
874 lvls[0].progress = mem_strdup("trainingload.ogf");
875 mn3_Open("training.mn3");
876 }
877 #endif
878 // load default script here.
879 InitMissionScript();
880 return true;
881 }
882 #endif
883
884 bool LoadMission(const char *mssn) {
885 Times_game_restored = 0;
886 mprintf(0, "In LoadMission()\n");
887 // ShowProgressScreen(TXT_LOADINGLEVEL);
888 #if (defined(OEM) || defined(DEMO))
889 #ifdef OEM
890 if (stricmp(mssn, "d3oem.mn3") == 0)
891 return DemoMission(0);
892 #elif defined(DEMO)
893 if (stricmp(mssn, "d3demo.mn3") == 0)
894 return DemoMission(0);
895 #endif
896 else if (stricmp(mssn, "polaris.d3l") == 0)
897 return DemoMission(1);
898 else if (stricmp(mssn, "thecore.d3l") == 0)
899 return DemoMission(2);
900 else if (stricmp(mssn, "taurus.d3l") == 0)
901 return DemoMission(3);
902 #ifdef OEM
903 else if (stricmp(mssn, "training.mn3") == 0)
904 return DemoMission(4);
905 #endif
906 #else
907
908 // #endif
909 tLevelNode *lvls = NULL; // Temporary storage for level data.
910 tMission *msn;
911 CFILE *fp = NULL; // Mission file
912 char errtext[80]; // Stores error if unable to read mission
913 char msnfname[_MAX_PATH];
914 char mission[_MAX_PATH];
915 int srclinenum = 0; // Current line of source.
916 int curlvlnum; // Current level number
917 int numlevels; // Number of levels required to read in.
918 int cur_objective; // current objective reading.
919 bool indesc; // are we in a multi-line block
920 bool res = false; // used to specify if no error has occurred.
921 char pathname[_MAX_PATH];
922 ResetMission(); // Reset everything.
923 // open MN3 if filename passed was an mn3 file.
924
925 if (IS_MN3_FILE(mssn)) {
926 strcpy(mission, mssn);
927 ddio_MakePath(pathname, D3MissionsDir, mission, NULL);
928 } else {
929 strcpy(mission, mssn);
930 strcpy(pathname, mssn);
931 strcpy(msnfname, mssn);
932 // ddio_MakePath(pathname, D3MissionsDir, mission, NULL);
933 }
934 if (IS_MN3_FILE(mission)) {
935
936 if (!mn3_Open(pathname)) {
937 strcpy(errtext, TXT_MSN_OPENMN3FAILED);
938 goto msnfile_error;
939 }
940 MN3_TO_MSN_NAME(mission, msnfname);
941 }
942 // open mission file
943 fp = cfopen(msnfname, "rt");
944 if (!fp) {
945 strcpy(errtext, TXT_MISSIONNOTFOUND);
946 goto msnfile_error;
947 }
948 msn = &Current_mission;
949
950 // read in mission file
951 srclinenum = 1;
952 numlevels = -1;
953 curlvlnum = 0;
954 indesc = 0;
955 cur_objective = -1;
956 msn->multiplayable = true;
957 msn->singleplayable = true;
958 msn->training_mission = false;
959
960 while (!cfeof(fp)) {
961 char srcline[128]; // One line of mission source
962 char command[32]; // Command read from line.
963 char operand[96]; // operand read from line
964 char *keyword; // parsed keyword
965 int readcount; // read-in count
966 readcount = cf_ReadString(srcline, sizeof(srcline), fp);
967 if (readcount) {
968 // we have a line of source. parse out primary keyword
969 // then parse out remainder.
970 keyword = strtok(srcline, " \t");
971 CleanupStr(command, srcline, sizeof(command));
972 CleanupStr(operand, srcline + strlen(command) + 1, sizeof(operand));
973 if (strlen(command) && indesc)
974 indesc = 0;
975 if (!stricmp(command, "NAME")) {
976 strncpy(msn->name, operand, MSN_NAMELEN - 1);
977 } else if (!stricmp(command, "MULTI")) {
978 if (stricmp("no", operand) == 0)
979 msn->multiplayable = false;
980 } else if (!stricmp(command, "SINGLE")) {
981 if (stricmp("no", operand) == 0)
982 msn->singleplayable = false;
983 } else if (!stricmp(command, "TRAINER")) {
984 if (curlvlnum == 0) {
985 msn->training_mission = true;
986 } else {
987 strcpy(errtext, TXT_MSN_MSNCOMMAND);
988 goto msnfile_error;
989 }
990 } else if (!stricmp(command, "AUTHOR")) {
991 strncpy(msn->author, operand, MSN_NAMELEN - 1);
992 } else if (!stricmp(command, "KEYWORDS")) {
993 // Don't do anything with this
994 } else if (!stricmp(command, "DESCRIPTION") || indesc) {
995 // multi-line descriptions require the strcat. the initial
996 // strings should be empty for this to work.
997 strcat(msn->desc, operand);
998 if (indesc)
999 strcat(msn->desc, "\n");
1000 indesc = 1; // this is a multiline command
1001 } else if (!stricmp(command, "URL")) {
1002 if (curlvlnum != 0) {
1003 strcpy(errtext, TXT_MSN_LVLCOMMAND);
1004 goto msnfile_error;
1005 } else {
1006 for (int a = 0; a < MAX_MISSION_URL_COUNT; a++) {
1007 if (Net_msn_URLs.URL[a][0] == '\0') {
1008 strncpy(Net_msn_URLs.URL[a], operand, MAX_MISSION_URL_LEN - 1);
1009 Net_msn_URLs.URL[a][MAX_MISSION_URL_LEN - 1] = '\0';
1010 mprintf(0, "Found a Mission URL: %s\n", operand);
1011 break;
1012 }
1013 }
1014 }
1015 } else if (!stricmp(command, "SHIP")) {
1016 // there is a different default ship
1017 if (curlvlnum != 0) {
1018 strcpy(errtext, TXT_MSN_LVLCOMMAND);
1019 goto msnfile_error;
1020 } else {
1021 int ship_index = FindShipName(operand);
1022 if (ship_index != -1) {
1023 // ok the ship exists, make this guy the new default ship
1024 PlayerResetShipPermissions(-1, false);
1025 PlayerSetShipPermission(-1, operand, true);
1026 mprintf(0, "MAKING %s THE NEW DEFAULT SHIP!\n", operand);
1027 } else {
1028 Int3();
1029 }
1030 }
1031 } else if (!stricmp(command, "EMAIL")) {
1032 if (curlvlnum != 0) {
1033 strcpy(errtext, TXT_MSN_LVLCOMMAND);
1034 goto msnfile_error;
1035 } else
1036 strncpy(msn->email, operand, MSN_URLLEN - 1);
1037 } else if (!stricmp(command, "SCORE")) {
1038 if (curlvlnum == 0) {
1039 strcpy(errtext, TXT_MSN_LVLCOMMAND);
1040 goto msnfile_error;
1041 } else {
1042 lvls[curlvlnum - 1].flags |= LVLFLAG_SCORE;
1043 lvls[curlvlnum - 1].score = mem_strdup(operand);
1044 if (!lvls[curlvlnum - 1].score)
1045 goto fatal_error;
1046 }
1047 } else if (!stricmp(command, "PROGRESS")) {
1048 if (curlvlnum == 0) {
1049 strcpy(errtext, TXT_MSN_LVLCOMMAND);
1050 goto msnfile_error;
1051 } else {
1052 lvls[curlvlnum - 1].progress = mem_strdup(operand);
1053 if (!lvls[curlvlnum - 1].progress)
1054 goto fatal_error;
1055 }
1056 } else if (!stricmp(command, "HOG")) {
1057 if (curlvlnum == 0) {
1058 msn->hog = mem_strdup(operand);
1059 if (!msn->hog)
1060 goto fatal_error;
1061 } else {
1062 lvls[curlvlnum - 1].flags |= LVLFLAG_SPECIALHOG;
1063 if (!(lvls[curlvlnum - 1].hog = mem_strdup(operand)))
1064 goto fatal_error;
1065 }
1066 } else if (!stricmp(command, "NUMLEVELS")) {
1067 if (curlvlnum != 0) {
1068 strcpy(errtext, TXT_MSN_LVLCOMMAND);
1069 goto msnfile_error;
1070 } else {
1071 // get number of levels
1072 int value = atoi(operand);
1073 if (value == 0) {
1074 strcpy(errtext, TXT_MSN_LVLNUMINVALID);
1075 goto msnfile_error;
1076 }
1077 lvls = (tLevelNode *)mem_malloc(sizeof(tLevelNode) * value);
1078 memset(lvls, 0, sizeof(tLevelNode) * value);
1079 numlevels = value;
1080 }
1081 } else if (!stricmp(command, "LEVEL")) {
1082 // first check if number of level is greater than num_levels
1083 if ((curlvlnum == numlevels) && (numlevels != -1)) {
1084 strcpy(errtext, TXT_MSN_NUMLVLSINVALID);
1085 goto msnfile_error;
1086 }
1087 curlvlnum = atoi(operand);
1088 if (curlvlnum == 0) {
1089 strcpy(errtext, TXT_MSN_LVLNUMINVALID);
1090 goto msnfile_error;
1091 } else if (curlvlnum > numlevels || curlvlnum < 0) {
1092 strcpy(errtext, TXT_MSN_LVLNUMINVALID);
1093 goto msnfile_error;
1094 }
1095 } else if (!stricmp(command, "INTROMOVIE")) {
1096 if (curlvlnum == 0) {
1097 strcpy(errtext, TXT_MSN_LVLCOMMAND);
1098 goto msnfile_error;
1099 } else {
1100 lvls[curlvlnum - 1].flags |= LVLFLAG_STARTMOVIE;
1101 if (!(lvls[curlvlnum - 1].moviename = mem_strdup(operand)))
1102 goto fatal_error;
1103 }
1104 } else if (!stricmp(command, "INTRODEFAULT")) {
1105 if (curlvlnum == 0) {
1106 strcpy(errtext, TXT_MSN_LVLCOMMAND);
1107 goto msnfile_error;
1108 } else if (!Descent_overrided_intro) {
1109 lvls[curlvlnum - 1].flags |= LVLFLAG_STARTMOVIE;
1110 if (!(lvls[curlvlnum - 1].moviename = mem_strdup(operand)))
1111 goto fatal_error;
1112 }
1113 } else if (!stricmp(command, "ENDMOVIE")) {
1114 if (curlvlnum == 0) {
1115 strcpy(errtext, TXT_MSN_LVLCOMMAND);
1116 goto msnfile_error;
1117 } else {
1118 lvls[curlvlnum - 1].flags |= LVLFLAG_ENDMOVIE;
1119 if (!(lvls[curlvlnum - 1].endmovie = mem_strdup(operand)))
1120 goto fatal_error;
1121 }
1122 } else if (!stricmp(command, "MINE")) {
1123 if (curlvlnum == 0) {
1124 strcpy(errtext, TXT_MSN_LVLCOMMAND);
1125 goto msnfile_error;
1126 } else {
1127 if (!(lvls[curlvlnum - 1].filename = mem_strdup(operand)))
1128 goto fatal_error;
1129 }
1130 } else if (!stricmp(command, "SECRET")) {
1131 if (curlvlnum == 0) {
1132 strcpy(errtext, TXT_MSN_LVLCOMMAND);
1133 goto msnfile_error;
1134 } else {
1135 lvls[curlvlnum - 1].flags |= LVLFLAG_SPAWNSECRET;
1136 lvls[curlvlnum - 1].secretlvl = atoi(operand);
1137 }
1138 } else if (!stricmp(command, "BRIEFING")) {
1139 if (curlvlnum == 0) {
1140 strcpy(errtext, TXT_MSN_LVLCOMMAND);
1141 goto msnfile_error;
1142 } else {
1143 lvls[curlvlnum - 1].flags |= LVLFLAG_BRIEFING;
1144 if (!(lvls[curlvlnum - 1].briefname = mem_strdup(operand)))
1145 goto fatal_error;
1146 }
1147 } else if (!stricmp(command, "BRANCH")) {
1148 // first check if number of level is greater than num_levels
1149 int lvlnum;
1150 if (curlvlnum == 0) {
1151 strcpy(errtext, TXT_MSN_LVLCOMMAND);
1152 goto msnfile_error;
1153 }
1154 lvlnum = atoi(operand);
1155 if (lvlnum == 0 || lvlnum > numlevels) {
1156 strcpy(errtext, TXT_MSN_LVLNUMINVALID);
1157 goto msnfile_error;
1158 }
1159 lvls[curlvlnum - 1].flags |= LVLFLAG_BRANCH;
1160 lvls[curlvlnum - 1].lvlbranch0 = lvlnum;
1161 } else if (!stricmp(command, "ENDMISSION")) {
1162 if (curlvlnum == 0) {
1163 strcpy(errtext, TXT_MSN_LVLCOMMAND);
1164 goto msnfile_error;
1165 } else {
1166 lvls[curlvlnum - 1].flags |= LVLFLAG_FINAL;
1167 }
1168 } else {
1169 snprintf(errtext, sizeof(errtext), TXT_MSN_ILLEGALCMD, command);
1170 goto msnfile_error;
1171 }
1172 }
1173 srclinenum++;
1174 }
1175 // set up current mission (movies are already set above)
1176 msn->cur_level = 1;
1177 msn->num_levels = numlevels;
1178 msn->levels = lvls;
1179 msn->filename = mem_strdup(mission);
1180 msn->game_state_flags = 0;
1181 strcpy(Net_msn_URLs.msnname, mission);
1182 res = true; // everthing is ok.
1183 // if error, print it out, else end.
1184 msnfile_error:
1185 if (!res) {
1186 char str_text[128];
1187 snprintf(str_text, sizeof(str_text), "%s\nline %d.", errtext, srclinenum);
1188 if (!Dedicated_server) {
1189 DoMessageBox(TXT_ERROR, str_text, MSGBOX_OK);
1190 } else {
1191 PrintDedicatedMessage("%s: %s\n", TXT_ERROR, str_text);
1192 }
1193 if (lvls)
1194 mem_free(lvls);
1195 }
1196 if (fp)
1197 cfclose(fp);
1198 // load default script here.
1199 if (!InitMissionScript()) {
1200 return false;
1201 }
1202 return res;
1203 fatal_error:
1204 mem_error();
1205 return false;
1206 #endif
1207 return false;
1208 }
1209 void FreeMission() {
1210 // Free up mission script
1211 int i; //,j;
1212 // close MN3 file if there is one.
1213 mn3_Close();
1214 // Tell Osiris to shutdown the Osiris Mission Memory System, freeing all memory
1215 Osiris_CloseOMMS();
1216 if (Current_mission.levels) {
1217 // free up any data allocated per level node.
1218 for (i = 0; i < Current_mission.num_levels; i++) {
1219 if (Current_mission.levels[i].filename)
1220 mem_free(Current_mission.levels[i].filename);
1221 if (Current_mission.levels[i].briefname)
1222 mem_free(Current_mission.levels[i].briefname);
1223 if (Current_mission.levels[i].hog)
1224 mem_free(Current_mission.levels[i].hog);
1225 if (Current_mission.levels[i].moviename)
1226 mem_free(Current_mission.levels[i].moviename);
1227 if (Current_mission.levels[i].endmovie)
1228 mem_free(Current_mission.levels[i].endmovie);
1229 if (Current_mission.levels[i].score)
1230 mem_free(Current_mission.levels[i].score);
1231 if (Current_mission.levels[i].progress)
1232 mem_free(Current_mission.levels[i].progress);
1233 }
1234 mem_free(Current_mission.levels);
1235 Current_mission.levels = NULL;
1236 }
1237 //@@ if (Current_mission.d3xmod) {
1238 //@@ D3XFreeProgram(Current_mission.d3xmod);
1239 //@@ Current_mission.d3xmod = NULL;
1240 //@@ }
1241 if (Current_mission.hog)
1242 mem_free(Current_mission.hog);
1243 if (Current_mission.filename) {
1244 // these DON't USE mem_free since we use _strdup, which doesn't use our memory routines.
1245 mem_free(Current_mission.filename);
1246 Current_mission.filename = NULL;
1247 }
1248 Current_mission.hog = NULL;
1249 Current_level = NULL;
1250 }
1251 #include "localization.h"
1252 #include "levelgoal.h"
1253 // Load the text (goal strings) for a level
1254 void LoadLevelText(const char *level_filename) {
1255 char pathname[_MAX_FNAME], filename[_MAX_FNAME];
1256 int n_strings;
1257 ddio_SplitPath(level_filename, pathname, filename, NULL);
1258 strcat(pathname, filename);
1259 strcat(pathname, ".str");
1260 char **goal_strings;
1261 if (CreateStringTable(pathname, &goal_strings, &n_strings)) {
1262 int n_goals = Level_goals.GetNumGoals();
1263 ASSERT(n_strings == (n_goals * 3));
1264 for (int i = 0; i < n_goals; i++) {
1265 Level_goals.GoalSetName(i, goal_strings[i * 3]);
1266 Level_goals.GoalSetItemName(i, goal_strings[i * 3 + 1]);
1267 Level_goals.GoalSetDesc(i, goal_strings[i * 3 + 2]);
1268 }
1269 DestroyStringTable(goal_strings, n_strings);
1270 }
1271 }
1272
1273 /* loads a level and sets it as current level in mission
1274 */
1275 bool LoadMissionLevel(int level) {
1276 Hud_show_controls = false;
1277 LoadLevelProgress(LOAD_PROGRESS_START, 0);
1278 if (!LoadLevel(Current_mission.levels[level - 1].filename, NULL)) {
1279 char buf[128];
1280 snprintf(buf, sizeof(buf), TXT_MSNERROR, Current_mission.levels[level - 1].filename);
1281 SetUICallback(DEFAULT_UICALLBACK);
1282 DoMessageBox(TXT_ERROR, buf, MSGBOX_OK);
1283 LoadLevelProgress(LOAD_PROGRESS_DONE, 0);
1284 return false;
1285 }
1286 // Test to see if levels are valid
1287 bool boa = true, terrain = true;
1288 char str[255];
1289
1290 if (BOAGetMineChecksum() != BOA_vis_checksum)
1291 boa = false;
1292 if (GetTerrainGeometryChecksum() != Terrain_checksum)
1293 terrain = false;
1294
1295 // JC: This isn't going to be fixed for a while, so silence the error
1296 /*
1297 if (!boa) {
1298 snprintf(str, sizeof(str), "BOA NOT VALID! %s", terrain ? "" : "TERRAINOCC NOT VALID!");
1299 ShowProgressScreen(str, NULL, true);
1300 Sleep(2000);
1301 } */
1302
1303 LoadLevelText(Current_mission.levels[level - 1].filename);
1304
1305 return true;
1306 }
1307 #define LOADBAR_X (16 * (float)Max_window_w / (float)FIXED_SCREEN_WIDTH)
1308 #define LOADBAR_Y1 (376 * (float)Max_window_h / (float)FIXED_SCREEN_HEIGHT)
1309 #define LOADBAR_Y2 (440 * (float)Max_window_h / (float)FIXED_SCREEN_HEIGHT)
1310 #define LOADBAR_W (260 * (float)Max_window_w / (float)FIXED_SCREEN_WIDTH)
1311 #define LOADBAR_H (22 * (float)Max_window_h / (float)FIXED_SCREEN_HEIGHT)
1312 #define N_LOAD_MSGS 12
1313 bool started_page = 0;
1314 /*
1315 $$TABLE_GAMEFILE "tunnelload.ogf"
1316 */
1317 bool Progress_screen_loaded = false;
1318 void LoadLevelProgress(int step, float percent, const char *chunk) {
1319 static tLargeBitmap level_bmp;
1320 static bool level_bmp_loaded = false;
1321 static int dedicated_last_string_len = -1;
1322 float lvl_percent_loaded = 0;
1323 float pag_percent_loaded = 0;
1324 int i;
1325 static int n_text_msgs = 0;
1326 static char text_msgs[N_LOAD_MSGS][80];
1327 char str[80];
1328 // If we're loading a level, send out a heartbeat
1329 if ((Game_mode & GM_MULTI)) {
1330 MultiSendHeartbeat();
1331 }
1332 if (percent > 1.0f) {
1333 percent = 1.0f;
1334 } else if (percent < 0.0f) {
1335 percent = 0.0f;
1336 }
1337 if ((!Progress_screen_loaded) && (step != LOAD_PROGRESS_START))
1338 return;
1339 switch (step) {
1340 case LOAD_PROGRESS_START: {
1341 lvl_percent_loaded = 0.0f;
1342 pag_percent_loaded = 0.0f;
1343 dedicated_last_string_len = -1;
1344 const char *p = NULL;
1345 if ((!(Game_mode & GM_MULTI)) && (!Current_mission.levels[Current_mission.cur_level - 1].progress)) {
1346 p = "tunnelload.ogf";
1347 } else {
1348 p = Current_mission.levels[Current_mission.cur_level - 1].progress;
1349 }
1350
1351 if (p) {
1352 if (LoadLargeBitmap(IGNORE_TABLE(p), &level_bmp)) {
1353 SetScreenMode(SM_MENU);
1354 level_bmp_loaded = true;
1355 n_text_msgs = 0;
1356 }
1357 }
1358 /*
1359 else
1360 {
1361 ShowProgressScreen (TXT_LOADINGLEVEL);
1362 }
1363 */
1364 Progress_screen_loaded = true;
1365 return;
1366 } break;
1367 case LOAD_PROGRESS_LOADING_LEVEL: {
1368 lvl_percent_loaded = percent;
1369 } break;
1370 case LOAD_PROGRESS_PAGING_DATA: {
1371 lvl_percent_loaded = 1.0f;
1372 pag_percent_loaded = percent;
1373 } break;
1374 case LOAD_PROGRESS_PREPARE:
1375 if (Dedicated_server) {
1376 PrintDedicatedMessage("\n");
1377 }
1378 lvl_percent_loaded = 1.0f;
1379 pag_percent_loaded = 1.0f;
1380 mprintf(0, "Prepare for Descent goes here...\n");
1381 // ShowProgressScreen(TXT_PREPARE_FOR_DESCENT,NULL,true);
1382 // return;
1383 break;
1384 case LOAD_PROGRESS_DONE: {
1385 if (level_bmp_loaded) {
1386 // print out final message
1387 FreeLargeBitmap(&level_bmp);
1388 level_bmp_loaded = false;
1389 }
1390 Progress_screen_loaded = false;
1391 if (Dedicated_server) {
1392 PrintDedicatedMessage("\n");
1393 }
1394 return;
1395 } break;
1396 default:
1397 mprintf(0, "Unknown step in LoadLevelProgress()\n");
1398 Int3();
1399 }
1400 if (Dedicated_server) {
1401 char tbuffer[512];
1402 char tbuffer1[512];
1403 nw_DoNetworkIdle();
1404 if (dedicated_last_string_len != -1) {
1405 memset(tbuffer, '\b', dedicated_last_string_len);
1406 tbuffer[dedicated_last_string_len] = '\0';
1407 PrintDedicatedMessage(tbuffer);
1408 }
1409 char levelname[100];
1410 snprintf(levelname, sizeof(levelname), "%s level %d", Current_mission.name, Current_mission.cur_level);
1411 if (lvl_percent_loaded < 1.0f) {
1412 snprintf(tbuffer1, sizeof(tbuffer1), TXT_DS_LEVELLOADSTATUS, levelname, lvl_percent_loaded * 100.0f);
1413 snprintf(tbuffer, sizeof(tbuffer), "%s%s", TXT_LOADINGLEVEL, tbuffer1);
1414 PrintDedicatedMessage(tbuffer);
1415 dedicated_last_string_len = strlen(tbuffer);
1416 } else {
1417 snprintf(tbuffer1, sizeof(tbuffer1), TXT_DS_LEVELLOADSTATUS, levelname, pag_percent_loaded * 100.0f);
1418 snprintf(tbuffer, sizeof(tbuffer), "%s%s", TXT_LL_PAGINGDATA, tbuffer1);
1419 PrintDedicatedMessage(tbuffer);
1420 dedicated_last_string_len = strlen(tbuffer);
1421 }
1422 return;
1423 }
1424 StartFrame(0, 0, Max_window_w, Max_window_h);
1425 // do background.
1426 if (!level_bmp_loaded) {
1427 int text_height;
1428 ASSERT(Current_level);
1429 rend_ClearScreen(GR_BLACK);
1430 grtext_SetFont(MENU_FONT);
1431 text_height = grfont_GetHeight(MENU_FONT);
1432 grtext_SetColor(GR_WHITE);
1433 grtext_CenteredPrintf(0, Max_window_h / 2, TXT_LOADINGLEVEL);
1434 // grtext_CenteredPrintf(0, (Max_window_h/2)+(text_height*2), Current_level->name);
1435 } else {
1436 #ifdef STEALTH // DAJ
1437 rend_ClearScreen(GR_BLACK);
1438 #else
1439 DrawLargeBitmap(&level_bmp, 0, 0, 1.0f);
1440 #endif
1441 // do relevent text.
1442 str[0] = 0;
1443 if (chunk) {
1444 if (strncmp(CHUNK_TERRAIN, chunk, strlen(CHUNK_TERRAIN)) == 0)
1445 strcpy(str, TXT_LL_TERRAIN);
1446 else if (strncmp(CHUNK_SCRIPT_CODE, chunk, strlen(CHUNK_SCRIPT_CODE)) == 0)
1447 strcpy(str, TXT_LL_SCRIPTLOADED);
1448 else if (strncmp(CHUNK_ROOMS, chunk, strlen(CHUNK_ROOMS)) == 0)
1449 strcpy(str, TXT_LL_ROOMSLOADED);
1450 else if (strncmp(CHUNK_OBJECTS, chunk, strlen(CHUNK_OBJECTS)) == 0)
1451 strcpy(str, TXT_LL_OBJECTSLOADED);
1452 }
1453 if (str[0]) {
1454 if (n_text_msgs == N_LOAD_MSGS) {
1455 for (i = 1; i < n_text_msgs; i++) {
1456 strcpy(text_msgs[i - 1], text_msgs[i]);
1457 }
1458 } else {
1459 n_text_msgs++;
1460 }
1461 strcpy(text_msgs[n_text_msgs - 1], str);
1462 }
1463 grtext_SetFont(BRIEFING_FONT);
1464 grtext_SetColor(GR_WHITE);
1465 grtext_SetAlpha(230);
1466 for (i = 0; i < n_text_msgs; i++) {
1467 grtext_Printf(14, 32 + (i * 15), text_msgs[i]);
1468 }
1469 }
1470 g3Point *pntlist[4], points[4];
1471 points[0].p3_sx = LOADBAR_X;
1472 points[0].p3_sy = LOADBAR_Y1;
1473 points[1].p3_sx = LOADBAR_X + LOADBAR_W;
1474 points[1].p3_sy = LOADBAR_Y1;
1475 points[2].p3_sx = LOADBAR_X + LOADBAR_W;
1476 points[2].p3_sy = LOADBAR_Y1 + LOADBAR_H;
1477 points[3].p3_sx = LOADBAR_X;
1478 points[3].p3_sy = LOADBAR_Y1 + LOADBAR_H;
1479 for (i = 0; i < 4; i++) {
1480 points[i].p3_z = 0;
1481 points[i].p3_flags = PF_PROJECTED;
1482 pntlist[i] = &points[i];
1483 }
1484 rend_SetZBufferState(0);
1485 rend_SetTextureType(TT_FLAT);
1486 rend_SetAlphaType(AT_CONSTANT);
1487 rend_SetLighting(LS_NONE);
1488 rend_SetAlphaValue(230);
1489 if (!level_bmp_loaded) {
1490 rend_SetFlatColor(GR_RGB(192, 192, 192));
1491 rend_DrawPolygon2D(0, pntlist, 4);
1492 }
1493
1494 pntlist[1]->p3_sx = LOADBAR_X + ((float)LOADBAR_W * lvl_percent_loaded);
1495 pntlist[2]->p3_sx = LOADBAR_X + ((float)LOADBAR_W * lvl_percent_loaded);
1496
1497 rend_SetFlatColor(GR_RGB(166, 7, 7));
1498 rend_DrawPolygon2D(0, pntlist, 4);
1499
1500 grtext_SetFont(BRIEFING_FONT);
1501 grtext_SetColor(GR_WHITE);
1502 if (lvl_percent_loaded != 1.0) {
1503 strcpy(str, TXT_LOADINGLEVEL);
1504 } else {
1505 strcpy(str, TXT_DONE);
1506 }
1507 grtext_Printf(LOADBAR_X + (LOADBAR_W - grtext_GetLineWidth(str)) / 2,
1508 LOADBAR_Y1 + (LOADBAR_H - grtext_GetHeight(str)) / 2, str);
1509 points[0].p3_sx = LOADBAR_X;
1510 points[0].p3_sy = LOADBAR_Y2;
1511 points[1].p3_sx = LOADBAR_X + LOADBAR_W;
1512 points[1].p3_sy = LOADBAR_Y2;
1513 points[2].p3_sx = LOADBAR_X + LOADBAR_W;
1514 points[2].p3_sy = LOADBAR_Y2 + LOADBAR_H;
1515 points[3].p3_sx = LOADBAR_X;
1516 points[3].p3_sy = LOADBAR_Y2 + LOADBAR_H;
1517 for (i = 0; i < 4; i++) {
1518 points[i].p3_z = 0;
1519 points[i].p3_flags = PF_PROJECTED;
1520 pntlist[i] = &points[i];
1521 }
1522 rend_SetZBufferState(0);
1523 rend_SetTextureType(TT_FLAT);
1524 rend_SetAlphaType(AT_CONSTANT);
1525 rend_SetLighting(LS_NONE);
1526 rend_SetAlphaValue(230);
1527 if (!level_bmp_loaded) {
1528 rend_SetFlatColor(GR_RGB(192, 192, 192));
1529 rend_DrawPolygon2D(0, pntlist, 4);
1530 }
1531
1532 pntlist[1]->p3_sx = LOADBAR_X + ((float)LOADBAR_W * pag_percent_loaded);
1533 pntlist[2]->p3_sx = LOADBAR_X + ((float)LOADBAR_W * pag_percent_loaded);
1534
1535 rend_SetFlatColor(GR_RGB(166, 7, 7));
1536 rend_DrawPolygon2D(0, pntlist, 4);
1537
1538 grtext_SetFont(BRIEFING_FONT);
1539 grtext_SetColor(GR_WHITE);
1540 if (pag_percent_loaded == 1.0) {
1541 strcpy(str, TXT_DONE);
1542 } else {
1543 strcpy(str, TXT_LL_PAGINGDATA);
1544 }
1545
1546 if (pag_percent_loaded > 0.0)
1547 grtext_Printf(LOADBAR_X + (LOADBAR_W - grtext_GetLineWidth(str)) / 2,
1548 LOADBAR_Y2 + (LOADBAR_H - grtext_GetHeight(str)) / 2, str);
1549
1550 // Display data errors
1551 extern int Data_error_count;
1552 if (Data_error_count) {
1553 char buf[1024];
1554 snprintf(buf, sizeof(buf), "This mission has %d data errors", Data_error_count);
1555 int y = 200 + 40;
1556 int x = 320 - (grtext_GetLineWidth(buf) / 2);
1557 grtext_Printf(x, y, buf);
1558 }
1559
1560 if (step == LOAD_PROGRESS_PREPARE) {
1561 grtext_SetFont(BIG_BRIEFING_FONT);
1562 grtext_SetColor(GR_WHITE);
1563
1564 int preparey = 200;
1565 int preparex = 320 - (grtext_GetLineWidth(TXT_PREPARE_FOR_DESCENT) / 2);
1566 if (preparex < 0)
1567 preparex = 0;
1568 grtext_Printf(preparex, preparey, TXT_PREPARE_FOR_DESCENT);
1569 }
1570 // Display level name if still loading
1571 if ((pag_percent_loaded > 0.0) && step != LOAD_PROGRESS_PREPARE) {
1572 char str[255];
1573
1574 snprintf(str, sizeof(str), "\"%s\"", Level_info.name);
1575 grtext_SetFont(BIG_BRIEFING_FONT);
1576 grtext_SetColor(GR_WHITE);
1577
1578 int preparey = 200;
1579 int preparex = 320 - (grtext_GetLineWidth(str) / 2);
1580 if (preparex < 0)
1581 preparex = 0;
1582 grtext_Printf(preparex, preparey, str);
1583 }
1584 grtext_Flush();
1585 EndFrame();
1586 rend_Flip();
1587 }
1588 /* this functions performs the end mission code
1589 */
1590 void DoEndMission() {
1591 if (Game_mode & GM_MULTI) // If multiplayer, just loop
1592 {
1593 if (Dedicated_server)
1594 PrintDedicatedMessage(TXT_DS_MISSIONDONE);
1595 SetCurrentLevel(1);
1596 return;
1597 }
1598 }
1599 // Shows some text on a background, useful for telling the player what is going on
1600 // ie "Loading level...", "Receiving data...", etc
1601 void ShowProgressScreen(const char *str, const char *str2, bool flip) {
1602 if (Dedicated_server) {
1603 PrintDedicatedMessage("%s\n", str);
1604 if (str2)
1605 PrintDedicatedMessage("%s\n", str2);
1606 return;
1607 }
1608 StartFrame(0, 0, Max_window_w, Max_window_h);
1609 rend_ClearScreen(GR_BLACK);
1610 grtext_SetFont(MENU_FONT);
1611 int text_height = grfont_GetHeight(MENU_FONT);
1612 grtext_SetColor(GR_WHITE);
1613 grtext_CenteredPrintf(0, Max_window_h / 2, str);
1614 if (str2)
1615 grtext_CenteredPrintf(0, (Max_window_h / 2) + (text_height * 2), str2);
1616 grtext_Flush();
1617 EndFrame();
1618 if (flip)
1619 rend_Flip();
1620 }
1621 /* does a mission briefing, returns if mission was canceled, a false, or 0 value.
1622 first displays mission goals and some warnings or advice.
1623 may allow for selection of player ships
1624 */
1625 bool DoMissionBriefing(int level) {
1626 tLevelNode *lvl = Current_level;
1627 bool ret = true;
1628 int num_ships = 0;
1629 for (int i = 0; i < MAX_SHIPS; i++) {
1630 if (Ships[i].used && PlayerIsShipAllowed(Player_num, i))
1631 num_ships++;
1632 }
1633 if (lvl->briefname[0] || num_ships > 1)
1634 ret = !TelComShow(TS_MISSION, false, true);
1635 return ret;
1636 }
1637 extern bool FirstGame;
1638
1639 // ---------------------------------------------------------------------------
1640 // play movie
1641 void DoMissionMovie(const char *movie) {
1642 if (PROGRAM(windowed)) {
1643 mprintf(0, "Skipping movie...can't do in windowed mode!\n");
1644 return;
1645 }
1646
1647 #ifdef D3_FAST
1648 return;
1649 #endif
1650 if (movie && *movie) {
1651 char mpath[_MAX_PATH];
1652 ddio_MakePath(mpath, LocalD3Dir, "movies", movie, NULL);
1653 PlayMovie(mpath);
1654 }
1655 }
1656
1657 ///////////////////////////////////////////////////////////////////////////////
1658 // Script Management for Missions and Levels
1659 ///////////////////////////////////////////////////////////////////////////////
1660 // Initializes a mission's default script
1661 bool InitMissionScript() {
1662 // need to do this so when UI runs, it has a background.
1663 // SetUICallback(DEFAULT_UICALLBACK);
1664 // if there is no default script, we will load a null script, which means that whatever object
1665 // uses scripts, will not do anything.
1666 //@@ fp = cfopen(DEFAULT_SCROBJ_NAME, "rb");
1667 //@@ if (!fp) {
1668 //@@ DoMessageBox("Error", "Unable to find mission script.", MSGBOX_OK, UICOL_WINDOW_TITLE,
1669 // UICOL_TEXT_NORMAL);
1670 //@@ mprintf(0, "Unable to open default script. Loading null script...\n");
1671 //@@ return false;
1672 //@@ }
1673 //@@ else {
1674 //@@ Current_mission.d3xmod = D3XLoadProgram(fp);
1675 //@@ if (!Current_mission.d3xmod) {
1676 //@@ DoMessageBox("Error", "Unable to find mission script.", MSGBOX_OK, UICOL_WINDOW_TITLE,
1677 // UICOL_TEXT_NORMAL);
1678 //@@ mprintf(0, "Unable to open default script. Loading null script...\n");
1679 //@@ return false;
1680 //@@ }
1681 //@@ cfclose(fp);
1682 //@@ }
1683 return true;
1684 }
1685 extern bool IsRestoredGame;
1686 void InitLevelScript() {
1687 if (Current_level->filename) {
1688 char filename[_MAX_PATH], ext[_MAX_EXT];
1689 ddio_SplitPath(Current_level->filename, NULL, filename, ext);
1690 #if defined(WIN32)
1691 strcat(filename, ".dll");
1692 #elif defined(MACOSX)
1693 strcat(filename, ".dylib");
1694 #elif defined(__LINUX__)
1695 strcat(filename, ".so");
1696 #else
1697 #error Unsupported platform!
1698 #endif
1699 Osiris_LoadLevelModule(filename);
1700 }
1701 //@$-D3XExecScript(Current_level->d3xthread, Current_mission.cur_level, REF_LEVELTYPE, EVT_LEVELSTART, 0, 0);
1702 tOSIRISEventInfo ei;
1703 // This is a hack... we don't want the level start script to be called when restoring a save game
1704 if (!IsRestoredGame)
1705 Osiris_CallLevelEvent(EVT_LEVELSTART, &ei);
1706 AssignScriptsForLevel(); // initialize all scripts for level.
1707 }
1708 void FreeLevelScript() {
1709 Osiris_UnloadLevelModule();
1710 if (Current_level) {
1711 // free level's script and thread
1712 //@$-D3XExecScript(Current_level->d3xthread, Current_mission.cur_level, REF_LEVELTYPE, EVT_LEVELEND, 0, 0);
1713 tOSIRISEventInfo ei;
1714 Osiris_CallLevelEvent(EVT_LEVELEND, &ei);
1715 }
1716 }
1717 // return information about a mission
1718 bool GetMissionInfo(const char *msnfile, tMissionInfo *msn) {
1719 CFILE *fp;
1720 bool indesc = false; // are we in a multi-line block
1721 // open mission file
1722 if (IS_MN3_FILE(msnfile)) {
1723 return mn3_GetInfo(msnfile, msn);
1724 }
1725 fp = cfopen(msnfile, "rt");
1726 if (!fp) {
1727 mprintf(0, "Failed to open mission file %s in GetMissionInfo.\n", msnfile);
1728 return false;
1729 }
1730 msn->multi = true;
1731 msn->single = true;
1732 msn->training = false;
1733 msn->author[0] = 0;
1734 msn->desc[0] = 0;
1735 while (!cfeof(fp)) {
1736 char srcline[128]; // One line of mission source
1737 char command[32]; // Command read from line.
1738 char operand[96]; // operand read from line
1739 char *keyword; // parsed keyword
1740 int readcount; // read-in count
1741 readcount = cf_ReadString(srcline, sizeof(srcline), fp);
1742 if (readcount) {
1743 // we have a line of source. parse out primary keyword
1744 // then parse out remainder.
1745 keyword = strtok(srcline, " \t");
1746 CleanupStr(command, srcline, sizeof(command));
1747 CleanupStr(operand, srcline + strlen(command) + 1, sizeof(operand));
1748 if (strlen(command) && indesc)
1749 indesc = false;
1750 if (!stricmp(command, "NAME")) {
1751 strncpy(msn->name, operand, MSN_NAMELEN - 1);
1752 } else if (!stricmp(command, "MULTI")) {
1753 if (stricmp("no", operand) == 0)
1754 msn->multi = false;
1755 } else if (!stricmp(command, "SINGLE")) {
1756 if (stricmp("no", operand) == 0)
1757 msn->single = false;
1758 } else if (!stricmp(command, "TRAINER")) {
1759 msn->training = true;
1760 } else if (!stricmp(command, "AUTHOR")) {
1761 strncpy(msn->author, operand, MSN_NAMELEN - 1);
1762 } else if (!stricmp(command, "DESCRIPTION") || indesc) {
1763 // multi-line descriptions require the strcat. the initial
1764 // strings should be empty for this to work.
1765 strcat(msn->desc, operand);
1766 if (indesc)
1767 strcat(msn->desc, "\n");
1768 indesc = true; // this is a multiline command
1769 } else if (!stricmp(command, "NUMLEVELS")) {
1770 // get number of levels
1771 int value = atoi(operand);
1772 msn->n_levels = value;
1773 } else if (!stricmp(command, "LEVEL")) {
1774 break;
1775 } else if (!stricmp(command, "KEYWORDS")) {
1776 // Read in all the keywords
1777 strncpy(msn->keywords, operand, MAX_KEYWORDLEN);
1778 }
1779 }
1780 }
1781 cfclose(fp);
1782 return true;
1783 }
1784 // ---------------------------------------------------------------------------
1785 const char *GetMissionName(const char *mission) {
1786 tMissionInfo msninfo;
1787 static char msnname[MSN_NAMELEN];
1788 msnname[0] = 0;
1789 if (GetMissionInfo(mission, &msninfo)) {
1790 strcpy(msnname, msninfo.name);
1791 } else {
1792 mprintf(0, "MISSION:GetMissionName failed from call to GetMissionInfo\n");
1793 }
1794 return msnname;
1795 }
1796 bool IsMissionMultiPlayable(const char *mission) {
1797 tMissionInfo msninfo;
1798 if (GetMissionInfo(mission, &msninfo)) {
1799 return msninfo.multi;
1800 }
1801 return false;
1802 }
1803 bool IsMissionSinglePlayable(const char *mission) {
1804 tMissionInfo msninfo;
1805 if (GetMissionInfo(mission, &msninfo)) {
1806 return msninfo.single;
1807 }
1808 return false;
1809 }
1810 int Mission_voice_hog_handle = 0;
1811 // MN3 based mission functions.
1812 // loads the msn file from the mn3 file specified, specifies the hog and table file.
1813 bool mn3_Open(const char *mn3file) {
1814 char pathname[_MAX_PATH];
1815 char filename[PSFILENAME_LEN + 1];
1816 char ext[PSFILENAME_LEN];
1817 int mn3_handle;
1818 // concatanate the mn3 extension if it isn't there.
1819 char tempMn3File[_MAX_PATH];
1820 if (!IS_MN3_FILE(mn3file)) {
1821 strncpy(tempMn3File, mn3file, sizeof(tempMn3File) - 1);
1822 tempMn3File[sizeof(tempMn3File) - 1] = 0;
1823 strcat(tempMn3File, ".mn3");
1824 mn3file = tempMn3File;
1825 }
1826
1827 ddio_MakePath(pathname, D3MissionsDir, mn3file, NULL);
1828 // open MN3 HOG.
1829 mn3_handle = cf_OpenLibrary(mn3file);
1830 if (mn3_handle == 0) {
1831 return false;
1832 } else {
1833 Osiris_ExtractScriptsFromHog(mn3_handle, true);
1834 }
1835 // do table file stuff.
1836 ddio_SplitPath(mn3file, NULL, filename, ext);
1837
1838 char voice_hog[_MAX_PATH*2];
1839 if ((stricmp(filename, "d3") == 0) || (stricmp(filename, "training") == 0)) {
1840 // Open audio hog file
1841 ddio_MakePath(voice_hog, D3MissionsDir, "d3voice1.hog", nullptr); // Audio for levels 1-4
1842 Mission_voice_hog_handle = cf_OpenLibrary(voice_hog);
1843 } else if (stricmp(filename, "d3_2") == 0) {
1844 // Open audio hog file
1845 ddio_MakePath(voice_hog, D3MissionsDir, "d3voice2.hog", nullptr); // Audio for levels 5-17
1846 Mission_voice_hog_handle = cf_OpenLibrary(voice_hog);
1847 }
1848 strcat(filename, ".gam");
1849 mng_SetAddonTable(filename);
1850 Current_mission.mn3_handle = mn3_handle;
1851 return true;
1852 }
1853
1854 // returns mission information given the mn3 file.
1855 bool mn3_GetInfo(const char *mn3file, tMissionInfo *msn) {
1856 int handle;
1857 bool retval;
1858 char pathname[_MAX_PATH];
1859 char filename[PSFILENAME_LEN + 1];
1860
1861 ddio_MakePath(pathname, D3MissionsDir, mn3file, nullptr);
1862 handle = cf_OpenLibrary(pathname);
1863 if (handle == 0) {
1864 mprintf(0, "MISSION: MN3 failed to open.\n");
1865 return false;
1866 }
1867 MN3_TO_MSN_NAME(mn3file, filename);
1868 retval = GetMissionInfo(filename, msn);
1869 cf_CloseLibrary(handle);
1870 return retval;
1871 }
1872 // closes the current mn3 file
1873 void mn3_Close() {
1874 if (Current_mission.mn3_handle) {
1875 Osiris_ClearExtractedScripts(true);
1876 cf_CloseLibrary(Current_mission.mn3_handle);
1877 }
1878 if (Mission_voice_hog_handle) {
1879 cf_CloseLibrary(Mission_voice_hog_handle);
1880 Mission_voice_hog_handle = 0;
1881 }
1882 Current_mission.mn3_handle = 0;
1883 }
1884 #define KEYWORD_LEN 16
1885 #define NUM_KEYWORDS 16
1886 #define GOALSTEXT "GOALS"
1887 #define GOALSTEXTLEN strlen(GOALSTEXT)
1888 #define MODMINGOALS "MINGOALS"
1889 #define MODMINGOALSLEN strlen(MODMINGOALS)
1890 // Returns the max number of teams this mission can support for this mod, or
1891 //-1 if this level shouldn't be played with this mission
1892 // Return values:
1893 // -1 Bad match -- this level and this mod shouldn't be played together!
1894 // MAX_NET_PLAYERS -- This is playable with any number of teams the mod wants
1895 int MissionGetKeywords(const char *mission, char *keywords) {
1896 ASSERT(mission);
1897 ASSERT(keywords);
1898
1899 char msn_keywords[NUM_KEYWORDS][KEYWORD_LEN];
1900 char mod_keywords[NUM_KEYWORDS][KEYWORD_LEN];
1901 int i;
1902 char *parse_keys = mem_strdup(keywords);
1903 char seps[] = ",";
1904 int teams = MAX_NET_PLAYERS;
1905 int goals = 0;
1906 int goalsneeded = 0;
1907 int mod_key_count = 0;
1908 int msn_key_count = 0;
1909 bool goal_per_team = false;
1910 tMissionInfo msn_info;
1911
1912 memset(msn_keywords, 0, sizeof(msn_keywords));
1913 memset(mod_keywords, 0, sizeof(mod_keywords));
1914 mprintf(0, "MissionGetKeywords(%s,%s)\n", mission, keywords);
1915 if (!GetMissionInfo(mission, &msn_info)) {
1916 return -1;
1917 }
1918
1919 if (!*parse_keys) {
1920 return MAX_NET_PLAYERS;
1921 }
1922 // Break up the mod keywords into an array
1923 char *tokp = strtok(parse_keys, seps);
1924 if (tokp) {
1925 do {
1926 strcpy(mod_keywords[mod_key_count], tokp);
1927 mod_key_count++;
1928 tokp = strtok(NULL, seps);
1929 } while ((tokp) && (mod_key_count < NUM_KEYWORDS));
1930 }
1931 // Break up the msn keywords into an array
1932 tokp = strtok(msn_info.keywords, seps);
1933 if (tokp) {
1934 do {
1935 strcpy(msn_keywords[msn_key_count], tokp);
1936 msn_key_count++;
1937 tokp = strtok(NULL, seps);
1938 } while ((tokp) && (msn_key_count < NUM_KEYWORDS));
1939 }
1940
1941 for (i = 0; i < NUM_KEYWORDS; i++) {
1942 if (msn_keywords[i][0] == 0) {
1943 continue;
1944 }
1945 if (strnicmp(GOALSTEXT, msn_keywords[i], GOALSTEXTLEN) == 0) {
1946 // Get the number of goals this game has
1947 goals = atoi(msn_keywords[i] + GOALSTEXTLEN);
1948 }
1949 }
1950 mem_free(parse_keys);
1951
1952 // Loop through looking for matches
1953 for (i = 0; i < NUM_KEYWORDS; i++) {
1954 if (mod_keywords[i][0] == 0) {
1955 continue;
1956 }
1957 if (strnicmp(mod_keywords[i], MODMINGOALS, MODMINGOALSLEN) == 0) {
1958 goalsneeded = atoi(mod_keywords[i] + MODMINGOALSLEN);
1959 } else if (stricmp("GOALPERTEAM", mod_keywords[i]) == 0) {
1960 goal_per_team = true;
1961 } else {
1962 bool found_keyword = false;
1963 // Loop through looking for matches
1964 for (int a = 0; a < NUM_KEYWORDS; a++) {
1965 if (msn_keywords[a][0] == 0) {
1966 continue;
1967 }
1968 if (stricmp(msn_keywords[a], mod_keywords[i]) == 0) {
1969 // Woohoo! it's found
1970 found_keyword = true;
1971 break;
1972 }
1973 }
1974 // We never found one we needed, so return -1;
1975 if (!found_keyword) {
1976 mprintf(0, "%s keyword needed in %s not found!\n", mod_keywords[i], mission);
1977 return -1;
1978 }
1979 }
1980 }
1981 if (goal_per_team) {
1982 teams = goals;
1983 }
1984 if (teams < goalsneeded) {
1985 mprintf(0, "Not enough goals in this level!\n");
1986 teams = -1;
1987 }
1988 if (goals < goalsneeded) {
1989 mprintf(0, "Not enough goals in this level!\n");
1990 teams = -1;
1991 }
1992 return teams;
1993 }
1994 //////////////////////////////////////////////////////////////////////////////
1995 #ifdef EDITOR
1996 // Used by editor->game to load all necessary elements for level playing for systems
1997 // not initialized in editor, but only in game.
1998 extern char Editor_quickplay_levelname[_MAX_PATH];
1999 void QuickStartMission() {
2000 // create the level script code here, if we really need to.
2001 ResetGamemode();
2002 // this initializes a mini one level mission with no frills.
2003 Current_mission.cur_level = 1;
2004 Current_mission.num_levels = 1;
2005 Current_mission.levels = (tLevelNode *)mem_malloc(sizeof(tLevelNode));
2006 memset(Current_mission.levels, 0, sizeof(tLevelNode));
2007 Current_level = Current_mission.levels;
2008 if (Editor_quickplay_levelname[0] != '\0')
2009 Current_level->filename = mem_strdup(Editor_quickplay_levelname);
2010 else
2011 Current_level->filename = NULL;
2012 // proceed with initialization.
2013 InitMissionScript();
2014 SetGameState(GAMESTATE_LVLSTART);
2015 }
2016 // Used by game->editor to free up all extra game mission elements not needed in editor.
2017 void QuickEndMission() {
2018 //@@ FreeScriptsForLevel();
2019 //@@ D3XFreeProgram(Current_mission.d3xmod);
2020 //@@ Current_mission.d3xmod = NULL;
2021 // free up mini mission.
2022 //@@ Current_level = NULL;
2023 //@@ mem_free(Current_mission.levels);
2024 //@@ Current_mission.levels = NULL;
2025 ResetMission();
2026 }
2027 #endif