Exemple #1
0
    public void AddRoom(Room r)
    {
        rooms.Add(r);
        roomGraph = null;

        Debug.ULogChannel("Rooms", "creating room:" + r.ID);
    }
Exemple #2
0
    private void SetupWorld(int width, int height, int depth)
    {
        // Set the current world to be this world.
        // TODO: Do we need to do any cleanup of the old world?
        Current = this;

        Width  = width;
        Height = height;
        Depth  = depth;

        tiles = new Tile[Width, Height, Depth];

        RoomManager           = new RoomManager();
        RoomManager.Adding   += (room) => roomGraph = null;
        RoomManager.Removing += (room) => roomGraph = null;

        FillTilesArray();

        FurnitureManager          = new FurnitureManager();
        FurnitureManager.Created += OnFurnitureCreated;

        UtilityManager   = new UtilityManager();
        CharacterManager = new CharacterManager();
        InventoryManager = new InventoryManager();
        jobQueue         = new JobQueue();
        GameEventManager = new GameEventManager();
        PowerNetwork     = new PowerNetwork();
        temperature      = new Temperature();
        ShipManager      = new ShipManager();
        Wallet           = new Wallet();
        CameraData       = new CameraData();

        LoadSkybox();
        AddEventListeners();
    }
Exemple #3
0
    private void SetupWorld(int width, int height)
    {
        // Set the current world to be this world.
        // TODO: Do we need to do any cleanup of the old world?
        Current = this;


        RoomManager           = new RoomManager();
        RoomManager.Adding   += (room) => roomGraph = null;
        RoomManager.Removing += (room) => roomGraph = null;

        FillTilesArray();

        FurnitureManager          = new FurnitureManager();
        FurnitureManager.Created += OnFurnitureCreated;

        UtilityManager   = new UtilityManager();
        CharacterManager = new CharacterManager();
        InventoryManager = new InventoryManager();
        jobQueue         = new JobQueue();
        GameEventManager = new GameEventManager();
        PowerNetwork     = new PowerNetwork();
        FluidNetwork     = new FluidNetwork();
        temperature      = new TemperatureDiffusion(this);
        Wallet           = new Wallet();
        CameraData       = new CameraData();

        LoadSkybox();
        AddEventListeners();

        holder.Start();
        biomes.RandomBiome();
        mapData.SetupWorld(width, height, biome.maxHeight);
    }
Exemple #4
0
    /// <summary>
    /// Initializes a new instance of the <see cref="World"/> class.
    /// </summary>
    /// <param name="width">Width in tiles.</param>
    /// <param name="height">Height in tiles.</param>
    /// <param name="depth">Depth in amount.</param>
    public World(int width, int height, int depth)
    {
        // Creates an empty world.
        SetupWorld(width, height, depth);
        int seed = UnityEngine.Random.Range(0, int.MaxValue);

        Debug.LogWarning("World Seed: " + seed);
        WorldGenerator.Instance.Generate(this, seed);
        UnityDebugger.Debugger.Log("World", "Generated World");

        tileGraph = new Path_TileGraph(this);
        roomGraph = new Path_RoomGraph(this);

        // Make one character.
        CharacterManager.Create(GetTileAt((Width / 2) - 1, Height / 2, 0));
    }
Exemple #5
0
    private void SetupWorld(int width, int height, int depth)
    {
        // Set the current world to be this world.
        // TODO: Do we need to do any cleanup of the old world?
        Current = this;

        Width  = width;
        Height = height;
        Depth  = depth;

        tiles = new Tile[Width, Height, Depth];

        RoomManager           = new RoomManager();
        RoomManager.Adding   += (room) => roomGraph = null;
        RoomManager.Removing += (room) => roomGraph = null;

        for (int x = 0; x < Width; x++)
        {
            for (int y = 0; y < Height; y++)
            {
                for (int z = 0; z < Depth; z++)
                {
                    tiles[x, y, z]                  = new Tile(x, y, z);
                    tiles[x, y, z].TileChanged     += OnTileChangedCallback;
                    tiles[x, y, z].TileTypeChanged += OnTileTypeChangedCallback;
                    tiles[x, y, z].Room             = RoomManager.OutsideRoom; // Rooms 0 is always going to be outside, and that is our default room
                }
            }
        }

        FurnitureManager          = new FurnitureManager();
        FurnitureManager.Created += OnFurnitureCreated;

        UtilityManager   = new UtilityManager();
        CharacterManager = new CharacterManager();
        InventoryManager = new InventoryManager();
        jobQueue         = new JobQueue();
        GameEventManager = new GameEventManager();
        PowerNetwork     = new PowerNetwork();
        temperature      = new Temperature();
        ShipManager      = new ShipManager();
        Wallet           = new Wallet();
        CameraData       = new CameraData();

        LoadSkybox();
        AddEventListeners();
    }
Exemple #6
0
    public void DeleteRoom(Room r)
    {
        if (r.IsOutsideRoom())
        {
            Debug.ULogErrorChannel("World", "Tried to delete the outside room.");
            return;
        }

        Debug.ULogChannel("Rooms", "Deleting room:" + r.ID);

        roomGraph = null;

        // Remove this room from our rooms list.
        rooms.Remove(r);

        // All tiles that belonged to this room should be re-assigned to
        // the outside.
        r.ReturnTilesToOutsideRoom();
    }
Exemple #7
0
    /// <summary>
    /// Initializes a new instance of the <see cref="World"/> class.
    /// </summary>
    /// <param name="width">Width in tiles.</param>
    /// <param name="height">Height in tiles.</param>
    /// <param name="depth">Depth in amount.</param>
    public World(int width, int height, int depth)
    {
        // Creates an empty world.
        SetupWorld(width, height, depth);
        Seed = UnityEngine.Random.Range(int.MinValue, int.MaxValue);
        if (SceneController.NewWorldSize != Vector3.zero)
        {
            Seed = SceneController.Seed;
        }

        Debug.LogWarning("World Seed: " + Seed);
        WorldGenerator.Instance.Generate(this, Seed);
        UnityDebugger.Debugger.Log("World", "Generated World");

        tileGraph = new Path_TileGraph(this);
        roomGraph = new Path_RoomGraph(this);

        // Make one character.
        CharacterManager.Create(GetTileAt((Width / 2) - 1, Height / 2, 0));
    }
Exemple #8
0
    /// <summary>
    /// Tests the room graph generation for the default world.
    /// </summary>
    private void TestRoomGraphGeneration(World world)
    {
        // FIXME: This code is fugly!!!
        // TODO: Make it work for other testing maps?

        // roomGraph is auto-generated by Path_AStar if needed
        // doing this explicitly here to make sure we have one now
        roomGraph = new Path_RoomGraph(world);

        int errorCount = 0;

        if (roomGraph.nodes.Count() != 6)
        {
            Debug.ULogErrorChannel("Path_RoomGraph", "Generated incorrect number of nodes: " + roomGraph.nodes.Count().ToString());
            errorCount++;
        }

        foreach (Room r in world.rooms)
        {
            if (roomGraph.nodes.ContainsKey(r) == false)
            {
                Debug.ULogErrorChannel("Path_RoomGraph", "Does not contain room: " + r.ID);
                errorCount++;
            }
            else
            {
                Path_Node <Room> node = roomGraph.nodes[r];
                int edgeCount         = node.edges.Count();
                switch (r.ID)
                {
                case 0:     // the outside room has two edges both connecting to room 2
                    if (edgeCount != 2)
                    {
                        Debug.ULogErrorChannel("Path_RoomGraph", "Room 0 supposed to have 2 edges. Instead has: " + edgeCount);
                        errorCount++;
                        continue;
                    }

                    if (node.edges[0].node.data != world.rooms[2] || node.edges[1].node.data != world.rooms[2])
                    {
                        Debug.ULogErrorChannel("Path_RoomGraph", "Room 0 supposed to have edges to Room 2.");
                        Debug.ULogErrorChannel(
                            "Path_RoomGraph",
                            string.Format("Instead has: {1} and {2}", node.edges[0].node.data.ID, node.edges[1].node.data.ID));

                        // "Instead has: " + node.edges[0].node.data.ID.ToString() + " and "
                        // + node.edges[1].node.data.ID.ToString());
                        errorCount++;
                    }

                    break;

                case 1:     // Room 1 has one edge connecting to room 2
                    if (edgeCount != 1)
                    {
                        Debug.ULogErrorChannel("Path_RoomGraph", "Room 1 supposed to have 1 edge. Instead has: " + edgeCount);
                        errorCount++;
                        continue;
                    }

                    if (node.edges[0].node.data != world.rooms[2])
                    {
                        Debug.ULogErrorChannel("Path_RoomGraph", "Room 1 supposed to have edge to Room 2.");
                        Debug.ULogErrorChannel("Path_RoomGraph", "Instead has: " + node.edges[0].node.data.ID.ToString());
                        errorCount++;
                    }

                    break;

                case 2:     // Room 2 has two edges both connecting to the outside room, one connecting to room 1 and one connecting to room 5
                    if (edgeCount != 4)
                    {
                        Debug.ULogErrorChannel("Path_RoomGraph", "Room 2 supposed to have 4 edges. Instead has: " + edgeCount);
                        errorCount++;
                        continue;
                    }

                    // group edges by target room
                    IEnumerable <IGrouping <Room, Path_Edge <Room> > > query =
                        node.edges.GroupBy(edge => edge.node.data, edge => edge);

                    foreach (IGrouping <Room, Path_Edge <Room> > group in query)
                    {
                        switch (group.Key.ID)
                        {
                        case 0:
                            if (group.Count() != 2)
                            {
                                Debug.ULogErrorChannel("Path_RoomGraph", "Room 2 supposed to have two edges to Room 0.");
                                errorCount++;
                            }

                            break;

                        case 1:
                            if (group.Count() != 1)
                            {
                                Debug.ULogErrorChannel("Path_RoomGraph", "Room 2 supposed to have one edge to Room 1.");
                                errorCount++;
                            }

                            break;

                        case 5:
                            if (group.Count() != 1)
                            {
                                Debug.ULogErrorChannel("Path_RoomGraph", "Room 2 supposed to have one edge to Room 5.");
                                errorCount++;
                            }

                            break;

                        default:
                            Debug.ULogErrorChannel("Path_RoomGraph", "Room 2 only supposed to have edges to Rooms 0, 1 and 5.");
                            errorCount++;
                            break;
                        }
                    }

                    break;

                case 3:     // Room 3 has no edges
                    if (edgeCount != 0)
                    {
                        Debug.ULogErrorChannel("Path_RoomGraph", "Room 3 supposed to have no edges. Instead has: " + edgeCount);
                        errorCount++;
                        continue;
                    }

                    break;

                case 4:     // Room 4 has no edges
                    if (edgeCount != 0)
                    {
                        Debug.ULogErrorChannel("Path_RoomGraph", "Room 4 supposed to have no edges. Instead has: " + edgeCount);
                        errorCount++;
                        continue;
                    }

                    break;

                case 5:     // Room 5 has one edge to Room 2
                    if (edgeCount != 1)
                    {
                        Debug.ULogErrorChannel("Path_RoomGraph", "Room 5 supposed to have 1 edge. Instead has: " + edgeCount);
                        errorCount++;
                        continue;
                    }

                    if (node.edges[0].node.data != world.rooms[2])
                    {
                        Debug.ULogErrorChannel("Path_RoomGraph", "Room 5 supposed to have edge to Room 2.");
                        Debug.ULogErrorChannel("Path_RoomGraph", "Instead has: " + node.edges[0].node.data.ID.ToString());
                        errorCount++;
                    }

                    break;

                default:
                    Debug.ULogErrorChannel("Path_RoomGraph", "Unknown room ID: " + r.ID);
                    errorCount++;
                    break;
                }
            }
        }

        if (errorCount == 0)
        {
            Debug.ULogChannel("Path_RoomGraph", "TestRoomGraphGeneration completed without errors!");
        }
    }
Exemple #9
0
    public void ResizeWorld(int width, int height, int depth)
    {
        if (width < Width || height < Height || depth < Depth)
        {
            if (width < Width)
            {
                UnityDebugger.Debugger.LogWarning("World", "Width too small: " + Width + " " + width);
            }

            if (height < Height)
            {
                UnityDebugger.Debugger.LogWarning("World", "Height too small: " + Height + " " + height);
            }

            if (depth < Depth)
            {
                UnityDebugger.Debugger.LogWarning("World", "Depth too small: " + Depth + " " + depth);
            }

            UnityDebugger.Debugger.LogError("World", "Shrinking the world is not presently supported");
            return;
        }

        if (width == Width && height == Height && depth == Depth)
        {
            // No change, just bail
            return;
        }

        int offsetX = (width - Width) / 2;
        int offsetY = ((height - Height) / 2) + 1;

        Tile[,,] oldTiles = (Tile[, , ])tiles.Clone();
        tiles             = new Tile[width, height, depth];

        int oldWidth  = Width;
        int oldHeight = Height;
        int oldDepth  = Depth;

        Width  = width;
        Height = height;
        Depth  = depth;

        FillTilesArray();
        tileGraph = null;
        roomGraph = null;

        // Reset temperature, so it properly sizes arrays to the new world size
        temperature.Resize();

        for (int x = 0; x < oldWidth; x++)
        {
            for (int y = 0; y < oldHeight; y++)
            {
                for (int z = 0; z < oldDepth; z++)
                {
                    tiles[x + offsetX, y + offsetY, z] = oldTiles[x, y, z];
                    oldTiles[x, y, z].MoveTile(x + offsetX, y + offsetY, z);
                }
            }
        }
    }
Exemple #10
0
    /// <summary>
    /// Tests the room graph generation for the default world.
    /// </summary>
    private void TestRoomGraphGeneration(World world)
    {
        // FIXME: This code is fugly!!!
        // TODO: Make it work for other testing maps?

        // roomGraph is auto-generated by Path_AStar if needed
        // doing this explicitly here to make sure we have one now
        roomGraph = new Path_RoomGraph(world);

        int errorCount = 0;

        if (roomGraph.nodes.Count() != 8)
        {
            UnityDebugger.Debugger.LogError("Path_RoomGraph", "Generated incorrect number of nodes: " + roomGraph.nodes.Count().ToString());
            errorCount++;
        }

        foreach (Room r in world.RoomManager)
        {
            if (roomGraph.nodes.ContainsKey(r) == false)
            {
                UnityDebugger.Debugger.LogError("Path_RoomGraph", "Does not contain room: " + r.ID);
                errorCount++;
            }
            else
            {
                Path_Node <Room> node = roomGraph.nodes[r];
                int edgeCount         = node.edges.Count();
                switch (r.ID)
                {
                case 0:     // the outside room has two edges both connecting to room 2
                    if (edgeCount != 2)
                    {
                        UnityDebugger.Debugger.LogError("Path_RoomGraph", "Room 0 supposed to have 2 edges. Instead has: " + edgeCount);
                        errorCount++;
                        continue;
                    }

                    if (node.edges[0].node.data != world.RoomManager[2] || node.edges[1].node.data != world.RoomManager[4])
                    {
                        UnityDebugger.Debugger.LogError("Path_RoomGraph", "Room 0 supposed to have edges to Room 2 and Room 4.");
                        UnityDebugger.Debugger.LogError(
                            "Path_RoomGraph",
                            string.Format("Instead has: {1} and {2}", node.edges[0].node.data.ID, node.edges[1].node.data.ID));
                        errorCount++;
                    }

                    break;

                case 1:     // Room 1 has one edge connecting to room 2
                    if (edgeCount != 1)
                    {
                        UnityDebugger.Debugger.LogError("Path_RoomGraph", "Room 1 supposed to have 1 edge. Instead has: " + edgeCount);
                        errorCount++;
                        continue;
                    }

                    if (node.edges[0].node.data != world.RoomManager[3])
                    {
                        UnityDebugger.Debugger.LogError("Path_RoomGraph", "Room 1 supposed to have edge to Room 3.");
                        UnityDebugger.Debugger.LogError("Path_RoomGraph", "Instead has: " + node.edges[0].node.data.ID.ToString());
                        errorCount++;
                    }

                    break;

                case 2:     // Room 2 has two edges both connecting to the outside room, one connecting to room 1 and one connecting to room 5
                    if (edgeCount != 2)
                    {
                        UnityDebugger.Debugger.LogError("Path_RoomGraph", "Room 2 supposed to have 2 edges. Instead has: " + edgeCount);
                        errorCount++;
                        continue;
                    }

                    if (node.edges[0].node.data != world.RoomManager[3] || node.edges[1].node.data != world.RoomManager[0])
                    {
                        UnityDebugger.Debugger.LogError("Path_RoomGraph", "Room 2 supposed to have edges to Room 3 and Room 0.");
                        UnityDebugger.Debugger.LogError(
                            "Path_RoomGraph",
                            string.Format("Instead has: {0} and {1}", node.edges[0].node.data.ID, node.edges[1].node.data.ID));
                        errorCount++;
                    }

                    break;

                case 3:     // Room 3 has 4 edges, connecting to Rooms 1, 2, 4, and 7
                    if (edgeCount != 4)
                    {
                        UnityDebugger.Debugger.LogError("Path_RoomGraph", "Room 3 supposed to have 4 edges. Instead has: " + edgeCount);
                        errorCount++;
                        continue;
                    }

                    if (node.edges[0].node.data != world.RoomManager[4] || node.edges[1].node.data != world.RoomManager[7] ||
                        node.edges[2].node.data != world.RoomManager[1] || node.edges[3].node.data != world.RoomManager[2])
                    {
                        UnityDebugger.Debugger.LogError("Path_RoomGraph", "Room 3 supposed to have edges to Rooms 4, 7, 1, and 2");
                        string errorMessage = string.Format(
                            "Instead has: {0}, {1}, {2}, and {3}",
                            node.edges[0].node.data.ID,
                            node.edges[1].node.data.ID,
                            node.edges[2].node.data.ID,
                            node.edges[3].node.data.ID);
                        UnityDebugger.Debugger.LogError("Path_RoomGraph", errorMessage);
                        errorCount++;
                    }

                    break;

                case 4:     // Room 2 has two edges both connecting to the outside room, one connecting to room 1 and one connecting to room 5
                    if (edgeCount != 2)
                    {
                        UnityDebugger.Debugger.LogError("Path_RoomGraph", "Room 4 supposed to have 2 edges. Instead has: " + edgeCount);
                        errorCount++;
                        continue;
                    }

                    if (node.edges[0].node.data != world.RoomManager[0] || node.edges[1].node.data != world.RoomManager[3])
                    {
                        UnityDebugger.Debugger.LogError("Path_RoomGraph", "Room 4 supposed to have edges to Room 0 and Room 3.");
                        UnityDebugger.Debugger.LogError(
                            "Path_RoomGraph",
                            string.Format("Instead has: {0} and {1}", node.edges[0].node.data.ID, node.edges[1].node.data.ID));

                        // "Instead has: " + node.edges[0].node.data.ID.ToString() + " and "
                        // + node.edges[1].node.data.ID.ToString());
                        errorCount++;
                    }

                    break;

                case 5:     // Room 5 has no edges
                    if (edgeCount != 0)
                    {
                        UnityDebugger.Debugger.LogError("Path_RoomGraph", "Room 5 supposed to have no edges. Instead has: " + edgeCount);
                        errorCount++;
                        continue;
                    }

                    break;

                case 6:     // Room 4 has no edges
                    if (edgeCount != 0)
                    {
                        UnityDebugger.Debugger.LogError("Path_RoomGraph", "Room 6 supposed to have no edges. Instead has: " + edgeCount);
                        errorCount++;
                        continue;
                    }

                    break;

                case 7:     // Room 5 has one edge to Room 3
                    if (edgeCount != 1)
                    {
                        UnityDebugger.Debugger.LogError("Path_RoomGraph", "Room 7 supposed to have 1 edge. Instead has: " + edgeCount);
                        errorCount++;
                        continue;
                    }

                    if (node.edges[0].node.data != world.RoomManager[3])
                    {
                        UnityDebugger.Debugger.LogError("Path_RoomGraph", "Room 7 supposed to have edge to Room 3.");
                        UnityDebugger.Debugger.LogError("Path_RoomGraph", "Instead has: " + node.edges[0].node.data.ID.ToString());
                        errorCount++;
                    }

                    break;

                default:
                    UnityDebugger.Debugger.LogError("Path_RoomGraph", "Unknown room ID: " + r.ID);
                    errorCount++;
                    break;
                }
            }
        }

        if (errorCount == 0)
        {
            UnityDebugger.Debugger.Log("Path_RoomGraph", "TestRoomGraphGeneration completed without errors!");
        }
    }