Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

id24: implement DEHACKED "Carousel icon" weapon block field #2144

Merged
merged 2 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/d_deh.c
Original file line number Diff line number Diff line change
Expand Up @@ -1503,6 +1503,8 @@ char *deh_weapon[] =
// mbf21
"Ammo per shot", // .ammopershot
"MBF21 Bits", // .flags
// id24
"Carousel icon", // .carouselicon
};

// CHEATS - Dehacked block name = "Cheat"
Expand Down Expand Up @@ -2566,7 +2568,20 @@ void deh_procWeapon(DEHFILE *fpin, FILE* fpout, char *line)

weaponinfo[indexnum].flags = value;
}
else
else
if (!strcasecmp(key, deh_weapon[8])) // Carousel icon
{
char candidate[9] = {0};
M_CopyLumpName(candidate, ptr_lstrip(strval));
int len = strlen(candidate);
if (len < 1 || len > 7)
{
if (fpout) fprintf(fpout,"Bad length for carousel icon name '%s'\n",candidate);
continue;
}
weaponinfo[indexnum].carouselicon = M_StringDuplicate(candidate);
}
else
if (fpout) fprintf(fpout,"Invalid weapon string index for '%s'\n",key);
}
return;
Expand Down Expand Up @@ -3397,7 +3412,7 @@ void rstrip(char *s) // strip trailing whitespace
//
char *ptr_lstrip(char *p) // point past leading whitespace
{
while (*p >= 0 && isspace(*p))
while (*p && isspace(*p))
p++;
return p;
}
Expand Down
1 change: 1 addition & 0 deletions src/d_items.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ typedef struct
int flags;
// id24
int slot;
const char *carouselicon;
} weaponinfo_t;

extern weaponinfo_t weaponinfo[NUMWEAPONS+2];
Expand Down
14 changes: 12 additions & 2 deletions src/st_carousel.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include <math.h>

#include "d_items.h"
#include "d_player.h"
#include "doomdef.h"
#include "doomtype.h"
Expand Down Expand Up @@ -164,8 +165,17 @@ void ST_UpdateCarousel(player_t *player)
static void DrawIcon(int x, int y, sbarelem_t *elem, weapon_icon_t icon)
{
char lump[9] = {0};
M_snprintf(lump, sizeof(lump), "%s%d", names[icon.weapon],
icon.state == wpi_selected);
const char *name;
if (weaponinfo[icon.weapon].carouselicon)
{
name = weaponinfo[icon.weapon].carouselicon;
}
else
{
name = names[icon.weapon];
}

M_snprintf(lump, sizeof(lump), "%s%d", name, icon.state == wpi_selected);

patch_t *patch = V_CachePatchName(lump, PU_CACHE);

Expand Down