void StartNewProcess(IntentProcess process) { var processCoroutine = creature.GetProcessCoroutine(process); this.currentProcess = process; this.currentProcessCoroutine = StartCoroutine(processCoroutine); }
public void ResetState() { this.currentProcess = null; if (this.currentProcessCoroutine != null) { StopCoroutine(this.currentProcessCoroutine); } }
void CancelCurrentProcess() { if (this.currentProcessCoroutine != null) { StopCoroutine(currentProcessCoroutine); this.currentProcessCoroutine = null; } this.currentProcess = null; creature.CleanContext(); }
public void Interrupt(IntentProcess process) { if (ShouldUpdateProcess(process.kind)) { currentProcess.priority = process.priority; return; } if (ShouldInterruptProcess(process.priority, process.kind)) { ChangeCurrentProcess(process); } }
void ChangeCurrentProcess(IntentProcess process) { if (verbose && currentProcess != null && process != null) { print(">> Change of process. [" + System.Enum.GetName(typeof(IntentProcessKind), currentProcess.kind) + "] (" + currentProcess.priority + ") => [" + System.Enum.GetName(typeof(IntentProcessKind), process.kind) + "] (" + process.priority + ")"); } CancelCurrentProcess(); StartNewProcess(process); }
public IEnumerator GetProcessCoroutine(IntentProcess process) { CleanContext(); switch (process.kind) { case IntentProcessKind.SEARCH_FOOD: case IntentProcessKind.SEARCH_MATE: while (true) { yield return(RandomWalk()); } case IntentProcessKind.GO_FOOD: case IntentProcessKind.GO_MATE: yield return(WalkTo(process.position)); break; case IntentProcessKind.EAT_FOOD: var food = process.target; if (IsFoodAvailable(food)) { yield return(Eat(food)); } break; case IntentProcessKind.COPULATE: var mate = process.target.GetComponent <Creature>(); yield return(Copulate(mate)); break; case IntentProcessKind.IDLE: while (true) { yield return(RandomWalk()); yield return(new WaitForSeconds(1f)); } default: Debug.LogError("This should not be happening. Process Kind: " + System.Enum.GetName(typeof(IntentProcessKind), process.kind)); Debug.Break(); break; } cpu.EndProcess(); }
void HandleFood(GameObject obj) { if (obj == null) { return; } float distance = Vector3.Distance(this.transform.position, obj.transform.position); var foodProcess = distance < TOUCHING_DISTANCE? IntentProcess.Proc_EatFood(this.hunger * 5f, obj) : IntentProcess.Proc_GoFood(this.hunger * 3f, obj); cpu.Interrupt(foodProcess); }
IEnumerator Copulate(Creature mate) { if (this.gender == Gender.MALE) { var mateProcess = IntentProcess.Proc_Copulate(15f, this.gameObject); mate.GetComponent <CPU>().Interrupt(mateProcess); } else { StartCoroutine(Gestate(this, mate)); } yield return(new WaitForSeconds(1f)); this.reproductiveUrge_x = this.gender == Gender.FEMALE ? Mathf.PI : 0f; this.reproductiveUrge = 0f; }
void HandleCreature(GameObject obj) { if (obj == null) { return; } float distance = Vector3.Distance(this.transform.position, obj.transform.position); var targetCreature = obj.GetComponentInChildren <Creature>(); if (this.gender == Gender.MALE && targetCreature.gender == Gender.FEMALE) { if (this.reproductiveUrge * targetCreature.reproductiveUrge > 0.7f) { var mateProcess = distance < TOUCHING_DISTANCE? IntentProcess.Proc_Copulate(5f, obj) : IntentProcess.Proc_GoMate(this.reproductiveUrge * targetCreature.reproductiveUrge * 2f, obj); cpu.Interrupt(mateProcess); } } }
void HandleIdle() { var idleProcess = IntentProcess.Proc_Idle(); cpu.Interrupt(idleProcess); }
void HandleHunger() { var hungerProcess = IntentProcess.Proc_SearchFood(this.hunger * 2f); cpu.Interrupt(hungerProcess); }