Skip to content

Commit

Permalink
#368 GBA fix free camera mode in combat mode, fix ammo shells consump…
Browse files Browse the repository at this point in the history
…tion for shotgun
  • Loading branch information
XProger committed Jul 31, 2021
1 parent 78e5947 commit 7076568
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 59 deletions.
3 changes: 3 additions & 0 deletions src/platform/gba/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,9 @@ struct Camera

void toCombat()
{
if (mode == CAMERA_MODE_FREE)
return;

if (mode == CAMERA_MODE_CUTSCENE)
return;

Expand Down
107 changes: 48 additions & 59 deletions src/platform/gba/lara.h
Original file line number Diff line number Diff line change
Expand Up @@ -3003,7 +3003,7 @@ struct Lara : Item
pos.z += (c * ((phd_cos(angle.y) * vSpeed) >> 16)) >> FIXED_SHIFT;
}

bool weaponShoot(const ExtraInfoLara::Arm* arm)
bool weaponFire(const ExtraInfoLara::Arm* arm)
{
int16 ammo = extraL->ammo[extraL->weapon];

Expand All @@ -3025,64 +3025,72 @@ struct Lara : Item
from.pos.z = pos.z;
from.room = room;

int32 aimX = int32(rand_logic() - 0x4000) * params.spread >> 16;
int32 aimY = int32(rand_logic() - 0x4000) * params.spread >> 16;
int32 count = (extraL->weapon == WEAPON_SHOTGUN) ? 6 : 1;

aimX += arm->angle.x;
aimY += arm->angle.y;
aimY += angle.y;
for (int32 i = 0; i < count; i++)
{
int32 aimX = int32(rand_logic() - 0x4000) * params.spread >> 16;
int32 aimY = int32(rand_logic() - 0x4000) * params.spread >> 16;

matrixSetView(from.pos, aimX, aimY);
aimX += arm->angle.x;
aimY += arm->angle.y;
aimY += angle.y;

int32 minDist = INT_MAX;
matrixSetView(from.pos, aimX, aimY);

if (arm->target)
{
Sphere spheres[MAX_SPHERES];
int32 spheresCount = arm->target->getSpheres(spheres, false);
int32 minDist = INT_MAX;

for (int32 i = 0; i < spheresCount; i++)
if (arm->target)
{
Sphere &s = spheres[i];
Sphere spheres[MAX_SPHERES];
int32 spheresCount = arm->target->getSpheres(spheres, false);

if (abs(s.center.x) >= s.radius)
continue;
for (int32 i = 0; i < spheresCount; i++)
{
Sphere &s = spheres[i];

if (abs(s.center.y) >= s.radius)
continue;
if (abs(s.center.x) >= s.radius)
continue;

if (s.center.z <= s.radius)
continue;
if (abs(s.center.y) >= s.radius)
continue;

if (X_SQR(s.center.x) + X_SQR(s.center.y) > X_SQR(s.radius))
continue;
if (s.center.z <= s.radius)
continue;

if (X_SQR(s.center.x) + X_SQR(s.center.y) > X_SQR(s.radius))
continue;

int32 dist = s.center.z - s.radius;
int32 dist = s.center.z - s.radius;

if (dist < minDist) {
minDist = dist;
if (dist < minDist) {
minDist = dist;
}
}
}
}

vec3i dir = matrixGetDir(matrixGet());
vec3i dir = matrixGetDir(matrixGet());

Location to = from;
Location to = from;

if (minDist != INT_MAX)
{
to.pos.x += dir.x * minDist >> FIXED_SHIFT;
to.pos.y += dir.y * minDist >> FIXED_SHIFT;
to.pos.z += dir.z * minDist >> FIXED_SHIFT;
if (minDist != INT_MAX)
{
dir *= minDist;
to.pos.x += dir.x >> FIXED_SHIFT;
to.pos.y += dir.y >> FIXED_SHIFT;
to.pos.z += dir.z >> FIXED_SHIFT;

arm->target->hit(params.damage, to.pos, 0);
} else {
to.pos += dir;
arm->target->hit(params.damage, to.pos, 0);
} else {
to.pos += dir;

trace(from, to);
fxRicochet(to.room, to.pos, true);
trace(from, to);
fxRicochet(to.room, to.pos, true);
}
}

soundPlay(params.soundId, pos);

return true;
}

Expand Down Expand Up @@ -3330,8 +3338,6 @@ struct Lara : Item
H.y = T.y = aY >> 1;
}

bool shotFlag = false;

const WeaponParams &params = weaponParams[extraL->weapon];

for (int32 i = 0; i < LARA_ARM_MAX; i++)
Expand All @@ -3349,7 +3355,7 @@ struct Lara : Item
{
if (frame == animLength)
{
if ((input & IN_ACTION) && weaponShoot(arm))
if ((input & IN_ACTION) && weaponFire(arm))
{
anim = ANIM_PISTOLS_FIRE;
frame = 0;
Expand All @@ -3358,12 +3364,6 @@ struct Lara : Item
arm->flash.angle = int16(rand_draw() << 1);
arm->flash.offset = params.flashOffset;
arm->flash.intensity = params.flashIntensity << 8;

if (!shotFlag) // skip sound replay if double shoot
{
shotFlag = true;
soundPlay(params.soundId, pos);
}
}
} else {
frame++;
Expand Down Expand Up @@ -3454,20 +3454,10 @@ struct Lara : Item
{
if (frame == animLength)
{
if (input & IN_ACTION)
if ((input & IN_ACTION) && weaponFire(arm))
{
frame = 1;
anim = ANIM_SHOTGUN_FIRE;

for (int32 i = 0; i < 6; i++)
{
if (!weaponShoot(arm))
break;

if (i == 5) {
soundPlay(params.soundId, pos);
}
}
}
} else {
frame++;
Expand Down Expand Up @@ -3697,7 +3687,6 @@ struct Lara : Item
case WEAPON_STATE_READY:
{
gCamera->toCombat();

weaponUpdateTargets();

if (extraL->weapon < WEAPON_SHOTGUN) {
Expand Down

0 comments on commit 7076568

Please sign in to comment.