From aadfd6979bc3dab2a57183653eff1bb0bf4e25c8 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 24 Aug 2013 10:10:16 +1200 Subject: [PATCH] Initial cleanup of BaseBuilder. --- OpenRA.Mods.RA/AI/BaseBuilder.cs | 109 +++++++++++++++---------------- 1 file changed, 51 insertions(+), 58 deletions(-) diff --git a/OpenRA.Mods.RA/AI/BaseBuilder.cs b/OpenRA.Mods.RA/AI/BaseBuilder.cs index 312870e9b0..fd7d153fd9 100644 --- a/OpenRA.Mods.RA/AI/BaseBuilder.cs +++ b/OpenRA.Mods.RA/AI/BaseBuilder.cs @@ -1,6 +1,6 @@ #region Copyright & License Information /* - * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) + * Copyright 2007-2013 The OpenRA Developers (see AUTHORS) * This file is part of OpenRA, which is free software. It is made * available to you under the terms of the GNU General Public License * as published by the Free Software Foundation. For more information, @@ -9,13 +9,7 @@ #endregion using System; -using System.Collections.Generic; using System.Linq; -using OpenRA.FileFormats; -using OpenRA.Mods.RA.Buildings; -using OpenRA.Traits; -using OpenRA.Mods.RA.Activities; -using XRandom = OpenRA.Thirdparty.Random; namespace OpenRA.Mods.RA.AI { @@ -39,70 +33,69 @@ namespace OpenRA.Mods.RA.AI public void Tick() { // Pick a free queue - var queue = ai.FindQueues( category ).FirstOrDefault(); + var queue = ai.FindQueues(category).FirstOrDefault(); if (queue == null) return; var currentBuilding = queue.CurrentItem(); switch (state) { - case BuildState.ChooseItem: + case BuildState.ChooseItem: + var item = chooseItem(queue); + if (item == null) + { + state = BuildState.WaitForFeedback; + lastThinkTick = ai.ticks; + } + else + { + HackyAI.BotDebug("AI: Starting production of {0}".F(item.Name)); + state = BuildState.WaitForProduction; + ai.world.IssueOrder(Order.StartProduction(queue.self, item.Name, 1)); + } + break; + + case BuildState.WaitForProduction: + if (currentBuilding == null) + return; + + if (currentBuilding.Paused) + ai.world.IssueOrder(Order.PauseProduction(queue.self, currentBuilding.Item, false)); + else if (currentBuilding.Done) + { + state = BuildState.WaitForFeedback; + lastThinkTick = ai.ticks; + + // Place the building + var type = BuildingType.Building; + if (Rules.Info[currentBuilding.Item].Traits.Contains()) + type = BuildingType.Defense; + else if (Rules.Info[currentBuilding.Item].Traits.Contains()) + type = BuildingType.Refinery; + + var location = ai.ChooseBuildLocation(currentBuilding.Item, type); + if (location == null) { - var item = chooseItem(queue); - if (item == null) - { - state = BuildState.WaitForFeedback; - lastThinkTick = ai.ticks; - } - else - { - HackyAI.BotDebug("AI: Starting production of {0}".F(item.Name)); - state = BuildState.WaitForProduction; - ai.world.IssueOrder(Order.StartProduction(queue.self, item.Name, 1)); - } + HackyAI.BotDebug("AI: Nowhere to place {0}".F(currentBuilding.Item)); + ai.world.IssueOrder(Order.CancelProduction(queue.self, currentBuilding.Item, 1)); } - break; - - case BuildState.WaitForProduction: - if (currentBuilding == null) return; /* let it happen.. */ - - else if (currentBuilding.Paused) - ai.world.IssueOrder(Order.PauseProduction(queue.self, currentBuilding.Item, false)); - else if (currentBuilding.Done) + else { - state = BuildState.WaitForFeedback; - lastThinkTick = ai.ticks; - - /* place the building */ - BuildingType type = BuildingType.Building; - if(Rules.Info[currentBuilding.Item].Traits.Contains()) - type = BuildingType.Defense; - else if(Rules.Info[currentBuilding.Item].Traits.Contains()) - type = BuildingType.Refinery; - - var location = ai.ChooseBuildLocation(currentBuilding.Item, type); - if (location == null) + ai.world.IssueOrder(new Order("PlaceBuilding", ai.p.PlayerActor, false) { - HackyAI.BotDebug("AI: Nowhere to place {0}".F(currentBuilding.Item)); - ai.world.IssueOrder(Order.CancelProduction(queue.self, currentBuilding.Item, 1)); - } - else - { - ai.world.IssueOrder(new Order("PlaceBuilding", ai.p.PlayerActor, false) - { - TargetLocation = location.Value, - TargetString = currentBuilding.Item - }); - } + TargetLocation = location.Value, + TargetString = currentBuilding.Item + }); } - break; + } - case BuildState.WaitForFeedback: - if (ai.ticks - lastThinkTick > HackyAI.feedbackTime) - state = BuildState.ChooseItem; - break; + break; + + case BuildState.WaitForFeedback: + if (ai.ticks - lastThinkTick > HackyAI.feedbackTime) + state = BuildState.ChooseItem; + break; } } } } -