diff --git a/OpenRa.Game/Game.cs b/OpenRa.Game/Game.cs index 8dee81b601..c3bb31ebab 100644 --- a/OpenRa.Game/Game.cs +++ b/OpenRa.Game/Game.cs @@ -7,7 +7,8 @@ using System.Linq; using IrrKlang; using IjwFramework.Collections; using System; -using IjwFramework.Types; +using IjwFramework.Types; +using OpenRa.Game.Traits; namespace OpenRa.Game { @@ -180,6 +181,22 @@ namespace OpenRa.Game public static readonly Pair SovietVoices = Pair.New( new VoicePool("ackno", "affirm1", "noprob", "overout", "ritaway", "roger", "ugotit"), - new VoicePool("await1", "ready", "report1", "yessir1")); + new VoicePool("await1", "ready", "report1", "yessir1")); + + public static void BuildUnit(Player player, string name) + { + var producer = world.Actors + .FirstOrDefault(a => a.unitInfo != null && a.unitInfo.Name == "weap" && a.Owner == player); + + if (producer == null) + throw new InvalidOperationException("BuildUnit without suitable production structure!"); + + var unit = new Actor(name, (1/24f * producer.CenterLocation).ToInt2(), player); + unit.Order(unit.Location + new int2(0, 3)).Apply(false); + + world.AddFrameEndTask(_ => world.Add(unit)); + + // todo: make the producing building play `build` + } } } diff --git a/OpenRa.Game/Sidebar.cs b/OpenRa.Game/Sidebar.cs index 02916ef578..0d10a1c508 100644 --- a/OpenRa.Game/Sidebar.cs +++ b/OpenRa.Game/Sidebar.cs @@ -59,10 +59,15 @@ namespace OpenRa.Game } public void Build(SidebarItem item) - { - if (item != null) - Game.controller.orderGenerator = new PlaceBuilding(Game.LocalPlayer, - item.techTreeItem.tag.ToLowerInvariant()); + { + if (item != null) + { + if (item.techTreeItem.IsStructure) + Game.controller.orderGenerator = new PlaceBuilding(Game.LocalPlayer, + item.techTreeItem.tag.ToLowerInvariant()); + else + Game.BuildUnit(Game.LocalPlayer, item.techTreeItem.tag.ToLowerInvariant()); + } } void LoadSprites( string category, string group )