ActionManager.cpp 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875
  1. /*
  2. ** Command & Conquer Generals(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: ActionManager.cpp ////////////////////////////////////////////////////////////////////////
  24. // Author: Colin Day
  25. // Desc: TheActionManager is a convenient place for us to wrap up all sorts of logical
  26. // queries about what objects can do in the world and to other objects. The purpose
  27. // of having a central place for this logic assists us in making these logical kind
  28. // of queries in the user interface and allows us to use the same code to validate
  29. // commands as they come in over the network interface in order to do the
  30. // real action.
  31. ///////////////////////////////////////////////////////////////////////////////////////////////////
  32. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  33. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  34. #include "Common/ActionManager.h"
  35. #include "Common/GlobalData.h"
  36. #include "Common/Player.h"
  37. #include "Common/PlayerList.h"
  38. #include "Common/SpecialPower.h"
  39. #include "Common/Team.h"
  40. #include "Common/ThingTemplate.h"
  41. #include "GameClient/Drawable.h"
  42. #include "GameClient/InGameUI.h"
  43. #include "GameLogic/Object.h"
  44. #include "GameLogic/PartitionManager.h"
  45. #include "GameLogic/Module/BodyModule.h"
  46. #include "GameLogic/Module/ContainModule.h"
  47. #include "GameLogic/Module/CollideModule.h"
  48. #include "GameLogic/Module/DozerAIUpdate.h"
  49. #include "GameLogic/Module/RailroadGuideAIUpdate.h"
  50. #include "GameLogic/Module/RailedTransportDockUpdate.h"
  51. #include "GameLogic/Module/SpawnBehavior.h"
  52. #include "GameLogic/Module/SupplyTruckAIUpdate.h"
  53. #include "GameLogic/Module/SupplyCenterDockUpdate.h"
  54. #include "GameLogic/Module/SupplyWarehouseDockUpdate.h"
  55. #include "GameLogic/Module/SpecialPowerModule.h"
  56. #include "GameLogic/Module/SpecialAbilityUpdate.h"
  57. #include "GameLogic/Weapon.h"
  58. #include "GameLogic/ExperienceTracker.h"//LORENZEN
  59. #ifdef _INTERNAL
  60. // for occasional debugging...
  61. //#pragma optimize("", off)
  62. //#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
  63. #endif
  64. // GLOBAL /////////////////////////////////////////////////////////////////////////////////////////
  65. ActionManager *TheActionManager = NULL;
  66. // LOCAL //////////////////////////////////////////////////////////////////////////////////////////
  67. // ------------------------------------------------------------------------------------------------
  68. // ------------------------------------------------------------------------------------------------
  69. static Bool appearsToContainFriendlies(const Object* obj, const Object* otherObject)
  70. {
  71. // check if the object is a container containing stealth units tricking
  72. // the player into thinking it isn't actually an enemy.
  73. const ContainModuleInterface *otherContain = otherObject->getContain();
  74. if( otherContain )
  75. {
  76. const Player *otherPlayer = otherContain->getApparentControllingPlayer(obj->getControllingPlayer());
  77. // if( otherPlayer && otherPlayer->getRelationship( obj->getTeam() ) != ENEMIES )
  78. // the above test is wrong; we want to know how WE consider THEM, not how THEY consider US
  79. if (otherPlayer && obj->getTeam()->getRelationship(otherPlayer->getDefaultTeam()) != ENEMIES)
  80. {
  81. return TRUE;
  82. }
  83. }
  84. return FALSE;
  85. }
  86. // ------------------------------------------------------------------------------------------------
  87. // ------------------------------------------------------------------------------------------------
  88. static Bool isObjectShroudedForAction ( const Object *source, const Object *target, CommandSourceType commandSource )
  89. {
  90. /// @todo - reenable this when we can avoid breaking scripted actions.
  91. // In order to support ai and scripted actions in singler player, we have to disable this for now.
  92. // We can re-enable it when we can tell that this is a player generated action. jba.
  93. // return false;
  94. // GS Keeping this comment to show we now have commandSource, so everything should be fine again.
  95. // The target is only shrouded for action if...
  96. // the asking player is human
  97. // the asking impetus is not from a script
  98. // and the target object is Fogged or worse
  99. if( source && target && source->getControllingPlayer() )
  100. {
  101. if( source->getControllingPlayer()->getPlayerType() == PLAYER_HUMAN
  102. && commandSource != CMD_FROM_SCRIPT
  103. && target->getShroudedStatus( source->getControllingPlayer()->getPlayerIndex() ) >= OBJECTSHROUD_FOGGED
  104. )
  105. {
  106. return TRUE;
  107. }
  108. }
  109. return FALSE;
  110. }
  111. ///////////////////////////////////////////////////////////////////////////////////////////////////
  112. // ------------------------------------------------------------------------------------------------
  113. // ------------------------------------------------------------------------------------------------
  114. ActionManager::ActionManager( void )
  115. {
  116. } // end ActionManager
  117. // ------------------------------------------------------------------------------------------------
  118. // ------------------------------------------------------------------------------------------------
  119. ActionManager::~ActionManager( void )
  120. {
  121. } // end ~ActionManager
  122. // ------------------------------------------------------------------------------------------------
  123. // ------------------------------------------------------------------------------------------------
  124. Bool ActionManager::canGetRepairedAt( const Object *obj, const Object *repairDest, CommandSourceType commandSource )
  125. {
  126. // sanity
  127. if( obj == NULL || repairDest == NULL )
  128. return FALSE;
  129. Relationship r = obj->getRelationship(repairDest);
  130. // only available by our allies
  131. if( r != ALLIES )
  132. return FALSE;
  133. // dead objects cannot be repaired
  134. if( obj->isEffectivelyDead() )
  135. return FALSE;
  136. // nothing can be done with things that are under construction
  137. if( BitTest( obj->getStatusBits(), OBJECT_STATUS_UNDER_CONSTRUCTION ) == TRUE ||
  138. BitTest( repairDest->getStatusBits(), OBJECT_STATUS_UNDER_CONSTRUCTION ) == TRUE )
  139. return FALSE;
  140. // Can't get repaired at something being sold
  141. if( repairDest->testStatus(OBJECT_STATUS_SOLD) )
  142. return FALSE;
  143. // only vehicles can go get repaired at something
  144. if( obj->isKindOf( KINDOF_VEHICLE ) == FALSE )
  145. return FALSE;
  146. // vehicles can only be repaired at something that is designated as a repair pad
  147. if (obj->isKindOf( KINDOF_AIRCRAFT ))
  148. {
  149. // aircraft require an airfield.
  150. if( !obj->isAboveTerrain() ||
  151. repairDest->isKindOf( KINDOF_AIRFIELD ) == FALSE )
  152. return FALSE;
  153. }
  154. else
  155. {
  156. if( repairDest->isKindOf( KINDOF_REPAIR_PAD ) == FALSE )
  157. return FALSE;
  158. }
  159. // if I am at full health, I can't get repair there
  160. BodyModuleInterface *body = obj->getBodyModule();
  161. if( body->getHealth() == body->getMaxHealth() )
  162. return FALSE;
  163. // if the target is in the shroud, we can't do anything
  164. if (isObjectShroudedForAction(obj, repairDest, commandSource))
  165. return FALSE;
  166. // all is well, we can be repaired here
  167. return TRUE;
  168. } // end canGetRepairedAt
  169. // ------------------------------------------------------------------------------------------------
  170. // ------------------------------------------------------------------------------------------------
  171. // note that "dest" is typically a building...
  172. Bool ActionManager::canTransferSuppliesAt( const Object *obj, const Object *transferDest )
  173. {
  174. // sanity
  175. if( obj == NULL || transferDest == NULL )
  176. return FALSE;
  177. if( transferDest->isEffectivelyDead() )
  178. {
  179. return FALSE;
  180. }
  181. // nothing can be done with things that are under construction
  182. if( BitTest( obj->getStatusBits(), OBJECT_STATUS_UNDER_CONSTRUCTION ) == TRUE ||
  183. BitTest( transferDest->getStatusBits(), OBJECT_STATUS_UNDER_CONSTRUCTION ) == TRUE )
  184. return FALSE;
  185. // Can't transfer at something being sold
  186. if( transferDest->testStatus(OBJECT_STATUS_SOLD) )
  187. return FALSE;
  188. // I must be something with a Supply Transfering AI interface
  189. const AIUpdateInterface *ai= obj->getAI();
  190. if( ai == NULL )
  191. return FALSE;
  192. const SupplyTruckAIInterface* supplyTruck = ai->getSupplyTruckAIInterface();
  193. if( supplyTruck == NULL )
  194. return FALSE;
  195. // If it is a warehouse, it must have boxes left and not be an enemy
  196. static const NameKeyType key_warehouseUpdate = NAMEKEY("SupplyWarehouseDockUpdate");
  197. SupplyWarehouseDockUpdate *warehouseModule = (SupplyWarehouseDockUpdate*)transferDest->findUpdateModule( key_warehouseUpdate );
  198. if( warehouseModule )
  199. if( warehouseModule->getBoxesStored() == 0 || transferDest->getRelationship( obj ) == ENEMIES )
  200. return FALSE;
  201. // if it is a supply center, I must have boxes, and must be controlled by the same player
  202. // (not merely an ally... otherwise you may find yourself funding your allies. ick.)
  203. static const NameKeyType key_centerUpdate = NAMEKEY("SupplyCenterDockUpdate");
  204. SupplyCenterDockUpdate *centerModule = (SupplyCenterDockUpdate*)transferDest->findUpdateModule( key_centerUpdate );
  205. if( centerModule )
  206. if( supplyTruck->getNumberBoxes() == 0 || transferDest->getControllingPlayer() != obj->getControllingPlayer() )
  207. return FALSE;
  208. // if he is not a warehouse or a center, then shut the hell up
  209. if( (warehouseModule == NULL) && (centerModule == NULL) )
  210. return FALSE;
  211. // We do not check ClearToApproach, as it is a temporary failure that is handled
  212. // in the state logic. This function is for Legality, not conditionals.
  213. // however, we DO check for the unit to be available (cf Chinook) (srj)
  214. if (!supplyTruck->isAvailableForSupplying())
  215. return FALSE;
  216. // if the target is in the shroud, we can't do anything
  217. // if (isObjectShroudedForAction(obj, transferDest))
  218. // return FALSE;
  219. //Commented out to show it is an intentional difference to most commands.
  220. // Fogged is okay for player, and anything is okay for AI.
  221. Player *objPlayer = obj->getControllingPlayer();
  222. if( objPlayer )
  223. {
  224. if( objPlayer->getPlayerType() == PLAYER_HUMAN &&
  225. transferDest->getShroudedStatus( objPlayer->getPlayerIndex() ) == OBJECTSHROUD_SHROUDED )
  226. {
  227. return FALSE;
  228. }
  229. }
  230. // all is well, we can transfer here
  231. return TRUE;
  232. }
  233. // ------------------------------------------------------------------------------------------------
  234. /** Can object 'obj' dock with object 'dockDest' for any reason */
  235. // ------------------------------------------------------------------------------------------------
  236. Bool ActionManager::canDockAt( const Object *obj, const Object *dockDest, CommandSourceType commandSource )
  237. {
  238. // look for a dock interface
  239. DockUpdateInterface *di = NULL;
  240. for (BehaviorModule **u = dockDest->getBehaviorModules(); *u; ++u)
  241. {
  242. if ((di = (*u)->getDockUpdateInterface()) != NULL)
  243. break;
  244. }
  245. if( di == NULL )
  246. return FALSE; // no dock update interface, can't possibly dock
  247. /*
  248. // can't dock if the dock is closed
  249. if( di->isDockOpen() == FALSE )
  250. return FALSE;
  251. */
  252. // transferring supplies is a valid docking action
  253. if( canTransferSuppliesAt( obj, dockDest ) == TRUE )
  254. return TRUE;
  255. // units and infantry can dock with a railed transport
  256. static const NameKeyType key = NAMEKEY( "RailedTransportDockUpdate" );
  257. RailedTransportDockUpdate *fdu = (RailedTransportDockUpdate *)dockDest->findUpdateModule( key );
  258. if( fdu )
  259. {
  260. if( obj->isKindOf( KINDOF_VEHICLE ) || obj->isKindOf( KINDOF_INFANTRY ) )
  261. return TRUE;
  262. } // end if
  263. // cannot dock
  264. return FALSE;
  265. } // end canDockAt
  266. // ------------------------------------------------------------------------------------------------
  267. // ------------------------------------------------------------------------------------------------
  268. Bool ActionManager::canGetHealedAt( const Object *obj, const Object *healDest, CommandSourceType commandSource )
  269. {
  270. // sanity
  271. if( obj == NULL || healDest == NULL )
  272. return FALSE;
  273. Relationship r = obj->getRelationship(healDest);
  274. // only available by our allies
  275. if( r != ALLIES )
  276. return FALSE;
  277. // dead objects cannot be healed
  278. if( healDest->isEffectivelyDead() )
  279. return FALSE;
  280. // nothing can be done with things that are under construction
  281. if( BitTest( obj->getStatusBits(), OBJECT_STATUS_UNDER_CONSTRUCTION ) == TRUE ||
  282. BitTest( healDest->getStatusBits(), OBJECT_STATUS_UNDER_CONSTRUCTION ) == TRUE )
  283. return FALSE;
  284. // Can't get healed at something being sold
  285. if( healDest->testStatus(OBJECT_STATUS_SOLD) )
  286. return FALSE;
  287. // only infantry can go get "healed" somewhere (vehicles get "repaired")
  288. if( obj->isKindOf( KINDOF_INFANTRY ) == FALSE )
  289. return FALSE;
  290. // infantry can only be healed at something that is designated as a heal pad
  291. if( healDest->isKindOf( KINDOF_HEAL_PAD ) == FALSE )
  292. return FALSE;
  293. // if the target is in the shroud, we can't do anything
  294. if (isObjectShroudedForAction(obj, healDest, commandSource))
  295. return FALSE;
  296. BodyModuleInterface *body = obj->getBodyModule();
  297. if( body && body->getHealth() == body->getMaxHealth() )
  298. {
  299. //No point in healing if you have full health!
  300. return FALSE;
  301. }
  302. // all is well, we can be healed here
  303. return TRUE;
  304. } // end canGetHealedAt
  305. // ------------------------------------------------------------------------------------------------
  306. // ------------------------------------------------------------------------------------------------
  307. Bool ActionManager::canRepairObject( const Object *obj, const Object *objectToRepair, CommandSourceType commandSource )
  308. {
  309. // sanity
  310. if( obj == NULL || objectToRepair == NULL )
  311. return FALSE;
  312. Relationship r = obj->getRelationship(objectToRepair);
  313. // you can only repair allies, we ignore this restriction for bridges
  314. // srj sez: nope, allow neutral too, so civ bldgs can be repaired
  315. // GS repairing bridges cut 12/12/02 , so this check is just no to enemies
  316. if( r == ENEMIES )
  317. return FALSE;
  318. //
  319. // can't repair dead things ... the exception is bridges and bridge towers, which can
  320. // be destroyed and die, but can be repaired to bring the bring "back to life"
  321. //
  322. // GS and again, repairing bridges is cut, so this is just a dead check
  323. if( objectToRepair->isEffectivelyDead() )
  324. {
  325. return FALSE;
  326. }
  327. //GS So here's the ensuring that they can't be repaired
  328. if( objectToRepair->isKindOf(KINDOF_BRIDGE) || objectToRepair->isKindOf(KINDOF_BRIDGE_TOWER) )
  329. return FALSE;
  330. // nothing can be done with things that are under construction
  331. if( BitTest( obj->getStatusBits(), OBJECT_STATUS_UNDER_CONSTRUCTION ) == TRUE ||
  332. BitTest( objectToRepair->getStatusBits(), OBJECT_STATUS_UNDER_CONSTRUCTION ) == TRUE )
  333. return FALSE;
  334. // we cannot manually repair things that are regeneration holes
  335. if( objectToRepair->isKindOf( KINDOF_REBUILD_HOLE ) == TRUE )
  336. return FALSE;
  337. // only Dozers can go repair things
  338. if( obj->isKindOf( KINDOF_DOZER ) == FALSE )
  339. return FALSE;
  340. // dozers can only repair buildings
  341. if( objectToRepair->isKindOf( KINDOF_STRUCTURE ) == FALSE )
  342. return FALSE;
  343. // get the body module from the object to repair
  344. BodyModuleInterface *body = objectToRepair->getBodyModule();
  345. // buildings that are at full health cannot be repaired
  346. if( body->getHealth() == body->getMaxHealth() )
  347. return FALSE;
  348. // if the target is in the shroud, we can't do anything
  349. if (isObjectShroudedForAction(obj, objectToRepair, commandSource))
  350. return FALSE;
  351. if( obj->getContainedBy() )
  352. {
  353. // We can't heal things while in a transport (especially our own transport, you cheater)
  354. return FALSE;
  355. }
  356. return TRUE;
  357. } // end canRepair
  358. // ------------------------------------------------------------------------------------------------
  359. /** Can 'obj' resume the construction of 'objectBeingConstructed' */
  360. // ------------------------------------------------------------------------------------------------
  361. Bool ActionManager::canResumeConstructionOf( const Object *obj,
  362. const Object *objectBeingConstructed,
  363. CommandSourceType commandSource )
  364. {
  365. // sanity
  366. if( obj == NULL || objectBeingConstructed == NULL )
  367. return FALSE;
  368. // only dozers or workers can resume construction of things
  369. if( obj->isKindOf( KINDOF_DOZER ) == FALSE )
  370. return FALSE;
  371. Relationship r = obj->getRelationship(objectBeingConstructed);
  372. // only available to our allies
  373. if( r != ALLIES )
  374. return FALSE;
  375. // if the objectBeingConstructed is not actually under construction we can't resume that!
  376. if( BitTest( objectBeingConstructed->getStatusBits(),
  377. OBJECT_STATUS_UNDER_CONSTRUCTION ) == FALSE )
  378. return FALSE;
  379. // dead things can do nothing
  380. if( obj->isEffectivelyDead() )
  381. {
  382. return FALSE;
  383. }
  384. //
  385. // if the object being constructed is actively being built by another dozer we cannot
  386. // add more effectiveness to the construction so we'll say no (this might change for workers
  387. // in the future)
  388. //
  389. Object *builder = TheGameLogic->findObjectByID( objectBeingConstructed->getBuilderID() );
  390. if( builder )
  391. {
  392. AIUpdateInterface *ai = builder->getAI();
  393. DEBUG_ASSERTCRASH( ai, ("Builder object does not have an AI interface!\n") );
  394. if( ai )
  395. {
  396. DozerAIInterface *dozerAI = ai->getDozerAIInterface();
  397. DEBUG_ASSERTCRASH( dozerAI, ("Builder object doest not have a DozerAI interface!\n") );
  398. if( dozerAI )
  399. {
  400. if( dozerAI->getCurrentTask() == DOZER_TASK_BUILD &&
  401. dozerAI->getTaskTarget( DOZER_TASK_BUILD ) == objectBeingConstructed->getID() )
  402. return FALSE;
  403. } // end if
  404. } // en dif
  405. } //end if
  406. // if the target is in the shroud, we can't do anything
  407. if (isObjectShroudedForAction(obj, objectBeingConstructed, commandSource))
  408. return FALSE;
  409. //
  410. // all is well, the objectBeingConstructeds' builder object has gone away or is no longer
  411. // building the object anymore
  412. //
  413. return TRUE;
  414. } // end canResumeConstructionOf
  415. // ------------------------------------------------------------------------------------------------
  416. // ------------------------------------------------------------------------------------------------
  417. Bool ActionManager::canEnterObject( const Object *obj, const Object *objectToEnter, CommandSourceType commandSource, CanEnterType mode )
  418. {
  419. // sanity
  420. if( obj == NULL || objectToEnter == NULL )
  421. return FALSE;
  422. if( obj == objectToEnter )
  423. {
  424. //You can't contain yourself (crash fix for pow truck reselection)
  425. return FALSE;
  426. }
  427. // can't enter dead things
  428. if( objectToEnter->isEffectivelyDead() )
  429. return FALSE;
  430. // if the target is in the shroud, we can't do anything
  431. if (isObjectShroudedForAction(obj, objectToEnter, commandSource))
  432. return FALSE;
  433. // nothing can be done with things that are under construction
  434. if( BitTest( obj->getStatusBits(), OBJECT_STATUS_UNDER_CONSTRUCTION ) == TRUE ||
  435. BitTest( objectToEnter->getStatusBits(), OBJECT_STATUS_UNDER_CONSTRUCTION ) == TRUE )
  436. {
  437. return FALSE;
  438. }
  439. // Can't enter something being sold
  440. if( objectToEnter->testStatus(OBJECT_STATUS_SOLD) )
  441. return FALSE;
  442. if ( obj->isKindOf( KINDOF_IGNORED_IN_GUI ) //As in, Angry Mob Members, Cargo Planes
  443. || obj->isKindOf( KINDOF_MOB_NEXUS )
  444. || objectToEnter->isKindOf( KINDOF_IGNORED_IN_GUI ) ) // As in Cargo Planes
  445. {
  446. return FALSE;
  447. }
  448. if( obj->isKindOf( KINDOF_STRUCTURE ) || obj->isKindOf( KINDOF_IMMOBILE ) )
  449. {
  450. //Structures or immobiles can't garrison
  451. return FALSE;
  452. }
  453. // Special case for unmanned vehicles. Any infantry unit can take over any unmanned vehicle!
  454. if( obj->isKindOf( KINDOF_INFANTRY ) && objectToEnter->isDisabledByType( DISABLED_UNMANNED ) )
  455. {
  456. return TRUE;
  457. }
  458. // Special case for aircraft.
  459. if( obj->isKindOf( KINDOF_AIRCRAFT ) && objectToEnter->isKindOf( KINDOF_AIRFIELD ) )
  460. {
  461. if (!obj->isAboveTerrain())
  462. return FALSE;
  463. if( obj->getControllingPlayer() == objectToEnter->getControllingPlayer() )
  464. {
  465. //Kris -- added code to prevent aircraft from landing in any airstrips other than their own!
  466. /// @todo srj -- this is horrible, but expedient.
  467. for (BehaviorModule** i = objectToEnter->getBehaviorModules(); *i; ++i)
  468. {
  469. ParkingPlaceBehaviorInterface* pp = (*i)->getParkingPlaceBehaviorInterface();
  470. if (pp == NULL)
  471. continue;
  472. if (pp->hasReservedSpace(obj->getID()))
  473. return TRUE;
  474. if (pp->shouldReserveDoorWhenQueued(obj->getTemplate()) && pp->hasAvailableSpaceFor(obj->getTemplate()))
  475. return TRUE;
  476. }
  477. }
  478. return FALSE;
  479. }
  480. // first, see if we'd like to collide with 'other'
  481. for (BehaviorModule** m = obj->getBehaviorModules(); *m; ++m)
  482. {
  483. CollideModuleInterface* collide = (*m)->getCollide();
  484. if (!collide)
  485. continue;
  486. if( collide->wouldLikeToCollideWith( objectToEnter ) )
  487. {
  488. //I thought this was a little confusing that it would return TRUE here before
  489. //getting to any of the other checks. The key is that it usually doesn't return
  490. //TRUE because most things aren't trying to collide with objects. This is different
  491. //for terrorist converting carbombs, and pilots entering vehicles. In these cases,
  492. //the vehicles don't have transport capacities, therefore returning true here
  493. //foregoes that checking later on.
  494. return TRUE;
  495. }
  496. }
  497. #ifdef ALLOW_SURRENDER
  498. if( objectToEnter->isKindOf( KINDOF_PRISON ) )
  499. {
  500. //We can't manually enter a prison!
  501. return FALSE;
  502. }
  503. #endif
  504. #ifdef ALLOW_SURRENDER
  505. if( objectToEnter->isKindOf( KINDOF_POW_TRUCK ) )
  506. {
  507. //We can't manually enter POWTruck, either!
  508. return FALSE;
  509. }
  510. #endif
  511. // make sure our objectToEnter has a contain module.
  512. ContainModuleInterface *contain = objectToEnter->getContain();
  513. if( !contain )
  514. {
  515. return FALSE;
  516. }
  517. if( contain->isHealContain() )
  518. {
  519. BodyModuleInterface *body = obj->getBodyModule();
  520. if( body->getHealth() == body->getMaxHealth() )
  521. {
  522. //This container is only used for the purposes of healing and we cannot
  523. //enter it with full health. This is not a normal container.
  524. return FALSE;
  525. }
  526. }
  527. if (mode == COMBATDROP_INTO)
  528. {
  529. // we don't care about valid container-ness, but we DO care about faction structures...
  530. // we aren't allowed to combat drop into them
  531. if (objectToEnter->isFactionStructure())
  532. return FALSE;
  533. }
  534. else
  535. {
  536. Bool checkCapacity = (mode == CHECK_CAPACITY);
  537. Int containCount = contain->getContainCount();
  538. Int stealthContainCount = contain->getStealthUnitsContained();
  539. Int nonStealthContainCount = containCount - stealthContainCount;
  540. // not ours... must do special checks.
  541. if (objectToEnter->getControllingPlayer() != obj->getControllingPlayer())
  542. {
  543. // not empty... can't do it.
  544. if (nonStealthContainCount > 0)
  545. return FALSE;
  546. // faction structure... can't do it.
  547. if (objectToEnter->isFactionStructure())
  548. return FALSE;
  549. // it's stealth-garrisoned... ignore check-cap and fall thru to
  550. // normal isValid test.
  551. if (stealthContainCount > 0 && nonStealthContainCount == 0)
  552. checkCapacity = FALSE;
  553. }
  554. // if our transport slot count is zero, we can't be transported. so punt.
  555. /// @todo srj -- seems like we should check always (not just for checkCap), but scared to change now -- check later
  556. if( checkCapacity && obj->getTransportSlotCount() == 0 )
  557. {
  558. return FALSE;
  559. }
  560. // finally: make sure that objectToEnter is a valid container for obj
  561. if( contain->isValidContainerFor( obj, checkCapacity ) == FALSE )
  562. {
  563. return FALSE;
  564. }
  565. }
  566. return TRUE;
  567. }
  568. // ------------------------------------------------------------------------------------------------
  569. // ------------------------------------------------------------------------------------------------
  570. CanAttackResult ActionManager::getCanAttackObject( const Object *obj, const Object *objectToAttack, CommandSourceType commandSource, AbleToAttackType attackType )
  571. {
  572. // sanity
  573. if( !obj || !objectToAttack || obj->isEffectivelyDead() || objectToAttack->isEffectivelyDead() || objectToAttack == obj )
  574. {
  575. return ATTACKRESULT_NOT_POSSIBLE;
  576. }
  577. if( !obj->isAbleToAttack() )
  578. {
  579. return ATTACKRESULT_NOT_POSSIBLE;
  580. }
  581. //has any weapons that are capable of inflicting damage. Special damage types are rejected
  582. //such as hack weapons... others can be added.
  583. CanAttackResult result = obj->getAbleToAttackSpecificObject( attackType, objectToAttack, commandSource );
  584. if( result != ATTACKRESULT_NOT_POSSIBLE )
  585. {
  586. if( result == ATTACKRESULT_INVALID_SHOT && obj->isKindOf( KINDOF_DOZER ) )
  587. {
  588. //For the case of dozers, we don't ever want to see an attack cursor
  589. //unless it's valid on a mine.
  590. const Weapon *weapon = obj->getCurrentWeapon();
  591. if( weapon && weapon->getDamageType() == DAMAGE_DISARM )
  592. {
  593. return ATTACKRESULT_NOT_POSSIBLE;
  594. }
  595. }
  596. return result;
  597. }
  598. //Special case code for stinger sites: Stinger sites have no weapons, instead -- their spawns are the weapons, in this case the
  599. //stinger soldiers.
  600. if( obj->isKindOf( KINDOF_SPAWNS_ARE_THE_WEAPONS ) )
  601. {
  602. //Look at the spawn behavior and evaluate them!
  603. SpawnBehaviorInterface *spawnInterface = obj->getSpawnBehaviorInterface();
  604. if( spawnInterface )
  605. {
  606. //We found the spawn interface, now get the closest slave to the target.
  607. Object *slave = spawnInterface->getClosestSlave( objectToAttack->getPosition() );
  608. if( slave )
  609. {
  610. result = slave->getAbleToAttackSpecificObject( attackType, objectToAttack, commandSource );
  611. if( result != ATTACKRESULT_NOT_POSSIBLE )
  612. {
  613. return result;
  614. }
  615. }
  616. }
  617. }
  618. return ATTACKRESULT_NOT_POSSIBLE;
  619. }
  620. // ------------------------------------------------------------------------------------------------
  621. // ------------------------------------------------------------------------------------------------
  622. Bool ActionManager::canConvertObjectToCarBomb( const Object *obj, const Object *objectToConvert, CommandSourceType commandSource )
  623. {
  624. // sanity
  625. if( obj == NULL || objectToConvert == NULL )
  626. {
  627. return FALSE;
  628. }
  629. if( objectToConvert->isEffectivelyDead() )
  630. {
  631. return FALSE;
  632. }
  633. // if the target is in the shroud, we can't do anything
  634. if (isObjectShroudedForAction(obj, objectToConvert, commandSource))
  635. return FALSE;
  636. // first, see if we'd like to collide with 'other'
  637. for (BehaviorModule** m = obj->getBehaviorModules(); *m; ++m)
  638. {
  639. CollideModuleInterface* collide = (*m)->getCollide();
  640. if (!collide)
  641. continue;
  642. if( collide->wouldLikeToCollideWith( objectToConvert ) && collide->isCarBombCrateCollide() )
  643. {
  644. return TRUE;
  645. }
  646. }
  647. return FALSE;
  648. }
  649. // ------------------------------------------------------------------------------------------------
  650. // ------------------------------------------------------------------------------------------------
  651. Bool ActionManager::canHijackVehicle( const Object *obj, const Object *objectToHijack, CommandSourceType commandSource ) //LORENZEN
  652. {
  653. int foo = 10;
  654. ++foo;
  655. // sanity
  656. if( obj == NULL || objectToHijack == NULL )
  657. {
  658. return FALSE;
  659. }
  660. //Make sure it's alive.
  661. if( objectToHijack->isEffectivelyDead() )
  662. {
  663. return FALSE;
  664. }
  665. // if the target is in the shroud, we can't do anything
  666. if (isObjectShroudedForAction(obj, objectToHijack, commandSource))
  667. {
  668. return FALSE;
  669. }
  670. Relationship r = obj->getRelationship(objectToHijack);
  671. //Only hijack enemy objects
  672. if( r != ENEMIES )
  673. {
  674. return FALSE;
  675. }
  676. //Make sure target is a vehicle.
  677. if( ! objectToHijack->isKindOf( KINDOF_VEHICLE ) )
  678. {
  679. return FALSE;
  680. }
  681. //Silly hijacker, you can't hijack that plane from the ground!
  682. //if( objectToHijack->isAirborneTarget() )
  683. //{
  684. // return FALSE;
  685. //}
  686. //Kris -- Hijackers can no longer hijack any aircraft.
  687. if( objectToHijack->isKindOf( KINDOF_AIRCRAFT ) )
  688. {
  689. return FALSE;
  690. }
  691. // Dustin asked for this to be removed, 12/13... ML
  692. //Elite and heroic units are immune to this kind of attack
  693. // VeterancyLevel veterancyLevel = objectToHijack->getVeterancyLevel();
  694. // if( veterancyLevel >= LEVEL_ELITE )
  695. // {
  696. // return FALSE;
  697. // }
  698. // last, see if we'd like to collide with 'objectToHijack'
  699. for (BehaviorModule** m = obj->getBehaviorModules(); *m; ++m)
  700. {
  701. CollideModuleInterface* collide = (*m)->getCollide();
  702. if (!collide)
  703. continue;
  704. if( collide->wouldLikeToCollideWith( objectToHijack ) && collide->isHijackedVehicleCrateCollide() )
  705. {
  706. return TRUE;
  707. }
  708. }
  709. return FALSE;
  710. }
  711. // ------------------------------------------------------------------------------------------------
  712. // ------------------------------------------------------------------------------------------------
  713. Bool ActionManager::canMakeObjectDefector( const Object *obj, const Object *objectToMakeDefector, CommandSourceType commandSource ) //LORENZEN
  714. {
  715. // sanity
  716. if( obj == NULL || objectToMakeDefector == NULL )
  717. {
  718. return FALSE;
  719. }
  720. Relationship r = obj->getRelationship(objectToMakeDefector);
  721. //Only make defectors of enemy objects
  722. if( r != ENEMIES )
  723. {
  724. return FALSE;
  725. }
  726. //Make sure it's alive.
  727. if( objectToMakeDefector->isEffectivelyDead() )
  728. {
  729. return FALSE;
  730. }
  731. // if the target is in the shroud, we can't do anything
  732. if (isObjectShroudedForAction(obj, objectToMakeDefector, commandSource))
  733. {
  734. return FALSE;
  735. }
  736. return TRUE;
  737. }
  738. // ------------------------------------------------------------------------------------------------
  739. // ------------------------------------------------------------------------------------------------
  740. Bool ActionManager::canCaptureBuilding( const Object *obj, const Object *objectToCapture, CommandSourceType commandSource )
  741. {
  742. // sanity
  743. if( obj == NULL || objectToCapture == NULL )
  744. return FALSE;
  745. //Make sure our object has the capability of performing this special ability.
  746. Bool isOwnerBlackLotus = obj->hasSpecialPower( SPECIAL_BLACKLOTUS_CAPTURE_BUILDING );
  747. if( !obj->hasSpecialPower( SPECIAL_INFANTRY_CAPTURE_BUILDING ) && !isOwnerBlackLotus)
  748. {
  749. return false;
  750. }
  751. if( objectToCapture->isKindOf( KINDOF_IMMUNE_TO_CAPTURE ) )
  752. {
  753. return false;
  754. }
  755. // This is the althernate way to one-at-a-time BlackLotus' specials; we'll keep it commented her until Dustin decides, or until 12/10/02
  756. // if ( isOwnerBlackLotus )
  757. // {
  758. // SpecialPowerModuleInterface *disableSPI = obj->findSpecialPowerModuleInterface( SPECIAL_BLACKLOTUS_DISABLE_VEHICLE_HACK );
  759. // if ( disableSPI && disableSPI->isBusy() )
  760. // return FALSE;
  761. // SpecialPowerModuleInterface *cashSPI = obj->findSpecialPowerModuleInterface( SPECIAL_BLACKLOTUS_STEAL_CASH_HACK );
  762. // if ( cashSPI && cashSPI->isBusy() )
  763. // return FALSE;
  764. // }
  765. SpecialPowerModuleInterface *spInterface = obj->findSpecialPowerModuleInterface( SPECIAL_INFANTRY_CAPTURE_BUILDING );
  766. if (!spInterface)
  767. spInterface = obj->findSpecialPowerModuleInterface( SPECIAL_BLACKLOTUS_CAPTURE_BUILDING );
  768. if (!spInterface)
  769. return false;
  770. if( spInterface->getPercentReady() < 1.0f )
  771. {
  772. // Special not ready or non-existent.
  773. return false;
  774. }
  775. // can't capture dead things.
  776. if (objectToCapture->isEffectivelyDead())
  777. {
  778. return FALSE;
  779. }
  780. // Make sure we are targeting a building!
  781. if( !objectToCapture->isKindOf( KINDOF_STRUCTURE ) )
  782. {
  783. return FALSE;
  784. }
  785. // can't capture things that are under construction, or sold.
  786. if (objectToCapture->testStatus(OBJECT_STATUS_UNDER_CONSTRUCTION) ||
  787. objectToCapture->testStatus(OBJECT_STATUS_SOLD))
  788. {
  789. return FALSE;
  790. }
  791. // if the target is in the shroud, we can't do anything
  792. if (isObjectShroudedForAction(obj, objectToCapture, commandSource))
  793. return FALSE;
  794. Relationship r = obj->getRelationship(objectToCapture);
  795. // ensure that it's capturable, and not allied
  796. // exception: we can always capture enemy bldgs, regardless of kindof
  797. if (!(r == ENEMIES || (objectToCapture->isKindOf(KINDOF_CAPTURABLE) && r != ALLIES)))
  798. return false;
  799. //If the enemy unit is stealthed and not detected, then we can't capture it!
  800. UnsignedInt status = objectToCapture->getStatusBits();
  801. if ((status & OBJECT_STATUS_STEALTHED) && !(status & OBJECT_STATUS_DETECTED))
  802. {
  803. return FALSE;
  804. }
  805. // if it's garrisoned already, we cannot capture it.
  806. // (unless it's just stealth-garrisoned.)
  807. ContainModuleInterface *contain = objectToCapture->getContain();
  808. if (contain != NULL && contain->isGarrisonable())
  809. {
  810. Int containCount = contain->getContainCount();
  811. Int stealthContainCount = contain->getStealthUnitsContained();
  812. Int nonStealthContainCount = containCount - stealthContainCount;
  813. if (nonStealthContainCount > 0)
  814. return FALSE;
  815. }
  816. // Also check if the object is a container containing stealth units, tricking
  817. // the player into thinking it isn't actually an enemy.
  818. if (appearsToContainFriendlies(obj, objectToCapture))
  819. return FALSE;
  820. return TRUE;
  821. }
  822. // ------------------------------------------------------------------------------------------------
  823. // ------------------------------------------------------------------------------------------------
  824. Bool ActionManager::canDisableVehicleViaHacking( const Object *obj, const Object *objectToHack, CommandSourceType commandSource, Bool checkSourceRequirements)
  825. {
  826. // sanity
  827. if( obj == NULL || objectToHack == NULL )
  828. return FALSE;
  829. if (checkSourceRequirements)
  830. {
  831. //Make sure our object has the capability of performing this special ability.
  832. if( !obj->hasSpecialPower( SPECIAL_BLACKLOTUS_DISABLE_VEHICLE_HACK ) )
  833. {
  834. return false;
  835. }
  836. }
  837. // This is the althernate way to one-at-a-time BlackLotus' specials; we'll keep it commented her until Dustin decides, or until 12/10/02
  838. // SpecialPowerModuleInterface *captureSPI = obj->findSpecialPowerModuleInterface( SPECIAL_BLACKLOTUS_CAPTURE_BUILDING );
  839. // if ( captureSPI && captureSPI->isBusy() )
  840. // return FALSE;
  841. // SpecialPowerModuleInterface *cashSPI = obj->findSpecialPowerModuleInterface( SPECIAL_BLACKLOTUS_STEAL_CASH_HACK );
  842. // if ( cashSPI && cashSPI->isBusy() )
  843. // return FALSE;
  844. SpecialPowerModuleInterface *spInterface = obj->findSpecialPowerModuleInterface( SPECIAL_BLACKLOTUS_DISABLE_VEHICLE_HACK );
  845. if (checkSourceRequirements)
  846. {
  847. if( !spInterface || spInterface->getPercentReady() < 1.0f )
  848. {
  849. //Special not ready or non-existent.
  850. return FALSE;
  851. }
  852. }
  853. if( objectToHack->isEffectivelyDead() )
  854. {
  855. return FALSE;
  856. }
  857. if( objectToHack->isKindOf( KINDOF_AIRCRAFT ) || objectToHack->isAirborneTarget() )
  858. {
  859. return false;
  860. }
  861. // if the target is in the shroud, we can't do anything
  862. if (isObjectShroudedForAction(obj, objectToHack, commandSource))
  863. return FALSE;
  864. Relationship r = obj->getRelationship(objectToHack);
  865. // Make sure object is an enemy
  866. if( r == ENEMIES )
  867. {
  868. //Make sure we are targeting a building!
  869. if( !objectToHack->isKindOf( KINDOF_VEHICLE ) )
  870. {
  871. return FALSE;
  872. }
  873. //If the enemy unit is stealthed and not detected, then we can't attack it!
  874. UnsignedInt status = objectToHack->getStatusBits();
  875. if( status & OBJECT_STATUS_STEALTHED && !(status & OBJECT_STATUS_DETECTED) )
  876. {
  877. return FALSE;
  878. }
  879. //Also check if the object is a container containing stealth units tricking
  880. //the player into thinking it isn't actually an enemy.
  881. if (appearsToContainFriendlies(obj, objectToHack))
  882. return FALSE;
  883. return TRUE;
  884. }
  885. return FALSE;
  886. }
  887. #ifdef ALLOW_SURRENDER
  888. // ------------------------------------------------------------------------------------------------
  889. /** Can 'obj' pick up the prisoner 'prisoner' */
  890. // ------------------------------------------------------------------------------------------------
  891. Bool ActionManager::canPickUpPrisoner( const Object *obj, const Object *prisoner, CommandSourceType commandSource )
  892. {
  893. // sanity
  894. if( obj == NULL || prisoner == NULL )
  895. return FALSE;
  896. // only pow trucks can pick up anything
  897. if( obj->isKindOf( KINDOF_POW_TRUCK ) == FALSE )
  898. return FALSE;
  899. // only infantry can be picked up
  900. if( prisoner->isKindOf( KINDOF_INFANTRY ) == FALSE )
  901. return FALSE;
  902. // prisoner cannot be contained inside anything
  903. if( prisoner->getContainedBy() )
  904. return FALSE;
  905. // prisoner must be in a surrendered state
  906. const AIUpdateInterface *ai = prisoner->getAI();
  907. if( ai == NULL || ai->isSurrendered() == FALSE )
  908. return FALSE;
  909. // prisoner must have been put in a surrendered state by our own player
  910. // (or be surrendered to "everyone")
  911. Int idx = ai->getSurrenderedPlayerIndex();
  912. Player* surrenderedToPlayer = (idx >= 0) ? ThePlayerList->getNthPlayer(idx) : NULL;
  913. if (surrenderedToPlayer != NULL && surrenderedToPlayer != obj->getControllingPlayer())
  914. return FALSE;
  915. // we must be enemies
  916. if( obj->getRelationship( prisoner ) != ENEMIES )
  917. return FALSE;
  918. return TRUE;
  919. } // end canPickUpPrisoner
  920. #endif
  921. // ------------------------------------------------------------------------------------------------
  922. // ------------------------------------------------------------------------------------------------
  923. Bool ActionManager::canStealCashViaHacking( const Object *obj, const Object *objectToHack, CommandSourceType commandSource )
  924. {
  925. // sanity
  926. if( obj == NULL || objectToHack == NULL )
  927. return FALSE;
  928. //Make sure our object has the capability of performing this special ability.
  929. if( !obj->hasSpecialPower( SPECIAL_BLACKLOTUS_STEAL_CASH_HACK ) )
  930. {
  931. return false;
  932. }
  933. // This is the althernate way to one-at-a-time BlackLotus' specials; we'll keep it commented her until Dustin decides, or until 12/10/02
  934. // SpecialPowerModuleInterface *captureSPI = obj->findSpecialPowerModuleInterface( SPECIAL_BLACKLOTUS_CAPTURE_BUILDING );
  935. // if ( captureSPI && captureSPI->isBusy() )
  936. // return FALSE;
  937. // SpecialPowerModuleInterface *disableSPI = obj->findSpecialPowerModuleInterface( SPECIAL_BLACKLOTUS_DISABLE_VEHICLE_HACK );
  938. // if ( disableSPI && disableSPI->isBusy() )
  939. // return FALSE;
  940. SpecialPowerModuleInterface *spInterface = obj->findSpecialPowerModuleInterface( SPECIAL_BLACKLOTUS_STEAL_CASH_HACK );
  941. if( !spInterface || spInterface->getPercentReady() < 1.0f )
  942. {
  943. //Special not ready or non-existent.
  944. return false;
  945. }
  946. if( objectToHack->isEffectivelyDead() )
  947. {
  948. return FALSE;
  949. }
  950. if( BitTest( objectToHack->getStatusBits(), OBJECT_STATUS_UNDER_CONSTRUCTION ) == TRUE )
  951. {
  952. return FALSE;
  953. }
  954. // if the target is in the shroud, we can't do anything
  955. if (isObjectShroudedForAction(obj, objectToHack, commandSource))
  956. return FALSE;
  957. Relationship r = obj->getRelationship(objectToHack);
  958. // Make sure object is an enemy
  959. if( r == ENEMIES )
  960. {
  961. //Make sure we are targeting something that contains cash!
  962. if( !objectToHack->isKindOf( KINDOF_CASH_GENERATOR ) )
  963. {
  964. return FALSE;
  965. }
  966. //Make sure object isn't under construction!
  967. UnsignedInt status = objectToHack->getStatusBits();
  968. if( status & OBJECT_STATUS_UNDER_CONSTRUCTION )
  969. {
  970. return FALSE;
  971. }
  972. //Make sure the building is considered hackable (temp: using capturable)
  973. if( !objectToHack->isKindOf( KINDOF_CAPTURABLE ) || objectToHack->isKindOf( KINDOF_REBUILD_HOLE ) )
  974. {
  975. return FALSE;
  976. }
  977. //If the enemy unit is stealthed and not detected, then we can't attack it!
  978. if( status & OBJECT_STATUS_STEALTHED && !(status & OBJECT_STATUS_DETECTED) )
  979. {
  980. return FALSE;
  981. }
  982. //Also check if the object is a container containing stealth units tricking
  983. //the player into thinking it isn't actually an enemy.
  984. if (appearsToContainFriendlies(obj, objectToHack))
  985. return FALSE;
  986. return TRUE;
  987. }
  988. return FALSE;
  989. }
  990. // ------------------------------------------------------------------------------------------------
  991. // ------------------------------------------------------------------------------------------------
  992. Bool ActionManager::canDisableBuildingViaHacking( const Object *obj, const Object *objectToHack, CommandSourceType commandSource )
  993. {
  994. // sanity
  995. if( obj == NULL || objectToHack == NULL )
  996. return FALSE;
  997. //Make sure our object has the capability of performing this special ability.
  998. if( !obj->hasSpecialPower( SPECIAL_HACKER_DISABLE_BUILDING ) )
  999. {
  1000. return FALSE;
  1001. }
  1002. SpecialPowerModuleInterface *spInterface = obj->findSpecialPowerModuleInterface( SPECIAL_HACKER_DISABLE_BUILDING );
  1003. if( !spInterface || spInterface->getPercentReady() < 1.0f )
  1004. {
  1005. //Special not ready or non-existent.
  1006. return FALSE;
  1007. }
  1008. if( objectToHack->isEffectivelyDead() )
  1009. {
  1010. return FALSE;
  1011. }
  1012. // if the target is in the shroud, we can't do anything
  1013. if (isObjectShroudedForAction(obj, objectToHack, commandSource))
  1014. return FALSE;
  1015. Relationship r = obj->getRelationship(objectToHack);
  1016. // Make sure object is an enemy
  1017. if( r != ENEMIES )
  1018. return FALSE;
  1019. //Make sure we are targeting a building!
  1020. if( !objectToHack->isKindOf( KINDOF_STRUCTURE ) )
  1021. {
  1022. return FALSE;
  1023. }
  1024. //Make sure the building is considered hackable (temp: using capturable)
  1025. // An exception is any TechFactionBuilding that is not explicitly immune to capture
  1026. if( ( !objectToHack->isKindOf( KINDOF_CAPTURABLE ) || objectToHack->isKindOf( KINDOF_REBUILD_HOLE ) ) &&
  1027. ! (objectToHack->isKindOf(KINDOF_FS_TECHNOLOGY) && ! objectToHack->isKindOf(KINDOF_IMMUNE_TO_CAPTURE)) )
  1028. {
  1029. return FALSE;
  1030. }
  1031. if ( objectToHack->isKindOf( KINDOF_REBUILD_HOLE ) || objectToHack->testStatus( OBJECT_STATUS_UNDER_CONSTRUCTION ))
  1032. return FALSE;
  1033. //If the enemy unit is stealthed and not detected, then we can't attack it!
  1034. UnsignedInt status = objectToHack->getStatusBits();
  1035. if( (status & OBJECT_STATUS_STEALTHED) && !(status & OBJECT_STATUS_DETECTED) )
  1036. {
  1037. return FALSE;
  1038. }
  1039. //Also check if the object is a container containing stealth units tricking
  1040. //the player into thinking it isn't actually an enemy.
  1041. if (appearsToContainFriendlies(obj, objectToHack))
  1042. return FALSE;
  1043. return TRUE;
  1044. }
  1045. // ------------------------------------------------------------------------------------------------
  1046. Bool ActionManager::canBribeUnit( const Object *obj, const Object *objectToBribe, CommandSourceType commandSource )
  1047. {
  1048. return FALSE;
  1049. }
  1050. // ------------------------------------------------------------------------------------------------
  1051. Bool ActionManager::canCutBuildingPower( const Object *obj, const Object *building, CommandSourceType commandSource )
  1052. {
  1053. return FALSE;
  1054. }
  1055. // ------------------------------------------------------------------------------------------------
  1056. // ------------------------------------------------------------------------------------------------
  1057. Bool ActionManager::canSnipeVehicle( const Object *obj, const Object *objectToSnipe, CommandSourceType commandSource )
  1058. {
  1059. //Sanity check
  1060. if( obj == NULL || objectToSnipe == NULL )
  1061. {
  1062. return FALSE;
  1063. }
  1064. //Make sure it's alive.
  1065. if( objectToSnipe->isEffectivelyDead() )
  1066. {
  1067. return FALSE;
  1068. }
  1069. // if the target is in the shroud, we can't do anything
  1070. if (isObjectShroudedForAction(obj, objectToSnipe, commandSource))
  1071. return FALSE;
  1072. Relationship r = obj->getRelationship(objectToSnipe);
  1073. if( r == ENEMIES )
  1074. {
  1075. //Make sure target is a vehicle.
  1076. if( !objectToSnipe->isKindOf( KINDOF_VEHICLE ) )
  1077. {
  1078. return FALSE;
  1079. }
  1080. //Make sure object is not flying
  1081. if( objectToSnipe->isAirborneTarget() )
  1082. {
  1083. return false;
  1084. }
  1085. //Make sure the vehicle is manned!
  1086. if( objectToSnipe->isDisabledByType( DISABLED_UNMANNED ) )
  1087. {
  1088. return FALSE;
  1089. }
  1090. return TRUE;
  1091. }
  1092. return FALSE;
  1093. }
  1094. // ------------------------------------------------------------------------------------------------
  1095. // ------------------------------------------------------------------------------------------------
  1096. Bool ActionManager::canDoSpecialPowerAtLocation( const Object *obj, const Coord3D *loc, CommandSourceType commandSource, const SpecialPowerTemplate *spTemplate, const Object *objectInWay, UnsignedInt commandOptions, Bool checkSourceRequirements )
  1097. {
  1098. if (checkSourceRequirements)
  1099. {
  1100. //First check, if our object can do this special power.
  1101. if( !obj->hasSpecialPower( spTemplate->getSpecialPowerType() ) )
  1102. {
  1103. return false;
  1104. }
  1105. }
  1106. SpecialPowerModuleInterface *mod = obj->getSpecialPowerModule( spTemplate );
  1107. if( mod )
  1108. {
  1109. if (checkSourceRequirements)
  1110. {
  1111. if( mod->getPercentReady() < 1.0f )
  1112. {
  1113. //Not fully ready
  1114. return false;
  1115. }
  1116. }
  1117. // First check terrain type, if it is cared about. Don't return a true, since there are more checks.
  1118. switch( spTemplate->getSpecialPowerType() )
  1119. {
  1120. case SPECIAL_PARADROP_AMERICA:
  1121. case SPECIAL_CRATE_DROP:
  1122. {
  1123. if( TheTerrainLogic->isUnderwater( loc->x, loc->y ) )
  1124. return FALSE;
  1125. }
  1126. }
  1127. // Last check is shroudedness, if it is cared about
  1128. switch( spTemplate->getSpecialPowerType() )
  1129. {
  1130. case SPECIAL_DAISY_CUTTER:
  1131. case SPECIAL_PARADROP_AMERICA:
  1132. case SPECIAL_CARPET_BOMB:
  1133. case SPECIAL_CLUSTER_MINES:
  1134. case SPECIAL_EMP_PULSE:
  1135. case SPECIAL_CRATE_DROP:
  1136. case SPECIAL_NAPALM_STRIKE:
  1137. case SPECIAL_BLACK_MARKET_NUKE:
  1138. case SPECIAL_ANTHRAX_BOMB:
  1139. case SPECIAL_TERROR_CELL:
  1140. case SPECIAL_AMBUSH:
  1141. case SPECIAL_NEUTRON_MISSILE:
  1142. case SPECIAL_SCUD_STORM:
  1143. #ifdef ALLOW_DEMORALIZE
  1144. case SPECIAL_DEMORALIZE:
  1145. #endif
  1146. case SPECIAL_A10_THUNDERBOLT_STRIKE:
  1147. case SPECIAL_REPAIR_VEHICLES:
  1148. case SPECIAL_ARTILLERY_BARRAGE:
  1149. case SPECIAL_PARTICLE_UPLINK_CANNON:
  1150. case SPECIAL_CLEANUP_AREA:
  1151. //Don't allow "damaging" special powers in shrouded areas, but Fogged are okay.
  1152. return ThePartitionManager->getShroudStatusForPlayer( obj->getControllingPlayer()->getPlayerIndex(), loc ) != CELLSHROUD_SHROUDED;
  1153. case SPECIAL_SPY_SATELLITE:
  1154. case SPECIAL_RADAR_VAN_SCAN:
  1155. case SPECIAL_SPY_DRONE:
  1156. case SPECIAL_LAUNCH_BAIKONUR_ROCKET:
  1157. //These specials can be used anywhere!
  1158. return true;
  1159. //These special powers require object targets!
  1160. case SPECIAL_MISSILE_DEFENDER_LASER_GUIDED_MISSILES:
  1161. case SPECIAL_HACKER_DISABLE_BUILDING:
  1162. case SPECIAL_TANKHUNTER_TNT_ATTACK:
  1163. case SPECIAL_CASH_HACK:
  1164. case SPECIAL_DEFECTOR:
  1165. case SPECIAL_BLACKLOTUS_CAPTURE_BUILDING:
  1166. case SPECIAL_BLACKLOTUS_DISABLE_VEHICLE_HACK:
  1167. case SPECIAL_BLACKLOTUS_STEAL_CASH_HACK:
  1168. case SPECIAL_INFANTRY_CAPTURE_BUILDING:
  1169. case SPECIAL_DETONATE_DIRTY_NUKE:
  1170. case SPECIAL_DISGUISE_AS_VEHICLE:
  1171. case SPECIAL_REMOTE_CHARGES:
  1172. case SPECIAL_TIMED_CHARGES:
  1173. case SPECIAL_CASH_BOUNTY:
  1174. case SPECIAL_CHANGE_BATTLE_PLANS:
  1175. return false;
  1176. }
  1177. }
  1178. return false;
  1179. }
  1180. // ------------------------------------------------------------------------------------------------
  1181. // ------------------------------------------------------------------------------------------------
  1182. Bool ActionManager::canDoSpecialPowerAtObject( const Object *obj, const Object *target, CommandSourceType commandSource, const SpecialPowerTemplate *spTemplate, UnsignedInt commandOptions, Bool checkSourceRequirements )
  1183. {
  1184. if (checkSourceRequirements)
  1185. {
  1186. //First check, if our object can do this special power.
  1187. if( !obj->hasSpecialPower( spTemplate->getSpecialPowerType() ) )
  1188. {
  1189. return false;
  1190. }
  1191. }
  1192. if( target->isEffectivelyDead() )
  1193. {
  1194. return FALSE;
  1195. }
  1196. Relationship r = obj->getRelationship(target);
  1197. SpecialPowerModuleInterface *mod = obj->getSpecialPowerModule( spTemplate );
  1198. if( mod )
  1199. {
  1200. if (checkSourceRequirements)
  1201. {
  1202. if( mod->getPercentReady() < 1.0f )
  1203. {
  1204. //Not fully ready
  1205. return false;
  1206. }
  1207. }
  1208. // if the target is in the shroud, we can't do anything
  1209. if (isObjectShroudedForAction(obj, target, commandSource))
  1210. return FALSE;
  1211. switch( spTemplate->getSpecialPowerType() )
  1212. {
  1213. case SPECIAL_CASH_BOUNTY:
  1214. return false;
  1215. case SPECIAL_TANKHUNTER_TNT_ATTACK:
  1216. if( target->isKindOf( KINDOF_STRUCTURE ) || (target->isKindOf( KINDOF_VEHICLE ) && !target->isKindOf(KINDOF_AIRCRAFT)) )
  1217. {
  1218. return true;
  1219. }
  1220. break;
  1221. case SPECIAL_MISSILE_DEFENDER_LASER_GUIDED_MISSILES:
  1222. //Can only use laser guided missiles on vehicles!
  1223. if( target->isKindOf( KINDOF_VEHICLE ) && r == ENEMIES )
  1224. {
  1225. return true;
  1226. }
  1227. break;
  1228. case SPECIAL_HACKER_DISABLE_BUILDING:
  1229. //Can only disable buildings...
  1230. if( target->isKindOf( KINDOF_STRUCTURE ) && r == ENEMIES )
  1231. {
  1232. //Make sure the building is considered hackable (temp: using capturable)
  1233. if( !target->isKindOf( KINDOF_CAPTURABLE ) || target->isKindOf( KINDOF_REBUILD_HOLE ) )
  1234. {
  1235. return FALSE;
  1236. }
  1237. return true;
  1238. }
  1239. break;
  1240. case SPECIAL_INFANTRY_CAPTURE_BUILDING:
  1241. case SPECIAL_BLACKLOTUS_CAPTURE_BUILDING:
  1242. return canCaptureBuilding( obj, target, commandSource );
  1243. case SPECIAL_BLACKLOTUS_DISABLE_VEHICLE_HACK:
  1244. return canDisableVehicleViaHacking( obj, target, commandSource, false );
  1245. case SPECIAL_BLACKLOTUS_STEAL_CASH_HACK:
  1246. return canStealCashViaHacking( obj, target, commandSource );
  1247. case SPECIAL_CASH_HACK:
  1248. //Can only disable enemy supply centers.
  1249. if( target->isKindOf( KINDOF_STRUCTURE ) && r == ENEMIES )
  1250. {
  1251. //Make sure the building is considered hackable (temp: using capturable)
  1252. if( !target->isKindOf( KINDOF_CAPTURABLE ) || target->isKindOf( KINDOF_REBUILD_HOLE ) )
  1253. {
  1254. return FALSE;
  1255. }
  1256. //Can't cash hack a building that's under construction.
  1257. if( BitTest( target->getStatusBits(), OBJECT_STATUS_UNDER_CONSTRUCTION ) )
  1258. {
  1259. return FALSE;
  1260. }
  1261. if (target->isKindOf( KINDOF_CASH_GENERATOR ) )
  1262. {
  1263. return true;
  1264. }
  1265. }
  1266. break;
  1267. case SPECIAL_DISGUISE_AS_VEHICLE:
  1268. if( target->isKindOf( KINDOF_VEHICLE ) && !target->isKindOf( KINDOF_AIRCRAFT ) && !target->isKindOf( KINDOF_BOAT ) )
  1269. {
  1270. //Don't allow it to disguise as another bomb truck -- that's just plain dumb.
  1271. //if( target->getTemplate() != obj->getTemplate() )
  1272. {
  1273. //Don't allow it to disguise as a train -- they don't have KINDOF_TRAIN yet, but
  1274. //if added, please change this code so it'll be faster!
  1275. static const NameKeyType key = NAMEKEY( "RailroadBehavior" );
  1276. RailroadBehavior *rBehavior = (RailroadBehavior*)target->findUpdateModule( key );
  1277. if( !rBehavior )
  1278. {
  1279. return true;
  1280. }
  1281. }
  1282. }
  1283. break;
  1284. case SPECIAL_DEFECTOR:
  1285. //buildings do not defect
  1286. if( ! target->isKindOf( KINDOF_STRUCTURE ) )
  1287. {
  1288. // only attacking type things will defect (no dozers, supply trucks, workers...)
  1289. // srj sez: I don't know why this is commented out, but it should remain thus, because
  1290. // it is not necessarily the case that dozers, workers, etc. cannot attack; they may
  1291. // "attack" Mines to disarm them...
  1292. // if ( target->isKindOf( KINDOF_CAN_ATTACK ) )
  1293. {
  1294. //neutral or same-team units are worthless defectors
  1295. if( r == ENEMIES )
  1296. {
  1297. return canMakeObjectDefector( obj, target, commandSource );
  1298. }
  1299. }
  1300. }
  1301. break;
  1302. //These special powers require locations, not objects!
  1303. case SPECIAL_DAISY_CUTTER:
  1304. case SPECIAL_PARADROP_AMERICA:
  1305. case SPECIAL_CARPET_BOMB:
  1306. case SPECIAL_CLUSTER_MINES:
  1307. case SPECIAL_EMP_PULSE:
  1308. case SPECIAL_CRATE_DROP:
  1309. case SPECIAL_NAPALM_STRIKE:
  1310. case SPECIAL_TERROR_CELL:
  1311. case SPECIAL_AMBUSH:
  1312. case SPECIAL_NEUTRON_MISSILE:
  1313. case SPECIAL_DETONATE_DIRTY_NUKE:
  1314. case SPECIAL_BLACK_MARKET_NUKE:
  1315. case SPECIAL_ANTHRAX_BOMB:
  1316. case SPECIAL_SPY_SATELLITE:
  1317. case SPECIAL_SPY_DRONE:
  1318. case SPECIAL_RADAR_VAN_SCAN:
  1319. case SPECIAL_SCUD_STORM:
  1320. case SPECIAL_A10_THUNDERBOLT_STRIKE:
  1321. case SPECIAL_ARTILLERY_BARRAGE:
  1322. case SPECIAL_REPAIR_VEHICLES:
  1323. case SPECIAL_PARTICLE_UPLINK_CANNON:
  1324. case SPECIAL_CHANGE_BATTLE_PLANS:
  1325. case SPECIAL_CLEANUP_AREA:
  1326. case SPECIAL_LAUNCH_BAIKONUR_ROCKET:
  1327. return false;
  1328. case SPECIAL_REMOTE_CHARGES:
  1329. case SPECIAL_TIMED_CHARGES:
  1330. {
  1331. if( target->isEffectivelyDead() ||
  1332. target->isKindOf( KINDOF_BRIDGE ) ||
  1333. target->isKindOf( KINDOF_BRIDGE_TOWER ) )
  1334. return FALSE;
  1335. if( target->isKindOf( KINDOF_STRUCTURE ) || target->isKindOf( KINDOF_VEHICLE ) )
  1336. {
  1337. SpecialAbilityUpdate *spUpdate = obj->findSpecialAbilityUpdate( spTemplate->getSpecialPowerType() );
  1338. if( spUpdate )
  1339. {
  1340. //Make sure we have enough equipment to place an additional charge.
  1341. if( spUpdate->getSpecialObjectCount() < spUpdate->getSpecialObjectMax() )
  1342. {
  1343. //Also restrict the unit from placing more than one charge on the same building.
  1344. //We accomplish this by having the stickybomb update store the target as the producer ID.
  1345. if( spUpdate->findSpecialObjectWithProducerID( target ) )
  1346. {
  1347. return false;
  1348. }
  1349. //HERE'S THE TOUGH CASE...
  1350. //We also don't want to allow a unit that can place timed charges on a building to be able to place
  1351. //remote charges (or vice-versa). So we're going to look for the other special ability update and
  1352. //reject if the other one has it planted...
  1353. if( spTemplate->getSpecialPowerType() == SPECIAL_REMOTE_CHARGES )
  1354. {
  1355. spUpdate = obj->findSpecialAbilityUpdate( SPECIAL_TIMED_CHARGES );
  1356. }
  1357. else if( spTemplate->getSpecialPowerType() == SPECIAL_TIMED_CHARGES )
  1358. {
  1359. spUpdate = obj->findSpecialAbilityUpdate( SPECIAL_REMOTE_CHARGES );
  1360. }
  1361. //If we have a valid pointer at this point, we found the other special. Make sure it
  1362. //isn't planted on the same target.
  1363. if( spUpdate && spUpdate->findSpecialObjectWithProducerID( target ) )
  1364. {
  1365. return false;
  1366. }
  1367. return true;
  1368. }
  1369. }
  1370. }
  1371. break;
  1372. }
  1373. }
  1374. }
  1375. return false;
  1376. }
  1377. // ------------------------------------------------------------------------------------------------
  1378. // ------------------------------------------------------------------------------------------------
  1379. Bool ActionManager::canDoSpecialPower( const Object *obj, const SpecialPowerTemplate *spTemplate, CommandSourceType commandSource, UnsignedInt commandOptions, Bool checkSourceRequirements )
  1380. {
  1381. if (checkSourceRequirements)
  1382. {
  1383. //First check, if our object can do this special power.
  1384. if( !obj->hasSpecialPower( spTemplate->getSpecialPowerType() ) )
  1385. {
  1386. return false;
  1387. }
  1388. }
  1389. SpecialPowerModuleInterface *mod = obj->getSpecialPowerModule( spTemplate );
  1390. if( mod )
  1391. {
  1392. if (checkSourceRequirements)
  1393. {
  1394. if( mod->getPercentReady() < 1.0f )
  1395. {
  1396. //Not fully ready
  1397. return false;
  1398. }
  1399. }
  1400. switch( spTemplate->getSpecialPowerType() )
  1401. {
  1402. case SPECIAL_MISSILE_DEFENDER_LASER_GUIDED_MISSILES:
  1403. case SPECIAL_TANKHUNTER_TNT_ATTACK:
  1404. case SPECIAL_DAISY_CUTTER:
  1405. case SPECIAL_PARADROP_AMERICA:
  1406. case SPECIAL_NAPALM_STRIKE:
  1407. case SPECIAL_TERROR_CELL:
  1408. case SPECIAL_NEUTRON_MISSILE:
  1409. case SPECIAL_BLACK_MARKET_NUKE:
  1410. case SPECIAL_ANTHRAX_BOMB:
  1411. case SPECIAL_SPY_SATELLITE:
  1412. case SPECIAL_SPY_DRONE:
  1413. case SPECIAL_RADAR_VAN_SCAN:
  1414. case SPECIAL_TIMED_CHARGES:
  1415. case SPECIAL_SCUD_STORM:
  1416. case SPECIAL_A10_THUNDERBOLT_STRIKE:
  1417. case SPECIAL_ARTILLERY_BARRAGE:
  1418. case SPECIAL_DISGUISE_AS_VEHICLE:
  1419. case SPECIAL_REPAIR_VEHICLES:
  1420. case SPECIAL_PARTICLE_UPLINK_CANNON:
  1421. case SPECIAL_CASH_BOUNTY:
  1422. case SPECIAL_CLEANUP_AREA:
  1423. //These all require object or location targets.
  1424. return false;
  1425. case SPECIAL_REMOTE_CHARGES:
  1426. case SPECIAL_CIA_INTELLIGENCE:
  1427. case SPECIAL_DETONATE_DIRTY_NUKE:
  1428. case SPECIAL_CHANGE_BATTLE_PLANS:
  1429. case SPECIAL_LAUNCH_BAIKONUR_ROCKET:
  1430. //Detonate's any existing charges
  1431. return true;
  1432. }
  1433. }
  1434. return false;
  1435. }
  1436. //------------------------------------------------------------------------------------------------
  1437. Bool ActionManager::canFireWeaponAtLocation( const Object *obj, const Coord3D *loc, CommandSourceType commandSource, const WeaponSlotType slot, const Object *objectInWay )
  1438. {
  1439. //Sanity check
  1440. if( obj == NULL || loc == NULL )
  1441. {
  1442. return false;
  1443. }
  1444. //Make sure we have the right weapon.
  1445. Weapon *weapon = obj->getWeaponInWeaponSlot( slot );
  1446. if( !weapon )
  1447. {
  1448. return false;
  1449. }
  1450. return true;
  1451. }
  1452. //------------------------------------------------------------------------------------------------
  1453. Bool ActionManager::canFireWeaponAtObject( const Object *obj, const Object *target, CommandSourceType commandSource, const WeaponSlotType slot )
  1454. {
  1455. //Sanity check
  1456. if( obj == NULL || target == NULL )
  1457. {
  1458. return false;
  1459. }
  1460. //Make sure we have the right weapon.
  1461. Weapon *weapon = obj->getWeaponInWeaponSlot( slot );
  1462. if( !weapon )
  1463. {
  1464. return false;
  1465. }
  1466. //if( weapon->getDamageType() == DAMAGE_KILLPILOT )
  1467. //{
  1468. // return canSnipeVehicle( obj, target, commandSource );
  1469. //}
  1470. CanAttackResult result = obj->getAbleToAttackSpecificObject( ATTACK_NEW_TARGET, target, commandSource );
  1471. if( result == ATTACKRESULT_POSSIBLE || result == ATTACKRESULT_POSSIBLE_AFTER_MOVING )
  1472. {
  1473. return weapon->estimateWeaponDamage( obj, target ) != 0.0f;
  1474. }
  1475. return FALSE;
  1476. }
  1477. //------------------------------------------------------------------------------------------------
  1478. Bool ActionManager::canFireWeapon( const Object *obj, const WeaponSlotType slot, CommandSourceType commandSource )
  1479. {
  1480. //Sanity check
  1481. if( obj == NULL )
  1482. {
  1483. return false;
  1484. }
  1485. //Make sure we have the right weapon.
  1486. Weapon *weapon = obj->getWeaponInWeaponSlot( slot );
  1487. if( !weapon )
  1488. {
  1489. return false;
  1490. }
  1491. return true;
  1492. }
  1493. //------------------------------------------------------------------------------------------------
  1494. Bool ActionManager::canGarrison( const Object *obj, const Object *target, CommandSourceType commandSource )
  1495. {
  1496. if (!(obj && target))
  1497. return false;
  1498. // The object was not an infantry, or is disallowed from being allowed to garrison stuff.
  1499. if (obj->isKindOf(KINDOF_INFANTRY) == false || obj->isKindOf(KINDOF_NO_GARRISON))
  1500. return false;
  1501. if (target->isKindOf(KINDOF_STRUCTURE) == false)
  1502. return false;
  1503. ContainModuleInterface *objCMI = obj->getContain();
  1504. if (!objCMI)
  1505. return false;
  1506. ContainModuleInterface *cmi = target->getContain();
  1507. if (cmi == NULL)
  1508. return false;
  1509. if (cmi->isGarrisonable() == false)
  1510. return false;
  1511. if (obj->getControllingPlayer() == target->getControllingPlayer())
  1512. {
  1513. return cmi->isValidContainerFor(obj, true);
  1514. }
  1515. if (obj->getControllingPlayer()->getRelationship(target->getTeam()) == NEUTRAL)
  1516. {
  1517. // needs to be empty if its not already ours.
  1518. return (cmi->getContainCount() == 0 && cmi->isValidContainerFor(obj, true));
  1519. }
  1520. return false;
  1521. }
  1522. //------------------------------------------------------------------------------------------------
  1523. Bool ActionManager::canPlayerGarrison( const Player *player, const Object *target, CommandSourceType commandSource )
  1524. {
  1525. if (!(player && target))
  1526. return false;
  1527. if (target->isEffectivelyDead()) {
  1528. return false;
  1529. }
  1530. if (target->isKindOf(KINDOF_STRUCTURE) == false)
  1531. return false;
  1532. ContainModuleInterface *cmi = target->getContain();
  1533. if (cmi == NULL)
  1534. return false;
  1535. if (cmi->isGarrisonable() == false)
  1536. return false;
  1537. if (player == target->getControllingPlayer())
  1538. {
  1539. return true;
  1540. }
  1541. if (player->getRelationship(target->getTeam()) == NEUTRAL)
  1542. {
  1543. // needs to be empty if its not already ours.
  1544. return cmi->getContainCount() == 0;
  1545. }
  1546. return false;
  1547. }
  1548. //------------------------------------------------------------------------------------------------
  1549. Bool ActionManager::canOverrideSpecialPowerDestination( const Object *obj, const Coord3D *loc, SpecialPowerType spType, CommandSourceType commandSource )
  1550. {
  1551. SpecialPowerUpdateInterface* spuInterface = obj->findSpecialPowerWithOverridableDestinationActive( spType );
  1552. if( spuInterface )
  1553. {
  1554. //But so long as it's not in the black areas of the map.
  1555. return ThePartitionManager->getShroudStatusForPlayer( obj->getControllingPlayer()->getPlayerIndex(), loc ) != CELLSHROUD_SHROUDED;
  1556. }
  1557. return false;
  1558. }