diff --git a/OpenRa.Game/PlaceBuilding.cs b/OpenRa.Game/PlaceBuilding.cs index 653627a841..5f4b8835d1 100644 --- a/OpenRa.Game/PlaceBuilding.cs +++ b/OpenRa.Game/PlaceBuilding.cs @@ -1,45 +1,50 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using OpenRa.Game.GameRules; - -namespace OpenRa.Game -{ - class PlaceBuilding : IOrderGenerator - { - public readonly Player Owner; - public readonly string Name; - - public PlaceBuilding(Player owner, string name) - { - Owner = owner; - Name = name; - } - - public IEnumerable Order(int2 xy, bool lmb) - { - if( lmb ) - { - var bi = (UnitInfo.BuildingInfo)Rules.UnitInfo[ Name ]; - if( Footprint.Tiles( bi, xy ).Any( - t => !Game.IsCellBuildable( t, - bi.WaterBound ? UnitMovementType.Float : UnitMovementType.Wheel ) ) ) - yield break; - - var maxDistance = bi.Adjacent + 2; /* real-ra is weird. this is 1 GAP. */ - if( !Footprint.Tiles( bi, xy ).Any( - t => Game.GetDistanceToBase( t, Owner ) < maxDistance ) ) - yield break; - - yield return OpenRa.Game.Order.PlaceBuilding( Owner, xy, Name ); - } - else // rmb - { - Game.world.AddFrameEndTask( _ => { Game.controller.orderGenerator = null; } ); - } - } +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using OpenRa.Game.GameRules; - public void Tick() { } - } -} +namespace OpenRa.Game +{ + class PlaceBuilding : IOrderGenerator + { + public readonly Player Owner; + public readonly string Name; + + public PlaceBuilding(Player owner, string name) + { + Owner = owner; + Name = name; + } + + public IEnumerable Order(int2 xy, bool lmb) + { + if( lmb ) + { + var bi = (UnitInfo.BuildingInfo)Rules.UnitInfo[ Name ]; + if( Footprint.Tiles( bi, xy ).Any( + t => !Game.IsCellBuildable( t, + bi.WaterBound ? UnitMovementType.Float : UnitMovementType.Wheel ) ) ) + yield break; + + var maxDistance = bi.Adjacent + 2; /* real-ra is weird. this is 1 GAP. */ + if( !Footprint.Tiles( bi, xy ).Any( + t => Game.GetDistanceToBase( t, Owner ) < maxDistance ) ) + yield break; + + yield return OpenRa.Game.Order.PlaceBuilding( Owner, xy, Name ); + } + else // rmb + { + Game.world.AddFrameEndTask( _ => { Game.controller.orderGenerator = null; } ); + } + } + + public void Tick() + { + var producing = Owner.Producing( "Building" ); + if( producing == null || producing.Item != Name || producing.RemainingTime != 0 ) + Game.world.AddFrameEndTask( _ => { Game.controller.orderGenerator = null; } ); + } + } +} diff --git a/OpenRa.Game/UnitOrders.cs b/OpenRa.Game/UnitOrders.cs index 41f0070599..fab96e2bc7 100755 --- a/OpenRa.Game/UnitOrders.cs +++ b/OpenRa.Game/UnitOrders.cs @@ -69,13 +69,14 @@ namespace OpenRa.Game Game.world.AddFrameEndTask( _ => { var building = Rules.UnitInfo[ order.TargetString ]; + var producing = order.Player.Producing( "Building" ); + if( producing == null || producing.Item != order.TargetString || producing.RemainingTime != 0 ) + return; + Log.Write( "Player \"{0}\" builds {1}", order.Player.PlayerName, building.Name ); - //Adjust placement for cursor to be in middle Game.world.Add( new Actor( building.Name, order.TargetLocation - GameRules.Footprint.AdjustForBuildingSize( building.Name ), order.Player ) ); - Game.controller.orderGenerator = null; - order.Player.FinishProduction(Rules.UnitCategory[building.Name]); } ); break;