From c7cc730c351416f1df97e2052ba95cc34f8aaefd Mon Sep 17 00:00:00 2001 From: toaster Date: Fri, 21 Apr 2023 21:06:21 +0100 Subject: [PATCH] Obj_AudienceInit: Improve color handling - Catch all invalid colors with default randomisation - Catch invalid colors more thoroughly - Report typos to the user --- src/objects/audience.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/objects/audience.c b/src/objects/audience.c index 466dd01b2..f924878a4 100644 --- a/src/objects/audience.c +++ b/src/objects/audience.c @@ -123,7 +123,7 @@ Obj_AudienceInit if (mthing->stringargs[1] != NULL) { - if (!strcmp("Random", mthing->stringargs[1])) + if (!stricmp("Random", mthing->stringargs[1])) { colorpick = FOLLOWERCOLOR_MATCH; } @@ -135,7 +135,8 @@ Obj_AudienceInit numref = 0; while (tok && numref < MAXHEADERFOLLOWERS) { - tempreflist[numref++] = R_GetColorByName(tok); + if ((tempreflist[numref++] = R_GetColorByName(tok)) == SKINCOLOR_NONE) + CONS_Alert(CONS_WARNING, "Mapthing %s: Follower color \"%s\" is invalid!\n", sizeu1(mthing-mapthings), tok); tok = strtok(NULL, " "); } @@ -148,13 +149,15 @@ Obj_AudienceInit } } - if (colorpick == SKINCOLOR_NONE) + if (colorpick == SKINCOLOR_NONE + || (colorpick >= numskincolors + && colorpick != FOLLOWERCOLOR_MATCH + && colorpick != FOLLOWERCOLOR_OPPOSITE)) { colorpick = followers[followerpick].defaultcolor; } - if (colorpick == FOLLOWERCOLOR_MATCH - || colorpick == FOLLOWERCOLOR_OPPOSITE) + if (colorpick >= numskincolors) { colorpick = P_RandomKey(PR_RANDOMAUDIENCE, numskincolors-1)+1; }