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 List<SmudgeReference> Smudges = new List<SmudgeReference>();
public Dictionary<string, int2> Waypoints = new Dictionary<string, int2>();
// 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
public byte TileFormat = 1;
public int2 MapSize;

View File

@@ -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)
{

View File

@@ -49,12 +49,34 @@ namespace OpenRA
TechTree = new TechTree();
}
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);
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()
{

View File

@@ -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<Actor> actors)
{

View File

@@ -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<TheaterInfo>()
.FirstOrDefault(t => t.Theater == Map.Theater);
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">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -90,6 +90,7 @@
<Compile Include="Thief.cs" />
<Compile Include="Crates\ResetRadarCrateAction.cs" />
<Compile Include="TraitsInterfaces.cs" />
<Compile Include="DefaultShellmapScript.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">

View File

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