Here's a fairly simple enhancement to allow this:
Add screen.h to comm.c and replace proc_colours:
static size_t proc_colors(char *txt, size_t maxlen, int char_colour_pref)
{
char *d, *s, *c, *p;
int i;
int colour_level = C_NRM;
if (!txt || !strchr(txt, '@')) /* skip out if no color codes */
return strlen(txt);
s = txt;
CREATE(d, char, maxlen);
p = d;
for( ; *s && ((size_t)(d-p) < maxlen); ) {
/* no color code - just copy */
if (*s != '@') {
*d++ = *s++;
continue;
}
/* if we get here we have a color code */
s++; /* s now points to the code */
switch(*s)
{
case 0: *d++ = '@'; continue; /* string was terminated with @; make sure s stays at the 0 */
case '@': *d++ = '@'; break; /* Always a @ */
case '+': colour_level = C_SPR; break; /* high colour - show even if SPARSE */
case '=': colour_level = C_NRM; break; /* normal colour */
case '-': colour_level = C_CMP; break; /* low colour - show only if COMPLETE */
default:
if (char_colour_pref >= colour_level) { /* only copy the new code if above the level */
for (i = 0; CCODE[i] != '!'; i++) { /* do we find it ? */
if ((*s) == CCODE[i]) { /* if so :*/
/* c now points to the first char in color code*/
for(c = ANSI[i] ; *c && ((size_t)(d-p) < maxlen); )
*d++ = *c++;
break;
}
}
}
break;
}
/* Whatever the code was (even invalid), skip it */
s++;
} /* for loop */
/* make sure txt is NULL - terminated */
d = 0;
strncpy(txt, p, maxlen-1);
free(p);
return strlen(txt);
}
and in vwrite_to_output, remove the if(t->character) check and insert this:
{
// Inherit colour settings if switched
struct char_data *dest = t->original ? t->original : t->character;
int colour_level = dest ? _clrlevel(dest) : 0;
wantsize = size = proc_colors(txt, sizeof(txt), colour_level);
}
This adds three new @ codes: @+, @= and @-, meaning 'sparse' 'normal' and 'complete' respectively. The setting applies from that point forward. In addition, @-code colours preferences are now taken from the parent character if switched.
A couple of design decisions here are up for grabs:
- should -, =, + correspond to the amount of colour displayed (+ means more colour visible, so SPR) or the user's settings (+ means more colour wanted, so CMP). Went with the former.
- What's the default? To match the existing behaviour it would want to be sparse. Went with NRM, the wiser design decision going forwards I reckon.
- push and pop might possibly be useful?
Possible that this also fixes a bug with the raw colour codes appearing if t->character was 0, but that's a rather unlikely situation, so probably not important.
Feel free to pull this into TBA if required. (I'm in the process of merging a very old MUD codebase with TBA, I've plenty of bug reports and small and large suggestions for enhancements coming at some point).