Description
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
- vehicle: Required. What vehicle is driving off? This should use the same vehicle selection algorithm that
remove_vehicles
in mapgen does, for consistency. For obvious reasons, most scripts should give the vehicle a unique name so that the player's vehicle doesn't decide to leave on its own. - need_driver: not required, default true. If false, the vehicle will start up and go whether or not someone is at the wheel. If true, the vehicle will plan its autodrive and initiate as soon as a valid driver besides the player is at the controls. This is to allow us to create an effect telling the vehicle to move at the same time as an effect telling an npc to get into the driver's seat, without having to carefully time things.
- pause: not required, default 10. Time to wait in seconds between starting the car and driving off. Another tool for keeping the car from driving off with its passengers left behind.
- drive_safe: not required, default true. Should the car pay attention to NPCs in front of it, or not? If true, the car won't start driving if there's a character within about a car length ahead. Optionally, we might have them wait the duration in
pause
and then, if there's someone just standing there, begin moving forward at minimum speed to try to clue them in. If the option exists to have the car navigate around the player, that would also be nice. Also would be fun if the driver started using those npc snippets for yelling at people in the way. - destination: required. Where are we setting the course? Ideally this might accept a list of options, so that if the first option can't be found, the second option is chosen instead.
- force: not required, default false. Options are
false
or cardinal directions (north/east/south/west). If the destination can't be found, the car will drive in this cardinal direction, avoiding obstacles, until it hits the edge of the reality bubble. This is mostly forexeunt
commands, like if you run into free merchants far from the refugee center and haven't yet found the center, they should still be able to drive off into the sunset. - exeunt: not required, default false. I guess this could be called "despawn" but aaaww. If true, then when the vehicle leaves the reality bubble, it will be deleted similarly to if
remove_vehicle
had run. Any items and NPCs in the vehicle should be removed along with it.
Basic algorithm
- 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.
- start vehicle. If vehicle can't start, try again.
- Wait
pause
number of turns - 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. - set autodrive target to designated OMT.
- If designated OMT can't be found, set autodrive target 10 OMTs to the
force
direction. - If no
force
direction is specified and designated OMT can't be found, cancel with an error. - 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;
- short range driving to a specific location by x-y coordinates and rotation, allowing npcs to move a car and park it and things like that
- drive on: have a vehicle spawn at the edge of the reality bubble, already full of NPCs, and drive in to park at a specific location.
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.
Metadata
Assignees
Labels
Type
Projects
Status
To do