Exemplo n.º 1
0
        public static GameInformation Deserialize(string data)
        {
            try
            {
                var info = new GameInformation();

                var nodes = MiniYaml.FromString(data);
                foreach (var node in nodes)
                {
                    var keyParts = node.Key.Split('@');

                    switch (keyParts[0])
                    {
                    case "Root":
                        FieldLoader.Load(info, node.Value);
                        break;

                    case "Player":
                        info.Players.Add(FieldLoader.Load <Player>(node.Value));
                        break;
                    }
                }

                return(info);
            }
            catch (InvalidOperationException)
            {
                Log.Write("debug", "GameInformation deserialized invalid MiniYaml:\n{0}".F(data));
                throw;
            }
        }
Exemplo n.º 2
0
        public static GameInformation Deserialize(string data)
        {
            try
            {
                var info = new GameInformation();

                var nodes = MiniYaml.FromString(data);
                foreach (var node in nodes)
                {
                    var keyParts = node.Key.Split('@');

                    switch (keyParts[0])
                    {
                        case "Root":
                            FieldLoader.Load(info, node.Value);
                            break;

                        case "Player":
                            info.Players.Add(FieldLoader.Load<Player>(node.Value));
                            break;
                    }
                }

                return info;
            }
            catch (InvalidOperationException)
            {
                Log.Write("debug", "GameInformation deserialized invalid MiniYaml:\n{0}".F(data));
                throw;
            }
        }
Exemplo n.º 3
0
        internal World(ModData modData, Map map, OrderManager orderManager, WorldType type)
        {
            Type           = type;
            OrderManager   = orderManager;
            orderGenerator = new UnitOrderGenerator();
            Map            = map;
            Timestep       = orderManager.LobbyInfo.GlobalSettings.Timestep;
            SharedRandom   = new MersenneTwister(orderManager.LobbyInfo.GlobalSettings.RandomSeed);
            LocalRandom    = new MersenneTwister();

            ModelCache = modData.ModelSequenceLoader.CacheModels(map, modData, map.Rules.ModelSequences);

            var worldActorType = type == WorldType.Editor ? "EditorWorld" : "World";

            WorldActor = CreateActor(worldActorType, new TypeDictionary());
            ActorMap   = WorldActor.Trait <IActorMap>();
            ScreenMap  = WorldActor.Trait <ScreenMap>();
            Selection  = WorldActor.Trait <ISelection>();

            // Reset mask
            LongBitSet <PlayerBitMask> .Reset();

            // Add players
            foreach (var cmp in WorldActor.TraitsImplementing <ICreatePlayers>())
            {
                cmp.CreatePlayers(this);
            }

            // Set defaults for any unset stances
            foreach (var p in Players)
            {
                if (!p.Spectating)
                {
                    AllPlayersMask = AllPlayersMask.Union(p.PlayerMask);
                }

                foreach (var q in Players)
                {
                    SetUpPlayerMask(p, q);

                    if (!p.Stances.ContainsKey(q))
                    {
                        p.Stances[q] = Stance.Neutral;
                    }
                }
            }

            Game.Sound.SoundVolumeModifier = 1.0f;

            gameInfo = new GameInformation
            {
                Mod     = Game.ModData.Manifest.Id,
                Version = Game.ModData.Manifest.Metadata.Version,

                MapUid   = Map.Uid,
                MapTitle = Map.Title
            };

            RulesContainTemporaryBlocker = map.Rules.Actors.Any(a => a.Value.HasTraitInfo <ITemporaryBlockerInfo>());
        }
Exemplo n.º 4
0
        internal World(Map map, OrderManager orderManager, WorldType type)
        {
            Type           = type;
            OrderManager   = orderManager;
            orderGenerator = new UnitOrderGenerator();
            Map            = map;
            Timestep       = orderManager.LobbyInfo.GlobalSettings.Timestep;

            TileSet      = map.Rules.TileSets[Map.Tileset];
            SharedRandom = new MersenneTwister(orderManager.LobbyInfo.GlobalSettings.RandomSeed);

            var worldActorType = type == WorldType.Editor ? "EditorWorld" : "World";

            WorldActor = CreateActor(worldActorType, new TypeDictionary());
            ActorMap   = WorldActor.Trait <ActorMap>();
            ScreenMap  = WorldActor.Trait <ScreenMap>();

            // Add players
            foreach (var cmp in WorldActor.TraitsImplementing <ICreatePlayers>())
            {
                cmp.CreatePlayers(this);
            }

            // Set defaults for any unset stances
            foreach (var p in Players)
            {
                foreach (var q in Players)
                {
                    if (!p.Stances.ContainsKey(q))
                    {
                        p.Stances[q] = Stance.Neutral;
                    }
                }
            }

            Game.Sound.SoundVolumeModifier = 1.0f;

            gameInfo = new GameInformation
            {
                Mod     = Game.ModData.Manifest.Mod.Id,
                Version = Game.ModData.Manifest.Mod.Version,

                MapUid   = Map.Uid,
                MapTitle = Map.Title
            };

            if (!LobbyInfo.GlobalSettings.Shroud)
            {
                foreach (var player in Players)
                {
                    player.Shroud.ExploreAll(this);
                }
            }
        }
Exemplo n.º 5
0
        internal World(ModData modData, Map map, OrderManager orderManager, WorldType type)
        {
            Type           = type;
            OrderManager   = orderManager;
            orderGenerator = new UnitOrderGenerator();
            Map            = map;
            Timestep       = orderManager.LobbyInfo.GlobalSettings.Timestep;
            SharedRandom   = new MersenneTwister(orderManager.LobbyInfo.GlobalSettings.RandomSeed);
            LocalRandom    = new MersenneTwister();

            ModelCache = modData.ModelSequenceLoader.CacheModels(map, modData, map.Rules.ModelSequences);

            var worldActorType = type == WorldType.Editor ? "EditorWorld" : "World";

            WorldActor      = CreateActor(worldActorType, new TypeDictionary());
            ActorMap        = WorldActor.Trait <IActorMap>();
            ScreenMap       = WorldActor.Trait <ScreenMap>();
            Selection       = WorldActor.Trait <ISelection>();
            OrderValidators = WorldActor.TraitsImplementing <IValidateOrder>().ToArray();

            LongBitSet <PlayerBitMask> .Reset();

            // Create an isolated RNG to simplify synchronization between client and server player faction/spawn assignments
            var playerRandom = new MersenneTwister(orderManager.LobbyInfo.GlobalSettings.RandomSeed);

            foreach (var cmp in WorldActor.TraitsImplementing <ICreatePlayers>())
            {
                cmp.CreatePlayers(this, playerRandom);
            }

            Game.Sound.SoundVolumeModifier = 1.0f;

            gameInfo = new GameInformation
            {
                Mod     = Game.ModData.Manifest.Id,
                Version = Game.ModData.Manifest.Metadata.Version,

                MapUid   = Map.Uid,
                MapTitle = Map.Title
            };

            RulesContainTemporaryBlocker = map.Rules.Actors.Any(a => a.Value.HasTraitInfo <ITemporaryBlockerInfo>());
            gameSettings = Game.Settings.Game;
        }
Exemplo n.º 6
0
        internal World(Map map, OrderManager orderManager, bool isShellmap)
        {
            IsShellmap        = isShellmap;
            this.orderManager = orderManager;
            orderGenerator_   = new UnitOrderGenerator();
            Map = map;

            TileSet      = map.Rules.TileSets[Map.Tileset];
            SharedRandom = new MersenneTwister(orderManager.LobbyInfo.GlobalSettings.RandomSeed);

            WorldActor = CreateActor("World", new TypeDictionary());
            ActorMap   = WorldActor.Trait <ActorMap>();
            ScreenMap  = WorldActor.Trait <ScreenMap>();

            // Add players
            foreach (var cmp in WorldActor.TraitsImplementing <ICreatePlayers>())
            {
                cmp.CreatePlayers(this);
            }

            // Set defaults for any unset stances
            foreach (var p in Players)
            {
                foreach (var q in Players)
                {
                    if (!p.Stances.ContainsKey(q))
                    {
                        p.Stances[q] = Stance.Neutral;
                    }
                }
            }

            Sound.SoundVolumeModifier = 1.0f;

            gameInfo = new GameInformation
            {
                MapUid   = Map.Uid,
                MapTitle = Map.Title
            };
        }