2008-01-16 23:19:50 +00:00
|
|
|
|
If you have any additions, corrections, ideas, or bug reports please stop by the
|
|
|
|
|
|
Builder Academy at telnet://tbamud.com:9091 or email rumble@tbamud.com -- Rumble
|
|
|
|
|
|
|
|
|
|
|
|
Using Color In tbaMUD
|
|
|
|
|
|
Originally by Jeremy Elson
|
|
|
|
|
|
|
|
|
|
|
|
This document is a description of how to write C code which displays messages
|
|
|
|
|
|
to players in color in the tbaMUD game engine. Its intended audience is for
|
|
|
|
|
|
Coders of tbaMUD.
|
|
|
|
|
|
|
|
|
|
|
|
tbaMUD allows you to create colorful messages by using ANSI control sequences.
|
2025-07-02 21:26:19 +02:00
|
|
|
|
Each player may select what “level” of color he/she desires from the four
|
|
|
|
|
|
levels “off,” “brief,” “normal,” and “complete.” Each player can select his/her
|
2008-01-16 23:19:50 +00:00
|
|
|
|
color level by using the TOGGLE COLOR command from within the MUD; you as the
|
|
|
|
|
|
programmer must decide which messages will be colored for each of the color
|
|
|
|
|
|
levels.
|
|
|
|
|
|
|
|
|
|
|
|
All files in which you wish to use color must have the line:
|
|
|
|
|
|
|
|
|
|
|
|
#include "screen.h"
|
|
|
|
|
|
|
|
|
|
|
|
This should be put in after all other includes in the beginning of the file.
|
|
|
|
|
|
|
2025-07-02 21:26:19 +02:00
|
|
|
|
There are 8 colors available – “normal,” red, green, yellow, blue, magenta,
|
2008-01-16 23:19:50 +00:00
|
|
|
|
cyan and white. They are accessible by sending control sequences as part of
|
|
|
|
|
|
another string, for example:
|
|
|
|
|
|
|
2025-07-02 21:26:19 +02:00
|
|
|
|
sprintf(buf, "If you’re %shappy%s and you know it clap "
|
2008-01-16 23:19:50 +00:00
|
|
|
|
"%d of your hands.\n\r", x, y, num_of_hands);
|
|
|
|
|
|
send_to_char(ch, buf);
|
|
|
|
|
|
|
2025-07-02 21:26:19 +02:00
|
|
|
|
In this example, x and y are the “on” and “off” sequences for the color you
|
|
|
|
|
|
want. There are 2 main series of color macros available for you to use (don’t
|
|
|
|
|
|
actually use “x” and “y,” of course!): the K series and the CC series. The CC
|
2008-01-16 23:19:50 +00:00
|
|
|
|
(Conditional Color) series is recommended for most general use.
|
|
|
|
|
|
|
|
|
|
|
|
The name of the actual sequence starts with the name of its series, plus a
|
|
|
|
|
|
3-letter color code, as follows:
|
|
|
|
|
|
|
|
|
|
|
|
Normal: NRM
|
|
|
|
|
|
Red: RED
|
|
|
|
|
|
Yellow: YEL
|
|
|
|
|
|
Green: GRN
|
|
|
|
|
|
Blue: BLU
|
|
|
|
|
|
Magenta: MAG
|
|
|
|
|
|
Cyan: CYN
|
|
|
|
|
|
White: WHT
|
|
|
|
|
|
|
|
|
|
|
|
For example, white in the K series is KWHT; blue in the CC series is
|
|
|
|
|
|
CCBLU() (arguments defined below).
|
|
|
|
|
|
|
|
|
|
|
|
The K series requires no arguments, and is simply a macro to the ANSI color
|
|
|
|
|
|
code. Therefore, if you use a K-series color code, the color will ALWAYS be
|
2025-07-02 21:26:19 +02:00
|
|
|
|
sent, even if the person you’re sending it to has color off. This can very bad.
|
2008-01-16 23:19:50 +00:00
|
|
|
|
Some people who do not have ANSI-compatible terminals will see garbage
|
|
|
|
|
|
characters instead of colors. If the terminal correctly ignores ANSI color
|
|
|
|
|
|
codes, then nothing will show up on their screen at all. The K series is mainly
|
2025-07-02 21:26:19 +02:00
|
|
|
|
used to print colors to a string if the player’s color level will later be
|
2008-01-16 23:19:50 +00:00
|
|
|
|
tested manually (for an example, see do_gen_com in act.comm.c).
|
|
|
|
|
|
|
|
|
|
|
|
The recommended series is the CC series (i.e. CCNRM(), CCRED(), etc.) The CC
|
2025-07-02 21:26:19 +02:00
|
|
|
|
series macros require two arguments – a pointer to the character to whom the
|
2008-01-16 23:19:50 +00:00
|
|
|
|
string is being sent, and the minimum color level the player must be set to in
|
|
|
|
|
|
order to see the color. Color sent as 'brief' (formerly known as sparse it was
|
2015-03-26 12:21:07 +00:00
|
|
|
|
changed for consistency with the syslog command) (C_SPR) will be seen by people
|
2025-07-02 21:26:19 +02:00
|
|
|
|
with color set to sparse, normal, or complete; color sent as ‘normal’ (C_NRM)
|
2008-01-16 23:19:50 +00:00
|
|
|
|
will be seen only by people with color set to normal or complete; color sent as
|
2025-07-02 21:26:19 +02:00
|
|
|
|
‘complete’ (C_CMP) will be seen only by people with color set to complete.
|
2008-01-16 23:19:50 +00:00
|
|
|
|
|
|
|
|
|
|
To illustrate the above, an example is in order:
|
|
|
|
|
|
|
|
|
|
|
|
#include "screen.h"
|
|
|
|
|
|
/* include screen.h in all files that you use color in */
|
|
|
|
|
|
|
|
|
|
|
|
ACMD(do_showcolor)
|
|
|
|
|
|
{
|
|
|
|
|
|
char buf[300];
|
|
|
|
|
|
|
2025-07-02 21:26:19 +02:00
|
|
|
|
sprintf(buf, "Don’t you just love %scolor%s, %scolor%s, " "%sCOLOR%s!\n\r",
|
2008-01-16 23:19:50 +00:00
|
|
|
|
CCBLU(ch, C_CMP), CCNRM(ch, C_CMP), CCYEL(ch, C_NRM), CCNRM(ch, C_NRM),
|
|
|
|
|
|
CCRED(ch, C_SPR), CCNRM(ch, C_SPR));
|
|
|
|
|
|
send_to_char(ch, buf);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
What does this do? For people with color set to Complete, it prints:
|
2025-07-02 21:26:19 +02:00
|
|
|
|
Don’t you just love color, color, COLOR! (blue) (yellow) (red)
|
2008-01-16 23:19:50 +00:00
|
|
|
|
|
|
|
|
|
|
People who have color set to Normal will see:
|
2025-07-02 21:26:19 +02:00
|
|
|
|
Don’t you just love color, color, COLOR! (yellow) (red)
|
2008-01-16 23:19:50 +00:00
|
|
|
|
|
|
|
|
|
|
People who have color set to Sparse will see:
|
2025-07-02 21:26:19 +02:00
|
|
|
|
Don’t you just love color, color, COLOR! (red)
|
2008-01-16 23:19:50 +00:00
|
|
|
|
|
|
|
|
|
|
People who have color set to Off will see:
|
2025-07-02 21:26:19 +02:00
|
|
|
|
Don’t you just love color, color, COLOR! (no color, as you’d expect)
|
2008-01-16 23:19:50 +00:00
|
|
|
|
|
|
|
|
|
|
There are several common pitfalls with using the CC series of color macros:
|
|
|
|
|
|
|
|
|
|
|
|
Do not confuse CCNRM with C_NRM. CCNRM() is a macro to turn the color back to
|
2025-07-02 21:26:19 +02:00
|
|
|
|
normal; C_NRMis a color level of “normal.” Always make sure that every pair of
|
|
|
|
|
|
“on” and “off” codes are at the same color level. For example:
|
2008-01-16 23:19:50 +00:00
|
|
|
|
|
|
|
|
|
|
WRONG: sprintf(buf, "%sCOLOR%s\n\r", CCBLU(ch, C_NRM), CCNRM(ch, C_CMP));
|
|
|
|
|
|
|
|
|
|
|
|
This is wrong because if someone has their color level set to Normal, the CCBLU
|
|
|
|
|
|
code will be sent but the CCNRM command will not, causing all subsequent output
|
|
|
|
|
|
to be blue.
|
|
|
|
|
|
|
|
|
|
|
|
WRONG: sprintf(buf, "%sCOLOR%s\n\r", CCBLU(ch, C_CMP), CCNRM(ch, C_NRM));
|
|
|
|
|
|
|
|
|
|
|
|
The above statement is also wrong, although not as bad. In this case, someone
|
|
|
|
|
|
with color set to Normal will (correctly) not get the CCBLU code, but will then
|
2025-07-02 21:26:19 +02:00
|
|
|
|
unnecessarily get the CCNRM code. Never send a color code if you don’t have to.
|
2008-01-16 23:19:50 +00:00
|
|
|
|
The codes are several bytes long, and cause a noticeable pause at 2400 baud.
|
|
|
|
|
|
|
2025-07-02 21:26:19 +02:00
|
|
|
|
This should go without saying, but don’t ever send color at the C_OFF level.
|
2008-01-16 23:19:50 +00:00
|
|
|
|
|
|
|
|
|
|
Special precautions must be taken when sending a colored string to a large
|
2025-07-02 21:26:19 +02:00
|
|
|
|
group of people. You can’t use the color level of “ch” (the person sending the
|
|
|
|
|
|
string) – each person receiving the string must get a string appropriately
|
2008-01-16 23:19:50 +00:00
|
|
|
|
colored for his/her level. In such cases, it is usually best to set up two
|
2025-07-02 21:26:19 +02:00
|
|
|
|
strings (one colored and one not), and test each player’s color level
|
2015-03-26 12:02:39 +00:00
|
|
|
|
individually (see do_gen_comin act.comm.c for an example).
|