-
Notifications
You must be signed in to change notification settings - Fork 0
/
cGame.cpp
1841 lines (1464 loc) · 56 KB
/
cGame.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
989
990
991
992
993
994
995
996
997
998
999
1000
///////////////////////////////////////////////////////
//*-------------------------------------------------*//
//| Part of Project One (https://www.maus-games.at) |//
//*-------------------------------------------------*//
//| Copyright (c) 2010 Martin Mauersics |//
//| Released under the zlib License |//
//*-------------------------------------------------*//
///////////////////////////////////////////////////////
#include "main.h"
// ****************************************************************
// constructor
cGame::cGame(const sGameOptions oOptions, const coreInt32* piMissionList, const coreUintW iNumMissions)noexcept
: m_BulletManagerPlayer (TYPE_BULLET_PLAYER)
, m_BulletManagerEnemy (TYPE_BULLET_ENEMY)
, m_BulletManagerPlayerTop (TYPE_BULLET_PLAYER)
, m_Interface ((oOptions.iType != GAME_TYPE_SOLO) ? GAME_PLAYERS : 1u)
, m_pRepairEnemy (NULL)
, m_piMissionList (piMissionList)
, m_iNumMissions (iNumMissions)
, m_pCurMission (NULL)
, m_iCurMissionIndex (coreUintW(-1))
, m_fTimeInOut (0.0f)
, m_fMusicFade (0.0f)
, m_fMusicSpeed (0.0f)
, m_fMusicVolume (1.0f)
, m_fHitDelay (0.0f)
, m_fVanishDelay (0.0f)
, m_bDefeatDelay (false)
, m_iContinuesLeft (0u)
, m_iContinuesMax (0u)
, m_iRaise (0u)
, m_iDepthLevel (0u)
, m_iDepthDebug (0u)
, m_iOutroType (GAME_OUTRO_MISSION)
, m_iOutroSub (0u)
, m_bRainbow (false)
, m_bVisibleCheck (true)
, m_iRepairMove (0xFFu)
, m_Options (oOptions)
, m_iVersion (g_Version.iNumber)
, m_iStatus (0u)
{
ASSERT(m_piMissionList && (m_iNumMissions <= MISSIONS))
//
const coreUint32 iContinue = (g_bDemoVersion || !REPLAY_WRAP_PROGRESS_FIRSTPLAY) ? GAME_CONTINUES : 0u;
m_iContinuesLeft = iContinue;
m_iContinuesMax = iContinue;
// configure first player
m_aPlayer[0].Configure (g_bCheatP1 ? PLAYER_SHIP_P1 : PLAYER_SHIP_ATK);
m_aPlayer[0].EquipShield(oOptions.aiShield[0]);
for(coreUintW i = 0u; i < PLAYER_EQUIP_WEAPONS; ++i) m_aPlayer[0].EquipWeapon (i, oOptions.aaiWeapon [0][i]);
for(coreUintW i = 0u; i < PLAYER_EQUIP_SUPPORTS; ++i) m_aPlayer[0].EquipSupport(i, oOptions.aaiSupport[0][i]);
if(this->IsMulti())
{
// configure second player
m_aPlayer[1].Configure (PLAYER_SHIP_DEF);
m_aPlayer[1].EquipShield(oOptions.aiShield[1]);
for(coreUintW i = 0u; i < PLAYER_EQUIP_WEAPONS; ++i) m_aPlayer[1].EquipWeapon (i, oOptions.aaiWeapon [1][i]);
for(coreUintW i = 0u; i < PLAYER_EQUIP_SUPPORTS; ++i) m_aPlayer[1].EquipSupport(i, oOptions.aaiSupport[1][i]);
//
m_aPlayer[0].SetInput(&g_aGameInput[0]);
m_aPlayer[1].SetInput(&g_aGameInput[1]);
STATIC_ASSERT(GAME_PLAYERS == 2u)
}
//
for(coreUintW i = 0u; i < GAME_HELPERS; ++i)
m_aHelper[i].Configure(ELEMENT_WHITE + i);
//
m_Interface .UpdateLayout(true);
m_Interface .UpdateEnabled(true);
m_CombatText.UpdateLayout();
//
m_pRepairEnemy = new cRepairEnemy(); // # because of enemy-registration
// load first mission
m_pCurMission = new cNoMission();
//
cHelper::GlobalReset();
//
const coreUint8 iRaiseSpeed = cGame::CalcRaiseSpeed (GetCurGameSpeed());
const coreUint8 iRaiseShield1 = cGame::CalcRaiseShield(oOptions.aiShield[0]);
const coreUint8 iRaiseShield2 = cGame::CalcRaiseShield(oOptions.aiShield[1]);
const coreUint8 iRaiseShield = (oOptions.iType != GAME_TYPE_SOLO) ? ((iRaiseShield1 + iRaiseShield2) / 2u) : iRaiseShield1;
m_iRaise = iRaiseSpeed + iRaiseShield;
//
g_pMenu->GetMusicBox()->ResetSelection();
//
g_pSave->SaveFile();
#if defined(_CORE_DEBUG_)
//
for(coreUintW i = 0u; i < iNumMissions; ++i)
for(coreUintW j = i+1u; j < iNumMissions; ++j)
ASSERT((m_piMissionList[i] != m_piMissionList[j]) ||
(m_piMissionList[i] == cNoMission::ID))
#endif
}
// ****************************************************************
// destructor
cGame::~cGame()
{
//
this->__ClearAll(false);
// delete last mission
SAFE_DELETE(m_pCurMission)
//
SAFE_DELETE(m_pRepairEnemy)
//
g_pWindscreen->ClearAdds(true);
//
g_pPostProcessing->Reset();
//
if(g_pEnvironment->GetOldBackground())
{
g_pEnvironment->SetTargetDirectionNow(ENVIRONMENT_DEFAULT_DIRECTION);
g_pEnvironment->SetTargetSideNow (ENVIRONMENT_DEFAULT_SIDE);
g_pEnvironment->SetTargetSpeedNow (ENVIRONMENT_DEFAULT_SPEED);
}
else
{
g_pEnvironment->SetTargetDirectionLerp(ENVIRONMENT_DEFAULT_DIRECTION, 5.0f);
g_pEnvironment->SetTargetSideLerp (ENVIRONMENT_DEFAULT_SIDE, 5.0f);
g_pEnvironment->SetTargetSpeedLerp (ENVIRONMENT_DEFAULT_SPEED, 5.0f);
}
//
g_pSave->SaveFile();
//
this->CancelFadeMusic();
if(g_bDemoVersion && (g_MusicPlayer.GetCurMusic() != g_MusicPlayer.GetMusicName("menu"))) // TODO 1: condition for finale in demo
g_MusicPlayer.Stop();
}
// ****************************************************************
// render the game
void cGame::Render()
{
if(g_bTiltMode)
{
const auto nFlipFunc = []()
{
if(g_CurConfig.Game.iMirrorMode)
{
if(IsHorizontal(g_pPostProcessing->GetDirection())) c_cast<coreMatrix4&>(Core::Graphics->GetPerspective())._22 *= -1.0f;
else c_cast<coreMatrix4&>(Core::Graphics->GetPerspective())._11 *= -1.0f;
}
};
coreVector3 vCamPos = CAMERA_POSITION;
if(g_fShiftMode)
{
const coreVector3 vShake = coreVector3(g_pPostProcessing->GetPosition() * 80.0f, 0.0f);
vCamPos += this->CalculateCamShift() * 0.5f + vShake;
}
const coreVector3 vCamOri = MapToAxis(CAMERA_ORIENTATION, g_pPostProcessing->GetDirection());
Core::Graphics->SetCamera(vCamPos, CAMERA_DIRECTION, vCamOri); // do not reset at the end
Core::Graphics->SetView(Core::System->GetResolution(), DEG_TO_RAD(45.0f), 51.0f, 500.0f); // invoke transform-update
Core::Graphics->SetView(Core::System->GetResolution(), DEG_TO_RAD(45.0f), 50.0f, 500.0f); // TODO 1: optimize
nFlipFunc();
if(g_CurConfig.Game.iMirrorMode) glCullFace(GL_FRONT);
__DEPTH_GROUP_BOTTOM
{
//
m_EnemyManager.RenderBottom();
m_pCurMission->RenderBottom();
//
m_CrashManager.Render();
//g_pSpecialEffects->RenderBottom();
}
__DEPTH_GROUP_SHIP // # 1
{
// render all players
for(coreUintW i = 0u; i < GAME_PLAYERS; ++i)
m_aPlayer[i].Render();
//
for(coreUintW i = 0u; i < GAME_HELPERS; ++i)
m_aHelper[i].Render();
//
m_Tracker.Render();
// render all enemies
m_EnemyManager.Render();
}
__DEPTH_GROUP_UNDER
{
Core::Graphics->SetView(Core::System->GetResolution(), DEG_TO_RAD(45.0f), 1.0f, 500.0f); // TODO 1: to make it possible for bullets flying towards screen
nFlipFunc();
m_EnemyManager.RenderUnder();
m_pCurMission->RenderUnder();
DEPTH_PUSH_DOUBLE
g_pSpecialEffects->RenderBottom();
m_BulletManagerEnemy.Render();
// render low-priority bullet manager
m_BulletManagerPlayer.Render();
m_BulletManagerPlayer.RenderAfter();
DEPTH_PUSH
//
m_ShieldManager.Render();
//
m_ExhaustManager.Render();
// render underlying objects
//if(!g_bTiltMode) m_EnemyManager.RenderUnder();
//if(!g_bTiltMode) m_pCurMission->RenderUnder();
Core::Graphics->SetView(Core::System->GetResolution(), DEG_TO_RAD(45.0f), 50.0f, 500.0f);
nFlipFunc();
DEPTH_PUSH
glDepthMask(false);
{
//
for(coreUintW i = 0u; i < GAME_PLAYERS; ++i)
m_aPlayer[i].RenderBefore();
//
m_Tracker.RenderBefore();
}
glDepthMask(true);
//
for(coreUintW i = 0u; i < GAME_HELPERS; ++i)
m_aHelper[i].RenderBefore();
}
__DEPTH_GROUP_SHIP // # 2
{
// apply deferred outline-layer
g_pOutline->Apply();
Core::Graphics->SetView(Core::System->GetResolution(), DEG_TO_RAD(45.0f), 1.0f, 500.0f); // TODO 1: to make it possible for bullets flying towards screen
nFlipFunc();
m_BulletManagerPlayerTop.Render();
m_BulletManagerPlayerTop.RenderAfter();
m_BulletManagerEnemy.RenderAfter();
Core::Graphics->SetView(Core::System->GetResolution(), DEG_TO_RAD(45.0f), 50.0f, 500.0f);
nFlipFunc();
}
__DEPTH_GROUP_OVER
{
DEPTH_PUSH
//
m_ItemManager.Render();
// render overlying objects
m_EnemyManager.RenderOver();
m_pCurMission->RenderOver();
// TODO 1: push or GL_DEPTH_TEST ?? move up ??
glDepthMask(false);
{
//
for(coreUintW i = 0u; i < GAME_PLAYERS; ++i)
m_aPlayer[i].RenderMiddle();
//
m_Tracker.RenderMiddle();
}
glDepthMask(true);
}
__DEPTH_GROUP_TOP
{
DEPTH_PUSH_DOUBLE
Core::Graphics->SetView(Core::System->GetResolution(), DEG_TO_RAD(45.0f), 1.0f, 500.0f); // TODO 1: to make it possible for ENEMIES and special effects near screen
nFlipFunc();
// render special-effects
g_pSpecialEffects->Render();
// render high-priority bullet manager
//if(!g_bTiltMode) m_BulletManagerEnemy.Render();
//if(!g_bTiltMode) m_BulletManagerEnemy.RenderAfter();
// render top objects
m_EnemyManager.RenderTop();
m_pCurMission->RenderTop();
Core::Graphics->SetView(Core::System->GetResolution(), DEG_TO_RAD(45.0f), 50.0f, 500.0f);
nFlipFunc();
glDisable(GL_DEPTH_TEST);
{
//
for(coreUintW i = 0u; i < GAME_PLAYERS; ++i)
m_aPlayer[i].RenderAfter();
//
for(coreUintW i = 0u; i < GAME_HELPERS; ++i)
m_aHelper[i].RenderAfter();
//
m_Tracker.RenderAfter();
}
glEnable(GL_DEPTH_TEST);
}
__DEPTH_RESET
nFlipFunc();
if(g_CurConfig.Game.iMirrorMode) glCullFace(GL_BACK);
}
else
{
__DEPTH_GROUP_BOTTOM
{
//
m_EnemyManager.RenderBottom();
m_pCurMission->RenderBottom();
//
m_CrashManager.Render();
g_pSpecialEffects->RenderBottom();
}
__DEPTH_GROUP_SHIP // # 1
{
// render all players
for(coreUintW i = 0u; i < GAME_PLAYERS; ++i)
m_aPlayer[i].Render();
//
for(coreUintW i = 0u; i < GAME_HELPERS; ++i)
m_aHelper[i].Render();
//
m_Tracker.Render();
// render all enemies
m_EnemyManager.Render();
}
__DEPTH_GROUP_UNDER
{
DEPTH_PUSH_DOUBLE
// render low-priority bullet manager
m_BulletManagerPlayer.Render();
m_BulletManagerPlayer.RenderAfter();
DEPTH_PUSH
//
m_ShieldManager.Render();
//
m_ExhaustManager.Render();
// render underlying objects
m_pCurMission->RenderUnder();
m_EnemyManager.RenderUnder();
DEPTH_PUSH
glDepthMask(false);
{
//
for(coreUintW i = 0u; i < GAME_PLAYERS; ++i)
m_aPlayer[i].RenderBefore();
//
m_Tracker.RenderBefore();
}
glDepthMask(true);
//
for(coreUintW i = 0u; i < GAME_HELPERS; ++i)
m_aHelper[i].RenderBefore();
}
__DEPTH_GROUP_SHIP // # 2
{
// apply deferred outline-layer
g_pOutline->Apply();
}
__DEPTH_GROUP_OVER
{
DEPTH_PUSH
//
m_ItemManager.Render();
// render overlying objects
m_EnemyManager.RenderOver();
m_pCurMission->RenderOver();
// TODO 1: push or GL_DEPTH_TEST ?? move up ??
//glDepthMask(false); because of pulse weapon
{
//
for(coreUintW i = 0u; i < GAME_PLAYERS; ++i)
m_aPlayer[i].RenderMiddle();
//
m_Tracker.RenderMiddle();
}
//glDepthMask(true);
}
__DEPTH_GROUP_TOP
{
DEPTH_PUSH_DOUBLE
// render special-effects
g_pSpecialEffects->Render();
// render high-priority bullet manager
m_BulletManagerEnemy.Render();
m_BulletManagerEnemy.RenderAfter();
if(m_BulletManagerPlayerTop.GetNumBulletsTypedEst<cRayBullet> () ||
m_BulletManagerPlayerTop.GetNumBulletsTypedEst<cPulseBullet>() ||
m_BulletManagerPlayerTop.GetNumBulletsTypedEst<cSurgeBullet>() ||
m_BulletManagerPlayerTop.GetNumBulletsTypedEst<cTeslaBullet>())
{
DEPTH_PUSH
m_BulletManagerPlayerTop.Render();
m_BulletManagerPlayerTop.RenderAfter();
}
// render top objects
m_EnemyManager.RenderTop();
m_pCurMission->RenderTop();
glDisable(GL_DEPTH_TEST);
{
//
for(coreUintW i = 0u; i < GAME_PLAYERS; ++i)
m_aPlayer[i].RenderAfter();
//
for(coreUintW i = 0u; i < GAME_HELPERS; ++i)
m_aHelper[i].RenderAfter();
//
m_Tracker.RenderAfter();
}
glEnable(GL_DEPTH_TEST);
}
__DEPTH_RESET
}
}
// ****************************************************************
// move the game
void cGame::Move()
{
// handle intro and outro animation
if(!this->__HandleIntro()) return;
if(!this->__HandleOutro()) return;
//
g_pReplay->Update();
//
m_pCurMission->MoveAlways();
if(SPECIAL_FROZEN)
{
// make sure player input is recognized
for(coreUintW i = 0u; i < GAME_PLAYERS; ++i)
m_aPlayer[i].Move();
// always handle defeat (to properly fade-out music (old), but prevents LUCKY)
if(!this->IsVersion(13u)) this->__HandleDefeat();
return;
}
this->__HandleRainbow();
//
m_TimeTable.Update();
//if(m_TimeTable.GetTimeEvent() >= 6.3f) // GAME_INTRO_INTERFACE
// m_Interface.SetVisible(true);
//
cHelper::GlobalUpdate();
//
m_EnemyManager.MoveBefore();
m_pCurMission->MoveBefore();
// move all players
for(coreUintW i = 0u; i < GAME_PLAYERS; ++i)
m_aPlayer[i].Move();
// move all helpers
for(coreUintW i = 0u; i < GAME_HELPERS; ++i)
m_aHelper[i].Move();
//
m_Tracker.Move();
//
m_pCurMission->MoveMiddle(); // # swapped
m_EnemyManager.MoveMiddle();
// move the bullet managers
m_BulletManagerPlayer.Move();
m_BulletManagerEnemy .Move();
m_BulletManagerPlayerTop.Move();
//
m_EnemyManager.MoveAfter();
m_pCurMission->MoveAfter();
//
m_ItemManager .Move();
m_ShieldManager.Move();
//
m_CrashManager.Move();
//
m_ExhaustManager.Move();
// handle default object collisions
this->__HandleCollisions();
//
this->__HandleDefeat();
m_fHitDelay .UpdateMax(-20.0f, 0.0f);
m_fVanishDelay.UpdateMax(-20.0f, 0.0f);
}
// ****************************************************************
// render the overlay separately
void cGame::RenderOverlay()
{
// render interface and combat text
m_Interface .Render();
m_CombatText.Render();
}
// ****************************************************************
// move the overlay separately
void cGame::MoveOverlay()
{
// move interface and combat text
m_Interface .Move();
m_CombatText.Move();
}
// ****************************************************************
//
void cGame::MoveAlways()
{
//
if(m_fMusicFade)
{
m_fMusicFade.UpdateMax(-m_fMusicSpeed, 0.0f);
if(!m_fMusicFade) g_MusicPlayer.Stop();
}
g_MusicPlayer.SetVolume((m_fMusicFade ? BLENDH3(m_fMusicFade.ToFloat()) : 1.0f) * g_pMenu->GetVolume() * m_fMusicVolume * (m_bDefeatDelay ? 0.0f : 1.0f) * MUSIC_VOLUME);
}
// ****************************************************************
// load new active mission
void cGame::LoadMissionID(const coreInt32 iID, const coreUint8 iTakeFrom, const coreUint8 iTakeTo)
{
for(coreUintW i = 0u; i < GAME_HELPERS; ++i)
{
if(!m_aHelper[i].HasStatus(HELPER_STATUS_DEAD))
g_pSpecialEffects->CreateSplashColor(m_aHelper[i].GetPosition(), SPECIAL_SPLASH_TINY, m_aHelper[i].GetColor3());
}
//
this->__ClearAll(false);
// hold old mission (to keep resources valid)
ASSERT(m_pCurMission)
const cMission* pOldMission = m_pCurMission;
// create new mission
switch(iID)
{
default: UNREACHABLE
case cNoMission ::ID: m_pCurMission = new cNoMission (); break;
case cViridoMission ::ID: m_pCurMission = new cViridoMission (); break;
case cNevoMission ::ID: m_pCurMission = new cNevoMission (); break;
case cHarenaMission ::ID: m_pCurMission = new cHarenaMission (); break;
case cRutilusMission::ID: m_pCurMission = new cRutilusMission(); break;
case cGeluMission ::ID: m_pCurMission = new cGeluMission (); break;
case cCalorMission ::ID: m_pCurMission = new cCalorMission (); break;
case cMuscusMission ::ID: m_pCurMission = new cMuscusMission (); break;
case cAterMission ::ID: m_pCurMission = new cAterMission (); break;
case cIntroMission ::ID: m_pCurMission = new cIntroMission (); break;
case cBonus1Mission ::ID: m_pCurMission = new cBonus1Mission (); break;
case cBonus2Mission ::ID: m_pCurMission = new cBonus2Mission (); break;
case cErrorMission ::ID: m_pCurMission = new cErrorMission (); break;
case cDemoMission ::ID: m_pCurMission = new cDemoMission (); break;
}
// delete possible old mission
SAFE_DELETE(pOldMission)
//
m_iCurMissionIndex = std::find(m_piMissionList, m_piMissionList + m_iNumMissions, iID) - m_piMissionList;
ASSERT(m_iCurMissionIndex < m_iNumMissions)
if(iID != cNoMission::ID)
{
// setup the mission
m_pCurMission->Setup(iTakeFrom, iTakeTo);
// set initial status
m_iStatus = GAME_STATUS_LOADING;
//
m_bDefeatDelay = false;
if((m_Options.iKind == GAME_KIND_ALL) || (m_Options.iKind == GAME_KIND_MISSION))
{
//
m_pCurMission->Open();
}
}
Core::Log->Info("Mission (%s) created", m_pCurMission->GetName());
}
// ****************************************************************
//
void cGame::LoadMissionIndex(const coreUintW iIndex, const coreUint8 iTakeFrom, const coreUint8 iTakeTo)
{
ASSERT(iIndex < m_iNumMissions)
this->LoadMissionID(m_piMissionList[iIndex], iTakeFrom, iTakeTo);
}
// ****************************************************************
//
void cGame::LoadNextMission()
{
//
this->CloseMission();
if((m_Options.iKind == GAME_KIND_ALL) && (m_iCurMissionIndex + 1u < m_iNumMissions))
{
//
this->LoadMissionIndex(m_iCurMissionIndex + 1u);
}
else
{
ASSERT(HAS_FLAG(m_iStatus, GAME_STATUS_OUTRO))
//
REMOVE_FLAG(m_iStatus, GAME_STATUS_OUTRO)
ADD_FLAG (m_iStatus, GAME_STATUS_FINISHED)
}
}
// ****************************************************************
//
void cGame::CloseMission()
{
if(m_pCurMission->GetID() != cNoMission::ID)
{
if((m_Options.iKind == GAME_KIND_ALL) || (m_Options.iKind == GAME_KIND_MISSION))
{
//
m_pCurMission->Close();
}
}
}
// ****************************************************************
//
void cGame::StartIntro()
{
ASSERT(!HAS_FLAG(m_iStatus, GAME_STATUS_PLAY))
ASSERT(!HAS_FLAG(m_iStatus, GAME_STATUS_OUTRO))
//
ADD_FLAG(m_iStatus, GAME_STATUS_INTRO)
//
m_fTimeInOut = GAME_INTRO_OFFSET;
for(coreUintW i = 0u, ie = this->GetNumPlayers(); i < ie; ++i)
{
//
m_aPlayer[i].Kill(false);
m_aPlayer[i].Resurrect();
m_aPlayer[i].AddStatus(PLAYER_STATUS_NO_INPUT_ALL); // TODO 1: handle combination with gameplay code
//
m_aPlayer[i].ActivateNormalShading();
//
const coreFloat fSide = this->IsMulti() ? (20.0f * (I_TO_F(i) - 0.5f * I_TO_F(GAME_PLAYERS - 1u))) : 0.0f;
m_aPlayer[i].SetPosition(coreVector3(fSide, -140.0f, 0.0f));
STATIC_ASSERT(GAME_PLAYERS == 2u)
}
}
// ****************************************************************
//
void cGame::StartOutro(const coreUint8 iType, const coreUint8 iSub)
{
ASSERT( HAS_FLAG(m_iStatus, GAME_STATUS_PLAY))
ASSERT(!HAS_FLAG(m_iStatus, GAME_STATUS_INTRO))
//
REMOVE_FLAG(m_iStatus, GAME_STATUS_PLAY)
ADD_FLAG (m_iStatus, GAME_STATUS_OUTRO)
//
m_fTimeInOut = 0.0f;
m_iOutroType = iType;
m_iOutroSub = iSub;
//
for(coreUintW i = 0u, ie = this->GetNumPlayers(); i < ie; ++i)
m_aPlayer[i].AddStatus(PLAYER_STATUS_NO_INPUT_ALL);
if(m_iOutroType == GAME_OUTRO_ENDING_NORMAL)
{
for(coreUintW i = 0u, ie = this->GetNumPlayers(); i < ie; ++i)
m_aPlayer[i].AddStatus(PLAYER_STATUS_KEEP_RANGE);
}
//
m_Interface .SetVisible(false);
m_CombatText.SetVisible(false);
//
g_pReplay->ApplySnapshot(REPLAY_SNAPSHOT_MISSION_END(this->GetContinuesCur(), m_iCurMissionIndex));
//
if((m_iOutroSub >= 1u) && (m_iOutroSub < 10u))
{
m_Tracker.Resurrect();
m_Tracker.EnableWind();
m_Tracker.SetPosition(coreVector3((m_iOutroSub == 1u) ? -0.5f : 0.8f, -1.5f, 0.0f) * FOREGROUND_AREA3);
}
else if((m_iOutroSub >= 11u) && (m_iOutroSub < 20u))
{
this->GetHelper(ELEMENT_WHITE)->Resurrect(false);
}
}
// ****************************************************************
//
void cGame::FadeMusic(const coreFloat fSpeed)
{
if(!m_fMusicFade)
{
//
m_fMusicFade = 1.0f;
m_fMusicSpeed = fSpeed;
}
}
// ****************************************************************
//
void cGame::CancelFadeMusic()
{
//
if(m_fMusicFade) g_MusicPlayer.Stop();
//
m_fMusicFade = 0.0f;
}
// ****************************************************************
//
void cGame::PlayHitSound(const coreVector3 vPosition)
{
if(!m_fHitDelay)
{
m_fHitDelay = 1.0f;
g_pSpecialEffects->PlaySound(vPosition, 1.0f, 1.0f, SOUND_BULLET_HIT);
}
}
// ****************************************************************
//
void cGame::PlayReflectSound(const coreVector3 vPosition)
{
if(!m_fHitDelay)
{
m_fHitDelay = 1.0f;
g_pSpecialEffects->PlaySound(vPosition, 1.0f, 1.0f, SOUND_BULLET_REFLECT);
}
}
// ****************************************************************
//
void cGame::PlayVanishSound(const coreVector3 vPosition)
{
if(!m_fVanishDelay)
{
m_fVanishDelay = 1.0f;
g_pSpecialEffects->PlaySound(vPosition, 1.0f, 1.0f, SOUND_BULLET_VANISH);
}
}
// ****************************************************************
//
void cGame::UseContinue()
{
ASSERT(HAS_FLAG(m_iStatus, GAME_STATUS_DEFEATED))
const coreUintW iMissionIndex = m_iCurMissionIndex;
const coreUintW iSegmentIndex = m_pCurMission->GetCurSegmentIndex();
const coreUint8 iCurContinue = this->GetContinuesCur();
//
this->LoadMissionID(m_pCurMission->GetID(), iSegmentIndex, m_pCurMission->GetTakeTo());
//
REMOVE_FLAG(m_iStatus, GAME_STATUS_DEFEATED) // # already removed
ADD_FLAG (m_iStatus, GAME_STATUS_CONTINUE)
ADD_FLAG (m_iStatus, GAME_STATUS_QUICK)
ADD_FLAG (m_iStatus, GAME_STATUS_NAMELESS)
//
ASSERT(m_iContinuesLeft)
m_iContinuesLeft -= 1u;
for(coreUintW i = 0u, ie = this->GetNumPlayers(); i < ie; ++i)
{
//
m_aPlayer[i].GetScoreTable()->StoreRun(iCurContinue, iMissionIndex, iSegmentIndex);
//
m_aPlayer[i].GetDataTable ()->RevertSegment (iMissionIndex, iSegmentIndex);
m_aPlayer[i].GetScoreTable()->RevertSegmentNew(iMissionIndex, iSegmentIndex);
//
m_aPlayer[i].GetDataTable()->EditCounterTotal () ->iContinuesUsed += 1u;
m_aPlayer[i].GetDataTable()->EditCounterMission(iMissionIndex) ->iContinuesUsed += 1u;
m_aPlayer[i].GetDataTable()->EditCounterSegment(iMissionIndex, iSegmentIndex)->iContinuesUsed += 1u;
}
//
m_TimeTable.RevertSegmentNew(iMissionIndex, iSegmentIndex);
//
g_pSave->EditGlobalStats () ->iContinuesUsed += 1u;
g_pSave->EditLocalStatsArcade () ->iContinuesUsed += 1u;
g_pSave->EditLocalStatsMission(iMissionIndex) ->iContinuesUsed += 1u;
g_pSave->EditLocalStatsSegment(iMissionIndex, iSegmentIndex)->iContinuesUsed += 1u;
}
// ****************************************************************
//
void cGame::UseNext()
{
//
ADD_FLAG(m_iStatus, GAME_STATUS_QUICK)
}
// ****************************************************************
//
void cGame::UseRestart()
{
//
ADD_FLAG(m_iStatus, GAME_STATUS_QUICK)
if(g_pReplay->GetMode() == REPLAY_MODE_DISABLED)
{
//
ADD_FLAG(m_iStatus, GAME_STATUS_NAMELESS)
}
}
// ****************************************************************
//
void cGame::DisableMissionName()
{
//
ADD_FLAG(m_iStatus, GAME_STATUS_NAMELESS)
}
// ****************************************************************
//
void cGame::RepairPlayer()
{
if(HAS_FLAG(m_iStatus, GAME_STATUS_DEFEATED)) return;
if(m_pRepairEnemy->GetPlayer())
{
cPlayer* pPlayer = m_pRepairEnemy->GetPlayer();
//
pPlayer->Resurrect();
//
pPlayer->SetPosition (m_pRepairEnemy->GetPosition());
pPlayer->SetDesaturate(PLAYER_DESATURATE);
pPlayer->StartFeeling (PLAYER_FEEL_TIME_REPAIR, 0u);
pPlayer->SetCurHealth(1);
pPlayer->SetCurShield(pPlayer->GetMaxShield() / 5);
pPlayer->AddStatus (PLAYER_STATUS_REPAIRED);
//
g_pSpecialEffects->PlaySound(m_pRepairEnemy->GetPosition(), 1.0f, 1.0f, SOUND_PLAYER_EXPLOSION);
g_pSpecialEffects->RumblePlayer(pPlayer, SPECIAL_RUMBLE_BIG, 500u);
//
pPlayer->GetDataTable()->EditCounterTotal ()->iRepairsUsed += 1u;
pPlayer->GetDataTable()->EditCounterMission()->iRepairsUsed += 1u;
pPlayer->GetDataTable()->EditCounterSegment()->iRepairsUsed += 1u;
//
g_pSave->EditGlobalStats ()->iRepairsUsed += 1u;
g_pSave->EditLocalStatsArcade ()->iRepairsUsed += 1u;
g_pSave->EditLocalStatsMission()->iRepairsUsed += 1u;
g_pSave->EditLocalStatsSegment()->iRepairsUsed += 1u;