diff --git a/OpenRa.Game/PathFinder.cs b/OpenRa.Game/PathFinder.cs index 3cbd755102..c5a211e0df 100644 --- a/OpenRa.Game/PathFinder.cs +++ b/OpenRa.Game/PathFinder.cs @@ -54,7 +54,7 @@ namespace OpenRa.Game for( int i = 0 ; i < path.Count ; i++ ) { var sl = path[ i ] + offset; - if( Game.BuildingInfluence.GetBuildingAt( path[ i ] ) == null & Game.UnitInfluence.GetUnitAt( path[ i ] ) == null ) + if( i == 0 || Game.BuildingInfluence.GetBuildingAt( path[ i ] ) == null & Game.UnitInfluence.GetUnitAt( path[ i ] ) == null ) { queue.Add( new PathDistance( estimator( sl - offset ), sl ) ); cellInfo[ sl.X, sl.Y ] = new CellInfo( cost, prev, false ); diff --git a/OpenRa.Game/Traits/Mobile.cs b/OpenRa.Game/Traits/Mobile.cs index 2746fb115f..e2f9a0f4fc 100644 --- a/OpenRa.Game/Traits/Mobile.cs +++ b/OpenRa.Game/Traits/Mobile.cs @@ -21,7 +21,8 @@ namespace OpenRa.Game.Traits public Mobile(Actor self) { this.self = self; - fromCell = toCell; + fromCell = toCell; + Game.UnitInfluence.Update( this ); } public void QueueActivity( CurrentActivity nextActivity ) @@ -205,7 +206,7 @@ namespace OpenRa.Game.Traits var nextCell = path[ path.Count - 1 ]; if( !CanEnterCell( nextCell, self ) ) { - if( ( mobile.toCell - destination.Value ).LengthSquared < 4 ) + if( ( mobile.toCell - destination.Value ).LengthSquared <= 8 ) { path.Clear(); return null; diff --git a/OpenRa.Game/UiOverlay.cs b/OpenRa.Game/UiOverlay.cs index cdb6f784ed..c1e12c2b83 100644 --- a/OpenRa.Game/UiOverlay.cs +++ b/OpenRa.Game/UiOverlay.cs @@ -1,7 +1,7 @@ using System.Drawing; using OpenRa.Game.Graphics; using System; -using OpenRa.Game.GameRules; +using OpenRa.Game.GameRules; using System.Linq; namespace OpenRa.Game @@ -9,8 +9,8 @@ namespace OpenRa.Game class UiOverlay { SpriteRenderer spriteRenderer; - Sprite buildOk, buildBlocked, unitDebug; - + Sprite buildOk, buildBlocked, unitDebug; + public static bool ShowUnitDebug = false; public UiOverlay(SpriteRenderer spriteRenderer) @@ -18,7 +18,7 @@ namespace OpenRa.Game this.spriteRenderer = spriteRenderer; buildOk = SynthesizeTile(0x80); - buildBlocked = SynthesizeTile(0xe6); + buildBlocked = SynthesizeTile(0xe6); unitDebug = SynthesizeTile(0x7c); } @@ -34,22 +34,22 @@ namespace OpenRa.Game } public void Draw() - { - if (ShowUnitDebug) - for (var j = 0; j < 128; j++) - for (var i = 0; i < 128; i++) - if (Game.UnitInfluence.GetUnitAt(new int2(i, j)) != null) + { + if (ShowUnitDebug) + for (var j = 0; j < 128; j++) + for (var i = 0; i < 128; i++) + if (Game.UnitInfluence.GetUnitAt(new int2(i, j)) != null) spriteRenderer.DrawSprite(unitDebug, Game.CellSize * new float2(i, j), 0); - if (!hasOverlay) return; - - var bi = (UnitInfo.BuildingInfo)Rules.UnitInfo[name]; - - var maxDistance = bi.Adjacent + 2; /* real-ra is weird. this is 1 GAP. */ - var tooFarFromBase = !Footprint.Tiles(bi, position).Any( - t => Game.GetDistanceToBase(t, Game.LocalPlayer) < maxDistance); - - foreach( var t in Footprint.Tiles( bi, position ) ) + if (!hasOverlay) return; + + var bi = (UnitInfo.BuildingInfo)Rules.UnitInfo[name]; + + var maxDistance = bi.Adjacent + 2; /* real-ra is weird. this is 1 GAP. */ + var tooFarFromBase = !Footprint.Tiles(bi, position).Any( + t => Game.GetDistanceToBase(t, Game.LocalPlayer) < maxDistance); + + foreach( var t in Footprint.Tiles( bi, position ) ) spriteRenderer.DrawSprite( !tooFarFromBase && Game.IsCellBuildable( t, bi.WaterBound ? UnitMovementType.Float : UnitMovementType.Wheel ) ? buildOk : buildBlocked, Game.CellSize * t, 0 ); diff --git a/OpenRa.Game/UnitInfluenceMap.cs b/OpenRa.Game/UnitInfluenceMap.cs index 16ffe011fe..86788ec8d1 100644 --- a/OpenRa.Game/UnitInfluenceMap.cs +++ b/OpenRa.Game/UnitInfluenceMap.cs @@ -18,19 +18,38 @@ namespace OpenRa.Game public void Tick() { + SanityCheck(); + var units = Game.world.Actors .Select( a => a.traits.GetOrDefault() ).Where( m => m != null ); foreach (var u in units) Update(u); + + SanityCheck(); + } + + [System.Diagnostics.Conditional( "SANITY_CHECKS" )] + void SanityCheck() + { + for( int y = 0 ; y < 128 ; y++ ) + for( int x = 0 ; x < 128 ; x++ ) + if( influence[ x, y ] != null && !influence[ x, y ].traits.Get().OccupiedCells().Contains( new int2( x, y ) ) ) + throw new InvalidOperationException( "UIM: Sanity check failed A" ); + + foreach( var a in Game.world.Actors ) + { + if( !a.traits.Contains() ) + continue; + foreach( var cell in a.traits.Get().OccupiedCells() ) + if( influence[ cell.X, cell.Y ] != a ) + throw new InvalidOperationException( "UIM: Sanity check failed B" ); + } } public Actor GetUnitAt( int2 a ) { - var actor = influence[ a.X, a.Y ]; - if( actor != null && !actor.traits.Get().OccupiedCells().Contains( a ) ) - throw new InvalidOperationException( "UIM: Unit is not in influenced square" ); - return actor; + return influence[ a.X, a.Y ]; } public void Add(Mobile a)