Exemplo n.º 1
0
        // The special constructor is used to deserialize values.
        public World(SerializationInfo info, StreamingContext context)
        {
            // TODO: move this to more generic place
            currentMapInfo = XMLObjectLoader.LoadXMLObject <MapInfo>("data\\xml\\DefaultMapInfo.xml", MapInfo.PostLoadInitialization);

            engine = Engine.instance;
            rng    = TCODRandom.getInstance();
            player = null;

            mapCache = (List <AreaMap>)info.GetValue("mapCache", typeof(List <AreaMap>));
            mapIdx   = (int)info.GetValue("mapIdx", typeof(int));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Cleans up the current level and regenerates a new one
        /// </summary>
        public void InitializeNewLevel()
        {
            // TODO: much more generic way of setting up the map data
            currentMapInfo = XMLObjectLoader.LoadXMLObject <MapInfo>("data\\xml\\DefaultMapInfo.xml", MapInfo.PostLoadInitialization);

            if (currentMap != null)
            {
                if (mapCache == null)
                {
                    mapCache = new List <AreaMap>();
                }

                mapCache.Add(currentMap);
                mapIdx += 1;

                CleanUpMap(currentMap);
                currentMap = null;
            }

            // Choose which generator to use
            Generator mapGenerator = null;

            switch (currentMapInfo.generatorType)
            {
            case MapInfo.EGeneratorType.Dungeon:
                if (rng.getFloat(0.0f, 1.0f) > 0.5f)
                {
                    mapGenerator = new GenCaveDungeon(rng, currentMapInfo.terrainSet, currentMapInfo);
                }
                else
                {
                    mapGenerator = new GenRoomDungeon(rng, currentMapInfo.terrainSet, currentMapInfo);
                }
                break;

            case MapInfo.EGeneratorType.Overworld:
                // TODO: new generator class
                break;

            default:
                mapGenerator = new GenSimpleDungeon(rng, currentMapInfo.terrainSet, currentMapInfo);
                break;
            }

            // Create the area map from the selected generator
            currentMap = new AreaMap(this, currentMapInfo.width, currentMapInfo.height, mapGenerator);

            // spawn the entities requested from the generation algorithm, stuff like doors and other static objects
            if (mapGenerator.objectSpawns != null)
            {
                foreach (var spawn in mapGenerator.objectSpawns)
                {
                    // special case handles player spawn, need to cache the reference
                    if (spawn.entity == "Player")
                    {
                        SpawnPlayer(spawn.location);
                        continue;
                    }

                    Entity spawned = SpawnEntity(spawn.entity, spawn.location);

                    // handle a few other special cases
                    if (spawn.entity == "Chest")
                    {
                        PopulateLootChest(spawned);
                    }
                    if (spawn.entity == "Entrance")
                    {
                        currentMap.entranceLoc = spawn.location;
                    }
                    if (spawn.entity == "Exit")
                    {
                        currentMap.exitLoc = spawn.location;
                    }
                }
            }

            // give the map a first LOS update
            currentMap.UpdateLOSFrom(player.position, 10);
        }