From e0a00940af830484276b6c96fef4c99e0d32af41 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Wed, 11 Aug 2010 18:23:17 +1200 Subject: [PATCH] initial buildqueue ai --- OpenRA.Mods.RA/World/HackyAI.cs | 77 ++++++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) diff --git a/OpenRA.Mods.RA/World/HackyAI.cs b/OpenRA.Mods.RA/World/HackyAI.cs index 65d2aa1f7d..1ce420181c 100644 --- a/OpenRA.Mods.RA/World/HackyAI.cs +++ b/OpenRA.Mods.RA/World/HackyAI.cs @@ -1,5 +1,6 @@ using System.Linq; using OpenRA.Traits; +using System; namespace OpenRA.Mods.RA { @@ -12,13 +13,40 @@ namespace OpenRA.Mods.RA bool enabled; int ticks; Player p; + ProductionQueue pq; + bool isBuildingStuff; + + enum BuildState + { + ChooseItem, + WaitForProduction, + WaitForFeedback, + } + + int lastThinkTick = 0; + + BuildState state = BuildState.WaitForFeedback; public void GameStarted(World w) { - enabled = Game.IsHost; p = Game.world.LocalPlayer; + enabled = Game.IsHost && p != null; + if (enabled) + pq = p.PlayerActor.traits.Get(); } + string ChooseItemToBuild() + { + return "powr"; // LOTS OF POWER + } + + int2? ChooseBuildLocation(ProductionItem item) + { + return null; // i don't know where to put it. + } + + const int feedbackTime = 30; // ticks; = a bit over 1s. must be >= netlag. + public void Tick(Actor self) { if (!enabled) @@ -37,6 +65,53 @@ namespace OpenRA.Mods.RA else Game.Debug("AI: Can't find the MCV."); } + + var currentBuilding = pq.CurrentItem("Building"); + switch (state) + { + case BuildState.ChooseItem: + { + var item = ChooseItemToBuild(); + if (item == null) + { + state = BuildState.WaitForFeedback; + lastThinkTick = ticks; + } + else + { + state = BuildState.WaitForProduction; + Game.IssueOrder(Order.StartProduction(p, item, 1)); + } + } + break; + + case BuildState.WaitForProduction: + if (currentBuilding == null) return; /* let it happen.. */ + + else if (currentBuilding.Paused) + Game.IssueOrder(Order.PauseProduction(p, currentBuilding.Item, false)); + else if (currentBuilding.Done) + { + state = BuildState.WaitForFeedback; + lastThinkTick = ticks; + + /* place the building */ + var location = ChooseBuildLocation(currentBuilding); + if (location == null) + Game.IssueOrder(Order.CancelProduction(p, currentBuilding.Item)); + else + { + // todo: place the building! + throw new NotImplementedException(); + } + } + break; + + case BuildState.WaitForFeedback: + if (ticks - lastThinkTick > feedbackTime) + state = BuildState.ChooseItem; + break; + } } } }