Skip to content

Commit

Permalink
Add Stances support to Supplies system
Browse files Browse the repository at this point in the history
  • Loading branch information
reaperrr committed Mar 21, 2017
1 parent 8eeb6e7 commit 85c0734
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 3 additions & 0 deletions OpenRA.Mods.Common/Traits/AcceptsSupplies.cs
Expand Up @@ -20,6 +20,9 @@ public class AcceptsSuppliesInfo : ITraitInfo
[Desc("Accepted `DeliversSupplies` types. Leave empty to accept all types.")]
public readonly HashSet<string> ValidTypes = new HashSet<string>();

[Desc("Stance the delivering actor needs to enter.")]
public readonly Stance ValidStances = Stance.Ally;

public object Create(ActorInitializer init) { return new AcceptsSupplies(init.Self, this); }
}

Expand Down
10 changes: 8 additions & 2 deletions OpenRA.Mods.Common/Traits/DeliversSupplies.cs
Expand Up @@ -89,14 +89,20 @@ public override bool CanTargetActor(Actor self, Actor target, TargetModifiers mo
{
var type = self.Info.TraitInfo<DeliversSuppliesInfo>().Type;
var targetInfo = target.Info.TraitInfoOrDefault<AcceptsSuppliesInfo>();
return targetInfo != null && (targetInfo.ValidTypes.Count == 0 || (!string.IsNullOrEmpty(type) && targetInfo.ValidTypes.Contains(type)));
return targetInfo != null
&& targetInfo.ValidStances.HasStance(target.Owner.Stances[self.Owner])
&& (targetInfo.ValidTypes.Count == 0
|| (!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<DeliversSuppliesInfo>().Type;
var targetInfo = target.Info.TraitInfoOrDefault<AcceptsSuppliesInfo>();
return targetInfo != null && (targetInfo.ValidTypes.Count == 0 || (!string.IsNullOrEmpty(type) && targetInfo.ValidTypes.Contains(type)));
return targetInfo != null
&& targetInfo.ValidStances.HasStance(target.Owner.Stances[self.Owner])
&& (targetInfo.ValidTypes.Count == 0
|| (!string.IsNullOrEmpty(type) && targetInfo.ValidTypes.Contains(type)));
}
}
}
Expand Down

0 comments on commit 85c0734

Please sign in to comment.