Misc code improvements
This commit is contained in:
@@ -102,6 +102,10 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public readonly Player Player;
|
public readonly Player Player;
|
||||||
|
|
||||||
readonly Predicate<Actor> unitCannotBeOrdered;
|
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>();
|
public List<Squad> Squads = new List<Squad>();
|
||||||
|
|
||||||
@@ -110,10 +114,6 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
IBotNotifyIdleBaseUnits[] notifyIdleBaseUnits;
|
IBotNotifyIdleBaseUnits[] notifyIdleBaseUnits;
|
||||||
|
|
||||||
CPos initialBaseCenter;
|
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 rushTicks;
|
||||||
int assignRolesTicks;
|
int assignRolesTicks;
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
var hash = 0;
|
var hash = 0;
|
||||||
foreach (var player in Repairers)
|
foreach (var player in Repairers)
|
||||||
hash ^= Sync.HashPlayer(player);
|
hash ^= Sync.HashPlayer(player);
|
||||||
|
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -86,7 +87,6 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (string.IsNullOrEmpty(Info.RepairCondition))
|
if (string.IsNullOrEmpty(Info.RepairCondition))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var currentRepairers = Repairers.Count;
|
|
||||||
while (Repairers.Count > repairTokens.Count)
|
while (Repairers.Count > repairTokens.Count)
|
||||||
repairTokens.Push(self.GrantCondition(Info.RepairCondition));
|
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)
|
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>();
|
var targetInfo = target.Info.TraitInfoOrDefault<AcceptsDeliveredCashInfo>();
|
||||||
return targetInfo != null
|
if (targetInfo == null || !targetInfo.ValidStances.HasStance(target.Owner.RelationshipWith(self.Owner)))
|
||||||
&& targetInfo.ValidStances.HasStance(target.Owner.RelationshipWith(self.Owner))
|
return false;
|
||||||
&& (targetInfo.ValidTypes.Count == 0
|
|
||||||
|| (!string.IsNullOrEmpty(type) && targetInfo.ValidTypes.Contains(type)));
|
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)
|
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>();
|
var targetInfo = target.Info.TraitInfoOrDefault<AcceptsDeliveredCashInfo>();
|
||||||
return targetInfo != null
|
if (targetInfo == null || !targetInfo.ValidStances.HasStance(target.Owner.RelationshipWith(self.Owner)))
|
||||||
&& targetInfo.ValidStances.HasStance(target.Owner.RelationshipWith(self.Owner))
|
return false;
|
||||||
&& (targetInfo.ValidTypes.Count == 0
|
|
||||||
|| (!string.IsNullOrEmpty(type) && targetInfo.ValidTypes.Contains(type)));
|
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)
|
if (target == self)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
var type = self.Info.TraitInfo<DeliversExperienceInfo>().Type;
|
|
||||||
var targetInfo = target.Info.TraitInfoOrDefault<AcceptsDeliveredExperienceInfo>();
|
|
||||||
var targetGainsExperience = target.TraitOrDefault<GainsExperience>();
|
var targetGainsExperience = target.TraitOrDefault<GainsExperience>();
|
||||||
if (targetGainsExperience == null || targetInfo == null)
|
if (targetGainsExperience == null || targetGainsExperience.Level == targetGainsExperience.MaxLevel)
|
||||||
return false;
|
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 false;
|
||||||
|
|
||||||
return targetInfo.ValidStances.HasStance(target.Owner.RelationshipWith(self.Owner))
|
if (targetInfo.ValidTypes.Count == 0)
|
||||||
&& (targetInfo.ValidTypes.Count == 0 || (!string.IsNullOrEmpty(type) && targetInfo.ValidTypes.Contains(type)));
|
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)
|
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)
|
if (target.Actor == null || target.Actor == self)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
var type = self.Info.TraitInfo<DeliversExperienceInfo>().Type;
|
|
||||||
var targetInfo = target.Info.TraitInfoOrDefault<AcceptsDeliveredExperienceInfo>();
|
|
||||||
var targetGainsExperience = target.Actor.TraitOrDefault<GainsExperience>();
|
var targetGainsExperience = target.Actor.TraitOrDefault<GainsExperience>();
|
||||||
|
if (targetGainsExperience == null || targetGainsExperience.Level == targetGainsExperience.MaxLevel)
|
||||||
if (targetGainsExperience == null || targetInfo == null)
|
|
||||||
return false;
|
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 false;
|
||||||
|
|
||||||
return targetInfo.ValidStances.HasStance(target.Owner.RelationshipWith(self.Owner))
|
if (targetInfo.ValidTypes.Count == 0)
|
||||||
&& (targetInfo.ValidTypes.Count == 0 || (!string.IsNullOrEmpty(type) && targetInfo.ValidTypes.Contains(type)));
|
return true;
|
||||||
|
|
||||||
|
var type = self.Info.TraitInfo<DeliversExperienceInfo>().Type;
|
||||||
|
return !string.IsNullOrEmpty(type) && targetInfo.ValidTypes.Contains(type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user