Misc code improvements
This commit is contained in:
@@ -102,6 +102,10 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public readonly Player Player;
|
||||
|
||||
readonly Predicate<Actor> unitCannotBeOrdered;
|
||||
readonly List<Actor> unitsHangingAroundTheBase = new List<Actor>();
|
||||
|
||||
// Units that the bot already knows about. Any unit not on this list needs to be given a role.
|
||||
readonly List<Actor> activeUnits = new List<Actor>();
|
||||
|
||||
public List<Squad> Squads = new List<Squad>();
|
||||
|
||||
@@ -110,10 +114,6 @@ namespace OpenRA.Mods.Common.Traits
|
||||
IBotNotifyIdleBaseUnits[] notifyIdleBaseUnits;
|
||||
|
||||
CPos initialBaseCenter;
|
||||
List<Actor> unitsHangingAroundTheBase = new List<Actor>();
|
||||
|
||||
// Units that the bot already knows about. Any unit not on this list needs to be given a role.
|
||||
List<Actor> activeUnits = new List<Actor>();
|
||||
|
||||
int rushTicks;
|
||||
int assignRolesTicks;
|
||||
|
||||
@@ -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));
|
||||
|
||||
|
||||
@@ -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<DeliversCashInfo>().Type;
|
||||
var targetInfo = target.Info.TraitInfoOrDefault<AcceptsDeliveredCashInfo>();
|
||||
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<DeliversCashInfo>().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<DeliversCashInfo>().Type;
|
||||
var targetInfo = target.Info.TraitInfoOrDefault<AcceptsDeliveredCashInfo>();
|
||||
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<DeliversCashInfo>().Type;
|
||||
return !string.IsNullOrEmpty(type) && targetInfo.ValidTypes.Contains(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,17 +100,19 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (target == self)
|
||||
return false;
|
||||
|
||||
var type = self.Info.TraitInfo<DeliversExperienceInfo>().Type;
|
||||
var targetInfo = target.Info.TraitInfoOrDefault<AcceptsDeliveredExperienceInfo>();
|
||||
var targetGainsExperience = target.TraitOrDefault<GainsExperience>();
|
||||
if (targetGainsExperience == null || targetInfo == null)
|
||||
if (targetGainsExperience == null || targetGainsExperience.Level == targetGainsExperience.MaxLevel)
|
||||
return false;
|
||||
|
||||
if (targetGainsExperience.Level == targetGainsExperience.MaxLevel)
|
||||
var targetInfo = target.Info.TraitInfoOrDefault<AcceptsDeliveredExperienceInfo>();
|
||||
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<DeliversExperienceInfo>().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<DeliversExperienceInfo>().Type;
|
||||
var targetInfo = target.Info.TraitInfoOrDefault<AcceptsDeliveredExperienceInfo>();
|
||||
var targetGainsExperience = target.Actor.TraitOrDefault<GainsExperience>();
|
||||
|
||||
if (targetGainsExperience == null || targetInfo == null)
|
||||
if (targetGainsExperience == null || targetGainsExperience.Level == targetGainsExperience.MaxLevel)
|
||||
return false;
|
||||
|
||||
if (targetGainsExperience.Level == targetGainsExperience.MaxLevel)
|
||||
var targetInfo = target.Info.TraitInfoOrDefault<AcceptsDeliveredExperienceInfo>();
|
||||
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<DeliversExperienceInfo>().Type;
|
||||
return !string.IsNullOrEmpty(type) && targetInfo.ValidTypes.Contains(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user