From ea8e87117680d3679350730dfc2ec01f52ad3d58 Mon Sep 17 00:00:00 2001 From: Lat Date: Wed, 20 Sep 2023 14:42:39 +0200 Subject: [PATCH] LSZ bungee: first pass --- src/k_kart.c | 7 ++- src/k_objects.h | 3 + src/objects/CMakeLists.txt | 1 + src/objects/bungee.c | 120 +++++++++++++++++++++++++++++++++++++ src/p_inter.c | 4 ++ src/p_saveg.c | 2 +- 6 files changed, 134 insertions(+), 3 deletions(-) create mode 100644 src/objects/bungee.c diff --git a/src/k_kart.c b/src/k_kart.c index e4459385b..d3aaf455b 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -11833,7 +11833,9 @@ void K_MoveKartPlayer(player_t *player, boolean onground) K_KartDrift(player, onground); K_KartSpindash(player); - if (onground == false) + if (onground == false + && !player->bungee // if this list of condition ever gets bigger, maybe this should become a function. + ) { K_AirFailsafe(player); } @@ -11841,8 +11843,9 @@ void K_MoveKartPlayer(player_t *player, boolean onground) { player->pflags &= ~PF_AIRFAILSAFE; } - + Obj_RingShooterInput(player); + Obj_playerBungeeThink(player); } void K_CheckSpectateStatus(boolean considermapreset) diff --git a/src/k_objects.h b/src/k_objects.h index 432063383..6166dc279 100644 --- a/src/k_objects.h +++ b/src/k_objects.h @@ -231,6 +231,9 @@ void Obj_RideroidNodeSpawn(mobj_t *mo); void Obj_RideroidNodeThink(mobj_t *mo); void Obj_getPlayerOffRideroid(mobj_t *mo); // used in p_map.c to get off of em when passing transfer lines. +/* LSZ Bungee */ +void Obj_BungeeSpecial(mobj_t *mo, player_t *p); // used when the player touches the bungee, to be used in p_inter.c +void Obj_playerBungeeThink(player_t *p); // player interaction with the bungee. The bungee is to be stored in p->mo->tracer. #ifdef __cplusplus } // extern "C" diff --git a/src/objects/CMakeLists.txt b/src/objects/CMakeLists.txt index 366a0a0f7..ee7c9df2c 100644 --- a/src/objects/CMakeLists.txt +++ b/src/objects/CMakeLists.txt @@ -30,4 +30,5 @@ target_sources(SRB2SDL2 PRIVATE emerald.c checkpoint.cpp rideroid.c + bungee.c ) diff --git a/src/objects/bungee.c b/src/objects/bungee.c new file mode 100644 index 000000000..1834cadcf --- /dev/null +++ b/src/objects/bungee.c @@ -0,0 +1,120 @@ +// DR. ROBOTNIK'S RING RACERS +//----------------------------------------------------------------------------- +// Copyright (C) 2022 by Sally "TehRealSalt" Cochenour +// Copyright (C) 2022 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 bungee.c +/// \brief Leaf Storm bungee interaction/behaviour code to be used in other files. + +#include "../doomdef.h" +#include "../doomstat.h" +#include "../info.h" +#include "../k_kart.h" +#include "../k_objects.h" +#include "../m_random.h" +#include "../p_local.h" +#include "../r_main.h" +#include "../s_sound.h" +#include "../g_game.h" +#include "../z_zone.h" +#include "../k_waypoint.h" +#include "../k_respawn.h" +#include "../k_collide.h" + +#define BUNGEE_NONE 0 +#define BUNGEE_LATCH 1 +#define BUNGEE_LAUNCH 2 + +// Touching the bungee, used in p_inter.c +void Obj_BungeeSpecial(mobj_t *mo, player_t *p) +{ + + mobj_t *latch; + + if (p->bungee || P_IsObjectOnGround(p->mo) || p->springstars) + return; + + P_InstaThrust(p->mo, 0, 0); + p->bungee = BUNGEE_LATCH; + p->mo->flags |= MF_NOCLIPTHING; // prevent players from bumping if they latch onto the same bungee. + p->pflags |= PF_NOFASTFALL; // didn't know this flag existed but it's very convenient!! + + latch = P_SpawnMobj(p->mo->x, p->mo->y, p->mo->z, MT_THOK); + P_SetMobjState(latch, S_INVISIBLE); + latch->angle = mo->angle; + + S_StartSound(mo, sfx_s3k5a); + P_SetTarget(&p->mo->tracer, latch); + + return; +} + +// this is the thinker to call on the player when they get bungee'd. +void Obj_playerBungeeThink(player_t *p) +{ + + mobj_t *bungee = p->mo->tracer; + UINT8 i; + + // someone removed it + if (!bungee || !P_MobjWasRemoved(bungee)) + return; + + bungee->tics = 4; // we set this to a low value so that it despawns if the player vanishes for some reason. + + if (p->bungee == BUNGEE_LATCH) + { + // rr has super high gravity which gets in the way. + p->mo->flags |= MF_NOGRAVITY; + p->mo->momz = (p->mo->momz*9)/10; + + if (abs(p->mo->momz) < 6*mapobjectscale) + { + p->bungee = BUNGEE_LAUNCH; + p->mo->momz = P_MobjFlip(p->mo)*mapobjectscale; + S_StartSound(p->mo, sfx_s3k81); + } + } + else if (p->bungee == BUNGEE_LAUNCH) + { + p->mo->momz = (p->mo->momz*12)/10; + + // if we go above/below (depending on our flip flags) the bungee, release us! + if ((p->mo->eflags & MFE_VERTICALFLIP && p->mo->z < bungee->z) + || (!(p->mo->eflags & MFE_VERTICALFLIP) && p->mo->z > bungee->z )) + { + + p->mo->flags &= ~MF_NOGRAVITY; + p->mo->flags &= ~MF_NOCLIPTHING; + p->mo->pflags &= ~PF_NOFASTFALL; + p->bungee = BUNGEE_NONE; + P_InstaThrust(p->mo, bungee->angle, p->mo->momz/8); + p->mo->momz = (p->mo->momz*3)/4; + + p->springstars = TICRATE; // these are used as a buffer not to latch to vines again. + p->springcolor = SKINCOLOR_EMERALD; + + P_RemoveMobj(bungee); + P_SetTarget(&p->mo->tracer, NULL); + return; + } + } + + // basic visuals (but hey they work fine enough!) + for (i=0; i<8; i++) + { + fixed_t xpos = -(bungee->x - p->mo->x) /8 *i; + fixed_t ypos = -(bungee->y - p->mo->y) /8 *i; + fixed_t zpos = -(bungee->z - p->mo->z) /8 *i; + + mobj_t *seg = P_SpawnMobj(bungee->x + xpos, bungee->y + ypos, bungee->z + zpos, MT_THOK); + + P_SetScale(seg, mapobjectscale/3); + seg->color = SKINCOLOR_EMERALD; + seg->fuse = 2; + } +} \ No newline at end of file diff --git a/src/p_inter.c b/src/p_inter.c index ffb4cff53..135b5d245 100644 --- a/src/p_inter.c +++ b/src/p_inter.c @@ -757,6 +757,10 @@ void P_TouchSpecialThing(mobj_t *special, mobj_t *toucher, boolean heightcheck) return; } + + case MT_LSZ_BUNGEE: + Obj_BungeeSpecial(special, player); + return; // CTF Flags case MT_REDFLAG: diff --git a/src/p_saveg.c b/src/p_saveg.c index 12ddd959e..e09b3fcf2 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -563,7 +563,7 @@ static void P_NetArchivePlayers(savebuffer_t *save) WRITEFIXED(save->p, players[i].rdaddmomy); WRITEFIXED(save->p, players[i].rdaddmomz); - WRITEUINT8(save->, players[i].bungee); + WRITEUINT8(save->p, players[i].bungee); // respawnvars_t WRITEUINT8(save->p, players[i].respawn.state);