TransportAIUpdate.cpp 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /*
  2. ** Command & Conquer Generals Zero Hour(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. // TransportAIUpdate.cpp //////////
  24. // Needs to check legality of evacuate, and may move to a place that is better to evacuate at
  25. // Author: Graham Smallwood, July 2002
  26. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  27. #include "Common/RandomValue.h"
  28. #include "GameLogic/Module/TransportAIUpdate.h"
  29. #include "GameLogic/Module/BehaviorModule.h"
  30. #include "GameLogic/Module/ContainModule.h"
  31. #include "GameLogic/Object.h"
  32. #ifdef _INTERNAL
  33. // for occasional debugging...
  34. //#pragma optimize("", off)
  35. //#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
  36. #endif
  37. //-------------------------------------------------------------------------------------------------
  38. AIStateMachine* TransportAIUpdate::makeStateMachine()
  39. {
  40. return newInstance(AIStateMachine)( getObject(), "TransportAIUpdateMachine");
  41. }
  42. //-------------------------------------------------------------------------------------------------
  43. TransportAIUpdate::TransportAIUpdate( Thing *thing, const ModuleData* moduleData ) : AIUpdateInterface( thing, moduleData )
  44. {
  45. }
  46. //-------------------------------------------------------------------------------------------------
  47. TransportAIUpdate::~TransportAIUpdate( void )
  48. {
  49. }
  50. //-------------------------------------------------------------------------------------------------
  51. /**
  52. * Attack given object
  53. */
  54. void TransportAIUpdate::privateAttackObject( Object *victim, Int maxShotsToFire, CommandSourceType cmdSource )
  55. {
  56. ContainModuleInterface* contain = getObject()->getContain();
  57. if( contain != NULL && contain->isPassengerAllowedToFire() )
  58. {
  59. // As an extension of the normal attack, I may want to tell my passengers to attack
  60. // too, but only if this is a direct command. (As opposed to a passive aquire)
  61. if( cmdSource == CMD_FROM_PLAYER || cmdSource == CMD_FROM_SCRIPT )
  62. {
  63. const ContainedItemsList *passengerList = contain->getContainedItemsList();
  64. ContainedItemsList::const_iterator passengerIterator;
  65. passengerIterator = passengerList->begin();
  66. while( passengerIterator != passengerList->end() )
  67. {
  68. Object *passenger = *passengerIterator;
  69. //Advance to the next iterator
  70. passengerIterator++;
  71. // If I am an overlord with a gattling upgrade, I do not tell it to fire if it is disabled
  72. if ( passenger->isKindOf( KINDOF_PORTABLE_STRUCTURE ) )
  73. {
  74. if( passenger->isDisabledByType( DISABLED_HACKED )
  75. || passenger->isDisabledByType( DISABLED_EMP )
  76. || passenger->isDisabledByType( DISABLED_SUBDUED )
  77. || passenger->isDisabledByType( DISABLED_PARALYZED) )
  78. continue;
  79. }
  80. AIUpdateInterface *passengerAI = passenger->getAIUpdateInterface();
  81. if( passengerAI )
  82. {
  83. passengerAI->aiAttackObject( victim, maxShotsToFire, cmdSource );
  84. }
  85. }
  86. }
  87. }
  88. AIUpdateInterface::privateAttackObject( victim, maxShotsToFire, cmdSource );
  89. }
  90. //-------------------------------------------------------------------------------------------------
  91. /**
  92. * Attack given object
  93. */
  94. void TransportAIUpdate::privateForceAttackObject( Object *victim, Int maxShotsToFire, CommandSourceType cmdSource )
  95. {
  96. ContainModuleInterface* contain = getObject()->getContain();
  97. if( contain != NULL && contain->isPassengerAllowedToFire() )
  98. {
  99. // As an extension of the normal attack, I may want to tell my passengers to attack
  100. // too, but only if this is a direct command. (As opposed to a passive aquire)
  101. if( cmdSource == CMD_FROM_PLAYER || cmdSource == CMD_FROM_SCRIPT )
  102. {
  103. const ContainedItemsList *passengerList = contain->getContainedItemsList();
  104. ContainedItemsList::const_iterator passengerIterator;
  105. passengerIterator = passengerList->begin();
  106. while( passengerIterator != passengerList->end() )
  107. {
  108. Object *passenger = *passengerIterator;
  109. //Advance to the next iterator
  110. passengerIterator++;
  111. // If I am an overlord with a gattling upgrade, I do not tell it to fire if it is disabled
  112. if ( passenger->isKindOf( KINDOF_PORTABLE_STRUCTURE ) )
  113. {
  114. if( passenger->isDisabledByType( DISABLED_HACKED )
  115. || passenger->isDisabledByType( DISABLED_EMP )
  116. || passenger->isDisabledByType( DISABLED_SUBDUED )
  117. || passenger->isDisabledByType( DISABLED_PARALYZED) )
  118. continue;
  119. }
  120. AIUpdateInterface *passengerAI = passenger->getAIUpdateInterface();
  121. if( passengerAI )
  122. {
  123. passengerAI->aiForceAttackObject( victim, maxShotsToFire, cmdSource );
  124. }
  125. }
  126. }
  127. }
  128. AIUpdateInterface::privateForceAttackObject( victim, maxShotsToFire, cmdSource );
  129. }
  130. //-------------------------------------------------------------------------------------------------
  131. /**
  132. * Attack given position
  133. */
  134. void TransportAIUpdate::privateAttackPosition( const Coord3D *pos, Int maxShotsToFire, CommandSourceType cmdSource )
  135. {
  136. ContainModuleInterface* contain = getObject()->getContain();
  137. if( contain != NULL && contain->isPassengerAllowedToFire() )
  138. {
  139. // As an extension of the normal attack, I may want to tell my passengers to attack
  140. // too, but only if this is a direct command. (As opposed to a passive aquire)
  141. if( cmdSource == CMD_FROM_PLAYER || cmdSource == CMD_FROM_SCRIPT )
  142. {
  143. const ContainedItemsList *passengerList = contain->getContainedItemsList();
  144. ContainedItemsList::const_iterator passengerIterator;
  145. passengerIterator = passengerList->begin();
  146. while( passengerIterator != passengerList->end() )
  147. {
  148. Object *passenger = *passengerIterator;
  149. //Advance to the next iterator
  150. passengerIterator++;
  151. // If I am an overlord with a gattling upgrade, I do not tell it ti fire if it is disabled
  152. if ( passenger->isKindOf( KINDOF_PORTABLE_STRUCTURE ) )
  153. {
  154. if( passenger->isDisabledByType( DISABLED_HACKED )
  155. || passenger->isDisabledByType( DISABLED_EMP)
  156. || passenger->isDisabledByType( DISABLED_SUBDUED )
  157. || passenger->isDisabledByType( DISABLED_PARALYZED) )
  158. continue;
  159. }
  160. AIUpdateInterface *passengerAI = passenger->getAIUpdateInterface();
  161. if( passengerAI )
  162. {
  163. passengerAI->aiAttackPosition( pos, maxShotsToFire, cmdSource );
  164. }
  165. }
  166. }
  167. }
  168. AIUpdateInterface::privateAttackPosition( pos, maxShotsToFire, cmdSource );
  169. }
  170. //-------------------------------------------------------------------------------------------------
  171. AIFreeToExitType TransportAIUpdate::getAiFreeToExit(const Object* exiter) const
  172. {
  173. // Transports have a speed at which you can exit.
  174. return FREE_TO_EXIT;
  175. }
  176. // ------------------------------------------------------------------------------------------------
  177. /** CRC */
  178. // ------------------------------------------------------------------------------------------------
  179. void TransportAIUpdate::crc( Xfer *xfer )
  180. {
  181. // extend base class
  182. AIUpdateInterface::crc(xfer);
  183. } // end crc
  184. // ------------------------------------------------------------------------------------------------
  185. /** Xfer method
  186. * Version Info:
  187. * 1: Initial version */
  188. // ------------------------------------------------------------------------------------------------
  189. void TransportAIUpdate::xfer( Xfer *xfer )
  190. {
  191. XferVersion currentVersion = 1;
  192. XferVersion version = currentVersion;
  193. xfer->xferVersion( &version, currentVersion );
  194. // extend base class
  195. AIUpdateInterface::xfer(xfer);
  196. } // end xfer
  197. // ------------------------------------------------------------------------------------------------
  198. /** Load post process */
  199. // ------------------------------------------------------------------------------------------------
  200. void TransportAIUpdate::loadPostProcess( void )
  201. {
  202. // extend base class
  203. AIUpdateInterface::loadPostProcess();
  204. } // end loadPostProcess