forked from TheSuperHackers/GeneralsGameCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameLogicDispatch.cpp
More file actions
2075 lines (1702 loc) · 64.2 KB
/
GameLogicDispatch.cpp
File metadata and controls
2075 lines (1702 loc) · 64.2 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(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: GameLogicDispatch.cpp ////////////////////////////////////////////////////////////////////
// Author: Mike Booth, Colin Day
// Description: Message logic to drive the game play
///////////////////////////////////////////////////////////////////////////////////////////////////
// INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
#include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine
#include "Common/CRCDebug.h"
#include "Common/FramePacer.h"
#include "Common/GameAudio.h"
#include "Common/GameEngine.h"
#include "Common/GlobalData.h"
#include "Common/NameKeyGenerator.h"
#include "Common/ThingFactory.h"
#include "Common/Player.h"
#include "Common/PlayerList.h"
#include "Common/PlayerTemplate.h"
#include "Common/MessageStream.h"
#include "Common/MultiplayerSettings.h"
#include "Common/Recorder.h"
#include "Common/BuildAssistant.h"
#include "Common/SpecialPower.h"
#include "Common/ThingTemplate.h"
#include "Common/Upgrade.h"
#include "Common/StatsCollector.h"
#include "Common/Radar.h"
#include "GameLogic/AIPathfind.h"
#include "GameLogic/GameLogic.h"
#include "GameLogic/Locomotor.h"
#include "GameLogic/Object.h"
#include "GameLogic/ObjectCreationList.h"
#include "GameLogic/ObjectIter.h"
//#include "GameLogic/PartitionManager.h"
#include "GameLogic/AI.h"
#include "GameLogic/Module/AIUpdate.h"
#include "GameLogic/Module/BodyModule.h"
#include "GameLogic/Module/OpenContain.h"
#include "GameLogic/Module/ProductionUpdate.h"
#include "GameLogic/Module/SpecialPowerModule.h"
#include "GameLogic/ScriptActions.h"
#include "GameLogic/ScriptEngine.h"
#include "GameLogic/VictoryConditions.h"
#include "GameLogic/Weapon.h"
#include "GameClient/CommandXlat.h"
#include "GameClient/ControlBar.h"
#include "GameClient/Drawable.h"
#include "GameClient/Eva.h"
#include "GameClient/GameText.h"
#include "GameClient/GameWindowManager.h"
#include "GameClient/GUICallbacks.h"
#include "GameClient/InGameUI.h"
#include "GameClient/KeyDefs.h"
#include "GameClient/Mouse.h"
#include "GameClient/ParticleSys.h"
#include "GameClient/Shell.h"
#include "GameClient/Module/BeaconClientUpdate.h"
#include "GameClient/LookAtXlat.h"
#include "GameNetwork/NetworkInterface.h"
#define MAX_PATH_SUBJECTS 64
static Bool theBuildPlan = false;
static Object *thePlanSubject[ MAX_PATH_SUBJECTS ];
static int thePlanSubjectCount = 0;
//static WindowLayout *background = nullptr;
// ------------------------------------------------------------------------------------------------
/** Issue the movement command to the object */
// ------------------------------------------------------------------------------------------------
static void doMoveTo( Object *obj, const Coord3D *pos )
{
AIUpdateInterface *ai = obj->getAIUpdateInterface();
DEBUG_ASSERTCRASH(ai, ("Attempted doMoveTo() on an Object with no AI"));
if (ai)
{
if (theBuildPlan)
{
int i;
// if this object isn't in the buildPlan set, add it
for( i=0; i<thePlanSubjectCount; i++ )
if (thePlanSubject[i] == obj)
break;
if (i == thePlanSubjectCount)
thePlanSubject[ thePlanSubjectCount++ ] = obj;
ai->queueWaypoint( pos );
}
else
{
ai->clearWaypointQueue();
obj->leaveGroup();
obj->releaseWeaponLock(LOCKED_TEMPORARILY); // release any temporary locks.
ai->aiMoveToPosition( pos, CMD_FROM_PLAYER );
}
}
}
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
static void doSetRallyPoint( Object *obj, const Coord3D& pos )
{
Bool isLocalPlayer = obj->isLocallyControlled();
//
// we must be able to find a path from the object to the point they have chosen, cause setting
// a rally point at a invalid location would suck. To be super nice, we have to make sure
// that every type of object that can be created from the thing setting the rally point
// can actually find a path from the thing to the point
//
// to see the never-finished code to check all locomotor sets, see past revs of GUICommandTranslator.cpp -MDC
//
// for now, just use the basic human locomotor ... and enable the above code when Steven
// tells me how to get the locomotor sets based on a thing template (CBD)
//
NameKeyType key = NAMEKEY( "BasicHumanLocomotor" );
LocomotorSet locomotorSet;
locomotorSet.addLocomotor( TheLocomotorStore->findLocomotorTemplate( key ) );
if( TheAI->pathfinder()->clientSafeQuickDoesPathExist( locomotorSet, obj->getPosition(), &pos ) == FALSE )
{
// user feedback
if( isLocalPlayer )
{
// display error message to user
TheInGameUI->message( TheGameText->fetch( "GUI:RallyPointNoPath" ) );
// play the no can do sound
static AudioEventRTS rallyNotSet("UnableToSetRallyPoint");
rallyNotSet.setPosition(&pos);
rallyNotSet.setPlayerIndex(obj->getControllingPlayer()->getPlayerIndex());
TheAudio->addAudioEvent(&rallyNotSet);
}
return;
}
// feedback to the player
if( isLocalPlayer )
{
// print a message to the user
UnicodeString info;
info.format( TheGameText->fetch( "GUI:RallyPointSet" ),
obj->getTemplate()->getDisplayName().str() );
TheInGameUI->message( info );
// play a sound for setting the rally point
static AudioEventRTS rallyPointSet("RallyPointSet");
rallyPointSet.setPosition(&pos);
rallyPointSet.setPlayerIndex(obj->getControllingPlayer()->getPlayerIndex());
TheAudio->addAudioEvent(&rallyPointSet);
// mark the UI as dirty so that we re-evaluate the selection and show the rally point
Drawable *draw = obj->getDrawable();
if( draw && draw->isSelected() )
TheControlBar->markUIDirty();
}
// if this object has a ProductionExitUpdate interface, we are setting a rally point
ExitInterface *exitInterface = obj->getObjectExitInterface();
if( exitInterface )
{
// set the rally point
exitInterface->setRallyPoint( &pos );
}
}
static Object * getSingleObjectFromSelection(const AIGroup *currentlySelectedGroup)
{
if( currentlySelectedGroup && !currentlySelectedGroup->isEmpty() )
{
const VecObjectID& selectedObjects = currentlySelectedGroup->getAllIDs();
DEBUG_ASSERTCRASH(selectedObjects.size() == 1, ("Trying to get single object from multiple selection!"));
VecObjectID::const_iterator it = selectedObjects.begin();
return TheGameLogic->findObjectByID(*it);
}
return nullptr;
}
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
void GameLogic::closeWindows()
{
HideDiplomacy();
ResetDiplomacy();
HideInGameChat();
ResetInGameChat();
TheControlBar->hidePurchaseScience();
TheControlBar->hideSpecialPowerShortcut();
HideQuitMenu();
// hide the options menu
NameKeyType buttonID = TheNameKeyGenerator->nameToKey( "OptionsMenu.wnd:ButtonBack" );
GameWindow *button = TheWindowManager->winGetWindowFromId( nullptr, buttonID );
GameWindow *window = TheWindowManager->winGetWindowFromId( nullptr, TheNameKeyGenerator->nameToKey("OptionsMenu.wnd:OptionsMenuParent") );
if(window)
TheWindowManager->winSendSystemMsg( window, GBM_SELECTED,
(WindowMsgData)button, buttonID );
}
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
void GameLogic::clearGameData( Bool showScoreScreen )
{
if( !isInGame() )
{
DEBUG_CRASH(("We tried to clear the game data when we weren't in a game"));
return;
}
setClearingGameData( TRUE );
// m_background = TheWindowManager->winCreateLayout("Menus/BlankWindow.wnd");
// DEBUG_ASSERTCRASH(m_background,("We Couldn't Load Menus/BlankWindow.wnd"));
// m_background->hide(FALSE);
// m_background->bringForward();
// reset the game engine to accept data for a new game
if(TheStatsCollector)
TheStatsCollector->writeFileEnd();
TheScriptActions->closeWindows(FALSE); // Close victory or defeat windows.
Bool shellGame = FALSE;
if ((!isInShellGame() || !isInGame()) && showScoreScreen && !TheGlobalData->m_headless)
{
shellGame = TRUE;
TheShell->push("Menus/ScoreScreen.wnd");
TheShell->showShell(FALSE); // by passing in false, we don't want to run the Init on the shell screen we just pushed on
void FixupScoreScreenMovieWindow();
FixupScoreScreenMovieWindow();
}
TheGameEngine->reset();
setGameMode(GAME_NONE);
// m_background->bringForward();
// if(shellGame)
if (TheGlobalData->m_initialFile.isEmpty() == FALSE)
{
TheGameEngine->setQuitting(TRUE);
}
HideControlBar();
closeWindows();
TheMouse->setVisibility(TRUE);
if(m_background)
{
m_background->destroyWindows();
deleteInstance(m_background);
m_background = nullptr;
}
setClearingGameData( FALSE );
}
// ------------------------------------------------------------------------------------------------
/** Prepare for a new game */
// ------------------------------------------------------------------------------------------------
void GameLogic::prepareNewGame( GameMode gameMode, GameDifficulty diff, Int rankPoints )
{
//Kris: Commented this out, but leaving it around incase it bites us later. I cleaned up the
// nomenclature. Look for setLoadingMap() and setLoadingSave()
//setGameLoading(TRUE);
TheScriptEngine->setGlobalDifficulty(diff);
if(!m_background)
{
m_background = TheWindowManager->winCreateLayout("Menus/BlankWindow.wnd");
DEBUG_ASSERTCRASH(m_background,("We Couldn't Load Menus/BlankWindow.wnd"));
m_background->hide(FALSE);
m_background->bringForward();
}
m_background->getFirstWindow()->winClearStatus(WIN_STATUS_IMAGE);
setGameMode( gameMode );
if (!TheGlobalData->m_pendingFile.isEmpty())
{
TheWritableGlobalData->m_mapName = TheGlobalData->m_pendingFile;
TheWritableGlobalData->m_pendingFile.clear();
}
m_rankPointsToAddAtGameStart = rankPoints;
DEBUG_LOG(("GameLogic::prepareNewGame() - m_rankPointsToAddAtGameStart = %d", m_rankPointsToAddAtGameStart));
// If we're about to start a game, hide the shell.
if(!isInShellGame())
TheShell->hideShell();
m_startNewGame = FALSE;
}
//-------------------------------------------------------------------------------------------------
/** This message handles dispatches object command messages to the
* appropriate objects.
* @todo Rename this to "CommandProcessor", or similar. */
//-------------------------------------------------------------------------------------------------
void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData )
{
#ifdef RTS_DEBUG
DEBUG_ASSERTCRASH(msg != nullptr && msg != (GameMessage*)0xdeadbeef, ("bad msg"));
#endif
Player *thisPlayer = ThePlayerList->getNthPlayer( msg->getPlayerIndex() );
DEBUG_ASSERTCRASH( thisPlayer, ("logicMessageDispatcher: Processing message from unknown player (player index '%d')",
msg->getPlayerIndex()) );
AIGroupPtr currentlySelectedGroup = nullptr;
if (isInGame())
{
if (msg->getType() >= GameMessage::MSG_BEGIN_NETWORK_MESSAGES && msg->getType() <= GameMessage::MSG_END_NETWORK_MESSAGES)
{
if (msg->getType() != GameMessage::MSG_LOGIC_CRC && msg->getType() != GameMessage::MSG_SET_REPLAY_CAMERA)
{
currentlySelectedGroup = TheAI->createGroup(); // can't do this outside a game - it'll cause sync errors galore.
CRCGEN_LOG(( "Creating AIGroup %d in GameLogic::logicMessageDispatcher()", currentlySelectedGroup?currentlySelectedGroup->getID():0 ));
#if RETAIL_COMPATIBLE_AIGROUP
thisPlayer->getCurrentSelectionAsAIGroup(currentlySelectedGroup);
#else
thisPlayer->getCurrentSelectionAsAIGroup(currentlySelectedGroup.Peek());
#endif
// We can't issue commands to groups that contain units that don't belong to the issuing player, so pretend like
// there's nothing selected. Also, if currentlySelectedGroup is empty, go ahead and delete it, so that we can skip
// any processing on it.
if (currentlySelectedGroup->isEmpty())
{
#if RETAIL_COMPATIBLE_AIGROUP
TheAI->destroyGroup(currentlySelectedGroup);
#endif
currentlySelectedGroup = nullptr;
}
// If there are any units that the player doesn't own, then remove them from the "currentlySelectedGroup"
if (currentlySelectedGroup)
if (currentlySelectedGroup->removeAnyObjectsNotOwnedByPlayer(thisPlayer))
currentlySelectedGroup = nullptr;
if(TheStatsCollector)
TheStatsCollector->collectMsgStats(msg);
}
}
}
#ifdef DEBUG_LOGGING
AsciiString commandName;
commandName = msg->getCommandAsString();
if (msg->getType() < GameMessage::MSG_BEGIN_NETWORK_MESSAGES || msg->getType() > GameMessage::MSG_END_NETWORK_MESSAGES)
{
commandName.concat(" (NON-LOGIC-MESSAGE!!!)");
}
else if (msg->getType() == GameMessage::MSG_BEGIN_NETWORK_MESSAGES)
{
commandName = " (CRC message!)";
}
#if 0
if (commandName.isNotEmpty() /*&& msg->getType() != GameMessage::MSG_FRAME_TICK*/)
{
DEBUG_LOG(("Frame %d: GameLogic::logicMessageDispatcher() saw a %s from player %d (%ls)", getFrame(), commandName.str(),
msg->getPlayerIndex(), thisPlayer->getPlayerDisplayName().str()));
}
#endif
#endif // DEBUG_LOGGING
// process the message
GameMessage::Type msgType = msg->getType();
switch( msgType )
{
//---------------------------------------------------------------------------------------------
case GameMessage::MSG_NEW_GAME:
{
//DEBUG_ASSERTCRASH(msg->getArgumentCount() == 1 || msg->getArgumentCount() == 2, ("%d arguments to MSG_NEW_GAME", msg->getArgumentCount()));
GameMode gameMode = (GameMode)msg->getArgument( 0 )->integer;
Int rankPoints = 0;
GameDifficulty diff = DIFFICULTY_NORMAL;
if ( msg->getArgumentCount() >= 2 )
diff = (GameDifficulty)msg->getArgument( 1 )->integer;
if ( msg->getArgumentCount() >= 3 )
rankPoints = msg->getArgument( 2 )->integer;
if ( msg->getArgumentCount() >= 4 )
{
Int maxFPS = msg->getArgument( 3 )->integer;
if (maxFPS < 1 || maxFPS > 1000)
maxFPS = TheGlobalData->m_framesPerSecondLimit;
DEBUG_LOG(("Setting max FPS limit to %d FPS", maxFPS));
TheFramePacer->setFramesPerSecondLimit(maxFPS);
TheWritableGlobalData->m_useFpsLimit = true;
}
// prepare for new game
prepareNewGame( gameMode, diff, rankPoints );
// start new game
startNewGame( FALSE );
break;
}
//---------------------------------------------------------------------------------------------
case GameMessage::MSG_CLEAR_GAME_DATA:
{
#if defined(RTS_DEBUG)
if (TheDisplay && TheGlobalData->m_dumpAssetUsage)
TheDisplay->dumpAssetUsage(TheGlobalData->m_mapName.str());
#endif
if (currentlySelectedGroup)
{
#if RETAIL_COMPATIBLE_AIGROUP
TheAI->destroyGroup(currentlySelectedGroup);
#else
currentlySelectedGroup->removeAll();
#endif
}
currentlySelectedGroup = nullptr;
clearGameData();
break;
}
//---------------------------------------------------------------------------------------------
case GameMessage::MSG_META_BEGIN_PATH_BUILD:
{
DEBUG_LOG(("META: begin path build"));
DEBUG_ASSERTCRASH(!theBuildPlan, ("mismatched theBuildPlan"));
if (theBuildPlan == false)
{
theBuildPlan = true;
thePlanSubjectCount = 0;
}
break;
}
//---------------------------------------------------------------------------------------------
case GameMessage::MSG_META_END_PATH_BUILD:
{
DEBUG_LOG(("META: end path build"));
DEBUG_ASSERTCRASH(theBuildPlan, ("mismatched theBuildPlan"));
// tell everyone who participated in the plan to move
for( int i=0; i<thePlanSubjectCount; i++ )
{
AIUpdateInterface *ai = thePlanSubject[i]->getAIUpdateInterface();
if (ai)
ai->executeWaypointQueue();
}
theBuildPlan = false;
thePlanSubjectCount = 0;
break;
}
//---------------------------------------------------------------------------------------------
case GameMessage::MSG_SET_RALLY_POINT:
{
Object *obj = findObjectByID( msg->getArgument( 0 )->objectID );
Coord3D dest = msg->getArgument( 1 )->location;
if (obj)
{
doSetRallyPoint( obj, dest );
}
break;
}
//---------------------------------------------------------------------------------------------
case GameMessage::MSG_DO_WEAPON:
{
WeaponSlotType weaponSlot = (WeaponSlotType)msg->getArgument( 0 )->integer;
Int maxShotsToFire = msg->getArgument( 1 )->integer;
// lock it just till the weapon is empty or the attack is "done"
if( currentlySelectedGroup && currentlySelectedGroup->setWeaponLockForGroup( weaponSlot, LOCKED_TEMPORARILY ))
{
currentlySelectedGroup->groupAttackPosition( nullptr, maxShotsToFire, CMD_FROM_PLAYER );
}
break;
}
//---------------------------------------------------------------------------------------------
case GameMessage::MSG_COMBATDROP_AT_OBJECT:
{
Object *targetObject = findObjectByID( msg->getArgument( 0 )->objectID );
// issue command for either single object or for selected group
if( currentlySelectedGroup && targetObject )
currentlySelectedGroup->groupCombatDrop( targetObject,
*targetObject->getPosition(),
CMD_FROM_PLAYER );
/*
if( sourceObject && targetObject )
{
AIUpdateInterface* sourceAI = sourceObject->getAIUpdateInterface();
if (sourceAI)
{
sourceAI->aiCombatDrop( targetObject, *targetObject->getPosition(), CMD_FROM_PLAYER );
}
}
*/
break;
}
//---------------------------------------------------------------------------------------------
case GameMessage::MSG_COMBATDROP_AT_LOCATION:
{
Coord3D targetLoc = msg->getArgument( 0 )->location;
if( currentlySelectedGroup )
currentlySelectedGroup->groupCombatDrop( nullptr, targetLoc, CMD_FROM_PLAYER );
/*
if( sourceObject )
{
AIUpdateInterface* sourceAI = sourceObject->getAIUpdateInterface();
if (sourceAI)
{
sourceAI->aiCombatDrop( nullptr, targetLoc, CMD_FROM_PLAYER );
}
}
*/
break;
}
//---------------------------------------------------------------------------------------------
case GameMessage::MSG_DO_WEAPON_AT_OBJECT:
{
// Lock the weapon choice to the right weapon, then give an attack command
WeaponSlotType weaponSlot = (WeaponSlotType)msg->getArgument( 0 )->integer;
Object *targetObject = findObjectByID( msg->getArgument( 1 )->objectID );
Int maxShotsToFire = msg->getArgument( 2 )->integer;
// sanity
if( targetObject == nullptr )
break;
// issue command for either single object or for selected group
if( currentlySelectedGroup )
{
// lock it just till the weapon is empty or the attack is "done"
if (currentlySelectedGroup->setWeaponLockForGroup( weaponSlot, LOCKED_TEMPORARILY ))
currentlySelectedGroup->groupAttackObject( targetObject, maxShotsToFire, CMD_FROM_PLAYER );
}
break;
}
//---------------------------------------------------------------------------------------------
case GameMessage::MSG_SWITCH_WEAPONS:
{
// use the selected group
WeaponSlotType weaponSlot = (WeaponSlotType)msg->getArgument( 0 )->integer;
// lock until un-switched, or switched to something else.
if( currentlySelectedGroup )
currentlySelectedGroup->setWeaponLockForGroup( weaponSlot, LOCKED_PERMANENTLY );
break;
}
//---------------------------------------------------------------------------------------------
case GameMessage::MSG_SET_MINE_CLEARING_DETAIL:
{
if( currentlySelectedGroup )
{
currentlySelectedGroup->setMineClearingDetail(true);
}
break;
}
//---------------------------------------------------------------------------------------------
case GameMessage::MSG_DO_WEAPON_AT_LOCATION:
{
WeaponSlotType weaponSlot = (WeaponSlotType)msg->getArgument( 0 )->integer;
Coord3D targetLoc = msg->getArgument( 1 )->location;
Int maxShotsToFire = msg->getArgument( 2 )->integer;
// issue command for either single object or for selected group
if( currentlySelectedGroup )
{
// lock it just till the weapon is empty or the attack is "done"
if (currentlySelectedGroup->setWeaponLockForGroup( weaponSlot, LOCKED_TEMPORARILY ))
currentlySelectedGroup->groupAttackPosition( &targetLoc, maxShotsToFire, CMD_FROM_PLAYER );
}
break;
}
//---------------------------------------------------------------------------------------------
case GameMessage::MSG_DO_SPECIAL_POWER:
{
// first argument is the special power ID
UnsignedInt specialPowerID = msg->getArgument( 0 )->integer;
// Command button options -- special power may care about variance options
UnsignedInt options = msg->getArgument( 1 )->integer;
// check for possible specific source, ignoring selection.
ObjectID sourceID = msg->getArgument(2)->objectID;
Object* source = findObjectByID(sourceID);
if (source != nullptr)
{
AIGroupPtr theGroup = TheAI->createGroup();
theGroup->add(source);
theGroup->groupDoSpecialPower( specialPowerID, options );
#if RETAIL_COMPATIBLE_AIGROUP
TheAI->destroyGroup(theGroup);
#else
theGroup->removeAll();
#endif
}
else
{
//Use the selected group!
if( currentlySelectedGroup )
{
currentlySelectedGroup->groupDoSpecialPower( specialPowerID, options );
}
}
break;
}
//---------------------------------------------------------------------------------------------
case GameMessage::MSG_DO_SPECIAL_POWER_AT_LOCATION:
{
// first argument is the special power ID
UnsignedInt specialPowerID = msg->getArgument( 0 )->integer;
// Location argument 2 is destination
Coord3D targetCoord = msg->getArgument(1)->location;
// Object in way -- if applicable (some specials care, others don't)
ObjectID objectID = msg->getArgument( 2 )->objectID;
Object *objectInWay = findObjectByID( objectID );
// Command button options -- special power may care about variance options
UnsignedInt options = msg->getArgument( 3 )->integer;
// check for possible specific source, ignoring selection.
ObjectID sourceID = msg->getArgument(4)->objectID;
Object* source = findObjectByID(sourceID);
if (source != nullptr)
{
AIGroupPtr theGroup = TheAI->createGroup();
theGroup->add(source);
theGroup->groupDoSpecialPowerAtLocation( specialPowerID, &targetCoord, INVALID_ANGLE, objectInWay, options );
#if RETAIL_COMPATIBLE_AIGROUP
TheAI->destroyGroup(theGroup);
#else
theGroup->removeAll();
#endif
}
else
{
//Use the selected group!
if( currentlySelectedGroup )
{
currentlySelectedGroup->groupDoSpecialPowerAtLocation( specialPowerID, &targetCoord, INVALID_ANGLE, objectInWay, options );
}
}
break;
}
//---------------------------------------------------------------------------------------------
case GameMessage::MSG_DO_SPECIAL_POWER_AT_OBJECT:
{
// first argument is the special power ID
UnsignedInt specialPowerID = msg->getArgument( 0 )->integer;
// argument 2 is target object
ObjectID targetID = msg->getArgument(1)->objectID;
Object *target = findObjectByID( targetID );
if( !target )
{
break;
}
// Command button options -- special power may care about variance options
UnsignedInt options = msg->getArgument( 2 )->integer;
// check for possible specific source, ignoring selection.
ObjectID sourceID = msg->getArgument(3)->objectID;
Object* source = findObjectByID(sourceID);
if (source != nullptr)
{
AIGroupPtr theGroup = TheAI->createGroup();
theGroup->add(source);
theGroup->groupDoSpecialPowerAtObject( specialPowerID, target, options );
#if RETAIL_COMPATIBLE_AIGROUP
TheAI->destroyGroup(theGroup);
#else
theGroup->removeAll();
#endif
}
else
{
if( currentlySelectedGroup )
{
currentlySelectedGroup->groupDoSpecialPowerAtObject( specialPowerID, target, options );
}
}
break;
}
//---------------------------------------------------------------------------------------------
case GameMessage::MSG_DO_ATTACKMOVETO:
{
Coord3D dest = msg->getArgument( 0 )->location;
if (currentlySelectedGroup)
{
currentlySelectedGroup->releaseWeaponLockForGroup(LOCKED_TEMPORARILY); // release any temporary locks.
currentlySelectedGroup->groupAttackMoveToPosition( &dest, NO_MAX_SHOTS_LIMIT, CMD_FROM_PLAYER );
}
break;
}
//---------------------------------------------------------------------------------------------
case GameMessage::MSG_DO_FORCEMOVETO:
{
Coord3D dest = msg->getArgument( 0 )->location;
if (currentlySelectedGroup)
{
currentlySelectedGroup->releaseWeaponLockForGroup(LOCKED_TEMPORARILY); // release any temporary locks.
currentlySelectedGroup->groupMoveToPosition( &dest, false, CMD_FROM_PLAYER );
}
break;
}
//---------------------------------------------------------------------------------------------
// MSG_DO_SALVAGE is intentionally set up to mimic the moveto.
case GameMessage::MSG_DO_SALVAGE:
case GameMessage::MSG_DO_MOVETO:
{
Coord3D dest = msg->getArgument( 0 )->location;
if( currentlySelectedGroup )
{
//DEBUG_LOG(("GameLogicDispatch - got a MSG_DO_MOVETO command"));
currentlySelectedGroup->releaseWeaponLockForGroup(LOCKED_TEMPORARILY); // release any temporary locks.
currentlySelectedGroup->groupMoveToPosition( &dest, false, CMD_FROM_PLAYER );
}
break;
}
//---------------------------------------------------------------------------------------------
case GameMessage::MSG_ADD_WAYPOINT:
{
Coord3D dest = msg->getArgument( 0 )->location;
if( currentlySelectedGroup )
{
//DEBUG_LOG(("GameLogicDispatch - got a MSG_DO_MOVETO command"));
currentlySelectedGroup->releaseWeaponLockForGroup(LOCKED_TEMPORARILY); // release any temporary locks.
currentlySelectedGroup->groupMoveToPosition( &dest, true, CMD_FROM_PLAYER );
}
break;
}
//---------------------------------------------------------------------------------------------
case GameMessage::MSG_DO_GUARD_POSITION:
{
Coord3D loc = msg->getArgument( 0 )->location;
GuardMode gm = (GuardMode)msg->getArgument( 1 )->integer;
if (currentlySelectedGroup)
{
currentlySelectedGroup->groupGuardPosition(&loc, gm, CMD_FROM_PLAYER);
}
break;
}
//---------------------------------------------------------------------------------------------
case GameMessage::MSG_DO_GUARD_OBJECT:
{
Object* obj = findObjectByID( msg->getArgument( 0 )->objectID );
if (!obj)
break;
GuardMode gm = (GuardMode)msg->getArgument( 1 )->integer;
if (currentlySelectedGroup)
{
currentlySelectedGroup->groupGuardObject(obj, gm, CMD_FROM_PLAYER);
}
break;
}
//---------------------------------------------------------------------------------------------
case GameMessage::MSG_DO_STOP:
{
if (currentlySelectedGroup)
{
currentlySelectedGroup->groupIdle(CMD_FROM_PLAYER);
}
break;
}
//---------------------------------------------------------------------------------------------
case GameMessage::MSG_DO_SCATTER:
{
if (currentlySelectedGroup)
{
currentlySelectedGroup->groupScatter(CMD_FROM_PLAYER);
}
break;
}
//---------------------------------------------------------------------------------------------
case GameMessage::MSG_CREATE_FORMATION:
{
if (currentlySelectedGroup)
{
currentlySelectedGroup->groupCreateFormation(CMD_FROM_PLAYER);
}
break;
}
//---------------------------------------------------------------------------------------------
case GameMessage::MSG_CLEAR_INGAME_POPUP_MESSAGE:
{
if( TheInGameUI )
{
TheInGameUI->clearPopupMessageData();
}
break;
}
//---------------------------------------------------------------------------------------------
case GameMessage::MSG_DO_CHEER:
{
//All selected units play cheer animation.
if( currentlySelectedGroup )
{
currentlySelectedGroup->groupCheer( CMD_FROM_PLAYER );
}
break;
}
#if defined(RTS_DEBUG)
//---------------------------------------------------------------------------------------------
case GameMessage::MSG_DEBUG_KILL_SELECTION:
{
//All selected units die
if( currentlySelectedGroup )
{
const VecObjectID& selectedObjects = currentlySelectedGroup->getAllIDs();
for (VecObjectID::const_iterator it = selectedObjects.begin(); it != selectedObjects.end(); ++it)
{
Object *obj = findObjectByID(*it);
if (obj)
{
obj->kill();
}
}
}
break;
}
//---------------------------------------------------------------------------------------------
case GameMessage::MSG_DEBUG_HURT_OBJECT:
{
Object* objToHurt = TheGameLogic->findObjectByID( msg->getArgument( 0 )->objectID );
if (objToHurt)
{
DamageInfo damageInfo;
damageInfo.in.m_damageType = DAMAGE_UNRESISTABLE;
damageInfo.in.m_deathType = DEATH_NORMAL;
damageInfo.in.m_sourceID = INVALID_ID;
damageInfo.in.m_amount = objToHurt->getBodyModule()->getMaxHealth() / 10.0f;
objToHurt->attemptDamage( &damageInfo );
}
break;
}
//---------------------------------------------------------------------------------------------
case GameMessage::MSG_DEBUG_KILL_OBJECT:
{
Object* objToHurt = TheGameLogic->findObjectByID( msg->getArgument( 0 )->objectID );
if (objToHurt)
{
objToHurt->kill();
}
break;
}
#endif
#ifdef ALLOW_SURRENDER
//---------------------------------------------------------------------------------------------
case GameMessage::MSG_DO_SURRENDER:
{
//All selected units surrender
if( currentlySelectedGroup )
{
Object* objWeSurrenderedTo = TheGameLogic->findObjectByID( msg->getArgument( 0 )->objectID );
Bool surrender = msg->getArgument( 1 )->boolean;
currentlySelectedGroup->groupSurrender( objWeSurrenderedTo, surrender, CMD_FROM_PLAYER );
}
break;
}
#endif
//---------------------------------------------------------------------------------------------
case GameMessage::MSG_ENTER:
{
Object *enter = findObjectByID( msg->getArgument( 1 )->objectID );
// sanity
if( enter == nullptr )
break;
if( currentlySelectedGroup )
{
currentlySelectedGroup->releaseWeaponLockForGroup(LOCKED_TEMPORARILY); // release any temporary locks.
currentlySelectedGroup->groupEnter( enter, CMD_FROM_PLAYER );
}
break;
}
//---------------------------------------------------------------------------------------------
case GameMessage::MSG_EXIT:
{
Object *objectWantingToExit = findObjectByID( msg->getArgument( 0 )->objectID );