Skip to content

Commit

Permalink
warn and adapt when adding and removing NaN priorities
Browse files Browse the repository at this point in the history
  • Loading branch information
Goober5000 committed Dec 12, 2024
1 parent 09552bb commit 58f90c2
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions code/ai/aigoals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1151,7 +1151,11 @@ void ai_add_goal_sub_sexp( int sexp, int type, ai_info *aip, ai_goal *aigp, cons
}
}

if ( aigp->priority > MAX_GOAL_PRIORITY || priority_is_nan || priority_is_nan_forever ) {
if ( priority_is_nan || priority_is_nan_forever ) {
Warning(LOCATION, "add-goal tried to add %s with a NaN priority; aborting...", Sexp_nodes[CAR(sexp)].text);
ai_goal_reset(aigp);
return;
} else if ( aigp->priority > MAX_GOAL_PRIORITY ) {
nprintf (("AI", "bashing add-goal sexpression priority of goal %s from %d to %d.\n", Sexp_nodes[CAR(sexp)].text, aigp->priority, MAX_GOAL_PRIORITY));
aigp->priority = MAX_GOAL_PRIORITY;
}
Expand Down Expand Up @@ -1255,7 +1259,12 @@ int ai_remove_goal_sexp_sub( int sexp, ai_goal* aigp, bool &remove_more )
int _priority = (n >= 0) ? eval_num(n, _priority_is_nan, _priority_is_nan_forever) : priority_if_no_n;
n = CDR(sexp); // we want the first node after the goal sub-tree

if (_priority > MAX_GOAL_PRIORITY || _priority_is_nan || _priority_is_nan_forever)
if (_priority_is_nan || _priority_is_nan_forever)
{
Warning(LOCATION, "remove-goal tried to remove %s with a NaN priority; the priority will not be used for goal comparison", Sexp_nodes[CAR(sexp)].text);
_priority = -1;
}
else if (_priority > MAX_GOAL_PRIORITY)
{
nprintf(("AI", "bashing remove-goal sexpression priority of goal %s from %d to %d.\n", Sexp_nodes[CAR(sexp)].text, _priority, MAX_GOAL_PRIORITY));
_priority = MAX_GOAL_PRIORITY;
Expand Down

0 comments on commit 58f90c2

Please sign in to comment.