Esempio n. 1
0
 private void Initialize(string name, Area area)
 {
     base.initialize(name);
     this.currentArea = area;
     taskManager      = new TaskManager(this);
     inventory        = new Inventory(this);
     if (baseSpecies == BASE_SPECIES.Gnat)
     {
         species = new Species('m', "Gnat", true, BASE_SPECIES.Gnat,
                               CONSUMPTION_TYPE.OMNIVORE, this);
     }
     else if (baseSpecies == BASE_SPECIES.Gagk)
     {
         species = new Species('n', baseSpecies.ToString(), true, BASE_SPECIES.Gagk,
                               CONSUMPTION_TYPE.HERBIVORE, this);
     }
     creaturePhysicalStats = CreatureConstants.PhysicalStatsInitialize(species.getBaseSpecies(), this);
     agent        = new CreatureAgent(this);
     audioSource  = GetComponent <AudioSource>();
     currentState = CREATURE_STATE.IDLE;
     creaturePhysicalStats.Initialize(species.getBaseSpecies());
     agent.Initialize(species.getBaseSpecies());
     miscVariables           = MiscVariables.GetCreatureMiscVariables(this);
     memberOfTribe           = null;
     knownGridSectorsVisited = new Dictionary <GridSector, bool>();
     lastObserved            = Random.Range(0, Time.time);
     observeEvery            = 2.5f;
     initialized             = true;
 }
Esempio n. 2
0
 public void ChangeState(CREATURE_STATE requestedState)
 {
     if (requestedState != currentState)
     {
         // Request to go to Sleep //
         if (requestedState == CREATURE_STATE.SLEEP)
         {
             agent.DisableAgent();
         }
         // If we need to wake up from sleep //
         else if (currentState == CREATURE_STATE.SLEEP)
         {
             agent.EnableAgent();
             Debug.LogWarning("ReEnabling Agent from sleep");
         }
         this.currentState = requestedState;
     }
     else
     {
         Debug.LogError("Call to request an already active state - " + currentState + "-" + requestedState);
     }
 }
Esempio n. 3
0
        public void Update()
        {
            if (RunDebugMethod)
            {
                taskManager.clearAllTasks();
                RunDebugMethod = false;
            }
            if (!initialized && DEBUGSCENE)
            {
                Initialize("TestCreature", World.CurrentArea);
            }
            float delta = Time.deltaTime;

            base.ManualUpdate(delta);
            agent.Update();
            lastUpdated += delta;
            if (lastUpdated > creaturePhysicalStats.updateEvery)
            {
                lastUpdated = 0;
                if (!CreatureConstants.CreatureIsIncapacitatedState(currentState))
                {
                    if (Time.time - lastObserved > observeEvery)
                    {
                        observeSurroundings();
                    }
                }
                // CREATURE IS IDLE, LOOK FOR SOMETHING TO DO //
                if (currentState == CREATURE_STATE.IDLE)
                {
                    debug("Creature is idle, looking for new task");
                    taskManager.GetNewTask(this);
                    if (taskManager.hasTask())
                    {
                        currentState = CREATURE_STATE.WAIT;
                    }
                }
                // CREATURE IS NOT IDLE //
                else
                {
                    debug("Performing current tasks - " + taskManager.getCurrentTaskType());
                    taskManager.PerformCurrentTask();
                    // Task was cancelled, mark creature as idle to get a new task next update //
                    if (taskManager.GetCurrentTaskStatus() == Tasks.TASK_STATUS.Cancelled &&
                        currentState != CREATURE_STATE.IDLE)
                    {
                        ChangeState(CREATURE_STATE.IDLE);
                    }
                    if (taskManager.GetCurrentAction() == ActionStep.Actions.MoveTo)
                    {
                        if (DEBUGSCENE)
                        {
                            Debug.DrawLine(transform.position, agent.Destination, Color.cyan, 1f);
                        }
                    }
                }
                //Debug.LogWarning("Current state - " + currentState);
                if (!taskManager.hasTask() && !CreatureConstants.CreatureIsIncapacitatedState(currentState))
                {
                    debug("No task found, marking Idle");
                    currentState = CREATURE_STATE.IDLE;
                }
                // CREATURE PHYSICAL STATS UPDATES //
                if (currentState != CREATURE_STATE.DEAD)
                {
                    creaturePhysicalStats.Update();
                }
            }
        }