prompt.c
./mudd/src/prompt.c · 3.9 KB
From the archive emlen.tar.gz
Download the archive « Back to the archive contents
#include <sys/types.h>
#ifdef Linux
#include <sys/time.h>
#endif
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "mud.h"
bool
check_pr (char *txt)
{
char *t;
bool last_a = FALSE;
for (t = txt; *t != '\0'; t++)
{
if (*t == '%')
return FALSE;
if (*t == '$')
{
last_a = TRUE;
continue;
}
if (last_a && (*t < '0' || *t > '9') && *t != 'B' && *t != 'R')
{
return FALSE;
}
last_a = FALSE;
}
return TRUE;
}
extern bool prmpt;
void
print_prompt (CHAR_DATA * ch)
{
char buf[STD_LENGTH];
char prompt[3*STD_LENGTH];
char rest[STD_LENGTH];
char *t;
int ii;
rest[0] = '\0';
if (IS_MOB(ch))
return;
sprintf (prompt, "\x1b[0;37m");
if (ch->wait > 1)
strcat(prompt, "*");
if (ch->pcdata->tickcounts > 11)
strcat(prompt, "+");
if (ch->fgt && ch->fgt->ears > 10)
{
sprintf (buf, "[%d] ", ch->fgt->ears - 10);
strcat(prompt, buf);
}
if (ch->position == POSITION_CASTING && FIGHTING (ch) != NULL)
strcat(prompt, "(Casting) ");
else if (ch->position == POSITION_BASHED)
strcat (prompt, "(Bashed) ");
else if (ch->position == POSITION_SHOOTING)
strcat(prompt, "(Aiming) ");
else if (ch->position == POSITION_FIRING)
strcat (prompt, "(Firing) ");
wwrap = FALSE;
ii = ch->position;
ch->position = POSITION_STANDING;
ch->pcdata->cursor = 0;
strcpy (rest, interpret_line (ch->pcdata->rprompt, ch));
for (t = rest; *t != '\0'; t++)
{
if (*t == '$')
{
t++;
continue;
}
if (*t == '\x1B')
{
t++;
while (*t != 'm' && *t != 'f' && *t != 'H' && *t != 'r' && *t != 'J' && *t != '\0')
t++;
continue;
}
if (*t == '\n' || ch->pcdata->cursor > 79)
{
ch->pcdata->cursor = 0;
}
ch->pcdata->cursor++;
}
ch->pcdata->cursor++;
strcat (prompt, rest);
act (prompt, ch, NULL, ch, TO_CHAR);
ch->position = ii;
wwrap = TRUE;
if (ch->desc && ch->desc->host[29] == 1)
gotoxy (ch, ch->pcdata->cursor, ch->pcdata->pagelen);
if (ch->desc && ch->desc->host[29] == 1)
{
send_to_char (ch->desc->inbuf, ch);
ch->pcdata->cursor += strlen (ch->desc->inbuf);
}
return;
}
void
try_prompt (char *tx, CHAR_DATA * ch)
{
static char hugebuf[2048];
int ii;
const char *i;
hugebuf[0] = '\0';
i = hugebuf;
send_to_char ("\x1B[37;0m", ch);
wwrap = FALSE;
ii = ch->position;
ch->position = POSITION_STANDING;
act (interpret_line (tx, ch), ch, NULL, ch, TO_CHAR);
ch->position = ii;
wwrap = TRUE;
send_to_char ("\n\r", ch);
return;
}
char *prompts[] =
{
"$R*rid*$B$1*hn*/*hm*$R$7hp$B$2 *mn*/*mm*$R$7mv $B$5*mnn*/*mmm*$R$7m *fi**tk*> ",
"$R*rid*$R$3*hn*$7/$3*hm*$7h$2 *mn*$7/$2*mm*$7mv $5*mnn*$7/$5*mmm*$7m *fi**tk*> ",
"$R*rid*$R*tk**hn*H *mn*M *fi*> ",
"$R*rid*$R*tk**fi**hn*H *mn*Mv *mnn*Ma> ",
"$R*rid*$B$2*hn*$R$7H $B$5*mn*$R$7Mv $B$6*mnn*$R$7Ma *fi**tk*> ",
"$R*rid*$R*hn*/*hm*H *mn*/*mm*Mv *mnn*Ma *fi**tk*> ",
"$R*rid*$R*hn*h *mn*m XL:*xl* *fi**tk*> ",
"$R*rid*$R*hn*/*hm*H *mn*/*mm*Mv *mnn*Ma XL(*xl*) *fi**tk*> ",
"$R*rid*$B$2*hn*$R$7hp $B$6*mn*$R$7mv $B$3*mnn*$R$7ma $B$5(*xl*)$R$7 *fi**tk*> ",
"$R*rid*$RH:*hn*/*hm* M:*mn*/*mm* XL:*xl* *fi**tk*> ",
"$R*rid*$RH:*hn* M:*mn* Ma:*mnn* XL:*xl* *fi**tk*> ",
"$R*rid*$B$2*hn*$R$7h $B$6*mn*$R$7m $B$1(*xl*)$R$7 *fi**tk*> ",
"$R*rid*$R$2*hn*$7h $6*mn*$7m $5(*xl*)$7 *fi**tk*> ",
"$R*rid*$R$2*hn*$7h $6*mn*$7mv $B$7*mnn*$R$7ma $5(*xl*)$7 *fi**tk*> ",
"$R*rid*$R$2H:*hn*/*hm* $3M:*mn*/*mm* $5XL:*xl*$7 *fi**tk*> ",
"$R*rid*$B$2H:*hn*/*hm* $B$6M:*mn*/*mm* $B$1XL:*xl*$R$7 *fi**tk*> ",
"END"
};
void
set_default_prompt (CHAR_DATA * ch, char option)
{
if (!ch)
return;
option = UPPER (option);
if (option < 'A' || option > 'P')
option = 'A';
if (ch->pcdata->rprompt)
free_string (ch->pcdata->rprompt);
ch->pcdata->rprompt = str_dup (prompts[(option - 'A')]);
return;
}