Begin unfailing movement types / IsBuildable / etc

This commit is contained in:
Paul Chote
2010-03-21 17:56:08 +13:00
parent 9017aa9cd6
commit b4540db406
15 changed files with 48 additions and 38 deletions

View File

@@ -72,7 +72,7 @@ namespace OpenRA.FileFormats
string tilename = string.Format(pattern, i + 1);
if (!walk.ContainsKey((ushort)(start + i)))
walk.Add((ushort)(start + i), Walkability.GetWalkability(tilename));
walk.Add((ushort)(start + i), Walkability.GetTerrainType(tilename));
using( Stream s = FileSystem.Open( tilename + "." + suffix ) )
{
@@ -99,7 +99,7 @@ namespace OpenRA.FileFormats
return missingTile;
}
public int GetWalkability(TileReference r)
public int GetTerrainType(TileReference r)
{
if (r.tile == 0xff || r.tile == 0xffff)
r.image = 0;

View File

@@ -65,7 +65,7 @@ namespace OpenRA.FileFormats
}
}
public TileTemplate GetWalkability(string terrainName)
public TileTemplate GetTerrainType(string terrainName)
{
return walkability[terrainName];
}

View File

@@ -1,4 +1,4 @@
#region Copyright & License Information
#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.
@@ -41,15 +41,14 @@ namespace OpenRA
var targetTile = ((1f / Game.CellSize) * loc.ToFloat2()).ToInt2();
var isWater = world.IsWater(targetTile);
var hitWater = world.IsCellBuildable(targetTile, UnitMovementType.Float);
var isWater = (Game.world.GetTerrainType(targetTile) == TerrainMovementType.Water);
if (warhead.Explosion != 0)
world.AddFrameEndTask(
w => w.Add(new Explosion(w, visualLoc, warhead.Explosion, hitWater)));
w => w.Add(new Explosion(w, visualLoc, warhead.Explosion, isWater)));
var impactSound = warhead.ImpactSound;
if (hitWater && warhead.WaterImpactSound != null)
if (isWater && warhead.WaterImpactSound != null)
impactSound = warhead.WaterImpactSound;
if (impactSound != null) Sound.Play(impactSound + ".aud");

View File

@@ -92,7 +92,7 @@ namespace OpenRA.Graphics
for (var y = 0; y < map.MapSize; y++)
for (var x = 0; x < map.MapSize; x++)
terrain.SetPixel(x, y, map.IsInMap(x, y)
? Color.FromArgb(alpha, terrainTypeColors[map.Theater].ColorForTerrainType(tileset.GetWalkability(map.MapTiles[x, y])))
? Color.FromArgb(alpha, terrainTypeColors[map.Theater].ColorForTerrainType(tileset.GetTerrainType(map.MapTiles[x, y])))
: shroudColor);
return terrain;
}

View File

@@ -42,7 +42,7 @@ namespace OpenRA
for( int y = 0 ; y < map.MapSize ; y++ )
for (var umt = UnitMovementType.Foot; umt <= UnitMovementType.Float; umt++ )
passableCost[(int)umt][ x, y ] = ( world.Map.IsInMap( x, y ) )
? (float)TerrainCosts.Cost( umt, world.TileSet.GetWalkability( world.Map.MapTiles[ x, y ] ) )
? (float)TerrainCosts.Cost( umt, world.TileSet.GetTerrainType( world.Map.MapTiles[ x, y ] ) )
: float.PositiveInfinity;
}
@@ -64,7 +64,7 @@ namespace OpenRA
using( new PerfSample( "find_unit_path_multiple_src" ) )
{
var tilesInRange = world.FindTilesInCircle(target, range)
.Where( t => world.IsCellBuildable( t, umt ) );
.Where( t => world.IsPathableCell( t, umt ) );
var path = FindPath( PathSearch.FromPoints( world, tilesInRange, src, umt, false ).WithCustomBlocker(AvoidUnitsNear(src, 4)));
path.Reverse();

View File

@@ -31,7 +31,7 @@ namespace OpenRA
Fly = 4,
}
enum TerrainMovementType : byte
public enum TerrainMovementType : byte
{
Clear = 0,
Water = 1,
@@ -51,6 +51,7 @@ namespace OpenRA
static float[][] costs = Util.MakeArray<float[]>(4,
a => Util.MakeArray<float>(11, b => float.PositiveInfinity));
static bool[] buildable = Util.MakeArray<bool>(11,b => false);
static TerrainCosts()
{
for( int i = 0 ; i < 11 ; i++ )
@@ -62,9 +63,15 @@ namespace OpenRA
string val = section.GetValue( ( (UnitMovementType)j ).ToString(), "0%" );
costs[j][i] = 100f / float.Parse(val.Substring(0, val.Length - 1));
}
buildable[i] = (section.GetValue("Buildable", "no") == "yes");
}
}
public static bool Buildable(int r)
{
return buildable[r];
}
public static float Cost( UnitMovementType unitMovementType, int r )
{
return costs[ (byte)unitMovementType ][ r ];

View File

@@ -1,4 +1,4 @@
#region Copyright & License Information
#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.
@@ -35,7 +35,7 @@ namespace OpenRA.Traits.Activities
if (unit.Altitude == 0)
return NextActivity;
if (requireSpace && !self.World.IsCellBuildable(self.Location, UnitMovementType.Foot))
if (requireSpace && !self.World.IsPathableCell(self.Location, UnitMovementType.Foot))
return this; // fail to land if no space
--unit.Altitude;

View File

@@ -1,4 +1,4 @@
#region Copyright & License Information
#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.
@@ -36,7 +36,7 @@ namespace OpenRA.Traits.Activities
for (var i = -1; i < 2; i++)
for (var j = -1; j < 2; j++)
if ((i != 0 || j != 0) &&
self.World.IsCellBuildable(self.Location + new int2(i, j),
self.World.IsPathableCell(self.Location + new int2(i, j),
UnitMovementType.Foot))
return self.Location + new int2(i, j);

View File

@@ -1,4 +1,4 @@
#region Copyright & License Information
#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.
@@ -97,7 +97,7 @@ namespace OpenRA.Traits
var numStates = self.Info.Traits.Get<BridgeInfo>().Long ? 6 : 3;
for (var n = 0; n < numStates; n++)
{
var stateTemplate = world.TileSet.Walkability.GetWalkability(NameFromState(template, n));
var stateTemplate = world.TileSet.Walkability.GetTerrainType(NameFromState(template, n));
Templates.Add( stateTemplate );
TileSprites.Add(replacedTiles.ToDictionary(

View File

@@ -91,7 +91,7 @@ namespace OpenRA.Traits
return self.World.Map.IsInMap(a.X, a.Y) &&
TerrainCosts.Cost(GetMovementType(),
self.World.TileSet.GetWalkability(self.World.Map.MapTiles[a.X, a.Y])) < double.PositiveInfinity;
self.World.TileSet.GetTerrainType(self.World.Map.MapTiles[a.X, a.Y])) < double.PositiveInfinity;
}
}
}

View File

@@ -1,4 +1,4 @@
#region Copyright & License Information
#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.
@@ -56,7 +56,7 @@ namespace OpenRA.Traits
this.self = self;
self.World.WorldActor.traits.Get<UnitInfluence>().Add(self, this);
if (self.World.IsWater(self.Location))
if (self.World.GetTerrainType(self.Location) == TerrainMovementType.Water)
self.traits.Get<RenderSimple>().anim.PlayRepeating("water");
}

View File

@@ -134,7 +134,7 @@ namespace OpenRA.Traits
return self.World.Map.IsInMap(a.X, a.Y) &&
TerrainCosts.Cost(GetMovementType(),
self.World.TileSet.GetWalkability(self.World.Map.MapTiles[a.X, a.Y])) < double.PositiveInfinity;
self.World.TileSet.GetTerrainType(self.World.Map.MapTiles[a.X, a.Y])) < double.PositiveInfinity;
}
public IEnumerable<int2> GetCurrentPath()

View File

@@ -1,4 +1,4 @@
#region Copyright & License Information
#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.

View File

@@ -1,4 +1,4 @@
#region Copyright & License Information
#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.

View File

@@ -30,6 +30,14 @@ namespace OpenRA
{
public static class WorldUtils
{
public static bool IsPathableCell(this World world, int2 a, UnitMovementType umt)
{
if (world.WorldActor.traits.Get<BuildingInfluence>().GetBuildingAt(a) != null) return false;
if (world.WorldActor.traits.Get<UnitInfluence>().GetUnitsAt(a).Any()) return false;
return world.Map.IsInMap(a.X, a.Y) && TerrainCosts.Cost(umt, world.TileSet.GetTerrainType(world.Map.MapTiles[a.X,a.Y])) < double.PositiveInfinity;
}
public static bool IsCellBuildable(this World world, int2 a, UnitMovementType umt)
{
return world.IsCellBuildable(a, umt, null);
@@ -40,9 +48,7 @@ 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;
return world.Map.IsInMap(a.X, a.Y) &&
TerrainCosts.Cost(umt,
world.TileSet.GetWalkability(world.Map.MapTiles[a.X, a.Y])) < double.PositiveInfinity;
return world.Map.IsInMap(a.X, a.Y) && TerrainCosts.Buildable(world.TileSet.GetTerrainType(world.Map.MapTiles[a.X, a.Y]));
}
public static bool IsActorCrushableByActor(this World world, Actor a, Actor b)
@@ -65,13 +71,6 @@ namespace OpenRA
.Any(c => c.IsCrushableBy(umt, a.Owner));
}
public static bool IsWater(this World world, int2 a)
{
return world.Map.IsInMap(a.X, a.Y) &&
TerrainCosts.Cost(UnitMovementType.Float,
world.TileSet.GetWalkability(world.Map.MapTiles[a.X, a.Y])) < double.PositiveInfinity;
}
public static IEnumerable<Actor> FindUnitsAtMouse(this World world, int2 mouseLocation)
{
var loc = mouseLocation + Game.viewport.Location;
@@ -127,6 +126,11 @@ namespace OpenRA
.FirstOrDefault();
}
public static TerrainMovementType GetTerrainType(this World world, int2 cell)
{
return (TerrainMovementType)world.TileSet.GetTerrainType(world.Map.MapTiles[cell.X, cell.Y]);
}
public static bool CanPlaceBuilding(this World world, string name, BuildingInfo building, int2 topLeft, Actor toIgnore)
{
var res = world.WorldActor.traits.Get<ResourceLayer>();