From a48d744cde1aef57ac9671d72610836716177f67 Mon Sep 17 00:00:00 2001 From: Alexander Batalov Date: Fri, 23 Dec 2022 12:44:52 +0300 Subject: [PATCH] Improve actions.cc readability --- src/actions.cc | 388 +++++++++++++++++++++++-------------------------- 1 file changed, 180 insertions(+), 208 deletions(-) diff --git a/src/actions.cc b/src/actions.cc index 5dceebc..ffff2b6 100644 --- a/src/actions.cc +++ b/src/actions.cc @@ -46,7 +46,7 @@ typedef enum ScienceRepairTargetType { } ScienceRepairTargetType; // 0x5106D0 -static int _action_in_explode = 0; +static bool _action_in_explode = false; // 0x5106E0 static const int gNormalDeathAnimations[DAMAGE_TYPE_COUNT] = { @@ -72,13 +72,13 @@ static const int gMaximumBloodDeathAnimations[DAMAGE_TYPE_COUNT] = { static int actionKnockdown(Object* obj, int* anim, int maxDistance, int rotation, int delay); static int _action_blood(Object* obj, int anim, int delay); -static int _pick_death(Object* attacker, Object* defender, Object* weapon, int damage, int anim, bool isFallingBack); -static int _check_death(Object* obj, int anim, int minViolenceLevel, bool isFallingBack); +static int _pick_death(Object* attacker, Object* defender, Object* weapon, int damage, int attackerAnimation, bool hitFromFront); +static int _check_death(Object* obj, int anim, int minViolenceLevel, bool hitFromFront); static int _internal_destroy(Object* a1, Object* a2); -static void _show_damage_to_object(Object* a1, int damage, int flags, Object* weapon, bool isFallingBack, int knockbackDistance, int knockbackRotation, int a8, Object* a9, int a10); +static void _show_damage_to_object(Object* defender, int damage, int flags, Object* weapon, bool hitFromFront, int knockbackDistance, int knockbackRotation, int attackerAnimation, Object* attacker, int delay); static int _show_death(Object* obj, int anim); static int _show_damage_extras(Attack* attack); -static void _show_damage(Attack* attack, int a2, int a3); +static void _show_damage(Attack* attack, int attackerAnimation, int delay); static int _action_melee(Attack* attack, int a2); static int _action_ranged(Attack* attack, int a2); static int _is_next_to(Object* a1, Object* a2); @@ -87,11 +87,11 @@ static int _action_use_skill_in_combat_error(Object* critter); static int _pick_fall(Object* obj, int anim); static int _report_explosion(Attack* attack, Object* a2); static int _finished_explosion(Object* a1, Object* a2); -static int _compute_explosion_damage(int min, int max, Object* a3, int* a4); +static int _compute_explosion_damage(int min, int max, Object* defender, int* knockbackDistancePtr); static int _can_talk_to(Object* a1, Object* a2); static int _talk_to(Object* a1, Object* a2); static int _report_dmg(Attack* attack, Object* a2); -static int _compute_dmg_damage(int min, int max, Object* obj, int* a4, int damage_type); +static int _compute_dmg_damage(int min, int max, Object* obj, int* knockbackDistancePtr, int damageType); static int hideProjectile(void* a1, void* a2); @@ -177,7 +177,7 @@ int _action_blood(Object* obj, int anim, int delay) } // 0x41060C -int _pick_death(Object* attacker, Object* defender, Object* weapon, int damage, int anim, bool isFallingBack) +int _pick_death(Object* attacker, Object* defender, Object* weapon, int damage, int attackerAnimation, bool hitFromFront) { int normalViolenceLevelDamageThreshold = 15; int maximumBloodViolenceLevelDamageThreshold = 45; @@ -188,7 +188,7 @@ int _pick_death(Object* attacker, Object* defender, Object* weapon, int damage, normalViolenceLevelDamageThreshold = 5; maximumBloodViolenceLevelDamageThreshold = 15; damageType = DAMAGE_TYPE_FIRE; - anim = ANIM_FIRE_SINGLE; + attackerAnimation = ANIM_FIRE_SINGLE; } if (attacker == gDude && perkHasRank(attacker, PERK_PYROMANIAC) && damageType == DAMAGE_TYPE_FIRE) { @@ -204,7 +204,7 @@ int _pick_death(Object* attacker, Object* defender, Object* weapon, int damage, int violenceLevel = settings.preferences.violence_level; if (_critter_flag_check(defender->pid, CRITTER_SPECIAL_DEATH)) { - return _check_death(defender, ANIM_EXPLODED_TO_NOTHING, VIOLENCE_LEVEL_NORMAL, isFallingBack); + return _check_death(defender, ANIM_EXPLODED_TO_NOTHING, VIOLENCE_LEVEL_NORMAL, hitFromFront); } bool hasBloodyMess = false; @@ -217,16 +217,16 @@ int _pick_death(Object* attacker, Object* defender, Object* weapon, int damage, // it with bunch of "else" statements. int deathAnim = ANIM_FALL_BACK; - if ((anim == ANIM_THROW_PUNCH && damageType == DAMAGE_TYPE_NORMAL) - || anim == ANIM_KICK_LEG - || anim == ANIM_THRUST_ANIM - || anim == ANIM_SWING_ANIM - || (anim == ANIM_THROW_ANIM && damageType != DAMAGE_TYPE_EXPLOSION)) { + if ((attackerAnimation == ANIM_THROW_PUNCH && damageType == DAMAGE_TYPE_NORMAL) + || attackerAnimation == ANIM_KICK_LEG + || attackerAnimation == ANIM_THRUST_ANIM + || attackerAnimation == ANIM_SWING_ANIM + || (attackerAnimation == ANIM_THROW_ANIM && damageType != DAMAGE_TYPE_EXPLOSION)) { if (violenceLevel == VIOLENCE_LEVEL_MAXIMUM_BLOOD && hasBloodyMess) { deathAnim = ANIM_BIG_HOLE; } } else { - if (anim == ANIM_FIRE_SINGLE && damageType == DAMAGE_TYPE_NORMAL) { + if (attackerAnimation == ANIM_FIRE_SINGLE && damageType == DAMAGE_TYPE_NORMAL) { if (violenceLevel == VIOLENCE_LEVEL_MAXIMUM_BLOOD) { if (hasBloodyMess || maximumBloodViolenceLevelDamageThreshold <= damage) { deathAnim = ANIM_BIG_HOLE; @@ -236,7 +236,7 @@ int _pick_death(Object* attacker, Object* defender, Object* weapon, int damage, if (violenceLevel > VIOLENCE_LEVEL_MINIMAL && (hasBloodyMess || normalViolenceLevelDamageThreshold <= damage)) { if (violenceLevel > VIOLENCE_LEVEL_NORMAL && (hasBloodyMess || maximumBloodViolenceLevelDamageThreshold <= damage)) { deathAnim = gMaximumBloodDeathAnimations[damageType]; - if (_check_death(defender, deathAnim, VIOLENCE_LEVEL_MAXIMUM_BLOOD, isFallingBack) != deathAnim) { + if (_check_death(defender, deathAnim, VIOLENCE_LEVEL_MAXIMUM_BLOOD, hitFromFront) != deathAnim) { deathAnim = gNormalDeathAnimations[damageType]; } } else { @@ -246,15 +246,15 @@ int _pick_death(Object* attacker, Object* defender, Object* weapon, int damage, } } - if (!isFallingBack && deathAnim == ANIM_FALL_BACK) { + if (!hitFromFront && deathAnim == ANIM_FALL_BACK) { deathAnim = ANIM_FALL_FRONT; } - return _check_death(defender, deathAnim, VIOLENCE_LEVEL_NONE, isFallingBack); + return _check_death(defender, deathAnim, VIOLENCE_LEVEL_NONE, hitFromFront); } // 0x410814 -int _check_death(Object* obj, int anim, int minViolenceLevel, bool isFallingBack) +int _check_death(Object* obj, int anim, int minViolenceLevel, bool hitFromFront) { int fid; @@ -265,7 +265,7 @@ int _check_death(Object* obj, int anim, int minViolenceLevel, bool isFallingBack } } - if (isFallingBack) { + if (hitFromFront) { return ANIM_FALL_BACK; } @@ -286,50 +286,50 @@ int _internal_destroy(Object* a1, Object* a2) // TODO: Check very carefully, lots of conditions and jumps. // // 0x4108D0 -void _show_damage_to_object(Object* a1, int damage, int flags, Object* weapon, bool isFallingBack, int knockbackDistance, int knockbackRotation, int a8, Object* a9, int a10) +void _show_damage_to_object(Object* defender, int damage, int flags, Object* weapon, bool hitFromFront, int knockbackDistance, int knockbackRotation, int attackerAnimation, Object* attacker, int delay) { int anim; int fid; const char* sfx_name; - if (_critter_flag_check(a1->pid, CRITTER_NO_KNOCKBACK)) { + if (_critter_flag_check(defender->pid, CRITTER_NO_KNOCKBACK)) { knockbackDistance = 0; } - anim = FID_ANIM_TYPE(a1->fid); - if (!_critter_is_prone(a1)) { + anim = FID_ANIM_TYPE(defender->fid); + if (!_critter_is_prone(defender)) { if ((flags & DAM_DEAD) != 0) { fid = buildFid(OBJ_TYPE_MISC, 10, 0, 0, 0); - if (fid == a9->fid) { - anim = _check_death(a1, ANIM_EXPLODED_TO_NOTHING, VIOLENCE_LEVEL_MAXIMUM_BLOOD, isFallingBack); - } else if (a9->pid == PROTO_ID_0x20001EB) { - anim = _check_death(a1, ANIM_ELECTRIFIED_TO_NOTHING, VIOLENCE_LEVEL_MAXIMUM_BLOOD, isFallingBack); - } else if (a9->fid == FID_0x20001F5) { - anim = _check_death(a1, a8, VIOLENCE_LEVEL_MAXIMUM_BLOOD, isFallingBack); + if (fid == attacker->fid) { + anim = _check_death(defender, ANIM_EXPLODED_TO_NOTHING, VIOLENCE_LEVEL_MAXIMUM_BLOOD, hitFromFront); + } else if (attacker->pid == PROTO_ID_0x20001EB) { + anim = _check_death(defender, ANIM_ELECTRIFIED_TO_NOTHING, VIOLENCE_LEVEL_MAXIMUM_BLOOD, hitFromFront); + } else if (attacker->fid == FID_0x20001F5) { + anim = _check_death(defender, attackerAnimation, VIOLENCE_LEVEL_MAXIMUM_BLOOD, hitFromFront); } else { - anim = _pick_death(a9, a1, weapon, damage, a8, isFallingBack); + anim = _pick_death(attacker, defender, weapon, damage, attackerAnimation, hitFromFront); } if (anim != ANIM_FIRE_DANCE) { if (knockbackDistance != 0 && (anim == ANIM_FALL_FRONT || anim == ANIM_FALL_BACK)) { - actionKnockdown(a1, &anim, knockbackDistance, knockbackRotation, a10); - anim = _action_blood(a1, anim, -1); + actionKnockdown(defender, &anim, knockbackDistance, knockbackRotation, delay); + anim = _action_blood(defender, anim, -1); } else { - sfx_name = sfxBuildCharName(a1, anim, CHARACTER_SOUND_EFFECT_DIE); - animationRegisterPlaySoundEffect(a1, sfx_name, a10); + sfx_name = sfxBuildCharName(defender, anim, CHARACTER_SOUND_EFFECT_DIE); + animationRegisterPlaySoundEffect(defender, sfx_name, delay); - anim = _pick_fall(a1, anim); - animationRegisterAnimate(a1, anim, 0); + anim = _pick_fall(defender, anim); + animationRegisterAnimate(defender, anim, 0); if (anim == ANIM_FALL_FRONT || anim == ANIM_FALL_BACK) { - anim = _action_blood(a1, anim, -1); + anim = _action_blood(defender, anim, -1); } } } else { - fid = buildFid(OBJ_TYPE_CRITTER, a1->fid & 0xFFF, ANIM_FIRE_DANCE, (a1->fid & 0xF000) >> 12, a1->rotation + 1); + fid = buildFid(OBJ_TYPE_CRITTER, defender->fid & 0xFFF, ANIM_FIRE_DANCE, (defender->fid & 0xF000) >> 12, defender->rotation + 1); if (artExists(fid)) { - sfx_name = sfxBuildCharName(a1, anim, CHARACTER_SOUND_EFFECT_UNUSED); - animationRegisterPlaySoundEffect(a1, sfx_name, a10); + sfx_name = sfxBuildCharName(defender, anim, CHARACTER_SOUND_EFFECT_UNUSED); + animationRegisterPlaySoundEffect(defender, sfx_name, delay); // SFALL if (explosionEmitsLight()) { @@ -339,10 +339,10 @@ void _show_damage_to_object(Object* a1, int damage, int flags, Object* weapon, b // // NOTE: Change intensity to 65536 (which is on par with // `anim_set_check_light_fix` Sfall's hack). - animationRegisterSetLightIntensity(a1, 2, 65536, 0); + animationRegisterSetLightIntensity(defender, 2, 65536, 0); } - animationRegisterAnimate(a1, anim, 0); + animationRegisterAnimate(defender, anim, 0); // SFALL if (explosionEmitsLight()) { @@ -354,7 +354,7 @@ void _show_damage_to_object(Object* a1, int damage, int flags, Object* weapon, b // workaround for `anim_set_check_light_fix` hack which // requires two upper bytes to be non-zero to override // default behaviour. - animationRegisterSetLightIntensity(a1, 0, 0, -1); + animationRegisterSetLightIntensity(defender, 0, 0, -1); } int randomDistance = randomBetween(2, 5); @@ -366,13 +366,13 @@ void _show_damage_to_object(Object* a1, int damage, int flags, Object* weapon, b int rotation = randomRotation; int distance = randomDistance; while (true) { - int tile = tileGetTileInDirection(a1->tile, (rotation + randomRotation) % ROTATION_COUNT, distance); - if (!isExitGridAt(tile, a1->elevation)) { + int tile = tileGetTileInDirection(defender->tile, (rotation + randomRotation) % ROTATION_COUNT, distance); + if (!isExitGridAt(tile, defender->elevation)) { Object* obstacle = NULL; - _make_straight_path(a1, a1->tile, tile, NULL, &obstacle, 4); + _make_straight_path(defender, defender->tile, tile, NULL, &obstacle, 4); if (obstacle == NULL) { - animationRegisterRotateToTile(a1, tile); - animationRegisterMoveToTileStraight(a1, tile, a1->elevation, anim, 0); + animationRegisterRotateToTile(defender, tile); + animationRegisterMoveToTileStraight(defender, tile, defender->elevation, anim, 0); break; } } @@ -389,52 +389,52 @@ void _show_damage_to_object(Object* a1, int damage, int flags, Object* weapon, b } anim = ANIM_BURNED_TO_NOTHING; - sfx_name = sfxBuildCharName(a1, anim, CHARACTER_SOUND_EFFECT_UNUSED); - animationRegisterPlaySoundEffect(a1, sfx_name, -1); - animationRegisterAnimate(a1, anim, 0); + sfx_name = sfxBuildCharName(defender, anim, CHARACTER_SOUND_EFFECT_UNUSED); + animationRegisterPlaySoundEffect(defender, sfx_name, -1); + animationRegisterAnimate(defender, anim, 0); } } else { if ((flags & (DAM_KNOCKED_OUT | DAM_KNOCKED_DOWN)) != 0) { - anim = isFallingBack ? ANIM_FALL_BACK : ANIM_FALL_FRONT; - sfx_name = sfxBuildCharName(a1, anim, CHARACTER_SOUND_EFFECT_UNUSED); - animationRegisterPlaySoundEffect(a1, sfx_name, a10); + anim = hitFromFront ? ANIM_FALL_BACK : ANIM_FALL_FRONT; + sfx_name = sfxBuildCharName(defender, anim, CHARACTER_SOUND_EFFECT_UNUSED); + animationRegisterPlaySoundEffect(defender, sfx_name, delay); if (knockbackDistance != 0) { - actionKnockdown(a1, &anim, knockbackDistance, knockbackRotation, 0); + actionKnockdown(defender, &anim, knockbackDistance, knockbackRotation, 0); } else { - anim = _pick_fall(a1, anim); - animationRegisterAnimate(a1, anim, 0); + anim = _pick_fall(defender, anim); + animationRegisterAnimate(defender, anim, 0); } - } else if ((flags & DAM_ON_FIRE) != 0 && artExists(buildFid(OBJ_TYPE_CRITTER, a1->fid & 0xFFF, ANIM_FIRE_DANCE, (a1->fid & 0xF000) >> 12, a1->rotation + 1))) { - animationRegisterAnimate(a1, ANIM_FIRE_DANCE, a10); + } else if ((flags & DAM_ON_FIRE) != 0 && artExists(buildFid(OBJ_TYPE_CRITTER, defender->fid & 0xFFF, ANIM_FIRE_DANCE, (defender->fid & 0xF000) >> 12, defender->rotation + 1))) { + animationRegisterAnimate(defender, ANIM_FIRE_DANCE, delay); - fid = buildFid(OBJ_TYPE_CRITTER, a1->fid & 0xFFF, ANIM_STAND, (a1->fid & 0xF000) >> 12, a1->rotation + 1); - animationRegisterSetFid(a1, fid, -1); + fid = buildFid(OBJ_TYPE_CRITTER, defender->fid & 0xFFF, ANIM_STAND, (defender->fid & 0xF000) >> 12, defender->rotation + 1); + animationRegisterSetFid(defender, fid, -1); } else { if (knockbackDistance != 0) { - anim = isFallingBack ? ANIM_FALL_BACK : ANIM_FALL_FRONT; - actionKnockdown(a1, &anim, knockbackDistance, knockbackRotation, a10); + anim = hitFromFront ? ANIM_FALL_BACK : ANIM_FALL_FRONT; + actionKnockdown(defender, &anim, knockbackDistance, knockbackRotation, delay); if (anim == ANIM_FALL_BACK) { - animationRegisterAnimate(a1, ANIM_BACK_TO_STANDING, -1); + animationRegisterAnimate(defender, ANIM_BACK_TO_STANDING, -1); } else { - animationRegisterAnimate(a1, ANIM_PRONE_TO_STANDING, -1); + animationRegisterAnimate(defender, ANIM_PRONE_TO_STANDING, -1); } } else { - if (isFallingBack || !artExists(buildFid(OBJ_TYPE_CRITTER, a1->fid & 0xFFF, ANIM_HIT_FROM_BACK, (a1->fid & 0xF000) >> 12, a1->rotation + 1))) { + if (hitFromFront || !artExists(buildFid(OBJ_TYPE_CRITTER, defender->fid & 0xFFF, ANIM_HIT_FROM_BACK, (defender->fid & 0xF000) >> 12, defender->rotation + 1))) { anim = ANIM_HIT_FROM_FRONT; } else { anim = ANIM_HIT_FROM_BACK; } - sfx_name = sfxBuildCharName(a1, anim, CHARACTER_SOUND_EFFECT_UNUSED); - animationRegisterPlaySoundEffect(a1, sfx_name, a10); + sfx_name = sfxBuildCharName(defender, anim, CHARACTER_SOUND_EFFECT_UNUSED); + animationRegisterPlaySoundEffect(defender, sfx_name, delay); - animationRegisterAnimate(a1, anim, 0); + animationRegisterAnimate(defender, anim, 0); } } } } else { - if ((flags & DAM_DEAD) != 0 && (a1->data.critter.combat.results & DAM_DEAD) == 0) { - anim = _action_blood(a1, anim, a10); + if ((flags & DAM_DEAD) != 0 && (defender->data.critter.combat.results & DAM_DEAD) == 0) { + anim = _action_blood(defender, anim, delay); } else { return; } @@ -442,63 +442,63 @@ void _show_damage_to_object(Object* a1, int damage, int flags, Object* weapon, b if (weapon != NULL) { if ((flags & DAM_EXPLODE) != 0) { - animationRegisterCallbackForced(a1, weapon, (AnimationCallback*)_obj_drop, -1); + animationRegisterCallbackForced(defender, weapon, (AnimationCallback*)_obj_drop, -1); fid = buildFid(OBJ_TYPE_MISC, 10, 0, 0, 0); animationRegisterSetFid(weapon, fid, 0); animationRegisterAnimateAndHide(weapon, ANIM_STAND, 0); - sfx_name = sfxBuildWeaponName(WEAPON_SOUND_EFFECT_HIT, weapon, HIT_MODE_RIGHT_WEAPON_PRIMARY, a1); + sfx_name = sfxBuildWeaponName(WEAPON_SOUND_EFFECT_HIT, weapon, HIT_MODE_RIGHT_WEAPON_PRIMARY, defender); animationRegisterPlaySoundEffect(weapon, sfx_name, 0); animationRegisterHideObjectForced(weapon); } else if ((flags & DAM_DESTROY) != 0) { - animationRegisterCallbackForced(a1, weapon, (AnimationCallback*)_internal_destroy, -1); + animationRegisterCallbackForced(defender, weapon, (AnimationCallback*)_internal_destroy, -1); } else if ((flags & DAM_DROP) != 0) { - animationRegisterCallbackForced(a1, weapon, (AnimationCallback*)_obj_drop, -1); + animationRegisterCallbackForced(defender, weapon, (AnimationCallback*)_obj_drop, -1); } } if ((flags & DAM_DEAD) != 0) { // TODO: Get rid of casts. - animationRegisterCallbackForced(a1, (void*)anim, (AnimationCallback*)_show_death, -1); + animationRegisterCallbackForced(defender, (void*)anim, (AnimationCallback*)_show_death, -1); } } // 0x410E24 int _show_death(Object* obj, int anim) { - Rect v7; - Rect v8; + Rect tempRect; + Rect dirtyRect; int fid; - objectGetRect(obj, &v8); + objectGetRect(obj, &dirtyRect); if (anim < 48 && anim > 63) { fid = buildFid(OBJ_TYPE_CRITTER, obj->fid & 0xFFF, anim + 28, (obj->fid & 0xF000) >> 12, obj->rotation + 1); - if (objectSetFid(obj, fid, &v7) == 0) { - rectUnion(&v8, &v7, &v8); + if (objectSetFid(obj, fid, &tempRect) == 0) { + rectUnion(&dirtyRect, &tempRect, &dirtyRect); } - if (objectSetFrame(obj, 0, &v7) == 0) { - rectUnion(&v8, &v7, &v8); + if (objectSetFrame(obj, 0, &tempRect) == 0) { + rectUnion(&dirtyRect, &tempRect, &dirtyRect); } } if (!_critter_flag_check(obj->pid, CRITTER_FLAT)) { obj->flags |= OBJECT_NO_BLOCK; - if (_obj_toggle_flat(obj, &v7) == 0) { - rectUnion(&v8, &v7, &v8); + if (_obj_toggle_flat(obj, &tempRect) == 0) { + rectUnion(&dirtyRect, &tempRect, &dirtyRect); } } - if (objectDisableOutline(obj, &v7) == 0) { - rectUnion(&v8, &v7, &v8); + if (objectDisableOutline(obj, &tempRect) == 0) { + rectUnion(&dirtyRect, &tempRect, &dirtyRect); } if (anim >= 30 && anim <= 31 && !_critter_flag_check(obj->pid, CRITTER_SPECIAL_DEATH) && !_critter_flag_check(obj->pid, CRITTER_NO_DROP)) { itemDropAll(obj, obj->tile); } - tileWindowRefreshRect(&v8, obj->elevation); + tileWindowRefreshRect(&dirtyRect, obj->elevation); return 0; } @@ -506,24 +506,16 @@ int _show_death(Object* obj, int anim) // 0x410FEC int _show_damage_extras(Attack* attack) { - int v6; - int v8; - int v9; - for (int index = 0; index < attack->extrasLength; index++) { Object* obj = attack->extras[index]; if (FID_TYPE(obj->fid) == OBJ_TYPE_CRITTER) { - int delta = attack->attacker->rotation - obj->rotation; - if (delta < 0) { - delta = -delta; - } - - v6 = delta != 0 && delta != 1 && delta != 5; + // NOTE: Uninline. + bool hitFromFront = _is_hit_from_front(attack->attacker, obj); reg_anim_begin(ANIMATION_REQUEST_RESERVED); _register_priority(1); - v8 = critterGetAnimationForHitMode(attack->attacker, attack->hitMode); - v9 = tileGetRotationTo(attack->attacker->tile, obj->tile); - _show_damage_to_object(obj, attack->extrasDamage[index], attack->extrasFlags[index], attack->weapon, v6, attack->extrasKnockback[index], v9, v8, attack->attacker, 0); + int attackerAnimation = critterGetAnimationForHitMode(attack->attacker, attack->hitMode); + int knockbackRotation = tileGetRotationTo(attack->attacker->tile, obj->tile); + _show_damage_to_object(obj, attack->extrasDamage[index], attack->extrasFlags[index], attack->weapon, hitFromFront, attack->extrasKnockback[index], knockbackRotation, attackerAnimation, attack->attacker, 0); reg_anim_end(); } } @@ -532,46 +524,35 @@ int _show_damage_extras(Attack* attack) } // 0x4110AC -void _show_damage(Attack* attack, int a2, int a3) +void _show_damage(Attack* attack, int attackerAnimation, int delay) { - int v5; - int v14; - int v17; - int v15; - - v5 = a3; for (int index = 0; index < attack->extrasLength; index++) { Object* object = attack->extras[index]; if (FID_TYPE(object->fid) == OBJ_TYPE_CRITTER) { - reg_anim_26(2, v5); - v5 = 0; + reg_anim_26(ANIMATION_REQUEST_RESERVED, delay); + delay = 0; } } if ((attack->attackerFlags & DAM_HIT) == 0) { if ((attack->attackerFlags & DAM_CRITICAL) != 0) { - _show_damage_to_object(attack->attacker, attack->attackerDamage, attack->attackerFlags, attack->weapon, 1, 0, 0, a2, attack->attacker, -1); + _show_damage_to_object(attack->attacker, attack->attackerDamage, attack->attackerFlags, attack->weapon, 1, 0, 0, attackerAnimation, attack->attacker, -1); } else if ((attack->attackerFlags & DAM_BACKWASH) != 0) { - _show_damage_to_object(attack->attacker, attack->attackerDamage, attack->attackerFlags, attack->weapon, 1, 0, 0, a2, attack->attacker, -1); + _show_damage_to_object(attack->attacker, attack->attackerDamage, attack->attackerFlags, attack->weapon, 1, 0, 0, attackerAnimation, attack->attacker, -1); } } else { if (attack->defender != NULL) { - // TODO: Looks very similar to _show_damage_extras. - int delta = attack->defender->rotation - attack->attacker->rotation; - if (delta < 0) { - delta = -delta; - } - - v15 = delta != 0 && delta != 1 && delta != 5; + // NOTE: Uninline. + bool hitFromFront = _is_hit_from_front(attack->defender, attack->attacker); if (FID_TYPE(attack->defender->fid) == OBJ_TYPE_CRITTER) { - if (attack->attacker->fid == 33554933) { - v14 = tileGetRotationTo(attack->attacker->tile, attack->defender->tile); - _show_damage_to_object(attack->defender, attack->defenderDamage, attack->defenderFlags, attack->weapon, v15, attack->defenderKnockback, v14, a2, attack->attacker, a3); + if (attack->attacker->fid == FID_0x20001F5) { + int knockbackRotation = tileGetRotationTo(attack->attacker->tile, attack->defender->tile); + _show_damage_to_object(attack->defender, attack->defenderDamage, attack->defenderFlags, attack->weapon, hitFromFront, attack->defenderKnockback, knockbackRotation, attackerAnimation, attack->attacker, delay); } else { - v17 = critterGetAnimationForHitMode(attack->attacker, attack->hitMode); - v14 = tileGetRotationTo(attack->attacker->tile, attack->defender->tile); - _show_damage_to_object(attack->defender, attack->defenderDamage, attack->defenderFlags, attack->weapon, v15, attack->defenderKnockback, v14, v17, attack->attacker, a3); + int weaponAnimation = critterGetAnimationForHitMode(attack->attacker, attack->hitMode); + int knockbackRotation = tileGetRotationTo(attack->attacker->tile, attack->defender->tile); + _show_damage_to_object(attack->defender, attack->defenderDamage, attack->defenderFlags, attack->weapon, hitFromFront, attack->defenderKnockback, knockbackRotation, weaponAnimation, attack->attacker, delay); } } else { tileGetRotationTo(attack->attacker->tile, attack->defender->tile); @@ -580,7 +561,7 @@ void _show_damage(Attack* attack, int a2, int a3) } if ((attack->attackerFlags & DAM_DUD) != 0) { - _show_damage_to_object(attack->attacker, attack->attackerDamage, attack->attackerFlags, attack->weapon, 1, 0, 0, a2, attack->attacker, -1); + _show_damage_to_object(attack->attacker, attack->attackerDamage, attack->attackerFlags, attack->weapon, 1, 0, 0, attackerAnimation, attack->attacker, -1); } } } @@ -616,10 +597,7 @@ int _action_melee(Attack* attack, int anim) int fid; Art* art; CacheEntry* cache_entry; - int v17; - int v18; - int delta; - int flag; + int delay; const char* sfx_name; char sfx_name_temp[16]; @@ -629,21 +607,15 @@ int _action_melee(Attack* attack, int anim) fid = buildFid(OBJ_TYPE_CRITTER, attack->attacker->fid & 0xFFF, anim, (attack->attacker->fid & 0xF000) >> 12, attack->attacker->rotation + 1); art = artLock(fid, &cache_entry); if (art != NULL) { - v17 = artGetActionFrame(art); + delay = artGetActionFrame(art); } else { - v17 = 0; + delay = 0; } artUnlock(cache_entry); tileGetTileInDirection(attack->attacker->tile, attack->attacker->rotation, 1); animationRegisterRotateToTile(attack->attacker, attack->defender->tile); - delta = attack->attacker->rotation - attack->defender->rotation; - if (delta < 0) { - delta = -delta; - } - flag = delta != 0 && delta != 1 && delta != 5; - if (anim != ANIM_THROW_PUNCH && anim != ANIM_KICK_LEG) { sfx_name = sfxBuildWeaponName(WEAPON_SOUND_EFFECT_ATTACK, attack->weapon, attack->hitMode, attack->defender); } else { @@ -665,7 +637,7 @@ int _action_melee(Attack* attack, int anim) strcpy(sfx_name_temp, sfx_name); animationRegisterAnimate(attack->attacker, anim, 0); - animationRegisterPlaySoundEffect(attack->attacker, sfx_name_temp, v17); + animationRegisterPlaySoundEffect(attack->attacker, sfx_name_temp, delay); _show_damage(attack, anim, 0); } else { if (attack->defender->data.critter.combat.results & 0x03) { @@ -675,21 +647,21 @@ int _action_melee(Attack* attack, int anim) fid = buildFid(OBJ_TYPE_CRITTER, attack->defender->fid & 0xFFF, ANIM_DODGE_ANIM, (attack->defender->fid & 0xF000) >> 12, attack->defender->rotation + 1); art = artLock(fid, &cache_entry); if (art != NULL) { - v18 = artGetActionFrame(art); + int dodgeDelay = artGetActionFrame(art); artUnlock(cache_entry); - if (v18 <= v17) { + if (dodgeDelay <= delay) { animationRegisterPlaySoundEffect(attack->attacker, sfx_name_temp, -1); animationRegisterAnimate(attack->attacker, anim, 0); sfx_name = sfxBuildCharName(attack->defender, ANIM_DODGE_ANIM, CHARACTER_SOUND_EFFECT_UNUSED); - animationRegisterPlaySoundEffect(attack->defender, sfx_name, v17 - v18); + animationRegisterPlaySoundEffect(attack->defender, sfx_name, delay - dodgeDelay); animationRegisterAnimate(attack->defender, ANIM_DODGE_ANIM, 0); } else { sfx_name = sfxBuildCharName(attack->defender, ANIM_DODGE_ANIM, CHARACTER_SOUND_EFFECT_UNUSED); animationRegisterPlaySoundEffect(attack->defender, sfx_name, -1); animationRegisterAnimate(attack->defender, ANIM_DODGE_ANIM, 0); - animationRegisterPlaySoundEffect(attack->attacker, sfx_name_temp, v18 - v17); + animationRegisterPlaySoundEffect(attack->attacker, sfx_name_temp, dodgeDelay - delay); animationRegisterAnimate(attack->attacker, anim, 0); } } @@ -716,14 +688,16 @@ int _action_melee(Attack* attack, int anim) // 0x411600 int _action_ranged(Attack* attack, int anim) { - Object* neighboors[6]; - memset(neighboors, 0, sizeof(neighboors)); + Object* adjacentObjects[ROTATION_COUNT]; + for (int rotation = 0; rotation < ROTATION_COUNT; rotation++) { + adjacentObjects[rotation] = NULL; + } reg_anim_begin(ANIMATION_REQUEST_RESERVED); _register_priority(1); Object* projectile = NULL; - Object* v50 = NULL; + Object* replacedWeapon = NULL; int weaponFid = -1; Proto* weaponProto; @@ -733,7 +707,7 @@ int _action_ranged(Attack* attack, int anim) int fid = buildFid(OBJ_TYPE_CRITTER, attack->attacker->fid & 0xFFF, anim, (attack->attacker->fid & 0xF000) >> 12, attack->attacker->rotation + 1); CacheEntry* artHandle; Art* art = artLock(fid, &artHandle); - int actionFrame = (art != NULL) ? artGetActionFrame(art) : 0; + int delay = (art != NULL) ? artGetActionFrame(art) : 0; artUnlock(artHandle); weaponGetRange(attack->attacker, attack->hitMode); @@ -783,12 +757,12 @@ int _action_ranged(Attack* attack, int anim) interfaceGetItemActions(&leftItemAction, &rightItemAction); itemRemove(attack->attacker, weapon, 1); - v50 = itemReplace(attack->attacker, weapon, weaponFlags & OBJECT_IN_ANY_HAND); + replacedWeapon = itemReplace(attack->attacker, weapon, weaponFlags & OBJECT_IN_ANY_HAND); objectSetFid(projectile, projectileProto->fid, NULL); _cAIPrepWeaponItem(attack->attacker, weapon); if (attack->attacker == gDude) { - if (v50 == NULL) { + if (replacedWeapon == NULL) { if ((weaponFlags & OBJECT_IN_LEFT_HAND) != 0) { leftItemAction = INTERFACE_ITEM_ACTION_DEFAULT; } else if ((weaponFlags & OBJECT_IN_RIGHT_HAND) != 0) { @@ -818,20 +792,20 @@ int _action_ranged(Attack* attack, int anim) int projectileRotation = tileGetRotationTo(attack->attacker->tile, attack->defender->tile); objectSetRotation(projectile, projectileRotation, NULL); - animationRegisterUnsetFlag(projectile, OBJECT_HIDDEN, actionFrame); + animationRegisterUnsetFlag(projectile, OBJECT_HIDDEN, delay); const char* sfx = sfxBuildWeaponName(WEAPON_SOUND_EFFECT_AMMO_FLYING, weapon, attack->hitMode, attack->defender); animationRegisterPlaySoundEffect(projectile, sfx, 0); - int v24; + int explosionCenterTile; if ((attack->attackerFlags & DAM_HIT) != 0) { animationRegisterMoveToTileStraight(projectile, attack->defender->tile, attack->defender->elevation, ANIM_WALK, 0); - actionFrame = _make_straight_path(projectile, projectileOrigin, attack->defender->tile, NULL, NULL, 32) - 1; - v24 = attack->defender->tile; + delay = _make_straight_path(projectile, projectileOrigin, attack->defender->tile, NULL, NULL, 32) - 1; + explosionCenterTile = attack->defender->tile; } else { animationRegisterMoveToTileStraight(projectile, attack->tile, attack->defender->elevation, ANIM_WALK, 0); - actionFrame = 0; - v24 = attack->tile; + delay = 0; + explosionCenterTile = attack->tile; } // SFALL @@ -887,11 +861,11 @@ int _action_ranged(Attack* attack, int anim) explosionGetPattern(&startRotation, &endRotation); for (int rotation = startRotation; rotation < endRotation; rotation++) { - if (objectCreateWithFidPid(&(neighboors[rotation]), explosionFid, -1) != -1) { - objectHide(neighboors[rotation], NULL); + if (objectCreateWithFidPid(&(adjacentObjects[rotation]), explosionFid, -1) != -1) { + objectHide(adjacentObjects[rotation], NULL); - int v31 = tileGetTileInDirection(v24, rotation, 1); - objectSetLocation(neighboors[rotation], v31, projectile->elevation, NULL); + int adjacentTile = tileGetTileInDirection(explosionCenterTile, rotation, 1); + objectSetLocation(adjacentObjects[rotation], adjacentTile, projectile->elevation, NULL); int delay; if (rotation != ROTATION_NE) { @@ -904,8 +878,8 @@ int _action_ranged(Attack* attack, int anim) } } - animationRegisterUnsetFlag(neighboors[rotation], OBJECT_HIDDEN, delay); - animationRegisterAnimateAndHide(neighboors[rotation], ANIM_STAND, 0); + animationRegisterUnsetFlag(adjacentObjects[rotation], OBJECT_HIDDEN, delay); + animationRegisterAnimateAndHide(adjacentObjects[rotation], ANIM_STAND, 0); } } @@ -919,15 +893,15 @@ int _action_ranged(Attack* attack, int anim) if (!l56) { const char* sfx = sfxBuildWeaponName(WEAPON_SOUND_EFFECT_HIT, weapon, attack->hitMode, attack->defender); - animationRegisterPlaySoundEffect(weapon, sfx, actionFrame); + animationRegisterPlaySoundEffect(weapon, sfx, delay); } - actionFrame = 0; + delay = 0; } else { if ((attack->attackerFlags & DAM_HIT) == 0) { Object* defender = attack->defender; if ((defender->data.critter.combat.results & (DAM_KNOCKED_OUT | DAM_KNOCKED_DOWN)) == 0) { - animationRegisterAnimate(defender, ANIM_DODGE_ANIM, actionFrame); + animationRegisterAnimate(defender, ANIM_DODGE_ANIM, delay); l56 = true; } } @@ -935,7 +909,7 @@ int _action_ranged(Attack* attack, int anim) } } - _show_damage(attack, anim, actionFrame); + _show_damage(attack, anim, delay); if ((attack->attackerFlags & DAM_HIT) == 0) { _combatai_msg(attack->defender, attack, AI_MESSAGE_TYPE_MISS, -1); @@ -962,23 +936,23 @@ int _action_ranged(Attack* attack, int anim) } for (int rotation = 0; rotation < ROTATION_COUNT; rotation++) { - if (neighboors[rotation] != NULL) { - animationRegisterHideObjectForced(neighboors[rotation]); + if (adjacentObjects[rotation] != NULL) { + animationRegisterHideObjectForced(adjacentObjects[rotation]); } } if ((attack->attackerFlags & (DAM_KNOCKED_OUT | DAM_KNOCKED_DOWN | DAM_DEAD)) == 0) { if (anim == ANIM_THROW_ANIM) { - bool l9 = false; - if (v50 != NULL) { - int v38 = weaponGetAnimationCode(v50); - if (v38 != 0) { - animationRegisterTakeOutWeapon(attack->attacker, v38, -1); - l9 = true; + bool takeOutAnimationRegistered = false; + if (replacedWeapon != NULL) { + int weaponAnimationCode = weaponGetAnimationCode(replacedWeapon); + if (weaponAnimationCode != 0) { + animationRegisterTakeOutWeapon(attack->attacker, weaponAnimationCode, -1); + takeOutAnimationRegistered = true; } } - if (!l9) { + if (!takeOutAnimationRegistered) { int fid = buildFid(OBJ_TYPE_CRITTER, attack->attacker->fid & 0xFFF, ANIM_STAND, 0, attack->attacker->rotation + 1); animationRegisterSetFid(attack->attacker, fid, -1); } @@ -994,8 +968,8 @@ int _action_ranged(Attack* attack, int anim) } for (int rotation = 0; rotation < ROTATION_COUNT; rotation++) { - if (neighboors[rotation] != NULL) { - objectDestroy(neighboors[rotation], NULL); + if (adjacentObjects[rotation] != NULL) { + objectDestroy(adjacentObjects[rotation], NULL); } } @@ -1473,19 +1447,19 @@ int actionUseSkill(Object* a1, Object* a2, int skill) } if (partyMember != NULL) { - bool v32 = false; + bool isDude = false; if (objectGetDistanceBetween(gDude, a2) <= 1) { - v32 = true; + isDude = true; } - char* msg = skillsGetGenericResponse(partyMember, v32); + char* msg = skillsGetGenericResponse(partyMember, isDude); Rect rect; if (textObjectAdd(partyMember, msg, 101, _colorTable[32747], _colorTable[0], &rect) == 0) { tileWindowRefreshRect(&rect, gElevation); } - if (v32) { + if (isDude) { performer = gDude; partyMember = NULL; } @@ -1597,7 +1571,7 @@ int _pick_fall(Object* obj, int anim) // 0x412CE4 bool _action_explode_running() { - return _action_in_explode != 0; + return _action_in_explode; } // action_explode @@ -1680,7 +1654,7 @@ int actionExplode(int tile, int elevation, int minDamage, int maxDamage, Object* attackComputeDeathFlags(attack); if (a6) { - _action_in_explode = 1; + _action_in_explode = true; reg_anim_begin(ANIMATION_REQUEST_RESERVED); _register_priority(1); @@ -1704,7 +1678,7 @@ int actionExplode(int tile, int elevation, int minDamage, int maxDamage, Object* animationRegisterCallbackForced(attack, a5, (AnimationCallback*)_report_explosion, -1); animationRegisterCallbackForced(NULL, NULL, (AnimationCallback*)_finished_explosion, -1); if (reg_anim_end() == -1) { - _action_in_explode = 0; + _action_in_explode = false; objectDestroy(explosion, NULL); @@ -1825,31 +1799,30 @@ int _report_explosion(Attack* attack, Object* a2) // 0x4132C0 int _finished_explosion(Object* a1, Object* a2) { - _action_in_explode = 0; + _action_in_explode = false; return 0; } // calculate explosion damage applying threshold and resistances // 0x4132CC -int _compute_explosion_damage(int min, int max, Object* a3, int* a4) +int _compute_explosion_damage(int min, int max, Object* defender, int* knockbackDistancePtr) { - int v5 = randomBetween(min, max); - int v7 = v5 - critterGetStat(a3, STAT_DAMAGE_THRESHOLD_EXPLOSION); - if (v7 > 0) { - v7 -= critterGetStat(a3, STAT_DAMAGE_RESISTANCE_EXPLOSION) * v7 / 100; + int damage = randomBetween(min, max) - critterGetStat(defender, STAT_DAMAGE_THRESHOLD_EXPLOSION); + if (damage > 0) { + damage -= critterGetStat(defender, STAT_DAMAGE_RESISTANCE_EXPLOSION) * damage / 100; } - if (v7 < 0) { - v7 = 0; + if (damage < 0) { + damage = 0; } - if (a4 != NULL) { - if ((a3->flags & OBJECT_MULTIHEX) == 0) { - *a4 = v7 / 10; + if (knockbackDistancePtr != NULL) { + if ((defender->flags & OBJECT_MULTIHEX) == 0) { + *knockbackDistancePtr = damage / 10; } } - return v7; + return damage; } // 0x413330 @@ -1992,29 +1965,28 @@ int _report_dmg(Attack* attack, Object* a2) // Calculate damage by applying threshold and resistances. // // 0x413660 -int _compute_dmg_damage(int min, int max, Object* obj, int* a4, int damageType) +int _compute_dmg_damage(int min, int max, Object* obj, int* knockbackDistancePtr, int damageType) { if (!_critter_flag_check(obj->pid, CRITTER_NO_KNOCKBACK)) { - a4 = NULL; + knockbackDistancePtr = NULL; } - int v8 = randomBetween(min, max); - int v10 = v8 - critterGetStat(obj, STAT_DAMAGE_THRESHOLD + damageType); - if (v10 > 0) { - v10 -= critterGetStat(obj, STAT_DAMAGE_RESISTANCE + damageType) * v10 / 100; + int damage = randomBetween(min, max) - critterGetStat(obj, STAT_DAMAGE_THRESHOLD + damageType); + if (damage > 0) { + damage -= critterGetStat(obj, STAT_DAMAGE_RESISTANCE + damageType) * damage / 100; } - if (v10 < 0) { - v10 = 0; + if (damage < 0) { + damage = 0; } - if (a4 != NULL) { + if (knockbackDistancePtr != NULL) { if ((obj->flags & OBJECT_MULTIHEX) == 0 && damageType != DAMAGE_TYPE_ELECTRICAL) { - *a4 = v10 / 10; + *knockbackDistancePtr = damage / 10; } } - return v10; + return damage; } // 0x4136EC