- checkavailweapon

This commit is contained in:
Christoph Oelckers 2020-05-05 22:07:54 +02:00
parent 2cc4176ed8
commit 51d4853375
9 changed files with 150 additions and 84 deletions

View file

@ -36,12 +36,6 @@ This file is a combination of code from the following sources:
- DukeGDX and RedneckGDX by Alexander Makarov-[M210] (m210-2007@mail.ru)
- Redneck Rampage reconstructed source by Nuke.YKT
Note:
Most of this code follows DukeGDX and RedneckGDX because for Java it had
to undo all the macro hackery that make the Duke source extremely hard to read.
The other code bases were mainly used to add missing feature support (e.g. WW2GI)
and verify correctness.
*/
//-------------------------------------------------------------------------
@ -231,6 +225,111 @@ void addweapon(struct player_struct* p, int weapon)
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void checkavailinven(struct player_struct* p)
{
if (p->firstaid_amount > 0)
p->inven_icon = ICON_FIRSTAID;
else if (p->steroids_amount > 0)
p->inven_icon = ICON_STEROIDS;
else if (p->holoduke_amount > 0)
p->inven_icon = ICON_HOLODUKE;
else if (p->jetpack_amount > 0)
p->inven_icon = ICON_JETPACK;
else if (p->heat_amount > 0)
p->inven_icon = ICON_HEATS;
else if (p->scuba_amount > 0)
p->inven_icon = ICON_SCUBA;
else if (p->boot_amount > 0)
p->inven_icon = ICON_BOOTS;
else p->inven_icon = ICON_NONE;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void checkavailweapon(struct player_struct* p)
{
short i, snum;
int weap;
if (p->wantweaponfire >= 0)
{
weap = p->wantweaponfire;
p->wantweaponfire = -1;
if (weap == p->curr_weapon) return;
else if (p->gotweapon[weap] && p->ammo_amount[weap] > 0)
{
addweapon(p, weap);
return;
}
}
weap = p->curr_weapon;
if (p->gotweapon[weap] && p->ammo_amount[weap] > 0)
return;
snum = sprite[p->i].yvel;
// Note: RedNukem has this restriction, but the original source and RedneckGDX do not.
#if 1 // TRANSITIONAL
int max = ((g_gameType & GAMEFLAG_RRALL) ? DEVISTATOR_WEAPON : FREEZE_WEAPON);
#else
int max = FREEZE_WEAPON;
#endif
for (i = 0; i < 10; i++)
{
weap = ud.wchoice[snum][i];
if ((g_gameType & GAMEFLAG_SHAREWARE) && weap > 6) continue;
if (weap == 0) weap = max;
else weap--;
if (weap == KNEE_WEAPON || (p->gotweapon[weap] && p->ammo_amount[weap] > 0))
break;
}
if (i == HANDREMOTE_WEAPON) weap = KNEE_WEAPON;
// Found the weapon
p->last_weapon = p->curr_weapon;
p->random_club_frame = 0;
p->curr_weapon = weap;
if (g_gameType & GAMEFLAG_WW2GI)
{
SetGameVarID(g_iWeaponVarID, p->curr_weapon, p->i, snum);
if (p->curr_weapon >= 0)
{
SetGameVarID(g_iWorksLikeVarID, aplWeaponWorksLike[p->curr_weapon][snum], p->i, snum);
}
else
{
SetGameVarID(g_iWorksLikeVarID, -1, p->i, snum);
}
OnEvent(EVENT_CHANGEWEAPON, p->i, snum, -1);
}
p->kickback_pic = 0;
if (p->holster_weapon == 1)
{
p->holster_weapon = 0;
p->weapon_pos = 10;
}
else p->weapon_pos = -1;
}
//---------------------------------------------------------------------------
//
//

View file

@ -7002,6 +7002,15 @@ void InitFonts();
int GameInterface::app_main()
{
for (int i = 0; i < MAXPLAYERS; i++)
{
for (int j = 0; j < 10; j++)
{
const char* s = "3457860291";
ud.wchoice[i][j] = s[j] - '0';
}
}
buttonMap.SetButtons(actions, NUM_ACTIONS);
playing_rr = 1;
g_skillCnt = 4;

View file

@ -174,6 +174,7 @@ typedef struct {
uint8_t user_map;
uint8_t screenfade, menubackground;
uint8_t shadow_pal;
uint8_t wchoice[MAXPLAYERS][MAX_WEAPONS];
} user_defs;
extern user_defs ud;

View file

@ -79,6 +79,8 @@ extern int32_t g_returnVarID; // var ID of "RETURN"
extern int32_t g_weaponVarID; // var ID of "WEAPON"
extern int32_t g_worksLikeVarID; // var ID of "WORKSLIKE"
extern int32_t g_zRangeVarID; // var ID of "ZRANGE"
#define g_iWeaponVarID g_weaponVarID
#define g_iWorksLikeVarID g_worksLikeVarID
#include "events_defs.h"
extern intptr_t apScriptEvents[MAXEVENTS];

View file

@ -53,6 +53,11 @@ static FORCE_INLINE int32_t VM_OnEvent(int nEventID, int spriteNum = -1, int pla
return VM_HaveEvent(nEventID) ? VM_ExecuteEvent(nEventID, spriteNum, playerNum) : 0;
}
inline int OnEvent(int id, int pnum, int snum, int what)
{
return VM_OnEvent(id, snum, pnum, what);
}
static FORCE_INLINE int32_t VM_OnEventWithReturn(int nEventID, int spriteNum, int playerNum, int32_t nReturn)
{
return VM_HaveEvent(nEventID) ? VM_ExecuteEventWithValue(nEventID, spriteNum, playerNum, nReturn) : nReturn;

View file

@ -84,6 +84,12 @@ int __fastcall Gv_GetVar(int const gameVar);
void __fastcall Gv_GetManyVars(int const numVars, int32_t * const outBuf);
void __fastcall Gv_SetVar(int const gameVar, int const newValue);
inline void SetGameVarID(int var, int newval, int pnum, int snum)
{
Gv_SetVar(var, newval, snum, pnum);
}
template <typename T>
static FORCE_INLINE void Gv_FillWithVars(T & rv)
{

View file

@ -3096,11 +3096,13 @@ void Net_SendClientInfo(void)
tempbuf[l++] = g_player[myconnectindex].pteam = playerteam;
#if 0
for (i=0; i<10; i++)
{
g_player[myconnectindex].wchoice[i] = g_player[0].wchoice[i];
tempbuf[l++] = (uint8_t)g_player[0].wchoice[i];
}
#endif
tempbuf[l++] = myconnectindex;
@ -3133,10 +3135,12 @@ void Net_ReceiveClientInfo(uint8_t *pbuf, int32_t packbufleng, int32_t fromserve
g_player[other].ps->palookup = g_player[other].pcolor = pbuf[i++];
g_player[other].pteam = pbuf[i++];
#if 0
for (j=i; i-j<10; i++)
{
g_player[other].wchoice[i-j] = pbuf[i];
}
#endif
if (fromserver)
{

View file

@ -4684,6 +4684,9 @@ void P_AddAmmo(DukePlayer_t * const pPlayer, int const weaponNum, int const addA
}
void addweapon(player_struct* p, int w);
void checkavailinven(struct player_struct* p);
void checkavailweapon(struct player_struct* p);
void P_AddWeapon(DukePlayer_t *pPlayer, int weaponNum)
{
addweapon(pPlayer, weaponNum);
@ -4691,87 +4694,12 @@ void P_AddWeapon(DukePlayer_t *pPlayer, int weaponNum)
void P_SelectNextInvItem(DukePlayer_t *pPlayer)
{
if (pPlayer->inv_amount[GET_FIRSTAID] > 0)
pPlayer->inven_icon = ICON_FIRSTAID;
else if (pPlayer->inv_amount[GET_STEROIDS] > 0)
pPlayer->inven_icon = ICON_STEROIDS;
else if (pPlayer->inv_amount[GET_JETPACK] > 0)
pPlayer->inven_icon = ICON_JETPACK;
else if (pPlayer->inv_amount[GET_HOLODUKE] > 0)
pPlayer->inven_icon = ICON_HOLODUKE;
else if (pPlayer->inv_amount[GET_HEATS] > 0)
pPlayer->inven_icon = ICON_HEATS;
else if (pPlayer->inv_amount[GET_SCUBA] > 0)
pPlayer->inven_icon = ICON_SCUBA;
else if (pPlayer->inv_amount[GET_BOOTS] > 0)
pPlayer->inven_icon = ICON_BOOTS;
else
pPlayer->inven_icon = ICON_NONE;
checkavailinven(pPlayer);
}
void P_CheckWeapon(DukePlayer_t *pPlayer)
{
int playerNum;
int weaponNum;
// if (pPlayer->reloading)
// return;
if (pPlayer->wantweaponfire >= 0)
{
weaponNum = pPlayer->wantweaponfire;
pPlayer->wantweaponfire = -1;
if (weaponNum == pPlayer->curr_weapon)
return;
if ((pPlayer->gotweapon[weaponNum]) && pPlayer->ammo_amount[weaponNum] > 0)
{
P_AddWeapon(pPlayer, weaponNum);
return;
}
}
weaponNum = pPlayer->curr_weapon;
if ((pPlayer->gotweapon[weaponNum]) && pPlayer->ammo_amount[weaponNum] > 0)
return;
playerNum = P_Get(pPlayer->i);
int wpnInc = 0;
for (wpnInc = 0; wpnInc <= (RR ? DEVISTATOR_WEAPON: FREEZE_WEAPON); ++wpnInc)
{
weaponNum = g_player[playerNum].wchoice[wpnInc];
if (VOLUMEONE && weaponNum > SHRINKER_WEAPON)
continue;
if (weaponNum == KNEE_WEAPON)
weaponNum = RR ? DEVISTATOR_WEAPON : FREEZE_WEAPON;
else weaponNum--;
if (weaponNum == KNEE_WEAPON || ((pPlayer->gotweapon[weaponNum]) && pPlayer->ammo_amount[weaponNum] > 0))
break;
}
if (wpnInc == HANDREMOTE_WEAPON)
weaponNum = KNEE_WEAPON;
// Found the weapon
pPlayer->last_weapon = pPlayer->curr_weapon;
pPlayer->random_club_frame = 0;
pPlayer->curr_weapon = weaponNum;
P_SetWeaponGamevars(playerNum, pPlayer);
VM_OnEvent(EVENT_CHANGEWEAPON, pPlayer->i, playerNum);
pPlayer->kickback_pic = 0;
if (pPlayer->holster_weapon == 1)
{
pPlayer->holster_weapon = 0;
pPlayer->weapon_pos = 10;
}
else pPlayer->weapon_pos = -1;
checkavailweapon(pPlayer);
}
static void DoWallTouchDamage(const DukePlayer_t *pPlayer, int32_t wallNum)

View file

@ -228,6 +228,16 @@ typedef struct player_struct {
int8_t padding_[3];
} DukePlayer_t;
// transition helpers
#define firstaid_amount inv_amount[GET_FIRSTAID]
#define steroids_amount inv_amount[GET_STEROIDS]
#define holoduke_amount inv_amount[GET_HOLODUKE]
#define jetpack_amount inv_amount[GET_JETPACK]
#define heat_amount inv_amount[GET_HEATS]
#define scuba_amount inv_amount[GET_SCUBA]
#define boot_amount inv_amount[GET_BOOTS]
// KEEPINSYNC lunatic/_defs_game.lua
typedef struct
{
@ -241,7 +251,7 @@ typedef struct
int32_t movefifoend, syncvalhead, myminlag;
int32_t pcolor, pteam;
// NOTE: wchoice[HANDREMOTE_WEAPON .. MAX_WEAPONS-1] unused
uint8_t frags[MAXPLAYERS], wchoice[MAX_WEAPONS];
uint8_t frags[MAXPLAYERS];
char vote, gotvote, playerreadyflag, playerquitflag, connected;
char user_name[32];
@ -384,6 +394,8 @@ static inline int P_GetP(const void *pSprite)
static inline int P_Get(int32_t spriteNum) { return P_GetP((const uspritetype *)&sprite[spriteNum]); }
extern int16_t max_ammo_amount[MAX_WEAPONS];
void P_SetWeaponGamevars(int playerNum, const DukePlayer_t* const pPlayer);
END_DUKE_NS
#endif