示例#1
0
    void StartNewProcess(IntentProcess process)
    {
        var processCoroutine = creature.GetProcessCoroutine(process);

        this.currentProcess          = process;
        this.currentProcessCoroutine = StartCoroutine(processCoroutine);
    }
示例#2
0
 public void ResetState()
 {
     this.currentProcess = null;
     if (this.currentProcessCoroutine != null)
     {
         StopCoroutine(this.currentProcessCoroutine);
     }
 }
示例#3
0
    void CancelCurrentProcess()
    {
        if (this.currentProcessCoroutine != null)
        {
            StopCoroutine(currentProcessCoroutine);
            this.currentProcessCoroutine = null;
        }

        this.currentProcess = null;
        creature.CleanContext();
    }
示例#4
0
    public void Interrupt(IntentProcess process)
    {
        if (ShouldUpdateProcess(process.kind))
        {
            currentProcess.priority = process.priority;
            return;
        }

        if (ShouldInterruptProcess(process.priority, process.kind))
        {
            ChangeCurrentProcess(process);
        }
    }
示例#5
0
    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);
    }
示例#6
0
    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();
    }
示例#7
0
    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);
    }
示例#8
0
    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;
    }
示例#9
0
    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);
            }
        }
    }
示例#10
0
    void HandleIdle()
    {
        var idleProcess = IntentProcess.Proc_Idle();

        cpu.Interrupt(idleProcess);
    }
示例#11
0
    void HandleHunger()
    {
        var hungerProcess = IntentProcess.Proc_SearchFood(this.hunger * 2f);

        cpu.Interrupt(hungerProcess);
    }