Abstract:
This is a rough writeup of my proposal to create a more dynamic natural world. In short, we create an AI for gaia. The AI will spawn units and trees in as realistic manner as possible, and control the movements of animals to simulate their natural behavior. The goals of this project are twofold:
*Renewable Resources - Gaia will spawn animals and trees in a reasonable manner. Logged forests should eventually regrow, and animal populations should eventually recover from hunting (assuming there's any left).
*Realistic Animal Behavior - Lions should hunt deer and travel in packs.
This post will focus on first part.
Step 1: GUI Support for a Gaia AI
Gaia is already allocated a player id, so we can just create an AI that does everything we want Gaia to do, and assign it to control Gaia. At a minimum, we could just assign it to be the default AI and leave it at that. (see /mods/public/simulation/data/player_defaults.json)
Preferably, there'd be a way to assign/unassign an AI to Gaia in game. I'm thinking a check-box "Active Gaia" by "Reveal Map" and "Teams Locked" in the game creating screen. Checking the box would assign GaiaBot (or whatever the AI is called) to Gaia, and unchecking it would unassign Gaiabot. Default behavior would be unchecked, or "off." As an additional consideration, GaiaBot would somehow have to be concealed from the players, lest the accidentally assign it to play a real civ.
We would then write the bot to do whatever actions we wanted Gaia to do.
Step 2: Establishing Population Limits for Fauna
We can't spawn fauna simply as a fraction of the existing fauna. While it would lead to exponential growth (which we expect to see in real populations) we run into the problem of maximum population. Growth that's proportional to existing population simply never quits growing. Having 2000 deer on your map would certainly cause performance problems. Additionally, in the real world, there's a finite amount of resources available for population growth. Our GaiaBot will need to establish population limits and use equations to control growth in such away as to not violate those limits.
Further down in the thread, I will post a brief overview of mathematical population modeling and link it here for those interested.
Step 2.1: Population Limits for Fauna
2.1.1 Possible Exceptions
GaiaBot will not compute population limits for Fauna with the parent template "template_unit_fauna_herd_domestic"
Population Limits for predators would initially depend on the number of prey. Later, once the bot is more sophisticated and can have predators actually hunt, the population limit will be based off the kills they make.
2.1.2 Calculating
It is up the map creator/RMS to decide what constitutes a reasonable number of animals for a given map. As such, at the start of each map, as it's first action, GaiaBot will simply count each animals of a given type. That value is then stored as a variable limiting the population of each animal of that type, i.e.
var deerpopcap = (relevant code); //The population cap for deer.
Step 2.2: Establishing Population Limits for Flora
2.2.1 Possible Exceptions
GaiaBot will not compute population limits for Flora that provide food (berry bushes, apple trees)
2.2.2 Calculating
Once again, we leave establishing a reasonable limit to trees to the map creator/RMS. However, GaiaBot doesn't care about the type of tree. We simply tally the total number of trees and store it.
Step 3: Establishing Growth Rates
For a somewhat in-depth analysis on why these formulas were chosen, see my later post on modeling populations.
For both flora and fauna, the growth rate is:
Rate of growth = k(Pop)(1-Pop/Cap)
Where Pop is the current population of a species and Cap is the population cap for that species (i.e. deerpopcap)
k is an arbitrary constant that is used to fine tune the rate. If we want something to spawn faster, give it a large k. (note also that a sufficiently large k could shoot a population over it's population limit. This would cause a die-off.) We can add terms to this equation if we like, to simulate say, a threshold for survival (if the population ever falls below said threshold, we slowly go extinct.)
After inputting the proper values for each species, we add the result to another variable (continuing with deer as an example, we'll call it deergrowth) which will then be used to determine how many we spawn. "deergrowth" holds the fractional remainders of previous operations, so we don't loose, say half a deer.
Say for example, we've been running GaiaBot for awhile and deergrowth is == .53. After running a rate of growth calculation for deer, we get a result of 4.32. This is then added to deergrowth for a total of 4.85.
Step 4: Spawning Entities
Step 4.1: Spawning Fauna
Let's do an example:
Our deergrowth variable is at 4.85. GaiaBot will then choose 4 random deer and order each of them to train one more deer. 4 is then subtracted from deergrowth. Placement of the new deer will obey the spawning code set up for <TrainingQue> (that is to say, it will be adjacent to the animal and will respect passability class.)
We'll have to add the <TrainingQue> tag to each class of fauna, with the ability to train itself (I've done a quick and dirty hack with deer, it works.)
Step 4.2: Spawning Flora
Regarding the number of flora to spawn, it's easy. If, say treegrowth == 2.34, then we spawn 2 trees. As far as the placement is concerned... I'm not so sure that <TrainingQue> is the best way to do it. Eventually, we'd wind up with dense, impassible forests. For some maps, this might be just fine. For others, not so much. Perhaps we could do it by tree type? Evergreens, say would use <TrainingQue> resulting in thick, dense pine forests. Palms would use some other method.
Step 5: Additional Features
Currently, players can't order fauna to move (meaning Gaia can't order Fauna to move.) There needs to be a way for Gaia to do this. According feneur, players will need to be able to order animals around, so it's a needed feature anyways.
Comments on Sections
1: Philip tuned me on to other ways of spawning units in game (scripted system component to be exact) but as the eventual goal of my proposal also requires moving animals, I think AI would be the best way to do it. Also, this seems to be the way requiring fewest changes to existing code. In fact, only the game setup screen should need changing (oh yeah, and all the gaia templates. Still possibly simpler than adding a new component.) Disabling renewable resources would also be a synch.
2An alternative method for generating population limits would be to have them specified by the map designer or RMS and stored in the map file itself. This would make the bot simpler, and allow the map maker slightly more control.
2.2This assumes we regenerate flora. Maybe growing trees back is too game breaking? That's the whole point of the thread! Also applies to 4.2
Edited by gudo, 28 September 2011 - 02:12 AM.















