public virtual void UpdateState(GameTime time, HackGameBoard board, HackNodeGameBoardMedia drawing) { if (killTimer != null && killTimer.IsAlive()) { killTimer.Update(time); if (!killTimer.IsAlive()) { SetCurrentState(HackGameAgent_State.HackGameAgent_State_BeingKilled); } } if (justStaying == true) { justStaying = false; HackGameBoardElement element = board.GetElementAtPoint(currentBoardElementLocation); if (element.type == HackGameBoardElementBaseType.HackGameBoardElementBaseType_Node) { ((HackGameBoardElement_Node)(element)).OnAgentStay(this, board); } } if (justLeaving == true) { justLeaving = false; justStaying = false; HackGameBoardElement element = board.GetElementAtPoint(justLeavingNode); if (element.type == HackGameBoardElementBaseType.HackGameBoardElementBaseType_Node) { ((HackGameBoardElement_Node)(element)).OnAgentExit(this, board); } } if (justArrived == true) { justArrived = false; justStaying = true; HackGameBoardElement element = board.GetElementAtPoint(currentBoardElementDestination); if (element.type == HackGameBoardElementBaseType.HackGameBoardElementBaseType_Node) { ((HackGameBoardElement_Node)(element)).OnAgentEnter(this, board); } //kill self if on a lethal node if (element.IsLethal()) { Kill(0); } } //ui for (int i = 0; i < agentUISprites.Count; i++) { agentUISprites[i].UpdateState(time, board); if (!agentUISprites[i].Alive()) { agentUISprites.RemoveAt(i); } } //do not allow storedMovementDirection to "snap" north when an AI is at a destination MovementDirection currentMovementDirection = getMovementDirection(); if (currentMovementDirection != MovementDirection.MovementDirection_None) { storedMovementDirection = getMovementDirection(); } //update any trails if (trails != null && trails.Count > 1) { for (int i = trails.Count - 1; i > 0; i--) { trails[i].SetToOtherAgentData(trails[i - 1]); } } if (trails != null && trails.Count > 0) { if (this is HackGameAgent_Player) { trails[0].SetToPlayerData((HackGameAgent_Player)(this)); } else { trails[0].SetToOtherAgentData(this); } } }
private void UpdateActiveState(GameTime time, HackGameBoard board, HackNodeGameBoardMedia drawing) { switch (currentAIState) { case HackGameAgent_AI_State.HackGameAgent_AI_State_Wander: Wander_Update(time, board); break; } if (StartPing_Update) { //be sure we're in a node. if (board.InBoard(getCurrentBoardLocation()) && board.GetElementAtPoint(getCurrentBoardLocation()).type == HackGameBoardElementBaseType.HackGameBoardElementBaseType_Node) { //do some other stuff here. StartPing_Draw = true; StartPing_Update = false; } } }
public void SetRandomDestination(HackGameBoard board) { Point current = this.getCurrentBoardLocation(); Point dest = current; //get all "nodes" List<Point> allNodes = new List<Point>(); for (int i = 0; i < board.GetGameBoardSize(); i++) { for (int k = 0; k < board.GetGameBoardSize(); k++) { if (board.board[i, k].type == HackGameBoardElementBaseType.HackGameBoardElementBaseType_Node && board.board[i, k].GetCurrentState() == HackGameBoardElement.HackGameBoardElement_State.HackGameBoardElement_State_Active) { allNodes.Add(new Point(k, i)); } } } if (allNodes.Count > 0) { TryDestination(allNodes[board.r.Next(0, allNodes.Count)], board); if (nextBoardElementDestinations.Count > maxThinkAheadLength) { //shorten to maxThinkAheadLength List<Point> rev = new List<Point>(); while (nextBoardElementDestinations.Count > 0) { rev.Add(nextBoardElementDestinations.Pop()); } rev.Reverse(); rev.RemoveRange(0, rev.Count - maxThinkAheadLength); while (board.GetElementAtPoint(rev[0]).type != HackGameBoardElementBaseType.HackGameBoardElementBaseType_Node && rev.Count > 0) { rev.RemoveAt(0); } if (rev.Count <= 0) { // uh oh. we were too aggressive. //reset. TryDestination(allNodes[board.r.Next(0, allNodes.Count)], board); } else { foreach (Point p in rev) { nextBoardElementDestinations.Push(p); } } } } else { Kill(0); } }
private void AlignToTarget(HackGameAgent target, HackGameBoard ourBoard) { if (target == null || !target.IsActive()) { //WACKY MISSILE! target = null; SetRandomDestination(ourBoard); } else { //easy case - enemy is going to be at a node as his next immediate destination if (ourBoard.GetElementAtPoint(target.getDestinationBoardLocation()).type == HackGameBoardElementBaseType.HackGameBoardElementBaseType_Node) { TryDestination(target.getDestinationBoardLocation(), ourBoard); } //harder case - enemy is on a bridge somewhere, not immediately headed for a node else { //you need to find the target's next NODE it's going to hit. bool found = false; Stack<Point> nextDestinations = target.GetNextDestinations(); foreach (Point p in nextDestinations.Reverse()) { if (ourBoard.GetElementAtPoint(p).type == HackGameBoardElementBaseType.HackGameBoardElementBaseType_Node) { TryDestination(p, ourBoard); found = true; break; } } if (!found) { //WACKY MISSILE! target = null; SetRandomDestination(ourBoard); } } } }
private void UpdateActiveState(GameTime time, HackGameBoard board, HackNodeGameBoardMedia drawing) { if (StartPing_Update) { //be sure we're in a node. if (board.InBoard(getCurrentBoardLocation()) && board.GetElementAtPoint(getCurrentBoardLocation()).type == HackGameBoardElementBaseType.HackGameBoardElementBaseType_Node) { //do some other stuff here. board.AddBackgroundTextStandard(new StringBuilder("HACKNODE PING #0198"), 0); board.AddBackgroundTextStandard(new StringBuilder("HACKNODE OK"), 0.75f); StartPing_Draw = true; StartPing_Update = false; } } if (this.getMovementDirection() != MovementDirection.MovementDirection_None) { setTtoDestination(getTtoDestination() + movementSpeed * (float)time.ElapsedGameTime.TotalSeconds * board.GetSpeedUpFactor()); } else if (nextBoardElementDestinations.Count > 0) { setDestinationBoardLocation(nextBoardElementDestinations.Pop(), board); } if (isHacking) { drawing.binaryOneFountain_emitter.Update(time, lastDrawPos + new Vector2(41.0f, 41.0f)); drawing.binaryZeroFountain_emitter.Update(time, lastDrawPos + new Vector2(41.0f, 41.0f)); } }
public override bool TryDestination(Point node, HackGameBoard board) { if (!IsDestinationAllowed(node, board)) { return false; } //start with the simplest case. //the player isn't moving. - or the stack is empty. if ((currentBoardElementDestination == currentBoardElementLocation || (getTtoDestination() >= 1.0f || getTtoDestination() <= 0.0f))) { pf.Reset(this.currentBoardElementLocation, node); bool success = pf.SearchPath(); if (success == true) { //add the final path to the stack. LinkedList<Point> path = pf.FinalPath(); path.RemoveFirst(); foreach (Point p in path.Reverse()) { nextBoardElementDestinations.Push(p); } return true; } else { return false; } } else { if (node == getCurrentBoardLocation() || node == getDestinationBoardLocation()) { //you can't kill it off entirely, you have to clear it all the way back to the first valid node. if (board.board[getDestinationBoardLocation().Y, getDestinationBoardLocation().X].type == HackGameBoardElementBaseType.HackGameBoardElementBaseType_Node && board.board[getDestinationBoardLocation().Y, getDestinationBoardLocation().X].GetCurrentState() == HackGameBoardElement.HackGameBoardElement_State.HackGameBoardElement_State_Active) { nextBoardElementDestinations.Clear(); } else { foreach (Point p in nextBoardElementDestinations) { if (p != getCurrentBoardLocation() && p != getDestinationBoardLocation() && board.GetElementAtPoint(p).type == HackGameBoardElementBaseType.HackGameBoardElementBaseType_Node && board.GetElementAtPoint(p).GetCurrentState() == HackGameBoardElement.HackGameBoardElement_State.HackGameBoardElement_State_Active) { Stack<Point> leftToDestination = TryDestinationBase(getCurrentBoardLocation(), p, board); Stack<Point> fromDestination = TryDestinationBase(getDestinationBoardLocation(), node, board); List<Point> reverser = new List<Point>(); if (fromDestination.Count > 0) { nextBoardElementDestinations.Clear(); while (fromDestination.Count > 0) { reverser.Add(fromDestination.Pop()); } while (leftToDestination.Count > 0) { reverser.Add(leftToDestination.Pop()); } foreach (Point pp in reverser) { nextBoardElementDestinations.Push(pp); } return true; } else { return false; } } } } return true; } else { //we need to create a new path that starts with all bridges up to the next node if (board.board[getDestinationBoardLocation().Y, getDestinationBoardLocation().X].type == HackGameBoardElementBaseType.HackGameBoardElementBaseType_Node && board.board[getDestinationBoardLocation().Y, getDestinationBoardLocation().X].GetCurrentState() == HackGameBoardElement.HackGameBoardElement_State.HackGameBoardElement_State_Active) { Stack<Point> fromDestination = TryDestinationBase(getDestinationBoardLocation(), node, board); if (fromDestination.Count > 0) { nextBoardElementDestinations.Clear(); nextBoardElementDestinations = fromDestination; return true; } else { return false; } //return TryDestination(node, board); } else //our immediate destination is not a node. { //find the next destination that IS a node, put a path together that starts with the path to that node. /* List<Point> old_path = new List<Point>(); Point currentCheckP = nextBoardElementDestinations.Pop(); old_path.Add(getCurrentBoardLocation()); old_path.Add(getDestinationBoardLocation()); old_path.Add(currentCheckP); while (board.board[getDestinationBoardLocation().Y, getDestinationBoardLocation().X].type != HackGameBoardElementBaseType.HackGameBoardElementBaseType_Node && nextBoardElementDestinations.Count > 0) { currentCheckP = nextBoardElementDestinations.Pop(); old_path.Add(currentCheckP); } nextBoardElementDestinations.Clear(); TryDestination(node, board); old_path.Reverse(); old_path.AddRange(nextBoardElementDestinations.ToList()); old_path.Reverse(); nextBoardElementDestinations.Clear(); foreach (Point p in old_path) { nextBoardElementDestinations.Push(p); } */ foreach (Point p in nextBoardElementDestinations) { if (p != getCurrentBoardLocation() && p != getDestinationBoardLocation() && board.GetElementAtPoint(p).type == HackGameBoardElementBaseType.HackGameBoardElementBaseType_Node && board.GetElementAtPoint(p).GetCurrentState() == HackGameBoardElement.HackGameBoardElement_State.HackGameBoardElement_State_Active) { Stack<Point> fromDestination = TryDestinationBase(getDestinationBoardLocation(), node, board); if (fromDestination.Count > 0) { nextBoardElementDestinations.Clear(); nextBoardElementDestinations = fromDestination; return true; } else { return false; } } } return false; //return false; } } } /* else if (node == getCurrentBoardLocation() || node == getDestinationBoardLocation() || IsInDestinationPath(node)) { //the player is already moving. one of three cases //ELIMINATED - TRYING ALL-KILL//1. it's the player's location or destination - kill path //ELIMINATED - TRYING ALL-KILL//2. it's a node already on the path - shorten path //ELIMINATED - TRYING ALL-KILL//3. it's a node outside the path - lengthen path if (node == getCurrentBoardLocation() || node == getDestinationBoardLocation()) { //you can't kill it off entirely, you have to clear it all the way back to the first valid node. if (board.board[getDestinationBoardLocation().Y, getDestinationBoardLocation().X].type == HackGameBoardElementBaseType.HackGameBoardElementBaseType_Node) { nextBoardElementDestinations.Clear(); } else { foreach (Point p in nextBoardElementDestinations) { if (p != getCurrentBoardLocation() && p != getDestinationBoardLocation() && board.GetElementAtPoint(p).type == HackGameBoardElementBaseType.HackGameBoardElementBaseType_Node) { //hah, recursion. nextBoardElementDestinations.Clear(); return TryDestination(p, board); } } } return true; } else if (IsInDestinationPath(node)) { foreach (Point p in nextBoardElementDestinations) { if (p == node) { //hah, recursion. nextBoardElementDestinations.Clear(); return TryDestination(p, board); } } } return false; } else // it's lengthening the path { if (nextBoardElementDestinations.Count > 0) { //find the last node in the stack pf.Reset(nextBoardElementDestinations.ElementAt(nextBoardElementDestinations.Count - 1), node); bool success = pf.SearchPath(); if (success == true) { //add the final path to the END OF THE stack. //1 turn stack into old list //2 clear stack //3 push new reverse list onto stack //4 push old list onto stack LinkedList<Point> new_path = pf.FinalPath(); new_path.RemoveFirst(); List<Point> old_path = nextBoardElementDestinations.ToList(); nextBoardElementDestinations.Clear(); foreach (Point p in new_path.Reverse()) { nextBoardElementDestinations.Push(p); } old_path.Reverse(); foreach (Point p in old_path) { nextBoardElementDestinations.Push(p); } return true; } } return false; } */ }
private void UpdateActiveState(GameTime time, HackGameBoard board, HackNodeGameBoardMedia drawing) { if (activeFlasher != null) { activeFlasher.Update(time); } if (collapseTimer != null) { collapseTimer.Update(time); if (collapseTimer.IsAlive() == false) { board.GetElementAtPoint(getCurrentBoardLocation()).Kill(0); List<HackGameBoardElement> nearby = new List<HackGameBoardElement>(); HackGameBoardElement west = board.getElementInDirection(getCurrentBoardLocation(), MovementDirection.MovementDirection_West); if (west != null) { nearby.Add(west); } HackGameBoardElement east = board.getElementInDirection(getCurrentBoardLocation(), MovementDirection.MovementDirection_East); if (east != null) { nearby.Add(east); } HackGameBoardElement north = board.getElementInDirection(getCurrentBoardLocation(), MovementDirection.MovementDirection_North); if (north != null) { nearby.Add(north); } HackGameBoardElement south = board.getElementInDirection(getCurrentBoardLocation(), MovementDirection.MovementDirection_South); if (south != null) { nearby.Add(south); } foreach (HackGameBoardElement el in nearby) { if (el.type == HackGameBoardElementBaseType.HackGameBoardElementBaseType_Bridge_NS || el.type == HackGameBoardElementBaseType.HackGameBoardElementBaseType_Bridge_EW) { el.Kill(2.0f); //slight delay } } //and - kill self. Kill(0); } UpdateTimerString(); } }