From 0532cc84843e35156df4b13623d08a24d045d390 Mon Sep 17 00:00:00 2001 From: toaster Date: Mon, 30 May 2022 18:15:52 +0100 Subject: [PATCH] Remove P_InitAngle and its kin, considered on a case-by-case basis for also setting old_angle as well. --- src/k_battle.c | 4 +- src/k_collide.c | 3 +- src/k_follower.c | 2 +- src/k_kart.c | 56 +++- src/k_race.c | 421 +++++++++++++++++++++++++ src/k_respawn.c | 770 ++++++++++++++++++++++++++++++++++++++++++++++ src/lua_baselib.c | 43 +++ src/p_enemy.c | 57 ++-- src/p_inter.c | 16 +- src/p_local.h | 3 - src/p_map.c | 25 -- src/p_mobj.c | 84 ++--- src/p_telept.c | 3 +- src/p_user.c | 10 +- 14 files changed, 1361 insertions(+), 136 deletions(-) create mode 100644 src/k_race.c create mode 100644 src/k_respawn.c diff --git a/src/k_battle.c b/src/k_battle.c index 4d1e6a9fa..9113e817e 100644 --- a/src/k_battle.c +++ b/src/k_battle.c @@ -274,7 +274,7 @@ mobj_t *K_SpawnSphereBox(fixed_t x, fixed_t y, fixed_t z, angle_t angle, SINT8 f { mobj_t *drop = P_SpawnMobj(x, y, z, MT_SPHEREBOX); - P_InitAngle(drop, angle); + drop->angle = angle; P_Thrust(drop, FixedAngle(P_RandomFixed() * 180) + angle, P_RandomRange(4, 12) * mapobjectscale); @@ -612,7 +612,7 @@ static void K_SpawnOvertimeLaser(fixed_t x, fixed_t y, fixed_t scale) mo->eflags |= MFE_VERTICALFLIP; } - P_InitAngle(mo, R_PointToAngle2(mo->x, mo->y, battleovertime.x, battleovertime.y) + ANGLE_90); + mo->angle = R_PointToAngle2(mo->x, mo->y, battleovertime.x, battleovertime.y) + ANGLE_90; mo->renderflags |= (RF_DONTDRAW & ~(K_GetPlayerDontDrawFlag(player))); P_SetScale(mo, scale); diff --git a/src/k_collide.c b/src/k_collide.c index 80847fa01..3bb144608 100644 --- a/src/k_collide.c +++ b/src/k_collide.c @@ -549,7 +549,7 @@ boolean K_DropTargetCollide(mobj_t *t1, mobj_t *t2) if (t2deflect < ANG10) P_InstaThrust(t2, t2angle, t2speed); - P_InitAngle(t1, R_PointToAngle2(0, 0, t1->momx, t1->momy)); + t1->angle = t1->old_angle = R_PointToAngle2(0, 0, t1->momx, t1->momy); t1->reactiontime = 7*(t1speed+t2speed)/FRACUNIT; if (t1->reactiontime < 10) @@ -591,7 +591,6 @@ boolean K_DropTargetCollide(mobj_t *t1, mobj_t *t2) { blast->angle += ANGLE_90; } - P_InitAngle(blast, blast->angle); blast->destscale *= 10; } diff --git a/src/k_follower.c b/src/k_follower.c index 2a5f92a05..53c211458 100644 --- a/src/k_follower.c +++ b/src/k_follower.c @@ -330,7 +330,7 @@ void K_HandleFollower(player_t *player) K_UpdateFollowerState(player->follower, fl.idlestate, FOLLOWERSTATE_IDLE); P_SetTarget(&player->follower->target, player->mo); // we need that to know when we need to disappear - P_InitAngle(player->follower, player->mo->angle); + player->follower->angle = player->follower->old_angle = player->mo->angle; // This is safe to only spawn it here, the follower is removed then respawned when switched. if (bubble) diff --git a/src/k_kart.c b/src/k_kart.c index ed886f906..27e0483c7 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -1787,7 +1787,7 @@ void K_SpawnDashDustRelease(player_t *player) dust = P_SpawnMobj(newx, newy, player->mo->z, MT_FASTDUST); P_SetTarget(&dust->target, player->mo); - P_InitAngle(dust, travelangle - ((i&1) ? -1 : 1) * ANGLE_45); + dust->angle = travelangle - (((i&1) ? -1 : 1) * ANGLE_45); dust->destscale = player->mo->scale; P_SetScale(dust, player->mo->scale); @@ -1835,7 +1835,7 @@ void K_SpawnNormalSpeedLines(player_t *player) MT_FASTLINE); P_SetTarget(&fast->target, player->mo); - P_InitAngle(fast, K_MomentumAngle(player->mo)); + fast->angle = K_MomentumAngle(player->mo); fast->momx = 3*player->mo->momx/4; fast->momy = 3*player->mo->momy/4; fast->momz = 3*P_GetMobjZMovement(player->mo)/4; @@ -1891,7 +1891,7 @@ void K_SpawnInvincibilitySpeedLines(mobj_t *mo) P_SetMobjState(fast, S_KARTINVLINES1); P_SetTarget(&fast->target, mo); - P_InitAngle(fast, K_MomentumAngle(mo)); + fast->angle = K_MomentumAngle(mo); fast->momx = 3*mo->momx/4; fast->momy = 3*mo->momy/4; @@ -3473,7 +3473,7 @@ void K_TakeBumpersFromPlayer(player_t *player, player_t *victim, UINT8 amount) P_SetTarget(&newmo->tracer, victim->mo); P_SetTarget(&newmo->target, player->mo); - P_InitAngle(newmo, (diff * (newbumper-1))); + newmo->angle = (diff * (newbumper-1)); newmo->color = victim->skincolor; if (newbumper+1 < 2) @@ -3561,7 +3561,7 @@ void K_SpawnMineExplosion(mobj_t *source, UINT8 color) { dust = P_SpawnMobj(source->x, source->y, source->z, MT_SMOKE); P_SetMobjState(dust, S_OPAQUESMOKE1); - P_InitAngle(dust, (ANGLE_180/16) * i); + dust->angle = (ANGLE_180/16) * i; P_SetScale(dust, source->scale); dust->destscale = source->scale*10; dust->scalespeed = source->scale/12; @@ -3676,6 +3676,7 @@ static mobj_t *K_SpawnKartMissile(mobj_t *source, mobjtype_t type, angle_t an, I } th->angle = an; + th->momx = FixedMul(finalspeed, FINECOSINE(an>>ANGLETOFINESHIFT)); th->momy = FixedMul(finalspeed, FINESINE(an>>ANGLETOFINESHIFT)); @@ -3818,7 +3819,7 @@ static void K_SpawnDriftSparks(player_t *player) spark = P_SpawnMobj(newx, newy, player->mo->z, MT_DRIFTSPARK); P_SetTarget(&spark->target, player->mo); - spark->angle = travelangle-(ANGLE_45/5)*player->drift; + spark->angle = travelangle-((ANGLE_45/5)*player->drift); spark->destscale = player->mo->scale; P_SetScale(spark, player->mo->scale); @@ -3945,7 +3946,7 @@ static void K_SpawnAIZDust(player_t *player) newy = player->mo->y + P_ReturnThrustY(player->mo, travelangle - (player->aizdriftstrat*ANGLE_45), FixedMul(24*FRACUNIT, player->mo->scale)); spark = P_SpawnMobj(newx, newy, player->mo->z, MT_AIZDRIFTSTRAT); - P_InitAngle(spark, travelangle+(player->aizdriftstrat*ANGLE_90)); + spark->angle = travelangle+(player->aizdriftstrat*ANGLE_90); P_SetScale(spark, (spark->destscale = (3*player->mo->scale)>>2)); spark->momx = (6*player->mo->momx)/5; @@ -3997,7 +3998,7 @@ void K_SpawnBoostTrail(player_t *player) flame = P_SpawnMobj(newx, newy, ground, MT_SNEAKERTRAIL); P_SetTarget(&flame->target, player->mo); - P_InitAngle(flame, travelangle); + flame->angle = travelangle; flame->fuse = TICRATE*2; flame->destscale = player->mo->scale; P_SetScale(flame, player->mo->scale); @@ -4069,7 +4070,7 @@ void K_SpawnWipeoutTrail(mobj_t *mo, boolean translucent) mo->z, MT_WIPEOUTTRAIL); P_SetTarget(&dust->target, mo); - dust->angle = R_PointToAngle2(0,0,mo->momx,mo->momy); + dust->angle = K_MomentumAngle(mo); dust->destscale = mo->scale; P_SetScale(dust, mo->scale); K_FlipFromObject(dust, mo); @@ -4527,7 +4528,7 @@ static void K_DoLightningShield(player_t *player) for (i=0; i<7; i++) { mo = P_SpawnMobj(player->mo->x, player->mo->y, player->mo->z, MT_THOK); - P_InitAngle(mo, P_RandomRange(0, 359)*ANG1); + mo->angle = P_RandomRange(0, 359)*ANG1; mo->fuse = P_RandomRange(20, 50); P_SetTarget(&mo->target, player->mo); P_SetMobjState(mo, S_KLIT1); @@ -4540,7 +4541,7 @@ static void K_DoLightningShield(player_t *player) sx = player->mo->x + FixedMul((player->mo->scale*THUNDERRADIUS), FINECOSINE((an*i)>>ANGLETOFINESHIFT)); sy = player->mo->y + FixedMul((player->mo->scale*THUNDERRADIUS), FINESINE((an*i)>>ANGLETOFINESHIFT)); mo = P_SpawnMobj(sx, sy, player->mo->z, MT_THOK); - P_InitAngle(mo, an*i); + mo->angle = an*i; mo->extravalue1 = THUNDERRADIUS; // Used to know whether we should teleport by radius or something. mo->scale = player->mo->scale*3; P_SetTarget(&mo->target, player->mo); @@ -4916,7 +4917,7 @@ static void K_ThrowLandMine(player_t *player) P_SetScale(landMine, player->mo->scale); landMine->destscale = player->mo->destscale; - P_InitAngle(landMine, player->mo->angle); + landMine->angle = player->mo->angle; landMine->momz = (30 * mapobjectscale * P_MobjFlip(player->mo)) + player->mo->momz; landMine->color = player->skincolor; @@ -5210,7 +5211,7 @@ mobj_t *K_CreatePaperItem(fixed_t x, fixed_t y, fixed_t z, angle_t angle, SINT8 P_SetScale(drop, drop->scale>>4); drop->destscale = (3*drop->destscale)/2; - P_InitAngle(drop, angle); + drop->angle = angle; P_Thrust(drop, FixedAngle(P_RandomFixed() * 180) + angle, 16*mapobjectscale); @@ -6789,7 +6790,7 @@ void K_KartPlayerThink(player_t *player, ticcmd_t *cmd) { mobj_t *ring = P_SpawnMobj(player->mo->x, player->mo->y, player->mo->z, MT_RING); ring->extravalue1 = 1; // Ring collect animation timer - P_InitAngle(ring, player->mo->angle); // animation angle + ring->angle = player->mo->angle; // animation angle P_SetTarget(&ring->target, player->mo); // toucher for thinker player->pickuprings++; if (player->superring <= 3) @@ -7694,6 +7695,27 @@ INT32 K_GetKartDriftSparkValue(player_t *player) return (26*4 + kartspeed*2 + (9 - player->kartweight))*8; } +INT32 K_GetKartDriftSparkValueForStage(player_t *player, UINT8 stage) +{ + fixed_t mul = FRACUNIT; + + // This code is function is pretty much useless now that the timing changes are linear but bleh. + switch (stage) + { + case 2: + mul = 2*FRACUNIT; // x2 + break; + case 3: + mul = 3*FRACUNIT; // x3 + break; + case 4: + mul = 4*FRACUNIT; // x4 + break; + } + + return (FixedMul(K_GetKartDriftSparkValue(player) * FRACUNIT, mul) / FRACUNIT); +} + static void K_KartDrift(player_t *player, boolean onground) { fixed_t minspeed = (10 * player->mo->scale); @@ -8443,7 +8465,7 @@ void K_MoveKartPlayer(player_t *player, boolean onground) mo = P_SpawnMobj(player->mo->x, player->mo->y, player->mo->z, MT_ROCKETSNEAKER); K_MatchGenericExtraFlags(mo, player->mo); mo->flags |= MF_NOCLIPTHING; - P_InitAngle(mo, player->mo->angle); + mo->angle = player->mo->angle; mo->threshold = 10; mo->movecount = moloop%2; mo->movedir = mo->lastlook = moloop+1; @@ -8541,7 +8563,7 @@ void K_MoveKartPlayer(player_t *player, boolean onground) break; } mo->flags |= MF_NOCLIPTHING; - P_InitAngle(mo, newangle); + mo->angle = newangle; mo->threshold = 10; mo->movecount = player->itemamount; mo->movedir = mo->lastlook = moloop+1; @@ -8582,7 +8604,7 @@ void K_MoveKartPlayer(player_t *player, boolean onground) break; } mo->flags |= MF_NOCLIPTHING; - P_InitAngle(mo, newangle); + mo->angle = newangle; mo->threshold = 10; mo->movecount = player->itemamount; mo->movedir = mo->lastlook = moloop+1; diff --git a/src/k_race.c b/src/k_race.c new file mode 100644 index 000000000..1354b9d56 --- /dev/null +++ b/src/k_race.c @@ -0,0 +1,421 @@ +// SONIC ROBO BLAST 2 KART +//----------------------------------------------------------------------------- +// Copyright (C) 2018-2020 by Kart Krew +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file k_race.c +/// \brief Race Mode specific code. + +#include "k_race.h" + +#include "k_kart.h" +#include "k_battle.h" +#include "k_pwrlv.h" +#include "k_color.h" +#include "k_respawn.h" +#include "doomdef.h" +#include "hu_stuff.h" +#include "g_game.h" +#include "m_random.h" +#include "p_local.h" +#include "p_slopes.h" +#include "p_setup.h" +#include "r_draw.h" +#include "r_local.h" +#include "s_sound.h" +#include "st_stuff.h" +#include "v_video.h" +#include "z_zone.h" +#include "m_misc.h" +#include "m_cond.h" +#include "f_finale.h" +#include "lua_hud.h" // For Lua hud checks +#include "lua_hook.h" // For MobjDamage and ShouldDamage +#include "m_cheat.h" // objectplacing +#include "p_spec.h" + +#include "k_waypoint.h" +#include "k_bot.h" +#include "k_hud.h" + +line_t *finishBeamLine = NULL; + +static mobj_t *beamPoints[2]; +static UINT8 numBeamPoints = 0; + +/*-------------------------------------------------- + void K_ClearFinishBeamLine(void) + + See header file for description. +--------------------------------------------------*/ +void K_ClearFinishBeamLine(void) +{ + size_t i; + + finishBeamLine = NULL; + + for (i = 0; i < 2; i++) + { + beamPoints[i] = NULL; + } + + numBeamPoints = 0; +} + +/*-------------------------------------------------- + static void K_FreeFinishBeamLine(void) + + See header file for description. +--------------------------------------------------*/ +static void K_FreeFinishBeamLine(void) +{ + if (finishBeamLine != NULL) + { + if (finishBeamLine->v1 != NULL) + { + Z_Free(finishBeamLine->v1); + } + + if (finishBeamLine->v2 != NULL) + { + Z_Free(finishBeamLine->v2); + } + + Z_Free(finishBeamLine); + } + + K_ClearFinishBeamLine(); +} + +/*-------------------------------------------------- + static void K_CreateFinishLineFromPoints(fixed_t x1, fixed_t y1, fixed_t x2, fixed_t y2) + + See header file for description. +--------------------------------------------------*/ +static void K_CreateFinishLineFromPoints(fixed_t x1, fixed_t y1, fixed_t x2, fixed_t y2) +{ + I_Assert(finishBeamLine == NULL); // Needs to be NULL + + finishBeamLine = Z_Calloc(sizeof (*finishBeamLine), PU_LEVEL, NULL); + + finishBeamLine->v1 = Z_Calloc(sizeof (*finishBeamLine->v1), PU_LEVEL, NULL); + finishBeamLine->v1->x = x1; + finishBeamLine->v1->y = y1; + + finishBeamLine->v2 = Z_Calloc(sizeof (*finishBeamLine->v2), PU_LEVEL, NULL); + finishBeamLine->v2->x = x2; + finishBeamLine->v2->y = y2; + + finishBeamLine->dx = x2 - x1; + finishBeamLine->dy = y2 - y1; + + finishBeamLine->flags = 0; +} + +/*-------------------------------------------------- + boolean K_GenerateFinishBeamLine(void) + + See header file for description. +--------------------------------------------------*/ +boolean K_GenerateFinishBeamLine(void) +{ + mapthing_t *mt; + + INT64 bounds[4]; + angle_t angle = 0; + + boolean valid = false; + size_t i; + + // Ensure everything's freed by this time. + K_FreeFinishBeamLine(); + + // First: attempt to create from beam point objects + for (i = 0, mt = mapthings; i < nummapthings; i++, mt++) + { + if (numBeamPoints >= 2) + { + break; + } + + if (mt->type == mobjinfo[MT_BEAMPOINT].doomednum) + { + beamPoints[numBeamPoints] = mt->mobj; + numBeamPoints++; + } + } + + if (numBeamPoints == 2) + { + // Found 'em! Really easy to generate a line out of these :) + + K_CreateFinishLineFromPoints( + beamPoints[0]->x, beamPoints[0]->y, + beamPoints[1]->x, beamPoints[1]->y + ); + + return true; + } + + bounds[0] = INT64_MAX; // min x + bounds[1] = INT64_MIN; // max x + bounds[2] = INT64_MAX; // min y + bounds[3] = INT64_MIN; // max y + + for (i = 0; i < numlines; i++) + { + angle_t thisAngle; + + if (lines[i].special != 2001) + { + continue; + } + + thisAngle = R_PointToAngle2(0, 0, lines[i].dx, lines[i].dy); + + bounds[0] = min(bounds[0], min(lines[i].v1->x, lines[i].v2->x)); // min x + bounds[1] = max(bounds[1], max(lines[i].v1->x, lines[i].v2->x)); // max x + bounds[2] = min(bounds[2], min(lines[i].v1->y, lines[i].v2->y)); // min y + bounds[3] = max(bounds[3], max(lines[i].v1->y, lines[i].v2->y)); // max y + + if (valid == false) + { + angle = thisAngle; + valid = true; + } + else if (angle != thisAngle) + { + // Do not even attempt to bother with curved finish lines. + // Will likely just crash. + valid = false; + + break; + } + } + + if (valid == true) + { + fixed_t span = P_AproxDistance(bounds[1] - bounds[0], bounds[3] - bounds[2]) / 2; + + fixed_t cx = (bounds[0] + bounds[1]) / 2; + fixed_t cy = (bounds[2] + bounds[3]) / 2; + + fixed_t spanC = FixedMul(span, FINECOSINE(angle >> ANGLETOFINESHIFT)); + fixed_t spanS = FixedMul(span, FINESINE(angle >> ANGLETOFINESHIFT)); + + K_CreateFinishLineFromPoints( + cx - spanC, cy - spanS, + cx + spanC, cy + spanS + ); + + return true; + } + + return false; +} + +/*-------------------------------------------------- + static void K_DrawFinishLineBeamForLine(fixed_t offset, angle_t aiming, line_t *line, boolean reverse) + + Draws a helix out of rainbow colored orbs along a line, unique for each display player. + Called twice for the finish line beam effect. + + Input Arguments:- + offset - Offset value for positioning. Changed every tick to make it animate. + aiming - Starting vertical angle value. Changed every tick to make it animate. + line - Linedef to draw along. + reverse - Draw in reverse. Call twice with this toggled to make a double helix. + + Return:- + None +--------------------------------------------------*/ + +static void K_DrawFinishLineBeamForLine(fixed_t offset, angle_t aiming, line_t *line, boolean reverse) +{ + const fixed_t linelength = P_AproxDistance(line->dx, line->dy); + const fixed_t xstep = FixedDiv(line->dx, linelength); + const fixed_t ystep = FixedDiv(line->dy, linelength); + + fixed_t linex = line->v1->x; + fixed_t liney = line->v1->y; + angle_t lineangle = R_PointToAngle2(0, 0, line->dx, line->dy) + ANGLE_90; + + UINT8 i; + + if (line->flags & ML_NOCLIMB) + { + // Line is flipped + lineangle += ANGLE_180; + } + + linex += FixedMul(offset, xstep); + liney += FixedMul(offset, ystep); + + while (offset < linelength) + { +#define COLORCYCLELEN 10 + const UINT8 colorcycle[COLORCYCLELEN] = { + SKINCOLOR_PERIWINKLE, + SKINCOLOR_SLATE, + SKINCOLOR_BLOSSOM, + SKINCOLOR_RASPBERRY, + SKINCOLOR_ORANGE, + SKINCOLOR_YELLOW, + SKINCOLOR_LIME, + SKINCOLOR_TURTLE, + SKINCOLOR_ROBIN, + SKINCOLOR_JAWZ + }; + + const UINT8 numframes = 5; + const angle_t framethreshold = ANGLE_180 / (numframes-1); + const angle_t frameaim = aiming + (framethreshold / 2); + + fixed_t x, y, z; + UINT8 spriteframe = 0; + + x = linex + FixedMul(FixedMul(FINISHLINEBEAM_SPACING, FINECOSINE(lineangle >> ANGLETOFINESHIFT)), FINECOSINE(aiming >> ANGLETOFINESHIFT)); + y = liney + FixedMul(FixedMul(FINISHLINEBEAM_SPACING, FINESINE(lineangle >> ANGLETOFINESHIFT)), FINECOSINE(aiming >> ANGLETOFINESHIFT)); + z = FINISHLINEBEAM_SPACING + FixedMul(FINISHLINEBEAM_SPACING, FINESINE(aiming >> ANGLETOFINESHIFT)); + + if (leveltime >= starttime) + { + spriteframe = 4; // Weakest sprite when passable + } + else if (frameaim > ANGLE_180) + { + spriteframe = (ANGLE_MAX - frameaim) / framethreshold; + } + else + { + spriteframe = frameaim / framethreshold; + } + + for (i = 0; i <= r_splitscreen; i++) + { + if (playeringame[displayplayers[i]] && players[displayplayers[i]].mo && !P_MobjWasRemoved(players[displayplayers[i]].mo)) + { + mobj_t *beam; + + beam = P_SpawnMobj(x, y, players[displayplayers[i]].mo->z + z, MT_THOK); + P_SetMobjState(beam, S_FINISHBEAM1 + spriteframe); + + beam->colorized = true; + beam->renderflags = RF_DONTDRAW & ~K_GetPlayerDontDrawFlag(&players[displayplayers[i]]); + + if (reverse) + { + beam->color = colorcycle[((leveltime / 4) + (COLORCYCLELEN/2)) % COLORCYCLELEN]; + } + else + { + beam->color = colorcycle[(leveltime / 4) % COLORCYCLELEN]; + } + } + } + + offset += FINISHLINEBEAM_SPACING; + linex += FixedMul(FINISHLINEBEAM_SPACING, xstep); + liney += FixedMul(FINISHLINEBEAM_SPACING, ystep); + + if (reverse) + { + aiming -= ANGLE_45; + } + else + { + aiming += ANGLE_45; + } + } + + for (i = 0; i <= r_splitscreen; i++) + { + if (playeringame[displayplayers[i]] && players[displayplayers[i]].mo && !P_MobjWasRemoved(players[displayplayers[i]].mo)) + { + UINT8 j; + for (j = 0; j < 2; j++) + { + vertex_t *v = line->v1; + mobj_t *end1, *end2; + angle_t a = R_PointToAngle2(0, 0, line->dx, line->dy); + fixed_t sx; + fixed_t sy; + + /* + if (line->flags & ML_NOCLIMB) + { + a += ANGLE_180; + } + */ + + sx = FixedMul(3*mapobjectscale, FINECOSINE(a >> ANGLETOFINESHIFT)); + sy = FixedMul(3*mapobjectscale, FINESINE(a >> ANGLETOFINESHIFT)); + + if (j == 1) + { + v = line->v2; + sx = -sx; + sy = -sy; + } + + end1 = P_SpawnMobj( + v->x + sx, + v->y + sy, + players[displayplayers[i]].mo->z + FINISHLINEBEAM_SPACING, + MT_THOK + ); + + P_SetMobjState(end1, S_FINISHBEAMEND1); + end1->renderflags = RF_DONTDRAW & ~K_GetPlayerDontDrawFlag(&players[displayplayers[i]]); + end1->angle = lineangle; + + end2 = P_SpawnMobj( + v->x + (8*sx), + v->y + (8*sy), + players[displayplayers[i]].mo->z + FINISHLINEBEAM_SPACING, + MT_THOK + ); + + P_SetMobjState(end2, S_FINISHBEAMEND2); + end2->renderflags = RF_DONTDRAW & ~K_GetPlayerDontDrawFlag(&players[displayplayers[i]]); + end2->angle = lineangle; + + P_SetTarget(&end2->tracer, end1); + end2->flags2 |= MF2_LINKDRAW; + } + } + } +} + +/*-------------------------------------------------- + void K_RunFinishLineBeam(void) + + See header file for description. +--------------------------------------------------*/ + +void K_RunFinishLineBeam(void) +{ + if (!(leveltime < starttime || rainbowstartavailable == true)) + { + return; + } + + if (finishBeamLine != NULL) + { + const angle_t angoffset = ANGLE_45; + const angle_t angadd = ANGLE_11hh; + const fixed_t speed = 6 * mapobjectscale; + + fixed_t offseta = (leveltime * speed) % FINISHLINEBEAM_SPACING; + angle_t aiminga = (angoffset * -((leveltime * speed) / FINISHLINEBEAM_SPACING)) + (angadd * leveltime); + + fixed_t offsetb = FINISHLINEBEAM_SPACING - offseta; + angle_t aimingb = (angoffset * -((leveltime * speed) / FINISHLINEBEAM_SPACING)) - (angadd * leveltime); + + K_DrawFinishLineBeamForLine(offseta, aiminga, finishBeamLine, false); + K_DrawFinishLineBeamForLine(offsetb, aimingb, finishBeamLine, true); + } +} diff --git a/src/k_respawn.c b/src/k_respawn.c new file mode 100644 index 000000000..ef2a4c9f9 --- /dev/null +++ b/src/k_respawn.c @@ -0,0 +1,770 @@ +// SONIC ROBO BLAST 2 KART +//----------------------------------------------------------------------------- +// Copyright (C) 2018-2020 by Kart Krew +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file k_respawn.c +/// \brief Respawning logic + +#include "k_respawn.h" +#include "doomdef.h" +#include "d_player.h" +#include "k_kart.h" +#include "k_battle.h" +#include "g_game.h" +#include "p_local.h" +#include "p_tick.h" +#include "p_setup.h" +#include "r_main.h" +#include "s_sound.h" +#include "p_slopes.h" +#include "r_defs.h" + +/*-------------------------------------------------- + fixed_t K_RespawnOffset(player_t *player, boolean flip) + + See header file for description. +--------------------------------------------------*/ +fixed_t K_RespawnOffset(player_t *player, boolean flip) +{ + fixed_t z = 0; + + if (flip == true) + { + // Lat 24/7/20: Okay so before we even think about applying this flag, check if the sector we're in doesn't already have reverse gravity for that. + // Otherwise, we would reverse the reverse gravity and cancel it out. Yes, this is absolutely fucking dumb. + // I'm honestly not sure if this flag is even necessary anymore but we'll keep it just in case. + + if (P_GetMobjGravity(player->mo) < 0) + player->mo->flags2 |= MF2_OBJECTFLIP; + + player->mo->eflags |= MFE_VERTICALFLIP; + z -= ((128 * mapobjectscale) + (player->mo->height)); + } + else + { + player->mo->flags2 &= ~MF2_OBJECTFLIP; + player->mo->eflags &= ~MFE_VERTICALFLIP; + z += (128 * mapobjectscale); + } + + return z; +} + +/*-------------------------------------------------- + static void K_FudgeRespawn(player_t *player, const waypoint_t *const waypoint) + + Fudges respawn coordinates to slightly before the waypoint if it would + be exactly on a line. See K_GetWaypointIsOnLine. +--------------------------------------------------*/ +static void K_FudgeRespawn(player_t *player, const waypoint_t *const waypoint) +{ + const angle_t from = R_PointToAngle2(waypoint->mobj->x, waypoint->mobj->y, + player->mo->x, player->mo->y) >> ANGLETOFINESHIFT; + + player->respawn.pointx += FixedMul(16, FINECOSINE(from)); + player->respawn.pointy += FixedMul(16, FINESINE(from)); +} + +/*-------------------------------------------------- + static void K_RespawnAtWaypoint(player_t *player, waypoint_t *waypoint) + + Updates a player's respawn variables to go to the provided waypoint. + + Input Arguments:- + player - Player to preform for. + waypoint - Waypoint to respawn to. + + Return:- + None +--------------------------------------------------*/ +static void K_RespawnAtWaypoint(player_t *player, waypoint_t *waypoint) +{ + if (player == NULL || player->mo == NULL || P_MobjWasRemoved(player->mo)) + { + return; + } + + if (waypoint == NULL || waypoint->mobj == NULL || P_MobjWasRemoved(waypoint->mobj)) + { + return; + } + + player->respawn.pointx = waypoint->mobj->x; + player->respawn.pointy = waypoint->mobj->y; + player->respawn.pointz = waypoint->mobj->z; + player->respawn.flip = (waypoint->mobj->flags2 & MF2_OBJECTFLIP) ? true : false; // K_RespawnOffset wants a boolean! + player->respawn.pointz += K_RespawnOffset(player, player->respawn.flip); + + if (waypoint->onaline) + { + K_FudgeRespawn(player, waypoint); + } +} + +/*-------------------------------------------------- + void K_DoFault(player_t *player) + + See header file for description. +--------------------------------------------------*/ + +void K_DoFault(player_t *player) +{ + player->nocontrol = (starttime - leveltime) + 50; + if (!(player->pflags & PF_FAULT)) + { + S_StartSound(player->mo, sfx_s3k83); + player->karthud[khud_fault] = 1; + player->pflags |= PF_FAULT; + } +} + +/*-------------------------------------------------- + void K_DoIngameRespawn(player_t *player) + + See header file for description. +--------------------------------------------------*/ +void K_DoIngameRespawn(player_t *player) +{ + if (!player->mo || P_MobjWasRemoved(player->mo)) + { + return; + } + + if (player->respawn.state != RESPAWNST_NONE && + ( player->pflags & PF_FAULT ) == 0) + { + return; + } + + if (leveltime <= introtime) + { + return; + } + + // FAULT + if (leveltime < starttime) + K_DoFault(player); + + player->ringboost = 0; + player->driftboost = player->strongdriftboost = 0; + + K_TumbleInterrupt(player); + P_ResetPlayer(player); + + // Set up respawn position if invalid + if (player->respawn.wp != NULL && leveltime >= starttime) + { + const UINT32 dist = RESPAWN_DIST + (player->airtime * 48); + player->respawn.distanceleft = (dist * mapobjectscale) / FRACUNIT; + K_RespawnAtWaypoint(player, player->respawn.wp); + } + else + { + UINT32 bestdist = UINT32_MAX; + mapthing_t *beststart = NULL; + UINT8 numstarts = 0; + + if (gametype == GT_RACE) + { + numstarts = numcoopstarts; + } + else if (gametype == GT_BATTLE) + { + numstarts = numdmstarts; + } + + if (numstarts > 0) + { + UINT8 i = 0; + + for (i = 0; i < numstarts; i++) + { + UINT32 dist = UINT32_MAX; + mapthing_t *checkstart = NULL; + + if (gametype == GT_RACE) + { + checkstart = playerstarts[i]; + } + else if (gametype == GT_BATTLE) + { + checkstart = deathmatchstarts[i]; + } + else + { + break; + } + + dist = (UINT32)P_AproxDistance((player->mo->x >> FRACBITS) - checkstart->x, + (player->mo->y >> FRACBITS) - checkstart->y); + + if (dist < bestdist) + { + beststart = checkstart; + bestdist = dist; + } + } + } + + if (beststart == NULL) + { + CONS_Alert(CONS_WARNING, "No respawn points!\n"); + player->respawn.pointx = 0; + player->respawn.pointy = 0; + player->respawn.pointz = 0; + player->respawn.flip = false; + } + else + { + sector_t *s; + fixed_t z = beststart->z * FRACUNIT; + + player->respawn.pointx = beststart->x << FRACBITS; + player->respawn.pointy = beststart->y << FRACBITS; + + player->mo->angle = ( beststart->angle * ANG1 ); + + s = R_PointInSubsector(beststart->x << FRACBITS, beststart->y << FRACBITS)->sector; + + player->respawn.flip = (beststart->options & MTF_OBJECTFLIP); + + if (player->respawn.flip == true) + { + player->respawn.pointz = ( +#ifdef ESLOPE + s->c_slope ? P_GetZAt(s->c_slope, player->respawn.pointx, player->respawn.pointy) : +#endif + s->ceilingheight); + + if (z != 0) + { + player->respawn.pointz -= z; + } + } + else + { + player->respawn.pointz = ( +#ifdef ESLOPE + s->f_slope ? P_GetZAt(s->f_slope, player->respawn.pointx, player->respawn.pointy) : +#endif + s->floorheight); + + if (z) + { + player->respawn.pointz += z; + } + } + } + + player->respawn.pointz += K_RespawnOffset(player, player->respawn.flip); + player->respawn.distanceleft = 0; + } + + player->respawn.timer = RESPAWN_TIME; + player->respawn.state = RESPAWNST_MOVE; + + player->respawn.airtimer = player->airtime; + player->respawn.truedeath = false; +} + +/*-------------------------------------------------- + size_t K_NextRespawnWaypointIndex(waypoint_t *waypoint) + + See header file for description. +--------------------------------------------------*/ +size_t K_NextRespawnWaypointIndex(waypoint_t *waypoint) +{ + size_t i = 0U; + size_t newwaypoint = SIZE_MAX; + + // Set to the first valid nextwaypoint, for simplicity's sake. + // If we reach the last waypoint and it's still not valid, just use it anyway. Someone needs to fix their map! + for (i = 0U; i < waypoint->numnextwaypoints; i++) + { + newwaypoint = i; + + if ((i == waypoint->numnextwaypoints - 1U) + || ((K_GetWaypointIsEnabled(waypoint->nextwaypoints[newwaypoint]) == true) + && (K_GetWaypointIsSpawnpoint(waypoint->nextwaypoints[newwaypoint]) == true))) + { + break; + } + } + + return newwaypoint; +} + +/*-------------------------------------------------- + static void K_MovePlayerToRespawnPoint(player_t *player) + + Handles the movement state of the respawn animation. + + Input Arguments:- + player - Player to preform for. + + Return:- + None +--------------------------------------------------*/ +static void K_MovePlayerToRespawnPoint(player_t *player) +{ + const int airCompensation = 128; + fixed_t realstepamt = (64 * mapobjectscale); + fixed_t stepamt; + + vector3_t dest, step, laser; + angle_t stepha, stepva; + fixed_t dist, fulldist; + + UINT8 lasersteps = 4; + UINT32 laserdist; + waypoint_t *laserwp; + boolean laserflip; + + /* speed up if in the air for a long time */ + realstepamt += FixedMul(realstepamt, + (player->respawn.airtimer * FRACUNIT) + / airCompensation); + + stepamt = realstepamt; + + player->mo->momx = player->mo->momy = player->mo->momz = 0; + + player->flashing = 2; + player->nocontrol = max(2, player->nocontrol); + + if (leveltime % 8 == 0 && !mapreset) + { + S_StartSound(player->mo, sfx_s3kcas); + } + + dest.x = player->respawn.pointx; + dest.y = player->respawn.pointy; + dest.z = player->respawn.pointz; + + dist = P_AproxDistance(P_AproxDistance( + player->mo->x - dest.x, + player->mo->y - dest.y), + player->mo->z - dest.z + ); + + if (dist <= stepamt) + { + // Reduce by the amount we needed to get to this waypoint + stepamt -= dist; + + // We've reached the destination point, + P_UnsetThingPosition(player->mo); + player->mo->x = dest.x; + player->mo->y = dest.y; + player->mo->z = dest.z; + P_SetThingPosition(player->mo); + + // Find the next waypoint to head towards + if (player->respawn.wp != NULL) + { + size_t nwp = K_NextRespawnWaypointIndex(player->respawn.wp); + + if (nwp == SIZE_MAX) + { + player->respawn.state = RESPAWNST_DROP; + return; + } + + // Set angle, regardless of if we're done or not + P_SetPlayerAngle(player, R_PointToAngle2( + player->respawn.wp->mobj->x, + player->respawn.wp->mobj->y, + player->respawn.wp->nextwaypoints[nwp]->mobj->x, + player->respawn.wp->nextwaypoints[nwp]->mobj->y + )); + player->drawangle = R_PointToAngle2( + player->mo->x, player->mo->y, + dest.x, dest.y + ); + + if ((player->respawn.distanceleft == 0 && K_GetWaypointIsSpawnpoint(player->respawn.wp) == true) + || (player->respawn.wp == K_GetFinishLineWaypoint() + || player->respawn.wp->nextwaypoints[nwp] == K_GetFinishLineWaypoint())) // Try not to allow you to pass the finish line while respawning, because it's janky + { + // Alright buddy, that's the end of the ride. + player->respawn.state = RESPAWNST_DROP; + return; + } + + if (player->respawn.distanceleft > player->respawn.wp->nextwaypointdistances[nwp]) + { + player->respawn.distanceleft -= player->respawn.wp->nextwaypointdistances[nwp]; + } + else + { + player->respawn.distanceleft = 0; + } + + player->respawn.wp = player->respawn.wp->nextwaypoints[nwp]; + K_RespawnAtWaypoint(player, player->respawn.wp); + + dest.x = player->respawn.pointx; + dest.y = player->respawn.pointy; + dest.z = player->respawn.pointz; + } + else + { + // We can now drop! + player->respawn.state = RESPAWNST_DROP; + return; + } + } + + stepha = R_PointToAngle2( + player->mo->x, player->mo->y, + dest.x, dest.y + ); + + stepva = R_PointToAngle2( + 0, player->mo->z, + P_AproxDistance(player->mo->x - dest.x, player->mo->y - dest.y), dest.z + ); + + // Move toward the respawn point + player->drawangle = stepha; + + step.x = FixedMul(FixedMul(FINECOSINE(stepha >> ANGLETOFINESHIFT), stepamt), FINECOSINE(stepva >> ANGLETOFINESHIFT)); + step.y = FixedMul(FixedMul(FINESINE(stepha >> ANGLETOFINESHIFT), stepamt), FINECOSINE(stepva >> ANGLETOFINESHIFT)); + step.z = FixedMul(FINESINE(stepva >> ANGLETOFINESHIFT), 2*stepamt); + + if (stepamt > 0) + { + player->mo->momx = step.x; + player->mo->momy = step.y; + player->mo->momz = step.z; + } + + // NOW THEN, time for loads of dumb duplication! + // "Emulate" the rest of the path, that way we can spawn a particle a certain distance ahead of you. + + if (stepamt != realstepamt) + { + // Reset back to default + stepamt = realstepamt; + + step.x = FixedMul(FixedMul(FINECOSINE(stepha >> ANGLETOFINESHIFT), stepamt), FINECOSINE(stepva >> ANGLETOFINESHIFT)); + step.y = FixedMul(FixedMul(FINESINE(stepha >> ANGLETOFINESHIFT), stepamt), FINECOSINE(stepva >> ANGLETOFINESHIFT)); + step.z = FixedMul(FINESINE(stepva >> ANGLETOFINESHIFT), 2*stepamt); + } + + laserdist = player->respawn.distanceleft; + laserwp = player->respawn.wp; + laserflip = player->respawn.flip; + + laser.x = player->mo->x + (step.x / 2); + laser.y = player->mo->y + (step.y / 2); + laser.z = player->mo->z + (step.z / 2); + + dist = P_AproxDistance(P_AproxDistance( + laser.x - dest.x, + laser.y - dest.y), + laser.z - dest.z + ); + fulldist = dist + (laserdist * FRACUNIT); + + while (lasersteps > 0) + { + if (fulldist <= stepamt) + { + break; + } + + if (dist <= stepamt) + { + size_t lnwp; + + laser.x = dest.x; + laser.y = dest.y; + laser.z = dest.z; + + if (laserdist <= 0) + { + break; + } + + lnwp = K_NextRespawnWaypointIndex(laserwp); + if (lnwp == SIZE_MAX) + { + break; + } + + if (laserdist > laserwp->nextwaypointdistances[lnwp]) + { + laserdist -= laserwp->nextwaypointdistances[lnwp]; + } + else + { + laserdist = 0; + } + + laserwp = laserwp->nextwaypoints[lnwp]; + + dest.x = laserwp->mobj->x; + dest.y = laserwp->mobj->y; + dest.z = laserwp->mobj->z; + laserflip = (laserwp->mobj->flags2 & MF2_OBJECTFLIP); + + if (laserflip == true) + { + dest.z -= (128 * mapobjectscale) - (player->mo->height); + } + else + { + dest.z += (128 * mapobjectscale); + } + + stepamt -= dist; + + stepha = R_PointToAngle2(laser.x, laser.y, dest.x, dest.y); + stepva = R_PointToAngle2(0, laser.z, P_AproxDistance(laser.x - dest.x, laser.y - dest.y), dest.z); + + step.x = FixedMul(FixedMul(FINECOSINE(stepha >> ANGLETOFINESHIFT), stepamt), FINECOSINE(stepva >> ANGLETOFINESHIFT)); + step.y = FixedMul(FixedMul(FINESINE(stepha >> ANGLETOFINESHIFT), stepamt), FINECOSINE(stepva >> ANGLETOFINESHIFT)); + step.z = FixedMul(FINESINE(stepva >> ANGLETOFINESHIFT), 2*stepamt); + } + else if (stepamt != realstepamt) + { + // Reset back to default + stepamt = realstepamt; + + step.x = FixedMul(FixedMul(FINECOSINE(stepha >> ANGLETOFINESHIFT), stepamt), FINECOSINE(stepva >> ANGLETOFINESHIFT)); + step.y = FixedMul(FixedMul(FINESINE(stepha >> ANGLETOFINESHIFT), stepamt), FINECOSINE(stepva >> ANGLETOFINESHIFT)); + step.z = FixedMul(FINESINE(stepva >> ANGLETOFINESHIFT), 2*stepamt); + } + + if (stepamt > 0) + { + laser.x += step.x; + laser.y += step.y; + laser.z += step.z; + } + + dist = P_AproxDistance(P_AproxDistance( + laser.x - dest.x, + laser.y - dest.y), + laser.z - dest.z + ); + fulldist = dist + (laserdist * FRACUNIT); + + lasersteps--; + } + + // Respawning after death: everything about the player + // is invisible + if (!player->respawn.truedeath && lasersteps == 0) // Don't spawn them beyond the respawn point. + { + mobj_t *lasermo = P_SpawnMobj(laser.x, laser.y, laser.z + (player->mo->height / 2), MT_DEZLASER); + + if (lasermo && !P_MobjWasRemoved(lasermo)) + { + P_SetMobjState(lasermo, S_DEZLASER_TRAIL1); + + if (player->mo->eflags & MFE_VERTICALFLIP) + { + lasermo->eflags |= MFE_VERTICALFLIP; + } + + P_SetTarget(&lasermo->target, player->mo); + + lasermo->angle = stepha + ANGLE_90; + P_SetScale(lasermo, (lasermo->destscale = player->mo->scale)); + } + } +} + +/*-------------------------------------------------- + static void K_HandleDropDash(player_t *player) + + Handles the visuals for the waiting period, + before you're allowed to Drop Dash. + + Input Arguments:- + player - Player to preform for. + + Return:- + None +--------------------------------------------------*/ +static void K_DropDashWait(player_t *player) +{ + if (player->nocontrol == 0) + player->respawn.timer--; + + if (leveltime % 8 == 0) + { + const UINT8 ns = 8; + const angle_t sidediff = FixedAngle((360 / ns) * FRACUNIT); + UINT8 i; + + if (!mapreset) + { + S_StartSound(player->mo, sfx_s3kcas); + } + + for (i = 0; i < ns; i++) + { + const angle_t newangle = sidediff * i; + vector3_t spawn; + mobj_t *laser; + + spawn.x = player->mo->x + P_ReturnThrustX(player->mo, newangle, 31 * player->mo->scale); + spawn.y = player->mo->y + P_ReturnThrustY(player->mo, newangle, 31 * player->mo->scale); + + if (player->mo->eflags & MFE_VERTICALFLIP) + { + spawn.z = player->mo->z + player->mo->height; + } + else + { + spawn.z = player->mo->z; + } + + laser = P_SpawnMobj(spawn.x, spawn.y, spawn.z, MT_DEZLASER); + + if (laser && !P_MobjWasRemoved(laser)) + { + if (player->mo->eflags & MFE_VERTICALFLIP) + { + laser->eflags |= MFE_VERTICALFLIP; + } + + P_SetTarget(&laser->target, player->mo); + + laser->angle = newangle + ANGLE_90; + laser->momz = (8 * player->mo->scale) * P_MobjFlip(player->mo); + P_SetScale(laser, (laser->destscale = player->mo->scale)); + } + } + } +} + + +/*-------------------------------------------------- + static void K_HandleDropDash(player_t *player) + + Handles input for the Drop Dash maneuver. + + Input Arguments:- + player - Player to preform for. + + Return:- + None +--------------------------------------------------*/ +static void K_HandleDropDash(player_t *player) +{ + const UINT16 buttons = K_GetKartButtons(player); + + if (player->growshrinktimer < 0) + { + player->mo->scalespeed = mapobjectscale/TICRATE; + player->mo->destscale = FixedMul(mapobjectscale, SHRINK_SCALE); + + if (K_PlayerShrinkCheat(player) == true) + { + player->mo->destscale = FixedMul(player->mo->destscale, SHRINK_SCALE); + } + } + + if (!P_IsObjectOnGround(player->mo)) + { + if (mapreset) + { + return; + } + + player->flashing = K_GetKartFlashing(player); + + // The old behavior was stupid and prone to accidental usage. + // Let's rip off Mania instead, and turn this into a Drop Dash! + + if ((buttons & BT_ACCELERATE) && !player->spinouttimer) // Since we're letting players spin out on respawn, don't let them charge a dropdash in this state. (It wouldn't work anyway) + { + player->respawn.dropdash++; + } + else + { + player->respawn.dropdash = 0; + } + + if (player->respawn.dropdash == TICRATE/4) + { + S_StartSound(player->mo, sfx_ddash); + } + + if ((player->respawn.dropdash >= TICRATE/4) && (player->respawn.dropdash & 1)) + { + player->mo->colorized = true; + } + else + { + player->mo->colorized = false; + } + } + else + { + if ((buttons & BT_ACCELERATE) && (player->respawn.dropdash >= TICRATE/4)) + { + S_StartSound(player->mo, sfx_s23c); + player->startboost = 50; + K_SpawnDashDustRelease(player); + } + + player->mo->colorized = false; + player->respawn.dropdash = 0; + + //P_PlayRinglossSound(player->mo); + P_PlayerRingBurst(player, 3); + + player->respawn.state = RESPAWNST_NONE; + } +} + +/*-------------------------------------------------- + void K_RespawnChecker(player_t *player) + + See header file for description. +--------------------------------------------------*/ +void K_RespawnChecker(player_t *player) +{ + if (player->respawn.state == RESPAWNST_NONE) + { + return; + } + + if (player->spectator) + { + player->respawn.state = RESPAWNST_NONE; + return; + } + + switch (player->respawn.state) + { + case RESPAWNST_MOVE: + player->mo->momx = player->mo->momy = player->mo->momz = 0; + K_MovePlayerToRespawnPoint(player); + return; + case RESPAWNST_DROP: + player->mo->momx = player->mo->momy = 0; + if (player->respawn.timer > 0) + { + player->mo->momz = 0; + K_DropDashWait(player); + } + else + { + K_HandleDropDash(player); + } + return; + default: + player->respawn.state = RESPAWNST_NONE; + return; + } +} diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 4e34aef42..1dafe61e7 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -1521,6 +1521,46 @@ static int lib_pMoveOrigin(lua_State *L) return 2; } +static int lib_pSetAngle(lua_State *L) +{ + mobj_t *thing = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ)); + angle_t newValue = luaL_checkangle(L, 2); + NOHUD + INLEVEL + + if (!thing) + return LUA_ErrInvalid(L, "mobj_t"); + //P_SetAngle(thing, newValue); + thing->angle = thing->old_angle = newValue; + return 0; +} + +static int lib_pSetPitch(lua_State *L) +{ + mobj_t *thing = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ)); + angle_t newValue = luaL_checkangle(L, 2); + NOHUD + INLEVEL + if (!thing) + return LUA_ErrInvalid(L, "mobj_t"); + //P_SetPitch(thing, newValue); + thing->pitch = thing->old_pitch = newValue; + return 0; +} + +static int lib_pSetRoll(lua_State *L) +{ + mobj_t *thing = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ)); + angle_t newValue = luaL_checkangle(L, 2); + NOHUD + INLEVEL + if (!thing) + return LUA_ErrInvalid(L, "mobj_t"); + //P_SetRoll(thing, newValue); + thing->roll = thing->old_roll = newValue; + return 0; +} + static int lib_pSlideMove(lua_State *L) { mobj_t *mo = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ)); @@ -3930,6 +3970,9 @@ static luaL_Reg lib[] = { {"P_TeleportMove",lib_pTeleportMove}, {"P_SetOrigin",lib_pSetOrigin}, {"P_MoveOrigin",lib_pMoveOrigin}, + {"P_SetAngle", lib_pSetAngle}, + {"P_SetPitch", lib_pSetPitch}, + {"P_SetRoll", lib_pSetRoll}, {"P_SlideMove",lib_pSlideMove}, {"P_BounceMove",lib_pBounceMove}, {"P_CheckSight", lib_pCheckSight}, diff --git a/src/p_enemy.c b/src/p_enemy.c index c5cd81b14..d64e0859a 100644 --- a/src/p_enemy.c +++ b/src/p_enemy.c @@ -1221,7 +1221,7 @@ void A_StatueBurst(mobj_t *actor) if (!locvar1 || !(new = P_SpawnMobjFromMobj(actor, 0, 0, 0, locvar1))) return; - P_InitAngle(new, actor->angle); + new->angle = actor->angle; P_SetTarget(&new->target, actor->target); if (locvar2) P_SetMobjState(new, (statenum_t)locvar2); @@ -2504,7 +2504,7 @@ void A_LobShot(mobj_t *actor) P_SetTarget(&shot->target, actor); // where it came from - P_InitAngle(shot, actor->angle); + shot->angle = actor->angle; an = actor->angle >> ANGLETOFINESHIFT; dist = P_AproxDistance(actor->target->x - shot->x, actor->target->y - shot->y); @@ -2871,7 +2871,7 @@ void A_Boss1Laser(mobj_t *actor) S_StartSound(actor, mobjinfo[locvar1].seesound); point = P_SpawnMobj(x + P_ReturnThrustX(actor, actor->angle, actor->radius), y + P_ReturnThrustY(actor, actor->angle, actor->radius), actor->z - actor->height / 2, MT_EGGMOBILE_TARGET); - P_InitAngle(point, actor->angle); + point->angle = actor->angle; point->fuse = dur+1; P_SetTarget(&point->target, actor->target); P_SetTarget(&actor->target, point); @@ -2881,7 +2881,7 @@ void A_Boss1Laser(mobj_t *actor) point = P_SpawnMobj(x, y, z, locvar1); P_SetTarget(&point->target, actor); - P_InitAngle(point, actor->angle); + point->angle = actor->angle; speed = point->radius; point->momz = FixedMul(FINECOSINE(angle>>ANGLETOFINESHIFT), speed); point->momx = FixedMul(FINESINE(angle>>ANGLETOFINESHIFT), FixedMul(FINECOSINE(point->angle>>ANGLETOFINESHIFT), speed)); @@ -2890,7 +2890,7 @@ void A_Boss1Laser(mobj_t *actor) for (i = 0; i < 256; i++) { mobj_t *mo = P_SpawnMobj(point->x, point->y, point->z, point->type); - P_InitAngle(mo, point->angle); + mo->angle = point->angle; mo->color = LASERCOLORS[((UINT8)(i + 3*dur) >> 2) % sizeof(LASERCOLORS)]; // codeing P_UnsetThingPosition(mo); mo->flags = MF_NOCLIP|MF_NOCLIPHEIGHT|MF_NOGRAVITY|MF_SCENERY; @@ -2922,7 +2922,7 @@ void A_Boss1Laser(mobj_t *actor) if (z - floorz < mobjinfo[MT_EGGMOBILE_FIRE].height>>1 && dur & 1) { point = P_SpawnMobj(x, y, floorz, MT_EGGMOBILE_FIRE); - P_InitAngle(point, actor->angle); + point->angle = actor->angle; point->destscale = actor->scale; P_SetScale(point, point->destscale); P_SetTarget(&point->target, actor); @@ -3831,7 +3831,7 @@ void A_AttractChase(mobj_t *actor) sparkle = P_SpawnMobj(actor->target->x, actor->target->y, actor->target->z, MT_RINGSPARKS); P_SetTarget(&sparkle->target, actor->target); - P_InitAngle(sparkle, (actor->target->angle + (offset>>1)) + (offset * actor->target->player->sparkleanim)); + sparkle->angle = (actor->target->angle + (offset>>1)) + (offset * actor->target->player->sparkleanim); actor->target->player->sparkleanim = (actor->target->player->sparkleanim+1) % 20; P_KillMobj(actor, actor->target, actor->target, DMG_NORMAL); @@ -6879,7 +6879,7 @@ void A_Boss3ShockThink(mobj_t *actor) snew->momx = (actor->momx + snext->momx) >> 1; snew->momy = (actor->momy + snext->momy) >> 1; snew->momz = (actor->momz + snext->momz) >> 1; // is this really needed? - P_InitAngle(snew, (actor->angle + snext->angle) >> 1); + snew->angle = (actor->angle + snext->angle) >> 1; P_SetTarget(&snew->target, actor->target); snew->fuse = actor->fuse; @@ -7065,7 +7065,7 @@ void A_SpawnObjectAbsolute(mobj_t *actor) mo = P_SpawnMobj(x<angle); + mo->angle = actor->angle; if (actor->eflags & MFE_VERTICALFLIP) mo->flags2 |= MF2_OBJECTFLIP; @@ -7107,7 +7107,7 @@ void A_SpawnObjectRelative(mobj_t *actor) (actor->eflags & MFE_VERTICALFLIP) ? ((actor->z + actor->height - mobjinfo[type].height) - FixedMul(z<scale)) : (actor->z + FixedMul(z<scale)), type); // Spawn objects with an angle matching the spawner's, rather than spawning Eastwards - Monster Iestyn - P_InitAngle(mo, actor->angle); + mo->angle = actor->angle; if (actor->eflags & MFE_VERTICALFLIP) mo->flags2 |= MF2_OBJECTFLIP; @@ -7817,7 +7817,7 @@ void A_BossJetFume(mobj_t *actor) P_SetScale(filler, filler->destscale); if (actor->eflags & MFE_VERTICALFLIP) filler->flags2 |= MF2_OBJECTFLIP; - P_InitAngle(filler, actor->angle - ANGLE_180); + filler->angle = actor->angle - ANGLE_180; P_SetTarget(&actor->tracer, filler); }*/ @@ -9571,7 +9571,7 @@ void A_TrapShot(mobj_t *actor) S_StartSound(missile, missile->info->seesound); P_SetTarget(&missile->target, actor); - P_InitAngle(missile, actor->angle); + missile->angle = actor->angle; speed = FixedMul(missile->info->speed, missile->scale); @@ -10148,7 +10148,7 @@ void A_BrakLobShot(mobj_t *actor) S_StartSound(shot, shot->info->seesound); P_SetTarget(&shot->target, actor); // where it came from - P_InitAngle(shot, actor->angle); + shot->angle = actor->angle; // Horizontal axes first. First parameter is initial horizontal impulse, second is to correct its angle. shot->momx = FixedMul(FixedMul(v, FINECOSINE(theta >> ANGLETOFINESHIFT)), FINECOSINE(shot->angle >> ANGLETOFINESHIFT)); @@ -10215,7 +10215,7 @@ void A_NapalmScatter(mobj_t *actor) mo = P_SpawnMobj(actor->x, actor->y, actor->z, typeOfShot); P_SetTarget(&mo->target, actor->target); // Transfer target so Brak doesn't hit himself like an idiot - P_InitAngle(mo, fa << ANGLETOFINESHIFT); + mo->angle = fa << ANGLETOFINESHIFT; mo->momx = FixedMul(FINECOSINE(fa),vx); mo->momy = FixedMul(FINESINE(fa),vx); mo->momz = vy; @@ -10239,7 +10239,7 @@ void A_SpawnFreshCopy(mobj_t *actor) newObject = P_SpawnMobjFromMobj(actor, 0, 0, 0, actor->type); newObject->flags2 = actor->flags2 & MF2_AMBUSH; - P_InitAngle(newObject, actor->angle); + newObject->angle = actor->angle; newObject->color = actor->color; P_SetTarget(&newObject->target, actor->target); P_SetTarget(&newObject->tracer, actor->tracer); @@ -10275,7 +10275,7 @@ mobj_t *P_InternalFlickySpawn(mobj_t *actor, mobjtype_t flickytype, fixed_t momz } flicky = P_SpawnMobjFromMobj(actor, offsx, offsy, 0, flickytype); - P_InitAngle(flicky, actor->angle); + flicky->angle = actor->angle; if (flickytype == MT_SEED) flicky->z += P_MobjFlip(actor)*(actor->height - flicky->height)/2; @@ -10427,7 +10427,7 @@ void A_FlickyCenter(mobj_t *actor) else if (actor->flags & MF_SLIDEME) // aimless { actor->tracer->fuse = 0; // less than 2*TICRATE means move aimlessly. - P_InitAngle(actor->tracer, P_RandomKey(180)*ANG2); + actor->tracer->angle = P_RandomKey(180)*ANG2; } else //orbit actor->tracer->fuse = FRACUNIT; @@ -11128,7 +11128,7 @@ void A_ConnectToGround(mobj_t *actor) { work = P_SpawnMobjFromMobj(actor, 0, 0, workz, locvar1); if (work) - P_InitAngle(work, ang); + work->angle = ang; ang += ANGLE_90; workz += workh; } @@ -11174,7 +11174,7 @@ void A_SpawnParticleRelative(mobj_t *actor) (actor->eflags & MFE_VERTICALFLIP) ? ((actor->z + actor->height - mobjinfo[MT_PARTICLE].height) - FixedMul(z<scale)) : (actor->z + FixedMul(z<scale)), MT_PARTICLE); // Spawn objects with an angle matching the spawner's, rather than spawning Eastwards - Monster Iestyn - P_InitAngle(mo, actor->angle); + mo->angle = actor->angle; if (actor->eflags & MFE_VERTICALFLIP) mo->flags2 |= MF2_OBJECTFLIP; @@ -11893,7 +11893,7 @@ void A_Boss5MakeJunk(mobj_t *actor) broked->fuse = TICRATE; else broked->fuse = (((locvar2 & 1) ? 4 : 2)*TICRATE)/3; - P_InitAngle(broked, ang); + broked->angle = ang; P_InstaThrust(broked, ang, ((locvar2 & 2) ? 8 : 5)*actor->scale); P_SetObjectMomZ(broked, (((locvar2) ? 4 : 0) + P_RandomRange(2, 5))< 0) @@ -11972,7 +11972,7 @@ static void P_DustRing(mobjtype_t mobjtype, UINT32 div, fixed_t x, fixed_t y, fi mobjtype ); - P_InitAngle(dust, ang*i + ANGLE_90); + dust->angle = ang*i + ANGLE_90; P_SetScale(dust, FixedMul(initscale, scale)); dust->destscale = FixedMul(4*FRACUNIT + P_RandomFixed(), scale); dust->scalespeed = scale/24; @@ -12177,7 +12177,7 @@ static mobj_t *P_TrainSeg(mobj_t *src, fixed_t x, fixed_t y, fixed_t z, angle_t s->fuse = 16*TICRATE; s->sprite = spr; s->frame = frame|FF_PAPERSPRITE; - P_InitAngle(s, ang); + s->angle = ang; P_Thrust(s, src->angle, 7*FRACUNIT); return s; } @@ -12549,7 +12549,7 @@ void A_SaloonDoorSpawn(mobj_t *actor) // One door... if (!(door = P_SpawnMobjFromMobj(actor, c, s, 0, locvar1))) return; - P_InitAngle(door, ang + ANGLE_180); + door->angle = ang + ANGLE_180; door->extravalue1 = AngleFixed(door->angle); // Origin angle door->extravalue2 = 0; // Angular speed P_SetTarget(&door->tracer, actor); // Origin door @@ -12557,7 +12557,7 @@ void A_SaloonDoorSpawn(mobj_t *actor) // ...two door! if (!(door = P_SpawnMobjFromMobj(actor, -c, -s, 0, locvar1))) return; - P_InitAngle(door, ang); + door->angle = ang; door->extravalue1 = AngleFixed(door->angle); // Origin angle door->extravalue2 = 0; // Angular speed P_SetTarget(&door->tracer, actor); // Origin door @@ -12753,7 +12753,7 @@ void A_SpawnPterabytes(mobj_t *actor) c = FINECOSINE(fa); s = FINESINE(fa); waypoint = P_SpawnMobjFromMobj(actor, FixedMul(c, rad), FixedMul(s, rad), 0, MT_PTERABYTEWAYPOINT); - P_InitAngle(waypoint, ang + ANGLE_90); + waypoint->angle = ang + ANGLE_90; P_SetTarget(&waypoint->tracer, actor); ptera = P_SpawnMobjFromMobj(waypoint, 0, 0, 0, MT_PTERABYTE); ptera->angle = waypoint->angle; @@ -12927,7 +12927,7 @@ void A_DragonbomberSpawn(mobj_t *actor) segment = P_SpawnMobjFromMobj(mo, x, y, 0, MT_DRAGONTAIL); P_SetTarget(&segment->target, mo); P_SetTarget(&mo->tracer, segment); - P_InitAngle(segment, mo->angle); + segment->angle = mo->angle; mo = segment; } for (i = 0; i < 2; i++) // spawn wings @@ -13314,7 +13314,6 @@ static void SpawnSPBTrailRings(mobj_t *actor) } } - void A_SPBChase(mobj_t *actor) { player_t *player = NULL; @@ -13782,7 +13781,7 @@ void A_RandomShadowFrame(mobj_t *actor) P_SetScale(fake, FRACUNIT*3/2); fake->scale = FRACUNIT*3/2; fake->destscale = FRACUNIT*3/2; - P_InitAngle(fake, actor->angle); + fake->angle = actor->angle; fake->tics = -1; actor->renderflags |= RF_DONTDRAW; actor->extravalue1 = 1; @@ -14171,8 +14170,6 @@ void A_FlameShieldPaper(mobj_t *actor) paper->frame |= framea; } - P_InitAngle(paper, paper->angle); - paper->extravalue1 = i; } } diff --git a/src/p_inter.c b/src/p_inter.c index a99a1aa02..d2f66482f 100644 --- a/src/p_inter.c +++ b/src/p_inter.c @@ -1257,7 +1257,7 @@ void P_KillMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source, UINT8 damaget mo->angle = FixedAngle((P_RandomKey(36)*10)<angle); + mo2->angle = mo->angle; P_SetMobjState(mo2, S_BOSSSEBH2); if (++i == 2) // we've already removed 2 of these, let's stop now @@ -1372,7 +1372,7 @@ void P_KillMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source, UINT8 damaget tire = P_SpawnMobjFromMobj(kart, 0, 0, 0, MT_KART_TIRE); tire->fuse = 2*TICRATE; - P_InitAngle(tire, tireAngle); + tire->angle = tireAngle; P_InstaThrust(tire, tireAngle, 3 * tire->scale); P_SetObjectMomZ(tire, 10*FRACUNIT, false); @@ -1428,7 +1428,7 @@ void P_KillMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source, UINT8 damaget for (i = 0; i < 2; i++) { mobj_t *blast = P_SpawnMobjFromMobj(target, 0, 0, target->info->height >> 1, MT_BATTLEBUMPER_BLAST); - P_InitAngle(blast, angle + i*ANGLE_90); + blast->angle = angle + i*ANGLE_90; P_SetScale(blast, 2*blast->scale/3); blast->destscale = 2*blast->scale; } @@ -1706,7 +1706,7 @@ void P_KillMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source, UINT8 damaget chunk = P_SpawnMobjFromMobj(target, 0, 0, 0, MT_SPIKE);\ P_SetMobjState(chunk, target->info->xdeathstate);\ chunk->health = 0;\ - P_InitAngle(chunk, angtweak);\ + chunk->angle = angtweak;\ P_UnsetThingPosition(chunk);\ chunk->flags = MF_NOCLIP;\ chunk->x += xmov;\ @@ -1728,7 +1728,7 @@ void P_KillMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source, UINT8 damaget chunk = P_SpawnMobjFromMobj(target, 0, 0, 0, MT_SPIKE); P_SetMobjState(chunk, target->info->deathstate); chunk->health = 0; - P_InitAngle(chunk, ang + ANGLE_180); + chunk->angle = ang + ANGLE_180; P_UnsetThingPosition(chunk); chunk->flags = MF_NOCLIP; chunk->x -= xoffs; @@ -1774,7 +1774,7 @@ void P_KillMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source, UINT8 damaget chunk = P_SpawnMobjFromMobj(target, 0, 0, 0, MT_WALLSPIKE);\ P_SetMobjState(chunk, target->info->xdeathstate);\ chunk->health = 0;\ - P_InitAngle(chunk, target->angle);\ + chunk->angle = target->angle;\ P_UnsetThingPosition(chunk);\ chunk->flags = MF_NOCLIP;\ chunk->x += xmov - forwardxoffs;\ @@ -1800,7 +1800,7 @@ void P_KillMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source, UINT8 damaget P_SetMobjState(chunk, target->info->deathstate); chunk->health = 0; - P_InitAngle(chunk, target->angle); + chunk->angle = target->angle; P_UnsetThingPosition(chunk); chunk->flags = MF_NOCLIP; chunk->x += forwardxoffs - xoffs; @@ -1925,7 +1925,7 @@ static boolean P_KillPlayer(player_t *player, mobj_t *inflictor, mobj_t *source, boom = P_SpawnMobj(player->mo->x, player->mo->y, player->mo->z, MT_FZEROBOOM); boom->scale = player->mo->scale; - P_InitAngle(boom, player->mo->angle); + boom->angle = player->mo->angle; P_SetTarget(&boom->target, player->mo); } diff --git a/src/p_local.h b/src/p_local.h index 8e94c61c5..06cc603c4 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -424,9 +424,6 @@ boolean P_TryMove(mobj_t *thing, fixed_t x, fixed_t y, boolean allowdropoff); boolean P_Move(mobj_t *actor, fixed_t speed); boolean P_SetOrigin(mobj_t *thing, fixed_t x, fixed_t y, fixed_t z); boolean P_MoveOrigin(mobj_t *thing, fixed_t x, fixed_t y, fixed_t z); -void P_InitAngle(mobj_t *thing, angle_t newValue); -void P_InitPitch(mobj_t *thing, angle_t newValue); -void P_InitRoll(mobj_t *thing, angle_t newValue); void P_SlideMove(mobj_t *mo); void P_BouncePlayerMove(mobj_t *mo); void P_BounceMove(mobj_t *mo); diff --git a/src/p_map.c b/src/p_map.c index df881a947..1d850d9e8 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -157,31 +157,6 @@ boolean P_MoveOrigin(mobj_t *thing, fixed_t x, fixed_t y, fixed_t z) return P_TeleportMove(thing, x, y, z); } -// -// P_InitAngle - Change an object's angle, including interp values. -// -void P_InitAngle(mobj_t *thing, angle_t newValue) -{ - thing->angle = thing->old_angle = newValue; -} - -// -// P_InitPitch - Change an object's pitch, including interp values. -// -void P_InitPitch(mobj_t *thing, angle_t newValue) -{ - thing->pitch = thing->old_pitch = newValue; -} - -// -// P_InitRoll - Change an object's roll, including interp values. -// -void P_InitRoll(mobj_t *thing, angle_t newValue) -{ - thing->roll = thing->old_roll = newValue; -} - - // ========================================================================= // MOVEMENT ITERATOR FUNCTIONS // ========================================================================= diff --git a/src/p_mobj.c b/src/p_mobj.c index 12cc18288..6f5930945 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -4228,7 +4228,7 @@ static void P_SpawnItemCapsuleParts(mobj_t *mobj) part = part->hnext; P_SetTarget(&part->target, mobj); P_SetMobjState(part, buttState); - P_InitAngle(part, i * ANG_CAPSULE); + part->angle = i * ANG_CAPSULE; part->movedir = spin; // rotation speed part->movefactor = 0; // z offset part->extravalue1 = buttScale; // relative scale @@ -4239,7 +4239,7 @@ static void P_SpawnItemCapsuleParts(mobj_t *mobj) part = part->hnext; P_SetTarget(&part->target, mobj); P_SetMobjState(part, S_ITEMCAPSULE_TOP_SIDE); - P_InitAngle(part, i * ANG_CAPSULE); + part->angle = i * ANG_CAPSULE; part->movedir = spin; // rotation speed part->movefactor = mobj->info->height - part->info->height; // z offset } @@ -4567,7 +4567,7 @@ void P_SpawnParaloop(fixed_t x, fixed_t y, fixed_t z, fixed_t radius, INT32 numb mobj->z -= mobj->height>>1; // change angle - P_InitAngle(mobj, R_PointToAngle2(mobj->x, mobj->y, x, y)); + mobj->angle = R_PointToAngle2(mobj->x, mobj->y, x, y); // change slope dist = P_AproxDistance(P_AproxDistance(x - mobj->x, y - mobj->y), z - mobj->z); @@ -5314,7 +5314,7 @@ static void P_FlameJetSceneryThink(mobj_t *mobj) flame = P_SpawnMobj(mobj->x, mobj->y, mobj->z, MT_FLAMEJETFLAME); P_SetMobjState(flame, S_FLAMEJETFLAME4); - P_InitAngle(flame, mobj->angle); + flame->angle = mobj->angle; if (mobj->flags2 & MF2_AMBUSH) // Wave up and down instead of side-to-side flame->momz = mobj->fuse << (FRACBITS - 2); @@ -5801,7 +5801,7 @@ static void P_MobjSceneryThink(mobj_t *mobj) blast->angle += ANGLE_90; S_StartSound(blast, sfx_cdfm64); } - P_InitAngle(blast, blast->angle); + blast->angle = blast->angle; blast->destscale *= 4; } @@ -5946,7 +5946,7 @@ static void P_MobjSceneryThink(mobj_t *mobj) mobj->x = mobj->target->x; mobj->y = mobj->target->y; - P_InitAngle (mobj, R_PointToAngle(mobj->x, mobj->y) + ANGLE_90); // literally only happened because i wanted to ^L^R the SPR_ITEM's + mobj->angle = R_PointToAngle(mobj->x, mobj->y) + ANGLE_90; // literally only happened because i wanted to ^L^R the SPR_ITEM's if (!r_splitscreen && players[displayplayers[0]].mo) { @@ -7599,7 +7599,7 @@ static boolean P_MobjRegularThink(mobj_t *mobj) mobj->z + (mobj->height/2) + (P_RandomRange(-20,20) * mobj->scale), MT_FASTLINE); - P_InitAngle(fast, mobj->angle); + fast->angle = mobj->angle; fast->momx = 3*mobj->target->momx/4; fast->momy = 3*mobj->target->momy/4; fast->momz = 3*P_GetMobjZMovement(mobj->target)/4; @@ -7661,7 +7661,7 @@ static boolean P_MobjRegularThink(mobj_t *mobj) if (underlayst != S_NULL) { mobj_t *underlay = P_SpawnMobj(mobj->target->x, mobj->target->y, mobj->target->z, MT_FLAMESHIELDUNDERLAY); - P_InitAngle(underlay, mobj->angle); + underlay->angle = mobj->angle; P_SetMobjState(underlay, underlayst); } break; @@ -8924,7 +8924,7 @@ static boolean P_FuseThink(mobj_t *mobj) for (i = 0; i < 5; i++) { mobj_t *debris = P_SpawnMobj(mobj->x, mobj->y, mobj->z, MT_SMK_ICEBLOCK_DEBRIS); - P_InitAngle(debris, FixedAngle(P_RandomRange(0,360)<angle = FixedAngle(P_RandomRange(0,360)<angle, P_RandomRange(3,18)*(FRACUNIT/4)); debris->momz = P_RandomRange(4,8)<angle + ((mobj->flags2 & MF2_AMBUSH) ? ANGLE_90 : ANGLE_270)); + bigmeatyclaw->angle = mobj->angle + ((mobj->flags2 & MF2_AMBUSH) ? ANGLE_90 : ANGLE_270); P_SetTarget(&mobj->tracer, bigmeatyclaw); P_SetTarget(&bigmeatyclaw->tracer, mobj); mobj->reactiontime >>= 1; @@ -9707,7 +9707,7 @@ mobj_t *P_SpawnMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type) case MT_BANPYURA: { mobj_t *bigmeatyclaw = P_SpawnMobjFromMobj(mobj, 0, 0, 0, MT_BANPSPRING); - P_InitAngle(bigmeatyclaw, mobj->angle + ((mobj->flags2 & MF2_AMBUSH) ? ANGLE_90 : ANGLE_270)); + bigmeatyclaw->angle = mobj->angle + ((mobj->flags2 & MF2_AMBUSH) ? ANGLE_90 : ANGLE_270); P_SetTarget(&mobj->tracer, bigmeatyclaw); P_SetTarget(&bigmeatyclaw->tracer, mobj); mobj->reactiontime >>= 1; @@ -9843,7 +9843,7 @@ mobj_t *P_SpawnMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type) break; case MT_MINECARTEND: P_SetTarget(&mobj->tracer, P_SpawnMobjFromMobj(mobj, 0, 0, 0, MT_MINECARTENDSOLID)); - P_InitAngle(mobj->tracer, mobj->angle + ANGLE_90); + mobj->tracer->angle = mobj->angle + ANGLE_90; break; case MT_TORCHFLOWER: { @@ -9965,8 +9965,8 @@ mobj_t *P_SpawnMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type) angle_t ang = i * diff; mobj_t *side = P_SpawnMobj(mobj->x + FINECOSINE((ang>>ANGLETOFINESHIFT) & FINEMASK), mobj->y + FINESINE((ang>>ANGLETOFINESHIFT) & FINEMASK), mobj->z, MT_DAYTONAPINETREE_SIDE); - P_InitAngle(side, ang); - P_SetTarget(&side->target, mobj); + side->angle = ang; + side->target = mobj; side->threshold = i; } break; @@ -9982,7 +9982,7 @@ mobj_t *P_SpawnMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type) cur = P_SpawnMobj(mobj->x + FINECOSINE(((mobj->angle*8)>>ANGLETOFINESHIFT) & FINEMASK), mobj->y + FINESINE(((mobj->angle*8)>>ANGLETOFINESHIFT) & FINEMASK), mobj->z, MT_EZZPROPELLER_BLADE); - P_InitAngle(cur, mobj->angle); + cur->angle = mobj->angle; P_SetTarget(&cur->hprev, prev); P_SetTarget(&prev->hnext, cur); @@ -10048,7 +10048,7 @@ mobj_t *P_SpawnMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type) cur->threshold = i; P_MoveOrigin(cur, cur->x + ((cur->radius>>FRACBITS) * FINECOSINE((FixedAngle((90*cur->threshold)<>ANGLETOFINESHIFT) & FINEMASK)), cur->y + ((cur->radius>>FRACBITS) * FINESINE((FixedAngle((90*cur->threshold)<>ANGLETOFINESHIFT) & FINEMASK)), cur->z); - P_InitAngle(cur, ANGLE_90*(cur->threshold+1)); + cur->angle = ANGLE_90*(cur->threshold+1); P_SetTarget(&cur->hprev, prev); P_SetTarget(&prev->hnext, cur); @@ -11585,7 +11585,7 @@ static boolean P_SetupMace(mapthing_t *mthing, mobj_t *mobj, boolean *doangle) spawnee->friction = mroll;\ spawnee->movefactor = mwidthset;\ spawnee->movecount = dist;\ - P_InitAngle(spawnee, myaw);\ + spawnee->angle = myaw;\ spawnee->flags |= (MF_NOGRAVITY|mflagsapply);\ spawnee->flags2 |= (mflags2apply|moreflags2);\ spawnee->eflags |= meflagsapply;\ @@ -11783,29 +11783,29 @@ static boolean P_SetupBooster(mapthing_t* mthing, mobj_t* mobj, boolean strong) statenum_t rollerstate = strong ? S_REDBOOSTERROLLER : S_YELLOWBOOSTERROLLER; mobj_t *seg = P_SpawnMobjFromMobj(mobj, 26*x1, 26*y1, 0, MT_BOOSTERSEG); - P_InitAngle(seg, angle - ANGLE_90); + seg->angle = angle - ANGLE_90; P_SetMobjState(seg, facestate); seg = P_SpawnMobjFromMobj(mobj, -26*x1, -26*y1, 0, MT_BOOSTERSEG); - P_InitAngle(seg, angle + ANGLE_90); + seg->angle = angle + ANGLE_90; P_SetMobjState(seg, facestate); seg = P_SpawnMobjFromMobj(mobj, 21*x2, 21*y2, 0, MT_BOOSTERSEG); - P_InitAngle(seg, angle); + seg->angle = angle; P_SetMobjState(seg, leftstate); seg = P_SpawnMobjFromMobj(mobj, -21*x2, -21*y2, 0, MT_BOOSTERSEG); - P_InitAngle(seg, angle); + seg->angle = angle; P_SetMobjState(seg, rightstate); seg = P_SpawnMobjFromMobj(mobj, 13*(x1 + x2), 13*(y1 + y2), 0, MT_BOOSTERROLLER); - P_InitAngle(seg, angle); + seg->angle = angle; P_SetMobjState(seg, rollerstate); seg = P_SpawnMobjFromMobj(mobj, 13*(x1 - x2), 13*(y1 - y2), 0, MT_BOOSTERROLLER); - P_InitAngle(seg, angle); + seg->angle = angle; P_SetMobjState(seg, rollerstate); seg = P_SpawnMobjFromMobj(mobj, -13*(x1 + x2), -13*(y1 + y2), 0, MT_BOOSTERROLLER); - P_InitAngle(seg, angle); + seg->angle = angle; P_SetMobjState(seg, rollerstate); seg = P_SpawnMobjFromMobj(mobj, -13*(x1 - x2), -13*(y1 - y2), 0, MT_BOOSTERROLLER); - P_InitAngle(seg, angle); + seg->angle = angle; P_SetMobjState(seg, rollerstate); return true; @@ -12009,19 +12009,19 @@ static boolean P_SetupSpawnedMapThing(mapthing_t *mthing, mobj_t *mobj, boolean case MT_THZTREE: { // Spawn the branches angle_t mobjangle = FixedAngle((mthing->angle % 113) << FRACBITS); - P_InitAngle(P_SpawnMobjFromMobj(mobj, FRACUNIT, 0, 0, MT_THZTREEBRANCH), mobjangle + ANGLE_22h); - P_InitAngle(P_SpawnMobjFromMobj(mobj, 0, FRACUNIT, 0, MT_THZTREEBRANCH), mobjangle + ANGLE_157h); - P_InitAngle(P_SpawnMobjFromMobj(mobj, -FRACUNIT, 0, 0, MT_THZTREEBRANCH), mobjangle + ANGLE_270); + P_SpawnMobjFromMobj(mobj, FRACUNIT, 0, 0, MT_THZTREEBRANCH)->angle = mobjangle + ANGLE_22h; + P_SpawnMobjFromMobj(mobj, 0, FRACUNIT, 0, MT_THZTREEBRANCH)->angle = mobjangle + ANGLE_157h; + P_SpawnMobjFromMobj(mobj, -FRACUNIT, 0, 0, MT_THZTREEBRANCH)->angle = mobjangle + ANGLE_270; } break; case MT_CEZPOLE1: case MT_CEZPOLE2: { // Spawn the banner angle_t mobjangle = FixedAngle(mthing->angle << FRACBITS); - P_InitAngle(P_SpawnMobjFromMobj(mobj, + P_SpawnMobjFromMobj(mobj, P_ReturnThrustX(mobj, mobjangle, 4 << FRACBITS), P_ReturnThrustY(mobj, mobjangle, 4 << FRACBITS), - 0, ((mobj->type == MT_CEZPOLE1) ? MT_CEZBANNER1 : MT_CEZBANNER2)), mobjangle + ANGLE_90); + 0, ((mobj->type == MT_CEZPOLE1) ? MT_CEZBANNER1 : MT_CEZBANNER2))->angle = mobjangle + ANGLE_90; } break; case MT_HHZTREE_TOP: @@ -12030,7 +12030,7 @@ static boolean P_SetupSpawnedMapThing(mapthing_t *mthing, mobj_t *mobj, boolean mobj_t* leaf; #define doleaf(x, y) \ leaf = P_SpawnMobjFromMobj(mobj, x, y, 0, MT_HHZTREE_PART);\ - P_InitAngle(leaf, mobjangle);\ + leaf->angle = mobjangle;\ P_SetMobjState(leaf, leaf->info->seestate);\ mobjangle += ANGLE_90 doleaf(FRACUNIT, 0); @@ -12054,7 +12054,7 @@ static boolean P_SetupSpawnedMapThing(mapthing_t *mthing, mobj_t *mobj, boolean fixed_t xoffs = FINECOSINE(fa); fixed_t yoffs = FINESINE(fa); mobj_t* leaf = P_SpawnMobjFromMobj(mobj, xoffs, yoffs, 0, MT_BIGFERNLEAF); - P_InitAngle(leaf, angle); + leaf->angle = angle; angle += ANGLE_45; } break; @@ -12136,7 +12136,7 @@ static boolean P_SetupSpawnedMapThing(mapthing_t *mthing, mobj_t *mobj, boolean mobj->x - P_ReturnThrustX(mobj, mobjangle, baseradius), mobj->y - P_ReturnThrustY(mobj, mobjangle, baseradius), mobj->z, MT_WALLSPIKEBASE); - P_InitAngle(base, mobjangle + ANGLE_90); + base->angle = mobjangle + ANGLE_90; base->destscale = mobj->destscale; P_SetScale(base, mobj->scale); P_SetTarget(&base->target, mobj); @@ -12347,7 +12347,7 @@ static boolean P_SetupSpawnedMapThing(mapthing_t *mthing, mobj_t *mobj, boolean leaf = P_SpawnMobj(mobj->x + FINECOSINE((mobj->angle>>ANGLETOFINESHIFT) & FINEMASK), mobj->y + FINESINE((mobj->angle>>ANGLETOFINESHIFT) & FINEMASK), top, MT_AAZTREE_LEAF); - P_InitAngle(leaf, mobj->angle); + leaf->angle = mobj->angle; // Small coconut for each leaf P_SpawnMobj(mobj->x + (32 * FINECOSINE((mobj->angle>>ANGLETOFINESHIFT) & FINEMASK)), @@ -12512,7 +12512,7 @@ static mobj_t *P_SpawnMobjFromMapThing(mapthing_t *mthing, fixed_t x, fixed_t y, if (doangle) { - P_InitAngle(mobj, FixedAngle(mthing->angle << FRACBITS)); + mobj->angle = FixedAngle(mthing->angle << FRACBITS); } if ((mobj->flags & MF_SPRING) @@ -12525,8 +12525,8 @@ static mobj_t *P_SpawnMobjFromMapThing(mapthing_t *mthing, fixed_t x, fixed_t y, mobj->spryoff = FixedMul(mobj->radius, FINESINE(a >> ANGLETOFINESHIFT)); } - P_InitPitch(mobj, FixedAngle(mthing->pitch << FRACBITS)); - P_InitRoll(mobj, FixedAngle(mthing->roll << FRACBITS)); + mobj->pitch = FixedAngle(mthing->pitch << FRACBITS); + mobj->roll = FixedAngle(mthing->roll << FRACBITS); P_SetThingTID(mobj, Tag_FGet(&mthing->tags)); @@ -12945,7 +12945,7 @@ mobj_t *P_SpawnXYZMissile(mobj_t *source, mobj_t *dest, mobjtype_t type, P_SetTarget(&th->target, source); // where it came from an = R_PointToAngle2(x, y, dest->x, dest->y); - P_InitAngle(th, an); + th->angle = an; an >>= ANGLETOFINESHIFT; th->momx = FixedMul(speed, FINECOSINE(an)); th->momy = FixedMul(speed, FINESINE(an)); @@ -13007,7 +13007,7 @@ mobj_t *P_SpawnAlteredDirectionMissile(mobj_t *source, mobjtype_t type, fixed_t P_SetTarget(&th->target, source->target); // where it came from an = R_PointToAngle2(0, 0, source->momx, source->momy) + (ANG1*shiftingAngle); - P_InitAngle(th, an); + th->angle = an; an >>= ANGLETOFINESHIFT; th->momx = FixedMul(speed, FINECOSINE(an)); th->momy = FixedMul(speed, FINESINE(an)); @@ -13072,7 +13072,7 @@ mobj_t *P_SpawnPointMissile(mobj_t *source, fixed_t xa, fixed_t ya, fixed_t za, P_SetTarget(&th->target, source); // where it came from an = R_PointToAngle2(x, y, xa, ya); - P_InitAngle(th, an); + th->angle = an; an >>= ANGLETOFINESHIFT; th->momx = FixedMul(speed, FINECOSINE(an)); th->momy = FixedMul(speed, FINESINE(an)); @@ -13151,7 +13151,7 @@ mobj_t *P_SpawnMissile(mobj_t *source, mobj_t *dest, mobjtype_t type) else an = R_PointToAngle2(source->x, source->y, dest->x, dest->y); - P_InitAngle(th, an); + th->angle = an; an >>= ANGLETOFINESHIFT; th->momx = FixedMul(speed, FINECOSINE(an)); th->momy = FixedMul(speed, FINESINE(an)); @@ -13239,7 +13239,7 @@ mobj_t *P_SPMAngle(mobj_t *source, mobjtype_t type, angle_t angle, UINT8 allowai speed = th->info->speed; - P_InitAngle(th, an); + th->angle = an; th->momx = FixedMul(speed, FINECOSINE(an>>ANGLETOFINESHIFT)); th->momy = FixedMul(speed, FINESINE(an>>ANGLETOFINESHIFT)); diff --git a/src/p_telept.c b/src/p_telept.c index 1d33625c2..73cfb4bcd 100644 --- a/src/p_telept.c +++ b/src/p_telept.c @@ -98,7 +98,8 @@ void P_MixUp(mobj_t *thing, fixed_t x, fixed_t y, fixed_t z, angle_t angle, P_FlashPal(thing->player, PAL_MIXUP, 10); } - P_InitAngle(thing, angle); + thing->old_angle += (angle-thing->angle); + thing->angle = angle; thing->momx = thing->momy = thing->momz = 0; diff --git a/src/p_user.c b/src/p_user.c index a57782bc5..a5e4ee30f 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -387,7 +387,7 @@ void P_GiveFinishFlags(player_t *player) fixed_t xoffs = FINECOSINE(fa); fixed_t yoffs = FINESINE(fa); mobj_t* flag = P_SpawnMobjFromMobj(player->mo, xoffs, yoffs, 0, MT_FINISHFLAG); - P_InitAngle(flag, angle); + flag->angle = angle; angle += FixedAngle(120*FRACUNIT); P_SetTarget(&flag->target, player->mo); @@ -2273,7 +2273,7 @@ void P_MovePlayer(player_t *player) // underlay water = P_SpawnMobj(x1, y1, ((player->mo->eflags & MFE_VERTICALFLIP) ? player->mo->waterbottom - FixedMul(mobjinfo[MT_WATERTRAILUNDERLAY].height, player->mo->scale) : player->mo->watertop), MT_WATERTRAILUNDERLAY); - P_InitAngle(water, forwardangle - ANGLE_180 - ANGLE_22h); + water->angle = forwardangle - ANGLE_180 - ANGLE_22h; water->destscale = trailScale; water->momx = player->mo->momx; water->momy = player->mo->momy; @@ -2284,7 +2284,7 @@ void P_MovePlayer(player_t *player) // overlay water = P_SpawnMobj(x1, y1, ((player->mo->eflags & MFE_VERTICALFLIP) ? player->mo->waterbottom - FixedMul(mobjinfo[MT_WATERTRAIL].height, player->mo->scale) : player->mo->watertop), MT_WATERTRAIL); - P_InitAngle(water, forwardangle - ANGLE_180 - ANGLE_22h); + water->angle = forwardangle - ANGLE_180 - ANGLE_22h; water->destscale = trailScale; water->momx = player->mo->momx; water->momy = player->mo->momy; @@ -2296,7 +2296,7 @@ void P_MovePlayer(player_t *player) // Underlay water = P_SpawnMobj(x2, y2, ((player->mo->eflags & MFE_VERTICALFLIP) ? player->mo->waterbottom - FixedMul(mobjinfo[MT_WATERTRAILUNDERLAY].height, player->mo->scale) : player->mo->watertop), MT_WATERTRAILUNDERLAY); - P_InitAngle(water, forwardangle - ANGLE_180 + ANGLE_22h); + water->angle = forwardangle - ANGLE_180 + ANGLE_22h; water->destscale = trailScale; water->momx = player->mo->momx; water->momy = player->mo->momy; @@ -2307,7 +2307,7 @@ void P_MovePlayer(player_t *player) // Overlay water = P_SpawnMobj(x2, y2, ((player->mo->eflags & MFE_VERTICALFLIP) ? player->mo->waterbottom - FixedMul(mobjinfo[MT_WATERTRAIL].height, player->mo->scale) : player->mo->watertop), MT_WATERTRAIL); - P_InitAngle(water, forwardangle - ANGLE_180 + ANGLE_22h); + water->angle = forwardangle - ANGLE_180 + ANGLE_22h; water->destscale = trailScale; water->momx = player->mo->momx; water->momy = player->mo->momy;