public void AfterTurnReset() { defending = false; wrapped = false; foreach (CharacterStats bleedTick in bleedCausers) { DamageCharacter(4, DamageTypes.Bleed, 0, bleedTick); } basics.bonus = basics.nextBonus; basics.nextBonus = 0; movementActions = 2; basics.fullPath = false; basics.keyPoints.Clear(); basics.shortPath.Clear(); basics.plannedPath.Clear(); basics.CheckPath(); }
public void ShotClear() { // Destroy path int n = basics.plannedPath.Count - 1; if (basics.keyPoints.Count > 2) { while (basics.plannedPath[n] != basics.keyPoints[basics.keyPoints.Count - 2]) { basics.plannedPath.Remove(basics.plannedPath[n]); n--; } basics.keyPoints.Remove(basics.keyPoints[basics.keyPoints.Count - 1]); } else { basics.plannedPath = null; basics.keyPoints.Clear(); } basics.CheckPath(); Debug.Log("ShotClr"); }
public void GeneratePathTo(int x, int y, int z) { if (gm.playResults) { return; } Node source = null; List <Node> path = new List <Node>(); UnitBasics unit = selectedUnit.GetComponent <UnitBasics>(); if (unit.plannedPath == null) { source = graph[ unit.tileX, unit.tileY, unit.tileZ ]; } else if (unit.plannedPath.Count <= 1) { source = graph[ unit.tileX, unit.tileY, unit.tileZ ]; unit.plannedPath = new List <Node>(); } else { source = unit.plannedPath[unit.plannedPath.Count - 1]; } Dictionary <Node, float> dist = new Dictionary <Node, float>(); Dictionary <Node, Node> prev = new Dictionary <Node, Node>(); // Setup the "Q" -- the list of nodes we haven't checked yet. List <Node> unvisited = new List <Node>(); Node target = graph[x, y, z]; if (selectedUnit.GetComponent <UnitBasics>() != null) { if (selectedUnit.GetComponent <UnitBasics>().keyPoints.Count == 0) { selectedUnit.GetComponent <UnitBasics>().keyPoints.Add(source); } if (!selectedUnit.GetComponent <UnitBasics>().fullPath) { selectedUnit.GetComponent <UnitBasics>().keyPoints.Add(target); } } dist[source] = 0; prev[source] = null; // Initialize everything to have INFINITY distance, since // we don't know any better right now. Also, it's possible // that some nodes CAN'T be reached from the source, // which would make INFINITY a reasonable value foreach (Node v in graph) { if (v != source) { dist[v] = Mathf.Infinity; prev[v] = null; } unvisited.Add(v); } while (unvisited.Count > 0) { // "nxt" is going to be the unvisited node with the smallest distance. Node nxt = null; foreach (Node potentialNext in unvisited) { if (nxt == null || dist[potentialNext] < dist[nxt]) { nxt = potentialNext; } } if (nxt == target) { break; // Exit the while loop! } unvisited.Remove(nxt); foreach (Node neighbor in nxt.neighbors) { float alt = dist[nxt] + nxt.DistanceTo(neighbor) + CostToEnter(neighbor.x, neighbor.y, neighbor.z, nxt.x, nxt.y, nxt.z); if (alt < dist[neighbor]) { dist[neighbor] = alt; prev[neighbor] = nxt; } } } // If we get there, the either we found the shortest route // to our target, or there is no route at ALL to our target. if (prev[target] == null) { // No route between our target and the source return; } Node currentStep = target; // Step through the "prev" chain and add it to our path while (currentStep != null) { path.Add(currentStep); currentStep = prev[currentStep]; } // Right now, currentPath describes a route from out target to our source // So we need to invert it! path.Add(graph[unit.tileX, unit.tileY, unit.tileZ]); path.Reverse(); if (unit.plannedPath == null) { unit.plannedPath = path; } else { for (int n = 1; n < path.Count; n++) { unit.plannedPath.Add(path[n]); } } unit.CheckPath(); }