Ikariam Search - Indexing Worlds

The biggest World wide index of Ikariam players, alliances and islands.

Skip to content

Predict max population

What you want included?

Predict max population

Postby Gousgounis on Mon Oct 26, 2009 10:56 am

A simple calculation that will predict when our city hall will be full of citizens, using the current growth rate.
If the growth rate is not sufficient to fill the city then display the predicted max population.
This could be very useful to know when a tavern upgrade is needed.

each new citizen reduces the growth rate by 0.02 so a town reaches the maximum population when growth rate <0.02

Sample code from http://userscripts.org/scripts/show/25813
Code: Select all
   var divCityOverview, curPopulation, maxPopulation, curPopulationGrowth, timeLeftEx;
   
   divCityOverview = document.getElementById('CityOverview');
   if (divCityOverview) {
      curPopulation      = Number(divCityOverview.childNodes[3].childNodes[3].childNodes[1].childNodes[1].textContent);
      maxPopulation      = Number(divCityOverview.childNodes[3].childNodes[3].childNodes[1].childNodes[3].textContent);
      curPopulationGrowth   = Number(divCityOverview.childNodes[3].childNodes[3].childNodes[3].childNodes[3].textContent);
//curPopulationGrowth    is NaN on 0.3.2 using this method (sorry I don't understand childNodes yet!)
      alert(curPopulation+' '+maxPopulation+' '+curPopulationGrowth);
      if (curPopulation > 0 && maxPopulation > 0 && curPopulationGrowth > 0 && curPopulationGrowth / 0.02 + curPopulation >= maxPopulation) {
         timeLeftEx = 0;
         for (i = curPopulation; i < maxPopulation; i++) {
            timeLeftEx = timeLeftEx + 1 / (curPopulationGrowth - 0.02 * (i - curPopulation));
         };
      } else {
         timelLeftEx = Infinity;
      }
      var parentNode = divCityOverview.childNodes[3].childNodes[3];
      var newNode = parentNode.childNodes[3].cloneNode(true);
      var insertedElement = parentNode.appendChild(newNode);
      insertedElement.style.position = "relative";
      insertedElement.style.top = "90px";
      insertedElement.innerHTML = 'Full' + timeRealToString(timeLeftEx);

function timeRealToString(rTime) {
   var sDays, sHours, sMinutes, sResult;
   if (isFinite(rTime)) {
      sDays = Math.floor(rTime / 24);
      sHours = Math.floor(rTime - sDays * 24);
      sMinutes = Math.floor((rTime - sDays * 24 - sHours) * 60);
      sResult = (sDays == 0)?"":String(sDays) + 'd';
      sResult += (sHours == 0)?"":String(sHours) + 'h';
      sResult += sMinutes + 'm';
   } else {
      sResult = 'Never';
   }
   return sResult;
ImageImageImage
User avatar
Gousgounis
Good Fellas
 
Posts: 129
Joined: Wed Oct 08, 2008 9:57 am
Location: Her place



Return to Feature Requests

Who is online

Users browsing this forum: No registered users and 1 guest