Optional NPC Unique ID: something we've needed for a while. #57419
Labels
<Bugfix>
This is a fix for a bug (or closes open issue)
[C++]
Changes (can be) made in C++. Previously named `Code`
Code: Infrastructure / Style / Static Analysis
Code internal infrastructure and style
<Enhancement / Feature>
New features, or enhancements on existing
[JSON]
Changes (can be) made in JSON
NPC / Factions
NPCs, AI, Speech, Factions, Ownership
<Suggestion / Discussion>
Talk it out before implementing
Is your feature request related to a problem? Please describe.
We currently don't give NPCs any kind of consistent unique ID aside from their names, which can be randomly generated, not do we track NPCs that should be unique, aside from if we make conditional EoCs for that purpose.
Solution you would like.
Add an optional field "unique_id" to "place_npcs" in mapgen.
The reason to specify this in mapgen, rather than the NPC definition, is illustrated here: Those guards are generated from the same NPC definition, but given different unique IDs, allowing us to do something like have an EoC script cause the lobby guards to react in a specific way. Presently that is not possible, as these guards have randomly generated names. To make it possible we'd have to make each one a unique NPC with the same name every time it spawns, because to target an NPC we must use its name.
If an NPC has a unique ID, some special effects apply:
I think this is all pretty self explanatory.
loaded_only
defaults to false. If true, the targeted NPC is only affected if they are currently loaded in the reality bubble (another way to handle this would be with aradius
option). I'm mostly including this because it can help error trap some things, eg if we have an NPC John_Bailey who can spawn with the same unique ID in the refugee center or in the exodii base, this lets us issue commands to that NPC locally (such as telling him to move somewhere) without having to worry about which location he is currently in.We do already have syntax to target an NPC by name, but since a unique ID is unique, this requires a lot less troubleshooting and fixing up. It is also much more concise on the JSON end.
Future Directions
Refer to Unique ID in text snippets
Further support for unique IDs might include things like text snippets to refer to a unique ID by their name, even if their name is randomly generated (eg:
<name_UID:dino_dave>
). This would open the way for more procedurally generated NPCs that can still react to each other. If we do this, we should also start distinguishing NPC's names from their titles, and perhaps giving them a few more names like 'familiar name' and 'polite name' so that we can do things like:Otherwise our snippets will look pretty dumb, like:
"Could you do me a favour and take this note to Dino Dave, Beggar for me?"
Assigning unique ID to non-unique characters
Although this wouldn't do much initially, I think where this tool could really shine is in making random NPC followers start to take on roles. We could follow up with an effect "assign_unique_id". This would allow us to take a randomly generated NPC and slot them into a story role, probably based on their backstory and job, allowing them to become a recurring major character even though they spawned procedurally and their role was adopted through random events. For example, that random doctor you met and spoke to might be assigned a unique ID like "desperate_doctor". From then on, using the snippets system above, we can start having the NPC marked as
desperate_doctor
respond to specific EoCs and events, interact with the NPCcurious_scientist
in specific ways, and anything else we'd do with a specific unique NPC. If your desperate doctor died, the unique_id system would allow a new one to get assigned by the same series of events, but otherwise, recruiting another NPC that could have beendesperate_doctor
would fail to assign the unique ID, keeping them - well, unique.Describe alternatives you have considered.
This is not strictly necessary at present. We can do all of this with a combination of EoCs and making locations unique instead of NPCs. However, this is one of those bits of infrastructure that we probably will need at some point and that can expand into a number of useful places. Almost every use of this I have currently listed could be done through a combination of unique traits and conditionals, but the amount of JSON coding for it and the room for error is exponentially larger than just recognizing that, overall, we're going to need some way to mark an NPC as unique and refer back to them as such, and since names are random in this game, it's better to do it with an ID token.
Additional context
This code would save a lot of work in random encounters by cutting out a few areas of error checking to ensure a random encounter doesn't pop up twice, but I actually thought of this in the context of trying to write code to move an NPC and realizing that it's currently very hard and error prone because we have to account for the fact that any given NPC might appear twice.
The text was updated successfully, but these errors were encountered: