Obj_AudienceInit: Clean up handling

- Don't require a mapthing to select a random Follower from the Audience list
- Don't print an error message if the mapheader Audience list is empty. This is probably intentional.
This commit is contained in:
toaster 2023-11-04 13:28:21 +00:00
parent c2d48e8ca7
commit ec4ea384c3

View file

@ -29,6 +29,7 @@ Obj_AudienceInit
mapthing_t *mthing, mapthing_t *mthing,
INT32 followerpick) INT32 followerpick)
{ {
const boolean ourchoiceofvisuals = (followerpick < 0 || followerpick > numfollowers);
INT16 *reflist = NULL; INT16 *reflist = NULL;
INT16 tempreflist[MAXHEADERFOLLOWERS]; INT16 tempreflist[MAXHEADERFOLLOWERS];
UINT8 numref = 0; UINT8 numref = 0;
@ -36,9 +37,9 @@ Obj_AudienceInit
audience_mainstate(mobj) = S_NULL; audience_mainstate(mobj) = S_NULL;
// Pick follower // Pick follower
if (mthing != NULL) if (ourchoiceofvisuals == true)
{ {
if (mthing->thing_stringargs[0] != NULL) if (mthing != NULL && mthing->thing_stringargs[0] != NULL)
{ {
// From mapthing // From mapthing
char *stringcopy = Z_StrDup(mthing->thing_stringargs[0]); char *stringcopy = Z_StrDup(mthing->thing_stringargs[0]);
@ -56,11 +57,23 @@ Obj_AudienceInit
*c = ' '; *c = ' ';
} }
if ((tempreflist[numref++] = K_FollowerAvailable(tok)) == -1) if ((tempreflist[numref] = K_FollowerAvailable(tok)) == -1)
{
CONS_Alert(CONS_WARNING, "Mapthing %s: Follower \"%s\" is invalid!\n", sizeu1(mthing-mapthings), tok); CONS_Alert(CONS_WARNING, "Mapthing %s: Follower \"%s\" is invalid!\n", sizeu1(mthing-mapthings), tok);
}
else
numref++;
tok = strtok(NULL, " ,"); tok = strtok(NULL, " ,");
} }
if (!numref)
{
// This is the one thing a user should definitely be told about.
CONS_Alert(CONS_WARNING, "Mapthing %s: Follower audience has no valid followers to pick from!\n", sizeu1(mthing-mapthings));
// DO NOT RETURN HERE
}
Z_Free(stringcopy); Z_Free(stringcopy);
reflist = tempreflist; reflist = tempreflist;
@ -81,8 +94,8 @@ Obj_AudienceInit
if (!numref || !reflist) if (!numref || !reflist)
{ {
// This is the one thing a user should definitely be told about. // Clean up after ourselves.
CONS_Alert(CONS_WARNING, "Mapthing %s: Follower audience has no valid followers to pick from!\n", sizeu1(mthing-mapthings)); P_RemoveMobj(mobj);
return; return;
} }
@ -137,11 +150,11 @@ Obj_AudienceInit
} }
// Handle colors // Handle colors
if (mthing != NULL) if (ourchoiceofvisuals == true)
{ {
UINT16 colorpick = SKINCOLOR_NONE; UINT16 colorpick = SKINCOLOR_NONE;
if (mthing->thing_stringargs[1] != NULL) if (mthing != NULL && mthing->thing_stringargs[1] != NULL)
{ {
if (!stricmp("Random", mthing->thing_stringargs[1])) if (!stricmp("Random", mthing->thing_stringargs[1]))
{ {