forked from electronicarts/CnC_Generals_Zero_Hour
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommandXlat.cpp
More file actions
5583 lines (4828 loc) · 187 KB
/
CommandXlat.cpp
File metadata and controls
5583 lines (4828 loc) · 187 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. //
// //
////////////////////////////////////////////////////////////////////////////////
// CommandXlat.cpp
// Translate raw input events into tactical commands
// Author: Michael S. Booth, February 2001
#include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
#include "stdlib.h" // VC++ wants this here, or gives compile error...
#include "Common/AudioAffect.h"
#include "Common/ActionManager.h"
#include "Common/FrameRateLimit.h"
#include "Common/GameAudio.h"
#include "Common/GameEngine.h"
#include "Common/GameType.h"
#include "Common/GlobalData.h"
#include "Common/MessageStream.h"
#include "Common/MiscAudio.h"
#include "Common/MultiplayerSettings.h"
#include "Common/PerfTimer.h"
#include "Common/Player.h"
#include "Common/PlayerList.h"
#include "Common/PlayerTemplate.h"
#include "Common/Radar.h"
#include "Common/Recorder.h"
#include "Common/SpecialPower.h"
#include "Common/StatsCollector.h"
#include "Common/ThingTemplate.h"
#include "Common/GameLOD.h"
#include "GameClient/InGameUI.h"
#include "GameClient/CommandXlat.h"
#include "GameClient/DebugDisplay.h"
#include "GameClient/Drawable.h"
#include "GameClient/GameClient.h"
#include "GameClient/GameWindowManager.h"
#include "GameClient/GameText.h"
#include "GameClient/ParticleSys.h"
#include "GameClient/GUICallbacks.h"
#include "GameClient/Shell.h"
#include "GameClient/ControlBar.h"
#include "GameClient/SelectionInfo.h"
#include "GameClient/SelectionXlat.h"
#include "GameLogic/Module/AIUpdate.h"
#include "GameLogic/ExperienceTracker.h"
#include "GameLogic/GameLogic.h"
#include "GameLogic/Module/BodyModule.h"
#include "GameLogic/Module/ProductionUpdate.h"
#include "GameLogic/Object.h"
#include "GameLogic/PartitionManager.h"
#include "GameLogic/ScriptEngine.h"
#include "GameLogic/TerrainLogic.h"
#include "GameLogic/GhostObject.h"
#include "GameLogic/Weapon.h"
#include "GameLogic/Module/SpawnBehavior.h"
#include "GameLogic/Module/SpecialPowerModule.h"
#include "Common/ThingFactory.h"
#include "GameLogic/Module/ContainModule.h"
#include "GameNetwork/NetworkInterface.h"
#include "GameNetwork/GameInfo.h"
#include "GameNetwork/GameSpyOverlay.h"
#include "GameNetwork/GameSpy/BuddyThread.h"
#define dont_ALLOW_ALT_F4
#if defined(RTS_DEBUG)
/*non-static*/ Real TheSkateDistOverride = 0.0f;
void countObjects(Object *obj, void *userData)
{
Int *numObjects = (Int *)userData;
if (!numObjects || !obj)
return;
DEBUG_LOG(("Looking at obj %d (%s) - isEffectivelyDead()==%d, isDestroyed==%d, numObjects==%d",
obj->getID(), obj->getTemplate()->getName().str(), obj->isEffectivelyDead(), obj->isDestroyed(), *numObjects));
if (!obj->isEffectivelyDead() && !obj->isDestroyed() && !obj->isKindOf(KINDOF_INERT))
++(*numObjects);
}
void printObjects(Object *obj, void *userData)
{
if (!obj)
return;
Bool isDead = obj->isEffectivelyDead() || obj->isDestroyed();
Bool isInert = obj->isKindOf(KINDOF_INERT);
AsciiString statusStr = (isDead)?"Dead":(isInert)?"Inert":"Living";
AsciiString line;
if (obj->getName().isEmpty())
line.format(" Obj#%d %s - (%g,%g) %s", obj->getID(), obj->getTemplate()->getName().str(),
obj->getPosition()->x, obj->getPosition()->y, statusStr.str());
else
line.format(" Obj#%d %s (%s) - (%g,%g) %s", obj->getID(), obj->getTemplate()->getName().str(),
obj->getName().str(), obj->getPosition()->x, obj->getPosition()->y, statusStr.str());
TheScriptEngine->AppendDebugMessage(line, FALSE);
}
#endif // defined(RTS_DEBUG)
#if defined(RTS_DEBUG) || defined(_ALLOW_DEBUG_CHEATS_IN_RELEASE)
void giveAllSciences(Player* player)
{
// cheese festival: do NOT imitate this code. it is for debug purposes only.
std::vector<AsciiString> v = TheScienceStore->friend_getScienceNames();
for (size_t i = 0; i < v.size(); ++i)
{
ScienceType st = TheScienceStore->getScienceFromInternalName(v[i]);
if (st != SCIENCE_INVALID && TheScienceStore->isScienceGrantable(st))
{
player->grantScience(st);
}
}
}
void objectUnderConstruction(Object* obj, void *underConstruction)
{
if (obj->testStatus(OBJECT_STATUS_UNDER_CONSTRUCTION))
{
*(Bool*)underConstruction = true;
return;
}
ProductionUpdateInterface *pui = ProductionUpdate::getProductionUpdateInterfaceFromObject(obj);
if(pui != NULL && pui->getProductionCount() > 0)
{
*(Bool*)underConstruction = true;
return;
}
}
Bool hasThingsInProduction(Player* player)
{
Bool hasThingInProduction = false;
player->iterateObjects( objectUnderConstruction, &hasThingInProduction );
return hasThingInProduction;
}
Bool hasThingsInProduction(PlayerType playerType)
{
for (Int n = 0; n < ThePlayerList->getPlayerCount(); ++n)
{
Player* player = ThePlayerList->getNthPlayer(n);
if (player->getPlayerType() == playerType)
{
if (hasThingsInProduction(player))
return true;
}
}
return false;
}
#endif // defined(RTS_DEBUG) || defined(_ALLOW_DEBUG_CHEATS_IN_RELEASE)
bool changeMaxRenderFps(FpsValueChange change)
{
UnsignedInt maxRenderFps = TheGameEngine->getFramesPerSecondLimit();
maxRenderFps = RenderFpsPreset::changeFpsValue(maxRenderFps, change);
TheGameEngine->setFramesPerSecondLimit(maxRenderFps);
TheWritableGlobalData->m_useFpsLimit = (maxRenderFps != RenderFpsPreset::UncappedFpsValue);
UnicodeString message;
if (TheWritableGlobalData->m_useFpsLimit)
{
message = TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:SetMaxRenderFps", L"Max Render FPS is %u", maxRenderFps);
}
else
{
message = TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:SetUncappedRenderFps", L"Max Render FPS is uncapped");
}
TheInGameUI->messageNoFormat(message);
return true;
}
bool changeLogicTimeScale(FpsValueChange change)
{
if (TheNetwork != NULL)
return false;
const UnsignedInt maxRenderFps = TheGameEngine->getFramesPerSecondLimit();
UnsignedInt maxRenderRemainder = LogicTimeScaleFpsPreset::StepFpsValue;
maxRenderRemainder -= maxRenderFps % LogicTimeScaleFpsPreset::StepFpsValue;
maxRenderRemainder %= LogicTimeScaleFpsPreset::StepFpsValue;
UnsignedInt logicTimeScaleFps = TheGameEngine->getLogicTimeScaleFps();
// Set the value to the max render fps value plus a bit when time scale is
// disabled. This ensures that the time scale does not re-enable with a
// 'surprise' value.
if (!TheGameEngine->isLogicTimeScaleEnabled())
{
logicTimeScaleFps = maxRenderFps + maxRenderRemainder;
}
// Ceil the value at the max render fps value plus a bit so that the next fps
// value decrease would undercut the max render fps at the correct step value.
// Example: render fps 72 -> logic value ceiled to 75 -> decreased to 70.
logicTimeScaleFps = min(logicTimeScaleFps, maxRenderFps + maxRenderRemainder);
logicTimeScaleFps = LogicTimeScaleFpsPreset::changeFpsValue(logicTimeScaleFps, change);
// Set value before potentially disabling it.
if (TheGameEngine->isLogicTimeScaleEnabled())
{
TheGameEngine->setLogicTimeScaleFps(logicTimeScaleFps);
}
TheGameEngine->enableLogicTimeScale(logicTimeScaleFps < maxRenderFps);
// Set value after potentially enabling it.
if (TheGameEngine->isLogicTimeScaleEnabled())
{
TheGameEngine->setLogicTimeScaleFps(logicTimeScaleFps);
}
logicTimeScaleFps = TheGameEngine->getLogicTimeScaleFps();
const UnsignedInt actualLogicTimeScaleFps = TheGameEngine->getActualLogicTimeScaleFps();
const Real actualLogicTimeScaleRatio = TheGameEngine->getActualLogicTimeScaleRatio();
UnicodeString message;
if (TheGameEngine->isLogicTimeScaleEnabled())
{
message = TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:SetLogicTimeScaleFps", L"Logic Time Scale FPS is %u (actual %u, ratio %.02f)",
logicTimeScaleFps, actualLogicTimeScaleFps, actualLogicTimeScaleRatio);
}
else
{
message = TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:SetUncappedLogicTimeScaleFps", L"Logic Time Scale FPS is uncapped (actual %u, ratio %.02f)",
actualLogicTimeScaleFps, actualLogicTimeScaleRatio);
}
TheInGameUI->messageNoFormat(message);
return true;
}
static Bool isSystemMessage( const GameMessage *msg );
enum{ DROPPED_MAX_PARTICLE_COUNT = 1000};
static Bool canSelectionSalvage( const Object *targetObj)
{
if (!targetObj) {
return FALSE;
}
if (!targetObj->isSalvageCrate()) {
return FALSE;
}
const DrawableList *drawList = TheInGameUI->getAllSelectedDrawables();
for (DrawableListCIt cit = drawList->begin(); cit != drawList->end(); ++cit)
{
Drawable *draw = *cit;
if (!draw)
{
continue;
}
Object *obj = draw->getObject();
if (!obj)
{
continue;
}
if (obj->isKindOf(KINDOF_SALVAGER)) {
return TRUE;
}
}
return FALSE;
}
//-------------------------------------------------------------------------------------------------
static CanAttackResult canObjectForceAttack( Object *obj, const Object *victim, const Coord3D *pos )
{
CanAttackResult result;
result = obj->isAbleToAttack() ? ATTACKRESULT_POSSIBLE : ATTACKRESULT_NOT_POSSIBLE;
if( result == ATTACKRESULT_NOT_POSSIBLE )
{
return ATTACKRESULT_NOT_POSSIBLE;
}
if (victim)
{
result = obj->getAbleToAttackSpecificObject(ATTACK_NEW_TARGET_FORCED, victim, CMD_FROM_PLAYER );
//Special case -- objects with spawn weapons have to do different checks. Stinger site with stinger soldiers is
//the catalyst example.
if ( obj->isKindOf( KINDOF_SPAWNS_ARE_THE_WEAPONS ) )
{
if( result != ATTACKRESULT_POSSIBLE && result != ATTACKRESULT_POSSIBLE_AFTER_MOVING )
{
SpawnBehaviorInterface *spawnInterface = obj->getSpawnBehaviorInterface();
if( spawnInterface )
{
//We found the spawn interface, now get the closest slave to the target.
Object *slave = spawnInterface->getClosestSlave( victim->getPosition() );
if( slave )
{
result = slave->getAbleToAttackSpecificObject( ATTACK_NEW_TARGET_FORCED, victim, CMD_FROM_PLAYER );
}
}
}
else // oh dear me. The wierd case of a garrisoncontainer being a KINDOF_SPAWNS_ARE_THE_WEAPONS... the AmericaBuildingFirebase
{
ContainModuleInterface *contain = obj->getContain();
if ( contain )
{
Object *rider = contain->getClosestRider( victim->getPosition() );
if ( rider )
{
result = rider->getAbleToAttackSpecificObject( ATTACK_NEW_TARGET_FORCED, victim, CMD_FROM_PLAYER );
if( result != ATTACKRESULT_NOT_POSSIBLE )
return result;
}
}
}
}
return result;
}
else
{
//Almost every combat unit can force attack a position. The exceptions include stationary units
//that try to force attack in a location beyond their reach (range, LOS, etc).
if( pos )
{
Object *testObj = obj;
if( obj->isKindOf( KINDOF_IMMOBILE ) || obj->isKindOf( KINDOF_SPAWNS_ARE_THE_WEAPONS ) )
{
SpawnBehaviorInterface *spawnInterface = obj->getSpawnBehaviorInterface();
if( spawnInterface )
{
//We found the spawn interface, now get the closest slave to the target.
Object *slave = spawnInterface->getClosestSlave( pos );
if( slave )
{
testObj = slave;
}
}
else
{
result = obj->getAbleToUseWeaponAgainstTarget( ATTACK_NEW_TARGET, NULL, pos, CMD_FROM_PLAYER );
if( result != ATTACKRESULT_POSSIBLE ) // oh dear me. The wierd case of a garrisoncontainer being a KINDOF_SPAWNS_ARE_THE_WEAPONS... the AmericaBuildingFirebase
{
ContainModuleInterface *contain = obj->getContain();
if ( contain )
{
Object *rider = contain->getClosestRider( pos );
if ( rider )
testObj = rider;
}
}
}
}
//Now evaluate the testObj again to see if it is capable of force attacking the pos.
result = testObj->getAbleToUseWeaponAgainstTarget( ATTACK_NEW_TARGET, NULL, pos, CMD_FROM_PLAYER );
return result;
}
}
return ATTACKRESULT_NOT_POSSIBLE;
}
//-------------------------------------------------------------------------------------------------
static CanAttackResult canAnyForceAttack(const DrawableList *allSelected, const Object *victim, const Coord3D *pos )
{
// check to make sure that allSelected can attack obj.
for (DrawableListCIt cit = allSelected->begin(); cit != allSelected->end(); ++cit)
{
Drawable *draw = *cit;
if (!draw)
{
continue;
}
Object *obj = draw->getObject();
if (!obj)
{
continue;
}
return canObjectForceAttack( obj, victim, pos );
}
return ATTACKRESULT_NOT_POSSIBLE;
}
//-------------------------------------------------------------------------------------------------
void pickAndPlayUnitVoiceResponse( const DrawableList *list, GameMessage::Type msgType, PickAndPlayInfo *info )
{
if (!list)
{
return;
}
const AudioEventRTS* soundToPlayPtr = NULL;
Object *objectWithSound = NULL;
Bool skip = false;
Object *target = NULL;
if( info && info->m_drawTarget )
{
target = info->m_drawTarget->getObject();
}
//Now, loop through all the drawables (even if you find a match on the first.
//The innards are responsible for "upgrading" a sound that is played based on
//priorities. For example, the voice move or voice crush. Voice move gets set
//when we have a null event -- but if any of the units can crush the specified
//target, then it changes to VoiceCrush.
for( DrawableListCIt it = list->begin(); it != list->end(); ++it )
{
Object *obj = (*it)->getObject();
if (obj->isKindOf( KINDOF_IGNORED_IN_GUI ))
continue;
// Use the object instead of the drawable to get the thing template from. This way, we get the
// sounds even if the thing is disguised as something else. (Ala bomb truck.)
const ThingTemplate *templ = obj->getTemplate();
if (!templ)
{
return;
}
switch (msgType)
{
case GameMessage::MSG_DOCK:
soundToPlayPtr = templ->getPerUnitSound("VoiceSupply");
objectWithSound = obj;
skip = true;
break;
case GameMessage::MSG_SELECT_TEAM0:
case GameMessage::MSG_SELECT_TEAM1:
case GameMessage::MSG_SELECT_TEAM2:
case GameMessage::MSG_SELECT_TEAM3:
case GameMessage::MSG_SELECT_TEAM4:
case GameMessage::MSG_SELECT_TEAM5:
case GameMessage::MSG_SELECT_TEAM6:
case GameMessage::MSG_SELECT_TEAM7:
case GameMessage::MSG_SELECT_TEAM8:
case GameMessage::MSG_SELECT_TEAM9:
case GameMessage::MSG_CREATE_SELECTED_GROUP:
soundToPlayPtr = templ->getVoiceSelect();
objectWithSound = obj;
skip = true;
break;
case GameMessage::MSG_EVACUATE:
soundToPlayPtr = templ->getPerUnitSound( "VoiceUnload" );
objectWithSound = obj;
skip = true;
break;
case GameMessage::MSG_DO_REPAIR:
soundToPlayPtr = templ->getPerUnitSound( "VoiceRepair" );
objectWithSound = obj;
skip = true;
break;
#ifdef ALLOW_SURRENDER
case GameMessage::MSG_PICK_UP_PRISONER:
soundToPlayPtr = templ->getPerUnitSound( "VoicePickup" );
objectWithSound = obj;
skip = true;
break;
#endif
case GameMessage::MSG_COMBATDROP_AT_LOCATION:
case GameMessage::MSG_COMBATDROP_AT_OBJECT:
soundToPlayPtr = templ->getPerUnitSound( "VoiceCombatDrop" );
objectWithSound = obj;
skip = true;
break;
case GameMessage::MSG_ENTER:
if( target && target->isKindOf( KINDOF_HEAL_PAD ) )
{
soundToPlayPtr = templ->getPerUnitSound( "VoiceGetHealed" );
}
else if( target && target->isKindOf( KINDOF_STRUCTURE ) )
{
if( obj->getRelationship( target ) == ENEMIES )
{
//Saboteurs
soundToPlayPtr = templ->getPerUnitSound( "VoiceEnterHostile" );
}
else
{
soundToPlayPtr = templ->getPerUnitSound( "VoiceGarrison" );
}
}
// order matters: we want to know if I consider it to be an ally, not vice versa
else if( target && obj->getRelationship(target) != ALLIES )
{
soundToPlayPtr = templ->getPerUnitSound( "VoiceEnterHostile" );
}
else
{
soundToPlayPtr = templ->getPerUnitSound( "VoiceEnter" );
}
objectWithSound = obj;
skip = true;
break;
case GameMessage::MSG_DO_MOVETO:
case GameMessage::MSG_DO_ATTACKMOVETO:
case GameMessage::MSG_GET_REPAIRED:
case GameMessage::MSG_GET_HEALED:
case GameMessage::MSG_DO_SALVAGE:
{
AIUpdateInterface *ai = obj->getAI();
if( ai )
{
//This flag determines if the object has started moving yet... if not
//it's a good initial check.
Bool isEffectivelyMoving = ai->isMoving() || ai->isWaitingForPath();
if( TheInGameUI->isInWaypointMode() )
{
if( isEffectivelyMoving )
{
//Don't want to play the sound unless he's not moving!
continue;
}
}
//Default to voice move (it'll be selected if we can't find a crush case as we iterate
//through the rest of the drawables)
if( !soundToPlayPtr )
{
soundToPlayPtr = templ->getVoiceMove();
objectWithSound = obj;
}
if( TheInGameUI->isInForceMoveToMode() && target )
{
if( obj->canCrushOrSquish( target ) )
{
//Change it to voice crush because we are intentionally trying to crush this!
soundToPlayPtr = templ->getPerUnitSound( "VoiceCrush" );
objectWithSound = obj;
skip = true;
}
}
if (msgType == GameMessage::MSG_DO_SALVAGE)
{
const AudioEventRTS *tempSound = templ->getPerUnitSound( "VoiceSalvage" );
if (TheAudio->isValidAudioEvent(tempSound))
{
soundToPlayPtr = tempSound;
objectWithSound = obj;
skip = true;
}
}
// Special case for GLA worker to use a different set of move voices when he has received the worker shoes upgrade
Player *player = obj->getControllingPlayer();
static const UpgradeTemplate *workerShoeTemplate = TheUpgradeCenter->findUpgrade( "Upgrade_GLAWorkerShoes" );
if (player && player->hasUpgradeComplete(workerShoeTemplate))
{
if (obj->isKindOf(KINDOF_INFANTRY) && obj->isKindOf(KINDOF_DOZER) && obj->isKindOf(KINDOF_HARVESTER)) // Only Workers fit all 3
{
soundToPlayPtr = templ->getPerUnitSound( "VoiceMoveUpgraded" );
objectWithSound = obj;
skip = true;
}
}
}
break;
}
case GameMessage::MSG_RESUME_CONSTRUCTION:
case GameMessage::MSG_DOZER_CONSTRUCT:
case GameMessage::MSG_DOZER_CONSTRUCT_LINE:
{
soundToPlayPtr = templ->getPerUnitSound( "VoiceBuildResponse" );
objectWithSound = obj;
skip = true;
break;
}
case GameMessage::MSG_SWITCH_WEAPONS:
{
if( info && info->m_weaponSlot )
{
switch( *info->m_weaponSlot )
{
case PRIMARY_WEAPON:
soundToPlayPtr = templ->getPerUnitSound( "VoicePrimaryWeaponMode" );
break;
case SECONDARY_WEAPON:
soundToPlayPtr = templ->getPerUnitSound( "VoiceSecondaryWeaponMode" );
break;
case TERTIARY_WEAPON:
soundToPlayPtr = templ->getPerUnitSound( "VoiceTertiaryWeaponMode" );
break;
}
objectWithSound = obj;
skip = true;
}
break;
}
case GameMessage::MSG_DO_FORCE_ATTACK_GROUND:
{
soundToPlayPtr = templ->getPerUnitSound( "VoiceBombard" );
objectWithSound = obj;
skip = true;
if (TheAudio->isValidAudioEvent(soundToPlayPtr)) {
break;
} else {
// clear out the sound to play, and drop into the attack object logic.
soundToPlayPtr = NULL;
FALLTHROUGH;
}
}
case GameMessage::MSG_DO_FORCE_ATTACK_OBJECT:
case GameMessage::MSG_DO_ATTACK_OBJECT:
case GameMessage::MSG_DO_WEAPON_AT_OBJECT:
{
if( !soundToPlayPtr )
{
//Low priority sounds -- only do this if uninitialized.
if( info && info->m_air )
soundToPlayPtr = templ->getVoiceAttackAir();
else
soundToPlayPtr = templ->getVoiceAttack();
objectWithSound = obj;
}
//Look for a specialty weapon fired via command button!
Bool specialtyWeapon = FALSE;
if( msgType == GameMessage::MSG_DO_WEAPON_AT_OBJECT )
{
specialtyWeapon = TRUE;
}
Weapon *weapon = obj->getCurrentWeapon();
if( info && info->m_weaponSlot )
{
weapon = obj->getWeaponInWeaponSlot( *info->m_weaponSlot );
}
if( weapon )
{
switch( weapon->getDamageType() )
{
// this stays, even if ALLOW_SURRENDER is not defed, since flashbangs still use 'em
case DAMAGE_SURRENDER:
if( target && target->isKindOf( KINDOF_STRUCTURE ) )
{
//We are attempting to take over a building with rangers and flashbangs!
soundToPlayPtr = templ->getPerUnitSound( "VoiceClearBuilding" );
}
else
{
//Special for subdue attacks.
soundToPlayPtr = templ->getPerUnitSound( "VoiceSubdue" );
}
objectWithSound = obj;
skip = true;
break;
case DAMAGE_DISARM:
//Special for mine clearing attacks.
soundToPlayPtr = templ->getPerUnitSound( "VoiceDisarm" );
objectWithSound = obj;
skip = true;
break;
case DAMAGE_KILLPILOT:
if( specialtyWeapon )
{
//Special for sniping vehicle pilots.
soundToPlayPtr = templ->getPerUnitSound( "VoiceSnipePilot" );
objectWithSound = obj;
skip = true;
}
break;
case DAMAGE_MELEE:
if( specialtyWeapon )
{
//Special for stabbing
soundToPlayPtr = templ->getPerUnitSound( "VoiceMelee" );
objectWithSound = obj;
skip = true;
}
break;
}
}
break;
}
case GameMessage::MSG_DO_WEAPON_AT_LOCATION:
{
if( !soundToPlayPtr )
{
//Low priority sounds -- only do this if uninitialized.
if( info && info->m_air )
soundToPlayPtr = templ->getVoiceAttackAir();
else
soundToPlayPtr = templ->getVoiceAttack();
objectWithSound = obj;
}
//Check for possibility of a higher priority sound!
Weapon *weapon = obj->getCurrentWeapon();
if( info && info->m_weaponSlot )
{
weapon = obj->getWeaponInWeaponSlot( *info->m_weaponSlot );
}
if( weapon )
{
switch( weapon->getDamageType() )
{
// this stays, even if ALLOW_SURRENDER is not defed, since flashbangs still use 'em
case DAMAGE_SURRENDER:
break;
case DAMAGE_DISARM:
//Special for mine clearing attacks.
soundToPlayPtr = templ->getPerUnitSound( "VoiceDisarm" );
objectWithSound = obj;
break;
//these are specific to the guicommand based ground attacks, the toxin sprinkler and the firestorm wall thing
//hence the additional check for it being a non-primary weapon
case DAMAGE_FLAME:
if (weapon->getWeaponSlot() != PRIMARY_WEAPON)
{
soundToPlayPtr = templ->getPerUnitSound( "VoiceFlameLocation" );
objectWithSound = obj;
}
break;
case DAMAGE_POISON:
if (weapon->getWeaponSlot() != PRIMARY_WEAPON)
{
soundToPlayPtr = templ->getPerUnitSound( "VoicePoisonLocation" );
objectWithSound = obj;
}
break;
default:
if( !weapon->getName().compare( "ComancheRocketPodWeapon" ) )
{
//Special case for comanche rocket pods.
soundToPlayPtr = templ->getPerUnitSound( "VoiceFireRocketPods" );
objectWithSound = obj;
skip = true;
}
}
}
break;
}
case GameMessage::MSG_DO_GUARD_POSITION:
case GameMessage::MSG_DO_GUARD_OBJECT:
soundToPlayPtr = templ->getVoiceGuard();
objectWithSound = obj;
skip = true;
break;
case GameMessage::MSG_DO_SPECIAL_POWER:
case GameMessage::MSG_DO_SPECIAL_POWER_AT_LOCATION:
case GameMessage::MSG_DO_SPECIAL_POWER_AT_OBJECT:
{
if( info && info->m_specialPowerType != SPECIAL_INVALID )
{
SpecialPowerModuleInterface *spmInterface = obj->findSpecialPowerModuleInterface( info->m_specialPowerType );
if( spmInterface )
{
objectWithSound = obj;
soundToPlayPtr = &spmInterface->getInitiateSound();
skip = TRUE;
}
}
break;
}
case GameMessage::MSG_INTERNET_HACK:
objectWithSound = obj;
soundToPlayPtr = templ->getPerUnitSound( "VoiceHackInternet" );
skip = TRUE;
break;
default:
DEBUG_LOG(("Requested to add voice of message type %d, but don't know how - jkmcd", msgType));
break;
}
if( skip )
{
//The unit sound doesn't have any sort of priority or special case, so simply play the first one that comes along.
break;
}
}
if (!soundToPlayPtr)
return;
AudioEventRTS soundToPlay = *soundToPlayPtr;
// to prevent voice stepping.
if( objectWithSound )
{
soundToPlay.setObjectID( objectWithSound->getID() );
TheAudio->addAudioEvent(&soundToPlay);
// This seems really hacky, and MarkL admits that it is. However, we do this so that we
// can "randomly" pick a different sound the next time, if we have 3 or more sounds. - jkmcd
((AudioEventRTS*)soundToPlayPtr)->setPlayingAudioIndex( soundToPlay.getPlayingAudioIndex() );
if( objectWithSound->testStatus( OBJECT_STATUS_IS_CARBOMB ) )
{
//Additional sounds for terrorists in cars.
switch (msgType)
{
case GameMessage::MSG_DO_FORCE_ATTACK_GROUND:
case GameMessage::MSG_DO_FORCE_ATTACK_OBJECT:
case GameMessage::MSG_DO_ATTACK_OBJECT:
soundToPlay = TheAudio->getMiscAudio()->m_terroristInCarAttackVoice;
soundToPlay.setObjectID( objectWithSound->getID() );
TheAudio->addAudioEvent(&soundToPlay);
break;
case GameMessage::MSG_DO_MOVETO:
case GameMessage::MSG_DO_ATTACKMOVETO:
case GameMessage::MSG_GET_REPAIRED:
case GameMessage::MSG_GET_HEALED:
case GameMessage::MSG_DO_SALVAGE:
soundToPlay = TheAudio->getMiscAudio()->m_terroristInCarMoveVoice;
soundToPlay.setObjectID( objectWithSound->getID() );
TheAudio->addAudioEvent(&soundToPlay);
break;
case GameMessage::MSG_SELECT_TEAM0:
case GameMessage::MSG_SELECT_TEAM1:
case GameMessage::MSG_SELECT_TEAM2:
case GameMessage::MSG_SELECT_TEAM3:
case GameMessage::MSG_SELECT_TEAM4:
case GameMessage::MSG_SELECT_TEAM5:
case GameMessage::MSG_SELECT_TEAM6:
case GameMessage::MSG_SELECT_TEAM7:
case GameMessage::MSG_SELECT_TEAM8:
case GameMessage::MSG_SELECT_TEAM9:
case GameMessage::MSG_CREATE_SELECTED_GROUP:
soundToPlay = TheAudio->getMiscAudio()->m_terroristInCarSelectVoice;
soundToPlay.setObjectID( objectWithSound->getID() );
TheAudio->addAudioEvent(&soundToPlay);
break;
}
}
}
}
//------------------------------------------------------------------------------------
/**
* Find a suitable command center to view.
*/
struct CommandCenterLocator
{
Bool atLeastOne;
Bool isCommandCenter;
Int val;
Coord3D loc;
CommandCenterLocator() : atLeastOne(false), isCommandCenter(false), val(-1)
{
loc.zero();
}
};
void findCommandCenterOrMostExpensiveBuilding(Object* obj, void* vccl)
{
if (!obj) {
return;
}
CommandCenterLocator *ccl = (CommandCenterLocator*) vccl;
// here's the deal. We want to get the first Command Center in the list.
// Barring that, we want the most expensive structure we currently own.
if (obj->isKindOf(KINDOF_COMMANDCENTER)) {
ccl->isCommandCenter = true;
ccl->loc = *obj->getPosition();
} else if (!ccl->isCommandCenter) {
if (!obj->isKindOf(KINDOF_STRUCTURE)) {
return;
}
Int costToBuild = obj->getTemplate()->calcCostToBuild(obj->getControllingPlayer());
if (costToBuild > ccl->val) {
ccl->val = costToBuild;
ccl->loc = *obj->getPosition();
}
}
ccl->atLeastOne = true;
}
static void viewCommandCenter( void )
{
Player* localPlayer = TheControlBar->getCurrentlyViewedPlayer();
if (!localPlayer)
return;
CommandCenterLocator ccl;
localPlayer->iterateObjects(findCommandCenterOrMostExpensiveBuilding, &ccl);
if (ccl.atLeastOne) {
TheTacticalView->lookAt(&ccl.loc);
} else {
// @todo. Find their starting position and look at that instead?
}
}
//----------------- Select and View Hero -----------------------------------
struct HeroHolder
{
Object *hero;
};
void amIAHero(Object* obj, void* heroHolder)
{
if (!obj || ((HeroHolder*)heroHolder)->hero != NULL)
{
return;
}
if (obj->isKindOf( KINDOF_HERO ))
{
((HeroHolder*)heroHolder)->hero = obj;
}
}
static Object *iNeedAHero( void )
{
Player* localPlayer = TheControlBar->getCurrentlyViewedPlayer();
if (!localPlayer)
return NULL;
HeroHolder heroHolder;
heroHolder.hero = NULL;
localPlayer->iterateObjects(amIAHero, (void*)&heroHolder);
return heroHolder.hero;
}