Make respawn function shut up and expose it to lua
This commit is contained in:
parent
df5e3f76c1
commit
24c0d8086a
3 changed files with 45 additions and 20 deletions
29
src/k_kart.c
29
src/k_kart.c
|
|
@ -7453,19 +7453,6 @@ void K_KartPlayerAfterThink(player_t *player)
|
|||
}
|
||||
}
|
||||
|
||||
typedef struct respawnresult_s
|
||||
{
|
||||
sector_t *cursec;
|
||||
fixed_t bestsectorheight;
|
||||
fixed_t bestfofheight;
|
||||
ffloor_t *bestrover;
|
||||
fixed_t bestpoheight;
|
||||
polyobj_t *bestpo;
|
||||
fixed_t finaldistances[3];
|
||||
|
||||
SINT8 result;
|
||||
} respawnresult_t;
|
||||
|
||||
static int clostVal(fixed_t arr[], int N, fixed_t K)
|
||||
{
|
||||
// Stores the closest
|
||||
|
|
@ -7491,7 +7478,7 @@ static int clostVal(fixed_t arr[], int N, fixed_t K)
|
|||
}
|
||||
|
||||
// Decides if respawning at this position is safe, used for nu waypoints.
|
||||
static boolean K_SafeRespawnPosition(mobj_t * mo)
|
||||
boolean K_SafeRespawnPosition(mobj_t * mo)
|
||||
{
|
||||
respawnresult_t result;
|
||||
const boolean flip = (mo->eflags & MFE_VERTICALFLIP) ? true : false;
|
||||
|
|
@ -7502,6 +7489,8 @@ static boolean K_SafeRespawnPosition(mobj_t * mo)
|
|||
result.cursec = R_PointInSubsector(mobjx, mobjy)->sector;
|
||||
result.bestfofheight = INT32_MAX;
|
||||
result.bestpoheight = INT32_MAX;
|
||||
result.bestrover = NULL;
|
||||
result.bestpo = NULL;
|
||||
|
||||
if (!result.cursec) // How tf do you do this?????
|
||||
return false;
|
||||
|
|
@ -7655,16 +7644,16 @@ static boolean K_SafeRespawnPosition(mobj_t * mo)
|
|||
|
||||
fixed_t closetvalue = clostVal(result.finaldistances, N, mobjz);
|
||||
if (closetvalue == result.bestfofheight && (result.bestfofheight != INT32_MAX))
|
||||
result.result = 2;
|
||||
result.result = RESPAWNRS_ROVER;
|
||||
else if (closetvalue == result.bestpoheight && (result.bestpoheight != INT32_MAX))
|
||||
result.result = 3;
|
||||
result.result = RESPAWNRS_PO;
|
||||
else
|
||||
result.result = 1;
|
||||
result.result = RESPAWNRS_SECTOR;
|
||||
}
|
||||
|
||||
// if rover is valid and bestfofheight is closer then bestsectorheight and bestpoheight
|
||||
// probably should consider flip
|
||||
if (result.result == 2)
|
||||
if (result.result == RESPAWNRS_ROVER)
|
||||
{
|
||||
// Check if rover is bad based on both its terrain, and sector specials.
|
||||
if (result.bestrover)
|
||||
|
|
@ -7702,7 +7691,7 @@ static boolean K_SafeRespawnPosition(mobj_t * mo)
|
|||
}
|
||||
// if po is valid and bestpoheight is closer then bestsectorheight and bestpoheight
|
||||
// probably should consider flip
|
||||
else if (result.result == 3)
|
||||
else if (result.result == RESPAWNRS_PO)
|
||||
{
|
||||
// Check if po is bad based on both its terrain, and sector specials.
|
||||
if (result.bestpo)
|
||||
|
|
@ -7739,7 +7728,7 @@ static boolean K_SafeRespawnPosition(mobj_t * mo)
|
|||
}
|
||||
// if everything else is not closest check sector
|
||||
// probably should consider flip
|
||||
else if (result.result == 1)
|
||||
else if (result.result == RESPAWNRS_SECTOR)
|
||||
{
|
||||
// Check if sector is bad based on both its terrain, and sector specials.
|
||||
|
||||
|
|
|
|||
24
src/k_kart.h
24
src/k_kart.h
|
|
@ -26,6 +26,28 @@ Make sure this matches the actual number of states
|
|||
#define GROW_SCALE ((3*FRACUNIT)/2)
|
||||
#define SHRINK_SCALE ((6*FRACUNIT)/8)
|
||||
|
||||
// Used for respawning checks.
|
||||
|
||||
typedef struct respawnresult_s
|
||||
{
|
||||
sector_t *cursec;
|
||||
fixed_t bestsectorheight;
|
||||
fixed_t bestfofheight;
|
||||
ffloor_t *bestrover;
|
||||
fixed_t bestpoheight;
|
||||
polyobj_t *bestpo;
|
||||
fixed_t finaldistances[3];
|
||||
|
||||
SINT8 result;
|
||||
} respawnresult_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
RESPAWNRS_SECTOR,
|
||||
RESPAWNRS_ROVER,
|
||||
RESPAWNRS_PO,
|
||||
} respawnresult_e;
|
||||
|
||||
angle_t K_ReflectAngle(angle_t angle, angle_t against, fixed_t maxspeed, fixed_t yourspeed);
|
||||
|
||||
void K_RegisterKartStuff(void);
|
||||
|
|
@ -148,6 +170,8 @@ void K_PlayPowerGloatSound(mobj_t *source);
|
|||
void K_SetItemOut(player_t *player);
|
||||
void K_UnsetItemOut(player_t *player);
|
||||
|
||||
boolean K_SafeRespawnPosition(mobj_t * mo);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -3937,6 +3937,17 @@ static int lib_kSetHyuCountdown(lua_State *L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
// Checks if the floor closet floor under an object would be safe to respawn/land on.
|
||||
static int lib_kSafeRespawnPosition(lua_State *L)
|
||||
{
|
||||
mobj_t *mobj = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ));
|
||||
//HUDSAFE
|
||||
if (!mobj)
|
||||
return LUA_ErrInvalid(L, "mobj_t");
|
||||
lua_pushfixed(L, K_SafeRespawnPosition(mobj));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int lib_getTimeMicros(lua_State *L)
|
||||
{
|
||||
lua_pushinteger(L, I_GetPreciseTime() / (I_GetPrecisePrecision() / 1000000));
|
||||
|
|
@ -4231,6 +4242,7 @@ static luaL_Reg lib[] = {
|
|||
{"K_SetExitCountdown",lib_kSetExitCountdown},
|
||||
{"K_SetIndirectItemCooldown",lib_kSetIndirectItemCountdown},
|
||||
{"K_SetHyudoroCooldown",lib_kSetHyuCountdown},
|
||||
{"K_SafeRespawnPosition", lib_kSafeRespawnPosition},
|
||||
|
||||
{"K_GetCollideAngle",lib_kGetCollideAngle},
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue