예제 #1
0
    public override bool checkProceduralPrecondition(GameObject agent)
    {
        // find the nearest supply pile that has spare firewood
        StoragePile[] storagepiles = (StoragePile[])UnityEngine.GameObject.FindObjectsOfType(typeof(StoragePile));
        StoragePile   closest      = null;
        float         closestDist  = 0;

        foreach (StoragePile storage in storagepiles)
        {
            if (closest == null)
            {
                //making sure that the pile actually has sticks in it.. lets hope this method works
                if (storage.numSticks > 0)
                {
                    // first one, so choose it for now
                    closest     = storage;
                    closestDist = (storage.gameObject.transform.position - agent.transform.position).magnitude;
                }
                //if it doesnt return a false to path finding
                else
                {
                    return(false);
                }
            }
            else
            {
                // is this one closer than the last?
                float dist = (storage.gameObject.transform.position - agent.transform.position).magnitude;
                if (dist < closestDist)
                {
                    // we found a closer one, use it
                    closest     = storage;
                    closestDist = dist;
                }
            }
        }
        if (closest == null)
        {
            return(false);
        }

        targetpile = closest;
        target     = targetpile.gameObject;

        return(closest != null);
    }
예제 #2
0
    public override bool checkProceduralPrecondition(GameObject agent)
    {
        //nearest storage
        StoragePile[] storages    = (StoragePile[])UnityEngine.GameObject.FindObjectsOfType(typeof(StoragePile));
        StoragePile   closest     = null;
        float         closestDist = 0;

        foreach (StoragePile storage in storages)
        {
            if (closest == null)
            {
                // first one, so choose it for now
                if (storage.numfood > 0)
                {
                    closest     = storage;
                    closestDist = (storage.gameObject.transform.position - agent.transform.position).magnitude;
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                // is this one closer than the last?
                float dist = (storage.gameObject.transform.position - agent.transform.position).magnitude;
                if (dist < closestDist)
                {
                    // we found a closer one, use it
                    closest     = storage;
                    closestDist = dist;
                }
            }
        }
        if (closest == null)
        {
            return(false);
        }

        targetstorage = closest;
        target        = targetstorage.gameObject;

        return(closest != null);
    }
예제 #3
0
 public override void reset()
 {
     hasFood       = false;
     targetstorage = null;
     startTime     = 0;
 }
예제 #4
0
 public override void reset()
 {
     hasPickedUpSticks = false;
     targetpile        = null;
     startTime         = 0;
 }
예제 #5
0
 public override void reset()
 {
     hasDroppedOffFood = false;
     targetStorage     = null;
     startTime         = 0;
 }