/// <summary> /// sumarize map around the position in range /// </summary> /// <param name="position">center position</param> /// <param name="range">range of cells around position</param> /// <returns>2D array of MapCellInfo around given position</returns> public MapCellInfo[,] getRelatedMap(System.Drawing.Point position, int range) { position.X -= range / 2; position.Y -= range / 2; if (position.X <= 0) { position.X = 0; } if (position.Y <= 0) { position.Y = 0; } MapCellInfo[,] newMap = new MapCellInfo[range, range]; if (range + position.X >= heightMap.GetLength(0)) { range = heightMap.GetLength(0) - (int)position.X; } if (range + position.Y >= heightMap.GetLength(1)) { range = heightMap.GetLength(0) - (int)position.Y; } for (int i = (int)position.X; i < position.X + range; i++) { for (int j = (int)position.Y; j < position.Y + range; j++) { newMap[i - (int)position.X, j - (int)position.Y] = this.cellMap[i, j]; } } return(newMap); }
/// <summary> /// private ctor - singleton /// </summary> /// <param name="terrain"></param> private Map(IWalkable terrain) { if (terrain == null) { return; } this.terrain = terrain; this.heightMap = terrain.GetMap(); cellMap = new MapCellInfo[heightMap.GetLength(0), heightMap.GetLength(1)]; size = new System.Drawing.Point(this.heightMap.GetLength(0), this.heightMap.GetLength(1)); this.playerPosition = terrain.GetPlayerPosition(); npcsPosition = new List <Point>(); List <Point> blocked = terrain.GetBlockedPositions(); Logging.Logger.AddInfo("Teren ma " + blocked.Count.ToString() + " blokovanych pozic"); int x, y; x = cellMap.GetLength(0); y = cellMap.GetLength(1); for (int i = 0; i < x; i++) { for (int j = 0; j < y; j++) { bool bPlayer = (terrain.GetPlayerPosition() == new System.Drawing.Point(i, j)); bool bFriendlyNPC = false; bool bBlocked = false; //(terrain.GetBlockedPositions()[i] == new System.Drawing.Point(i, j)); foreach (System.Drawing.Point p in blocked) { if (p == new System.Drawing.Point(i, j)) { bBlocked = true; blocked.Remove(p); break; } } if (heightMap[i, j] > this.maxHeight) { this.maxHeight = heightMap[i, j]; } cellMap[i, j] = new MapCellInfo(heightMap[i, j], bPlayer, bFriendlyNPC, false, bBlocked, new System.Drawing.Point(i, j)); } } bmp = new Bitmap(this.MapSize.X, this.MapSize.Y); Logging.Logger.AddInfo("AI: Nactena mapa"); }