From f4a5c9069b0c4b8e188cfdb7d045f795a35dadb9 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Sun, 1 Nov 2009 21:29:05 +1300 Subject: [PATCH] deploy mcv now requires clear space --- OpenRa.Game/Cursor.cs | 1 + OpenRa.Game/Game.cs | 21 ++++++++++++++++++++- OpenRa.Game/Order.cs | 5 +++-- OpenRa.Game/PlaceBuilding.cs | 1 - OpenRa.Game/Traits/McvDeploy.cs | 24 ++++++++++++------------ OpenRa.Game/UnitOrders.cs | 5 +++++ sequences.xml | 2 +- 7 files changed, 42 insertions(+), 17 deletions(-) diff --git a/OpenRa.Game/Cursor.cs b/OpenRa.Game/Cursor.cs index 2a5d138fc6..77049a3e7d 100644 --- a/OpenRa.Game/Cursor.cs +++ b/OpenRa.Game/Cursor.cs @@ -25,5 +25,6 @@ namespace OpenRa.Game public static Cursor Attack { get { return new Cursor("attack"); } } public static Cursor Deploy { get { return new Cursor("deploy"); } } public static Cursor Enter { get { return new Cursor("enter"); } } + public static Cursor DeployBlocked { get { return new Cursor("deploy-blocked"); } } } } diff --git a/OpenRa.Game/Game.cs b/OpenRa.Game/Game.cs index d368b16407..0a89612c46 100644 --- a/OpenRa.Game/Game.cs +++ b/OpenRa.Game/Game.cs @@ -156,9 +156,14 @@ namespace OpenRa.Game } public static bool IsCellBuildable(int2 a, UnitMovementType umt) + { + return IsCellBuildable(a, umt, null); + } + + public static bool IsCellBuildable(int2 a, UnitMovementType umt, Actor toIgnore) { if (BuildingInfluence.GetBuildingAt(a) != null) return false; - if (UnitInfluence.GetUnitAt(a) != null) return false; + if (UnitInfluence.GetUnitAt(a) != null && UnitInfluence.GetUnitAt(a) != toIgnore) return false; return map.IsInMap(a.X, a.Y) && TerrainCosts.Cost(umt, @@ -246,6 +251,20 @@ namespace OpenRa.Game return null; } + public static bool CanPlaceBuilding(string name, int2 xy, Actor toIgnore) + { + var bi = (UnitInfo.BuildingInfo)Rules.UnitInfo["fact"]; + return !Footprint.Tiles(bi, xy).Any( + t => !Game.IsCellBuildable(t, + bi.WaterBound ? UnitMovementType.Float : UnitMovementType.Wheel, + toIgnore)); + } + + public static bool CanPlaceBuilding(string name, int2 xy) + { + return CanPlaceBuilding(name, xy, null); + } + public static void BuildUnit(Player player, string name) { var producerTypes = Rules.TechTree.UnitBuiltAt( Rules.UnitInfo[ name ] ); diff --git a/OpenRa.Game/Order.cs b/OpenRa.Game/Order.cs index 6df223b866..66675d2d99 100644 --- a/OpenRa.Game/Order.cs +++ b/OpenRa.Game/Order.cs @@ -98,9 +98,10 @@ namespace OpenRa.Game isBlocked ? Cursor.MoveBlocked : Cursor.Move); } - public static Order DeployMcv(Actor subject) + public static Order DeployMcv(Actor subject, bool isBlocked) { - return new Order(subject.Owner, "DeployMcv", subject, null, int2.Zero, null, Cursor.Deploy); + return new Order(subject.Owner, "DeployMcv", subject, null, int2.Zero, isBlocked ? "nop" : null, + isBlocked ? Cursor.DeployBlocked : Cursor.Deploy); } public static Order PlaceBuilding(Player subject, int2 target, string buildingName) diff --git a/OpenRa.Game/PlaceBuilding.cs b/OpenRa.Game/PlaceBuilding.cs index 795a255870..653627a841 100644 --- a/OpenRa.Game/PlaceBuilding.cs +++ b/OpenRa.Game/PlaceBuilding.cs @@ -21,7 +21,6 @@ namespace OpenRa.Game { if( lmb ) { - // todo: check that space is free var bi = (UnitInfo.BuildingInfo)Rules.UnitInfo[ Name ]; if( Footprint.Tiles( bi, xy ).Any( t => !Game.IsCellBuildable( t, diff --git a/OpenRa.Game/Traits/McvDeploy.cs b/OpenRa.Game/Traits/McvDeploy.cs index 204f0aa67c..de8fac5ce2 100644 --- a/OpenRa.Game/Traits/McvDeploy.cs +++ b/OpenRa.Game/Traits/McvDeploy.cs @@ -1,7 +1,8 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; +using System.Text; +using OpenRa.Game.GameRules; namespace OpenRa.Game.Traits { @@ -9,17 +10,16 @@ namespace OpenRa.Game.Traits { public McvDeploy(Actor self) { - } - - public Order Order(Actor self, int2 xy, bool lmb, Actor underCursor) - { - if( lmb ) return null; - - // TODO: check that there's enough space at the destination. - if( xy == self.Location ) - return OpenRa.Game.Order.DeployMcv( self ); - - return null; + } + + public Order Order(Actor self, int2 xy, bool lmb, Actor underCursor) + { + if (lmb) return null; + + if (xy == self.Location) + return OpenRa.Game.Order.DeployMcv(self, !Game.CanPlaceBuilding("fact", xy, self)); + + return null; } } } diff --git a/OpenRa.Game/UnitOrders.cs b/OpenRa.Game/UnitOrders.cs index 014238c5f9..83a3d1717a 100755 --- a/OpenRa.Game/UnitOrders.cs +++ b/OpenRa.Game/UnitOrders.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using OpenRa.Game.Traits; +using OpenRa.Game.GameRules; namespace OpenRa.Game { @@ -45,6 +46,10 @@ namespace OpenRa.Game } case "DeployMcv": { + var bi = (UnitInfo.BuildingInfo)Rules.UnitInfo["fact"]; + if (!Game.CanPlaceBuilding("fact", order.Subject.Location, order.Subject)) + break; /* throw the order on the floor */ + var mobile = order.Subject.traits.Get(); mobile.QueueActivity( new Mobile.Turn( 96 ) ); mobile.QueueActivity( new Traits.Activities.DeployMcv() ); diff --git a/sequences.xml b/sequences.xml index 6cfee2f777..85f6a62814 100644 --- a/sequences.xml +++ b/sequences.xml @@ -385,7 +385,7 @@ - +