// Growth
function Growth(race, cols, crew, troops, guards) {
  this.race = races[race * 1];
  this.cols = cols * 1;
  this.crew = crew * 1;
  this.troops = troops * 1;
  this.guards = guards * 1;
  this.tc = new Object();
  this.tc.growth = 2;
  this.tc.delta = new Object();
  this.tc.delta.crew = 10;
  this.tc.delta.troop = 5;
  this.tc.delta.guard = 1;
  this.gov = 0;
  this.tcs = 0;
  this.cts = 0;
  this.ucs = 0;
  this.food = 0;
  this.happy = 0;
  this.cloneA = 0;
  this.cloneB = 0;
  this.cloneC = 0;
  this.starheat = 0;
  this.king = 1;
  
  this.buildings = set_buildings;
  this.modiffiers = set_modiffiers;
  this.cloningA = set_cloningA;
  this.cloningB = set_cloningB;
  this.cloningC = set_cloningC;
  
  this.calculated_growth = J7;
  
  this.max_cities = A11;
  this.max_factories = B11;
  this.food_supply = C11;
  
  this.solorian_growth = D11;
  this.cyborg_growth = E11;
  
  this.city_mod = F11;
  this.tc_mod = G11;
  
  this.growth_rate = H11;
  this.food_mod = I11;
  this.happiness_mod = J11;
  
  this.born_colonists = A17;
  this.total_colonists = B17;
  
  this.trained_crew = C17;
  this.born_crew = D17;
  this.total_crew = E17;
  
  this.trained_troops = F17;
  this.born_troops = G17;
  this.total_troops = H17;
  
  this.trained_guards = I17;
  this.total_guards = J17;
  
  this.tips_psp_max_arrivals = A19;
  this.tips_happiness = C22;
  this.tips_food = C23;
  this.tips_population = C24;
  this.tips_training = C25;
  this.tips_guards = C26;
  
  function set_buildings(gov, tcs, cts, ucs) {
    this.gov = gov * 1;
    this.tcs = tcs * 1;
    this.cts = cts * 1;
    this.ucs = ucs * 1;
  }
  function set_modiffiers(food, happy, starheat, king) {
    this.food = food * 1;
    this.happy = happy * 1;
    this.starheat = starheat * 1;
    this.king = king * 1;
  }
  function set_cloningA(cloneA) {
    this.cloneA = cloneA * 1;
  }
  function set_cloningB(cloneB) {
    this.cloneB = cloneB * 1;
  }
  function set_cloningC(cloneC) {
    this.cloneC = cloneC * 1;
  }
  
  function J7() {
    if(this.food>0) {
      return (this.city_mod()*this.tc_mod()*this.growth_rate()*this.food_mod()*this.happiness_mod());
    } else {
      return -0.05;
    }
  }
  
  function A11() {
    return Math.round(this.cols/100000);
  }
  function B11() {
    return Math.floor(Math.sqrt(2*this.cols));
  }
  function C11() {
    return (this.food/this.max_cities());
    //return (this.food/(2*Math.min(this.max_cities(),this.cts+this.ucs)+this.max_cities()));
  }
  
  function D11() {
    var sol = 0;
    if(this.race.id != 811) {
      return 0;
    } else if(this.starheat<30) {
      sol = 0;
    } else if(this.starheat>90) {
      sol = (this.starheat/30+0.2)*0,05;
    } else if(this.starheat>70) {
      sol = (this.starheat/50+0.2)*0.05;
    } else {
      sol = (this.starheat/90+0.2)*0.05;
    }
    return (sol/0.05*100);
  }
  function E11() {
    if(this.race.id != 106) {
      return 0;
    } else if(this.king) {
      return 120;
    } else {
      return 15;
    }
  }
  
  function F11() {
    var mod = 0;
    if(this.cts>this.ucs) {
      mod = Math.min(this.cts-this.ucs, this.max_cities())/500*(1+Math.min(0.3,Math.min(this.ucs,this.max_cities())*0.01));
    }
    return 1-mod;
  }
  function G11() {
    return Math.max((100-this.cts)/100,0);
  }
  
  function H11() {
    return ((this.race.grow.rate+this.cloneA+this.cloneB+this.cloneC)/100*0.05);
  }
  function I11() {
    return Math.min(this.food_supply()/100,1);
  }
  function J11() {
    if(this.happy>100) {
      return 1.5;
    } else if(this.happy<30) {
      return 0.5;
    } else {
      return 1;
    }
  }
  
  function A17() {
    var crew = 0;
    if(this.food>0) {
      crew = (this.crew-this.trained_guards())*this.calculated_growth();
    }
    return ((this.cols-this.trained_crew())*this.calculated_growth()+crew);
  }
  function B17() {
    return Math.round(this.cols+this.born_colonists()-this.trained_crew());
  }
  
  function C17() {
    if(this.food>0) {
      return (this.cols*this.tcs*(this.race.grow.crew+this.gov*10+300)/400000);
    } else {
      return 0;
    }
  }
  function D17() {
    if(this.food>0) {
      return ((this.crew-this.trained_troops())*this.calculated_growth());
    } else {
      return 0;
    }
  }
  function E17() {
    return Math.round(this.crew+this.trained_crew()+this.born_crew()-this.trained_troops());
  }
  
  function F17() {
    if(this.food>0) {
      return ((this.crew+this.trained_crew())*this.tcs*(this.race.grow.troop+this.gov*5+300)/400000);
    } else {
      return 0;
    }
  }
  function G17() {
    if(this.food>0) {
      return (this.guards*this.calculated_growth());
    } else {
      return 0;
    }
  }
  function H17() {
    return Math.round(this.troops+this.trained_troops()+this.born_troops()-this.trained_guards());
  }
  
  function I17() {
    var max = Math.sqrt(this.food*Math.sqrt(this.race.grow.hg));
    var trained = Math.pow(this.tcs,0.8)*((this.troops+this.trained_troops())/100000)*this.race.grow.hg;
    return Math.min(trained, max);
  }
  function J17() {
    return Math.round(this.guards+this.trained_guards());
  }
  
  function A19() {
    return Math.min(this.cols/1000*this.psps,1000000);
  }
  function C22() {
    if(this.happy>80) {
      return "Doing Great!";
    } else if(this.happy<30) {
      return "Get that Happiness above 100!";
    } else {
      return "Get that Happiness to 30 at least!";
    }
  }
  function C23() {
    var food = (2*Math.min(this.max_cities(),this.cts)+Math.round(this.cols/100000))*100;
    if(this.food_supply()==100) {
      food = food-this.food;
      return "You need " + food + " more food for maximum growth";
    } else if(this.food_supply()>100) {
      var food = this.food-food;
      return "You have a surplus of " + food + " Food in regards to Population growth";
    } else {
      return "You have a 100 turn of supply of Food (barely)";
    }
  }
  function C24() {
    var cols = Math.round(this.cols-this.cols*this.food_mod());
    return "You may move up to " + cols + " Colonists with minimal effect on growth rate";
  }
  function C25() {
    if(this.tcs>99) {
      return "All Growth Stopped";
    } else if(this.tcs>74) {
      return "Growth less than 1/4 normal";
    } else if(this.tcs>49) {
      return "Growth less than 1/2 normal";
    } else if(this.tcs>24) {
      return "Growth less than 3/4 normal";
    } else if(this.tcs>9) {
      return "Growth still more than 3/4 normal";
    } else if(this.tcs>0) {
      return "Growth still more than 9/10 of normal";
    } else {
      return "No Loss";
    }
  }
  function C26() {
    var hg = Math.pow(this.tcs,0.8)*(this.total_troops()+this.trained_troops())/100000*(this.race.grow.hg+this.gov);
    var food = Math.round(Math.pow((Math.pow(this.tcs,0.8)*(this.total_troops()+this.trained_troops())/100000)*this.race.grow.hg,2)/Math.sqrt(this.race.grow.hg));
    if(hg==Math.sqrt(this.food*Math.sqrt(this.race.grow.hg))) {
      return "You have enough Food for maximum High Guard Production";
    } else if(hg<Math.sqrt(this.food*Math.sqrt(this.race.grow.hg+this.gov))) {
      var hg = Math.round((Math.pow(this.tcs,0.8)*(this.total_troops()+this.trained_troops())/100000)*this.race.grow.hg);
      return "You need " + food + " more food to train a total of " + hg + " High Guard";
    } else {
      food = this.food - food;
      return "You have a surplus of " + food + " Food in regards to High Guard training";
    }
  }
}