예제 #1
0
        public ActorMap( World world )
        {
            map = world.Map;
            influence = new InfluenceNode[world.Map.MapSize.X, world.Map.MapSize.Y];

            world.ActorAdded += a => Add( a, a.OccupiesSpace );
            world.ActorRemoved += a => Remove( a, a.OccupiesSpace );
        }
예제 #2
0
        public ShroudRenderer(Player owner, Map map)
        {
            this.shroud = owner.World.WorldActor.Trait<Traits.Shroud>();
            this.map = map;

            sprites = new Sprite[map.MapSize.X, map.MapSize.Y];
            fogSprites = new Sprite[map.MapSize.X, map.MapSize.Y];

            shroud.Dirty += () => dirty = true;
        }
예제 #3
0
		public ShroudRenderer(World world, ShroudRendererInfo info)
		{
			this.info = info;
			map = world.Map;

			tiles = new CellLayer<ShroudTile>(map);

			// Force update on first render
			shroudHash = -1;

			// Load sprite variants
			if (info.ShroudVariants.Length != info.FogVariants.Length)
				throw new InvalidOperationException("ShroudRenderer must define the same number of shroud and fog variants!");

			if ((info.OverrideFullFog == null) ^ (info.OverrideFullShroud == null))
				throw new InvalidOperationException("ShroudRenderer cannot define overrides for only one of shroud or fog!");

			var variantCount = info.ShroudVariants.Length;
			variantStride = info.Index.Length + (info.OverrideFullShroud != null ? 1 : 0);
			shroudSprites = new Sprite[variantCount * variantStride];
			fogSprites = new Sprite[variantCount * variantStride];

			for (var j = 0; j < variantCount; j++)
			{
				var shroud = map.SequenceProvider.GetSequence(info.Sequence, info.ShroudVariants[j]);
				var fog = map.SequenceProvider.GetSequence(info.Sequence, info.FogVariants[j]);
				for (var i = 0; i < info.Index.Length; i++)
				{
					shroudSprites[j * variantStride + i] = shroud.GetSprite(i);
					fogSprites[j * variantStride + i] = fog.GetSprite(i);
				}

				if (info.OverrideFullShroud != null)
				{
					var i = (j + 1) * variantStride - 1;
					shroudSprites[i] = map.SequenceProvider.GetSequence(info.Sequence, info.OverrideFullShroud).GetSprite(0);
					fogSprites[i] = map.SequenceProvider.GetSequence(info.Sequence, info.OverrideFullFog).GetSprite(0);
				}
			}

			// Mapping of shrouded directions -> sprite index
			spriteMap = new int[info.UseExtendedIndex ? 256 : 16];
			for (var i = 0; i < info.Index.Length; i++)
				spriteMap[info.Index[i]] = i;

			if (info.OverrideFullShroud != null)
				spriteMap[info.OverrideShroudIndex] = variantStride - 1;
		}
예제 #4
0
파일: ModData.cs 프로젝트: Berzeger/OpenRA
		void LoadTranslations(Map map)
		{
			var selectedTranslations = new Dictionary<string, string>();
			var defaultTranslations = new Dictionary<string, string>();

			if (!Manifest.Translations.Any())
			{
				Languages = new string[0];
				FieldLoader.Translations = new Dictionary<string, string>();
				return;
			}

			var yaml = Manifest.Translations.Select(MiniYaml.FromFile).Aggregate(MiniYaml.MergeLiberal);
			Languages = yaml.Select(t => t.Key).ToArray();

			yaml = MiniYaml.MergeLiberal(map.TranslationDefinitions, yaml);

			foreach (var y in yaml)
			{
				if (y.Key == Game.Settings.Graphics.Language)
					selectedTranslations = y.Value.ToDictionary(my => my.Value ?? "");
				else if (y.Key == Game.Settings.Graphics.DefaultLanguage)
					defaultTranslations = y.Value.ToDictionary(my => my.Value ?? "");
			}

			var translations = new Dictionary<string, string>();
			foreach (var tkv in defaultTranslations.Concat(selectedTranslations))
			{
				if (translations.ContainsKey(tkv.Key))
					continue;
				if (selectedTranslations.ContainsKey(tkv.Key))
					translations.Add(tkv.Key, selectedTranslations[tkv.Key]);
				else
					translations.Add(tkv.Key, tkv.Value);
			}

			FieldLoader.Translations = translations;
		}
예제 #5
0
파일: Map.cs 프로젝트: ushardul/OpenRA
        public static Map FromTileset(TileSet tileset)
        {
            var size = new Size(1, 1);
            var tileShape = Game.ModData.Manifest.TileShape;
            var tileRef = new TerrainTile(tileset.Templates.First().Key, (byte)0);

            var makeMapTiles = Exts.Lazy(() =>
            {
                var ret = new CellLayer<TerrainTile>(tileShape, size);
                ret.Clear(tileRef);
                return ret;
            });

            var makeMapHeight = Exts.Lazy(() =>
            {
                var ret = new CellLayer<byte>(tileShape, size);
                ret.Clear(0);
                return ret;
            });

            var map = new Map()
            {
                Title = "Name your map here",
                Description = "Describe your map here",
                Author = "Your name here",
                MapSize = new int2(size),
                Tileset = tileset.Id,
                Videos = new MapVideos(),
                Options = new MapOptions(),
                MapResources = Exts.Lazy(() => new CellLayer<ResourceTile>(tileShape, size)),
                MapTiles = makeMapTiles,
                MapHeight = makeMapHeight,

                SpawnPoints = Exts.Lazy(() => new CPos[0])
            };

            map.PostInit();

            return map;
        }
예제 #6
0
파일: Map.cs 프로젝트: JackKucan/OpenRA
		public static Map FromTileset(TileSet tileset)
		{
			var size = new Size(1, 1);
			var tileShape = Game.modData.Manifest.TileShape;
			var tileRef = new TerrainTile(tileset.Templates.First().Key, (byte)0);

			var makeMapTiles =  Exts.Lazy(() =>
			{
				var ret = new CellLayer<TerrainTile>(tileShape, size);
				ret.Clear(tileRef);
				return ret;
			});

			var map = new Map()
			{
				Title = "Name your map here",
				Description = "Describe your map here",
				Author = "Your name here",
				MapSize = new int2(size),
				Tileset = tileset.Id,
				Options = new MapOptions(),
				MapResources = Exts.Lazy(() => new CellLayer<ResourceTile>(tileShape, size)),
				MapTiles = makeMapTiles,
				Actors = Exts.Lazy(() => new Dictionary<string, ActorReference>()),
				Smudges = Exts.Lazy(() => new List<SmudgeReference>())
			};
			map.PostInit();

			return map;
		}
예제 #7
0
파일: ModData.cs 프로젝트: RunCraze/OpenRA
        public Map PrepareMap(string uid)
        {
            LoadScreen.Display();

            if (MapCache[uid].Status != MapStatus.Available)
                throw new InvalidDataException("Invalid map uid: {0}".F(uid));

            // Operate on a copy of the map to avoid gameplay state leaking into the cache
            var map = new Map(MapCache[uid].Map.Path);

            LoadTranslations(map);

            // Reinit all our assets
            InitializeLoaders();
            GlobalFileSystem.LoadFromManifest(Manifest);

            // Mount map package so custom assets can be used. TODO: check priority.
            GlobalFileSystem.Mount(GlobalFileSystem.OpenPackage(map.Path, null, int.MaxValue));

            using (new Support.PerfTimer("Map.PreloadRules"))
                map.PreloadRules();
            using (new Support.PerfTimer("Map.SequenceProvider.Preload"))
                map.SequenceProvider.Preload();

            VoxelProvider.Initialize(Manifest.VoxelSequences, map.VoxelSequenceDefinitions);

            return map;
        }
예제 #8
0
		public void UpdateFromMap(Map m, MapClassification classification)
		{
			Map = m;
			Title = m.Title;
			Type = m.Type;
			Type = m.Type;
			Author = m.Author;
			PlayerCount = m.Players.Count(x => x.Value.Playable);
			Bounds = m.Bounds;
			SpawnPoints = m.GetSpawnPoints().ToList();
			CustomPreview = m.CustomPreview;
			Status = MapStatus.Available;
			Class = classification;
		}
예제 #9
0
파일: Map.cs 프로젝트: RunCraze/OpenRA
        public static Map FromTileset(TileSet tileset)
        {
            var tile = tileset.Templates.First();
            var tileRef = new TileReference<ushort, byte> { Type = tile.Key, Index = (byte)0 };

            Map map = new Map()
            {
                Title = "Name your map here",
                Description = "Describe your map here",
                Author = "Your name here",
                MapSize = new int2(1, 1),
                Tileset = tileset.Id,
                Options = new MapOptions(),
                MapResources = Exts.Lazy(() => new TileReference<byte, byte>[1, 1]),
                MapTiles = Exts.Lazy(() => new TileReference<ushort, byte>[1, 1] { { tileRef } }),
                Actors = Exts.Lazy(() => new Dictionary<string, ActorReference>()),
                Smudges = Exts.Lazy(() => new List<SmudgeReference>())
            };
            map.PostInit();

            return map;
        }
예제 #10
0
파일: Map.cs 프로젝트: pchote/OpenRA
 public void Serialize(Map map, List<MiniYamlNode> nodes)
 {
     var value = field != null ? field.GetValue(map) : property.GetValue(map, null);
     if (type == Type.NodeList)
     {
         var listValue = (List<MiniYamlNode>)value;
         if (required || listValue.Any())
             nodes.Add(new MiniYamlNode(key, null, listValue));
     }
     else if (type == Type.MiniYaml)
     {
         var yamlValue = (MiniYaml)value;
         if (required || (yamlValue != null && (yamlValue.Value != null || yamlValue.Nodes.Any())))
             nodes.Add(new MiniYamlNode(key, yamlValue));
     }
     else
     {
         var formattedValue = FieldSaver.FormatValue(value);
         if (required || formattedValue != ignoreIfValue)
             nodes.Add(new MiniYamlNode(key, formattedValue));
     }
 }
예제 #11
0
파일: Map.cs 프로젝트: pchote/OpenRA
        public void Deserialize(Map map, List<MiniYamlNode> nodes)
        {
            var node = nodes.FirstOrDefault(n => n.Key == key);
            if (node == null)
            {
                if (required)
                    throw new YamlException("Required field `{0}` not found in map.yaml".F(key));
                return;
            }

            if (field != null)
            {
                if (type == Type.NodeList)
                    field.SetValue(map, node.Value.Nodes);
                else if (type == Type.MiniYaml)
                    field.SetValue(map, node.Value);
                else
                    FieldLoader.LoadField(map, fieldName, node.Value.Value);
            }

            if (property != null)
            {
                if (type == Type.NodeList)
                    property.SetValue(map, node.Value.Nodes, null);
                else if (type == Type.MiniYaml)
                    property.SetValue(map, node.Value, null);
                else
                    FieldLoader.LoadField(map, fieldName, node.Value.Value);
            }
        }
예제 #12
0
		public void UpdateFromMap(Map m, MapClassification classification)
		{
			Map = m;
			Title = m.Title;
			Type = m.Type;
			Type = m.Type;
			Author = m.Author;
			Bounds = m.Bounds;
			SpawnPoints = m.SpawnPoints.Value;
			GridType = m.Grid.Type;
			CustomPreview = m.CustomPreview;
			Status = MapStatus.Available;
			Class = classification;

			var players = new MapPlayers(m.PlayerDefinitions).Players;
			PlayerCount = players.Count(x => x.Value.Playable);

			SuitableForInitialMap = EvaluateUserFriendliness(players);
		}
예제 #13
0
		static int ObserverShroudedEdges(Map map, CPos p, bool useExtendedIndex)
		{
			var u = 0;
			if (!map.Contains(p + new CVec(0, -1))) u |= 0x13;
			if (!map.Contains(p + new CVec(1, 0))) u |= 0x26;
			if (!map.Contains(p + new CVec(0, 1))) u |= 0x4C;
			if (!map.Contains(p + new CVec(-1, 0))) u |= 0x89;

			var uside = u & 0x0F;
			if (!map.Contains(p + new CVec(-1, -1))) u |= 0x01;
			if (!map.Contains(p + new CVec(1, -1))) u |= 0x02;
			if (!map.Contains(p + new CVec(1, 1))) u |= 0x04;
			if (!map.Contains(p + new CVec(-1, 1))) u |= 0x08;

			return useExtendedIndex ? u ^ uside : u & 0x0F;
		}
예제 #14
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();

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

            // Add players
            // 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);
            }

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