Minor changes and fixes

This commit is contained in:
Jaime Ita Passos 2021-08-10 15:17:22 -03:00
parent 655b48b52e
commit 1a84f1bcba
14 changed files with 96 additions and 76 deletions

View file

@ -375,10 +375,10 @@ typedef struct player_s
UINT16 flashcount;
UINT16 flashpal;
// Player skin colorshift, 0-15 for which color to draw player.
// Player skin colorshift, which color to draw player.
UINT16 skincolor;
INT32 skin;
UINT8 skin;
UINT32 availabilities;
UINT32 score; // player score

View file

@ -187,7 +187,7 @@ void clear_levels(void)
P_AllocMapHeader(gamemap-1);
}
static boolean findFreeSlot(INT32 *num)
static boolean findCharacterSlot(INT32 *num)
{
if (description)
{
@ -213,30 +213,43 @@ void readPlayer(MYFILE *f, INT32 num)
char *s = Z_Malloc(MAXLINELEN, PU_STATIC, NULL);
char *word;
char *word2;
char *displayname = ZZ_Alloc(MAXLINELEN+1);
INT32 i;
boolean slotfound = false;
boolean failure = false;
INT32 i;
if (num < 0 || num >= MAXCHARACTERSLOTS)
{
deh_warning("Character %d out of range (0 - %d)", num, MAXCHARACTERSLOTS-1);
failure = true;
}
#define FINDSLOT \
if (!failure && !slotfound && (slotfound = findCharacterSlot(&num)) == false) { \
failure = true; \
deh_warning("Too many characters, ignoring"); \
}
#define SLOTFOUND \
if (!slotfound && (slotfound = findFreeSlot(&num)) == false) \
goto done;
displayname[MAXLINELEN] = '\0';
FINDSLOT \
if (failure) \
continue;
do
{
if (myfgets(s, MAXLINELEN, f))
{
char stringvalue[MAXLINELEN];
if (s[0] == '\n')
break;
for (i = 0; i < MAXLINELEN-3; i++)
stringvalue[0] = '\0';
for (i = 0; i < MAXLINELEN-3 && !failure; i++)
{
char *tmp;
if (s[i] == '=')
{
tmp = &s[i+2];
strncpy(displayname, tmp, SKINNAMESIZE);
strlcpy(stringvalue, &s[i+2], sizeof stringvalue);
break;
}
}
@ -251,7 +264,13 @@ void readPlayer(MYFILE *f, INT32 num)
{
char *playertext = NULL;
SLOTFOUND
FINDSLOT
if (failure)
{
ignorelinesuntilhash(f);
continue;
}
// A friendly neighborhood alias for brevity's sake
#define NOTE_SIZE sizeof(description[num].notes)
@ -271,7 +290,7 @@ void readPlayer(MYFILE *f, INT32 num)
myhashfgets(playertext, NOTE_SIZE, f), NOTE_SIZE);
}
else
strcpy(description[num].notes, "");
description[num].notes[0] = '\0';
// For some reason, cutting the string did not work above. Most likely due to strcpy or strcat...
// It works down here, though.
@ -300,37 +319,32 @@ void readPlayer(MYFILE *f, INT32 num)
if (word2[strlen(word2)-1] == '\n')
word2[strlen(word2)-1] = '\0';
i = atoi(word2);
if (fastcmp(word, "PICNAME"))
{
SLOTFOUND
strncpy(description[num].picname, word2, 8);
}
// new character select
else if (fastcmp(word, "DISPLAYNAME"))
{
char *cur = NULL;
SLOTFOUND
// replace '#' with line breaks
// (also remove any '\n')
// Remove any line breaks
cur = strchr(stringvalue, '\n');
if (cur)
*cur = '\0';
// Turn '#' into line breaks
cur = strchr(stringvalue, '#');
while (cur)
{
char *cur = NULL;
// remove '\n'
cur = strchr(displayname, '\n');
if (cur)
*cur = '\0';
// turn '#' into '\n'
cur = strchr(displayname, '#');
while (cur)
{
*cur = '\n';
cur = strchr(cur, '#');
}
*cur = '\n';
cur = strchr(cur, '#');
}
// copy final string
strncpy(description[num].displayname, displayname, SKINNAMESIZE);
strlcpy(description[num].displayname, stringvalue, sizeof description[num].displayname);
}
else if (fastcmp(word, "OPPOSITECOLOR") || fastcmp(word, "OPPOSITECOLOUR"))
{
@ -361,10 +375,12 @@ void readPlayer(MYFILE *f, INT32 num)
Because of this, you are allowed to edit any previous entries you like, but only if you
signal that you are purposely doing so by disabling and then reenabling the slot.
*/
if (i && !slotfound && (slotfound = findFreeSlot(&num)) == false)
goto done;
i = atoi(word2);
if (i && !slotfound && (slotfound = findCharacterSlot(&num)) == false)
failure = true;
description[num].used = (!!i);
if (!failure)
description[num].used = (!!i);
}
else if (fastcmp(word, "SKINNAME"))
{
@ -373,13 +389,12 @@ void readPlayer(MYFILE *f, INT32 num)
strlcpy(description[num].skinname, word2, sizeof description[num].skinname);
strlwr(description[num].skinname);
}
else
else if (!failure)
deh_warning("readPlayer %d: unknown word '%s'", num, word);
}
} while (!myfeof(f)); // finish when the line is empty
#undef FINDSLOT
#undef SLOTFOUND
done:
Z_Free(displayname);
Z_Free(s);
}
@ -920,7 +935,7 @@ void readspriteinfo(MYFILE *f, INT32 num, boolean sprite2)
INT32 value;
#endif
char *lastline;
INT32 *skinnumbers = NULL;
UINT8 *skinnumbers = NULL;
INT32 foundskins = 0;
// allocate a spriteinfo
@ -1010,8 +1025,8 @@ void readspriteinfo(MYFILE *f, INT32 num, boolean sprite2)
}
if (skinnumbers == NULL)
skinnumbers = Z_Malloc(sizeof(INT32) * numskins, PU_STATIC, NULL);
skinnumbers[foundskins] = skinnum;
skinnumbers = Z_Malloc(sizeof(UINT8) * numskins, PU_STATIC, NULL);
skinnumbers[foundskins] = (UINT8)skinnum;
foundskins++;
}
else if (fastcmp(word, "DEFAULT"))
@ -1054,8 +1069,7 @@ void readspriteinfo(MYFILE *f, INT32 num, boolean sprite2)
}
for (i = 0; i < foundskins; i++)
{
size_t skinnum = skinnumbers[i];
skin_t *skin = skins[skinnum];
skin_t *skin = skins[skinnumbers[i]];
spriteinfo_t *sprinfo = skin->sprinfo;
M_Memcpy(&sprinfo[num], info, sizeof(spriteinfo_t));
}
@ -1121,7 +1135,6 @@ void readsprite2(MYFILE *f, INT32 num)
Z_Free(s);
}
// copypasted from readPlayer :]
void readgametype(MYFILE *f, char *gtname)
{
char *s = Z_Malloc(MAXLINELEN, PU_STATIC, NULL);

View file

@ -169,6 +169,20 @@ static void ignorelines(MYFILE *f)
Z_Free(s);
}
void ignorelinesuntilhash(MYFILE *f)
{
char *s = Z_Malloc(MAXLINELEN, PU_STATIC, NULL);
do
{
if (myfgets(s, MAXLINELEN, f))
{
if (s[0] == '#')
break;
}
} while (!myfeof(f));
Z_Free(s);
}
static void DEH_LoadDehackedFile(MYFILE *f, boolean mainfile)
{
char *s = Z_Malloc(MAXLINELEN, PU_STATIC, NULL);
@ -226,13 +240,7 @@ static void DEH_LoadDehackedFile(MYFILE *f, boolean mainfile)
i = 0;
if (fastcmp(word, "CHARACTER"))
{
if (i >= 0 && i < MAXCHARACTERSLOTS)
readPlayer(f, i);
else
{
deh_warning("Character %d out of range (0 - 31)", i);
ignorelines(f);
}
readPlayer(f, i);
continue;
}
else if (fastcmp(word, "EMBLEM"))

View file

@ -61,4 +61,5 @@ typedef struct
#define myfeof(a) (a->data + a->size <= a->curpos)
char *myfgets(char *buf, size_t bufsize, MYFILE *f);
char *myhashfgets(char *buf, size_t bufsize, MYFILE *f);
void ignorelinesuntilhash(MYFILE *f);
#endif

View file

@ -220,10 +220,11 @@ extern char logfilename[1024];
// NOTE: it needs more than this to increase the number of players...
#define MAXPLAYERS 32
#define MAXSKINS 256
#define MAXCHARACTERSLOTS (MAXSKINS * 2)
#define PLAYERSMASK (MAXPLAYERS-1)
#define MAXPLAYERNAME 21
#define PLAYERSMASK (MAXPLAYERS-1)
#define MAXSKINS 256
#define MAXCHARACTERSLOTS (MAXSKINS * 3)
#define COLORRAMPSIZE 16
#define MAXCOLORNAME 32

View file

@ -2488,7 +2488,7 @@ void G_PlayerReborn(INT32 player, boolean betweenmaps)
UINT8 laps;
UINT8 mare;
UINT16 skincolor;
INT32 skin;
UINT8 skin;
UINT32 availabilities;
tic_t jointime;
tic_t quittime;

View file

@ -5359,7 +5359,7 @@ static void HWR_ProjectSprite(mobj_t *thing)
}
else if (thing->skin && thing->sprite == SPR_PLAY) // This thing is a player!
{
INT32 skinnum = ((skin_t*)thing->skin)->skinnum;
UINT8 skinnum = ((skin_t*)thing->skin)->skinnum;
vis->colormap = R_GetTranslationColormap(skinnum, thing->color, GTC_CACHE);
}
else

View file

@ -1271,7 +1271,7 @@ boolean HWR_DrawModel(gl_vissprite_t *spr)
// 2. draw model with correct position, rotation,...
if (spr->mobj->skin && spr->mobj->sprite == SPR_PLAY) // Use the player MD2 list if the mobj has a skin and is using the player sprites
{
INT32 skinnum = ((skin_t*)spr->mobj->skin)->skinnum;
UINT8 skinnum = ((skin_t*)spr->mobj->skin)->skinnum;
md2 = &md2_playermodels[skinnum];
sprinfo = &((skin_t *)spr->mobj->skin)->sprinfo[spr->mobj->sprite2];
}

View file

@ -375,10 +375,8 @@ typedef struct
patch_t *charpic;
UINT8 prev;
UINT8 next;
// new character select
char displayname[SKINNAMESIZE+1];
SINT8 skinnum[2];
INT16 skinnum[2];
UINT16 oppositecolor;
char nametag[8];
patch_t *namepic;

View file

@ -1498,7 +1498,7 @@ static void R_ParseSpriteInfo(boolean spr2)
spritenum_t sprnum = NUMSPRITES;
playersprite_t spr2num = NUMPLAYERSPRITES;
INT32 i;
INT32 *skinnumbers = NULL;
UINT8 *skinnumbers = NULL;
INT32 foundskins = 0;
// Sprite name
@ -1597,8 +1597,8 @@ static void R_ParseSpriteInfo(boolean spr2)
I_Error("Error parsing SPRTINFO lump: Unknown skin \"%s\"", skinName);
if (skinnumbers == NULL)
skinnumbers = Z_Malloc(sizeof(INT32) * numskins, PU_STATIC, NULL);
skinnumbers[foundskins] = skinnum;
skinnumbers = Z_Malloc(sizeof(UINT8) * numskins, PU_STATIC, NULL);
skinnumbers[foundskins] = (UINT8)skinnum;
foundskins++;
}
else if (stricmp(sprinfoToken, "FRAME")==0)
@ -1611,8 +1611,7 @@ static void R_ParseSpriteInfo(boolean spr2)
I_Error("Error parsing SPRTINFO lump: No skins specified in this sprite2 definition");
for (i = 0; i < foundskins; i++)
{
size_t skinnum = skinnumbers[i];
skin_t *skin = skins[skinnum];
skin_t *skin = skins[skinnumbers[i]];
spriteinfo_t *sprinfo = skin->sprinfo;
M_Memcpy(&sprinfo[spr2num], info, sizeof(spriteinfo_t));
}

View file

@ -278,7 +278,7 @@ INT32 R_SkinAvailable(const char *name)
{
// search in the skin list
if (!stricmp(skins[i]->name,name))
return skins[i]->skinnum;
return i;
}
return -1;
}

View file

@ -31,8 +31,8 @@
/// The skin_t struct
typedef struct
{
char name[SKINNAMESIZE+1]; // INT16 descriptive name of the skin
UINT32 skinnum;
char name[SKINNAMESIZE+1]; // name of the skin
UINT8 skinnum;
UINT16 wadnum;
skinflags_t flags;

View file

@ -764,7 +764,7 @@ UINT8 *R_GetSpriteTranslation(vissprite_t *vis)
}
else if (!(vis->cut & SC_PRECIP) && vis->mobj->skin && vis->mobj->sprite == SPR_PLAY) // This thing is a player!
{
INT32 skinnum = ((skin_t*)vis->mobj->skin)->skinnum;
UINT8 skinnum = ((skin_t*)vis->mobj->skin)->skinnum;
return R_GetTranslationColormap(skinnum, vis->mobj->color, GTC_CACHE);
}
else // Use the defaults

View file

@ -1617,7 +1617,7 @@ static void Y_CalculateMatchWinners(void)
{
data.match.scores[data.match.numplayers] = players[i].score;
data.match.color[data.match.numplayers] = &players[i].skincolor;
data.match.character[data.match.numplayers] = &players[i].skin;
data.match.character[data.match.numplayers] = players[i].skin;
data.match.name[data.match.numplayers] = player_names[i];
data.match.spectator[data.match.numplayers] = players[i].spectator;
data.match.num[data.match.numplayers] = i;
@ -1662,7 +1662,7 @@ static void Y_CalculateTimeRaceWinners(void)
{
data.match.scores[data.match.numplayers] = players[i].realtime;
data.match.color[data.match.numplayers] = &players[i].skincolor;
data.match.character[data.match.numplayers] = &players[i].skin;
data.match.character[data.match.numplayers] = players[i].skin;
data.match.name[data.match.numplayers] = player_names[i];
data.match.num[data.match.numplayers] = i;
}
@ -1788,7 +1788,7 @@ static void Y_CalculateCompetitionWinners(void)
strncpy(data.competition.name[data.competition.numplayers], tempname, 9);
data.competition.color[data.competition.numplayers] = &players[winner].skincolor;
data.competition.character[data.competition.numplayers] = &players[winner].skin;
data.competition.character[data.competition.numplayers] = players[winner].skin;
completed[winner] = true;
data.competition.numplayers++;
@ -2110,7 +2110,7 @@ static void Y_AwardSpecialStageBonus(void)
if (players[i].gotcontinue)
data.spec.continues |= 0x80;
data.spec.playercolor = &players[i].skincolor;
data.spec.playerchar = &players[i].skin;
data.spec.playerchar = players[i].skin;
}
}
}