From 11c9bd7bc8102cfbe90af4ac8cab91b4095e5de0 Mon Sep 17 00:00:00 2001 From: Squiggles211 Date: Tue, 29 Apr 2014 01:07:56 -0500 Subject: [PATCH 1/3] Fix TechTree prerequisite bug for buildings with a build limit. Fixes where a building/unit whose prereq is a build limited structure was always available to be built even when the prereq was not satisfied. --- OpenRA.Mods.RA/Player/TechTree.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/OpenRA.Mods.RA/Player/TechTree.cs b/OpenRA.Mods.RA/Player/TechTree.cs index 4e85d0e8bc..1b37cce524 100755 --- a/OpenRA.Mods.RA/Player/TechTree.cs +++ b/OpenRA.Mods.RA/Player/TechTree.cs @@ -113,7 +113,11 @@ namespace OpenRA.Mods.RA public void Update(Cache> buildables) { - var hasReachedBuildLimit = buildLimit > 0 && buildables[Key].Count >= buildLimit; + var hasReachedBuildLimit = false; + + if(buildables.Keys.Contains(Key)) + hasReachedBuildLimit = buildLimit > 0 && buildables[Key].Count >= buildLimit; + var nowHasPrerequisites = HasPrerequisites(buildables) && !hasReachedBuildLimit; if (nowHasPrerequisites && !hasPrerequisites) From a495d9d552e4a68f366a4950d76609bcb9edf8c5 Mon Sep 17 00:00:00 2001 From: Squiggles211 Date: Fri, 2 May 2014 08:26:36 -0500 Subject: [PATCH 2/3] Rewrite for better efficiency uses a single, more concise statement rather than an if statement, and checks buildLimit before attempting to check if the buildables cache contains the key. --- OpenRA.Mods.RA/Player/TechTree.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/OpenRA.Mods.RA/Player/TechTree.cs b/OpenRA.Mods.RA/Player/TechTree.cs index 1b37cce524..a320713820 100755 --- a/OpenRA.Mods.RA/Player/TechTree.cs +++ b/OpenRA.Mods.RA/Player/TechTree.cs @@ -113,10 +113,7 @@ namespace OpenRA.Mods.RA public void Update(Cache> buildables) { - var hasReachedBuildLimit = false; - - if(buildables.Keys.Contains(Key)) - hasReachedBuildLimit = buildLimit > 0 && buildables[Key].Count >= buildLimit; + var hasReachedBuildLimit = buildLimit > 0 && buildables.Keys.Contains(Key) && buildables[Key].Count >= buildLimit; var nowHasPrerequisites = HasPrerequisites(buildables) && !hasReachedBuildLimit; From ce69ea2237447678d26d84daab9bd599f15f5b8b Mon Sep 17 00:00:00 2001 From: Squiggles211 Date: Mon, 12 May 2014 08:42:44 -0500 Subject: [PATCH 3/3] Fix sold tech bug on build limited structures Fixes where if a structure with a build limit was sold, it was not properly removed from the buildables prerequisite list until next update. --- OpenRA.Mods.RA/Player/TechTree.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/OpenRA.Mods.RA/Player/TechTree.cs b/OpenRA.Mods.RA/Player/TechTree.cs index a320713820..a90ee60602 100755 --- a/OpenRA.Mods.RA/Player/TechTree.cs +++ b/OpenRA.Mods.RA/Player/TechTree.cs @@ -80,7 +80,7 @@ namespace OpenRA.Mods.RA // Add buildables that have a build limit set and are not already in the list player.World.ActorsWithTrait() - .Where(a => a.Actor.Info.Traits.Get().BuildLimit > 0 && !a.Actor.IsDead() && a.Actor.Owner == player && ret.Keys.All(k => k != a.Actor.Info.Name)) + .Where(a => a.Actor.Info.Traits.Get().BuildLimit > 0 && !a.Actor.IsDead() && a.Actor.IsInWorld && a.Actor.Owner == player && ret.Keys.All(k => k != a.Actor.Info.Name)) .ToList() .ForEach(b => ret[b.Actor.Info.Name].Add(b.Actor)); @@ -114,7 +114,6 @@ namespace OpenRA.Mods.RA public void Update(Cache> buildables) { var hasReachedBuildLimit = buildLimit > 0 && buildables.Keys.Contains(Key) && buildables[Key].Count >= buildLimit; - var nowHasPrerequisites = HasPrerequisites(buildables) && !hasReachedBuildLimit; if (nowHasPrerequisites && !hasPrerequisites)