forked from electronicarts/CnC_Generals_Zero_Hour
-
Notifications
You must be signed in to change notification settings - Fork 250
bugfix: Fix issue where builders could resume completed tasks after being disabled #2793
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Stubbjax
wants to merge
19
commits into
TheSuperHackers:main
Choose a base branch
from
Stubbjax:fix-previous-dozer-task
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+303
−74
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
68743ff
bugfix: Fix issue where builders could resume completed tasks after b…
Stubbjax 8b4cd2e
bugfix: Only save the previous task for resumption when explicitly di…
Stubbjax 0c66471
refactor: Move fix to the task resumption method
Stubbjax 6cf851a
docs: Remove superfluous comments
Stubbjax dc11862
refactor: Check construction status bit instead of construction percent
Stubbjax 122edf0
tweak: Still clear previous task if the resumed build fails
Stubbjax 04e0119
refactor: Optimise target acquisition
Stubbjax cbb639a
fix: Reverse condition
Stubbjax 2145c6a
bugfix: Apply correct version condition
Stubbjax cb68740
tweak: Support resumption of repair tasks
Stubbjax 506f141
refactor: Streamline previous task assignment
Stubbjax 5f41b3b
refactor: Push down onDisabledEdge behaviour to DozerAIUpdate and Wor…
Stubbjax 155c6d4
refactor: Remember task as part of cancellation
Stubbjax 3886b38
refactor: Consolidate previous task clearing logic
Stubbjax 6bc5dac
bugfix: Also resume FORTIFY tasks
Stubbjax 3c36a85
bugfix: Cancelling all tasks now clears the previous task
Stubbjax a87efc3
docs: Explain new method argument
Stubbjax 47ccf55
chore: Move previous-task methods from the interface to the implementers
Stubbjax d85087d
chore: Clear previous task if we're not remembering
Stubbjax File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2045,8 +2045,12 @@ void DozerAIUpdate::newTask( DozerTask task, Object *target ) | |
| * re-evaluate what it wants to do if it was working on the task being | ||
| * cancelled */ | ||
| //------------------------------------------------------------------------------------------------- | ||
| void DozerAIUpdate::cancelTask( DozerTask task ) | ||
| void DozerAIUpdate::cancelTask( DozerTask task, Bool rememberTask ) | ||
| { | ||
| if (rememberTask) | ||
| setPreviousTask(task); | ||
| else | ||
| clearPreviousTask(); | ||
|
|
||
| // clear the order | ||
| internalCancelTask( task ); | ||
|
|
@@ -2061,20 +2065,51 @@ void DozerAIUpdate::cancelAllTasks() | |
| for (UnsignedInt task = DOZER_TASK_FIRST; task < DOZER_NUM_TASKS; ++task) | ||
| internalCancelTask((DozerTask)task); | ||
|
|
||
| clearPreviousTask(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better move it up so it is consistent with the call order in |
||
|
|
||
| m_dozerMachine->resetToDefaultState(); | ||
| } | ||
|
|
||
| //------------------------------------------------------------------------------------------------- | ||
| /** Set the previous task so that we may return to it if we become temporarily incapacitated */ | ||
| //------------------------------------------------------------------------------------------------- | ||
| void DozerAIUpdate::setPreviousTask(DozerTask task) | ||
| { | ||
| if (task == DOZER_TASK_INVALID) | ||
| return; | ||
|
|
||
| m_previousTask = task; | ||
| m_previousTaskInfo = m_task[task]; | ||
| } | ||
|
|
||
| //------------------------------------------------------------------------------------------------- | ||
| /** Attempt to resume the previous task */ | ||
| //------------------------------------------------------------------------------------------------- | ||
| void DozerAIUpdate::resumePreviousTask() | ||
| { | ||
| if (m_previousTask != DOZER_TASK_INVALID) | ||
| if (m_previousTask == DOZER_TASK_INVALID) | ||
| return; | ||
|
|
||
| if (m_previousTask == DOZER_TASK_BUILD) | ||
| { | ||
| Object* target = TheGameLogic->findObjectByID(m_previousTaskInfo.m_targetObjectID); | ||
| if (target && target->testStatus(OBJECT_STATUS_UNDER_CONSTRUCTION)) | ||
| newTask(m_previousTask, target); | ||
| } | ||
| else if (m_previousTask == DOZER_TASK_REPAIR || m_previousTask == DOZER_TASK_FORTIFY) | ||
| { | ||
| newTask(m_previousTask, TheGameLogic->findObjectByID(m_previousTaskInfo.m_targetObjectID)); | ||
| m_previousTask = DOZER_TASK_INVALID; | ||
| m_previousTaskInfo = DozerTaskInfo(); | ||
| Object* target = TheGameLogic->findObjectByID(m_previousTaskInfo.m_targetObjectID); | ||
| if (target) | ||
| newTask(m_previousTask, target); | ||
| } | ||
|
|
||
| clearPreviousTask(); | ||
| } | ||
|
|
||
| void DozerAIUpdate::clearPreviousTask() | ||
| { | ||
| m_previousTask = DOZER_TASK_INVALID; | ||
| m_previousTaskInfo = DozerTaskInfo(); | ||
| } | ||
|
|
||
| //------------------------------------------------------------------------------------------------- | ||
|
|
@@ -2133,8 +2168,7 @@ void DozerAIUpdate::internalTaskComplete( DozerTask task ) | |
| m_task[ task ].m_targetObjectID = INVALID_ID; | ||
| m_task[ task ].m_taskOrderFrame = 0; | ||
|
|
||
| m_previousTask = DOZER_TASK_INVALID; | ||
| m_previousTaskInfo = DozerTaskInfo(); | ||
| clearPreviousTask(); | ||
|
|
||
| // remove dock point info for this task | ||
| for( Int i = 0; i < DOZER_NUM_DOCK_POINTS; i++ ) | ||
|
|
@@ -2158,9 +2192,6 @@ void DozerAIUpdate::internalCancelTask( DozerTask task ) | |
| // call the single method that gets called for completing and canceling tasks | ||
| internalTaskCompleteOrCancelled( task ); | ||
|
|
||
| m_previousTask = task; | ||
| m_previousTaskInfo = m_task[task]; | ||
|
|
||
| // remove the info for this task | ||
| m_task[ task ].m_targetObjectID = INVALID_ID; | ||
| m_task[ task ].m_taskOrderFrame = 0; | ||
|
|
@@ -2297,6 +2328,32 @@ void DozerAIUpdate::onDelete() | |
| } | ||
| } | ||
|
|
||
| void DozerAIUpdate::onDisabledEdge(Bool nowDisabled) | ||
| { | ||
| if (nowDisabled) | ||
| { | ||
| // Have to say goodbye to the thing we might be building or repairing so someone else can do it. | ||
| if (getCurrentTask() != DOZER_TASK_INVALID) | ||
| { | ||
| // TheSuperHackers @info We want to explicitly define what types to resume from as some types | ||
| // are undesirable (e.g. DISABLED_HELD via entering/exiting a container). | ||
| Bool rememberTask = getObject()->isDisabledByType(DISABLED_EMP) || | ||
| getObject()->isDisabledByType(DISABLED_HACKED) || | ||
| getObject()->isDisabledByType(DISABLED_SUBDUED) || | ||
| getObject()->isDisabledByType(DISABLED_UNDERPOWERED); | ||
|
|
||
| cancelTask(getCurrentTask(), rememberTask); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| #if !RETAIL_COMPATIBLE_CRC | ||
| // TheSuperHackers @bugfix Stubbjax 17/11/2025 Resume previous task when re-enabled. | ||
| resumePreviousTask(); | ||
| #endif | ||
| } | ||
| } | ||
|
|
||
| //------------------------------------------------------------------------------------------------- | ||
| /** Get the most recently issued task */ | ||
| //------------------------------------------------------------------------------------------------- | ||
|
|
@@ -2511,7 +2568,7 @@ void DozerAIUpdate::xfer( Xfer *xfer ) | |
| xfer->xferSnapshot(m_dozerMachine); | ||
| xfer->xferUser(&m_currentTask, sizeof(m_currentTask)); | ||
|
|
||
| if (currentVersion >= 2) | ||
| if (version >= 2) | ||
| { | ||
| xfer->xferUser(&m_previousTask, sizeof(m_previousTask)); | ||
| xfer->xferUser(&m_previousTaskInfo, sizeof(m_previousTaskInfo)); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.