diff --git a/OpenRA.FileFormats/Map/Map.cs b/OpenRA.FileFormats/Map/Map.cs index 2aa0ef4390..c256789833 100644 --- a/OpenRA.FileFormats/Map/Map.cs +++ b/OpenRA.FileFormats/Map/Map.cs @@ -44,8 +44,12 @@ namespace OpenRA.FileFormats public Dictionary Actors = new Dictionary(); public List Smudges = new List(); public Dictionary Waypoints = new Dictionary(); + + // Rules overrides public Dictionary Rules = new Dictionary(); - + public Dictionary Weapons = new Dictionary(); + public Dictionary Voices = new Dictionary(); + public Dictionary Terrain = new Dictionary(); // Binary map data public byte TileFormat = 1; public int2 MapSize; diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index 5ce9b8e2d5..0fd72c93de 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -135,8 +135,6 @@ namespace OpenRA SheetBuilder.Initialize(renderer); LoadModPackages(manifest); Timer.Time( "load assemblies, packages: {0}" ); - Rules.LoadRules(manifest); - Timer.Time( "load rules: {0}" ); Game.packageChangePending = false; LoadMap(manifest.ShellmapUid); @@ -157,7 +155,7 @@ namespace OpenRA world = null; // trying to access the old world will NRE, rather than silently doing it wrong. ChromeProvider.Initialize(manifest.Chrome); - world = new World(mapName); + world = new World(manifest,mapName); Timer.Time( "world: {0}" ); SequenceProvider.Initialize(manifest.Sequences); @@ -170,6 +168,11 @@ namespace OpenRA Timer.Time( "----end LoadMap" ); Debug("Map change {0} -> {1}".F(Game.mapName, mapName)); } + + public static void MoveViewport(int2 loc) + { + viewport.Center(loc); + } internal static void Initialize(Renderer renderer, int2 clientSize, int localPlayer, Controller controller) { diff --git a/OpenRA.Game/GameRules/Rules.cs b/OpenRA.Game/GameRules/Rules.cs index a1179742a2..019c043731 100755 --- a/OpenRA.Game/GameRules/Rules.cs +++ b/OpenRA.Game/GameRules/Rules.cs @@ -49,12 +49,34 @@ namespace OpenRA TechTree = new TechTree(); } - static Dictionary LoadYamlRules(string[] files, Func, Dictionary, T> f) { var y = files.Select(a => MiniYaml.FromFile(a)).Aggregate(MiniYaml.Merge); return y.ToDictionary(kv => kv.Key.ToLowerInvariant(), kv => f(kv, y)); } + + public static void LoadRules(Manifest m, Map map) + { + Log.Write("Using rules files: "); + foreach (var y in m.Rules) + Log.Write(" -- {0}", y); + + Log.Write("Using Map: {0}",map.Uid); + + Info = LoadYamlRules(m.Rules, map.Rules, (k, y) => new ActorInfo(k.Key.ToLowerInvariant(), k.Value, y)); + Weapons = LoadYamlRules(m.Weapons, map.Weapons, (k, _) => new WeaponInfo(k.Key.ToLowerInvariant(), k.Value)); + Voices = LoadYamlRules(m.Voices, map.Voices, (k, _) => new VoiceInfo(k.Value)); + TerrainTypes = LoadYamlRules(m.Terrain, map.Terrain, (k, _) => new TerrainCost(k.Value)) + .ToDictionary(kv => (TerrainType)Enum.Parse(typeof(TerrainType), kv.Key, true), kv => kv.Value); + + TechTree = new TechTree(); + } + + static Dictionary LoadYamlRules(string[] files, Dictionarydict, Func, Dictionary, T> f) + { + var y = files.Select(a => MiniYaml.FromFile(a)).Aggregate(dict,MiniYaml.Merge); + return y.ToDictionary(kv => kv.Key.ToLowerInvariant(), kv => f(kv, y)); + } public static IEnumerable Categories() { diff --git a/OpenRA.Game/Graphics/Viewport.cs b/OpenRA.Game/Graphics/Viewport.cs index 3bccfb2033..9bf71ffff7 100644 --- a/OpenRA.Game/Graphics/Viewport.cs +++ b/OpenRA.Game/Graphics/Viewport.cs @@ -165,6 +165,11 @@ namespace OpenRA.Graphics { return (1 / 24.0f) * (new float2(mi.Location.X, mi.Location.Y) + Location); } + + public void Center(int2 loc) + { + scrollPosition = (Game.CellSize*loc - .5f * new float2(Width, Height)).ToInt2(); + } public void Center(IEnumerable actors) { diff --git a/OpenRA.Game/World.cs b/OpenRA.Game/World.cs index a3e08bd1fd..cd593b54c9 100644 --- a/OpenRA.Game/World.cs +++ b/OpenRA.Game/World.cs @@ -75,7 +75,7 @@ namespace OpenRA public readonly WorldRenderer WorldRenderer; internal readonly Minimap Minimap; - public World(string mapUid) + public World(Manifest manifest, string mapUid) { Timer.Time( "----World.ctor" ); @@ -83,9 +83,14 @@ namespace OpenRA throw new InvalidDataException("Cannot find map with Uid {0}".F(mapUid)); Map = new Map( Game.AvailableMaps[mapUid].Package ); + + customTerrain = new ICustomTerrain[Map.MapSize.X, Map.MapSize.Y]; Timer.Time( "new Map: {0}" ); + Rules.LoadRules(manifest,Map); + Timer.Time( "load rules: {0}" ); + var theaterInfo = Rules.Info["world"].Traits.WithInterface() .FirstOrDefault(t => t.Theater == Map.Theater); TileSet = new TileSet(theaterInfo.Tileset, theaterInfo.Templates, theaterInfo.Suffix); diff --git a/OpenRA.Mods.RA/DefaultShellmapScript.cs b/OpenRA.Mods.RA/DefaultShellmapScript.cs new file mode 100644 index 0000000000..8a28cad365 --- /dev/null +++ b/OpenRA.Mods.RA/DefaultShellmapScript.cs @@ -0,0 +1,46 @@ +#region Copyright & License Information +/* + * Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford. + * This file is part of OpenRA. + * + * OpenRA is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * OpenRA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with OpenRA. If not, see . + */ +#endregion + +using OpenRA.Mods.RA.Effects; +using OpenRA.Traits; +using OpenRA; + +namespace OpenRA.Mods.RA +{ + class DefaultShellmapScriptInfo : ITraitInfo + { + public object Create(Actor self) { return new DefaultShellmapScript(); } + } + + class DefaultShellmapScript : ITick + { + // Rude hack around the multiple-creation bug: + // wait long enough for the transient copies to die before starting + int initialDelay = 20; + public void Tick(Actor self) + { + // Another rude hack + Game.MoveViewport(new int2(85,65)); + + if (initialDelay > 0 && --initialDelay == 0) + Sound.PlayMusic("hell226m.aud"); + } + } +} diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index 23b62a198e..c85884d0bb 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -1,4 +1,4 @@ - + Debug @@ -90,6 +90,7 @@ + diff --git a/mods/ra/maps/shellmap/map.yaml b/mods/ra/maps/shellmap/map.yaml index d32007037e..a70d92c39b 100644 --- a/mods/ra/maps/shellmap/map.yaml +++ b/mods/ra/maps/shellmap/map.yaml @@ -415,4 +415,5 @@ Waypoints: Smudges: Rules: - + World: + DefaultShellmapScript: \ No newline at end of file