Ejemplo n.º 1
0
    public override bool Perform(GAgent agent)
    {
        timer += Time.deltaTime;

        //agent. //TODO

        //run the action - return true while the action is being executed
        //return false if something makes it unable to finish executing it's task.

        return(false);
    }
    public override bool Perform(GAgent agent)
    {
        //run the action - return true while the action is being executed
        //return false if something makes it unable to finish executing it's task.
        if (!isInitialized)
        {
            Initialize(agent);
        }


        return(false);
    }
Ejemplo n.º 3
0
    public override bool CheckProceduralPrecondition(GAgent agent)
    {
        //set target if none is set yet.
        if (target == null)
        {
            target = agent.BlackBoard.RequestSourceLocation(SourceNames.Forest);
        }

        //if target is still null, no target is known.
        if (target == null)
        {
            return(false);
        }


        #region ironRockCode

        /*
         * // find the nearest rock that we can mine
         * IronRockComponent[] rocks = FindObjectsOfType(typeof(IronRockComponent)) as IronRockComponent[];
         * IronRockComponent closest = null;
         * float closestDist = 0;
         *
         * foreach (IronRockComponent rock in rocks)
         * {
         *  if (closest == null)
         *  {
         *      // first one, so choose it for now
         *      closest = rock;
         *      closestDist = (rock.gameObject.transform.position - agent.transform.position).magnitude;
         *  }
         *  else
         *  {
         *      // is this one closer than the last?
         *      float dist = (rock.gameObject.transform.position - agent.transform.position).magnitude;
         *      if (dist < closestDist)
         *      {
         *          // we found a closer one, use it
         *          closest = rock;
         *          closestDist = dist;
         *      }
         *  }
         * }
         * targetRock = closest;
         * target = targetRock.gameObject;
         *
         * return closest != null;
         */
        #endregion
        return(true);
    }
Ejemplo n.º 4
0
    public override bool Perform(GAgent agent)
    {
        if (startTime == 0)
        {
            startTime = Time.time;
        }

        if (Time.time - startTime > GatherDuration)
        { //finished
            Debug.Log("wood gathered");
        }

        return(true);
    }
Ejemplo n.º 5
0
 private void OnTriggerStay(Collider other)
 {
     if (other.CompareTag(Tags.Pirate))
     {
         GameObject victim = Inventory.GetItem(VictimKey);
         if (!victim || Vector3.Distance(transform.position, victim.transform.position) > Vector3.Distance(transform.position, other.transform.position))
         {
             // Check if the pirate is attacking someone
             GAgent otherAgent = other.GetComponent <GAgent>();
             if (otherAgent.Inventory.GetItem(VictimKey) != null)
             {
                 Inventory.AddItem(VictimKey, other.gameObject);
                 Beliefs.SetState(FoundVictimKey, 1);
             }
         }
     }
 }
Ejemplo n.º 6
0
    public virtual void Awake()
    {
        if (PreConditions != null)
        {
            foreach (WorldState w in PreConditions)
            {
                Preconditions.Add(w.Key, w.Value);
            }
        }

        if (AfterEffects != null)
        {
            foreach (WorldState w in AfterEffects)
            {
                Effects.Add(w.Key, w.Value);
            }
        }

        mAgent = GetComponent <GAgent>();
    }
Ejemplo n.º 7
0
    public override bool Perform(GAgent agent)
    {
        if (!isInitialized)
        {
            Initialize(agent);
        }

        //run the action - return true while the action is being executed
        //return false if something makes it unable to finish executing it's task.

        float step = agent.moveSpeed * Time.deltaTime;

        agent.transform.position = Vector3.MoveTowards(agent.transform.position, target.transform.position, step);

        if (gameObject.transform.position.Equals(target.transform.position))
        {
            agent.NearTarget = done = true;
        }
        return(true);
    }
Ejemplo n.º 8
0
    public override bool CheckProceduralPrecondition(GAgent agent)
    {
        //Cant move to target if the agent has no target
        //save the target to check if the target changed while moving.
        if (agent.Target == null)
        {
            return(false);
        }
        else if (target == null)
        {
            target = agent.Target;
        }

        //cancel out if target changed
        if (target != agent.Target)
        {
            return(false);
        }

        return(true);
    }
Ejemplo n.º 9
0
 // Start is called before the first frame update
 void Start()
 {
     thisAgent = this.GetComponent <GAgent>();
 }
Ejemplo n.º 10
0
 void Start()
 {
     inventory = gameObject.GetComponent <AgentInventory>();
     agent     = gameObject.GetComponent <GAgent>();
 }
Ejemplo n.º 11
0
 //run the action - return value should be true if the action is performed succesfully and false if something happened that makes it no longer be able to perform its action.
 public abstract bool Perform(GAgent agent);
Ejemplo n.º 12
0
 //procedurally keeps checking if the action can run, if the action needs it.
 //only use this to check if it is even possible to run an action in the first place.
 public abstract bool CheckProceduralPrecondition(GAgent agent);
 private void Initialize(GAgent agent)
 {
     isInitialized = true;
     //Execute any code you only want to run once during this action here.
 }
Ejemplo n.º 14
0
    //TODO: public int MaxDepth = 10;

    public Queue <GAction> Plan(GAgent agent, HashSet <GAction> availableActions, Dictionary <string, object> worldState, Dictionary <string, object> goalState)
    {
        foreach (GAction a in availableActions)
        {
            a.ResetVariables();
        }

        // check what actions can run using their checkProceduralPrecondition
        HashSet <GAction> usableActions = new HashSet <GAction>();

        foreach (GAction a in availableActions)
        {
            if (a.CheckProceduralPrecondition(agent))
            {
                usableActions.Add(a);
            }
        }

        List <GNode> leaves = new List <GNode>();

        Debug.Log("Started planing");

        GNode start   = new GNode(null, 0, worldState, null);
        bool  success = BuildGraph(start, leaves, usableActions, goalState);

        if (!success)
        {
            Debug.Log("No plan found!");
            return(null);
        }

        GNode cheapest = null;

        foreach (GNode leaf in leaves)
        {
            if (cheapest == null)
            {
                cheapest = leaf;
            }
            else
            {
                if (leaf.runningCost < cheapest.runningCost)
                {
                    cheapest = leaf;
                }
            }
        }

        List <GAction> result = new List <GAction>();
        GNode          n      = cheapest;

        while (n != null) //puts the cheapest branch of leaves in order in result
        {
            if (n.action != null)
            {
                result.Insert(0, n.action);
            }
            n = n.parent;
        }

        //is this necesary? maybe implement this loop in previous loop.
        Queue <GAction> queue = new Queue <GAction>();

        foreach (GAction a in result)
        {
            queue.Enqueue(a);
        }

        return(queue);
    }
Ejemplo n.º 15
0
 private void Initialize(GAgent agent)
 {
     agent.NearTarget = false;
 }
Ejemplo n.º 16
0
 private void Awake()
 {
     mAgent = GetComponent <GAgent>();
 }