public void AddToStorage(CustomTile _customTile) { if (Storage.Count <= StorageCapacity) { for (int i = 0; i < Storage.Count; ++i) { if (Storage[i].Items.Count <= 0) { Storage.RemoveAt(i); } } if (Storage.Any(t => t.Items.All(t => t.ItemID == _customTile.Item.ItemID))) { ItemInventory itemIv = Storage.Where(s => s.Items.Any(t => t.ItemID == _customTile.Item.ItemID)).First(); itemIv.ID = _customTile.Item.ItemID; itemIv.Items.Add(_customTile.Item); } if (Storage.All(t => t.Items.All(t => t.ItemID != _customTile.Item.ItemID))) { ItemInventory itemIv = new ItemInventory(); itemIv.ID = _customTile.Item.ItemID; itemIv.Items.Add(_customTile.Item); Storage.Add(itemIv); Display.AddToSlot(_customTile); } } }
public float GetTileValue(CustomTile pTile) //UGLY PART: Code duplication with AICityManager. Left in because of time pressure. { Building pBuilding = pTile.GetBuildingOnTile(); if (pBuilding == null) { return(0); } float value = -(pBuilding.GetCost() / 3); //Remove cost from the value of the move. City tileCity = pTile.GetCity(); bool buildingIsProduction = false; float happinessValue = 0; float moneyValue = 0; float collectionValue = 1; if (pBuilding is ProductionBuilding) { buildingIsProduction = true; ProductionBuilding prodBuilding = pBuilding as ProductionBuilding; happinessValue += prodBuilding.GetHappinessGain(); moneyValue += prodBuilding.GetMoneyGain(); collectionValue = 0; } Building[] buildingsInRange = tileCity.GetBuildingsAroundTile(1, pTile); foreach (Building b in buildingsInRange) { if (b is CollectionBuilding && buildingIsProduction) { //If this move places a production building next to a collection building, add value to the move. collectionValue += 1; } else if (b is ProductionBuilding) { if (!buildingIsProduction) { //If this move places a collection building next to a production building, add value to the move. ProductionBuilding prodBuilding = b as ProductionBuilding; happinessValue += prodBuilding.GetHappinessGain(); moneyValue += prodBuilding.GetMoneyGain(); } else if (pBuilding.GetType() == b.GetType()) { ProductionBuilding prodBuilding = pBuilding as ProductionBuilding; happinessValue += prodBuilding.GetHappinessGain() * Glob.FactoryProductionMultiplier; moneyValue += prodBuilding.GetMoneyGain() * Glob.FactoryProductionMultiplier; //If a production building is placed next to a production building of the same type, add value to the move. } else { //If a production building is placed next to a production building of a different type, subtract value from the move. ProductionBuilding prodBuilding = pBuilding as ProductionBuilding; happinessValue -= prodBuilding.GetHappinessGain() * Glob.FactoryProductionMultiplier; moneyValue -= prodBuilding.GetMoneyGain() * Glob.FactoryProductionMultiplier; } } } value += (happinessValue + moneyValue) * collectionValue; return(value); }
public void OpenInventoryPickup() { CustomTile tile = Map.current.GetTile(Player.player.location); inventory.Setup(tile.inventory, ItemAction.PICK_UP); inventory.Activate(); }
//The main function! This EXACT coroutine will be executed, even across frames. //See GameAction.cs for more information on how this function should work! public override IEnumerator TakeAction() { yield return(GameAction.StateCheck); CustomTile tile = Map.current.GetTile(intendedLocation); if (tile.BlocksMovement()) { Debug.Log("Console Message: You don't can't do that."); yield break; } caller.connections.OnMove.Invoke(); if (tile.currentlyStanding != null) { AttackAction attack = new AttackAction(tile.currentlyStanding); attack.Setup(caller); while (attack.action.MoveNext()) { yield return(attack.action.Current); } yield break; } caller.SetPosition(intendedLocation); if (costs) { caller.energy -= caller.energyPerStep * tile.movementCost; } caller.UpdateLOS(); }
void SwapTile(GameObject _otherTile) { ChosenTile = _otherTile.GetComponent <HoldCustomTile>().CustomTile; _otherTile.GetComponent <HoldCustomTile>().CustomTile = TransitTile; TileImage.transform.GetChild(0).GetComponent <Image>().sprite = ChosenTile.Item.Sprite; if (ChosenTile.Item.CanBePlaced) { TileImage.transform.GetChild(0).GetComponent <Image>().sprite = ChosenTile.Item.Sprite; } if (!ChosenTile.Item.CanBePlaced) { TileImage.transform.GetChild(0).GetComponent <Image>().sprite = ChosenTile.Item.Sprite; } TileImage.transform.GetChild(0).GetComponent <Image>().color = ChosenTile.TileColour; _otherTile.GetComponent <Image>().color = _otherTile.GetComponent <HoldCustomTile>().CustomTile.TileColour; if (_otherTile.GetComponent <HoldCustomTile>().CustomTile.Item.CanBePlaced) { _otherTile.GetComponent <Image>().sprite = _otherTile.GetComponent <HoldCustomTile>().CustomTile.Item.Sprite; } if (!_otherTile.GetComponent <HoldCustomTile>().CustomTile.Item.CanBePlaced) { _otherTile.GetComponent <Image>().sprite = _otherTile.GetComponent <HoldCustomTile>().CustomTile.Item.Sprite; } DisplayCount(); }
public void ChangeSelectedTile(CityManager.DirectionKey pDirection) { _soundHandler.PlaySound(SoundHandler.Sounds.MOVE); _selectedTile.Reset(); int[] Position = GetTilePosition(_selectedTile); switch (pDirection) { case CityManager.DirectionKey.LEFT: Position[0] = Mathf.Clamp(Position[0] - 1, 0, _tileMap.GetLength(0) - 1); break; case CityManager.DirectionKey.RIGHT: Position[0] = Mathf.Clamp(Position[0] + 1, 0, _tileMap.GetLength(0) - 1); break; case CityManager.DirectionKey.UP: Position[1] = Mathf.Clamp(Position[1] + 1, 0, _tileMap.GetLength(1) - 1); break; case CityManager.DirectionKey.DOWN: Position[1] = Mathf.Clamp(Position[1] - 1, 0, _tileMap.GetLength(1) - 1); break; } _selectedTile = GetTileAtPosition(Position[0], Position[1]); }
private IEnumerator moveToTarget() { IEnumerable <Vector3> nextPositions = Utility.directions() .Select(direction => transform.position + direction) .Where(position => { CustomTile tile = maze.getCustomTile(position); return(!(tile is ObstacleTile || tile is TrapTile)); }).Shuffle(rnd); Vector3 nextRepairTilePosition = nextPositions.Where(position => { RepairTile tile = maze.getTile <RepairTile>(position); return(tile != null && tile.repaired); }).FirstOrDefault(); nextRepairTilePosition = nextRepairTilePosition != Vector3.zero ? nextRepairTilePosition : nextPositions.First(); yield return(StartCoroutine(moveTowards(nextRepairTilePosition))); if (checkoutRepairTile()) { yield break; } yield return(new WaitForSeconds(Random.Range(0f, delay))); StartCoroutine(moveToTarget()); }
public void Setup() { if (setup) { return; } //Set up inventory available = capacity; Items = new ItemStack[capacity]; CustomTile tile = GetComponent <CustomTile>(); Monster monster = GetComponent <Monster>(); if (tile) { holder = tile.transform.parent.parent.parent.GetComponent <Map>().itemContainer; } if (monster) { GameObject hold = new GameObject("Items"); hold.transform.parent = transform; holder = hold.transform; } Debug.Assert(holder != null, "Inventory wasn't attached to monster or tile? Make sure to update inventory logic if this is intentional.", this); //TODO: REWORK THIS this.enabled = false; //This is really, really dumb. I know. Gives us back 15 fps, though setup = true; }
public void move(Vector3Int endGridPos, bool comeback, bool sliding) { if (!isMoving) { isMoving = true; Vector3 startPosition = transform.position; Vector3 endPosition = tilemap_Obstacle.CellToLocal(endGridPos); CustomTile endTile = tilemap_Obstacle.GetTile <CustomTile>(endGridPos); if (sliding && comeback) { Vector3 direction = (endPosition - startPosition).normalized; endGridPos -= Vector3Int.FloorToInt(direction); endPosition = tilemap_Obstacle.CellToLocal(endGridPos); endTile = tilemap_Obstacle.GetTile <CustomTile>(endGridPos); comeback = false; } if (startPosition != endPosition) { playerOverTarget = endTile.type == "target"; StartCoroutine(LerpMove(startPosition, endPosition, endTile, comeback)); } else { EventManager.TriggerEvent("ready"); isMoving = false; } } }
public void CollectEntities(Map map) { visibleMonsters.Clear(); visibleItems.Clear(); Vector2Int start = origin - Vector2Int.one * radius; for (int i = 0; i < (radius * 2 + 1); i++) { for (int j = 0; j < (radius * 2 + 1); j++) { if (definedArea[i, j]) { Vector2Int loc = new Vector2Int(i + start.x, j + start.y); if (loc.x >= 0 && loc.x < map.width && loc.y >= 0 && loc.y < map.height) { CustomTile tile = map.GetTile(new Vector2Int(i + start.x, j + start.y)); if (tile.currentlyStanding) { visibleMonsters.Add(tile.currentlyStanding); } visibleItems.AddRange(tile.inventory.AllHeld()); } } } } }
private SpriteRenderer[,] spriteArray; //tableau de sprite public Grid(int width, int height, float cellSIze, Vector3 originPosition, CustomTile defaultTile) { this.width = width; this.height = height; this.cellSize = cellSIze; this.originPosition = originPosition; this.defaultTile = defaultTile; map = GameObject.Find("Map"); tile = Resources.Load <Sprite>("Sprites/square"); //chargement du spite(assets/ressource/sprites/square.png gridArray = new CustomTile[width, height]; spriteArray = new SpriteRenderer[width, height]; for (int x = 0; x < gridArray.GetLength(0); x++) { for (int y = 0; y < gridArray.GetLength(1); y++) { spriteArray[x, y] = CreateTile(map.transform, "map", GetWorldPosition(x, y) + new Vector3(cellSize, cellSize) * .5f, Color.yellow, 1f); SetValue(x, y, defaultTile); //debugTextArray[x, y] = UtilsClass.CreateWorldText(gridArray[x, y].ToString(), null, (GetWorldPosition(x, y) + new Vector3(cellSize, cellSize) * 0.5f), 20, Color.white, TextAnchor.MiddleCenter); Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x, y + 1), Color.white, 100f); Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x + 1, y), Color.yellow, 100f); } } Debug.DrawLine(GetWorldPosition(0, height), GetWorldPosition(width, height), Color.yellow, 100f); Debug.DrawLine(GetWorldPosition(width, 0), GetWorldPosition(width, height), Color.white, 100f); }
public static BresenhamResults CalculateLine(Vector2Int start, Vector2Int end) { BresenhamResults results = new BresenhamResults(); results.path = new List <CustomTile>(); results.fullPath = new List <CustomTile>(); bool beenBlocked = false; foreach (Vector2Int spot in GetPointsOnLine(start.x, start.y, end.x, end.y)) { //It's assumed that something that blocks movement blocks this line. //TODO: Make sure this assumption actually makes sense CustomTile t = Map.current.GetTile(spot); if (!beenBlocked) { results.path.Add(t); results.fullPath.Add(t); } if (t.BlocksMovement()) { beenBlocked = true; } } results.blocked = beenBlocked; return(results); }
public void HandleHappiness(CustomTile pTile, bool pHappy) { int[] tilePos = GetTilePosition(pTile); for (int x = 0; x < 3; x++)//Check all bordering tiles { for (int y = 0; y < 3; y++) { int xCoordinate = tilePos[0] - 1 + x; int yCoordinate = tilePos[1] - 1 + y; if ((xCoordinate < 0 || xCoordinate >= _tileMap.GetLength(0)) || (yCoordinate < 0 || yCoordinate >= _tileMap.GetLength(1))) { continue; } CustomTile borderingTile = _tileMap[xCoordinate, yCoordinate]; if (!borderingTile.GetIsHappy()) { borderingTile.SetIsHappy(pHappy); if (borderingTile.GetBuildingOnTile() is House && _myManager is PlayerCityManager && pHappy) { GameInitializer.AddSocializerScore(2); } } } } }
public void Update() { if (Input.GetMouseButtonDown(2)) { if (ShouldDetect) { Vector2 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); Vector3Int mousePosAdjusted = new Vector3Int((int)mousePos.x, (int)mousePos.y, 0); if (TileManager.GetTileDictionaryFloor().ContainsKey(mousePosAdjusted)) { CustomTile cT = TileManager.GetTileDictionaryFloor()[mousePosAdjusted].CustomTile; TileName = cT.name; TileType = cT.Type.ToString(); MaxTileHealth = cT.Health; TileSpeed = cT.Speed; TileDamage = cT.Damage; TileScore = cT.ScoreDispense; } if (TileManager.GetTileDictionaryWalls().ContainsKey(mousePosAdjusted)) { CustomTile cT = TileManager.GetTileDictionaryWalls()[mousePosAdjusted].CustomTile; TileName = cT.name; TileType = cT.Type.ToString(); MaxTileHealth = cT.Health; TileSpeed = cT.Speed; TileDamage = cT.Damage; TileScore = cT.ScoreDispense; } } } }
public void AddRelic() { _amountOfRelics++; UIHandler.ShowNotification("You currently have <b>" + _amountOfRelics + "/" + Glob.AmountOfRelicsNeededToWin + "</b> relics in your museum."); if (_amountOfRelics <= Glob.AmountOfRelicsNeededToWin && _myManager is PlayerCityManager) { GameInitializer.AddExplorerScore(6); } if (_amountOfRelics >= Glob.AmountOfRelicsNeededToWin) { CustomTile targetTile = _tileMap[0, 0]; foreach (CustomTile tile in _tileMap) { if (tile.GetBuildingOnTile() is Digsite) { targetTile = tile; break; } } GameInitializer.GetCameraManager().MoveCameraTo(targetTile.transform.position + Glob.CameraBuildingOffset, Glob.CameraBuildingZoomTime); //TODO: Zoom in on a digsite if (_myManager is PlayerCityManager) { UIHandler.ShowNotification("Your city is swarmed with tourists, thanks to the " + _amountOfRelics + " relics you found and put in your museum. AIton's city doesn't stand a chance against this massive economical advantage."); } else { UIHandler.ShowNotification("AIton's city is swarmed with tourists, thanks to the " + _amountOfRelics + " relics he found and put in his museum. Your city doesn't stand a chance against this massive economical advantage, and thus you are forced to surrender."); } GameInitializer.EndGame(false, this); } }
public TileMap(int width, int height, float cellsize, CustomTile tile) { this.width = width; this.height = height; this.defaultTile = tile; this.grid = new Grid(width, height, 10f, new Vector3(0, 0), tile); }
public void AddMissileLaunched() { _missilesLaunched++; if (_myManager is PlayerCityManager) { AICityManager AICity = GameInitializer.GetNextCity(this).GetManager() as AICityManager; AICity.ChangeAnimosity(50, GameInitializer.GetNextCity(this)); } if (_myManager is PlayerCityManager) { GameInitializer.AddKillerScore(20); } if (_missilesLaunched >= Glob.AmountOfMissilesNeededToWin) { CustomTile targetTile = _tileMap[0, 0]; foreach (CustomTile tile in _tileMap) { if (tile.GetBuildingOnTile() is MissileSilo) { targetTile = tile; break; } } GameInitializer.GetCameraManager().MoveCameraTo(targetTile.transform.position + Glob.CameraBuildingOffset, Glob.CameraBuildingZoomTime); //TODO: Zoom in on a digsite if (_myManager is PlayerCityManager) { UIHandler.ShowNotification("AIton has surrendered! He was too afraid of your firepower and decided to run away, leaving his city and inhabitants behind."); } else { UIHandler.ShowNotification("All of your inhabitants have fled your city after all the bombardments AIton launched at you. You have no choice but to surrender."); } GameInitializer.EndGame(false, this); } }
public void SetValue(Vector3 worldPosition, CustomTile tile) { int x, y; GetXY(worldPosition, out x, out y); SetValue(x, y, tile); }
/// <summary> /// Returns the buildings in a list, around the selected tile. First parameter gives the radius of it. /// </summary> /// <param name="pAmountOfTiles"></param> /// <param name="pTargetTile"></param> /// <returns></returns> public Building[] GetBuildingsAroundTile(int pAmountOfTiles, CustomTile pTargetTile) { List <Building> Buildings = new List <Building>(); int[] Coordinates = GetTilePosition(pTargetTile); //This is the maximum difference between the first tile and the last tile. int MaxOffSet = (pAmountOfTiles * 2) + 1; for (int x = 0; x < MaxOffSet; x++) { for (int y = 0; y < MaxOffSet; y++) { int xCoordinate = Coordinates[0] - pAmountOfTiles + x; int yCoordinate = Coordinates[1] - pAmountOfTiles + y; if ((xCoordinate < 0 || xCoordinate >= _tileMap.GetLength(0)) || (yCoordinate < 0 || yCoordinate >= _tileMap.GetLength(1))) { continue; } Building building = _tileMap[xCoordinate, yCoordinate].GetBuildingOnTile(); if (building != null) { Buildings.Add(building); } } } return(Buildings.ToArray()); }
public void OnPointerClick(PointerEventData _data) { if (_data.pointerCurrentRaycast.gameObject.GetComponent <HoldCustomTile>() != null && _data.pointerCurrentRaycast.gameObject.name.Contains("SlotPrefab")) { SetTransitTile(); if (TransitTile == null && _data.pointerCurrentRaycast.gameObject.GetComponent <HoldCustomTile>().CustomTile != null) { PickTile(_data.pointerCurrentRaycast.gameObject); TextInfo.SetActive(false); } if (_data.pointerCurrentRaycast.gameObject.GetComponent <HoldCustomTile>().CustomTile == null) { PlaceEndTile(_data.pointerCurrentRaycast.gameObject); } else { SwapTile(_data.pointerCurrentRaycast.gameObject); } } if (_data.pointerCurrentRaycast.gameObject.name.Contains("Bin")) { m_inventoryBackPack.ClearStorage(ChosenTile); ChosenTile = null; TileImage.gameObject.SetActive(false); } }
protected void CleanTile() { CustomTile _tile = GameData.Instance.m_TileManager.GetTile(m_GridPosition); _tile.m_Entities.Clear(); _tile.m_Walkable = true; Destroy(gameObject); }
private int CalculateDistanceCost(CustomTile a, CustomTile b) { int xDistance = Mathf.Abs(a.GetPosX() - b.GetPosX()); int yDistance = Mathf.Abs(a.GetPosY() - b.GetPosY()); int remaining = Mathf.Abs(xDistance - yDistance); return(DIAGONAL_COST * Mathf.Min(xDistance, yDistance) + STRAIGHT_COST * remaining); }
// Start is called before the first frame update void Start() { pathTile = CustomTile.CreateCustomTile(pathSprite, 0, 0); //testing generatePath(); }
public void Setup() { inventory = GetComponent <Inventory>(); tile = GetComponent <CustomTile>(); inventory.itemsAdded += ItemIsAdded; inventory.itemsRemoved += ItemIsRemoved; this.enabled = false; }
public static void ChangeTileColour(Tilemap _map, Vector3Int _tilePos, CustomTile _customTile) { if (_customTile.ShouldUseColour) { _map.SetTileFlags(_tilePos, TileFlags.None); _map.SetColor(_tilePos, _customTile.TileColour); } }
private void ProcessingFunction(BuildingMeshBuilderProperties properties, CustomTile tile) { for (var i = 0; i < properties.FeatureCount; ++i) { ProcessFeature(i, tile, properties); } CoroutineManager.Run(_processor.RunJob(tile)); }
public void PlaceTileClick(CustomTile _tile) { if (_tile != null) { DropBlock(_tile); } if (_tile != null && _tile.Item != null && _tile.Item.CanBePlaced || m_manager.Creative) { Vector2 worldPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); m_placePos = new Vector3Int((int)worldPosition.x, (int)worldPosition.y, 0); if (m_enemySpawner.Enemies.All(g => new Vector3Int((int)g.transform.position.x, (int)g.transform.position.y, (int)g.transform.position.z) != m_placePos)) { float distance = Vector3Int.Distance(m_placePos, new Vector3Int((int)transform.position.x, (int)transform.position.y, (int)transform.position.z)); CustomTile newCopy = Instantiate(_tile); if (distance <= MaxRange) { if (Input.GetMouseButton(1)) { if (newCopy.Type == TileType.Wall) { if (WallGen.GetTilemap().GetTile(m_placePos) == null) { if (new Vector3Int((int)transform.position.x, (int)transform.position.y, 0) != m_placePos) { PTile(newCopy); if (!m_fileManager.PlacedOnTiles.ContainsKey(m_placePos)) { m_fileManager.PlacedOnTiles.Add(m_placePos, TileManager.GetTileDictionaryFloor()[m_placePos].CustomTile); } if (TileManager.GetTileDictionaryFloor().ContainsKey(m_placePos)) { int id = TileManager.GetTileDictionaryFloor()[m_placePos].CustomTile.ID; DataToSave tempData = new DataToSave { Position = new Vector2Int(m_placePos.x, m_placePos.y), IsPlacedTile = true, ID = id, }; m_fileManager.Input(tempData); } } } } if (newCopy.Type == TileType.Floor || newCopy.Type == TileType.Path) { if (WallGen.GetTilemap().GetTile(m_placePos) == null) { if (TileManager.GetTileDictionaryFloor()[m_placePos].CustomTile.ID != _tile.ID) { PTile(newCopy); } } } } } } } }
public void PickUpAll() { CustomTile tile = Map.current.GetTile(monster.location); for (int i = capacity - 1; i >= 0; i--) { FloorToMonster(i); } }
public IEnumerator BuildFromTemplate(int[,] map, TileList availableTiles) { int xSize = map.GetLength(0); int ySize = map.GetLength(1); tiles = new CustomTile[xSize, ySize]; blocksVision = new bool[xSize, ySize]; moveCosts = new float[xSize, ySize]; yield return(null); tileContainer = new GameObject("Tiles").transform; monsterContainer = new GameObject("Monsters").transform; itemContainer = new GameObject("Items").transform; tileContainer.parent = transform; monsterContainer.parent = transform; itemContainer.parent = transform; width = xSize; height = ySize; for (int j = 0; j < height; j++) { GameObject row = new GameObject { name = $"Row {j}" }; row.transform.parent = tileContainer; for (int i = 0; i < width; i++) { GameObject g = Instantiate(availableTiles.tiles[map[i, j]], row.transform, true); g.name = $"Tile ({i}, {j})"; CustomTile custom = g.GetComponent <CustomTile>(); if (!custom) { Debug.LogError("Tile did not have tile component."); } g.transform.position = new Vector3(i, j, 0); tiles[i, j] = custom; custom.SetMap(this, new Vector2Int(i, j)); custom.Setup(); if (i % 33 == 32) { yield return(null); } } yield return(null); } //Now that map data is finished, go rebuild it for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { tiles[i, j].RebuildMapData(); } yield return(null); } }
public CustomTileForm(MainForm mainForm, CustomTile customTile) { this.mainForm = mainForm; this.customTile = customTile; tileNum = customTile.tileNum; tile = customTile.tile; InitializeComponent(); folderRadioButton.Checked = true; }
private void LoadTiles() { string[] tilePaths = System.IO.Directory.GetFiles(Application.dataPath + "/Resources/Tiles", "*.asset"); foreach (string path in tilePaths) { string fn = System.IO.Path.GetFileNameWithoutExtension(path); CustomTile curTile = Resources.Load <CustomTile>("Tiles/" + fn); TilesDict.Add(fn, curTile); } }