Skip to content

Commit a16be86

Browse files
authored
Actually grab the object's type when doing type checks. (#4505)
PR #4500 added some checks, but accidentally compared `aip->target_objnum` to an object type (although the assertion message correctly retrieved the object type, leading to the bizarre assertion that `OBJ_SHIP`, i.e. 1, was an invalid target object type). This commit makes them all access the `Objects[]` array and retrieve the `.type`, just as the assertion message does (and the pre-#4500 conditional did). Related to #4504, in that it's the source of the failed assertions, although I can't be sure it was the cause of the crashes without testing.
1 parent de80c25 commit a16be86

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

code/ai/aicode.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10022,11 +10022,11 @@ void guard_object_was_hit(object *guard_objp, object *hitter_objp)
1002210022

1002310023
// This just checks to see that the target was a valid type. If it is not one of these, something really
1002410024
// 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,
10025+
Assertion(Objects[aip->target_objnum].type == OBJ_SHIP || Objects[aip->target_objnum].type == OBJ_WEAPON || Objects[aip->target_objnum].type == OBJ_DEBRIS || Objects[aip->target_objnum].type == OBJ_ASTEROID || Objects[aip->target_objnum].type == OBJ_WAYPOINT,
1002610026
"This function just discovered that %s has an invalid target object type of %d. This is bad. Please report!",
1002710027
Ships[aip->shipnum].ship_name, Objects[aip->target_objnum].type);
1002810028

10029-
if (!(aip->target_objnum == OBJ_SHIP || aip->target_objnum == OBJ_WEAPON || aip->target_objnum == OBJ_ASTEROID || aip->target_objnum == OBJ_DEBRIS)){
10029+
if (!(Objects[aip->target_objnum].type == OBJ_SHIP || Objects[aip->target_objnum].type == OBJ_WEAPON || Objects[aip->target_objnum].type == OBJ_ASTEROID || Objects[aip->target_objnum].type == OBJ_DEBRIS)){
1003010030
// it's probably a valid target, but retail would not count those cases, so just return.
1003110031
return;
1003210032
}

0 commit comments

Comments
 (0)