-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathACraft.cpp
More file actions
812 lines (701 loc) · 26.9 KB
/
ACraft.cpp
File metadata and controls
812 lines (701 loc) · 26.9 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
#include "ACraft.h"
#include "AtomGroup.h"
#include "Leg.h"
#include "Controller.h"
#include "Matrix.h"
#include "AEmitter.h"
#include "HDFirearm.h"
#include "Controller.h"
#include "SceneMan.h"
#include "Scene.h"
#include "SettingsMan.h"
#include "FrameMan.h"
#include "GUI.h"
#include "AllegroBitmap.h"
using namespace RTE;
AbstractClassInfo(ACraft, Actor);
const std::string ACraft::Exit::c_ClassName = "Exit";
bool ACraft::s_CrabBombInEffect = false;
#define EXITLINESPACING 7
#define EXITSUCKDELAYMS 1500
ACraft::ACraft() {
Clear();
}
ACraft::~ACraft() {
Destroy(true);
}
void ACraft::Exit::Clear() {
m_Offset.Reset();
m_Velocity.Reset();
m_VelSpread = 0.2f;
m_Radius = 10;
m_Range = 35;
m_Clear = true;
m_pIncomingMO = 0;
}
int ACraft::Exit::Create(const Exit& reference) {
m_Offset = reference.m_Offset;
m_Velocity = reference.m_Velocity;
m_VelSpread = reference.m_VelSpread;
m_Radius = reference.m_Radius;
m_Range = reference.m_Range;
m_Clear = reference.m_Clear;
return 0;
}
int ACraft::Exit::Create() {
if (Serializable::Create() < 0)
return -1;
return 0;
}
int ACraft::Exit::ReadProperty(const std::string_view& propName, Reader& reader) {
StartPropertyList(return Serializable::ReadProperty(propName, reader));
MatchProperty("Offset", { reader >> m_Offset; });
MatchProperty("Velocity", { reader >> m_Velocity; });
MatchProperty("VelocitySpread", { reader >> m_VelSpread; });
MatchProperty("Radius", { reader >> m_Radius; });
MatchProperty("Range", { reader >> m_Range; });
EndPropertyList;
}
int ACraft::Exit::Save(Writer& writer) const {
Serializable::Save(writer);
writer.NewProperty("Offset");
writer << m_Offset;
writer.NewProperty("Velocity");
writer << m_Velocity;
writer.NewProperty("VelocitySpread");
writer << m_VelSpread;
writer.NewProperty("Radius");
writer << m_Radius;
writer.NewProperty("Range");
writer << m_Range;
return 0;
}
bool ACraft::Exit::CheckIfClear(const Vector& pos, Matrix& rot, float size) {
Vector notUsed;
Vector ray = m_Velocity;
ray.SetMagnitude(size);
return m_Clear = !g_SceneMan.CastNotMaterialRay(pos + (m_Offset * rot), ray * rot, g_MaterialAir, notUsed);
}
MOSRotating* ACraft::Exit::SuckInMOs(ACraft* pExitOwner) {
if (!pExitOwner || !m_Clear)
return 0;
Vector exitPos = pExitOwner->GetPos() + pExitOwner->RotateOffset(m_Offset);
Vector exitRadius;
Vector exitCorner;
Vector rayVec = pExitOwner->RotateOffset(m_Velocity);
// If we're sucking on an MO already
if (m_pIncomingMO) {
const float suckageRange = m_Range * 1.5F;
// Check that it's still active and valid (not destroyed)
if (!(g_MovableMan.IsDevice(m_pIncomingMO) || g_MovableMan.IsActor(m_pIncomingMO))) {
m_pIncomingMO = 0;
}
// See if it's now out of range of suckage
else if ((exitPos - m_pIncomingMO->GetPos()).MagnitudeIsGreaterThan(suckageRange)) {
m_pIncomingMO = 0;
}
// See if the object has been sucked in far enough to be considered picked up by the exit
else if ((m_pIncomingMO->GetPos() - exitPos).Dot(rayVec) < 0) {
// Yes, the object has been sucked in beyond the offset position of the exit itself, so we're done picking it up
// Zero out the incoming member pointer to show that we're not sucking on anyhting anymore
MOSRotating* pReturnMO = m_pIncomingMO;
m_pIncomingMO = 0;
return pReturnMO;
}
// Ok it's not quite there yet, so keep sucking it in
else {
// Figure the distance left for the object to go to reach the exit
Vector toGo = exitPos - m_pIncomingMO->GetPos();
// If the object is still a bit away from the exit goal, override velocity of the object to head straight into the exit
const float threshold = 1.0F;
if (toGo.MagnitudeIsGreaterThan(threshold)) {
m_pIncomingMO->SetVel(toGo.SetMagnitude(m_Velocity.GetMagnitude()));
}
// Turn off collisions between the object and the craft sucking it in
m_pIncomingMO->SetWhichMOToNotHit(pExitOwner, 3);
pExitOwner->SetWhichMOToNotHit(m_pIncomingMO, 3);
}
}
// Not sucking in anything, so see if there's anyhting to start doing it to
if (!m_pIncomingMO) {
exitRadius = pExitOwner->RotateOffset(m_Velocity.GetPerpendicular().SetMagnitude(m_Radius));
exitCorner = exitPos + exitRadius;
rayVec = pExitOwner->RotateOffset(m_Velocity);
rayVec.SetMagnitude(m_Range);
MOID itemMOID = g_SceneMan.CastMORay(exitCorner, rayVec, pExitOwner->GetRootID(), Activity::NoTeam, g_MaterialGrass, true, 4);
// Try the other side if we didn't find anything
if (itemMOID == g_NoMOID) {
exitCorner -= exitRadius * 2;
itemMOID = g_SceneMan.CastMORay(exitCorner, rayVec, pExitOwner->GetRootID(), Activity::NoTeam, g_MaterialGrass, true, 4);
}
// Try center beam if we STILL didn't find anything
if (itemMOID == g_NoMOID) {
exitCorner += exitRadius;
itemMOID = g_SceneMan.CastMORay(exitCorner, rayVec, pExitOwner->GetRootID(), Activity::NoTeam, g_MaterialGrass, true, 4);
}
// See if we caught anything
MovableObject* pItem = g_MovableMan.GetMOFromID(itemMOID);
if (pItem) {
// We did! Now start sucking it in (next frame)
m_pIncomingMO = dynamic_cast<MOSRotating*>(pItem->GetRootParent());
// Don't suck in other ACraft!
if (dynamic_cast<ACraft*>(m_pIncomingMO))
m_pIncomingMO = 0;
}
}
// Nothing was sucked in far enough to be returned as done
return 0;
}
void ACraft::Clear() {
m_AIMode = AIMODE_DELIVER;
m_MovementState = NOMOVE;
m_HatchState = CLOSED;
m_HatchTimer.Reset();
m_HatchDelay = 0;
m_HatchOpenSound = nullptr;
m_HatchCloseSound = nullptr;
m_CollectedInventory.clear();
m_Exits.clear();
m_CurrentExit = m_Exits.begin();
m_ExitInterval = 1000;
m_ExitTimer.Reset();
m_ExitLinePhase = 0;
m_HasDelivered = false;
m_LandingCraft = true;
m_FlippedTimer.Reset();
m_CrashTimer.Reset();
m_CrashSound = nullptr;
m_DeliveryState = FALL;
m_AltitudeMoveState = HOVER;
m_AltitudeControl = 0;
m_CanEnterOrbit = true;
m_MaxPassengers = -1;
m_DeliveryDelayMultiplier = 1.0;
m_ScuttleIfFlippedTime = 4000;
m_ScuttleOnDeath = true;
}
int ACraft::Create() {
// Read all the properties
if (Actor::Create() < 0)
return -1;
if (m_AIMode == Actor::AIMODE_NONE) {
m_AIMode = Actor::AIMODE_DELIVER;
}
m_CurrentExit = m_Exits.begin();
return 0;
}
int ACraft::Create(const ACraft& reference) {
Actor::Create(reference);
m_MovementState = reference.m_MovementState;
m_HatchState = reference.m_HatchState;
m_HatchDelay = reference.m_HatchDelay;
if (reference.m_HatchOpenSound) {
m_HatchOpenSound = dynamic_cast<SoundContainer*>(reference.m_HatchOpenSound->Clone());
}
if (reference.m_HatchCloseSound) {
m_HatchCloseSound = dynamic_cast<SoundContainer*>(reference.m_HatchCloseSound->Clone());
} else if (reference.m_HatchOpenSound) {
m_HatchCloseSound = dynamic_cast<SoundContainer*>(reference.m_HatchOpenSound->Clone());
}
for (std::deque<MovableObject*>::const_iterator niItr = reference.m_CollectedInventory.begin(); niItr != reference.m_CollectedInventory.end(); ++niItr)
m_CollectedInventory.push_back(dynamic_cast<MovableObject*>((*niItr)->Clone()));
for (std::list<Exit>::const_iterator eItr = reference.m_Exits.begin(); eItr != reference.m_Exits.end(); ++eItr)
m_Exits.push_back(*eItr);
m_CurrentExit = m_Exits.begin();
m_ExitInterval = reference.m_ExitInterval;
m_HasDelivered = reference.m_HasDelivered;
m_LandingCraft = reference.m_LandingCraft;
if (reference.m_CrashSound) {
m_CrashSound = dynamic_cast<SoundContainer*>(reference.m_CrashSound->Clone());
}
m_DeliveryState = reference.m_DeliveryState;
m_AltitudeMoveState = reference.m_AltitudeMoveState;
m_AltitudeControl = reference.m_AltitudeControl;
m_CanEnterOrbit = reference.m_CanEnterOrbit;
m_MaxPassengers = reference.m_MaxPassengers;
m_DeliveryDelayMultiplier = reference.m_DeliveryDelayMultiplier;
m_ScuttleIfFlippedTime = reference.m_ScuttleIfFlippedTime;
m_ScuttleOnDeath = reference.m_ScuttleOnDeath;
return 0;
}
int ACraft::ReadProperty(const std::string_view& propName, Reader& reader) {
StartPropertyList(return Actor::ReadProperty(propName, reader));
MatchProperty("HatchDelay", { reader >> m_HatchDelay; });
MatchProperty("HatchOpenSound", {
m_HatchOpenSound = new SoundContainer;
reader >> m_HatchOpenSound;
});
MatchProperty("HatchCloseSound", {
m_HatchCloseSound = new SoundContainer;
reader >> m_HatchCloseSound;
});
MatchProperty("CrashSound", {
m_CrashSound = new SoundContainer;
reader >> m_CrashSound;
});
MatchProperty("AddExit",
{
Exit exit;
reader >> exit;
m_Exits.push_back(exit);
});
MatchProperty("DeliveryDelayMultiplier", { reader >> m_DeliveryDelayMultiplier; });
MatchProperty("ExitInterval", { reader >> m_ExitInterval; });
MatchProperty("CanLand", { reader >> m_LandingCraft; });
MatchProperty("CanEnterOrbit", { reader >> m_CanEnterOrbit; });
MatchProperty("MaxPassengers", { reader >> m_MaxPassengers; });
MatchProperty("ScuttleIfFlippedTime", { reader >> m_ScuttleIfFlippedTime; });
MatchProperty("ScuttleOnDeath", { reader >> m_ScuttleOnDeath; });
EndPropertyList;
}
int ACraft::Save(Writer& writer) const {
Actor::Save(writer);
writer.NewProperty("HatchDelay");
writer << m_HatchDelay;
writer.NewProperty("HatchOpenSound");
writer << m_HatchOpenSound;
writer.NewProperty("HatchCloseSound");
writer << m_HatchCloseSound;
for (std::list<Exit>::const_iterator itr = m_Exits.begin(); itr != m_Exits.end(); ++itr) {
writer.NewProperty("AddExit");
writer << (*itr);
}
writer.NewProperty("DeliveryDelayMultiplier");
writer << m_DeliveryDelayMultiplier;
writer.NewProperty("ExitInterval");
writer << m_ExitInterval;
writer.NewProperty("CanLand");
writer << m_LandingCraft;
writer.NewProperty("CrashSound");
writer << m_CrashSound;
writer.NewProperty("CanEnterOrbit");
writer << m_CanEnterOrbit;
writer.NewProperty("MaxPassengers");
writer << m_MaxPassengers;
writer.NewProperty("ScuttleIfFlippedTime");
writer << m_ScuttleIfFlippedTime;
writer.NewProperty("ScuttleOnDeath");
writer << m_ScuttleOnDeath;
return 0;
}
void ACraft::Destroy(bool notInherited) {
delete m_HatchOpenSound;
delete m_HatchCloseSound;
delete m_CrashSound;
if (!notInherited)
Actor::Destroy();
Clear();
}
float ACraft::GetTotalValue(int nativeModule, float foreignMult, float nativeMult) const {
float totalValue = Actor::GetTotalValue(nativeModule, foreignMult, nativeMult);
MOSprite* pItem = 0;
for (std::deque<MovableObject*>::const_iterator itr = m_CollectedInventory.begin(); itr != m_CollectedInventory.end(); ++itr) {
pItem = dynamic_cast<MOSprite*>(*itr);
if (pItem)
totalValue += pItem->GetTotalValue(nativeModule, foreignMult, nativeMult);
}
return totalValue;
}
bool ACraft::HasObject(std::string objectName) const {
if (Actor::HasObject(objectName))
return true;
for (std::deque<MovableObject*>::const_iterator itr = m_CollectedInventory.begin(); itr != m_CollectedInventory.end(); ++itr) {
if ((*itr) && (*itr)->HasObject(objectName))
return true;
}
return false;
}
bool ACraft::HasObjectInGroup(std::string groupName) const {
if (Actor::HasObjectInGroup(groupName))
return true;
for (std::deque<MovableObject*>::const_iterator itr = m_CollectedInventory.begin(); itr != m_CollectedInventory.end(); ++itr) {
if ((*itr) && (*itr)->HasObjectInGroup(groupName))
return true;
}
return false;
}
void ACraft::SetTeam(int team) {
Actor::SetTeam(team);
// Also set all actors in the new inventory
Actor* pActor = 0;
for (std::deque<MovableObject*>::iterator itr = m_CollectedInventory.begin(); itr != m_CollectedInventory.end(); ++itr) {
pActor = dynamic_cast<Actor*>(*itr);
if (pActor)
pActor->SetTeam(team);
}
}
bool ACraft::HandlePieCommand(PieSliceType pieSliceIndex) {
if (pieSliceIndex != PieSliceType::NoType) {
if (pieSliceIndex == PieSliceType::Deliver) {
m_AIMode = AIMODE_DELIVER;
m_DeliveryState = FALL;
m_HasDelivered = false;
} else if (pieSliceIndex == PieSliceType::Return) {
m_AIMode = AIMODE_RETURN;
m_DeliveryState = LAUNCH;
} else if (pieSliceIndex == PieSliceType::Stay) {
m_AIMode = AIMODE_STAY;
m_DeliveryState = FALL;
} else if (pieSliceIndex == PieSliceType::Sentry) {
m_AIMode = AIMODE_SENTRY;
m_DeliveryState = FALL;
} else if (pieSliceIndex == PieSliceType::GoTo) {
m_AIMode = AIMODE_GOTO;
m_DeliveryState = FALL;
ClearAIWaypoints();
} else if (pieSliceIndex == PieSliceType::Scuttle) {
m_AIMode = AIMODE_SCUTTLE;
} else {
return Actor::HandlePieCommand(pieSliceIndex);
}
}
return false;
}
void ACraft::OpenHatch() {
if (m_HatchState == CLOSED || m_HatchState == CLOSING) {
m_HatchState = OPENING;
m_HatchTimer.Reset();
// PSCHHT
if (m_HatchOpenSound) {
m_HatchOpenSound->Play(m_Pos);
}
}
}
void ACraft::CloseHatch() {
if (m_HatchState == OPEN || m_HatchState == OPENING) {
m_HatchState = CLOSING;
m_HatchTimer.Reset();
// When closing, move all newly added inventory to the regular inventory list so it'll be ejected next time doors open
for (std::deque<MovableObject*>::const_iterator niItr = m_CollectedInventory.begin(); niItr != m_CollectedInventory.end(); ++niItr) {
AddToInventoryBack(*niItr);
}
// Clear the new inventory hold, it's all been moved to the regular inventory
m_CollectedInventory.clear();
// PSCHHT
if (m_HatchCloseSound) {
m_HatchCloseSound->Play(m_Pos);
}
}
}
void ACraft::AddInventoryItem(MovableObject* pItemToAdd) {
if (pItemToAdd) {
// If the hatch is open, then only add the new item to the intermediate new inventory list
// so that it doesn't get chucked out right away again
if (m_HatchState == OPEN || m_HatchState == OPENING) {
m_CollectedInventory.push_back(pItemToAdd);
} else {
// If doors are already closed, it's safe to put the item directly the regular inventory
AddToInventoryBack(pItemToAdd);
}
if (Actor* itemAsActor = dynamic_cast<Actor*>(pItemToAdd); itemAsActor && itemAsActor->GetGoldCarried() > 0) {
m_GoldCarried += itemAsActor->GetGoldCarried();
itemAsActor->SetGoldCarried(0);
m_GoldPicked = true;
if (g_ActivityMan.GetActivity()->IsHumanTeam(m_Team)) {
for (int player = Players::PlayerOne; player < Players::MaxPlayerCount; player++) {
if (g_ActivityMan.GetActivity()->GetTeamOfPlayer(player) == m_Team) {
g_GUISound.FundsChangedSound()->Play(player);
}
}
}
}
}
}
void ACraft::DropAllInventory() {
if (m_HatchState == OPEN && !m_Exits.empty()) {
// Cancel if we're not due to release
if (!m_ExitTimer.IsPastSimMS(m_ExitInterval))
return;
bool exitExists = false;
std::list<Exit>::iterator exit = m_Exits.begin();
// Check which exits are clear of the terrain, if any
for (; exit != m_Exits.end(); ++exit) {
if (exit->CheckIfClear(m_Pos, m_Rotation, 18))
exitExists = true;
}
// Cancel if no exits are clear
if (!exitExists) {
// TODO: give some kind of audio feedback to user
return;
}
// Eject inventory and passengers, through alternating clear exits
Vector exitVel, exitVelNorm, gravityNorm;
float antiGravBoost = 0;
Actor* pPassenger = 0;
bool droppedSomething = false;
for (std::deque<MovableObject*>::iterator exitee = m_Inventory.begin(); exitee != m_Inventory.end(); ++exitee) {
// Select next clear exit
do {
if (++m_CurrentExit == m_Exits.end())
m_CurrentExit = m_Exits.begin();
} while (!m_CurrentExit->IsClear());
//(*exitee)->SetPos(m_Pos + m_CurrentExit->GetOffset() * m_Rotation);
(*exitee)->SetPos(m_Pos + RotateOffset(m_CurrentExit->GetOffset()));
// Reset all the timers of the object being shot out so it doesn't emit a bunch of particles that have been backed up while dormant in inventory
(*exitee)->ResetAllTimers();
// exitVel = m_CurrentExit->GetVelocity() * m_Rotation;
exitVel = RotateOffset(m_CurrentExit->GetVelocity());
// Boost against gravity
// Normalize the gravity and exit velocity vectors
exitVelNorm = exitVel;
exitVelNorm.SetMagnitude(1.0);
gravityNorm = g_SceneMan.GetGlobalAcc();
gravityNorm.SetMagnitude(1.0);
// Make the gravity boost be proportional to counteract gravity
antiGravBoost = 1.0 + 1.0 * exitVelNorm.Dot(-gravityNorm);
if (antiGravBoost < 1.0)
antiGravBoost = 1.0;
// Detect whether we're dealing with a passenger and add it as Actor instead
pPassenger = dynamic_cast<Actor*>(*exitee);
if (pPassenger && m_ExitTimer.IsPastSimMS(m_ExitInterval)) {
pPassenger->SetVel(m_Vel + exitVel * antiGravBoost);
// pPassenger->SetRotAngle(m_Rotation + exitVel.GetAbsRadAngle() (ejectDir > 0 ? -c_HalfPI : c_HalfPI));
// pPassenger->SetHFlipped(ejectDir <= 0);
// Avoid having immediate collisions with this
pPassenger->SetWhichMOToNotHit(this, 0.5f);
// Avoid this immediate collisions with it
SetWhichMOToNotHit(pPassenger, 0.5f);
// Add to scene
g_MovableMan.AddActor(pPassenger);
// If this craft is being directly controlled by a player, and has landed, switch control to the first guy out
if (pPassenger->GetTeam() == m_Team && m_Controller.IsPlayerControlled() && g_ActivityMan.GetActivity()->GetControlledActor(m_Controller.GetPlayer()) == this && m_LandingCraft) {
g_ActivityMan.GetActivity()->SwitchToActor(pPassenger, m_Controller.GetPlayer(), m_Team);
// To avoid jump in the view, Update the passenger so its viewpoint is next to it and not at 0,0
pPassenger->Update();
}
// Remove from inventory
m_Inventory.erase(exitee);
// Reset timer interval and quit until next one is due
m_ExitTimer.Reset();
} else {
(*exitee)->SetVel(m_Vel + exitVel * antiGravBoost);
(*exitee)->SetAngularVel(5.0F * RandomNormalNum());
// Avoid it having immediate collisions with this
(*exitee)->SetWhichMOToNotHit(this, 0.5f);
// Avoid this immediate collisions with it
SetWhichMOToNotHit(*exitee, 0.5f);
// Add to scene
g_MovableMan.AddMO(*exitee);
// Remove passenger from inventory
m_Inventory.erase(exitee);
// Reset timer interval and quit until next one is due
m_ExitTimer.Reset();
}
}
if (m_Inventory.empty()) {
m_HasDelivered = true;
// Kill craft if it is lying down.
if (std::fabs(m_Rotation.GetRadAngle()) > c_HalfPI && m_Status != DYING) {
m_Status = DYING;
m_DeathTmr.Reset();
}
// Reset exit timer so we can time until when we should start sucking things in again
// Don't reset it if inventory is empty but we didn't drop anyhting, it means that doors just opened and nothing was inside, so immediately start sucking
if (droppedSomething)
m_ExitTimer.Reset();
}
} else {
if (m_HatchState != OPENING) {
if (m_HatchOpenSound) {
m_HatchOpenSound->Play(m_Pos);
}
g_MovableMan.RegisterAlarmEvent(AlarmEvent(m_Pos, m_Team, 0.4));
m_HatchTimer.Reset();
}
m_HatchState = OPENING;
}
}
float ACraft::GetCollectedInventoryMass() const {
float inventoryMass = 0.0F;
for (const MovableObject* inventoryItem: m_CollectedInventory) {
inventoryMass += inventoryItem->GetMass();
}
return inventoryMass;
}
void ACraft::GibThis(const Vector& impactImpulse, MovableObject* movableObjectToIgnore) {
if (g_SettingsMan.CrabBombsEnabled() && !s_CrabBombInEffect) {
s_CrabBombInEffect = true;
int crabCount = 0;
for (const MovableObject* inventoryEntry: m_Inventory) {
if (inventoryEntry->GetPresetName() == "Crab") {
crabCount++;
}
}
if (crabCount >= g_SettingsMan.GetCrabBombThreshold()) {
for (int moid = 1; moid < g_MovableMan.GetMOIDCount() - 1; moid++) {
Actor* actor = dynamic_cast<Actor*>(g_MovableMan.GetMOFromID(moid));
if (actor && actor != this && actor->GetClassName() != "ADoor" && !actor->IsInGroup("Brains")) {
actor->GibThis();
}
}
}
s_CrabBombInEffect = false;
}
Actor::GibThis(impactImpulse, movableObjectToIgnore);
}
void ACraft::ResetAllTimers() {
MOSRotating::ResetAllTimers();
m_FlippedTimer.Reset();
}
void ACraft::Update() {
Actor::Update();
////////////////////////////////////
// Update viewpoint
// Set viewpoint based on how we are aiming etc.
m_ViewPoint = m_Pos.GetFloored();
// Add velocity also so the viewpoint moves ahead at high speeds
if (m_Vel.MagnitudeIsGreaterThan(10.0F)) {
m_ViewPoint += m_Vel * std::sqrt(m_Vel.GetMagnitude() * 0.1F);
}
///////////////////////////////////////////////////
// Crash detection and handling
const float crashSpeedThreshold = 1.0F;
if (m_DeepHardness > 5 && m_Vel.MagnitudeIsGreaterThan(crashSpeedThreshold)) {
m_Health -= m_DeepHardness * 0.03;
// TODO: HELLA GHETTO, REWORK
if (m_CrashTimer.GetElapsedSimTimeMS() > 500) {
if (m_CrashSound) {
m_CrashSound->Play(m_Pos);
}
m_CrashTimer.Reset();
}
}
///////////////////////////////////////////////////
// Doors open logic
if (m_HatchState == OPEN) {
// Keep ejecting things if hatch is open and inventory isn't empty
if (!IsInventoryEmpty())
DropAllInventory();
// If doors are open and all inventory is ejected (and they have had a chance to fall away), then actively look for things to suck in through the exits.
else if (m_Status == STABLE && m_ExitTimer.IsPastSimMS(EXITSUCKDELAYMS)) {
// See if any of the exits have sucked in an MO
for (std::list<Exit>::iterator exit = m_Exits.begin(); exit != m_Exits.end(); ++exit) {
// If exit sucked in an MO, add it to invetory
MOSRotating* pNewObject = exit->SuckInMOs(this);
if (pNewObject && !pNewObject->IsSetToDelete()) {
// Did we catch an Actor? If so, we need to do special controller switching in case it's player controlled atm
Actor* pCaughtActor = 0;
if (pCaughtActor = dynamic_cast<Actor*>(pNewObject)) {
// Switch control to this craft if the Actor we just caught is on our team and currently player controlled
// Set AI controller of the Actor going into the ship
if (pCaughtActor->GetTeam() == m_Team && g_ActivityMan.GetActivity() && pCaughtActor->GetController()->IsPlayerControlled())
g_ActivityMan.GetActivity()->SwitchToActor(this, pCaughtActor->GetController()->GetPlayer(), pCaughtActor->GetTeam());
// Add (copy) of caught Actor to this' inventory
AddInventoryItem(dynamic_cast<MovableObject*>(pCaughtActor->Clone()));
// Delete the original from scene - this is safer than 'removing' or handing over ownership halfway through MovableMan's update
pCaughtActor->SetToDelete();
// Negate the team 'loss' that will be reported when the deletion is done
g_ActivityMan.GetActivity()->ReportDeath(pCaughtActor->GetTeam(), -1);
}
// Any other MO has been caught, jsut add it to inventory
// TODO: do we need special case for Attachables?? (so we can detach them first? - probably no because SuckInMOs is unlikely to return an attahced thing)
else {
// Add (copy) of caught Actor to this' inventory
AddInventoryItem(dynamic_cast<MovableObject*>(pNewObject->Clone()));
// Delete the original from scene - this is safer than 'removing' or handing over ownership halfway through MovableMan's update
pNewObject->SetToDelete();
}
pNewObject = 0;
}
}
}
}
/////////////////////////////////////////
// Check for having gone into orbit
if (m_CanEnterOrbit) {
if (m_Pos.m_Y < -m_CharHeight || m_Pos.m_Y > g_SceneMan.GetSceneHeight() + m_CharHeight) {
g_ActivityMan.GetActivity()->HandleCraftEnteringOrbit(this);
// Play fading away thruster sound
// if (m_pMThruster && m_pMThruster->IsEmitting())
// m_pMThruster->(pTargetBitmap, targetPos, mode, onlyPhysical);
m_ToDelete = true;
}
// Horizontal orbiting, if scene doesn't wrap
if (g_ActivityMan.GetActivity()->GetCraftOrbitAtTheEdge()) {
if (g_SceneMan.GetScene() && !g_SceneMan.GetScene()->WrapsX()) {
if (m_Pos.m_X < -GetSpriteWidth() || m_Pos.m_X > g_SceneMan.GetSceneWidth() + GetSpriteWidth()) {
g_ActivityMan.GetActivity()->HandleCraftEnteringOrbit(this);
m_ToDelete = true;
}
}
}
}
if (m_Status == DEAD) {
if (m_ScuttleOnDeath || m_AIMode == AIMODE_SCUTTLE) {
GibThis();
}
} else if (m_Status == DYING) {
if ((m_ScuttleOnDeath || m_AIMode == AIMODE_SCUTTLE) && m_DeathTmr.IsPastSimMS(500) && m_DeathTmr.AlternateSim(100)) {
FlashWhite(10);
}
} else if (m_Health <= 0 || m_AIMode == AIMODE_SCUTTLE || (m_ScuttleIfFlippedTime >= 0 && m_FlippedTimer.IsPastSimMS(m_ScuttleIfFlippedTime))) {
m_Status = DYING;
m_DeathTmr.Reset();
DropAllInventory();
}
// Get the rotation in radians.
float rot = m_Rotation.GetRadAngle();
// Eliminate rotations over half a turn.
if (std::abs(rot) > c_PI) {
rot += (rot > 0) ? -c_TwoPI : c_TwoPI;
m_Rotation.SetRadAngle(rot);
}
if (rot < c_HalfPI && rot > -c_HalfPI) {
m_FlippedTimer.Reset();
}
/////////////////////////////////////////
// Misc.
m_DeepCheck = true /*m_Status == DEAD*/;
}
void ACraft::DrawHUD(BITMAP* pTargetBitmap, const Vector& targetPos, int whichScreen, bool playerControlled) {
m_HUDStack = -m_CharHeight / 2;
// Only do HUD if on a team
if (m_Team < 0) {
return;
}
// Only draw if the team viewing this is on the same team OR has seen the space where this is located.
int viewingTeam = g_ActivityMan.GetActivity()->GetTeamOfPlayer(g_ActivityMan.GetActivity()->PlayerOfScreen(whichScreen));
if (viewingTeam != m_Team && viewingTeam != Activity::NoTeam && (!g_SettingsMan.ShowEnemyHUD() || g_SceneMan.IsUnseen(m_Pos.GetFloorIntX(), m_Pos.GetFloorIntY(), viewingTeam))) {
return;
}
Actor::DrawHUD(pTargetBitmap, targetPos, whichScreen);
if (!m_HUDVisible) {
return;
}
GUIFont* pSymbolFont = g_FrameMan.GetLargeFont();
GUIFont* pSmallFont = g_FrameMan.GetSmallFont();
// Draw hud guides for the Exits, depending on whether the doors are open
if (m_HatchState == OPEN /* || m_HatchState == OPENING*/) {
// Doors open and inventory not empty yet, so show arrows pointing out of the exits since things are still coming out
if (!IsInventoryEmpty()) {
// --------
// | \ \
// -+- | |
// | / /
// --------
// Make the dotted lines crawl out of the exit, indicating that things are still coming out
if (--m_ExitLinePhase < 0) {
m_ExitLinePhase = EXITLINESPACING - 1;
}
}
// Inventory empty and doors open, so show arrows pointing into the exits IF the delay to allow for things to eject away all the way has passed
else if (m_ExitTimer.IsPastSimMS(EXITSUCKDELAYMS)) {
// Make the dotted lines crawl back into the exit, inviting people to jump in
if (++m_ExitLinePhase >= EXITLINESPACING) {
m_ExitLinePhase = 0;
}
}
// Draw the actual dotted lines
for (std::list<Exit>::iterator exit = m_Exits.begin(); exit != m_Exits.end(); ++exit) {
if (!exit->CheckIfClear(m_Pos, m_Rotation, 18)) {
continue;
}
Vector exitRadius = RotateOffset(exit->GetVelocity().GetPerpendicular().SetMagnitude(exit->GetRadius()));
Vector exitCorner = m_Pos - targetPos + RotateOffset(exit->GetOffset()) + exitRadius;
Vector arrowVec = RotateOffset(exit->GetVelocity().SetMagnitude(exit->GetRange()));
g_FrameMan.DrawLine(pTargetBitmap, exitCorner, exitCorner + arrowVec, 120, 120, EXITLINESPACING, m_ExitLinePhase);
exitCorner -= exitRadius * 2;
g_FrameMan.DrawLine(pTargetBitmap, exitCorner, exitCorner + arrowVec, 120, 120, EXITLINESPACING, m_ExitLinePhase);
}
}
}