| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282 |
- /*
- ** Command & Conquer Generals Zero Hour(tm)
- ** Copyright 2025 Electronic Arts Inc.
- **
- ** This program is free software: you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation, either version 3 of the License, or
- ** (at your option) any later version.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- ////////////////////////////////////////////////////////////////////////////////
- // //
- // (c) 2001-2003 Electronic Arts Inc. //
- // //
- ////////////////////////////////////////////////////////////////////////////////
- // FILE: PropagandaCenterBehavior.cpp /////////////////////////////////////////////////////////////
- // Author: Colin Day, August 2002
- // Desc: Propaganda Center Behavior
- ///////////////////////////////////////////////////////////////////////////////////////////////////
- // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
- #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
- #include "Common/Player.h"
- #include "Common/ThingTemplate.h"
- #include "Common/Xfer.h"
- #include "GameClient/InGameUI.h"
- #include "GameLogic/GameLogic.h"
- #include "GameLogic/Object.h"
- #include "GameLogic/Module/AIUpdate.h"
- #include "GameLogic/Module/PropagandaCenterBehavior.h"
- #ifdef ALLOW_SURRENDER
- ///////////////////////////////////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////////////////////////////////
- // ------------------------------------------------------------------------------------------------
- // ------------------------------------------------------------------------------------------------
- PropagandaCenterBehaviorModuleData::PropagandaCenterBehaviorModuleData( void )
- {
- m_brainwashDuration = 0;
- } // end PropagandaCenterBehaviorModuleData
- // ------------------------------------------------------------------------------------------------
- // ------------------------------------------------------------------------------------------------
- /*static*/ void PropagandaCenterBehaviorModuleData::buildFieldParse( MultiIniFieldParse &p )
- {
- PrisonBehaviorModuleData::buildFieldParse( p );
- static const FieldParse dataFieldParse[] =
- {
-
- { "BrainwashDuration", INI::parseDurationUnsignedInt, NULL, offsetof( PropagandaCenterBehaviorModuleData, m_brainwashDuration ) },
- { 0, 0, 0, 0 }
- };
- p.add( dataFieldParse );
- } // end buildFieldParse
- ///////////////////////////////////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////////////////////////////////
- // ------------------------------------------------------------------------------------------------
- // ------------------------------------------------------------------------------------------------
- PropagandaCenterBehavior::PropagandaCenterBehavior( Thing *thing, const ModuleData *moduleData )
- : PrisonBehavior( thing, moduleData )
- {
- m_brainwashingSubjectID = INVALID_ID;
- m_brainwashingSubjectStartFrame = 0;
- } // end PropagandaCenterBehavior
- // ------------------------------------------------------------------------------------------------
- // ------------------------------------------------------------------------------------------------
- PropagandaCenterBehavior::~PropagandaCenterBehavior( void )
- {
- } // end ~PropagandaCenterBehavior
- // ------------------------------------------------------------------------------------------------
- // ------------------------------------------------------------------------------------------------
- void PropagandaCenterBehavior::onDelete( void )
- {
- // extend functionality
- PrisonBehavior::onDelete();
- //
- // go through our list of brainwashed objects, and if they are still under our
- // control, return them to their original owners
- //
- for( BrainwashedIDListContIterator it = m_brainwashedList.begin();
- it != m_brainwashedList.end();
- ++it )
- {
- Object *obj;
- // get this object
- obj = TheGameLogic->findObjectByID( *it );
- if( obj )
- {
- // return this object under the control of the original owner
- obj->restoreOriginalTeam();
- } // end if
-
- } // end for
-
- // clear the list
- m_brainwashedList.clear();
- } // end onDelete
- // ------------------------------------------------------------------------------------------------
- // ------------------------------------------------------------------------------------------------
- UpdateSleepTime PropagandaCenterBehavior::update( void )
- {
- Object *us = getObject();
- const PropagandaCenterBehaviorModuleData *modData = getPropagandaCenterBehaviorModuleData();
- // extend functionality
- PrisonBehavior::update();
- // if we have a prisoner inside, continue the brainwashing on them (one at a time)
- if( m_brainwashingSubjectID != INVALID_ID )
- {
- Object *brainwashingSubject = TheGameLogic->findObjectByID( m_brainwashingSubjectID );
- if( brainwashingSubject )
- {
- // if we've been in here long enough, we come out brainwashed
- if( TheGameLogic->getFrame() - m_brainwashingSubjectStartFrame >= modData->m_brainwashDuration )
- {
- // only can exit if the prison allows us to
- ExitDoorType exitDoor = reserveDoorForExit(brainwashingSubject->getTemplate(), brainwashingSubject);
- if(exitDoor != DOOR_NONE_AVAILABLE)
- {
- // place this object under the control of the player
- Player *player = us->getControllingPlayer();
- DEBUG_ASSERTCRASH( player, ("Brainwashing: No controlling player for '%s'\n", us->getTemplate()->getName().str()) );
- if( player )
- brainwashingSubject->setTemporaryTeam( player->getDefaultTeam() );
- // remove any surrender status from this object
- AIUpdateInterface *ai = brainwashingSubject->getAIUpdateInterface();
- if( ai )
- ai->setSurrendered( NULL, FALSE );
- // add this object to our brainwashed list if we're not already in it
- for( BrainwashedIDListIterator it = m_brainwashedList.begin();
- it != m_brainwashedList.end(); ++it )
- if( *it == brainwashingSubject->getID() )
- break; // exit for
- if( it == m_brainwashedList.end() )
- m_brainwashedList.push_front( brainwashingSubject->getID() );
- // exit the prison
- exitObjectViaDoor( brainwashingSubject, exitDoor );
- } // end if
-
- } // end if
- } // end if,
- } // end if
- // if we have no brainwashing subject, hook one up if we have people inside us
- if( m_brainwashingSubjectID == INVALID_ID )
- {
- // find the first object in our containment list
- if( getContainList().begin() != getContainList().end() )
- {
- Object *obj = getContainList().front();
- if( obj )
- {
- // assign brainwashing subject on this frame
- m_brainwashingSubjectID = obj->getID();
- m_brainwashingSubjectStartFrame = TheGameLogic->getFrame();
- } // end if
-
- } // end if
- } // end if
- return UPDATE_SLEEP_NONE;
- } // end update
- // ------------------------------------------------------------------------------------------------
- // ------------------------------------------------------------------------------------------------
- void PropagandaCenterBehavior::onRemoving( Object *obj )
- {
- // if we're removing the brainwashing subject, NULL the pointer
- if( m_brainwashingSubjectID == obj->getID() )
- {
- m_brainwashingSubjectID = INVALID_ID;
- m_brainwashingSubjectStartFrame = 0;
- } // end if
- // extend functionality
- PrisonBehavior::onRemoving( obj );
- } // end onRemoving
- // ------------------------------------------------------------------------------------------------
- /** CRC */
- // ------------------------------------------------------------------------------------------------
- void PropagandaCenterBehavior::crc( Xfer *xfer )
- {
- // extend base class
- PrisonBehavior::crc( xfer );
- } // end crc
- // ------------------------------------------------------------------------------------------------
- /** Xfer method
- * Version Info:
- * 1: Initial version */
- // ------------------------------------------------------------------------------------------------
- void PropagandaCenterBehavior::xfer( Xfer *xfer )
- {
- // version
- XferVersion currentVersion = 1;
- XferVersion version = currentVersion;
- xfer->xferVersion( &version, currentVersion );
- // extend base class
- PrisonBehavior::xfer( xfer );
- // brainwashing subject
- xfer->xferObjectID( &m_brainwashingSubjectID );
- // brainwashing subject start frame
- xfer->xferUnsignedInt( &m_brainwashingSubjectStartFrame );
- // brainwashed list size and data
- xfer->xferSTLObjectIDList( &m_brainwashedList );
- } // end xfer
- // ------------------------------------------------------------------------------------------------
- /** Load post process */
- // ------------------------------------------------------------------------------------------------
- void PropagandaCenterBehavior::loadPostProcess( void )
- {
- // extend base class
- PrisonBehavior::loadPostProcess();
- } // end loadPostProcess
- #endif
|