From 7c0088b752b6ac6df2c824c48b6382e4d7becbae Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Tue, 7 Dec 2021 17:23:42 -0500 Subject: [PATCH 01/29] TERRAIN lump mockup --- src/k_terrain.c | 366 ++++++++++++++++++++++++++++++++++++++++++++++++ src/k_terrain.h | 70 +++++++++ 2 files changed, 436 insertions(+) create mode 100644 src/k_terrain.c create mode 100644 src/k_terrain.h diff --git a/src/k_terrain.c b/src/k_terrain.c new file mode 100644 index 000000000..ea78c9d2d --- /dev/null +++ b/src/k_terrain.c @@ -0,0 +1,366 @@ +// DR. ROBOTNIK'S RING RACERS +//----------------------------------------------------------------------------- +// Copyright (C) 1998-2021 by ZDoom + GZDoom teams, and contributors +// Copyright (C) 2021 by Sally "TehRealSalt" Cochenour +// Copyright (C) 2021 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_terrain.c +/// \brief Implementation of TERRAIN lump from GZDoom codebase for DRRR. + +#include "k_terrain.h" + +#include "z_zone.h" + +t_splash_t *splashDefs = NULL; +UINT16 numSplashDefs = 0; + +t_footstep_t *footstepDefs = NULL; +UINT16 numFootstepDefs = 0; + +terrain_t *terrainDefs = NULL; +UINT16 numTerrainDefs = 0; + +UINT16 defaultTerrain = UINT16_MAX; + +terrain_t *K_GetTerrainByIndex(UINT16 checkIndex) +{ + if (checkIndex >= numTerrainDefs) + { + return NULL; + } + + return terrainDefs[checkIndex]; +} + +terrain_t *K_GetTerrainByName(const char *checkName) +{ + INT32 i; + + if (numTerrainDefs == 0) + { + return NULL; + } + + // Search backwards through all terrain definitions. + // The latest one will have priority over the older one. + for (i = numTerrainDefs-1; i >= 0; i--) + { + terrain_t t = terrainDefs[i]; + + if (stricmp(checkName, t->name) == 0) + { + // Name matches. + return t; + } + } + + return NULL; +} + +terrain_t *K_GetDefaultTerrain(void) +{ + return K_GetTerrainByIndex(defaultTerrain); +} + +terrain_t *K_GetTerrainForTextureNum(INT32 textureNum) +{ + INT32 i, j; + + if (textureNum == -1) + { + return NULL; + } + + if (numTerrainDefs == 0) + { + return NULL; + } + + // Search backwards through all terrain definitions. + // The latest one will have priority over the older one. + + for (i = numTerrainDefs-1; i >= 0; i--) + { + terrain_t t = terrainDefs[i]; + + if (t->numTextureIDs == 0) + { + // No textures are applied to this terrain type. + continue; + } + + for (j = 0; j < numTextureIDs; j++) + { + if (textureNum == t->textureIDs[j]) + { + // Texture matches. + return t; + } + } + } + + // This texture doesn't have a terrain directly applied to it, + // so we fallback to the default terrain. + return K_GetDefaultTerrain(); +} + +terrain_t *K_GetTerrainForTextureName(const char *checkName) +{ + return K_GetTerrainForTextureNum( R_CheckTextureNumForName(checkName) ); +} + +static void K_GrowSplashDefs(void) +{ + numSplashDefs++; + splashDefs = (t_splash_t *)Z_Realloc(splashDefs, sizeof(t_splash_t) * (numSplashDefs + 1), PU_STATIC, NULL); +} + +static void K_GrowFootstepDefs(void) +{ + numFootstepDefs++; + footstepDefs = (t_footstep_t *)Z_Realloc(footstepDefs, sizeof(t_footstep_t) * (numFootstepDefs + 1), PU_STATIC, NULL); +} + +static void K_ParseNextLine(char *p, char *token) +{ + // parse next line + while (*p != '\0' && *p != '\n') + { + ++p; + } + + if (*p == '\n') + { + ++p; + } + + token = M_GetToken(p); +} + +static void K_GrowTerrainDefs(void) +{ + numTerrainDefs++; + terrainDefs = (terrain_t *)Z_Realloc(terrainDefs, sizeof(terrain_t) * (numTerrainDefs + 1), PU_STATIC, NULL); +} + +static void K_ParseTerrainDefintion(void) +{ + char *token; + size_t tokenLength; + char *endPos; + size_t i; + + // Startname + token = M_GetToken(NULL); + + if (token == NULL) + { + I_Error("Error parsing TERRAIN lump: Expected terrain definition, got end of file"); + } + + if (stricmp(token, "{") != 0) + { + I_Error("Error parsing TERRAIN lump: No starting bracket"); + } + + while (token != NULL) + { + + } + tokenLength = strlen(token); + + if (stricmp(animdefsToken, "OPTIONAL") == 0) + { + // This is meaningful to ZDoom - it tells the program NOT to bomb out + // if the textures can't be found - but it's useless in SRB2, so we'll + // just smile, nod, and carry on + Z_Free(animdefsToken); + animdefsToken = M_GetToken(NULL); + + if (animdefsToken == NULL) + { + I_Error("Error parsing ANIMDEFS lump: Unexpected end of file where start texture/flat name should be"); + } + else if (stricmp(animdefsToken, "RANGE") == 0) + { + // Oh. Um. Apparently "OPTIONAL" is a texture name. Naughty. + // I should probably handle this more gracefully, but right now + // I can't be bothered; especially since ZDoom doesn't handle this + // condition at all. + I_Error("Error parsing ANIMDEFS lump: \"OPTIONAL\" is a keyword; you cannot use it as the startname of an animation"); + } + } + animdefsTokenLength = strlen(animdefsToken); + if (animdefsTokenLength>8) + { + I_Error("Error parsing ANIMDEFS lump: lump name \"%s\" exceeds 8 characters", animdefsToken); + } + + // Search for existing animdef + for (i = 0; i < maxanims; i++) + if (animdefs[i].istexture == istexture // Check if it's the same type! + && stricmp(animdefsToken, animdefs[i].startname) == 0) + { + //CONS_Alert(CONS_NOTICE, "Duplicate animation: %s\n", animdefsToken); + + // If we weren't parsing in reverse order, we would `break` here and parse the new data into the existing slot we found. + // Instead, we're just going to skip parsing the rest of this line entirely. + Z_Free(animdefsToken); + return; + } + + // Not found + if (i == maxanims) + { + // Increase the size to make room for the new animation definition + GrowAnimDefs(); + strncpy(animdefs[i].startname, animdefsToken, 9); + } + + // animdefs[i].startname is now set to animdefsToken either way. + Z_Free(animdefsToken); + + // set texture type + animdefs[i].istexture = istexture; + + // "RANGE" + animdefsToken = M_GetToken(NULL); + if (animdefsToken == NULL) + { + I_Error("Error parsing ANIMDEFS lump: Unexpected end of file where \"RANGE\" after \"%s\"'s startname should be", animdefs[i].startname); + } + if (stricmp(animdefsToken, "ALLOWDECALS") == 0) + { + // Another ZDoom keyword, ho-hum. Skip it, move on to the next token. + Z_Free(animdefsToken); + animdefsToken = M_GetToken(NULL); + } + if (stricmp(animdefsToken, "PIC") == 0) + { + // This is technically legitimate ANIMDEFS syntax, but SRB2 doesn't support it. + I_Error("Error parsing ANIMDEFS lump: Animation definitions utilizing \"PIC\" (specific frames instead of a consecutive range) are not supported by SRB2"); + } + if (stricmp(animdefsToken, "RANGE") != 0) + { + I_Error("Error parsing ANIMDEFS lump: Expected \"RANGE\" after \"%s\"'s startname, got \"%s\"", animdefs[i].startname, animdefsToken); + } + Z_Free(animdefsToken); + + // Endname + animdefsToken = M_GetToken(NULL); + if (animdefsToken == NULL) + { + I_Error("Error parsing ANIMDEFS lump: Unexpected end of file where \"%s\"'s end texture/flat name should be", animdefs[i].startname); + } + animdefsTokenLength = strlen(animdefsToken); + if (animdefsTokenLength>8) + { + I_Error("Error parsing ANIMDEFS lump: lump name \"%s\" exceeds 8 characters", animdefsToken); + } + strncpy(animdefs[i].endname, animdefsToken, 9); + Z_Free(animdefsToken); + + // "TICS" + animdefsToken = M_GetToken(NULL); + if (animdefsToken == NULL) + { + I_Error("Error parsing ANIMDEFS lump: Unexpected end of file where \"%s\"'s \"TICS\" should be", animdefs[i].startname); + } + if (stricmp(animdefsToken, "RAND") == 0) + { + // This is technically legitimate ANIMDEFS syntax, but SRB2 doesn't support it. + I_Error("Error parsing ANIMDEFS lump: Animation definitions utilizing \"RAND\" (random duration per frame) are not supported by SRB2"); + } + if (stricmp(animdefsToken, "TICS") != 0) + { + I_Error("Error parsing ANIMDEFS lump: Expected \"TICS\" in animation definition for \"%s\", got \"%s\"", animdefs[i].startname, animdefsToken); + } + Z_Free(animdefsToken); + + // Speed + animdefsToken = M_GetToken(NULL); + if (animdefsToken == NULL) + { + I_Error("Error parsing ANIMDEFS lump: Unexpected end of file where \"%s\"'s animation speed should be", animdefs[i].startname); + } + endPos = NULL; +#ifndef AVOID_ERRNO + errno = 0; +#endif + + animSpeed = strtol(animdefsToken,&endPos,10); + + if (endPos == animdefsToken // Empty string + || *endPos != '\0' // Not end of string +#ifndef AVOID_ERRNO + || errno == ERANGE // Number out-of-range +#endif + || animSpeed < 0) // Number is not positive + { + I_Error("Error parsing ANIMDEFS lump: Expected a positive integer for \"%s\"'s animation speed, got \"%s\"", animdefs[i].startname, animdefsToken); + } + + animdefs[i].speed = animSpeed; + + Z_Free(animdefsToken); +} + +void K_ParseTERRAINLump(INT32 wadNum, UINT16 lumpnum) +{ + char *lump; + size_t lumpLength; + char *fullText; + char *token; + char *p; + + // Since lumps AREN'T \0-terminated like I'd assumed they should be, I'll + // need to make a space of memory where I can ensure that it will terminate + // correctly. Start by loading the relevant data from the WAD. + lump = (char *)W_CacheLumpNumPwad(wadNum, lumpnum, PU_STATIC); + + // If that didn't exist, we have nothing to do here. + if (lump == NULL) + { + return; + } + + // If we're still here, then it DOES exist; figure out how long it is, and allot memory accordingly. + lumpLength = W_LumpLengthPwad(wadNum, lumpnum); + fullText = (char *)Z_Malloc((lumpLength + 1) * sizeof(char), PU_STATIC, NULL); + + // Now move the contents of the lump into this new location. + memmove(fullText, lump, lumpLength); + + // Make damn well sure the last character in our new memory location is \0. + fullText[lumpLength] = '\0'; + + // Finally, free up the memory from the first data load, because we really + // don't need it. + Z_Free(lump); + + // Now, let's start parsing this thing + p = fullText; + token = M_GetToken(p); + + while (token != NULL) + { + if (stricmp(token, "TERRAIN") == 0) + { + Z_Free(token); + K_ParseTerrainDefintion(&p, &token); + } + else + { + I_Error("Error parsing TERRAIN lump: Expected \"SPLASH\", \"FOOTSTEP\", \"TERRAIN\", \"FLOOR\"; got \"%s\"", token); + } + + K_ParseNextLine(&p, &token); + } + + Z_Free(token); + Z_Free((void *)fullText); +} diff --git a/src/k_terrain.h b/src/k_terrain.h new file mode 100644 index 000000000..ac504cd48 --- /dev/null +++ b/src/k_terrain.h @@ -0,0 +1,70 @@ +// DR. ROBOTNIK'S RING RACERS +//----------------------------------------------------------------------------- +// Copyright (C) 1998-2021 by ZDoom + GZDoom teams, and contributors +// Copyright (C) 2021 by Sally "TehRealSalt" Cochenour +// Copyright (C) 2021 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_terrain.h +/// \brief Implementation of a TERRAIN-style lump for DRRR, ala GZDoom's codebase. + +#ifndef __K_TERRAIN_H__ +#define __K_TERRAIN_H__ + +typedef struct t_splash_s +{ + // Splash definition. + // These are particles spawned when hitting the floor. + + const char *name; // Lookup name. + + UINT16 objType; // Thing type. MT_NULL to not spawn anything. + UINT16 sound; // Sound to play. +} t_splash_t; + +typedef struct t_footstep_s +{ + // Footstep definition. + // These are particles spawned when moving fast enough on a floor. + + const char *name; // Lookup name. + + UINT16 objType; // Thing type. MT_NULL to not spawn anything. + UINT16 sound; // Sound to play. +} t_footstep_t; + +typedef struct terrain_s +{ + // Terrain definition. + // These are all of the properties that the floor gets. + + const char *name; // Lookup name. + + INT32 *textureIDs; // Texture nums this terrain applies to. (Doesn't support flats, stop using them already.) + UINT32 numTextureIDs; // Length of the above table. + + UINT16 splashID; // Splash defintion ID. + UINT16 footstepID; // Footstep defintion ID. + + fixed_t friction; // The default friction of this texture. + UINT8 offroad; // The default offroad level of this texture. + INT16 damageType; // The default damage type of this texture. (Negative means no damage). +} terrain_t; + +// Arrays for all terrain definitions. +extern t_splash_t *splashDefs; +extern UINT16 numSplashDefs; + +extern t_footstep_t *footstepDefs; +extern UINT16 numFootstepDefs; + +extern terrain_t *terrainDefs; +extern UINT16 numTerrainDefs; + +// Default terrain definition ID. +extern UINT16 defaultTerrain; + +#endif // __K_TERRAIN_H__ From a8615cac5b1d30e6047dfc77901aeec0a3255f90 Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Wed, 8 Dec 2021 19:16:12 -0500 Subject: [PATCH 02/29] TERRAIN lump reading Does not impact gameplay but hey pretty cool --- src/Sourcefile | 1 + src/k_terrain.c | 409 ++++++++++++++++++++++-------------------------- src/k_terrain.h | 19 ++- src/w_wad.c | 4 + 4 files changed, 204 insertions(+), 229 deletions(-) diff --git a/src/Sourcefile b/src/Sourcefile index 9bc27d4da..a1d6e176a 100644 --- a/src/Sourcefile +++ b/src/Sourcefile @@ -111,3 +111,4 @@ k_botitem.c k_botsearch.c k_grandprix.c k_hud.c +k_terrain.c diff --git a/src/k_terrain.c b/src/k_terrain.c index ea78c9d2d..77537f0f3 100644 --- a/src/k_terrain.c +++ b/src/k_terrain.c @@ -13,6 +13,12 @@ #include "k_terrain.h" +#include "dehacked.h" // get_number +#include "doomtype.h" +#include "fastcmp.h" +#include "m_fixed.h" +#include "r_textures.h" +#include "w_wad.h" #include "z_zone.h" t_splash_t *splashDefs = NULL; @@ -33,7 +39,7 @@ terrain_t *K_GetTerrainByIndex(UINT16 checkIndex) return NULL; } - return terrainDefs[checkIndex]; + return &terrainDefs[checkIndex]; } terrain_t *K_GetTerrainByName(const char *checkName) @@ -49,7 +55,7 @@ terrain_t *K_GetTerrainByName(const char *checkName) // The latest one will have priority over the older one. for (i = numTerrainDefs-1; i >= 0; i--) { - terrain_t t = terrainDefs[i]; + terrain_t *t = &terrainDefs[i]; if (stricmp(checkName, t->name) == 0) { @@ -68,7 +74,7 @@ terrain_t *K_GetDefaultTerrain(void) terrain_t *K_GetTerrainForTextureNum(INT32 textureNum) { - INT32 i, j; + INT32 i; if (textureNum == -1) { @@ -85,7 +91,8 @@ terrain_t *K_GetTerrainForTextureNum(INT32 textureNum) for (i = numTerrainDefs-1; i >= 0; i--) { - terrain_t t = terrainDefs[i]; + terrain_t *t = &terrainDefs[i]; + size_t j; if (t->numTextureIDs == 0) { @@ -93,7 +100,7 @@ terrain_t *K_GetTerrainForTextureNum(INT32 textureNum) continue; } - for (j = 0; j < numTextureIDs; j++) + for (j = 0; j < t->numTextureIDs; j++) { if (textureNum == t->textureIDs[j]) { @@ -113,254 +120,204 @@ terrain_t *K_GetTerrainForTextureName(const char *checkName) return K_GetTerrainForTextureNum( R_CheckTextureNumForName(checkName) ); } -static void K_GrowSplashDefs(void) +// +// Parser code starts here. +// + +static void K_TerrainDefaults(terrain_t *terrain) { - numSplashDefs++; - splashDefs = (t_splash_t *)Z_Realloc(splashDefs, sizeof(t_splash_t) * (numSplashDefs + 1), PU_STATIC, NULL); + terrain->splashID = UINT16_MAX; + terrain->footstepID = UINT16_MAX; + + terrain->friction = FRACUNIT; + terrain->offroad = 0; + terrain->damageType = -1; } -static void K_GrowFootstepDefs(void) -{ - numFootstepDefs++; - footstepDefs = (t_footstep_t *)Z_Realloc(footstepDefs, sizeof(t_footstep_t) * (numFootstepDefs + 1), PU_STATIC, NULL); -} - -static void K_ParseNextLine(char *p, char *token) -{ - // parse next line - while (*p != '\0' && *p != '\n') - { - ++p; - } - - if (*p == '\n') - { - ++p; - } - - token = M_GetToken(p); -} - -static void K_GrowTerrainDefs(void) +static void K_NewTerrainDefs(void) { numTerrainDefs++; terrainDefs = (terrain_t *)Z_Realloc(terrainDefs, sizeof(terrain_t) * (numTerrainDefs + 1), PU_STATIC, NULL); + K_TerrainDefaults( &terrainDefs[numTerrainDefs - 1] ); } -static void K_ParseTerrainDefintion(void) +static void K_ParseTerrainParameter(UINT32 i, char *param, char *val) { - char *token; - size_t tokenLength; - char *endPos; + terrain_t *terrain = &terrainDefs[i]; + + if (stricmp(param, "splash") == 0) + { + //terrain->splashID = 0; + } + else if (stricmp(param, "footstep") == 0) + { + //terrain->footstepID = 0; + } + else if (stricmp(param, "friction") == 0) + { + terrain->friction = FLOAT_TO_FIXED(atof(val)); + } + else if (stricmp(param, "offroad") == 0) + { + terrain->offroad = (UINT8)get_number(val); + } + else if (stricmp(param, "damageType") == 0) + { + terrain->damageType = (INT16)get_number(val); + } +} + +static boolean K_DoTERRAINLumpParse(size_t num, void (*parser)(UINT32, char *, char *)) +{ + char *param, *val; + + param = M_GetToken(NULL); + + if (!fastcmp(param, "{")) + { + Z_Free(param); + CONS_Alert(CONS_WARNING, "Invalid TERRAIN data capsule!\n"); + return false; + } + + Z_Free(param); + + while (true) + { + param = M_GetToken(NULL); + + if (fastcmp(param, "}")) + { + Z_Free(param); + break; + } + + val = M_GetToken(NULL); + parser(num, param, val); + + Z_Free(param); + Z_Free(val); + } + + return true; +} + +static boolean K_TERRAINLumpParser(UINT8 *data, size_t size) +{ + char *tkn = M_GetToken((char *)data); + size_t pos = 0; size_t i; - // Startname - token = M_GetToken(NULL); - - if (token == NULL) + while (tkn && (pos = M_GetTokenPos()) < size) { - I_Error("Error parsing TERRAIN lump: Expected terrain definition, got end of file"); - } + boolean result = true; - if (stricmp(token, "{") != 0) - { - I_Error("Error parsing TERRAIN lump: No starting bracket"); - } - - while (token != NULL) - { - - } - tokenLength = strlen(token); - - if (stricmp(animdefsToken, "OPTIONAL") == 0) - { - // This is meaningful to ZDoom - it tells the program NOT to bomb out - // if the textures can't be found - but it's useless in SRB2, so we'll - // just smile, nod, and carry on - Z_Free(animdefsToken); - animdefsToken = M_GetToken(NULL); - - if (animdefsToken == NULL) + // Avoid anything inside bracketed stuff, only look for external keywords. + if (fastcmp(tkn, "{") || fastcmp(tkn, "}")) { - I_Error("Error parsing ANIMDEFS lump: Unexpected end of file where start texture/flat name should be"); + CONS_Alert(CONS_ERROR, "Rogue bracket detected in TERRAIN lump.\n"); + Z_Free(tkn); + return false; } - else if (stricmp(animdefsToken, "RANGE") == 0) + // Check for valid fields. + else if (stricmp(tkn, "terrain") == 0) { - // Oh. Um. Apparently "OPTIONAL" is a texture name. Naughty. - // I should probably handle this more gracefully, but right now - // I can't be bothered; especially since ZDoom doesn't handle this - // condition at all. - I_Error("Error parsing ANIMDEFS lump: \"OPTIONAL\" is a keyword; you cannot use it as the startname of an animation"); - } - } - animdefsTokenLength = strlen(animdefsToken); - if (animdefsTokenLength>8) - { - I_Error("Error parsing ANIMDEFS lump: lump name \"%s\" exceeds 8 characters", animdefsToken); - } + Z_Free(tkn); + tkn = M_GetToken(NULL); + pos = M_GetTokenPos(); - // Search for existing animdef - for (i = 0; i < maxanims; i++) - if (animdefs[i].istexture == istexture // Check if it's the same type! - && stricmp(animdefsToken, animdefs[i].startname) == 0) - { - //CONS_Alert(CONS_NOTICE, "Duplicate animation: %s\n", animdefsToken); + if (tkn && pos < size) + { + terrain_t *t = NULL; - // If we weren't parsing in reverse order, we would `break` here and parse the new data into the existing slot we found. - // Instead, we're just going to skip parsing the rest of this line entirely. - Z_Free(animdefsToken); - return; - } + for (i = 0; i < numTerrainDefs; i++) + { + t = &terrainDefs[i]; - // Not found - if (i == maxanims) - { - // Increase the size to make room for the new animation definition - GrowAnimDefs(); - strncpy(animdefs[i].startname, animdefsToken, 9); - } + if (stricmp(tkn, t->name) == 0) + { + break; + } + } - // animdefs[i].startname is now set to animdefsToken either way. - Z_Free(animdefsToken); + if (i == numTerrainDefs) + { + K_NewTerrainDefs(); + t = &terrainDefs[i]; - // set texture type - animdefs[i].istexture = istexture; + strncpy(t->name, tkn, TERRAIN_NAME_LEN); + CONS_Printf("Created new Terrain type '%s'\n", t->name); + } - // "RANGE" - animdefsToken = M_GetToken(NULL); - if (animdefsToken == NULL) - { - I_Error("Error parsing ANIMDEFS lump: Unexpected end of file where \"RANGE\" after \"%s\"'s startname should be", animdefs[i].startname); - } - if (stricmp(animdefsToken, "ALLOWDECALS") == 0) - { - // Another ZDoom keyword, ho-hum. Skip it, move on to the next token. - Z_Free(animdefsToken); - animdefsToken = M_GetToken(NULL); - } - if (stricmp(animdefsToken, "PIC") == 0) - { - // This is technically legitimate ANIMDEFS syntax, but SRB2 doesn't support it. - I_Error("Error parsing ANIMDEFS lump: Animation definitions utilizing \"PIC\" (specific frames instead of a consecutive range) are not supported by SRB2"); - } - if (stricmp(animdefsToken, "RANGE") != 0) - { - I_Error("Error parsing ANIMDEFS lump: Expected \"RANGE\" after \"%s\"'s startname, got \"%s\"", animdefs[i].startname, animdefsToken); - } - Z_Free(animdefsToken); - - // Endname - animdefsToken = M_GetToken(NULL); - if (animdefsToken == NULL) - { - I_Error("Error parsing ANIMDEFS lump: Unexpected end of file where \"%s\"'s end texture/flat name should be", animdefs[i].startname); - } - animdefsTokenLength = strlen(animdefsToken); - if (animdefsTokenLength>8) - { - I_Error("Error parsing ANIMDEFS lump: lump name \"%s\" exceeds 8 characters", animdefsToken); - } - strncpy(animdefs[i].endname, animdefsToken, 9); - Z_Free(animdefsToken); - - // "TICS" - animdefsToken = M_GetToken(NULL); - if (animdefsToken == NULL) - { - I_Error("Error parsing ANIMDEFS lump: Unexpected end of file where \"%s\"'s \"TICS\" should be", animdefs[i].startname); - } - if (stricmp(animdefsToken, "RAND") == 0) - { - // This is technically legitimate ANIMDEFS syntax, but SRB2 doesn't support it. - I_Error("Error parsing ANIMDEFS lump: Animation definitions utilizing \"RAND\" (random duration per frame) are not supported by SRB2"); - } - if (stricmp(animdefsToken, "TICS") != 0) - { - I_Error("Error parsing ANIMDEFS lump: Expected \"TICS\" in animation definition for \"%s\", got \"%s\"", animdefs[i].startname, animdefsToken); - } - Z_Free(animdefsToken); - - // Speed - animdefsToken = M_GetToken(NULL); - if (animdefsToken == NULL) - { - I_Error("Error parsing ANIMDEFS lump: Unexpected end of file where \"%s\"'s animation speed should be", animdefs[i].startname); - } - endPos = NULL; -#ifndef AVOID_ERRNO - errno = 0; -#endif - - animSpeed = strtol(animdefsToken,&endPos,10); - - if (endPos == animdefsToken // Empty string - || *endPos != '\0' // Not end of string -#ifndef AVOID_ERRNO - || errno == ERANGE // Number out-of-range -#endif - || animSpeed < 0) // Number is not positive - { - I_Error("Error parsing ANIMDEFS lump: Expected a positive integer for \"%s\"'s animation speed, got \"%s\"", animdefs[i].startname, animdefsToken); - } - - animdefs[i].speed = animSpeed; - - Z_Free(animdefsToken); -} - -void K_ParseTERRAINLump(INT32 wadNum, UINT16 lumpnum) -{ - char *lump; - size_t lumpLength; - char *fullText; - char *token; - char *p; - - // Since lumps AREN'T \0-terminated like I'd assumed they should be, I'll - // need to make a space of memory where I can ensure that it will terminate - // correctly. Start by loading the relevant data from the WAD. - lump = (char *)W_CacheLumpNumPwad(wadNum, lumpnum, PU_STATIC); - - // If that didn't exist, we have nothing to do here. - if (lump == NULL) - { - return; - } - - // If we're still here, then it DOES exist; figure out how long it is, and allot memory accordingly. - lumpLength = W_LumpLengthPwad(wadNum, lumpnum); - fullText = (char *)Z_Malloc((lumpLength + 1) * sizeof(char), PU_STATIC, NULL); - - // Now move the contents of the lump into this new location. - memmove(fullText, lump, lumpLength); - - // Make damn well sure the last character in our new memory location is \0. - fullText[lumpLength] = '\0'; - - // Finally, free up the memory from the first data load, because we really - // don't need it. - Z_Free(lump); - - // Now, let's start parsing this thing - p = fullText; - token = M_GetToken(p); - - while (token != NULL) - { - if (stricmp(token, "TERRAIN") == 0) - { - Z_Free(token); - K_ParseTerrainDefintion(&p, &token); + result = K_DoTERRAINLumpParse(i, K_ParseTerrainParameter); + } + // TODO: the other block types! + else + { + CONS_Alert(CONS_NOTICE, "No terrain type name.\n"); + } } else { - I_Error("Error parsing TERRAIN lump: Expected \"SPLASH\", \"FOOTSTEP\", \"TERRAIN\", \"FLOOR\"; got \"%s\"", token); + CONS_Alert(CONS_NOTICE, "Unknown field '%s' found in TERRAIN lump.\n", tkn); + Z_Free(tkn); + return false; } - K_ParseNextLine(&p, &token); + if (result == false) + { + Z_Free(tkn); + return false; + } + + Z_Free(tkn); + tkn = M_GetToken(NULL); } - Z_Free(token); - Z_Free((void *)fullText); + Z_Free(tkn); + return true; +} + +void K_InitTerrain(UINT16 wadNum) +{ + UINT16 lumpNum; + lumpinfo_t *lump_p = wadfiles[wadNum]->lumpinfo; + + // Iterate through all lumps and compare the name individually. + // In PK3 files, you can potentially have multiple TERRAIN differentiated by + // their file extension. + for (lumpNum = 0; lumpNum < wadfiles[wadNum]->numlumps; lumpNum++, lump_p++) + { + UINT8 *data; + + if (memcmp(lump_p->name, "TERRAIN", 8) != 0) + { + continue; + } + + data = (UINT8 *)W_CacheLumpNumPwad(wadNum, lumpNum, PU_STATIC); + + // If that didn't exist, we have nothing to do here. + if (data == NULL) + { + continue; + } + else + { + size_t size = W_LumpLengthPwad(wadNum, lumpNum); + + size_t nameLength = strlen(wadfiles[wadNum]->filename) + 1 + strlen(lump_p->fullname); // length of file name, '|', and lump name + char *name = malloc(nameLength + 1); + + sprintf(name, "%s|%s", wadfiles[wadNum]->filename, lump_p->fullname); + name[nameLength] = '\0'; + + size = W_LumpLengthPwad(wadNum, lumpNum); + + CONS_Printf(M_GetText("Loading TERRAIN from %s\n"), name); + K_TERRAINLumpParser(data, size); + + free(name); + } + } } diff --git a/src/k_terrain.h b/src/k_terrain.h index ac504cd48..d774fa130 100644 --- a/src/k_terrain.h +++ b/src/k_terrain.h @@ -14,12 +14,17 @@ #ifndef __K_TERRAIN_H__ #define __K_TERRAIN_H__ +#include "doomtype.h" +#include "m_fixed.h" + +#define TERRAIN_NAME_LEN 32 + typedef struct t_splash_s { // Splash definition. // These are particles spawned when hitting the floor. - const char *name; // Lookup name. + char name[TERRAIN_NAME_LEN]; // Lookup name. UINT16 objType; // Thing type. MT_NULL to not spawn anything. UINT16 sound; // Sound to play. @@ -30,7 +35,7 @@ typedef struct t_footstep_s // Footstep definition. // These are particles spawned when moving fast enough on a floor. - const char *name; // Lookup name. + char name[TERRAIN_NAME_LEN]; // Lookup name. UINT16 objType; // Thing type. MT_NULL to not spawn anything. UINT16 sound; // Sound to play. @@ -41,7 +46,7 @@ typedef struct terrain_s // Terrain definition. // These are all of the properties that the floor gets. - const char *name; // Lookup name. + char name[TERRAIN_NAME_LEN]; // Lookup name. INT32 *textureIDs; // Texture nums this terrain applies to. (Doesn't support flats, stop using them already.) UINT32 numTextureIDs; // Length of the above table. @@ -67,4 +72,12 @@ extern UINT16 numTerrainDefs; // Default terrain definition ID. extern UINT16 defaultTerrain; +terrain_t *K_GetTerrainByIndex(UINT16 checkIndex); +terrain_t *K_GetTerrainByName(const char *checkName); +terrain_t *K_GetDefaultTerrain(void); +terrain_t *K_GetTerrainForTextureNum(INT32 textureNum); +terrain_t *K_GetTerrainForTextureName(const char *checkName); + +void K_InitTerrain(UINT16 wadNum); + #endif // __K_TERRAIN_H__ diff --git a/src/w_wad.c b/src/w_wad.c index 4e7e97dbb..34f846664 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -69,6 +69,8 @@ #include "m_misc.h" // M_MapNumber #include "g_game.h" // G_SetGameModified +#include "k_terrain.h" + #ifdef HWRENDER #include "hardware/hw_main.h" #include "hardware/hw_glob.h" @@ -866,6 +868,8 @@ UINT16 W_InitFile(const char *filename, boolean mainfile, boolean startup) break; } + K_InitTerrain(numwadfiles - 1); + if (refreshdirmenu & REFRESHDIR_GAMEDATA) G_LoadGameData(); DEH_UpdateMaxFreeslots(); From 150faf9de67dfdb8a106233d6595e09a7ee471fb Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Thu, 9 Dec 2021 00:56:05 -0500 Subject: [PATCH 03/29] Add terrain pointer to mobj_t --- src/k_kart.c | 1 + src/k_terrain.c | 88 ++++++++++++++++++++++++++++++++++++++++--------- src/k_terrain.h | 14 ++++++++ src/p_inter.c | 1 + src/p_local.h | 1 + src/p_map.c | 51 +++++++++++++++++++++++++--- src/p_maputl.c | 8 +++++ src/p_maputl.h | 1 + src/p_mobj.c | 79 ++++++++++++++++++++++++++++++-------------- src/p_mobj.h | 1 + src/p_slopes.c | 1 + 11 files changed, 203 insertions(+), 43 deletions(-) diff --git a/src/k_kart.c b/src/k_kart.c index 73661c018..cf51e3646 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -5176,6 +5176,7 @@ void K_DoPogoSpring(mobj_t *mo, fixed_t vertispeed, UINT8 sound) return; mo->standingslope = NULL; + mo->terrain = NULL; mo->eflags |= MFE_SPRUNG; diff --git a/src/k_terrain.c b/src/k_terrain.c index 77537f0f3..fabc89882 100644 --- a/src/k_terrain.c +++ b/src/k_terrain.c @@ -14,9 +14,13 @@ #include "k_terrain.h" #include "dehacked.h" // get_number +#include "doomdata.h" +#include "doomdef.h" #include "doomtype.h" #include "fastcmp.h" #include "m_fixed.h" +#include "p_local.h" +#include "p_mobj.h" #include "r_textures.h" #include "w_wad.h" #include "z_zone.h" @@ -120,10 +124,51 @@ terrain_t *K_GetTerrainForTextureName(const char *checkName) return K_GetTerrainForTextureNum( R_CheckTextureNumForName(checkName) ); } +void K_UpdateMobjTerrain(mobj_t *mo, INT32 flatID) +{ + levelflat_t *levelFlat = NULL; + + if (mo == NULL || P_MobjWasRemoved(mo) == true) + { + // Invalid object. + return; + } + + if (flatID < 0 || flatID >= (signed)numlevelflats) + { + // Clearly invalid floor... + mo->terrain = NULL; + return; + } + + if (mo->flags & MF_NOCLIPHEIGHT) + { + // You can't collide with floors anyway! + mo->terrain = NULL; + return; + } + + // Update the object's terrain pointer. + levelFlat = &levelflats[flatID]; + mo->terrain = K_GetTerrainForTextureName(levelFlat->name); +} + // // Parser code starts here. // +static void K_FlagBoolean(UINT32 *inputFlags, UINT32 newFlag, char *val) +{ + if (stricmp(val, "true") == 0) + { + *inputFlags |= newFlag; + } + else if (stricmp(val, "false") == 0) + { + *inputFlags &= ~newFlag; + } +} + static void K_TerrainDefaults(terrain_t *terrain) { terrain->splashID = UINT16_MAX; @@ -132,6 +177,8 @@ static void K_TerrainDefaults(terrain_t *terrain) terrain->friction = FRACUNIT; terrain->offroad = 0; terrain->damageType = -1; + terrain->trickPanel = 0; + terrain->flags = 0; } static void K_NewTerrainDefs(void) @@ -159,12 +206,24 @@ static void K_ParseTerrainParameter(UINT32 i, char *param, char *val) } else if (stricmp(param, "offroad") == 0) { - terrain->offroad = (UINT8)get_number(val); + terrain->offroad = (UINT8)get_number(val); // offroad strength enum? } else if (stricmp(param, "damageType") == 0) { terrain->damageType = (INT16)get_number(val); } + else if (stricmp(param, "trickPanel") == 0) + { + terrain->trickPanel = (UINT8)get_number(val); // trick panel strength enum? + } + else if (stricmp(param, "liquid") == 0) + { + K_FlagBoolean(&terrain->flags, TRF_LIQUID, val); + } + else if (stricmp(param, "sneakerPanel") == 0) + { + K_FlagBoolean(&terrain->flags, TRF_SNEAKERPANEL, val); + } } static boolean K_DoTERRAINLumpParse(size_t num, void (*parser)(UINT32, char *, char *)) @@ -210,14 +269,13 @@ static boolean K_TERRAINLumpParser(UINT8 *data, size_t size) while (tkn && (pos = M_GetTokenPos()) < size) { - boolean result = true; + boolean valid = true; // Avoid anything inside bracketed stuff, only look for external keywords. if (fastcmp(tkn, "{") || fastcmp(tkn, "}")) { CONS_Alert(CONS_ERROR, "Rogue bracket detected in TERRAIN lump.\n"); - Z_Free(tkn); - return false; + valid = false; } // Check for valid fields. else if (stricmp(tkn, "terrain") == 0) @@ -249,28 +307,28 @@ static boolean K_TERRAINLumpParser(UINT8 *data, size_t size) CONS_Printf("Created new Terrain type '%s'\n", t->name); } - result = K_DoTERRAINLumpParse(i, K_ParseTerrainParameter); + valid = K_DoTERRAINLumpParse(i, K_ParseTerrainParameter); } // TODO: the other block types! else { - CONS_Alert(CONS_NOTICE, "No terrain type name.\n"); + CONS_Alert(CONS_ERROR, "No terrain type name.\n"); + valid = false; } } else { - CONS_Alert(CONS_NOTICE, "Unknown field '%s' found in TERRAIN lump.\n", tkn); - Z_Free(tkn); - return false; - } - - if (result == false) - { - Z_Free(tkn); - return false; + CONS_Alert(CONS_ERROR, "Unknown field '%s' found in TERRAIN lump.\n", tkn); + valid = false; } Z_Free(tkn); + + if (valid == false) + { + return false; + } + tkn = M_GetToken(NULL); } diff --git a/src/k_terrain.h b/src/k_terrain.h index d774fa130..94db49dfb 100644 --- a/src/k_terrain.h +++ b/src/k_terrain.h @@ -14,8 +14,11 @@ #ifndef __K_TERRAIN_H__ #define __K_TERRAIN_H__ +#include "doomdata.h" +#include "doomdef.h" #include "doomtype.h" #include "m_fixed.h" +#include "p_mobj.h" #define TERRAIN_NAME_LEN 32 @@ -41,6 +44,13 @@ typedef struct t_footstep_s UINT16 sound; // Sound to play. } t_footstep_t; +typedef enum +{ + // Terrain flag values. + TRF_LIQUID = 1, // Texture water properties (wavy, slippery, etc) + TRF_SNEAKERPANEL = 1<<1 // Texture is a booster +} terrain_flags_t; + typedef struct terrain_s { // Terrain definition. @@ -57,6 +67,8 @@ typedef struct terrain_s fixed_t friction; // The default friction of this texture. UINT8 offroad; // The default offroad level of this texture. INT16 damageType; // The default damage type of this texture. (Negative means no damage). + UINT8 trickPanel; // Trick panel strength + UINT32 flags; // Flag values (see: terrain_flags_t) } terrain_t; // Arrays for all terrain definitions. @@ -78,6 +90,8 @@ terrain_t *K_GetDefaultTerrain(void); terrain_t *K_GetTerrainForTextureNum(INT32 textureNum); terrain_t *K_GetTerrainForTextureName(const char *checkName); +void K_UpdateMobjTerrain(mobj_t *mo, INT32 flatID); + void K_InitTerrain(UINT16 wadNum); #endif // __K_TERRAIN_H__ diff --git a/src/p_inter.c b/src/p_inter.c index 0a2bb4e13..e0171522e 100644 --- a/src/p_inter.c +++ b/src/p_inter.c @@ -1061,6 +1061,7 @@ void P_KillMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source, UINT8 damaget target->flags |= MF_NOBLOCKMAP|MF_NOCLIP|MF_NOCLIPHEIGHT|MF_NOGRAVITY; P_SetThingPosition(target); target->standingslope = NULL; + target->terrain = NULL; target->pmomz = 0; target->player->playerstate = PST_DEAD; diff --git a/src/p_local.h b/src/p_local.h index 61a8cf3a0..fa6e39670 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -384,6 +384,7 @@ extern camera_t *mapcampointer; extern fixed_t tmx; extern fixed_t tmy; extern pslope_t *tmfloorslope, *tmceilingslope; +extern INT32 tmfloorpic, tmceilingpic; /* cphipps 2004/08/30 */ extern void P_MapStart(void); diff --git a/src/p_map.c b/src/p_map.c index d0716790b..36ec3ef0a 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -24,12 +24,13 @@ #include "r_sky.h" #include "s_sound.h" #include "w_wad.h" + #include "k_kart.h" // SRB2kart 011617 #include "k_collide.h" #include "k_respawn.h" - #include "hu_stuff.h" // SRB2kart #include "i_system.h" // SRB2kart +#include "k_terrain.h" #include "r_splats.h" @@ -60,6 +61,7 @@ mobj_t *tmfloorthing; // the thing corresponding to tmfloorz or NULL if tmfloorz mobj_t *tmhitthing; // the solid thing you bumped into (for collisions) ffloor_t *tmfloorrover, *tmceilingrover; pslope_t *tmfloorslope, *tmceilingslope; +INT32 tmfloorpic, tmceilingpic; static fixed_t tmfloorstep; static fixed_t tmceilingstep; @@ -303,6 +305,7 @@ boolean P_DoSpring(mobj_t *spring, mobj_t *object) } object->standingslope = NULL; // Okay, now we know it's not going to be relevant - no launching off at silly angles for you. + object->terrain = NULL; object->eflags |= MFE_SPRUNG; // apply this flag asap! spring->flags &= ~(MF_SOLID|MF_SPECIAL); // De-solidify @@ -441,6 +444,7 @@ static void P_DoFanAndGasJet(mobj_t *spring, mobj_t *object) } object->standingslope = NULL; // No launching off at silly angles for you. + object->terrain = NULL; switch (spring->type) { @@ -1427,6 +1431,7 @@ static boolean PIT_CheckThing(mobj_t *thing) tmfloorz = thing->z + thing->height; tmfloorrover = NULL; tmfloorslope = NULL; + tmfloorpic = -1; } return true; } @@ -1446,6 +1451,7 @@ static boolean PIT_CheckThing(mobj_t *thing) tmfloorz = tmceilingz = topz; // block while in air tmceilingrover = NULL; tmceilingslope = NULL; + tmceilingpic = -1; tmfloorthing = thing; // needed for side collision } else if (topz < tmceilingz && tmthing->z <= thing->z+thing->height) @@ -1453,6 +1459,7 @@ static boolean PIT_CheckThing(mobj_t *thing) tmceilingz = topz; tmceilingrover = NULL; tmceilingslope = NULL; + tmceilingpic = -1; tmfloorthing = thing; // thing we may stand on } } @@ -1468,6 +1475,7 @@ static boolean PIT_CheckThing(mobj_t *thing) tmceilingz = thing->z; tmceilingrover = NULL; tmceilingslope = NULL; + tmceilingpic = -1; } return true; } @@ -1487,6 +1495,7 @@ static boolean PIT_CheckThing(mobj_t *thing) tmfloorz = tmceilingz = topz; // block while in air tmfloorrover = NULL; tmfloorslope = NULL; + tmfloorpic = -1; tmfloorthing = thing; // needed for side collision } else if (topz > tmfloorz && tmthing->z+tmthing->height >= thing->z) @@ -1494,6 +1503,7 @@ static boolean PIT_CheckThing(mobj_t *thing) tmfloorz = topz; tmfloorrover = NULL; tmfloorslope = NULL; + tmfloorpic = -1; tmfloorthing = thing; // thing we may stand on } } @@ -1673,6 +1683,7 @@ static boolean PIT_CheckLine(line_t *ld) ceilingline = ld; tmceilingrover = openceilingrover; tmceilingslope = opentopslope; + tmceilingpic = opentoppic; tmceilingstep = openceilingstep; if (thingtop == tmthing->ceilingz) { @@ -1685,6 +1696,7 @@ static boolean PIT_CheckLine(line_t *ld) tmfloorz = openbottom; tmfloorrover = openfloorrover; tmfloorslope = openbottomslope; + tmfloorpic = openbottompic; tmfloorstep = openfloorstep; if (tmthing->z == tmthing->floorz) { @@ -1781,6 +1793,8 @@ boolean P_CheckPosition(mobj_t *thing, fixed_t x, fixed_t y) tmceilingrover = NULL; tmfloorslope = newsubsec->sector->f_slope; tmceilingslope = newsubsec->sector->c_slope; + tmfloorpic = newsubsec->sector->floorpic; + tmceilingpic = newsubsec->sector->ceilingpic; tmfloorstep = 0; tmceilingstep = 0; @@ -1834,6 +1848,7 @@ boolean P_CheckPosition(mobj_t *thing, fixed_t x, fixed_t y) tmfloorz = topheight - sinklevel; tmfloorrover = rover; tmfloorslope = *rover->t_slope; + tmfloorpic = *rover->toppic; } } else if (thing->eflags & MFE_VERTICALFLIP && thingtop <= bottomheight + sinklevel && thing->momz >= 0) @@ -1842,6 +1857,7 @@ boolean P_CheckPosition(mobj_t *thing, fixed_t x, fixed_t y) tmceilingz = bottomheight + sinklevel; tmceilingrover = rover; tmceilingslope = *rover->b_slope; + tmceilingpic = *rover->bottompic; } } } @@ -1865,6 +1881,7 @@ boolean P_CheckPosition(mobj_t *thing, fixed_t x, fixed_t y) tmfloorz = thing->z; tmfloorrover = rover; tmfloorslope = NULL; + tmfloorpic = *rover->toppic; } } // Quicksand blocks never change heights otherwise. @@ -1882,6 +1899,7 @@ boolean P_CheckPosition(mobj_t *thing, fixed_t x, fixed_t y) tmfloorz = tmdropoffz = topheight; tmfloorrover = rover; tmfloorslope = *rover->t_slope; + tmfloorpic = *rover->toppic; } if (bottomheight < tmceilingz && abs(delta1) >= abs(delta2) && !(rover->flags & FF_PLATFORM) @@ -1890,6 +1908,7 @@ boolean P_CheckPosition(mobj_t *thing, fixed_t x, fixed_t y) tmceilingz = tmdrpoffceilz = bottomheight; tmceilingrover = rover; tmceilingslope = *rover->b_slope; + tmceilingpic = *rover->bottompic; } } } @@ -1964,12 +1983,14 @@ boolean P_CheckPosition(mobj_t *thing, fixed_t x, fixed_t y) tmfloorz = tmdropoffz = polytop; tmfloorslope = NULL; tmfloorrover = NULL; + tmfloorpic = polysec->ceilingpic; } if (polybottom < tmceilingz && abs(delta1) >= abs(delta2)) { tmceilingz = tmdrpoffceilz = polybottom; tmceilingslope = NULL; tmceilingrover = NULL; + tmceilingpic = polysec->floorpic; } } plink = (polymaplink_t *)(plink->link.next); @@ -2387,6 +2408,8 @@ boolean PIT_PushableMoved(mobj_t *thing) ffloor_t *oldceilrover = tmceilingrover; pslope_t *oldfslope = tmfloorslope; pslope_t *oldcslope = tmceilingslope; + INT32 oldfpic = tmfloorpic; + INT32 oldcpic = tmceilingpic; // Move the player P_TryMove(thing, thing->x+stand->momx, thing->y+stand->momy, true); @@ -2403,6 +2426,8 @@ boolean PIT_PushableMoved(mobj_t *thing) tmceilingrover = oldceilrover; tmfloorslope = oldfslope; tmceilingslope = oldcslope; + tmfloorpic = oldfpic; + tmceilingpic = oldcpic; thing->momz = stand->momz; } else @@ -2616,9 +2641,14 @@ boolean P_TryMove(mobj_t *thing, fixed_t x, fixed_t y, boolean allowdropoff) if (!(thing->flags & MF_NOCLIPHEIGHT)) { // Assign thing's standingslope if needed - if (thing->z <= tmfloorz && !(thing->eflags & MFE_VERTICALFLIP)) { + if (thing->z <= tmfloorz && !(thing->eflags & MFE_VERTICALFLIP)) + { + K_UpdateMobjTerrain(thing, tmfloorpic); + if (!startingonground && tmfloorslope) + { P_HandleSlopeLanding(thing, tmfloorslope); + } if (thing->momz <= 0) { @@ -2626,12 +2656,19 @@ boolean P_TryMove(mobj_t *thing, fixed_t x, fixed_t y, boolean allowdropoff) P_SetPitchRollFromSlope(thing, thing->standingslope); if (thing->momz == 0 && thing->player && !startingonground) + { P_PlayerHitFloor(thing->player, true); + } } } - else if (thing->z+thing->height >= tmceilingz && (thing->eflags & MFE_VERTICALFLIP)) { + else if (thing->z+thing->height >= tmceilingz && (thing->eflags & MFE_VERTICALFLIP)) + { + K_UpdateMobjTerrain(thing, tmceilingpic); + if (!startingonground && tmceilingslope) + { P_HandleSlopeLanding(thing, tmceilingslope); + } if (thing->momz >= 0) { @@ -2639,12 +2676,18 @@ boolean P_TryMove(mobj_t *thing, fixed_t x, fixed_t y, boolean allowdropoff) P_SetPitchRollFromSlope(thing, thing->standingslope); if (thing->momz == 0 && thing->player && !startingonground) + { P_PlayerHitFloor(thing->player, true); + } } } } - else // don't set standingslope if you're not going to clip against it + else + { + // don't set standingslope if you're not going to clip against it thing->standingslope = NULL; + thing->terrain = NULL; + } /* FIXME: slope step down (even up) has some false positives, so just ignore them entirely. */ diff --git a/src/p_maputl.c b/src/p_maputl.c index 2e21f5ee3..e30c0e0da 100644 --- a/src/p_maputl.c +++ b/src/p_maputl.c @@ -342,6 +342,7 @@ fixed_t openceilingstep; fixed_t openceilingdrop; fixed_t openfloorstep; fixed_t openfloordrop; +INT32 opentoppic, openbottompic; // P_CameraLineOpening // P_LineOpening, but for camera @@ -537,6 +538,7 @@ void P_LineOpening(line_t *linedef, mobj_t *mobj) highceiling = INT32_MIN; lowfloor = INT32_MAX; opentopslope = openbottomslope = NULL; + opentoppic = openbottompic = -1; openceilingstep = 0; openceilingdrop = 0; openfloorstep = 0; @@ -556,6 +558,7 @@ void P_LineOpening(line_t *linedef, mobj_t *mobj) opentop = height[lo]; highceiling = height[hi]; opentopslope = sector[lo]->c_slope; + opentoppic = sector[lo]->ceilingpic; if (mobj) { @@ -575,6 +578,7 @@ void P_LineOpening(line_t *linedef, mobj_t *mobj) openbottom = height[hi]; lowfloor = height[lo]; openbottomslope = sector[hi]->f_slope; + openbottompic = sector[hi]->floorpic; if (mobj) { @@ -747,6 +751,7 @@ void P_LineOpening(line_t *linedef, mobj_t *mobj) if (bottomheight < open[FRONT].top) { open[FRONT].top = bottomheight; opentopslope = *rover->b_slope; + opentoppic = *rover->bottompic; open[FRONT].ceilingrover = rover; } else if (bottomheight < highceiling) @@ -758,6 +763,7 @@ void P_LineOpening(line_t *linedef, mobj_t *mobj) if (topheight > open[FRONT].bottom) { open[FRONT].bottom = topheight; openbottomslope = *rover->t_slope; + openbottompic = *rover->toppic; open[FRONT].floorrover = rover; } else if (topheight > lowfloor) @@ -789,6 +795,7 @@ void P_LineOpening(line_t *linedef, mobj_t *mobj) if (bottomheight < open[BACK].top) { open[BACK].top = bottomheight; opentopslope = *rover->b_slope; + opentoppic = *rover->bottompic; open[BACK].ceilingrover = rover; } else if (bottomheight < highceiling) @@ -800,6 +807,7 @@ void P_LineOpening(line_t *linedef, mobj_t *mobj) if (topheight > open[BACK].bottom) { open[BACK].bottom = topheight; openbottomslope = *rover->t_slope; + openbottompic = *rover->toppic; open[BACK].floorrover = rover; } else if (topheight > lowfloor) diff --git a/src/p_maputl.h b/src/p_maputl.h index 6f0c1f8ad..43a7fb507 100644 --- a/src/p_maputl.h +++ b/src/p_maputl.h @@ -63,6 +63,7 @@ extern fixed_t openceilingstep; extern fixed_t openceilingdrop; extern fixed_t openfloorstep; extern fixed_t openfloordrop; +extern INT32 opentoppic, openbottompic; void P_LineOpening(line_t *plinedef, mobj_t *mobj); diff --git a/src/p_mobj.c b/src/p_mobj.c index b066e2a1c..46394dd24 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -40,6 +40,7 @@ #include "k_color.h" #include "k_respawn.h" #include "k_bot.h" +#include "k_terrain.h" static CV_PossibleValue_t CV_BobSpeed[] = {{0, "MIN"}, {4*FRACUNIT, "MAX"}, {0, NULL}}; consvar_t cv_movebob = CVAR_INIT ("movebob", "1.0", CV_FLOAT|CV_SAVE, CV_BobSpeed, NULL); @@ -1505,7 +1506,10 @@ void P_XYMovement(mobj_t *mo) oldy = mo->y; if (mo->flags & MF_NOCLIPHEIGHT) + { mo->standingslope = NULL; + mo->terrain = NULL; + } // adjust various things based on slope if (mo->standingslope && abs(mo->standingslope->zdelta) > FRACUNIT>>8) { @@ -1671,6 +1675,7 @@ void P_XYMovement(mobj_t *mo) { mo->momz = transfermomz; mo->standingslope = NULL; + mo->terrain = NULL; P_SetPitchRoll(mo, ANGLE_90, transferslope->xydirection + (transferslope->zangle @@ -1782,6 +1787,7 @@ void P_XYMovement(mobj_t *mo) mo->momz = P_MobjFlip(mo)*FRACUNIT/2; mo->z = predictedz + P_MobjFlip(mo); mo->standingslope = NULL; + mo->terrain = NULL; //CONS_Printf("Launched off of flat surface running into downward slope\n"); } } @@ -2274,6 +2280,8 @@ boolean P_ZMovement(mobj_t *mo) } P_CheckPosition(mo, mo->x, mo->y); // Sets mo->standingslope correctly + K_UpdateMobjTerrain(mo, ((mo->eflags & MFE_VERTICALFLIP) ? tmceilingpic : tmfloorpic)); + if (((mo->eflags & MFE_VERTICALFLIP) ? tmceilingslope : tmfloorslope) && (mo->type != MT_STEAM)) { mo->standingslope = (mo->eflags & MFE_VERTICALFLIP) ? tmceilingslope : tmfloorslope; @@ -2503,12 +2511,17 @@ boolean P_ZMovement(mobj_t *mo) if (mo->type == MT_STEAM) return true; } - else if (!(mo->flags & MF_NOGRAVITY)) // Gravity here! + else { - /// \todo may not be needed (done in P_MobjThinker normally) - mo->eflags &= ~MFE_JUSTHITFLOOR; + mo->terrain = NULL; - P_CheckGravity(mo, true); + if (!(mo->flags & MF_NOGRAVITY)) // Gravity here! + { + /// \todo may not be needed (done in P_MobjThinker normally) + mo->eflags &= ~MFE_JUSTHITFLOOR; + + P_CheckGravity(mo, true); + } } if (((mo->z + mo->height > mo->ceilingz && !(mo->eflags & MFE_VERTICALFLIP)) @@ -2712,20 +2725,29 @@ void P_PlayerZMovement(mobj_t *mo) if (onground && !(mo->flags & MF_NOCLIPHEIGHT)) { if (mo->eflags & MFE_VERTICALFLIP) + { mo->z = mo->ceilingz - mo->height; + } else + { mo->z = mo->floorz; + } + + K_UpdateMobjTerrain(mo, (mo->eflags & MFE_VERTICALFLIP ? tmceilingpic : tmfloorpic)); // Get up if you fell. if (mo->player->panim == PA_HURT && mo->player->spinouttimer == 0 && mo->player->tumbleBounces == 0) + { P_SetPlayerMobjState(mo, S_KART_STILL); + } - if (!mo->standingslope && (mo->eflags & MFE_VERTICALFLIP ? tmceilingslope : tmfloorslope)) { + if (!mo->standingslope && (mo->eflags & MFE_VERTICALFLIP ? tmceilingslope : tmfloorslope)) + { // Handle landing on slope during Z movement P_HandleSlopeLanding(mo, (mo->eflags & MFE_VERTICALFLIP ? tmceilingslope : tmfloorslope)); } - if (P_MobjFlip(mo)*mo->momz < 0) // falling + if (P_MobjFlip(mo) * mo->momz < 0) // falling { boolean clipmomz = !(P_CheckDeathPitCollide(mo)); @@ -2736,29 +2758,38 @@ void P_PlayerZMovement(mobj_t *mo) P_PlayerPolyObjectZMovement(mo); if (clipmomz) + { mo->momz = (tmfloorthing ? tmfloorthing->momz : 0); + } } else if (tmfloorthing) - mo->momz = tmfloorthing->momz; - } - else if (!(mo->flags & MF_NOGRAVITY)) // Gravity here! - { - if (P_IsObjectInGoop(mo) && !(mo->flags & MF_NOCLIPHEIGHT)) { - if (mo->z < mo->floorz) - { - mo->z = mo->floorz; - mo->momz = 0; - } - else if (mo->z + mo->height > mo->ceilingz) - { - mo->z = mo->ceilingz - mo->height; - mo->momz = 0; - } + mo->momz = tmfloorthing->momz; + } + } + else + { + mo->terrain = NULL; + + if (!(mo->flags & MF_NOGRAVITY)) // Gravity here! + { + if (P_IsObjectInGoop(mo) && !(mo->flags & MF_NOCLIPHEIGHT)) + { + if (mo->z < mo->floorz) + { + mo->z = mo->floorz; + mo->momz = 0; + } + else if (mo->z + mo->height > mo->ceilingz) + { + mo->z = mo->ceilingz - mo->height; + mo->momz = 0; + } + } + /// \todo may not be needed (done in P_MobjThinker normally) + mo->eflags &= ~MFE_JUSTHITFLOOR; + P_CheckGravity(mo, true); } - /// \todo may not be needed (done in P_MobjThinker normally) - mo->eflags &= ~MFE_JUSTHITFLOOR; - P_CheckGravity(mo, true); } if (((mo->eflags & MFE_VERTICALFLIP && mo->z < mo->floorz) || (!(mo->eflags & MFE_VERTICALFLIP) && mo->z + mo->height > mo->ceilingz)) diff --git a/src/p_mobj.h b/src/p_mobj.h index 2373bdca4..9d73c433b 100644 --- a/src/p_mobj.h +++ b/src/p_mobj.h @@ -395,6 +395,7 @@ typedef struct mobj_s fixed_t sprxoff, spryoff, sprzoff; // Sprite offsets in real space, does NOT affect position or collision + struct terrain_s *terrain; // Terrain definition of the floor this object last hit. NULL when in the air. INT32 hitlag; // Sal-style hit lag, straight from Captain Fetch's jowls // WARNING: New fields must be added separately to savegame and Lua. diff --git a/src/p_slopes.c b/src/p_slopes.c index 1bde8f4ee..6c660ad0f 100644 --- a/src/p_slopes.c +++ b/src/p_slopes.c @@ -850,6 +850,7 @@ void P_SlopeLaunch(mobj_t *mo) //CONS_Printf("Launched off of slope.\n"); mo->standingslope = NULL; + mo->terrain = NULL; if (mo->player) { From 53d777788a258aaffb3a174a3af565ca38d81c14 Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Thu, 9 Dec 2021 01:21:34 -0500 Subject: [PATCH 04/29] Friction value is used, implemented DefaultTerrain --- src/k_terrain.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++ src/k_terrain.h | 1 + src/p_mobj.c | 2 +- 3 files changed, 91 insertions(+), 1 deletion(-) diff --git a/src/k_terrain.c b/src/k_terrain.c index fabc89882..4928281b1 100644 --- a/src/k_terrain.c +++ b/src/k_terrain.c @@ -153,6 +153,58 @@ void K_UpdateMobjTerrain(mobj_t *mo, INT32 flatID) mo->terrain = K_GetTerrainForTextureName(levelFlat->name); } +void K_SetDefaultFriction(mobj_t *mo) +{ + mo->friction = ORIG_FRICTION; + + if (mo->player != NULL) + { + mo->movefactor = FRACUNIT; + } + + if (mo->terrain != NULL) + { + fixed_t strength = mo->terrain->friction; + + fixed_t newFriction = INT32_MAX; + fixed_t newMovefactor = INT32_MAX; + + if (strength > 0) // sludge + { + strength = strength*2; // otherwise, the maximum sludginess value is +967... + } + + // The following might seem odd. At the time of movement, + // the move distance is multiplied by 'friction/0x10000', so a + // higher friction value actually means 'less friction'. + newFriction = ORIG_FRICTION - FixedMul(0x1EB8, strength) / 0x80; // ORIG_FRICTION is 0xE800 + + if (newFriction > FRACUNIT) + { + newFriction = FRACUNIT; + } + + if (newFriction < 0) + { + newFriction = 0; + } + + newMovefactor = FixedDiv(ORIG_FRICTION, newFriction); + + if (newMovefactor < FRACUNIT) + { + newMovefactor = 19*newMovefactor - 18*FRACUNIT; + } + else + { + newMovefactor = FRACUNIT; + } + + mo->friction = newFriction; + mo->movefactor = newMovefactor; + } +} + // // Parser code starts here. // @@ -316,6 +368,43 @@ static boolean K_TERRAINLumpParser(UINT8 *data, size_t size) valid = false; } } + else if (stricmp(tkn, "defaultTerrain") == 0) + { + Z_Free(tkn); + tkn = M_GetToken(NULL); + pos = M_GetTokenPos(); + + if (tkn && pos < size) + { + terrain_t *t = NULL; + + for (i = 0; i < numTerrainDefs; i++) + { + t = &terrainDefs[i]; + + if (stricmp(tkn, t->name) == 0) + { + break; + } + } + + if (i == numTerrainDefs) + { + CONS_Alert(CONS_ERROR, "Invalid DefaultTerrain type.\n"); + valid = false; + } + else + { + defaultTerrain = i; + } + } + // TODO: the other block types! + else + { + CONS_Alert(CONS_ERROR, "No DefaultTerrain type.\n"); + valid = false; + } + } else { CONS_Alert(CONS_ERROR, "Unknown field '%s' found in TERRAIN lump.\n", tkn); diff --git a/src/k_terrain.h b/src/k_terrain.h index 94db49dfb..5660c0d4b 100644 --- a/src/k_terrain.h +++ b/src/k_terrain.h @@ -91,6 +91,7 @@ terrain_t *K_GetTerrainForTextureNum(INT32 textureNum); terrain_t *K_GetTerrainForTextureName(const char *checkName); void K_UpdateMobjTerrain(mobj_t *mo, INT32 flatID); +void K_SetDefaultFriction(mobj_t *mo); void K_InitTerrain(UINT16 wadNum); diff --git a/src/p_mobj.c b/src/p_mobj.c index 46394dd24..87ea3d9b5 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -1341,7 +1341,7 @@ static void P_XYFriction(mobj_t *mo, fixed_t oldx, fixed_t oldy) mo->momy = FixedMul(mo->momy, mo->friction); } - mo->friction = ORIG_FRICTION; + K_SetDefaultFriction(mo); } } else From f7834054a5c0da760093a24c265b5f327564b6df Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Thu, 9 Dec 2021 01:55:29 -0500 Subject: [PATCH 05/29] You can now link terrain to textures --- src/k_terrain.c | 128 ++++++++++++++++++++++++++++++++++++++---------- src/k_terrain.h | 21 ++++++-- 2 files changed, 119 insertions(+), 30 deletions(-) diff --git a/src/k_terrain.c b/src/k_terrain.c index 4928281b1..a2b09158d 100644 --- a/src/k_terrain.c +++ b/src/k_terrain.c @@ -34,6 +34,9 @@ UINT16 numFootstepDefs = 0; terrain_t *terrainDefs = NULL; UINT16 numTerrainDefs = 0; +t_floor_t *terrainFloorDefs = NULL; +UINT16 numTerrainFloorDefs = 0; + UINT16 defaultTerrain = UINT16_MAX; terrain_t *K_GetTerrainByIndex(UINT16 checkIndex) @@ -76,16 +79,11 @@ terrain_t *K_GetDefaultTerrain(void) return K_GetTerrainByIndex(defaultTerrain); } -terrain_t *K_GetTerrainForTextureNum(INT32 textureNum) +terrain_t *K_GetTerrainForTextureName(const char *checkName) { INT32 i; - if (textureNum == -1) - { - return NULL; - } - - if (numTerrainDefs == 0) + if (numTerrainFloorDefs == 0) { return NULL; } @@ -93,24 +91,13 @@ terrain_t *K_GetTerrainForTextureNum(INT32 textureNum) // Search backwards through all terrain definitions. // The latest one will have priority over the older one. - for (i = numTerrainDefs-1; i >= 0; i--) + for (i = 0; i < numTerrainFloorDefs; i++) { - terrain_t *t = &terrainDefs[i]; - size_t j; + t_floor_t *f = &terrainFloorDefs[i]; - if (t->numTextureIDs == 0) + if (stricmp(checkName, f->textureName) == 0) { - // No textures are applied to this terrain type. - continue; - } - - for (j = 0; j < t->numTextureIDs; j++) - { - if (textureNum == t->textureIDs[j]) - { - // Texture matches. - return t; - } + return K_GetTerrainByIndex(f->terrainID); } } @@ -119,9 +106,17 @@ terrain_t *K_GetTerrainForTextureNum(INT32 textureNum) return K_GetDefaultTerrain(); } -terrain_t *K_GetTerrainForTextureName(const char *checkName) +terrain_t *K_GetTerrainForTextureNum(INT32 textureNum) { - return K_GetTerrainForTextureNum( R_CheckTextureNumForName(checkName) ); + texture_t *tex = NULL; + + if (textureNum < 0 || textureNum >= numtextures) + { + return NULL; + } + + tex = textures[textureNum]; + return K_GetTerrainForTextureName(tex->name); } void K_UpdateMobjTerrain(mobj_t *mo, INT32 flatID) @@ -278,6 +273,12 @@ static void K_ParseTerrainParameter(UINT32 i, char *param, char *val) } } +static void K_NewTerrainFloorDefs(void) +{ + numTerrainFloorDefs++; + terrainFloorDefs = (t_floor_t *)Z_Realloc(terrainFloorDefs, sizeof(t_floor_t) * (numTerrainFloorDefs + 1), PU_STATIC, NULL); +} + static boolean K_DoTERRAINLumpParse(size_t num, void (*parser)(UINT32, char *, char *)) { char *param, *val; @@ -361,13 +362,88 @@ static boolean K_TERRAINLumpParser(UINT8 *data, size_t size) valid = K_DoTERRAINLumpParse(i, K_ParseTerrainParameter); } - // TODO: the other block types! else { CONS_Alert(CONS_ERROR, "No terrain type name.\n"); valid = false; } } + else if (stricmp(tkn, "floor") == 0) + { + Z_Free(tkn); + tkn = M_GetToken(NULL); + pos = M_GetTokenPos(); + + if (tkn && pos < size) + { + if (stricmp(tkn, "optional") == 0) + { + // "optional" is ZDoom syntax + // We don't use it, but we can ignore it. + Z_Free(tkn); + tkn = M_GetToken(NULL); + pos = M_GetTokenPos(); + } + + if (tkn && pos < size) + { + t_floor_t *f = NULL; + + for (i = 0; i < numTerrainFloorDefs; i++) + { + f = &terrainFloorDefs[i]; + + if (stricmp(tkn, f->textureName) == 0) + { + break; + } + } + + if (i == numTerrainFloorDefs) + { + K_NewTerrainFloorDefs(); + f = &terrainFloorDefs[i]; + + strncpy(f->textureName, tkn, 9); + } + + Z_Free(tkn); + tkn = M_GetToken(NULL); + pos = M_GetTokenPos(); + + if (tkn && pos < size) + { + terrain_t *t = K_GetTerrainByName(tkn); + + if (t == NULL) + { + CONS_Alert(CONS_ERROR, "Invalid Terrain type '%s'.\n", tkn); + valid = false; + } + else + { + f->terrainID = (t - terrainDefs); + CONS_Printf("Texture '%s' set to Terrain '%s'\n", f->textureName, tkn); + } + } + else + { + CONS_Alert(CONS_ERROR, "No terrain for floor definition.\n"); + valid = false; + } + } + else + { + CONS_Alert(CONS_ERROR, "No texture for floor definition.\n"); + valid = false; + } + } + else + { + CONS_Alert(CONS_ERROR, "No texture for floor definition.\n"); + valid = false; + } + } else if (stricmp(tkn, "defaultTerrain") == 0) { Z_Free(tkn); @@ -398,13 +474,13 @@ static boolean K_TERRAINLumpParser(UINT8 *data, size_t size) defaultTerrain = i; } } - // TODO: the other block types! else { CONS_Alert(CONS_ERROR, "No DefaultTerrain type.\n"); valid = false; } } + // TODO: splash & footstep blocks else { CONS_Alert(CONS_ERROR, "Unknown field '%s' found in TERRAIN lump.\n", tkn); diff --git a/src/k_terrain.h b/src/k_terrain.h index 5660c0d4b..e42a2ada2 100644 --- a/src/k_terrain.h +++ b/src/k_terrain.h @@ -58,9 +58,6 @@ typedef struct terrain_s char name[TERRAIN_NAME_LEN]; // Lookup name. - INT32 *textureIDs; // Texture nums this terrain applies to. (Doesn't support flats, stop using them already.) - UINT32 numTextureIDs; // Length of the above table. - UINT16 splashID; // Splash defintion ID. UINT16 footstepID; // Footstep defintion ID. @@ -71,6 +68,19 @@ typedef struct terrain_s UINT32 flags; // Flag values (see: terrain_flags_t) } terrain_t; +typedef struct t_floor_s +{ + // Terrain floor definition. + // Ties texture names to a . + + // (Could be optimized by using texture IDs instead of names, + // but was concerned because I recall sooomething about those not being netsafe? + // Someone confirm if I just hallucinated that. :V) + + char textureName[9]; // Floor texture name. + UINT16 terrainID; // Terrain definition ID. +} t_floor_t; + // Arrays for all terrain definitions. extern t_splash_t *splashDefs; extern UINT16 numSplashDefs; @@ -81,14 +91,17 @@ extern UINT16 numFootstepDefs; extern terrain_t *terrainDefs; extern UINT16 numTerrainDefs; +extern t_floor_t *terrainFloorDefs; +extern UINT16 numTerrainFloorDefs; + // Default terrain definition ID. extern UINT16 defaultTerrain; terrain_t *K_GetTerrainByIndex(UINT16 checkIndex); terrain_t *K_GetTerrainByName(const char *checkName); terrain_t *K_GetDefaultTerrain(void); -terrain_t *K_GetTerrainForTextureNum(INT32 textureNum); terrain_t *K_GetTerrainForTextureName(const char *checkName); +terrain_t *K_GetTerrainForTextureNum(INT32 textureNum); void K_UpdateMobjTerrain(mobj_t *mo, INT32 flatID); void K_SetDefaultFriction(mobj_t *mo); From d7a8ec9fbde39a86187032d25323de703f799b65 Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Thu, 9 Dec 2021 02:37:44 -0500 Subject: [PATCH 06/29] Liquid terrain functions --- src/p_mobj.c | 119 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 92 insertions(+), 27 deletions(-) diff --git a/src/p_mobj.c b/src/p_mobj.c index 87ea3d9b5..8bbd90f51 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -3042,27 +3042,78 @@ void P_MobjCheckWater(mobj_t *mobj) } } + if (mobj->terrain != NULL) + { + if (mobj->terrain->flags & TRF_LIQUID) + { + // This floor is water. + mobj->eflags |= MFE_TOUCHWATER; + + if (mobj->eflags & MFE_VERTICALFLIP) + { + mobj->watertop = thingtop + height; + mobj->waterbottom = thingtop; + } + else + { + mobj->watertop = mobj->z; + mobj->waterbottom = mobj->z - height; + } + } + } + // Spectators and dead players don't get to do any of the things after this. if (p && (p->spectator || p->playerstate != PST_LIVE)) + { return; + } // The rest of this code only executes on a water state change. if (waterwasnotset || !!(mobj->eflags & MFE_UNDERWATER) == wasinwater) + { return; + } if ((p) // Players || (mobj->flags & MF_PUSHABLE) // Pushables || ((mobj->info->flags & MF_PUSHABLE) && mobj->fuse) // Previously pushable, might be moving still ) { + fixed_t waterZ = INT32_MAX; + fixed_t solidZ = INT32_MAX; + fixed_t diff = INT32_MAX; + + fixed_t thingZ = INT32_MAX; + boolean splashValid = false; + + if (mobj->eflags & MFE_VERTICALFLIP) + { + waterZ = mobj->waterbottom; + solidZ = mobj->ceilingz; + } + else + { + waterZ = mobj->watertop; + solidZ = mobj->floorz; + } + + diff = waterZ - solidZ; + if (mobj->eflags & MFE_VERTICALFLIP) + { + diff = -diff; + } + // Check to make sure you didn't just cross into a sector to jump out of // that has shallower water than the block you were originally in. - if ((!(mobj->eflags & MFE_VERTICALFLIP) && mobj->watertop-mobj->floorz <= height>>1) - || ((mobj->eflags & MFE_VERTICALFLIP) && mobj->ceilingz-mobj->waterbottom <= height>>1)) + if (diff <= (height >> 1)) + { return; + } - if (mobj->eflags & MFE_GOOWATER || wasingoo) { // Decide what happens to your momentum when you enter/leave goopy water. - if (P_MobjFlip(mobj)*mobj->momz > 0) + if (mobj->eflags & MFE_GOOWATER || wasingoo) + { + // Decide what happens to your momentum when you enter/leave goopy water. + if (P_MobjFlip(mobj) * mobj->momz > 0) { mobj->momz -= (mobj->momz/8); // cut momentum a little bit to prevent multiple bobs //CONS_Printf("leaving\n"); @@ -3074,25 +3125,42 @@ void P_MobjCheckWater(mobj_t *mobj) //CONS_Printf("entering\n"); } } - else if (wasinwater && P_MobjFlip(mobj)*mobj->momz > 0) - mobj->momz = FixedMul(mobj->momz, FixedDiv(780*FRACUNIT, 457*FRACUNIT)); // Give the mobj a little out-of-water boost. - - if (P_MobjFlip(mobj)*mobj->momz < 0) + else if (wasinwater && P_MobjFlip(mobj) * mobj->momz > 0) { - if ((mobj->eflags & MFE_VERTICALFLIP && thingtop-(height>>1)-mobj->momz <= mobj->waterbottom) - || (!(mobj->eflags & MFE_VERTICALFLIP) && mobj->z+(height>>1)-mobj->momz >= mobj->watertop)) + // Give the mobj a little out-of-water boost. + mobj->momz = FixedMul(mobj->momz, FixedDiv(780*FRACUNIT, 457*FRACUNIT)); + } + + if (mobj->eflags & MFE_VERTICALFLIP) + { + thingZ = thingtop - (height >> 1); + splashValid = (thingZ - mobj->momz <= waterZ); + } + else + { + thingZ = mobj->z + (height >> 1); + splashValid = (thingZ - mobj->momz >= waterZ); + } + + if (P_MobjFlip(mobj) * mobj->momz <= 0) + { + if (splashValid == true) { // Spawn a splash mobj_t *splish; mobjtype_t splishtype = (mobj->eflags & MFE_TOUCHLAVA) ? MT_LAVASPLISH : MT_SPLISH; + if (mobj->eflags & MFE_VERTICALFLIP) { - splish = P_SpawnMobj(mobj->x, mobj->y, mobj->waterbottom-FixedMul(mobjinfo[splishtype].height, mobj->scale), splishtype); + splish = P_SpawnMobj(mobj->x, mobj->y, waterZ - FixedMul(mobjinfo[splishtype].height, mobj->scale), splishtype); splish->flags2 |= MF2_OBJECTFLIP; splish->eflags |= MFE_VERTICALFLIP; } else - splish = P_SpawnMobj(mobj->x, mobj->y, mobj->watertop, splishtype); + { + splish = P_SpawnMobj(mobj->x, mobj->y, waterZ, splishtype); + } + splish->destscale = mobj->scale; P_SetScale(splish, mobj->scale); } @@ -3101,40 +3169,37 @@ void P_MobjCheckWater(mobj_t *mobj) if (p && p->waterskip < 2 && ((p->speed/3 > abs(mobj->momz)) // Going more forward than horizontal, so you can skip across the water. || (p->speed > 20*mapobjectscale && p->waterskip)) // Already skipped once, so you can skip once more! - && ((!(mobj->eflags & MFE_VERTICALFLIP) && thingtop - mobj->momz > mobj->watertop) - || ((mobj->eflags & MFE_VERTICALFLIP) && mobj->z - mobj->momz < mobj->waterbottom))) + && (splashValid == true)) { - const fixed_t hop = 5<scale; mobj->momx = (4*mobj->momx)/5; mobj->momy = (4*mobj->momy)/5; - - if (mobj->eflags & MFE_VERTICALFLIP) - mobj->momz = FixedMul(-hop, mobj->scale); - else - mobj->momz = FixedMul(hop, mobj->scale); + mobj->momz = hop * P_MobjFlip(mobj); p->waterskip++; } } - else if (P_MobjFlip(mobj)*mobj->momz > 0) + else if (P_MobjFlip(mobj) * mobj->momz > 0) { - if (((mobj->eflags & MFE_VERTICALFLIP && thingtop-(height>>1)-mobj->momz > mobj->waterbottom) - || (!(mobj->eflags & MFE_VERTICALFLIP) && mobj->z+(height>>1)-mobj->momz < mobj->watertop)) - && !(mobj->eflags & MFE_UNDERWATER)) // underwater check to prevent splashes on opposite side + if (splashValid == true && !(mobj->eflags & MFE_UNDERWATER)) // underwater check to prevent splashes on opposite side { // Spawn a splash mobj_t *splish; mobjtype_t splishtype = (mobj->eflags & MFE_TOUCHLAVA) ? MT_LAVASPLISH : MT_SPLISH; + if (mobj->eflags & MFE_VERTICALFLIP) { - splish = P_SpawnMobj(mobj->x, mobj->y, mobj->waterbottom-FixedMul(mobjinfo[splishtype].height, mobj->scale), splishtype); + splish = P_SpawnMobj(mobj->x, mobj->y, waterZ - FixedMul(mobjinfo[splishtype].height, mobj->scale), splishtype); splish->flags2 |= MF2_OBJECTFLIP; splish->eflags |= MFE_VERTICALFLIP; } else - splish = P_SpawnMobj(mobj->x, mobj->y, mobj->watertop, splishtype); + { + splish = P_SpawnMobj(mobj->x, mobj->y, waterZ, splishtype); + } + splish->destscale = mobj->scale; P_SetScale(splish, mobj->scale); } @@ -3155,7 +3220,7 @@ void P_MobjCheckWater(mobj_t *mobj) else S_StartSound(mobj, sfx_splish); // And make a sound! - bubblecount = FixedDiv(abs(mobj->momz), mobj->scale)>>(FRACBITS-1); + bubblecount = FixedDiv(abs(mobj->momz), mobj->scale) >> (FRACBITS-1); // Max bubble count if (bubblecount > 128) bubblecount = 128; From e212f947adc729a1ee38708936436ec63ad78a8b Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Thu, 9 Dec 2021 03:20:45 -0500 Subject: [PATCH 07/29] Implement the sector special-like effects Offroad, sneaker panels, trick panels, and damaging floors can now be set via terrain. --- src/k_kart.c | 14 ++++++- src/k_terrain.c | 99 ++++++++++++++++++++++++++++++++++++++++++++----- src/k_terrain.h | 2 + src/p_spec.c | 4 ++ src/r_bsp.c | 32 ++++++++++++++-- 5 files changed, 137 insertions(+), 14 deletions(-) diff --git a/src/k_kart.c b/src/k_kart.c index cf51e3646..e880181e5 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -33,6 +33,7 @@ #include "k_waypoint.h" #include "k_bot.h" #include "k_hud.h" +#include "k_terrain.h" // SOME IMPORTANT VARIABLES DEFINED IN DOOMDEF.H: // gamespeed is cc (0 for easy, 1 for normal, 2 for hard) @@ -1605,6 +1606,7 @@ static UINT8 K_CheckOffroadCollide(mobj_t *mo) } } + return 0; // couldn't find any offroad } @@ -1616,7 +1618,17 @@ static UINT8 K_CheckOffroadCollide(mobj_t *mo) */ static void K_UpdateOffroad(player_t *player) { - fixed_t offroadstrength = (K_CheckOffroadCollide(player->mo) << FRACBITS); + terrain_t *terrain = player->mo->terrain; + fixed_t offroadstrength = 0; + + if (terrain != NULL && terrain->offroad > 0) + { + offroadstrength = (terrain->offroad << FRACBITS); + } + else + { + offroadstrength = (K_CheckOffroadCollide(player->mo) << FRACBITS); + } // If you are in offroad, a timer starts. if (offroadstrength) diff --git a/src/k_terrain.c b/src/k_terrain.c index a2b09158d..b8edebf03 100644 --- a/src/k_terrain.c +++ b/src/k_terrain.c @@ -25,6 +25,8 @@ #include "w_wad.h" #include "z_zone.h" +#include "k_kart.h" // on the chopping block... + t_splash_t *splashDefs = NULL; UINT16 numSplashDefs = 0; @@ -119,20 +121,25 @@ terrain_t *K_GetTerrainForTextureNum(INT32 textureNum) return K_GetTerrainForTextureName(tex->name); } -void K_UpdateMobjTerrain(mobj_t *mo, INT32 flatID) +terrain_t *K_GetTerrainForFlatNum(INT32 flatID) { levelflat_t *levelFlat = NULL; - if (mo == NULL || P_MobjWasRemoved(mo) == true) - { - // Invalid object. - return; - } - if (flatID < 0 || flatID >= (signed)numlevelflats) { // Clearly invalid floor... - mo->terrain = NULL; + return NULL; + } + + levelFlat = &levelflats[flatID]; + return K_GetTerrainForTextureName(levelFlat->name); +} + +void K_UpdateMobjTerrain(mobj_t *mo, INT32 flatID) +{ + if (mo == NULL || P_MobjWasRemoved(mo) == true) + { + // Invalid object. return; } @@ -144,12 +151,84 @@ void K_UpdateMobjTerrain(mobj_t *mo, INT32 flatID) } // Update the object's terrain pointer. - levelFlat = &levelflats[flatID]; - mo->terrain = K_GetTerrainForTextureName(levelFlat->name); + mo->terrain = K_GetTerrainForFlatNum(flatID); +} + +void K_ProcessTerrainEffect(mobj_t *mo) +{ + player_t *player = NULL; + terrain_t *terrain = NULL; + + if (mo == NULL || P_MobjWasRemoved(mo) == true) + { + // Invalid object. + return; + } + + if (mo->terrain == NULL) + { + // No terrain type. + return; + } + + terrain = mo->terrain; + player = mo->player; + + if (player == NULL) + { + // maybe can support regualar mobjs later? :) + return; + } + + // Damage effects + if (terrain->damageType > 0) + { + UINT8 dmg = (terrain->damageType & 0xFF); + P_DamageMobj(mo, NULL, NULL, 1, dmg); + } + + // Sneaker panel + if (terrain->flags & TRF_SNEAKERPANEL) + { + if (!player->floorboost) + player->floorboost = 3; + else + player->floorboost = 2; + + K_DoSneaker(player, 0); + } + + // Trick panel + if (terrain->trickPanel > 0 && !(mo->eflags & MFE_SPRUNG)) + { + const fixed_t hscale = mapobjectscale + (mapobjectscale - mo->scale); + const fixed_t minspeed = 24*hscale; + fixed_t speed = FixedHypot(mo->momx, mo->momy); + fixed_t upwards = 16 * FRACUNIT * terrain->trickPanel; + + player->trickpanel = 1; + player->pflags |= PF_TRICKDELAY; + K_DoPogoSpring(mo, upwards, 1); + + if (speed < minspeed) + { + speed = minspeed; + } + + P_InstaThrust(mo, mo->angle, speed); + } + + // (Offroad is handled elsewhere!) } void K_SetDefaultFriction(mobj_t *mo) { + if (mo == NULL || P_MobjWasRemoved(mo) == true) + { + // Invalid object. + return; + } + mo->friction = ORIG_FRICTION; if (mo->player != NULL) diff --git a/src/k_terrain.h b/src/k_terrain.h index e42a2ada2..600656522 100644 --- a/src/k_terrain.h +++ b/src/k_terrain.h @@ -102,8 +102,10 @@ terrain_t *K_GetTerrainByName(const char *checkName); terrain_t *K_GetDefaultTerrain(void); terrain_t *K_GetTerrainForTextureName(const char *checkName); terrain_t *K_GetTerrainForTextureNum(INT32 textureNum); +terrain_t *K_GetTerrainForFlatNum(INT32 flatID); void K_UpdateMobjTerrain(mobj_t *mo, INT32 flatID); +void K_ProcessTerrainEffect(mobj_t *mo); void K_SetDefaultFriction(mobj_t *mo); void K_InitTerrain(UINT16 wadNum); diff --git a/src/p_spec.c b/src/p_spec.c index 07825759c..db615fb4f 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -43,6 +43,7 @@ #include "k_kart.h" #include "console.h" // CON_LogMessage #include "k_respawn.h" +#include "k_terrain.h" #ifdef HW3SOUND #include "hardware/hw3sound.h" @@ -4333,7 +4334,9 @@ void P_ProcessSpecialSector(player_t *player, sector_t *sector, sector_t *rovers // Conveyor stuff if (section3 == 2 || section3 == 4) + { player->onconveyor = section3; + } special = section1; @@ -5050,6 +5053,7 @@ void P_PlayerInSpecialSector(player_t *player) if (!player->mo) return; + K_ProcessTerrainEffect(player->mo); originalsector = player->mo->subsector->sector; P_PlayerOnSpecial3DFloor(player, originalsector); // Handle FOFs first. diff --git a/src/r_bsp.c b/src/r_bsp.c index e9d51c03a..6095f3739 100644 --- a/src/r_bsp.c +++ b/src/r_bsp.c @@ -23,6 +23,8 @@ #include "z_zone.h" // Check R_Prep3DFloors #include "taglist.h" +#include "k_terrain.h" + seg_t *curline; side_t *sidedef; line_t *linedef; @@ -67,11 +69,35 @@ boolean R_IsRipplePlane(sector_t *sector, ffloor_t *rover, int ceiling) static void R_PlaneLightOverride(sector_t *sector, boolean ceiling, INT32 *lightlevel) { - if (GETSECSPECIAL(sector->special, 4) == 6) // Fullbright sneaker panels + terrain_t *t = NULL; + + if (ceiling == true) { - if ((ceiling && (sector->flags & SF_FLIPSPECIAL_CEILING)) - || (!ceiling && (sector->flags & SF_FLIPSPECIAL_FLOOR))) + t = K_GetTerrainForFlatNum(sector->ceilingpic); + } + else + { + t = K_GetTerrainForFlatNum(sector->floorpic); + } + + if (t != NULL) + { + if (t->flags & TRF_SNEAKERPANEL) + { *lightlevel = 255; + } + } + else + { + // Sector effect sneaker panels (DEPRECATED) + if (GETSECSPECIAL(sector->special, 4) == 6) + { + if ((ceiling && (sector->flags & SF_FLIPSPECIAL_CEILING)) + || (!ceiling && (sector->flags & SF_FLIPSPECIAL_FLOOR))) + { + *lightlevel = 255; + } + } } } From b1ffaa99f84fdf0a4cdd23d43b72220a39ad2093 Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Thu, 9 Dec 2021 13:20:35 -0500 Subject: [PATCH 08/29] Sync mobj->terrain This should be enough I think to sync terrain up. The data structures can't change after the files have been loaded, so it should be good. Needs proper online testing though --- src/k_terrain.c | 21 +++++++++++++++++++++ src/k_terrain.h | 1 + src/p_saveg.c | 16 ++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/src/k_terrain.c b/src/k_terrain.c index b8edebf03..8c55ac4f2 100644 --- a/src/k_terrain.c +++ b/src/k_terrain.c @@ -41,6 +41,27 @@ UINT16 numTerrainFloorDefs = 0; UINT16 defaultTerrain = UINT16_MAX; +/*-------------------------------------------------- + size_t K_GetTerrainHeapIndex(terrain_t *terrain) + + See header file for description. +--------------------------------------------------*/ +size_t K_GetTerrainHeapIndex(terrain_t *terrain) +{ + size_t i = SIZE_MAX; + + if (terrain == NULL) + { + CONS_Debug(DBG_GAMELOGIC, "NULL terrain in K_GetTerrainHeapIndex.\n"); + } + else + { + i = (terrain - terrainDefs); + } + + return i; +} + terrain_t *K_GetTerrainByIndex(UINT16 checkIndex) { if (checkIndex >= numTerrainDefs) diff --git a/src/k_terrain.h b/src/k_terrain.h index 600656522..c5bf51168 100644 --- a/src/k_terrain.h +++ b/src/k_terrain.h @@ -97,6 +97,7 @@ extern UINT16 numTerrainFloorDefs; // Default terrain definition ID. extern UINT16 defaultTerrain; +size_t K_GetTerrainHeapIndex(terrain_t *terrain); terrain_t *K_GetTerrainByIndex(UINT16 checkIndex); terrain_t *K_GetTerrainByName(const char *checkName); terrain_t *K_GetDefaultTerrain(void); diff --git a/src/p_saveg.c b/src/p_saveg.c index 39a4fec28..bfa6d6e15 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -38,6 +38,7 @@ // SRB2Kart #include "k_battle.h" #include "k_pwrlv.h" +#include "k_terrain.h" savedata_t savedata; UINT8 *save_p; @@ -1540,6 +1541,7 @@ typedef enum MD2_KITEMCAP = 1<<26, MD2_ITNEXT = 1<<27, MD2_LASTMOMZ = 1<<28, + MD2_TERRAIN = 1<<29, } mobj_diff2_t; typedef enum @@ -1782,6 +1784,8 @@ static void SaveMobjThinker(const thinker_t *th, const UINT8 type) diff2 |= MD2_ITNEXT; if (mobj->lastmomz) diff2 |= MD2_LASTMOMZ; + if (mobj->terrain != NULL) + diff2 |= MD2_TERRAIN; if (diff2 != 0) diff |= MD_MORE; @@ -1979,6 +1983,10 @@ static void SaveMobjThinker(const thinker_t *th, const UINT8 type) { WRITEINT32(save_p, mobj->lastmomz); } + if (diff2 & MD2_TERRAIN) + { + WRITEUINT32(save_p, K_GetTerrainHeapIndex(mobj->terrain)); + } WRITEUINT32(save_p, mobj->mobjnum); } @@ -3077,6 +3085,14 @@ static thinker_t* LoadMobjThinker(actionf_p1 thinker) { mobj->lastmomz = READINT32(save_p); } + if (diff2 & MD2_TERRAIN) + { + mobj->terrain = (terrain_t *)(size_t)READUINT32(save_p); + } + else + { + mobj->terrain = NULL; + } if (diff & MD_REDFLAG) { From 35a72e56dc691dbac149bf07b4e0a8a44c047e7c Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Thu, 9 Dec 2021 14:45:59 -0500 Subject: [PATCH 09/29] Implement splash & footstep blocks, commentate more of the code They do nothing atm, but they can be set properly now :) --- src/k_terrain.c | 578 +++++++++++++++++++++++++++++++++++++++++++----- src/k_terrain.h | 330 +++++++++++++++++++++++++-- src/p_user.c | 4 - 3 files changed, 839 insertions(+), 73 deletions(-) diff --git a/src/k_terrain.c b/src/k_terrain.c index 8c55ac4f2..9ba13757d 100644 --- a/src/k_terrain.c +++ b/src/k_terrain.c @@ -14,6 +14,7 @@ #include "k_terrain.h" #include "dehacked.h" // get_number +#include "deh_soc.h" // get_mobjtype #include "doomdata.h" #include "doomdef.h" #include "doomtype.h" @@ -27,19 +28,155 @@ #include "k_kart.h" // on the chopping block... -t_splash_t *splashDefs = NULL; -UINT16 numSplashDefs = 0; +static t_splash_t *splashDefs = NULL; +static size_t numSplashDefs = 0; -t_footstep_t *footstepDefs = NULL; -UINT16 numFootstepDefs = 0; +static t_footstep_t *footstepDefs = NULL; +static size_t numFootstepDefs = 0; -terrain_t *terrainDefs = NULL; -UINT16 numTerrainDefs = 0; +static terrain_t *terrainDefs = NULL; +static size_t numTerrainDefs = 0; -t_floor_t *terrainFloorDefs = NULL; -UINT16 numTerrainFloorDefs = 0; +static t_floor_t *terrainFloorDefs = NULL; +static size_t numTerrainFloorDefs = 0; -UINT16 defaultTerrain = UINT16_MAX; +static size_t defaultTerrain = SIZE_MAX; + +/*-------------------------------------------------- + size_t K_GetSplashHeapIndex(t_splash_t *splash) + + See header file for description. +--------------------------------------------------*/ +size_t K_GetSplashHeapIndex(t_splash_t *splash) +{ + if (splash == NULL) + { + return SIZE_MAX; + } + + return (splash - splashDefs); +} + +/*-------------------------------------------------- + size_t K_GetNumSplashDefs(void) + + See header file for description. +--------------------------------------------------*/ +size_t K_GetNumSplashDefs(void) +{ + return numSplashDefs; +} + +/*-------------------------------------------------- + t_splash_t *K_GetSplashByIndex(size_t checkIndex) + + See header file for description. +--------------------------------------------------*/ +t_splash_t *K_GetSplashByIndex(size_t checkIndex) +{ + if (checkIndex >= numSplashDefs) + { + return NULL; + } + + return &splashDefs[checkIndex]; +} + +/*-------------------------------------------------- + t_splash_t *K_GetSplashByName(const char *checkName) + + See header file for description. +--------------------------------------------------*/ +t_splash_t *K_GetSplashByName(const char *checkName) +{ + size_t i; + + if (numSplashDefs == 0) + { + return NULL; + } + + for (i = 0; i < numSplashDefs; i++) + { + t_splash_t *s = &splashDefs[i]; + + if (stricmp(checkName, s->name) == 0) + { + // Name matches. + return s; + } + } + + return NULL; +} + +/*-------------------------------------------------- + size_t K_GetFootstepHeapIndex(t_footstep_t *footstep) + + See header file for description. +--------------------------------------------------*/ +size_t K_GetFootstepHeapIndex(t_footstep_t *footstep) +{ + if (footstep == NULL) + { + return SIZE_MAX; + } + + return (footstep - footstepDefs); +} + +/*-------------------------------------------------- + size_t K_GetNumFootstepDefs(void) + + See header file for description. +--------------------------------------------------*/ +size_t K_GetNumFootstepDefs(void) +{ + return numFootstepDefs; +} + +/*-------------------------------------------------- + t_footstep_t *K_GetFootstepByIndex(size_t checkIndex) + + See header file for description. +--------------------------------------------------*/ +t_footstep_t *K_GetFootstepByIndex(size_t checkIndex) +{ + if (checkIndex >= numFootstepDefs) + { + return NULL; + } + + return &footstepDefs[checkIndex]; +} + +/*-------------------------------------------------- + t_footstep_t *K_GetFootstepByName(const char *checkName) + + See header file for description. +--------------------------------------------------*/ +t_footstep_t *K_GetFootstepByName(const char *checkName) +{ + size_t i; + + if (numFootstepDefs == 0) + { + return NULL; + } + + for (i = 0; i < numFootstepDefs; i++) + { + t_footstep_t *fs = &footstepDefs[i]; + + if (stricmp(checkName, fs->name) == 0) + { + // Name matches. + return fs; + } + } + + return NULL; +} /*-------------------------------------------------- size_t K_GetTerrainHeapIndex(terrain_t *terrain) @@ -48,21 +185,30 @@ UINT16 defaultTerrain = UINT16_MAX; --------------------------------------------------*/ size_t K_GetTerrainHeapIndex(terrain_t *terrain) { - size_t i = SIZE_MAX; - if (terrain == NULL) { - CONS_Debug(DBG_GAMELOGIC, "NULL terrain in K_GetTerrainHeapIndex.\n"); - } - else - { - i = (terrain - terrainDefs); + return SIZE_MAX; } - return i; + return (terrain - terrainDefs); } -terrain_t *K_GetTerrainByIndex(UINT16 checkIndex) +/*-------------------------------------------------- + size_t K_GetNumTerrainDefs(void) + + See header file for description. +--------------------------------------------------*/ +size_t K_GetNumTerrainDefs(void) +{ + return numTerrainDefs; +} + +/*-------------------------------------------------- + terrain_t *K_GetTerrainByIndex(size_t checkIndex) + + See header file for description. +--------------------------------------------------*/ +terrain_t *K_GetTerrainByIndex(size_t checkIndex) { if (checkIndex >= numTerrainDefs) { @@ -72,18 +218,21 @@ terrain_t *K_GetTerrainByIndex(UINT16 checkIndex) return &terrainDefs[checkIndex]; } +/*-------------------------------------------------- + terrain_t *K_GetTerrainByName(const char *checkName) + + See header file for description. +--------------------------------------------------*/ terrain_t *K_GetTerrainByName(const char *checkName) { - INT32 i; + size_t i; if (numTerrainDefs == 0) { return NULL; } - // Search backwards through all terrain definitions. - // The latest one will have priority over the older one. - for (i = numTerrainDefs-1; i >= 0; i--) + for (i = 0; i < numTerrainDefs; i++) { terrain_t *t = &terrainDefs[i]; @@ -97,23 +246,30 @@ terrain_t *K_GetTerrainByName(const char *checkName) return NULL; } +/*-------------------------------------------------- + terrain_t *K_GetDefaultTerrain(void) + + See header file for description. +--------------------------------------------------*/ terrain_t *K_GetDefaultTerrain(void) { return K_GetTerrainByIndex(defaultTerrain); } +/*-------------------------------------------------- + terrain_t *K_GetTerrainForTextureName(const char *checkName) + + See header file for description. +--------------------------------------------------*/ terrain_t *K_GetTerrainForTextureName(const char *checkName) { - INT32 i; + size_t i; if (numTerrainFloorDefs == 0) { return NULL; } - // Search backwards through all terrain definitions. - // The latest one will have priority over the older one. - for (i = 0; i < numTerrainFloorDefs; i++) { t_floor_t *f = &terrainFloorDefs[i]; @@ -129,6 +285,11 @@ terrain_t *K_GetTerrainForTextureName(const char *checkName) return K_GetDefaultTerrain(); } +/*-------------------------------------------------- + terrain_t *K_GetTerrainForTextureNum(INT32 textureNum) + + See header file for description. +--------------------------------------------------*/ terrain_t *K_GetTerrainForTextureNum(INT32 textureNum) { texture_t *tex = NULL; @@ -142,6 +303,11 @@ terrain_t *K_GetTerrainForTextureNum(INT32 textureNum) return K_GetTerrainForTextureName(tex->name); } +/*-------------------------------------------------- + terrain_t *K_GetTerrainForFlatNum(INT32 flatID) + + See header file for description. +--------------------------------------------------*/ terrain_t *K_GetTerrainForFlatNum(INT32 flatID) { levelflat_t *levelFlat = NULL; @@ -156,6 +322,11 @@ terrain_t *K_GetTerrainForFlatNum(INT32 flatID) return K_GetTerrainForTextureName(levelFlat->name); } +/*-------------------------------------------------- + void K_UpdateMobjTerrain(mobj_t *mo, INT32 flatID) + + See header file for description. +--------------------------------------------------*/ void K_UpdateMobjTerrain(mobj_t *mo, INT32 flatID) { if (mo == NULL || P_MobjWasRemoved(mo) == true) @@ -175,6 +346,11 @@ void K_UpdateMobjTerrain(mobj_t *mo, INT32 flatID) mo->terrain = K_GetTerrainForFlatNum(flatID); } +/*-------------------------------------------------- + void K_ProcessTerrainEffect(mobj_t *mo) + + See header file for description. +--------------------------------------------------*/ void K_ProcessTerrainEffect(mobj_t *mo) { player_t *player = NULL; @@ -242,17 +418,26 @@ void K_ProcessTerrainEffect(mobj_t *mo) // (Offroad is handled elsewhere!) } +/*-------------------------------------------------- + void K_SetDefaultFriction(mobj_t *mo) + + See header file for description. +--------------------------------------------------*/ void K_SetDefaultFriction(mobj_t *mo) { + boolean isPlayer = false; + if (mo == NULL || P_MobjWasRemoved(mo) == true) { // Invalid object. return; } + isPlayer = (mo->player != NULL); + mo->friction = ORIG_FRICTION; - if (mo->player != NULL) + if (isPlayer == true) { mo->movefactor = FRACUNIT; } @@ -266,7 +451,7 @@ void K_SetDefaultFriction(mobj_t *mo) if (strength > 0) // sludge { - strength = strength*2; // otherwise, the maximum sludginess value is +967... + strength = strength * 2; // otherwise, the maximum sludginess value is +967... } // The following might seem odd. At the time of movement, @@ -284,26 +469,40 @@ void K_SetDefaultFriction(mobj_t *mo) newFriction = 0; } - newMovefactor = FixedDiv(ORIG_FRICTION, newFriction); - - if (newMovefactor < FRACUNIT) - { - newMovefactor = 19*newMovefactor - 18*FRACUNIT; - } - else - { - newMovefactor = FRACUNIT; - } - mo->friction = newFriction; - mo->movefactor = newMovefactor; + + if (isPlayer == true) + { + newMovefactor = FixedDiv(ORIG_FRICTION, newFriction); + + if (newMovefactor < FRACUNIT) + { + newMovefactor = 19*newMovefactor - 18*FRACUNIT; + } + else + { + newMovefactor = FRACUNIT; + } + + mo->movefactor = newMovefactor; + } } } -// -// Parser code starts here. -// +/*-------------------------------------------------- + static void K_FlagBoolean(UINT32 *inputFlags, UINT32 newFlag, char *val) + Sets a flag to true or false depending on + the string input. + + Input Arguments:- + inputFlags - Pointer to flags value to modify. + newFlag - The flag(s) to set / unset. + val - The string input from the file. + + Return:- + None +--------------------------------------------------*/ static void K_FlagBoolean(UINT32 *inputFlags, UINT32 newFlag, char *val) { if (stricmp(val, "true") == 0) @@ -316,10 +515,147 @@ static void K_FlagBoolean(UINT32 *inputFlags, UINT32 newFlag, char *val) } } +/*-------------------------------------------------- + static void K_SplashDefaults(t_splash_t *splash) + + Sets the defaults for a new Splash block. + + Input Arguments:- + splash - Terrain Splash structure to default. + + Return:- + None +--------------------------------------------------*/ +static void K_SplashDefaults(t_splash_t *splash) +{ + splash->mobjType = MT_NULL; + splash->sfx = sfx_None; +} + +/*-------------------------------------------------- + static void K_NewSplashDefs(void) + + Increases the size of splashDefs by 1, and + sets the new struct's values to their defaults. + + Input Arguments:- + None + + Return:- + None +--------------------------------------------------*/ +static void K_NewSplashDefs(void) +{ + numSplashDefs++; + splashDefs = (t_splash_t *)Z_Realloc(splashDefs, sizeof(t_splash_t) * (numSplashDefs + 1), PU_STATIC, NULL); + K_SplashDefaults( &splashDefs[numSplashDefs - 1] ); +} + +/*-------------------------------------------------- + static void K_ParseSplashParameter(size_t i, char *param, char *val) + + Parser function for Splash blocks. + + Input Arguments:- + i - Struct ID + param - Parameter string + val - Value string + + Return:- + None +--------------------------------------------------*/ +static void K_ParseSplashParameter(size_t i, char *param, char *val) +{ + t_splash_t *splash = &splashDefs[i]; + + if (stricmp(param, "mobjType") == 0) + { + splash->mobjType = get_mobjtype(val); + } + else if (stricmp(param, "sfx") == 0) + { + splash->sfx = get_sfx(val); + } +} + +/*-------------------------------------------------- + static void K_FootstepDefaults(t_footstep_t *footstep) + + Sets the defaults for a new Footstep block. + + Input Arguments:- + footstep - Terrain Footstep structure to default. + + Return:- + None +--------------------------------------------------*/ +static void K_FootstepDefaults(t_footstep_t *footstep) +{ + footstep->mobjType = MT_NULL; + footstep->sfx = sfx_None; +} + +/*-------------------------------------------------- + static void K_NewFootstepDefs(void) + + Increases the size of footstepDefs by 1, and + sets the new struct's values to their defaults. + + Input Arguments:- + None + + Return:- + None +--------------------------------------------------*/ +static void K_NewFootstepDefs(void) +{ + numFootstepDefs++; + footstepDefs = (t_footstep_t *)Z_Realloc(footstepDefs, sizeof(t_footstep_t) * (numFootstepDefs + 1), PU_STATIC, NULL); + K_FootstepDefaults( &footstepDefs[numFootstepDefs - 1] ); +} + +/*-------------------------------------------------- + static void K_ParseFootstepParameter(size_t i, char *param, char *val) + + Parser function for Footstep blocks. + + Input Arguments:- + i - Struct ID + param - Parameter string + val - Value string + + Return:- + None +--------------------------------------------------*/ +static void K_ParseFootstepParameter(size_t i, char *param, char *val) +{ + t_footstep_t *footstep = &footstepDefs[i]; + + if (stricmp(param, "mobjType") == 0) + { + footstep->mobjType = get_mobjtype(val); + } + else if (stricmp(param, "sfx") == 0) + { + footstep->sfx = get_sfx(val); + } +} + +/*-------------------------------------------------- + static void K_TerrainDefaults(terrain_t *terrain) + + Sets the defaults for a new Terrain block. + + Input Arguments:- + terrain - Terrain structure to default. + + Return:- + None +--------------------------------------------------*/ static void K_TerrainDefaults(terrain_t *terrain) { - terrain->splashID = UINT16_MAX; - terrain->footstepID = UINT16_MAX; + terrain->splashID = SIZE_MAX; + terrain->footstepID = SIZE_MAX; terrain->friction = FRACUNIT; terrain->offroad = 0; @@ -328,6 +664,18 @@ static void K_TerrainDefaults(terrain_t *terrain) terrain->flags = 0; } +/*-------------------------------------------------- + static void K_NewTerrainDefs(void) + + Increases the size of terrainDefs by 1, and + sets the new struct's values to their defaults. + + Input Arguments:- + None + + Return:- + None +--------------------------------------------------*/ static void K_NewTerrainDefs(void) { numTerrainDefs++; @@ -335,17 +683,32 @@ static void K_NewTerrainDefs(void) K_TerrainDefaults( &terrainDefs[numTerrainDefs - 1] ); } +/*-------------------------------------------------- + static void K_ParseTerrainParameter(UINT32 i, char *param, char *val) + + Parser function for Terrain blocks. + + Input Arguments:- + i - Struct ID + param - Parameter string + val - Value string + + Return:- + None +--------------------------------------------------*/ static void K_ParseTerrainParameter(UINT32 i, char *param, char *val) { terrain_t *terrain = &terrainDefs[i]; if (stricmp(param, "splash") == 0) { - //terrain->splashID = 0; + t_splash_t *splash = K_GetSplashByName(val); + terrain->splashID = K_GetSplashHeapIndex(splash); } else if (stricmp(param, "footstep") == 0) { - //terrain->footstepID = 0; + t_footstep_t *footstep = K_GetFootstepByName(val); + terrain->footstepID = K_GetFootstepHeapIndex(footstep); } else if (stricmp(param, "friction") == 0) { @@ -373,12 +736,37 @@ static void K_ParseTerrainParameter(UINT32 i, char *param, char *val) } } +/*-------------------------------------------------- + static void K_NewTerrainFloorDefs(void) + + Increases the size of numTerrainFloorDefs by 1. + + Input Arguments:- + None + + Return:- + None +--------------------------------------------------*/ static void K_NewTerrainFloorDefs(void) { numTerrainFloorDefs++; terrainFloorDefs = (t_floor_t *)Z_Realloc(terrainFloorDefs, sizeof(t_floor_t) * (numTerrainFloorDefs + 1), PU_STATIC, NULL); } +/*-------------------------------------------------- + static boolean K_DoTERRAINLumpParse(size_t num, void (*parser)(UINT32, char *, char *)) + + Runs another parser function for the TERRAIN + lump, handling the nitty-gritty parts of the + token handling. + + Input Arguments:- + num - Struct ID to modify. Which one it will modify depends on the parser function. + parser - The parser function. Takes three inputs: Struct ID, Parameter String, and Value String. + + Return:- + false if any errors occured, otherwise true. +--------------------------------------------------*/ static boolean K_DoTERRAINLumpParse(size_t num, void (*parser)(UINT32, char *, char *)) { char *param, *val; @@ -414,6 +802,18 @@ static boolean K_DoTERRAINLumpParse(size_t num, void (*parser)(UINT32, char *, c return true; } +/*-------------------------------------------------- + static boolean K_TERRAINLumpParser(UINT8 *data, size_t size) + + Parses inputted lump data as a TERRAIN lump. + + Input Arguments:- + data - Pointer to lump data. + size - The length of the lump data. + + Return:- + false if any errors occured, otherwise true. +--------------------------------------------------*/ static boolean K_TERRAINLumpParser(UINT8 *data, size_t size) { char *tkn = M_GetToken((char *)data); @@ -431,6 +831,80 @@ static boolean K_TERRAINLumpParser(UINT8 *data, size_t size) valid = false; } // Check for valid fields. + else if (stricmp(tkn, "splash") == 0) + { + Z_Free(tkn); + tkn = M_GetToken(NULL); + pos = M_GetTokenPos(); + + if (tkn && pos < size) + { + t_splash_t *s = NULL; + + for (i = 0; i < numSplashDefs; i++) + { + s = &splashDefs[i]; + + if (stricmp(tkn, s->name) == 0) + { + break; + } + } + + if (i == numSplashDefs) + { + K_NewSplashDefs(); + s = &splashDefs[i]; + + strncpy(s->name, tkn, TERRAIN_NAME_LEN); + CONS_Printf("Created new Splash type '%s'\n", s->name); + } + + valid = K_DoTERRAINLumpParse(i, K_ParseSplashParameter); + } + else + { + CONS_Alert(CONS_ERROR, "No Splash type name.\n"); + valid = false; + } + } + else if (stricmp(tkn, "footstep") == 0) + { + Z_Free(tkn); + tkn = M_GetToken(NULL); + pos = M_GetTokenPos(); + + if (tkn && pos < size) + { + t_footstep_t *fs = NULL; + + for (i = 0; i < numFootstepDefs; i++) + { + fs = &footstepDefs[i]; + + if (stricmp(tkn, fs->name) == 0) + { + break; + } + } + + if (i == numFootstepDefs) + { + K_NewFootstepDefs(); + fs = &footstepDefs[i]; + + strncpy(fs->name, tkn, TERRAIN_NAME_LEN); + CONS_Printf("Created new Footstep type '%s'\n", fs->name); + } + + valid = K_DoTERRAINLumpParse(i, K_ParseFootstepParameter); + } + else + { + CONS_Alert(CONS_ERROR, "No Footstep type name.\n"); + valid = false; + } + } else if (stricmp(tkn, "terrain") == 0) { Z_Free(tkn); @@ -464,7 +938,7 @@ static boolean K_TERRAINLumpParser(UINT8 *data, size_t size) } else { - CONS_Alert(CONS_ERROR, "No terrain type name.\n"); + CONS_Alert(CONS_ERROR, "No Terrain type name.\n"); valid = false; } } @@ -522,7 +996,7 @@ static boolean K_TERRAINLumpParser(UINT8 *data, size_t size) } else { - f->terrainID = (t - terrainDefs); + f->terrainID = K_GetTerrainHeapIndex(t); CONS_Printf("Texture '%s' set to Terrain '%s'\n", f->textureName, tkn); } } @@ -580,7 +1054,6 @@ static boolean K_TERRAINLumpParser(UINT8 *data, size_t size) valid = false; } } - // TODO: splash & footstep blocks else { CONS_Alert(CONS_ERROR, "Unknown field '%s' found in TERRAIN lump.\n", tkn); @@ -601,6 +1074,11 @@ static boolean K_TERRAINLumpParser(UINT8 *data, size_t size) return true; } +/*-------------------------------------------------- + void K_InitTerrain(UINT16 wadNum) + + See header file for description. +--------------------------------------------------*/ void K_InitTerrain(UINT16 wadNum) { UINT16 lumpNum; diff --git a/src/k_terrain.h b/src/k_terrain.h index c5bf51168..0e36388ea 100644 --- a/src/k_terrain.h +++ b/src/k_terrain.h @@ -29,8 +29,8 @@ typedef struct t_splash_s char name[TERRAIN_NAME_LEN]; // Lookup name. - UINT16 objType; // Thing type. MT_NULL to not spawn anything. - UINT16 sound; // Sound to play. + UINT16 mobjType; // Thing type. MT_NULL to not spawn anything. + UINT16 sfx; // Sound to play. } t_splash_t; typedef struct t_footstep_s @@ -40,8 +40,8 @@ typedef struct t_footstep_s char name[TERRAIN_NAME_LEN]; // Lookup name. - UINT16 objType; // Thing type. MT_NULL to not spawn anything. - UINT16 sound; // Sound to play. + UINT16 mobjType; // Thing type. MT_NULL to not spawn anything. + UINT16 sfx; // Sound to play. } t_footstep_t; typedef enum @@ -58,8 +58,8 @@ typedef struct terrain_s char name[TERRAIN_NAME_LEN]; // Lookup name. - UINT16 splashID; // Splash defintion ID. - UINT16 footstepID; // Footstep defintion ID. + size_t splashID; // Splash defintion ID. + size_t footstepID; // Footstep defintion ID. fixed_t friction; // The default friction of this texture. UINT8 offroad; // The default offroad level of this texture. @@ -78,37 +78,329 @@ typedef struct t_floor_s // Someone confirm if I just hallucinated that. :V) char textureName[9]; // Floor texture name. - UINT16 terrainID; // Terrain definition ID. + size_t terrainID; // Terrain definition ID. } t_floor_t; -// Arrays for all terrain definitions. -extern t_splash_t *splashDefs; -extern UINT16 numSplashDefs; +/*-------------------------------------------------- + size_t K_GetSplashHeapIndex(t_splash_t *splash); -extern t_footstep_t *footstepDefs; -extern UINT16 numFootstepDefs; + Returns a splash defintion's index in the + splash definition heap. -extern terrain_t *terrainDefs; -extern UINT16 numTerrainDefs; + Input Arguments:- + splash - The splash definition to return the index of. -extern t_floor_t *terrainFloorDefs; -extern UINT16 numTerrainFloorDefs; + Return:- + The splash heap index, SIZE_MAX if the splash was invalid. +--------------------------------------------------*/ -// Default terrain definition ID. -extern UINT16 defaultTerrain; +size_t K_GetSplashHeapIndex(t_splash_t *splash); + + +/*-------------------------------------------------- + size_t K_GetNumSplashDefs(void); + + Returns the number of splash definitions. + + Input Arguments:- + None + + Return:- + Length of splashDefs. +--------------------------------------------------*/ + +size_t K_GetNumSplashDefs(void); + + +/*-------------------------------------------------- + t_splash_t *K_GetSplashByIndex(size_t checkIndex); + + Retrieves a splash definition by its heap index. + + Input Arguments:- + checkIndex - The heap index to retrieve. + + Return:- + The splash definition, NULL if it didn't exist. +--------------------------------------------------*/ + +t_splash_t *K_GetSplashByIndex(size_t checkIndex); + + +/*-------------------------------------------------- + t_splash_t *K_GetSplashByName(const char *checkName); + + Retrieves a splash definition by its lookup name. + + Input Arguments:- + checkName - The lookup name to retrieve. + + Return:- + The splash definition, NULL if it didn't exist. +--------------------------------------------------*/ + +t_splash_t *K_GetSplashByName(const char *checkName); + + +/*-------------------------------------------------- + size_t K_GetFootstepHeapIndex(t_footstep_t *footstep); + + Returns a footstep defintion's index in the + footstep definition heap. + + Input Arguments:- + footstep - The footstep definition to return the index of. + + Return:- + The footstep heap index, SIZE_MAX if the footstep was invalid. +--------------------------------------------------*/ + +size_t K_GetFootstepHeapIndex(t_footstep_t *footstep); + + +/*-------------------------------------------------- + size_t K_GetNumFootstepDefs(void); + + Returns the number of footstep definitions. + + Input Arguments:- + None + + Return:- + Length of footstepDefs. +--------------------------------------------------*/ + +size_t K_GetNumFootstepDefs(void); + + +/*-------------------------------------------------- + t_footstep_t *K_GetFootstepByIndex(size_t checkIndex); + + Retrieves a footstep definition by its heap index. + + Input Arguments:- + checkIndex - The heap index to retrieve. + + Return:- + The footstep definition, NULL if it didn't exist. +--------------------------------------------------*/ + +t_footstep_t *K_GetFootstepByIndex(size_t checkIndex); + + +/*-------------------------------------------------- + t_footstep_t *K_GetFootstepByName(const char *checkName); + + Retrieves a footstep definition by its lookup name. + + Input Arguments:- + checkName - The lookup name to retrieve. + + Return:- + The footstep definition, NULL if it didn't exist. +--------------------------------------------------*/ + +t_footstep_t *K_GetFootstepByName(const char *checkName); + + +/*-------------------------------------------------- + size_t K_GetTerrainHeapIndex(terrain_t *terrain); + + Returns a terrain defintion's index in the + terrain definition heap. + + Input Arguments:- + terrain - The terrain definition to return the index of. + + Return:- + The terrain heap index, SIZE_MAX if the terrain was invalid. +--------------------------------------------------*/ size_t K_GetTerrainHeapIndex(terrain_t *terrain); -terrain_t *K_GetTerrainByIndex(UINT16 checkIndex); + + +/*-------------------------------------------------- + size_t K_GetNumTerrainDefs(void); + + Returns the number of terrain definitions. + + Input Arguments:- + None + + Return:- + Length of terrainDefs. +--------------------------------------------------*/ + +size_t K_GetNumTerrainDefs(void); + + +/*-------------------------------------------------- + terrain_t *K_GetTerrainByIndex(size_t checkIndex); + + Retrieves a terrain definition by its heap index. + + Input Arguments:- + checkIndex - The heap index to retrieve. + + Return:- + The terrain definition, NULL if it didn't exist. +--------------------------------------------------*/ + +terrain_t *K_GetTerrainByIndex(size_t checkIndex); + + +/*-------------------------------------------------- + terrain_t *K_GetTerrainByName(const char *checkName); + + Retrieves a terrain definition by its lookup name. + + Input Arguments:- + checkName - The lookup name to retrieve. + + Return:- + The terrain definition, NULL if it didn't exist. +--------------------------------------------------*/ + terrain_t *K_GetTerrainByName(const char *checkName); + +/*-------------------------------------------------- + terrain_t *K_GetDefaultTerrain(void); + + Returns the default terrain definition, used + in cases where terrain is not set for a texture. + + Input Arguments:- + None + + Return:- + The default terrain definition, NULL if it didn't exist. +--------------------------------------------------*/ + terrain_t *K_GetDefaultTerrain(void); + + +/*-------------------------------------------------- + terrain_t *K_GetTerrainForTextureName(const char *checkName); + + Returns the terrain definition applied to + the texture name inputted. + + Input Arguments:- + checkName - The texture's name. + + Return:- + The texture's terrain definition if it exists, + otherwise the default terrain if it exists, + otherwise NULL. +--------------------------------------------------*/ + terrain_t *K_GetTerrainForTextureName(const char *checkName); + + +/*-------------------------------------------------- + terrain_t *K_GetTerrainForTextureNum(INT32 textureNum); + + Returns the terrain definition applied to + the texture ID inputted. + + Input Arguments:- + textureNum - The texture's ID. + + Return:- + The texture's terrain definition if it exists, + otherwise the default terrain if it exists, + otherwise NULL. +--------------------------------------------------*/ + terrain_t *K_GetTerrainForTextureNum(INT32 textureNum); + + +/*-------------------------------------------------- + terrain_t *K_GetTerrainForFlatNum(INT32 flatID); + + Returns the terrain definition applied to + the level flat ID. + + Input Arguments:- + flatID - The level flat's ID. + + Return:- + The level flat's terrain definition if it exists, + otherwise the default terrain if it exists, + otherwise NULL. +--------------------------------------------------*/ + terrain_t *K_GetTerrainForFlatNum(INT32 flatID); + +/*-------------------------------------------------- + void K_UpdateMobjTerrain(mobj_t *mo, INT32 flatID); + + Updates an object's terrain pointer, based on + the level flat ID supplied. Intended to be called + when the object moves to new floors. + + Input Arguments:- + mo - The object to update. + flatID - The level flat ID the object is standing on. + + Return:- + None +--------------------------------------------------*/ + void K_UpdateMobjTerrain(mobj_t *mo, INT32 flatID); + + +/*-------------------------------------------------- + void K_ProcessTerrainEffect(mobj_t *mo); + + Handles applying terrain effects to the object, + intended to be called in a thinker. + + Currently only intended for players, but + could be modified to be inclusive of all + object types. + + Input Arguments:- + mo - The object to apply effects to. + + Return:- + None +--------------------------------------------------*/ + void K_ProcessTerrainEffect(mobj_t *mo); + + +/*-------------------------------------------------- + void K_SetDefaultFriction(mobj_t *mo); + + Resets an object to their default friction values. + If they are on terrain with different friction, + they will update to that value. + + Input Arguments:- + mo - The object to reset the friction values of. + + Return:- + None +--------------------------------------------------*/ + void K_SetDefaultFriction(mobj_t *mo); + +/*-------------------------------------------------- + void K_InitTerrain(UINT16 wadNum); + + Finds the TERRAIN lumps in a WAD/PK3, and + processes all of them. + + Input Arguments:- + wadNum - WAD file ID to process. + + Return:- + None +--------------------------------------------------*/ + void K_InitTerrain(UINT16 wadNum); #endif // __K_TERRAIN_H__ diff --git a/src/p_user.c b/src/p_user.c index 5f5242e66..2550e3ba6 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -2118,8 +2118,6 @@ void P_MovePlayer(player_t *player) player->mo->rollangle = 0; } - player->mo->movefactor = FRACUNIT; // We're not going to do any more with this, so let's change it back for the next frame. - //{ SRB2kart // Drifting sound @@ -4468,8 +4466,6 @@ void P_PlayerThink(player_t *player) P_MovePlayer(player); } - player->mo->movefactor = FRACUNIT; // We're not going to do any more with this, so let's change it back for the next frame. - // Unset statis flag after moving. // In other words, if you manually set stasis via code, // it lasts for one tic. From b3d3135c5871e27742fbdc97c0095c88f5a7a75d Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Thu, 9 Dec 2021 15:54:22 -0500 Subject: [PATCH 10/29] Instead of embedding specific textures to be tripwire in hardcode ... make it a TERRAIN flag! --- src/k_kart.c | 11 +++++------ src/k_terrain.c | 12 ++++++++++-- src/k_terrain.h | 4 +++- src/lua_playerlib.c | 4 ++-- src/p_setup.c | 8 +++----- src/p_spec.c | 2 +- 6 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/k_kart.c b/src/k_kart.c index de660b812..812b856ce 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -5063,7 +5063,7 @@ void K_DoSneaker(player_t *player, INT32 type) { const fixed_t intendedboost = FRACUNIT/2; - if (!player->floorboost || player->floorboost == 3) + if (player->floorboost == 0 || player->floorboost == 3) { const sfxenum_t normalsfx = sfx_cdfm01; const sfxenum_t smallsfx = sfx_cdfm40; @@ -5086,7 +5086,7 @@ void K_DoSneaker(player_t *player, INT32 type) player->numsneakers++; } - if (!player->sneakertimer) + if (player->sneakertimer == 0) { if (type == 2) { @@ -5120,13 +5120,12 @@ void K_DoSneaker(player_t *player, INT32 type) { player->pflags |= PF_ATTACKDOWN; K_PlayBoostTaunt(player->mo); - } player->sneakertimer = sneakertime; // set angle for spun out players: - player->boostangle = (INT32)player->mo->angle; + player->boostangle = player->mo->angle; } static void K_DoShrink(player_t *user) @@ -6646,7 +6645,7 @@ void K_KartPlayerThink(player_t *player, ticcmd_t *cmd) // update boost angle if not spun out if (!player->spinouttimer && !player->wipeoutslow) - player->boostangle = (INT32)player->mo->angle; + player->boostangle = player->mo->angle; K_GetKartBoostPower(player); @@ -6919,7 +6918,7 @@ void K_KartPlayerThink(player_t *player, ticcmd_t *cmd) if (player->sneakertimer && player->wipeoutslow > 0 && player->wipeoutslow < wipeoutslowtime+1) player->wipeoutslow = wipeoutslowtime+1; - if (player->floorboost) + if (player->floorboost > 0) player->floorboost--; if (player->driftboost) diff --git a/src/k_terrain.c b/src/k_terrain.c index 9ba13757d..dfd059893 100644 --- a/src/k_terrain.c +++ b/src/k_terrain.c @@ -274,7 +274,7 @@ terrain_t *K_GetTerrainForTextureName(const char *checkName) { t_floor_t *f = &terrainFloorDefs[i]; - if (stricmp(checkName, f->textureName) == 0) + if (strncasecmp(checkName, f->textureName, 8) == 0) { return K_GetTerrainByIndex(f->terrainID); } @@ -387,7 +387,7 @@ void K_ProcessTerrainEffect(mobj_t *mo) // Sneaker panel if (terrain->flags & TRF_SNEAKERPANEL) { - if (!player->floorboost) + if (player->floorboost == 0) player->floorboost = 3; else player->floorboost = 2; @@ -734,6 +734,14 @@ static void K_ParseTerrainParameter(UINT32 i, char *param, char *val) { K_FlagBoolean(&terrain->flags, TRF_SNEAKERPANEL, val); } + else if (stricmp(param, "bumpy") == 0 || stricmp(param, "stairJank") == 0) + { + K_FlagBoolean(&terrain->flags, TRF_STAIRJANK, val); + } + else if (stricmp(param, "tripwire") == 0) + { + K_FlagBoolean(&terrain->flags, TRF_TRIPWIRE, val); + } } /*-------------------------------------------------- diff --git a/src/k_terrain.h b/src/k_terrain.h index 0e36388ea..e53a72358 100644 --- a/src/k_terrain.h +++ b/src/k_terrain.h @@ -48,7 +48,9 @@ typedef enum { // Terrain flag values. TRF_LIQUID = 1, // Texture water properties (wavy, slippery, etc) - TRF_SNEAKERPANEL = 1<<1 // Texture is a booster + TRF_SNEAKERPANEL = 1<<1, // Texture is a booster + TRF_STAIRJANK = 1<<2, // Texture is bumpy road + TRF_TRIPWIRE = 1<<3 // Texture is a tripwire when used as a midtexture } terrain_flags_t; typedef struct terrain_s diff --git a/src/lua_playerlib.c b/src/lua_playerlib.c index f7c20ab64..23e2e2b67 100644 --- a/src/lua_playerlib.c +++ b/src/lua_playerlib.c @@ -281,7 +281,7 @@ static int player_get(lua_State *L) else if (fastcmp(field,"handleboost")) lua_pushinteger(L, plr->handleboost); else if (fastcmp(field,"boostangle")) - lua_pushinteger(L, plr->boostangle); + lua_pushangle(L, plr->boostangle); else if (fastcmp(field,"draftpower")) lua_pushinteger(L, plr->draftpower); else if (fastcmp(field,"draftleeway")) @@ -626,7 +626,7 @@ static int player_set(lua_State *L) else if (fastcmp(field,"handleboost")) plr->handleboost = luaL_checkinteger(L, 3); else if (fastcmp(field,"boostangle")) - plr->boostangle = luaL_checkinteger(L, 3); + plr->boostangle = luaL_checkangle(L, 3); else if (fastcmp(field,"draftpower")) plr->draftpower = luaL_checkinteger(L, 3); else if (fastcmp(field,"draftleeway")) diff --git a/src/p_setup.c b/src/p_setup.c index fab5429b8..30323c70e 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -91,6 +91,7 @@ #include "k_waypoint.h" #include "k_bot.h" #include "k_grandprix.h" +#include "k_terrain.h" // TRF_TRIPWIRE // Replay names have time #if !defined (UNDER_CE) @@ -1939,18 +1940,15 @@ static void P_ProcessLinedefsAfterSidedefs(void) size_t i = numlines; register line_t *ld = lines; - const INT32 TEX_TRIPWIRE = R_TextureNumForName("TRIPWIRE"); - const INT32 TEX_4RIPWIRE = R_TextureNumForName("4RIPWIRE"); - for (; i--; ld++) { INT32 midtexture = sides[ld->sidenum[0]].midtexture; + terrain_t *terrain = K_GetTerrainForTextureNum(midtexture); ld->frontsector = sides[ld->sidenum[0]].sector; //e6y: Can't be -1 here ld->backsector = ld->sidenum[1] != 0xffff ? sides[ld->sidenum[1]].sector : 0; - if (midtexture == TEX_TRIPWIRE || - midtexture == TEX_4RIPWIRE) + if (terrain != NULL && (terrain->flags & TRF_TRIPWIRE)) { ld->tripwire = true; } diff --git a/src/p_spec.c b/src/p_spec.c index cd6f0f6ae..a52cfe932 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -4660,7 +4660,7 @@ DoneSection2: case 6: // SRB2kart 190117 - Sneaker Panel if (roversector || P_MobjReadyToTrigger(player->mo, sector)) { - if (!player->floorboost) + if (player->floorboost == 0) player->floorboost = 3; else player->floorboost = 2; From 047b725a309c8d5b2f8da48e0fdbd2ab3f721f00 Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Thu, 9 Dec 2021 16:12:09 -0500 Subject: [PATCH 11/29] Implement bumpy floor --- src/k_terrain.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/k_terrain.c b/src/k_terrain.c index dfd059893..1ad7e45a3 100644 --- a/src/k_terrain.c +++ b/src/k_terrain.c @@ -415,6 +415,26 @@ void K_ProcessTerrainEffect(mobj_t *mo) P_InstaThrust(mo, mo->angle, speed); } + // Bumpy floor + if (terrain->flags & TRF_STAIRJANK) + { + /* use a shorter sound if not two tics have passed + * since the last step */ + S_StartSound(mo, player->stairjank + >= 16 ? sfx_s23b : sfx_s268); + + if (player->stairjank == 0) + { + mobj_t *spark = P_SpawnMobjFromMobj(mo, + 0, 0, 0, MT_JANKSPARK); + spark->fuse = 9; + spark->cusval = K_StairJankFlip(ANGLE_90); + P_SetTarget(&spark->target, mo); + } + + player->stairjank = 17; + } + // (Offroad is handled elsewhere!) } From 35a3f65e83f8e6058cf3d6731de7c8086f5cd4b1 Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Thu, 9 Dec 2021 16:32:31 -0500 Subject: [PATCH 12/29] Allow "texture" as an alias to "floor" Since we I'm using it for Tripwire too --- src/k_terrain.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/k_terrain.c b/src/k_terrain.c index 1ad7e45a3..9cfd399d0 100644 --- a/src/k_terrain.c +++ b/src/k_terrain.c @@ -970,7 +970,7 @@ static boolean K_TERRAINLumpParser(UINT8 *data, size_t size) valid = false; } } - else if (stricmp(tkn, "floor") == 0) + else if (stricmp(tkn, "floor") == 0 || stricmp(tkn, "texture") == 0) { Z_Free(tkn); tkn = M_GetToken(NULL); From edef941a081c2dd7287bb06af0246abd9e47911e Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Sat, 18 Dec 2021 18:30:19 -0500 Subject: [PATCH 13/29] Add scale & color parameters to terrain particles --- src/k_terrain.c | 16 ++++++++++++++++ src/k_terrain.h | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/src/k_terrain.c b/src/k_terrain.c index 9cfd399d0..c2022d1b9 100644 --- a/src/k_terrain.c +++ b/src/k_terrain.c @@ -596,6 +596,14 @@ static void K_ParseSplashParameter(size_t i, char *param, char *val) { splash->sfx = get_sfx(val); } + else if (stricmp(param, "scale") == 0) + { + splash->scale = FLOAT_TO_FIXED(atof(val)); + } + else if (stricmp(param, "color") == 0) + { + splash->color = get_skincolor(val); + } } /*-------------------------------------------------- @@ -659,6 +667,14 @@ static void K_ParseFootstepParameter(size_t i, char *param, char *val) { footstep->sfx = get_sfx(val); } + else if (stricmp(param, "scale") == 0) + { + footstep->scale = FLOAT_TO_FIXED(atof(val)); + } + else if (stricmp(param, "color") == 0) + { + footstep->color = get_skincolor(val); + } } /*-------------------------------------------------- diff --git a/src/k_terrain.h b/src/k_terrain.h index e53a72358..d494f5edf 100644 --- a/src/k_terrain.h +++ b/src/k_terrain.h @@ -31,6 +31,8 @@ typedef struct t_splash_s UINT16 mobjType; // Thing type. MT_NULL to not spawn anything. UINT16 sfx; // Sound to play. + fixed_t scale; // Thing scale multiplier. + UINT16 color; // Colorize effect. SKINCOLOR_NONE has no colorize. } t_splash_t; typedef struct t_footstep_s @@ -42,6 +44,8 @@ typedef struct t_footstep_s UINT16 mobjType; // Thing type. MT_NULL to not spawn anything. UINT16 sfx; // Sound to play. + fixed_t scale; // Thing scale multiplier. + UINT16 color; // Colorize effect. SKINCOLOR_NONE has no colorize. } t_footstep_t; typedef enum From 8667aeb620ccf16cc4a1ed5dba6e5f480f4da6d2 Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Sat, 18 Dec 2021 21:23:41 -0500 Subject: [PATCH 14/29] Add footstep particles --- src/k_kart.c | 20 ++---- src/k_kart.h | 2 +- src/k_terrain.c | 164 ++++++++++++++++++++++++++++++++++++++++++++-- src/k_terrain.h | 16 +++++ src/lua_baselib.c | 3 +- src/p_user.c | 2 +- 6 files changed, 181 insertions(+), 26 deletions(-) diff --git a/src/k_kart.c b/src/k_kart.c index c0f5909ec..fefc5387b 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -4346,7 +4346,7 @@ void K_SpawnSparkleTrail(mobj_t *mo) sparkle->color = mo->color; } -void K_SpawnWipeoutTrail(mobj_t *mo, boolean offroad) +void K_SpawnWipeoutTrail(mobj_t *mo) { mobj_t *dust; angle_t aoff; @@ -4373,13 +4373,6 @@ void K_SpawnWipeoutTrail(mobj_t *mo, boolean offroad) dust->destscale = mo->scale; P_SetScale(dust, mo->scale); K_FlipFromObject(dust, mo); - - if (offroad) // offroad effect - { - dust->momx = mo->momx/2; - dust->momy = mo->momy/2; - dust->momz = mo->momz/2; - } } void K_SpawnDraftDust(mobj_t *mo) @@ -6698,16 +6691,11 @@ void K_KartPlayerThink(player_t *player, ticcmd_t *cmd) ghost->renderflags |= RF_DONTDRAW; } + // Could probably be moved somewhere else. + K_HandleFootstepParticles(player->mo); + if (P_IsObjectOnGround(player->mo)) { - // Offroad dust - if (player->boostpower < FRACUNIT) - { - K_SpawnWipeoutTrail(player->mo, true); - if (leveltime % 6 == 0) - S_StartSound(player->mo, sfx_cdfm70); - } - // Draft dust if (player->draftpower >= FRACUNIT) { diff --git a/src/k_kart.h b/src/k_kart.h index dffc1cedf..04d80fd05 100644 --- a/src/k_kart.h +++ b/src/k_kart.h @@ -76,7 +76,7 @@ void K_RunFinishLineBeam(void); UINT16 K_DriftSparkColor(player_t *player, INT32 charge); void K_SpawnBoostTrail(player_t *player); void K_SpawnSparkleTrail(mobj_t *mo); -void K_SpawnWipeoutTrail(mobj_t *mo, boolean offroad); +void K_SpawnWipeoutTrail(mobj_t *mo); void K_SpawnDraftDust(mobj_t *mo); void K_DriftDustHandling(mobj_t *spawner); void K_Squish(mobj_t *mo); diff --git a/src/k_terrain.c b/src/k_terrain.c index c2022d1b9..4f9f63cbf 100644 --- a/src/k_terrain.c +++ b/src/k_terrain.c @@ -20,6 +20,7 @@ #include "doomtype.h" #include "fastcmp.h" #include "m_fixed.h" +#include "m_random.h" #include "p_local.h" #include "p_mobj.h" #include "r_textures.h" @@ -41,6 +42,7 @@ static t_floor_t *terrainFloorDefs = NULL; static size_t numTerrainFloorDefs = 0; static size_t defaultTerrain = SIZE_MAX; +static size_t defaultOffroadFootstep = SIZE_MAX; /*-------------------------------------------------- size_t K_GetSplashHeapIndex(t_splash_t *splash) @@ -509,6 +511,114 @@ void K_SetDefaultFriction(mobj_t *mo) } } +/*-------------------------------------------------- + static void K_SpawnFootstepParticle(mobj_t *mo, t_footstep_t *fs) + + See header file for description. +--------------------------------------------------*/ +static void K_SpawnFootstepParticle(mobj_t *mo, t_footstep_t *fs) +{ + mobj_t *dust = NULL; + angle_t pushAngle = ANGLE_MAX; + angle_t tireAngle = ANGLE_MAX; + fixed_t momentum = INT32_MAX; + + if (mo->player != NULL) + { + tireAngle = (mo->player->drawangle + ANGLE_180); + } + else + { + tireAngle = (mo->angle + ANGLE_180); + } + + if ((leveltime / 2) & 1) + { + tireAngle -= ANGLE_45; + tireAngle -= P_RandomRange(0, ANGLE_11hh); + } + else + { + tireAngle += ANGLE_45; + tireAngle += P_RandomRange(0, ANGLE_11hh); + } + + pushAngle = K_MomentumAngle(mo) + ANGLE_180; + + dust = P_SpawnMobjFromMobj( + mo, + (P_RandomRange(-2, 2) * FRACUNIT) + (24 * FINECOSINE(tireAngle >> ANGLETOFINESHIFT)), + (P_RandomRange(-2, 2) * FRACUNIT) + (24 * FINESINE(tireAngle >> ANGLETOFINESHIFT)), + 0, fs->mobjType + ); + + P_SetTarget(&dust->target, mo); + dust->angle = K_MomentumAngle(mo); + + dust->destscale = FixedMul(mo->scale, fs->scale); + P_SetScale(dust, dust->destscale); + + dust->momx = mo->momx; + dust->momy = mo->momy; + dust->momz = mo->momz; + + momentum = P_AproxDistance(mo->momx, mo->momy) / 2; + dust->momx += FixedMul(momentum, FINECOSINE(pushAngle >> ANGLETOFINESHIFT)); + dust->momy += FixedMul(momentum, FINESINE(pushAngle >> ANGLETOFINESHIFT)); + dust->momz += (momentum / 16) * P_MobjFlip(mo); + + if (fs->color != SKINCOLOR_NONE) + { + dust->color = fs->color; + } + + if (fs->sfx != sfx_None && (leveltime % 6 == 0)) + { + S_StartSound(mo, fs->sfx); + } +} + +/*-------------------------------------------------- + void K_HandleFootstepParticles(mobj_t *mo) + + See header file for description. +--------------------------------------------------*/ +void K_HandleFootstepParticles(mobj_t *mo) +{ + t_footstep_t *fs = NULL; + + if (mo == NULL || P_MobjWasRemoved(mo) == true) + { + // Invalid object. + return; + } + + if (mo->terrain == NULL || mo->terrain->footstepID == SIZE_MAX) + { + // If no terrain, check for offroad. + // If we're in offroad, use the default particle. + + if (mo->player != NULL && mo->player->boostpower < FRACUNIT) + { + fs = K_GetFootstepByIndex(defaultOffroadFootstep); + } + } + else + { + fs = K_GetFootstepByIndex(mo->terrain->footstepID); + } + + if (fs == NULL || fs->mobjType == MT_NULL) + { + // No particles to spawn. + return; + } + + // Idea for later: if different spawning styles are desired, + // we can put a switch case here! + K_SpawnFootstepParticle(mo, fs); +} + /*-------------------------------------------------- static void K_FlagBoolean(UINT32 *inputFlags, UINT32 newFlag, char *val) @@ -550,6 +660,8 @@ static void K_SplashDefaults(t_splash_t *splash) { splash->mobjType = MT_NULL; splash->sfx = sfx_None; + splash->scale = FRACUNIT; + splash->color = SKINCOLOR_NONE; } /*-------------------------------------------------- @@ -590,11 +702,11 @@ static void K_ParseSplashParameter(size_t i, char *param, char *val) if (stricmp(param, "mobjType") == 0) { - splash->mobjType = get_mobjtype(val); + splash->mobjType = get_number(val) + 1; } else if (stricmp(param, "sfx") == 0) { - splash->sfx = get_sfx(val); + splash->sfx = get_number(val); } else if (stricmp(param, "scale") == 0) { @@ -602,7 +714,7 @@ static void K_ParseSplashParameter(size_t i, char *param, char *val) } else if (stricmp(param, "color") == 0) { - splash->color = get_skincolor(val); + splash->color = get_number(val); } } @@ -621,6 +733,8 @@ static void K_FootstepDefaults(t_footstep_t *footstep) { footstep->mobjType = MT_NULL; footstep->sfx = sfx_None; + footstep->scale = FRACUNIT; + footstep->color = SKINCOLOR_NONE; } /*-------------------------------------------------- @@ -661,11 +775,11 @@ static void K_ParseFootstepParameter(size_t i, char *param, char *val) if (stricmp(param, "mobjType") == 0) { - footstep->mobjType = get_mobjtype(val); + footstep->mobjType = get_number(val) + 1; } else if (stricmp(param, "sfx") == 0) { - footstep->sfx = get_sfx(val); + footstep->sfx = get_number(val); } else if (stricmp(param, "scale") == 0) { @@ -673,7 +787,7 @@ static void K_ParseFootstepParameter(size_t i, char *param, char *val) } else if (stricmp(param, "color") == 0) { - footstep->color = get_skincolor(val); + footstep->color = get_number(val); } } @@ -1090,6 +1204,7 @@ static boolean K_TERRAINLumpParser(UINT8 *data, size_t size) else { defaultTerrain = i; + CONS_Printf("DefaultTerrain set to '%s'\n", tkn); } } else @@ -1098,6 +1213,43 @@ static boolean K_TERRAINLumpParser(UINT8 *data, size_t size) valid = false; } } + else if (stricmp(tkn, "defaultOffroadFootstep") == 0) + { + Z_Free(tkn); + tkn = M_GetToken(NULL); + pos = M_GetTokenPos(); + + if (tkn && pos < size) + { + t_footstep_t *fs = NULL; + + for (i = 0; i < numFootstepDefs; i++) + { + fs = &footstepDefs[i]; + + if (stricmp(tkn, fs->name) == 0) + { + break; + } + } + + if (i == numFootstepDefs) + { + CONS_Alert(CONS_ERROR, "Invalid DefaultOffroadFootstep type.\n"); + valid = false; + } + else + { + defaultOffroadFootstep = i; + CONS_Printf("DefaultOffroadFootstep set to '%s'\n", tkn); + } + } + else + { + CONS_Alert(CONS_ERROR, "No DefaultOffroadFootstep type.\n"); + valid = false; + } + } else { CONS_Alert(CONS_ERROR, "Unknown field '%s' found in TERRAIN lump.\n", tkn); diff --git a/src/k_terrain.h b/src/k_terrain.h index d494f5edf..32921d393 100644 --- a/src/k_terrain.h +++ b/src/k_terrain.h @@ -394,6 +394,22 @@ void K_ProcessTerrainEffect(mobj_t *mo); void K_SetDefaultFriction(mobj_t *mo); +/*-------------------------------------------------- + void K_HandleFootstepParticles(mobj_t *mo); + + Spawns the footstep particles for an object's + terrain type. Intended to be called every tic. + + Input Arguments:- + mo - The object to spawn footsteps for. + + Return:- + None +--------------------------------------------------*/ + +void K_HandleFootstepParticles(mobj_t *mo); + + /*-------------------------------------------------- void K_InitTerrain(UINT16 wadNum); diff --git a/src/lua_baselib.c b/src/lua_baselib.c index e07c41bd4..7f410310c 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -3588,11 +3588,10 @@ static int lib_kSpawnSparkleTrail(lua_State *L) static int lib_kSpawnWipeoutTrail(lua_State *L) { mobj_t *mo = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ)); - boolean offroad = lua_optboolean(L, 2); NOHUD if (!mo) return LUA_ErrInvalid(L, "mobj_t"); - K_SpawnWipeoutTrail(mo, offroad); + K_SpawnWipeoutTrail(mo); return 0; } diff --git a/src/p_user.c b/src/p_user.c index 0cd83dfc7..5a065e8d5 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -2265,7 +2265,7 @@ void P_MovePlayer(player_t *player) K_SpawnSparkleTrail(player->mo); if (player->wipeoutslow > 1 && (leveltime & 1)) - K_SpawnWipeoutTrail(player->mo, false); + K_SpawnWipeoutTrail(player->mo); K_DriftDustHandling(player->mo); From 528ee29f2fa5f8a87489729cd8d45e922d5d8496 Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Sat, 18 Dec 2021 23:30:57 -0500 Subject: [PATCH 15/29] Use mobjzmovement for footsteps --- src/k_terrain.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/k_terrain.c b/src/k_terrain.c index 4f9f63cbf..d94acb886 100644 --- a/src/k_terrain.c +++ b/src/k_terrain.c @@ -560,7 +560,7 @@ static void K_SpawnFootstepParticle(mobj_t *mo, t_footstep_t *fs) dust->momx = mo->momx; dust->momy = mo->momy; - dust->momz = mo->momz; + dust->momz = P_GetMobjZMovement(mo) / 2; momentum = P_AproxDistance(mo->momx, mo->momy) / 2; dust->momx += FixedMul(momentum, FINECOSINE(pushAngle >> ANGLETOFINESHIFT)); From da459a9c73606c64de1f27ae943ee79ebcdc31d4 Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Sun, 19 Dec 2021 00:57:45 -0500 Subject: [PATCH 16/29] Add terrain splashes --- src/k_terrain.c | 125 ++++++++++++++++++++++++++++++++++++++++++++++-- src/k_terrain.h | 29 +++++++++++ src/p_local.h | 2 +- src/p_user.c | 10 ++-- 4 files changed, 156 insertions(+), 10 deletions(-) diff --git a/src/k_terrain.c b/src/k_terrain.c index d94acb886..1bbef1bcb 100644 --- a/src/k_terrain.c +++ b/src/k_terrain.c @@ -511,6 +511,102 @@ void K_SetDefaultFriction(mobj_t *mo) } } +/*-------------------------------------------------- + static void K_SpawnSplashParticles(mobj_t *mo, t_splash_t *s, fixed_t impact) + + See header file for description. +--------------------------------------------------*/ +static void K_SpawnSplashParticles(mobj_t *mo, t_splash_t *s, fixed_t impact) +{ + const UINT8 numParticles = s->numParticles; + const angle_t particleSpread = ANGLE_MAX / numParticles; + size_t i; + + for (i = 0; i < numParticles; i++) + { + mobj_t *dust = NULL; + angle_t pushAngle = (particleSpread * i); + fixed_t momH = INT32_MAX; + fixed_t momV = INT32_MAX; + + if (numParticles == 1) + { + // Random angle. + pushAngle = P_RandomRange(0, ANGLE_MAX); + } + + dust = P_SpawnMobjFromMobj( + mo, + (12 * FINECOSINE(pushAngle >> ANGLETOFINESHIFT)), + (12 * FINESINE(pushAngle >> ANGLETOFINESHIFT)), + 0, s->mobjType + ); + + P_SetTarget(&dust->target, mo); + dust->angle = pushAngle; + + dust->destscale = FixedMul(mo->scale, s->scale); + P_SetScale(dust, dust->destscale); + + dust->momx = mo->momx / 2; + dust->momy = mo->momy / 2; + dust->momz = 0; + + momH = FixedMul(impact, s->pushH); + momV = FixedMul(impact, s->pushV); + + dust->momx += FixedMul(momH, FINECOSINE(pushAngle >> ANGLETOFINESHIFT)); + dust->momy += FixedMul(momH, FINESINE(pushAngle >> ANGLETOFINESHIFT)); + dust->momz += momV * P_MobjFlip(mo); + + if (s->color != SKINCOLOR_NONE) + { + dust->color = s->color; + } + + if (s->sfx != sfx_None) + { + S_StartSound(mo, s->sfx); + } + } +} + +/*-------------------------------------------------- + void K_SpawnSplashForMobj(mobj_t *mo, fixed_t impact) + + See header file for description. +--------------------------------------------------*/ +void K_SpawnSplashForMobj(mobj_t *mo, fixed_t impact) +{ + t_splash_t *s = NULL; + + if (mo == NULL || P_MobjWasRemoved(mo) == true) + { + // Invalid object. + return; + } + + if (mo->terrain == NULL || mo->terrain->splashID == SIZE_MAX) + { + // No impact for this terrain type. + return; + } + else + { + s = K_GetSplashByIndex(mo->terrain->splashID); + } + + if (s == NULL || s->mobjType == MT_NULL || s->numParticles == 0) + { + // No particles to spawn. + return; + } + + // Idea for later: if different spawning styles are desired, + // we can put a switch case here! + K_SpawnSplashParticles(mo, s, impact); +} + /*-------------------------------------------------- static void K_SpawnFootstepParticle(mobj_t *mo, t_footstep_t *fs) @@ -522,6 +618,8 @@ static void K_SpawnFootstepParticle(mobj_t *mo, t_footstep_t *fs) angle_t pushAngle = ANGLE_MAX; angle_t tireAngle = ANGLE_MAX; fixed_t momentum = INT32_MAX; + fixed_t momH = INT32_MAX; + fixed_t momV = INT32_MAX; if (mo->player != NULL) { @@ -562,17 +660,20 @@ static void K_SpawnFootstepParticle(mobj_t *mo, t_footstep_t *fs) dust->momy = mo->momy; dust->momz = P_GetMobjZMovement(mo) / 2; - momentum = P_AproxDistance(mo->momx, mo->momy) / 2; - dust->momx += FixedMul(momentum, FINECOSINE(pushAngle >> ANGLETOFINESHIFT)); - dust->momy += FixedMul(momentum, FINESINE(pushAngle >> ANGLETOFINESHIFT)); - dust->momz += (momentum / 16) * P_MobjFlip(mo); + momentum = P_AproxDistance(mo->momx, mo->momy); + momH = FixedMul(momentum, fs->pushH); + momV = FixedMul(momentum, fs->pushV); + + dust->momx += FixedMul(momH, FINECOSINE(pushAngle >> ANGLETOFINESHIFT)); + dust->momy += FixedMul(momH, FINESINE(pushAngle >> ANGLETOFINESHIFT)); + dust->momz += (momV / 16) * P_MobjFlip(mo); if (fs->color != SKINCOLOR_NONE) { dust->color = fs->color; } - if (fs->sfx != sfx_None && (leveltime % 6 == 0)) + if ((fs->sfx != sfx_None) && (fs->sfxFreq > 0) && (leveltime % fs->sfxFreq == 0)) { S_StartSound(mo, fs->sfx); } @@ -662,6 +763,13 @@ static void K_SplashDefaults(t_splash_t *splash) splash->sfx = sfx_None; splash->scale = FRACUNIT; splash->color = SKINCOLOR_NONE; + + splash->pushH = FRACUNIT/4; + splash->pushV = FRACUNIT/64; + splash->spread = 2; + splash->cone = ANGLE_11hh; + + splash->numParticles = 8; } /*-------------------------------------------------- @@ -735,6 +843,13 @@ static void K_FootstepDefaults(t_footstep_t *footstep) footstep->sfx = sfx_None; footstep->scale = FRACUNIT; footstep->color = SKINCOLOR_NONE; + + footstep->pushH = FRACUNIT/2; + footstep->pushV = FRACUNIT/32; + footstep->spread = 2; + footstep->cone = ANGLE_11hh; + + footstep->sfxFreq = 6; } /*-------------------------------------------------- diff --git a/src/k_terrain.h b/src/k_terrain.h index 32921d393..e4055be23 100644 --- a/src/k_terrain.h +++ b/src/k_terrain.h @@ -33,6 +33,13 @@ typedef struct t_splash_s UINT16 sfx; // Sound to play. fixed_t scale; // Thing scale multiplier. UINT16 color; // Colorize effect. SKINCOLOR_NONE has no colorize. + + fixed_t pushH; // Push-out horizontal multiplier. + fixed_t pushV; // Push-out vertical multiplier. + fixed_t spread; // Randomized spread distance. + angle_t cone; // Randomized angle of the push-out. + + UINT8 numParticles; // Number of particles to spawn. } t_splash_t; typedef struct t_footstep_s @@ -46,6 +53,13 @@ typedef struct t_footstep_s UINT16 sfx; // Sound to play. fixed_t scale; // Thing scale multiplier. UINT16 color; // Colorize effect. SKINCOLOR_NONE has no colorize. + + fixed_t pushH; // Push-out horizontal multiplier. + fixed_t pushV; // Push-out vertical multiplier. + fixed_t spread; // Randomized spread distance. + angle_t cone; // Randomized angle of the push-out. + + tic_t sfxFreq; // How frequently to play the sound. } t_footstep_t; typedef enum @@ -394,6 +408,21 @@ void K_ProcessTerrainEffect(mobj_t *mo); void K_SetDefaultFriction(mobj_t *mo); +/*-------------------------------------------------- + void K_SpawnSplashForMobj(mobj_t *mo, fixed_t impact); + + Spawns the splash particles for an object's + terrain type. Intended to be called when hitting a floor. + + Input Arguments:- + mo - The object to spawn a splash for. + + Return:- + None +--------------------------------------------------*/ +void K_SpawnSplashForMobj(mobj_t *mo, fixed_t impact); + + /*-------------------------------------------------- void K_HandleFootstepParticles(mobj_t *mo); diff --git a/src/p_local.h b/src/p_local.h index 7ddf59875..b9802b106 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -168,7 +168,7 @@ boolean P_IsObjectOnGroundIn(mobj_t *mo, sector_t *sec); boolean P_IsObjectOnRealGround(mobj_t *mo, sector_t *sec); // SRB2Kart #define P_IsObjectFlipped(o) ((o)->eflags & MFE_VERTICALFLIP) boolean P_InQuicksand(mobj_t *mo); -boolean P_PlayerHitFloor(player_t *player, boolean dorollstuff); +boolean P_PlayerHitFloor(player_t *player, boolean fromAir); void P_SetObjectMomZ(mobj_t *mo, fixed_t value, boolean relative); void P_RestoreMusic(player_t *player); diff --git a/src/p_user.c b/src/p_user.c index 5a065e8d5..9ba08e7d4 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -52,6 +52,7 @@ #include "k_respawn.h" #include "k_bot.h" #include "k_grandprix.h" +#include "k_terrain.h" // K_SpawnSplashForMobj #ifdef HW3SOUND #include "hardware/hw3sound.h" @@ -1274,17 +1275,18 @@ void P_DoPlayerExit(player_t *player) // // Handles player hitting floor surface. // Returns whether to clip momz. -boolean P_PlayerHitFloor(player_t *player, boolean dorollstuff) +boolean P_PlayerHitFloor(player_t *player, boolean fromAir) { boolean clipmomz; - (void)dorollstuff; - I_Assert(player->mo != NULL); clipmomz = !(P_CheckDeathPitCollide(player->mo)); - // SRB2Kart: removed lots of really vanilla-specific code here + if (fromAir == true && clipmomz == true) + { + K_SpawnSplashForMobj(player->mo, abs(player->mo->momz)); + } return clipmomz; } From 9bae31fd038de51e73b1d6401ce1b302581b6cc0 Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Sun, 19 Dec 2021 01:09:37 -0500 Subject: [PATCH 17/29] Properly put in the parameters --- src/k_terrain.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/k_terrain.c b/src/k_terrain.c index 1bbef1bcb..8b8fa64df 100644 --- a/src/k_terrain.c +++ b/src/k_terrain.c @@ -824,6 +824,26 @@ static void K_ParseSplashParameter(size_t i, char *param, char *val) { splash->color = get_number(val); } + else if (stricmp(param, "pushH") == 0) + { + splash->pushH = FLOAT_TO_FIXED(atof(val)); + } + else if (stricmp(param, "pushV") == 0) + { + splash->pushV = FLOAT_TO_FIXED(atof(val)); + } + else if (stricmp(param, "spread") == 0) + { + splash->spread = FLOAT_TO_FIXED(atof(val)); + } + else if (stricmp(param, "cone") == 0) + { + splash->cone = AngleFixed(FLOAT_TO_FIXED(atof(val))); // lol + } + else if (stricmp(param, "numParticles") == 0) + { + splash->numParticles = (UINT8)atoi(val); + } } /*-------------------------------------------------- @@ -904,6 +924,26 @@ static void K_ParseFootstepParameter(size_t i, char *param, char *val) { footstep->color = get_number(val); } + else if (stricmp(param, "pushH") == 0) + { + footstep->pushH = FLOAT_TO_FIXED(atof(val)); + } + else if (stricmp(param, "pushV") == 0) + { + footstep->pushV = FLOAT_TO_FIXED(atof(val)); + } + else if (stricmp(param, "spread") == 0) + { + footstep->spread = FLOAT_TO_FIXED(atof(val)); + } + else if (stricmp(param, "cone") == 0) + { + footstep->cone = AngleFixed(FLOAT_TO_FIXED(atof(val))); // lol + } + else if (stricmp(param, "sfxFreq") == 0) + { + footstep->sfxFreq = (tic_t)atoi(val); + } } /*-------------------------------------------------- From 72b2997440d3ffc471b4cf327d3c8264b4de4dc4 Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Thu, 23 Dec 2021 03:23:42 -0500 Subject: [PATCH 18/29] Remove off by one """"fix"""" --- src/k_terrain.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/k_terrain.c b/src/k_terrain.c index 8b8fa64df..d178b212c 100644 --- a/src/k_terrain.c +++ b/src/k_terrain.c @@ -810,7 +810,7 @@ static void K_ParseSplashParameter(size_t i, char *param, char *val) if (stricmp(param, "mobjType") == 0) { - splash->mobjType = get_number(val) + 1; + splash->mobjType = get_number(val); } else if (stricmp(param, "sfx") == 0) { @@ -910,7 +910,7 @@ static void K_ParseFootstepParameter(size_t i, char *param, char *val) if (stricmp(param, "mobjType") == 0) { - footstep->mobjType = get_number(val) + 1; + footstep->mobjType = get_number(val); } else if (stricmp(param, "sfx") == 0) { From d1827b1c161fc2f583c3f8c43d5b85bd4b2dbe92 Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Thu, 23 Dec 2021 22:48:23 -0500 Subject: [PATCH 19/29] Fix it not using footstep->cone --- src/k_terrain.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/k_terrain.c b/src/k_terrain.c index d178b212c..0328d29b3 100644 --- a/src/k_terrain.c +++ b/src/k_terrain.c @@ -633,12 +633,12 @@ static void K_SpawnFootstepParticle(mobj_t *mo, t_footstep_t *fs) if ((leveltime / 2) & 1) { tireAngle -= ANGLE_45; - tireAngle -= P_RandomRange(0, ANGLE_11hh); + tireAngle -= P_RandomRange(0, footstep->cone); } else { tireAngle += ANGLE_45; - tireAngle += P_RandomRange(0, ANGLE_11hh); + tireAngle += P_RandomRange(0, footstep->cone); } pushAngle = K_MomentumAngle(mo) + ANGLE_180; From a0c36c6126cc566dba5825e45edcdfe772820a81 Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Thu, 23 Dec 2021 22:50:57 -0500 Subject: [PATCH 20/29] Wrong var name oops I autopiloted --- src/k_terrain.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/k_terrain.c b/src/k_terrain.c index 0328d29b3..33c7d4cf9 100644 --- a/src/k_terrain.c +++ b/src/k_terrain.c @@ -633,12 +633,12 @@ static void K_SpawnFootstepParticle(mobj_t *mo, t_footstep_t *fs) if ((leveltime / 2) & 1) { tireAngle -= ANGLE_45; - tireAngle -= P_RandomRange(0, footstep->cone); + tireAngle -= P_RandomRange(0, fs->cone); } else { tireAngle += ANGLE_45; - tireAngle += P_RandomRange(0, footstep->cone); + tireAngle += P_RandomRange(0, fs->cone); } pushAngle = K_MomentumAngle(mo) + ANGLE_180; From 2d5d78b76e50565b7bb7c9126c135d503f77c09c Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Thu, 23 Dec 2021 22:58:25 -0500 Subject: [PATCH 21/29] Oops ... can't use raw angles for P_RandomRange anyway. --- src/k_terrain.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/k_terrain.c b/src/k_terrain.c index 33c7d4cf9..b50fead33 100644 --- a/src/k_terrain.c +++ b/src/k_terrain.c @@ -633,12 +633,12 @@ static void K_SpawnFootstepParticle(mobj_t *mo, t_footstep_t *fs) if ((leveltime / 2) & 1) { tireAngle -= ANGLE_45; - tireAngle -= P_RandomRange(0, fs->cone); + tireAngle -= P_RandomRange(0, fs->cone / ANG1) * ANG1; } else { tireAngle += ANGLE_45; - tireAngle += P_RandomRange(0, fs->cone); + tireAngle += P_RandomRange(0, fs->cone / ANG1) * ANG1; } pushAngle = K_MomentumAngle(mo) + ANGLE_180; From 8cdfe87dca006b2f741b9ef39ef7f8a5b36db41d Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Thu, 23 Dec 2021 23:15:36 -0500 Subject: [PATCH 22/29] Let's just convert this in a more sane fashion... --- src/k_terrain.c | 4 ++-- src/tables.c | 10 ++++++++++ src/tables.h | 2 ++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/k_terrain.c b/src/k_terrain.c index b50fead33..da5a93f90 100644 --- a/src/k_terrain.c +++ b/src/k_terrain.c @@ -838,7 +838,7 @@ static void K_ParseSplashParameter(size_t i, char *param, char *val) } else if (stricmp(param, "cone") == 0) { - splash->cone = AngleFixed(FLOAT_TO_FIXED(atof(val))); // lol + splash->cone = FloatToAngle(atof(val)); } else if (stricmp(param, "numParticles") == 0) { @@ -938,7 +938,7 @@ static void K_ParseFootstepParameter(size_t i, char *param, char *val) } else if (stricmp(param, "cone") == 0) { - footstep->cone = AngleFixed(FLOAT_TO_FIXED(atof(val))); // lol + footstep->cone = FloatToAngle(atof(val)); } else if (stricmp(param, "sfxFreq") == 0) { diff --git a/src/tables.c b/src/tables.c index 42ad6a73c..8c4dc50e1 100644 --- a/src/tables.c +++ b/src/tables.c @@ -185,6 +185,16 @@ INT32 AngleDeltaSigned(angle_t a1, angle_t a2) return (INT32)(a1) - (INT32)(a2); } +float AngleToFloat(angle_t x) +{ + return x / (float)ANG1; +} + +angle_t FloatToAngle(float f) +{ + return (angle_t)(f * ANG1); +} + #include "t_ftan.c" #include "t_fsin.c" diff --git a/src/tables.h b/src/tables.h index 5e5b6e57b..e122975e1 100644 --- a/src/tables.h +++ b/src/tables.h @@ -108,6 +108,8 @@ FUNCMATH angle_t FixedAngleC(fixed_t fa, fixed_t factor); // difference between two angle_t FUNCMATH INT32 AngleDelta(angle_t a1, angle_t a2); FUNCMATH INT32 AngleDeltaSigned(angle_t a1, angle_t a2); +FUNCMATH float AngleToFloat(angle_t x); +FUNCMATH angle_t FloatToAngle(float f); /// The FixedAcos function FUNCMATH angle_t FixedAcos(fixed_t x); From cdf75cfbe025df2d90144bd59b570aabd35a7d4b Mon Sep 17 00:00:00 2001 From: James R Date: Thu, 23 Dec 2021 21:08:19 -0800 Subject: [PATCH 23/29] Fix incompatible prototype --- src/k_terrain.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/k_terrain.c b/src/k_terrain.c index da5a93f90..e365b2907 100644 --- a/src/k_terrain.c +++ b/src/k_terrain.c @@ -989,7 +989,7 @@ static void K_NewTerrainDefs(void) } /*-------------------------------------------------- - static void K_ParseTerrainParameter(UINT32 i, char *param, char *val) + static void K_ParseTerrainParameter(size_t i, char *param, char *val) Parser function for Terrain blocks. @@ -1001,7 +1001,7 @@ static void K_NewTerrainDefs(void) Return:- None --------------------------------------------------*/ -static void K_ParseTerrainParameter(UINT32 i, char *param, char *val) +static void K_ParseTerrainParameter(size_t i, char *param, char *val) { terrain_t *terrain = &terrainDefs[i]; @@ -1080,7 +1080,7 @@ static void K_NewTerrainFloorDefs(void) Return:- false if any errors occured, otherwise true. --------------------------------------------------*/ -static boolean K_DoTERRAINLumpParse(size_t num, void (*parser)(UINT32, char *, char *)) +static boolean K_DoTERRAINLumpParse(size_t num, void (*parser)(size_t, char *, char *)) { char *param, *val; From ff3cb90cda57da10c0f70ee7130529ede46661e8 Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Fri, 24 Dec 2021 09:50:00 -0500 Subject: [PATCH 24/29] Super random push Looks better to me, and makes cone have a more pronounced effect --- src/k_terrain.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/k_terrain.c b/src/k_terrain.c index da5a93f90..907c610fa 100644 --- a/src/k_terrain.c +++ b/src/k_terrain.c @@ -630,19 +630,21 @@ static void K_SpawnFootstepParticle(mobj_t *mo, t_footstep_t *fs) tireAngle = (mo->angle + ANGLE_180); } + pushAngle = K_MomentumAngle(mo) + ANGLE_180; + if ((leveltime / 2) & 1) { tireAngle -= ANGLE_45; tireAngle -= P_RandomRange(0, fs->cone / ANG1) * ANG1; + pushAngle -= P_RandomRange(0, fs->cone / ANG1) * ANG1; } else { tireAngle += ANGLE_45; tireAngle += P_RandomRange(0, fs->cone / ANG1) * ANG1; + pushAngle += P_RandomRange(0, fs->cone / ANG1) * ANG1; } - pushAngle = K_MomentumAngle(mo) + ANGLE_180; - dust = P_SpawnMobjFromMobj( mo, (P_RandomRange(-2, 2) * FRACUNIT) + (24 * FINECOSINE(tireAngle >> ANGLETOFINESHIFT)), From c6f69e8f5955fb1c698394c8f6d4122cb4d6d68f Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Sun, 2 Jan 2022 21:42:20 -0500 Subject: [PATCH 25/29] Add required speed percent --- src/k_terrain.c | 24 +++++++++++++++++++++++- src/k_terrain.h | 2 ++ src/lua_mobjlib.c | 3 --- src/lua_playerlib.c | 5 +---- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/k_terrain.c b/src/k_terrain.c index 8c7a0643d..323e55734 100644 --- a/src/k_terrain.c +++ b/src/k_terrain.c @@ -618,16 +618,29 @@ static void K_SpawnFootstepParticle(mobj_t *mo, t_footstep_t *fs) angle_t pushAngle = ANGLE_MAX; angle_t tireAngle = ANGLE_MAX; fixed_t momentum = INT32_MAX; + fixed_t speedValue = INT32_MAX; fixed_t momH = INT32_MAX; fixed_t momV = INT32_MAX; + momentum = P_AproxDistance(mo->momx, mo->momy); + if (mo->player != NULL) { tireAngle = (mo->player->drawangle + ANGLE_180); + speedValue = K_GetKartSpeedFromStat(mo->player->kartspeed); } else { tireAngle = (mo->angle + ANGLE_180); + speedValue = K_GetKartSpeedFromStat(5); + } + + speedValue = FixedMul(speedValue, mo->scale); + speedValue = FixedMul(speedValue, fs->requiredSpeed); + + if (momentum < speedValue) + { + return; } pushAngle = K_MomentumAngle(mo) + ANGLE_180; @@ -662,7 +675,6 @@ static void K_SpawnFootstepParticle(mobj_t *mo, t_footstep_t *fs) dust->momy = mo->momy; dust->momz = P_GetMobjZMovement(mo) / 2; - momentum = P_AproxDistance(mo->momx, mo->momy); momH = FixedMul(momentum, fs->pushH); momV = FixedMul(momentum, fs->pushV); @@ -872,6 +884,8 @@ static void K_FootstepDefaults(t_footstep_t *footstep) footstep->cone = ANGLE_11hh; footstep->sfxFreq = 6; + footstep->frequency = 1; + footstep->requiredSpeed = 0; } /*-------------------------------------------------- @@ -946,6 +960,14 @@ static void K_ParseFootstepParameter(size_t i, char *param, char *val) { footstep->sfxFreq = (tic_t)atoi(val); } + else if (stricmp(param, "frequency") == 0) + { + footstep->frequency = (tic_t)atoi(val); + } + else if (stricmp(param, "requiredSpeed") == 0) + { + footstep->requiredSpeed = FLOAT_TO_FIXED(atof(val)); + } } /*-------------------------------------------------- diff --git a/src/k_terrain.h b/src/k_terrain.h index e4055be23..924f7a1b1 100644 --- a/src/k_terrain.h +++ b/src/k_terrain.h @@ -60,6 +60,8 @@ typedef struct t_footstep_s angle_t cone; // Randomized angle of the push-out. tic_t sfxFreq; // How frequently to play the sound. + tic_t frequency; // How frequently to spawn the particles. + fixed_t requiredSpeed; // Speed percentage you need to be at to trigger the particles. } t_footstep_t; typedef enum diff --git a/src/lua_mobjlib.c b/src/lua_mobjlib.c index 8a4a1e7a5..4c2a4f24d 100644 --- a/src/lua_mobjlib.c +++ b/src/lua_mobjlib.c @@ -494,9 +494,6 @@ static int mobj_set(lua_State *L) if (hook_cmd_running) return luaL_error(L, "Do not alter mobj_t in CMD building code!"); - if (hook_cmd_running) - return luaL_error(L, "Do not alter mobj_t in BuildCMD code!"); - switch(field) { case mobj_valid: diff --git a/src/lua_playerlib.c b/src/lua_playerlib.c index 23e2e2b67..17e1a39b1 100644 --- a/src/lua_playerlib.c +++ b/src/lua_playerlib.c @@ -499,9 +499,6 @@ static int player_set(lua_State *L) if (hook_cmd_running) return luaL_error(L, "Do not alter player_t in CMD building code!"); - if (hook_cmd_running) - return luaL_error(L, "Do not alter player_t in BuildCMD code!"); - if (fastcmp(field,"mo")) { mobj_t *newmo = *((mobj_t **)luaL_checkudata(L, 3, META_MOBJ)); plr->mo->player = NULL; // remove player pointer from old mobj @@ -861,7 +858,7 @@ static int karthud_set(lua_State *L) if (hud_running) return luaL_error(L, "Do not alter player_t in HUD rendering code!"); if (hook_cmd_running) - return luaL_error(L, "Do not alter player_t in BuildCMD code!"); + return luaL_error(L, "Do not alter player_t in CMD building code!"); karthud[ks] = i; return 0; } From 9e56e54e31aa8647b29c2f7718c0b32ea877e99a Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Mon, 3 Jan 2022 00:07:46 -0500 Subject: [PATCH 26/29] Implement particle spawn frequency, offset spawning by player num --- src/k_terrain.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/src/k_terrain.c b/src/k_terrain.c index 323e55734..68a78af69 100644 --- a/src/k_terrain.c +++ b/src/k_terrain.c @@ -612,7 +612,7 @@ void K_SpawnSplashForMobj(mobj_t *mo, fixed_t impact) See header file for description. --------------------------------------------------*/ -static void K_SpawnFootstepParticle(mobj_t *mo, t_footstep_t *fs) +static void K_SpawnFootstepParticle(mobj_t *mo, t_footstep_t *fs, tic_t timer) { mobj_t *dust = NULL; angle_t pushAngle = ANGLE_MAX; @@ -621,6 +621,13 @@ static void K_SpawnFootstepParticle(mobj_t *mo, t_footstep_t *fs) fixed_t speedValue = INT32_MAX; fixed_t momH = INT32_MAX; fixed_t momV = INT32_MAX; + fixed_t xOff = INT32_MAX; + fixed_t yOff = INT32_MAX; + + if (timer % fs->frequency != 0) + { + return; + } momentum = P_AproxDistance(mo->momx, mo->momy); @@ -645,7 +652,7 @@ static void K_SpawnFootstepParticle(mobj_t *mo, t_footstep_t *fs) pushAngle = K_MomentumAngle(mo) + ANGLE_180; - if ((leveltime / 2) & 1) + if (((timer / fs->frequency) / 2) & 1) { tireAngle -= ANGLE_45; tireAngle -= P_RandomRange(0, fs->cone / ANG1) * ANG1; @@ -658,10 +665,13 @@ static void K_SpawnFootstepParticle(mobj_t *mo, t_footstep_t *fs) pushAngle += P_RandomRange(0, fs->cone / ANG1) * ANG1; } + xOff = P_RandomRange(-fs->spread / FRACUNIT, fs->spread / FRACUNIT) * FRACUNIT; + yOff = P_RandomRange(-fs->spread / FRACUNIT, fs->spread / FRACUNIT) * FRACUNIT; + dust = P_SpawnMobjFromMobj( mo, - (P_RandomRange(-2, 2) * FRACUNIT) + (24 * FINECOSINE(tireAngle >> ANGLETOFINESHIFT)), - (P_RandomRange(-2, 2) * FRACUNIT) + (24 * FINESINE(tireAngle >> ANGLETOFINESHIFT)), + xOff + (24 * FINECOSINE(tireAngle >> ANGLETOFINESHIFT)), + yOff + (24 * FINESINE(tireAngle >> ANGLETOFINESHIFT)), 0, fs->mobjType ); @@ -687,7 +697,7 @@ static void K_SpawnFootstepParticle(mobj_t *mo, t_footstep_t *fs) dust->color = fs->color; } - if ((fs->sfx != sfx_None) && (fs->sfxFreq > 0) && (leveltime % fs->sfxFreq == 0)) + if ((fs->sfx != sfx_None) && (fs->sfxFreq > 0) && (timer % fs->sfxFreq == 0)) { S_StartSound(mo, fs->sfx); } @@ -700,6 +710,7 @@ static void K_SpawnFootstepParticle(mobj_t *mo, t_footstep_t *fs) --------------------------------------------------*/ void K_HandleFootstepParticles(mobj_t *mo) { + tic_t timer = leveltime; t_footstep_t *fs = NULL; if (mo == NULL || P_MobjWasRemoved(mo) == true) @@ -723,15 +734,21 @@ void K_HandleFootstepParticles(mobj_t *mo) fs = K_GetFootstepByIndex(mo->terrain->footstepID); } - if (fs == NULL || fs->mobjType == MT_NULL) + if (fs == NULL || fs->mobjType == MT_NULL || fs->frequency <= 0) { // No particles to spawn. return; } + if (mo->player != NULL) + { + // Offset timer by player ID. + timer += mo->player - players; + } + // Idea for later: if different spawning styles are desired, // we can put a switch case here! - K_SpawnFootstepParticle(mo, fs); + K_SpawnFootstepParticle(mo, fs, timer); } /*-------------------------------------------------- @@ -780,7 +797,7 @@ static void K_SplashDefaults(t_splash_t *splash) splash->pushH = FRACUNIT/4; splash->pushV = FRACUNIT/64; - splash->spread = 2; + splash->spread = 2*FRACUNIT; splash->cone = ANGLE_11hh; splash->numParticles = 8; @@ -880,7 +897,7 @@ static void K_FootstepDefaults(t_footstep_t *footstep) footstep->pushH = FRACUNIT/2; footstep->pushV = FRACUNIT/32; - footstep->spread = 2; + footstep->spread = 2*FRACUNIT; footstep->cone = ANGLE_11hh; footstep->sfxFreq = 6; From 2033e84bce292a671d442df28e9dad308d6d5c62 Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Mon, 3 Jan 2022 00:17:59 -0500 Subject: [PATCH 27/29] Minimum impact amount for splashes --- src/k_terrain.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/k_terrain.c b/src/k_terrain.c index 68a78af69..bae39d216 100644 --- a/src/k_terrain.c +++ b/src/k_terrain.c @@ -578,6 +578,7 @@ static void K_SpawnSplashParticles(mobj_t *mo, t_splash_t *s, fixed_t impact) --------------------------------------------------*/ void K_SpawnSplashForMobj(mobj_t *mo, fixed_t impact) { + const fixed_t minImpact = 4 * mo->scale; t_splash_t *s = NULL; if (mo == NULL || P_MobjWasRemoved(mo) == true) @@ -602,6 +603,11 @@ void K_SpawnSplashForMobj(mobj_t *mo, fixed_t impact) return; } + if (impact < minImpact) + { + impact = minImpact; + } + // Idea for later: if different spawning styles are desired, // we can put a switch case here! K_SpawnSplashParticles(mo, s, impact); From df3a0ad5079cc630625b44d8b7c798a6af1fe943 Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Mon, 3 Jan 2022 01:40:38 -0500 Subject: [PATCH 28/29] Only do spread if above 0 --- src/k_terrain.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/k_terrain.c b/src/k_terrain.c index bae39d216..f5323e94b 100644 --- a/src/k_terrain.c +++ b/src/k_terrain.c @@ -627,8 +627,8 @@ static void K_SpawnFootstepParticle(mobj_t *mo, t_footstep_t *fs, tic_t timer) fixed_t speedValue = INT32_MAX; fixed_t momH = INT32_MAX; fixed_t momV = INT32_MAX; - fixed_t xOff = INT32_MAX; - fixed_t yOff = INT32_MAX; + fixed_t xOff = 0; + fixed_t yOff = 0; if (timer % fs->frequency != 0) { @@ -671,8 +671,11 @@ static void K_SpawnFootstepParticle(mobj_t *mo, t_footstep_t *fs, tic_t timer) pushAngle += P_RandomRange(0, fs->cone / ANG1) * ANG1; } - xOff = P_RandomRange(-fs->spread / FRACUNIT, fs->spread / FRACUNIT) * FRACUNIT; - yOff = P_RandomRange(-fs->spread / FRACUNIT, fs->spread / FRACUNIT) * FRACUNIT; + if (fs->spread > 0) + { + xOff = P_RandomRange(-fs->spread / FRACUNIT, fs->spread / FRACUNIT) * FRACUNIT; + yOff = P_RandomRange(-fs->spread / FRACUNIT, fs->spread / FRACUNIT) * FRACUNIT; + } dust = P_SpawnMobjFromMobj( mo, From 211fc17974187eacf396e64529ff291be1b85a03 Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Tue, 4 Jan 2022 12:45:20 -0500 Subject: [PATCH 29/29] NULL terrain for spectators --- src/k_terrain.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/k_terrain.c b/src/k_terrain.c index f5323e94b..e03ee2059 100644 --- a/src/k_terrain.c +++ b/src/k_terrain.c @@ -344,6 +344,13 @@ void K_UpdateMobjTerrain(mobj_t *mo, INT32 flatID) return; } + if (mo->player != NULL && mo->player->spectator == true) + { + // We don't want a terrain pointer for spectators. + mo->terrain = NULL; + return; + } + // Update the object's terrain pointer. mo->terrain = K_GetTerrainForFlatNum(flatID); }