Implement equality on TraitPair.
This commit is contained in:
@@ -255,7 +255,7 @@ namespace OpenRA
|
||||
|
||||
public void Reset() { index = -1; }
|
||||
public bool MoveNext() { return ++index < actors.Count; }
|
||||
public TraitPair<T> Current { get { return new TraitPair<T> { Actor = actors[index], Trait = traits[index] }; } }
|
||||
public TraitPair<T> Current { get { return new TraitPair<T>(actors[index], traits[index]); } }
|
||||
object System.Collections.IEnumerator.Current { get { return Current; } }
|
||||
public void Dispose() { }
|
||||
}
|
||||
|
||||
@@ -408,14 +408,21 @@ namespace OpenRA
|
||||
}
|
||||
}
|
||||
|
||||
public struct TraitPair<T>
|
||||
public struct TraitPair<T> : IEquatable<TraitPair<T>>
|
||||
{
|
||||
public Actor Actor;
|
||||
public T Trait;
|
||||
public readonly Actor Actor;
|
||||
public readonly T Trait;
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "{0}->{1}".F(Actor.Info.Name, Trait.GetType().Name);
|
||||
}
|
||||
public TraitPair(Actor actor, T trait) { Actor = actor; Trait = trait; }
|
||||
|
||||
public static bool operator ==(TraitPair<T> me, TraitPair<T> other) { return me.Actor == other.Actor && Equals(me.Trait, other.Trait); }
|
||||
public static bool operator !=(TraitPair<T> me, TraitPair<T> other) { return !(me == other); }
|
||||
|
||||
public override int GetHashCode() { return Actor.GetHashCode() ^ Trait.GetHashCode(); }
|
||||
|
||||
public bool Equals(TraitPair<T> other) { return this == other; }
|
||||
public override bool Equals(object obj) { return obj is TraitPair<T> && Equals((TraitPair<T>)obj); }
|
||||
|
||||
public override string ToString() { return "{0}->{1}".F(Actor.Info.Name, Trait.GetType().Name); }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,7 +236,7 @@ namespace OpenRA.Mods.Common.Orders
|
||||
|
||||
var blockers = allTiles.SelectMany(world.ActorMap.GetActorsAt)
|
||||
.Where(a => a.Owner == queue.Actor.Owner && a.IsIdle)
|
||||
.Select(a => new TraitPair<Mobile> { Actor = a, Trait = a.TraitOrDefault<Mobile>() });
|
||||
.Select(a => new TraitPair<Mobile>(a, a.TraitOrDefault<Mobile>()));
|
||||
|
||||
foreach (var blocker in blockers.Where(x => x.Trait != null))
|
||||
{
|
||||
|
||||
@@ -361,7 +361,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public virtual TraitPair<Production> MostLikelyProducer()
|
||||
{
|
||||
var trait = self.TraitsImplementing<Production>().FirstOrDefault(p => p.Info.Produces.Contains(Info.Type));
|
||||
return new TraitPair<Production> { Actor = self, Trait = trait };
|
||||
return new TraitPair<Production>(self, trait);
|
||||
}
|
||||
|
||||
// Builds a unit from the actor that holds this queue (1 queue per building)
|
||||
|
||||
Reference in New Issue
Block a user