From 1d789d0d393f56ae1137f7f304713649eb634f39 Mon Sep 17 00:00:00 2001 From: XProger Date: Sun, 1 Aug 2021 01:55:11 +0300 Subject: [PATCH] #368 GBA fix aiming --- src/platform/gba/lara.h | 106 ++++++++++++++++++++++++---------------- 1 file changed, 63 insertions(+), 43 deletions(-) diff --git a/src/platform/gba/lara.h b/src/platform/gba/lara.h index 565ece8d..e81da206 100644 --- a/src/platform/gba/lara.h +++ b/src/platform/gba/lara.h @@ -2757,37 +2757,70 @@ struct Lara : Item void updateLook() { + ExtraInfoLara::Arm &R = extraL->armR; + ExtraInfoLara::Arm &L = extraL->armL; + vec3s &H = extraL->head.angle; + vec3s &T = extraL->torso.angle; + if (health <= 0) { - extraL->head.angle = vec3s(0, 0, 0); - } else if ((input & IN_LOOK) && gCamera->mode != CAMERA_MODE_FIXED) { + H = T = vec3s(0, 0, 0); + return; + } + + if (R.target || L.target) + { + if (extraL->weapon < WEAPON_SHOTGUN) + { + int32 aX = R.angle.x + L.angle.x; + int32 aY = R.angle.y + L.angle.y; + + if (R.aim && L.aim) { + H.x = T.x = aX >> 2; + H.y = T.y = aY >> 2; + } else if (R.aim ^ L.aim) { + H.x = T.x = aX >> 1; + H.y = T.y = aY >> 1; + } + } else { + T.x = R.angle.x; + T.y = R.angle.y; + H.x = H.y = 0; + } + return; + } + + if ((input & IN_LOOK) && gCamera->mode != CAMERA_MODE_FIXED) + { gCamera->lookAtItem = NULL; if (input & IN_UP) { - extraL->head.angle.x -= LARA_LOOK_TURN_SPEED; + H.x -= LARA_LOOK_TURN_SPEED; } if (input & IN_DOWN) { - extraL->head.angle.x += LARA_LOOK_TURN_SPEED; + H.x += LARA_LOOK_TURN_SPEED; } if (input & IN_LEFT) { - extraL->head.angle.y -= LARA_LOOK_TURN_SPEED; + H.y -= LARA_LOOK_TURN_SPEED; } if (input & IN_RIGHT) { - extraL->head.angle.y += LARA_LOOK_TURN_SPEED; + H.y += LARA_LOOK_TURN_SPEED; } - extraL->head.angle.x = X_CLAMP(extraL->head.angle.x, LARA_LOOK_ANGLE_MIN, LARA_LOOK_ANGLE_MAX); - extraL->head.angle.y = X_CLAMP(extraL->head.angle.y, -LARA_LOOK_ANGLE_Y, LARA_LOOK_ANGLE_Y); + H.x = T.x = X_CLAMP(H.x, LARA_LOOK_ANGLE_MIN, LARA_LOOK_ANGLE_MAX); + H.y = T.y = X_CLAMP(H.y, -LARA_LOOK_ANGLE_Y, LARA_LOOK_ANGLE_Y); input &= ~(IN_RIGHT | IN_LEFT | IN_UP | IN_DOWN); - } else if (gCamera->lastItem == NULL) { - extraL->head.angle.x = angleDec(extraL->head.angle.x, abs(extraL->head.angle.x) >> 3); - extraL->head.angle.y = angleDec(extraL->head.angle.y, abs(extraL->head.angle.y) >> 3); + return; } - extraL->torso.angle = extraL->head.angle; + if (gCamera->lastItem != NULL) + return; + + H.x = T.x = angleDec(H.x, abs(H.x) >> 3); + H.y = T.y = angleDec(H.y, abs(H.y) >> 3); } void updateWaterState() @@ -3100,19 +3133,27 @@ struct Lara : Item return; extraL->weaponState = weaponState; + ExtraInfoLara::Arm &R = extraL->armR; + ExtraInfoLara::Arm &L = extraL->armL; + if (weaponState == WEAPON_STATE_DRAW) { const WeaponParams ¶ms = weaponParams[extraL->weapon]; int32 anim = (extraL->weapon == WEAPON_SHOTGUN) ? ANIM_SHOTGUN_DRAW : ANIM_PISTOLS_PICK; - extraL->armR.animIndex = extraL->armL.animIndex = models[params.animType].animIndex + anim; - extraL->armR.frameIndex = extraL->armL.frameIndex = 0; + R.animIndex = L.animIndex = models[params.animType].animIndex + anim; + R.frameIndex = L.frameIndex = 0; + } + + if (weaponState == WEAPON_STATE_HOLSTER) + { + R.target = L.target = NULL; } if (weaponState == WEAPON_STATE_FREE) { - extraL->armR.useBasis = extraL->armL.useBasis = false; - extraL->armR.animIndex = extraL->armL.animIndex = 0; - extraL->armR.frameIndex = extraL->armL.frameIndex = 0; + R.useBasis = L.useBasis = false; + R.animIndex = L.animIndex = 0; + R.frameIndex = L.frameIndex = 0; } } @@ -3321,23 +3362,10 @@ struct Lara : Item { ExtraInfoLara::Arm &R = extraL->armR; ExtraInfoLara::Arm &L = extraL->armL; - vec3s &H = extraL->head.angle; - vec3s &T = extraL->torso.angle; weaponAim(R); weaponAim(L); - int32 aX = R.angle.x + L.angle.x; - int32 aY = R.angle.y + L.angle.y; - - if (R.aim && L.aim) { - H.x = T.x = aX >> 2; - H.y = T.y = aY >> 2; - } else if (R.aim ^ L.aim) { - H.x = T.x = aX >> 1; - H.y = T.y = aY >> 1; - } - const WeaponParams ¶ms = weaponParams[extraL->weapon]; for (int32 i = 0; i < LARA_ARM_MAX; i++) @@ -3399,18 +3427,8 @@ struct Lara : Item ExtraInfoLara::Arm &R = extraL->armR; ExtraInfoLara::Arm &L = extraL->armL; - vec3s &H = extraL->head.angle; - vec3s &T = extraL->torso.angle; - weaponAim(R); - if (R.aim) - { - T.x = R.angle.x; - T.y = R.angle.y; - H.x = H.y = 0; - } - const WeaponParams ¶ms = weaponParams[extraL->weapon]; ExtraInfoLara::Arm* arm = &extraL->armR; @@ -3420,6 +3438,8 @@ struct Lara : Item int32 frame = arm->frameIndex; int32 anim = arm->animIndex - models[params.animType].animIndex; + bool aim = ((input & IN_ACTION) && !arm->target) || arm->aim; + switch (anim) { case ANIM_SHOTGUN_FIRE: @@ -3431,7 +3451,7 @@ struct Lara : Item anim = ANIM_SHOTGUN_AIM; animPtr = level.anims + models[params.animType].animIndex + anim; frame = animPtr->frameEnd - animPtr->frameBegin; - } else if ((animLength - frame < 10) && !(input & IN_ACTION)) { + } else if ((animLength - frame < 10) && !aim) { anim = ANIM_SHOTGUN_AIM; frame = animLength - frame; // how many frames left for fire animation animPtr = level.anims + models[params.animType].animIndex + anim; @@ -3441,7 +3461,7 @@ struct Lara : Item } case ANIM_SHOTGUN_DRAW: { - if (((input & IN_ACTION) && !arm->target) || arm->aim) + if (aim) { anim = ANIM_SHOTGUN_AIM; frame = 1; @@ -3450,7 +3470,7 @@ struct Lara : Item } case ANIM_SHOTGUN_AIM: { - if (((input & IN_ACTION) && !arm->target) || arm->aim) + if (aim) { if (frame == animLength) {