Skip to content

Commit 4a819d7

Browse files
Include more valid object types in this check (#4500)
* Include more valid object types in this check The previous version of the fix only included ships because it was believed to be the object that a ship used to be guarding. Now it's clear that this is an object that the ship is currently targeting *after* guarding something. So remove the UNREACHABLE and manually check the valid object types with an assert. Then only continue with the function if it is the right target type. * typo
1 parent d5af6b5 commit 4a819d7

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

code/ai/aicode.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10015,12 +10015,26 @@ void guard_object_was_hit(object *guard_objp, object *hitter_objp)
1001510015
aip->submode = SM_ATTACK;
1001610016
aip->submode_start_time = Missiontime;
1001710017
aip->active_goal = AI_ACTIVE_GOAL_DYNAMIC;
10018-
} else if (Objects[aip->target_objnum].type == OBJ_SHIP) {
10019-
int num_attacking_cur, num_attacking_new;
10018+
} else {
10019+
// This section used to be a lot simpler, but some "invalid" object types were probably getting into num_ships_attacking
10020+
// below, so we have to manually return for some object types and make sure to assert for other object types
10021+
// that are symptomatic of a larger problem with the engine.
10022+
10023+
// This just checks to see that the target was a valid type. If it is not one of these, something really
10024+
// could be drastically wrong in the engine.
10025+
Assertion(aip->target_objnum == OBJ_SHIP || aip->target_objnum == OBJ_WEAPON || aip->target_objnum == OBJ_DEBRIS || aip->target_objnum == OBJ_ASTEROID || aip->target_objnum == OBJ_WAYPOINT,
10026+
"This function just discovered that %s has an invalid target object type of %d. This is bad. Please report!",
10027+
Ships[aip->shipnum].ship_name, Objects[aip->target_objnum].type);
10028+
10029+
if (!(aip->target_objnum == OBJ_SHIP || aip->target_objnum == OBJ_WEAPON || aip->target_objnum == OBJ_ASTEROID || aip->target_objnum == OBJ_DEBRIS)){
10030+
// it's probably a valid target, but retail would not count those cases, so just return.
10031+
return;
10032+
}
10033+
10034+
int num_attacking_cur = num_ships_attacking(aip->target_objnum);
1002010035

10021-
num_attacking_cur = num_ships_attacking(aip->target_objnum);
1002210036
if (num_attacking_cur > 1) {
10023-
num_attacking_new = num_ships_attacking(hitter_objnum);
10037+
int num_attacking_new = num_ships_attacking(hitter_objnum);
1002410038

1002510039
if (num_attacking_new < num_attacking_cur) {
1002610040

@@ -10037,8 +10051,6 @@ void guard_object_was_hit(object *guard_objp, object *hitter_objp)
1003710051
aip->active_goal = AI_ACTIVE_GOAL_DYNAMIC;
1003810052
}
1003910053
}
10040-
} else {
10041-
UNREACHABLE("The AI previously had a guard goal to guard something besides a ship, specifically an object of type %d. As we understand it, this should not happen. Please report!", Objects[aip->target_objnum].type);
1004210054
}
1004310055
}
1004410056
}

0 commit comments

Comments
 (0)