CleverRaven / Cataclysm-DDA

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

Let's get a simple script to get NPCs started driving. Those layabouts have been riding shotgun too long. #56662

Open I-am-Erk opened 2 years ago

I-am-Erk commented 2 years ago

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

We have a robust system for autodrive, and for some time we've known that this could be used to get NPCs to drive. With the addition of random encounters, I now have a more immediate need for this function. Using random encounters as a start point for autodrive is a very good way for us to start developing NPC driving, because it lets us circumvent some of the early problems and test it out as a feature. Specifically, if used for scripted events, we don't need to worry about long distance travel on the overmap, for example, because a first pass implementation can have vehicles despawn once they hit the edge of the map. It also lets us skip various details related to the AI deciding when to drive and things, because it'll be the script, not the AI, that does it.

Solution you would like.

The gist of it is, we add an effect framework for giving a vehicle an autodrive destination, then have it go there. We need a few steps to this for error trapping. The effect should target the vehicle, not an NPC.

Example JSON code:

"effect": [
  { "autodrive": { "vehicle": "FM_early_pickup", "need_driver": true, "pause": 100, "drive_safe": true, "destination": "evac_center_8", "force": "east", "exeunt": true } }
]

Breakdown

Basic algorithm

  1. if required, check if NPC is in driver's seat. If not, repeat this step every turn. OPTIONAL: We might want a setting to require that the npc be the same faction as the vehicle, to prevent weird stuff like your follower NPC wandering into the seat and getting dragged off. Getting further advanced, we could have settings for the vehicle to not drive if any non-faction NPCs are in it, or to require particular NPCs by ID to be on board.
  2. start vehicle. If vehicle can't start, try again.
  3. Wait pause number of turns
  4. if drive_safe is true, check if a non-hostile character is within 10 tiles of the front of the vehicle. If yes, wait 1 turn and repeat this step.
  5. set autodrive target to designated OMT.
  6. If designated OMT can't be found, set autodrive target 10 OMTs to the force direction.
  7. If no force direction is specified and designated OMT can't be found, cancel with an error.
  8. drive. If vehicle can't drive for some reason, eg. not enough wheels or fuel, cancel script. However, if exeunt was active, still despawn vehicle and NPCs once they leave the reality bubble.

I am not sure if we have the infrastructure to have vehicles travel outside the reality bubble like NPCs do. If not, then for a first pass we should force exeunt=true for now, but keep the syntax in place for later when we can allow vehicles to travel on the overmap without the player

Note that even if the vehicle couldn't drive off for some reason, if it's set to exeunt it should still despawn when it leaves the reality bubble.

Describe alternatives you have considered.

I think this basic mechanic is pretty straightforward, but it could be made simpler by being a "drive_away" effect, which then implies some of the settings automatically. That doesn't let us do as much cool stuff with it though.

The same code could be adapted into a few other JSON effects, such as;

Additional context

Can you imagine what this will do to the 'lived in feeling' of the world? You're stopped by the road, then a car drives up, parks, people get out and take a break, then get back in and drive off? This would make that possible.

PatrikLundell commented 2 years ago

Not sure if this is implied by "NPC", but whatever gets into the driver's seat ought to be checked to actually be capable of driving, or you may get effects such as a fox, zombie, (normal) feral, zomborg, or exodii quadroped driving off.

Faction checks should also be performed, or you can get weirdness such as robbers attacking merchants get one of the robbers driving off with a support vehicle because the robber pathed through the vehicle (and cool but unintended stuff such as a robber accidentally drives off with the vehicle carrying all the loot).

I-am-Erk commented 2 years ago

The only bad unexpected consequence I can see is if a player faction Npc gets sucked away and despawns with the free merchant car, never to be seen again. Robbers doing that would be just emergent behaviour, since it would make the script into "bandits stole the truck".

Monsters and pets aren't characters so a check for a character in the driver's seat wouldn't register them.

Zireael07 commented 2 years ago

Dupe/related to this one: https://github.com/CleverRaven/Cataclysm-DDA/issues/48859

I-am-Erk commented 2 years ago

Less related than it seems, since that would use the towing mechanic... but more related than it seems since towing mechanic is secretly autodrive.

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. Please do not bump or comment on this issue unless you are actively working on it. Stale issues, and stale issues that are closed are still considered.