The Dawn Of Time
The Official Forums for the Dawn Of Time Mud Codebase
 
Log in Register FAQ Memberlist Search The Dawn Of Time Forum Index Goto the Official Dawn Website

1.6 million colors

 
Post new topic   Reply to topic    The Dawn Of Time Forum Index » Snippets
View previous topic :: View next topic  
Author Message
Trell



Joined: 28 Jun 2013
Posts: 49

PostPosted: Thu Dec 10, 2015 5:15 pm    Post subject: 1.6 million colors Reply with quote

Some of you may already know what hex color values are. They appear in the colour.cpp file in the colour table at the top for html and mxp color values, but there are millions more values that muds don't often make use of because there's no simple way to do it. I've created a system that allows inputting these hex values directly through the mud to use them if you can't quite get the color you're looking for with the standard and extended colours from the colour table. By using : as a special color code, we can do things like "short `:222222A male dwarf`w" for an extra black short description. The six digits following the `: will be used as the hex code. Hex code values can be found all over the web, but we keep a link in our colour help file to http://www.rapidtables.com/web/color/RGB_Color.htm which is a pretty good place to get easy codes. Two things of note: First, even though `x and `w use the same colour values in the colour table, `x does not always work to reset the colour whereas `w does. I do not know why. Second, not everyone will be able to see hex colors, as they rely on mxp and/or html, but the system will use preceding colors instead, since there is no table to default to like colors, so you would instead use "short `S`:222222A male dwarf`w" and people with html would see the hex colors, and people with ansi would see the `S color. Obviously it's not as user friendly as everything else in the colour code is, but it is a powerful thing without limits, so it's understandably a little more complex.

This is not hard code, but it is semi-complex in its placement in some places, so make backups before you begin just in case, because if you drop something in the wrong place, it might mess with your displays of things. There is also not much to it....

In colour.cpp near the bottom of the colour_table at the top of the file, add with the rest of the symbol lines:
Code:

{':', "custom hex code", true, true, "", "", "", "", "", "", ""},


Next, in colour.cpp in the process_colour() function find:
Code:

if (*pSrc==COLOURCODE){
         // check for special codes
         if(colourTable[(unsigned char)*(++pSrc)].special){


and along with the other special character handling if/else if checks in there add:
Code:

else if (*pSrc==':'){
               if(cType!=CT_HTML && cType != CT_MXP && cType != CT_BRIGHT){
                  //not html/mxp/bright, use `w
                  ++pSrc;
                  ++pSrc;
                  ++pSrc;
                  ++pSrc;
                  ++pSrc;
                  ++pSrc;
                  col = baseCol;
               }else{
                  ++pSrc;
                  char chex[11];
                  char cfull[MIL];
                  int z;
                  chex[0] = '#';
                  for (z = 1;z<7 ;z++ )
                  {
                     chex[z] = *pSrc++;
                  }
                  chex[z] = '\0';
                  switch (cType)
                  {
                  case CT_HTML:
                     sprintf(cfull,"</FONT><FONT COLOR=\"%s\">",chex);
                     break;
                  case CT_MXP:
                  case CT_BRIGHT:
                     sprintf(cfull,"</C><C \"%s\">",chex);
                     break;
                  default:
                     sprintf(cfull,"%s",chex);
                     break;
                  }
                  
                  col = (char*)cfull;
                  pSrc--;
               }


You now have 1.6 million colors, but we're not done. We need to handle places where strings are formatted and counted to handle 7 character color codes, or else .f and such in editors will stop working right with them...

In note.cpp in note_format_string_width() find this:
Code:

// calculate the effects of colour codes
            if (*(point)=='`')
            {
               i++;
               point++;
               *point= *(rdesc+i); // copy the next character
               switch (*point)
               {
                  default: // most codes count as none
                     vischars--;
                     break;


and in the switch add:
Code:

case ':':
                  vischars -= 7;
                  //i+=5;
                  //point+=5;
                  break;


In string.cpp find this code:
Code:

// record the last space location.
            if (*(point)==' ')
            {
               last_space=i;
            }
            
            // calculate the effects of colour codes
            if (*(point)=='`')
            {
               i++;
               point++;
               *point= *(rdesc+i); // copy the next character
               switch (*point)
               {
               default: // most codes count as none
                  vischars--;
                  break;


and in that switch statement add:
Code:

case ':':
                  logf("vischars %d",vischars);
                  vischars -= 7;
                  i+=5;
                  point+=5;
                  break;


And finally in handler.cpp in the c_str_len() function find:
Code:

case '=': // custom colour
               s++; // skip the '=' moving to the colour char...
                   // we don't bother counting it since we assume
                   // it is always a colour
               break;


and below it add:
Code:

case ':':
               s++;
               len--;
               len--;
               len--;
               len--;
               len--;
               len--;
               break;


And that's all I've done with it, and it works well with everything we've used hex colors for... rooms, shorts, objects... it's pretty cool, you know... if you like colors.


Back to top
View user's profile Send private message
cheshik



Joined: 02 Oct 2018
Posts: 7
Location: Russia

PostPosted: Thu Oct 11, 2018 11:12 pm    Post subject: Reply with quote

Thank you, Trell! This is indeed a really cool snippet and allows to do many new things not available in regular MUDs...

I implemented your snippet into 1.69s_beta6, but get "too long string" problems after editing descriptions with hex colors assigned, e.g.:
`:10010001`:0e01001`:1302001`:1b04000`:2205000`:2706000`:2c09011`:320b021`:320c021`:300c031`:3e190e0`:3b150a1`:350e030`:370d020`:360c021`:3c0d021`:450f010`:4a10010`:5413020`:6018020`:7020040`:7c27051`:812c060`:822e061`:8330080`:8934080`:8432070`:9238070`:9b3b071`:9f3b061`:a13c060`:a43f071`:a845081`:ae4e0a0`:b3550c1`:ba610e1`:c170140`:c7831c1`:cc94261`:dab14f1`:debb680`:d29c290`:cc86190`:c673110`:a75a111`:6320041`:6f370e0`:99420a0`:993a060`:8f35060`:8831061`:8e3e0a1`:8833071`:8331060`:772e060`:702e071`:6a78450`:94a4920`:848f621`:7d4a171`:5b1e031`:5016020`:430f010`:380b010`:320a010`:3109010`:2a07011`:2506000`:2406001`:2706011`:2e08011`:3109010`:2e08010`:2d07000`:2606001`:1e04001`:1b04001`:1c04001`:1b03000`w

Not sure how to fix this. Could it be related to MLN?
Did you have any problems like this and if so, how did you fix them?


Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    The Dawn Of Time Forum Index » Snippets All times are GMT + 13 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001-2005 phpBB Group
Theme created by Vjacheslav Trushkin