char whatColor(char *str, char *pos)
{ static char col;
col = 'x';
while(str != pos)
{ if(*str == '&')
{ ++str;
if(!str) break;
col = *str;
}
++str;
}
return col;
}
/* Add the text, if necessary */
if( !alldesc )
{
pos = get_line( p, 63 );
char col[3], c;
c = (char)whatColor(text, p);
if(c == 'x')
sprintf(col, "%s", ch->color_str(AT_RMDESC) );
else
sprintf(col, "&%c", c);
if( pos > 0 )
{
mudstrlcat( buf, col, MSL*2 );
strncat( buf, p, pos );
p += pos;
}
else
{
mudstrlcat( buf, col, MSL*2 );
mudstrlcat( buf, p, MSL*2 );
alldesc = true;
}
}
I have that function as part of AFKMud 2.0. It has a slight bug, which probably wasn't readily noticed. But when the room descriptions are split up based on how large the mini-map segment is. But when this splitting is done, the color codes don't carry over to the next line the way they should.
So I was hoping someone better with strings than I am could help with this. Valid color tags in AFKMud are &, {, and }. Ideally the last color tag change in a line should carry over as the first color tag on the next line's text.
Sample output of a room description with the mini-map:
This description begins life as cyan, tag &c, but that only goes out to the end of the first line at which point everything reverts back to default.