forked from TheSuperHackers/GeneralsGameCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpecialAbilityUpdate.cpp
More file actions
2086 lines (1806 loc) · 69.6 KB
/
Copy pathSpecialAbilityUpdate.cpp
File metadata and controls
2086 lines (1806 loc) · 69.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
** Command & Conquer Generals Zero Hour(tm)
** Copyright 2025 Electronic Arts Inc.
**
** 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 3 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, see <http://www.gnu.org/licenses/>.
*/
////////////////////////////////////////////////////////////////////////////////
// //
// (c) 2001-2003 Electronic Arts Inc. //
// //
////////////////////////////////////////////////////////////////////////////////
// FILE: SpecialAbilityUpdate.cpp /////////////////////////////////////////////////////////////////////////
// Author: Kris Morness, July 2002
// Desc: Handles processing of unit special abilities.
///////////////////////////////////////////////////////////////////////////////////////////////////
#include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine
#include "Common/GameAudio.h"
#include "Common/GlobalData.h"
#include "Common/Player.h"
#include "Common/PlayerList.h"
#include "Common/Radar.h"
#include "Common/SpecialPower.h"
#include "Common/Team.h"
#include "Common/ThingFactory.h"
#include "Common/ThingTemplate.h"
#include "Common/MiscAudio.h"
#include "Common/Xfer.h"
#include "GameClient/Drawable.h"
#include "GameClient/FXList.h"
#include "GameClient/Eva.h"
#include "GameClient/InGameUI.h"
#include "GameClient/ControlBar.h"
#include "GameClient/GameText.h"
#include "GameLogic/AIPathfind.h"
#include "GameLogic/GameLogic.h"
#include "GameLogic/Object.h"
#include "GameLogic/PartitionManager.h"
#include "GameLogic/Weapon.h"
#include "GameLogic/ExperienceTracker.h"
#include "GameLogic/Module/AIUpdate.h"
#include "GameLogic/Module/LaserUpdate.h"
#include "GameLogic/Module/PhysicsUpdate.h"
#include "GameLogic/Module/SpecialAbilityUpdate.h"
#include "GameLogic/Module/SpecialPowerModule.h"
#include "GameLogic/Module/StickyBombUpdate.h"
#include "GameLogic/Module/StealthUpdate.h"
#include "GameLogic/Module/ContainModule.h"
//-------------------------------------------------------------------------------------------------
SpecialAbilityUpdate::SpecialAbilityUpdate( Thing *thing, const ModuleData* moduleData ) : SpecialPowerUpdateModule( thing, moduleData )
{
m_captureFlashPhase = 0.0f;
m_active = false;
m_prepFrames = 0;
m_animFrames = 0;
m_targetID = INVALID_ID;
m_targetPos.zero();
m_locationCount = 0;
m_specialObjectEntries = 0;
m_noTargetCommand = false;
m_packingState = STATE_NONE;
m_facingInitiated = false;
m_facingComplete = false;
m_withinStartAbilityRange = false;
m_doDisableFXParticles = TRUE;// true always, unless small unit causes it to toggle on-off
setWakeFrame(getObject(), UPDATE_SLEEP_FOREVER);
// This is the althernate way to one-at-a-time BlackLotus' specials; we'll keep it commented her until Dustin decides, or until 12/10/02
// setBusy( FALSE );
}
//-------------------------------------------------------------------------------------------------
SpecialAbilityUpdate::~SpecialAbilityUpdate()
{
onExit( true );
}
/*------------------------------------------------------------------------------------------------
void SpecialAbilityUpdate::update()
This is the brains of the entire special ability update. There are several optional steps and
variations that can be processed for any particular type of special ability. A special ability
that has every option will do the following in order:
1 -- APPROACH: If I'm not close enough to the target, then approach it
2 -- UNPACK: If I need to unpack before I can prepare, then do so now (this uses the model
condition unpack).
3 -- PREPARE: If I need to perform a task for a period of time before I can trigger my special
ability, then do so now. A good example is aiming with a targeting laser for a few
seconds before firing your special weapon.
4 -- TRIGGER: Once preparation is complete, fire your special ability now.
5 -- PACK: If I need to pack after finishing my attack, do so now.
6 -- FINISH: Clean up the states, and turn off the update.
Variations:
Persistent Specials -- A persistent special will continually trigger it's effect every so often
and never end. A good example of this is the disable building hack. The hacker will run up
to the target building, unpack, prepare (firing hack stream), then after a period of time,
the building becomes disabled. But because it's persistent, we reset the preparation and
trigger the building disabled code over and over again -- which is on a timer.
No Target Specials -- You can link two different main specials together. Colonel Burton has the
ability to lay C4 charges on multiple targets. Activating these specials require a target.
The non-target version is actually the detonator, which goes through all the special objects
and detonates each one of them.
Options:
SpecialPowerTemplate -- Defines the special power template that links to a command.
StartAbilityRange -- Specify how far you want your unit to be from the target before
start your special ability.
AbilityAbortRange -- After starting an attack, it'll allow preparation unless the target goes
beyond this range. If this happens, the ability is aborted outright.
PreparationTime -- How long it takes to prepare your special once in position and unpacked.
PersistentPrepTime -- This value defines whether or not you are using a persistent special.
Once the special ability is triggered, it'll wait until this specified
delay occurs and it'll trigger it again, for ever until the unit dies,
the target dies, or the unit decides to do something else.
PackTime -- How long it takes to pack up the unit after triggering a non persistent
special ability or after ordering the unit to do something else, or the
target dies (if applicable).
PackUnpackVariationFactor -- Randomizes the pack and unpack time by specified range. The closer
to zero, the smaller the variation. 0.2 would have a pack or unpack range
of xTime +/- 20%. This is important because it represents averages.
UnpackTime -- Same as PackTime, except used once entering range of target.
SkipPackingWithNoTarget -- This option is used by the No Target Special variation, and only uses
packing/unpacking when you have a specific target. In the case of Colonel
Burton, this value is set to true. When he plants a C4 charge, he has a
target, therefore he requires unpacking (laying the charge). When he runs
away and decides to detonate the charge, he calls the same special
ability, but without a target -- therefore the packing is skipped and
detonates it right away.
SpecialObject -- Defines the special object the unit will create via the special ability.
In one case, it creates and maintains the laser or binary stream during
preparation. In Colonel Burton's case, it keeps track of the C4 charges
that he has placed.
MaxSpecialObjects -- Defines the max number of special objects that can exist at any given
time. The laser example only has one, but the C4 charges can have more.
SpecialObjectsPersistent -- If this flag is set, then the objects will remain should the owner
decides to do something else... C4 charges are a good example.
EffectDuration -- Defines the duration of the special ability. In the case of disabling
the building (hacker), this value will dictate how long the building
will be disabled should the hacker die or stop the attack.
UniqueSpecialObjectTargets -- Prevents the owner from placing multiple special objects on the
same target. C4 charges once again.
SpecialObjectsPersistWhenOwnerDies -- If the owner dies, the special objects will remain in
the world. Timed C4 charges is a good example, but remote C4 charges
is a bad example -- because it requires the owner to detonate them.
FlipObjectAfterPacking -- Simply rotates the object 180 degrees after packing (due to special
animation case).
FlipObjectAfterUnPacking -- Simply rotates the object 180 degrees after unpacking (due to
special animation case). Used by colonel burton after planting charge.
Lets use the Age of Kings Trebuchet as a simple example:
Variation -- PersistentPrepTime (set to true in ini file)
1 -- APPROACH: Get within range before unpacking
2 -- UNPACK: Unpack the treb at this location.
3 -- PREPARE: Aim at the target
4 -- TRIGGER: Fire the treb.
5 -- RESET PREPARATION: Go to step 3 until target dead.
6 -- PACK: Assuming we are done... pack up
7 -- FINISH: Stop the special ability
-------------------------------------------------------------------------------------------------*/
UpdateSleepTime SpecialAbilityUpdate::update()
{
/// @todo srj -- this could probably sleep more between stages. maybe someday.
// Note: This will be complicated because one difficult example is handling Burton when he dies while
// bombs are in the world.
//Validation of special objects makes sure that they still exist. Sometimes special
//objects can be destroyed or removed, or detonate, etc! When they go missing,
//they are removed from the special object list and free up slots for those units
//that can have multiple.
//We need to do this now because it's possible the special objects need to be checked while
//the the special ability is over (thus inactive).
const SpecialAbilityUpdateModuleData* data = getSpecialAbilityUpdateModuleData();
validateSpecialObjects();
//Important! This check will see if there has been any commands issued by either the player
//or script. When told to do something else, we need to immediately cleanup our special ability.
//This also means some things might be left around like timed charges to detonate.
if( getObject()->isEffectivelyDead() )
{
onExit( TRUE );
return calcSleepTime();
}
if( !m_active ) // Not active.
return calcSleepTime();
AIUpdateInterface *ai = getObject()->getAIUpdateInterface();
if( !ai )
{
onExit( false );
return calcSleepTime();
}
if( ai->getLastCommandSource() != CMD_FROM_AI )
{
onExit( false );
return calcSleepTime();
}
if( ai->isMoving() && isPowerCurrentlyInUse() && !m_facingInitiated )
{
// Capture is broken by movement just as if we had been given a direct command (above check).
// However, the time of Facing the target is considered isPowerCurrentlyInUse, but isMoving. So let that slide.
switch(data->m_specialPowerTemplate->getSpecialPowerType() )
{
case SPECIAL_INFANTRY_CAPTURE_BUILDING:
case SPECIAL_BLACKLOTUS_CAPTURE_BUILDING:
{
onExit( false );
return calcSleepTime();
}
break;
default:
break;
}
}
//STEP 2 & 5(6) -- Handles packing and unpacking in progress. If packing
//then ends the special ability once complete. Things that don't pack
//will never be handled, nor do things that aren't in a packing state.
if( handlePackingProcessing() )
{
return calcSleepTime();
}
Bool shouldAbort = false;
// A dead target will end our special (if we are using a target).
if (m_targetID != INVALID_ID)
{
Object* target = TheGameLogic->findObjectByID(m_targetID);
if (target != nullptr)
{
if (target->isEffectivelyDead())
shouldAbort = TRUE;
else switch (data->m_specialPowerTemplate->getSpecialPowerType())
{
case SPECIAL_INFANTRY_CAPTURE_BUILDING:
case SPECIAL_BLACKLOTUS_CAPTURE_BUILDING:
case SPECIAL_HACKER_DISABLE_BUILDING:
{
if (target->getTeam() == getObject()->getTeam())
{
// it's been captured by a colleague! we should stop.
shouldAbort = TRUE;
}
FALLTHROUGH; //deliberately falling through...
}
case SPECIAL_BLACKLOTUS_STEAL_CASH_HACK:
case SPECIAL_BOOBY_TRAP:
{
if ( target->testStatus( OBJECT_STATUS_STEALTHED ) && (target->testStatus( OBJECT_STATUS_DETECTED ) == FALSE ) )
{
if ( !isPreparationComplete() )
shouldAbort = TRUE;
}
break;
}
case SPECIAL_REMOTE_CHARGES:
case SPECIAL_TIMED_CHARGES:
{
if ( ! needToUnpack() )
{
if ( target->testStatus( OBJECT_STATUS_STEALTHED ) && (target->testStatus( OBJECT_STATUS_DETECTED ) == FALSE ) )
{
if ( !isPreparationComplete() )
shouldAbort = TRUE;
}
}
break;
}
case SPECIAL_MISSILE_DEFENDER_LASER_GUIDED_MISSILES:
{
if ( target->isKindOf( KINDOF_STRUCTURE ) )
shouldAbort = TRUE;
FALLTHROUGH; //deliberately falling through
}
case SPECIAL_BLACKLOTUS_DISABLE_VEHICLE_HACK:
{
if ( target->testStatus( OBJECT_STATUS_STEALTHED ) && (target->testStatus( OBJECT_STATUS_DETECTED ) == FALSE ) )
{
// where'd my target go? 'Twas here just a second ago.
shouldAbort = TRUE;
}
break;
}
}
}
}
SpecialPowerModuleInterface *spm = getMySPM();
if ( shouldAbort || spm == nullptr )
{
// doh, a colleague has already captured it. just stop.
ai->aiIdle( CMD_FROM_AI );
onExit( false );
return calcSleepTime();
}
//DETERMINE OUR PHASE! BRAIN LOGIC
if( !isPreparationComplete() )
{
//The special ability has fired, now continue to process the special ability
//until it expires
Bool SPMReady = TRUE;// normally considered ready since this ability has just been initiated
// Lorenzen added this additional flag to support the NapalmBombDrop
// It causes this update to force a recharge of the SPM between drops
if( isPersistentAbility() && getDoesPersistenceRequireRecharge() )//unless I intend to persist in this ability's effect, whereupon I must verify that power is recharged
SPMReady = ( spm->isReady() && spm->getReadyFrame() < TheGameLogic->getFrame() );
if ( SPMReady )// if power requires recharging, lets freeze prep countdown until power is ready
m_prepFrames--;
if( isPreparationComplete() )
{
//STEP 4 -- TRIGGER (with preparation)
triggerAbilityEffect();
if( isPersistentAbility() )
{
//VARIATION -- PERSISTENCE (repeats preparation)
resetPreparation();
//tell the special power module to restart the recharge timer
if ( getDoesPersistenceRequireRecharge() )
spm->startPowerRecharge();
}
else
{
endPreparation();
if( needToPack() )
{
//STEP 5 -- PACK
//Note: If we actually do pack, then cleanup will be handled in
//handlePackingProcess(), near the top of this function.
startPacking(true);
}
else
{
//STEP 6 -- FINISH
finishAbility();
}
}
}
else
{
//Process the preparation if it's still not complete.
Bool continuePrep = continuePreparation();
if( !continuePrep )
{
//We failed so abort!
endPreparation();
if( needToPack() )
{
//STEP 5 -- PACK
//Note: If we actually do pack, then cleanup will be handled in
//handlePackingProcess(), near the top of this function.
startPacking(false);
}
else
{
//STEP 6 -- FINISH
finishAbility();
}
}
}
}
else if( isWithinStartAbilityRange() )
{
m_withinStartAbilityRange = true;
if( !isFacing() && needToFace() )
{
startFacing();
return calcSleepTime();
}
if( needToUnpack() )
{
//STEP 2 -- UNPACK
startUnpacking();
return calcSleepTime();
}
if( m_packingState == STATE_UNPACKED )
{
//STEP 3 -- PREPARE
startPreparation();
if( isPreparationComplete() )
{
//STEP 4 -- TRIGGER (skipping preparation)
triggerAbilityEffect();
// Lorenzen added this additional flag to support the NapalmBombDrop
// It causes this update to force a recharge of the SPM between drops
if( isPersistentAbility() && getDoesPersistenceRequireRecharge())
{
//VARIATION -- PERSISTENCE (repeats preparation)
resetPreparation();
//tell the special power module to restart the recharge timer
spm->startPowerRecharge();
return calcSleepTime();
}
else
endPreparation();
if( needToPack() )
{
//STEP 5 -- PACK
//Note: If we actually do pack, then cleanup will be handled in
//handlePackingProcess(), near the top of this function.
startPacking(true);
}
else
{
//STEP 6 -- FINISH
finishAbility();
}
}
}
}
else if( ai->isIdle() )
{
//STEP 1 -- APPROACH
approachTarget();
}
return calcSleepTime();
}
//-------------------------------------------------------------------------------------------------
Bool SpecialAbilityUpdate::initiateIntentToDoSpecialPower( const SpecialPowerTemplate *specialPowerTemplate,
const Object *targetObj,
const Coord3D *targetPos,
const Waypoint *way,
UnsignedInt commandOptions )
{
const SpecialAbilityUpdateModuleData* data = getSpecialAbilityUpdateModuleData();
const SpecialPowerTemplate *spTemplate = data->m_specialPowerTemplate;
if( spTemplate != specialPowerTemplate )
{
//Check to make sure our modules are connected.
return FALSE;
}
//Clear target values
m_targetID = INVALID_ID;
m_targetPos.zero();
m_locationCount = 0;
m_prepFrames = 0;
m_animFrames = 0;
m_packingState = STATE_PACKED;
m_facingInitiated = false;
m_facingComplete = false;
m_withinStartAbilityRange = false;
// getObject()->getControllingPlayer()->getAcademyStats()->recordSpecialPowerUsed( specialPowerTemplate );
getObject()->clearModelConditionFlags(
MAKE_MODELCONDITION_MASK4( MODELCONDITION_UNPACKING, MODELCONDITION_PACKING, MODELCONDITION_FIRING_A, MODELCONDITION_RAISING_FLAG ) );
if( targetObj )
{
//Get the target!
m_targetID = targetObj ? targetObj->getID() : INVALID_ID;
}
else if( targetPos )
{
//Get the position!
m_targetPos = *targetPos;
}
//Clear any old AI before starting this special ability.
if( !getObject()->getAIUpdateInterface() )
{
return FALSE;
}
getObject()->getAIUpdateInterface()->aiIdle( CMD_FROM_AI );
//Determine whether we are triggering a command (rather than executing special at location or target)
m_noTargetCommand = !targetObj && !targetPos;
if( data->m_unpackTime == 0 || (m_noTargetCommand && data->m_skipPackingWithNoTarget) )
{
//Only unpack if we need to -- setting it to unpacked will skip step 2 in the update
m_packingState = STATE_UNPACKED;
}
m_active = true;
//Prevent other mutually exclusive specials from running (kill them now if we're starting something else)
SpecialAbilityUpdate *disableSA;
disableSA = getObject()->findSpecialAbilityUpdate( SPECIAL_BLACKLOTUS_DISABLE_VEHICLE_HACK );
if( disableSA && disableSA != this )
disableSA->onExit( FALSE );
disableSA = getObject()->findSpecialAbilityUpdate( SPECIAL_BLACKLOTUS_STEAL_CASH_HACK );
if( disableSA && disableSA != this )
disableSA->onExit( FALSE );
disableSA = getObject()->findSpecialAbilityUpdate( SPECIAL_BLACKLOTUS_CAPTURE_BUILDING );
if( disableSA && disableSA != this )
disableSA->onExit( FALSE );
disableSA = getObject()->findSpecialAbilityUpdate( SPECIAL_REMOTE_CHARGES );
if( disableSA && disableSA != this )
disableSA->onExit( FALSE );
disableSA = getObject()->findSpecialAbilityUpdate( SPECIAL_TIMED_CHARGES );
if( disableSA && disableSA != this )
disableSA->onExit( FALSE );
disableSA = getObject()->findSpecialAbilityUpdate( SPECIAL_INFANTRY_CAPTURE_BUILDING );
if( disableSA && disableSA != this )
disableSA->onExit( FALSE );
disableSA = getObject()->findSpecialAbilityUpdate( SPECIAL_BOOBY_TRAP );
if( disableSA && disableSA != this )
disableSA->onExit( FALSE );
setWakeFrame(getObject(), UPDATE_SLEEP_NONE);
return TRUE;
}
//-------------------------------------------------------------------------------------------------
Bool SpecialAbilityUpdate::isPowerCurrentlyInUse( const CommandButton *command ) const
{
if( command )
{
if( command->getSpecialPowerTemplate() && command->getSpecialPowerTemplate()->getSpecialPowerType() == SPECIAL_REMOTE_CHARGES )
{
if( !BitIsSet( command->getOptions(), CONTEXTMODE_COMMAND ) )
{
//This is the detonate charge button. Treat it backwards saying it's in use when we don't have any special objects (charges).
//That way, the button will be grayed out.
return getSpecialObjectCount() == 0;
}
}
}
if( m_packingState != STATE_NONE )
{
//exception for powers with zero reload time... they are ready to use immediately!
if ( (m_packingState == STATE_PACKING || m_packingState == STATE_PACKED) &&
command && command->getSpecialPowerTemplate()->getReloadTime() == 0 )
return false;
if ( m_withinStartAbilityRange )
{
return true;
}
}
return false;
}
//-------------------------------------------------------------------------------------------------
void SpecialAbilityUpdate::onExit( Bool cleanup )
{
const SpecialAbilityUpdateModuleData* data = getSpecialAbilityUpdateModuleData();
getObject()->clearModelConditionFlags(
MAKE_MODELCONDITION_MASK4( MODELCONDITION_UNPACKING, MODELCONDITION_PACKING, MODELCONDITION_FIRING_A, MODELCONDITION_RAISING_FLAG ) );
getObject()->clearStatus( MAKE_OBJECT_STATUS_MASK( OBJECT_STATUS_IS_USING_ABILITY ) );
TheAudio->removeAudioEvent( m_prepSoundLoop.getPlayingHandle() );
endPreparation();
if( !data->m_specialObjectsPersistent || (cleanup && !data->m_specialObjectsPersistWhenOwnerDies) )
{
//Delete special objects that aren't considered persistent whenever we turn off
//leave the special ability update.
killSpecialObjects();
}
m_active = false;
m_withinStartAbilityRange = false;
m_packingState = STATE_NONE;
// This is the althernate way to one-at-a-time BlackLotus' specials; we'll keep it commented her until Dustin decides, or until 12/10/02
// setBusy( FALSE );// My owner is no longer using me
// no, actually, we DON'T want to call this here, since onExit is always called
// (directly or indirectly) from update()... and calling setWakeFrame() from your
// own update() method is a no-no (since it would just be ignored in favor
// of the return value from update() anyway). just set m_active to false,
// and we'll put ourselves to sleep.
// setWakeFrame(getObject(), UPDATE_SLEEP_FOREVER);
}
//-------------------------------------------------------------------------------------------------
//Some special abilities requires packing or unpacking. When setup, all this function does is
//decrement the counter and clear the model state when finished.
//Returns TRUE if we are still packing or unpacking.
//-------------------------------------------------------------------------------------------------
Bool SpecialAbilityUpdate::handlePackingProcessing()
{
const SpecialAbilityUpdateModuleData* data = getSpecialAbilityUpdateModuleData();
if( m_animFrames > 0 )
{
m_animFrames--;
if( m_animFrames == 0 )
{
// We're done, so clear the states.
getObject()->clearModelConditionFlags( MAKE_MODELCONDITION_MASK2( MODELCONDITION_UNPACKING, MODELCONDITION_PACKING ) );
if( m_packingState == STATE_UNPACKING )
{
if( data->m_flipObjectAfterUnpacking )
{
getObject()->setOrientation( getObject()->getOrientation() + PI );
}
m_packingState = STATE_UNPACKED;
}
else if( m_packingState == STATE_PACKING )
{
if( data->m_flipObjectAfterPacking )
{
getObject()->setOrientation( getObject()->getOrientation() + PI );
}
//We just finished packing up, therefore
//we have completed our special ability.
m_packingState = STATE_PACKED;
//Do exit preparation.
finishAbility();
//Complete the special ability now
return true;
}
//We're finished processing
return false;
}
//This is new... the ability to disable stealth before triggering
if( getSpecialAbilityUpdateModuleData()->m_loseStealthOnTrigger &&
m_animFrames < getSpecialAbilityUpdateModuleData()->m_preTriggerUnstealthFrames)
{
StealthUpdate* stealth = getObject()->getStealth();
if( stealth )
{
stealth->markAsDetected();
}
}
//We're still processing
return true;
}
//We're not processing
return false;
}
//-------------------------------------------------------------------------------------------------
Bool SpecialAbilityUpdate::needToPack() const
{
const SpecialAbilityUpdateModuleData* data = getSpecialAbilityUpdateModuleData();
if( m_packingState == STATE_UNPACKED )
{
if( data->m_skipPackingWithNoTarget && m_noTargetCommand )
{
return false;
}
if( data->m_packTime )
{
return true;
}
}
return false;
}
//-------------------------------------------------------------------------------------------------
Bool SpecialAbilityUpdate::needToUnpack() const
{
const SpecialAbilityUpdateModuleData* data = getSpecialAbilityUpdateModuleData();
if( m_packingState == STATE_PACKED )
{
if( data->m_skipPackingWithNoTarget && m_noTargetCommand )
{
return false;
}
if( data->m_unpackTime )
{
return true;
}
}
return false;
}
//-------------------------------------------------------------------------------------------------
void SpecialAbilityUpdate::startPacking(Bool success)
{
const SpecialAbilityUpdateModuleData* data = getSpecialAbilityUpdateModuleData();
m_packingState = STATE_PACKING;
Real variation = GameLogicRandomValueReal( 1.0f - data->m_packUnpackVariationFactor, 1.0f + data->m_packUnpackVariationFactor );
m_animFrames = data->m_packTime * variation;
//Set the animation state
getObject()->clearAndSetModelConditionFlags(
MAKE_MODELCONDITION_MASK2( MODELCONDITION_UNPACKING, MODELCONDITION_RAISING_FLAG ),
MAKE_MODELCONDITION_MASK( MODELCONDITION_PACKING ) );
AudioEventRTS sound = data->m_packSound;
sound.setObjectID( getObject()->getID() );
TheAudio->addAudioEvent( &sound );
//Sync the animation length to the time it'll take to pack.
Drawable* draw = getObject()->getDrawable();
if (draw)
draw->setAnimationCompletionTime( m_animFrames );
AIUpdateInterface *ai = getObject()->getAIUpdateInterface();
if (ai)
ai->aiBusy(CMD_FROM_AI);
if (success)
{
AudioEventRTS event;
switch( data->m_specialPowerTemplate->getSpecialPowerType() )
{
//case SPECIAL_HACKER_DISABLE_BUILDING:// Awaiting Mical's new sound
// event = *getObject()->getTemplate()->getPerUnitSound( "VoiceDisableBuildingComplete" );
// break;
case SPECIAL_BLACKLOTUS_CAPTURE_BUILDING:
event = *getObject()->getTemplate()->getPerUnitSound( "VoiceCaptureBuildingComplete" );
break;
case SPECIAL_BLACKLOTUS_DISABLE_VEHICLE_HACK:
event = *getObject()->getTemplate()->getPerUnitSound( "VoiceDisableVehicleComplete" );
break;
case SPECIAL_BLACKLOTUS_STEAL_CASH_HACK:
event = *getObject()->getTemplate()->getPerUnitSound( "VoiceStealCashComplete" );
break;
default:
event = *getObject()->getTemplate()->getVoiceTaskComplete();
break;
}
event.setObjectID(getObject()->getID());
TheAudio->addAudioEvent(&event);
}
}
//-------------------------------------------------------------------------------------------------
void SpecialAbilityUpdate::startUnpacking()
{
const SpecialAbilityUpdateModuleData* data = getSpecialAbilityUpdateModuleData();
m_packingState = STATE_UNPACKING;
Real variation = GameLogicRandomValueReal( 1.0f - data->m_packUnpackVariationFactor, 1.0f + data->m_packUnpackVariationFactor );
m_animFrames = data->m_unpackTime * variation;
//Set the animation state
getObject()->clearAndSetModelConditionFlags(
MAKE_MODELCONDITION_MASK( MODELCONDITION_PACKING ),
MAKE_MODELCONDITION_MASK( MODELCONDITION_UNPACKING ) );
AudioEventRTS sound = data->m_unpackSound;
sound.setObjectID( getObject()->getID() );
TheAudio->addAudioEvent( &sound );
//Sync the animation length to the time it'll take to unpack.
Drawable* draw = getObject()->getDrawable();
if (draw)
draw->setAnimationCompletionTime( m_animFrames );
AIUpdateInterface *ai = getObject()->getAIUpdateInterface();
if (ai)
ai->aiBusy(CMD_FROM_AI);
}
//-------------------------------------------------------------------------------------------------
Bool SpecialAbilityUpdate::isWithinStartAbilityRange() const
{
const SpecialAbilityUpdateModuleData* data = getSpecialAbilityUpdateModuleData();
const Object *self = getObject();
//Quickly convert very short range approaches to "contact" class requiring collision before
//stopping.
Real range = data->m_startAbilityRange;
const Real UNDERSIZE = PATHFIND_CELL_SIZE_F * 0.25f;
range = __max( 0.0f, range - UNDERSIZE );
if( m_withinStartAbilityRange )
{
//Only get within range once.
return true;
}
Real fDistSquared = 0.0f;
Object *target = nullptr;
if( m_targetID != INVALID_ID )
{
target = TheGameLogic->findObjectByID( m_targetID );
if( target )
{
fDistSquared = ThePartitionManager->getDistanceSquared( self, target, FROM_BOUNDINGSPHERE_2D );
}
}
else if( m_targetPos.x || m_targetPos.y || m_targetPos.z ) //It's zero if not used...
{
fDistSquared = ThePartitionManager->getDistanceSquared( self, &m_targetPos, FROM_BOUNDINGSPHERE_2D );
}
else
{
//No position, so this step is useless
return true;
}
//Check to see how far we are from the target!
Real fStartRangeSquared = data->m_startAbilityRange * data->m_startAbilityRange;
if( fDistSquared <= fStartRangeSquared )
{
if( range == 0.0f && m_targetID != INVALID_ID )
{
//We want to ensure we collided with our target first!
ObjectIterator *iter = ThePartitionManager->iteratePotentialCollisions( self->getPosition(), self->getGeometryInfo(), 0.0f );
MemoryPoolObjectHolder hold(iter);
for( Object *them = iter->first(); them; them = iter->next() )
{
if( target == them )
{
return true;
}
}
return false;
}
if( data->m_approachRequiresLOS )
{
//Make sure we can see the target!
PartitionFilterLineOfSight filterLOS( self );
PartitionFilter *filters[] = { &filterLOS, nullptr };
ObjectIterator *iter = ThePartitionManager->iterateObjectsInRange( self, range, FROM_BOUNDINGSPHERE_2D, filters, ITER_SORTED_NEAR_TO_FAR );
MemoryPoolObjectHolder hold(iter);
for( Object *theTarget = iter->first(); theTarget; theTarget = iter->next() )
{
//LOS check succeeded.
if( target == theTarget )
{
return true;
}
}
}
else
{
return true;
}
}
return false;
}
//-------------------------------------------------------------------------------------------------
Bool SpecialAbilityUpdate::isWithinAbilityAbortRange() const
{
const SpecialAbilityUpdateModuleData* data = getSpecialAbilityUpdateModuleData();
const Object *self = getObject();
//Quickly convert very short range approaches to "contact" class requiring collision before
//stopping.
Real range = data->m_startAbilityRange;
const Real UNDERSIZE = PATHFIND_CELL_SIZE_F * 0.25f;
range = __max( 0.0f, range - UNDERSIZE );
Real fDistSquared = 0.0f;
Object *target = nullptr;
if( m_targetID != INVALID_ID )
{
target = TheGameLogic->findObjectByID( m_targetID );
if( target )
{
fDistSquared = ThePartitionManager->getDistanceSquared( self, target, FROM_BOUNDINGSPHERE_2D );
}
}
else if( m_targetPos.x || m_targetPos.y || m_targetPos.z ) //It's zero if not used...
{
fDistSquared = ThePartitionManager->getDistanceSquared( self, &m_targetPos, FROM_BOUNDINGSPHERE_2D );
}
else
{
//No position, so this step is useless
return true;
}
//Check to see how far we are from the target!
Real fStartRangeSquared = data->m_abilityAbortRange * data->m_abilityAbortRange;
if( fDistSquared <= fStartRangeSquared )
{
if( range == 0.0f && m_targetID != INVALID_ID )
{
//We want to ensure we collided with our target first!
ObjectIterator *iter = ThePartitionManager->iteratePotentialCollisions( self->getPosition(), self->getGeometryInfo(), 0.0f );
MemoryPoolObjectHolder hold(iter);
for( Object *them = iter->first(); them; them = iter->next() )
{
if( target == them )
{
return true;
}
}
return false;
}
return true;
}
return false;
}
//-------------------------------------------------------------------------------------------------
Bool SpecialAbilityUpdate::approachTarget()
{
Object *self = getObject();
if( m_targetID != INVALID_ID )
{
Object *target = TheGameLogic->findObjectByID( m_targetID );
if( target )
{
AIUpdateInterface *ai = self->getAIUpdateInterface();
if( ai )
{
ai->ignoreObstacle( target );
ai->aiMoveToObject( target, CMD_FROM_AI );
return true;
}
}
}
else if( m_targetPos.x || m_targetPos.y || m_targetPos.z ) //It's zero if not used...
{
AIUpdateInterface *ai = self->getAIUpdateInterface();
if( ai )
{
ai->aiMoveToPosition( &m_targetPos, CMD_FROM_AI );
return true;
}
}
return false;
}
//-------------------------------------------------------------------------------------------------
void SpecialAbilityUpdate::startPreparation()
{
const SpecialAbilityUpdateModuleData* data = getSpecialAbilityUpdateModuleData();
const SpecialPowerTemplate *spTemplate = data->m_specialPowerTemplate;
//Set the preparation timer
m_prepFrames = data->m_preparationFrames;
switch( spTemplate->getSpecialPowerType() )
{
case SPECIAL_MISSILE_DEFENDER_LASER_GUIDED_MISSILES:
{
Object *target = TheGameLogic->findObjectByID( m_targetID );
if( target )
{
//Specialized code that specifically creates and looks up a laser update.
Object *specialObject = createSpecialObject();
if( specialObject )
{
if (!initLaser(specialObject, target))
return;