Ejemplo n.º 1
0
 public override void OnDrawBTGizmos(AITankControl tank)
 {
     if (selected)
     {
         selected.OnDrawBTGizmos(tank);
     }
 }
Ejemplo n.º 2
0
    /// <summary>
    /// Run our selected child.  If no child is selected, select one.  If can't select one, return false.
    /// </summary>
    /// <param name="tank">Tank being controlled.</param>
    /// <returns>Whether we want to continue running.</returns>
    public override bool Tick(AITankControl tank)
    {
        // Fill me in
        BehaviorTreeNode s_child = SelectChild(tank);

        if (s_child != null)
        {
            if (s_child != selected)
            {
                Deactivate(tank);
                selected = s_child;
                Activate(tank);
            }


            bool tick_val = selected.Tick(tank);
            if (tick_val == false)
            {
                Deactivate(tank);
                selected = null;
            }

            return(true);
        }

        else
        {
            return(false);
        }
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Run the specified decider and returns its value
    /// </summary>
    /// <param name="d">Decider to run</param>
    /// <param name="tank">Tank being controlled</param>
    /// <returns>True if decider wants to run</returns>
    public static bool Decide(this DeciderType d, AITankControl tank)
    {
        switch (d)
        {
        case DeciderType.Always:
            return(true);

        case DeciderType.TooManyBullets:
            return(Physics2D.OverlapCircleAll(tank.transform.position, BulletSearchRadius, (int)Layers.Projectiles).Length
                   > MaxBullets);

        case DeciderType.LineOfSightToPlayer:
            return(!BehaviorTreeNode.WallBetween(tank.transform.position, BehaviorTreeNode.Player.position));

        case DeciderType.CanFire:
            float angle = Vector2.Angle(BehaviorTreeNode.Player.position - tank.transform.position,
                                        tank.transform.up);
            return(angle < MaxAngularDifference &&
                   Vector2.Distance(tank.transform.position, BehaviorTreeNode.Player.position)
                   < DistanceThreshold);

        default:
            throw new ArgumentException("Unknown Decider: " + d);
        }
    }
Ejemplo n.º 4
0
    /// <summary>
    /// Select a child to run based on the policy.
    /// </summary>
    /// <param name="tank">Tank being controlled</param>
    /// <returns>Child to run, or null if no runnable children.</returns>
    private BehaviorTreeNode SelectChild(AITankControl tank)
    {
        switch (Policy)
        {
        case SelectionPolicy.Prioritized:
            // Fill this in
            foreach (BehaviorTreeNode child in Children)
            {
                if (child == selected)
                {
                    return(selected);
                }

                else
                if (child.Decide(tank))
                {
                    return(child);
                }
            }
            return(null);

        default:
            throw new NotImplementedException("Unimplemented policy: " + Policy);
        }
    }
Ejemplo n.º 5
0
 public override void Activate(AITankControl tank)
 {
     // Check to make sure the subset property is satisfied
     if (!Children.Any(c => c.Decide(tank)))
     {
         Debug.Log(name + " activated without runnable child");
     }
 }
Ejemplo n.º 6
0
 /// <summary>
 /// We're not running anymore; recursively deactivate our selected child.
 /// </summary>
 /// <param name="tank">Tank being controlled</param>
 public override void Deactivate(AITankControl tank)
 {
     if (selected)
     {
         selected.Deactivate(tank);
         selected = null;
     }
 }
Ejemplo n.º 7
0
    public override bool Tick(AITankControl tank)
    {
        if (!WallBetween(tank.transform.position, Player.position))
        {
            tank.MoveTowards(Player.position);
            return(true);
        }

        else
        {
            return(false);
        }
    }
Ejemplo n.º 8
0
    /// <summary>
    /// Move toward the next waypoint
    /// </summary>
    /// <param name="tank">Tank being controlled</param>
    /// <returns>True if we aren't there yet</returns>
    public override bool Tick(AITankControl tank)
    {
        if (currentPath == null || currentPath.Count == 0)
        {
            currentPath = Waypoint.FindPath(tank.transform.position, Player.position);
        }

        if (Vector3.Distance(currentPath[0].transform.position, tank.transform.position) < 1)
        {
            currentPath.RemoveAt(0);
            return(false);
        }

        tank.MoveTowards(currentPath[0].transform.position);

        return(true);
    }
Ejemplo n.º 9
0
    /// <summary>
    /// Run toward the goal
    /// </summary>
    /// <param name="tank">Tank being controlled</param>
    /// <returns>True if behavior wants to keep running</returns>
    public override bool Tick(AITankControl tank)
    {
        while (WallBetween(tank.transform.position, goal))
        {
            goal = SpawnController.FindFreeLocation(1);
        }

        if (Vector3.Distance(goal, tank.transform.position) > 1)
        {
            tank.MoveTowards(goal);
            return(true);
        }

        else
        {
            return(false);
        }
    }
Ejemplo n.º 10
0
    public override void OnDrawBTGizmos(AITankControl tank)
    {
        if (currentPath == null || currentPath.Count == 0)
        {
            return;
        }

        Gizmos.color = Color.green;
        Gizmos.DrawLine(currentPath[0].transform.position + Vector3.right,
                        tank.transform.position + Vector3.right);
        Gizmos.DrawLine(currentPath[0].transform.position + Vector3.up,
                        tank.transform.position + Vector3.up);
        for (int i = 1; i < currentPath.Count; i++)
        {
            Gizmos.DrawLine(currentPath[i].transform.position + Vector3.right,
                            currentPath[i - 1].transform.position + Vector3.right);
            Gizmos.DrawLine(currentPath[i].transform.position + Vector3.up,
                            currentPath[i - 1].transform.position + Vector3.up);
        }
    }
Ejemplo n.º 11
0
 public override bool Tick(AITankControl tank)
 {
     return(false);
 }
Ejemplo n.º 12
0
 public override bool Tick(AITankControl tank)
 {
     tank.Fire();
     return(false);
 }
Ejemplo n.º 13
0
 public virtual void OnDrawBTGizmos(AITankControl tank)
 {
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Called when node is deselected.
 /// Not called again, until it is reselected and then deselected again.
 /// </summary>
 /// <param name="tank">Tank being controlled</param>
 public virtual void Deactivate(AITankControl tank)
 {
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Control the tank.  Called only if this node has been chosen to run.
 /// </summary>
 /// <param name="tank">Tank to control</param>
 /// <returns>True if we want to keep running.</returns>
 public abstract bool Tick(AITankControl tank);
Ejemplo n.º 16
0
 /// <summary>
 /// Check if we want to run
 /// </summary>
 /// <param name="tank">The tank being controlled</param>
 /// <returns>True if we want to run</returns>
 public bool Decide(AITankControl tank)
 {
     return(tank.AILevel >= MinimumLevel && Decider.Decide(tank));
 }