/************************************************************************ Realms of Aurealis James Rhone aka Vall of RoA prompt.c RoA prompt code... ******** 100% Completely Original Code ******** *** BE AWARE OF ALL RIGHTS AND RESERVATIONS *** ******** 100% Completely Original Code ******** All rights reserved henceforth. Please note that no guarantees are associated with any code from Realms of Aurealis. All code which has been released to the general public has been done so with an 'as is' pretense. RoA is based on both Diku and CircleMUD and ALL licenses from both *MUST* be adhered to as well as the RoA license. *** Read, Learn, Understand, Improve *** *************************************************************************/ #include "conf.h" #include "sysdep.h" #include "structures.h" #include "utils.h" #include "comm.h" #include "interpreter.h" #include "acmd.h" #include "handler.h" #include "db.h" #include "mudlimits.h" #include "screen.h" #include "lists.h" extern struct time_info_data time_info; void display_prompt(chdata *ch, char *newstr); int find_message(chdata *ch); /* Array for condition messages */ const char *cond_array[] = { "Perfect", "Few Scratches", "Small Bruises", "Very Good", "Moderate Scratches", "Moderate Bruises", "Good", "Small Wounds", "Deep Bruises", "Moderate Bleeding", "Fair", "Large Cuts", "Severe Contusions", "Large Gashes", "Quite a Few Wounds", "Bleeding Severely", "Poor", "Very Poor", "Awful", "About to Die" }; int find_message(chdata *pchar) { int i = (sizeof(cond_array)/sizeof(cond_array[0])) - 1; int j; int cur_hp = (pchar->points).hit; int max_hp = (pchar->points).max_hit; if(cur_hp >= max_hp) return 0; for(j = 1; j <=i; j++) { if((j*max_hp > i * cur_hp) && ((j-1) *max_hp <= i * cur_hp)) { return i - j; } } return i; } void get_bar(int current, int total, char *barfinal) { static float res = 0.0; static int intres = 0; static int i; static char bar[MAX_INPUT_LENGTH]; if (current < 0 || total < 0) { sprintf(barfinal, "{%%1NEAR DEATH%%0}"); return; } res = ((float) current / (float) total) * 10.0; intres = (int) res; if (intres >= 6) sprintf(bar, "%%2"); else if (intres >= 4) sprintf(bar, "%%3"); else sprintf(bar, "%%1"); strcat(bar, ">"); for (i = 0; i < (intres-1); i++) strcat(bar, ">"); strcat(bar, "%0"); sprintf(barfinal, "{%-14.14s}", bar); } ACMD(do_bars) { if (IS_NPC(ch)) return; if (BARS(ch)) { ch->pc_specials->saved.bars = FALSE; send_to_char("VT100 bars deactivated.\n\r",ch); } else { ch->pc_specials->saved.bars = TRUE; send_to_char("VT100 bars activated.\n\r",ch); } } void display_prompt(chdata *ch, char* newstr) { static char prompt[MAX_INPUT_LENGTH +1]; static char bar[MAX_INPUT_LENGTH]; static char Xits[100]; static char *pstring; static int i; char vtstr[MAX_CLAN_LENGTH]; int numnewlines; chdata *natural; extern int exp_table[NUM_CLASSES][MAX_LEVELS]; extern void get_exit_prompt(chdata *ch, char *str); if (IN_NOWHERE(ch)) return; *newstr = *prompt = '\0'; if (IS_NPC(ch)) strcpy(newstr, "(NPC)"); if (!ch->desc) return; natural = (ch->desc->original) ? ch->desc->original : ch; pstring = natural->pc_specials->saved.saved_prompt; if (GET_INVIS_LEV(ch) >= LEV_IMM) sprintf(prompt, "(i%%B%d%%0) ", GET_INVIS_LEV(ch)); if (!*pstring) { strcat(newstr, ">"); return; } strcat(prompt, newstr); numnewlines = 0; while(*pstring) { if(*pstring != '%') { sprintf(prompt, "%s%c", prompt, *pstring); pstring++; continue; } pstring++; switch(*pstring) { case 'R': case 'r': if (IS_IMMORTAL(ch) || IS_IMMORTAL(natural)) { sprintf(prompt, "%s#%d", prompt, world[ch->in_room].number); pstring++; } break; case 'h': if (BARS(ch)) { get_bar(GET_HIT(ch), GET_MAX_HIT(ch), bar); sprintf(prompt, "%s%%BHIT:%%0%s", prompt, bar); } else sprintf(prompt, "%s%d", prompt, GET_HIT(ch)); pstring++; break; case 'H': sprintf(prompt, "%s%d", prompt, (ch->points).max_hit); pstring++; break; case 'm': if (BARS(ch)) { get_bar(GET_MANA(ch), GET_MAX_MANA(ch), bar); sprintf(prompt, "%s%%BMANA:%%0%s", prompt, bar); } else sprintf(prompt, "%s%d", prompt, (ch->points).mana); pstring++; break; case 'M': sprintf(prompt, "%s%d",prompt, (ch->points).max_mana); pstring++; break; case 'v': if (BARS(ch)) { get_bar(GET_MOVE(ch), GET_MAX_MOVE(ch), bar); sprintf(prompt, "%s%%BMV:%%0%s", prompt, bar); } else sprintf(prompt, "%s%d", prompt, (ch->points).move); pstring++; break; case 'V': sprintf(prompt, "%s%d", prompt, (ch->points).max_move); pstring++; break; case 'F': /* f for name of mob fighting */ if (FIGHTING(ch)) { sprintf(prompt, "%s%s", prompt, FIGHTING(ch)->player.short_descr); } pstring++; break; case 'E': /* e for enemies condition */ if (FIGHTING(ch)) { if (BARS(ch)) { get_bar(GET_HIT(FIGHTING(ch)), GET_MAX_HIT(FIGHTING(ch)), bar); sprintf(prompt, "%s%%B%s:%%0%s", prompt, GET_NAME(FIGHTING(ch)), bar); } else { i = find_message(FIGHTING(ch)); sprintf(prompt, "%s{%s}", prompt, cond_array[i]); } } pstring++; break; case 'T': /* t for tanks condition */ if (FIGHTING(ch) && FIGHTING(FIGHTING(ch))) { if (BARS(ch)) { get_bar(GET_HIT(FIGHTING(FIGHTING(ch))), GET_MAX_HIT(FIGHTING(FIGHTING(ch))), bar); sprintf(prompt, "%s%%B%s:%%0%s", prompt, GET_NAME(FIGHTING(FIGHTING(ch))), bar); } else { i = find_message(FIGHTING(FIGHTING(ch))); sprintf(prompt, "%s{%s}", prompt, cond_array[i]); } } pstring++; break; case 'Z': /* this one is like %F and %E combined */ if(FIGHTING(ch)) { i = find_message(FIGHTING(ch)); sprintf(prompt, "%s{%s: %s}", prompt, FIGHTING(ch)->player.short_descr, cond_array[i]); } pstring++; break; case 't': /* Get time and stick it in */ sprintf(prompt, "%s%d%s", prompt, ((time_info.hours % 12 == 0) ? 12 : (time_info.hours % 12)), ((time_info.hours >= 12) ? "pm" : "am")); pstring++; break; /* Experience to level */ case 'x': if(GET_LEVEL(ch) < LEV_IMM) { sprintf(prompt, "%s%d", prompt, exp_table[GET_CLASS(ch)-1][GET_LEVEL(ch)+1] - GET_EXP(ch)); } pstring++; break; /* auto exits in prompt */ case 'X': if (!IN_NOWHERE(ch)) { get_exit_prompt(ch, Xits); sprintf(prompt, "%s%s", prompt, Xits); } pstring++; break; case 'n': /* add a newline to prompt for vt100 menus */ if (VT100(ch)) { numnewlines++; sprintf(vtstr, CURSPOS, CURSOR_ROW(ch) + 2 + numnewlines, 0); sprintf(prompt, "%s%s%s", prompt, vtstr, CLRLINE); } else sprintf(prompt, "%s\n\r", prompt); pstring++; break; case '%': /* normal percentage */ sprintf(prompt, "%s%%", prompt); pstring++; break; default: sprintf(prompt, "%s%%%c", prompt, *pstring); pstring++; break; } } if (*prompt) color_decode(natural, prompt, newstr); return; } ACMD(do_prompt) { if(IS_NPC(ch)) return; if(!*argument) { sprintf(buf, "Your current prompt is: %s\r\n", ch->pc_specials->saved.saved_prompt); send_to_char(buf, ch); return; } if(strlen(argument) >= MAX_POOFIN_LENGTH -1) { sprintf(buf, "Prompt string can not be longer than %d characters.\r\n", MAX_POOFIN_LENGTH); send_to_char(buf, ch); return; } for (; *argument == ' '; argument++) ; strcpy(ch->pc_specials->saved.saved_prompt, argument); sprintf(buf, "Your prompt is now: %s.\r\n", argument); send_to_char(buf, ch); }