-
Notifications
You must be signed in to change notification settings - Fork 0
/
cEnemy.cpp
1530 lines (1232 loc) · 42.4 KB
/
cEnemy.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
cEnemy::cEnemy()noexcept
: m_fLifeTime (0.0f)
, m_fLifeTimeBefore (0.0f)
, m_iLastAttacker (0u)
, m_bWasDamaged (false)
, m_iExtraDamage (0)
, m_iDamageForwarded (0)
{
// load object resources
this->DefineTexture(0u, "ship_enemy.png");
this->DefineProgram("object_ship_blink_program");
// reset base properties
this->ResetProperties();
}
// ****************************************************************
// configure the enemy
void cEnemy::Configure(const coreInt32 iHealth, const coreVector3 vColor, const coreBool bInverted, const coreBool bIgnored, const coreBool bWhite)
{
// set health and color
this->SetMaxHealth(iHealth);
this->SetBaseColor(vColor, bInverted, bIgnored, bWhite);
}
// ****************************************************************
// render the enemy
void cEnemy::Render()
{
if(!HAS_FLAG(m_iStatus, ENEMY_STATUS_BOTTOM))
if(!HAS_FLAG(m_iStatus, ENEMY_STATUS_TOP))
if(!HAS_FLAG(m_iStatus, ENEMY_STATUS_DEAD))
{
//
this->_EnableBlink();
//
cLodObject::RenderHighObject(this);
}
}
// ****************************************************************
// move the enemy
void cEnemy::Move()
{
if(!HAS_FLAG(m_iStatus, ENEMY_STATUS_DEAD))
{
//
m_fLifeTimeBefore = m_fLifeTime;
m_fLifeTime.Update(1.0f);
// call individual move routines
this->__MoveOwn();
// move the 3d-object
this->coreObject3D::Move();
//
m_bWasDamaged = false;
//
if(!HAS_FLAG(m_iStatus, ENEMY_STATUS_DEAD)) // may change in __MoveOwn
{
if(g_pForeground->IsVisibleObject(this))
{
this->SetEnabled(HAS_FLAG(m_iStatus, ENEMY_STATUS_HIDDEN) ? CORE_OBJECT_ENABLE_MOVE : CORE_OBJECT_ENABLE_ALL);
this->ChangeType(TYPE_ENEMY); // # make it available in cEnemyManager::ForEachEnemy
}
else
{
this->SetEnabled(CORE_OBJECT_ENABLE_MOVE);
}
// reduce collision overhead for ghost enemies without bounding volume
const coreModelPtr& pLowQuad = Core::Manager::Object->GetLowQuad();
if(HAS_FLAG(m_iStatus, ENEMY_STATUS_GHOST) && !HAS_FLAG(m_iStatus, ENEMY_STATUS_KEEPVOLUME))
{
if(m_pVolume.GetHandle() == NULL) this->DefineVolume(pLowQuad);
}
else
{
if(m_pVolume.GetHandle() == pLowQuad.GetHandle()) this->DefineVolume(NULL);
}
//
if(STATIC_ISVALID(g_pGame))
{
if(HAS_FLAG(m_iStatus, ENEMY_STATUS_INVINCIBLE) && !HAS_FLAG(m_iStatus, ENEMY_STATUS_SECRET)) g_pGame->GetShieldManager()->GetEffect(SHIELD_EFFECT_INVINCIBLE)->BindEnemy (this);
else g_pGame->GetShieldManager()->GetEffect(SHIELD_EFFECT_INVINCIBLE)->UnbindEnemy(this);
//if(HAS_FLAG(m_iStatus, ENEMY_STATUS_DAMAGING) && !HAS_FLAG(m_iStatus, ENEMY_STATUS_SECRET)) g_pGame->GetShieldManager()->GetEffect(SHIELD_EFFECT_DAMAGING) ->BindEnemy (this);
//else g_pGame->GetShieldManager()->GetEffect(SHIELD_EFFECT_DAMAGING) ->UnbindEnemy(this);
// TODO 1: same shield state is checked in both types
}
}
}
//
this->_UpdateAlwaysAfter();
}
// ****************************************************************
// reduce current health
coreInt32 cEnemy::TakeDamage(const coreInt32 iDamage, const coreUint8 iElement, const coreVector2 vImpact, cPlayer* OUTPUT pAttacker, const coreBool bNeutral)
{
ASSERT(STATIC_ISVALID(g_pGame))
//
const coreBool bMulti = (pAttacker && g_pGame->IsMulti());
m_iLastAttacker = bMulti ? g_pGame->GetPlayerIndex(pAttacker) : 0u;
if(!HAS_FLAG(m_iStatus, ENEMY_STATUS_INVINCIBLE))
{
//
m_bWasDamaged = (m_iCurHealth != 0) && (iDamage != 0);
// forward to parent
if(this->IsChild())
{
const coreInt32 iTaken = m_apMember.front()->TakeDamage(iDamage, iElement, vImpact, pAttacker, bNeutral);
m_iDamageForwarded += iTaken;
return iTaken;
}
if(iDamage)
{
//
const coreInt32 iPower = (bMulti || bNeutral || (this->GetCurHealth() == 1)) ? 1 : GAME_PLAYERS;
const coreInt32 iTotal = m_iExtraDamage + iDamage * iPower * (bNeutral ? 10000 : ((g_pGame->IsEasy() ? 110 : 101) * (g_pGame->IsMulti() ? 110 : 100)));
const coreInt32 iTaken = ABS(this->_TakeDamage(iTotal / 10000, iElement, vImpact) / iPower);
ASSERT(coreMath::IsAligned(this->GetMaxHealth(), iPower)) // ???
m_iExtraDamage = iTotal % 10000;
if(iTaken)
{
//
this->RefreshColorAll();
this->InvokeBlinkAll();
if(pAttacker)
{
//
pAttacker->GetScoreTable()->RefreshCooldown();
if(!HAS_FLAG(m_iStatus, ENEMY_STATUS_WORTHLESS))
{
if(HAS_FLAG(m_iStatus, ENEMY_STATUS_BOSS) || HAS_FLAG(m_iStatus, ENEMY_STATUS_CHAIN))
{
//
pAttacker->GetScoreTable()->AddChain(iTaken);
}
//
pAttacker->GetDataTable()->EditCounterTotal ()->iDamageGiven += iTaken;
pAttacker->GetDataTable()->EditCounterMission()->iDamageGiven += iTaken;
pAttacker->GetDataTable()->EditCounterSegment()->iDamageGiven += iTaken;
//
g_pSave->EditGlobalStats ()->iDamageGiven += iTaken;
g_pSave->EditLocalStatsArcade ()->iDamageGiven += iTaken;
g_pSave->EditLocalStatsMission()->iDamageGiven += iTaken;
g_pSave->EditLocalStatsSegment()->iDamageGiven += iTaken;
}
}
}
if(!m_iCurHealth)
{
if(!HAS_FLAG(m_iStatus, ENEMY_STATUS_IMMORTAL))
{
//
this->Kill(true);
//
if(pAttacker) this->ApplyScore(pAttacker);
}
}
return iTaken;
}
}
return 0;
}
// ****************************************************************
// add enemy to the game
void cEnemy::Resurrect()
{
// resurrect enemy
if(!HAS_FLAG(m_iStatus, ENEMY_STATUS_DEAD)) return;
REMOVE_FLAG(m_iStatus, ENEMY_STATUS_DEAD)
//
const coreBool bSingle = HAS_FLAG(m_iStatus, ENEMY_STATUS_SINGLE);
const coreBool bEnergy = HAS_FLAG(m_iStatus, ENEMY_STATUS_ENERGY);
const coreBool bBottom = HAS_FLAG(m_iStatus, ENEMY_STATUS_BOTTOM);
const coreBool bTop = HAS_FLAG(m_iStatus, ENEMY_STATUS_TOP);
ASSERT(!bEnergy || bSingle)
//ASSERT(!bBottom || bSingle)
//
m_fLifeTime = 0.0f;
m_fLifeTimeBefore = 0.0f;
m_bWasDamaged = false;
m_iExtraDamage = 0;
if(bEnergy)
{
// add ship to glow and outline
g_pGlow->BindObject(this);
if(!bBottom && !bTop) g_pOutline->GetStyle(this->GetOutlineStyle())->BindObject(this);
}
else if(bSingle)
{
// add ship to global shadow and outline
cShadow::GetGlobalContainer()->BindObject(this);
if(!bBottom && !bTop) g_pOutline->GetStyle(this->GetOutlineStyle())->BindObject(this);
}
if(HAS_FLAG(m_iStatus, ENEMY_STATUS_BOSS))
{
//
if(this->IsParent()) FOR_EACH(it, m_apMember) (*it)->ChangeType(TYPE_ENEMY);
this->ChangeType(TYPE_ENEMY);
}
// add ship to the game
this->_Resurrect();
if(HAS_FLAG(m_iStatus, ENEMY_STATUS_HIDDEN)) this->SetEnabled(CORE_OBJECT_ENABLE_MOVE);
//
this->__ResurrectOwn();
//
if(this->IsParent()) FOR_EACH(it, m_apMember) (*it)->Resurrect();
}
// ****************************************************************
// remove enemy from the game
void cEnemy::Kill(const coreBool bAnimated)
{
// kill enemy
if(HAS_FLAG(m_iStatus, ENEMY_STATUS_DEAD)) return;
ADD_FLAG(m_iStatus, ENEMY_STATUS_DEAD)
//
const coreBool bSingle = HAS_FLAG(m_iStatus, ENEMY_STATUS_SINGLE);
const coreBool bEnergy = HAS_FLAG(m_iStatus, ENEMY_STATUS_ENERGY);
const coreBool bBottom = HAS_FLAG(m_iStatus, ENEMY_STATUS_BOTTOM);
const coreBool bTop = HAS_FLAG(m_iStatus, ENEMY_STATUS_TOP);
ASSERT(!bEnergy || bSingle)
//ASSERT(!bBottom || bSingle)
//
if(STATIC_ISVALID(g_pGame))
{
g_pGame->GetShieldManager()->GetEffect(SHIELD_EFFECT_INVINCIBLE)->UnbindEnemy(this);
g_pGame->GetShieldManager()->GetEffect(SHIELD_EFFECT_DAMAGING) ->UnbindEnemy(this);
}
//
if(bAnimated && this->GetType()) // sollten am rand explodieren
{
if(!HAS_FLAG(m_iStatus, ENEMY_STATUS_SKIPEXPLOSION))
{
//
if(HAS_BIT(m_iBaseColor, SHIP_INVERTED_BIT))
{
const coreVector3 vColor = (g_pEnvironment->GetBackground()->GetID() == cSnowBackground::ID) ? COLOR_FIRE_BLUE : COLOR_FIRE_ORANGE;
g_pSpecialEffects->MacroDestructionColor(this, vColor);
}
else
{
g_pSpecialEffects->MacroDestructionDark(this);
}
//
const coreFloat fVolume = ((g_pEnvironment->GetBackground()->GetID() == cCloudBackground::ID) && (this->GetExplosionSound() == SOUND_ENEMY_EXPLOSION_10)) ? 0.8f : 1.0f;
g_pSpecialEffects->PlaySound(this->GetPosition(), fVolume, this->GetExplosionPitch(), this->GetExplosionSound());
//
if(STATIC_ISVALID(g_pGame) && HAS_FLAG(m_iStatus, ENEMY_STATUS_CRASH))
{
g_pGame->GetCrashManager()->AddCrash(*this, this->GetPosition().xy() - this->GetPosition().xy().Normalized() * 20.0f, NULL);
//g_pGame->GetCrashManager()->AddCrash(*this, coreVector2(0.0f,0.0f), NULL);
}
}
}
if(bEnergy)
{
// remove ship from glow and outline
g_pGlow->UnbindObject(this);
if(!bBottom && !bTop) g_pOutline->GetStyle(this->GetOutlineStyle())->UnbindObject(this);
}
else if(bSingle)
{
// remove ship from global shadow and outline
cShadow::GetGlobalContainer()->UnbindObject(this);
if(!bBottom && !bTop) g_pOutline->GetStyle(this->GetOutlineStyle())->UnbindObject(this);
}
// disable collision
this->ChangeType(0);
// remove ship from the game
this->_Kill(bAnimated);
//
this->__KillOwn(bAnimated);
//
if(this->IsParent()) FOR_EACH(it, m_apMember) (*it)->Kill(false); // # never animate
}
// ****************************************************************
// reset base properties
void cEnemy::ResetProperties()
{
// set object properties
this->SetPosition (coreVector3(HIDDEN_POS, 0.0f));
this->SetSize (coreVector3(1.0f, 1.0f, 1.0f) * ENEMY_SIZE_FACTOR);
this->SetDirection (coreVector3(0.0f,-1.0f, 0.0f));
this->SetOrientation (coreVector3(0.0f, 0.0f, 1.0f));
this->SetCollisionModifier(coreVector3(1.0f, 1.0f, 1.0f));
this->SetColor4 (coreVector4(1.0f, 1.0f, 1.0f, 1.0f));
// set initial status
m_iStatus = ENEMY_STATUS_DEAD;
}
// ****************************************************************
//
void cEnemy::ApplyScore(cPlayer* pPlayer)
{
ASSERT(STATIC_ISVALID(g_pGame))
ASSERT(!HAS_FLAG(m_iStatus, ENEMY_STATUS_BOSS))
if(!HAS_FLAG(m_iStatus, ENEMY_STATUS_WORTHLESS))
{
//
const coreUint32 iScore = pPlayer->GetScoreTable()->AddScore(g_pGame->RaiseValue(10u * m_iMaxHealth), true);
pPlayer->GetScoreTable()->AddCombo(1u);
//
g_pGame->GetCombatText()->DrawScore(iScore, this->GetPosition(), false);
//
this->TrackEnemy();
}
}
void cEnemy::ApplyScore()
{
//
this->ApplyScore(this->LastAttacker());
}
// ****************************************************************
//
void cEnemy::TrackEnemy()
{
//
g_pSave->EditGlobalStats()->iEnemiesDone += 1u;
}
// ****************************************************************
//
void cEnemy::RefreshColorAll(const coreFloat fFactor)
{
//
this->RefreshColor(fFactor);
//
if(this->IsParent())
{
FOR_EACH(it, m_apMember) (*it)->RefreshColor(fFactor);
}
}
void cEnemy::RefreshColorAll()
{
//
this->RefreshColorAll(this->GetCurHealthPct());
}
// ****************************************************************
//
void cEnemy::InvokeBlinkAll()
{
//
this->InvokeBlink();
//
if(this->IsParent())
{
FOR_EACH(it, m_apMember)(*it)->InvokeBlink();
}
}
// ****************************************************************
//
void cEnemy::ChangeToBottom()
{
//ASSERT(HAS_FLAG(m_iStatus, ENEMY_STATUS_SINGLE))
if(HAS_FLAG(m_iStatus, ENEMY_STATUS_SINGLE))
//
if(!HAS_FLAG(m_iStatus, ENEMY_STATUS_DEAD))
{
if(!HAS_FLAG(m_iStatus, ENEMY_STATUS_BOTTOM) && !HAS_FLAG(m_iStatus, ENEMY_STATUS_TOP))
g_pOutline->GetStyle(this->GetOutlineStyle())->UnbindObject(this);
}
//
ADD_FLAG (m_iStatus, ENEMY_STATUS_BOTTOM)
REMOVE_FLAG(m_iStatus, ENEMY_STATUS_TOP)
}
void cEnemy::ChangeToTop()
{
//ASSERT(HAS_FLAG(m_iStatus, ENEMY_STATUS_SINGLE))
if(HAS_FLAG(m_iStatus, ENEMY_STATUS_SINGLE))
//
if(!HAS_FLAG(m_iStatus, ENEMY_STATUS_DEAD))
{
if(!HAS_FLAG(m_iStatus, ENEMY_STATUS_BOTTOM) && !HAS_FLAG(m_iStatus, ENEMY_STATUS_TOP))
g_pOutline->GetStyle(this->GetOutlineStyle())->UnbindObject(this);
}
//
REMOVE_FLAG(m_iStatus, ENEMY_STATUS_BOTTOM)
ADD_FLAG (m_iStatus, ENEMY_STATUS_TOP)
}
void cEnemy::ChangeToNormal()
{
//ASSERT(HAS_FLAG(m_iStatus, ENEMY_STATUS_SINGLE))
if(HAS_FLAG(m_iStatus, ENEMY_STATUS_SINGLE))
//
if(!HAS_FLAG(m_iStatus, ENEMY_STATUS_DEAD))
{
if(HAS_FLAG(m_iStatus, ENEMY_STATUS_BOTTOM) || HAS_FLAG(m_iStatus, ENEMY_STATUS_TOP))
g_pOutline->GetStyle(this->GetOutlineStyle())->BindObject(this);
}
//
REMOVE_FLAG(m_iStatus, ENEMY_STATUS_BOTTOM)
REMOVE_FLAG(m_iStatus, ENEMY_STATUS_TOP)
}
// ****************************************************************
//
cPlayer* cEnemy::LastAttacker()const
{
//
ASSERT(STATIC_ISVALID(g_pGame))
return g_pGame->GetPlayer(this->LastAttackerIndex());
}
coreUintW cEnemy::LastAttackerIndex()const
{
//
ASSERT(m_iLastAttacker < GAME_PLAYERS)
return m_iLastAttacker;
}
// ****************************************************************
//
cPlayer* cEnemy::NearestPlayerSide()const
{
//
ASSERT(STATIC_ISVALID(g_pGame))
return g_pGame->FindPlayerSide(this->GetPosition().xy());
}
cPlayer* cEnemy::NearestPlayerSideRev()const
{
//
ASSERT(STATIC_ISVALID(g_pGame))
return g_pGame->FindPlayerSide(this->GetPosition().xy().InvertedX());
}
cPlayer* cEnemy::NearestPlayerDual(const coreUintW iIndex)const
{
//
ASSERT(STATIC_ISVALID(g_pGame))
return g_pGame->FindPlayerDual(iIndex);
}
// ****************************************************************
//
coreVector2 cEnemy::AimAtPlayerSide()const
{
//
return (this->NearestPlayerSide()->GetPosition().xy() - this->GetPosition().xy());
}
coreVector2 cEnemy::AimAtPlayerSideRev()const
{
//
return (this->NearestPlayerSideRev()->GetPosition().xy() - this->GetPosition().xy());
}
coreVector2 cEnemy::AimAtPlayerDual(const coreUintW iIndex)const
{
//
return (this->NearestPlayerDual(iIndex)->GetPosition().xy() - this->GetPosition().xy());
}
// ****************************************************************
//
void cEnemy::_SetParent(cEnemy* pParent)
{
ASSERT(!this->IsParent())
if(!m_apMember.empty())
{
//
m_apMember.front()->m_apMember.erase(this);
m_apMember.clear();
}
if(pParent)
{
ASSERT(!pParent->IsChild())
//
m_apMember.insert(pParent);
this->AddStatus(ENEMY_STATUS_CHILD);
//
pParent->m_apMember.insert(this);
pParent->RemoveStatus(ENEMY_STATUS_CHILD);
}
//
this->RefreshColor((pParent ? pParent : this)->GetCurHealthPct());
}
// ****************************************************************
// constructor
cEnemyManager::sEnemySetGen::sEnemySetGen()noexcept
: oEnemyActive ()
, iTopEnemy (0u)
{
}
// ****************************************************************
// constructor
cEnemyManager::cEnemyManager()noexcept
: m_apEnemySet {}
{
}
// ****************************************************************
// destructor
cEnemyManager::~cEnemyManager()
{
ASSERT(m_apAdditional.empty())
//
for(coreUintW i = 0u; i < ENEMY_SET_COUNT; ++i)
SAFE_DELETE(m_apEnemySet[i])
// clear memory
m_apAdditional.clear();
}
// ****************************************************************
// render the enemy manager
void cEnemyManager::Render()
{
// render all additional enemies
FOR_EACH(it, m_apAdditional)
{
if((*it)->HasStatus(ENEMY_STATUS_DEAD))
continue;
(*it)->Render();
}
// loop through all enemy sets
for(coreUintW i = 0u; i < ENEMY_SET_COUNT; ++i)
{
if(!m_apEnemySet[i]) continue;
coreBatchList* pEnemyActive = &m_apEnemySet[i]->oEnemyActive;
//
if(!pEnemyActive->GetNumEnabled()) continue;
// render all active enemies
cLodObject::RenderHighList(pEnemyActive);
}
}
#define __RENDER_OWN(f) \
{ \
/* */ \
const auto nRenderFunc = [](cEnemy* OUTPUT pEnemy) \
{ \
if(pEnemy->HasStatus(ENEMY_STATUS_DEAD)) \
return; \
\
pEnemy->f(); \
}; \
\
/* render all additional enemies */ \
FOR_EACH(it, m_apAdditional) \
nRenderFunc(*it); \
\
/* loop through all enemy sets */ \
for(coreUintW i = 0u; i < ENEMY_SET_COUNT; ++i) \
{ \
if(!m_apEnemySet[i]) continue; \
coreBatchList* pEnemyActive = &m_apEnemySet[i]->oEnemyActive; \
\
/* render all active enemies */ \
FOR_EACH(it, *pEnemyActive->List()) \
nRenderFunc(d_cast<cEnemy*>(*it)); \
} \
}
void cEnemyManager::RenderBottom()
{
__RENDER_OWN(__RenderOwnBottom)
DEPTH_PUSH
/* */
const auto nRenderFunc = [](cEnemy* OUTPUT pEnemy)
{
if(pEnemy->HasStatus(ENEMY_STATUS_DEAD))
return;
if(pEnemy->HasStatus(ENEMY_STATUS_BOTTOM))
{
pEnemy->_EnableBlink();
//
cLodObject::RenderHighObject(pEnemy);
g_pOutline->GetStyle(pEnemy->GetOutlineStyle())->ApplyObject(pEnemy); // TODO 1: batching
}
};
/* render all additional enemies */
FOR_EACH(it, m_apAdditional)
nRenderFunc(*it);
/* loop through all enemy sets */
for(coreUintW i = 0u; i < ENEMY_SET_COUNT; ++i)
{
if(!m_apEnemySet[i]) continue;
coreBatchList* pEnemyActive = &m_apEnemySet[i]->oEnemyActive;
/* render all active enemies */
FOR_EACH(it, *pEnemyActive->List())
nRenderFunc(d_cast<cEnemy*>(*it));
}
}
void cEnemyManager::RenderUnder () {__RENDER_OWN(__RenderOwnUnder)}
void cEnemyManager::RenderOver () {__RENDER_OWN(__RenderOwnOver)}
void cEnemyManager::RenderTop () {
DEPTH_PUSH
/* */
const auto nRenderFunc2 = [](cEnemy* OUTPUT pEnemy)
{
if(pEnemy->HasStatus(ENEMY_STATUS_DEAD))
return;
if(pEnemy->HasStatus(ENEMY_STATUS_TOP))
{
pEnemy->_EnableBlink();
//
cLodObject::RenderHighObject(pEnemy);
g_pOutline->GetStyle(pEnemy->GetOutlineStyle())->ApplyObject(pEnemy); // TODO 1: batching
}
};
/* render all additional enemies */
FOR_EACH(it, m_apAdditional)
nRenderFunc2(*it);
/* loop through all enemy sets */
for(coreUintW i = 0u; i < ENEMY_SET_COUNT; ++i)
{
if(!m_apEnemySet[i]) continue;
coreBatchList* pEnemyActive = &m_apEnemySet[i]->oEnemyActive;
/* render all active enemies */
FOR_EACH(it, *pEnemyActive->List())
nRenderFunc2(d_cast<cEnemy*>(*it));
}
//glEnable(GL_DEPTH_TEST);
__RENDER_OWN(__RenderOwnTop) // always after base
}
#undef __RENDER_OWN
// ****************************************************************
// move the enemy manager
void cEnemyManager::MoveBefore()
{
//
FOR_EACH(it, m_apAdditional)
(*it)->_UpdateAlwaysBefore();
//
for(coreUintW i = 0u; i < ENEMY_SET_COUNT; ++i)
{
if(!m_apEnemySet[i]) continue;
coreBatchList* pEnemyActive = &m_apEnemySet[i]->oEnemyActive;
//
FOR_EACH(it, *pEnemyActive->List())
d_cast<cEnemy*>(*it)->_UpdateAlwaysBefore();
}
}
void cEnemyManager::MoveMiddle()
{
// move all additional enemies (# bosses need to move before other enemies)
FOR_EACH(it, m_apAdditional)
(*it)->Move();
// loop through all enemy sets
for(coreUintW i = 0u; i < ENEMY_SET_COUNT; ++i)
{
if(!m_apEnemySet[i]) continue;
coreBatchList* pEnemyActive = &m_apEnemySet[i]->oEnemyActive;
// move the enemy set
pEnemyActive->MoveNormal();
}
}
void cEnemyManager::MoveAfter()
{
// not used
}
// ****************************************************************
//
void cEnemyManager::FreeEnemy(cEnemy** OUTPUT ppEnemy)
{
cEnemy* pEnemy = (*ppEnemy);
sEnemySetGen* pEnemySet = m_apEnemySet[pEnemy->GetID()];
//
pEnemy->Kill(false);
//
pEnemy->RemoveStatus(ENEMY_STATUS_ASSIGNED);
pEnemySet->oEnemyActive.UnbindObject(pEnemy);
//
pEnemySet->iTopEnemy = 0u;
//
(*ppEnemy) = NULL;
}
// ****************************************************************
// remove all enemies
void cEnemyManager::ClearEnemies(const coreBool bAnimated)
{
// loop trough all enemy sets
for(coreUintW i = 0u; i < ENEMY_SET_COUNT; ++i)
{
if(!m_apEnemySet[i]) continue;
coreBatchList* pEnemyActive = &m_apEnemySet[i]->oEnemyActive;
// deactivate all active enemies
FOR_EACH(it, *pEnemyActive->List())
d_cast<cEnemy*>(*it)->Kill(bAnimated);
}
// deactivate all additional enemies
FOR_EACH(it, m_apAdditional)
(*it)->Kill(bAnimated);
}
// ****************************************************************
//
cEnemy* cEnemyManager::FindEnemy(const coreVector2 vPosition)const
{
//
cEnemy* pEnemy = NULL;
coreFloat fLenSq = FLT_MAX;
//
this->ForEachEnemy([&](cEnemy* OUTPUT pCurEnemy)
{
//
const coreFloat fCurLenSq = (pCurEnemy->GetPosition().xy() - vPosition).LengthSq();
if(fCurLenSq < fLenSq)
{
//
pEnemy = pCurEnemy;
fLenSq = fCurLenSq;
}
});
return pEnemy;
}
// ****************************************************************
//
cEnemy* cEnemyManager::FindEnemyRev(const coreVector2 vPosition)const
{
//
cEnemy* pEnemy = NULL;
coreFloat fLenSq = 0.0f;
//
this->ForEachEnemy([&](cEnemy* OUTPUT pCurEnemy)
{
//
const coreFloat fCurLenSq = (pCurEnemy->GetPosition().xy() - vPosition).LengthSq();
if(fCurLenSq > fLenSq)
{
//
pEnemy = pCurEnemy;
fLenSq = fCurLenSq;
}
});
return pEnemy;
}
// ****************************************************************
// destructor
cEnemySquad::~cEnemySquad()
{
//
this->FreeEnemies();
}
// ****************************************************************
//
void cEnemySquad::FreeEnemies()
{
//
FOR_EACH(it, m_apEnemy)
cEnemySquad::__GetDefaultEnemyManager()->FreeEnemy(&(*it));
// clear memory
m_apEnemy.clear();
}
// ****************************************************************
//
void cEnemySquad::ClearEnemies(const coreBool bAnimated)const
{
//
FOR_EACH(it, m_apEnemy)
(*it)->Kill(bAnimated);
}
// ****************************************************************
//
cEnemy* cEnemySquad::FindEnemy(const coreVector2 vPosition)const
{
//
cEnemy* pEnemy = NULL;
coreFloat fLenSq = FLT_MAX;
//
this->ForEachEnemy([&](cEnemy* OUTPUT pCurEnemy, const coreUintW i)
{
//
const coreFloat fCurLenSq = (pCurEnemy->GetPosition().xy() - vPosition).LengthSq();
if(fCurLenSq < fLenSq)
{
//
pEnemy = pCurEnemy;
fLenSq = fCurLenSq;
}
});
return pEnemy;
}
// ****************************************************************
//
cEnemy* cEnemySquad::FindEnemyRev(const coreVector2 vPosition)const
{
//
cEnemy* pEnemy = NULL;
coreFloat fLenSq = 0.0f;
//
this->ForEachEnemy([&](cEnemy* OUTPUT pCurEnemy, const coreUintW i)
{
//
const coreFloat fCurLenSq = (pCurEnemy->GetPosition().xy() - vPosition).LengthSq();
if(fCurLenSq > fLenSq)
{
//
pEnemy = pCurEnemy;
fLenSq = fCurLenSq;
}
});
return pEnemy;
}
// ****************************************************************
//
cEnemyManager* cEnemySquad::__GetDefaultEnemyManager()
{
ASSERT(STATIC_ISVALID(g_pGame))
return g_pGame->GetEnemyManager();
}
// ****************************************************************
// constructor
cDummyEnemy::cDummyEnemy()noexcept
{
// load models
this->DefineModelHigh(Core::Manager::Object->GetLowQuad());
this->DefineModelLow (Core::Manager::Object->GetLowQuad());
}
// ****************************************************************
// constructor
cScoutEnemy::cScoutEnemy()noexcept
{
// load models
this->DefineModelHigh("ship_enemy_scout_high.md3");
this->DefineModelLow ("ship_enemy_scout_low.md3");
this->DefineVolume ("ship_enemy_scout_volume.md3");
}
// ****************************************************************
//
void cScoutEnemy::__ResurrectOwn()
{
//