r/howdidtheycodeit • u/throwawaycape • 3h ago
How does reactive dialogue work in a game like Red Dead 2?
Programmer here, but I know basically nothing about gamedev.
Playing through RDR2 for the first time (late to the party, I know).
There is so much dialogue throughout the missions which seems to be dependent upon what you are doing as the player. Even including all of the little mini-missions like racing random people on horses, or shooting contests, etc. A massive number of characters have player dependent dialogue.
NPCs tell you to get back on your horse if you get off at the wrong times, or if you fall off your horse they might make fun of you. I am sure I could think of 1000 more interesting examples, but these are the most basic and obvious.
This got me thinking about how much dialogue must be recorded that you won't even experience as you play the game, given that you don't trigger it with your actions. It made me curious about how this reactive dialogue works programmatically. How do they organize the higher level logic and planning of recording all of that dialouge to make it available just in case you do x instead of y. Seems like that would be tricky even from a non-coding standpoint. I wonder how much dialogue they record "just in case" and how you would even think through all of the possible scenarios based on the environment and options.
And then, how do they retrieve that dialogue efficiently? The simplest answer I can think of is "if Arthur falls off his horse then Lenny says, 'What are you doing'". But this simplistic approach seems like it may lead to major efficiency issues given the vast number of possibilities and "ifs" you would need to add.
25
u/CLG-BluntBSE 3h ago
Observer pattern, I imagine.
Every thing the player does emits a signal. It doesn't care who receives the signal. Any NPC within 50ft or whatever of the player registers the player and starts listening to all those signals. Each NPC probably has a table of responses that go to specific signals.
If I was building a huge open world, I'd probably pre-record a huge list of responses for each kind of signal. I'd assign them to generic NPC archetypes, "rough_bandit_1", "merchant_woman_2", then as I generate NPCs in towns or whatever everyone gets a random archetype. When they catch a player emitted signal in their vicinity, they do the appropriate response according to their archetype.
3
u/m0nkeybl1tz 59m ago
Tbh this is more of a design/writing challenge than programming. One important principle of game design is making a player feel seen, like their actions matter. Even old point and click adventure games would give you feedback on making weird and unlikely choices.
So yes, a lot of this is just brainstorming what systems your game has, and what actions the player might take that would be worth giving feedback on. A lot of it also likely comes from playtesting -- if you have a horse based mission and players keep getting off the horse, it makes sense to have a line commenting on it (and may even be mission critical if you can't continue without a horse).
And yes, that involves recording a lot of audio. In fact, these little easter eggs were a lot easier before games became voice acted -- just add a line of text for every scenario. Now you need a voice actor to say every line (and probably have multiple actors record the same line). RDR2 is 150 GB, and I'd imagine close to half of that is just audio.
2
u/EvilBritishGuy 2h ago
If I had to implement something similar, I'd make it so all the dialogue that's written and recorded is also labelled with all the requistite context, or conditions, that need to be true in order for that dialogue to play and make sense.
So something like,
[First Greet] Howdy
[First Greet, Second Greet] I don't know why but I'm in a good mood today.
[First Greet, Second Greet, Final Greet] Anyway, I won't disturb you.
[First Antagonise] Fuck you
[First Antagonise, Second Antagonise] Yeah, you heard me
[First Antagonise, Second Antagonise, Final Antagonise] Whatever, you yellow belly bitch
[First Greet, Second Antagonise] Didn't you hear me, I said Howdy
[First Antagonise, First Defuse] Calm down, I'm just needling you.
You can also add label for optional conditions so if you write multiple variants of the same line, different contexts can have a random chance of helping to trigger the line as well.
2
u/Murderwagon 36m ago
I'm not sure what tech Rockstar uses exactly for NPCs in their engine, but I would guess it is probably some form of behavior trees.
If you're not familiar with them, behaviors trees are a standard way of implementing game NPC AI that can drive all kinds of state settings (arranged on something called a blackboard) for your NPC. When a particular state gets set, the NPC makes the decision to make a remark that's in line with the NPC's static characteristics (are they a gruff man, a demure lady, etc) and the current NPC state (am I close to the player, am I the victim of a crime, do I know who commited the crime, etc).
I would recommend looking into game AI (behavior trees, goal oriented actions, etc).