Persistent creature populations

Scripted ALFA systems & related tech discussions (ACR)

Moderators: ALFA Administrators, Staff - Technical

Locked
Ronan
Dungeon Master
Posts: 4611
Joined: Sun Feb 20, 2005 9:48 am

Persistent creature populations

Post by Ronan »

I always thought this was the holy grail of ALFA: IC ways to generate statics, limit static farming and simply present the world better. Unfortunately I set my sights way too high* and wanted way too many features out of it. As a result of this and the work on the spawn system** I got rather burnt out and moved on to other things.

Note that populations don't have to be creatures, they can be herbs, rocks, or even gnomes.

Of course I've been out of the loop for years, and don't remember much NWN anyways. I need some help and input. For all I know we already have a system like this?

My proposal:

What builders would have to do:
Place spawn points as normal. Make these spawns as if they were designing how the population would spawn when at its peak. Then put this local variable on the spawn waypoints:

Code: Select all

string ACR_POP_NAME: The name of the population the spawn point belongs to.
string ACR_SPAWN_CATEGORY: The name of an optional spawn category
The optional spawn categories are ways to override a group of regular spawn points' parameters. So you can control an entire set of spawn points in one script. Say you might want all Bad Moon spawns to drop Bad Moon ears, them all to be named with a prefix "Bad Moon" or all to belong to a certain faction. Or you might want Cormanthor drow to only spawn at night. Minor coding knowledge is required here because there are a TON of spawn system parameters and I don't want to write a function for each one.

In a script, say "acf_population":

Code: Select all

#include "acr_spawn_i"

SetSpawnCategoryInt("teh drows", WP_SPAWN_HOUR, 20)
SetSpawnCategoryInt("teh drows", WP_DESPAWN_HOUR, 5)
SetSpawnCategoryInt("teh drows", WP_SPAWN_IN_STEALTH, 1)
SetSpawnCategoryString("teh drows", WP_ADD_ITEM, "abr_drow_ear")
SetSpawnCategoryString("Bad Moon Boyz", WP_SPAWN_FACTION_RESREF, "051_badmoonboss" // This would be a resref of a creature belonging to the faction you want. No other way to switch factions on the fly that I know of.
So you could set:

Code: Select all

ACR_POP_NAME: "teh drows"
ACR_SPAWN_CATEGORY = "teh drows"
...and have persistent spawns which drop bounties (ears).

Then of course the population's limits need to be defined: min, max and growth in terms of hit dice. Since these values should be persistent, we'll go ahead and set them with a DM GUI and not in script. If they aren't set, we'll assume the spawn is at 100% all the time. That just makes it a convenient way to batch-edit spawn options.

The chances of that spawn point spawning would be equal to its regular chance (the ACR_SPAWN_CHANCE local int on the spawn waypoint) times the percentage of population available ((currently_alive - currently_spawned) / max_pop). The problem with any more involved calcs is guestimaing the hd of the spawn (very do-able, I just want to get it up and running first).

Initial limitations:
  • Nothing for overland map travel because I don't know anything about that yet. This would probably be the first thing to add to it, though.
  • If there were 1 out of 100 hd worth of Bad Moons remaining, you could still trigger a 20 hd spawn point. This is fixable by monitoring what we spawn in real-time but something that could be implemented later.
  • Its more difficult to change some spawn behavior at run-time, because of all the caching that is done. This caching is part of the reason that our system is something like 10x more performant than NESS was. I don't think we'll want to do this anyways.
  • I didn't list any alternative growth functions, although we could easily add others. I'm thinking with start with just a linear function where growth is constant until the population caps.
  • No way to add spawns to an area without manually placing spawn points (i.e. no way to say "there are deer in this area"). I'm not sure if this is a big deal, since spawn points can be made to spawn creatures anywhere in the area. In any case its something we could add.
  • Doesn't keep track of individual ResRefs. If you kill all the goblin war1s, the chief may be gone, and vise-versa. But given the nature of these populations (they should be able to run away) this is probably a good thing.
  • Doesn't change the distribution of a population at all. So if you kill all the Bad Moons in area A1, they're just as likely to re-spawn there as anywhere else.
  • Setting off a spawn in A1 reduces the chances of that pop spawning anywhere else until they despawn. The more hd A1's spawn has relative to the rest of the population, the bigger this effect. So if you have a low population max relative to your spawns, a player could set one off in one location and not run into any again. However, quick despawn times would mitigate this.
So basically the builder maybe adds some lines of code, puts spawns down as he wants them with the population at its peak, and enjoys watching them slaughter players.***

* I whittled down a lot of features while writing this. Looking back, I may have been able to implement the thing in the time it took to type this up.

** Aside from all the other awesome stuff he's done, thanks to AL for perfecting it. I was really proud of it, especially its performance, and I'm glad to see it be used. Looking at the SVN repo on Sourceforge, its amazing the amount of work he's done.

*** Ok, I'm sure there will be bugs at first. This is fine because bugs usually result in more player deaths.

Alternative approaches include generating encounters from pre-defined ResRefs, or having builders state a spawn's CR or HD in a variable. I'm thinking we'd eventually do the later, along with caching of a spawn's HD (so the variable would be a way to override the automatic behavior). Once you know how many orcs come out of a spawn point and how tough they are, you can do a lot more logic regarding where all the unspawned creatures "are".

Thoughts?
Zelknolf
Chosen of Forumamus, God of Forums
Posts: 6139
Joined: Tue Jul 05, 2005 7:04 pm

Re: Persistent creature populations

Post by Zelknolf »

Jeezuhs. ALFA has spent this month thinking that stuff I did in Mundasia was a good idea.

I've written persistent faction coffers / populations and hooked them into a spawn system there. Waaaaay too much code to post, but it's available if you want it.
Ronan
Dungeon Master
Posts: 4611
Joined: Sun Feb 20, 2005 9:48 am

Re: Persistent creature populations

Post by Ronan »

We actually started this years ago. After looking at some of my old code and talking with paazin, I'm not sure the above approach will work very well for many existing spawns, because many of those are something like "spawn one of thirty possible things", so a single population label won't work. I'm mostly done with it so I might go ahead and finish anyways...

In any case I'd love to look at any code anyone has. The hooks into the spawn system should be pretty minor.

The SpawnCategories are obviously ACR-specific, but they're easy anyways.

We could associate an individual spawn group with a population in its script, so a single spawn point could spawn a random population. We could also associate it via ResRef spawned, but I'm not sure I like that idea...
Zelknolf
Chosen of Forumamus, God of Forums
Posts: 6139
Joined: Tue Jul 05, 2005 7:04 pm

Re: Persistent creature populations

Post by Zelknolf »

It's a bit of a brute force thing, but it links populations to factions, rather than to a single spawn (that is, it does indeed turn one spawn point into potentially 30 different things... 31 actually) and then determines spawns based on how rich the faction is and how many members it has. Poor factions spawn lower level (I argued "poorly-trained" and "poorly-equipped") bad guys, and small factions spawn more NPC classes (not many dudes means that the chances of a wizard being available to repel those dang PCs is low); rich factions spawn higher-levle dudes and populous factions spawn more PC classes. The trouble is that I did it without the power of NWNx2, and so it was done by actually having 31 resrefs per faction, and the nature of SetFaction meant that I had to have a big gay pile of NPCs from every faction sitting in a holding area to make it work.

The major perks were that it allowed a DM to point a tool at any given NPC and say "These guys live here now." and the faction would effectively invade the area and start spawning there; and the spawns tended to be diverse groups with an AI that made them play nice together-- which sounds like a lateral move from what you're aiming for?

Anyhow, I'll throw the mod up on the techftp in some sort of "Not actually ALFA stuff, but if you want to read my code." folder if it can be helpful.
Ronan
Dungeon Master
Posts: 4611
Joined: Sun Feb 20, 2005 9:48 am

Re: Persistent creature populations

Post by Ronan »

Thanks for the info. Gives me more to think about.
Zelknolf wrote:The major perks were that it allowed a DM to point a tool at any given NPC and say "These guys live here now." and the faction would effectively invade the area and start spawning there; and the spawns tended to be diverse groups with an AI that made them play nice together-- which sounds like a lateral move from what you're aiming for?
Not really - I'm aiming for compatibility with the spawn system. So if we made a tool that allowed a DM to create a spawn point (maybe we already have one?) they could do that too. The spawn system is something like 1,000 lines of code, very high performance and has a ton of options, so I want to make use of it.

As a side note, the spawn groups are scripts, so a spawn group could call population functions (GetMaxPop, GetRemainingPop, etc.) and decide what to spawn more dynamically than a simple point could.
Sandermann
Rust Monster
Posts: 1228
Joined: Sun Jul 18, 2004 3:01 pm
Location: Richmond, North Yorkshire

Re: Persistent creature populations

Post by Sandermann »

BG and NU already have a dynamic population system that causes creatures to populate a set of areas. The vairables used are designed to be tied into statics, I just never got the chance to finish that side of it before I lost my house.

Rather than go again from scratch I'll be revamping it as I get round to it on NU.
PC: Liasola Dark Arrow
Ex PC: Arzit'el Tlabbar

Blindhamsterman : "I think Sand may have just won the internet"
Thangorn
Haste Bear
Posts: 2081
Joined: Fri Oct 01, 2004 1:00 pm
Location: Queenstown, New Zealand

Re: Persistent creature populations

Post by Thangorn »

This is fine because bugs usually result in more player deaths.
I would prefer to kill their characters to avoid potential legal implications, etc. :D

Thanks for working on this.. looks like nifty idea
On indefinite real life hiatus

[22:52] <Veilan> obviously something sinister must be afoot if a DM does not have his social security number in his avatar name!
Ronan
Dungeon Master
Posts: 4611
Joined: Sun Feb 20, 2005 9:48 am

Re: Persistent creature populations

Post by Ronan »

So this took me like 30 minutes to complete. Really easy.

...except the UI. I've been out of the loop in regards to NWN2 UIs. Basically the DM needs to be able to do a few very simple things:

Select from existing populations.
Edit population variables: min, max, current and growth.

Pretty simple. Anyone have suggestions on where to start? Can I use some generic UIs or do I have to roll my own XML? I really, really hate XML.
Zelknolf
Chosen of Forumamus, God of Forums
Posts: 6139
Joined: Tue Jul 05, 2005 7:04 pm

Re: Persistent creature populations

Post by Zelknolf »

I'm not sure that I gather what you're asking for here? You want a UI that displays and sets these variables -- alrighty, that's easy enough -- but what do you mean by "Select from existing populations." ?
Locked