示例#1
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>());
        }
示例#2
0
        internal World(ModData modData, Map map, OrderManager orderManager, WorldT type)
        {
            Type           = type;
            OrderManager   = orderManager;
            orderGenerator = new UnitOrderGenerator();
            Map            = map;
            Timestep       = orderManager.LobbyInfo.GlobalSettings.Timestep;
            SharedRandom   = new MersenneTwister(orderManager.LobbyInfo.GlobalSettings.RandomSeed);

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

            var worldActorT = type == WorldT.Editor ? "EditorWorld" : "World";

            WorldActor = CreateActor(worldActorT, new TypeDictionary());
            ActorMap   = WorldActor.Trait <IActorMap>();
            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;
                    }
                }
            }
        }
示例#3
0
        public void WorldLoaded(World w, WorldRenderer wr)
        {
            var map = w.Map;

            actorMap              = w.ActorMap;
            actorMap.CellUpdated += CellUpdated;

            cellsCost     = new[] { new CellLayer <short>(map) };
            blockingCache = new[] { new CellLayer <CellCache>(map) };

            foreach (var cell in map.AllCells)
            {
                UpdateCellCost(cell);
            }

            map.CustomTerrain.CellEntryChanged += UpdateCellCost;
            map.Tiles.CellEntryChanged         += UpdateCellCost;

            // This section needs to run after WorldLoaded() because we need to be sure that all types of ICustomMovementLayer have been initialized.
            w.AddFrameEndTask(_ =>
            {
                var customMovementLayers = world.GetCustomMovementLayers();
                Array.Resize(ref cellsCost, customMovementLayers.Length);
                Array.Resize(ref blockingCache, customMovementLayers.Length);
                foreach (var cml in customMovementLayers)
                {
                    if (cml == null)
                    {
                        continue;
                    }

                    var cellLayer            = new CellLayer <short>(map);
                    cellsCost[cml.Index]     = cellLayer;
                    blockingCache[cml.Index] = new CellLayer <CellCache>(map);

                    foreach (var cell in map.AllCells)
                    {
                        var index = cml.GetTerrainIndex(cell);

                        var cost = PathGraph.MovementCostForUnreachableCell;

                        if (index != byte.MaxValue)
                        {
                            cost = terrainInfos[index].Cost;
                        }

                        cellLayer[cell] = cost;
                    }
                }
            });
        }
示例#4
0
        public void WorldLoaded(World w, WorldRenderer wr)
        {
            var map = w.Map;

            actorMap = w.ActorMap;
            map.CustomTerrain.CellEntryChanged += UpdateCellCost;
            map.Tiles.CellEntryChanged         += UpdateCellCost;
            actorMap.CellUpdated += CellUpdated;

            cellsCost     = new[] { new CellLayer <short>(map) };
            blockingCache = new[] { new CellLayer <CellCache>(map) };

            foreach (var cell in map.AllCells)
            {
                UpdateCellCost(cell);
                UpdateCellBlocking(cell);
            }

            // NotBefore<> ensures all custom movement layers have been initialized.
            var customMovementLayers = world.GetCustomMovementLayers();

            Array.Resize(ref cellsCost, customMovementLayers.Length);
            Array.Resize(ref blockingCache, customMovementLayers.Length);
            foreach (var cml in customMovementLayers)
            {
                if (cml == null)
                {
                    continue;
                }

                var cellLayer = new CellLayer <short>(map);
                cellsCost[cml.Index]     = cellLayer;
                blockingCache[cml.Index] = new CellLayer <CellCache>(map);

                foreach (var cell in map.AllCells)
                {
                    var index = cml.GetTerrainIndex(cell);

                    var cost = PathGraph.MovementCostForUnreachableCell;

                    if (index != byte.MaxValue)
                    {
                        cost = terrainInfos[index].Cost;
                    }

                    cellLayer[cell] = cost;
                }
            }
        }
示例#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);

            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>();

            // 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.Id,
                Version = Game.ModData.Manifest.Metadata.Version,

                MapUid   = Map.Uid,
                MapTitle = Map.Title
            };
        }
示例#6
0
        public void WorldLoaded(World w, WorldRenderer wr)
        {
            world = w;
            var map = w.Map;

            actorMap              = w.ActorMap;
            actorMap.CellUpdated += CellUpdated;
            terrainInfos          = Info.TilesetTerrainInfo[map.Rules.TileSet];

            blockingCache = new CellLayer <CellCache>(map);
            cellsCost     = new CellLayer <short>(map);

            foreach (var cell in map.AllCells)
            {
                UpdateCellCost(cell);
            }

            map.CustomTerrain.CellEntryChanged += UpdateCellCost;
            map.Tiles.CellEntryChanged         += UpdateCellCost;

            // This section needs to run after WorldLoaded() because we need to be sure that all types of ICustomMovementLayer have been initialized.
            w.AddFrameEndTask(_ =>
            {
                var customMovementLayers = w.WorldActor.TraitsImplementing <ICustomMovementLayer>();
                foreach (var cml in customMovementLayers)
                {
                    var cellLayer = new CellLayer <short>(map);
                    customLayerCellsCost[cml.Index]     = cellLayer;
                    customLayerBlockingCache[cml.Index] = new CellLayer <CellCache>(map);

                    foreach (var cell in map.AllCells)
                    {
                        var index = cml.GetTerrainIndex(cell);

                        var cost = short.MaxValue;

                        if (index != byte.MaxValue)
                        {
                            cost = terrainInfos[index].Cost;
                        }

                        cellLayer[cell] = cost;
                    }
                }
            });
        }
示例#7
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;
        }
        public void WorldLoaded(World w, WorldRenderer wr)
        {
            world = w;
            var map = w.Map;

            actorMap              = w.ActorMap;
            actorMap.CellUpdated += CellUpdated;
            blockingCache         = new CellLayer <CellCache>(map);
            cellsCost             = new CellLayer <short>(map);

            terrainInfos = Info.TilesetTerrainInfo[map.Rules.TileSet];

            foreach (var cell in map.AllCells)
            {
                UpdateCellCost(cell);
            }

            map.CustomTerrain.CellEntryChanged += UpdateCellCost;
            map.Tiles.CellEntryChanged         += UpdateCellCost;
        }