Skip to content

Commit ac59d40

Browse files
committed
bugfix: Builders now resume their task after having been disabled
1 parent 6461ca5 commit ac59d40

File tree

9 files changed

+75
-4
lines changed

9 files changed

+75
-4
lines changed

Generals/Code/GameEngine/Include/GameLogic/Module/DozerAIUpdate.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ class DozerAIInterface
140140
// task actions
141141
virtual void newTask( DozerTask task, Object *target ) = 0; ///< set a desire to do the requrested task
142142
virtual void cancelTask( DozerTask task ) = 0; ///< cancel this task from the queue, if it's the current task the dozer will stop working on it
143+
virtual void resumePreviousTask(void) = 0; ///< resume the previous task if there was one
143144

144145
// internal methods to manage behavior from within the dozer state machine
145146
virtual void internalTaskComplete( DozerTask task ) = 0; ///< set a dozer task as successfully completed
@@ -239,6 +240,7 @@ class DozerAIUpdate : public AIUpdateInterface, public DozerAIInterface
239240
// task actions
240241
virtual void newTask( DozerTask task, Object *target ); ///< set a desire to do the requrested task
241242
virtual void cancelTask( DozerTask task ); ///< cancel this task from the queue, if it's the current task the dozer will stop working on it
243+
virtual void resumePreviousTask(void); ///< resume the previous task if there was one
242244

243245
// internal methods to manage behavior from within the dozer state machine
244246
virtual void internalTaskComplete( DozerTask task ); ///< set a dozer task as successfully completed
@@ -282,6 +284,8 @@ class DozerAIUpdate : public AIUpdateInterface, public DozerAIInterface
282284

283285
DozerPrimaryStateMachine *m_dozerMachine; ///< the custom state machine for Dozer behavior
284286
DozerTask m_currentTask; ///< current task the dozer is attending to (if any)
287+
DozerTask m_previousTask; ///< previous task the dozer was attending to (if any)
288+
DozerTaskInfo m_previousTaskInfo; ///< info on the previous task the dozer was attending to (if any)
285289
AudioEventRTS m_buildingSound; ///< sound is pulled from the object we are building!
286290
Bool m_isRebuild; ///< is this a rebuild of a previous building?
287291

Generals/Code/GameEngine/Include/GameLogic/Module/WorkerAIUpdate.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ class WorkerAIUpdate : public AIUpdateInterface, public DozerAIInterface, public
155155
// task actions
156156
virtual void newTask( DozerTask task, Object* target ); ///< set a desire to do the requrested task
157157
virtual void cancelTask( DozerTask task ); ///< cancel this task from the queue, if it's the current task the dozer will stop working on it
158+
virtual void resumePreviousTask(void); ///< resume the previous task if there was one
158159

159160
// internal methods to manage behavior from within the dozer state machine
160161
virtual void internalTaskComplete( DozerTask task ); ///< set a dozer task as successfully completed
@@ -218,6 +219,8 @@ class WorkerAIUpdate : public AIUpdateInterface, public DozerAIInterface, public
218219

219220

220221
DozerTask m_currentTask; ///< current task the dozer is attending to (if any)
222+
DozerTask m_previousTask; ///< previous task the dozer was attending to (if any)
223+
DozerTaskInfo m_previousTaskInfo; ///< info on the previous task the dozer was attending to (if any)
221224

222225
//
223226
// the following info array can be used if we want to have more complicated approaches

Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DozerAIUpdate.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2037,6 +2037,15 @@ void DozerAIUpdate::cancelTask( DozerTask task )
20372037

20382038
}
20392039

2040+
//-------------------------------------------------------------------------------------------------
2041+
/** Attempt to resume the previous task */
2042+
//-------------------------------------------------------------------------------------------------
2043+
void DozerAIUpdate::resumePreviousTask(void)
2044+
{
2045+
if (m_previousTask != DOZER_TASK_INVALID)
2046+
newTask(m_previousTask, TheGameLogic->findObjectByID(m_previousTaskInfo.m_targetObjectID));
2047+
}
2048+
20402049
//-------------------------------------------------------------------------------------------------
20412050
/** Is there a given task waiting to be done */
20422051
//-------------------------------------------------------------------------------------------------
@@ -2115,6 +2124,9 @@ void DozerAIUpdate::internalCancelTask( DozerTask task )
21152124
// call the single method that gets called for completing and canceling tasks
21162125
internalTaskCompleteOrCancelled( task );
21172126

2127+
m_previousTask = task;
2128+
m_previousTaskInfo = m_task[task];
2129+
21182130
// remove the info for this task
21192131
m_task[ task ].m_targetObjectID = INVALID_ID;
21202132
m_task[ task ].m_taskOrderFrame = 0;

Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/WorkerAIUpdate.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,15 @@ void WorkerAIUpdate::cancelTask( DozerTask task )
695695

696696
}
697697

698+
//-------------------------------------------------------------------------------------------------
699+
/** Attempt to resume the previous task */
700+
//-------------------------------------------------------------------------------------------------
701+
void WorkerAIUpdate::resumePreviousTask(void)
702+
{
703+
if (m_previousTask != DOZER_TASK_INVALID)
704+
newTask(m_previousTask, TheGameLogic->findObjectByID(m_previousTaskInfo.m_targetObjectID));
705+
}
706+
698707
//-------------------------------------------------------------------------------------------------
699708
/** Is there a given task waiting to be done */
700709
//-------------------------------------------------------------------------------------------------
@@ -773,6 +782,9 @@ void WorkerAIUpdate::internalCancelTask( DozerTask task )
773782
// call the single method that gets called for completing and canceling tasks
774783
internalTaskCompleteOrCancelled( task );
775784

785+
m_previousTask = task;
786+
m_previousTaskInfo = m_task[task];
787+
776788
// remove the info for this task
777789
m_task[ task ].m_targetObjectID = INVALID_ID;
778790
m_task[ task ].m_taskOrderFrame = 0;

GeneralsMD/Code/GameEngine/Include/GameLogic/Module/DozerAIUpdate.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ class DozerAIInterface
140140
// task actions
141141
virtual void newTask( DozerTask task, Object *target ) = 0; ///< set a desire to do the requrested task
142142
virtual void cancelTask( DozerTask task ) = 0; ///< cancel this task from the queue, if it's the current task the dozer will stop working on it
143+
virtual void resumePreviousTask(void) = 0; ///< resume the previous task if there was one
143144

144145
// internal methods to manage behavior from within the dozer state machine
145146
virtual void internalTaskComplete( DozerTask task ) = 0; ///< set a dozer task as successfully completed
@@ -239,6 +240,7 @@ class DozerAIUpdate : public AIUpdateInterface, public DozerAIInterface
239240
// task actions
240241
virtual void newTask( DozerTask task, Object *target ); ///< set a desire to do the requrested task
241242
virtual void cancelTask( DozerTask task ); ///< cancel this task from the queue, if it's the current task the dozer will stop working on it
243+
virtual void resumePreviousTask(void); ///< resume the previous task if there was one
242244

243245
// internal methods to manage behavior from within the dozer state machine
244246
virtual void internalTaskComplete( DozerTask task ); ///< set a dozer task as successfully completed
@@ -282,6 +284,8 @@ class DozerAIUpdate : public AIUpdateInterface, public DozerAIInterface
282284

283285
DozerPrimaryStateMachine *m_dozerMachine; ///< the custom state machine for Dozer behavior
284286
DozerTask m_currentTask; ///< current task the dozer is attending to (if any)
287+
DozerTask m_previousTask; ///< previous task the dozer was attending to (if any)
288+
DozerTaskInfo m_previousTaskInfo; ///< info on the previous task the dozer was attending to (if any)
285289
AudioEventRTS m_buildingSound; ///< sound is pulled from the object we are building!
286290
Bool m_isRebuild; ///< is this a rebuild of a previous building?
287291

GeneralsMD/Code/GameEngine/Include/GameLogic/Module/WorkerAIUpdate.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ class WorkerAIUpdate : public AIUpdateInterface, public DozerAIInterface, public
158158
// task actions
159159
virtual void newTask( DozerTask task, Object* target ); ///< set a desire to do the requrested task
160160
virtual void cancelTask( DozerTask task ); ///< cancel this task from the queue, if it's the current task the dozer will stop working on it
161+
virtual void resumePreviousTask(void); ///< resume the previous task if there was one
161162

162163
// internal methods to manage behavior from within the dozer state machine
163164
virtual void internalTaskComplete( DozerTask task ); ///< set a dozer task as successfully completed
@@ -223,6 +224,8 @@ class WorkerAIUpdate : public AIUpdateInterface, public DozerAIInterface, public
223224

224225

225226
DozerTask m_currentTask; ///< current task the dozer is attending to (if any)
227+
DozerTask m_previousTask; ///< previous task the dozer was attending to (if any)
228+
DozerTaskInfo m_previousTaskInfo; ///< info on the previous task the dozer was attending to (if any)
226229

227230
//
228231
// the following info array can be used if we want to have more complicated approaches

GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3809,11 +3809,20 @@ void Object::onDisabledEdge(Bool becomingDisabled)
38093809
(*module)->onDisabledEdge( becomingDisabled );
38103810

38113811
DozerAIInterface *dozerAI = getAI() ? getAI()->getDozerAIInterface() : NULL;
3812-
if( becomingDisabled && dozerAI )
3812+
if (dozerAI)
38133813
{
3814-
// Have to say goodbye to the thing we might be building or repairing so someone else can do it.
3815-
if( dozerAI->getCurrentTask() != DOZER_TASK_INVALID )
3816-
dozerAI->cancelTask( dozerAI->getCurrentTask() );
3814+
if (becomingDisabled)
3815+
{
3816+
// Have to say goodbye to the thing we might be building or repairing so someone else can do it.
3817+
if (dozerAI->getCurrentTask() != DOZER_TASK_INVALID)
3818+
dozerAI->cancelTask(dozerAI->getCurrentTask());
3819+
}
3820+
else
3821+
{
3822+
#if !RETAIL_COMPATIBLE_CRC
3823+
dozerAI->resumePreviousTask();
3824+
#endif
3825+
}
38173826
}
38183827

38193828
Player* controller = getControllingPlayer();

GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DozerAIUpdate.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2042,6 +2042,15 @@ void DozerAIUpdate::cancelTask( DozerTask task )
20422042

20432043
}
20442044

2045+
//-------------------------------------------------------------------------------------------------
2046+
/** Attempt to resume the previous task */
2047+
//-------------------------------------------------------------------------------------------------
2048+
void DozerAIUpdate::resumePreviousTask(void)
2049+
{
2050+
if (m_previousTask != DOZER_TASK_INVALID)
2051+
newTask(m_previousTask, TheGameLogic->findObjectByID(m_previousTaskInfo.m_targetObjectID));
2052+
}
2053+
20452054
//-------------------------------------------------------------------------------------------------
20462055
/** Is there a given task waiting to be done */
20472056
//-------------------------------------------------------------------------------------------------
@@ -2120,6 +2129,9 @@ void DozerAIUpdate::internalCancelTask( DozerTask task )
21202129
// call the single method that gets called for completing and canceling tasks
21212130
internalTaskCompleteOrCancelled( task );
21222131

2132+
m_previousTask = task;
2133+
m_previousTaskInfo = m_task[task];
2134+
21232135
// remove the info for this task
21242136
m_task[ task ].m_targetObjectID = INVALID_ID;
21252137
m_task[ task ].m_taskOrderFrame = 0;

GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/WorkerAIUpdate.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,15 @@ void WorkerAIUpdate::cancelTask( DozerTask task )
695695

696696
}
697697

698+
//-------------------------------------------------------------------------------------------------
699+
/** Attempt to resume the previous task */
700+
//-------------------------------------------------------------------------------------------------
701+
void WorkerAIUpdate::resumePreviousTask(void)
702+
{
703+
if (m_previousTask != DOZER_TASK_INVALID)
704+
newTask(m_previousTask, TheGameLogic->findObjectByID(m_previousTaskInfo.m_targetObjectID));
705+
}
706+
698707
//-------------------------------------------------------------------------------------------------
699708
/** Is there a given task waiting to be done */
700709
//-------------------------------------------------------------------------------------------------
@@ -773,6 +782,9 @@ void WorkerAIUpdate::internalCancelTask( DozerTask task )
773782
// call the single method that gets called for completing and canceling tasks
774783
internalTaskCompleteOrCancelled( task );
775784

785+
m_previousTask = task;
786+
m_previousTaskInfo = m_task[task];
787+
776788
// remove the info for this task
777789
m_task[ task ].m_targetObjectID = INVALID_ID;
778790
m_task[ task ].m_taskOrderFrame = 0;

0 commit comments

Comments
 (0)