mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2026-02-18 03:22:35 +00:00
Refactor weapon pref into one place
This commit is contained in:
parent
7ab84ebd2f
commit
36a40d0971
4 changed files with 51 additions and 42 deletions
|
|
@ -1731,40 +1731,65 @@ static void Got_NameAndColor(UINT8 **cp, INT32 playernum)
|
|||
#endif
|
||||
}
|
||||
|
||||
void SendWeaponPref(UINT8 n)
|
||||
enum {
|
||||
WP_KICKSTARTACCEL = 1<<0,
|
||||
WP_SHRINKME = 1<<1,
|
||||
};
|
||||
|
||||
void WeaponPref_Send(UINT8 ssplayer)
|
||||
{
|
||||
UINT8 buf[1];
|
||||
UINT8 prefs = 0;
|
||||
|
||||
buf[0] = 0;
|
||||
if (cv_kickstartaccel[ssplayer].value)
|
||||
prefs |= WP_KICKSTARTACCEL;
|
||||
|
||||
if (cv_kickstartaccel[n].value)
|
||||
buf[0] |= 1;
|
||||
if (cv_shrinkme[ssplayer].value)
|
||||
prefs |= WP_SHRINKME;
|
||||
|
||||
if (cv_shrinkme[n].value)
|
||||
buf[0] |= 2;
|
||||
|
||||
SendNetXCmdForPlayer(n, XD_WEAPONPREF, buf, 1);
|
||||
SendNetXCmdForPlayer(ssplayer, XD_WEAPONPREF, &prefs, 1);
|
||||
}
|
||||
|
||||
static void Got_WeaponPref(UINT8 **cp,INT32 playernum)
|
||||
void WeaponPref_Save(UINT8 **cp, INT32 playernum)
|
||||
{
|
||||
player_t *player = &players[playernum];
|
||||
|
||||
UINT8 prefs = 0;
|
||||
|
||||
if (player->pflags & PF_KICKSTARTACCEL)
|
||||
prefs |= WP_KICKSTARTACCEL;
|
||||
|
||||
if (player->pflags & PF_SHRINKME)
|
||||
prefs |= WP_SHRINKME;
|
||||
|
||||
WRITEUINT8(*cp, prefs);
|
||||
}
|
||||
|
||||
void WeaponPref_Parse(UINT8 **cp, INT32 playernum)
|
||||
{
|
||||
player_t *player = &players[playernum];
|
||||
|
||||
UINT8 prefs = READUINT8(*cp);
|
||||
|
||||
players[playernum].pflags &= ~(PF_KICKSTARTACCEL|PF_SHRINKME);
|
||||
player->pflags &= ~(PF_KICKSTARTACCEL|PF_SHRINKME);
|
||||
|
||||
if (prefs & 1)
|
||||
players[playernum].pflags |= PF_KICKSTARTACCEL;
|
||||
if (prefs & WP_KICKSTARTACCEL)
|
||||
player->pflags |= PF_KICKSTARTACCEL;
|
||||
|
||||
if (prefs & 2)
|
||||
players[playernum].pflags |= PF_SHRINKME;
|
||||
if (prefs & WP_SHRINKME)
|
||||
player->pflags |= PF_SHRINKME;
|
||||
|
||||
if (leveltime < 2)
|
||||
{
|
||||
// BAD HACK: No other place I tried to slot this in
|
||||
// made it work for the host when they initally host,
|
||||
// so this will have to do.
|
||||
K_UpdateShrinkCheat(&players[playernum]);
|
||||
K_UpdateShrinkCheat(player);
|
||||
}
|
||||
}
|
||||
|
||||
static void Got_WeaponPref(UINT8 **cp,INT32 playernum)
|
||||
{
|
||||
WeaponPref_Parse(cp, playernum);
|
||||
|
||||
// SEE ALSO g_demo.c
|
||||
demo_extradata[playernum] |= DXD_WEAPONPREF;
|
||||
|
|
@ -1952,7 +1977,7 @@ void D_SendPlayerConfig(UINT8 n)
|
|||
UINT8 *p = buf;
|
||||
|
||||
SendNameAndColor(n);
|
||||
SendWeaponPref(n);
|
||||
WeaponPref_Send(n);
|
||||
|
||||
if (pr != NULL)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -230,7 +230,9 @@ void D_RegisterServerCommands(void);
|
|||
void D_RegisterClientCommands(void);
|
||||
void CleanupPlayerName(INT32 playernum, const char *newname);
|
||||
boolean EnsurePlayerNameIsGood(char *name, INT32 playernum);
|
||||
void SendWeaponPref(UINT8 n);
|
||||
void WeaponPref_Send(UINT8 ssplayer);
|
||||
void WeaponPref_Save(UINT8 **cp, INT32 playernum);
|
||||
void WeaponPref_Parse(UINT8 **cp, INT32 playernum);
|
||||
void D_SendPlayerConfig(UINT8 n);
|
||||
void Command_ExitGame_f(void);
|
||||
void Command_Retry_f(void);
|
||||
|
|
|
|||
22
src/g_demo.c
22
src/g_demo.c
|
|
@ -364,20 +364,7 @@ void G_ReadDemoExtraData(void)
|
|||
}
|
||||
if (extradata & DXD_WEAPONPREF)
|
||||
{
|
||||
i = READUINT8(demo_p);
|
||||
players[p].pflags &= ~(PF_KICKSTARTACCEL|PF_SHRINKME);
|
||||
if (i & 1)
|
||||
players[p].pflags |= PF_KICKSTARTACCEL;
|
||||
if (i & 2)
|
||||
players[p].pflags |= PF_SHRINKME;
|
||||
|
||||
if (leveltime < 2)
|
||||
{
|
||||
// BAD HACK: No other place I tried to slot this in
|
||||
// made it work for the host when they initally host,
|
||||
// so this will have to do.
|
||||
K_UpdateShrinkCheat(&players[p]);
|
||||
}
|
||||
WeaponPref_Parse(&demo_p, p);
|
||||
|
||||
//CONS_Printf("weaponpref is %d for player %d\n", i, p);
|
||||
}
|
||||
|
|
@ -492,12 +479,7 @@ void G_WriteDemoExtraData(void)
|
|||
}
|
||||
if (demo_extradata[i] & DXD_WEAPONPREF)
|
||||
{
|
||||
UINT8 prefs = 0;
|
||||
if (players[i].pflags & PF_KICKSTARTACCEL)
|
||||
prefs |= 1;
|
||||
if (players[i].pflags & PF_SHRINKME)
|
||||
prefs |= 2;
|
||||
WRITEUINT8(demo_p, prefs);
|
||||
WeaponPref_Save(&demo_p, i);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1303,22 +1303,22 @@ ticcmd_t *G_MoveTiccmd(ticcmd_t* dest, const ticcmd_t* src, const size_t n)
|
|||
|
||||
static void weaponPrefChange(void)
|
||||
{
|
||||
SendWeaponPref(0);
|
||||
WeaponPref_Send(0);
|
||||
}
|
||||
|
||||
static void weaponPrefChange2(void)
|
||||
{
|
||||
SendWeaponPref(1);
|
||||
WeaponPref_Send(1);
|
||||
}
|
||||
|
||||
static void weaponPrefChange3(void)
|
||||
{
|
||||
SendWeaponPref(2);
|
||||
WeaponPref_Send(2);
|
||||
}
|
||||
|
||||
static void weaponPrefChange4(void)
|
||||
{
|
||||
SendWeaponPref(3);
|
||||
WeaponPref_Send(3);
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue