Delete critter from combat during _partyFixMultipleMembers (#277)

Co-authored-by: Alexander Batalov <alex.batalov@gmail.com>
This commit is contained in:
Vasilii Rogin 2023-05-24 21:32:09 +03:00 committed by GitHub
parent 53a4437be9
commit 70b0b61664
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 46 additions and 56 deletions

View File

@ -6,6 +6,7 @@
#include "animation.h"
#include "color.h"
#include "combat.h"
#include "combat_ai.h"
#include "combat_ai_defs.h"
#include "config.h"
@ -80,7 +81,7 @@ static int _partyMemberPrepItemSave(Object* object);
static int _partyMemberItemSave(Object* object);
static int _partyMemberItemRecover(STRUCT_519DA8* a1);
static int _partyMemberClearItemList();
static int _partyFixMultipleMembers();
static int partyFixMultipleMembers();
static int _partyMemberCopyLevelInfo(Object* object, int a2);
// 0x519D9C
@ -655,7 +656,7 @@ int _partyMemberRecoverLoad()
_partyStatePrepped = 0;
if (!_isLoadingGame()) {
_partyFixMultipleMembers();
partyFixMultipleMembers();
}
return 0;
@ -759,7 +760,7 @@ int partyMembersLoad(File* stream)
}
}
_partyFixMultipleMembers();
partyFixMultipleMembers();
for (int index = 1; index < gPartyMemberDescriptionsLength; index++) {
STRU_519DBC* ptr_519DBC = &(_partyMemberLevelUpInfoList[index]);
@ -1196,16 +1197,14 @@ int partyGetBestSkillValue(int skill)
}
// 0x495620
static int _partyFixMultipleMembers()
static int partyFixMultipleMembers()
{
debugPrint("\n\n\n[Party Members]:");
// NOTE: Original code is slightly different (uses two nested loops).
int critterCount = 0;
for (Object* obj = objectFindFirst(); obj != NULL; obj = objectFindNext()) {
if (PID_TYPE(obj->pid) == OBJ_TYPE_CRITTER) {
critterCount++;
}
Object* obj = objectFindFirst();
while (obj != NULL) {
bool isPartyMember = false;
for (int index = 1; index < gPartyMemberDescriptionsLength; index++) {
if (obj->pid == gPartyMemberPids[index]) {
@ -1214,49 +1213,26 @@ static int _partyFixMultipleMembers()
}
}
if (!isPartyMember) {
continue;
}
if (isPartyMember) {
debugPrint("\n PM: %s", critterGetName(obj));
bool v19 = false;
bool remove = false;
if (obj->sid == -1) {
v19 = true;
remove = true;
} else {
Object* v7 = NULL;
for (int i = 0; i < gPartyMembersLength; i++) {
if (obj->pid == gPartyMembers[i].object->pid) {
v7 = gPartyMembers[i].object;
break;
}
}
if (v7 != NULL && obj != v7) {
if (v7->sid == obj->sid) {
// NOTE: Uninline.
Object* partyMember = partyMemberFindByPid(obj->pid);
if (partyMember != NULL && partyMember != obj) {
if (partyMember->sid == obj->sid) {
obj->sid = -1;
}
v19 = true;
remove = true;
}
}
if (!v19) {
continue;
}
Object* v10 = NULL;
for (int i = 0; i < gPartyMembersLength; i++) {
if (obj->pid == gPartyMembers[i].object->pid) {
v10 = gPartyMembers[i].object;
}
}
// TODO: Probably wrong.
if (obj == v10) {
debugPrint("\nError: Attempting to destroy evil critter doppleganger FAILED!");
continue;
}
if (remove) {
// NOTE: Uninline.
if (obj != partyMemberFindByPid(obj->pid)) {
debugPrint("\nDestroying evil critter doppleganger!");
if (obj->sid != -1) {
@ -1268,7 +1244,21 @@ static int _partyFixMultipleMembers()
}
}
_combat_delete_critter(obj);
objectDestroy(obj, NULL);
// Start over.
critterCount = 0;
obj = objectFindFirst();
continue;
} else {
debugPrint("\nError: Attempting to destroy evil critter doppleganger FAILED!");
}
}
}
obj = objectFindNext();
}
for (int index = 0; index < gPartyMembersLength; index++) {