public TileData(int x, int y, string name, Types type, int resourceQuantity, int moveCost, float _hp, float _defence, float _attk, float _shield, int nCost) { tileName = name; posX = x; posY = y; tileType = type; maxResourceQuantity = resourceQuantity; movementCost = moveCost; // MAKING ROCK UNWAKABLE if (type != Types.empty && type != Types.water) { isWalkable = false; } tileStats = new TileStats(_hp, _defence, _attk, _shield, nCost); //hp = _hp; //def = _defence; //attk = _attk; //shield = _shield; //nanoBotCost = nCost; }
public Blueprint_Battle(int ammo, float reload_time, float rate, float damage, float hp, float attk, float defense, float shield) { battleStats = new TowerGunStats(ammo, reload_time); unitStats = new UnitStats(); unitStats.InitStartingStats(hp, defense, attk, shield, rate, damage, 0); unitStats.Init(); tileStats = new TileStats(hp, defense, attk, shield, nanoBotCost); }
private List <GameObject> GetConnectedTiles(TileStats tile) { List <GameObject> tiles = new List <GameObject>(); tiles.Add(tile.gameObject); if (tile.GetRightTile() != null) { return(tiles.Concat(GetConnectedTiles(tile.GetRightTile().GetComponent <TileStats>())).ToList()); } else { return(tiles); } }
private List <int> GetInstructions(TileStats stats) { List <int> instructions = new List <int>(); instructions.Add(stats.InstructionID); if (stats.GetRightTile() != null) { return(instructions.Concat(GetInstructions(stats.GetRightTile().GetComponent <TileStats>())).ToList()); } else { return(instructions); } }
/*static public TileStats[,] GenerateBaseMap(int width, int height, Tilemap ground, TileBase sprite) * { * var map = new TileStats[width, height]; * * for(int i = 0; i < width; i++) * { * for(int t = 0; t < height; t++) * { * Vector3Int position = new Vector3Int(i, t, 0); * map[i, t] = new TileStats(ground, position, sprite, i, t); * } * } * return map; * }*/ static public TileStats[,] GenerateBaseMap(int width, int height, Tilemap ground, TileTemplate template) { var map = new TileStats[width, height]; for (int i = 0; i < width; i++) { for (int t = 0; t < height; t++) { Vector3Int position = new Vector3Int(i, t, 0); map[i, t] = new TileStats(ground, position, template, i, t); } } return(map); }
public Locator MatchingLoc(TileStats tilestat, MapHelper.LocatorDirection dir) { List <Locator> match = new List <Locator>(); foreach (Locator loc in tilestat.locators) { switch (dir) { case MapHelper.LocatorDirection.North: if (loc.dir == MapHelper.LocatorDirection.South) { match.Add(loc); break; } break; case MapHelper.LocatorDirection.East: if (loc.dir == MapHelper.LocatorDirection.West) { match.Add(loc); break; } break; case MapHelper.LocatorDirection.South: if (loc.dir == MapHelper.LocatorDirection.North) { match.Add(loc); break; } break; case MapHelper.LocatorDirection.West: if (loc.dir == MapHelper.LocatorDirection.East) { match.Add(loc); break; } break; } } Locator[] matchArray = match.ToArray(); return(matchArray[UnityEngine.Random.Range(0, matchArray.Length)]); }
void FindPath(Vector3 startpos, Vector3 targetpos) { TileStats startNode = grid.NodeFromWorldPoint(startpos); TileStats targetNode = grid.NodeFromWorldPoint(targetpos); List <TileStats> openSet = new List <TileStats>(); HashSet <TileStats> closedSet = new HashSet <TileStats>(); openSet.Add(startNode); while (openSet.Count > 0) { TileStats currentNode = openSet[0]; for (int i = 1; i < openSet.Count; i++) { if (openSet[i].fCost < currentNode.fCost || openSet[i].fCost == currentNode.fCost && openSet[i].hCost < currentNode.hCost) { currentNode = openSet[i]; } } openSet.Remove(currentNode); closedSet.Add(currentNode); if (currentNode == targetNode) { return; } foreach (TileStats neighbour in grid.GetNeighbors(currentNode)) { if (!neighbour.walkable || closedSet.Contains(neighbour)) { continue; } int newMovementCostToNeighbour = currentNode.gCost + GetDistance(currentNode, neighbour); if (newMovementCostToNeighbour < neighbour.gCost || !openSet.Contains(neighbour)) { neighbour.gCost = newMovementCostToNeighbour; neighbour.hCost = GetDistance(neighbour, targetNode); neighbour.parent = currentNode; if (!openSet.Contains(neighbour)) { openSet.Add(neighbour); } } } } }
void CreateGrid() { grid = new TileStats[gridSizeX, gridSizeY]; Vector3 worldBottomLeft = transform.position - Vector3.right * gridWorldSize.x / 2 - Vector3.forward * gridWorldSize.y / 2; for (int x = 0; x < gridSizeX; x++) { for (int y = 0; y < gridSizeY; y++) { Vector3 worldPoint = worldBottomLeft + Vector3.right * (x * nodeDiameter + nodeRadius) + Vector3.forward * (y * nodeDiameter + nodeRadius); bool walkable = !(Physics2D.OverlapCircle(worldPoint, nodeRadius, unwalkableMask)); Vector3Int wp = new Vector3Int(Mathf.FloorToInt(worldPoint.x), Mathf.FloorToInt(worldPoint.y), Mathf.FloorToInt(worldPoint.z)); grid[x, y] = new TileStats(walkable, wp, x, y); } } }
private string[] GetSubTypeValues(SerializedProperty layerProperty, string visualizerLayer, VectorSourceType sourceType) { string[] typesArray = null; string roadLayer = layerProperty.FindPropertyRelative("roadLayer").stringValue; string landuseLayer = layerProperty.FindPropertyRelative("landuseLayer").stringValue; if (visualizerLayer == roadLayer || visualizerLayer == landuseLayer) { _streetsV7TileStats = TileStatsFetcher.Instance.GetTileStats(sourceType); if (_streetsV7TileStats != null && _streetsV7TileStats.layers != null && _streetsV7TileStats.layers.Length != 0) { foreach (var layer in _streetsV7TileStats.layers) { if (layer.layer != visualizerLayer) { continue; } string presetPropertyName = ""; if (layer.layer == roadLayer) { presetPropertyName = layerProperty.FindPropertyRelative("roadLayer_TypeProperty").stringValue; } else if (layer.layer == landuseLayer) { presetPropertyName = layerProperty.FindPropertyRelative("landuseLayer_TypeProperty").stringValue; } if (layer.attributes != null && layer.attributes.Length > 0) { foreach (var attributeItem in layer.attributes) { if (attributeItem.attribute == presetPropertyName) { typesArray = attributeItem.values; } } } } } } return(typesArray); }
public TileData(int x, int y, Types type, int resourceQuantity, int moveCost, int _hardness = 0) { posX = x; posY = y; tileType = type; maxResourceQuantity = resourceQuantity; hardness = _hardness; movementCost = moveCost; // MAKING ROCK UNWAKABLE if (type != Types.empty && type != Types.water) { isWalkable = false; } tileName = type.ToString (); tileStats = new TileStats(); }
public List <(TileStats, int)> breadth_first_search(int range) { TileStats space = getSpace(); Queue <(TileStats, int)> need_to_visit = new Queue <(TileStats, int)>(); List <(TileStats, int)> can_reach = new List <(TileStats, int)>(); need_to_visit.Enqueue((space, 0)); space.selectable = true; while (need_to_visit.Count > 0) { (TileStats, int)temp = need_to_visit.Dequeue(); TileStats current_space = temp.Item1; int current_cost = temp.Item2; //var up = new Vector3(current_space.Location.x , current_space.Location.y + 1, 0); breadth_add_to_queue(need_to_visit, (current_space.m_x, current_space.m_y + 1), current_cost + 1, range); //var left = new Vector3(current_space.Location.x - 1, current_space.Location.y, 0); breadth_add_to_queue(need_to_visit, (current_space.m_x - 1, current_space.m_y), current_cost + 1, range); //var right = new Vector3(current_space.Location.x + 1, current_space.Location.y, 0); breadth_add_to_queue(need_to_visit, (current_space.m_x + 1, current_space.m_y), current_cost + 1, range); //var down = new Vector3(current_space.Location.x, current_space.Location.y - 1, 0); breadth_add_to_queue(need_to_visit, (current_space.m_x, current_space.m_y - 1), current_cost + 1, range); if (current_cost <= range) { can_reach.Add((current_space, current_cost)); //current_space.TilemapMember.SetTileFlags(current_space.Location, TileFlags.None); //current_space.TilemapMember.SetColor(current_space.Location, Color.green); } } return(can_reach); }
void Start() { //Temp map generation FileStream stream = new FileStream("Assets/Resources/TileData/Test.XML", FileMode.Open); XmlSerializer serializer = new XmlSerializer(typeof(List <TileTemplate>)); List <TileTemplate> tiles = (List <TileTemplate>)serializer.Deserialize(stream); map = TileStats.GenerateBaseMap(mapWidth, mapHeight, Ground, tiles[0]); //Place Creatures on the map player.PlayerBoot(); enemy.PlayerBoot(); //Temp Action Generation actionList = new List <Action>(); actionList.Add(new Action("Attack", AttackAction)); actionList.Add(new Action("Move", MoveAction)); buttons = new List <GameObject>(); //Debug.Log(actionList); generateActions(); }
public void selectSpace(int x, int y) { //Create the Tile Display Object GameObject template = Resources.Load <GameObject>("Buttons/TileDisplay"); GameObject tile_display = Instantiate(template, canvas.transform); //Get the tile we are selecting TileStats tile = map[x, y]; //Remove Selector Destroy(selecter.gameObject); selecter = null; //add image to tile display Image display = tile_display.transform.Find("Sprite Display").GetComponent <Image>(); display.sprite = tile.GetSprite(); //Add Options for Tiles tile_options = tile_display.transform.Find("Tile Dropdown").GetComponent <Dropdown>(); //Add functionality to button Button submit = tile_display.transform.Find("Select Tile").GetComponent <Button>(); submit.onClick.AddListener(delegate { ActivateTile(); }); //Find a different place for this, seems like we should have this loaded already FileStream stream = new FileStream("Assets/Resources/TileData/Test.XML", FileMode.Open); XmlSerializer serializer = new XmlSerializer(typeof(List <TileTemplate>)); List <TileTemplate> tile_temps = (List <TileTemplate>)serializer.Deserialize(stream); foreach (TileTemplate tile_temp in tile_temps) { Dropdown.OptionData option = new Dropdown.OptionData(tile_temp.id); tile_options.options.Add(option); } }
private Button SpaceButton(TileStats tile) { // Create Button Object var buttonObject = new GameObject(); buttonObject.transform.parent = screen.transform; buttonObject.name = "Button"; //Adding the image to the button. var image = buttonObject.AddComponent <Image>(); image.sprite = MoveSquare; //creating the button functionality var button = buttonObject.AddComponent <Button>(); //Create position and size component var rectTransform = button.GetComponent <RectTransform>(); rectTransform.pivot = new Vector2(); //Calculate size var size = screen.renderingDisplaySize.y / 20; rectTransform.sizeDelta = new Vector2(size, size); //calculate position var postionOnScreen = Camera.main.WorldToViewportPoint(tile.Location); var positionInPixels = postionOnScreen * screen.renderingDisplaySize; var Offset = screen.renderingDisplaySize / 2; rectTransform.localPosition = positionInPixels - Offset; buttons.Add(buttonObject); return(button); }
private void SuccessCheck(TileModel tileModel) { TileStats tileStats = tileModel.Stats; SquadStats selectedSquadStats = _gameState.Game.SelectedSquadStats; tileModel.Success = true; if (tileStats.Combat.Value > selectedSquadStats.Combat.Value) { tileModel.Success = false; } else if (tileStats.Stealth.Value > selectedSquadStats.Stealth.Value) { tileModel.Success = false; } else if (tileStats.Cunning.Value > selectedSquadStats.Cunning.Value) { tileModel.Success = false; } else if (tileStats.Diplomacy.Value > selectedSquadStats.Diplomacy.Value) { tileModel.Success = false; } }
public List <TileStats> GetNeighbors(TileStats node) { List <TileStats> neighbours = new List <TileStats>(); for (int x = -1; x <= 1; x++) { for (int y = -1; y <= 1; y++) { if (x == 0 && y == 0) { continue; } int checkX = node.gridX + x; int checkY = node.gridY + y; if (checkX >= 0 && checkX < gridSizeX && checkY >= 0 && checkY < gridSizeY) { neighbours.Add(grid[checkX, checkY]); } } } return(neighbours); }
public List <TileStats> getBorderingTiles(int x, int y, int width, int height) { List <TileStats> borderList = new List <TileStats>(); nodegrid = new GameObject[gridboundX + 1, gridboundY + 1]; foreach (GameObject g in allnodes) { //turns nodes into a list TileStats TS = g.GetComponent <TileStats>(); Debug.Log(TS.gridX + " " + TS.gridY); nodegrid[TS.gridX, TS.gridY] = g; } if (x > 0 && x < width - 1) // left and right { if (y > 0 && y < height - 1) // top and bottom { //Go through each neighboring node and add it to a borderlist if (nodegrid[x + 1, y] != null) { TileStats TS1 = nodegrid[x + 1, y].GetComponent <TileStats>(); if (TS1 != null) { borderList.Add(TS1); } } if (nodegrid[x - 1, y] != null) { TileStats TS2 = nodegrid[x - 1, y].GetComponent <TileStats>(); if (TS2 != null) { borderList.Add(TS2); } } if (nodegrid[x, y + 1] != null) { TileStats TS3 = nodegrid[x, y + 1].GetComponent <TileStats>(); if (TS3 != null) { borderList.Add(TS3); } } if (nodegrid[x, y - 1] != null) { TileStats TS4 = nodegrid[x, y - 1].GetComponent <TileStats>(); if (TS4 != null) { borderList.Add(TS4); } } else if (y == 0) { if (nodegrid [x + 1, y] != null) { TileStats TS1 = nodegrid[x + 1, y].GetComponent <TileStats>(); if (TS1 != null) { borderList.Add(TS1); } } if (nodegrid[x - 1, y] != null) { TileStats TS2 = nodegrid[x - 1, y].GetComponent <TileStats>(); if (TS2 != null) { borderList.Add(TS2); } } if (nodegrid[x, y + 1] != null) { TileStats TS3 = nodegrid[x, y + 1].GetComponent <TileStats>(); if (TS3 != null) { borderList.Add(TS3); } } if (nodegrid[x, y - 1] != null) { TileStats TS4 = nodegrid[x, y - 1].GetComponent <TileStats>(); if (TS4 != null) { borderList.Add(TS4); } } } else if (y == height - 1) { if (nodegrid[x, y - 1] != null) { TileStats TS4 = nodegrid[x, y - 1].GetComponent <TileStats>(); if (TS4 != null) { borderList.Add(TS4); } } if (nodegrid[x + 1, y] != null) { TileStats TS1 = nodegrid[x + 1, y].GetComponent <TileStats>(); if (TS1 != null) { borderList.Add(TS1); } } if (nodegrid[x - 1, y] != null) { TileStats TS2 = nodegrid[x - 1, y].GetComponent <TileStats>(); if (TS2 != null) { borderList.Add(TS2); } } } } else if (x == 0) { if (y > 0 && y < height - 1) { if (nodegrid[x + 1, y] != null) { TileStats TS1 = nodegrid[x + 1, y].GetComponent <TileStats>(); if (TS1 != null) { borderList.Add(TS1); } } if (nodegrid[x, y - 1] != null) { TileStats TS4 = nodegrid[x, y - 1].GetComponent <TileStats>(); if (TS4 != null) { borderList.Add(TS4); } } if (nodegrid[x, y + 1] != null) { TileStats TS3 = nodegrid[x, y + 1].GetComponent <TileStats>(); if (TS3 != null) { borderList.Add(TS3); } } } else if (y == 0) { if (nodegrid[x + 1, y] != null) { TileStats TS1 = nodegrid[x + 1, y].GetComponent <TileStats>(); if (TS1 != null) { borderList.Add(TS1); } } if (nodegrid[x, y + 1] != null) { TileStats TS3 = nodegrid[x, y = 1].GetComponent <TileStats>(); if (TS3 != null) { borderList.Add(TS3); } } } else if (y == height - 1) { if (nodegrid[x + 1, y] != null) { TileStats TS1 = nodegrid[x + 1, y].GetComponent <TileStats>(); if (TS1 != null) { borderList.Add(TS1); } } if (nodegrid[x, y - 1] != null) { TileStats TS4 = nodegrid[x, y - 1].GetComponent <TileStats>(); if (TS4 != null) { borderList.Add(TS4); } } } } else if (x == width - 1) { if (y > 0 && y < height - 1) { if (nodegrid[x - 1, y] != null) { TileStats TS2 = nodegrid[x - 1, y].GetComponent <TileStats>(); if (TS2 != null) { borderList.Add(TS2); } } if (nodegrid[x, y + 1] != null) { TileStats TS3 = nodegrid[x, y + 1].GetComponent <TileStats>(); if (TS3 != null) { borderList.Add(TS3); } } if (nodegrid [x, y - 1] != null) { TileStats TS4 = nodegrid[x, y - 1].GetComponent <TileStats>(); if (TS4 != null) { borderList.Add(TS4); } } } else if (y == 0) { if (nodegrid [x - 1, y] != null) { TileStats TS2 = nodegrid[x - 1, y].GetComponent <TileStats>(); if (TS2 != null) { borderList.Add(TS2); } } if (nodegrid[x, y + 1] != null) { TileStats TS3 = nodegrid[x, y + 1].GetComponent <TileStats>(); if (TS3 != null) { borderList.Add(TS3); } } } else if (y == height - 1) { if (nodegrid[x - 1, y] != null) { TileStats TS2 = nodegrid[x - 1, y].GetComponent <TileStats>(); if (TS2 != null) { borderList.Add(TS2); } } if (nodegrid[x, y - 1] != null) { TileStats TS4 = nodegrid[x, y - 1].GetComponent <TileStats>(); if (TS4 != null) { borderList.Add(TS4); } } } } } return(borderList); }
/// <summary> /// Swaps the type of the tile. /// </summary> /// <param name="x">The x coordinate.</param> /// <param name="y">The y coordinate.</param> /// <param name="newType">New type.</param> public void SwapTileType(int x, int y, TileData.Types newType, string bpName, int nanoBotCost = 0, float spriteSizeX = 0, float spriteSizeY = 0) { TileStats tileStats = new TileStats(); if (bpName != "Empty") { tileStats = BlueprintDatabase.Instance.GetTileStats(bpName); } // MAKE SURE THIS IS NOT A SPAWNED TILE ALREADY!!! // So we don't change the grid tile data where we don't want to! if (spawnedTiles [x, y] == null) { // If spawnedTiles[x, y] is null it means that this tile is an EMPTY land tile, // so in ALL cases below it will be turning the EMPTY walkable tile into a BUILDING unwalkable tile // SO.. update the Node Grid here as well: grid[x, y].isWalkable = false; // sprite size X represents how many tiles will be needed for its width, y for the height // round them down to ints int spriteWidth = Mathf.RoundToInt(spriteSizeX); int spriteHeight = Mathf.RoundToInt(spriteSizeY); switch (newType) { case TileData.Types.extractor: if (spriteWidth > 0 && spriteHeight > 0) DefineMultipleTiles(x, y, spriteWidth, spriteHeight, "Extractor", newType, 0, 10000, 5, 5, 0, 0, nanoBotCost); else tiles [x, y] = new TileData (x, y, "Extractor",newType, 0, 10000, 5, 5, 0, 0, nanoBotCost); break; case TileData.Types.machine_gun: if (spriteWidth > 0 && spriteHeight > 0) { DefineMultipleTiles(x, y, spriteWidth, spriteHeight, "Machine Gun", newType, 0, 10000, tileStats.HP, tileStats.Defense, tileStats.Attack, tileStats.Shield, nanoBotCost); } else { tiles[x, y] = new TileData(x, y, "Machine Gun", newType, 0, 10000, tileStats.HP, tileStats.Defense, tileStats.Attack, tileStats.Shield, nanoBotCost); } break; case TileData.Types.cannons: if (spriteWidth > 0 && spriteHeight > 0) DefineMultipleTiles(x, y, spriteWidth, spriteHeight, "Cannons", newType, 0, 10000, tileStats.HP, tileStats.Defense, tileStats.Attack, tileStats.Shield, nanoBotCost); else tiles [x, y] = new TileData (x, y, "Cannons", newType, 0, 10000, tileStats.HP, tileStats.Defense, tileStats.Attack, tileStats.Shield, nanoBotCost); break; case TileData.Types.harpoonHall: if(spriteWidth > 0 && spriteHeight > 0) DefineMultipleTiles(x, y, spriteWidth, spriteHeight, "Harpooner's Hall", newType, 0, 10000, tileStats.HP, tileStats.Defense, tileStats.Attack, tileStats.Shield, nanoBotCost); else tiles [x, y] = new TileData (x, y, "Harpooner's Hall", newType, 0, 10000, tileStats.HP, tileStats.Defense, tileStats.Attack, tileStats.Shield, nanoBotCost); break; case TileData.Types.farm_s: if (spriteWidth > 0 && spriteHeight > 0) DefineMultipleTiles(x, y, spriteWidth, spriteHeight, "Seaweed Farm", newType, 0, 10000, 25, 1, 0, 0, nanoBotCost); else tiles [x, y] = new TileData (x, y, "Seaweed Farm", newType, 0, 10000, 25, 1, 0, 0, nanoBotCost); break; case TileData.Types.storage: if (spriteWidth > 0 && spriteHeight > 0) DefineMultipleTiles(x, y, spriteWidth, spriteHeight, "Storage", newType, 0, 10000, 35, 2, 0, 0, nanoBotCost); else tiles [x, y] = new TileData (x, y, "Storage", newType, 0, 10000, 35, 2, 0, 0, nanoBotCost); break; case TileData.Types.desalt_s: if (spriteWidth > 0 && spriteHeight > 0) DefineMultipleTiles(x, y, spriteWidth, spriteHeight, "Desalination Pump", newType, 0, 10000, 15, 1, 0, 0, nanoBotCost); else tiles [x, y] = new TileData (x, y, "Desalination Pump", newType, 0, 10000, 15, 1, 0, 0, nanoBotCost); break; case TileData.Types.sniper: if (spriteWidth > 0 && spriteHeight > 0) DefineMultipleTiles(x, y, spriteWidth, spriteHeight, "Sniper Gun", newType, 0, 10000, tileStats.HP, tileStats.Defense, tileStats.Attack, tileStats.Shield, nanoBotCost); else tiles [x, y] = new TileData (x, y, "Sniper Gun", newType, 0, 10000, tileStats.HP, tileStats.Defense, tileStats.Attack, tileStats.Shield, nanoBotCost); break; case TileData.Types.seaWitch: if (spriteWidth > 0 && spriteHeight > 0) DefineMultipleTiles(x, y, spriteWidth, spriteHeight, "Sea-Witch Crag", newType, 0, 10000, tileStats.HP, tileStats.Defense, tileStats.Attack, tileStats.Shield, nanoBotCost); else tiles [x, y] = new TileData (x, y, "Sea-Witch Crag", newType, 0, 10000, tileStats.HP, tileStats.Defense, tileStats.Attack, tileStats.Shield, nanoBotCost); break; case TileData.Types.nutrient: if (spriteWidth > 0 && spriteHeight > 0) DefineMultipleTiles(x, y, spriteWidth, spriteHeight, "Nutrient Generator", newType, 0, 10000, 0, 0, 0, 0, nanoBotCost); else tiles [x, y] = new TileData (x, y, "Nutrient Generator", newType, 0, 10000, 0, 0, 0, 0, nanoBotCost); break; case TileData.Types.generator: if (spriteWidth > 0 && spriteHeight > 0) DefineMultipleTiles(x, y, spriteWidth, spriteHeight, "Energy Generator", newType, 0, 10000, 0, 0, 0, 0, nanoBotCost); else tiles [x, y] = new TileData (x, y, "Energy Generator", newType, 0, 10000, 0, 0, 0, 0, nanoBotCost); break; case TileData.Types.terraformer: if (spriteWidth > 0 && spriteHeight > 0) { DefineMultipleTiles(x, y, spriteWidth, spriteHeight, "Terraformer", newType, 0, 10000, tileStats.HP, tileStats.Defense, tileStats.Attack, tileStats.Shield, nanoBotCost); // Keep a record of the Terraformer's main tile terraformerTile = tiles[x, y]; } else tiles[x, y] = new TileData(x, y, "Terraformer", newType, 0, 10000, tileStats.HP, tileStats.Defense, tileStats.Attack, tileStats.Shield, nanoBotCost); terraformer_built = true; break; case TileData.Types.building: tiles [x, y] = new TileData (x, y, newType, 0, 10000); break; default: print ("No tile changed."); break; } // Discover the tile to display it DiscoverTile(x, y, true, spriteWidth, spriteHeight); //if (BlueprintDatabase.Instance.GetTowerType(bpName) == BuildingType.BATTLE) //{ // if (BattleTowerBuiltCB != null) // BattleTowerBuiltCB(spawnedTiles[x, y].transform); //} //else if (BlueprintDatabase.Instance.GetTowerType(bpName) == BuildingType.UTILITY) //{ // if (UtilityTowerBuiltCB != null) // UtilityTowerBuiltCB(spawnedTiles[x, y].transform); //} } else { // if we are swapping an already spawned tile we are MOST LIKELY turning it into an empty tile // BUT if this was a building that has an ENERGY cost that must be reflected in Player resources // by subtracting from the total ENERGY cost //if (tiles[x,y].energyCost > 0){ // playerResources.totalEnergyCost = playerResources.totalEnergyCost - tiles[x,y].energyCost; //} // // ALSO if it's a Farm we need to subtract its FOOD production and its WATER consumed // if (playerResources.foodProducedPerDay > 0){ // if (tiles[x,y].tileType == TileData.Types.farm_s || tiles[x,y].tileType == TileData.Types.nutrient){ // FoodProduction_Manager foodM = spawnedTiles [x, y].GetComponent<FoodProduction_Manager>(); // playerResources.CalculateFoodProduction(foodM.foodProduced, foodM.productionRate, foodM.waterConsumed, true); // } // } // // AND if it's a STORAGE we need to subtract all the ORE and WATER from the resources // if (tiles[x,y].tileType == TileData.Types.storage){ // Storage storage = spawnedTiles[x,y].GetComponent<Storage>(); //// // // remove the storage building from the list // playerResources.RemoveStorageBuilding(storage); // } // // If it's an EXTRACTOR also need to subtract from Ore Produced // if (tiles[x,y].tileType == TileData.Types.extractor){ // Extractor extra = spawnedTiles [x, y].GetComponent<Extractor>(); // playerResources.CalculateOreProduction(extra.extractAmmnt, extra.extractRate, true); // } // // Same thing for a WATER PUMP // if (tiles[x,y].tileType == TileData.Types.desalt_s || tiles[x,y].tileType == TileData.Types.desalt_m // || tiles[x,y].tileType == TileData.Types.desalt_l){ // DeSalt_Plant pump = spawnedTiles [x, y].GetComponent<DeSalt_Plant>(); // playerResources.CalculateWaterProduction(pump.waterPumped, pump.pumpRate, true); // } // // If it's a ENERGY GENERATOR we have to subtract Energy //TODO: Add an energy produced per day panel // if (tiles[x,y].tileType == TileData.Types.generator){ // Energy_Generator gen = spawnedTiles [x,y].GetComponent<Energy_Generator>(); // playerResources.ChangeResource("Energy", -gen.energyUnitsGenerated); // } //********* NANO BOTS RETURNED: // Return bots... THIS WILL NEED TO EQUAL A NANOBOTS COST LATER, JUST USING 10 int returnNanoCost = tiles[x, y].tileStats.NanoBotCost; NanoBuilding_Handler nanoBuilder = Hero.GetComponent<NanoBuilding_Handler>(); nanoBuilder.nanoBots += returnNanoCost; Debug.Log("GRID: Returning " + returnNanoCost + " NANOBOTS "); // *********** DEFINE NEW EMPTY TILES: // Store the gameobject before doing anything to it. GameObject tileToBeDestroyed = spawnedTiles[x, y]; // If a tile was set as a group of multiple tiles to cover the space of its sprite, we nee to turn ALL of them to empty if (spriteSizeX > 0 || spriteSizeY > 0) // < ----- the way we are swapping for an empty tile, these are always = 0 in this case { tiles[x, y] = new TileData(x, y, newType, 0, 1); } else { // we need the size of the tile that WAS here. We can get the gameobject from spawnedTiles[,], and from that get the Sprite if (tileToBeDestroyed != null) { int width = Mathf.RoundToInt(spawnedTiles[x, y].GetComponent<SpriteRenderer>().sprite.bounds.size.x); int height = Mathf.RoundToInt(spawnedTiles[x, y].GetComponent<SpriteRenderer>().sprite.bounds.size.y); // Define these as empty using this new width and height (doing this since the arguments passed in would be 0 for an empty SwapTile) DefineMultipleEmptyTiles(x, y, width, height, tileToBeDestroyed); } else { Debug.Log("GRID: Could not find the Sprite Renderer. spawnedTiles gameobject = " + spawnedTiles[x, y]); tiles[x, y] = new TileData(x, y, newType, 0, 1); } } //********* POOL SPAWNED TILE: // Use the stored gameobject variable from above to pool it. This represents the base tile of this object, the other placemarkers in the spawnedTiles array have been removed. objPool.PoolObject(tileToBeDestroyed); } }
// Use this for initialization void Start() { this.snapShadow = this.transform.GetChild(0).gameObject; this.tileStats = this.transform.parent.GetComponent <TileStats>(); }
void Start() { tile = GetComponent <TileStats>(); }
//okay so, this is brought up from tileselection. I need to take from TileStats, and get Structures, Units, etc. //case for selecting "Settler" //case for selecting "City" //case for selecting "Tile" private void Start() { myStats = GetComponent <TileStats>(); }