Примеры кодов для ядра
Colour
Код:
Search for: #include "structs.h" Above it, add: #include "screen.h" Search for: extern char *help[]; Below it, add: void proc_color(char *inbuf, int color); Search for: /* add the extra CRLF if the person isn't in compact mode */ if (!t->connected && t->character && !PRF_FLAGGED(t->character, PRF_COMPACT)) strcat(i + 2, "\r\n"); Below it, add: if(t->character) proc_color(i, (clr(t->character, C_NRM))); -=-=-=-=-=-=-=-=-=- Makefile -=-=-=-=-=-=-=-=-=- Search for: spells.o utils.o weather.o Change to: spells.o utils.o weather.o color.o Search for: class.o: class.c conf.h sysdep.h structs.h db.h utils.h spells.h interpreter.h $(CC) -c $(CFLAGS) class.c Below it, add: color.o: color.c conf.h $(CC) -c $(CFLAGS) color.c ^^^^^^^^ ***MAKE SURE THIS IS A <TAB> OR ELSE THE MAKEFILE WILL PRODUCE ERRORS!!!!!*** -=-=-=-=-=-=-=-=-=- color.c(MAKE NEW FILE) -=-=-=-=-=-=-=-=-=- #include "conf.h" #define CNUL "" /* Plain Colors */ #define CNRM "\x1B[0;0m" /* %00 */ #define CRED "\x1B[31m" /* %01 */ #define CGRN "\x1B[32m" /* %02 */ #define CYEL "\x1B[33m" /* %03 */ #define CBLU "\x1B[34m" /* %04 */ #define CMAG "\x1B[35m" /* %05 */ #define CCYN "\x1B[36m" /* %06 */ #define CWHT "\x1B[37m" /* %07 */ #define CBLK "\x1B[30m" /* %08 */ /* Bold Colors */ #define BRED "\x1B[1;31m" /* %09 */ #define BGRN "\x1B[1;32m" /* %10 */ #define BYEL "\x1B[1;33m" /* %11 */ #define BBLU "\x1B[1;34m" /* %12 */ #define BMAG "\x1B[1;35m" /* %13 */ #define BCYN "\x1B[1;36m" /* %14 */ #define BWHT "\x1B[1;37m" /* %15 */ #define BBLK "\x1B[1;30m" /* %16 */ /* Backgrounds */ #define BKRED "\x1B[41m" /* %17 */ #define BKGRN "\x1B[42m" /* %18 */ #define BKYEL "\x1B[43m" /* %19 */ #define BKBLU "\x1B[44m" /* %20 */ #define BKMAG "\x1B[45m" /* %21 */ #define BKCYN "\x1B[46m" /* %22 */ #define BKWHT "\x1B[47m" /* %23 */ #define BKBLK "\x1B[40m" /* %24 */ /* Underline, Flashing */ #define UNDER "\x1B[4m" /* %25 */ #define FLASH "\x1B[5m" /* %26 */ const char *COLORLIST[] = {CNRM, CRED, CGRN, CYEL, CBLU, CMAG, CCYN, CWHT, CBLK , BRED, BGRN, BYEL, BBLU, BMAG, BCYN, BWHT, BBLK, BKRED,BKGRN,BKYEL,BKBLU,BKMAG,BKCYN,BKWHT,BKBLK, UNDER,FLASH}; #define MAX_COLORS 26 int isnum(char i) { return( (i >= '0') && (i <= '9') ); } void proc_color(char *inbuf, int color) { register int j=0,p=0; int c,k,max; char out_buf[32768]; if(inbuf[0] == '\0') return; while(inbuf[j]!='\0') { if( (inbuf[j]=='&') && isnum(inbuf[j+1]) && isnum(inbuf[j+2]) ) { c=(inbuf[j+1]-'0')*10 + inbuf[j+2]-'0'; if(c>MAX_COLORS) c = 0; max=strlen(COLORLIST[c]); j+=3; if(color) for(k=0;k<max;k++) { out_buf[p] = COLORLIST[c][k]; p++; } } else {out_buf[p] = inbuf[j]; j++;p++;} } out_buf[p] = '\0'; strcpy(inbuf, out_buf); } That's all you need. Simple, eh? Hope this helps... - Nashak
Коды цветов для версии 3.1
Код:
This is a color code drop in for circle 3.1 that allows many nice ANSI functions. It is loosly based on colourcode.txt by Jason Berg. See bottom of file for the color codes themselves. Dylan Myers a.k.a. Ulath of Caer Dubrin telnet://cd.dubrin.net:9900 ralgith@yahoo.com Instructions * Edit your comm.c file. * Add these function to comm.c * Be sure these go in below write_to_output and above vwrite_to_output #define COLOR_ON(ch) (!IS_NPC(ch) ? (PRF_FLAGGED((ch), PRF_COLOR_1 | PRF_COLOR_2) ? 1 : 0) : 0) /* Color replacement arrays. Renx -- 011100 */ #define A "\x1B[" const char *ANSI[] = { "&", A"0m",A"0;30m",A"0;34m",A"0;32m",A"0;36m",A"0;31m", A"0;35m",A"0;33m",A"0;37m",A"1;30m",A"1;34m",A"1;32m",A"1;36m",A"1;31m", A"1;35m",A"1;33m",A"1;37m",A"40m",A"44m",A"42m",A"46m",A"41m",A"45m", A"43m",A"47m",A"5m",A"4m",A"1m",A"7m" ,"!"}; #undef A const char CCODE[] = "&nkbgcrmywKBGCRMYW01234567luoe!"; #define NEW_STRING_LENGTH (size_t)(dest_char-save_pos) size_t proc_colors(char *txt, size_t maxlen, int parse) { char *dest_char, *source_char, *color_char, *save_pos; int i; size_t wanted; if (!txt || !strchr(txt, '&')) /* skip out if no color codes */ return strlen(txt); source_char = txt; CREATE(dest_char, char, maxlen); save_pos = dest_char; for( ; *source_char && (NEW_STRING_LENGTH < maxlen); ) { /* no color code - just copy */ if (*source_char != '&') { *dest_char++ = *source_char++; continue; } /* if we get here we have a color code */ source_char++; /* source_char now points to the code */ if (*source_char == '\0') { /* string was terminated with color code - just put it in */ *dest_char++ = '&'; /* source_char will now point to '\0' in the for() check */ continue; } if (!parse) { /* not parsing, just skip the code, unless it's && */ if (*source_char == '&') { *dest_char++ = '&'; } source_char++; /* skip to next (non-colorcode) char */ continue; } /* parse the color code */ for (i = 0; CCODE[i] != '!'; i++) { /* do we find it ? */ if ((*source_char) == CCODE[i]) { /* if so :*/ if ( NEW_STRING_LENGTH + strlen(ANSI[i]) < maxlen) { /* only substitute if there's room for the whole code */ /* color_char now points to the first char in color code*/ for(color_char = (char *)ANSI[i] ; *color_char ; ) *dest_char++ = *color_char++; } break; } } /* If we couldn't find any correct color code, or we found it and * substituted above, let's just process the next character. * - Welcor */ source_char++; } /* for loop */ /* make sure output is NULL - terminated */ *dest_char = '\0'; wanted = strlen(source_char); /* see if we wanted more space */ strncpy(txt, save_pos, maxlen-1); free(save_pos); /* plug memory leak */ return NEW_STRING_LENGTH+wanted; } #undef NEW_STRING_LENGTH --- End of Drop in Code --- My screen.h -- Included just cause it allows you to use the extra codes such as blink and underline inside code -- /* ************************************************************************ * File: screen.h Part of CircleMUD * * Usage: header file with ANSI color codes for online color * * * * All rights reserved. See license.doc for complete information. * * Modifications by Dylan Myers aka Ulath of Caer Dubrin (C) 2004 * * * * Copyright (C) 1993, 94 by the Trustees of the Johns Hopkins University * * CircleMUD is based on DikuMUD, Copyright (C) 1990, 1991. * ************************************************************************ */ #define KNRM "\033[0m" #define KRED "\033[31m" #define KGRN "\033[32m" #define KYEL "\033[33m" #define KBLU "\033[34m" #define KMAG "\033[35m" #define KCYN "\033[36m" #define KWHT "\033[37m" #define KBLK "\033[30m" #define KBLD "\033[1m" #define KBLN "\033[5m" #define KNUL "" #define KCLR "\033[2J" #define KUND "\033[4m" #define KDAR "\033[2m" #define KBRED "\033[41m" #define KBGRN "\033[42m" #define KBYEL "\033[43m" #define KBBLU "\033[44m" #define KBMAG "\033[45m" #define KBCYN "\033[46m" #define KBWHT "\033[47m" #define KBBLK "\033[40m" /* conditional color. pass it a pointer to a char_data and a color level. */ #define C_OFF 0 #define C_SPR 1 #define C_NRM 2 #define C_CMP 3 #define _clrlevel(ch) ((PRF_FLAGGED((ch), PRF_COLOR_1) ? 1 : 0) + \ (PRF_FLAGGED((ch), PRF_COLOR_2) ? 2 : 0)) #define clr(ch,lvl) (_clrlevel(ch) >= (lvl)) #define CCNRM(ch,lvl) (clr((ch),(lvl))?KNRM:KNUL) #define CCBLK(ch,lvl) (clr((ch),(lvl))?KBLK:KNUL) #define CCRED(ch,lvl) (clr((ch),(lvl))?KRED:KNUL) #define CCGRN(ch,lvl) (clr((ch),(lvl))?KGRN:KNUL) #define CCYEL(ch,lvl) (clr((ch),(lvl))?KYEL:KNUL) #define CCBLU(ch,lvl) (clr((ch),(lvl))?KBLU:KNUL) #define CCMAG(ch,lvl) (clr((ch),(lvl))?KMAG:KNUL) #define CCCYN(ch,lvl) (clr((ch),(lvl))?KCYN:KNUL) #define CCWHT(ch,lvl) (clr((ch),(lvl))?KWHT:KNUL) #define CCBLD(ch,lvl) (clr((ch),(lvl))?KBLD:KNUL) #define CCBLN(ch,lvl) (clr((ch),(lvl))?KBLN:KNUL) #define CCCLR(ch,lvl) (clr((ch),(lvl))?KCLR:KNUL) #define CCUND(ch,lvl) (clr((ch),(lvl))?KUND:KNUL) #define CCDAR(ch,lvl) (clr((ch),(lvl))?KDAR:KNUL) #define CCBBLK(ch,lvl) (clr((ch),(lvl))?KBBLK:KNUL) #define CCBRED(ch,lvl) (clr((ch),(lvl))?KBRED:KNUL) #define CCBGRN(ch,lvl) (clr((ch),(lvl))?KBGRN:KNUL) #define CCBYEL(ch,lvl) (clr((ch),(lvl))?KBYEL:KNUL) #define CCBBLU(ch,lvl) (clr((ch),(lvl))?KBBLU:KNUL) #define CCBMAG(ch,lvl) (clr((ch),(lvl))?KBMAG:KNUL) #define CCBCYN(ch,lvl) (clr((ch),(lvl))?KBCYN:KNUL) #define CCBWHT(ch,lvl) (clr((ch),(lvl))?KBWHT:KNUL) #define COLOR_LEV(ch) (_clrlevel(ch)) #define QNRM CCNRM(ch,C_SPR) #define QBLK CCBLK(ch,C_SPR) #define QRED CCRED(ch,C_SPR) #define QGRN CCGRN(ch,C_SPR) #define QYEL CCYEL(ch,C_SPR) #define QBLU CCBLU(ch,C_SPR) #define QMAG CCMAG(ch,C_SPR) #define QCYN CCCYN(ch,C_SPR) #define QWHT CCWHT(ch,C_SPR) #define QBLD CCBLD(ch,C_SPR) #define QBLN CCBLN(ch,C_SPR) #define QCLR CCBLN(ch,C_SPR) #define QUND CCUND(ch,C_SPR) #define QDAR CCDAR(ch,C_SPR) #define QBBLK CCBBLK(ch,C_SPR) #define QBRED CCBRED(ch,C_SPR) #define QBGRN CCBGRN(ch,C_SPR) #define QBYEL CCBYEL(ch,C_SPR) #define QBBLU CCBBLU(ch,C_SPR) #define QBMAG CCBMAG(ch,C_SPR) #define QBCYN CCBCYN(ch,C_SPR) #define QBWHT CCBWHT(ch,C_SPR) -- End screen.h -- Compile and you're done. How to use it & color-codes How to use it: Wherever whenever you feel like adding some color (for those who have colorlevel >= NORMAL) you just do something like this: Color Codes: &n - normal &k - black &K - gray &0 - background black &b - blue &B - bright blue &1 - background blue &g - green &G - bright green &2 - background green &c - cyan &C - bright cyan &3 - background cyan &r - red &R - bright red &4 - background red &m - magneta &M - bright magneta &5 - background magneta &y - yellow &Y - bright yellow &6 - background yellow &w - white &W - bright white &7 - background white Extra codes: &l - blink &o - bold (just makes normal colors bright..) &u - underline &e - reverse video && - single &
Деф мессаги серверка клиенту
Код:
This will add in player settable colors, so player 1 can speak with black and red to other people, but player 2 can speak in green and light green and the other people see it. This may lag the server if its slow, but I haven't had any color-slowness problems; in my opinion this adds lots of variety and uniqueness. Credits to Thomas Arp for lots of help, Peter Ajamian for help, and Ben Merton for the original concept. If you wish to make it so everyone can set colors but they only see what they have set, its easy to change that, contact me if you wish that. Example of how to expand: We now want something like holler expandable, add on a #define COLOR_HOLLER 7 and up the NUM_COLORS to 8. Then whenever you see a str_dup("nnnnnnn"); add on an extra n. If you use binary pfiles, you will need pwipe each time you change this. Now in act.other add on a field for holler, and have COLOR_HOLLER next to it. Now, when you actually go into where holler is done, tack on some of the things like in do_say... all done. -Edward Felch lord.spinlock.net 9991 Darkness Falling MUD Assumptions: - ascii pfiles - already have it so you can use & to put color in like say &rhello. - that you want a unique way of handling colors for players structs.h Near the other defines add in: /* player definable colors */ #define COLOR_SAY1 0 #define COLOR_SAY2 1 #define COLOR_PROMPT 2 #define COLOR_TELL 3 #define COLOR_GOSSIP 4 #define COLOR_OBJECT 5 #define COLOR_CREATURE 6 #define NUM_COLORS 7 In: struct char_player_data { add char *player_color; // defined colors Later on in: struct char_file_u { add char player_color[NUM_COLORS+1]; utils.h Somewhere add in: #define GET_PLAYER_COLOR(ch) ((ch)->player.player_color) In act.other.c or somewhere nice: struct set_fields { const char *change_field; int field; } set_pcolor_fields[] = { { "say1", COLOR_SAY1}, { "say2", COLOR_SAY2}, { "tell", COLOR_TELL}, { "gossip", COLOR_GOSSIP}, { "object", COLOR_OBJECT}, { "creature", COLOR_CREATURE}, { "\n", -1} }; const char *color_char[][2] = { { "red", "r"}, { "blue", "b"}, { "green", "g"}, { "yellow", "y"}, { "magneta", "m"}, { "grey", "w"}, { "cyan", "c"}, { "bred", "R"}, { "bblue", "B"}, { "bgreen", "G"}, { "byellow", "Y"}, { "bmagneta", "M"}, { "bcyan", "C"}, { "white", "W"}, { "black", "D"}, { "normal", "n"}, { "\n", "\n"} }; ACMD(do_setcolor) { char field[MAX_INPUT_LENGTH], ccolor[MAX_INPUT_LENGTH]; int mode = 0, len = 0, found = 0, cmode = 0; int change = 0; half_chop(argument, field, ccolor); if (!field || !*field) { send_to_char("You can change the following fields:\r\n", ch); for (mode = 0; *(set_pcolor_fields[mode].change_field) != '\n'; mode++) { sprintf(buf, " %s\r\n", set_pcolor_fields[mode].change_field); send_to_char(buf, ch); } return; } /* go through settable_colors */ len = strlen(field); for (mode = 0; *(set_pcolor_fields[mode].change_field) != '\n' || found; mode++) if (is_abbrev(field, set_pcolor_fields[mode].change_field)) { found = 1; break; } if (!found) { send_to_char("You cannot change that field's color!\r\n", ch); return; } if (!ccolor || !*ccolor) { send_to_char("You can use the following color codes:\r\n", ch); for (cmode = 0; *(color_char[cmode][0]) != '\n'; cmode++) { sprintf(buf, " &%s%s\r\n", color_char[cmode][1], color_char[cmode][0]); send_to_char(buf, ch); } return; } found = 0; len = strlen(ccolor); for (cmode = 0; *(color_char[cmode][0]) != '\n' || found; cmode++) if (is_abbrev(ccolor, color_char[cmode][0])) { found = 1; break; } if (!found) { send_to_char("What color did you want that to be?\r\n", ch); return; } /* we have a correct field, and a color */ change = set_pcolor_fields[mode].field; GET_PLAYER_COLOR(ch)[change] = *(color_char[cmode][1]); sprintf(buf, "You have changed %s to be %s.\r\n", set_pcolor_fields[mode].change_field, color_char[cmode][0]); send_to_char(buf, ch); return; } In db.c: in load_char where everything is being set to default values: GET_PLAYER_COLOR(ch) = str_dup("nnnnnnn"); in load_char in the actual setting of variables, under P add: else if (!strcmp(tag, "Pcol")) GET_PLAYER_COLOR(ch) = str_dup(line); in save_char in the saving of variables, add in somewhere: if (GET_PLAYER_COLOR(ch)) fbprintf(fl, "Pcol: %s\n", GET_PLAYER_COLOR(ch)); in init_char add in: GET_PLAYER_COLOR(ch) = str_dup("nnnnnnn"); in parse_mobile where things like title and name are being NULLED add in: mob_proto[i].player.player_color = str_dup("nnnnnnn"); in free_char you should probably add in: if (GET_PLAYER_COLOR(ch)) free(GET_PLAYER_COLOR(ch)); In medit.c inside of void init_mobile(struct char_data *mob) add in GET_PLAYER_COLOR(mob) = str_dup("nnnnnnn"); In hander.c add in: const char *interpret_color(struct char_data *ch, int position) { char return_s[MAX_INPUT_LENGTH]; char *returner; sprintf(return_s, "&%c", GET_PLAYER_COLOR(ch)[position]); returner = str_dup(return_s); return returner; } In handler.h add in under utility: const char *interpret_color(struct char_data *ch, int position); For this implementation of unique, definable colors I will only show you one place where it is declared, which uses say1 and say2: Inside of act.comm.c: ACMD(do_say) { skip_spaces(&argument); if (!*argument) send_to_char("Yes, but WHAT do you want to say?\r\n", ch); else { delete_doubledollar(argument); sprintf(buf, "%s$n says, &n'%s%s&n'&n", interpret_color(ch, COLOR_SAY1), interpret_color(ch, COLOR_SAY2), argument); act(buf, FALSE, ch, 0, 0, TO_ROOM|DG_NO_TRIG); // if you dont use dgscripts, remove the |DG_NO_TRIG if (!IS_NPC(ch) && PRF_FLAGGED(ch, PRF_NOREPEAT)) send_to_char(OK, ch); else { delete_doubledollar(argument); sprintf(buf, "%sYou say, &n'%s%s&n'&n\r\n", interpret_color(ch, COLOR_SAY1), interpret_color(ch, COLOR_SAY2), argument); send_to_char(buf, ch); } } /* trigger check */ speech_mtrigger(ch, argument); // if you use dgscripts speech_wtrigger(ch, argument); // if you use dgscripts }
Коды цветов для версии 2.х
Код:
This is a change from the origional code by Jorgen Sigvardsson The code will run slightly faster here because it know when to run and when to not run. My comments end with JB Jason Berg <Gameguru42@hotmail.com> Original code done by : Jorgen Sigvardsson <di4sig@sce.hks.se> Subject: Color Codes Sorry about the second file but I forgot to change my color codes back to what they were before. Instructions * Edit your comm.c file. * Add these function to comm.c * Be sure these go in above write_to_output JB int count_chars(const char *txt, char character) { int i, cnt = 0; for(i = 0; txt[i]; i++) if(txt[i] == character) cnt++; return cnt; } /* Added const to both routines to fix 2 warnings */ char *parse_color(const char *txt, struct descriptor_data *t) { char *new_txt; char *toret; register int i, j = 0; i = count_chars(txt, '&'); /* count how many control-chars there are in the string */ new_txt = malloc(i * 5 + strlen(txt) + 1); /* no ansi-escape code is larger than 5 bytes so a 5 * times the '&' appears + strlen(txt) + 1 character big buffer should be enough */ if (!i || t->connected == CON_GET_NAME){ /* Returns same string if there is no change needed JB*/ strcpy(new_txt, txt); /* Fixes a warning and a strange bug with (I)MOTD's vanishing JB */ return new_txt; } /* the parser.. Huge but fast */ if (clr(t->character, C_NRM)){ /* checks to see if character has neccisary color on JB */ for(i = 0; txt[i]; i++) { if(txt[i] == '&') { i++; switch(txt[i]) { case '0' : /* Removed the color check code's here to */ strcpy(new_txt + j, KNRM); /* speed up the exchange JB */ j += 4; break; case '1' : strcpy(new_txt + j, KRED); j += 5; break; case '2' : strcpy(new_txt + j, KGRN); j += 5; break; case '3' : strcpy(new_txt + j, KYEL); j += 5; break; case '4' : strcpy(new_txt + j, KBLU); j += 5; break; case '5' : strcpy(new_txt + j, KMAG); j += 5; break; case '6' : strcpy(new_txt + j, KCYN); j += 5; break; case '7' : strcpy(new_txt + j, KWHT); j += 5; break; case '8' : /* both cases did same thing JB */ case 'b' : strcpy(new_txt + j, KBLD); j += 4; break; case '9' : strcpy(new_txt + j, KBLK); j += 5; break; case 'u' : strcpy(new_txt + j, KUND); j += 4; break; case 'd' : strcpy(new_txt + j, KDAR); j += 4; break; case 'R' : strcpy(new_txt + j, KBRED); j += 5; break; case 'G' : strcpy(new_txt + j, KBGRN); j += 5; break; case 'Y' : strcpy(new_txt + j, KBYEL); j += 5; break; case 'B' : strcpy(new_txt + j, KBBLU); j += 5; break; case 'M' : strcpy(new_txt + j, KBMAG); j += 5; break; case 'C' : strcpy(new_txt + j, KBCYN); j += 5; break; case 'W' : strcpy(new_txt + j, KBWHT); j += 5; break; case 'S' : strcpy(new_txt + j, KBBLK); j += 5; break; case '&' : new_txt[j] = txt[i]; j++; break; default: break; } } else { new_txt[j] = txt[i]; j++; } } } else { /* Quick little function in case they don't have color */ for(i = 0; txt[i]; i++) /* Only transfers the & character JB */ if(txt[i] == '&'){ i++; if (txt[i] == '&'){ new_txt[j] = txt[i]; j++; } } else { new_txt[j] = txt[i]; j++; } } new_txt[j] = '\0'; /* terminate the string */ toret = strdup(new_txt); /* create a new string with no eventual memoryloss */ free(new_txt); /* free the old buffer */ return toret; /* the colorized buffer */ } * Change the function write_to_output(const char *txt, struct descriptor_data *t) to this: void write_to_output(const char *txt, struct descriptor_data *t) { int size; char *new_txt; new_txt = parse_color(txt, t); size = strlen(new_txt); /* if we're in the overflow state already, ignore this new output */ if (t->bufptr < 0) return; /* if we have enough space, just write to buffer and that's it! */ if (t->bufspace >= size) { strcpy(t->output + t->bufptr, new_txt); t->bufspace -= size; t->bufptr += size; free(new_txt); return; } /* * If we're already using the large buffer, or if even the large buffer * is too small to handle this new text, chuck the text and switch to the * overflow state. */ if (t->large_outbuf || ((size + strlen(t->output)) > LARGE_BUFSIZE)) { t->bufptr = -1; buf_overflows++; free(new_txt); return; } buf_switches++; /* if the pool has a buffer in it, grab it */ if (bufpool != NULL) { t->large_outbuf = bufpool; bufpool = bufpool->next; } else { /* else create a new one */ CREATE(t->large_outbuf, struct txt_block, 1); CREATE(t->large_outbuf->text, char, LARGE_BUFSIZE); buf_largecount++; } strcpy(t->large_outbuf->text, t->output); /* copy to big buffer */ t->output = t->large_outbuf->text; /* make big buffer primary */ strcat(t->output, new_txt); /* now add new text */ /* calculate how much space is left in the buffer */ t->bufspace = LARGE_BUFSIZE - 1 - strlen(t->output); /* set the pointer for the next write */ t->bufptr = strlen(t->output); free(new_txt); } * My screen.h /* ************************************************************************ * File: screen.h Part of CircleMUD * * Usage: header file with ANSI color codes for online color * * * * All rights reserved. See license.doc for complete information. * * * * Copyright (C) 1993, 94 by the Trustees of the Johns Hopkins University * * CircleMUD is based on DikuMUD, Copyright (C) 1990, 1991. * ************************************************************************ */ #define KNRM "\033[0m" #define KRED "\033[31m" #define KGRN "\033[32m" #define KYEL "\033[33m" #define KBLU "\033[34m" #define KMAG "\033[35m" #define KCYN "\033[36m" #define KWHT "\033[37m" #define KBLK "\033[30m" #define KBLD "\033[1m" #define KBLN "\033[5m" #define KNUL "" #define KCLR "\033[2J" #define KUND "\033[4m" #define KDAR "\033[2m" #define KBRED "\033[41m" #define KBGRN "\033[42m" #define KBYEL "\033[43m" #define KBBLU "\033[44m" #define KBMAG "\033[45m" #define KBCYN "\033[46m" #define KBWHT "\033[47m" #define KBBLK "\033[40m" /* conditional color. pass it a pointer to a char_data and a color level. */ #define C_OFF 0 #define C_SPR 1 #define C_NRM 2 #define C_CMP 3 #define _clrlevel(ch) ((PRF_FLAGGED((ch), PRF_COLOR_1) ? 1 : 0) + \ (PRF_FLAGGED((ch), PRF_COLOR_2) ? 2 : 0)) #define clr(ch,lvl) (_clrlevel(ch) >= (lvl)) #define CCNRM(ch,lvl) (clr((ch),(lvl))?KNRM:KNUL) #define CCBLK(ch,lvl) (clr((ch),(lvl))?KBLK:KNUL) #define CCRED(ch,lvl) (clr((ch),(lvl))?KRED:KNUL) #define CCGRN(ch,lvl) (clr((ch),(lvl))?KGRN:KNUL) #define CCYEL(ch,lvl) (clr((ch),(lvl))?KYEL:KNUL) #define CCBLU(ch,lvl) (clr((ch),(lvl))?KBLU:KNUL) #define CCMAG(ch,lvl) (clr((ch),(lvl))?KMAG:KNUL) #define CCCYN(ch,lvl) (clr((ch),(lvl))?KCYN:KNUL) #define CCWHT(ch,lvl) (clr((ch),(lvl))?KWHT:KNUL) #define CCBLD(ch,lvl) (clr((ch),(lvl))?KBLD:KNUL) #define CCBLN(ch,lvl) (clr((ch),(lvl))?KBLN:KNUL) #define CCCLR(ch,lvl) (clr((ch),(lvl))?KCLR:KNUL) #define CCUND(ch,lvl) (clr((ch),(lvl))?KUND:KNUL) #define CCDAR(ch,lvl) (clr((ch),(lvl))?KDAR:KNUL) #define CCBBLK(ch,lvl) (clr((ch),(lvl))?KBBLK:KNUL) #define CCBRED(ch,lvl) (clr((ch),(lvl))?KBRED:KNUL) #define CCBGRN(ch,lvl) (clr((ch),(lvl))?KBGRN:KNUL) #define CCBYEL(ch,lvl) (clr((ch),(lvl))?KBYEL:KNUL) #define CCBBLU(ch,lvl) (clr((ch),(lvl))?KBBLU:KNUL) #define CCBMAG(ch,lvl) (clr((ch),(lvl))?KBMAG:KNUL) #define CCBCYN(ch,lvl) (clr((ch),(lvl))?KBCYN:KNUL) #define CCBWHT(ch,lvl) (clr((ch),(lvl))?KBWHT:KNUL) #define COLOR_LEV(ch) (_clrlevel(ch)) #define QNRM CCNRM(ch,C_SPR) #define QBLK CCBLK(ch,C_SPR) #define QRED CCRED(ch,C_SPR) #define QGRN CCGRN(ch,C_SPR) #define QYEL CCYEL(ch,C_SPR) #define QBLU CCBLU(ch,C_SPR) #define QMAG CCMAG(ch,C_SPR) #define QCYN CCCYN(ch,C_SPR) #define QWHT CCWHT(ch,C_SPR) #define QBLD CCBLD(ch,C_SPR) #define QBLN CCBLN(ch,C_SPR) #define QCLR CCBLN(ch,C_SPR) #define QUND CCUND(ch,C_SPR) #define QDAR CCDAR(ch,C_SPR) #define QBBLK CCBBLK(ch,C_SPR) #define QBRED CCBRED(ch,C_SPR) #define QBGRN CCBGRN(ch,C_SPR) #define QBYEL CCBYEL(ch,C_SPR) #define QBBLU CCBBLU(ch,C_SPR) #define QBMAG CCBMAG(ch,C_SPR) #define QBCYN CCBCYN(ch,C_SPR) #define QBWHT CCBWHT(ch,C_SPR) * Compile and you're done. * How to use it + color-codes How to use it: Wherever whenever you feel like adding some color (for those who have colorlevel >= NORMAL) you just do something like this: &1Red&0 &4Blue&0 and so on.. Works in room_descs, gossips, tells, you name it. Here's a list of the color-codes: 0 Normal attributes 1 red 2 green 3 yellow 4 blue 5 magenta 6 cyan 7 white 8 bold 9 black u underline d dark b bright R red bground G green brgound B Blue bground Y yellow brgound M magenta bground C Cyan bground W white bground S black bground (S as in Svart (swedish)) & the character & Anything other than these characters, will produce nothing.