//create a population et generate random stats for it private GameInfo.PopulationStat[] GeneratePopulationStats() { Random random = new Random(); GameInfo.PopulationStat[] populationStat = new GameInfo.PopulationStat[GameInfo.populationCount]; for (int i = 1; i < populationStat.Count(); i++) { int availablePoints = 20; populationStat[i] = new GameInfo.PopulationStat(); //divide the points in the stats, trying to get one higher than the others for (int j = 0; j < populationStat[i].stats.Count(); j++) { int pointSpent = Random.Range(0, availablePoints + 1); populationStat[i].stats[j] = pointSpent; availablePoints -= pointSpent; if (availablePoints == 0) { break; } } //shuffle the stats for (int j = 0; j < populationStat[i].stats.Count(); j++) { int firstRandom = Random.Range(0, populationStat[i].stats.Count()); int secondRandom = Random.Range(0, populationStat[i].stats.Count()); (populationStat[i].stats[firstRandom], populationStat[i].stats[secondRandom]) = (populationStat[i].stats[secondRandom], populationStat[i].stats[firstRandom]); } } return(populationStat); }
public void Init(PopulationController parentPopulation, GameInfo.PopulationStat populationStat) { this.parentPopulation = parentPopulation; this.stats = populationStat.stats; SphereCollider agroCollider = GetComponentInChildren <SphereCollider>(); aiDestinationSetter = GetComponent <AIDestinationSetter>(); aIPath = GetComponent <AIPath>(); //set the base stats of the individual from its population stats aIPath.maxSpeed = stats[(int)GameInfo.PopulationStat.stat.speed] * 2f + 15f; agroCollider.radius = stats[(int)GameInfo.PopulationStat.stat.vision] * 2 + 10; timeLeft += stats[(int)GameInfo.PopulationStat.stat.endurance] * 1.5f; newTarget = new GameObject().transform; target = generatePosition(); aiDestinationSetter.target = target; aIPath.SearchPath(); }
public void Init(Color color, GameInfo.PopulationStat stats) { this.color = color; this.stats = stats; }