TransportAIUpdate.cpp 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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. // 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_PARALYZED) )
  77. continue;
  78. }
  79. AIUpdateInterface *passengerAI = passenger->getAIUpdateInterface();
  80. if( passengerAI )
  81. {
  82. passengerAI->aiAttackObject( victim, maxShotsToFire, cmdSource );
  83. }
  84. }
  85. }
  86. }
  87. AIUpdateInterface::privateAttackObject( victim, maxShotsToFire, cmdSource );
  88. }
  89. //-------------------------------------------------------------------------------------------------
  90. /**
  91. * Attack given object
  92. */
  93. void TransportAIUpdate::privateForceAttackObject( Object *victim, Int maxShotsToFire, CommandSourceType cmdSource )
  94. {
  95. ContainModuleInterface* contain = getObject()->getContain();
  96. if( contain != NULL && contain->isPassengerAllowedToFire() )
  97. {
  98. // As an extension of the normal attack, I may want to tell my passengers to attack
  99. // too, but only if this is a direct command. (As opposed to a passive aquire)
  100. if( cmdSource == CMD_FROM_PLAYER || cmdSource == CMD_FROM_SCRIPT )
  101. {
  102. const ContainedItemsList *passengerList = contain->getContainedItemsList();
  103. ContainedItemsList::const_iterator passengerIterator;
  104. passengerIterator = passengerList->begin();
  105. while( passengerIterator != passengerList->end() )
  106. {
  107. Object *passenger = *passengerIterator;
  108. //Advance to the next iterator
  109. passengerIterator++;
  110. // If I am an overlord with a gattling upgrade, I do not tell it to fire if it is disabled
  111. if ( passenger->isKindOf( KINDOF_PORTABLE_STRUCTURE ) )
  112. {
  113. if( passenger->isDisabledByType( DISABLED_HACKED )
  114. || passenger->isDisabledByType( DISABLED_EMP )
  115. || passenger->isDisabledByType( DISABLED_PARALYZED) )
  116. continue;
  117. }
  118. AIUpdateInterface *passengerAI = passenger->getAIUpdateInterface();
  119. if( passengerAI )
  120. {
  121. passengerAI->aiForceAttackObject( victim, maxShotsToFire, cmdSource );
  122. }
  123. }
  124. }
  125. }
  126. AIUpdateInterface::privateForceAttackObject( victim, maxShotsToFire, cmdSource );
  127. }
  128. //-------------------------------------------------------------------------------------------------
  129. /**
  130. * Attack given position
  131. */
  132. void TransportAIUpdate::privateAttackPosition( const Coord3D *pos, Int maxShotsToFire, CommandSourceType cmdSource )
  133. {
  134. ContainModuleInterface* contain = getObject()->getContain();
  135. if( contain != NULL && contain->isPassengerAllowedToFire() )
  136. {
  137. // As an extension of the normal attack, I may want to tell my passengers to attack
  138. // too, but only if this is a direct command. (As opposed to a passive aquire)
  139. if( cmdSource == CMD_FROM_PLAYER || cmdSource == CMD_FROM_SCRIPT )
  140. {
  141. const ContainedItemsList *passengerList = contain->getContainedItemsList();
  142. ContainedItemsList::const_iterator passengerIterator;
  143. passengerIterator = passengerList->begin();
  144. while( passengerIterator != passengerList->end() )
  145. {
  146. Object *passenger = *passengerIterator;
  147. //Advance to the next iterator
  148. passengerIterator++;
  149. // If I am an overlord with a gattling upgrade, I do not tell it ti fire if it is disabled
  150. if ( passenger->isKindOf( KINDOF_PORTABLE_STRUCTURE ) )
  151. {
  152. if( passenger->isDisabledByType( DISABLED_HACKED )
  153. || passenger->isDisabledByType( DISABLED_EMP)
  154. || passenger->isDisabledByType( DISABLED_PARALYZED) )
  155. continue;
  156. }
  157. AIUpdateInterface *passengerAI = passenger->getAIUpdateInterface();
  158. if( passengerAI )
  159. {
  160. passengerAI->aiAttackPosition( pos, maxShotsToFire, cmdSource );
  161. }
  162. }
  163. }
  164. }
  165. AIUpdateInterface::privateAttackPosition( pos, maxShotsToFire, cmdSource );
  166. }
  167. //-------------------------------------------------------------------------------------------------
  168. AIFreeToExitType TransportAIUpdate::getAiFreeToExit(const Object* exiter) const
  169. {
  170. // Transports have a speed at which you can exit.
  171. return FREE_TO_EXIT;
  172. }
  173. // ------------------------------------------------------------------------------------------------
  174. /** CRC */
  175. // ------------------------------------------------------------------------------------------------
  176. void TransportAIUpdate::crc( Xfer *xfer )
  177. {
  178. // extend base class
  179. AIUpdateInterface::crc(xfer);
  180. } // end crc
  181. // ------------------------------------------------------------------------------------------------
  182. /** Xfer method
  183. * Version Info:
  184. * 1: Initial version */
  185. // ------------------------------------------------------------------------------------------------
  186. void TransportAIUpdate::xfer( Xfer *xfer )
  187. {
  188. XferVersion currentVersion = 1;
  189. XferVersion version = currentVersion;
  190. xfer->xferVersion( &version, currentVersion );
  191. // extend base class
  192. AIUpdateInterface::xfer(xfer);
  193. } // end xfer
  194. // ------------------------------------------------------------------------------------------------
  195. /** Load post process */
  196. // ------------------------------------------------------------------------------------------------
  197. void TransportAIUpdate::loadPostProcess( void )
  198. {
  199. // extend base class
  200. AIUpdateInterface::loadPostProcess();
  201. } // end loadPostProcess