Ejemplo n.º 1
0
 public CapturedState(OrientedActor actor, OrientedActor cap)
 {
     self          = actor;
     self.captured = true;
     CtF           = self.CtF;
     capturer      = cap;
     if (cap != null)
     {
         if (self._Team == OrientedActor.Team.cyan)
         {
             if (cap._Team != self._Team)
             {
                 self.PrintMessage("Status: I am Captured!");
             }
             else
             {
                 self.PrintMessage("Status: I am being Rescued!");
             }
         }
         self.jailed = false;
     }
     else
     {
         if (self._Team == OrientedActor.Team.cyan)
         {
             self.PrintMessage("Status: I am in Jail");
         }
         self.jailed = true;
         self.CallforHelp();
     }
 }
Ejemplo n.º 2
0
 public RescueState(OrientedActor actor, OrientedActor teammate)
 {
     self       = actor;
     pathFinder = self.pathFind;
     grid       = self.grid;
     teamMate   = teammate;
 }
Ejemplo n.º 3
0
 public Rescuer(OrientedActor actor, OrientedActor teammate)
 {
     self         = actor;
     teamMate     = teammate;
     rescueState  = new RescueState(self, teamMate);
     currentState = rescueState;
     currentState.Enter();
 }
Ejemplo n.º 4
0
 public ConvoyState(OrientedActor actor, OrientedActor teammate)
 {
     self       = actor;
     pathFinder = self.pathFind;
     grid       = self.grid;
     CtF        = self.CtF;
     teamMate   = teammate;
 }
Ejemplo n.º 5
0
 public Flagger(OrientedActor actor)
 {
     self         = actor;
     attackState  = new AttackState(self, this);
     returnState  = new ReturnState(self, this);
     currentState = attackState;
     attackState.Enter();
 }
Ejemplo n.º 6
0
 public PursueState(OrientedActor actor, Defender job, OrientedActor theenemy)
 {
     self         = actor;
     enemy        = theenemy;
     pathFinder   = self.pathFind;
     grid         = self.grid;
     CtF          = self.CtF;
     defenderself = job;
 }
Ejemplo n.º 7
0
 public PatrolState(OrientedActor actor, Defender job)
 {
     self         = actor;
     pathFinder   = self.pathFind;
     grid         = self.grid;
     CtF          = self.CtF;
     defenderself = job;
     SetRandGoal();
 }
Ejemplo n.º 8
0
 public EscortState(OrientedActor actor, Defender job, OrientedActor theenemy)
 {
     self           = actor;
     pathFinder     = self.pathFind;
     grid           = self.grid;
     CtF            = self.CtF;
     self.escorting = true;
     defenderself   = job;
     enemy          = theenemy;
 }
Ejemplo n.º 9
0
        OrientedActor CreatePlayer(bool iscyan, bool isdefender)
        {
            OrientedActor newPlayer = Instantiate <OrientedActor> (actorPrefab);

            newPlayer.CtF = this;
            if (iscyan)
            {
                cyanCount++;
                newPlayer.teamNum     = cyanCount;
                newPlayer.teamName    = "Cyan Player ";
                newPlayer.position    = CyanZone [Random.Range(0, CyanZone.Count - 1)].transform.position;
                newPlayer.currentNode = grid.PostoNode(newPlayer.position);
                newPlayer._Team       = OrientedActor.Team.cyan;

                if (isdefender)
                {
                    newPlayer.SetJob(1);
                    newPlayer.gameObject.name = "Cyan Defender";
                }
                else
                {
                    newPlayer.gameObject.name = "Cyan Attacker";
                    newPlayer.SetJob(2);
                }
            }
            else
            {
                mangCount++;
                newPlayer.teamNum     = mangCount;
                newPlayer.teamName    = "Mangetta Player ";
                newPlayer.position    = MangettaZone [Random.Range(0, CyanZone.Count - 1)].transform.position;
                newPlayer.currentNode = grid.PostoNode(newPlayer.position);
                newPlayer._Team       = OrientedActor.Team.mangetta;

                if (isdefender)
                {
                    newPlayer.gameObject.name = "Mangetta Defender";
                    newPlayer.SetJob(1);
                }
                else
                {
                    newPlayer.gameObject.name = "Mangetta Attacker";
                    newPlayer.SetJob(2);
                }
            }

            newPlayer.transform.SetParent(transform);
            newPlayer.gameObject.SetActive(true);
            playerCount++;
            return(newPlayer);
        }
Ejemplo n.º 10
0
        public void Captured(OrientedActor capturer)
        {
            currentState.ResetPathColor();

            currentState = new CapturedState(self, capturer);
        }
Ejemplo n.º 11
0
 public void FlagSave()
 {
     captured = false;
     capturer = null;
 }
Ejemplo n.º 12
0
 public static bool GetShortestPath(OrientedActor i_orientedActor, GridNode i_start, GridNode i_end, bool isDiagonal, out List<GridNode> o_path)
 {
     List<GridNode> open;
     return GetShortestPath(i_orientedActor, i_start, i_end, isDiagonal, out o_path, out open);
 }
Ejemplo n.º 13
0
 public JailedState(OrientedActor actor)
 {
     self = actor;
 }
Ejemplo n.º 14
0
        public static bool GetShortestPath(OrientedActor i_orientedActor, GridNode i_start, GridNode i_end, bool isDiagonal, out List<GridNode> o_path, out List<GridNode> o_open)
        {
            o_path = new List<GridNode>();
            o_open = new List<GridNode>();

            IDictionary<GridNode, GridNode> path = new Dictionary<GridNode, GridNode>();
            IDictionary<GridNode, float> open = new Dictionary<GridNode, float>();

            PriorityQueue<float, GridNode> priorityQueue = new PriorityQueue<float, GridNode>(30 * 30, Comparer<float>.Default);

            priorityQueue.Add(new KeyValuePair<float, GridNode>(GetDistance(i_start, i_end, isDiagonal), i_start));
            open.Add(new KeyValuePair<GridNode, float>(i_start, 0));

            bool succeed = false;
            while (!priorityQueue.IsEmpty)
            {
                KeyValuePair<float, GridNode> current = priorityQueue.Peek();
                GridNode currentNode = current.Value;
                float currentCost;
                if (!open.TryGetValue(currentNode, out currentCost))
                {
                    Debug.Assert(false);
                }

                if (currentNode == i_end)
                {
                    succeed = true;
                    break;
                }

                foreach (GridNode neighbour in currentNode.GetNeighbors(isDiagonal))
                {
                    if (EntityManager.GridPassable(neighbour, i_end, i_orientedActor))
                    {
                        float newCost = currentCost + GetCost(currentNode, neighbour, isDiagonal);
                        float oldCost;
                        if (!open.TryGetValue(neighbour, out oldCost))
                        {
                            path.Add(neighbour, currentNode);
                            open.Add(neighbour, newCost);
                            float dist = GetDistance(neighbour, i_end, isDiagonal);
                            priorityQueue.Add(new KeyValuePair<float, GridNode>(newCost + dist, neighbour));
                        }
                        else if (newCost < oldCost)
                        {
                            path[neighbour] = currentNode;
                            open[neighbour] = newCost;
                            float dist = GetDistance(neighbour, i_end, isDiagonal);
                            priorityQueue.Remove(new KeyValuePair<float, GridNode>(oldCost + dist, neighbour));
                            priorityQueue.Add(new KeyValuePair<float, GridNode>(newCost + dist, neighbour));
                        }
                    }
                }

                priorityQueue.Remove(current);
            }

            if (succeed)
            {

                GridNode currentNode = i_end;
                do
                {
                    o_path.Add(currentNode);
                    currentNode = path[currentNode];
                }
                while (path.ContainsKey(currentNode));
                o_path.Reverse();

            }

            o_open = open.Keys.ToList();

            return succeed;
        }
Ejemplo n.º 15
0
 public static bool GridPassable(GridNode i_gridnode, GridNode i_endNode, OrientedActor i_orientedActor)
 {
     if (i_gridnode.EntityType != EntityType.LockedDoor)
     {
         return TerrainTypeManager.GetPassable(i_gridnode.TerrainType);
     }
     else
     {
         int index = EntityColorIndex.GetIndex(i_gridnode.EntityColor);
         return (i_orientedActor.Keys[index] > 0 && i_gridnode == i_endNode);
     }
 }
Ejemplo n.º 16
0
 public SadState(OrientedActor actor)
 {
     self = actor;
 }
Ejemplo n.º 17
0
        public List <GridNode> FindPath(OrientedActor actor, GridNode goal)
        {
            //Debug.Log ("calculating");
            GridNode startNode = actor.currentNode;

            startNode.CostSoFar = 0;
            startNode.Heu       = heuristic(startNode, goal);
            Open.Clear();
            Closed.Clear();
            Open.Enqueue(0, startNode);
            List <GridNode> thePath = new List <GridNode> ();

            while (true)
            {
                GridNode currentNode = Open.DequeueValue();

                if (currentNode == goal)
                {
                    Closed.Clear();
                    while (Open.IsEmpty == false)
                    {
                        Open.DequeueValue();
                    }
                    GridNode fromnode = goal;
                    while (fromnode != startNode)
                    {
                        //fromnode.SetPathStatus (GridNode.PathStatus.isOnPath);
                        //fromnode.DrawPath (PFActor.DrawPath);
                        thePath.Add(fromnode);
                        fromnode = fromnode.prevNode;
                    }

                    //startNode.SetPathStatus (GridNode.PathStatus.isOnPath);

                    thePath.Add(startNode);
                    return(thePath);
                    //break;
                }

                Closed.Add(currentNode);
                //Debug.Log(PFActor.toDoor);
                foreach (GridNode nextNode in currentNode.Neighbors)
                {
                    if (nextNode._NodeStatus == GridNode.NodeStatus.blocked)
                    {
                        continue;
                    }

                    //nextNode.SetPathStatus (GridNode.PathStatus._checked);
                    //checkedNode.Add (nextNode);
                    int influence   = actor._Team == OrientedActor.Team.cyan ? nextNode.MangInfluence : nextNode.CyanInfluence;
                    int cost_so_far = heuristic(nextNode, currentNode) * (nextNode.Cost + influence) + currentNode.CostSoFar;
                    int heu         = heuristic(nextNode, goal);
                    if (nextNode.CostSoFar == 0 && nextNode != startNode)
                    {
                        nextNode.CostSoFar = cost_so_far;
                    }
                    if (nextNode.Heu == 0 && nextNode != startNode)
                    {
                        nextNode.Heu = heu;
                    }


                    if (inOpen(nextNode).Value != null && cost_so_far + heu < inOpen(nextNode).Key)
                    {
                        Open.Remove(inOpen(nextNode));
                        Open.Enqueue(cost_so_far + heu, nextNode);
                        nextNode.CostSoFar = cost_so_far;
                        nextNode.Heu       = heu;
                        nextNode.prevNode  = currentNode;
                    }


                    if (inOpen(nextNode).Value == null && !Closed.Contains(nextNode))
                    {
                        Open.Enqueue(cost_so_far + heu, nextNode);
                        nextNode.prevNode = currentNode;
                    }

                    //nextNode.SetText ((nextNode.CostSoFar + nextNode.Heu).ToString ());
                    //nextNode._text.gameObject.SetActive (true);
                    //if (nextNode != goal && nextNode != startNode) {
                    //}
                }
                if (Open.IsEmpty && currentNode != goal)
                {
                    List <GridNode> emptyList = new List <GridNode> ();
                    emptyList.Add(startNode);
                    return(emptyList);
                }
            }
        }
Ejemplo n.º 18
0
 public void FlagCapture(OrientedActor actor)
 {
     captured = true;
     capturer = actor;
 }