Beispiel #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;
 }
Beispiel #2
0
        protected Dictionary <MiscVariables.AgentMiscVariables, float> miscVariables; // Misc Constants

        public Part(CreaturePart creaturePart, Transform transform, float updateEvery)
        {
            this.PartType      = creaturePart;
            this.PartTransform = transform;
            this.UpdateEvery   = updateEvery;

            this.parentCreature = transform.GetComponentInParent <Creature>();
            this.attachedAgent  = parentCreature.GetCreatureAgent();
            miscVariables       = MiscVariables.GetAgentMiscVariables(parentCreature);
            audioClip           = CreatureConstants.GetCreaturePartAudioClip(parentCreature.GetBaseSpecies(), creaturePart);
            Enabled             = true;
        }
 public void Initialize(BASE_SPECIES baseSpecies)
 {
     rigidbody = creature.GetComponent <Rigidbody>();
     CreatureConstants.CreatureAgentInitialize(baseSpecies, this);
     if (rigidbody == null)
     {
         rigidbody = creature.GetComponentInParent <Rigidbody>();
         if (rigidbody == null)
         {
             rigidbody = creature.GetComponentInChildren <Rigidbody>();
             if (rigidbody == null)
             {
                 Debug.LogError("Can't find rigid body on " + creature.thingName);
             }
         }
     }
     rigidbody.constraints = RigidbodyConstraints.None;
     _transform            = rigidbody.transform;
     if (baseSpecies == BASE_SPECIES.Gnat)
     {
         locomotionType = CreatureLocomotionType.Flight;
     }
     else if (baseSpecies == BASE_SPECIES.Gagk)
     {
         locomotionType = CreatureLocomotionType.StandardForwardBack;
     }
     foreach (Part part in allParts)
     {
         if (part is EnginePart)
         {
             EnginePart movePart = (EnginePart)part;
             movePart.InitializeMovementPart();
         }
     }
     ignoreIncomingCollisions = false;
     initialized = true;
 }
        public void SetState(MovementState requestedState)
        {
            //Debug.LogWarning("Change of state to " + requestedState + "-" + flightDirection);
            List <MovementState> availableStates = CreatureConstants.GetStatesCanSwithTo(CurrentState);

            if (!availableStates.Contains(requestedState))
            {
                Debug.LogError("Requesting change of state to invalid state request-current" +
                               requestedState + "-" + CurrentState);
                return;
            }
            Vector3 currentForce = cf.relativeForce;

            if (requestedState == MovementState.FORWARD)
            {
                if (flightDirection == Direction.X)
                {
                    currentForce.x = MaxForce;
                }
                else if (flightDirection == Direction.Y)
                {
                    currentForce.y = MaxForce;
                }
                else
                {
                    currentForce.z = MaxForce;
                }
            }
            else if (requestedState == MovementState.IDLE)
            {
                if (MinForce > 0)
                {
                    if (flightDirection == Direction.X)
                    {
                        currentForce.x = MinForce;
                    }
                    else if (flightDirection == Direction.Y)
                    {
                        currentForce.y = MinForce;
                    }
                    else if (flightDirection == Direction.Z)
                    {
                        currentForce.z = MinForce;
                    }
                }
                else
                {
                    if (flightDirection == Direction.X)
                    {
                        currentForce.x = 0;
                    }
                    else if (flightDirection == Direction.Y)
                    {
                        currentForce.y = 0;
                    }
                    else if (flightDirection == Direction.Z)
                    {
                        currentForce.z = 0;
                    }
                }
            }
            else if (requestedState == MovementState.REVERSE)
            {
                if (flightDirection == Direction.X)
                {
                    currentForce.x = MinForce;
                }
                else if (flightDirection == Direction.Y)
                {
                    currentForce.y = MinForce;
                }
                else if (flightDirection == Direction.Z)
                {
                    currentForce.z = MinForce;
                }
            }
            else if (requestedState == MovementState.UNINITIALIZED)
            {
                if (flightDirection == Direction.X)
                {
                    currentForce.x = 0;
                }
                else if (flightDirection == Direction.Y)
                {
                    currentForce.y = 0;
                }
                else if (flightDirection == Direction.Z)
                {
                    currentForce.z = 0;
                }
            }
            else if (requestedState == MovementState.POWER_DOWN)
            {
                if (flightDirection == Direction.X)
                {
                    currentForce.x = 0;
                }
                else if (flightDirection == Direction.Y)
                {
                    currentForce.y = MinForce;
                }
                else if (flightDirection == Direction.Z)
                {
                    currentForce.z = 0;
                }
            }
            cf.relativeForce = currentForce;
            CurrentState     = requestedState;
        }
Beispiel #5
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();
                }
            }
        }
Beispiel #6
0
 public Needs(BASE_SPECIES baseSpecies)
 {
     currentNeeds = CreatureConstants.NeedsInitialize(baseSpecies);
 }