Unhardcode terrain types. Needs a bit more work re initialization and bridges
This commit is contained in:
@@ -48,7 +48,8 @@ namespace OpenRA
|
||||
if (!world.Map.IsInMap(targetTile))
|
||||
return;
|
||||
|
||||
var isWater = world.GetTerrainType(targetTile) == TerrainType.Water;
|
||||
// Todo: Unhardcode "Water" terraintype reference
|
||||
var isWater = world.GetTerrainType(targetTile) == "Water";
|
||||
|
||||
if (warhead.Explosion != 0)
|
||||
world.AddFrameEndTask(
|
||||
|
||||
@@ -660,65 +660,6 @@ namespace OpenRA
|
||||
file.Write(id);
|
||||
file.Flush();
|
||||
file.Close();
|
||||
}
|
||||
|
||||
public static void ConvertTileset(OpenRA.FileFormats.TileSet Tileset, OpenRA.Traits.TheaterInfo Info, string outFile)
|
||||
{
|
||||
List<string> SimpleFields = new List<string>() {
|
||||
"Name", "Size", "PickAny", "Bridge", "HP"
|
||||
};
|
||||
OpenRA.FileFormats.TerrainColorSet colors = new TerrainColorSet(Info.MapColors);
|
||||
|
||||
Dictionary<string, MiniYaml> root = new Dictionary<string, MiniYaml>();
|
||||
Dictionary<string, MiniYaml> terrainYaml = new Dictionary<string, MiniYaml>();
|
||||
|
||||
for (TerrainType t = TerrainType.Clear; t <= TerrainType.Special; t++)
|
||||
{
|
||||
Dictionary<string, MiniYaml> nodeYaml = new Dictionary<string, MiniYaml>();
|
||||
string type = Enum.GetName( typeof(TerrainType), t);
|
||||
nodeYaml.Add("Type", new MiniYaml(type, null));
|
||||
nodeYaml.Add("Buildable", new MiniYaml(Rules.TerrainTypes[t].Buildable.ToString(), null));
|
||||
nodeYaml.Add("AcceptSmudge", new MiniYaml(Rules.TerrainTypes[t].AcceptSmudge.ToString(), null));
|
||||
|
||||
var color = colors.ColorForTerrainType(t);
|
||||
nodeYaml.Add("Color", new MiniYaml("{0}, {1}, {2}".F(color.R, color.G, color.B), null));
|
||||
terrainYaml.Add("TerrainType@{0}".F(type), new MiniYaml(null, nodeYaml));
|
||||
}
|
||||
|
||||
root.Add("Terrain", new MiniYaml(null, terrainYaml));
|
||||
|
||||
Dictionary<string, MiniYaml> templateYaml = new Dictionary<string, MiniYaml>();
|
||||
foreach(var w in Tileset.walk)
|
||||
{
|
||||
Dictionary<string, MiniYaml> nodeYaml = new Dictionary<string, MiniYaml>();
|
||||
nodeYaml.Add("Id", new MiniYaml(w.Key.ToString(), null));
|
||||
|
||||
foreach (var field in SimpleFields)
|
||||
{
|
||||
var save = field;
|
||||
System.Reflection.FieldInfo f = w.Value.GetType().GetField(field);
|
||||
if (f.GetValue(w.Value) == null) continue;
|
||||
|
||||
if (field == "Name")
|
||||
save = "Image";
|
||||
|
||||
if (field == "HP" && w.Value.HP == 0)
|
||||
continue;
|
||||
|
||||
if (field == "HP")
|
||||
save = "Strength";
|
||||
|
||||
if (field == "PickAny" && !w.Value.PickAny)
|
||||
continue;
|
||||
|
||||
nodeYaml.Add(save, new MiniYaml(FieldSaver.FormatValue(w.Value, f), null));
|
||||
}
|
||||
|
||||
nodeYaml.Add("Tiles", MiniYaml.FromDictionary<int, TerrainType>(w.Value.TerrainType));
|
||||
templateYaml.Add("Template@{0}".F(w.Key), new MiniYaml(null, nodeYaml));
|
||||
}
|
||||
root.Add("Templates", new MiniYaml(null, templateYaml));
|
||||
root.WriteToFile(outFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,6 @@ namespace OpenRA
|
||||
public static Dictionary<string, WeaponInfo> Weapons;
|
||||
public static Dictionary<string, VoiceInfo> Voices;
|
||||
public static Dictionary<string, MusicInfo> Music;
|
||||
public static Dictionary<TerrainType, TerrainCost> TerrainTypes;
|
||||
|
||||
public static void LoadRules(Manifest m, Map map)
|
||||
{
|
||||
@@ -48,9 +47,6 @@ namespace OpenRA
|
||||
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));
|
||||
Music = LoadYamlRules(m.Music, map.Music, (k, _) => new MusicInfo(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();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
#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 System;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Graphics;
|
||||
|
||||
namespace OpenRA.GameRules
|
||||
{
|
||||
public class TerrainCost
|
||||
{
|
||||
public readonly bool Buildable = true;
|
||||
public readonly bool AcceptSmudge = true;
|
||||
|
||||
public TerrainCost(MiniYaml y) { FieldLoader.Load(this, y); }
|
||||
}
|
||||
}
|
||||
@@ -72,12 +72,6 @@ namespace OpenRA.Graphics
|
||||
return new Rectangle(m.TopLeft.X - dw, m.TopLeft.Y - dh, size, size);
|
||||
}
|
||||
|
||||
static Cache<string, TerrainColorSet> terrainTypeColors = new Cache<string, TerrainColorSet>(
|
||||
theater =>
|
||||
{
|
||||
return new TerrainColorSet(Rules.Info["world"].Traits.WithInterface<TheaterInfo>().FirstOrDefault(t => t.Theater == theater).MapColors);
|
||||
});
|
||||
|
||||
static Color shroudColor;
|
||||
|
||||
public void InvalidateOre() { oreLayer = null; }
|
||||
@@ -85,11 +79,15 @@ namespace OpenRA.Graphics
|
||||
public static Bitmap RenderTerrainBitmap(Map map, TileSet tileset)
|
||||
{
|
||||
var terrain = new Bitmap(map.MapSize.X, map.MapSize.Y);
|
||||
|
||||
for (var x = 0; x < map.MapSize.X; x++)
|
||||
for (var y = 0; y < map.MapSize.Y; y++)
|
||||
{
|
||||
var type = tileset.GetTerrainType(map.MapTiles[x, y]);
|
||||
terrain.SetPixel(x, y, map.IsInMap(x, y)
|
||||
? Color.FromArgb(alpha, terrainTypeColors[map.Theater].ColorForTerrainType(tileset.GetTerrainType(map.MapTiles[x, y])))
|
||||
? Color.FromArgb(alpha, tileset.Terrain[type].Color)
|
||||
: shroudColor);
|
||||
}
|
||||
return terrain;
|
||||
}
|
||||
|
||||
@@ -102,11 +100,14 @@ namespace OpenRA.Graphics
|
||||
{
|
||||
var res = world.WorldActor.traits.Get<ResourceLayer>();
|
||||
|
||||
// This is an ugly hack
|
||||
Color oreColor = world.TileSet.Terrain["Ore"].Color;
|
||||
|
||||
oreLayer = new Bitmap(terrain);
|
||||
for (var x = world.Map.TopLeft.X; x < world.Map.BottomRight.X; x++)
|
||||
for (var y = world.Map.TopLeft.Y; y < world.Map.BottomRight.Y; y++)
|
||||
if (res.GetResource(new int2(x,y)) != null)
|
||||
oreLayer.SetPixel(x, y, Color.FromArgb(alpha, terrainTypeColors[world.Map.Theater].ColorForTerrainType(TerrainType.Ore)));
|
||||
oreLayer.SetPixel(x, y, Color.FromArgb(alpha, oreColor));
|
||||
}
|
||||
|
||||
if (!world.GameHasStarted || !world.Queries.OwnedBy[world.LocalPlayer].WithTrait<ProvidesRadar>().Any())
|
||||
@@ -133,9 +134,12 @@ namespace OpenRA.Graphics
|
||||
continue;
|
||||
}
|
||||
var b = world.WorldActor.traits.Get<BuildingInfluence>().GetBuildingAt(new int2(x, y));
|
||||
|
||||
// This is an even worse hack than the ore!
|
||||
var treeColor = world.TileSet.Terrain["tree"].Color;
|
||||
if (b != null)
|
||||
*(c + (y * bitmapData.Stride >> 2) + x) =
|
||||
(b.Owner != null ? Color.FromArgb(alpha, b.Owner.Color) : Color.FromArgb(alpha, terrainTypeColors[world.Map.Theater].ColorForTerrainType(TerrainType.Tree))).ToArgb();
|
||||
(b.Owner != null ? Color.FromArgb(alpha, b.Owner.Color) : Color.FromArgb(alpha, treeColor)).ToArgb();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -177,7 +177,6 @@
|
||||
<Compile Include="Graphics\Sprite.cs" />
|
||||
<Compile Include="Graphics\SpriteRenderer.cs" />
|
||||
<Compile Include="Graphics\SpriteSheetBuilder.cs" />
|
||||
<Compile Include="GameRules\TerrainCost.cs" />
|
||||
<Compile Include="Graphics\TerrainRenderer.cs" />
|
||||
<Compile Include="Traits\Activities\Move.cs" />
|
||||
<Compile Include="Traits\Activities\Turn.cs" />
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace OpenRA.Traits
|
||||
{
|
||||
public class MobileInfo : ITraitInfo, ITraitPrerequisite<UnitInfo>
|
||||
{
|
||||
public readonly TerrainType[] TerrainTypes;
|
||||
public readonly string[] TerrainTypes;
|
||||
public readonly float[] TerrainSpeeds;
|
||||
public readonly string[] Crushes;
|
||||
public readonly int WaitAverage = 60;
|
||||
@@ -41,8 +41,8 @@ namespace OpenRA.Traits
|
||||
{
|
||||
public readonly Actor self;
|
||||
public readonly MobileInfo Info;
|
||||
public readonly Dictionary<TerrainType,float> TerrainCost;
|
||||
public readonly Dictionary<TerrainType,float> TerrainSpeed;
|
||||
public readonly Dictionary<string,float> TerrainCost;
|
||||
public readonly Dictionary<string,float> TerrainSpeed;
|
||||
|
||||
[Sync]
|
||||
int2 __fromCell, __toCell;
|
||||
@@ -73,8 +73,8 @@ namespace OpenRA.Traits
|
||||
this.__fromCell = this.__toCell = init.location;
|
||||
AddInfluence();
|
||||
|
||||
TerrainCost = new Dictionary<TerrainType, float>();
|
||||
TerrainSpeed = new Dictionary<TerrainType, float>();
|
||||
TerrainCost = new Dictionary<string, float>();
|
||||
TerrainSpeed = new Dictionary<string, float>();
|
||||
|
||||
if (info.TerrainTypes.Count() != info.TerrainSpeeds.Count())
|
||||
throw new InvalidOperationException("Mobile TerrainType/TerrainSpeed length missmatch");
|
||||
@@ -196,7 +196,7 @@ namespace OpenRA.Traits
|
||||
.FirstOrDefault();
|
||||
|
||||
// Todo: Hack this until i finish migrating TerrainType to a string
|
||||
var type = (customTerrain != null) ? (TerrainType)Enum.Parse(typeof(TerrainType), customTerrain) : self.World.TileSet.GetTerrainType(self.World.Map.MapTiles[cell.X, cell.Y]);
|
||||
var type = (customTerrain != null) ? customTerrain : self.World.GetTerrainType(cell);
|
||||
var additionalCost = self.World.WorldActor.traits.WithInterface<ITerrainCost>()
|
||||
.Select( t => t.GetTerrainCost(cell, self) ).Sum();
|
||||
|
||||
@@ -216,7 +216,7 @@ namespace OpenRA.Traits
|
||||
.FirstOrDefault();
|
||||
|
||||
// Todo: Hack this until i finish migrating TerrainType to a string
|
||||
var type = (customTerrain != null) ? (TerrainType)Enum.Parse(typeof(TerrainType), customTerrain) : self.World.TileSet.GetTerrainType(self.World.Map.MapTiles[cell.X, cell.Y]);
|
||||
var type = (customTerrain != null) ? customTerrain : self.World.GetTerrainType(cell);
|
||||
|
||||
var modifier = self.traits
|
||||
.WithInterface<ISpeedModifier>()
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace OpenRA.Traits
|
||||
|
||||
public void AddSmudge(int2 loc)
|
||||
{
|
||||
if (!Rules.TerrainTypes[world.GetTerrainType(loc)].AcceptSmudge)
|
||||
if (!world.GetTerrainInfo(loc).AcceptSmudge)
|
||||
return;
|
||||
|
||||
// No smudge; create a new one
|
||||
|
||||
@@ -26,8 +26,6 @@ namespace OpenRA.Traits
|
||||
public readonly string Theater = null;
|
||||
public readonly string Suffix = null;
|
||||
public readonly string Tileset = null;
|
||||
public readonly string Templates = null;
|
||||
public readonly string MapColors = null;
|
||||
}
|
||||
|
||||
public class Theater {}
|
||||
|
||||
@@ -80,9 +80,8 @@ namespace OpenRA
|
||||
|
||||
var theaterInfo = Rules.Info["world"].Traits.WithInterface<TheaterInfo>()
|
||||
.FirstOrDefault(t => t.Theater == Map.Theater);
|
||||
TileSet = new TileSet(theaterInfo.Tileset, theaterInfo.Templates, theaterInfo.Suffix);
|
||||
TileSet = new TileSet(theaterInfo.Tileset, theaterInfo.Suffix);
|
||||
|
||||
Game.ConvertTileset(TileSet, theaterInfo, "tileset-"+theaterInfo.Suffix+".yaml");
|
||||
SpriteSheetBuilder.Initialize( Map );
|
||||
Timer.Time( "Tileset: {0}" );
|
||||
|
||||
|
||||
@@ -41,12 +41,11 @@ namespace OpenRA
|
||||
if (world.WorldActor.traits.Get<BuildingInfluence>().GetBuildingAt(a) != null) return false;
|
||||
if (world.WorldActor.traits.Get<UnitInfluence>().GetUnitsAt(a).Any(b => b != toIgnore)) return false;
|
||||
|
||||
// Todo: Unhardcode "Water" terraintype reference
|
||||
if (waterBound)
|
||||
return world.Map.IsInMap(a.X,a.Y) && GetTerrainType(world,a) == TerrainType.Water;
|
||||
return world.Map.IsInMap(a.X,a.Y) && GetTerrainType(world,a) == "Water";
|
||||
|
||||
return world.Map.IsInMap(a.X, a.Y) &&
|
||||
Rules.TerrainTypes[world.TileSet.GetTerrainType(world.Map.MapTiles[a.X, a.Y])]
|
||||
.Buildable;
|
||||
return world.Map.IsInMap(a.X, a.Y) && world.GetTerrainInfo(a).Buildable;
|
||||
}
|
||||
|
||||
public static IEnumerable<Actor> FindUnitsAtMouse(this World world, int2 mouseLocation)
|
||||
@@ -105,9 +104,14 @@ namespace OpenRA
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
public static TerrainType GetTerrainType(this World world, int2 cell)
|
||||
public static string GetTerrainType(this World world, int2 cell)
|
||||
{
|
||||
return (TerrainType)world.TileSet.GetTerrainType(world.Map.MapTiles[cell.X, cell.Y]);
|
||||
return world.TileSet.GetTerrainType(world.Map.MapTiles[cell.X, cell.Y]);
|
||||
}
|
||||
|
||||
public static TerrainTypeInfo GetTerrainInfo(this World world, int2 cell)
|
||||
{
|
||||
return world.TileSet.Terrain[world.GetTerrainType(cell)];
|
||||
}
|
||||
|
||||
public static bool CanPlaceBuilding(this World world, string name, BuildingInfo building, int2 topLeft, Actor toIgnore)
|
||||
|
||||
Reference in New Issue
Block a user