forked from TheSuperHackers/GeneralsGameCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathActionManager.cpp
More file actions
2106 lines (1768 loc) · 64.9 KB
/
ActionManager.cpp
File metadata and controls
2106 lines (1768 loc) · 64.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
** Command & Conquer Generals Zero Hour(tm)
** Copyright 2025 Electronic Arts Inc.
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
////////////////////////////////////////////////////////////////////////////////
// //
// (c) 2001-2003 Electronic Arts Inc. //
// //
////////////////////////////////////////////////////////////////////////////////
// FILE: ActionManager.cpp ////////////////////////////////////////////////////////////////////////
// Author: Colin Day
// Desc: TheActionManager is a convenient place for us to wrap up all sorts of logical
// queries about what objects can do in the world and to other objects. The purpose
// of having a central place for this logic assists us in making these logical kind
// of queries in the user interface and allows us to use the same code to validate
// commands as they come in over the network interface in order to do the
// real action.
///////////////////////////////////////////////////////////////////////////////////////////////////
// INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
#include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine
#include "Common/ActionManager.h"
#include "Common/GlobalData.h"
#include "Common/Player.h"
#include "Common/PlayerList.h"
#include "Common/SpecialPower.h"
#include "Common/Team.h"
#include "Common/ThingTemplate.h"
#include "GameClient/Drawable.h"
#include "GameClient/InGameUI.h"
#include "GameLogic/Object.h"
#include "GameLogic/PartitionManager.h"
#include "GameLogic/Module/BodyModule.h"
#include "GameLogic/Module/ContainModule.h"
#include "GameLogic/Module/CollideModule.h"
#include "GameLogic/Module/DozerAIUpdate.h"
#include "GameLogic/Module/RailroadGuideAIUpdate.h"
#include "GameLogic/Module/RailedTransportDockUpdate.h"
#include "GameLogic/Module/SpawnBehavior.h"
#include "GameLogic/Module/SupplyTruckAIUpdate.h"
#include "GameLogic/Module/SupplyCenterDockUpdate.h"
#include "GameLogic/Module/SupplyWarehouseDockUpdate.h"
#include "GameLogic/Module/SpecialPowerModule.h"
#include "GameLogic/Module/SpecialAbilityUpdate.h"
#include "GameLogic/Weapon.h"
#include "GameLogic/ExperienceTracker.h"//LORENZEN
// GLOBAL /////////////////////////////////////////////////////////////////////////////////////////
ActionManager *TheActionManager = nullptr;
// LOCAL //////////////////////////////////////////////////////////////////////////////////////////
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
static Bool appearsToContainFriendlies(const Object* obj, const Object* otherObject)
{
// check if the object is a container containing stealth units tricking
// the player into thinking it isn't actually an enemy.
const ContainModuleInterface *otherContain = otherObject->getContain();
if( otherContain )
{
const Player *otherPlayer = otherContain->getApparentControllingPlayer(obj->getControllingPlayer());
// if( otherPlayer && otherPlayer->getRelationship( obj->getTeam() ) != ENEMIES )
// the above test is wrong; we want to know how WE consider THEM, not how THEY consider US
if (otherPlayer && obj->getTeam()->getRelationship(otherPlayer->getDefaultTeam()) != ENEMIES)
{
return TRUE;
}
}
return FALSE;
}
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
static Bool isObjectShroudedForAction ( const Object *source, const Object *target, CommandSourceType commandSource )
{
/// @todo - reenable this when we can avoid breaking scripted actions.
// In order to support ai and scripted actions in singler player, we have to disable this for now.
// We can re-enable it when we can tell that this is a player generated action. jba.
// return false;
// GS Keeping this comment to show we now have commandSource, so everything should be fine again.
// The target is only shrouded for action if...
// the asking player is human
// the asking impetus is not from a script
// and the target object is Fogged or worse
if( source && target && source->getControllingPlayer() )
{
if( source->getControllingPlayer()->getPlayerType() == PLAYER_HUMAN
&& commandSource != CMD_FROM_SCRIPT
&& target->getShroudedStatus( source->getControllingPlayer()->getPlayerIndex() ) >= OBJECTSHROUD_FOGGED
)
{
return TRUE;
}
}
return FALSE;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
ActionManager::ActionManager( void )
{
}
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
ActionManager::~ActionManager( void )
{
}
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
Bool ActionManager::canGetRepairedAt( const Object *obj, const Object *repairDest, CommandSourceType commandSource )
{
// sanity
if( obj == nullptr || repairDest == nullptr )
return FALSE;
Relationship r = obj->getRelationship(repairDest);
// only available by our allies
if( r != ALLIES )
return FALSE;
// dead objects cannot be repaired
if( obj->isEffectivelyDead() )
return FALSE;
// If I can't move, I can't get repaired
if( !obj->isMobile() )
return FALSE;
// nothing can be done with things that are under construction
if( obj->getStatusBits().test( OBJECT_STATUS_UNDER_CONSTRUCTION ) ||
repairDest->getStatusBits().test( OBJECT_STATUS_UNDER_CONSTRUCTION ) )
return FALSE;
// Can't get repaired at something being sold
if( repairDest->testStatus(OBJECT_STATUS_SOLD) )
return FALSE;
// only vehicles can go get repaired at something
if( obj->isKindOf( KINDOF_VEHICLE ) == FALSE )
return FALSE;
// vehicles can only be repaired at something that is designated as a repair pad
if (obj->isKindOf( KINDOF_AIRCRAFT ))
{
// aircraft require an airfield.
if( !obj->isAboveTerrain() ||
repairDest->isKindOf( KINDOF_FS_AIRFIELD ) == FALSE )
return FALSE;
}
else
{
if( repairDest->isKindOf( KINDOF_REPAIR_PAD ) == FALSE )
return FALSE;
}
// if I am at full health, I can't get repair there
BodyModuleInterface *body = obj->getBodyModule();
if( body->getHealth() == body->getMaxHealth() )
return FALSE;
// if the target is in the shroud, we can't do anything
if (isObjectShroudedForAction(obj, repairDest, commandSource))
return FALSE;
// all is well, we can be repaired here
return TRUE;
}
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
// note that "dest" is typically a building...
Bool ActionManager::canTransferSuppliesAt( const Object *obj, const Object *transferDest )
{
// sanity
if( obj == nullptr || transferDest == nullptr )
return FALSE;
if( transferDest->isEffectivelyDead() )
{
return FALSE;
}
// nothing can be done with things that are under construction
if( obj->getStatusBits().test( OBJECT_STATUS_UNDER_CONSTRUCTION ) ||
transferDest->getStatusBits().test( OBJECT_STATUS_UNDER_CONSTRUCTION ) )
return FALSE;
// Can't transfer at something being sold
if( transferDest->testStatus(OBJECT_STATUS_SOLD) )
return FALSE;
// I must be something with a Supply Transferring AI interface
const AIUpdateInterface *ai= obj->getAI();
if( ai == nullptr )
return FALSE;
const SupplyTruckAIInterface* supplyTruck = ai->getSupplyTruckAIInterface();
if( supplyTruck == nullptr )
return FALSE;
// If it is a warehouse, it must have boxes left and not be an enemy
static const NameKeyType key_warehouseUpdate = NAMEKEY("SupplyWarehouseDockUpdate");
SupplyWarehouseDockUpdate *warehouseModule = (SupplyWarehouseDockUpdate*)transferDest->findUpdateModule( key_warehouseUpdate );
if( warehouseModule )
if( warehouseModule->getBoxesStored() == 0 || transferDest->getRelationship( obj ) == ENEMIES )
return FALSE;
// if it is a supply center, I must have boxes, and must be controlled by the same player
// (not merely an ally... otherwise you may find yourself funding your allies. ick.)
static const NameKeyType key_centerUpdate = NAMEKEY("SupplyCenterDockUpdate");
SupplyCenterDockUpdate *centerModule = (SupplyCenterDockUpdate*)transferDest->findUpdateModule( key_centerUpdate );
if( centerModule )
if( supplyTruck->getNumberBoxes() == 0 || transferDest->getControllingPlayer() != obj->getControllingPlayer() )
return FALSE;
// if he is not a warehouse or a center, then shut the hell up
if( (warehouseModule == nullptr) && (centerModule == nullptr) )
return FALSE;
// We do not check ClearToApproach, as it is a temporary failure that is handled
// in the state logic. This function is for Legality, not conditionals.
// however, we DO check for the unit to be available (cf Chinook) (srj)
if (!supplyTruck->isAvailableForSupplying())
return FALSE;
// if the target is in the shroud, we can't do anything
// if (isObjectShroudedForAction(obj, transferDest))
// return FALSE;
//Commented out to show it is an intentional difference to most commands.
// Fogged is okay for player, and anything is okay for AI.
Player *objPlayer = obj->getControllingPlayer();
if( objPlayer )
{
if( objPlayer->getPlayerType() == PLAYER_HUMAN &&
transferDest->getShroudedStatus( objPlayer->getPlayerIndex() ) == OBJECTSHROUD_SHROUDED )
{
return FALSE;
}
}
// all is well, we can transfer here
return TRUE;
}
// ------------------------------------------------------------------------------------------------
/** Can object 'obj' dock with object 'dockDest' for any reason */
// ------------------------------------------------------------------------------------------------
Bool ActionManager::canDockAt( const Object *obj, const Object *dockDest, CommandSourceType commandSource )
{
// look for a dock interface
DockUpdateInterface *di = nullptr;
for (BehaviorModule **u = dockDest->getBehaviorModules(); *u; ++u)
{
if ((di = (*u)->getDockUpdateInterface()) != nullptr)
break;
}
if( di == nullptr )
return FALSE; // no dock update interface, can't possibly dock
/*
// can't dock if the dock is closed
if( di->isDockOpen() == FALSE )
return FALSE;
*/
// transferring supplies is a valid docking action
if( canTransferSuppliesAt( obj, dockDest ) == TRUE )
return TRUE;
// units and infantry can dock with a railed transport
static const NameKeyType key = NAMEKEY( "RailedTransportDockUpdate" );
RailedTransportDockUpdate *fdu = (RailedTransportDockUpdate *)dockDest->findUpdateModule( key );
if( fdu )
{
if( obj->isKindOf( KINDOF_VEHICLE ) || obj->isKindOf( KINDOF_INFANTRY ) )
return TRUE;
}
// cannot dock
return FALSE;
}
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
Bool ActionManager::canGetHealedAt( const Object *obj, const Object *healDest, CommandSourceType commandSource )
{
// sanity
if( obj == nullptr || healDest == nullptr )
return FALSE;
Relationship r = obj->getRelationship(healDest);
// only available by our allies
if( r != ALLIES )
return FALSE;
// dead objects cannot be healed
if( healDest->isEffectivelyDead() )
return FALSE;
// nothing can be done with things that are under construction
if( obj->getStatusBits().test( OBJECT_STATUS_UNDER_CONSTRUCTION ) ||
healDest->getStatusBits().test( OBJECT_STATUS_UNDER_CONSTRUCTION ) )
return FALSE;
// Can't get healed at something being sold
if( healDest->testStatus(OBJECT_STATUS_SOLD) )
return FALSE;
// only infantry can go get "healed" somewhere (vehicles get "repaired")
if( obj->isKindOf( KINDOF_INFANTRY ) == FALSE )
return FALSE;
// infantry can only be healed at something that is designated as a heal pad
if( healDest->isKindOf( KINDOF_HEAL_PAD ) == FALSE )
return FALSE;
// if the target is in the shroud, we can't do anything
if (isObjectShroudedForAction(obj, healDest, commandSource))
return FALSE;
BodyModuleInterface *body = obj->getBodyModule();
if( body && body->getHealth() == body->getMaxHealth() )
{
//No point in healing if you have full health!
return FALSE;
}
// all is well, we can be healed here
return TRUE;
}
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
Bool ActionManager::canRepairObject( const Object *obj, const Object *objectToRepair, CommandSourceType commandSource )
{
// sanity
if( obj == nullptr || objectToRepair == nullptr )
return FALSE;
Relationship r = obj->getRelationship(objectToRepair);
// you can only repair allies, we ignore this restriction for bridges
// srj sez: nope, allow neutral too, so civ bldgs can be repaired
// GS repairing bridges cut 12/12/02 , so this check is just no to enemies
if( r == ENEMIES )
return FALSE;
//
// can't repair dead things ... the exception is bridges and bridge towers, which can
// be destroyed and die, but can be repaired to bring the bring "back to life"
//
// GS and again, repairing bridges is cut, so this is just a dead check
if( objectToRepair->isEffectivelyDead() )
{
return FALSE;
}
//GS So here's the ensuring that they can't be repaired
if( objectToRepair->isKindOf(KINDOF_BRIDGE) || objectToRepair->isKindOf(KINDOF_BRIDGE_TOWER) )
return FALSE;
// nothing can be done with things that are under construction
if( obj->getStatusBits().test( OBJECT_STATUS_UNDER_CONSTRUCTION ) ||
objectToRepair->getStatusBits().test( OBJECT_STATUS_UNDER_CONSTRUCTION ) )
return FALSE;
// we cannot manually repair things that are regeneration holes
if( objectToRepair->isKindOf( KINDOF_REBUILD_HOLE ) == TRUE )
return FALSE;
// only Dozers can go repair things
if( obj->isKindOf( KINDOF_DOZER ) == FALSE )
return FALSE;
// dozers can only repair buildings
if( objectToRepair->isKindOf( KINDOF_STRUCTURE ) == FALSE )
return FALSE;
// get the body module from the object to repair
BodyModuleInterface *body = objectToRepair->getBodyModule();
// buildings that are at full health cannot be repaired
if( body->getHealth() == body->getMaxHealth() )
return FALSE;
// if the target is in the shroud, we can't do anything
if (isObjectShroudedForAction(obj, objectToRepair, commandSource))
return FALSE;
if( obj->getContainedBy() )
{
// We can't heal things while in a transport (especially our own transport, you cheater)
return FALSE;
}
return TRUE;
}
// ------------------------------------------------------------------------------------------------
/** Can 'obj' resume the construction of 'objectBeingConstructed' */
// ------------------------------------------------------------------------------------------------
Bool ActionManager::canResumeConstructionOf( const Object *obj,
const Object *objectBeingConstructed,
CommandSourceType commandSource )
{
// sanity
if( obj == nullptr || objectBeingConstructed == nullptr )
return FALSE;
// only dozers or workers can resume construction of things
if( obj->isKindOf( KINDOF_DOZER ) == FALSE )
return FALSE;
// TheSuperHackers @bugfix Stubbjax 06/01/2026 Ensure only the owner of the construction can resume it.
#if RETAIL_COMPATIBLE_CRC
Relationship r = obj->getRelationship(objectBeingConstructed);
// only available to our allies
if( r != ALLIES )
return FALSE;
#else
if (obj->getControllingPlayer() != objectBeingConstructed->getControllingPlayer())
return FALSE;
#endif
// if the objectBeingConstructed is not actually under construction we can't resume that!
if( !objectBeingConstructed->getStatusBits().test( OBJECT_STATUS_UNDER_CONSTRUCTION ) )
return FALSE;
// dead things can do nothing
if( obj->isEffectivelyDead() )
{
return FALSE;
}
//
// if the object being constructed is actively being built by another dozer we cannot
// add more effectiveness to the construction so we'll say no (this might change for workers
// in the future)
//
Object *builder = TheGameLogic->findObjectByID( objectBeingConstructed->getBuilderID() );
#if RETAIL_COMPATIBLE_CRC
if( builder )
#else
// TheSuperHackers @bugfix Stubbjax 18/11/2025 Allow scaffold to be immediately resumed after builder death.
if (builder && !builder->isEffectivelyDead())
#endif
{
AIUpdateInterface *ai = builder->getAI();
DEBUG_ASSERTCRASH( ai, ("Builder object does not have an AI interface!") );
if( ai )
{
DozerAIInterface *dozerAI = ai->getDozerAIInterface();
DEBUG_ASSERTCRASH( dozerAI, ("Builder object doest not have a DozerAI interface!") );
if( dozerAI )
{
if( dozerAI->getCurrentTask() == DOZER_TASK_BUILD &&
dozerAI->getTaskTarget( DOZER_TASK_BUILD ) == objectBeingConstructed->getID() )
return FALSE;
}
}
}
// if the target is in the shroud, we can't do anything
if (isObjectShroudedForAction(obj, objectBeingConstructed, commandSource))
return FALSE;
//
// all is well, the objectBeingConstructeds' builder object has gone away or is no longer
// building the object anymore
//
return TRUE;
}
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
Bool ActionManager::canEnterObject( const Object *obj, const Object *objectToEnter, CommandSourceType commandSource, CanEnterType mode )
{
// sanity
if( obj == nullptr || objectToEnter == nullptr )
return FALSE;
if( obj == objectToEnter )
{
//You can't contain yourself (crash fix for pow truck reselection)
return FALSE;
}
// can't enter dead things
if( objectToEnter->isEffectivelyDead() )
return FALSE;
// if the target is in the shroud, we can't do anything
if (isObjectShroudedForAction(obj, objectToEnter, commandSource))
return FALSE;
// nothing can be done with things that are under construction
if( obj->getStatusBits().test( OBJECT_STATUS_UNDER_CONSTRUCTION ) ||
objectToEnter->getStatusBits().test( OBJECT_STATUS_UNDER_CONSTRUCTION ) )
{
return FALSE;
}
// Can't enter something being sold
if( objectToEnter->testStatus(OBJECT_STATUS_SOLD) )
return FALSE;
if ( obj->isKindOf( KINDOF_IGNORED_IN_GUI ) //As in, Angry Mob Members, Cargo Planes
|| obj->isKindOf( KINDOF_MOB_NEXUS )
|| objectToEnter->isKindOf( KINDOF_IGNORED_IN_GUI ) ) // As in Cargo Planes
{
return FALSE;
}
if (objectToEnter->isDisabledByType( DISABLED_SUBDUED ))
return FALSE; // a microwave tank has soldered the doors shut
if( obj->isKindOf( KINDOF_STRUCTURE ) || obj->isKindOf( KINDOF_IMMOBILE ) )
{
//Structures or immobiles can't garrison
return FALSE;
}
// Special case for unmanned vehicles. Any infantry unit can take over any unmanned vehicle!
if( obj->isKindOf( KINDOF_INFANTRY ) && objectToEnter->isDisabledByType( DISABLED_UNMANNED ) )
{
if( !obj->isKindOf( KINDOF_REJECT_UNMANNED ) )
{
//But only if it's allowed to.
return TRUE;
}
}
// Special case for aircraft.
if( obj->isKindOf( KINDOF_AIRCRAFT ) && objectToEnter->isKindOf( KINDOF_FS_AIRFIELD ) )
{
if( obj->getStatusBits().test( OBJECT_STATUS_DECK_HEIGHT_OFFSET ) && obj->getCarrierDeckHeight() >= obj->getPosition()->z )
{
return FALSE;
}
if (!obj->isAboveTerrain())
return FALSE;
if( obj->getControllingPlayer() == objectToEnter->getControllingPlayer() )
{
//Kris -- added code to prevent aircraft from landing in any airstrips other than their own!
/// @todo srj -- this is horrible, but expedient.
for (BehaviorModule** i = objectToEnter->getBehaviorModules(); *i; ++i)
{
ParkingPlaceBehaviorInterface* pp = (*i)->getParkingPlaceBehaviorInterface();
if (pp == nullptr)
continue;
if (pp->hasReservedSpace(obj->getID()))
return TRUE;
if (pp->shouldReserveDoorWhenQueued(obj->getTemplate()) && pp->hasAvailableSpaceFor(obj->getTemplate()))
return TRUE;
}
}
return FALSE;
}
// first, see if we'd like to collide with 'other'
for (BehaviorModule** m = obj->getBehaviorModules(); *m; ++m)
{
CollideModuleInterface* collide = (*m)->getCollide();
if (!collide)
continue;
if( collide->wouldLikeToCollideWith( objectToEnter ) )
{
//I thought this was a little confusing that it would return TRUE here before
//getting to any of the other checks. The key is that it usually doesn't return
//TRUE because most things aren't trying to collide with objects. This is different
//for terrorist converting carbombs, and pilots entering vehicles. In these cases,
//the vehicles don't have transport capacities, therefore returning true here
//foregoes that checking later on.
return TRUE;
}
}
#ifdef ALLOW_SURRENDER
if( objectToEnter->isKindOf( KINDOF_PRISON ) )
{
//We can't manually enter a prison!
return FALSE;
}
#endif
#ifdef ALLOW_SURRENDER
if( objectToEnter->isKindOf( KINDOF_POW_TRUCK ) )
{
//We can't manually enter POWTruck, either!
return FALSE;
}
#endif
// make sure our objectToEnter has a contain module.
ContainModuleInterface *contain = objectToEnter->getContain();
if( !contain )
{
return FALSE;
}
if( contain->isHealContain() )
{
BodyModuleInterface *body = obj->getBodyModule();
if( body->getHealth() == body->getMaxHealth() )
{
//This container is only used for the purposes of healing and we cannot
//enter it with full health. This is not a normal container.
return FALSE;
}
}
if (mode == COMBATDROP_INTO)
{
// we don't care about valid container-ness, but we DO care about faction structures...
// we aren't allowed to combat drop into them
if (objectToEnter->isFactionStructure())
return FALSE;
}
else
{
Bool checkCapacity = (mode == CHECK_CAPACITY);
Int containCount = contain->getContainCount();
Int stealthContainCount = contain->getStealthUnitsContained();
Int nonStealthContainCount = containCount - stealthContainCount;
// not ours... must do special checks.
if (objectToEnter->getControllingPlayer() != obj->getControllingPlayer())
{
// not empty... can't do it.
if (nonStealthContainCount > 0)
return FALSE;
// faction structure... can't do it.
if (objectToEnter->isFactionStructure())
return FALSE;
// it's stealth-garrisoned... ignore check-cap and fall thru to
// normal isValid test.
if (stealthContainCount > 0 && nonStealthContainCount == 0)
checkCapacity = FALSE;
}
// if our transport slot count is zero, we can't be transported. so punt.
/// @todo srj -- seems like we should check always (not just for checkCap), but scared to change now -- check later
if( checkCapacity && obj->getTransportSlotCount() == 0 )
{
return FALSE;
}
// finally: make sure that objectToEnter is a valid container for obj
if( contain->isValidContainerFor( obj, checkCapacity ) == FALSE )
{
return FALSE;
}
}
return TRUE;
}
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
CanAttackResult ActionManager::getCanAttackObject( const Object *obj, const Object *objectToAttack, CommandSourceType commandSource, AbleToAttackType attackType )
{
// sanity
if( !obj || !objectToAttack || obj->isEffectivelyDead() || objectToAttack->isEffectivelyDead() || objectToAttack == obj )
{
return ATTACKRESULT_NOT_POSSIBLE;
}
if( !obj->isAbleToAttack() )
{
return ATTACKRESULT_NOT_POSSIBLE;
}
//has any weapons that are capable of inflicting damage. Special damage types are rejected
//such as hack weapons... others can be added.
CanAttackResult result = obj->getAbleToAttackSpecificObject( attackType, objectToAttack, commandSource );
if( result != ATTACKRESULT_NOT_POSSIBLE )
{
//Kris: August 5, 2003
//Fix a case where the Demo_GLAInfantryWorker is able to attack using his passive bomb upgrade. We don't
//want him to allow a visible attack cursor for the player. This code never checked for AutoChoosesSources
//logic, but now we will but only when the commandSource is FROM_PLAYER.
if( commandSource == CMD_FROM_PLAYER )
{
//Check if it's got any weapons that can be used.
Bool anyValidWeapon = FALSE;
for( Int i = 0; i < WEAPONSLOT_COUNT; i++ )
{
UnsignedInt cmdSourceMask = obj->getWeaponInWeaponSlotCommandSourceMask( (WeaponSlotType)i );
if( cmdSourceMask )
{
anyValidWeapon = TRUE;
break;
}
}
if( !anyValidWeapon )
{
return ATTACKRESULT_NOT_POSSIBLE;
}
}
if( result == ATTACKRESULT_INVALID_SHOT && obj->isKindOf( KINDOF_DOZER ) )
{
//For the case of dozers, we don't ever want to see an attack cursor
//unless it's valid on a mine.
const Weapon *weapon = obj->getCurrentWeapon();
if( weapon && weapon->getDamageType() == DAMAGE_DISARM )
{
return ATTACKRESULT_NOT_POSSIBLE;
}
}
return result;
}
//Special case code for stinger sites: Stinger sites have no weapons, instead -- their spawns are the weapons, in this case the
//stinger soldiers.
if( obj->isKindOf( KINDOF_SPAWNS_ARE_THE_WEAPONS ) )
{
//Look at the spawn behavior and evaluate them!
SpawnBehaviorInterface *spawnInterface = obj->getSpawnBehaviorInterface();
if( spawnInterface )
{
//We found the spawn interface, now get the closest slave to the target.
Object *slave = spawnInterface->getClosestSlave( objectToAttack->getPosition() );
if( slave )
{
result = slave->getAbleToAttackSpecificObject( attackType, objectToAttack, commandSource );
if( result != ATTACKRESULT_NOT_POSSIBLE )
{
return result;
}
}
}
else if( result == ATTACKRESULT_NOT_POSSIBLE )// oh dear me. The weird case of a garrisoncontainer being a KINDOF_SPAWNS_ARE_THE_WEAPONS... the AmericaBuildingFirebase
{
ContainModuleInterface *contain = obj->getContain();
if ( contain )
{
Object *rider = contain->getClosestRider( objectToAttack->getPosition() );
if ( rider )
{
result = rider->getAbleToAttackSpecificObject( attackType, objectToAttack, commandSource );
if( result != ATTACKRESULT_NOT_POSSIBLE )
return result;
}
}
}
}
return ATTACKRESULT_NOT_POSSIBLE;
}
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
Bool ActionManager::canConvertObjectToCarBomb( const Object *obj, const Object *objectToConvert, CommandSourceType commandSource )
{
// sanity
if( obj == nullptr || objectToConvert == nullptr )
{
return FALSE;
}
if( objectToConvert->isEffectivelyDead() )
{
return FALSE;
}
// if the target is in the shroud, we can't do anything
if (isObjectShroudedForAction(obj, objectToConvert, commandSource))
return FALSE;
// first, see if we'd like to collide with 'other'
for (BehaviorModule** m = obj->getBehaviorModules(); *m; ++m)
{
CollideModuleInterface* collide = (*m)->getCollide();
if (!collide)
continue;
if( collide->wouldLikeToCollideWith( objectToConvert ) && collide->isCarBombCrateCollide() )
{
return TRUE;
}
}
return FALSE;
}
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
Bool ActionManager::canHijackVehicle( const Object *obj, const Object *objectToHijack, CommandSourceType commandSource ) //LORENZEN
{
// sanity
if( obj == nullptr || objectToHijack == nullptr )
{
return FALSE;
}
//Make sure it's alive.
if( objectToHijack->isEffectivelyDead() )
{
return FALSE;
}
// if the target is in the shroud, we can't do anything
if (isObjectShroudedForAction(obj, objectToHijack, commandSource))
{
return FALSE;
}
Relationship r = obj->getRelationship(objectToHijack);
//Only hijack enemy objects
if( r != ENEMIES )
{
return FALSE;
}
//Make sure target is a vehicle.
if( ! objectToHijack->isKindOf( KINDOF_VEHICLE ) )
{
return FALSE;
}
//Kris -- Hijackers can no longer hijack any aircraft.
if( objectToHijack->isKindOf( KINDOF_AIRCRAFT ) )
{
return FALSE;
}
//Can't hijack a drone type.
if( objectToHijack->isKindOf( KINDOF_DRONE ) )
{
return FALSE;
}
// last, see if we'd like to collide with 'objectToHijack'
for (BehaviorModule** m = obj->getBehaviorModules(); *m; ++m)
{
CollideModuleInterface* collide = (*m)->getCollide();
if (!collide)
continue;
if( collide->wouldLikeToCollideWith( objectToHijack ) && collide->isHijackedVehicleCrateCollide() )
{
return TRUE;
}
}
return FALSE;
}
// ------------------------------------------------------------------------------------------------
Bool ActionManager::canSabotageBuilding( const Object *obj, const Object *objectToSabotage, CommandSourceType commandSource )
{
// sanity
if( obj == nullptr || objectToSabotage == nullptr )
{
return FALSE;
}
//Make sure it's alive.
if( objectToSabotage->isEffectivelyDead() )
{
return FALSE;
}
// if the target is in the shroud, we can't do anything
if (isObjectShroudedForAction(obj, objectToSabotage, commandSource))
{
return FALSE;
}
Relationship r = obj->getRelationship(objectToSabotage);
//Only sabotage enemy objects
if( r != ENEMIES )
{
return FALSE;
}
// last, see if we'd like to collide with 'objectToSabotage'
for (BehaviorModule** m = obj->getBehaviorModules(); *m; ++m)
{
CollideModuleInterface* collide = (*m)->getCollide();
if (!collide)
continue;
if( collide->wouldLikeToCollideWith( objectToSabotage ) && collide->isSabotageBuildingCrateCollide() )
{
return TRUE;
}
}
return FALSE;
}
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
Bool ActionManager::canMakeObjectDefector( const Object *obj, const Object *objectToMakeDefector, CommandSourceType commandSource ) //LORENZEN
{
// sanity
if( obj == nullptr || objectToMakeDefector == nullptr )
{
return FALSE;
}
Relationship r = obj->getRelationship(objectToMakeDefector);
//Only make defectors of enemy objects
if( r != ENEMIES )
{
return FALSE;
}
//Make sure it's alive.
if( objectToMakeDefector->isEffectivelyDead() )
{
return FALSE;
}
// if the target is in the shroud, we can't do anything
if (isObjectShroudedForAction(obj, objectToMakeDefector, commandSource))
{
return FALSE;
}
return TRUE;
}
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------