diff --git a/source/blood/src/weapon.cpp b/source/blood/src/weapon.cpp index 87cd75f77..10e85a982 100644 --- a/source/blood/src/weapon.cpp +++ b/source/blood/src/weapon.cpp @@ -368,7 +368,8 @@ void UpdateAimVector(PLAYER * pPlayer) WEAPONTRACK *pWeaponTrack = &gWeaponTrack[pPlayer->curWeapon]; int nTarget = -1; pPlayer->aimTargetsCount = 0; - if (cl_autoaim == 1 || (cl_autoaim == 2 && !pWeaponTrack->bIsProjectile) || pPlayer->curWeapon == 10 || pPlayer->curWeapon == 9) + int autoaim = Autoaim(pPlayer->nPlayer); + if (autoaim == 1 || (autoaim == 2 && !pWeaponTrack->bIsProjectile) || pPlayer->curWeapon == 10 || pPlayer->curWeapon == 9) { int nClosest = 0x7fffffff; int nSprite; diff --git a/source/core/gamecvars.h b/source/core/gamecvars.h index f43a77054..c3882c122 100644 --- a/source/core/gamecvars.h +++ b/source/core/gamecvars.h @@ -107,6 +107,12 @@ inline const char* PlayerName(int pindex) return playername; } +inline bool Autoaim(int player) +{ + // Todo: proper implementation of user CVARs. + return cl_autoaim; +} + extern bool gNoAutoLoad; extern int hud_statusbarrange; // will be set by the game's configuration setup. bool G_CheckAutorun(bool button); diff --git a/source/exhumed/src/gun.cpp b/source/exhumed/src/gun.cpp index 636f64cac..6293362a8 100644 --- a/source/exhumed/src/gun.cpp +++ b/source/exhumed/src/gun.cpp @@ -847,9 +847,9 @@ loc_flag: int var_50 = PlayerList[nLocalPlayer].horizon.horiz.asq16() >> 14; nHeight -= var_50; - if (sPlayerInput[nPlayer].nTarget >= 0 && cl_autoaim) + if (sPlayerInput[nPlayer].nTarget >= 0 && Autoaim(nPlayer)) { - assert(sprite[sPlayerInput[nPlayer].nTarget].sectnum < kMaxSectors); + assert(sprite[sPlayerInput[nPlayer].nTarget].sectnum < kMaxSectors); var_50 = sPlayerInput[nPlayer].nTarget + 10000; } diff --git a/source/games/duke/src/2d_d.cpp b/source/games/duke/src/2d_d.cpp index 1eaa6a4e2..1b60aaace 100644 --- a/source/games/duke/src/2d_d.cpp +++ b/source/games/duke/src/2d_d.cpp @@ -735,7 +735,7 @@ public: mysnprintf(tempbuf, 32, "%d", i + 1); MiniText(30, 90 + t, tempbuf, 0); - MiniText(38, 90 + t, ud.user_name[i], 0, -1, ps[i].palookup); + MiniText(38, 90 + t, PlayerName(i), 0, -1, ps[i].palookup); for (int y = 0; y < playerswhenstarted; y++) { diff --git a/source/games/duke/src/2d_r.cpp b/source/games/duke/src/2d_r.cpp index f5fcfd0d3..d2de862e4 100644 --- a/source/games/duke/src/2d_r.cpp +++ b/source/games/duke/src/2d_r.cpp @@ -296,7 +296,7 @@ public: mysnprintf(tempbuf, 32, "%d", i + 1); MiniText(30, 90 + t, tempbuf, 0); - MiniText(38, 90 + t, ud.user_name[i], 0, -1, ps[i].palookup); + MiniText(38, 90 + t, PlayerName(i), 0, -1, ps[i].palookup); for (int y = 0; y < playerswhenstarted; y++) { diff --git a/source/games/duke/src/funct.h b/source/games/duke/src/funct.h index 1852c62e9..9c5ff1ddb 100644 --- a/source/games/duke/src/funct.h +++ b/source/games/duke/src/funct.h @@ -119,7 +119,7 @@ void footprints(int snum); int makepainsounds(int snum, int type); void playerCrouch(int snum); void playerJump(int snum, int fz, int cz); -void processavel(player_struct* p, float* avel); + void checklook(int snum, ESyncBits actions); void playerCenterView(int snum); void playerLookUp(int snum, ESyncBits actions); @@ -231,10 +231,8 @@ void exitlevel(MapRecord *next); void enterlevel(MapRecord* mi, int gm); void donewgame(MapRecord* map, int sk); void startnewgame(MapRecord* map, int skill); -void setlocalplayerinput(player_struct *pp); int playercolor2lookup(int color); void PlayerColorChanged(void); -void apply_seasick(player_struct* p, double scalefactor); void calcviewpitch(player_struct* p, double factor); bool movementBlocked(int snum); void loadcons(); @@ -242,9 +240,4 @@ void recordoldspritepos(); int* animateptr(int i); -void backuppos(player_struct* p, bool noclipping = false); -void backupweapon(player_struct* p); -void checkhardlanding(player_struct* p); -void playerweaponsway(player_struct* p, spritetype* s); - END_DUKE_NS diff --git a/source/games/duke/src/game.cpp b/source/games/duke/src/game.cpp index 142f33e86..8b284df75 100644 --- a/source/games/duke/src/game.cpp +++ b/source/games/duke/src/game.cpp @@ -325,12 +325,6 @@ void GameInterface::app_init() screenpeek = myconnectindex; - for (int j = numplayers; j < ud.multimode; j++) - { - mysnprintf(ud.user_name[j], sizeof(ud.user_name[j]), "%s %d", GStrings("PLAYER"), j + 1); - ps[j].auto_aim = 0; - } - LoadDefinitions(); fi.InitFonts(); SetTileNames(); diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index 83ace2bdb..43bf17dda 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -72,7 +72,7 @@ void hud_input(int plnum) p->sync.actions |= SB_CENTERVIEW; // Backup weapon here as hud_input() is the first function where any one of the weapon variables can change. - backupweapon(p); + p->backupweapon(); if (isRR()) { @@ -854,11 +854,6 @@ void GameInterface::GetInput(InputPacket* packet, ControlInfo* const hidInput) auto const p = &ps[myconnectindex]; - if (numplayers == 1) - { - setlocalplayerinput(p); - } - double const scaleAdjust = InputScale(); InputPacket input{}; @@ -870,7 +865,7 @@ void GameInterface::GetInput(InputPacket* packet, ControlInfo* const hidInput) if (!cl_syncinput && p->GetActor()->s.extra > 0) { - apply_seasick(p, scaleAdjust); + p->apply_seasick(scaleAdjust); } } else @@ -886,7 +881,7 @@ void GameInterface::GetInput(InputPacket* packet, ControlInfo* const hidInput) { // Do these in the same order as the old code. calcviewpitch(p, scaleAdjust); - processavel(p, &input.avel); + input.avel = p->adjustavel(input.avel); applylook(&p->angle, input.avel, &p->sync.actions, scaleAdjust); sethorizon(&p->horizon.horiz, input.horz, &p->sync.actions, scaleAdjust); } diff --git a/source/games/duke/src/player.cpp b/source/games/duke/src/player.cpp index 744024f36..9551e2886 100644 --- a/source/games/duke/src/player.cpp +++ b/source/games/duke/src/player.cpp @@ -71,18 +71,6 @@ void PlayerColorChanged(void) pp.GetActor()->s.pal = ud.user_pals[myconnectindex]; } -//--------------------------------------------------------------------------- -// -// Sync local player with CVARs. -// -//--------------------------------------------------------------------------- - -void setlocalplayerinput(player_struct* pp) -{ - pp->aim_mode = in_mousemode; - pp->auto_aim = cl_autoaim; -} - //--------------------------------------------------------------------------- // // calculates automatic view pitch for playing without a mouse @@ -295,13 +283,14 @@ DDukeActor* aim(DDukeActor* actor, int aang) // Autoaim from DukeGDX. if (s->picnum == TILE_APLAYER) { - if (ps[s->yvel].auto_aim == 0) + int autoaim = Autoaim(s->yvel); + if (!autoaim) { // The chickens in RRRA are homing and must always autoaim. if (!isRRRA() || ps[s->yvel].curr_weapon != CHICKEN_WEAPON) return nullptr; } - else if (ps[s->yvel].auto_aim == 2) + else if (autoaim == 2) { int weap; if (!isWW2GI()) @@ -582,7 +571,7 @@ void footprints(int snum) inline void backupplayer(player_struct* p) { - backuppos(p); + p->backuppos(); p->angle.backup(); p->horizon.backup(); } @@ -625,7 +614,7 @@ void playerisdead(int snum, int psectlotag, int fz, int cz) ps[p->frag_ps].frag++; frags[p->frag_ps][snum]++; - auto pname = &ud.user_name[p->frag_ps][0]; + auto pname = PlayerName(p->frag_ps); if (snum == screenpeek) { Printf(PRINT_NOTIFY, "Killed by %s", pname); @@ -781,42 +770,23 @@ void playerJump(int snum, int fz, int cz) // //--------------------------------------------------------------------------- -void apply_seasick(player_struct* p, double factor) +void player_struct::apply_seasick(double factor) { - if (isRRRA() && p->SeaSick && p->dead_flag == 0) + if (isRRRA() && SeaSick && dead_flag == 0) { - if (p->SeaSick < 250) + if (SeaSick < 250) { - if (p->SeaSick >= 180) - p->angle.rotscrnang += bamlook(xs_CRoundToUInt(24 * factor * BAMUNIT)); - else if (p->SeaSick >= 130) - p->angle.rotscrnang -= bamlook(xs_CRoundToUInt(24 * factor * BAMUNIT)); - else if (p->SeaSick >= 70) - p->angle.rotscrnang += bamlook(xs_CRoundToUInt(24 * factor * BAMUNIT)); - else if (p->SeaSick >= 20) - p->angle.rotscrnang -= bamlook(xs_CRoundToUInt(24 * factor * BAMUNIT)); + if (SeaSick >= 180) + angle.rotscrnang += bamlook(xs_CRoundToUInt(24 * factor * BAMUNIT)); + else if (SeaSick >= 130) + angle.rotscrnang -= bamlook(xs_CRoundToUInt(24 * factor * BAMUNIT)); + else if (SeaSick >= 70) + angle.rotscrnang += bamlook(xs_CRoundToUInt(24 * factor * BAMUNIT)); + else if (SeaSick >= 20) + angle.rotscrnang -= bamlook(xs_CRoundToUInt(24 * factor * BAMUNIT)); } - if (p->SeaSick < 250) - p->angle.look_ang = bamlook(xs_CRoundToUInt(((krand() & 255) - 128) * factor * BAMUNIT)); - } -} - -//--------------------------------------------------------------------------- -// -// split off because it can be called from multiple places. -// -//--------------------------------------------------------------------------- - -void processavel(player_struct* p, float* avel) -{ - // Taken from processinput() for use with applying look while cl_syncinput is 0. - if (p->psectlotag == ST_2_UNDERWATER) - { - *avel = (*avel - (*avel / 8.f)) * sgn(TICSPERFRAME); - } - else - { - *avel = *avel * sgn(TICSPERFRAME); + if (SeaSick < 250) + angle.look_ang = bamlook(xs_CRoundToUInt(((krand() & 255) - 128) * factor * BAMUNIT)); } } @@ -826,23 +796,23 @@ void processavel(player_struct* p, float* avel) // //--------------------------------------------------------------------------- -void backuppos(player_struct* p, bool noclipping) +void player_struct::backuppos(bool noclipping) { if (!noclipping) { - p->oposx = p->posx; - p->oposy = p->posy; + oposx = posx; + oposy = posy; } else { - p->posx = p->oposx; - p->posy = p->oposy; + posx = oposx; + posy = oposy; } - p->oposz = p->posz; - p->bobposx = p->posx; - p->bobposy = p->posy; - p->opyoff = p->pyoff; + oposz = posz; + bobposx = posx; + bobposy = posy; + opyoff = pyoff; } //--------------------------------------------------------------------------- @@ -851,13 +821,13 @@ void backuppos(player_struct* p, bool noclipping) // //--------------------------------------------------------------------------- -void backupweapon(player_struct* p) +void player_struct::backupweapon() { - p->oweapon_sway = p->weapon_sway; - p->oweapon_pos = p->weapon_pos; - p->okickback_pic = p->kickback_pic; - p->orandom_club_frame = p->random_club_frame; - p->ohard_landing = p->hard_landing; + oweapon_sway = weapon_sway; + oweapon_pos = weapon_pos; + okickback_pic = kickback_pic; + orandom_club_frame = random_club_frame; + ohard_landing = hard_landing; } //--------------------------------------------------------------------------- @@ -866,34 +836,34 @@ void backupweapon(player_struct* p) // //--------------------------------------------------------------------------- -void checkhardlanding(player_struct* p) +void player_struct::checkhardlanding() { - if (p->hard_landing > 0) + if (hard_landing > 0) { - p->horizon.addadjustment(-(p->hard_landing << 4)); - p->hard_landing--; + horizon.addadjustment(-(hard_landing << 4)); + hard_landing--; } } -void playerweaponsway(player_struct* p, spritetype* s) +void player_struct::playerweaponsway(int xvel) { if (cl_weaponsway) { - if (s->xvel < 32 || p->on_ground == 0 || p->bobcounter == 1024) + if (xvel < 32 || on_ground == 0 || bobcounter == 1024) { - if ((p->weapon_sway & 2047) > (1024 + 96)) - p->weapon_sway -= 96; - else if ((p->weapon_sway & 2047) < (1024 - 96)) - p->weapon_sway += 96; - else p->oweapon_sway = p->weapon_sway = 1024; + if ((weapon_sway & 2047) > (1024 + 96)) + weapon_sway -= 96; + else if ((weapon_sway & 2047) < (1024 - 96)) + weapon_sway += 96; + else oweapon_sway = weapon_sway = 1024; } else { - p->weapon_sway = p->bobcounter; + weapon_sway = bobcounter; - if ((p->bobcounter - p->oweapon_sway) > 256) + if ((bobcounter - oweapon_sway) > 256) { - p->oweapon_sway = p->weapon_sway; + oweapon_sway = weapon_sway; } } } diff --git a/source/games/duke/src/player_d.cpp b/source/games/duke/src/player_d.cpp index bc11ca362..0a3674315 100644 --- a/source/games/duke/src/player_d.cpp +++ b/source/games/duke/src/player_d.cpp @@ -2850,12 +2850,12 @@ void processinput_d(int snum) if (p->on_crane != nullptr) goto HORIZONLY; - playerweaponsway(p, s); + p->playerweaponsway(s->xvel); s->xvel = clamp(ksqrt((p->posx - p->bobposx) * (p->posx - p->bobposx) + (p->posy - p->bobposy) * (p->posy - p->bobposy)), 0, 512); if (p->on_ground) p->bobcounter += p->GetActor()->s.xvel >> 1; - backuppos(p, ud.clipping == 0 && (sector[p->cursectnum].floorpicnum == MIRROR || p->cursectnum < 0 || p->cursectnum >= MAXSECTORS)); + p->backuppos(ud.clipping == 0 && (sector[p->cursectnum].floorpicnum == MIRROR || p->cursectnum < 0 || p->cursectnum >= MAXSECTORS)); // Shrinking code @@ -2889,7 +2889,7 @@ void processinput_d(int snum) //ENGINE calculates angvel for you // may still be needed later for demo recording - processavel(p, &sb_avel); + sb_avel = p->adjustavel(sb_avel); applylook(&p->angle, sb_avel, &p->sync.actions); } @@ -3126,7 +3126,7 @@ HORIZONLY: sethorizon(&p->horizon.horiz, PlayerHorizon(snum), &p->sync.actions); } - checkhardlanding(p); + p->checkhardlanding(); //Shooting code/changes diff --git a/source/games/duke/src/player_r.cpp b/source/games/duke/src/player_r.cpp index f9037e6ac..f670a5986 100644 --- a/source/games/duke/src/player_r.cpp +++ b/source/games/duke/src/player_r.cpp @@ -3574,12 +3574,12 @@ void processinput_r(int snum) if (p->on_crane != nullptr) goto HORIZONLY; - playerweaponsway(p, s); + p->playerweaponsway(s->xvel); s->xvel = clamp(ksqrt((p->posx - p->bobposx) * (p->posx - p->bobposx) + (p->posy - p->bobposy) * (p->posy - p->bobposy)), 0, 512); if (p->on_ground) p->bobcounter += p->GetActor()->s.xvel >> 1; - backuppos(p, ud.clipping == 0 && (sector[p->cursectnum].floorpicnum == MIRROR || p->cursectnum < 0 || p->cursectnum >= MAXSECTORS)); + p->backuppos(ud.clipping == 0 && (sector[p->cursectnum].floorpicnum == MIRROR || p->cursectnum < 0 || p->cursectnum >= MAXSECTORS)); // Shrinking code @@ -3629,9 +3629,9 @@ void processinput_r(int snum) //ENGINE calculates angvel for you // may still be needed later for demo recording - processavel(p, &sb_avel); + sb_avel = p->adjustavel(sb_avel); applylook(&p->angle, sb_avel, &p->sync.actions); - apply_seasick(p, 1); + p->apply_seasick(1); } if (p->spritebridge == 0) @@ -3996,7 +3996,7 @@ HORIZONLY: sethorizon(&p->horizon.horiz, PlayerHorizon(snum), &p->sync.actions); } - checkhardlanding(p); + p->checkhardlanding(); //Shooting code/changes diff --git a/source/games/duke/src/premap.cpp b/source/games/duke/src/premap.cpp index 31164a273..09763c05a 100644 --- a/source/games/duke/src/premap.cpp +++ b/source/games/duke/src/premap.cpp @@ -501,7 +501,7 @@ void resetpspritevars(int g) short circ; int firstx, firsty; spritetype* s; - int aimmode[MAXPLAYERS], autoaim[MAXPLAYERS]; + int aimmode[MAXPLAYERS]; STATUSBARTYPE tsbar[MAXPLAYERS]; EGS(ps[0].cursectnum, ps[0].posx, ps[0].posy, ps[0].posz, @@ -510,7 +510,6 @@ void resetpspritevars(int g) if (ud.recstat != 2) for (i = 0; i < MAXPLAYERS; i++) { aimmode[i] = ps[i].aim_mode; - autoaim[i] = ps[i].auto_aim; if (ud.multimode > 1 && ud.coop == 1 && ud.last_level >= 0) { for (j = 0; j < MAX_WEAPONS; j++) @@ -541,7 +540,6 @@ void resetpspritevars(int g) if (ud.recstat != 2) for (i = 0; i < MAXPLAYERS; i++) { ps[i].aim_mode = aimmode[i]; - ps[i].auto_aim = autoaim[i]; if (ud.multimode > 1 && ud.coop == 1 && ud.last_level >= 0) { for (j = 0; j < MAX_WEAPONS; j++) @@ -997,7 +995,6 @@ void startnewgame(MapRecord* map, int skill) { enterlevel(map, 0); ud.showweapons = cl_showweapon; - setlocalplayerinput(&ps[myconnectindex]); PlayerColorChanged(); inputState.ClearAllInput(); gameaction = ga_level; diff --git a/source/games/duke/src/savegame.cpp b/source/games/duke/src/savegame.cpp index 802239fa8..7f439ece2 100644 --- a/source/games/duke/src/savegame.cpp +++ b/source/games/duke/src/savegame.cpp @@ -115,7 +115,6 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, player_struct& w, ("randomflamex", w.randomflamex) ("crack_time", w.crack_time) ("aim.mode", w.aim_mode) - ("auto_aim", w.auto_aim) ("psectlotag", w.psectlotag) ("cursectnum", w.cursectnum) ("last_extra", w.last_extra) diff --git a/source/games/duke/src/types.h b/source/games/duke/src/types.h index 2ab9b0038..95f4f0bd2 100644 --- a/source/games/duke/src/types.h +++ b/source/games/duke/src/types.h @@ -126,7 +126,6 @@ struct user_defs int levelclock; unsigned char god, cashman, eog; unsigned char clipping; - char user_name[MAXPLAYERS][32]; unsigned char showweapons; unsigned char user_pals[MAXPLAYERS]; @@ -202,7 +201,7 @@ struct player_struct int bobcounter; int randomflamex, crack_time; - int aim_mode, auto_aim, ftt; + int aim_mode, ftt; short cursectnum, last_extra, subweapon; short ammo_amount[MAX_WEAPONS], frag, fraggedself; @@ -284,6 +283,18 @@ struct player_struct DDukeActor* GetActor(); int GetPlayerNum(); + void apply_seasick(double factor); + void backuppos(bool noclipping = false); + void backupweapon(); + void checkhardlanding(); + void playerweaponsway(int xvel); + + float adjustavel(float avel) + { + return (psectlotag == ST_2_UNDERWATER)? avel * 0.875f : avel; + } + + }; // Wrapper around the insane collision info mess from Build. diff --git a/source/sw/src/game.cpp b/source/sw/src/game.cpp index f1e9d647d..063435154 100644 --- a/source/sw/src/game.cpp +++ b/source/sw/src/game.cpp @@ -424,7 +424,7 @@ void InitPlayerGameSettings(void) // everyone gets the same Auto Aim TRAVERSE_CONNECT(pnum) { - if (gNet.AutoAim) + if (Autoaim(pnum)) SET(Player[pnum].Flags, PF_AUTO_AIM); else RESET(Player[pnum].Flags, PF_AUTO_AIM); @@ -432,7 +432,7 @@ void InitPlayerGameSettings(void) } else { - if (cl_autoaim) + if (Autoaim(myconnectindex)) SET(Player[myconnectindex].Flags, PF_AUTO_AIM); else RESET(Player[myconnectindex].Flags, PF_AUTO_AIM); diff --git a/source/sw/src/input.cpp b/source/sw/src/input.cpp index 8c51474d4..fc36f0ebe 100644 --- a/source/sw/src/input.cpp +++ b/source/sw/src/input.cpp @@ -93,7 +93,7 @@ static void processInputBits(PLAYERp const pp, ControlInfo* const hidInput) else RESET(Player[myconnectindex].Flags, PF_MOUSE_AIMING_ON); - if (cl_autoaim) + if (Autoaim(myconnectindex)) SET(Player[myconnectindex].Flags, PF_AUTO_AIM); else RESET(Player[myconnectindex].Flags, PF_AUTO_AIM);