From 79dd9a9c6b910ad58ed2f1bd26ed895050ded0de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Fri, 4 Jul 2014 14:57:34 +0200 Subject: [PATCH] get rid of the RallypointTestBuilding hack --- OpenRA.Mods.RA/AI/HackyAI.cs | 26 +++++++++----------------- mods/d2k/rules/ai.yaml | 3 --- 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/OpenRA.Mods.RA/AI/HackyAI.cs b/OpenRA.Mods.RA/AI/HackyAI.cs index ead8a6ccb6..304b3295c2 100644 --- a/OpenRA.Mods.RA/AI/HackyAI.cs +++ b/OpenRA.Mods.RA/AI/HackyAI.cs @@ -46,8 +46,6 @@ namespace OpenRA.Mods.RA.AI [Desc("Radius in cells around a factory scanned for rally points by the AI.")] public readonly int RallyPointScanRadius = 8; - // Temporary hack to maintain previous rallypoint behavior. - public readonly string RallypointTestBuilding = "fact"; public readonly string[] UnitQueues = { "Vehicle", "Infantry", "Plane", "Ship", "Aircraft" }; public readonly bool ShouldRepairBuildings = true; @@ -101,7 +99,6 @@ namespace OpenRA.Mods.RA.AI PowerManager playerPower; SupportPowerManager supportPowerMngr; PlayerResources playerResource; - BuildingInfo rallypointTestBuilding; internal readonly HackyAIInfo Info; HashSet resourceTypeIndices; @@ -128,9 +125,6 @@ namespace OpenRA.Mods.RA.AI { Info = info; world = init.world; - - // Temporary hack. - rallypointTestBuilding = Map.Rules.Actors[Info.RallypointTestBuilding].Traits.Get(); } public static void BotDebug(string s, params object[] args) @@ -671,37 +665,35 @@ namespace OpenRA.Mods.RA.AI } } - bool IsRallyPointValid(CPos x) + bool IsRallyPointValid(CPos x, BuildingInfo info) { - // This is actually WRONG as soon as HackyAI is building units with - // a variety of movement capabilities. (has always been wrong) - return world.IsCellBuildable(x, rallypointTestBuilding); + return info != null && world.IsCellBuildable(x, info); } void SetRallyPointsForNewProductionBuildings(Actor self) { var buildings = self.World.ActorsWithTrait() .Where(rp => rp.Actor.Owner == p && - !IsRallyPointValid(rp.Trait.rallyPoint)).ToArray(); + !IsRallyPointValid(rp.Trait.rallyPoint, rp.Actor.Info.Traits.GetOrDefault())).ToArray(); if (buildings.Length > 0) BotDebug("Bot {0} needs to find rallypoints for {1} buildings.", p.PlayerName, buildings.Length); foreach (var a in buildings) - world.IssueOrder(new Order("SetRallyPoint", a.Actor, false) { TargetLocation = ChooseRallyLocationNear(a.Actor.Location), SuppressVisualFeedback = true }); + world.IssueOrder(new Order("SetRallyPoint", a.Actor, false) { TargetLocation = ChooseRallyLocationNear(a.Actor), SuppressVisualFeedback = true }); } // Won't work for shipyards... - CPos ChooseRallyLocationNear(CPos startPos) + CPos ChooseRallyLocationNear(Actor producer) { - var possibleRallyPoints = Map.FindTilesInCircle(startPos, Info.RallyPointScanRadius) - .Where(IsRallyPointValid); + var possibleRallyPoints = Map.FindTilesInCircle(producer.Location, Info.RallyPointScanRadius) + .Where(c => IsRallyPointValid(c, producer.Info.Traits.GetOrDefault())); if (!possibleRallyPoints.Any()) { - BotDebug("Bot Bug: No possible rallypoint near {0}", startPos); - return startPos; + BotDebug("Bot Bug: No possible rallypoint near {0}", producer.Location); + return producer.Location; } return possibleRallyPoints.Random(random); diff --git a/mods/d2k/rules/ai.yaml b/mods/d2k/rules/ai.yaml index 5f604d153c..08cc977824 100644 --- a/mods/d2k/rules/ai.yaml +++ b/mods/d2k/rules/ai.yaml @@ -2,7 +2,6 @@ Player: HackyAI@Omnius: Name: Omnius UnitQueues: Infantry, Vehicle, Armor, Starport - RallypointTestBuilding: conyarda BuildingCommonNames: ConstructionYard: conyarda,conyardh,conyardo Refinery: refa,refh,refo @@ -104,7 +103,6 @@ Player: HackyAI@Vidius: Name: Vidious UnitQueues: Infantry, Vehicle, Armor, Starport - RallypointTestBuilding: conyarda BuildingCommonNames: ConstructionYard: conyarda,conyardh,conyardo Refinery: refa,refh,refo @@ -207,7 +205,6 @@ Player: HackyAI@Gladius: Name: Gladius UnitQueues: Infantry, Vehicle, Armor, Starport - RallypointTestBuilding: conyarda BuildingCommonNames: ConstructionYard: conyarda,conyardh,conyardo Refinery: refa,refh,refo