working on Orders for sidebar

This commit is contained in:
Bob
2009-11-01 23:54:22 +13:00
parent 90ba576cc6
commit b4510876d3
3 changed files with 25 additions and 29 deletions

View File

@@ -109,14 +109,14 @@ namespace OpenRa.Game
return new Order(subject, "PlaceBuilding", null, null, target, buildingName, Cursor.Default); 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) public static Order DeliverOre(Actor subject, Actor target)
{ {
return new Order(subject.Owner, "DeliverOre", subject, target, int2.Zero, null, Cursor.Enter); 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 );
}
} }
} }

View File

@@ -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) if( item.IsStructure )
Game.controller.orderGenerator = new PlaceBuilding(player, Game.controller.orderGenerator = new PlaceBuilding( player,
item.Tag.ToLowerInvariant()); item.Tag.ToLowerInvariant() );
else
Game.controller.AddOrder(Order.BuildUnit(player, item.Tag.ToLowerInvariant()));
} }
void LoadSprites( string group ) void LoadSprites( string group )
@@ -224,20 +222,7 @@ namespace OpenRa.Game
if (producing == null) if (producing == null)
{ {
var ui = Rules.UnitInfo[item.Tag]; Game.controller.AddOrder( Order.StartProduction( player, 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.PlaySound("abldgin1.aud", false); Game.PlaySound("abldgin1.aud", false);
} }
else if (producing.Item == item.Tag) else if (producing.Item == item.Tag)

View File

@@ -46,7 +46,6 @@ namespace OpenRa.Game
} }
case "DeployMcv": case "DeployMcv":
{ {
var bi = (UnitInfo.BuildingInfo)Rules.UnitInfo["fact"];
if (!Game.CanPlaceBuilding("fact", order.Subject.Location, order.Subject)) if (!Game.CanPlaceBuilding("fact", order.Subject.Location, order.Subject))
break; /* throw the order on the floor */ break; /* throw the order on the floor */
@@ -81,9 +80,21 @@ namespace OpenRa.Game
} ); } );
break; 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; break;
} }
default: default: