Add support for Alt. item patches

This commit is contained in:
yamamama 2025-12-07 19:58:48 -05:00
parent 09bfc6506a
commit 6aa50b62d7
5 changed files with 50 additions and 11 deletions

View file

@ -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;
}
}

View file

@ -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;

View file

@ -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;

View file

@ -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);

View file

@ -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},