コード例 #1
0
    public bool CheckFurniturePreviewValid(TileOWW tile, FurnitureType furnitureType)
    {
        if (furnitureType.cost > CurrencyController.Instance.GetBankBalance())
        {
            // Debug.Log("Couldn't affoard.");
            return(false);
        }

        // Check all tiles of multi-tile furniture
        for (int i = 0; i < furnitureType.sizeX; i++)
        {
            for (int j = 0; j < furnitureType.sizeY; j++)
            {
                TileOWW t = WorldController.Instance.GetWorld().GetTileAt(tile.GetX() + i, tile.GetY() + j);
                if ((t.GetTileType() == "Hull" && furnitureType.exteriorOnly) || (t.GetTileType() == "Empty" && !furnitureType.exteriorOnly))
                {
                    // Debug.Log("Interior / exterior check failed.");
                    return(false);
                }
                if (t.installedFurnitureAltX != null || t.installedFurnitureAltY != null)
                {
                    //Allow certain furniture to overwrite others
                    if (t.GetInstalledFurniture()?.GetFurnitureType() == "Wall" && furnitureType.title == "Airlock")
                    {
                        return(true);
                    }
                    // Debug.Log("Multi-tile furniture check failed.");
                    return(false);
                }
                if (t.GetInstalledFurniture() != null)
                {
                    //Allow certain furniture to overwrite others
                    if (t.GetInstalledFurniture().GetFurnitureType() == "Wall" && furnitureType.title == "Airlock")
                    {
                        return(true);
                    }
                    // Debug.Log("Installed furniture check failed");
                    return(false);
                }
                if (t.currentJobType != null)
                {
                    // Debug.Log("Existing job check failed.");
                    return(false);
                }
            }
        }

        // All checks passed, furniture is valid.
        return(true);
    }
コード例 #2
0
    public List <TileOWW> PreviewRoom(string roomType, int start_x, int end_x, int start_y, int end_y)
    {
        List <TileOWW> room_tiles = new List <TileOWW>();

        ClearPreviews();

        for (int x = start_x; x <= end_x; x++)
        {
            for (int y = start_y; y <= end_y; y++)
            {
                TileOWW t = WorldController.Instance.GetWorld().GetTileAt(x, y);

                if (t != null)
                {
                    // Check valid
                    if (t.GetInstalledFurniture()?.GetFurnitureType() != "Wall" && t.GetTileType() == "Hull")
                    {
                        room_tiles.Add(t);
                        CreatePreview(validPreviewPrefab, "Hull", x, y); // TODO: Different looks per room?
                    }
                    else
                    {
                        CreatePreview(invalidPreviewPrefab, "Hull", x, y);  // TODO: Different looks per room?
                    }
                }
            }
        }

        return(room_tiles);
    }
コード例 #3
0
    public List <TileOWW> PreviewRemoveHull(int start_x, int end_x, int start_y, int end_y)
    {
        List <TileOWW> hull_tiles = new List <TileOWW>();

        ClearPreviews();

        // Loop through all the tiles
        for (int x = start_x; x <= end_x; x++)
        {
            for (int y = start_y; y <= end_y; y++)
            {
                TileOWW tileOWW = WorldController.Instance.GetWorld().GetTileAt(x, y);

                // Check valid - remove installed hull OR job
                if (tileOWW != null)
                {
                    if (tileOWW.GetTileType() == "Hull")
                    {
                        hull_tiles.Add(tileOWW);
                        CreatePreview(removePreviewPrefab, "Hull", x, y);
                    }
                    // Can remove any build job
                    else if (tileOWW.currentJobType != null)
                    {
                        if (tileOWW.currentJobType.Contains("Build"))
                        {
                            hull_tiles.Add(tileOWW);
                            CreatePreview(removePreviewPrefab, "Hull", x, y);
                        }
                    }
                }
            }
        }
        return(hull_tiles);
    }
コード例 #4
0
    private void UpdateOxygenSprite(TileOWW tileOWW, float oxygenLevel)
    {
        Tile t;

        if (tileOWW.oxygenLevel > 0)
        {
            // Create room graphics
            t = Resources.Load <Tile>("TileSets/Rooms/Oxygen");
            if (tileOWW.GetTileType() == "Hull")
            {
                t.color = new Color(0.227451f, 0.7294118f, 0.9960784f, tileOWW.oxygenLevel / 50);
            }
            else
            {
                t.color = new Color(0.9215686f, 0.5764706f, 0.1176471f);
                // TODO: Notification
            }

            tilemap.SetTile(new Vector3Int(tileOWW.GetX(), tileOWW.GetY(), 0), t);
            tilemap.RefreshTile(new Vector3Int(tileOWW.GetX(), tileOWW.GetY(), 0));
        }
        else
        {
            // Remove tile graphics
            t = null;
            tilemap.SetTile(new Vector3Int(tileOWW.GetX(), tileOWW.GetY(), 0), t);
            tilemap.RefreshTile(new Vector3Int(tileOWW.GetX(), tileOWW.GetY(), 0));
        }
    }
コード例 #5
0
    private void TileOxygen(TileOWW originTile, TileOWW nextTile)
    {
        // Base case #1
        if (nextTile.GetInstalledFurniture()?.GetFurnitureType() == "Wall" || nextTile.GetInstalledFurniture()?.GetFurnitureType() == "Airlock")
        {
            return;
        }

        // Base case #2
        if (!uncheckedTiles.Contains(nextTile))
        {
            return;
        }

        // Main
        oxygenTileGroups[originTile].Add(nextTile);
        if (uncheckedTiles.Contains(nextTile))
        {
            uncheckedTiles.Remove(nextTile);
        }

        // Base case #3
        // Note we still add this tile to the group without spreading to other tiles
        if (nextTile.GetTileType() == "Empty")
        {
            return;
        }

        // Spread to next tiles
        TileOWW tileNorth = WorldController.Instance.GetWorld().GetTileAt(nextTile.GetX(), nextTile.GetY() + 1);
        TileOWW tileEast  = WorldController.Instance.GetWorld().GetTileAt(nextTile.GetX() + 1, nextTile.GetY());
        TileOWW tileSouth = WorldController.Instance.GetWorld().GetTileAt(nextTile.GetX(), nextTile.GetY() - 1);
        TileOWW tileWest  = WorldController.Instance.GetWorld().GetTileAt(nextTile.GetX() - 1, nextTile.GetY());

        if (tileNorth != null)
        {
            {
                TileOxygen(originTile, tileNorth);
            }
        }
        if (tileEast != null)
        {
            {
                TileOxygen(originTile, tileEast);
            }
        }
        if (tileSouth != null)
        {
            {
                TileOxygen(originTile, tileSouth);
            }
        }
        if (tileWest != null)
        {
            {
                TileOxygen(originTile, tileWest);
            }
        }
    }
コード例 #6
0
    // Update is called once per frame
    void Update()
    {
        transform.localScale    = Vector3.Lerp(new Vector3(Camera.main.orthographicSize / 500, Camera.main.orthographicSize / 500, 1), transform.localScale, 0.8f);
        transform.localPosition = new Vector3(tile.GetX() + 0.85f, tile.GetY() + 0.5f, 0);

        tileType.text = tile.GetTileType();

        // Installed furniture
        if (tile.GetInstalledFurniture() != null)
        {
            if (furniturePanelGO == null)
            {
                furniturePanelGO = Instantiate(furniturePanelPrefab, parentGO.transform);
            }
            furniturePanelGO.GetComponent <FurniturePanel>().furnitureType.text = tile.GetInstalledFurniture().GetFurnitureType();
        }

        /*
         * // Installed furniture alt position
         * else if (tile.installedFurnitureAltX != null && tile.installedFurnitureAltY != null)
         * {
         *  if (tile.installedFurnitureAltX != tile.GetX() || tile.installedFurnitureAltY != tile.GetY())
         *  {
         *      if (furniturePanelGO == null)
         *      {
         *          furniturePanelGO = Instantiate(furniturePanelPrefab, parentGO.transform);
         *      }
         *      TileOWW furnitureTile = WorldController.Instance.GetWorld().GetTileAt((int)tile.installedFurnitureAltX, (int)tile.installedFurnitureAltY);
         *      furniturePanelGO.GetComponent<FurniturePanel>().furnitureType.text = furnitureTile.GetInstalledFurniture().GetFurnitureType() + " (from alt tile)";
         *  }
         * }
         */
        else
        {
            if (furniturePanelGO != null)
            {
                Destroy(furniturePanelGO);
            }
        }

        // Current job
        if (tile.currentJobType != null)
        {
            if (jobPanelGO == null)
            {
                jobPanelGO = Instantiate(jobPanelPrefab, parentGO.transform);
            }
            jobPanelGO.GetComponent <JobPanel>().jobType.text = tile.currentJobType;
        }
        else
        {
            if (jobPanelGO != null)
            {
                Destroy(jobPanelGO);
            }
        }
    }
コード例 #7
0
    public void UpdateTile(TileOWW tile)
    {
        Tile t;

        if (!tileObjectMap.ContainsKey(tile))
        {
            // The tile might not exist when loading a game from file
            t        = ScriptableObject.CreateInstance <Tile>();
            t.name   = tile.GetX() + "_" + tile.GetY();
            t.sprite = Resources.Load <Sprite>("Images/Tiles/" + tile.GetTileType());
            tilemap.SetTile(new Vector3Int(tile.GetX(), tile.GetY(), 0), t);
            tileObjectMap.Add(tile, t);
        }
        else
        {
            t        = tileObjectMap[tile];
            t.sprite = Resources.Load <Sprite>("Images/Tiles/" + tile.GetTileType());
            tilemap.RefreshTile(new Vector3Int(tile.GetX(), tile.GetY(), 0));
        }
    }
コード例 #8
0
    void UpdateTileInterface()
    {
        // Abort if in any building mode
        if (isMode_Plopable || isMode_Dragable)
        {
            return;
        }

        if (Input.GetMouseButtonUp(0)) // LMB
        {
            // Check if player clicked on something other than a tile
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out RaycastHit hit))
            {
                if (hit.collider.tag != "NavigationPlane")
                {
                    return;
                }
            }

            // Get tile clicked on
            Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            TileOWW tileOWW  = WorldController.Instance.GetWorld().GetTileAt((int)mousePos.x, (int)mousePos.y);

            // Null checks
            if (tileOWW == null)
            {
                return;
            }
            if (tileOWW.GetTileType() == "Empty" && tileOWW.currentJobType == null)
            {
                return;
            }

            // Create interface
            tileInterfaceGO = Instantiate(tileInterfacePrefab);
            tileInterfaceGO.GetComponent <TileInterface>().tile          = tileOWW;
            tileInterfaceGO.GetComponent <TileInterface>().tileType.text = tileOWW.GetTileType();
        }
    }
コード例 #9
0
    public void RemoveFurniture(TileOWW tile)
    {
        string furnitureType = tile.GetInstalledFurniture()?.GetFurnitureType();

        // 'Airlock' may be in 'Airlock Open' state
        if (furnitureType == "Airlock Open")
        {
            furnitureType = "Airlock";
        }

        // Update pathfinding
        if (furnitureType == "Wall")
        {
            // TODO: reset all failed jobs
        }

        tile.RemoveInstalledFurniture();

        // Multi-tile references
        for (int i = 0; i < furnitureTypes[furnitureType].sizeX; i++)
        {
            for (int j = 0; j < furnitureTypes[furnitureType].sizeY; j++)
            {
                TileOWW temp = WorldController.Instance.GetWorld().GetTileAt(tile.GetX() + i, tile.GetY() + j);
                temp.installedFurnitureAltX = null;
                temp.installedFurnitureAltY = null;

                if (tile.GetTileType() == "Hull")
                {
                    emptyHullTiles.Add(tile);
                }
            }
        }

        // Remove from map of furnitureType TileOWW
        while (furnitureTileOWWMap[furnitureType].Contains(tile))
        {
            furnitureTileOWWMap[furnitureType].Remove(tile);
        }

        ObjectiveController.Instance.CheckObjectives();
    }
コード例 #10
0
    // Create build jobs for Hull
    public Tuple <List <TileOWW>, List <TileOWW>, List <TileOWW> > PreviewHull(int start_x, int end_x, int start_y, int end_y, bool includeWalls)
    {
        List <TileOWW> hull_tiles  = new List <TileOWW>();
        List <TileOWW> wall_tiles  = new List <TileOWW>();
        List <TileOWW> floor_tiles = new List <TileOWW>();

        ClearPreviews();

        int estimatedCost = 0;

        // Loop through all the tiles
        for (int x = start_x; x <= end_x; x++)
        {
            for (int y = start_y; y <= end_y; y++)
            {
                TileOWW t = WorldController.Instance.GetWorld().GetTileAt(x, y);

                if (t != null)
                {
                    // Check valid
                    // if (t.GetTileType() == "Empty") hull_tiles.Add(t);

                    // Check outlines if including walls
                    if (includeWalls && (t.GetX() == start_x || t.GetX() == end_x || t.GetY() == start_y || t.GetY() == end_y))
                    {
                        // Check valid
                        if (t.GetInstalledFurniture() == null &&
                            t.installedFurnitureAltX == null && // not apart of a multi-tile furniture
                            t.installedFurnitureAltY == null)
                        {
                            wall_tiles.Add(t);
                            CreatePreview(validPreviewPrefab, "Wall", x, y);
                            estimatedCost += WALL_COST;
                            estimatedCost += HULL_COST;
                        }
                        else
                        {
                            CreatePreview(invalidPreviewPrefab, "Wall", x, y);
                        }
                    }
                    else
                    {
                        if (t.GetTileType() == "Empty")
                        {
                            floor_tiles.Add(t);
                            CreatePreview(validPreviewPrefab, "Hull", x, y);
                            estimatedCost += HULL_COST;
                        }
                        else
                        {
                            CreatePreview(invalidPreviewPrefab, "Hull", x, y);
                        }
                    }
                }
            }
        }

        // Consider materials already in stock

        /*
         * if (CargoController.Instance.unusedShipStock.ContainsKey("Hull")) {
         *  estimatedCost -= (CargoController.Instance.unusedShipStock["Hull"] * HULL_COST);
         * }
         *
         * if (CargoController.Instance.unusedShipStock.ContainsKey("Wall"))
         * {
         *  estimatedCost -= (CargoController.Instance.unusedShipStock["Wall"] * WALL_COST);
         * }
         */

        // Display price UI
        InputController.Instance.currentBuildPrice = estimatedCost;

        // Check funds
        if (estimatedCost > CurrencyController.Instance.GetBankBalance())
        {
            // reset all previews invalid
            ClearPreviews();
            for (int x = start_x; x <= end_x; x++)
            {
                for (int y = start_y; y <= end_y; y++)
                {
                    TileOWW t = WorldController.Instance.GetWorld().GetTileAt(x, y);
                    if (t != null)
                    {
                        // Check outlines
                        if (includeWalls && (t.GetX() == start_x || t.GetX() == end_x || t.GetY() == start_y || t.GetY() == end_y))
                        {
                            CreatePreview(invalidPreviewPrefab, "Wall", x, y);
                        }
                        else
                        {
                            CreatePreview(invalidPreviewPrefab, "Hull", x, y);
                        }
                    }
                }
            }
            // Can NOT affoard this, so return NO valid tiles
            return(null);
        }
        // Can affoard this, so return valid tiles
        else
        {
            return(Tuple.Create(hull_tiles, wall_tiles, floor_tiles));
        }
    }
コード例 #11
0
    public List <TileOWW> PreviewWall(int start_x, int end_x, int start_y, int end_y)
    {
        List <TileOWW> wall_tiles = new List <TileOWW>();

        ClearPreviews();

        int estimatedCost = 0;

        for (int x = start_x; x <= end_x; x++)
        {
            for (int y = start_y; y <= end_y; y++)
            {
                TileOWW t = WorldController.Instance.GetWorld().GetTileAt(x, y);

                if (t != null)
                {
                    // Check outlines
                    if (t.GetX() == start_x || t.GetX() == end_x || t.GetY() == start_y || t.GetY() == end_y)
                    {
                        // Check valid
                        if (t.GetInstalledFurniture() == null && t.GetTileType() == "Hull" &&
                            t.installedFurnitureAltX == null && // not apart of a multi-tile furniture
                            t.installedFurnitureAltY == null)
                        {
                            wall_tiles.Add(t);
                            CreatePreview(validPreviewPrefab, "Wall", x, y);
                            estimatedCost += 50;
                        }
                        else
                        {
                            CreatePreview(invalidPreviewPrefab, "Wall", x, y);
                        }
                    }
                }
            }
        }

        // Display price UI
        InputController.Instance.currentBuildPrice = estimatedCost;

        if (estimatedCost > CurrencyController.Instance.GetBankBalance())
        {
            ClearPreviews();
            for (int x = start_x; x <= end_x; x++)
            {
                for (int y = start_y; y <= end_y; y++)
                {
                    TileOWW t = WorldController.Instance.GetWorld().GetTileAt(x, y);

                    if (t != null)
                    {
                        // Check outlines
                        if (t.GetX() == start_x || t.GetX() == end_x || t.GetY() == start_y || t.GetY() == end_y)
                        {
                            CreatePreview(invalidPreviewPrefab, "Wall", x, y);
                        }
                    }
                }
            }
            return(null);
        }
        else
        {
            return(wall_tiles);
        }
    }