Ejemplo n.º 1
0
    public override bool checkProceduralPrecondition(GameObject agent)
    {
        // find the nearest tree that we can mine
        BushEntity[] bushes      = FindObjectsOfType(typeof(BushEntity)) as BushEntity[];
        BushEntity   closest     = null;
        float        closestDist = 0;

        foreach (BushEntity bush in bushes)
        {
            if (bush.food > 0)
            {
                if (closest == null)
                {
                    // first one, so choose it for now
                    closest     = bush;
                    closestDist = (bush.gameObject.transform.position - agent.transform.position).magnitude;
                }
                else
                {
                    // is this one closer than the last?
                    float dist = (bush.gameObject.transform.position - agent.transform.position).magnitude;
                    if (dist < closestDist)
                    {
                        // we found a closer one, use it
                        closest     = bush;
                        closestDist = dist;
                    }
                }
            }
        }
        targetBush = closest;
        target     = targetBush.gameObject;
        return(closest != null);
    }
Ejemplo n.º 2
0
    public override bool checkProceduralPrecondition(GameObject agent)
    {
        Collector collector = (Collector)agent.GetComponent(typeof(Collector));

        targetBush = collector.actualBush;
        if (targetBush != null)
        {
            target = targetBush.gameObject;
        }
        return(targetBush != null);
    }
    public override bool checkProceduralPrecondition(GameObject agent)
    {
        // Find bush
        float localRadius = (numTry / 2) + radius;

        numTry++;
        Collider2D[] colliders       = Physics2D.OverlapCircleAll(agent.transform.position, localRadius);
        Collider2D   closestCollider = null;
        float        closestDist     = 0;

        if (colliders == null)
        {
            return(false);
        }
        foreach (Collider2D hit in colliders)
        {
            if (hit.tag != "Bush")
            {
                continue;
            }

            BushEntity bush = (BushEntity)hit.gameObject.GetComponent(typeof(BushEntity));
            if (bush.empty || bush.viewed)
            {
                continue;
            }
            if (closestCollider == null)
            {
                closestCollider = hit;
                closestDist     = (closestCollider.gameObject.transform.position - agent.transform.position).magnitude;
            }
            else
            {
                float dist = (hit.gameObject.transform.position - agent.transform.position).magnitude;
                if (dist < closestDist)
                {
                    // we found a closer one, use it
                    closestCollider = hit;
                    closestDist     = dist;
                }
            }
            Debug.DrawLine(closestCollider.gameObject.transform.position, agent.transform.position, Color.red, 3, false);
        }

        bool isClosest = closestCollider != null;

        if (isClosest)
        {
            targetBush = (BushEntity)closestCollider.gameObject.GetComponent(typeof(BushEntity));
            target     = targetBush.gameObject;
            numTry     = 1;
        }
        // Bush too far
        if (numTry > 10)
        {
            // Evolution process
            Collector collector = (Collector)agent.GetComponent(typeof(Collector));
            if (collector.center.needCarriers())
            {
                collector.instanciateSuccessor("Carrier");
                return(false);
            }

            if (collector.center.needHunters())
            {
                collector.instanciateSuccessor("Hunter");
                return(false);
            }

            if (collector.center.needFishers())
            {
                collector.instanciateSuccessor("Fisher");
                return(false);
            }

            collector.instanciateSuccessor("Farmer");
            return(false);
        }
        return(isClosest);
    }
 public override void reset()
 {
     analyzed   = false;
     targetBush = null;
     startTime  = 0;
 }
Ejemplo n.º 5
0
 public override void reset()
 {
     collected  = false;
     targetBush = null;
     startTime  = 0;
 }