Devlog 1 - My Dream Game, NPCs, and game logic around schedules and locations
Bethesda upsets me. Not because I hate them or anything, but because they aren’t making the game I want them to make. I’ve been wanting a new Skyrim like game for a long while now, but it just seems like we aren’t getting it. The next Elder Scrolls game is scheduled for who knows how many years into the future, but even when we get it, I don’t think it will be the dream game I wish it was. Sure, it’ll be made better with Mods (provided they support them still) but still. At this point, I’m considering just making the game myself.
Sure, I won’t be able to match the graphical fidelity of AAA games. And yea, I won’t be able to match the productivity power of a giant studio with hundreds of employees. Regardless, I don’t care. If there’s one thing I learned over the years, is that greatness comes from a few individuals. You have teams of hundreds held up by the power of a few. You have entire companies who revolve around the potential of a handful of top tier minds. I’ve never felt as if I was one of these people, but sometimes I see evidence to the contrary. Not many have the skills I possess. Not many people know how to do so many things from 3D modeling, rigging, animation, sound, music, programming, etc. Not many people wear as many hats as I do. At work it’s the same, where I do networking, system administration, cyber security etc. I do it all. So maybe, just maybe, I can be an indie dev, where you need to be the jack of all trades, master of all.
The biggest challenge isn’t related to IF i can do it. It’s if I have the patience. It’ll be less of a technical challenge than it will be a test of mental fortitude. The information to do anything is out there. It’s if I have the patience and perseverance to find it.
So with that being said, I’ve been planning my own Open World fantasy game for a bit, and I wanted to start with a thought experiment. Let’s think about Skyrim for a moment. Skyrim is a huge game with a lot of NPCs. I want a huge game with a lot of NPCs also. So how do I make that happen? Well, it’s as easy as slapping a ton of NPC objects into the world. OK cool, but what if I want those NPCs to be as ALIVE as Skyrims? Walking around with schedules and tasks they accomplish?
Let’s start this thought experiment by solving this problem in a logical manner, in which perhaps the game logic would solve it.
NPC Schedule and Location Game State Logic
Skyrim and other open world games have NPCs with schedules. They live daily lives and walk around doing things. We need to establish an efficient way to do this that doesn’t overwhelm game logic or become inefficient at scale. If you have a game with 1000 NPCs, each with their own schedules and routines, parsing this data every time a player enters or exists a zone will waste CPU cycles. How do we cut the game logic up to require less data reads / writes?
There are likely a billion approaches, but my brain came up with this one.
First, we need to think about what data is required for this to function. I think the easiest way is to attach each NPCs schedule to the NPC themselves as a child attribute, which could be checked when required. Each NPC will have a number of attributes associated with them, from body, to inventory etc. Their schedule will also be included, as NPC Scheduled Location– Lists where the NPC is scheduled to be at any given hour, day, week, month, year etc
Now, we need to have a way for the game to know what NPCs needs to be checked at any given time, otherwise it will have to check every NPC’s NPC Scheduled Location in the entire game every time we enter a zone to see if anyone is scheduled to be there. That is data heavy. Checking 1000 NPCs every time we enter a zone doesn’t sound efficient to me.
Let’s have a way to determine which NPC can possibly exist in a zone at any given time. We can do that by creating another data point. Much like how each NPC has a NPC Scheduled Location child attribute, each Scene will have a Scene NPC Table which lists which NPCs could exist within it. This table will be pre-generated at the start of the game based on NPC Scheduled Locations, but will be modified whenever there are changes to NPCs. Example: NPC dies. Their NPC Scheduled Location will clear resulting the game logic to remove this NPC from any location they would normally be at. Game logic will now remove NPC from Scene NPC Table or Overworld Area Tables as necessary.
Overworld Area Tables – Because the overworld is massive, it makes sense to divide it up into sections. Each section should have its own Area Table associated with it so the game logic doesn’t have an absolutely massive table to check for characters who have scheduled locations within the overworld. The game will automatically load and unload these based on player proximity. Morrowind uses a square chunk based system if I recall.
As a result of the above data, Scene NPC Table or Overworld Area Tables give the game an easy way to check which NPCs can possibly exist in an area, and NPC Scheduled Locations associated with NPCs tell you more details, like exactly WHEN they will be somewhere.
NPC datapoint
–NPC Scheduled Locations (times, locations, NPC schedule)
Scene (area) datapoint
–Scene NPC Table (NPCs which have schedules that include this location)
Overworld (area) datapoint
–Overworld Area Tables (NPCs which have schedules that include this location)
The data is managed in such a way that the game logic should never need to parse through a billion NPC tables or schedules at any given time. Only which data is applicable to the player at the given moment. Let’s see this play out logically.
Scenario 1:
Player enters a (scene / zone / area). Game has to load appropriate NPCs.
Game Logic checks local Scene NPC Table or Overworld Area Tables to see which NPCs should be present in zone. Outputs list of NPCs.
Example
Player enters tavern.
Game logic checks and sees that 5 NPCs have schedules which include the Tavern and outputs IDs of 5 NPCs.
Tim, Greg, John, Bob, Sara
Game logic takes the output list of NPCs, and queries their NPC Scheduled Location data. Checks current hour, day, week, month, year. If NPCs are supposed to be present, spawns them at designated locations.
Example
What time is it? 5pm, Tuesday, May, 2022
Tim – Schedule says tavern from 2pm-4pm – NOT PRESENT
Greg – Schedule says tavern from 2pm-8pm on Wednesdays only – NOT PRESENT
John – Schedule says tavern from 5pm-7pm – PRESENT
Bob – Schedule says tavern from 1pm-2pm – NOT PRESENT
Sara – Schedule says tavern from 1am-4am – NOT PRESENT
After the check is complete, the game spawns in the appropriate NPCs. Game logic complete.
That’s only a baseline. There are things to account for beyond this.
Say you’re in a Tavern at 1pm. There’s an NPC with you. Let’s call him Bob. Bob is scheduled to be at the Tavern at 1pm, and at Home at 2pm.
What happens if you’re standing in the Tavern at 1PM and it turns 2PM? I have this planned out as well.
Anyway, I’ll write more as I go, but this is a start of many a dev log.