Unhardcode terrain types. Needs a bit more work re initialization and bridges

This commit is contained in:
Paul Chote
2010-06-26 10:55:29 +12:00
parent 8fbbaddce9
commit bf6b2da1a8
31 changed files with 138 additions and 3127 deletions

View File

@@ -126,7 +126,6 @@ namespace MapConverter
{Pair.New("cnc","WINTER"),Pair.New("win","winter.col")},
};
TerrainColorSet terrainTypeColors;
TileSet tileset;
public void ConvertIniMap(string iniFile)
{
@@ -154,16 +153,17 @@ namespace MapConverter
UnpackRATileData(ReadPackedSection(file.GetSection("MapPack")));
UnpackRAOverlayData(ReadPackedSection(file.GetSection("OverlayPack")));
ReadRATrees(file);
terrainTypeColors = new TerrainColorSet(fileMapping[Pair.New("ra",Map.Tileset)].Second);
tileset = new TileSet("tileSet.til","templates.ini",fileMapping[Pair.New("ra",Map.Tileset)].First);
// TODO: Fixme
//tileset = new TileSet("tileSet.til","templates.ini",fileMapping[Pair.New("ra",Map.Tileset)].First);
}
else // CNC
{
UnpackCncTileData(FileSystem.Open(iniFile.Substring(0,iniFile.Length-4)+".bin"));
ReadCncOverlay(file);
ReadCncTrees(file);
terrainTypeColors = new TerrainColorSet(fileMapping[Pair.New("cnc",Map.Tileset)].Second);
tileset = new TileSet("tileSet.til","templates.ini",fileMapping[Pair.New("cnc",Map.Tileset)].First);
// TODO: Fixme
//tileset = new TileSet("tileSet.til","templates.ini",fileMapping[Pair.New("cnc",Map.Tileset)].First);
}
LoadActors(file, "STRUCTURES");
@@ -373,31 +373,12 @@ namespace MapConverter
{
return s.Length <= maxLength ? s : s.Substring(0,maxLength );
}
public void SavePreviewImage(string filepath)
{
var xs = Map.TopLeft.X;
var ys = Map.TopLeft.Y;
var bitmap = new Bitmap(Map.Width, Map.Height);
for (var x = 0; x < Map.Width; x++)
for (var y = 0; y < Map.Height; y++)
bitmap.SetPixel(x, y, terrainTypeColors.ColorForTerrainType(tileset.GetTerrainType(Map.MapTiles[x+xs, y+ys])));
for (var x = 0; x < Map.Width; x++)
for (var y = 0; y < Map.Height; y++)
if (Map.MapResources[x+xs, y+ys].type > 0)
bitmap.SetPixel(x, y, terrainTypeColors.ColorForTerrainType(TerrainType.Ore));
bitmap.Save(filepath,ImageFormat.Png);
}
public void Save(string filepath)
{
Directory.CreateDirectory(filepath);
Map.Package = new Folder(filepath);
SavePreviewImage(Path.Combine(filepath,"preview.png"));
Map.Save(filepath);
}
}

View File

@@ -330,7 +330,7 @@ namespace OpenRA.Editor
surface1.Invalidate();
}
}
void SavePreviewImage(string filepath)
{
var Map = surface1.Map;
@@ -338,19 +338,15 @@ namespace OpenRA.Editor
var xs = Map.TopLeft.X;
var ys = Map.TopLeft.Y;
var terrainTypeColors = new TerrainColorSet(colors);
var bitmap = new Bitmap(Map.Width, Map.Height);
for (var x = 0; x < Map.Width; x++)
for (var y = 0; y < Map.Height; y++)
bitmap.SetPixel(x, y, terrainTypeColors.ColorForTerrainType(
tileset.GetTerrainType(Map.MapTiles[x + xs, y + ys])));
bitmap.SetPixel(x, y, tileset.Terrain[tileset.GetTerrainType(Map.MapTiles[x + xs, y + ys])].Color);
for (var x = 0; x < Map.Width; x++)
for (var y = 0; y < Map.Height; y++)
if (Map.MapResources[x + xs, y + ys].type > 0)
bitmap.SetPixel(x, y, terrainTypeColors.ColorForTerrainType(TerrainType.Ore));
bitmap.SetPixel(x, y, tileset.Terrain["Ore"].Color);
bitmap.Save(filepath, ImageFormat.Png);
}

View File

@@ -69,13 +69,22 @@ namespace OpenRA.FileFormats
if (x != null) x = x.Trim();
if( fieldType == typeof( int ) )
return int.Parse( x );
else if( fieldType == typeof( ushort ) )
return ushort.Parse( x );
else if (fieldType == typeof(float))
return float.Parse(x.Replace("%","")) * (x.Contains( '%' ) ? 0.01f : 1f);
else if (fieldType == typeof(string))
return x;
else if (fieldType == typeof(System.Drawing.Color))
{
var parts = x.Split(',');
return System.Drawing.Color.FromArgb(int.Parse(parts[0]), int.Parse(parts[1]), int.Parse(parts[2]));
}
else if (fieldType.IsEnum)
return Enum.Parse(fieldType, x, true);

View File

@@ -1,51 +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 System.Collections.Generic;
using System.Drawing;
using System.Linq;
namespace OpenRA.FileFormats
{
public class TerrainColorSet
{
readonly Dictionary<TerrainType, Color> colors;
public TerrainColorSet(string colorFile)
{
var lines = FileSystem.Open(colorFile).ReadAllLines()
.Select(l => l.Trim())
.Where(l => !l.StartsWith(";") && l.Length > 0);
colors = lines.Select(l => l.Split('=')).ToDictionary(
kv => (TerrainType)Enum.Parse(typeof(TerrainType), kv[0]),
kv => ColorFromRgbString(kv[1]));
}
static Color ColorFromRgbString(string s)
{
var parts = s.Split(',');
return Color.FromArgb(int.Parse(parts[0]), int.Parse(parts[1]), int.Parse(parts[2]));
}
public Color ColorForTerrainType(TerrainType type) { return colors[type]; }
}
}

View File

@@ -21,73 +21,78 @@
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Drawing;
namespace OpenRA.FileFormats
{
public class TerrainTypeInfo
{
public string Type;
public bool Buildable = true;
public bool AcceptSmudge = true;
public Color Color;
public TerrainTypeInfo(MiniYaml my)
{
FieldLoader.Load(this, my);
}
}
public class TileTemplate
{
public ushort Id;
public string Image;
public int2 Size;
public string Bridge;
public float HP;
public bool PickAny;
public Dictionary<int, string> Tiles = new Dictionary<int, string>();
static List<string> fields = new List<string>() {"Id", "Image", "Size", "Bridge", "HP", "PickAny"};
public TileTemplate(Dictionary<string,MiniYaml> my)
{
FieldLoader.LoadFields(this, my, fields);
}
}
public class TileSet
{
public readonly Dictionary<ushort, Terrain> tiles = new Dictionary<ushort, Terrain>();
public readonly Walkability Walkability;
public readonly Dictionary<ushort, TileTemplate> walk
= new Dictionary<ushort, TileTemplate>();
string NextLine( StreamReader reader )
public readonly Dictionary<string, TerrainTypeInfo> Terrain = new Dictionary<string, TerrainTypeInfo>();
public readonly Dictionary<ushort, Terrain> Tiles = new Dictionary<ushort, Terrain>();
public readonly Dictionary<ushort, TileTemplate> Templates = new Dictionary<ushort, TileTemplate>();
public TileSet( string tilesetFile, string suffix )
{
string ret;
do
var yaml = MiniYaml.FromFile(tilesetFile);
// TerrainTypes
foreach (var tt in yaml["Terrain"].Nodes)
{
ret = reader.ReadLine();
if( ret == null )
return null;
ret = ret.Trim();
var t = new TerrainTypeInfo(tt.Value);
Terrain.Add(t.Type, t);
}
while( ret.Length == 0 || ret[ 0 ] == ';' );
return ret;
}
public TileSet( string tilesetFile, string templatesFile, string suffix )
{
Walkability = new Walkability(templatesFile);
char tileSetChar = char.ToUpperInvariant( suffix[ 0 ] );
StreamReader tileIdFile = new StreamReader( FileSystem.Open(tilesetFile) );
while( true )
// Templates
foreach (var tt in yaml["Templates"].Nodes)
{
string tileSetStr = NextLine( tileIdFile );
string countStr = NextLine( tileIdFile );
string startStr = NextLine( tileIdFile );
string pattern = NextLine( tileIdFile );
if( tileSetStr == null || countStr == null || startStr == null || pattern == null )
break;
if( tileSetStr.IndexOf( tileSetChar.ToString() ) == -1 )
continue;
int count = int.Parse( countStr );
int start = int.Parse( startStr, NumberStyles.HexNumber );
for( int i = 0 ; i < count ; i++ )
// Info
var t = new TileTemplate(tt.Value.Nodes);
Templates.Add(t.Id, t);
// Artwork
using( Stream s = FileSystem.Open( t.Image + "." + suffix ) )
{
string tilename = string.Format(pattern, i + 1);
if (!walk.ContainsKey((ushort)(start + i)))
walk.Add((ushort)(start + i), Walkability.GetTileTemplate(tilename));
using( Stream s = FileSystem.Open( tilename + "." + suffix ) )
{
if( !tiles.ContainsKey( (ushort)( start + i ) ) )
tiles.Add( (ushort)( start + i ), new Terrain( s ) );
}
if( !Tiles.ContainsKey( t.Id ) )
Tiles.Add( t.Id, new Terrain( s ) );
}
}
tileIdFile.Close();
}
public byte[] GetBytes(TileReference<ushort,byte> r)
{
Terrain tile;
if( tiles.TryGetValue( r.type, out tile ) )
if( Tiles.TryGetValue( r.type, out tile ) )
return tile.TileBitmapBytes[ r.image ];
byte[] missingTile = new byte[ 24 * 24 ];
@@ -97,12 +102,13 @@ namespace OpenRA.FileFormats
return missingTile;
}
public TerrainType GetTerrainType(TileReference<ushort, byte> r)
public string GetTerrainType(TileReference<ushort, byte> r)
{
var tt = walk[r.type].TerrainType;
TerrainType ret;
var tt = Templates[r.type].Tiles;
string ret;
if (!tt.TryGetValue(r.image, out ret))
return 0;// Default zero (walkable)
return "Clear";// Default zero (walkable)
return ret;
}
}

View File

@@ -1,97 +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 System.Collections.Generic;
using System.Linq;
namespace OpenRA.FileFormats
{
public enum TerrainType : byte
{
Clear = 0,
Water = 1,
Road = 2,
Rock = 3,
Tree = 4,
River = 5,
Rough = 6,
Wall = 7,
Beach = 8,
Ore = 9,
Special = 10,
}
public class TileTemplate
{
public int Index; // not valid for `interior` stuff. only used for bridges.
public string Name;
public int2 Size;
public string Bridge;
public float HP;
public bool PickAny;
public Dictionary<int, TerrainType> TerrainType = new Dictionary<int, TerrainType>();
}
public class Walkability
{
Dictionary<string, TileTemplate> templates
= new Dictionary<string,TileTemplate>();
public Walkability(string templatesFile)
{
var file = new IniFile( FileSystem.Open( templatesFile ) );
foreach (var section in file.Sections)
{
var name = section.GetValue("Name", null).ToLowerInvariant();
if (!section.Contains("width") || !section.Contains("height"))
throw new InvalidOperationException("no width/height for template `{0}`".F(name));
var tile = new TileTemplate
{
Name = name,
Size = new int2(
int.Parse(section.GetValue("width", "--")),
int.Parse(section.GetValue("height", "--"))),
TerrainType = section
.Where(p => p.Key.StartsWith("tiletype"))
.ToDictionary(
p => int.Parse(p.Key.Substring(8)),
p => (TerrainType)Enum.Parse(typeof(TerrainType),p.Value)),
Bridge = section.GetValue("bridge", null),
HP = float.Parse(section.GetValue("hp", "0")),
PickAny = (bool)FieldLoader.GetValue(typeof(bool), section.GetValue("pickany", "no")),
};
tile.Index = -1;
int.TryParse(section.Name.Substring(3), out tile.Index);
templates[tile.Name] = tile;
}
}
public TileTemplate GetTileTemplate(string terrainName)
{
return templates[terrainName];
}
}
}

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -80,12 +80,10 @@
<Compile Include="Map\ActorReference.cs" />
<Compile Include="Map\Map.cs" />
<Compile Include="Map\TileReference.cs" />
<Compile Include="Map\Walkability.cs" />
<Compile Include="Map\Terrain.cs" />
<Compile Include="Primitives\Cache.cs" />
<Compile Include="Primitives\float2.cs" />
<Compile Include="Primitives\Pair.cs" />
<Compile Include="Map\TerrainColorSet.cs" />
<Compile Include="Map\TileSet.cs" />
<Compile Include="Primitives\PriorityQueue.cs" />
<Compile Include="Primitives\Lazy.cs" />

View File

@@ -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(

View File

@@ -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);
}
}
}

View File

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

View File

@@ -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); }
}
}

View File

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

View File

@@ -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" />

View File

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

View File

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

View File

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

View File

@@ -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}" );

View File

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

View File

@@ -39,7 +39,7 @@ namespace OpenRA.Mods.RA
public object Create(ActorInitializer init) { return new Bridge(init.self); }
}
class Bridge: IRender, INotifyDamage
class Bridge //: IRender, INotifyDamage
{
Dictionary<int2, int> Tiles;
List<Dictionary<int2, Sprite>> TileSprites = new List<Dictionary<int2,Sprite>>();
@@ -49,7 +49,7 @@ namespace OpenRA.Mods.RA
Bridge northNeighbour, southNeighbour;
public Bridge(Actor self) { this.self = self; self.RemoveOnDeath = false; }
static string cachedTileset;
static Cache<TileReference<ushort,byte>, Sprite> sprites;
@@ -80,6 +80,7 @@ namespace OpenRA.Mods.RA
public int StateFromTemplate(TileTemplate t)
{
/*
var info = self.Info.Traits.Get<BridgeInfo>();
if (info.UseAlternateNames)
{
@@ -89,19 +90,23 @@ namespace OpenRA.Mods.RA
}
else
return t.Name[t.Name.Length - 1] - 'a';
*/
return 0;
}
public string NameFromState(TileTemplate t, int state)
{
var info = self.Info.Traits.Get<BridgeInfo>();
/*var info = self.Info.Traits.Get<BridgeInfo>();
if (info.UseAlternateNames)
return t.Bridge + new[] { "", "h", "d" }[state];
else
return t.Bridge + (char)(state + 'a');
return t.Bridge + (char)(state + 'a');*/
return "";
}
public void SetTiles(World world, TileTemplate template, Dictionary<int2, int> replacedTiles)
{
/*
Tiles = replacedTiles;
state = StateFromTemplate(template);
@@ -125,12 +130,14 @@ namespace OpenRA.Mods.RA
}
self.Health = (int)(self.GetMaxHP() * template.HP);
*/
}
public string GetTerrainType(int2 cell)
{
return "";
// Ugly hack until terraintypes are converted from enums
return Enum.GetName( typeof(TerrainType), Templates[state].TerrainType[Tiles[cell]]);
//return Enum.GetName( typeof(TerrainType), Templates[state].TerrainType[Tiles[cell]]);
}
static bool IsIntact(Bridge b)

View File

@@ -49,7 +49,7 @@ namespace OpenRA.Mods.RA
void ConvertBridgeToActor(World w, int i, int j)
{
Log.Write("debug", "Converting bridge at {0} {1}", i, j);
/*
var tile = w.Map.MapTiles[i, j].type;
var image = w.Map.MapTiles[i, j].image;
var template = w.TileSet.walk[tile];
@@ -88,18 +88,20 @@ namespace OpenRA.Mods.RA
br.SetTiles(w, template, replacedTiles);
}
*/
}
public string GetTerrainType(int2 cell)
{
if (bridges[ cell.X, cell.Y ] != null)
return bridges[ cell.X, cell.Y ].GetTerrainType(cell);
/*if (bridges[ cell.X, cell.Y ] != null)
return bridges[ cell.X, cell.Y ].GetTerrainType(cell);*/
return null;
}
static bool IsBridge(World w, ushort t)
{
return w.TileSet.walk[t].Bridge != null;
return false;
//return w.TileSet.walk[t].Bridge != null;
}
public void WorldLoaded(World w)

View File

@@ -91,7 +91,7 @@ namespace OpenRA.Mods.RA
if (++ticks >= self.Info.Traits.Get<CrateInfo>().Lifetime * 25)
self.World.AddFrameEndTask(w => w.Remove(self));
var seq = self.World.GetTerrainType(cell) == TerrainType.Water ? "water" : "idle";
var seq = self.World.GetTerrainType(cell) == "Water" ? "water" : "idle";
if (seq != self.traits.Get<RenderSimple>().anim.CurrentSequence.Name)
self.traits.Get<RenderSimple>().anim.PlayRepeating(seq);
}

View File

@@ -70,10 +70,8 @@ namespace OpenRA.Mods.RA
var p = self.World.ChooseRandomCell(self.World.SharedRandom);
// Is this valid terrain?
// Ugly hack until terraintypes are converted from enums
var terrainType = self.World.TileSet.GetTerrainType(self.World.Map.MapTiles[p.X, p.Y]);
var terrain = Enum.GetName( typeof(TerrainType), terrainType);
if (!(inWater ? info.ValidWater : info.ValidGround).Contains(terrain)) continue;
if (!(inWater ? info.ValidWater : info.ValidGround).Contains(terrainType)) continue;
// Don't drop on any actors
if (self.World.WorldActor.traits.Get<BuildingInfluence>().GetBuildingAt(p) != null) continue;

View File

@@ -70,10 +70,8 @@ namespace OpenRA.Mods.RA
var p = self.World.ChooseRandomCell(self.World.SharedRandom);
// Is this valid terrain?
// Ugly hack until terraintypes are converted from enums
var terrainType = self.World.TileSet.GetTerrainType(self.World.Map.MapTiles[p.X, p.Y]);
var terrain = Enum.GetName( typeof(TerrainType), terrainType);
if (!(inWater ? info.ValidWater : info.ValidGround).Contains(terrain)) continue;
if (!(inWater ? info.ValidWater : info.ValidGround).Contains(terrainType)) continue;
// Don't spawn on any actors
if (self.World.WorldActor.traits.Get<BuildingInfluence>().GetBuildingAt(p) != null) continue;

View File

@@ -1,13 +0,0 @@
; Minimap colors for cnc DESERT theater
; Format: terraintype=R,G,B
Clear=134,95,69
Water=93,165,206
Road=168,123,83
Rock=116,90,63
Tree=28,32,36
River=111,132,139
Rough=68,68,60
Wall=208,192,160
Beach=176,156,120
Ore=161,226,28
Special=124,124,124

View File

@@ -48,8 +48,5 @@ Weapons:
Voices:
mods/cnc/voices.yaml:
Terrain:
mods/cnc/terrain.yaml
ShellmapUid:a0e5a8a3cb4e7fb82a08e8d768c32d480f0ec152

View File

@@ -54,23 +54,17 @@ World:
Name:Desert
Theater:DESERT
Suffix:des
Templates:templates.ini
Tileset:tileSet.til
MapColors:desert.col
Tileset:mods/cnc/tileset-des.yaml
Theater@WINTER:
Name:Winter
Theater:WINTER
Suffix:win
Templates:templates.ini
Tileset:tileSet.til
MapColors:winter.col
Tileset:mods/cnc/tileset-win.yaml
Theater@TEMPERAT:
Name:Temperate
Theater:TEMPERAT
Suffix:tem
Templates:templates.ini
Tileset:tileSet.til
MapColors:temperat.col
Tileset:mods/cnc/tileset-tem.yaml
PaletteFromFile@terrain_desert:
Name: terrain
Theater: desert

View File

@@ -1,13 +0,0 @@
; Minimap colors for cnc TEMPERAT theater
; Format: terraintype,R,G,B
Clear=40,68,40
Water=92,116,164
Road=88,116,116
Rock=68,68,60
Tree=28,32,36
River=92,140,180
Rough=68,68,60
Wall=208,192,160
Beach=176,156,120
Ore=161,226,28
Special=124,124,124

File diff suppressed because it is too large Load Diff

View File

@@ -1,38 +0,0 @@
Clear:
Buildable: yes
Rough:
Buildable: no
Road:
Buildable: yes
Tree:
Buildable: no
AcceptSmudge: no
Water:
Buildable: no
AcceptSmudge: no
Rock:
Buildable: no
AcceptSmudge: no
Wall:
Buildable: no
Ore:
Buildable: no
Beach:
Buildable: no
AcceptSmudge: no
River:
Buildable: no
AcceptSmudge: no
Special:
Buildable: no
AcceptSmudge: no

View File

@@ -1,589 +0,0 @@
; clear ground
DTW
1
00ff
clear1
; clear ground
DTW
1
ffff
clear1
; clear ground
DTW
1
0000
clear1
; plain water
DTW
1
0001
w1
-TW
1
0002
w2
; Coastline
-TW
5
0003
sh{0}
-TW
1
0008
sh11
-TW
1
0009
sh12
-TW
1
000A
sh13
-TW
1
000B
sh14
-TW
1
000C
sh15
; Cliffs
DTW
38
000D
s{0:00}
; More Coast
-TW
1
0033
sh32
-TW
1
0034
sh33
D--
1
0035
sh20
D--
1
0036
sh21
D--
1
0037
sh22
D--
1
0038
sh23
; Bushes
D--
10
0039
br{0}
; Bones/Wall/Mud/UFO/Rock
DT-
4
0043
p{0:00}
D--
1
0047
p05
D--
1
0048
p06
DTW
1
0049
p07
-TW
1
004A
p08
; Ford WU
-TW
1
004B
sh16
; Water
DTW
1
004C
sh17
; Water
DTW
1
004D
sh18
D--
1
004E
sh19
; Destroyed house
-TW
1
004F
p13
; Walls
-TW
1
0050
p14
; Snow
--W
1
0051
p15
; Rocks
DTW
2
0052
b{0}
-TW
1
0054
b3
D--
1
0055
b4
D--
1
0056
b5
D--
1
0057
b6
; More coast
-TW
1
0058
sh6
-TW
1
0059
sh7
-TW
1
005A
sh8
-TW
1
005B
sh9
-TW
1
005C
sh10
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ROADS
; roads
DTW
43
005d
d{0:00}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; RIVERS
; rivers
-TW
13
0088
rv{0:00}
D--
1
0095
rv14
D--
1
0096
rv15
D--
1
0097
rv16
D--
1
0098
rv17
D--
1
0099
rv18
D--
1
009A
rv19
D--
1
009B
rv20
D--
1
009C
rv21
D--
1
009D
rv22
D--
1
009E
rv23
D--
1
009F
rv24
D--
1
00A0
rv25
; River Crossing
DTW
2
00A1
ford{0}
; Waterfalls
DTW
2
00A3
falls{0}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; BRIDGES
; short bridge "/"
-TW
1
00A5
bridge1
; short bridge "/" (destroyed)
-TW
1
00A6
bridge1d
; short bridge "\"
-TW
1
00A7
bridge2
; short bridge "\" (destroyed)
-TW
1
00A8
bridge2d
; desert short bridge "/"
D--
1
00A9
bridge3
; desert short bridge "/" (destroyed)
D--
1
00AA
bridge3d
; desert short bridge "\"
D--
1
00AB
bridge4
; desert short bridge "\" (destroyed)
D--
1
00AC
bridge4d
; Desert coast
D--
1
00AD
sh24
D--
1
00AE
sh25
D--
1
00AF
sh26
D--
1
00B0
sh27
D--
1
00B1
sh28
D--
1
00B2
sh29
D--
1
00B3
sh30
D--
1
00B4
sh31
; Snow
--W
1
00B5
p16
--W
1
00B6
p17
--W
1
00B7
p18
--W
1
00B8
p19
--W
1
00B9
p20
; More coast
-TW
1
00BA
sh34
-TW
1
00BB
sh35
D--
1
00BC
sh36
D--
1
00BD
sh37
D--
1
00BE
sh38
D--
1
00BF
sh39
D--
1
00C0
sh40
D--
1
00C1
sh41
D--
1
00C2
sh42
D--
1
00C3
sh43
D--
1
00C4
sh44
D--
1
00C5
sh45
D--
1
00C6
sh46
D--
1
00C7
sh47
D--
1
00C8
sh48
D--
1
00C9
sh49
D--
1
00CA
sh50
D--
1
00CB
sh51
D--
1
00CC
sh52
D--
1
00CD
sh53
D--
1
00CE
sh54
D--
1
00CF
sh55
D--
1
00D0
sh56
D--
1
00D1
sh57
D--
1
00D2
sh58
D--
1
00D3
sh59
D--
1
00D4
sh60
D--
1
00D5
sh61
D--
1
00D6
sh62
D--
1
00D7
sh63
; bogus
TS-
1
fffe
bogus

View File

@@ -1,13 +0,0 @@
; Minimap colors for cnc WINTER theater
; Format: terraintype,R,G,B
Clear=40,68,40
Water=92,116,164
Road=88,116,116
Rock=68,68,60
Tree=28,32,36
River=92,140,180
Rough=68,68,60
Wall=208,192,160
Beach=176,156,120
Ore=161,226,28
Special=124,124,124