| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819 |
- /*
- ** Command & Conquer Generals(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. //
- // //
- ////////////////////////////////////////////////////////////////////////////////
- // AIDock.cpp
- // Implementation of docking behavior
- // Author: Michael S. Booth, February 2002
- #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
- #include "Common/Module.h"
- #include "Common/Player.h"
- #include "GameLogic/Object.h"
- #include "GameLogic/AIDock.h"
- #include "GameLogic/Module/AIUpdate.h"
- #include "GameLogic/Module/SupplyTruckAIUpdate.h"
- #include "GameLogic/Module/UpdateModule.h"
- //----------------------------------------------------------------------------------------------------------
- /**
- * Create an AI state machine. Define all of the states the machine
- * can possibly be in, and set the initial (default) state.
- */
- AIDockMachine::AIDockMachine( Object *obj ) : StateMachine( obj, "AIDockMachine" )
- {
- static const StateConditionInfo waitForClearanceConditions[] =
- {
- StateConditionInfo(ableToAdvance, AI_DOCK_ADVANCE_POSITION, NULL),
- StateConditionInfo(NULL, NULL, NULL) // keep last
- };
- // order matters: first state is the default state.
- defineState( AI_DOCK_APPROACH, newInstance(AIDockApproachState)( this ), AI_DOCK_WAIT_FOR_CLEARANCE, EXIT_MACHINE_WITH_FAILURE );
- defineState( AI_DOCK_WAIT_FOR_CLEARANCE, newInstance(AIDockWaitForClearanceState)( this ), AI_DOCK_MOVE_TO_ENTRY, EXIT_MACHINE_WITH_FAILURE, waitForClearanceConditions );
- defineState( AI_DOCK_ADVANCE_POSITION, newInstance(AIDockAdvancePositionState)( this ), AI_DOCK_WAIT_FOR_CLEARANCE, EXIT_MACHINE_WITH_FAILURE );
- defineState( AI_DOCK_MOVE_TO_ENTRY, newInstance(AIDockMoveToEntryState)( this ), AI_DOCK_MOVE_TO_DOCK, AI_DOCK_MOVE_TO_EXIT );
- defineState( AI_DOCK_MOVE_TO_DOCK, newInstance(AIDockMoveToDockState)( this ), AI_DOCK_PROCESS_DOCK, AI_DOCK_MOVE_TO_EXIT );
- defineState( AI_DOCK_PROCESS_DOCK, newInstance(AIDockProcessDockState)( this ), AI_DOCK_MOVE_TO_EXIT, AI_DOCK_MOVE_TO_EXIT );
- defineState( AI_DOCK_MOVE_TO_EXIT, newInstance(AIDockMoveToExitState)( this ), AI_DOCK_MOVE_TO_RALLY, EXIT_MACHINE_WITH_FAILURE );
- defineState( AI_DOCK_MOVE_TO_RALLY, newInstance(AIDockMoveToRallyState)( this ), EXIT_MACHINE_WITH_SUCCESS, EXIT_MACHINE_WITH_FAILURE );
- m_approachPosition = -1;
- }
- AIDockMachine::~AIDockMachine()
- {
- }
- //-----------------------------------------------------------------------------
- void AIDockMachine::halt()
- {
- Object *goalObject = getGoalObject();
-
- // sanity
- if( goalObject != NULL )
- {
- // get dock update interface
- DockUpdateInterface *dock = goalObject->getDockUpdateInterface();
- // We need to say goodbye, or we will leave our spot taken forever.
- if( dock != NULL )
- dock->cancelDock( getOwner() );
- }
- StateMachine::halt();
- }
- // ------------------------------------------------------------------------------------------------
- /** CRC */
- // ------------------------------------------------------------------------------------------------
- void AIDockMachine::crc( Xfer *xfer )
- {
- StateMachine::crc(xfer);
- } // end crc
- // ------------------------------------------------------------------------------------------------
- /** Xfer Method */
- // ------------------------------------------------------------------------------------------------
- void AIDockMachine::xfer( Xfer *xfer )
- {
- XferVersion cv = 1;
- XferVersion v = cv;
- xfer->xferVersion( &v, cv );
- StateMachine::xfer(xfer);
- xfer->xferInt(&m_approachPosition);
- } // end xfer
- // ------------------------------------------------------------------------------------------------
- /** Load post process */
- // ------------------------------------------------------------------------------------------------
- void AIDockMachine::loadPostProcess( void )
- {
- StateMachine::loadPostProcess();
- } // end loadPostProcess
- // State transition conditions ----------------------------------------------------------------------------
- //-------------------------------------------------------------------------------------------------
- /* static */ Bool AIDockMachine::ableToAdvance( State *thisState, void* userData )
- {
- Object *goalObject = thisState->getMachineGoalObject();
- AIDockMachine *myMachine = (AIDockMachine *)thisState->getMachine();
- if( goalObject == NULL )
- return FALSE;
- DockUpdateInterface *dock = goalObject->getDockUpdateInterface();
- // if we have nothing to dock with, fail
- if( dock == NULL )
- return FALSE;
- // if the dock says we can advance, then sidetrack to the scoot forward state
- if( dock->isClearToAdvance( thisState->getMachineOwner(), myMachine->m_approachPosition ) )
- return TRUE;
- // continue to wait
- return FALSE;
- }
- //----------------------------------------------------------------------------------------------
- //----------------------------------------------------------------------------------------------
- //----------------------------------------------------------------------------------------------
- // ------------------------------------------------------------------------------------------------
- /** Xfer Method */
- // ------------------------------------------------------------------------------------------------
- void AIDockApproachState::xfer( Xfer *xfer )
- {
- // version
- XferVersion currentVersion = 2;
- XferVersion version = currentVersion;
- xfer->xferVersion( &version, currentVersion );
- if (version>=2) {
- AIInternalMoveToState::xfer(xfer);
- }
- } // end xfer
- //----------------------------------------------------------------------------------------------
- /**
- * Approach our waiting spot next to the dock.
- */
- StateReturnType AIDockApproachState::onEnter( void )
- {
- Object *goalObject = getMachineGoalObject();
-
- // sanity
- if( goalObject == NULL )
- return STATE_FAILURE;
- // get dock update interface
- DockUpdateInterface *dock = goalObject->getDockUpdateInterface();
- // if we have nothing to dock with, fail
- if (dock == NULL)
- return STATE_FAILURE;
- // fail if the dock is closed
- if( dock->isDockOpen() == FALSE )
- {
- dock->cancelDock( getMachineOwner() );
- return STATE_FAILURE;
- }
- // get a good place to wait from the dock
- Bool reserved = dock->reserveApproachPosition( getMachineOwner(), &m_goalPosition, &(( (AIDockMachine*)getMachine() )->m_approachPosition) );
- if( reserved == FALSE )
- {
- // dock is full
- return STATE_FAILURE;
- }
- AIUpdateInterface *ai = getMachineOwner()->getAIUpdateInterface();
- if (ai) {
- ai->ignoreObstacle( NULL );
- }
- // this behavior is an extention of basic MoveTo
- return AIInternalMoveToState::onEnter();
- }
- //----------------------------------------------------------------------------------------------
- StateReturnType AIDockApproachState::update( void )
- {
- Object *goalObject = getMachineGoalObject();
- // if we have nothing to dock with, fail
- if (goalObject == NULL)
- return STATE_FAILURE;
- // this behavior is an extention of basic MoveTo
- return AIInternalMoveToState::update();
- }
- //----------------------------------------------------------------------------------------------
- void AIDockApproachState::onExit( StateExitType status )
- {
- Object *goalObject = getMachineGoalObject();
- DockUpdateInterface *dock = NULL;
- if( goalObject )
- dock = goalObject->getDockUpdateInterface();
- // tell the dock we have approached
- if (dock)
- {
- // if we were interrupted, let the dock know we're not coming
- if (status == EXIT_RESET || dock->isDockOpen() == FALSE)
- dock->cancelDock( getMachineOwner() );
- else
- dock->onApproachReached( getMachineOwner() );
- }
- // this behavior is an extention of basic MoveTo
- AIInternalMoveToState::onExit( status );
- }
- //----------------------------------------------------------------------------------------------
- //----------------------------------------------------------------------------------------------
- //----------------------------------------------------------------------------------------------
- //----------------------------------------------------------------------------------------------
- /**
- * We have approached, now wait at our queue position until the dock says we can enter.
- */
- StateReturnType AIDockWaitForClearanceState::onEnter( void )
- {
- m_enterFrame = TheGameLogic->getFrame();
- return STATE_CONTINUE;
- }
- /**
- * We have approached, now wait at our queue position until the dock says we can enter.
- * @todo What if we are pushed off of our queue spot? We need to move back on... (MSB)
- */
- StateReturnType AIDockWaitForClearanceState::update( void )
- {
- Object *goalObject = getMachineGoalObject();
- if( goalObject == NULL )
- return STATE_FAILURE;
- DockUpdateInterface *dock = goalObject->getDockUpdateInterface();
- // if we have nothing to dock with, fail
- if (dock == NULL)
- return STATE_FAILURE;
- // fail if the dock is closed
- if( dock->isDockOpen() == FALSE )
- {
- dock->cancelDock( getMachineOwner() );
- return STATE_FAILURE;
- }
- // if the dock says we can enter, our wait is over
- if (dock->isClearToEnter( getMachineOwner() ))
- return STATE_SUCCESS;
- if (m_enterFrame + 30*LOGICFRAMES_PER_SECOND < TheGameLogic->getFrame()) {
- return STATE_FAILURE;
- }
- // continue to wait
- return STATE_CONTINUE;
- }
- //----------------------------------------------------------------------------------------------
- void AIDockWaitForClearanceState::onExit( StateExitType status )
- {
- Object *goalObject = getMachineGoalObject();
- DockUpdateInterface *dock = NULL;
- if( goalObject )
- dock = goalObject->getDockUpdateInterface();
- // if we were interrupted, let the dock know we're not coming
- if (dock && (dock->isDockOpen() == FALSE || status == EXIT_RESET))
- dock->cancelDock( getMachineOwner() );
- }
- //----------------------------------------------------------------------------------------------
- void AIDockWaitForClearanceState::xfer(Xfer *xfer )
- {
- XferVersion cv = 2;
- XferVersion v = cv;
- xfer->xferVersion( &v, cv );
- if (v >= 2) {
- xfer->xferUnsignedInt(&m_enterFrame);
- } else {
- m_enterFrame = TheGameLogic->getFrame();
- }
- }
- //----------------------------------------------------------------------------------------------
- //----------------------------------------------------------------------------------------------
- //----------------------------------------------------------------------------------------------
- //----------------------------------------------------------------------------------------------
- /**
- * Advance to our next waiting spot next to the dock.
- */
- StateReturnType AIDockAdvancePositionState::onEnter( void )
- {
- Object *goalObject = getMachineGoalObject();
-
- // sanity
- if( goalObject == NULL )
- return STATE_FAILURE;
- // get dock update interface
- DockUpdateInterface *dock = goalObject->getDockUpdateInterface();
- // if we have nothing to dock with, fail
- if (dock == NULL)
- return STATE_FAILURE;
- // fail if the dock is closed
- if( dock->isDockOpen() == FALSE )
- {
- dock->cancelDock( getMachineOwner() );
- return STATE_FAILURE;
- }
- // get a good place to wait from the dock
- Bool reserved = dock->advanceApproachPosition( getMachineOwner(), &m_goalPosition, &(( (AIDockMachine*)getMachine() )->m_approachPosition) );
- if( reserved == FALSE )
- {
- // dock is full
- return STATE_FAILURE;
- }
- AIUpdateInterface *ai = getMachineOwner()->getAIUpdateInterface();
- if (ai) {
- ai->ignoreObstacle( NULL );
- }
- // this behavior is an extention of basic MoveTo
- return AIInternalMoveToState::onEnter();
- }
- //----------------------------------------------------------------------------------------------
- StateReturnType AIDockAdvancePositionState::update( void )
- {
- Object *goalObject = getMachineGoalObject();
- // if we have nothing to dock with, fail
- if (goalObject == NULL)
- return STATE_FAILURE;
- // this behavior is an extention of basic MoveTo
- return AIInternalMoveToState::update();
- }
- //----------------------------------------------------------------------------------------------
- void AIDockAdvancePositionState::onExit( StateExitType status )
- {
- Object *goalObject = getMachineGoalObject();
- DockUpdateInterface *dock = NULL;
- if( goalObject )
- dock = goalObject->getDockUpdateInterface();
- // tell the dock we have approached
- if (dock)
- {
- // if we were interrupted, let the dock know we're not coming
- if (status == EXIT_RESET || dock->isDockOpen() == FALSE)
- dock->cancelDock( getMachineOwner() );
- else
- dock->onApproachReached( getMachineOwner() );
- }
- // this behavior is an extention of basic MoveTo
- AIInternalMoveToState::onExit( status );
- }
- //----------------------------------------------------------------------------------------------
- //----------------------------------------------------------------------------------------------
- //----------------------------------------------------------------------------------------------
- //----------------------------------------------------------------------------------------------
- /**
- * Move to the dock's entry position.
- */
- StateReturnType AIDockMoveToEntryState::onEnter( void )
- {
- Object *goalObject = getMachineGoalObject();
- DockUpdateInterface *dock = NULL;
- if( goalObject )
- dock = goalObject->getDockUpdateInterface();
- // if we have nothing to dock with, fail
- if (dock == NULL)
- return STATE_FAILURE;
- // fail if the dock is closed
- if( dock->isDockOpen() == FALSE )
- {
- dock->cancelDock( getMachineOwner() );
- return STATE_FAILURE;
- }
- AIUpdateInterface *ai = getMachineOwner()->getAIUpdateInterface();
- if( ai && dock->isAllowPassthroughType() )
- {
- ai->ignoreObstacle( getMachineGoalObject() );
- }
- // get the enter position and set as our goal position
- dock->getEnterPosition( getMachineOwner(), &m_goalPosition );
- ( (AIDockMachine*)getMachine() )->m_approachPosition = -1;
- // this behavior is an extention of basic MoveTo
- return AIInternalMoveToState::onEnter();
- }
- //----------------------------------------------------------------------------------------------
- StateReturnType AIDockMoveToEntryState::update( void )
- {
- // if we have nothing to dock with, fail
- if (getMachineGoalObject() == NULL)
- return STATE_FAILURE;
- // this behavior is an extention of basic MoveTo
- return AIInternalMoveToState::update();
- }
- //----------------------------------------------------------------------------------------------
- void AIDockMoveToEntryState::onExit( StateExitType status )
- {
- Object *goalObject = getMachineGoalObject();
- DockUpdateInterface *dock = NULL;
- if( goalObject )
- dock = goalObject->getDockUpdateInterface();
- if (dock)
- {
- if (dock->isDockOpen() == FALSE || status == EXIT_RESET)
- {
- // if we were interrupted, let the dock know we're not coming
- dock->cancelDock( getMachineOwner() );
- }
- else
- {
- // tell the dock we are at the entrance
- dock->onEnterReached( getMachineOwner() );
- }
- }
- // this behavior is an extention of basic MoveTo
- AIInternalMoveToState::onExit( status );
- }
- //----------------------------------------------------------------------------------------------
- //----------------------------------------------------------------------------------------------
- //----------------------------------------------------------------------------------------------
- //----------------------------------------------------------------------------------------------
- /**
- * Move to the dock's docking position.
- */
- StateReturnType AIDockMoveToDockState::onEnter( void )
- {
- Object *goalObject = getMachineGoalObject();
- DockUpdateInterface *dock = NULL;
- if( goalObject )
- dock = goalObject->getDockUpdateInterface();
- // if we have nothing to dock with, fail
- if (dock == NULL)
- return STATE_FAILURE;
- // fail if the dock is closed
- if( dock->isDockOpen() == FALSE )
- {
- dock->cancelDock( getMachineOwner() );
- return STATE_FAILURE;
- }
- // get the docking position
- dock->getDockPosition( getMachineOwner(), &m_goalPosition );
- AIUpdateInterface *ai = getMachineOwner()->getAIUpdateInterface();
- if( ai && dock->isAllowPassthroughType() )
- {
- ai->ignoreObstacle( getMachineGoalObject() );
- setAdjustsDestination(false);
- }
- // since we are moving inside the dock, disallow interruptions
- getMachine()->lock("AIDockMoveToDockState::onEnter");
- // this behavior is an extention of basic MoveTo
- return AIInternalMoveToState::onEnter();
- }
- //----------------------------------------------------------------------------------------------
- StateReturnType AIDockMoveToDockState::update( void )
- {
- Object *goalObject = getMachineGoalObject();
- // if we have nothing to dock with, fail
- if (goalObject == NULL)
- return STATE_FAILURE;
- DockUpdateInterface *dock = goalObject->getDockUpdateInterface();
- if( dock->isDockOpen() == FALSE )
- return STATE_FAILURE;
- // this behavior is an extention of basic MoveTo
- return AIInternalMoveToState::update();
- }
- //----------------------------------------------------------------------------------------------
- void AIDockMoveToDockState::onExit( StateExitType status )
- {
- Object *goalObject = getMachineGoalObject();
- DockUpdateInterface *dock = NULL;
- if( goalObject )
- dock = goalObject->getDockUpdateInterface();
- // tell the dock we are at the docking point
- if (dock)
- {
- // if we were interrupted, let the dock know we're not coming
- if (status == EXIT_RESET || dock->isDockOpen() == FALSE )
- dock->cancelDock( getMachineOwner() );
- else
- dock->onDockReached( getMachineOwner() );
- }
- // unlock the machine
- getMachine()->unlock();
- // this behavior is an extention of basic MoveTo
- AIInternalMoveToState::onExit( status );
- }
- //----------------------------------------------------------------------------------------------
- //----------------------------------------------------------------------------------------------
- AIDockProcessDockState::AIDockProcessDockState( StateMachine *machine ) : State( machine, "AIDockProcessDockState" )
- {
- m_nextDockActionFrame = 0;
- }
- //----------------------------------------------------------------------------------------------
- //----------------------------------------------------------------------------------------------
- void AIDockProcessDockState::setNextDockActionFrame()
- {
- // If we have a SupplyTruck Interface, then we will ask for our specific delay time
- SupplyTruckAIInterface *supplyTruck = getMachineOwner()->getAI()->getSupplyTruckAIInterface();
- if( supplyTruck )
- {
- m_nextDockActionFrame = TheGameLogic->getFrame() + supplyTruck->getActionDelayForDock( getMachineGoalObject() );
- return;
- }
- // The default is that it is simply okay to Action right away
- m_nextDockActionFrame = TheGameLogic->getFrame();
- }
- //----------------------------------------------------------------------------------------------
- //----------------------------------------------------------------------------------------------
- StateReturnType AIDockProcessDockState::onEnter( void )
- {
- Object *goalObject = getMachineGoalObject();
- DockUpdateInterface *dock = NULL;
- if( goalObject )
- dock = goalObject->getDockUpdateInterface();
- // if we have nothing to dock with, fail
- if (dock == NULL)
- return STATE_FAILURE;
- setNextDockActionFrame();
- return STATE_CONTINUE;
- }
- //----------------------------------------------------------------------------------------------
- //----------------------------------------------------------------------------------------------
- /**
- * We are now docked. Invoke the dock's action() method until it returns false.
- */
- StateReturnType AIDockProcessDockState::update( void )
- {
- Object *goalObject = getMachineGoalObject();
- DockUpdateInterface *dock = NULL;
- if( goalObject )
- dock = goalObject->getDockUpdateInterface();
- // if we have nothing to dock with, fail
- if (dock == NULL)
- return STATE_FAILURE;
- // Some dockers can have a delay built in
- if( TheGameLogic->getFrame() < m_nextDockActionFrame )
- return STATE_CONTINUE;
- setNextDockActionFrame();
- Object *drone = findMyDrone();
- // invoke the dock's action until it tells us it is done or the dock becomes closed
- if( dock->isDockOpen() == false || dock->action( getMachineOwner(), drone ) == false )
- return STATE_SUCCESS;
- return STATE_CONTINUE;
- }
- //----------------------------------------------------------------------------------------------
- struct DroneInfo
- {
- Object *owner;
- Object *drone;
- Bool found;
- };
- void findDrone( Object *obj, void *droneInfo )
- {
- DroneInfo *dInfo = (DroneInfo*)droneInfo;
-
- if( !dInfo->found && obj )
- {
- if( obj->isKindOf( KINDOF_DRONE ) && obj->getProducerID() == dInfo->owner->getID() )
- {
- dInfo->found = TRUE;
- dInfo->drone = obj;
- }
- }
- }
- //----------------------------------------------------------------------------------------------
- Object* AIDockProcessDockState::findMyDrone()
- {
- //First do the fast cached check.
- Object *drone = TheGameLogic->findObjectByID( m_droneID );
- if( drone )
- {
- return drone;
- }
- //Nope... look for a drone (perhaps we just finished building one after docking?)
- Object *self = getMachineOwner();
- Player *player = self->getControllingPlayer();
- DroneInfo dInfo;
- dInfo.found = FALSE;
- dInfo.drone = NULL;
- dInfo.owner = self;
- //Iterate the objects in search for a drone with a producer ID of me.
- if( player )
- {
- player->iterateObjects( findDrone, &dInfo );
- }
- //If we found a drone, store it's ID as cached.
- if( dInfo.drone )
- {
- m_droneID = dInfo.drone->getID();
- }
- return dInfo.drone;
- }
- //----------------------------------------------------------------------------------------------
- void AIDockProcessDockState::onExit( StateExitType status )
- {
- // unlock the machine
- getMachine()->unlock();
- }
- //----------------------------------------------------------------------------------------------
- //----------------------------------------------------------------------------------------------
- //----------------------------------------------------------------------------------------------
- //----------------------------------------------------------------------------------------------
- /**
- * Move to the dock's exit position.
- */
- StateReturnType AIDockMoveToExitState::onEnter( void )
- {
- Object *goalObject = getMachineGoalObject();
- DockUpdateInterface *dock = NULL;
- if( goalObject )
- dock = goalObject->getDockUpdateInterface();
- // if we have nothing to dock with, fail
- if (dock == NULL)
- return STATE_FAILURE;
- // get the exit position
- dock->getExitPosition( getMachineOwner(), &m_goalPosition );
- AIUpdateInterface *ai = getMachineOwner()->getAIUpdateInterface();
- if( ai && dock->isAllowPassthroughType() )
- {
- ai->ignoreObstacle( getMachineGoalObject() );
- setAdjustsDestination(false);
- }
- // this behavior is an extention of basic MoveTo
- return AIInternalMoveToState::onEnter();
- }
- //----------------------------------------------------------------------------------------------
- StateReturnType AIDockMoveToExitState::update( void )
- {
- // if we have nothing to dock with, fail
- if (getMachineGoalObject() == NULL)
- return STATE_FAILURE;
- // this behavior is an extention of basic MoveTo
- return AIInternalMoveToState::update();
- }
- //----------------------------------------------------------------------------------------------
- void AIDockMoveToExitState::onExit( StateExitType status )
- {
- Object *goalObject = getMachineGoalObject();
- DockUpdateInterface *dock = NULL;
- if( goalObject )
- dock = goalObject->getDockUpdateInterface();
- // tell the dock we have exited
- if (dock)
- dock->onExitReached( getMachineOwner() );
- // unlock the machine
- getMachine()->unlock();
- // this behavior is an extention of basic MoveTo
- AIInternalMoveToState::onExit( status );
- }
- //----------------------------------------------------------------------------------------------
- //----------------------------------------------------------------------------------------------
- //----------------------------------------------------------------------------------------------
- //----------------------------------------------------------------------------------------------
- /**
- * Move to the dock's rally position, if he wants me to.
- */
- StateReturnType AIDockMoveToRallyState::onEnter( void )
- {
- Object *goalObject = getMachineGoalObject();
- DockUpdateInterface *dock = NULL;
- if( goalObject )
- dock = goalObject->getDockUpdateInterface();
- // if we have nothing to dock with, fail
- if (dock == NULL)
- return STATE_FAILURE;
- // if they don't have anywhere to send us, then we are good
- if( ! dock->isRallyPointAfterDockType() //Chooses not to
- || goalObject->getObjectExitInterface() == NULL //or can't
- || goalObject->getObjectExitInterface()->getRallyPoint() == NULL //or can't right now.
- )
- {
- return STATE_SUCCESS; // Success in an Enter is like success in an update. We're all fine here
- }
- // get the rally point and set as our goal position
- m_goalPosition = *goalObject->getObjectExitInterface()->getRallyPoint();
- // this behavior is an extention of basic MoveTo
- return AIInternalMoveToState::onEnter();
- }
- //----------------------------------------------------------------------------------------------
- StateReturnType AIDockMoveToRallyState::update( void )
- {
- // This state is fine with the loss of the goal object after the move starts
- // this behavior is an extention of basic MoveTo
- return AIInternalMoveToState::update();
- }
- //----------------------------------------------------------------------------------------------
- void AIDockMoveToRallyState::onExit( StateExitType status )
- {
- // This state is fine with the loss of the goal object after the move starts
- // this behavior is an extention of basic MoveTo
- AIInternalMoveToState::onExit( status );
- }
|