Fix some stupid bugs; remove hardcoded references to water/ore/tree terraintypes

This commit is contained in:
Paul Chote
2010-06-26 12:02:30 +12:00
parent bf6b2da1a8
commit 08ee425415
13 changed files with 39 additions and 33 deletions

View File

@@ -30,6 +30,7 @@ namespace OpenRA.FileFormats
public string Type;
public bool Buildable = true;
public bool AcceptSmudge = true;
public bool IsWater = false;
public Color Color;
public TerrainTypeInfo(MiniYaml my)
@@ -46,13 +47,15 @@ namespace OpenRA.FileFormats
public string Bridge;
public float HP;
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"};
public TileTemplate(Dictionary<string,MiniYaml> my)
{
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;
string ret;
if (!tt.TryGetValue(r.image, out ret))
return "Clear";// Default zero (walkable)
return "Clear"; // Default walkable
return ret;
}
}

View File

@@ -48,8 +48,7 @@ namespace OpenRA
if (!world.Map.IsInMap(targetTile))
return;
// Todo: Unhardcode "Water" terraintype reference
var isWater = world.GetTerrainType(targetTile) == "Water";
var isWater = world.GetTerrainInfo(targetTile).IsWater;
if (warhead.Explosion != 0)
world.AddFrameEndTask(

View File

@@ -34,7 +34,7 @@ namespace OpenRA.Graphics
SpriteRenderer rgbaRenderer;
LineRenderer lineRenderer;
Sprite sprite;
Bitmap terrain, oreLayer;
Bitmap terrain, customLayer;
Rectangle bounds;
Sprite ownedSpawnPoint;
@@ -74,7 +74,7 @@ namespace OpenRA.Graphics
static Color shroudColor;
public void InvalidateOre() { oreLayer = null; }
public void InvalidateCustom() { customLayer = null; }
public static Bitmap RenderTerrainBitmap(Map map, TileSet tileset)
{
@@ -92,28 +92,29 @@ namespace OpenRA.Graphics
}
public void Update()
{
{
if (terrain == null)
terrain = RenderTerrainBitmap(world.Map, world.TileSet);
if (oreLayer == null)
// Custom terrain layer
if (customLayer == null)
{
var res = world.WorldActor.traits.Get<ResourceLayer>();
// This is an ugly hack
Color oreColor = world.TileSet.Terrain["Ore"].Color;
oreLayer = new Bitmap(terrain);
customLayer = 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, 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())
return;
var bitmap = new Bitmap(oreLayer);
var bitmap = new Bitmap(customLayer);
var bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height),
ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
@@ -135,11 +136,8 @@ namespace OpenRA.Graphics
}
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, treeColor)).ToArgb();
*(c + (y * bitmapData.Stride >> 2) + x) = Color.FromArgb(alpha, b.Owner.Color).ToArgb();
}
}

View File

@@ -144,6 +144,9 @@ namespace OpenRA.Traits
var building = self.World.WorldActor.traits.Get<BuildingInfluence>().GetBuildingBlocking(cell);
if (building != null && building != ignoreActor)
{
if (Info.Crushes == null)
return false;
var crushable = building.traits.WithInterface<ICrushable>();
if (crushable.Count() == 0)
return false;
@@ -164,7 +167,10 @@ namespace OpenRA.Traits
if (shareable.Count() >= 5)
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>() &&
a.traits.WithInterface<ICrushable>().Any(b => b.CrushClasses.Intersect(Info.Crushes).Any()))))
return false;
@@ -191,11 +197,9 @@ namespace OpenRA.Traits
// Custom terrain types don't stack: pick one
var customTerrain = self.World.WorldActor.traits.WithInterface<ITerrainTypeModifier>()
.Where( t => t.GetTerrainType(cell) != null )
.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 additionalCost = self.World.WorldActor.traits.WithInterface<ITerrainCost>()
.Select( t => t.GetTerrainCost(cell, self) ).Sum();
@@ -211,11 +215,9 @@ namespace OpenRA.Traits
// Custom terrain types don't stack: pick one
var customTerrain = self.World.WorldActor.traits.WithInterface<ITerrainTypeModifier>()
.Where( t => t.GetTerrainType(cell) != null )
.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 modifier = self.traits

View File

@@ -32,7 +32,7 @@ namespace OpenRA.Traits
public readonly int ValuePerUnit = 0;
public readonly string Name = null;
public readonly string TerrainType = null;
public readonly string TerrainType = "Ore";
public Sprite[][] Sprites;

View File

@@ -41,9 +41,8 @@ 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) == "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;
}

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) == "Water" ? "water" : "idle";
var seq = self.World.GetTerrainInfo(cell).IsWater ? "water" : "idle";
if (seq != self.traits.Get<RenderSimple>().anim.CurrentSequence.Name)
self.traits.Get<RenderSimple>().anim.PlayRepeating(seq);
}

View File

@@ -6,6 +6,7 @@ Terrain:
Color: 134, 95, 69
TerrainType@Water:
Type: Water
IsWater: true
Buildable: False
AcceptSmudge: False
Color: 93, 165, 206

View File

@@ -6,6 +6,7 @@ Terrain:
Color: 40, 68, 40
TerrainType@Water:
Type: Water
IsWater: true
Buildable: False
AcceptSmudge: False
Color: 92, 116, 164

View File

@@ -6,6 +6,7 @@ Terrain:
Color: 40, 68, 40
TerrainType@Water:
Type: Water
IsWater: true
Buildable: False
AcceptSmudge: False
Color: 92, 116, 164

View File

@@ -6,6 +6,7 @@ Terrain:
Color: 40, 68, 40
TerrainType@Water:
Type: Water
IsWater: true
Buildable: False
AcceptSmudge: False
Color: 92, 116, 164

View File

@@ -6,6 +6,7 @@ Terrain:
Color: 196, 196, 196
TerrainType@Water:
Type: Water
IsWater: true
Buildable: False
AcceptSmudge: False
Color: 92, 116, 164

View File

@@ -6,6 +6,7 @@ Terrain:
Color: 40, 68, 40
TerrainType@Water:
Type: Water
IsWater: true
Buildable: False
AcceptSmudge: False
Color: 92, 116, 164