Post news RSS Spirit in the Heap

The in-game all powerful spawn controller has been created, and works quite well.

Posted by on

God?
God is simply a thread that makes sure the universe is populated according to specifications. God takes faction standings, sovereignty, universe size, and faction-specific population density limiters, and maintains the living universe.


The Basics
God controls spawning of both NPCs and Stations. The name of the game is population density. This number is calculated by dividing the number of relevant ships the faction owns by the number of solar systems in the game.

There are currently 3 population density parameters that can be specified.

  • traderDensity: The minimum population density of traders for this faction.
  • taxieDensity: The minimum population density of taxies for this faction.
  • stationDensity: The minimum population density of stations for this faction.

This allows personalities for a faction to be defined. Later on when combat such as raids and patrols are added, these densities will allow the creation of any kind of faction. I can make factions with tons of traders but rare patrols, or factions with tons of patrols but rarely a trader. I can even make factions with tons of patrols and traders. You could even remove a role from the faction by setting the density to 0!

Also, note that ships continue to exist and behave even in solar systems you're not present in. This means that, unlike games like Freelancer which despawn NPCs when you're not able to interact with them, the universe is truly alive and dynamic. Destroying a freighter of Food Stuffs means that a factory never got the supplies it needed to produce those semiconductors, producing an amazing and awesome ripple effect in the world.

Faction File?
Here's a sample of a faction defined in the faction file.

<Faction=Ageiran Federation>
    shortName=Federation
    hasSov=true
    spread=5000
    traderDensity=0.25
    taxieDensity=0.25
    stationDensity=0.25
    standing=Ageiran Federation:1
    standing=Interspace Alliance:1
    standing=Caina Conglemerate:-0.25
    standing=Lonestar Commerce:0
    standing=Profit Motive:0.5
    standing=Gateway Laboratories:0.25
    standing=New Flag Army:-1
    standing=Everyshore:0
    standing=Interstellar Treaty Organization:1
    standing=The Warlords:-1
    standing=Pacifists:0
    standing=The Wolves:-1
    standing=Shuna:-1
    info=The wealthiest empire formed in the Second Foundation War.
    #loadouts
    loadout=emptyBronco:BehaviorTrader
    loadout=emptyFalcon:BehaviorTaxie
</Faction>

Notice the loadouts as well. You can even link certain behaviors to certain ships. That's not one-ship one role either: you can specify multiple possible ships for a specific role.

Example?
Here's some un-optomized Java code that God once used. It's easier to read than the final version.

private void traderPopulationControl() {
        /*
         * The mission is simple. Count the # of traders for each faction 
         * and divide that by the # of systems. If it is below that number,
         * add a trader.
         */
        Faction testFactions = new Faction(BASE_FACTION, factionFile);
        for (int a = 0; a < testFactions.factionStanding.size(); a++) {
            Faction tmpFaction = new Faction(testFactions.factionStanding.get(a).split(":")[0], factionFile);
            //get count
            int count = getCountOfRoleByFaction(BEHAVIOR_TRADER, tmpFaction);
            //determine pop density
            float density = (float) count / (float) universe.systems.length;
            if (density < tmpFaction.getTraderDensity()) {
                spawnTrader(tmpFaction);
            }
        }
    }

Basically, it performs these steps.

  1. Get a list of all in-game factions from the "Base Faction". This is done every cycle so that I can dynamically add and remove entire factions down the road.
  2. Go down the list and generate the faction the list named.
  3. Count the number of ships in a role (in this case traders) and divide that by the number of systems.
  4. If the density is less than the minimum one specified for that faction, add a trader somewhere in the universe.

This keeps the populations at an expected value despite combat and accidents (such as crashing).

Station Rules
Since stations can't move around, they need to be placed somewhere that makes sense instead of randomly across the universe. So, when spawning a station the following rules are applied.

  • If the station's faction can hold sov, it can only be placed in a system its faction holds sov in. This means Ageiran stations only spawn in Ageiran space.
  • If the station's faction cannot hold sov, it may spawn in any system that is either unclaimed or owned by an empire that likes (not is neutral to, likes) it. This means that many corporate and pirate stations are often found in the unclaimed territory.

In the long term this will help the empire war system. When an empire claims another empire's space, it will vastly affect the trade landscape because of these rules.

Future of God
Development is far from done. Eventually God will be able to detect holes in the economy and spawn stations producing the missing goods (keeping density in mind, of course) similar to how X3 will add more power plants when producing energy cells becomes insanely more profitable (generally due to the player).

Eventually God will take a much more active role in shaping the universe. God will roll dice to determine when factions launch major offensives, generate economic events, and other awesome things to liven up the universe. But laying the foundation was important.

Other Work
In addition to God, I have recently added...

  • Loadouts: This allows an NPC's ship and fitting to be linked to a specific role.
  • Cockpit View: I'm working on it. Right now its more the HUD-only view from Ace Combat, but eventually I want actual cockpits.
  • Custom Textures: I finally figured out a way of making good planet textures in GIMP that look realistic. So I redid all the textures to avoid copy-pasting textures from Celestia for my planets.
Comments
247defed
247defed - - 67 comments

I like the way you write these articles, really nicely done.

Reply Good karma Bad karma+1 vote
lol1234
lol1234 - - 1,765 comments

I like the way he names his scripts ;)

Reply Good karma Bad karma+1 vote
Post a comment
Sign in or join with:

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.