diff --git a/src/combat.cc b/src/combat.cc index 771d0da..36c0495 100644 --- a/src/combat.cc +++ b/src/combat.cc @@ -2718,7 +2718,7 @@ static void _combat_over() if (critter != gDude) { // SFALL: Fix to prevent dead NPCs from reloading their weapons. if ((critter->data.critter.combat.results & DAM_DEAD) == 0) { - _cai_attempt_w_reload(critter, 0); + aiAttemptWeaponReload(critter, 0); } } } diff --git a/src/combat_ai.cc b/src/combat_ai.cc index 0c55356..633a83f 100644 --- a/src/combat_ai.cc +++ b/src/combat_ai.cc @@ -2716,33 +2716,31 @@ int _cAIPrepWeaponItem(Object* critter, Object* item) } // 0x42AECC -void _cai_attempt_w_reload(Object* critter_obj, int a2) +void aiAttemptWeaponReload(Object* critter, int animate) { - Object* weapon_obj; - Object* ammo_obj; - int v5; - int v9; - const char* sfx; - int v10; - - weapon_obj = critterGetItem2(critter_obj); - if (weapon_obj == NULL) { + Object* weapon = critterGetItem2(critter); + if (weapon == NULL) { return; } - v5 = ammoGetQuantity(weapon_obj); - if (v5 < ammoGetCapacity(weapon_obj) && _ai_have_ammo(critter_obj, weapon_obj, &ammo_obj)) { - v9 = weaponReload(weapon_obj, ammo_obj); - if (v9 == 0) { - _obj_destroy(ammo_obj); - } + int ammoQuantity = ammoGetQuantity(weapon); + int ammoCapacity = ammoGetCapacity(weapon); + if (ammoQuantity < ammoCapacity) { + Object* ammo; + if (_ai_have_ammo(critter, weapon, &ammo)) { + int rc = weaponReload(weapon, ammo); + if (rc == 0) { + _obj_destroy(ammo); + } - if (v9 != -1 && objectIsPartyMember(critter_obj)) { - v10 = _gsound_compute_relative_volume(critter_obj); - sfx = sfxBuildWeaponName(WEAPON_SOUND_EFFECT_READY, weapon_obj, HIT_MODE_RIGHT_WEAPON_PRIMARY, NULL); - _gsound_play_sfx_file_volume(sfx, v10); - if (a2) { - _ai_magic_hands(critter_obj, weapon_obj, 5002); + if (rc != -1 && objectIsPartyMember(critter)) { + int volume = _gsound_compute_relative_volume(critter); + const char* sfx = sfxBuildWeaponName(WEAPON_SOUND_EFFECT_READY, weapon, HIT_MODE_RIGHT_WEAPON_PRIMARY, NULL); + _gsound_play_sfx_file_volume(sfx, volume); + + if (animate) { + _ai_magic_hands(critter, weapon, 5002); + } } } } diff --git a/src/combat_ai.h b/src/combat_ai.h index 25f68d2..48cb157 100644 --- a/src/combat_ai.h +++ b/src/combat_ai.h @@ -48,7 +48,7 @@ void _caiTeamCombatExit(); Object* _ai_search_inven_weap(Object* critter, int a2, Object* a3); Object* _ai_search_inven_armor(Object* critter); int _cAIPrepWeaponItem(Object* critter, Object* item); -void _cai_attempt_w_reload(Object* critter_obj, int a2); +void aiAttemptWeaponReload(Object* critter, int animate); void _combat_ai_begin(int a1, void* a2); void _combat_ai_over(); int _cai_perform_distance_prefs(Object* a1, Object* a2); diff --git a/src/game_dialog.cc b/src/game_dialog.cc index bab70fd..41b0cde 100644 --- a/src/game_dialog.cc +++ b/src/game_dialog.cc @@ -3245,7 +3245,7 @@ void _gdialog_barter_destroy_win() windowDestroy(gGameDialogWindow); gGameDialogWindow = -1; - _cai_attempt_w_reload(gGameDialogSpeaker, 0); + aiAttemptWeaponReload(gGameDialogSpeaker, 0); } // 0x448660 @@ -3656,7 +3656,7 @@ void partyMemberControlWindowHandleEvents() Object* weapon = _ai_search_inven_weap(gGameDialogSpeaker, 0, NULL); if (weapon != NULL) { _inven_wield(gGameDialogSpeaker, weapon, 1); - _cai_attempt_w_reload(gGameDialogSpeaker, 0); + aiAttemptWeaponReload(gGameDialogSpeaker, 0); int num = _gdPickAIUpdateMsg(gGameDialogSpeaker); char* msg = getmsg(&gProtoMessageList, &messageListItem, num);