Ejemplo n.º 1
0
    void OnCollisionEnter(Collision collision)
    {
        if (collision.transform.tag == GetFoodTag())
        {
            if (collision.transform.tag == "Species1")
            {
                CreatureAgent targetAgent = collision.transform.GetComponent <CreatureAgent>();
                if (targetAgent != null)
                {
                    targetAgent.Eaten();
                }
            }
            if (collision.transform.tag == "Grass")
            {
                Grass grass = collision.transform.GetComponent <Grass>();
                if (grass != null)
                {
                    grass.Eaten();
                }
            }

            AddReward(1.0f);

            //Commenting out EndEpisode as the agents don't concern with consequences of after eating (i.e. other thing eats them)
            //EndEpisode();
        }
    }
Ejemplo n.º 2
0
    // scanner
    private void FixedUpdate()
    {
        RaycastHit hitInfo;

        if (Physics.Raycast(creature.position + currentRotation * creature.localScale.x / 2, currentRotation, out hitInfo, length))
        {
            // as soon as planet has relief then add if statement
            other = hitInfo.collider.gameObject.GetComponent <CreatureAgent>();
        }
        else
        {
            other = null;
        }
    }
Ejemplo n.º 3
0
        // MAIN METHOD //
        public void performAction(Creature performer)
        {
            elapsedTime += Time.deltaTime;
            //Debug.LogWarning("Elapsed Time - " + elapsedTime + " Max - " + maxAllowedTime);
            if (elapsedTime > maxAllowedTime)
            {
                DebugMenu.AppendLine(performer.thingName + " has exceeded task time for task. Resetting");
                Debug.Log(performer.thingName + " has exceeded task time for task. Resetting");
                status     = Tasks.TASK_STATUS.Failed;
                failReason = FailReason.ExceededTimeLimit;
                if (_targetThing != null)
                {
                    _targetThing.MakeAvailable(performer);
                }
                return;
            }
            //Debug.Log("Performing action " + action + " For Task - " + associatedTask);

            // LOCATE //
            if (action == Actions.Locate)
            {
                // LOCATE EAT //
                if (associatedTask == Tasks.CreatureTasks.EAT)
                {
                    //Debug.LogWarning("Locating consumeable");
                    Thing target = performer.GetClosestKnownReachableConsumable();
                    if (target == null)
                    {
                        // Target doesn't know of any consumables //
                        failReason = FailReason.NoKnownFood;
                        status     = Tasks.TASK_STATUS.Failed;
                        return;
                    }
                    else
                    {
                        _targetThing    = target;
                        _targetPosition = target.transform.position;
                        _targetThing.MakeUnavailable();
                        //Debug.LogWarning("Locate task complete with target - " + _targetThing.name);
                        status = Tasks.TASK_STATUS.Complete;
                    }
                }
                // LOCATE SLEEP //
                else if (associatedTask == Tasks.CreatureTasks.SLEEP)
                {
                    // Search for target ground //
                    float   boxSizeMult = performer.miscVariables[MiscVariables.CreatureMiscVariables.Agent_Locate_Sleep_Area_BoxCast_Size_Multipler];
                    Vector3 raycastHit  = performer.BoxCastNotMeGetClosestPoint(5, Vector3.down);

                    if (raycastHit != Vector3.positiveInfinity)
                    {
                        raycastHit.y    = performer.transform.position.y;
                        _targetPosition = raycastHit;
                        performer.GetCreatureAgent().SetDestination(_targetPosition);
                        creatureAgentDestinationHasBeenSet = true;
                        status = Tasks.TASK_STATUS.Complete;
                        return;
                    }
                    else
                    {
                        // Get's picked up by the TaskManager Update() //
                        status     = Tasks.TASK_STATUS.Failed;
                        failReason = FailReason.InfinityDistance;
                    }
                }
                // LOCATE EXPLORE //
                else if (associatedTask == Tasks.CreatureTasks.EXPLORE)
                {
                    //Debug.LogWarning("Locating explore sector");
                    GridSector sector = performer.GetClosestUnexploredSector();
                    if (sector != null)
                    {
                        Vector3 explorePoint = sector.GetRandomPositionInSector;
                        _targetPosition = explorePoint;
                    }
                    else
                    {
                        //Debug.Log("No unexplored sectors!");
                        _targetPosition = performer.GetRandomKnownSectorPosition();
                    }
                    performer.GetCreatureAgent().SetDestination(_targetPosition);
                    creatureAgentDestinationHasBeenSet = true;
                    status = Tasks.TASK_STATUS.Complete;
                    return;
                }
                // LOCATE GATHER //
                else if (associatedTask == Tasks.CreatureTasks.GATHER)
                {
                    //Thing target = performer.GetClosestKnownReachableThing(targetBaseType);
                }
            }

            // MOVE TO //
            else if (action == Actions.MoveTo)
            {
                Debug.DrawLine(performer.transform.position, _targetPosition, Color.cyan, .5f);
                // The agent should have a destination before getting to this point //
                if (!creatureAgentDestinationHasBeenSet)
                {
                    failReason = FailReason.MoveToWithNoDestination;
                    Debug.LogError("ERROR MoveTo with no destination");
                    status = Tasks.TASK_STATUS.Failed;
                    return;
                }
                else // Needs to be an else since it takes a frame for the remaining distance to calculate
                {
                    if (performer.getDistanceFromDestination() == Mathf.Infinity)
                    {
                        Debug.Log("Infinity distance");
                        failReason = FailReason.InfinityDistance;
                        status     = Tasks.TASK_STATUS.Failed;
                        return;
                    }
                    if (associatedTask == Tasks.CreatureTasks.MOVE_AND_OBSERVE)
                    {
                        performer.RequestObservationUpdate();
                    }
                    // Raycast if we're close enough to the target to where we should be able to see it //
                    float distanceBeforeRayCastCheckOnTarget = performer.miscVariables
                                                               [MiscVariables.CreatureMiscVariables.Agent_MoveTo_Raycast_For_Target_When_Distance_Below];
                    // Arrived //
                    float distanceToCompleteArrival;
                    if (associatedTask != Tasks.CreatureTasks.EXPLORE)
                    {
                        distanceToCompleteArrival = performer.getCreatureStats().getDistanceFromTargetBeforeConsideredReached();
                    }
                    else
                    {
                        distanceToCompleteArrival = 50;
                    }
                    if (performer.getDistanceFromDestination() <= distanceToCompleteArrival)
                    {
                        status = Tasks.TASK_STATUS.Complete;
                        return;
                    }
                    // Haven't arrived yet
                    else if (_targetThing != null)
                    {
                        // Check if we're close enough to start raycasting //
                        if (performer.getDistanceFromDestination() < distanceBeforeRayCastCheckOnTarget)
                        {
                            if (_targetThing != null)
                            {
                                // Raycast forward //
                                if (!performer.IsTargetInFrontOfMe(_targetThing))
                                {
                                    performer.GetCreatureAgent().SetIgnoreCollisions(false);
                                }
                                else
                                {
                                    performer.GetCreatureAgent().SetIgnoreCollisions(true);
                                }
                            }
                        }
                        // Not close enough, make sure orbiting is disabled //
                        else
                        {
                            performer.GetCreatureAgent().SetIgnoreCollisions(false);
                        }
                    }
                }
            }
            // ADD //
            else if (action == Actions.Add)
            {
                CreatureAgent agent = performer.GetCreatureAgent();
                // Tractor Beam //
                if (agent.grabType == CreatureGrabType.TractorBeam)
                {
                    // Touching Target //
                    if (Vector3.Distance(_targetThing.transform.position, performer.transform.position) < .5f)
                    {
                        if (performer.AddThingToInventory(_targetThing))
                        {
                            performer.GetCreatureAgent().CollisionRemoveIfPresent(_targetThing.transform);
                            _targetThing.transform.SetParent(performer.transform);
                            status = Tasks.TASK_STATUS.Complete;
                            return;
                        }
                        else
                        {
                            Debug.LogWarning("Failed adding thing to inventory");
                            failReason = FailReason.FailureAddingToInventory;
                            status     = Tasks.TASK_STATUS.Failed;
                            return;
                        }
                    }
                }
            }
            // EAT //
            else if (action == Actions.Eat)
            {
                if (_targetThing.beConsumed(performer))
                {
                    performer.PlayOneShot();
                    performer.ConsumeThing(_targetThing);
                    status = Tasks.TASK_STATUS.Complete;
                    return;
                }
            }
            // Land //
            else if (action == Actions.Land)
            {
                CreatureAgent agent = performer.GetCreatureAgent();
                if (!agent.IsLanding())
                {
                    // Landing failed //
                    agent.Land();
                    return;
                }
                return;
            }
            // DEACTIVATE SELF //
            else if (action == Actions.Sleep)
            {
                if (performer.GetCurrentState() != Creature.CREATURE_STATE.SLEEP)
                {
                    performer.GetCreatureAgent().Sleep();
                }
                if (!performer.StillNeedsSleep())
                {
                    status = Tasks.TASK_STATUS.Complete;
                }
            }
        }