Basic (zomg hacked) shellmap script [commit hacked by chrisf to remove 3MB AUD]

This commit is contained in:
Paul Chote
2010-04-09 23:20:18 +12:00
committed by Chris Forbes
parent 0e459877c2
commit 803076caf9
8 changed files with 95 additions and 8 deletions

View File

@@ -44,8 +44,12 @@ namespace OpenRA.FileFormats
public Dictionary<string, ActorReference> Actors = new Dictionary<string, ActorReference>(); public Dictionary<string, ActorReference> Actors = new Dictionary<string, ActorReference>();
public List<SmudgeReference> Smudges = new List<SmudgeReference>(); public List<SmudgeReference> Smudges = new List<SmudgeReference>();
public Dictionary<string, int2> Waypoints = new Dictionary<string, int2>(); public Dictionary<string, int2> Waypoints = new Dictionary<string, int2>();
public Dictionary<string, MiniYaml> Rules = new Dictionary<string, MiniYaml>();
// Rules overrides
public Dictionary<string, MiniYaml> Rules = new Dictionary<string, MiniYaml>();
public Dictionary<string, MiniYaml> Weapons = new Dictionary<string, MiniYaml>();
public Dictionary<string, MiniYaml> Voices = new Dictionary<string, MiniYaml>();
public Dictionary<string, MiniYaml> Terrain = new Dictionary<string, MiniYaml>();
// Binary map data // Binary map data
public byte TileFormat = 1; public byte TileFormat = 1;
public int2 MapSize; public int2 MapSize;

View File

@@ -135,8 +135,6 @@ namespace OpenRA
SheetBuilder.Initialize(renderer); SheetBuilder.Initialize(renderer);
LoadModPackages(manifest); LoadModPackages(manifest);
Timer.Time( "load assemblies, packages: {0}" ); Timer.Time( "load assemblies, packages: {0}" );
Rules.LoadRules(manifest);
Timer.Time( "load rules: {0}" );
Game.packageChangePending = false; Game.packageChangePending = false;
LoadMap(manifest.ShellmapUid); 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. world = null; // trying to access the old world will NRE, rather than silently doing it wrong.
ChromeProvider.Initialize(manifest.Chrome); ChromeProvider.Initialize(manifest.Chrome);
world = new World(mapName); world = new World(manifest,mapName);
Timer.Time( "world: {0}" ); Timer.Time( "world: {0}" );
SequenceProvider.Initialize(manifest.Sequences); SequenceProvider.Initialize(manifest.Sequences);
@@ -171,6 +169,11 @@ namespace OpenRA
Debug("Map change {0} -> {1}".F(Game.mapName, mapName)); 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) internal static void Initialize(Renderer renderer, int2 clientSize, int localPlayer, Controller controller)
{ {
Game.renderer = renderer; Game.renderer = renderer;

View File

@@ -49,13 +49,35 @@ namespace OpenRA
TechTree = new TechTree(); TechTree = new TechTree();
} }
static Dictionary<string, T> LoadYamlRules<T>(string[] files, Func<KeyValuePair<string, MiniYaml>, Dictionary<string, MiniYaml>, T> f) static Dictionary<string, T> LoadYamlRules<T>(string[] files, Func<KeyValuePair<string, MiniYaml>, Dictionary<string, MiniYaml>, T> f)
{ {
var y = files.Select(a => MiniYaml.FromFile(a)).Aggregate(MiniYaml.Merge); var y = files.Select(a => MiniYaml.FromFile(a)).Aggregate(MiniYaml.Merge);
return y.ToDictionary(kv => kv.Key.ToLowerInvariant(), kv => f(kv, y)); 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<string, T> LoadYamlRules<T>(string[] files, Dictionary<string,MiniYaml>dict, Func<KeyValuePair<string, MiniYaml>, Dictionary<string, MiniYaml>, 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<string> Categories() public static IEnumerable<string> Categories()
{ {
return Info.Values.Select( x => x.Category ).Distinct().Where( g => g != null ).ToList(); return Info.Values.Select( x => x.Category ).Distinct().Where( g => g != null ).ToList();

View File

@@ -166,6 +166,11 @@ namespace OpenRA.Graphics
return (1 / 24.0f) * (new float2(mi.Location.X, mi.Location.Y) + Location); 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<Actor> actors) public void Center(IEnumerable<Actor> actors)
{ {
if (!actors.Any()) return; if (!actors.Any()) return;

View File

@@ -75,7 +75,7 @@ namespace OpenRA
public readonly WorldRenderer WorldRenderer; public readonly WorldRenderer WorldRenderer;
internal readonly Minimap Minimap; internal readonly Minimap Minimap;
public World(string mapUid) public World(Manifest manifest, string mapUid)
{ {
Timer.Time( "----World.ctor" ); Timer.Time( "----World.ctor" );
@@ -83,9 +83,14 @@ namespace OpenRA
throw new InvalidDataException("Cannot find map with Uid {0}".F(mapUid)); throw new InvalidDataException("Cannot find map with Uid {0}".F(mapUid));
Map = new Map( Game.AvailableMaps[mapUid].Package ); Map = new Map( Game.AvailableMaps[mapUid].Package );
customTerrain = new ICustomTerrain[Map.MapSize.X, Map.MapSize.Y]; customTerrain = new ICustomTerrain[Map.MapSize.X, Map.MapSize.Y];
Timer.Time( "new Map: {0}" ); Timer.Time( "new Map: {0}" );
Rules.LoadRules(manifest,Map);
Timer.Time( "load rules: {0}" );
var theaterInfo = Rules.Info["world"].Traits.WithInterface<TheaterInfo>() var theaterInfo = Rules.Info["world"].Traits.WithInterface<TheaterInfo>()
.FirstOrDefault(t => t.Theater == Map.Theater); .FirstOrDefault(t => t.Theater == Map.Theater);
TileSet = new TileSet(theaterInfo.Tileset, theaterInfo.Templates, theaterInfo.Suffix); TileSet = new TileSet(theaterInfo.Tileset, theaterInfo.Templates, theaterInfo.Suffix);

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
#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");
}
}
}

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -90,6 +90,7 @@
<Compile Include="Thief.cs" /> <Compile Include="Thief.cs" />
<Compile Include="Crates\ResetRadarCrateAction.cs" /> <Compile Include="Crates\ResetRadarCrateAction.cs" />
<Compile Include="TraitsInterfaces.cs" /> <Compile Include="TraitsInterfaces.cs" />
<Compile Include="DefaultShellmapScript.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj"> <ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">

View File

@@ -415,4 +415,5 @@ Waypoints:
Smudges: Smudges:
Rules: Rules:
World:
DefaultShellmapScript: