From aae428be2b671663a895636439d3d48f9557094e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sat, 28 Jun 2014 11:18:24 +0200 Subject: [PATCH 1/2] throw with a more helpful error than NullReferenceException closes #5622 --- OpenRA.Mods.RA/AI/HackyAI.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenRA.Mods.RA/AI/HackyAI.cs b/OpenRA.Mods.RA/AI/HackyAI.cs index 22292835c2..f994cd14d6 100644 --- a/OpenRA.Mods.RA/AI/HackyAI.cs +++ b/OpenRA.Mods.RA/AI/HackyAI.cs @@ -234,7 +234,7 @@ namespace OpenRA.Mods.RA.AI ActorInfo GetInfoByCommonName(Dictionary names, string commonName, Player owner) { if (!names.Any() || !names.ContainsKey(commonName)) - return null; + throw new InvalidOperationException("Can't find {0} in the HackyAI UnitsCommonNames definition.".F(commonName)); return Map.Rules.Actors.Where(k => names[commonName].Contains(k.Key)).Random(random).Value; } From 5130723fcd91f04f0312f61bc82d3343686caa01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sat, 28 Jun 2014 11:20:41 +0200 Subject: [PATCH 2/2] remove the overly complicated configurable MCV actor name hack --- OpenRA.Mods.RA/AI/HackyAI.cs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/OpenRA.Mods.RA/AI/HackyAI.cs b/OpenRA.Mods.RA/AI/HackyAI.cs index f994cd14d6..0d179f8d3f 100644 --- a/OpenRA.Mods.RA/AI/HackyAI.cs +++ b/OpenRA.Mods.RA/AI/HackyAI.cs @@ -734,13 +734,6 @@ namespace OpenRA.Mods.RA.AI { var maxBaseDistance = Math.Max(world.Map.MapSize.X, world.Map.MapSize.Y); - // HACK: Assumes all MCVs deploy into the same construction yard footprint - var mcvInfo = GetUnitInfoByCommonName("Mcv", p); - if (mcvInfo == null) - return; - - var factType = mcvInfo.Traits.Get().IntoActor; - // HACK: This needs to query against MCVs directly var mcvs = self.World.Actors.Where(a => a.Owner == p && a.HasTrait() && a.HasTrait()); if (!mcvs.Any()) @@ -751,6 +744,7 @@ namespace OpenRA.Mods.RA.AI if (mcv.IsMoving()) continue; + var factType = mcv.Info.Traits.Get().IntoActor; var desiredLocation = ChooseBuildLocation(factType, false, maxBaseDistance, BuildingType.Building); if (desiredLocation == null) continue;