public void PutGeneticMaterial(VillagerBody body) { if (body.Female) FemaleMaterials.Enqueue(body.Genetics); else MaleMaterials.Enqueue(body.Genetics); }
void GiveBirth() { Vector3 location = UnityEngine.Random.onUnitSphere; location.y = 0; location.Normalize(); location *= Size * 1.1f; location += transform.position; VillagerBody newChild = Instantiate(VillagerPrefab, location, Quaternion.identity); newChild.transform.parent = transform.parent; newChild.Home = this; newChild.Alignment = Alignment; newChild.Female = UnityEngine.Random.value >= 0.5f; BrainWrapper newBrain = newChild.gameObject.AddComponent<BrainWrapper>(); newBrain.Brain = BrainLoader.NewBrain(); newBrain.SetRules(GameManager.Instance.Rules); if (FemaleMaterials.Count > 0 && MaleMaterials.Count > 0) { GeneticMaterial mother = FemaleMaterials.Dequeue(); GeneticMaterial father = MaleMaterials.Dequeue(); AiProtocol.IBrainGenetics childBrain = null; if (mother.BrainGenetics != null && father.BrainGenetics != null) childBrain = mother.BrainGenetics.Cross(father.BrainGenetics); newChild.Strength = (int)(mother.Strength + father.Strength + UnityEngine.Random.Range(-1f, 2f)); newChild.Intelligence = (int)(mother.Intelligence + father.Intelligence + UnityEngine.Random.Range(-1f, 2f)); newChild.Agility = (int)(mother.Agility + father.Agility + UnityEngine.Random.Range(-1f, 2f)); newBrain.Initialize(childBrain); } else { newChild.Strength = (int)(UnityEngine.Random.Range(LowStrength, HighStrength) + 0.5f); newChild.Agility = (int)(UnityEngine.Random.Range(LowAgility, HighAgility) + 0.5f); newChild.Intelligence = (int)(UnityEngine.Random.Range(LowIntelligence, HighIntelligence) + 0.5f); } }
public void PutGeneticMaterial(VillagerBody body) { if (body.Alignment != Alignment) { return; } if (body.Female) { FemaleMaterials.Enqueue(body.Genetics); } else { MaleMaterials.Enqueue(body.Genetics); } }