public void replaceTile(Tile new_tile, int new_distance, int new_cost, List<Tile> new_path) { if (!containsTile(new_tile)) { selection_grid[new_tile] = new Selection_Data(new_distance, new_cost, new_path); } }
public void addTile(Tile new_tile, int new_distance, int new_cost, List<Tile> new_path) { if (!containsTile(new_tile)) { selection_grid.Add(new_tile, new Selection_Data(new_distance, new_cost, new_path)); } }
public void addTile(Tile newTile) { tile_selection_list.Add(newTile); if (newTile.occupant != null) { unit_selection_list.Add(newTile.occupant); } }
//Returns 0 if new cost = old cost, 1 if new cost is larger, -1 if new cost is smaller or doesn't exist public int comparePath(Tile new_tile, int new_cost) { Selection_Data selection_data; if (selection_grid.TryGetValue(new_tile, out selection_data)) { if (selection_data.travel_cost > new_cost) { return -1; } else if (selection_data.travel_cost == new_cost) { return 0; } else { return 1; } } return -1; }
//TODO: What is a 'neighbour'? Figure out the cases the satisfy the condition of 'neighbour' and implement accordingly //There's a case for tiles to be adjacent to each other but completely unreachable to each other //Just because of height differences, possible walls, etc. //TODO: Consider placing this method inside Tile and storing neighour data there //THIS IS HIGH PRIORITY //NOTE: For now, this assumes that there is no height difference between tiles public Tile[] getNeighbours(Tile inputTile) { List<Tile> output = new List<Tile>(); if (inputTile.location_x + 1 >= size_x) { output.Add(returnTile(inputTile.location_x + 1, inputTile.location_y, inputTile.location_z)); } if (inputTile.location_x - 1 < 0) { output.Add(returnTile(inputTile.location_x - 1, inputTile.location_y, inputTile.location_z)); } if (inputTile.location_z + 1 >= size_z) { output.Add(returnTile(inputTile.location_x, inputTile.location_y, inputTile.location_z + 1)); } if (inputTile.location_x - 1 < 0) { output.Add(returnTile(inputTile.location_x, inputTile.location_y, inputTile.location_z - 1)); } return output.ToArray(); }
public bool containsTile(Tile input) { return selection_grid.ContainsKey(input); }
public static Map loadMap(String inputFile) { Map output = null; int x = 0; int y = 0; int z = 0; Tile[][][] tile_map = null; int tileCounter = 0; //replaces tile_map, tile_count using (StreamReader reader = new StreamReader(inputFile)) { int current_y = -1; int current_z = -1; int current_x = 0; string currentLine; Console.WriteLine("Starting parse.."); while ((currentLine = reader.ReadLine()) != null) { //Parsing map size here if (currentLine.StartsWith("size_x:")) { int.TryParse(currentLine.Substring(7), out x); Console.WriteLine("Size x:{0}", x); } if (currentLine.StartsWith("size_y:")) { int.TryParse(currentLine.Substring(7), out y); Console.WriteLine("Size y:{0}", y); } if (currentLine.StartsWith("size_z:")) { int.TryParse(currentLine.Substring(7), out z); Console.WriteLine("Size z:{0}", z); } //Parsing levels here //Only start if map is created if (tile_map != null) { if (current_y > -1 && current_z < z) { string[] tempArray = currentLine.Split(' '); current_x = 0; foreach (string tile in tempArray) { Tile newTile = null; switch (tile[0]) { case 'G': newTile = new Tile(current_x, current_y, current_z); newTile.terrain = Terrain.GRASSLAND; break; case 'P': newTile = new Tile(current_x, current_y, current_z); newTile.terrain = Terrain.PLAIN; break; case 'W': newTile = new Tile(current_x, current_y, current_z); newTile.terrain = Terrain.WETLAND; break; default: break; } tile_map[current_y][current_z][current_x] = newTile; if (newTile != null) { //Assigning a tile_id to newTile tile_map[current_y][current_z][current_x].tile_id = tile_id_generator; tile_id_generator++; tileCounter++; } current_x++; } current_z++; } if (currentLine.StartsWith("level:")) { Console.WriteLine("Parsing level"); int.TryParse(currentLine.Substring(6), out current_y); current_z = 0; } if (currentLine.StartsWith("endlevel")) { Console.WriteLine("End of level parse"); current_y = -1; current_z = -1; } } //Create map container if (x > 0 && y > 0 && z > 0 && tile_map == null) { Console.WriteLine("Creating container"); tile_map = new Tile[y][][]; int i, j; for (i = 0; i < y; i++) { tile_map[i] = new Tile[z][]; for (j = 0; j < z; j++) { tile_map[i][j] = new Tile[x]; } } } } if (tileCounter > 0) { Console.WriteLine("Filling in map data"); output = new Map(); output.tile_map = tile_map; output.size_x = x; output.size_y = y; output.size_z = z; output.tile_count = tileCounter; } } return output; }