forked from TheSuperHackers/GeneralsGameCode
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathSpecialPowerModule.cpp
More file actions
902 lines (761 loc) · 33.6 KB
/
SpecialPowerModule.cpp
File metadata and controls
902 lines (761 loc) · 33.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
/*
** 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: SpecialPowerModule.cpp ///////////////////////////////////////////////////////////////////
// Author: Colin Day, April 2002
// Desc: Special power module interface
///////////////////////////////////////////////////////////////////////////////////////////////////
// USER INCLUDES //////////////////////////////////////////////////////////////////////////////////
#include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine
#include "Common/GameAudio.h"
#include "Common/GameUtility.h"
#include "Common/GlobalData.h"
#include "Common/INI.h"
#include "Common/Player.h"
#include "Common/PlayerList.h"
#include "Common/Science.h"
#include "Common/SpecialPower.h"
#include "Common/ThingFactory.h"
#include "Common/ThingTemplate.h"
#include "Common/Xfer.h"
#include "GameLogic/GameLogic.h"
#include "GameLogic/Object.h"
#include "GameLogic/Module/DeletionUpdate.h"
#include "GameLogic/Module/UpdateModule.h"
#include "GameLogic/Module/SpecialPowerModule.h"
#include "GameLogic/Module/SpecialPowerUpdateModule.h"
#include "GameLogic/ScriptEngine.h"
#include "GameClient/Eva.h"
#include "GameClient/InGameUI.h"
#include "GameClient/ControlBar.h"
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
SpecialPowerModuleData::SpecialPowerModuleData()
{
m_specialPowerTemplate = nullptr;
m_updateModuleStartsAttack = false;
m_startsPaused = FALSE;
m_scriptedSpecialPowerOnly = FALSE;
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
/* static */ void SpecialPowerModuleData::buildFieldParse(MultiIniFieldParse& p)
{
BehaviorModuleData::buildFieldParse( p );
static const FieldParse dataFieldParse[] =
{
{ "SpecialPowerTemplate", INI::parseSpecialPowerTemplate, nullptr, offsetof( SpecialPowerModuleData, m_specialPowerTemplate ) },
{ "UpdateModuleStartsAttack", INI::parseBool, nullptr, offsetof( SpecialPowerModuleData, m_updateModuleStartsAttack ) },
{ "StartsPaused", INI::parseBool, nullptr, offsetof( SpecialPowerModuleData, m_startsPaused ) },
{ "InitiateSound", INI::parseAudioEventRTS, nullptr, offsetof( SpecialPowerModuleData, m_initiateSound ) },
{ "ScriptedSpecialPowerOnly", INI::parseBool, nullptr, offsetof( SpecialPowerModuleData, m_scriptedSpecialPowerOnly ) },
{ nullptr, nullptr, nullptr, 0 }
};
p.add(dataFieldParse);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
SpecialPowerModule::SpecialPowerModule( Thing *thing, const ModuleData *moduleData )
: BehaviorModule( thing, moduleData )
{
#if RETAIL_COMPATIBLE_CRC
m_availableOnFrame = 0;
#else
m_availableOnFrame = 0;
#endif
m_pausedCount = 0;
m_pausedOnFrame = 0;
m_pausedPercent = 0.0f;
// we won't be able to use the power for X number of frames now
// if we're pre-built, start counting down
if( !getObject()->getStatusBits().test( OBJECT_STATUS_UNDER_CONSTRUCTION ) )
{
//A sharedNSync special only startPowerRecharges when first scienced or when executed,
//Since a new module with same SPTemplates may construct at any time.
if ( getSpecialPowerTemplate() != nullptr && getSpecialPowerTemplate()->isSharedNSync() == FALSE )
startPowerRecharge();
}
// WE USED TO DO THE POLL-EVERYBODY-AND-VOTE-ON-WHO-TO-SYNC-TO THING HERE,
// BUT NO MORE, NOW IT IS HANDLED IN PLAYER
// Some Special powers need to be activated by an Upgrade, so prevent the timer from going until then
const SpecialPowerModuleData *md = (const SpecialPowerModuleData *)moduleData;
if( md->m_startsPaused )
pauseCountdown( TRUE );
resolveSpecialPower();
// Now, if we find that we have just come into being,
// but there is already a science granted for our shared superweapon,
// lets make sure TheIngameUI knows about our public timer
// add this weapon to the UI if it has a public timer for all to see
if( m_pausedCount == 0 &&
getSpecialPowerTemplate() != nullptr &&
getSpecialPowerTemplate()->isSharedNSync() == TRUE &&
getSpecialPowerTemplate()->hasPublicTimer() == TRUE &&
getObject()->getControllingPlayer() &&
getObject()->isKindOf( KINDOF_STRUCTURE ) )
{
TheInGameUI->addSuperweapon( getObject()->getControllingPlayer()->getPlayerIndex(),
getPowerName(),
getObject()->getID(),
getSpecialPowerModuleData()->m_specialPowerTemplate );
}
}
//-------------------------------------------------------------------------------------------------
const AudioEventRTS& SpecialPowerModule::getInitiateSound() const
{
return getSpecialPowerModuleData()->m_initiateSound;
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
SpecialPowerModule::~SpecialPowerModule()
{
if( getSpecialPowerModuleData()->m_specialPowerTemplate->hasPublicTimer() == TRUE &&
getObject()->getControllingPlayer() )
TheInGameUI->removeSuperweapon( getObject()->getControllingPlayer()->getPlayerIndex(),
getPowerName(),
getObject()->getID(),
getSpecialPowerModuleData()->m_specialPowerTemplate );
}
//-------------------------------------------------------------------------------------------------
void SpecialPowerModule::setReadyFrame( UnsignedInt frame )
{
m_availableOnFrame = frame;
//If a script should change the ready frame, we need to update the paused frame. This value isn't
//used directly to determine if paused or not... it uses m_pausedCount.
m_pausedOnFrame = TheGameLogic->getFrame();
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
void SpecialPowerModule::resolveSpecialPower( void )
{
/*
// if we're pre-built, and not from a command center, and a building register us with the UI
if( getSpecialPowerModuleData()->m_specialPowerTemplate->hasPublicTimer() == TRUE &&
TheGameLogic->getFrame() == 0 && getObject()->getControllingPlayer() &&
getObject()->isKindOf( KINDOF_COMMANDCENTER ) == FALSE &&
getObject()->isKindOf( KINDOF_STRUCTURE ) )
{
//KM: The KINDOF_STRUCTURE check was made to prevent scripted bombers from registering their
// special powers as public timers.
TheInGameUI->addSuperweapon( getObject()->getControllingPlayer()->getPlayerIndex(),
getPowerName(),
getObject()->getID(),
getSpecialPowerModuleData()->m_specialPowerTemplate );
}
*/
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
void SpecialPowerModule::onSpecialPowerCreation( void )
{
// THIS gets called by addScience(), that is, when the General has purchased a new special power,
// and this module is thus activated.
// start a power recharge going
startPowerRecharge();
// Dustin wants these special powers to start ready to fire,
// so here (and only here) we will expressly set them to ready-now.
if ( getSpecialPowerTemplate()->isSharedNSync())
{
Player *player = getObject()->getControllingPlayer();
if ( player )
{
player->expressSpecialPowerReadyFrame( getSpecialPowerTemplate(), TheGameLogic->getFrame() );
m_availableOnFrame = player->getOrStartSpecialPowerReadyFrame( getSpecialPowerTemplate() );
}
}
// Some Special powers need to be activated by an Upgrade, so prevent the timer from going until then
const SpecialPowerModuleData *md = getSpecialPowerModuleData();
if( md->m_startsPaused )
pauseCountdown( TRUE );
// add this weapon to the UI if it has a public timer for all to see
if( getSpecialPowerModuleData()->m_specialPowerTemplate->hasPublicTimer() == TRUE &&
getObject()->getControllingPlayer() &&
getObject()->isKindOf( KINDOF_STRUCTURE ) )
{
TheInGameUI->addSuperweapon( getObject()->getControllingPlayer()->getPlayerIndex(),
getPowerName(),
getObject()->getID(),
getSpecialPowerModuleData()->m_specialPowerTemplate );
}
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
ScienceType SpecialPowerModule::getRequiredScience( void ) const
{
return getSpecialPowerModuleData()->m_specialPowerTemplate->getRequiredScience();
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
const SpecialPowerTemplate * SpecialPowerModule::getSpecialPowerTemplate( void ) const
{
return getSpecialPowerModuleData()->m_specialPowerTemplate;
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
AsciiString SpecialPowerModule::getPowerName( void ) const
{
return getSpecialPowerModuleData()->m_specialPowerTemplate->getName();
}
//-------------------------------------------------------------------------------------------------
/** Is this module designed for the power identier template passed in? */
//-------------------------------------------------------------------------------------------------
Bool SpecialPowerModule::isModuleForPower( const SpecialPowerTemplate *specialPowerTemplate ) const
{
// get the module data
const SpecialPowerModuleData *modData = getSpecialPowerModuleData();
//
// if the special power template defined in the module data matches the template we want
// to check then we are for it!
//
if( modData->m_specialPowerTemplate == specialPowerTemplate )
{
//We match templates.
return TRUE;
}
//We don't match templates.
return FALSE;
}
//-------------------------------------------------------------------------------------------------
/** Is this special power ready to use */
//-------------------------------------------------------------------------------------------------
Bool SpecialPowerModule::isReady() const
{
#if defined(RTS_DEBUG) || defined(_ALLOW_DEBUG_CHEATS_IN_RELEASE)
// this is a cheat ... remove this for release!
if( TheGlobalData->m_specialPowerUsesDelay == FALSE )
return TRUE;
#endif
const Object* obj = getObject();
const SpecialPowerModuleData *modData = getSpecialPowerModuleData();
if ( obj && modData )
{
Player *player = getObject()->getControllingPlayer();
if ( player )
{
if ( modData->m_specialPowerTemplate->isSharedNSync())
return (TheGameLogic->getFrame() >= player->getOrStartSpecialPowerReadyFrame( modData->m_specialPowerTemplate ) );
}
}
return (m_pausedCount == 0) && (TheGameLogic->getFrame() >= m_availableOnFrame);
}
//-------------------------------------------------------------------------------------------------
/** Get the percentage ready a special power is to use
* 1.0f = ready now
* 0.5f = 50% ready
* 0.2f = 20% ready
* etc ... */
//-------------------------------------------------------------------------------------------------
Real SpecialPowerModule::getPercentReady() const
{
if( m_pausedCount > 0 && m_pausedPercent == 1.0f )
{
//Don't consider it ready if paused.
return 0.99999f;
}
#if defined(RTS_DEBUG) || defined(_ALLOW_DEBUG_CHEATS_IN_RELEASE)
if( TheGlobalData->m_specialPowerUsesDelay == FALSE )
return 1.0f;
#endif
// easy case ... is ready
if( isReady() )
return 1.0f;
if( m_pausedCount > 0 )
{
return m_pausedPercent;
}
// get the module data
const SpecialPowerModuleData *modData = getSpecialPowerModuleData();
// sanity
if( modData->m_specialPowerTemplate == nullptr )
return 0.0f;
UnsignedInt readyFrame = m_availableOnFrame;
//unless
const Object* obj = getObject();
if ( obj )
{
Player *player = getObject()->getControllingPlayer();
if ( player )
{
if ( modData->m_specialPowerTemplate->isSharedNSync())
{
readyFrame = player->getOrStartSpecialPowerReadyFrame( getSpecialPowerTemplate() );
}
}
}
// calculate the percent
Real percent = 1.0f - ((readyFrame - TheGameLogic->getFrame()) /
(Real)modData->m_specialPowerTemplate->getReloadTime());
return percent;
}
//-------------------------------------------------------------------------------------------------
// A special power module that is only supposed to be fired via scripts. An example of this
// are the various cargo plane units we have. Scripters can launch specials from them after
// specifying a waypoint path for them to follow them.
//-------------------------------------------------------------------------------------------------
Bool SpecialPowerModule::isScriptOnly() const
{
const SpecialPowerModuleData *modData = getSpecialPowerModuleData();
return modData->m_scriptedSpecialPowerOnly;
}
//-------------------------------------------------------------------------------------------------
/** A special power has been used ... start the recharge process by computing the frame
* we will become fully available on in the future again */
//-------------------------------------------------------------------------------------------------
void SpecialPowerModule::startPowerRecharge()
{
#if defined(RTS_DEBUG) || defined(_ALLOW_DEBUG_CHEATS_IN_RELEASE)
// this is a cheat ... remove this for release!
if( TheGlobalData->m_specialPowerUsesDelay == FALSE )
return;
#endif
const SpecialPowerModuleData *modData = getSpecialPowerModuleData();
// sanity
if( modData->m_specialPowerTemplate == nullptr )
{
DEBUG_CRASH(("special power not found"));
return;
}
Object* obj = getObject();
if (!obj)
return;
Player* player = getObject()->getControllingPlayer();
if (!player)
return;
//Here, we make sure that general specials work as one between command centers
// only factory type faction buildings should do this, and only with generals powers (in general)
// but there are no restrictions on the use of SharedNSync on specialPowerTemplates at large
if ( modData->m_specialPowerTemplate->isSharedNSync() )
{
player->resetOrStartSpecialPowerReadyFrame( modData->m_specialPowerTemplate );
}
else
{
// set the frame we will be 100% available on now
m_availableOnFrame = TheGameLogic->getFrame() + getSpecialPowerTemplate()->getReloadTime();
}
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
Bool SpecialPowerModule::initiateIntentToDoSpecialPower( const Object *targetObj, const Coord3D *targetPos, const Waypoint *way, UnsignedInt commandOptions )
{
Bool valid = false;
// tell our update modules that we intend to do this special power.
for( BehaviorModule** u = getObject()->getBehaviorModules(); *u; ++u )
{
SpecialPowerUpdateInterface* spu = (*u)->getSpecialPowerUpdateInterface();
if( spu )
{
//Validate that we are calling the correct module!
if( isModuleForPower( getSpecialPowerModuleData()->m_specialPowerTemplate ) )
{
if( spu->doesSpecialPowerUpdatePassScienceTest() )
{
if( spu->initiateIntentToDoSpecialPower( getSpecialPowerModuleData()->m_specialPowerTemplate, targetObj, targetPos, way, commandOptions ) )
{
//Kris: Aug 2003
//We have executed the special power, so don't try to execute any more. This logic
//was changed for multi-level spectres. Before, multiple modules would get launched
//causing 2 or 3 spectres to be created.
valid = true;
break;
}
}
}
}
}
#if RETAIL_COMPATIBLE_CRC
// TheSuperHackers @info we need to leave early if we are in the MissileLauncherBuildingUpdate crash fix codepath
if (m_availableOnFrame == 0xFFFFFFFF)
{
DEBUG_ASSERTCRASH(!valid, ("Using MissileLauncherBuildingUpdate escape path when valid is set to true"));
return false;
}
#endif
getObject()->getControllingPlayer()->getAcademyStats()->recordSpecialPowerUsed( getSpecialPowerModuleData()->m_specialPowerTemplate );
//If we depend on our update module to trigger the special power, make sure we have the
//appropriate update module!
if( !valid && getSpecialPowerModuleData()->m_updateModuleStartsAttack )
{
DEBUG_CRASH( ("Object does not contain a special power module to execute. Did you forget to add it to the object INI?"));
//DEBUG_CRASH(( "Object does not contain special power module (%s) to execute. Did you forget to add it to the object INI?",
// command->m_specialPower->getName().str() ));
}
return valid;
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
void SpecialPowerModule::triggerSpecialPower( const Coord3D *location )
{
aboutToDoSpecialPower( location ); // do BEFORE recharge
createViewObject(location);
// we won't be able to use the power for X number of frames now
startPowerRecharge();
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
void SpecialPowerModule::createViewObject( const Coord3D *location )
{
const SpecialPowerModuleData *modData = getSpecialPowerModuleData();
const SpecialPowerTemplate *powerTemplate = modData->m_specialPowerTemplate;
if( modData == nullptr || powerTemplate == nullptr )
return;
Real visionRange = powerTemplate->getViewObjectRange();
UnsignedInt visionDuration = powerTemplate->getViewObjectDuration();
if( visionRange == 0 || visionDuration == 0 )
return; // We don't want a view object at all.
AsciiString objectName = TheGlobalData->m_specialPowerViewObjectName;
if( objectName.isEmpty() )
return;
const ThingTemplate *viewObjectTemplate = TheThingFactory->findTemplate( objectName );
if( viewObjectTemplate == nullptr )
return;
Object *viewObject = TheThingFactory->newObject( viewObjectTemplate, getObject()->getControllingPlayer()->getDefaultTeam() );
if( viewObject == nullptr )
return;
viewObject->setPosition( location );
viewObject->setShroudClearingRange( visionRange );
static NameKeyType key_DeletionUpdate = NAMEKEY("DeletionUpdate");
DeletionUpdate* dup = (DeletionUpdate*)viewObject->findUpdateModule(key_DeletionUpdate);
if( dup )
{
dup->setLifetimeRange( visionDuration, visionDuration );
}
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
void SpecialPowerModule::markSpecialPowerTriggered( const Coord3D *location )
{
triggerSpecialPower( location );
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
void SpecialPowerModule::aboutToDoSpecialPower( const Coord3D *location )
{
// Tell the scripting engine!
TheScriptEngine->notifyOfTriggeredSpecialPower(
getObject()->getControllingPlayer()->getPlayerIndex(),
getSpecialPowerModuleData()->m_specialPowerTemplate->getName(),
getObject()->getID());
// Let EVA do her thing
SpecialPowerType type = getSpecialPowerModuleData()->m_specialPowerTemplate->getSpecialPowerType();
Player *localPlayer = rts::getObservedOrLocalPlayer();
Relationship relationship = localPlayer->getRelationship(getObject()->getTeam());
// Only play the EVA sounds if this is not the local player, and the local player doesn't consider the
// person an enemy.
// Kris: Actually, all players need to hear these warnings.
// Ian: But now there are different Eva messages depending on who launched
//if (localPlayer != getObject()->getControllingPlayer() && localPlayer->getRelationship(getObject()->getTeam()) != ENEMIES)
{
if( type == SPECIAL_PARTICLE_UPLINK_CANNON || type == SUPW_SPECIAL_PARTICLE_UPLINK_CANNON || type == LAZR_SPECIAL_PARTICLE_UPLINK_CANNON )
{
if ( localPlayer == getObject()->getControllingPlayer() )
{
TheEva->setShouldPlay(EVA_SuperweaponLaunched_Own_ParticleCannon);
}
else if (relationship != ENEMIES)
{
// Note: counting relationship NEUTRAL as ally. Not sure if this makes a difference???
TheEva->setShouldPlay(EVA_SuperweaponLaunched_Ally_ParticleCannon);
}
else
{
TheEva->setShouldPlay(EVA_SuperweaponLaunched_Enemy_ParticleCannon);
}
}
else if( type == SPECIAL_NEUTRON_MISSILE || type == NUKE_SPECIAL_NEUTRON_MISSILE || type == SUPW_SPECIAL_NEUTRON_MISSILE )
{
if ( localPlayer == getObject()->getControllingPlayer() )
{
TheEva->setShouldPlay(EVA_SuperweaponLaunched_Own_Nuke);
}
else if (relationship != ENEMIES)
{
// Note: counting relationship NEUTRAL as ally. Not sure if this makes a difference???
TheEva->setShouldPlay(EVA_SuperweaponLaunched_Ally_Nuke);
}
else
{
TheEva->setShouldPlay(EVA_SuperweaponLaunched_Enemy_Nuke);
}
}
else if (type == SPECIAL_SCUD_STORM)
{
if ( localPlayer == getObject()->getControllingPlayer() )
{
TheEva->setShouldPlay(EVA_SuperweaponLaunched_Own_ScudStorm);
}
else if (relationship != ENEMIES)
{
// Note: counting relationship NEUTRAL as ally. Not sure if this makes a difference???
TheEva->setShouldPlay(EVA_SuperweaponLaunched_Ally_ScudStorm);
}
else
{
TheEva->setShouldPlay(EVA_SuperweaponLaunched_Enemy_ScudStorm);
}
}
else if (type == SPECIAL_GPS_SCRAMBLER || type == SLTH_SPECIAL_GPS_SCRAMBLER )
{
// This is Ghetto. Voices should be ini lines in the special power entry. You shouldn't have to
// add to an enum to get a new voice
if ( localPlayer == getObject()->getControllingPlayer() )
{
TheEva->setShouldPlay(EVA_SuperweaponLaunched_Own_GPS_Scrambler);
}
else if (relationship != ENEMIES)
{
// Note: counting relationship NEUTRAL as ally. Not sure if this makes a difference???
TheEva->setShouldPlay(EVA_SuperweaponLaunched_Ally_GPS_Scrambler);
}
else
{
TheEva->setShouldPlay(EVA_SuperweaponLaunched_Enemy_GPS_Scrambler);
}
}
else if (type == SPECIAL_SNEAK_ATTACK)
{
if ( localPlayer == getObject()->getControllingPlayer() )
{
TheEva->setShouldPlay(EVA_SuperweaponLaunched_Own_Sneak_Attack);
}
else if (relationship != ENEMIES)
{
// Note: counting relationship NEUTRAL as ally. Not sure if this makes a difference???
TheEva->setShouldPlay(EVA_SuperweaponLaunched_Ally_Sneak_Attack);
}
else
{
TheEva->setShouldPlay(EVA_SuperweaponLaunched_Enemy_Sneak_Attack);
}
}
}
// Notify the UI that this special power was activated (for observer notifications)
const Object* obj = getObject();
const SpecialPowerTemplate* tpl = getSpecialPowerTemplate();
if (obj && tpl && TheInGameUI) {
if (Player* p = obj->getControllingPlayer())
TheInGameUI->notifySpecialPowerUsed(p, tpl);
}
// get module data
const SpecialPowerModuleData *modData = getSpecialPowerModuleData();
// play our initiate sound if we have one
AudioEventRTS audioEvent = *modData->m_specialPowerTemplate->getInitiateSound();
audioEvent.setObjectID(getObject()->getID());
TheAudio->addAudioEvent( &audioEvent );
// play sound at target location if specified
if( location )
{
AudioEventRTS soundAtLocation = *modData->m_specialPowerTemplate->getInitiateAtTargetSound();
soundAtLocation.setPosition( location );
soundAtLocation.setPlayerIndex(getObject()->getControllingPlayer()->getPlayerIndex());
TheAudio->addAudioEvent( &soundAtLocation );
}
}
//-------------------------------------------------------------------------------------------------
//By default, special powers are not triggered by it's update module -- in which case
//it triggers it and resets its timer immediately. When the update module triggers it,
//then all we do is initiate the special power, and trust that the update module will
//do the rest.
//-------------------------------------------------------------------------------------------------
void SpecialPowerModule::doSpecialPower( UnsignedInt commandOptions )
{
if (m_pausedCount > 0 || getObject()->isDisabled()) {
return;
}
//This tells the update module that we want to do our special power. The update modules
//will then start processing each frame.
initiateIntentToDoSpecialPower( nullptr, nullptr, nullptr, commandOptions );
//Only trigger the special power immediately if the updatemodule doesn't start the attack.
//An example of a case that wouldn't trigger immediately is for a unit that needs to
//close to range before firing the special attack. A case that would trigger immediately
//is the napalm strike. If we don't call this now, it's up to the update module to do so.
if( !getSpecialPowerModuleData()->m_updateModuleStartsAttack )
{
triggerSpecialPower( nullptr );// Location-less trigger
}
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
void SpecialPowerModule::doSpecialPowerAtObject( Object *obj, UnsignedInt commandOptions )
{
if (m_pausedCount > 0 || getObject()->isDisabled()) {
return;
}
//This tells the update module that we want to do our special power. The update modules
//will then start processing each frame.
initiateIntentToDoSpecialPower( obj, nullptr, nullptr, commandOptions );
//Only trigger the special power immediately if the updatemodule doesn't start the attack.
//An example of a case that wouldn't trigger immediately is for a unit that needs to
//close to range before firing the special attack. A case that would trigger immediately
//is the napalm strike. If we don't call this now, it's up to the update module to do so.
if( !getSpecialPowerModuleData()->m_updateModuleStartsAttack )
{
triggerSpecialPower( obj->getPosition() );
}
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
void SpecialPowerModule::doSpecialPowerAtLocation( const Coord3D *loc, Real angle, UnsignedInt commandOptions )
{
if (m_pausedCount > 0 || getObject()->isDisabled()) {
return;
}
//This tells the update module that we want to do our special power. The update modules
//will then start processing each frame.
initiateIntentToDoSpecialPower( nullptr, loc, nullptr, commandOptions );
#if RETAIL_COMPATIBLE_CRC
// TheSuperHackers @info we need to leave early if we are in the MissileLauncherBuildingUpdate crash fix codepath
if (m_availableOnFrame == 0xFFFFFFFF)
return;
#endif
//Only trigger the special power immediately if the updatemodule doesn't start the attack.
//An example of a case that wouldn't trigger immediately is for a unit that needs to
//close to range before firing the special attack. A case that would trigger immediately
//is the napalm strike. If we don't call this now, it's up to the update module to do so.
if( !getSpecialPowerModuleData()->m_updateModuleStartsAttack )
{
triggerSpecialPower( loc );
}
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
void SpecialPowerModule::doSpecialPowerUsingWaypoints( const Waypoint *way, UnsignedInt commandOptions )
{
if (m_pausedCount > 0 || getObject()->isDisabled()) {
return;
}
//This tells the update module that we want to do our special power. The update modules
//will then start processing each frame.
initiateIntentToDoSpecialPower( nullptr, nullptr, way, commandOptions );
//Only trigger the special power immediately if the updatemodule doesn't start the attack.
//An example of a case that wouldn't trigger immediately is for a unit that needs to
//close to range before firing the special attack. A case that would trigger immediately
//is the napalm strike. If we don't call this now, it's up to the update module to do so.
if( !getSpecialPowerModuleData()->m_updateModuleStartsAttack )
{
triggerSpecialPower( nullptr );// This type doesn't create view objects
}
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
void SpecialPowerModule::pauseCountdown( Bool pause )
{
if (pause)// If pausing
{
if( m_pausedCount == 0 )
{
// Only record this with the first pausing, otherwise upon final unpausing you would get credited the time
// between pauses as time served.
m_pausedOnFrame = TheGameLogic->getFrame();
m_pausedPercent = getPercentReady();
}
++m_pausedCount;
}
else if( m_pausedCount > 0 )//Else if unpausing, but only if I am in fact paused, so multiple unpauses don't break.
{
--m_pausedCount;
// And only update the ready time if we are fully unpaused now.
if( m_pausedCount == 0 )
{
m_availableOnFrame += (TheGameLogic->getFrame() - m_pausedOnFrame);
}
}
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
UnsignedInt SpecialPowerModule::getReadyFrame( void ) const
{
if ( getSpecialPowerTemplate()->isSharedNSync() )
{
const Object* obj = getObject();
if ( obj )
{
Player *player = getObject()->getControllingPlayer();
if ( player )
return player->getOrStartSpecialPowerReadyFrame( getSpecialPowerTemplate() );
}
}
if (m_pausedCount > 0 || getObject()->isDisabled())
{
Int pausedFrames = TheGameLogic->getFrame() - m_pausedOnFrame;
return m_availableOnFrame + pausedFrames;
}
else
{
return m_availableOnFrame;
}
}
// ------------------------------------------------------------------------------------------------
/** CRC */
// ------------------------------------------------------------------------------------------------
void SpecialPowerModule::crc( Xfer *xfer )
{
// extend base class
BehaviorModule::crc( xfer );
}
// ------------------------------------------------------------------------------------------------
/** Xfer method
* Version Info:
* 1: Initial version */
// ------------------------------------------------------------------------------------------------
void SpecialPowerModule::xfer( Xfer *xfer )
{
// version
XferVersion currentVersion = 1;
XferVersion version = currentVersion;
xfer->xferVersion( &version, currentVersion );
// extend base class
BehaviorModule::xfer( xfer );
// available on frame
xfer->xferUnsignedInt( &m_availableOnFrame );
// paused by script
xfer->xferInt( &m_pausedCount );
// paused on frame
xfer->xferUnsignedInt( &m_pausedOnFrame );
// paused percent
xfer->xferReal( &m_pausedPercent );
}
// ------------------------------------------------------------------------------------------------
/** Load post process */
// ------------------------------------------------------------------------------------------------
void SpecialPowerModule::loadPostProcess( void )
{
// extend base class
BehaviorModule::loadPostProcess();
// Now, if we find that we have just come into being,
// but there is already a science granted for our shared superweapon,
// lets make sure TheIngameUI knows about our public timer
// add this weapon to the UI if it has a public timer for all to see
if( m_pausedCount == 0 &&
getSpecialPowerTemplate()->isSharedNSync() == TRUE &&
getSpecialPowerTemplate()->hasPublicTimer() == TRUE &&
getObject()->getControllingPlayer() &&
getObject()->isKindOf( KINDOF_STRUCTURE ) )
{
TheInGameUI->addSuperweapon( getObject()->getControllingPlayer()->getPlayerIndex(),
getPowerName(),
getObject()->getID(),
getSpecialPowerModuleData()->m_specialPowerTemplate );
}
}