From b4510876d34c29c58b38a3c0e26e50fc3ef841f1 Mon Sep 17 00:00:00 2001 From: Bob Date: Sun, 1 Nov 2009 23:54:22 +1300 Subject: [PATCH] working on Orders for sidebar --- OpenRa.Game/Order.cs | 10 +++++----- OpenRa.Game/Sidebar.cs | 27 ++++++--------------------- OpenRa.Game/UnitOrders.cs | 17 ++++++++++++++--- 3 files changed, 25 insertions(+), 29 deletions(-) diff --git a/OpenRa.Game/Order.cs b/OpenRa.Game/Order.cs index e983fc3cb3..efc960df1c 100644 --- a/OpenRa.Game/Order.cs +++ b/OpenRa.Game/Order.cs @@ -109,14 +109,14 @@ namespace OpenRa.Game return new Order(subject, "PlaceBuilding", null, null, target, buildingName, Cursor.Default); } - public static Order BuildUnit(Player subject, string unitName) - { - return new Order(subject, "BuildUnit", null, null, int2.Zero, unitName, Cursor.Default); - } - public static Order DeliverOre(Actor subject, Actor target) { return new Order(subject.Owner, "DeliverOre", subject, target, int2.Zero, null, Cursor.Enter); } + + public static Order StartProduction(Player subject, string item) + { + return new Order(subject, "StartProduction", null, null, int2.Zero, item, Cursor.Default ); + } } } diff --git a/OpenRa.Game/Sidebar.cs b/OpenRa.Game/Sidebar.cs index dfcc0e8e64..2fafac9253 100644 --- a/OpenRa.Game/Sidebar.cs +++ b/OpenRa.Game/Sidebar.cs @@ -73,15 +73,13 @@ namespace OpenRa.Game }; } - public void Build(SidebarItem item) + public void Build( SidebarItem item ) { - if (item == null) return; + if( item == null ) return; - if (item.IsStructure) - Game.controller.orderGenerator = new PlaceBuilding(player, - item.Tag.ToLowerInvariant()); - else - Game.controller.AddOrder(Order.BuildUnit(player, item.Tag.ToLowerInvariant())); + if( item.IsStructure ) + Game.controller.orderGenerator = new PlaceBuilding( player, + item.Tag.ToLowerInvariant() ); } void LoadSprites( string group ) @@ -224,20 +222,7 @@ namespace OpenRa.Game if (producing == null) { - var ui = Rules.UnitInfo[item.Tag]; - var time = ui.Cost - * .8f /* Game.BuildSpeed */ /* todo: country-specific build speed bonus */ - * (25 * 60) /* frames per min */ /* todo: build acceleration, if we do that */ - / 1000; - - time = .05f * time; /* temporary hax so we can build stuff fast for test */ - - Action complete = null; - if (IsAutoCompleting(group)) complete = () => Build(item); - - player.BeginProduction(group, - new ProductionItem(item.Tag, (int)time, ui.Cost, complete)); - + Game.controller.AddOrder( Order.StartProduction( player, item.Tag ) ); Game.PlaySound("abldgin1.aud", false); } else if (producing.Item == item.Tag) diff --git a/OpenRa.Game/UnitOrders.cs b/OpenRa.Game/UnitOrders.cs index 83a3d1717a..44a0b4d7eb 100755 --- a/OpenRa.Game/UnitOrders.cs +++ b/OpenRa.Game/UnitOrders.cs @@ -46,7 +46,6 @@ 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 */ @@ -81,9 +80,21 @@ namespace OpenRa.Game } ); break; } - case "BuildUnit": + case "StartProduction": { - Game.world.AddFrameEndTask(_ => Game.BuildUnit( order.Player, order.TargetString )); + string group = Rules.UnitCategory[ order.TargetString ]; + var ui = Rules.UnitInfo[ order.TargetString ]; + var time = ui.Cost + * .8f /* Game.BuildSpeed */ /* todo: country-specific build speed bonus */ + * ( 25 * 60 ) /* frames per min */ /* todo: build acceleration, if we do that */ + / 1000; + + time = .05f * time; /* temporary hax so we can build stuff fast for test */ + + Action complete = null; + if( group != "Building" ) complete = () => Game.world.AddFrameEndTask( _ => Game.BuildUnit( order.Player, order.TargetString ) ); + + order.Player.BeginProduction( group, new ProductionItem( order.TargetString, (int)time, ui.Cost, complete ) ); break; } default: