Skip to content

Commit

Permalink
Added throwing actor.Crushables initialization checks to Aircraft & L…
Browse files Browse the repository at this point in the history
…ocomotor.IsBlockedBy(...)

Also changed the wording for HierarchicalPathFinder.ActorIsBlocking(Actor actor).
All three now tell which trait had the error in the error message.
This may lead to more crashes; however, those crashes will report otherwise silent issues.
  • Loading branch information
atlimit8 committed Feb 6, 2024
1 parent c30a5b4 commit 0459e2e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Pathfinder/HierarchicalPathFinder.cs
Expand Up @@ -651,7 +651,7 @@ bool ActorIsBlocking(Actor actor)
{
var crushables = actor.Crushables;
if (crushables == null)
throw new InvalidOperationException($"Actor {actor} is still in the process of being created. Cannot determine if it is blocking.");
throw new InvalidOperationException($"Actor {actor.Info.Name} is still in the process of being created. HierarchicalPathFinder cannot determine if it is blocking.");

var isMovable = actor.OccupiesSpace is Mobile mobile && !mobile.IsTraitDisabled && !mobile.IsTraitPaused && !mobile.IsImmovable;
if (isMovable)
Expand Down
6 changes: 5 additions & 1 deletion OpenRA.Mods.Common/Traits/Air/Aircraft.cs
Expand Up @@ -692,6 +692,10 @@ bool IsBlockedBy(Actor self, Actor otherActor, Actor ignoreActor, bool blockedBy
if (otherActor == self || otherActor == ignoreActor)
return false;

var crushables = otherActor.Crushables;
if (crushables == null)
throw new InvalidOperationException($"Actor {otherActor.Info.Name} is still in the process of being created. Aircraft cannot determine if it is blocking.");

// We are not blocked by actors we can nudge out of the way
// TODO: Generalize blocker checks and handling here and in Locomotor
if (!blockedByMobile && self.Owner.RelationshipWith(otherActor.Owner) == PlayerRelationship.Ally &&
Expand All @@ -713,7 +717,7 @@ bool IsBlockedBy(Actor self, Actor otherActor, Actor ignoreActor, bool blockedBy

// If the other actor in our way cannot be crushed, we are blocked.
// PERF: Avoid LINQ.
foreach (var crushable in otherActor.Crushables)
foreach (var crushable in crushables)
if (crushable.CrushableBy(otherActor, self, Info.Crushes))
return false;

Expand Down
5 changes: 4 additions & 1 deletion OpenRA.Mods.Common/Traits/World/Locomotor.cs
Expand Up @@ -346,6 +346,10 @@ bool IsBlockedBy(Actor actor, Actor otherActor, Actor ignoreActor, CPos cell, Bl
if (otherActor == ignoreActor)
return false;

var crushables = otherActor.Crushables;
if (crushables == null)
throw new InvalidOperationException($"Actor {otherActor.Info.Name} is still in the process of being created. Locomotor cannot determine if it is blocking.");

var otherMobile = otherActor.OccupiesSpace as Mobile;
var otherIsMovable = otherMobile != null && !otherMobile.IsTraitDisabled && !otherMobile.IsTraitPaused && !otherMobile.IsImmovable;
var otherIsMoving = otherIsMovable && otherMobile.CurrentMovementTypes.HasMovementType(MovementType.Horizontal);
Expand Down Expand Up @@ -380,7 +384,6 @@ bool IsBlockedBy(Actor actor, Actor otherActor, Actor ignoreActor, CPos cell, Bl

// If the other actor in our way cannot be crushed, we are blocked.
// PERF: Avoid LINQ.
var crushables = otherActor.Crushables;
foreach (var crushable in crushables)
if (crushable.CrushableBy(otherActor, actor, Info.Crushes))
return false;
Expand Down

0 comments on commit 0459e2e

Please sign in to comment.