/** * Make this planet a homeworld planet for a race */ public void makeHomeworld(Player player, int year) { owner = player; ownerID = owner.getID(); Race race = player.getRace(); System.Random random = new System.Random(); int min = Consts.minHWMineralConc; int max = Consts.maxStartingConc; concMinerals = new Mineral(random.Next(max) + min, random.Next(max) + min, random.Next(max) + min); hab = new Hab(); hab.setGrav(((race.getHabHigh().getGrav() - race.getHabLow().getGrav()) / 2) + race.getHabLow().getGrav()); hab.setTemp(((race.getHabHigh().getTemp() - race.getHabLow().getTemp()) / 2) + race.getHabLow().getTemp()); hab.setRad(((race.getHabHigh().getRad() - race.getHabLow().getRad()) / 2) + race.getHabLow().getRad()); min = Consts.minStartingSurf; max = Consts.maxStartingSurf; setCargo(new Cargo(random.Next(max) + min, random.Next(max) + min, random.Next(max) + min, 0, 0)); setPopulation(Consts.startingPopulation); if (race.hasLRT(LRT.LSP)) { setPopulation((int)(getPopulation() * Consts.lowStartingPopFactor)); } mines = Consts.startingMines; factories = Consts.startingFactories; defenses = Consts.startingDefenses; homeworld = true; contributesToResearch = true; scanner = true; }
/** * Compute the hab range advantage points for this race by generating test planets for a variety * of ranges and using the habitability of those planets */ private static long getHabRange() { bool totalTerraforming; double temperatureSum, gravitySum; long radiationSum, planetDesirability; int terraformOffsetSum, tmpHab; int[] terraformOffset = new int[3]; Hab testHabStart = new Hab(); Hab testHabWidth = new Hab(); double points = 0.0; totalTerraforming = race.getLrts().Contains(LRT.TT); terraformOffset[0] = terraformOffset[1] = terraformOffset[2] = 0; if (race.isImmuneGrav()) { numIterationsGrav = 1; } else { numIterationsGrav = 11; } if (race.isImmuneTemp()) { numIterationsTemp = 1; } else { numIterationsTemp = 11; } if (race.isImmuneRad()) { numIterationsRad = 1; } else { numIterationsRad = 11; } for (int loopIndex = 0; loopIndex < 3; loopIndex++) { // each main loop gets a different TTCorrectionFactor if (loopIndex == 0) { TTCorrectionFactor = 0; } else if (loopIndex == 1) { TTCorrectionFactor = totalTerraforming ? 8 : 5; } else { TTCorrectionFactor = totalTerraforming ? 17 : 15; } for (int habType = 0; habType < 3; habType++) { if (race.isImmune(habType)) { testHabStart.setAtIndex(habType, 50); testHabWidth.setAtIndex(habType, 11); } else { testHabStart.setAtIndex(habType, race.getHabLow().getAtIndex(habType) - TTCorrectionFactor); if (testHabStart.getAtIndex(habType) < 0) { testHabStart.setAtIndex(habType, 0); } tmpHab = race.getHabHigh().getAtIndex(habType) + TTCorrectionFactor; if (tmpHab > 100) { tmpHab = 100; } testHabWidth.setAtIndex(habType, tmpHab - testHabStart.getAtIndex(habType)); } } gravitySum = 0.0; for (int iterationGrav = 0; iterationGrav < numIterationsGrav; iterationGrav++) { tmpHab = getPlanetHabForHabIndex(iterationGrav, 0, loopIndex, numIterationsGrav, testHabStart.getGrav(), testHabWidth.getGrav(), terraformOffset); testPlanetHab.setGrav(tmpHab); temperatureSum = 0.0; for (int iterationTemp = 0; iterationTemp < numIterationsTemp; iterationTemp++) { tmpHab = getPlanetHabForHabIndex(iterationTemp, 1, loopIndex, numIterationsTemp, testHabStart.getTemp(), testHabWidth.getTemp(), terraformOffset); testPlanetHab.setTemp(tmpHab); radiationSum = 0; for (int iterationRad = 0; iterationRad < numIterationsRad; iterationRad++) { tmpHab = getPlanetHabForHabIndex(iterationRad, 2, loopIndex, numIterationsRad, testHabStart.getRad(), testHabWidth.getRad(), terraformOffset); testPlanetHab.setRad(tmpHab); planetDesirability = race.getPlanetHabitability(testPlanetHab); terraformOffsetSum = terraformOffset[0] + terraformOffset[1] + terraformOffset[2]; if (terraformOffsetSum > TTCorrectionFactor) { planetDesirability -= terraformOffsetSum - TTCorrectionFactor; if (planetDesirability < 0) { planetDesirability = 0; } } planetDesirability *= planetDesirability; switch (loopIndex) { case 0: planetDesirability *= 7; break; case 1: planetDesirability *= 5; break; default: planetDesirability *= 6; break; } radiationSum += planetDesirability; } if (!race.isImmuneRad()) { radiationSum = (radiationSum * testHabWidth.getRad()) / 100; } else { radiationSum *= 11; } temperatureSum += radiationSum; } if (!race.isImmuneTemp()) { temperatureSum = (temperatureSum * testHabWidth.getTemp()) / 100; } else { temperatureSum *= 11; } gravitySum += temperatureSum; } if (!race.isImmuneGrav()) { gravitySum = (gravitySum * testHabWidth.getGrav()) / 100; } else { gravitySum *= 11; } points += gravitySum; } return((long)(points / 10.0 + 0.5)); }