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
Rewrite tool_dig_to_pos2 (part 2) #2845
Draft
eddebaby
wants to merge
7
commits into
dkfans:master
Choose a base branch
from
eddebaby:rewrite_tool_dig_to_pos2_part2
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
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.
Draft
Conversation
This file contains 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
might be more stuff to gather from my notes. Just want it in a commit finally.
This reverts commit 0454396.
In the future
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Rewrite tool_dig_to_pos2 and its children.
Cleanly isolates
tool_dig_to_pos2
(and its children) in to 3 main parts:This PR resolves the chicken and egg situation of "needing requirements to start implementation" and "needing to know the intended design of the implementation to write the requirements" - I have reverse-engineered the design and implementation of DK/KFX mark for digging path finding by observing the behaviour in both DK and KFX (they are ~95% identical), and then confirming my assumptions in the KFX codebase.
So if the requirements for the "dig to" CPU player tasks are different to the requirements fulfilled in this PR, then this thorough explanation of "how it works in master at the current time" should allow said requirements to be written so that programmers may work sanely.
The "dig to" CPU player tasks
tool_dig_to_pos2
is called bysimulate_dig_to
,task_dig_room_passage
,task_dig_to_entrance
,task_dig_to_gold
,task_dig_to_attack
, andtask_dig_to_neutral
tool_dig_to_pos2
traces a path, slab by slab, from the beginning slab, to the destination slab (struct ComputerDig
) - using the ariadne wallhug algorithm (see below).tool_dig_to_pos2
returns when a slab has been marked for digging (or another action has been triggered).tool_dig_to_pos2
(and the calling task function above) is called again and again (e.g. after each slab marked for digging) until the task is marked as done.tool_dig_to_pos2
returns the "result of the last processed slab".task_dig_...
handles the "result of the last processed slab" and decides whether to continue the dig task, wait for a sub-task, or end the dig task.The "result of the last processed slab" is:
0
for "impassable">= 1
for "passable"< 0
for "exittool_dig_to_pos2
and return totask_dig_...
" (e.g. destination reached, slab marked for digging, error).Reimplement the DK "ariadne_wallhug" algorithm - without the decompiled C.
The "ariadne wallhug" algorithm in Dungeon Keeper is a maze-solving algorithm with similarities to the Pledge algorithm and the Chain algorithm.
Function overview
ariadne_wallhug
- loop, return on slab = (destination/action complete/action queued/error)ariadne_wallhug_single_step
- either step towards destination, or return the result ofwall_follow_single_step
wall_follow_single_step
- follow the wall (using the passed rule: left-hand or right-hand)setup_look_ahead_robots
- sets up a left-hand rule following robot, and a right-hand rule following robot, each robot loops throughariadne_wallhug_single_step
providing a breadth-first approach to decide whether the left-hand rule is best, or the right-hand rule is best.ariadne_wallhug
is called bytool_dig_to_pos2_f
and requires a properly setupstruct ComputerDig
to function.ariadne_wallhug_single_step
calls onsmall_index_towards_destination
(andsmall_index_towards_direction
for the robots) to measure the distance between the current slab and the destination slab.Both
ariadne_wallhug_single_step
andwall_follow_single_step
call oncheck_slab
to check whether a slab is "good for a computer dig path" and uses this slab status to filter behaviour.Algorithm psuedocode