From 6aa50b62d7c6dbd8f274688d6f89d22a03c23937 Mon Sep 17 00:00:00 2001 From: yamamama Date: Sun, 7 Dec 2025 19:58:48 -0500 Subject: [PATCH] Add support for Alt. item patches --- src/deh_soc.c | 20 ++++++++++++++++---- src/k_hud.c | 6 ++++-- src/k_items.c | 9 +++++++-- src/k_items.h | 6 ++++-- src/lua_baselib.c | 20 +++++++++++++++++++- 5 files changed, 50 insertions(+), 11 deletions(-) diff --git a/src/deh_soc.c b/src/deh_soc.c index 1d939825f..179e85267 100644 --- a/src/deh_soc.c +++ b/src/deh_soc.c @@ -4079,9 +4079,15 @@ void readkartitem(MYFILE *f, kartitem_t *item) word2 = (tmp += 2); strupr(word2); - if (fastcmp(word, "BIGPATCHES") || fastcmp(word, "SMALLPATCHES")) + if (fastcmp(word, "BIGPATCHES") || fastcmp(word, "SMALLPATCHES") || + fastcmp(word, "BIGALTPATCHES") || fastcmp(word, "SMALLALTPATCHES")) { - kartitemgraphics_t *graphics = &item->graphics[word[0] == 'B' ? 0 : 1]; + UINT8 patch_idx = (word[0] == 'B') ? 0 : 1; + + // Alt. patches are stored in the same array, just in their own slots. + patch_idx += (word[3 + (patch_idx << 1)] == 'A') ? 2 : 0; + + kartitemgraphics_t* graphics = &item->graphics[patch_idx]; if (graphics == &item->graphics[0] && item->spritedef.numframes > 0) { @@ -4095,11 +4101,17 @@ void readkartitem(MYFILE *f, kartitem_t *item) graphics->patches[i] = NULL; } - tmp = strtok(word2,","); + tmp = strtok(word2, ","); for (graphics->numpatches = 0; graphics->numpatches < MAXITEMPATCHES;) { graphics->patchnames[graphics->numpatches++] = Z_StrDup(tmp); - if ((tmp = strtok(NULL,",")) == NULL) + + if (patch_idx > 1) + { + item->altgraphics = true; + } + + if ((tmp = strtok(NULL, ",")) == NULL) break; } } diff --git a/src/k_hud.c b/src/k_hud.c index 41eddc1b6..d4995f4c4 100644 --- a/src/k_hud.c +++ b/src/k_hud.c @@ -542,7 +542,9 @@ void K_LoadKartHUDGraphics(void) for (i = 0; i < numkartitems; i++) { kartitem_t *item = &kartitems[i]; - for (j = 0; j < 2; j++) + + INT32 n = (item->altgraphics) ? 4 : 2; + for (j = 0; j < n; j++) { kartitemgraphics_t *graphics = &item->graphics[j]; for (INT32 k = 0; k < graphics->numpatches; k++) @@ -1330,7 +1332,7 @@ static void K_drawKartItem(void) localpatch = K_GetCachedItemPatch(stplyr->itemtype, tiny, stplyr->itemamount); if (localpatch == NULL) localpatch = kp_nodraw; // diagnose underflows - else if (K_IsKartItemAlternate(stplyr->itemtype)) + else if (K_IsKartItemAlternate(stplyr->itemtype) && (!kartitems[stplyr->itemtype].altgraphics)) isalt = true; dark = K_GetItemFlags(stplyr->itemtype) & KIF_DARKBG; diff --git a/src/k_items.c b/src/k_items.c index 981944d81..52f84398b 100644 --- a/src/k_items.c +++ b/src/k_items.c @@ -202,10 +202,15 @@ UINT8 K_GetItemNumberDisplayMin(kartitemtype_e type, boolean tiny) return K_GetItemFlags(type) & KIF_ANIMATED ? 2 : kartitems[type].graphics[tiny ? 1 : 0].numpatches + 1; } -patch_t *K_GetCachedItemPatch(kartitemtype_e type, boolean tiny, UINT8 amount) +patch_t *K_GetCachedItemPatchEx(kartitemtype_e type, boolean tiny, UINT8 amount, boolean *altforce) { kartitem_t *item = &kartitems[type >= numkartresults ? 0 : type]; - kartitemgraphics_t *graphics = &item->graphics[tiny ? 1 : 0]; + boolean alt = item->altgraphics && K_IsKartItemAlternate(type); + + if (altforce != NULL) + alt = (*altforce) && item->altgraphics; + + kartitemgraphics_t *graphics = &item->graphics[(tiny ? 1 : 0) + (alt ? 2 : 0)]; if (graphics->numpatches == 0) return missingpat; diff --git a/src/k_items.h b/src/k_items.h index c82bb7807..42ad693fb 100644 --- a/src/k_items.h +++ b/src/k_items.h @@ -117,10 +117,11 @@ struct kartitem_t dehinfo_t info; kartitemequip_e equipstyle[2]; kartitemflags_e flags[2]; - kartitemgraphics_t graphics[2]; + kartitemgraphics_t graphics[4]; spritedef_t spritedef; consvar_t *altcvar; // if not NULL, an altitem exists + boolean altgraphics; boolean altenabled; }; @@ -185,7 +186,8 @@ boolean K_IsKartItemAlternate(kartitemtype_e itemtype); kartitemflags_e K_GetItemFlags(kartitemtype_e itemtype); kartitemequip_e K_GetItemEquipStyle(kartitemtype_e mobjtype); UINT8 K_GetItemNumberDisplayMin(kartitemtype_e type, boolean tiny); -patch_t *K_GetCachedItemPatch(kartitemtype_e type, boolean tiny, UINT8 amount); +patch_t *K_GetCachedItemPatchEx(kartitemtype_e type, boolean tiny, UINT8 amount, boolean *altforce); +#define K_GetCachedItemPatch(type, tiny, amount) K_GetCachedItemPatchEx(type, tiny, amount, NULL) void K_SetItemOut(player_t *player, kartitemtype_e itemtype, itemflags_t flags); void K_UnsetItemOut(player_t *player); diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 0215bf4fe..138f0dc2b 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -4104,6 +4104,7 @@ static int lib_kGetItemPatch(lua_State *L) { kartitemtype_e item = (kartitemtype_e)luaL_optinteger(L, 1, KITEM_NONE); boolean tiny = lua_optboolean(L, 2); + boolean alt = lua_isnoneornil(L, 3) ? false : luaL_checkboolean(L, 3); //HUDSAFE // TODO: compatmode KRITEM @@ -4114,11 +4115,27 @@ static int lib_kGetItemPatch(lua_State *L) return 1; } - kartitemgraphics_t *graphics = &kartitems[item].graphics[tiny ? 1 : 0]; + if (alt && (!kartitems[item].altgraphics)) + { + alt = false; + } + + kartitemgraphics_t *graphics = &kartitems[item].graphics[(tiny ? 1 : 0) + (alt ? 2 : 0)]; lua_pushstring(L, graphics->numpatches == 0 ? sad : graphics->patchnames[0]); return 1; } +static int lib_kItemHasAltPatches(lua_State *L) +{ + kartitemtype_e item = (kartitemtype_e)luaL_optinteger(L, 1, KITEM_NONE); + + if (item <= 0 || item >= numkartitems) + return luaL_error(L, "item number %d out of range (0 - %d)", item, numkartitems-1); + + lua_pushboolean(L, kartitems[item].altgraphics); + return 1; +} + static int lib_kIsKartItemAlternate(lua_State *L) { kartitemtype_e item = (kartitemtype_e)luaL_optinteger(L, 1, KITEM_NONE); @@ -5530,6 +5547,7 @@ static luaL_Reg lib[] = { {"K_GetKartFlashing",lib_kGetKartFlashing}, {"K_GetItemPatch",lib_kGetItemPatch}, {"K_IsKartItemAlternate",lib_kIsKartItemAlternate}, + {"K_ItemHasAltPatches", lib_kItemHasAltPatches}, {"K_IsAltShrunk", lib_kIsAltShrunk}, {"K_SetRaceCountdown",lib_kSetRaceCountdown}, {"K_SetExitCountdown",lib_kSetExitCountdown},