/
jm_free.cpp
988 lines (757 loc) · 21.9 KB
/
jm_free.cpp
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
/*
BStone: A Source port of
Blake Stone: Aliens of Gold and Blake Stone: Planet Strike
Copyright (c) 1992-2013 Apogee Entertainment, LLC
Copyright (c) 2013-2015 Boris I. Bendovsky (bibendovsky@hotmail.com)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the
Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
//
// Warning!
//
// All functions in this source file are designated usable by the memory
// manager after program initialization.
//
#include "3d_def.h"
extern SpanStart spanstart;
extern StepScale stepscale;
extern BaseDist basedist;
extern PlaneYLookup planeylookup;
extern MirrorOfs mirrorofs;
void CA_CannotOpen(
const std::string& string);
void CAL_GetGrChunkLength(
int16_t chunk);
void CA_CacheScreen(
int16_t chunk);
void VH_UpdateScreen();
void IN_StartAck();
bool IN_CheckAck();
void OpenMapFile();
void CloseMapFile();
void ClearMemory();
void ShutdownId();
void InitRedShifts();
void CAL_OptimizeNodes(
huffnode* table);
void OpenAudioFile();
void ReadConfig();
void read_high_scores();
void initialize_sprites();
void initialize_states();
void initialize_audio_constants();
void initialize_songs();
void initialize_gfxv_contants();
void initialize_tp_shape_table();
void initialize_tp_animation_table();
void initialize_static_info_constants();
void initialize_weapon_constants();
void initialize_grenade_shape_constants();
void initialize_static_health_table();
void initialize_boss_constants();
void initialize_messages();
void initialize_ca_constants();
void SDL_SetupDigi();
static uint8_t wolfdigimap[] = {
// These first sounds are in the upload version
ATKIONCANNONSND, 0,
ATKCHARGEDSND, 1,
ATKBURSTRIFLESND, 2,
ATKGRENADESND, 46,
OPENDOORSND, 3,
CLOSEDOORSND, 4,
HTECHDOOROPENSND, 5,
HTECHDOORCLOSESND, 6,
INFORMANTDEATHSND, 7,
SCIENTISTHALTSND, 19,
SCIENTISTDEATHSND, 20,
GOLDSTERNHALTSND, 8,
GOLDSTERNLAUGHSND, 24,
HALTSND, 9, // Rent-A-Cop 1st sighting
RENTDEATH1SND, 10, // Rent-A-Cop Death
EXPLODE1SND, 11,
GGUARDHALTSND, 12,
GGUARDDEATHSND, 17,
PROHALTSND, 16,
PROGUARDDEATHSND, 13,
BLUEBOYDEATHSND, 18,
BLUEBOYHALTSND, 51,
SWATHALTSND, 22,
SWATDIESND, 47,
SCANHALTSND, 15,
SCANDEATHSND, 23,
PODHATCHSND, 26,
PODHALTSND, 50,
PODDEATHSND, 49,
ELECTSHOTSND, 27,
DOGBOYHALTSND, 14,
DOGBOYDEATHSND, 21,
ELECARCDAMAGESND, 25,
ELECAPPEARSND, 28,
ELECDIESND, 29,
INFORMDEATH2SND, 39, // Informant Death #2
RENTDEATH2SND, 34, // Rent-A-Cop Death #2
PRODEATH2SND, 42, // PRO Death #2
SWATDEATH2SND, 48, // SWAT Death #2
SCIDEATH2SND, 53, // Gen. Sci Death #2
LIQUIDDIESND, 30,
GURNEYSND, 31,
GURNEYDEATHSND, 41,
WARPINSND, 32,
WARPOUTSND, 33,
EXPLODE2SND, 35,
LCANHALTSND, 36,
LCANDEATHSND, 37,
// RENTDEATH3SND, 38, // Rent-A-Cop Death #3
INFORMDEATH3SND, 40, // Informant Death #3
PRODEATH3SND, 43, // PRO Death #3
SWATDEATH3SND, 52, // Swat Guard #3
SCIDEATH3SND, 54, // Gen. Sci Death #3
LCANBREAKSND, 44,
SCANBREAKSND, 45,
CLAWATTACKSND, 56,
SPITATTACKSND, 55,
PUNCHATTACKSND, 57,
LASTSOUND,
};
extern const uint8_t colormap[16896];
const uint8_t* lightsource;
// ------------------ ID Software 'startup' functions ---------------------
/*
==================
=
= BuildTables
=
= Calculates:
=
= scale projection constant
= sintable/costable overlapping fractional tables
=
==================
*/
const float radtoint = static_cast<float>(FINEANGLES / 2 / PI);
void BuildTables()
{
int16_t i;
float angle, anglestep;
double tang;
fixed value;
//
// calculate fine tangents
//
for (i = 0; i < FINEANGLES / 8; i++) {
tang = tan((i + 0.5) / radtoint);
finetangent[i] = static_cast<int32_t>(tang * TILEGLOBAL);
finetangent[FINEANGLES / 4 - 1 - i] = static_cast<int32_t>(1 / tang * TILEGLOBAL);
}
//
// costable overlays sintable with a quarter phase shift
// ANGLES is assumed to be divisable by four
//
// The low word of the value is the fraction, the high bit is the sign bit,
// bits 16-30 should be 0
//
angle = 0.0F;
anglestep = static_cast<float>(PI / 2 / ANGLEQUAD);
for (i = 0; i <= ANGLEQUAD; i++) {
value = static_cast<fixed>(GLOBAL1 * sin(static_cast<double>(angle)));
sintable[i] =
sintable[i + ANGLES] =
sintable[ANGLES / 2 - i] = value;
sintable[ANGLES - i] =
sintable[ANGLES / 2 + i] = value | 0x80000000l;
angle += anglestep;
}
lightsource = colormap;
}
// Map tile values to scaled pics
void SetupWalls()
{
//
// Hey! Yea You! This is where you can VERY easly setup to use a
// specific 'BANK' of wall graphics.... JTR
//
for (int i = 1; i < MAXWALLTILES; ++i)
{
::horizwall[i] = (i - 1) * 2;
::vertwall[i] = ::horizwall[i] + 1;
}
WallHeight().swap(wallheight);
wallheight.resize(::vga_width);
const int k_half_height = ::vga_height / 2;
SpanStart().swap(spanstart);
spanstart.resize(k_half_height);
StepScale().swap(stepscale);
stepscale.resize(k_half_height);
BaseDist().swap(basedist);
basedist.resize(k_half_height);
PlaneYLookup().swap(planeylookup);
planeylookup.resize(k_half_height);
MirrorOfs().swap(mirrorofs);
mirrorofs.resize(k_half_height);
}
void InitDigiMap()
{
char* map;
for (map = reinterpret_cast<char*>(wolfdigimap); *map != LASTSOUND; map += 2) {
DigiMap[static_cast<int>(map[0])] = map[1];
}
}
void CAL_SetupAudioFile()
{
bstone::FileStream handle;
//
// load maphead.ext (offsets and tileinfo for map file)
//
#ifndef AUDIOHEADERLINKED
::ca_open_resource(::aheadname, handle);
auto length = static_cast<int32_t>(handle.get_size());
::audiostarts = new int32_t[length / 4];
handle.read(::audiostarts, length);
handle.close();
#else
// TODO Remove or fix
audiohuffman = (huffnode*)&audiodict;
CAL_OptimizeNodes(audiohuffman);
audiostarts = (int32_t*)FP_SEG(&audiohead);
#endif
//
// open the data file
//
::OpenAudioFile();
}
void CAL_SetupGrFile()
{
bstone::FileStream handle;
uint8_t* compseg;
//
// load ???dict.ext (huffman dictionary for graphics files)
//
::ca_open_resource(::gdictname, handle);
handle.read(&::grhuffman, sizeof(::grhuffman));
//
// load the data offsets from ???head.ext
//
int grstarts_size = (NUMCHUNKS + 1) * FILEPOSSIZE;
::grstarts = new int32_t[(grstarts_size + 3) / 4];
::ca_open_resource(::gheadname, handle);
handle.read(::grstarts, grstarts_size);
//
// Open the graphics file, leaving it open until the game is finished
//
::ca_open_resource(::gfilename, ::grhandle);
//
// load the pic and sprite headers into the arrays in the data segment
//
::pictable = new pictabletype[NUMPICS];
::CAL_GetGrChunkLength(STRUCTPIC); // position file pointer
compseg = new uint8_t[::chunkcomplen];
::grhandle.read(compseg, ::chunkcomplen);
::CAL_HuffExpand(
compseg,
reinterpret_cast<uint8_t*>(pictable),
NUMPICS * sizeof(pictabletype),
::grhuffman);
delete [] compseg;
}
void CAL_SetupMapFile()
{
int16_t i;
bstone::FileStream handle;
int32_t pos;
mapfiletype header;
maptype* map_header;
//
// load maphead.ext (offsets and tileinfo for map file)
//
::ca_open_resource(::mheadname, handle);
handle.read(&header.RLEWtag, sizeof(header.RLEWtag));
handle.read(&header.headeroffsets, sizeof(header.headeroffsets));
rlew_tag = header.RLEWtag;
//
// open the data file
//
OpenMapFile();
//
// load all map header
//
for (i = 0; i < NUMMAPS; ++i) {
pos = header.headeroffsets[i];
if (pos < 0) {
continue;
}
mapheaderseg[i] = new maptype();
map_header = mapheaderseg[i];
maphandle.set_position(pos);
maphandle.read(
&map_header->planestart,
sizeof(map_header->planestart));
maphandle.read(
&map_header->planelength,
sizeof(map_header->planelength));
maphandle.read(
&map_header->width,
sizeof(map_header->width));
maphandle.read(
&map_header->height,
sizeof(map_header->height));
maphandle.read(
&map_header->name,
sizeof(map_header->name));
}
//
// allocate space for 3 64*64 planes
//
for (i = 0; i < MAPPLANES; ++i) {
mapsegs[i] = new uint16_t[64 * 64];
}
CloseMapFile();
}
// --------------------- Other general functions ------------------------
extern CP_itemtype NewEmenu[];
extern int16_t EpisodeSelect[];
namespace {
int get_ref_vgahead_offset_count(
GameType game_type)
{
switch (game_type) {
case GameType::aog_sw:
return 213;
case GameType::aog_full_v1_0:
return 213;
case GameType::aog_full_v2_x:
return 224;
case GameType::aog_full_v3_0:
return 226;
case GameType::ps:
return 249;
default:
throw std::invalid_argument("Invalid game type.");
}
}
const bstone::StringList& get_file_names(
GameType game_type)
{
static const bstone::StringList aog_sw_file_names = {
"AUDIOHED.BS1",
"AUDIOT.BS1",
"IANIM.BS1",
"MAPHEAD.BS1",
"MAPTEMP.BS1",
"SANIM.BS1",
"VGADICT.BS1",
"VGAGRAPH.BS1",
"VGAHEAD.BS1",
"VSWAP.BS1",
}; // aog_sw_file_names
static const bstone::StringList aog_full_file_names = {
"AUDIOHED.BS6",
"AUDIOT.BS6",
"EANIM.BS6",
"GANIM.BS6",
"IANIM.BS6",
"MAPHEAD.BS6",
"MAPTEMP.BS6",
"SANIM.BS6",
"VGADICT.BS6",
"VGAGRAPH.BS6",
"VGAHEAD.BS6",
"VSWAP.BS6",
}; // aog_file_names
static const bstone::StringList ps_file_names = {
"AUDIOHED.VSI",
"AUDIOT.VSI",
"EANIM.VSI",
"IANIM.VSI",
"MAPHEAD.VSI",
"MAPTEMP.VSI",
"VGADICT.VSI",
"VGAGRAPH.VSI",
"VGAHEAD.VSI",
"VSWAP.VSI",
}; // ps_file_names
switch (game_type) {
case GameType::aog_sw:
return aog_sw_file_names;
case GameType::aog_full_v1_0:
case GameType::aog_full_v2_x:
case GameType::aog_full_v3_0:
return aog_full_file_names;
case GameType::ps:
return ps_file_names;
default:
throw std::invalid_argument("Invalid game type.");
}
}
const std::string& get_file_extension(
const GameType game_type)
{
static const std::string aog_sw_extension = "BS1";
static const std::string aog_full_extension = "BS6";
static const std::string ps_extension = "VSI";
switch (game_type)
{
case GameType::aog_sw:
return aog_sw_extension;
case GameType::aog_full_v1_0:
case GameType::aog_full_v2_x:
case GameType::aog_full_v3_0:
return aog_full_extension;
case GameType::ps:
return ps_extension;
default:
throw std::invalid_argument("Invalid game type.");
}
}
bool are_files_exist(
const GameType game_type)
{
const auto& file_names = get_file_names(game_type);
const auto it_cend = file_names.cend();
const auto it = std::find_if_not(
file_names.cbegin(),
it_cend,
[](const std::string& file_name)
{
return ::ca_is_resource_exists(file_name);
}
);
return it == it_cend;
}
int get_vgahead_offset_count(
const GameType game_type)
{
bstone::FileStream stream;
const auto file_extension = get_file_extension(game_type);
const auto is_open = ::ca_open_resource_non_fatal(::gheadname, file_extension, stream);
if (!is_open)
{
return 0;
}
auto file_size = stream.get_size();
if ((file_size % FILEPOSSIZE) != 0) {
return 0;
}
return static_cast<int>(file_size / FILEPOSSIZE);
}
bool check_vgahead_offset_count(
GameType game_type)
{
auto offset_count = get_vgahead_offset_count(game_type);
return offset_count == get_ref_vgahead_offset_count(game_type);
}
static bool set_game_type(
GameType game_type)
{
if (!are_files_exist(game_type)) {
return false;
}
if (!check_vgahead_offset_count(game_type)) {
return false;
}
::g_game_type = game_type;
return true;
}
} // namespace
void CheckForEpisodes()
{
bool is_succeed = true;
::g_game_type = GameType::none;
if (::g_args.has_option("aog_sw")) {
bstone::Log::write("Forcing Aliens Of Gold (shareware, v3.0).\n");
if (!::set_game_type(GameType::aog_sw)) {
is_succeed = false;
}
} else if (::g_args.has_option("aog_10")) {
bstone::Log::write("Forcing Aliens Of Gold (full, v1.0).\n");
if (!::set_game_type(GameType::aog_full_v1_0)) {
is_succeed = false;
}
} else if (::g_args.has_option("aog_2x")) {
bstone::Log::write("Forcing Aliens Of Gold (full, v2.x).\n");
if (!::set_game_type(GameType::aog_full_v2_x)) {
is_succeed = false;
}
} else if (::g_args.has_option("aog_30")) {
bstone::Log::write("Forcing Aliens Of Gold (full, v3.0).\n");
if (!::set_game_type(GameType::aog_full_v3_0)) {
is_succeed = false;
}
} else if (::g_args.has_option("ps")) {
bstone::Log::write("Forcing Planet Strike (full, v1.0/v1.1).\n");
if (!::set_game_type(GameType::ps)) {
is_succeed = false;
}
} else {
bool is_found = false;
bstone::Log::write("Searching for data files...");
if (!is_found) {
is_found = ::set_game_type(GameType::aog_full_v3_0);
}
if (!is_found) {
is_found = ::set_game_type(GameType::aog_full_v2_x);
}
if (!is_found) {
is_found = ::set_game_type(GameType::aog_full_v1_0);
}
if (!is_found) {
is_found = ::set_game_type(GameType::ps);
}
if (!is_found) {
is_found = ::set_game_type(GameType::aog_sw);
}
if (is_found) {
switch (::g_game_type) {
case GameType::aog_sw:
bstone::Log::write("Found Aliens Of Gold (shareware, v3.0).\n");
break;
case GameType::aog_full_v1_0:
bstone::Log::write("Found Aliens Of Gold (full, v1.0).\n");
break;
case GameType::aog_full_v2_x:
bstone::Log::write("Found Aliens Of Gold (full, v2.x).\n");
break;
case GameType::aog_full_v3_0:
bstone::Log::write("Found Aliens Of Gold (full, v3.0).\n");
break;
case GameType::ps:
bstone::Log::write("Found Planet Strike (v1.x).\n");
break;
default:
is_succeed = false;
break;
}
} else {
is_succeed = false;
}
}
if (!is_succeed) {
::Quit("Data files not found.");
}
::extension = ::get_file_extension(::g_game_type);
if (::is_aog_full()) {
for (int i = 1; i < 6; ++i) {
::NewEmenu[i].active = AT_ENABLED;
::EpisodeSelect[i] = 1;
}
}
}
extern const char* MainStrs[];
extern char bc_buffer[];
void PreDemo()
{
if (::g_no_intro_outro)
{
return;
}
::vid_is_movie = true;
VL_SetPaletteIntensity(0, 255, vgapal, 0);
if (!(gamestate.flags & GS_NOWAIT)) {
if (::is_aog_full()) {
// ---------------------
// Anti-piracy screen
// ---------------------
// Cache pic
//
CA_CacheScreen(PIRACYPIC);
// Cache and set palette. AND Fade it in!
//
CA_CacheGrChunk(PIRACYPALETTE);
VL_SetPalette(0, 256, static_cast<const uint8_t*>(grsegs[PIRACYPALETTE]));
VL_SetPaletteIntensity(0, 255, static_cast<const uint8_t*>(grsegs[PIRACYPALETTE]), 0);
VW_UpdateScreen();
VL_FadeOut(0, 255, 0, 0, 25, 20);
VL_FadeIn(0, 255, static_cast<const uint8_t*>(grsegs[PIRACYPALETTE]), 30);
// Wait a little
//
IN_UserInput(TickBase * 20);
// Free palette
//
UNCACHEGRCHUNK(PIRACYPALETTE);
VL_FadeOut(0, 255, 0, 0, 25, 20);
VW_FadeOut();
// Cleanup screen for upcoming SetPalette call
//
::VL_Bar(0, 0, 320, 200, 0);
}
// ---------------------
// Apogee presents
// ---------------------
// Cache pic
//
CA_CacheScreen(APOGEEPIC);
// Load and start music
//
CA_CacheAudioChunk(STARTMUSIC + APOGFNFM_MUS);
::SD_StartMusic(APOGFNFM_MUS);
// Cache and set palette. AND Fade it in!
//
CA_CacheGrChunk(APOGEEPALETTE);
VL_SetPalette(0, 256, static_cast<const uint8_t*>(grsegs[APOGEEPALETTE]));
VL_SetPaletteIntensity(0, 255, static_cast<const uint8_t*>(grsegs[APOGEEPALETTE]), 0);
VW_UpdateScreen();
if (::is_aog()) {
VL_FadeOut(0, 255, 0, 0, 0, 20);
} else {
VL_FadeOut(0, 255, 25, 29, 53, 20);
}
VL_FadeIn(0, 255, static_cast<const uint8_t*>(grsegs[APOGEEPALETTE]), 30);
// Wait for end of fanfare
//
if (::sd_is_music_enabled) {
IN_StartAck();
while ((!sqPlayedOnce) && (!IN_CheckAck())) {
}
} else {
IN_UserInput(TickBase * 6);
}
SD_MusicOff();
// Free palette and music. AND Restore palette
//
UNCACHEGRCHUNK(APOGEEPALETTE);
delete [] audiosegs[STARTMUSIC + APOGFNFM_MUS];
audiosegs[STARTMUSIC + APOGFNFM_MUS] = nullptr;
if (::is_ps()) {
// Do A Blue Flash!
::VL_FadeOut(0, 255, 25, 29, 53, 20);
} else {
::VL_FadeOut(0, 255, 0, 0, 0, 30);
}
// ---------------------
// JAM logo intro
// ---------------------
// Load and start music
//
CA_CacheAudioChunk(STARTMUSIC + TITLE_LOOP_MUSIC);
::SD_StartMusic(TITLE_LOOP_MUSIC);
// Show JAM logo
//
if (!DoMovie(mv_intro, 0)) {
::Quit("JAM animation (IANIM.xxx) does not exist.");
}
// ---------------------
// PC-13
// ---------------------
VL_Bar(0, 0, 320, 200, 0x14);
CacheDrawPic(0, 64, PC13PIC);
VW_UpdateScreen();
VW_FadeIn();
IN_UserInput(TickBase * 2);
// Do A Red Flash!
if (::is_aog()) {
::VL_FadeOut(0, 255, 39, 0, 0, 20);
} else {
::VL_FadeOut(0, 255, 0, 0, 0, 20);
}
VW_FadeOut();
}
::vid_is_movie = false;
}
void InitGame()
{
::vid_is_movie = true;
int16_t i, x, y;
uint16_t* blockstart;
CA_Startup();
VW_Startup();
IN_Startup();
PM_Startup();
SD_Startup();
US_Startup();
VL_SetPalette(0, 256, vgapal);
//
// build some tables
//
InitDigiMap();
for (i = 0; i < MAPSIZE; i++) {
nearmapylookup[i] = &tilemap[0][0] + MAPSIZE * i;
farmapylookup[i] = i * 64;
}
for (i = 0; i < PORTTILESHIGH; i++) {
uwidthtable[i] = UPDATEWIDE * i;
}
blockstart = &blockstarts[0];
for (y = 0; y < UPDATEHIGH; y++) {
for (x = 0; x < UPDATEWIDE; x++) {
*blockstart++ = SCREENWIDTH * 16 * y + x * TILEWIDTH;
}
}
updateptr = &update[0];
bufferofs = 0;
::ReadConfig();
::read_high_scores();
//
// load in and lock down some basic chunks
//
LoadFonts();
LoadLatchMem();
BuildTables(); // trig tables
SetupWalls();
NewViewSize();
//
// initialize variables
//
InitRedShifts();
::vid_is_movie = false;
}
uint16_t scan_atoi(
const char* s)
{
while (*s && (!isdigit(*s))) { // First scans for a digit...
s++;
}
return static_cast<uint16_t>(atoi(s)); // Then converts to integer...
}
extern const char* MainStrs[];
extern int16_t starting_episode, starting_level, starting_difficulty;
void freed_main()
{
if (::g_args.has_option("version")) {
bstone::Log::write_version();
::Quit();
}
// Setup for APOGEECD thingie.
//
::InitDestPath();
// Make sure there's room to play the game
//
::CheckDiskSpace(DISK_SPACE_NEEDED, CANT_PLAY_TXT, cds_dos_print);
// Which version is this? (SHAREWARE? 1-3? 1-6?)
//
::CheckForEpisodes();
// BBi
::initialize_sprites();
::initialize_gfxv_contants();
::initialize_states();
::initialize_tp_shape_table();
::initialize_tp_animation_table();
::initialize_audio_constants();
::initialize_songs();
::initialize_static_info_constants();
::initialize_weapon_constants();
::initialize_grenade_shape_constants();
::initialize_static_health_table();
::initialize_boss_constants();
::initialize_messages();
::initialize_ca_constants();
::gamestuff.initialize();
if (::g_args.has_option("no_screens"))
{
::g_no_intro_outro = true;
}
if (::g_args.has_option("cheats")) {
::DebugOk = true;
}
::InitGame();
::PreDemo();
}