Beispiel #1
0
 public void StartConstructionOfCityTile(ConstructedTile tile, Vector3Int position)
 {
     tile.StartConstruction();
     PlaceConstructedTile(position, tile);
     cities.SetTileFlags(position, TileFlags.None);
     cities.SetColor(position, new Color(0.5f, 0.5f, 0.5f));
 }
Beispiel #2
0
    public void InstantiateConstructedTile(string id, Vector3Int pos)
    {
        string          path = System.IO.Path.Combine("Projects", "Constructed Tiles", id);
        ConstructedTile tile = Resources.Load <ConstructedTile>(path);

        PlaceConstructedTile(pos, tile);
    }
Beispiel #3
0
    public void FinishConstructionOfCityTile(City city, ConstructedTileProject project, Vector3Int position, ConstructedTileProject upgradee = null)
    {
        ConstructedTile tile = GetConstructedTile(position);

        tile.FinishConstruction(city, project.ProjectType, project);
        cities.SetColor(position, new Color(1, 1, 1));

        if (upgradee != null)
        {
            //TODO: Manage replacing old constructed tile after upgrade
            project.OnUpgrade(upgradee);
        }
    }
Beispiel #4
0
        public override bool IsValidTile(Vector3Int gridPos, World world, City city)
        {
            Vector3[] checks      = new Vector3[] { new Vector3(-1, 0), new Vector3(-0.5f, 0.75f), new Vector3(0.5f, 0.75f), new Vector3(1, 0), new Vector3(0.5f, -0.75f), new Vector3(-0.5f, -0.75f) };
            bool      validBorder = false;

            foreach (Vector3 check in checks)
            {
                Vector3Int      checkPos = world.WorldToCell(world.CellToWorld(gridPos) + check);
                ConstructedTile tile     = world.GetConstructedTile(checkPos);
                if (checkPos.Equals(city.Position) || (tile != null && tile.City == city && tile.Type.Equals("District")))
                {
                    validBorder = true;
                    break;
                }
            }

            return(validBorder && !invalidTiles.Contains(world.GetTerrainTile(gridPos).name));
        }
Beispiel #5
0
 public void PlaceConstructedTile(Vector3Int position, ConstructedTile tile)
 {
     cities.SetTile(position, tile);
 }
        private IEnumerator WaitForPlacement(City city, World world, ConstructedTileProject project, GUIStateManager state)
        {
            state.SetState(GUIStateManager.GHOST_TILE);
            char sepChar = System.IO.Path.DirectorySeparatorChar;

            spriteRenderer.sprite = Resources.Load <Sprite>("Projects" + sepChar + "Constructed Tiles" + sepChar + project.ID);
            spriteRenderer.color  = new Color(0.5f, 0.5f, 0.5f);

            Vector3Int gridPos = world.WorldToCell(Camera.main.ScreenToWorldPoint(Input.mousePosition));

            HashSet <Vector3Int> range = city.GetCityRange(world);

            UnityEngine.Tilemaps.Tile green = Resources.Load <UnityEngine.Tilemaps.Tile>(System.IO.Path.Combine("Tiles", "Green"));
            foreach (Vector3Int pos in range)
            {
                if (IsValidTile(pos, city, world, project))
                {
                    world.SetMovementTile(pos, green);
                }
            }

            yield return(new WaitForSeconds(0.1f));

            bool click = Input.GetMouseButtonUp(0);

            while (!click || !IsValidTile(gridPos, city, world, project))
            {
                gridPos            = world.WorldToCell(Camera.main.ScreenToWorldPoint(Input.mousePosition));
                transform.position = world.CellToWorld(gridPos);

                string text = project.GetTooltipText(gridPos, world);
                if (text != null)
                {
                    if (!canvas.gameObject.activeSelf)
                    {
                        canvas.gameObject.SetActive(true);
                    }
                    tooltipText.text = text;
                }
                else
                {
                    if (canvas.gameObject.activeSelf)
                    {
                        canvas.gameObject.SetActive(false);
                    }
                }

                if (!IsValidTile(gridPos, city, world, project))
                {
                    spriteRenderer.color = new Color(0, 0, 0);
                }
                else
                {
                    spriteRenderer.color = new Color(0.5f, 0.5f, 0.5f);
                }

                click = Input.GetMouseButtonUp(0);
                yield return(null);
            }

            ConstructedTile tile = Resources.Load <ConstructedTile>("Projects" + sepChar + "Constructed Tiles" + sepChar + project.ID);

            if (world.GetConstructedTile(gridPos) != null)
            {
                project.OnPlacement(gridPos, (world.GetConstructedTile(gridPos)).Project);
            }
            else
            {
                project.OnPlacement(gridPos);
            }

            world.StartConstructionOfCityTile(tile, gridPos);

            foreach (Vector3Int pos in range)
            {
                world.SetMovementTile(pos, null);
            }

            Debug.Log("Tile Selected");
            state.SetState(GUIStateManager.CITY);
            yield break;
        }