diff --git a/OpenRA.Game/TraitDictionary.cs b/OpenRA.Game/TraitDictionary.cs index ce07a9fef0..81cb4c20ce 100644 --- a/OpenRA.Game/TraitDictionary.cs +++ b/OpenRA.Game/TraitDictionary.cs @@ -86,13 +86,13 @@ namespace OpenRA public T Get(Actor actor) { CheckDestroyed(actor); - return InnerGet().Get(actor.ActorID); + return InnerGet().Get(actor); } public T GetOrDefault(Actor actor) { CheckDestroyed(actor); - return InnerGet().GetOrDefault(actor.ActorID); + return InnerGet().GetOrDefault(actor); } public IEnumerable WithInterface(Actor actor) @@ -144,22 +144,22 @@ namespace OpenRA traits.Insert(insertIndex, (T)trait); } - public T Get(uint actor) + public T Get(Actor actor) { var result = GetOrDefault(actor); if (result == null) - throw new InvalidOperationException("Actor does not have trait of type `{0}`".F(typeof(T))); + throw new InvalidOperationException("Actor {0} does not have trait of type `{1}`".F(actor.Info.Name, typeof(T))); return result; } - public T GetOrDefault(uint actor) + public T GetOrDefault(Actor actor) { ++Queries; - var index = actors.BinarySearchMany(actor); - if (index >= actors.Count || actors[index].ActorID != actor) + var index = actors.BinarySearchMany(actor.ActorID); + if (index >= actors.Count || actors[index] != actor) return default(T); - else if (index + 1 < actors.Count && actors[index + 1].ActorID == actor) - throw new InvalidOperationException("Actor {0} has multiple traits of type `{1}`".F(actors[index].Info.Name, typeof(T))); + else if (index + 1 < actors.Count && actors[index + 1] == actor) + throw new InvalidOperationException("Actor {0} has multiple traits of type `{1}`".F(actor.Info.Name, typeof(T))); else return traits[index]; }