prse.c

./mudd/src/prse.c · 16.9 KB

From the archive emlen.tar.gz

Download the archive   « Back to the archive contents

#include <sys/types.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "mud.h"

struct int_apply_type int_app[33];
struct wis_apply_type wis_app[33];
struct con_apply_type con_app[33];

int lne = 1;
char line[40960];

int 
grab_num_2 (char *txt)
{
  int n = 0;
  char *t;
  for (t = txt; *t != '\0'; t++)
    {
      if (*t >= '0' && *t <= '9')
	{
	  n *= 10;
	  n += (*t) - '0';
	  continue;
	}
    }
  return n;
}

bool prmpt=FALSE;

char *
interpret_line (char *inlne, CHAR_DATA * ch)
{
  char tmpcd[100];
  int gpos;
  int pos;
  char *t;
  line[0] = '\0';
  lne = 1;
  gpos = 0;
  if (inlne == NULL)
    return "(type prompt all)";
  for (t = inlne; *t != '\0'; t++)
    {
      tmpcd[0] = '\0';
      pos = 0;
      if (*t == '\n')
	lne++;
      if (*t == '*')
	{
	  for (t++; *t != '*'; t++)
	    {
	      if (pos >= 10)
		{
		  fprintf (stderr, "Bad interpret * code.. '%s'.\n", inlne);
		  line[0] = '\0';
		  return line;
		}
	      tmpcd[pos] = *t;
	      pos++;
	    }
	  tmpcd[pos] = '\0';
	  line[gpos] = '\0';
	  strcat (line, parse_txt (tmpcd, ch));
	  gpos = strlen (line);
	  continue;
	}
      line[gpos] = *t;
      gpos++;
    }
  line[gpos] = '\0';
  return line;
}



char *
parse_txt (char *code, CHAR_DATA * ch)
{
  static char bf[200];
  char buf2[200];
  int sl = 0;
  int pad = 0;
  int i;
  char *tt;
  bool minus = FALSE;
  bool centered = FALSE;
  short leftpad = 0;
  short rightpad = 0;
  bf[0] = '\0';
  pad = grab_num_2 (code);
  if (pad > 20) pad = 20;
  for (tt = code; *tt != '\0'; tt++)
    {
      if (*tt == '-')
	minus = TRUE;
      else if (*tt == '!')
	centered = TRUE;
      else if (!is_digit(*tt))
	break;
    }
  switch (UPPER(*tt))
    {
    case 'A':
      if (!str_infix ("aff", code))
	{
	  if (ch->affected != NULL)
	    {
	      SPELL_DATA *spell;
	      AFFECT_DATA *paf;
	      char buf[500];
	      strcat (bf, "\n\rYou are affected by:");
	      lne++;
	      for (paf = ch->affected; paf != NULL; paf = paf->next)
		{
		  if ((spell = skill_lookup (NULL, paf->type)) == NULL)
		    continue;
		  lne++;
		  sprintf (buf, "\n\r%s", capitalize (spell->spell_name));
		  strcat (bf, buf);
		  if (IS_MOB (ch) || (LEVEL (ch) > 100))
		    sprintf (buf,
			     " (modifies %s by %d for %d mud hours)",
			     affect_loc_name (paf->location),
			     paf->modifier,
			     paf->duration);
		  else
		    {
		      if (paf->duration > 50)
			sprintf (buf, ", which won't wear off for many days!");
		      else if (paf->duration > 30)
			sprintf (buf, ", which will wear off in a day or two.");
		      else if (paf->duration > 20)
			sprintf (buf, ", which will wear off in about a day.");
		      else if (paf->duration > 10)
			sprintf (buf, ", which will wear off in about half a day.");
		      else if (paf->duration > 6)
			sprintf (buf, ", which will wear off in about a quarter of a day.");
		      else if (paf->duration > 3)
			sprintf (buf, ", which will wear off in a few hours.");
		      else if (paf->duration > 1)
			sprintf (buf, ", which will wear off soon.");
		      else if (paf->duration == 1)
			sprintf (buf, ", which will wear off very soon.");
		      else
			sprintf (buf, ", which will wear off at any moment.");
		    }
		  strcat (bf, buf);
		}
	    }
	} 
      else if (!str_infix ("al", code))
	{
	  sprintf (bf, "%d", ALIGN (ch));
	} 
      else if (!str_infix ("ap", code))
	{
	    sprintf (bf, "%d", GET_DAMROLL (ch)); 
	}
      else if (!str_infix ("a", code))
	{
	  sprintf (bf, "%d", get_age (ch));
	}
      break;
    case 'C':
      if (!str_infix ("cond", code))
	{
	  char tbf[100];
	  tbf[0] = '\0';
	  if (ch->pcdata->condition[COND_DRUNK] > 10)
	    strcat (tbf, "You are drunk.\n\r");
	  if (ch->pcdata->condition[COND_FULL] < 10 &&
	      ch->pcdata->condition[COND_FULL] > 5)
	    strcat (tbf, "You are starting to get hungry.\n\r");
	  if (ch->pcdata->condition[COND_THIRST] < 10 &&
	      ch->pcdata->condition[COND_THIRST] > 5)
	    strcat (tbf, "You are beginning to get thirsty.\n\r");
	  if (ch->pcdata->condition[COND_FULL] < 5 &&
	      ch->pcdata->condition[COND_FULL] > 0)
	    strcat (tbf, "You are hungry.\n\r");
	  if (ch->pcdata->condition[COND_THIRST] < 5 &&
	      ch->pcdata->condition[COND_THIRST] > 0)
	    strcat (tbf, "You are thirsty.\n\r");
	  if (ch->pcdata->condition[COND_THIRST] < 1)
	    strcat (tbf, "You are totally dehydrated!\n\r");
	  if (ch->pcdata->condition[COND_FULL] < 1)
	    strcat (tbf, "You are STARVING!\n\r");
	  if (tbf[0] != '\0')
	    {
	      lne++;
	      strcat (bf, "\n\r");
	      strcat (bf, tbf);
	    }
	}
      else if (!str_infix("cskl", code))
	{
	  sprintf(bf, "%d", leftover_slots(ch, 0));
	}
      else if (!str_infix("cspl", code))
	{
	  sprintf(bf, "%d", leftover_slots(ch, 1));
	}
      else if (!str_infix("cprf", code))
	{
	  sprintf(bf, "%d", leftover_slots(ch, 2));
	}
     
      else if (!str_infix ("clan", code))
	{
	  int ii;
	  if (IS_PLAYER (ch))
	    {
	      ii = clan_number (ch);
	      if (ii > 0)
		{
		  sprintf (bf, "\n\rMember of \x1B[1;36m%s\x1B[37;0m clan.", get_clan_index (ii)->name);
		  lne++;
		}
	    }
	}
      else if (!str_infix ("cv", code))
	{
	  if (LEVEL (ch) > 100)
	    sprintf (bf, "%d", ch->in_room->vnum);
	  else
	    bf[0] = '\0';
	} 
      else if (!str_infix ("cr", code))
	{
	  sprintf (bf, "%d", ch->pcdata->carry_number);
	}
      else if (!str_infix ("cn", code))
	{
	  sprintf (bf, "%d", tally_coins(ch));
	}
      else if (!str_infix ("cb", code))
	{
	  sprintf (bf, "%ld", ch->pcdata->bank);
	}
      break;
    case 'D':
      if (!str_infix ("dth", code))
	{
	  sprintf(bf, "%d", ch->pcdata->deaths);
	}
      break;
    case 'E':
      if (!str_infix ("eb", code))
	{
	  int evasion;
	  if (!ch->pcdata)
	    sprintf (bf, "0");
	  else
	    {
	      evasion = get_curr_dex (ch) + (LEVEL (ch) / 5) + 
		is_member (ch, GUILD_THIEF) +
		(ch->pcdata->learned[gsn_parry] / 7) +
		(ch->pcdata->learned[gsn_dodge] / 6) +
		(ch->pcdata->learned[gsn_shield_block] / 9) +
		(ch->pcdata->learned[gsn_riposte] / 7) +
		(ch->pcdata->learned[gsn_enhanced_dodge] / 6) +
		(ch->pcdata->learned[gsn_shieldbash] / 9) +
		(ch->pcdata->learned[gsn_blink]/8) +
		(IS_SET (ch->pcdata->fight_ops, F_AGGRESSIVE) ? 0 : 4);
	      sprintf (bf, "%d", evasion);
	    }
	}
      break;
    case 'F':
      if (!str_infix ("fi", code))
	{
	  if (!FIGHTING (ch))
	    bf[0] = '\0';
	  else
	    sprintf (bf, "[Oppnt: %s] ", capitalize (STRING_HITS (FIGHTING (ch))));
	}
      break;
    case 'G':
      
      if (!str_infix ("guilpt", code) && IS_PLAYER (ch))
	{
	  
	  sprintf(bf, "%d", ch->pcdata->guild_points);
	}
      else if (!str_infix ("guil", code) && IS_PLAYER (ch))
	{
	  
	  sprintf(bf, " %s",show_guilds(ch));
	}
      else if (!str_infix ("g", code))
	{
	  int i, j;
	  char *t;
	  i = 0;
	  for (t = line + (strlen (line)); t != line && *t != '\r' && *t != '\n'; t--)
	    {
	      i++;
	    }
	  for (j = pad - i; j > 0; j--)
	    {
	      strcat (bf, " ");
	      if (strlen(bf)>80) break;
	    }
	  return bf;
	}
      break;
    case 'H':
      if (!str_infix ("hn", code))
	{
	  sprintf (bf, "%ld", ch->hit);
	}
      else if (!str_infix ("hm", code))
	{
	  sprintf (bf, "%ld", ch->max_hit);
	}
      else if (!str_infix ("hw", code))
	{
	  sprintf (bf, "%s", capitalize (STRING_HITS (ch)));
	}
      else if (!str_infix ("ht", code))
	{
	  sprintf (bf, "%d' %2d\"",
		   ch->height / 12, ch->height % 12);
	}
      
      break; 
    case 'K':
      if (!str_infix ("kw", code))
	{
          sprintf (bf, "%d.%d Stone%s", ch->pcdata->carry_weight/WGT_MULT, ch->pcdata->carry_weight % WGT_MULT, ch->pcdata->carry_weight/WGT_MULT < 2 ? "" : "s");
	}
      else if (!str_infix ("kp", code))
	{
	  sprintf (bf, "%d", ch->pcdata->killpoints);
	}
      
      break;
    case 'L':
      if (!str_infix ("lea", code))
	{
	  sprintf (bf, "%d", (IS_MOB (ch) ? 0 : ch->pcdata->learn));
	}
      else if (!str_infix ("lvl", code))
	{
	  sprintf (bf, "%d", LEVEL (ch));
	}
     
      else if (!str_infix ("lnme", code))
	{
	  int offset = strlen(NAME(ch))/2;
	  int backset = (strlen(NAME(ch))+1)/2;
	  char buff[100];
	  int i;
	  sprintf(buff, " ");
	  for (i = 0; i < (20-offset); i++)
	    strcat(buff, " ");
	  strcat(buff, NAME(ch));
	  for (i = 0; i < (20-backset); i++)
	    strcat(buff, " "); 
	  
	  sprintf (bf, buff);
	}
      
      break;
    case 'M':
      if (!str_infix ("mnn", code))
	{
	  sprintf (bf, "%d", mana_now (ch));
	} 
      else if (!str_infix ("mmm", code))
	{
	  sprintf (bf, "%d", max_mana (ch));
	} 
      else if (!str_infix ("mn", code))
	{
	  sprintf (bf, "%d", ch->move);
	}
      else if (!str_infix ("mm", code))
	{
	  sprintf (bf, "%d", ch->max_move);
	}
      else if (!str_infix ("mw", code))
	{
	  sprintf (bf, "%s", capitalize (STRING_MOVES (ch)));
	}
      break;
    case 'N':
      if (!str_infix ("npkl", code))
	{
	  sprintf (bf, "%ld", ch->pcdata->pklevels);
	}
      else if (!str_infix ("npkh", code))
	{
	  sprintf (bf, "%ld", ch->pcdata->pkhelpers);
	}
      else if (!str_infix ("npks", code))
	{
	  sprintf (bf, "%d", ch->pcdata->pkills);
	}
      else if (!str_infix ("npkd", code))
	{
	  sprintf (bf, "%d", ch->pcdata->pkilled);
	} 
      else if (!str_infix ("npkr", code))
	{
	  sprintf (bf, "%ld", ch->pcdata->pkers);
	} 
      break;
    case 'O':
      if (!str_infix ("ob", code))
	{
	  int bonushit, offensive;
	  SINGLE_OBJECT *objt;
	  objt = get_item_held(ch, ITEM_WEAPON);
	  if (objt != NULL)
	    bonushit = addoffense2 (ch, objt);
          else
            bonushit = 0;
	  offensive = bonushit + GET_HITROLL (ch);
	  sprintf (bf, "%d", offensive);
	}
      break;  
    case 'P':
      if (!str_infix ("pos", code))
	{
	  char tbf[100];
	  tbf[0] = '\0';
	  switch (ch->position)
	    {
	    case POSITION_DEAD:
	      strcpy (tbf, "You are DEAD!!           ");
	      break;
	    case POSITION_MORTAL:
	      strcpy (tbf, "You are mortally wounded.");
	      break;
	    case POSITION_INCAP:
	      strcpy (tbf, "You are incapacitated.   ");
	      break;
	    case POSITION_STUNNED:
	      strcpy (tbf, "You are stunned.         ");
	      break;
	    case POSITION_SLEEPING:
	      strcpy (tbf, "You are sleeping.        ");
	      break;
	    case POSITION_RESTING:
	      strcpy (tbf, "You are resting.         ");
	      break;
	    case POSITION_MEDITATING:
	      strcpy (tbf, "You are meditating.      ");
	      break;
	    }
	  if (tbf[0] != '\0')
	    {
	      strcat (bf, "\n\r");
	      lne++;
	      strcat (bf, tbf);
	    }
	}
      else if (!str_infix ("pra", code))
	{
	  sprintf (bf, "%d", (IS_MOB (ch) ? 0 : ch->pcdata->practice));
	}
      
      else if (!str_infix ("pt", code))
	{
	  int hours = ((ch->pcdata->played) + (((int) (current_time - ch->pcdata->logon)))) / 3600;
	  sprintf (bf, "%d", hours);
	}
      break;
    case 'Q':
      for (i = 0; i < NUM_STATS; i++)
	{
	  if (!str_infix (stat_short_name[i], code))
	    {
	      if(LEVEL(ch) >= pow.level_to_see_numeric_stats)
		sprintf (bf, "%d", ch->pcdata->stat[i]);
	      else 
		sprintf(bf, "XX");  
	      break;
	    }
	}
      break;
    case 'R':
      if (!str_infix ("rank", code))
	{
	  if (LEVEL (ch) < 4)
	    sprintf (bf, "Inexperienced");
	  else if (LEVEL (ch) < 12)
	    sprintf (bf, "Knowledgable ");
	  else if (LEVEL (ch) < 27)
	    sprintf (bf, "Experienced  ");
	  else if (LEVEL (ch) < 45)
	    sprintf (bf, "Well-Known   ");
	  else if (LEVEL (ch) < 70)
	    sprintf (bf, "Famous       ");
	  else if (LEVEL (ch) < 100)
	    sprintf (bf, "LEGEND       ");
	  else
	    sprintf (bf, "A God        ");
	}
      else if (!str_infix ("rmt", code))
	{
	  sprintf (bf, "%d", ch->pcdata->remort_times);
	}
      else if (!str_infix ("rid", code))
        {
           if (MOUNTED_BY (ch))
             {
               sprintf(bf, "(ridden) ");
             }
           else if (RIDING (ch))
             {
               sprintf (bf, "(riding) ");
             }
           else bf[0] = '\0';
        }

      else if (!str_infix ("rpt", code))
	{
	  sprintf (bf, "%d", ch->pcdata->resist_points);
	}
      else if (!str_infix ("r", code))
	{
	  sprintf (bf, "%s", race_info[ch->pcdata->race].name);
	}
      break;
      
    case 'S':
      if (!str_infix ("sex", code))
	{
	  if (ch->pcdata->sex == SEX_MALE) sprintf (bf, "Male   ");
	  else if (ch->pcdata->sex == SEX_FEMALE) sprintf (bf, "Female ");
	  else 
	    {
	      ch->pcdata->sex = SEX_NEUTRAL;
	      sprintf(bf, "Neutral");
	    }
	} 
      else if (!str_infix("snme", code))
	{
	  sprintf (bf, NAME(ch));
	}
      else if (!str_infix ("sect", code))
	{
	  int ii;
	  if (IS_PLAYER (ch))
	    {
	      ii = clan_number_2 (ch);
	      if (ii > 0)
		{
		  sprintf (bf, "\n\rMember of \x1B[1;36m%s\x1B[37;0m sect.", get_clan_index_2 (ii)->name);
		  lne++;
		}
	    }
	}
      break;
    case 'T':
      if (!str_infix ("tskl", code))
	{
	  sprintf(bf, "%d", total_slots(ch, 0));
	}
      else  if (!str_infix ("tspl", code))
	{
	  sprintf(bf, "%d", total_slots(ch, 1));
	}
      else  if (!str_infix ("tprf", code))
	{
	  sprintf(bf, "%d", total_slots(ch, 2));
	}
      else if (!str_infix ("tk", code))
	{
	  if (!FIGHTING (ch) || !FIGHTING (FIGHTING (ch)) || FIGHTING (FIGHTING (ch)) == ch)
	    bf[0] = '\0';
	  else
	    sprintf (bf, "[%s: %s] ", NAME (FIGHTING (FIGHTING (ch))), capitalize (STRING_HITS (FIGHTING (FIGHTING (ch)))));
	}
      else if (!str_infix ("twp", code))
	{
	  sprintf (bf, "%ld", ch->pcdata->total_wps);
	} 
      else if (!str_infix ("tc", code))
	{
	  sprintf (bf, "%d", ch->pcdata->totalkills);
	}
      break;
    case 'W':
      if (!str_infix ("warm", code) && IS_PLAYER (ch))
	{
	  if (cur_temp (ch) < 50)
	    {
	      if (ch->pcdata->warmth > 0)
		{
		  switch (ch->pcdata->warmth / 10)
		    {
		    case 0:
		    case 1:
		      strcat (bf, "\n\rYour clothing doesn't protect you too well in cold weather.");
		      break;
		    case 2:
		    case 3:
		      strcat (bf, "\n\rYour clothing protects you moderately well in cold weather.");
		      break;
		    case 4:
		      strcat (bf, "\n\rYour clothing protects you quite well in cold weather.");
		      break;
		    case 5:
		      strcat (bf, "\n\rYour clothing would keep you warm in some of the most frigid conditions.");
		      break;
		    default:
		      strcat (bf, "\n\rYour clothing would keep you very warm even in the middle of a blizzard!");
		      break;
		    }
		  lne++; 
		}
	    }
	}
      else if (!str_infix ("wim", code))
	{
	  sprintf (bf, "%d", (!ch->pcdata ? 0 : ch->pcdata->wimpy));
	}
      else if (!str_infix ("wil", code))
	{
	  if( LEVEL(ch) >= pow.level_to_see_numeric_stats)
	    sprintf (bf, "%d", get_stat (ch, WIL));
	  else 
	    sprintf(bf, "XX");
	}
      
      else if (!str_infix ("wm", code))
	{
	  sprintf (bf, "%s", capitalize (string_mana (mana_now (ch))));
	}
      else if (!str_infix ("ww", code))
	{
	  int weightmult = (get_curr_str(ch)+
			    (IS_AUGMENTED(ch, AUG_BODY_STR) ? 2 : 0)+
			    (IS_AUGMENTED(ch, AUG_LEG_STR) ? 2 : 0)+ 
			    (IS_AUGMENTED(ch, AUG_FOOT_STR) ? 1 : 0))* WGT_MULT;
	  
	  if (ch->pcdata->carry_weight < weightmult *1)
	    sprintf (bf, "You are unburdened.");
	  else if (ch->pcdata->carry_weight < (weightmult * 2))
	    sprintf (bf, "No problem.        ");
	  else if (ch->pcdata->carry_weight < (weightmult * 3))
	    sprintf (bf, "It is a tad heavy. ");
	  else if (ch->pcdata->carry_weight < (weightmult * 4))
	    sprintf (bf, "It is heavy now.   ");
	  else if (ch->pcdata->carry_weight < (weightmult * 5))
	    sprintf (bf, "VERY heavy!        ");
	  else
	    sprintf (bf, "YOU ARE IN PAIN!   ");
	  
	}
      else if (!str_infix ("wp", code))
	{
	  sprintf (bf, "%ld", ch->pcdata->warpoints);
	}
      break;
      
    case 'X':
      if (!str_infix ("xp", code))
	{
	  sprintf (bf, "%ld", ch->pcdata->exp);
	}
      else if (!str_infix ("xl", code))
	{
	  sprintf (bf, "%ld", ((FIND_EXP (LEVEL (ch), ch->race)) - ch->pcdata->exp));
	}
      break;
    case 'Z':
      for (i = 0; i < NUM_STATS; i++)
	{
	  if (!str_infix (stat_short_name[i], code))
	    {
	      if(LEVEL(ch) >= pow.level_to_see_numeric_stats)
		sprintf (bf, "%d", get_stat (ch, i));
	      else 
		sprintf(bf, "XX");  
	      break;
	    }
	}
      break;
    }
  
  
  
  sl = strlen (bf);

  /* If the padding is too big, we check if its centerd and split the 
     white space. Putting a - makes the extra space go on the left,
     for centering. */
  
  if (pad > sl)
    {
      if (centered)
	{
	  leftpad = (pad - sl)/2;
	  rightpad = (pad - sl)/2;
	  if (minus) /* centered minus makes the shift one space to the left*/
	    rightpad += (pad - sl) % 2;
	  else
	    leftpad += (pad - sl) % 2;
	}
      else
	{
	  if (minus) /* If we have the minus, stuff is left justified */
	    rightpad = (pad - sl);
	  else /* Without a minus, things are right justified. */
	    leftpad = (pad - sl);
	}
      buf2[0] = '\0';
      if (leftpad > 0)
	for (i = 0; i < leftpad; i++)
	  {
	    strcat(buf2, " ");
	  }
      strcat(buf2, bf);
      if (rightpad > 0)
	for (i = 0; i < rightpad; i++)
	  {
	    strcat(buf2, " ");
	  }
      strcpy (bf, buf2);
    }
  if (pad > 1 && pad < sl)
    {
      bf[pad] = '\0';
    }
  
  return bf;
}
















Site Stats

Snippets: 1791
Codebases: 571