Пример #1
0
        internal Scene3D(Game game, MapFile mapFile, int randomSeed)
            : this(game, () => game.Viewport, game.InputMessageBuffer, randomSeed, false)
        {
            var contentManager = game.ContentManager;

            _players = Player.FromMapData(mapFile.SidesList.Players, game.AssetStore).ToList();

            // TODO: This is completely wrong.
            LocalPlayer = _players.FirstOrDefault();

            _teams = (mapFile.SidesList.Teams ?? mapFile.Teams.Items)
                     .Select(team => Team.FromMapData(team, _players))
                     .ToList();

            MapFile    = mapFile;
            Terrain    = AddDisposable(new Terrain.Terrain(mapFile, game.AssetStore.LoadContext));
            WaterAreas = AddDisposable(new WaterAreaCollection(mapFile.PolygonTriggers, mapFile.StandingWaterAreas, mapFile.StandingWaveAreas, game.AssetStore.LoadContext));
            Navigation = new Navigation.Navigation(mapFile.BlendTileData, Terrain.HeightMap);

            Audio            = game.Audio;
            AssetLoadContext = game.AssetStore.LoadContext;

            Lighting = new WorldLighting(
                mapFile.GlobalLighting.LightingConfigurations.ToLightSettingsDictionary(),
                mapFile.GlobalLighting.Time);

            LoadObjects(
                game.AssetStore.LoadContext,
                game.CivilianPlayer,
                Terrain.HeightMap,
                mapFile.ObjectsList.Objects,
                MapFile.NamedCameras,
                _teams,
                out var waypoints,
                out var gameObjects,
                out var roads,
                out var bridges,
                out var cameras);

            Roads       = roads;
            Bridges     = bridges;
            GameObjects = gameObjects;
            Waypoints   = waypoints;
            Cameras     = cameras;

            PlayerScripts = mapFile
                            .GetPlayerScriptsList()
                            .ScriptLists
                            .Select(s => new MapScriptCollection(s))
                            .ToArray();

            CameraController = new RtsCameraController(game.AssetStore.GameData.Current)
            {
                TerrainPosition = Terrain.HeightMap.GetPosition(
                    Terrain.HeightMap.Width / 2,
                    Terrain.HeightMap.Height / 2)
            };

            contentManager.GraphicsDevice.WaitForIdle();
        }
Пример #2
0
        // This needs to operate on the entire player list, because players have references to each other
        // (allies and enemies).
        private static IEnumerable <Player> CreatePlayers(Data.Map.Player[] mapPlayers, AssetStore assetStore, GameType gameType)
        {
            var players = new Dictionary <string, Player>();
            var allies  = new Dictionary <string, string[]>();
            var enemies = new Dictionary <string, string[]>();

            var id = 0u;

            foreach (var mapPlayer in mapPlayers)
            {
                var player = Player.FromMapData(id++, mapPlayer, assetStore, gameType != GameType.SinglePlayer);
                players[player.Name] = player;
                allies[player.Name]  =
                    (mapPlayer.Properties.GetPropOrNull("playerAllies")?.Value as string)?.Split(' ');
                enemies[player.Name] =
                    (mapPlayer.Properties.GetPropOrNull("playerEnemies")?.Value as string)?.Split(' ');
            }

            foreach (var(name, player) in players)
            {
                player.Allies  = allies[name].Select(ally => players[ally]).ToSet();
                player.Enemies = enemies[name].Select(enemy => players[enemy]).ToSet();
            }

            return(players.Values);
        }
Пример #3
0
        internal Scene3D(Game game, MapFile mapFile)
            : this(game, () => game.Viewport, game.InputMessageBuffer, false)
        {
            var contentManager = game.ContentManager;

            _players = Player.FromMapData(mapFile.SidesList.Players, game.AssetStore).ToList();

            // TODO: This is completely wrong.
            LocalPlayer = _players.FirstOrDefault();

            _teams = (mapFile.SidesList.Teams ?? mapFile.Teams.Items)
                     .Select(team => Team.FromMapData(team, _players))
                     .ToList();

            MapFile    = mapFile;
            Terrain    = AddDisposable(new Terrain.Terrain(mapFile, game.AssetStore.LoadContext));
            WaterAreas = AddDisposable(new WaterAreaCollection(mapFile.PolygonTriggers, mapFile.StandingWaterAreas, mapFile.StandingWaveAreas, game.AssetStore.LoadContext));

            Lighting = new WorldLighting(
                mapFile.GlobalLighting.LightingConfigurations.ToLightSettingsDictionary(),
                mapFile.GlobalLighting.Time);

            LoadObjects(
                game.AssetStore.LoadContext,
                game.CivilianPlayer,
                Terrain.HeightMap,
                mapFile.ObjectsList.Objects,
                MapFile.NamedCameras,
                _teams,
                out var waypoints,
                out var gameObjects,
                out var roads,
                out var bridges,
                out var cameras);

            Roads         = roads;
            Bridges       = bridges;
            GameObjects   = gameObjects;
            Waypoints     = waypoints;
            WaypointPaths = new WaypointPathCollection(waypoints, mapFile.WaypointsList.WaypointPaths);
            Cameras       = cameras;

            // TODO: Don't hardcode this.
            // Perhaps add one ScriptComponent for the neutral player,
            // and one for the active player.
            var scriptList = mapFile.GetPlayerScriptsList().ScriptLists[0];

            Scripts = new MapScriptCollection(scriptList);

            CameraController = new RtsCameraController(game.AssetStore.GameData.Current)
            {
                TerrainPosition = Terrain.HeightMap.GetPosition(
                    Terrain.HeightMap.Width / 2,
                    Terrain.HeightMap.Height / 2)
            };

            contentManager.GraphicsDevice.WaitForIdle();
        }
Пример #4
0
        internal Scene3D(Game game, MapFile mapFile, string mapPath, int randomSeed)
            : this(game, () => game.Viewport, game.InputMessageBuffer, randomSeed, false, mapFile, mapPath)
        {
            var contentManager = game.ContentManager;

            _players = Player.FromMapData(mapFile.SidesList.Players, game.AssetStore).ToList();

            LocalPlayer = _players.First();

            _teams = (mapFile.SidesList.Teams ?? mapFile.Teams.Items)
                     .Select(team => Team.FromMapData(team, _players))
                     .ToList();

            Audio            = game.Audio;
            AssetLoadContext = game.AssetStore.LoadContext;

            Lighting = new WorldLighting(
                mapFile.GlobalLighting.LightingConfigurations.ToLightSettingsDictionary(),
                mapFile.GlobalLighting.Time);

            LoadObjects(
                game.AssetStore.LoadContext,
                Terrain.HeightMap,
                mapFile.ObjectsList.Objects,
                MapFile.NamedCameras,
                _teams,
                out var waypoints,
                out var roads,
                out var bridges,
                out var cameras);

            Roads     = roads;
            Bridges   = bridges;
            Waypoints = waypoints;
            Cameras   = cameras;

            PlayerScripts = mapFile
                            .GetPlayerScriptsList()
                            .ScriptLists;

            CameraController = new RtsCameraController(game.AssetStore.GameData.Current, Camera, Terrain.HeightMap)
            {
                TerrainPosition = Terrain.HeightMap.GetPosition(
                    Terrain.HeightMap.Width / 2,
                    Terrain.HeightMap.Height / 2)
            };

            contentManager.GraphicsDevice.WaitForIdle();
        }