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(); } }
public RescueState(OrientedActor actor, OrientedActor teammate) { self = actor; pathFinder = self.pathFind; grid = self.grid; teamMate = teammate; }
public Rescuer(OrientedActor actor, OrientedActor teammate) { self = actor; teamMate = teammate; rescueState = new RescueState(self, teamMate); currentState = rescueState; currentState.Enter(); }
public ConvoyState(OrientedActor actor, OrientedActor teammate) { self = actor; pathFinder = self.pathFind; grid = self.grid; CtF = self.CtF; teamMate = teammate; }
public Flagger(OrientedActor actor) { self = actor; attackState = new AttackState(self, this); returnState = new ReturnState(self, this); currentState = attackState; attackState.Enter(); }
public PursueState(OrientedActor actor, Defender job, OrientedActor theenemy) { self = actor; enemy = theenemy; pathFinder = self.pathFind; grid = self.grid; CtF = self.CtF; defenderself = job; }
public PatrolState(OrientedActor actor, Defender job) { self = actor; pathFinder = self.pathFind; grid = self.grid; CtF = self.CtF; defenderself = job; SetRandGoal(); }
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; }
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); }
public void Captured(OrientedActor capturer) { currentState.ResetPathColor(); currentState = new CapturedState(self, capturer); }
public void FlagSave() { captured = false; capturer = null; }
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); }
public JailedState(OrientedActor actor) { self = actor; }
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; }
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); } }
public SadState(OrientedActor actor) { self = actor; }
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); } } }
public void FlagCapture(OrientedActor actor) { captured = true; capturer = actor; }