diff --git a/src/combat.cc b/src/combat.cc index 0f3599c..42e2188 100644 --- a/src/combat.cc +++ b/src/combat.cc @@ -2171,7 +2171,9 @@ int combatLoad(File* stream) if (a2 == -1) { aiInfo->friendlyDead = NULL; } else { - aiInfo->friendlyDead = objectFindById(a2); + // SFALL: Fix incorrect object type search when loading a game in + // combat mode. + aiInfo->friendlyDead = objectTypedFindById(a2, OBJ_TYPE_CRITTER); if (aiInfo->friendlyDead == NULL) return -1; } @@ -2180,7 +2182,9 @@ int combatLoad(File* stream) if (a2 == -1) { aiInfo->lastTarget = NULL; } else { - aiInfo->lastTarget = objectFindById(a2); + // SFALL: Fix incorrect object type search when loading a game in + // combat mode. + aiInfo->lastTarget = objectTypedFindById(a2, OBJ_TYPE_CRITTER); if (aiInfo->lastTarget == NULL) return -1; } @@ -2189,7 +2193,9 @@ int combatLoad(File* stream) if (a2 == -1) { aiInfo->lastItem = NULL; } else { - aiInfo->lastItem = objectFindById(a2); + // SFALL: Fix incorrect object type search when loading a game in + // combat mode. + aiInfo->lastItem = objectTypedFindById(a2, OBJ_TYPE_ITEM); if (aiInfo->lastItem == NULL) return -1; } diff --git a/src/object.cc b/src/object.cc index 6d1e6f5..5a1f908 100644 --- a/src/object.cc +++ b/src/object.cc @@ -5222,3 +5222,16 @@ static int _obj_preload_sort(const void* a1, const void* a2) cmp = ((v1 & 0xFF0000) >> 16) - (((v2 & 0xFF0000) >> 16)); return cmp; } + +Object* objectTypedFindById(int id, int type) +{ + Object* obj = objectFindFirst(); + while (obj != NULL) { + if (obj->id == id && PID_TYPE(obj->pid) == type) { + return obj; + } + obj = objectFindNext(); + } + + return NULL; +} diff --git a/src/object.h b/src/object.h index 93c62b3..18ae033 100644 --- a/src/object.h +++ b/src/object.h @@ -96,4 +96,6 @@ int _obj_save_dude(File* stream); int _obj_load_dude(File* stream); void _obj_fix_violence_settings(int* fid); +Object* objectTypedFindById(int id, int type); + #endif /* OBJECT_H */