Improve aiAttemptWeaponReload

This commit is contained in:
Alexander Batalov 2022-08-31 10:05:00 +03:00
parent b3431fadf7
commit 1b69c97ce4
4 changed files with 24 additions and 26 deletions

View File

@ -2718,7 +2718,7 @@ static void _combat_over()
if (critter != gDude) { if (critter != gDude) {
// SFALL: Fix to prevent dead NPCs from reloading their weapons. // SFALL: Fix to prevent dead NPCs from reloading their weapons.
if ((critter->data.critter.combat.results & DAM_DEAD) == 0) { if ((critter->data.critter.combat.results & DAM_DEAD) == 0) {
_cai_attempt_w_reload(critter, 0); aiAttemptWeaponReload(critter, 0);
} }
} }
} }

View File

@ -2716,33 +2716,31 @@ int _cAIPrepWeaponItem(Object* critter, Object* item)
} }
// 0x42AECC // 0x42AECC
void _cai_attempt_w_reload(Object* critter_obj, int a2) void aiAttemptWeaponReload(Object* critter, int animate)
{ {
Object* weapon_obj; Object* weapon = critterGetItem2(critter);
Object* ammo_obj; if (weapon == NULL) {
int v5;
int v9;
const char* sfx;
int v10;
weapon_obj = critterGetItem2(critter_obj);
if (weapon_obj == NULL) {
return; return;
} }
v5 = ammoGetQuantity(weapon_obj); int ammoQuantity = ammoGetQuantity(weapon);
if (v5 < ammoGetCapacity(weapon_obj) && _ai_have_ammo(critter_obj, weapon_obj, &ammo_obj)) { int ammoCapacity = ammoGetCapacity(weapon);
v9 = weaponReload(weapon_obj, ammo_obj); if (ammoQuantity < ammoCapacity) {
if (v9 == 0) { Object* ammo;
_obj_destroy(ammo_obj); if (_ai_have_ammo(critter, weapon, &ammo)) {
} int rc = weaponReload(weapon, ammo);
if (rc == 0) {
_obj_destroy(ammo);
}
if (v9 != -1 && objectIsPartyMember(critter_obj)) { if (rc != -1 && objectIsPartyMember(critter)) {
v10 = _gsound_compute_relative_volume(critter_obj); int volume = _gsound_compute_relative_volume(critter);
sfx = sfxBuildWeaponName(WEAPON_SOUND_EFFECT_READY, weapon_obj, HIT_MODE_RIGHT_WEAPON_PRIMARY, NULL); const char* sfx = sfxBuildWeaponName(WEAPON_SOUND_EFFECT_READY, weapon, HIT_MODE_RIGHT_WEAPON_PRIMARY, NULL);
_gsound_play_sfx_file_volume(sfx, v10); _gsound_play_sfx_file_volume(sfx, volume);
if (a2) {
_ai_magic_hands(critter_obj, weapon_obj, 5002); if (animate) {
_ai_magic_hands(critter, weapon, 5002);
}
} }
} }
} }

View File

@ -48,7 +48,7 @@ void _caiTeamCombatExit();
Object* _ai_search_inven_weap(Object* critter, int a2, Object* a3); Object* _ai_search_inven_weap(Object* critter, int a2, Object* a3);
Object* _ai_search_inven_armor(Object* critter); Object* _ai_search_inven_armor(Object* critter);
int _cAIPrepWeaponItem(Object* critter, Object* item); 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_begin(int a1, void* a2);
void _combat_ai_over(); void _combat_ai_over();
int _cai_perform_distance_prefs(Object* a1, Object* a2); int _cai_perform_distance_prefs(Object* a1, Object* a2);

View File

@ -3245,7 +3245,7 @@ void _gdialog_barter_destroy_win()
windowDestroy(gGameDialogWindow); windowDestroy(gGameDialogWindow);
gGameDialogWindow = -1; gGameDialogWindow = -1;
_cai_attempt_w_reload(gGameDialogSpeaker, 0); aiAttemptWeaponReload(gGameDialogSpeaker, 0);
} }
// 0x448660 // 0x448660
@ -3656,7 +3656,7 @@ void partyMemberControlWindowHandleEvents()
Object* weapon = _ai_search_inven_weap(gGameDialogSpeaker, 0, NULL); Object* weapon = _ai_search_inven_weap(gGameDialogSpeaker, 0, NULL);
if (weapon != NULL) { if (weapon != NULL) {
_inven_wield(gGameDialogSpeaker, weapon, 1); _inven_wield(gGameDialogSpeaker, weapon, 1);
_cai_attempt_w_reload(gGameDialogSpeaker, 0); aiAttemptWeaponReload(gGameDialogSpeaker, 0);
int num = _gdPickAIUpdateMsg(gGameDialogSpeaker); int num = _gdPickAIUpdateMsg(gGameDialogSpeaker);
char* msg = getmsg(&gProtoMessageList, &messageListItem, num); char* msg = getmsg(&gProtoMessageList, &messageListItem, num);