Fix some stupid bugs; remove hardcoded references to water/ore/tree terraintypes
This commit is contained in:
@@ -30,6 +30,7 @@ namespace OpenRA.FileFormats
|
|||||||
public string Type;
|
public string Type;
|
||||||
public bool Buildable = true;
|
public bool Buildable = true;
|
||||||
public bool AcceptSmudge = true;
|
public bool AcceptSmudge = true;
|
||||||
|
public bool IsWater = false;
|
||||||
public Color Color;
|
public Color Color;
|
||||||
|
|
||||||
public TerrainTypeInfo(MiniYaml my)
|
public TerrainTypeInfo(MiniYaml my)
|
||||||
@@ -46,13 +47,15 @@ namespace OpenRA.FileFormats
|
|||||||
public string Bridge;
|
public string Bridge;
|
||||||
public float HP;
|
public float HP;
|
||||||
public bool PickAny;
|
public bool PickAny;
|
||||||
public Dictionary<int, string> Tiles = new Dictionary<int, string>();
|
public Dictionary<byte, string> Tiles = new Dictionary<byte, string>();
|
||||||
|
|
||||||
static List<string> fields = new List<string>() {"Id", "Image", "Size", "Bridge", "HP", "PickAny"};
|
static List<string> fields = new List<string>() {"Id", "Image", "Size", "Bridge", "HP", "PickAny"};
|
||||||
|
|
||||||
public TileTemplate(Dictionary<string,MiniYaml> my)
|
public TileTemplate(Dictionary<string,MiniYaml> my)
|
||||||
{
|
{
|
||||||
FieldLoader.LoadFields(this, my, fields);
|
FieldLoader.LoadFields(this, my, fields);
|
||||||
|
foreach (var tt in my["Tiles"].Nodes)
|
||||||
|
Tiles.Add(byte.Parse(tt.Key), tt.Value.Value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,8 +110,7 @@ namespace OpenRA.FileFormats
|
|||||||
var tt = Templates[r.type].Tiles;
|
var tt = Templates[r.type].Tiles;
|
||||||
string ret;
|
string ret;
|
||||||
if (!tt.TryGetValue(r.image, out ret))
|
if (!tt.TryGetValue(r.image, out ret))
|
||||||
return "Clear";// Default zero (walkable)
|
return "Clear"; // Default walkable
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,8 +48,7 @@ namespace OpenRA
|
|||||||
if (!world.Map.IsInMap(targetTile))
|
if (!world.Map.IsInMap(targetTile))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Todo: Unhardcode "Water" terraintype reference
|
var isWater = world.GetTerrainInfo(targetTile).IsWater;
|
||||||
var isWater = world.GetTerrainType(targetTile) == "Water";
|
|
||||||
|
|
||||||
if (warhead.Explosion != 0)
|
if (warhead.Explosion != 0)
|
||||||
world.AddFrameEndTask(
|
world.AddFrameEndTask(
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ namespace OpenRA.Graphics
|
|||||||
SpriteRenderer rgbaRenderer;
|
SpriteRenderer rgbaRenderer;
|
||||||
LineRenderer lineRenderer;
|
LineRenderer lineRenderer;
|
||||||
Sprite sprite;
|
Sprite sprite;
|
||||||
Bitmap terrain, oreLayer;
|
Bitmap terrain, customLayer;
|
||||||
Rectangle bounds;
|
Rectangle bounds;
|
||||||
|
|
||||||
Sprite ownedSpawnPoint;
|
Sprite ownedSpawnPoint;
|
||||||
@@ -74,7 +74,7 @@ namespace OpenRA.Graphics
|
|||||||
|
|
||||||
static Color shroudColor;
|
static Color shroudColor;
|
||||||
|
|
||||||
public void InvalidateOre() { oreLayer = null; }
|
public void InvalidateCustom() { customLayer = null; }
|
||||||
|
|
||||||
public static Bitmap RenderTerrainBitmap(Map map, TileSet tileset)
|
public static Bitmap RenderTerrainBitmap(Map map, TileSet tileset)
|
||||||
{
|
{
|
||||||
@@ -96,24 +96,25 @@ namespace OpenRA.Graphics
|
|||||||
if (terrain == null)
|
if (terrain == null)
|
||||||
terrain = RenderTerrainBitmap(world.Map, world.TileSet);
|
terrain = RenderTerrainBitmap(world.Map, world.TileSet);
|
||||||
|
|
||||||
if (oreLayer == null)
|
// Custom terrain layer
|
||||||
|
if (customLayer == null)
|
||||||
{
|
{
|
||||||
var res = world.WorldActor.traits.Get<ResourceLayer>();
|
customLayer = new Bitmap(terrain);
|
||||||
|
|
||||||
// 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 x = world.Map.TopLeft.X; x < world.Map.BottomRight.X; x++)
|
||||||
for (var y = world.Map.TopLeft.Y; y < world.Map.BottomRight.Y; y++)
|
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, oreColor));
|
var customTerrain = world.WorldActor.traits.WithInterface<ITerrainTypeModifier>()
|
||||||
|
.Select( t => t.GetTerrainType(new int2(x,y)) )
|
||||||
|
.FirstOrDefault( t => t != null );
|
||||||
|
if (customTerrain == null) continue;
|
||||||
|
customLayer.SetPixel(x, y, Color.FromArgb(alpha, world.TileSet.Terrain[customTerrain].Color));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!world.GameHasStarted || !world.Queries.OwnedBy[world.LocalPlayer].WithTrait<ProvidesRadar>().Any())
|
if (!world.GameHasStarted || !world.Queries.OwnedBy[world.LocalPlayer].WithTrait<ProvidesRadar>().Any())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var bitmap = new Bitmap(oreLayer);
|
var bitmap = new Bitmap(customLayer);
|
||||||
var bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height),
|
var bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height),
|
||||||
ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
|
ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
|
||||||
|
|
||||||
@@ -135,11 +136,8 @@ namespace OpenRA.Graphics
|
|||||||
}
|
}
|
||||||
var b = world.WorldActor.traits.Get<BuildingInfluence>().GetBuildingAt(new int2(x, y));
|
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)
|
if (b != null)
|
||||||
*(c + (y * bitmapData.Stride >> 2) + x) =
|
*(c + (y * bitmapData.Stride >> 2) + x) = Color.FromArgb(alpha, b.Owner.Color).ToArgb();
|
||||||
(b.Owner != null ? Color.FromArgb(alpha, b.Owner.Color) : Color.FromArgb(alpha, treeColor)).ToArgb();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -144,6 +144,9 @@ namespace OpenRA.Traits
|
|||||||
var building = self.World.WorldActor.traits.Get<BuildingInfluence>().GetBuildingBlocking(cell);
|
var building = self.World.WorldActor.traits.Get<BuildingInfluence>().GetBuildingBlocking(cell);
|
||||||
if (building != null && building != ignoreActor)
|
if (building != null && building != ignoreActor)
|
||||||
{
|
{
|
||||||
|
if (Info.Crushes == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
var crushable = building.traits.WithInterface<ICrushable>();
|
var crushable = building.traits.WithInterface<ICrushable>();
|
||||||
if (crushable.Count() == 0)
|
if (crushable.Count() == 0)
|
||||||
return false;
|
return false;
|
||||||
@@ -164,7 +167,10 @@ namespace OpenRA.Traits
|
|||||||
if (shareable.Count() >= 5)
|
if (shareable.Count() >= 5)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// We can enter a cell with nonshareable units if we can crush all of them
|
// We can enter a cell with nonshareable units only if we can crush all of them
|
||||||
|
if (Info.Crushes == null && nonshareable.Count() > 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
if (nonshareable.Any(a => !(a.traits.Contains<ICrushable>() &&
|
if (nonshareable.Any(a => !(a.traits.Contains<ICrushable>() &&
|
||||||
a.traits.WithInterface<ICrushable>().Any(b => b.CrushClasses.Intersect(Info.Crushes).Any()))))
|
a.traits.WithInterface<ICrushable>().Any(b => b.CrushClasses.Intersect(Info.Crushes).Any()))))
|
||||||
return false;
|
return false;
|
||||||
@@ -191,11 +197,9 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
// Custom terrain types don't stack: pick one
|
// Custom terrain types don't stack: pick one
|
||||||
var customTerrain = self.World.WorldActor.traits.WithInterface<ITerrainTypeModifier>()
|
var customTerrain = self.World.WorldActor.traits.WithInterface<ITerrainTypeModifier>()
|
||||||
.Where( t => t.GetTerrainType(cell) != null )
|
|
||||||
.Select( t => t.GetTerrainType(cell) )
|
.Select( t => t.GetTerrainType(cell) )
|
||||||
.FirstOrDefault();
|
.FirstOrDefault( t => t != null );
|
||||||
|
|
||||||
// Todo: Hack this until i finish migrating TerrainType to a string
|
|
||||||
var type = (customTerrain != null) ? customTerrain : self.World.GetTerrainType(cell);
|
var type = (customTerrain != null) ? customTerrain : self.World.GetTerrainType(cell);
|
||||||
var additionalCost = self.World.WorldActor.traits.WithInterface<ITerrainCost>()
|
var additionalCost = self.World.WorldActor.traits.WithInterface<ITerrainCost>()
|
||||||
.Select( t => t.GetTerrainCost(cell, self) ).Sum();
|
.Select( t => t.GetTerrainCost(cell, self) ).Sum();
|
||||||
@@ -211,11 +215,9 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
// Custom terrain types don't stack: pick one
|
// Custom terrain types don't stack: pick one
|
||||||
var customTerrain = self.World.WorldActor.traits.WithInterface<ITerrainTypeModifier>()
|
var customTerrain = self.World.WorldActor.traits.WithInterface<ITerrainTypeModifier>()
|
||||||
.Where( t => t.GetTerrainType(cell) != null )
|
|
||||||
.Select( t => t.GetTerrainType(cell) )
|
.Select( t => t.GetTerrainType(cell) )
|
||||||
.FirstOrDefault();
|
.FirstOrDefault( t => t != null );
|
||||||
|
|
||||||
// Todo: Hack this until i finish migrating TerrainType to a string
|
|
||||||
var type = (customTerrain != null) ? customTerrain : self.World.GetTerrainType(cell);
|
var type = (customTerrain != null) ? customTerrain : self.World.GetTerrainType(cell);
|
||||||
|
|
||||||
var modifier = self.traits
|
var modifier = self.traits
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
public readonly int ValuePerUnit = 0;
|
public readonly int ValuePerUnit = 0;
|
||||||
public readonly string Name = null;
|
public readonly string Name = null;
|
||||||
public readonly string TerrainType = null;
|
public readonly string TerrainType = "Ore";
|
||||||
|
|
||||||
public Sprite[][] Sprites;
|
public Sprite[][] Sprites;
|
||||||
|
|
||||||
|
|||||||
@@ -41,9 +41,8 @@ namespace OpenRA
|
|||||||
if (world.WorldActor.traits.Get<BuildingInfluence>().GetBuildingAt(a) != null) return false;
|
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;
|
if (world.WorldActor.traits.Get<UnitInfluence>().GetUnitsAt(a).Any(b => b != toIgnore)) return false;
|
||||||
|
|
||||||
// Todo: Unhardcode "Water" terraintype reference
|
|
||||||
if (waterBound)
|
if (waterBound)
|
||||||
return world.Map.IsInMap(a.X,a.Y) && GetTerrainType(world,a) == "Water";
|
return world.Map.IsInMap(a.X,a.Y) && GetTerrainInfo(world,a).IsWater;
|
||||||
|
|
||||||
return world.Map.IsInMap(a.X, a.Y) && world.GetTerrainInfo(a).Buildable;
|
return world.Map.IsInMap(a.X, a.Y) && world.GetTerrainInfo(a).Buildable;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ namespace OpenRA.Mods.RA
|
|||||||
if (++ticks >= self.Info.Traits.Get<CrateInfo>().Lifetime * 25)
|
if (++ticks >= self.Info.Traits.Get<CrateInfo>().Lifetime * 25)
|
||||||
self.World.AddFrameEndTask(w => w.Remove(self));
|
self.World.AddFrameEndTask(w => w.Remove(self));
|
||||||
|
|
||||||
var seq = self.World.GetTerrainType(cell) == "Water" ? "water" : "idle";
|
var seq = self.World.GetTerrainInfo(cell).IsWater ? "water" : "idle";
|
||||||
if (seq != self.traits.Get<RenderSimple>().anim.CurrentSequence.Name)
|
if (seq != self.traits.Get<RenderSimple>().anim.CurrentSequence.Name)
|
||||||
self.traits.Get<RenderSimple>().anim.PlayRepeating(seq);
|
self.traits.Get<RenderSimple>().anim.PlayRepeating(seq);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ Terrain:
|
|||||||
Color: 134, 95, 69
|
Color: 134, 95, 69
|
||||||
TerrainType@Water:
|
TerrainType@Water:
|
||||||
Type: Water
|
Type: Water
|
||||||
|
IsWater: true
|
||||||
Buildable: False
|
Buildable: False
|
||||||
AcceptSmudge: False
|
AcceptSmudge: False
|
||||||
Color: 93, 165, 206
|
Color: 93, 165, 206
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ Terrain:
|
|||||||
Color: 40, 68, 40
|
Color: 40, 68, 40
|
||||||
TerrainType@Water:
|
TerrainType@Water:
|
||||||
Type: Water
|
Type: Water
|
||||||
|
IsWater: true
|
||||||
Buildable: False
|
Buildable: False
|
||||||
AcceptSmudge: False
|
AcceptSmudge: False
|
||||||
Color: 92, 116, 164
|
Color: 92, 116, 164
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ Terrain:
|
|||||||
Color: 40, 68, 40
|
Color: 40, 68, 40
|
||||||
TerrainType@Water:
|
TerrainType@Water:
|
||||||
Type: Water
|
Type: Water
|
||||||
|
IsWater: true
|
||||||
Buildable: False
|
Buildable: False
|
||||||
AcceptSmudge: False
|
AcceptSmudge: False
|
||||||
Color: 92, 116, 164
|
Color: 92, 116, 164
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ Terrain:
|
|||||||
Color: 40, 68, 40
|
Color: 40, 68, 40
|
||||||
TerrainType@Water:
|
TerrainType@Water:
|
||||||
Type: Water
|
Type: Water
|
||||||
|
IsWater: true
|
||||||
Buildable: False
|
Buildable: False
|
||||||
AcceptSmudge: False
|
AcceptSmudge: False
|
||||||
Color: 92, 116, 164
|
Color: 92, 116, 164
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ Terrain:
|
|||||||
Color: 196, 196, 196
|
Color: 196, 196, 196
|
||||||
TerrainType@Water:
|
TerrainType@Water:
|
||||||
Type: Water
|
Type: Water
|
||||||
|
IsWater: true
|
||||||
Buildable: False
|
Buildable: False
|
||||||
AcceptSmudge: False
|
AcceptSmudge: False
|
||||||
Color: 92, 116, 164
|
Color: 92, 116, 164
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ Terrain:
|
|||||||
Color: 40, 68, 40
|
Color: 40, 68, 40
|
||||||
TerrainType@Water:
|
TerrainType@Water:
|
||||||
Type: Water
|
Type: Water
|
||||||
|
IsWater: true
|
||||||
Buildable: False
|
Buildable: False
|
||||||
AcceptSmudge: False
|
AcceptSmudge: False
|
||||||
Color: 92, 116, 164
|
Color: 92, 116, 164
|
||||||
|
|||||||
Reference in New Issue
Block a user