Skip to content

Commit

Permalink
id24: implement DEHACKED "Carousel icon" weapon block field (#2144)
Browse files Browse the repository at this point in the history
  • Loading branch information
rfomin authored Jan 16, 2025
1 parent ce584fb commit bfe1af9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
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

This comment has been minimized.

Copy link
@fabiangreffrath

fabiangreffrath Jan 16, 2025

Owner

Should we re-indent (this part of) src/d_deh.c with our clang-format rules? Its layout has really become close to unreadable.

This comment has been minimized.

Copy link
@rfomin

rfomin Jan 16, 2025

Author Collaborator

I think we should reformat the whole d_deh.c, redo the logging (if (fpout) fprintf(...)), add enums for arrays, etc.

This comment has been minimized.

Copy link
@fabiangreffrath

fabiangreffrath Jan 16, 2025

Owner

I agree, logging is a mess, and lines like if (!strcasecmp(key, deh_weapon[8])) (why 8?) make the whole code fragile and hard to work with.

This comment has been minimized.

Copy link
@rfomin

rfomin Jan 16, 2025

Author Collaborator

Okay, I'll finish with the changelog then I'll start formatting/refactoring.

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

0 comments on commit bfe1af9

Please sign in to comment.