diff --git a/source/games/duke/src/actors.cpp b/source/games/duke/src/actors.cpp index 163f5a2e0..88e94d733 100644 --- a/source/games/duke/src/actors.cpp +++ b/source/games/duke/src/actors.cpp @@ -466,15 +466,7 @@ void moveplayers(void) //Players if (p->actorsqu >= 0) { - int ang = getincangle(p->getang(), getangle(sprite[p->actorsqu].x - p->posx, sprite[p->actorsqu].y - p->posy)) >> 2; - if (!cl_syncinput) - { - p->angAdjust += ang; - } - else - { - p->addang(ang); - } + playerAddAngle(p, getincangle(p->getang(), getangle(sprite[p->actorsqu].x - p->posx, sprite[p->actorsqu].y - p->posy)) >> 2); } if (s->extra > 0) @@ -497,15 +489,7 @@ void moveplayers(void) //Players if (p->wackedbyactor >= 0 && sprite[p->wackedbyactor].statnum < MAXSTATUS) { - int ang = getincangle(p->getang(), getangle(sprite[p->wackedbyactor].x - p->posx, sprite[p->wackedbyactor].y - p->posy)) >> 1; - if (!cl_syncinput) - { - p->angAdjust += ang; - } - else - { - p->addang(ang); - } + playerAddAngle(p, getincangle(p->getang(), getangle(sprite[p->wackedbyactor].x - p->posx, sprite[p->wackedbyactor].y - p->posy)) >> 1); } } s->ang = p->getang(); @@ -762,15 +746,7 @@ void movecrane(int i, int crane) s->owner = -2; ps[p].on_crane = i; S_PlayActorSound(isRR() ? 390 : DUKE_GRUNT, ps[p].i); - int ang = s->ang + 1024; - if (!cl_syncinput) - { - ps[p].angAdjust += ps[p].getang() + ang; - } - else - { - ps[p].setang(ang); - } + playerSetAngle(&ps[p], s->ang + 1024); } else { @@ -2693,15 +2669,7 @@ void handle_se00(int i, int LASERLINE) { if (ps[p].cursectnum == s->sectnum && ps[p].on_ground == 1) { - int ang = l * q; - if (!cl_syncinput) - { - ps[p].angAdjust += ang; - } - else - { - ps[p].addang(ang); - } + playerAddAngle(&ps[p], l * q); ps[p].posz += zchange; @@ -2893,14 +2861,7 @@ void handle_se14(int i, bool checkstat, int RPG, int JIBS6) ps[p].bobposx += m; ps[p].bobposy += x; - if (!cl_syncinput) - { - ps[p].angAdjust += q; - } - else - { - ps[p].addang(q); - } + playerAddAngle(&ps[p], q); if (numplayers > 1) { diff --git a/source/games/duke/src/actors_d.cpp b/source/games/duke/src/actors_d.cpp index 2f56879b3..b992c6049 100644 --- a/source/games/duke/src/actors_d.cpp +++ b/source/games/duke/src/actors_d.cpp @@ -1852,15 +1852,7 @@ void moveweapons_d(void) if (s->picnum == SPIT) { - int horiz = 32; - if (!cl_syncinput) - { - ps[p].horizAdjust += horiz; - } - else - { - ps[p].addhoriz(horiz); - } + playerAddHoriz(&ps[p], 32); ps[p].return_to_center = 8; if (ps[p].loogcnt == 0) diff --git a/source/games/duke/src/actors_r.cpp b/source/games/duke/src/actors_r.cpp index 95fd3e136..91a0cde88 100644 --- a/source/games/duke/src/actors_r.cpp +++ b/source/games/duke/src/actors_r.cpp @@ -1399,15 +1399,7 @@ void moveweapons_r(void) guts_r(s, RABBITJIBC, 2, myconnectindex); } - int horiz = 32; - if (!cl_syncinput) - { - ps[p].horizAdjust += horiz; - } - else - { - ps[p].addhoriz(horiz); - } + playerAddHoriz(&ps[p], 32); ps[p].return_to_center = 8; if (ps[p].loogcnt == 0) diff --git a/source/games/duke/src/funct.h b/source/games/duke/src/funct.h index 2b714a81c..21f0740d9 100644 --- a/source/games/duke/src/funct.h +++ b/source/games/duke/src/funct.h @@ -251,4 +251,9 @@ void backupweapon(player_struct* p); void resetinputhelpers(player_struct* p); void checkhardlanding(player_struct* p); +void playerAddAngle(player_struct* p, int ang); +void playerSetAngle(player_struct* p, int ang); +void playerAddHoriz(player_struct* p, int horiz); +void playerSetHoriz(player_struct* p, int horiz); + END_DUKE_NS diff --git a/source/games/duke/src/player.cpp b/source/games/duke/src/player.cpp index a95a41431..38870bf51 100644 --- a/source/games/duke/src/player.cpp +++ b/source/games/duke/src/player.cpp @@ -163,15 +163,7 @@ void forceplayerangle(struct player_struct* p) n = 128 - (krand() & 255); - int horiz = 64; - if (!cl_syncinput) - { - p->horizAdjust += horiz; - } - else - { - p->addhoriz(horiz); - } + playerAddHoriz(p, 64); p->return_to_center = 9; p->setlookang(n >> 1); p->setrotscrnang(n >> 1); @@ -413,15 +405,7 @@ void dokneeattack(int snum, int pi, const std::initializer_list & respawnli if (p->knee_incs > 0) { p->knee_incs++; - int horiz = -48; - if (!cl_syncinput) - { - p->horizAdjust += horiz; - } - else - { - p->addhoriz(horiz); - } + playerAddHoriz(p, -48); p->return_to_center = 9; if (p->knee_incs > 15) { @@ -938,15 +922,7 @@ void checkhardlanding(player_struct* p) { if (p->hard_landing > 0) { - int horiz = p->hard_landing << 4; - if (!cl_syncinput) - { - p->horizAdjust -= horiz; - } - else - { - p->addhoriz(-horiz); - } + playerAddHoriz(p, -(p->hard_landing << 4)); p->hard_landing--; } } @@ -1085,6 +1061,60 @@ void playerAimDown(int snum, ESyncBits sb_snum) } } +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- + +void playerAddAngle(player_struct* p, int ang) +{ + if (!cl_syncinput) + { + p->angAdjust += ang; + } + else + { + p->addang(ang); + } +} + +void playerSetAngle(player_struct* p, int ang) +{ + if (!cl_syncinput) + { + p->angAdjust += -1. * ((p->q16ang / 65536.) - ang); + } + else + { + p->setang(ang); + } +} + +void playerAddHoriz(player_struct* p, int horiz) +{ + if (!cl_syncinput) + { + p->horizAdjust += horiz; + } + else + { + p->addhoriz(horiz); + } +} + +void playerSetHoriz(player_struct* p, int horiz) +{ + if (!cl_syncinput) + { + p->horizAdjust += -1. * ((p->q16horiz / 65536.) - horiz); + } + else + { + p->sethoriz(horiz); + } +} + //--------------------------------------------------------------------------- // // split out so that the weapon check can be done right. diff --git a/source/games/duke/src/player_d.cpp b/source/games/duke/src/player_d.cpp index d97f07933..18fdbf677 100644 --- a/source/games/duke/src/player_d.cpp +++ b/source/games/duke/src/player_d.cpp @@ -3033,19 +3033,7 @@ HORIZONLY: sethorizon(snum, sb_snum, 1, sync[snum].q16horz); } - if (p->hard_landing > 0) - { - int horiz = p->hard_landing << 4; - if (!cl_syncinput) - { - p->horizAdjust -= horiz; - } - else - { - p->addhoriz(-horiz); - } - p->hard_landing--; - } + checkhardlanding(p); //Shooting code/changes diff --git a/source/games/duke/src/player_r.cpp b/source/games/duke/src/player_r.cpp index 944229ac7..82d5578e4 100644 --- a/source/games/duke/src/player_r.cpp +++ b/source/games/duke/src/player_r.cpp @@ -1503,18 +1503,6 @@ void checkweapons_r(struct player_struct* p) } } -//--------------------------------------------------------------------------- -// -// -// -//--------------------------------------------------------------------------- - -static inline double calcVehicleHorizAdjust(fixed_t q16horiz, int adjustment) -{ - return -1. * ((q16horiz / 65536.) - adjustment); -} - - //--------------------------------------------------------------------------- // // @@ -1706,14 +1694,7 @@ static void onMotorcycle(int snum, ESyncBits &sb_snum) p->TurbCount--; p->moto_drink = (krand() & 3) - 2; } - if (!cl_syncinput) - { - p->horizAdjust += calcVehicleHorizAdjust(p->q16horiz, horiz); - } - else - { - p->sethoriz(horiz); - } + playerSetHoriz(p, horiz); } else if (p->VBumpTarget > p->VBumpNow) { @@ -1723,14 +1704,7 @@ static void onMotorcycle(int snum, ESyncBits &sb_snum) p->VBumpNow++; if (p->VBumpTarget < p->VBumpNow) p->VBumpNow = p->VBumpTarget; - if (!cl_syncinput) - { - p->horizAdjust += calcVehicleHorizAdjust(p->q16horiz, 100 + p->VBumpNow / 3); - } - else - { - p->sethoriz(100 + p->VBumpNow / 3); - } + playerSetHoriz(p, 100 + p->VBumpNow / 3); } else if (p->VBumpTarget < p->VBumpNow) { @@ -1740,14 +1714,7 @@ static void onMotorcycle(int snum, ESyncBits &sb_snum) p->VBumpNow--; if (p->VBumpTarget > p->VBumpNow) p->VBumpNow = p->VBumpTarget; - if (!cl_syncinput) - { - p->horizAdjust += calcVehicleHorizAdjust(p->q16horiz, 100 + p->VBumpNow / 3); - } - else - { - p->sethoriz(100 + p->VBumpNow / 3); - } + playerSetHoriz(p, 100 + p->VBumpNow / 3); } else { @@ -1806,14 +1773,7 @@ static void onMotorcycle(int snum, ESyncBits &sb_snum) ang = var98 >> 7; } } - if (!cl_syncinput) - { - p->angAdjust -= ang; - } - else - { - p->setang((var90 - ang) & 2047); - } + playerSetAngle(p, (var90 - ang) & 2047); } else if (p->MotoSpeed >= 20 && p->on_ground == 1 && (p->moto_on_mud || p->moto_on_oil)) { @@ -2058,14 +2018,7 @@ static void onBoat(int snum, ESyncBits& sb_snum) p->TurbCount--; p->moto_drink = (krand() & 3) - 2; } - if (!cl_syncinput) - { - p->horizAdjust += calcVehicleHorizAdjust(p->q16horiz, horiz); - } - else - { - p->sethoriz(horiz); - } + playerSetHoriz(p, horiz); } else if (p->VBumpTarget > p->VBumpNow) { @@ -2075,14 +2028,7 @@ static void onBoat(int snum, ESyncBits& sb_snum) p->VBumpNow++; if (p->VBumpTarget < p->VBumpNow) p->VBumpNow = p->VBumpTarget; - if (!cl_syncinput) - { - p->horizAdjust += calcVehicleHorizAdjust(p->q16horiz, 100 + p->VBumpNow / 3); - } - else - { - p->sethoriz(100 + p->VBumpNow / 3); - } + playerSetHoriz(p, 100 + p->VBumpNow / 3); } else if (p->VBumpTarget < p->VBumpNow) { @@ -2092,14 +2038,7 @@ static void onBoat(int snum, ESyncBits& sb_snum) p->VBumpNow--; if (p->VBumpTarget > p->VBumpNow) p->VBumpNow = p->VBumpTarget; - if (!cl_syncinput) - { - p->horizAdjust += calcVehicleHorizAdjust(p->q16horiz, 100 + p->VBumpNow / 3); - } - else - { - p->sethoriz(100 + p->VBumpNow / 3); - } + playerSetHoriz(p, 100 + p->VBumpNow / 3); } else { @@ -2133,14 +2072,7 @@ static void onBoat(int snum, ESyncBits& sb_snum) p->posyv += (vard4 >> 7) * (sintable[(vardc * -51 + vard8) & 2047] << 4); ang = vare0 >> 6; } - if (!cl_syncinput) - { - p->angAdjust -= ang; - } - else - { - p->setang((vard8 - ang) & 2047); - } + playerSetAngle(p, (vard8 - ang) & 2047); } if (p->NotOnWater) if (p->MotoSpeed > 50) @@ -2482,14 +2414,7 @@ void onMotorcycleMove(int snum, int psect, int j) ang = -(p->MotoSpeed >> 1); break; } - if (!cl_syncinput) - { - p->angAdjust += ang; - } - else - { - p->addang(ang); - } + playerAddAngle(p, ang); if (var10c >= 441 && var10c <= 581) { var104 = (p->MotoSpeed * p->MotoSpeed) >> 8; @@ -2556,14 +2481,7 @@ void onBoatMove(int snum, int psect, int j) ang = -(p->MotoSpeed >> 2); break; } - if (!cl_syncinput) - { - p->angAdjust += ang; - } - else - { - p->addang(ang); - } + playerAddAngle(p, ang); if (var118 >= 441 && var118 <= 581) { p->MotoSpeed = ((p->MotoSpeed >> 1) + (p->MotoSpeed >> 2)) >> 2; @@ -3097,14 +3015,7 @@ static void operateweapon(int snum, ESyncBits sb_snum, int psect) case RIFLEGUN_WEAPON: p->kickback_pic++; - if (!cl_syncinput) - { - p->horizAdjust += 1; - } - else - { - p->addhoriz(1); - } + playerAddHoriz(p, 1); p->recoil++; if (p->kickback_pic <= 12) @@ -3194,25 +3105,11 @@ static void operateweapon(int snum, ESyncBits sb_snum, int psect) } if (p->kickback_pic == 2) { - if (!cl_syncinput) - { - p->angAdjust += 16; - } - else - { - p->addang(16); - } + playerAddAngle(p, 16); } else if (p->kickback_pic == 4) { - if (!cl_syncinput) - { - p->angAdjust -= 16; - } - else - { - p->addang(-16); - } + playerAddAngle(p, -16); } if (p->kickback_pic > 4) p->kickback_pic = 1; @@ -3238,26 +3135,11 @@ static void operateweapon(int snum, ESyncBits sb_snum, int psect) } if (p->kickback_pic == 2) { - int ang = 4; - if (!cl_syncinput) - { - p->angAdjust += 4; - } - else - { - p->addang(4); - } + playerAddAngle(p, 4); } else if (p->kickback_pic == 4) { - if (!cl_syncinput) - { - p->angAdjust -= -4; - } - else - { - p->addang(-4); - } + playerAddAngle(p, -4); } if (p->kickback_pic > 4) p->kickback_pic = 1; @@ -3305,14 +3187,7 @@ static void operateweapon(int snum, ESyncBits sb_snum, int psect) { p->posxv -= sintable[(p->getang() + 512) & 2047] << 4; p->posyv -= sintable[p->getang() & 2047] << 4; - if (!cl_syncinput) - { - p->horizAdjust += 20; - } - else - { - p->addhoriz(20); - } + playerAddHoriz(p, 20); p->recoil += 20; } if (p->kickback_pic > 20) @@ -4196,15 +4071,7 @@ HORIZONLY: if (!d) d = 1; p->recoil -= d; - - if (!cl_syncinput) - { - p->horizAdjust -= d; - } - else - { - p->addhoriz(-d); - } + playerAddHoriz(p, -d); } if (cl_syncinput) diff --git a/source/games/duke/src/premap.cpp b/source/games/duke/src/premap.cpp index e0705fe9d..99044ca90 100644 --- a/source/games/duke/src/premap.cpp +++ b/source/games/duke/src/premap.cpp @@ -59,6 +59,7 @@ void pickrandomspot(int snum) p->bobposy = p->oposy = p->posy = po[i].oy; p->oposz = p->posz = po[i].oz; p->setang(po[i].oa); + p->setoang(po[i].oa); p->cursectnum = po[i].os; }