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); } }
void Update() { timer -= Time.deltaTime; if (timer < 0 && GameManager.Instance.Config.TigersOnMap < GameManager.Instance.Config.TigersLimit) { TigerBody newChild = Instantiate(AnimalPrefab, transform.position, Quaternion.identity); newChild.transform.parent = transform.parent; newChild.Female = UnityEngine.Random.value >= 0.5f; BrainWrapper newBrain = newChild.gameObject.AddComponent <BrainWrapper>(); newChild.Speed = GameManager.Instance.Config.TigerSpeed; newChild.SneakMastery = GameManager.Instance.Config.TigerSneakMastery; newChild.Damage = GameManager.Instance.Config.TigerDamage; newChild.AttackSpeed = GameManager.Instance.Config.TigerAttackSpeed; timer = GameManager.Instance.Config.TigerSpawnTimer; } }
protected virtual void Start() { TextPrefab = Instantiate(TextPrefab); TextPrefab.SetActive(false); TextPrefab.transform.SetParent(GameObject.Find("Canvas").transform, false); TextPrefab.transform.localScale = new Vector3(0, 0, 0); Brain = GetComponent <BrainWrapper>(); if (Brain == null || Brain.Brain == null) { if (Brain == null) { Brain = gameObject.AddComponent <BrainWrapper>(); } Brain.Brain = new TigerBrain(); print("added tigerbrain"); } Body = GetComponent <LivingEntityBody>(); }
public void Submit() { if (Input.GetKey(KeyCode.Return) || Input.GetKey(KeyCode.KeypadEnter)) { print("SUBMIT"); var input = GetComponent <InputField>(); BrainWrapper villagerBrain = null; if (GameManager.Instance.SelectionController.Selected != null) { villagerBrain = GameManager.Instance.SelectionController.Selected.GetComponent <BrainWrapper>(); } string msg = ""; if (villagerBrain != null) { BaseCommand res = null; try { res = ParseCommand(input.text); msg = ""; } catch (Exception e) { msg = e.Message; } if (res != null) { villagerBrain.Brain.SetNextAction(res); } else if (GameManager.Instance.Config.CheatsOn) { try { ParseCheat(input.text); msg = ""; } catch (Exception e) { msg += e.Message; } } } else if (GameManager.Instance.Config.CheatsOn) { try { ParseCheat(input.text); msg = ""; print("cheat parsed"); } catch (Exception e) { msg = e.Message; } } if (msg != "") { print("Can't parse \"" + input.text + "\"\n" + msg); } else { print("OK"); } //todo - put feedback above the console instead of printing it input.text = ""; } }