-
Notifications
You must be signed in to change notification settings - Fork 182
Expand file tree
/
Copy pathfreespace.cpp
More file actions
8171 lines (6606 loc) · 228 KB
/
Copy pathfreespace.cpp
File metadata and controls
8171 lines (6606 loc) · 228 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) Volition, Inc. 1999. All rights reserved.
*
* All source code herein is the property of Volition, Inc. You may not sell
* or otherwise commercially exploit the source or things you created based on the
* source.
*
*/
#ifdef _WIN32
#include <winsock2.h> // required to prevent winsock 1.1 being used
#include <direct.h>
#include <io.h>
#include <psapi.h>
#ifndef _MINGW
#include <crtdbg.h>
#endif // !_MINGW
#else
#ifdef APPLE_APP
#include <sys/types.h>
#include <libproc.h>
#endif
#include <unistd.h>
#include <sys/stat.h>
#endif
#include "globalincs/alphacolors.h"
#include "globalincs/crashdump.h"
#include "globalincs/mspdb_callstack.h"
#include "globalincs/version.h"
#include "SDLGraphicsOperations.h"
#include "freespace.h"
#include "freespaceresource.h"
#include "levelpaging.h"
#include "anim/animplay.h"
#include "asteroid/asteroid.h"
#include "autopilot/autopilot.h"
#include "bmpman/bmpman.h"
#include "camera/photomode.h"
#include "cfile/cfile.h"
#include "cheats_table/cheats_table.h"
#include "cmdline/cmdline.h"
#include "cmeasure/cmeasure.h"
#include "cutscene/cutscenes.h"
#include "cutscene/movie.h"
#include "executor/global_executors.h"
#include "cutscene/player.h"
#include "debris/debris.h"
#include "debugconsole/console.h"
#include "decals/decals.h"
#include "events/events.h"
#include "exceptionhandler/exceptionhandler.h"
#include "fireball/fireballs.h"
#include "gamehelp/contexthelp.h"
#include "gamehelp/gameplayhelp.h"
#include "gamesequence/gamesequence.h"
#include "gamesnd/eventmusic.h"
#include "gamesnd/gamesnd.h"
#include "graphics/debug_sphere.h"
#include "graphics/font.h"
#include "graphics/light.h"
#include "graphics/matrix.h"
#include "graphics/openxr.h"
#include "graphics/shadows.h"
#include "headtracking/headtracking.h"
#include "hud/hud.h"
#include "hud/hudconfig.h"
#include "hud/hudescort.h"
#include "hud/hudlock.h"
#include "hud/hudmessage.h"
#include "hud/hudparse.h"
#include "hud/hudshield.h"
#include "hud/hudsquadmsg.h"
#include "hud/hudtargetbox.h"
#include "iff_defs/iff_defs.h"
#include "io/cursor.h"
#include "io/joy.h"
#include "io/joy_ff.h"
#include "io/key.h"
#include "io/mouse.h"
#include "io/timer.h"
#include "jumpnode/jumpnode.h"
#include "lab/labv2.h"
#include "libs/discord/discord.h"
#include "libs/ffmpeg/FFmpeg.h"
#include "lighting/lighting.h"
#include "lighting/lighting_profiles.h"
#include "localization/localize.h"
#include "math/staticrand.h"
#include "math/curve.h"
#include "menuui/barracks.h"
#include "menuui/credits.h"
#include "menuui/mainhallmenu.h"
#include "menuui/optionsmenu.h"
#include "menuui/playermenu.h"
#include "menuui/readyroom.h"
#include "menuui/snazzyui.h"
#include "menuui/techmenu.h"
#include "menuui/trainingmenu.h"
#include "mission/missionbriefcommon.h"
#include "mission/missioncampaign.h"
#include "mission/missiongoals.h"
#include "mission/missionhotkey.h"
#include "mission/missionload.h"
#include "mission/missionlog.h"
#include "mission/missionmessage.h"
#include "mission/missionparse.h"
#include "mission/missiontraining.h"
#include "missionui/fictionviewer.h"
#include "missionui/missionbrief.h"
#include "missionui/missioncmdbrief.h"
#include "missionui/missiondebrief.h"
#include "missionui/missionloopbrief.h"
#include "missionui/missionpause.h"
#include "missionui/missionscreencommon.h"
#include "missionui/missionshipchoice.h"
#include "missionui/missionweaponchoice.h"
#include "missionui/redalert.h"
#include "mod_table/mod_table.h"
#include "model/modelrender.h"
#include "model/modelreplace.h"
#include "nebula/neb.h"
#include "nebula/neblightning.h"
#include "nebula/volumetrics.h"
#include "network/multi.h"
#include "network/multi_dogfight.h"
#include "network/multi_endgame.h"
#include "network/multi_fstracker.h"
#include "network/multi_ingame.h"
#include "network/multi_interpolate.h"
#include "network/multi_log.h"
#include "network/multi_pause.h"
#include "network/multi_pxo.h"
#include "network/multi_rate.h"
#include "network/multi_respawn.h"
#include "network/multi_turret_manager.h"
#include "network/multi_voice.h"
#include "network/multimsgs.h"
#include "network/multiteamselect.h"
#include "network/multiui.h"
#include "network/multiutil.h"
#include "network/stand_gui.h"
#include "object/objcollide.h"
#include "object/objectsnd.h"
#include "object/waypoint.h"
#include "observer/observer.h"
#include "options/default_settings_table.h"
#include "options/Ingame_Options.h"
#include "options/Option.h"
#include "options/OptionsManager.h"
#include "osapi/osapi.h"
#include "osapi/osregistry.h"
#include "parse/encrypt.h"
#include "parse/generic_log.h"
#include "parse/parselo.h"
#include "parse/sexp.h"
#include "parse/sexp/sexp_lookup.h"
#include "particle/ParticleManager.h"
#include "particle/particle.h"
#include "pilotfile/pilotfile.h"
#include "playerman/managepilot.h"
#include "playerman/player.h"
#include "popup/popup.h"
#include "popup/popupdead.h"
#include "prop/prop.h"
#include "radar/radar.h"
#include "radar/radarsetup.h"
#include "render/3d.h"
#include "render/batching.h"
#include "scpui/rocket_ui.h"
#include "scripting/api/objs/gamestate.h"
#include "scripting/api/objs/camera.h"
#include "scripting/global_hooks.h"
#include "scripting/hook_api.h"
#include "scripting/scripting.h"
#include "ship/afterburner.h"
#include "ship/awacs.h"
#include "ship/ship.h"
#include "ship/shipcontrails.h"
#include "ship/shipfx.h"
#include "ship/shiphit.h"
#include "sound/audiostr.h"
#include "sound/ds.h"
#include "sound/fsspeech.h"
#include "sound/sound.h"
#include "sound/voicerec.h"
#include "starfield/starfield.h"
#include "starfield/supernova.h"
#include "stats/medals.h"
#include "stats/stats.h"
#include "tracing/Monitor.h"
#include "tracing/tracing.h"
#include "utils/Random.h"
#include "utils/threading.h"
#include "weapon/beam.h"
#include "weapon/emp.h"
#include "weapon/flak.h"
#include "weapon/muzzleflash.h"
#include "weapon/shockwave.h"
#include "weapon/weapon.h"
#include <SDL.h>
#include <SDL_main.h>
#include <cinttypes>
#include <stdexcept>
#include "imgui.h"
#ifdef WIN32
// According to AMD and NV, these _should_ force their drivers into high-performance mode
extern "C" {
__declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
__declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
}
#endif
#ifdef NDEBUG
#ifdef FRED
#error macro FRED is defined when trying to build release FreeSpace. Please undefine FRED macro in build settings
#endif
#endif
// Revision history.
// Full version:
// 1.00.04 5/26/98 MWA -- going final (12 pm)
// 1.00.03 5/26/98 MWA -- going final (3 am)
// 1.00.02 5/25/98 MWA -- going final
// 1.00.01 5/25/98 MWA -- going final
// 0.90 5/21/98 MWA -- getting ready for final.
// 0.10 4/9/98. Set by MK.
//
// OEM version:
// 1.00 5/28/98 AL. First release to Interplay QA.
void game_reset_view_clip();
void game_reset_shade_frame();
void game_post_level_init();
void game_do_frame(bool set_frametime = true);
void game_time_level_init();
void game_time_level_close();
void game_show_framerate(); // draws framerate in lower right corner
struct big_expl_flash {
float max_flash_intensity; // max intensity
float cur_flash_intensity; // cur intensity
TIMESTAMP flash_start; // start time
};
#define FRAME_FILTER 16
#define DEFAULT_SKILL_LEVEL 1
int Game_skill_level = DEFAULT_SKILL_LEVEL;
static SCP_string skill_level_display(int value)
{
return SCP_string(Skill_level_names(value, true));
}
static void parse_skill_func()
{
int value;
stuff_int(&value);
value -= 1; // Parse 1-5 for the skill levels but convert to our internal 0-4
CLAMP(value, 0, 4);
Game_skill_level = value;
}
// coverity[GLOBAL_INIT_ORDER] -- safe; OptionBuilder::finish() uses Meyers singleton
static auto GameSkillOption __UNUSED = options::OptionBuilder<int>("Game.SkillLevel",
std::pair<const char*, int>{"Skill Level", 1284},
std::pair<const char*, int>{"The skill level for the game.", 1700})
.category(std::make_pair("Game", 1824))
.range(0, 4)
.level(options::ExpertLevel::Beginner)
.default_func([]() { return DEFAULT_SKILL_LEVEL; })
.bind_to(&Game_skill_level)
.display(skill_level_display)
.importance(1)
.flags({options::OptionFlags::RetailBuiltinOption})
.parser(parse_skill_func)
.finish();
bool Screenshake_enabled = true;
static void parse_screenshake_func()
{
bool enabled;
stuff_boolean(&enabled);
Screenshake_enabled = enabled;
}
// coverity[GLOBAL_INIT_ORDER] -- safe; OptionBuilder::finish() uses Meyers singleton
auto ScreenShakeOption = options::OptionBuilder<bool>("Graphics.ScreenShake",
std::pair<const char*, int>{"Screen Shudder Effect", 1812}, // do xstr
std::pair<const char*, int>{"Toggles the screen shake effect for weapons, afterburners, and shockwaves", 1813})
.category(std::make_pair("Graphics", 1825))
.default_func([]() { return Screenshake_enabled; })
.level(options::ExpertLevel::Advanced)
.importance(55)
.bind_to(&Screenshake_enabled)
.parser(parse_screenshake_func)
.finish();
bool Allow_unfocused_pause = true;
static SCP_string unfocused_pause_display(bool mode) { return mode ? XSTR("Yes", 1394) : XSTR("No", 1395); }
static void parse_unfocused_pause_func()
{
bool enabled;
stuff_boolean(&enabled);
Allow_unfocused_pause = enabled;
}
// coverity[GLOBAL_INIT_ORDER] -- safe; OptionBuilder::finish() uses Meyers singleton
auto UnfocusedPauseOption = options::OptionBuilder<bool>("Game.UnfocusedPause",
std::pair<const char*, int>{"Pause If Unfocused", 1814}, // do xstr
std::pair<const char*, int>{"Whether or not the game automatically pauses if it loses focus", 1815})
.category(std::make_pair("Game", 1824))
.default_func([]() { return Allow_unfocused_pause; })
.level(options::ExpertLevel::Advanced)
.display(unfocused_pause_display)
.importance(55)
.bind_to(&Allow_unfocused_pause)
.parser(parse_unfocused_pause_func)
.finish();
#define EXE_FNAME ("fs2.exe")
// JAS: Code for warphole camera.
// Needs to be cleaned up.
float Warpout_time = 0.0f;
int Warpout_forced = 0; // Set if this is a forced warpout that cannot be cancelled.
sound_handle Warpout_sound = sound_handle::invalid();
int Use_joy_mouse = 0;
int Use_palette_flash = 1;
#ifndef NDEBUG
int Use_fullscreen_at_startup = 0;
#endif
int Show_area_effect = 0;
object *Last_view_target = nullptr;
int dogfight_blown = 0;
int frame_int = -1;
float frametimes[FRAME_FILTER];
float frametotal = 0.0f;
float flRealframetime;
float flFrametime;
fix FrametimeOverall = 0;
#ifndef NDEBUG
int Show_framerate = 1;
#else
int Show_framerate = 0;
#endif
int Framerate_cap = 120;
// for the model page in system
extern void model_page_in_start();
int Show_cpu = 0;
int Show_target_debug_info = 0;
int Show_target_weapons = 0;
#ifndef NDEBUG
static int Show_player_pos = 0; // debug console command to show player world pos on HUD
#endif
int Debug_octant = -1;
fix Game_time_compression = F1_0;
fix Desired_time_compression = Game_time_compression;
fix Time_compression_change_rate = 0;
bool Time_compression_locked = false; //Can the user change time with shift- controls?
// auto-lang stuff
int detect_lang();
// if the ships.tbl the player has is valid
int Game_ships_tbl_valid = 0;
// if the weapons.tbl the player has is valid
int Game_weapons_tbl_valid = 0;
int Test_begin = 0;
extern int Player_attacking_enabled;
int Show_net_stats;
bool Pre_player_entry = false;
int Fred_running = 0;
int Qtfred_running = 0;
bool running_unittests = false;
// required for hudtarget... kinda dumb, but meh
char Fred_alt_names[MAX_SHIPS][NAME_LENGTH+1];
char Fred_callsigns[MAX_SHIPS][NAME_LENGTH+1];
char Game_current_mission_filename[MAX_FILENAME_LEN];
int game_single_step = 0;
int last_single_step=0;
int game_zbuffer = 1;
extern void ssm_init();
extern void ssm_level_init();
extern void ssm_process();
// static variable to contain the time this version was built
// commented out for now until
// I figure out how to get the username into the file
//LOCAL char freespace_build_time[] = "Compiled on:"__DATE__" "__TIME__" by "__USER__;
// amount of time to wait after the player has died before we display the death died popup
#define PLAYER_DIED_POPUP_WAIT 2500
UI_TIMESTAMP Player_died_popup_wait;
UI_TIMESTAMP Multi_ping_timestamp;
// builtin mission list stuff
int Game_builtin_mission_count = 92;
fs_builtin_mission Game_builtin_mission_list[MAX_BUILTIN_MISSIONS] = {
// single player campaign
{ "freespace2.fc2", (FSB_FROM_VOLITION | FSB_CAMPAIGN_FILE), "" },
// act 1
{ "sm1-01.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_2 },
{ "sm1-02.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_2 },
{ "sm1-03.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_2 },
{ "sm1-04.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_2 },
{ "sm1-05.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_2 },
{ "sm1-06.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_2 },
{ "sm1-07.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_2 },
{ "sm1-08.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_2 },
{ "sm1-09.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_2 },
{ "sm1-10.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_2 },
{ "loop1-1.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_2 },
{ "loop1-2.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_2 },
{ "loop1-3.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_2 },
{ "training-1.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_2 },
{ "training-2.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_2 },
{ "training-3.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_2 },
{ "tsm-104.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_2 },
{ "tsm-105.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_2 },
{ "tsm-106.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_2 },
// act 2
{ "sm2-01.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_3 },
{ "sm2-02.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_3 },
{ "sm2-03.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_3 },
{ "sm2-04.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_3 },
{ "sm2-05.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_3 },
{ "sm2-06.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_3 },
{ "sm2-07.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_3 },
{ "sm2-08.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_3 },
{ "sm2-09.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_3 },
{ "sm2-10.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_3 },
// act 3
{ "sm3-01.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_3 },
{ "sm3-02.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_3 },
{ "sm3-03.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_3 },
{ "sm3-04.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_3 },
{ "sm3-05.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_3 },
{ "sm3-06.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_3 },
{ "sm3-07.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_3 },
{ "sm3-08.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_3 },
{ "sm3-09.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_3 },
{ "sm3-10.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_3 },
{ "loop2-1.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_3 },
{ "loop2-2.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_3 },
// multiplayer missions
// gauntlet
{ "g-shi.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
{ "g-ter.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
{ "g-vas.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
// coop
{ "m-01.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
{ "m-02.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
{ "m-03.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
{ "m-04.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
// dogfight
{ "mdh-01.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
{ "mdh-02.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
{ "mdh-03.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
{ "mdh-04.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
{ "mdh-05.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
{ "mdh-06.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
{ "mdh-07.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
{ "mdh-08.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
{ "mdh-09.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
{ "mdl-01.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
{ "mdl-02.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
{ "mdl-03.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
{ "mdl-04.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
{ "mdl-05.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
{ "mdl-06.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
{ "mdl-07.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
{ "mdl-08.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
{ "mdl-09.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
{ "mdm-01.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
{ "mdm-02.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
{ "mdm-03.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
{ "mdm-04.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
{ "mdm-05.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
{ "mdm-06.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
{ "mdm-07.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
{ "mdm-08.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
{ "mdm-09.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
{ "osdog.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
// TvT
{ "mt-01.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
{ "mt-02.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
{ "mt-03.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
{ "mt-04.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
{ "mt-05.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
{ "mt-06.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
{ "mt-07.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
{ "mt-08.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
{ "mt-09.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
{ "mt-10.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
// campaign
{ "templar.fc2", (FSB_FROM_VOLITION | FSB_MULTI | FSB_CAMPAIGN_FILE), "" },
{ "templar-01.fs2", (FSB_FROM_VOLITION | FSB_MULTI | FSB_CAMPAIGN), "" },
{ "templar-02.fs2", (FSB_FROM_VOLITION | FSB_MULTI | FSB_CAMPAIGN), "" },
{ "templar-03.fs2", (FSB_FROM_VOLITION | FSB_MULTI | FSB_CAMPAIGN), "" },
{ "templar-04.fs2", (FSB_FROM_VOLITION | FSB_MULTI | FSB_CAMPAIGN), "" },
};
// Internal function prototypes
void game_do_training_checks();
void game_shutdown();
void game_show_event_debug(float frametime);
void game_event_debug_init();
void game_frame(bool paused = false);
void game_start_subspace_ambient_sound();
void game_stop_subspace_ambient_sound();
void verify_ships_tbl();
void verify_weapons_tbl();
void game_title_screen_display();
void game_title_screen_close();
// loading background filenames
static const char *Game_loading_bground_fname[GR_NUM_RESOLUTIONS] = {
"LoadingBG", // GR_640
"2_LoadingBG" // GR_1024
};
static const char *Game_loading_ani_fname[GR_NUM_RESOLUTIONS] = {
"Loading", // GR_640
"2_Loading" // GR_1024
};
static const char *Game_title_screen_fname[GR_NUM_RESOLUTIONS] = {
"PreLoad",
"2_PreLoad"
};
static const char *Game_logo_screen_fname[GR_NUM_RESOLUTIONS] = {
"PreLoadLogo",
"2_PreLoadLogo"
};
// for title screens
static int Game_title_bitmap = -1;
static int Game_title_logo = -1;
// How much RAM is on this machine. Set in WinMain
uint64_t FreeSpace_total_ram = 0;
// game flash stuff
float Game_flash_red = 0.0f;
float Game_flash_green = 0.0f;
float Game_flash_blue = 0.0f;
float Sun_spot = 0.0f;
big_expl_flash Big_expl_flash = {0.0f, 0.0f, TIMESTAMP::invalid()};
// game shudder stuff (in ms)
bool Game_shudder_perpetual = false;
bool Game_shudder_everywhere = false;
TIMESTAMP Game_shudder_time = TIMESTAMP::invalid();
int Game_shudder_total = 0;
float Game_shudder_intensity = 0.0f; // should be between 0.0 and 100.0
// EAX stuff
sound_env Game_sound_env;
sound_env Game_default_sound_env = { EAX_ENVIRONMENT_BATHROOM, 0.2f, 0.2f, 1.0f };
const fs_builtin_mission *game_find_builtin_mission(const char *filename)
{
// look through all existing builtin missions
for(int idx=0; idx<Game_builtin_mission_count; idx++){
if(!stricmp(Game_builtin_mission_list[idx].filename, filename)){
return &Game_builtin_mission_list[idx];
}
}
// didn't find it
return nullptr;
}
int game_get_default_skill_level()
{
return DEFAULT_SKILL_LEVEL;
}
// Resets the flash
void game_flash_reset()
{
Game_flash_red = 0.0f;
Game_flash_green = 0.0f;
Game_flash_blue = 0.0f;
Sun_spot = 0.0f;
Big_expl_flash.max_flash_intensity = 0.0f;
Big_expl_flash.cur_flash_intensity = 0.0f;
Big_expl_flash.flash_start = TIMESTAMP::invalid();
}
extern float Framerate;
/**
* Adds a flash effect.
*
* These can be positive or negative. The range will get capped at around -1 to 1, so stick
* with a range like that.
*
* @param r red colour value
* @param g green colour value
* @param b blue colour value
*/
void game_flash( float r, float g, float b )
{
Game_flash_red += r;
Game_flash_green += g;
Game_flash_blue += b;
if ( Game_flash_red < -1.0f ) {
Game_flash_red = -1.0f;
} else if ( Game_flash_red > 1.0f ) {
Game_flash_red = 1.0f;
}
if ( Game_flash_green < -1.0f ) {
Game_flash_green = -1.0f;
} else if ( Game_flash_green > 1.0f ) {
Game_flash_green = 1.0f;
}
if ( Game_flash_blue < -1.0f ) {
Game_flash_blue = -1.0f;
} else if ( Game_flash_blue > 1.0f ) {
Game_flash_blue = 1.0f;
}
}
/**
* Adds a flash for Big Ship explosions
* @param flash flash intensity. Range capped from 0 to 1.
*/
void big_explosion_flash(float flash)
{
CLAMP(flash, 0.0f, 1.0f);
Big_expl_flash.flash_start = TIMESTAMP::immediate();
Big_expl_flash.max_flash_intensity = flash;
Big_expl_flash.cur_flash_intensity = 0.0f;
}
// Amount to diminish palette towards normal, per second.
#define DIMINISH_RATE 0.75f
#define SUN_DIMINISH_RATE 6.00f
int Sun_drew = 0;
float sn_glare_scale = 1.7f;
DCF(sn_glare, "Sets the sun glare scale (Default is 1.7)")
{
dc_stuff_float(&sn_glare_scale);
}
float Supernova_last_glare = 0.0f;
void game_sunspot_process(float frametime)
{
TRACE_SCOPE(tracing::SunspotProcess);
float Sun_spot_goal = 0.0f;
int supernova_sun_idx = 0;
int supernova_light_idx = light_find_for_sun(supernova_sun_idx);
// supernova
auto sn_stage = supernova_stage();
if (sn_stage != SUPERNOVA_STAGE::NONE && supernova_light_idx >= 0) {
// sunspot differently based on supernova stage
switch (sn_stage) {
// this case is only here to make gcc happy - apparently it doesn't know we already checked for it
case SUPERNOVA_STAGE::NONE:
UNREACHABLE("The SUPERNOVA_STAGE::NONE case should have already been handled");
break;
// approaching. player still in control
case SUPERNOVA_STAGE::STARTED:
case SUPERNOVA_STAGE::CLOSE:
float pct;
pct = supernova_sunspot_pct();
vec3d light_dir;
light_get_global_dir(&light_dir, supernova_light_idx);
float dot;
dot = vm_vec_dot( &light_dir, &Eye_matrix.vec.fvec );
if(dot >= 0.0f){
// scale it some more
dot = dot * (0.5f + (pct * 0.5f));
dot += 0.05f;
Sun_spot_goal += (dot * sn_glare_scale);
}
// draw the sun glow
if ( !shipfx_eye_in_shadow( &Eye_position, Viewer_obj, supernova_light_idx ) ) {
// draw the glow for this sun
stars_draw_sun_glow(supernova_sun_idx);
}
Supernova_last_glare = Sun_spot_goal;
break;
// camera cut. player not in control. note : at this point camera starts out facing the sun. so we can go nice and bright
case SUPERNOVA_STAGE::HIT:
case SUPERNOVA_STAGE::TOOLTIME:
Sun_spot_goal = 0.9f;
Sun_spot_goal += supernova_sunspot_pct() * 0.1f;
if(Sun_spot_goal > 1.0f){
Sun_spot_goal = 1.0f;
}
Sun_spot_goal *= sn_glare_scale;
Supernova_last_glare = Sun_spot_goal;
break;
// fade to white. display dead popup
case SUPERNOVA_STAGE::DEAD1:
case SUPERNOVA_STAGE::DEAD2:
Supernova_last_glare += (2.0f * flFrametime);
if(Supernova_last_glare > 2.0f){
Supernova_last_glare = 2.0f;
}
Sun_spot_goal = Supernova_last_glare;
break;
}
Sun_drew = 0;
} else {
Sun_spot_goal = 0.0f;
if ( Sun_drew ) {
// check sunspots for all suns
int n_lights = light_get_global_count();
// check
for(int light_idx=0; light_idx<n_lights; light_idx++) {
bool in_shadow = shipfx_eye_in_shadow(&Eye_position, Viewer_obj, light_idx);
if (!in_shadow) {
vec3d light_dir;
light_get_global_dir(&light_dir, light_idx);
//only do sunglare stuff if this light source has one
if (light_has_glare(light_idx)) {
float dot = vm_vec_dot( &light_dir, &Eye_matrix.vec.fvec )*0.5f+0.5f;
Sun_spot_goal += (float)pow(dot,85.0f);
}
// draw the glow for this sun
int sun_idx = light_get_sun_index(light_idx);
if (sun_idx >= 0) {
stars_draw_sun_glow(sun_idx);
}
}
}
Sun_drew = 0;
}
}
float dec_amount = frametime*SUN_DIMINISH_RATE;
if ( Sun_spot < Sun_spot_goal ) {
Sun_spot += dec_amount;
if ( Sun_spot > Sun_spot_goal ) {
Sun_spot = Sun_spot_goal;
}
} else if ( Sun_spot > Sun_spot_goal ) {
Sun_spot -= dec_amount;
if ( Sun_spot < Sun_spot_goal ) {
Sun_spot = Sun_spot_goal;
}
}
}
// Top/bottom bar height for the "dead view" / supernova letterbox
static int dead_view_letterbox_yborder()
{
return gr_screen.max_h / 4;
}
// Apply the clip rect for the "dead view" / supernova letterbox interior
static void set_dead_view_letterbox_clip()
{
int yborder = dead_view_letterbox_yborder();
// Numeric constants encouraged by J "pig farmer" S, who shall remain semi-anonymous.
// J.S. I've changed my ways!! See the new "no constants" code!!!
gr_set_clip(0, yborder, gr_screen.max_w, gr_screen.max_h - yborder*2, GR_RESIZE_NONE);
}
/**
* Call once a frame to diminish the flash effect to 0.
* @param frametime Period over which to dimish at ::DIMINISH_RATE
*/
static void game_flash_diminish(float frametime)
{
float dec_amount = frametime*DIMINISH_RATE;
if ( Game_flash_red > 0.0f ) {
Game_flash_red -= dec_amount;
if ( Game_flash_red < 0.0f )
Game_flash_red = 0.0f;
} else {
Game_flash_red += dec_amount;
if ( Game_flash_red > 0.0f )
Game_flash_red = 0.0f;
}
if ( Game_flash_green > 0.0f ) {
Game_flash_green -= dec_amount;
if ( Game_flash_green < 0.0f )
Game_flash_green = 0.0f;
} else {
Game_flash_green += dec_amount;
if ( Game_flash_green > 0.0f )
Game_flash_green = 0.0f;
}
if ( Game_flash_blue > 0.0f ) {
Game_flash_blue -= dec_amount;
if ( Game_flash_blue < 0.0f )
Game_flash_blue = 0.0f;
} else {
Game_flash_blue += dec_amount;
if ( Game_flash_blue > 0.0f )
Game_flash_blue = 0.0f;
}
// update big_explosion_cur_flash
if (Big_expl_flash.flash_start.isValid()) {
#define TIME_UP 1500
#define TIME_DOWN 2500
int duration = TIME_UP + TIME_DOWN;
int time = timestamp_until(Big_expl_flash.flash_start);
if (time > -duration) {
time = -time;
if (time < TIME_UP) {
Big_expl_flash.cur_flash_intensity = Big_expl_flash.max_flash_intensity * time / (float)TIME_UP;
}
else {
time -= TIME_UP;
Big_expl_flash.cur_flash_intensity = Big_expl_flash.max_flash_intensity * ((float)TIME_DOWN - time) / (float)TIME_DOWN;
}
}
} else {
Big_expl_flash.cur_flash_intensity = 0.0f;
}
if ( Use_palette_flash ) {
int r,g,b;
// Change the 200 to change the color range of colors.
r = fl2i( Game_flash_red*128.0f );
g = fl2i( Game_flash_green*128.0f );
b = fl2i( Game_flash_blue*128.0f );
if ( Sun_spot > 0.0f && gr_sunglare_enabled() && !gr_lightshafts_enabled()) {
r += fl2i(Sun_spot*128.0f);
g += fl2i(Sun_spot*128.0f);
b += fl2i(Sun_spot*128.0f);
}
if ( Big_expl_flash.cur_flash_intensity > 0.0f ) {
r += fl2i(Big_expl_flash.cur_flash_intensity*128.0f);
g += fl2i(Big_expl_flash.cur_flash_intensity*128.0f);
b += fl2i(Big_expl_flash.cur_flash_intensity*128.0f);
}
if ( r < 0 ) r = 0; else if ( r > 255 ) r = 255;
if ( g < 0 ) g = 0; else if ( g > 255 ) g = 255;
if ( b < 0 ) b = 0; else if ( b > 255 ) b = 255;
if ( (r!=0) || (g!=0) || (b!=0) ) {
// the letterbox bars are drawn earlier in the frame, but game_render_hud calls gr_reset_clip()
// before this runs, so the flash would paint over the bars unless we re-apply the letterbox clip
bool letterbox_active = (Game_mode & GM_DEAD) || (supernova_stage() >= SUPERNOVA_STAGE::HIT);
if (letterbox_active) {
set_dead_view_letterbox_clip();
}
gr_flash( r, g, b );
if (letterbox_active) {
gr_reset_clip();
}
}
}
}
void game_level_close()
{
if (scripting::hooks::OnMissionAboutToEndHook->isActive())
{
scripting::hooks::OnMissionAboutToEndHook->run();
}
//WMC - this is actually pretty damn dangerous, but I don't want a modder
//to accidentally use an override here without realizing it.
if (!scripting::hooks::OnMissionEndHook->isActive() || !scripting::hooks::OnMissionEndHook->isOverride())
{
// save on-close variables and containers
mission_campaign_store_variables(SEXP_VARIABLE_SAVE_ON_MISSION_CLOSE, false); // Goober5000
mission_campaign_store_containers(ContainerType::SAVE_ON_MISSION_CLOSE, false); // jg18
// De-Initialize the game subsystems
obj_delete_all();
obj_reset_colliders();
multi_interpolate_clear_all(); // object related
sexp_music_close(); // Goober5000
event_music_level_close();
game_stop_looped_sounds();
snd_stop_all();
obj_snd_level_close(); // uninit object-linked persistant sounds
gamesnd_unload_gameplay_sounds(); // unload gameplay sounds from memory
anim_level_close(); // stop and clean up any anim instances
message_mission_shutdown(); // called after anim_level_close() to make sure instances are clear
shockwave_level_close();
fireball_close();
shield_hit_close();
props_level_close();
asteroid_level_close();
jumpnode_level_close();
waypoint_level_close();
flak_level_close(); // unload flak stuff
neb2_level_close(); // shutdown gaseous nebula stuff
volumetrics_level_close();
ct_level_close();
beam_level_close();
mission_brief_common_reset(); // close out parsed briefing/mission stuff
photo_mode_set_active(false);
cam_close();
subtitles_close();
animation::ModelAnimationSet::stopAnimations();
particle::ParticleManager::get()->clearSources();
particle::close();
trail_level_close();
ship_level_close();
hud_level_close();
hud_escort_clear_all();
model_instance_free_all();
batch_render_close();
// be sure to not only reset the time but the lock as well
set_time_compression(1.0f, 0.0f);
lock_time_compression(false);
audiostream_unpause_all();
snd_aav_init();
gr_set_ambient_light(120, 120, 120);