Skip to content

Commit

Permalink
port RifleHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Feb 20, 2021
1 parent a5a0925 commit 85be97f
Show file tree
Hide file tree
Showing 8 changed files with 172 additions and 11 deletions.
12 changes: 6 additions & 6 deletions docs/progress.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions docs/progress.txt
Original file line number Diff line number Diff line change
Expand Up @@ -401,19 +401,19 @@ TestLaraSlide 0x00425C50 0x0000011A +
LaraLandedBad 0x00425D70 0x000000BE +
draw_shotgun 0x00425E30 0x00000113 -
undraw_shotgun 0x00425F50 0x00000160 -
RifleHandler 0x004260F0 0x00000373 -
RifleHandler 0x004260F0 0x00000373 +
draw_pistols 0x00426470 0x00000147 -
undraw_pistols 0x004265C0 0x00000261 -
draw_pistol_meshes 0x00426830 0x00000061 -
PistolHandler 0x004268A0 0x0000012E -
AnimatePistols 0x004269D0 0x000001F5 -
LaraGun 0x00426BD0 0x00000271 *
InitialiseNewWeapon 0x00426E60 0x000000B9 -
LaraTargetInfo 0x00426F20 0x00000194 -
LaraGetNewTarget 0x004270C0 0x000001D9 -
LaraTargetInfo 0x00426F20 0x00000194 *
LaraGetNewTarget 0x004270C0 0x000001D9 *
find_target_point 0x004272A0 0x000000B2 -
AimWeapon 0x00427360 0x000000C1 -
FireWeapon 0x00427430 0x000002F2 -
AimWeapon 0x00427360 0x000000C1 *
FireWeapon 0x00427430 0x000002F2 *
HitTarget 0x00427730 0x000000E5 -
LaraControl 0x00427850 0x00000372 *
LaraSwapMeshExtra 0x00427BD0 0x00000030 +
Expand Down
1 change: 1 addition & 0 deletions src/game/const.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#define DAMAGE_LENGTH 14
#define NO_ITEM -1
#define SHOTGUN_AMMO_CLIP 6
#define PELLET_SCATTER (20 * ONE_DEGREE)
#define SFX_ALWAYS 2
#define NUM_EFFECTS 100
#define DEATH_WAIT (10 * 30)
Expand Down
1 change: 1 addition & 0 deletions src/game/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
#define DoorVBuf ARRAY_(0x00462540, DOOR_VBUF, [4])
#define RoomsToDraw ARRAY_(0x00462580, int16_t, [100])
#define RoomsToDrawNum VAR_U_(0x00461F38, int32_t)
#define Weapons ARRAY_(0x004563A8, WEAPON_INFO, [NUM_WEAPONS])
// clang-format on

#endif
9 changes: 9 additions & 0 deletions src/game/lara.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
#define UpdateLaraRoom ((void __cdecl(*)(ITEM_INFO* item, int height))0x004126A0)
#define ShiftItem ((void __cdecl(*)(ITEM_INFO* item, COLL_INFO *coll))0x00412660)
#define LaraGun ((void __cdecl(*)())0x00426BD0)
#define LaraTargetInfo ((void __cdecl(*)(WEAPON_INFO* winfo))0x00426F20)
#define LaraGetNewTarget ((void __cdecl(*)(WEAPON_INFO* winfo))0x004270C0)
#define AimWeapon ((void __cdecl(*)(WEAPON_INFO* winfo, LARA_ARM* arm))0x00427360)
#define FireWeapon ((int32_t __cdecl(*)(int32_t weapon_type, ITEM_INFO *target, ITEM_INFO *src, PHD_ANGLE *angles))0x00427430)
// clang-format on

void __cdecl LaraSwapMeshExtra();
Expand Down Expand Up @@ -162,6 +166,10 @@ int32_t __cdecl LaraTestWaterClimbOut(ITEM_INFO* item, COLL_INFO* coll);
extern void (*LaraControlRoutines[])(ITEM_INFO* item, COLL_INFO* coll);
extern void (*LaraCollisionRoutines[])(ITEM_INFO* item, COLL_INFO* coll);

void __cdecl RifleHandler(int32_t weapon_type);
void __cdecl AnimateShotgun();
void __cdecl FireShotgun();

void Tomb1MLookLeftRight();
void Tomb1MLookUpDown();
void Tomb1MResetLook();
Expand All @@ -170,5 +178,6 @@ void Tomb1MInjectGameLara();
void Tomb1MInjectGameLaraMisc();
void Tomb1MInjectGameLaraSurf();
void Tomb1MInjectGameLaraSwim();
void Tomb1MInjectGameLaraGun1();

#endif
128 changes: 128 additions & 0 deletions src/game/lara1gun.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#include "game/effects.h"
#include "game/data.h"
#include "game/lara.h"
#include "specific/game.h"
#include "specific/input.h"

void __cdecl RifleHandler(int32_t weapon_type)
{
WEAPON_INFO* winfo = &Weapons[LGT_SHOTGUN];

if (Input & IN_ACTION) {
LaraTargetInfo(winfo);
} else {
Lara.target = NULL;
}
if (!Lara.target) {
LaraGetNewTarget(winfo);
}

AimWeapon(winfo, &Lara.left_arm);

if (Lara.left_arm.lock) {
Lara.torso_y_rot = Lara.left_arm.y_rot / 2;
Lara.torso_x_rot = Lara.left_arm.x_rot / 2;
Lara.head_x_rot = 0;
Lara.head_y_rot = 0;
}

AnimateShotgun();
}

void __cdecl AnimateShotgun()
{
int16_t ani = Lara.left_arm.frame_number;

if (Lara.left_arm.lock) {
if (ani >= AF_SG_AIM && ani < AF_SG_DRAW) {
ani++;
if (ani == AF_SG_DRAW) {
ani = AF_SG_RECOIL;
}
} else if (ani == AF_SG_RECOIL) {
if (Input & IN_ACTION) {
FireShotgun();
ani++;
}
} else if (ani > AF_SG_RECOIL && ani < AF_SG_UNDRAW) {
ani++;
if (ani == AF_SG_UNDRAW) {
ani = AF_SG_RECOIL;
} else if (ani == AF_SG_RECOIL + 10) {
SoundEffect(9, &LaraItem->pos, 0);
}
} else if (ani >= AF_SG_UNAIM && ani < AF_SG_END) {
ani++;
if (ani == AF_SG_END) {
ani = AF_SG_AIM;
}
}
} else {
if (ani == AF_SG_AIM && (Input & IN_ACTION)) {
ani++;
} else if (ani > AF_SG_AIM && ani < AF_SG_DRAW) {
ani++;
if (ani == AF_SG_DRAW) {
if (Input & IN_ACTION) {
ani = AF_SG_RECOIL;
} else {
ani = AF_SG_UNAIM;
}
}
} else {
if (ani == AF_SG_RECOIL) {
if (Input & IN_ACTION) {
FireShotgun();
ani++;
} else {
ani = AF_SG_UNAIM;
}
} else if (ani > AF_SG_RECOIL && ani < AF_SG_UNDRAW) {
ani++;
if (ani == AF_SG_RECOIL + 12 + 1) {
ani = AF_SG_AIM;
} else if (ani == AF_SG_UNDRAW) {
ani = AF_SG_UNAIM;
} else if (ani == AF_SG_RECOIL + 10) {
SoundEffect(9, &LaraItem->pos, 0);
}
} else if (ani >= AF_SG_UNAIM && ani < AF_SG_END) {
ani++;
if (ani == AF_SG_END) {
ani = AF_SG_AIM;
}
}
}
}

Lara.right_arm.frame_number = ani;
Lara.left_arm.frame_number = ani;
}

void __cdecl FireShotgun()
{
int i, r, fired;
PHD_ANGLE angles[2];
PHD_ANGLE dangles[2];

angles[0] = Lara.left_arm.y_rot + LaraItem->pos.y_rot;
angles[1] = Lara.left_arm.x_rot;

for (int i = 0; i < SHOTGUN_AMMO_CLIP; i++) {
r = (int)((GetRandomControl() - 16384) * PELLET_SCATTER) / 65536;
dangles[0] = angles[0] + r;
r = (int)((GetRandomControl() - 16384) * PELLET_SCATTER) / 65536;
dangles[1] = angles[1] + r;
if (FireWeapon(LGT_SHOTGUN, Lara.target, LaraItem, dangles)) {
fired = 1;
}
}
if (fired) {
SoundEffect(Weapons[LGT_SHOTGUN].sample_num, &LaraItem->pos, 0);
}
}

void Tomb1MInjectGameLaraGun1()
{
INJECT(0x004260F0, RifleHandler);
}
21 changes: 21 additions & 0 deletions src/game/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,12 @@ typedef enum {
AF_PICKUP_UW = 2970,
AF_PICKUPSCION = 44,
AF_USEPUZZLE = 3372,
AF_SG_AIM = 0,
AF_SG_DRAW = 13,
AF_SG_RECOIL = 47,
AF_SG_UNDRAW = 80,
AF_SG_UNAIM = 114,
AF_SG_END = 127,
} LARA_ANIMATION_FRAMES;

typedef enum {
Expand Down Expand Up @@ -1116,6 +1122,21 @@ typedef struct {
/* 0014 end */
} PHDTEXTURESTRUCT;

typedef struct {
/* 0000 */ PHD_ANGLE lock_angles[4];
/* 0008 */ PHD_ANGLE left_angles[4];
/* 0010 */ PHD_ANGLE right_angles[4];
/* 0018 */ PHD_ANGLE aim_speed;
/* 001A */ PHD_ANGLE shot_accuracy;
/* 001C */ int32_t gun_height;
/* 0020 */ int32_t damage;
/* 0024 */ int32_t target_dist;
/* 0028 */ int16_t recoil_frame;
/* 002A */ int16_t flash_time;
/* 002C */ int16_t sample_num;
/* 002E end */
} WEAPON_INFO;

#pragma pop

typedef void(__cdecl* ControlRoutine)(ITEM_INFO*, COLL_INFO*);
Expand Down
1 change: 1 addition & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ static void Tomb1MInject()
Tomb1MInjectGameItems();
Tomb1MInjectGameLOT();
Tomb1MInjectGameLara();
Tomb1MInjectGameLaraGun1();
Tomb1MInjectGameLaraMisc();
Tomb1MInjectGameLaraSurf();
Tomb1MInjectGameLaraSwim();
Expand Down

0 comments on commit 85be97f

Please sign in to comment.