Noble Master Games
Noble Master Games
Navigation
Categories:

Search:

Meta:

Archives:
Dev. Blog
Forums
 

Noble Master Developer's Blog

April 14, 2010

Population Growth, Migration & Economy

Filed under: Development — noblemaster @ 10:23

Each turn, the following updates are applied to the ecosystem of Age of Conquest. Updates include population growth, population migration and economy changes.

    // population: constant growth
    for (int i = 0; i < provinceList.size(); i++) {
      Province province = provinceList.get(i);
      int population = province.getPopulation();
      long increasePercent = 8;
      long increase = population * increasePercent / 100
                                 * province.getEconomy() / Province.MAX_ECONOMY
                                 * (province.isTown() ? 125 : 100) / 100;
      population += increase;
      province.setPopulation(population);
    }

    // population: migration
    List populations = new ArrayList();
    for (int i = 0; i < provinceList.size(); i++) {
      Province province = provinceList.get(i);
      populations.add(province.getPopulation());
    }
    for (int i = 0; i < provinceList.size(); i++) {
       Province province = provinceList.get(i);
       ProvinceList neighbors = province.getNeighbors();
       int population = populations.get(i);
       int neighborCount = neighbors.size();
       if (neighborCount > 0) {
        int migrationPercent = 15;
        int migrationPopulation = population * migrationPercent / 100 / neighborCount;
        for (int k = 0; k < neighborCount; k++) {
          Province neighbor = neighbors.get(k);
          neighbor.setPopulation(neighbor.getPopulation() + migrationPopulation);
          province.setPopulation(province.getPopulation() - migrationPopulation);
        }
      }
    }

    // economy: changes depending on population size difference to economy difference
    for (int i = 0; i < provinceList.size(); i++) {
      Province province = provinceList.get(i);
      int economy = province.getEconomy();
      long increasePercent = 2;
      long increase = (province.getPopulation() - economy) * increasePercent / 100;
      economy += increase;
      province.setEconomy(economy);
    }

Please note that the code sample does not include all the variables as of yet.

No Comments »

No comments yet.

Leave a comment