예제 #1
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);
            }
        }
    }
    public void UpdateFurniture(TileOWW tileOWW)
    {
        RuleTile t;

        if (tileOWW.GetInstalledFurniture() != null)
        {
            // Create tile graphics
            t = Resources.Load <RuleTile>("TileSets/Furniture/" + tileOWW.GetInstalledFurniture().GetFurnitureType());
            tilemap.SetTile(new Vector3Int(tileOWW.GetX(), tileOWW.GetY(), 0), t);
            tilemap.RefreshTile(new Vector3Int(tileOWW.GetX(), tileOWW.GetY(), 0));

            // Pathfinding
            if (!tileOWW.GetIsWalkable())
            {
                // Create NavMeshObstacle GameObject
                GameObject go = new GameObject();
                go.name               = "NavMeshBlocking: (" + tileOWW.GetX() + " ," + tileOWW.GetY() + ")";
                go.transform.parent   = Instance.transform;
                go.transform.position = new Vector3(tileOWW.GetX(), tileOWW.GetY(), 0);
                NavMeshObstacle nma = go.AddComponent <NavMeshObstacle>();
                nma.center = new Vector3(0.5f, 0.5f);

                // Set parameters depending on the furniture type
                if (tileOWW.GetInstalledFurniture().GetFurnitureType() == "Wall")
                {
                    nma.carving = true;
                    nma.size    = new Vector3(0.7f, 0.7f, 1f);
                }
                else if (tileOWW.GetInstalledFurniture().GetFurnitureType() == "Airlock")
                {
                    nma.size = new Vector3(1f, 1f, 1f);
                    go.AddComponent <AirlockDoor>();
                    BoxCollider2D boxCollider = go.AddComponent <BoxCollider2D>();
                    boxCollider.isTrigger = true;
                    boxCollider.offset    = new Vector2(0.5f, 0.5f);
                    Rigidbody2D rigidbody = go.AddComponent <Rigidbody2D>();
                    rigidbody.constraints = RigidbodyConstraints2D.FreezeAll;
                }
                tileNavBlockMap.Add(tileOWW, go);
            }
        }
        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));
            if (tileNavBlockMap.ContainsKey(tileOWW))
            {
                if (tileNavBlockMap[tileOWW] != null)
                {
                    // Remove NavMeshObstacle GameObject
                    GameObject go = tileNavBlockMap[tileOWW];
                    tileNavBlockMap.Remove(tileOWW);
                    Destroy(go);
                }
            }
        }
    }
    // 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);
            }
        }
    }
예제 #4
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);
    }
예제 #5
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);
    }
예제 #6
0
    private void CreateRemoveFurnitureAction(TileOWW tile, int offsetX = 0, int offsetY = 0)
    {
        Action removeFurnitureAction = delegate() { RemoveFurniture(tile); };
        Job    j = new Job(removeFurnitureAction, tile, 2, "Remove " + tile.GetInstalledFurniture().GetFurnitureType(), JobPriority.Medium);

        j.SetAltPosition(tile.GetX() + offsetX, tile.GetY() + offsetY);
        tile.currentJobType = j.GetJobType();
        JobQueueController.BuildersJobQueue.AddJob(j);
    }
예제 #7
0
    void OnTriggerStay2D(Collider2D other)
    {
        if (other.gameObject.tag == "Passenger" || other.gameObject.tag == "Guard" || other.gameObject.tag == "Builder" || other.gameObject.tag == "Captain")
        {
            // Incase the installed furniture has changed
            if (tileOWW.GetInstalledFurniture()?.GetFurnitureType() == "Airlock")
            {
                // Disable collision
                gameObject.GetComponent <NavMeshObstacle>().enabled = false;

                // Open door texure
                RuleTile t = Resources.Load <RuleTile>("TileSets/Furniture/Airlock Open");
                FurnitureSpriteController.Instance.tilemap.SetTile(new Vector3Int((int)gameObject.transform.position.x, (int)gameObject.transform.position.y, 0), t);

                // Allow oxygen flow
                tileOWW.GetInstalledFurniture().SetFurnitureType("Airlock Open");
            }
            else if (tileOWW.GetInstalledFurniture()?.GetFurnitureType() == "Airlock Open")
            {
                // Do nothing
            }
            else
            {
                Destroy(gameObject);
            }
        }
    }
예제 #8
0
    // Overloaded method for planing single furniture jobs at once
    public void PlanFurniture(TileOWW furnitureTile, FurnitureType furnitureType)
    {
        if (furnitureTile != null)
        {
            // Check validity for multi-tile
            for (int i = 0; i < furnitureType.sizeX; i++)
            {
                for (int j = 0; j < furnitureType.sizeY; j++)
                {
                    TileOWW temp = WorldController.Instance.GetWorld().GetTileAt(furnitureTile.GetX() + i, furnitureTile.GetY() + j);
                    if (temp.currentJobType != null)
                    {
                        Debug.Log("Unable to place job baceause tile already had an existing job: " + temp.currentJobType);
                        return; // Failed to place
                    }
                }
            }

            Action placeFurnitureAction = delegate() { PlaceFurniture(furnitureTile, furnitureType.title); };
            Job    job;

            // Allow certain furniture to overwrite others by creating a prerequisite removal job
            if (furnitureTile.GetInstalledFurniture()?.GetFurnitureType() == "Wall" && furnitureType.title == "Airlock")
            {
                Action removeExistingFurnitureAction = delegate() { RemoveFurniture(furnitureTile); };
                Job    prerequisiteJob = new Job(removeExistingFurnitureAction, furnitureTile, 2, "Remove Wall", JobPriority.Medium);
                job = new Job(placeFurnitureAction, furnitureTile, furnitureType.installTime, "Build " + furnitureType.title, JobPriority.Medium, prerequisiteJob);
            }
            else
            {
                job = new Job(placeFurnitureAction, furnitureTile, furnitureType.installTime, "Build " + furnitureType.title, JobPriority.Medium);
            }

            furnitureTile.currentJobType = job.GetJobType();
            JobQueueController.BuildersJobQueue.AddJob(job);

            // Invoice
            CurrencyController.Instance.DeductBankBalance(furnitureType.cost);

            // Multi-tile furniture items
            for (int i = 0; i < furnitureType.sizeX; i++)
            {
                for (int j = 0; j < furnitureType.sizeY; j++)
                {
                    TileOWW temp = WorldController.Instance.GetWorld().GetTileAt(furnitureTile.GetX() + i, furnitureTile.GetY() + j);
                    temp.currentJobType         = furnitureTile.currentJobType;
                    temp.installedFurnitureAltX = furnitureTile.GetX();
                    temp.installedFurnitureAltY = furnitureTile.GetY();
                }
            }
        }
    }
예제 #9
0
    public List <TileOWW> PreviewRemoveFurniture(int start_x, int end_x, int start_y, int end_y)
    {
        List <TileOWW> furniture_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
                if (tileOWW != null)
                {
                    if (tileOWW.GetInstalledFurniture() != null)
                    {
                        if (tileOWW.GetInstalledFurniture().GetFurnitureType() != "Wall") // Do NOT remove wall furniture items!
                        {
                            furniture_tiles.Add(tileOWW);
                            CreatePreview(removePreviewPrefab, "Hull", x, y);
                        }
                    }
                    // Allow removal of build jobs that are not walls
                    else if (tileOWW.currentJobType != null)
                    {
                        if (tileOWW.currentJobType.Contains("Build") && !tileOWW.currentJobType.Contains("Wall") && !tileOWW.currentJobType.Contains("Hull"))
                        {
                            furniture_tiles.Add(tileOWW);
                            CreatePreview(removePreviewPrefab, "Hull", x, y);
                        }
                    }
                }
            }
        }
        return(furniture_tiles);
    }
예제 #10
0
    public TileOWW PreviewRemoveFurniture(int posX, int posY)
    {
        ClearPreviews();

        TileOWW tileOWW = WorldController.Instance.GetWorld().GetTileAt(posX, posY);

        // Check valid
        if (tileOWW?.GetInstalledFurniture()?.GetFurnitureType() == "Wall" || tileOWW?.currentJobType == "Build Wall")
        {
            CreatePreview(removePreviewPrefab, "Wall", posX, posY);
            return(tileOWW);
        }
        return(null);
    }
예제 #11
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();
    }
예제 #12
0
    // TODO: Return true before marking off the other tiles as checked!!
    private bool CheckTile(TileOWW tile, List <TileOWW> tilesToCheck)
    {
        if (tilesToCheck.Contains(tile))
        {
            tilesToCheck.Remove(tile);

            bool isSuccessful = false;

            if (CheckTile(WorldController.Instance.GetWorld().GetTileAt(tile.GetX(), tile.GetY() + 1), tilesToCheck))
            {
                isSuccessful = true;
            }
            if (CheckTile(WorldController.Instance.GetWorld().GetTileAt(tile.GetX(), tile.GetY() - 1), tilesToCheck))
            {
                isSuccessful = true;
            }
            if (CheckTile(WorldController.Instance.GetWorld().GetTileAt(tile.GetX() + 1, tile.GetY()), tilesToCheck))
            {
                isSuccessful = true;
            }
            if (CheckTile(WorldController.Instance.GetWorld().GetTileAt(tile.GetX() - 1, tile.GetY()), tilesToCheck))
            {
                isSuccessful = true;
            }

            if (isSuccessful)
            {
                return(true);
            }

            if (tile.GetInstalledFurniture()?.GetFurnitureType() == "Charging Pad") // TODO: The validity will be horrible
            {
                return(true);
            }

            return(false);
        }
        else
        {
            return(false);
        }
    }
예제 #13
0
    public List <TileOWW> PreviewRemoveWall(int start_x, int end_x, int start_y, int end_y)
    {
        List <TileOWW> wall_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
                if (tileOWW?.GetInstalledFurniture()?.GetFurnitureType() == "Wall" || tileOWW?.currentJobType == "Build Wall") // Only remove wall furniture items!
                {
                    wall_tiles.Add(tileOWW);
                    CreatePreview(removePreviewPrefab, "Wall", x, y);
                }
            }
        }
        return(wall_tiles);
    }
예제 #14
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));
        }
    }
예제 #15
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);
        }
    }