From cd1f3739d9ac7eafdf827584a567d24e93e15675 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Sun, 20 Jan 2013 21:16:54 +0000 Subject: [PATCH] player.c: factor out repeated code into P_SetWeaponGamevars(). git-svn-id: https://svn.eduke32.com/eduke32@3413 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/player.c | 35 ++++++++++++++++++++------------- polymer/eduke32/source/player.h | 1 + polymer/eduke32/source/sector.c | 3 +-- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/polymer/eduke32/source/player.c b/polymer/eduke32/source/player.c index dbaa9cb15..3750e2bdf 100644 --- a/polymer/eduke32/source/player.c +++ b/polymer/eduke32/source/player.c @@ -1925,6 +1925,20 @@ static int32_t P_DisplayKnuckles(int32_t gs,int32_t snum) return 1; } +void P_SetWeaponGamevars(int32_t snum, const DukePlayer_t *p) +{ +#ifdef LUNATIC + UNREFERENCED_PARAMETER(snum); + UNREFERENCED_PARAMETER(p); +#else + Gv_SetVar(g_iWeaponVarID, p->curr_weapon, p->i, snum); + Gv_SetVar(g_iWorksLikeVarID, + ((unsigned)p->curr_weapon < MAX_WEAPONS) ? PWEAPON(snum, p->curr_weapon, WorksLike) : -1, + p->i, snum); +#endif +} + + static void P_FireWeapon(DukePlayer_t *p) { int32_t i, snum = sprite[p->i].yvel; @@ -1939,8 +1953,7 @@ static void P_FireWeapon(DukePlayer_t *p) if (PWEAPON(snum, p->curr_weapon, FireSound) > 0) A_PlaySound(PWEAPON(snum, p->curr_weapon, FireSound),p->i); - Gv_SetVar(g_iWeaponVarID,p->curr_weapon,p->i,snum); - Gv_SetVar(g_iWorksLikeVarID,PWEAPON(snum, p->curr_weapon, WorksLike), p->i, snum); + P_SetWeaponGamevars(snum, p); // OSD_Printf("doing %d %d %d\n",PWEAPON(snum, p->curr_weapon, Shoots),p->curr_weapon,snum); A_Shoot(p->i,PWEAPON(snum, p->curr_weapon, Shoots)); @@ -3246,10 +3259,7 @@ void P_ChangeWeapon(DukePlayer_t *p,int32_t weapon) p->kickback_pic = 0; - Gv_SetVar(g_iWeaponVarID, p->curr_weapon, p->i, snum); - Gv_SetVar(g_iWorksLikeVarID, - (unsigned)p->curr_weapon < MAX_WEAPONS ? PWEAPON(snum, p->curr_weapon, WorksLike) : -1, - p->i, snum); + P_SetWeaponGamevars(snum, p); } void P_AddWeapon(DukePlayer_t *p,int32_t weapon) @@ -3621,8 +3631,7 @@ static void P_ProcessWeapon(int32_t snum) if (TEST_SYNC_KEY(sb_snum, SK_FIRE)) { - Gv_SetVar(g_iWeaponVarID,p->curr_weapon,p->i,snum); - Gv_SetVar(g_iWorksLikeVarID,PWEAPON(snum, p->curr_weapon, WorksLike),p->i,snum); + P_SetWeaponGamevars(snum, p); if (VM_OnEvent(EVENT_PRESSEDFIRE, p->i, snum, -1, 0) != 0) sb_snum &= ~BIT(SK_FIRE); @@ -3630,8 +3639,7 @@ static void P_ProcessWeapon(int32_t snum) if (TEST_SYNC_KEY(sb_snum, SK_HOLSTER)) // 'Holster Weapon { - Gv_SetVar(g_iWeaponVarID,p->curr_weapon,p->i,snum); - Gv_SetVar(g_iWorksLikeVarID,PWEAPON(snum, p->curr_weapon, WorksLike),p->i,snum); + P_SetWeaponGamevars(snum, p); if (VM_OnEvent(EVENT_HOLSTER, p->i, snum, -1, 0) == 0) { @@ -3732,8 +3740,7 @@ static void P_ProcessWeapon(int32_t snum) } else { - Gv_SetVar(g_iWeaponVarID,p->curr_weapon,p->i,snum); - Gv_SetVar(g_iWorksLikeVarID,PWEAPON(snum, p->curr_weapon, WorksLike),p->i,snum); + P_SetWeaponGamevars(snum, p); if (VM_OnEvent(EVENT_FIRE, p->i, snum, -1, 0) == 0) { @@ -3947,8 +3954,8 @@ static void P_ProcessWeapon(int32_t snum) lastvisinc = totalclock+32; p->visibility = 0; } - Gv_SetVar(g_iWeaponVarID,p->curr_weapon,p->i,snum); - Gv_SetVar(g_iWorksLikeVarID,PWEAPON(snum, p->curr_weapon, WorksLike), p->i, snum); + + P_SetWeaponGamevars(snum, p); A_Shoot(p->i, PWEAPON(snum, p->curr_weapon, Shoots)); } } diff --git a/polymer/eduke32/source/player.h b/polymer/eduke32/source/player.h index 8a640da59..70b27a2c1 100644 --- a/polymer/eduke32/source/player.h +++ b/polymer/eduke32/source/player.h @@ -355,5 +355,6 @@ void P_QuickKill(DukePlayer_t *p); void P_SelectNextInvItem(DukePlayer_t *p); void P_UpdateScreenPal(DukePlayer_t *p); void P_PalFrom(DukePlayer_t *p, uint8_t f, uint8_t r, uint8_t g, uint8_t b); +void P_SetWeaponGamevars(int32_t snum, const DukePlayer_t *p); #endif diff --git a/polymer/eduke32/source/sector.c b/polymer/eduke32/source/sector.c index 7c162bf79..7d967983b 100644 --- a/polymer/eduke32/source/sector.c +++ b/polymer/eduke32/source/sector.c @@ -2756,8 +2756,7 @@ CHECKINV1: } } - Gv_SetVar(g_iWorksLikeVarID,PWEAPON(snum, p->curr_weapon, WorksLike),p->i,snum); - Gv_SetVar(g_iWeaponVarID,j, p->i, snum); + P_SetWeaponGamevars(snum, p); j = VM_OnEvent(EVENT_SELECTWEAPON,p->i,snum, -1, j);