diff --git a/OpenRA.Mods.Common/Traits/BotModules/SquadManagerBotModule.cs b/OpenRA.Mods.Common/Traits/BotModules/SquadManagerBotModule.cs index d37b697101..28c5442726 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/SquadManagerBotModule.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/SquadManagerBotModule.cs @@ -102,6 +102,10 @@ namespace OpenRA.Mods.Common.Traits public readonly Player Player; readonly Predicate unitCannotBeOrdered; + readonly List unitsHangingAroundTheBase = new List(); + + // Units that the bot already knows about. Any unit not on this list needs to be given a role. + readonly List activeUnits = new List(); public List Squads = new List(); @@ -110,10 +114,6 @@ namespace OpenRA.Mods.Common.Traits IBotNotifyIdleBaseUnits[] notifyIdleBaseUnits; CPos initialBaseCenter; - List unitsHangingAroundTheBase = new List(); - - // Units that the bot already knows about. Any unit not on this list needs to be given a role. - List activeUnits = new List(); int rushTicks; int assignRolesTicks; diff --git a/OpenRA.Mods.Common/Traits/Buildings/RepairableBuilding.cs b/OpenRA.Mods.Common/Traits/Buildings/RepairableBuilding.cs index c44573dd08..8842a83e3f 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/RepairableBuilding.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/RepairableBuilding.cs @@ -77,6 +77,7 @@ namespace OpenRA.Mods.Common.Traits var hash = 0; foreach (var player in Repairers) hash ^= Sync.HashPlayer(player); + return hash; } } @@ -86,7 +87,6 @@ namespace OpenRA.Mods.Common.Traits if (string.IsNullOrEmpty(Info.RepairCondition)) return; - var currentRepairers = Repairers.Count; while (Repairers.Count > repairTokens.Count) repairTokens.Push(self.GrantCondition(Info.RepairCondition)); diff --git a/OpenRA.Mods.Common/Traits/DeliversCash.cs b/OpenRA.Mods.Common/Traits/DeliversCash.cs index 3b706e5937..c469e2f0c2 100644 --- a/OpenRA.Mods.Common/Traits/DeliversCash.cs +++ b/OpenRA.Mods.Common/Traits/DeliversCash.cs @@ -94,22 +94,28 @@ namespace OpenRA.Mods.Common.Traits public override bool CanTargetActor(Actor self, Actor target, TargetModifiers modifiers, ref string cursor) { - var type = self.Info.TraitInfo().Type; var targetInfo = target.Info.TraitInfoOrDefault(); - return targetInfo != null - && targetInfo.ValidStances.HasStance(target.Owner.RelationshipWith(self.Owner)) - && (targetInfo.ValidTypes.Count == 0 - || (!string.IsNullOrEmpty(type) && targetInfo.ValidTypes.Contains(type))); + if (targetInfo == null || !targetInfo.ValidStances.HasStance(target.Owner.RelationshipWith(self.Owner))) + return false; + + if (targetInfo.ValidTypes.Count == 0) + return true; + + var type = self.Info.TraitInfo().Type; + return !string.IsNullOrEmpty(type) && targetInfo.ValidTypes.Contains(type); } public override bool CanTargetFrozenActor(Actor self, FrozenActor target, TargetModifiers modifiers, ref string cursor) { - var type = self.Info.TraitInfo().Type; var targetInfo = target.Info.TraitInfoOrDefault(); - return targetInfo != null - && targetInfo.ValidStances.HasStance(target.Owner.RelationshipWith(self.Owner)) - && (targetInfo.ValidTypes.Count == 0 - || (!string.IsNullOrEmpty(type) && targetInfo.ValidTypes.Contains(type))); + if (targetInfo == null || !targetInfo.ValidStances.HasStance(target.Owner.RelationshipWith(self.Owner))) + return false; + + if (targetInfo.ValidTypes.Count == 0) + return true; + + var type = self.Info.TraitInfo().Type; + return !string.IsNullOrEmpty(type) && targetInfo.ValidTypes.Contains(type); } } } diff --git a/OpenRA.Mods.Common/Traits/DeliversExperience.cs b/OpenRA.Mods.Common/Traits/DeliversExperience.cs index a3cfad81ee..cee0809a44 100644 --- a/OpenRA.Mods.Common/Traits/DeliversExperience.cs +++ b/OpenRA.Mods.Common/Traits/DeliversExperience.cs @@ -100,17 +100,19 @@ namespace OpenRA.Mods.Common.Traits if (target == self) return false; - var type = self.Info.TraitInfo().Type; - var targetInfo = target.Info.TraitInfoOrDefault(); var targetGainsExperience = target.TraitOrDefault(); - if (targetGainsExperience == null || targetInfo == null) + if (targetGainsExperience == null || targetGainsExperience.Level == targetGainsExperience.MaxLevel) return false; - if (targetGainsExperience.Level == targetGainsExperience.MaxLevel) + var targetInfo = target.Info.TraitInfoOrDefault(); + if (targetInfo == null || !targetInfo.ValidStances.HasStance(target.Owner.RelationshipWith(self.Owner))) return false; - return targetInfo.ValidStances.HasStance(target.Owner.RelationshipWith(self.Owner)) - && (targetInfo.ValidTypes.Count == 0 || (!string.IsNullOrEmpty(type) && targetInfo.ValidTypes.Contains(type))); + if (targetInfo.ValidTypes.Count == 0) + return true; + + var type = self.Info.TraitInfo().Type; + return !string.IsNullOrEmpty(type) && targetInfo.ValidTypes.Contains(type); } public override bool CanTargetFrozenActor(Actor self, FrozenActor target, TargetModifiers modifiers, ref string cursor) @@ -118,18 +120,19 @@ namespace OpenRA.Mods.Common.Traits if (target.Actor == null || target.Actor == self) return false; - var type = self.Info.TraitInfo().Type; - var targetInfo = target.Info.TraitInfoOrDefault(); var targetGainsExperience = target.Actor.TraitOrDefault(); - - if (targetGainsExperience == null || targetInfo == null) + if (targetGainsExperience == null || targetGainsExperience.Level == targetGainsExperience.MaxLevel) return false; - if (targetGainsExperience.Level == targetGainsExperience.MaxLevel) + var targetInfo = target.Info.TraitInfoOrDefault(); + if (targetInfo == null || !targetInfo.ValidStances.HasStance(target.Owner.RelationshipWith(self.Owner))) return false; - return targetInfo.ValidStances.HasStance(target.Owner.RelationshipWith(self.Owner)) - && (targetInfo.ValidTypes.Count == 0 || (!string.IsNullOrEmpty(type) && targetInfo.ValidTypes.Contains(type))); + if (targetInfo.ValidTypes.Count == 0) + return true; + + var type = self.Info.TraitInfo().Type; + return !string.IsNullOrEmpty(type) && targetInfo.ValidTypes.Contains(type); } } }