From 0aeef8c3f719d70c7bd4ca28c1606cc2b9db62b6 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Tue, 19 Jan 2010 11:49:01 +1300 Subject: [PATCH] bridge pathing works --- OpenRa.Game/PathSearch.cs | 1 - OpenRa.Game/TerrainCosts.cs | 8 ++++---- OpenRa.Game/Traits/Bridge.cs | 11 ++++++----- ra.yaml | 9 ++++++--- units.ini | 7 +++++-- 5 files changed, 21 insertions(+), 15 deletions(-) diff --git a/OpenRa.Game/PathSearch.cs b/OpenRa.Game/PathSearch.cs index 30c79ae194..f6a9c0266c 100755 --- a/OpenRa.Game/PathSearch.cs +++ b/OpenRa.Game/PathSearch.cs @@ -56,7 +56,6 @@ namespace OpenRa continue; var custom = Game.world.customTerrain[newHere.X, newHere.Y]; - if (custom != null) throw new NotImplementedException(); var costHere = (custom != null) ? custom.GetCost(newHere, umt) : passableCost[(int)umt][newHere.X, newHere.Y]; if (costHere == float.PositiveInfinity) diff --git a/OpenRa.Game/TerrainCosts.cs b/OpenRa.Game/TerrainCosts.cs index f794344c77..66bda9cea1 100644 --- a/OpenRa.Game/TerrainCosts.cs +++ b/OpenRa.Game/TerrainCosts.cs @@ -28,8 +28,8 @@ namespace OpenRa static class TerrainCosts { - static double[][] costs = Util.MakeArray( 4, - a => Util.MakeArray( 11, b => double.PositiveInfinity )); + static float[][] costs = Util.MakeArray(4, + a => Util.MakeArray(11, b => float.PositiveInfinity)); static TerrainCosts() { @@ -40,12 +40,12 @@ namespace OpenRa for( int j = 0 ; j < 4 ; j++ ) { string val = section.GetValue( ( (UnitMovementType)j ).ToString(), "0%" ); - costs[ j ][ i ] = 100.0 / double.Parse( val.Substring( 0, val.Length - 1 ) ); + costs[j][i] = 100f / float.Parse(val.Substring(0, val.Length - 1)); } } } - public static double Cost( UnitMovementType unitMovementType, int r ) + public static float Cost( UnitMovementType unitMovementType, int r ) { return costs[ (byte)unitMovementType ][ r ]; } diff --git a/OpenRa.Game/Traits/Bridge.cs b/OpenRa.Game/Traits/Bridge.cs index f9ce4106f5..7d4da56189 100644 --- a/OpenRa.Game/Traits/Bridge.cs +++ b/OpenRa.Game/Traits/Bridge.cs @@ -9,7 +9,7 @@ using System.Drawing; namespace OpenRa.Traits { - class BridgeInfo : OwnedActorInfo, ITraitInfo + class BridgeInfo : ITraitInfo { public object Create(Actor self) { return new Bridge(self); } } @@ -19,8 +19,9 @@ namespace OpenRa.Traits Dictionary Tiles; TileTemplate Template; Dictionary TileSprites; + Actor self; - public Bridge(Actor self) { self.RemoveOnDeath = false; } + public Bridge(Actor self) { this.self = self; self.RemoveOnDeath = false; } static string cachedTheater; static Cache sprites; @@ -55,9 +56,9 @@ namespace OpenRa.Traits public float GetCost(int2 p, UnitMovementType umt) { - throw new NotImplementedException(); - var origTile = Tiles[p]; // if this explodes, then SetTiles did something horribly wrong. - return float.PositiveInfinity; + return self.Health > 0 + ? TerrainCosts.Cost(umt, Template.TerrainType[Tiles[p]]) + : TerrainCosts.Cost(umt, 1); } } } diff --git a/ra.yaml b/ra.yaml index bcdc69117f..c41ded2c59 100644 --- a/ra.yaml +++ b/ra.yaml @@ -1438,11 +1438,14 @@ DOMF: Fake: BRIDGE: - Inherits: ^Building + Category: Building + Selectable: Bridge: BelowUnits: - -Selectable: - -Building: + Building: + Footprint: ____ ____ + Dimensions: 4,2 + HP: 1000 T01: Inherits: ^Building diff --git a/units.ini b/units.ini index 9f9fbf2d23..44d99972c5 100644 --- a/units.ini +++ b/units.ini @@ -535,8 +535,11 @@ Traits=Unit,RenderUnit,BelowUnits,InvisibleToOthers Selectable=no [Bridge] -Traits=Bridge, BelowUnits -Selectable=no +Traits=Bridge, BelowUnits, Building +Strength=1000 +Dimensions=4,2 +Footprint=____ ____ +Selectable=yes ;; temp hack [InfantryTypes] DOG