Pre-Order the Game!

Desura Digital Distribution

Wednesday, April 13, 2011

Partial progress on migration

When I started work on migration stuff, I realized that I needed a feature implemented before I could do migration. The feature in question is the ability to find a path to a grid cell INSIDE a star. If you've noticed in the released version, when you hover above a star, you don't have a path leading to the star. This is because the grid cells in a star is "unpassable".

The migration need to check and see if a path exists from the origin system to the target system, using influence map as the "fuel range" (if the two systems aren't connected via influence, no migration occurs). In order to do that, I need to be able to just give it the system's X,Y coordinates. So I put some work into doing that, and am quite pleased with the result. I can hover over a star and the selected fleet will automatically pick the shortest path to that star. This will make selecting a destination much easier now.

There is a bug however, if you hover to where the path ends at the star, and above the star, sometimes you see different ETA time (the actual duration is the same, just that it reads in one node too many). I'm not quite sure why it's occuring, I've put in checks to prevent reading in unpassable nodes. I'm tired at the moment, so maybe tomorrow when I read the code, I'll hopefully go "Aha!"

Back to topic of migration. This is how it will work:
Planets with over 75% of planet's capacity can migrate. Planets with low population is more attractive than empty planets, up to 25% capacity. Planets between 25% to 75% will experience no migration in either direction.

It calculates population growth first, then grabs a list of planets that is over 75% capacity, and grabs a list of planets that can be migrated to. The planet with the highest amount of migrates will go first, and it goes through list of available planets, starting with the best planet to migrate to first. If a planet is unreachable through influence map, it skips that planet and checks the next planet. This continues until a planet is found, or list runs out. If a planet is found, the maximum amount of migrates is determined from the lowest of two (the migrate planet's amount vs the target planet's immigration limit), and the people are transferred. Both planets are then removed from the list. So it's one to one ratio. This continues until one of the two lists are empty. If no planets are reachable to the origin planet, that origin planet is removed from the list.

I should be done with migration code this week, then I will release the new version.


  1. Just curious, how is population growth calculated?

  2. I use a formula called "Logistic Function", you can google it up. The formula looks like this:

    amount of growth = (current population * growth rate) * (1 - (current population / maximum population))

    Growth is slow when it's near 0% or 100% population, and is fastest at 50% population. This is why I cap the migrates to be from planets with at least 75% max population, and they can move to only planets that have less than 25% max population. So migration don't really amplify the population growth, it's more of an overcrowding relief.