public void ResetCache(CombatGameState combat) { MapMetaData mapMetaData = combat.MapMetaData; HexGrid hexGrid = combat.HexGrid; CacheNodeLink.PathBlockerGradeMultiplier = combat.Constants.MoveConstants.PathBlockerGradeMultiplier; this.SetDimensions(mapMetaData, hexGrid); this.cacheNodes = new CacheNode[this.Width, this.Height]; for (int x = 0; x < this.Width; x++) { for (int z = 0; z < this.Height; z++) { Vector3 pos = this.WorldPosFromNode(x, z); this.cacheNodes[x, z] = new CacheNode(pos, mapMetaData); } } for (int x = 0; x < this.Width; x++) { for (int z = 0; z < this.Height; z++) { CacheNode from = this.cacheNodes[x, z]; for (int k = 0; k < 8; k++) { Point diff = PathingUtil.GetForwardDelta(k); CacheNode to = this.GetNodeAt(x + diff.X, z + diff.Z); if (to != null) { from.NeighborLinks[k] = new CacheNodeLink(from, to, this.DistFromAngle(k), k, mapMetaData); } } } } }
public CacheNodeLink(CacheNode from, CacheNode to, float distance, int angle, MapMetaData mapMetaData) { this.From = from; this.To = to; this.Reciprocal = to.NeighborLinks[(angle + 4) % 8]; if (this.Reciprocal != null) { this.Reciprocal.Reciprocal = this; } this.PathCells = new List <MapTerrainDataCell>(); this.TargetDistCells = new List <DistCell[]>(); List <Point> indexLine = BresenhamLineUtil.BresenhamLine(from.CellIndex, to.CellIndex); for (int i = 0; i < indexLine.Count - 1; i++) { // Targets are indexLine[i + 1] and the cells in the adjacent cardinal directions DistCell[] targets = new DistCell[3]; Point current = indexLine[i]; int xDiff = indexLine[i + 1].X - current.X; int zDiff = indexLine[i + 1].Z - current.Z; if (xDiff >= 0) { targets[0] = new DistCell(cellDelta, mapMetaData.GetCellAt(current.X + 1, current.Z)); } else { targets[0] = new DistCell(cellDelta, mapMetaData.GetCellAt(current.X - 1, current.Z)); } if (zDiff >= 0) { targets[1] = new DistCell(cellDelta, mapMetaData.GetCellAt(current.X, current.Z + 1)); } else { targets[1] = new DistCell(cellDelta, mapMetaData.GetCellAt(current.X, current.Z - 1)); } if (xDiff == 0) { targets[2] = new DistCell(cellDelta, mapMetaData.GetCellAt(current.X - 1, current.Z)); } else if (zDiff == 0) { targets[2] = new DistCell(cellDelta, mapMetaData.GetCellAt(current.X, current.Z - 1)); } else { // this should be impossible with the modified bresenham they're using targets[2] = new DistCell(cellDeltaDiag, mapMetaData.GetCellAt(indexLine[i])); } this.PathCells.Add(mapMetaData.GetCellAt(current)); this.TargetDistCells.Add(targets); } this.Distance = distance; this.UpdateGrade(); this.UpdateMaxGrade(); }