PropagandaCenterBehavior.cpp 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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. // FILE: PropagandaCenterBehavior.cpp /////////////////////////////////////////////////////////////
  24. // Author: Colin Day, August 2002
  25. // Desc: Propaganda Center Behavior
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  28. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  29. #include "Common/Player.h"
  30. #include "Common/ThingTemplate.h"
  31. #include "Common/Xfer.h"
  32. #include "GameClient/InGameUI.h"
  33. #include "GameLogic/GameLogic.h"
  34. #include "GameLogic/Object.h"
  35. #include "GameLogic/Module/AIUpdate.h"
  36. #include "GameLogic/Module/PropagandaCenterBehavior.h"
  37. #ifdef ALLOW_SURRENDER
  38. ///////////////////////////////////////////////////////////////////////////////////////////////////
  39. ///////////////////////////////////////////////////////////////////////////////////////////////////
  40. ///////////////////////////////////////////////////////////////////////////////////////////////////
  41. // ------------------------------------------------------------------------------------------------
  42. // ------------------------------------------------------------------------------------------------
  43. PropagandaCenterBehaviorModuleData::PropagandaCenterBehaviorModuleData( void )
  44. {
  45. m_brainwashDuration = 0;
  46. } // end PropagandaCenterBehaviorModuleData
  47. // ------------------------------------------------------------------------------------------------
  48. // ------------------------------------------------------------------------------------------------
  49. /*static*/ void PropagandaCenterBehaviorModuleData::buildFieldParse( MultiIniFieldParse &p )
  50. {
  51. PrisonBehaviorModuleData::buildFieldParse( p );
  52. static const FieldParse dataFieldParse[] =
  53. {
  54. { "BrainwashDuration", INI::parseDurationUnsignedInt, NULL, offsetof( PropagandaCenterBehaviorModuleData, m_brainwashDuration ) },
  55. { 0, 0, 0, 0 }
  56. };
  57. p.add( dataFieldParse );
  58. } // end buildFieldParse
  59. ///////////////////////////////////////////////////////////////////////////////////////////////////
  60. ///////////////////////////////////////////////////////////////////////////////////////////////////
  61. ///////////////////////////////////////////////////////////////////////////////////////////////////
  62. // ------------------------------------------------------------------------------------------------
  63. // ------------------------------------------------------------------------------------------------
  64. PropagandaCenterBehavior::PropagandaCenterBehavior( Thing *thing, const ModuleData *moduleData )
  65. : PrisonBehavior( thing, moduleData )
  66. {
  67. m_brainwashingSubjectID = INVALID_ID;
  68. m_brainwashingSubjectStartFrame = 0;
  69. } // end PropagandaCenterBehavior
  70. // ------------------------------------------------------------------------------------------------
  71. // ------------------------------------------------------------------------------------------------
  72. PropagandaCenterBehavior::~PropagandaCenterBehavior( void )
  73. {
  74. } // end ~PropagandaCenterBehavior
  75. // ------------------------------------------------------------------------------------------------
  76. // ------------------------------------------------------------------------------------------------
  77. void PropagandaCenterBehavior::onDelete( void )
  78. {
  79. // extend functionality
  80. PrisonBehavior::onDelete();
  81. //
  82. // go through our list of brainwashed objects, and if they are still under our
  83. // control, return them to their original owners
  84. //
  85. for( BrainwashedIDListContIterator it = m_brainwashedList.begin();
  86. it != m_brainwashedList.end();
  87. ++it )
  88. {
  89. Object *obj;
  90. // get this object
  91. obj = TheGameLogic->findObjectByID( *it );
  92. if( obj )
  93. {
  94. // return this object under the control of the original owner
  95. obj->restoreOriginalTeam();
  96. } // end if
  97. } // end for
  98. // clear the list
  99. m_brainwashedList.clear();
  100. } // end onDelete
  101. // ------------------------------------------------------------------------------------------------
  102. // ------------------------------------------------------------------------------------------------
  103. UpdateSleepTime PropagandaCenterBehavior::update( void )
  104. {
  105. Object *us = getObject();
  106. const PropagandaCenterBehaviorModuleData *modData = getPropagandaCenterBehaviorModuleData();
  107. // extend functionality
  108. PrisonBehavior::update();
  109. // if we have a prisoner inside, continue the brainwashing on them (one at a time)
  110. if( m_brainwashingSubjectID != INVALID_ID )
  111. {
  112. Object *brainwashingSubject = TheGameLogic->findObjectByID( m_brainwashingSubjectID );
  113. if( brainwashingSubject )
  114. {
  115. // if we've been in here long enough, we come out brainwashed
  116. if( TheGameLogic->getFrame() - m_brainwashingSubjectStartFrame >= modData->m_brainwashDuration )
  117. {
  118. // only can exit if the prison allows us to
  119. ExitDoorType exitDoor = reserveDoorForExit(brainwashingSubject->getTemplate(), brainwashingSubject);
  120. if(exitDoor != DOOR_NONE_AVAILABLE)
  121. {
  122. // place this object under the control of the player
  123. Player *player = us->getControllingPlayer();
  124. DEBUG_ASSERTCRASH( player, ("Brainwashing: No controlling player for '%s'\n", us->getTemplate()->getName().str()) );
  125. if( player )
  126. brainwashingSubject->setTemporaryTeam( player->getDefaultTeam() );
  127. // remove any surrender status from this object
  128. AIUpdateInterface *ai = brainwashingSubject->getAIUpdateInterface();
  129. if( ai )
  130. ai->setSurrendered( NULL, FALSE );
  131. // add this object to our brainwashed list if we're not already in it
  132. for( BrainwashedIDListIterator it = m_brainwashedList.begin();
  133. it != m_brainwashedList.end(); ++it )
  134. if( *it == brainwashingSubject->getID() )
  135. break; // exit for
  136. if( it == m_brainwashedList.end() )
  137. m_brainwashedList.push_front( brainwashingSubject->getID() );
  138. // exit the prison
  139. exitObjectViaDoor( brainwashingSubject, exitDoor );
  140. } // end if
  141. } // end if
  142. } // end if,
  143. } // end if
  144. // if we have no brainwashing subject, hook one up if we have people inside us
  145. if( m_brainwashingSubjectID == INVALID_ID )
  146. {
  147. // find the first object in our containment list
  148. if( getContainList().begin() != getContainList().end() )
  149. {
  150. Object *obj = getContainList().front();
  151. if( obj )
  152. {
  153. // assign brainwashing subject on this frame
  154. m_brainwashingSubjectID = obj->getID();
  155. m_brainwashingSubjectStartFrame = TheGameLogic->getFrame();
  156. } // end if
  157. } // end if
  158. } // end if
  159. return UPDATE_SLEEP_NONE;
  160. } // end update
  161. // ------------------------------------------------------------------------------------------------
  162. // ------------------------------------------------------------------------------------------------
  163. void PropagandaCenterBehavior::onRemoving( Object *obj )
  164. {
  165. // if we're removing the brainwashing subject, NULL the pointer
  166. if( m_brainwashingSubjectID == obj->getID() )
  167. {
  168. m_brainwashingSubjectID = INVALID_ID;
  169. m_brainwashingSubjectStartFrame = 0;
  170. } // end if
  171. // extend functionality
  172. PrisonBehavior::onRemoving( obj );
  173. } // end onRemoving
  174. // ------------------------------------------------------------------------------------------------
  175. /** CRC */
  176. // ------------------------------------------------------------------------------------------------
  177. void PropagandaCenterBehavior::crc( Xfer *xfer )
  178. {
  179. // extend base class
  180. PrisonBehavior::crc( xfer );
  181. } // end crc
  182. // ------------------------------------------------------------------------------------------------
  183. /** Xfer method
  184. * Version Info:
  185. * 1: Initial version */
  186. // ------------------------------------------------------------------------------------------------
  187. void PropagandaCenterBehavior::xfer( Xfer *xfer )
  188. {
  189. // version
  190. XferVersion currentVersion = 1;
  191. XferVersion version = currentVersion;
  192. xfer->xferVersion( &version, currentVersion );
  193. // extend base class
  194. PrisonBehavior::xfer( xfer );
  195. // brainwashing subject
  196. xfer->xferObjectID( &m_brainwashingSubjectID );
  197. // brainwashing subject start frame
  198. xfer->xferUnsignedInt( &m_brainwashingSubjectStartFrame );
  199. // brainwashed list size and data
  200. xfer->xferSTLObjectIDList( &m_brainwashedList );
  201. } // end xfer
  202. // ------------------------------------------------------------------------------------------------
  203. /** Load post process */
  204. // ------------------------------------------------------------------------------------------------
  205. void PropagandaCenterBehavior::loadPostProcess( void )
  206. {
  207. // extend base class
  208. PrisonBehavior::loadPostProcess();
  209. } // end loadPostProcess
  210. #endif