コード例 #1
0
    public void DoBuild(Tile t)
    {
        if (buildMode == BuildMode.FURNITURE)
        {
            // Create the Furniture and assign it to the tile
            // Can we build the furniture in the selected tile?
            // Run the ValidPlacement function!
            string furnitureType = buildModeObjectType;

            if (
                WorldController.Instance.World.IsFurniturePlacementValid(furnitureType, t) &&
                DoesBuildJobOverlapExistingBuildJob(t, furnitureType) == false)
            {
                // This tile position is valid for this furniture

                // Check if there is existing furniture in this tile. If so delete it.
                // TODO Possibly return resources. Will the Deconstruct() method handle that? If so what will happen if resources drop ontop of new non-passable structure.
                if (t.Furniture != null)
                {
                    t.Furniture.Deconstruct();
                }

                // Create a job for it to be build
                Job j;

                if (PrototypeManager.FurnitureJob.Has(furnitureType))
                {
                    // Make a clone of the job prototype
                    j = PrototypeManager.FurnitureJob.Get(furnitureType).Clone();

                    // Assign the correct tile.
                    j.tile = t;
                }
                else
                {
                    Debug.ULogErrorChannel("BuildModeController", "There is no furniture job prototype for '" + furnitureType + "'");
                    j = new Job(t, furnitureType, FurnitureActions.JobComplete_FurnitureBuilding, 0.1f, null, Job.JobPriority.High);
                    j.JobDescription = "job_build_" + furnitureType + "_desc";
                }

                j.furniturePrototype = PrototypeManager.Furniture.Get(furnitureType);

                // Add the job to the queue or build immediately if in dev mode
                if (Settings.GetSetting("DialogBoxSettings_developerModeToggle", false))
                {
                    WorldController.Instance.World.PlaceFurniture(j.JobObjectType, j.tile);
                }
                else
                {
                    for (int x_off = t.X; x_off < (t.X + j.furniturePrototype.Width); x_off++)
                    {
                        for (int y_off = t.Y; y_off < (t.Y + j.furniturePrototype.Height); y_off++)
                        {
                            // FIXME: I don't like having to manually and explicitly set
                            // flags that preven conflicts. It's too easy to forget to set/clear them!
                            Tile offsetTile = WorldController.Instance.World.GetTileAt(x_off, y_off, t.Z);
                            offsetTile.PendingBuildJob = j;
                            j.OnJobStopped            += (theJob) =>
                            {
                                offsetTile.PendingBuildJob = null;
                            };
                        }
                    }

                    WorldController.Instance.World.jobQueue.Enqueue(j);
                }
            }
        }
        else if (buildMode == BuildMode.FLOOR)
        {
            // We are in tile-changing mode.
            ////t.Type = buildModeTile;

            TileType tileType = buildModeTile;

            if (
                t.Type != tileType &&
                t.Furniture == null &&
                t.PendingBuildJob == null &&
                CanBuildTileTypeHere(t, tileType))
            {
                // This tile position is valid tile type

                // Create a job for it to be build
                Job j = TileType.GetConstructionJobPrototype(tileType);

                j.tile = t;

                // Add the job to the queue or build immediately if in dev mode
                if (Settings.GetSetting("DialogBoxSettings_developerModeToggle", false))
                {
                    j.tile.Type = j.JobTileType;
                }
                else
                {
                    // FIXME: I don't like having to manually and explicitly set
                    // flags that preven conflicts. It's too easy to forget to set/clear them!
                    t.PendingBuildJob = j;
                    j.OnJobStopped   += (theJob) =>
                    {
                        theJob.tile.PendingBuildJob = null;
                    };

                    WorldController.Instance.World.jobQueue.Enqueue(j);
                }
            }
        }
        else if (buildMode == BuildMode.DECONSTRUCT)
        {
            // TODO
            if (t.Furniture != null)
            {
                // check if this is a WALL neighbouring a pressured and pressureless environ & if so bail
                if (t.Furniture.HasTypeTag("Wall"))
                {
                    Tile[] neighbors          = t.GetNeighbours(); // diagOkay??
                    int    pressuredNeighbors = 0;
                    int    vacuumNeighbors    = 0;
                    foreach (Tile neighbor in neighbors)
                    {
                        if (neighbor != null && neighbor.Room != null)
                        {
                            if ((neighbor.Room == World.Current.GetOutsideRoom()) || MathUtilities.IsZero(neighbor.Room.GetTotalGasPressure()))
                            {
                                vacuumNeighbors++;
                            }
                            else
                            {
                                pressuredNeighbors++;
                            }
                        }
                    }

                    if (vacuumNeighbors > 0 && pressuredNeighbors > 0)
                    {
                        Debug.ULogChannel("BuildModeController", "Someone tried to deconstruct a wall between a pressurised room and vacuum!");
                        return;
                    }
                }

                t.Furniture.Deconstruct();
            }
            else if (t.PendingBuildJob != null)
            {
                t.PendingBuildJob.CancelJob();
            }
        }
        else
        {
            Debug.ULogErrorChannel("BuildModeController", "UNIMPLEMENTED BUILD MODE");
        }
    }
コード例 #2
0
    public void DoBuild(Tile t)
    {
        if (buildMode == BuildMode.FURNITURE)
        {
            // Create the Furniture and assign it to the tile
            // Can we build the furniture in the selected tile?
            // Run the ValidPlacement function!
            string furnitureType = buildModeObjectType;

            if (
                WorldController.Instance.world.IsFurniturePlacementValid(furnitureType, t) &&
                DoesBuildJobOverlapExistingBuildJob(t, furnitureType) == false)
            {
                // This tile position is valid for this furniture

                // Check if there is existing furniture in this tile. If so delete it.
                // TODO Possibly return resources. Will the Deconstruct() method handle that? If so what will happen if resources drop ontop of new non-passable structure.
                if (t.Furniture != null)
                {
                    t.Furniture.Deconstruct();
                }

                // Create a job for it to be build
                Job j;

                if (WorldController.Instance.world.furnitureJobPrototypes.ContainsKey(furnitureType))
                {
                    // Make a clone of the job prototype
                    j = WorldController.Instance.world.furnitureJobPrototypes[furnitureType].Clone();

                    // Assign the correct tile.
                    j.tile = t;
                }
                else
                {
                    Debug.LogError("There is no furniture job prototype for '" + furnitureType + "'");
                    j = new Job(t, furnitureType, FurnitureActions.JobComplete_FurnitureBuilding, 0.1f, null, Job.JobPriority.High);
                    j.JobDescription = "job_build_" + furnitureType + "_desc";
                }

                j.furniturePrototype = WorldController.Instance.world.furniturePrototypes[furnitureType];

                for (int x_off = t.X; x_off < (t.X + WorldController.Instance.world.furniturePrototypes[furnitureType].Width); x_off++)
                {
                    for (int y_off = t.Y; y_off < (t.Y + WorldController.Instance.world.furniturePrototypes[furnitureType].Height); y_off++)
                    {
                        // FIXME: I don't like having to manually and explicitly set
                        // flags that preven conflicts. It's too easy to forget to set/clear them!
                        Tile offsetTile = WorldController.Instance.world.GetTileAt(x_off, y_off);
                        offsetTile.PendingBuildJob = j;
                        j.cbJobStopped            += (theJob) =>
                        {
                            offsetTile.PendingBuildJob = null;
                        };
                    }
                }

                // Add the job to the queue
                if (WorldController.Instance.devMode)
                {
                    WorldController.Instance.world.PlaceFurniture(j.jobObjectType, j.tile);
                }
                else
                {
                    WorldController.Instance.world.jobQueue.Enqueue(j);
                }
            }
        }
        else if (buildMode == BuildMode.FLOOR)
        {
            // We are in tile-changing mode.
            ////t.Type = buildModeTile;

            TileType tileType = buildModeTile;

            if (
                t.Type != tileType &&
                t.Furniture == null &&
                t.PendingBuildJob == null &&
                CanBuildTileTypeHere(t, tileType))
            {
                // This tile position is valid tile type

                // Create a job for it to be build
                Job j = TileType.GetConstructionJobPrototype(tileType);

                j.tile = t;

                // FIXME: I don't like having to manually and explicitly set
                // flags that preven conflicts. It's too easy to forget to set/clear them!
                t.PendingBuildJob = j;
                j.cbJobStopped   += (theJob) =>
                {
                    theJob.tile.PendingBuildJob = null;
                };

                // Add the job to the queue
                if (WorldController.Instance.devMode)
                {
                    j.tile.Type = j.jobTileType;
                }
                else
                {
                    WorldController.Instance.world.jobQueue.Enqueue(j);
                }
            }
        }
        else if (buildMode == BuildMode.DECONSTRUCT)
        {
            // TODO
            if (t.Furniture != null)
            {
                t.Furniture.Deconstruct();
            }
            else if (t.PendingBuildJob != null)
            {
                t.PendingBuildJob.CancelJob();
            }
        }
        else
        {
            Debug.LogError("UNIMPLEMENTED BUILD MODE");
        }
    }