Improve actions.cc readability

This commit is contained in:
Alexander Batalov 2022-12-23 12:44:52 +03:00
parent 16dbe1122e
commit a48d744cde
1 changed files with 180 additions and 208 deletions

View File

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