CleverRaven / Cataclysm-DDA

Cataclysm - Dark Days Ahead. A turn-based survival game set in a post-apocalyptic world.
http://cataclysmdda.org
Other
10.1k stars 4.1k forks source link

Record path then take it (again and again). #74433

Open Brambor opened 2 months ago

Brambor commented 2 months ago

Is your feature request related to a problem? Please describe.

TL;DR: I want to record the perfect path from a mine entrance to the bottom, then take it.

Long version: I want to take the path I took last time and I want to spend as little IRL time as possible. I know the path by heart. Just follow the rails on the right and step aside when pit ahead. I would like to input this path once and let the game travel me to the end. Failing that, I am punished by falling into a pit because I don't want to tediously press the keys, I am bored doing it the 10th time. Realistically, my character would remember. I would remember IRL if I might fall into a pit. But I have 0 adrenaline sitting behind a keyboard pressing keys. It is a game. Let me do the fun stuff. Not the travel to stuff.

Existing solutions.

Solution you would like.

Record a path:

  1. Open a menu, and press "Start recording".
    • This makes a new vector and puts the starting position in.
  2. Player moves. (repeatable)
    • Add the destination tripoint to the end of the vector.
    • Must work for stairs etc. (across multiple z-levels).
  3. Open a menu, and press "End and save recording".
    • Save the vector somewhere.

Walk the path:

  1. Open a menu and press "Walk the path".
    • Check that the player is on a tile that corresponds to exactly one tripoint that is the start or the end of a path.
    • If so, travel to the other end. This is an activity, so SAFEMODE etc. works. Hauling also works, I want to use this with hauling.

Starting the auto walk: I imagine this like with auto hauling: the player presses \ to open a menu and \ again to haul all items under their feet. Just like that, I want a double press to start walking.

You could make four points in front of your base, each of them leading you all the way to a different place. Or maybe make a decision at each crossroads. Both would work.

I said player, I meant Character. Let's implement it for the Character right away. It might be useful later.

Quality of life.

When recording a new path: Going back to a tripoint you were already on, delete the loop you made.

image

Example path. Green is the final path from start to end. Red are the deleted loops. Pink is near a path that was already taken and it is in the final path.

The loop is deleted the moment you step to a tripoint you already were on.

Activated with a checkbox in the menu (on by default).

An example when you don't want to delete a loop: you are grabbing a vehicle and you need to turn it around.

Possible optimizations.

Don't store each tripoint. We can skip straight lines or other such easy things.

Or don't store tripoints at all. Just directions (example path: north, north, up a z level, south-west). Which is 10 bits instead of whatever the size of a tripoint is (I assume 3 x 32 bits).

Currently I implemented a vector of tripoints. To find a loop, we don't need to search the whole vector. The character in one step can (at maximum) increase/decrease z level by 1, or go diagonally. Look at one point at index i, count the distance from the new point dist = abs(z1-z2) + max(abs(x1-x2), abs(y1-y2)). The new point cannot be at indexes i-dist+1, ..., i+dist-1. So skip those in loop checking. In case of straight path, this makes search closer to O(1) than to O(n).

Describe alternatives you have considered.

Walk the path step 1.

Additional context

No response

Brambor commented 2 months ago

I really need to do something else.... but....

Brambor commented 2 months ago

There more discussion of this on Discord: https://discord.com/channels/598523535169945603/598529174302490644/1249842203056930826

dominic-dimico commented 2 months ago

This would be wonderful. Yes! The ability to create a path using intermediate points that you walk through. The old AD&D CRPGs like Baldur's Gate had pathsetting features like this, where you'd right-click in a sequence and your character would walk in optimal sub-paths to all those points.

You know, this reminds me. Vim has a feature where it records keystrokes into macros. You can play the exact keystrokes back by invoking the macro. If you were implement it this way, you wouldn't have to rely on pathfinding; but you would be at the mercy of your own macro definitions, if you know what I mean. Not only walking, but also other repetitive activities could be handled this way. Just a thought.

Brambor commented 2 months ago

My current local implementation records the tripoints you step on specifically. I don't want to get into the weeds of key recording. I want it simple and bug-resistant. This also allows for some QoL optimizations that you couldn't get with plain key recording (the loop detection).

I hope to make a PR today (at least a draft).

Brambor commented 2 months ago

I am not implementing any visuals to the path. This PR displays NPC path on overmap, maybe I could steel from it:

Brambor commented 2 months ago

If anyone has suggestions for keybinding to open the menu, I am all ears! Locally I am doing it with CTRL+M which cannot be pushed.

Brambor commented 2 months ago

This is how it currently looks btw. (WIP): image