info.c

./mudd/src/info.c · 18.3 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"

void
do_levels (CHAR_DATA * ch, char *argy)
{
  int i, a, b;
  char buffr[256];
  char arg1[SML_LENGTH];
  DEFINE_COMMAND ("levels", do_levels, POSITION_DEAD, 0, LOG_NORMAL, "This command shows exp needed for the level range specified.")

    buffr[0] = '\0';
  argy = one_argy (argy, arg1);
  if (!is_number (argy) || !is_number (arg1))
    {
      send_to_char ("Syntax is \"level <min> <max>\"\n\r", ch);
      return;
    }
  a = atoi (arg1);
  b = atoi (argy);
  if (a >= b || a < 1 || a > 90 || b < 2 || b > 90)
    {
      send_to_char ("Invalid range.\n\r", ch);
      return;
    }
  for (i = a; i < b; i++)
    {
      sprintf (buffr, "Level %d Exp: %ld\n\r", i + 1, FIND_EXP (i, ch->race));
      send_to_char (buffr, ch);
    }
  return;
}


void
do_reload_help (CHAR_DATA * ch, char *argy)
{
  FILE *fp;
  char word[500];
  DESCRIPTOR_DATA *d;
  HELP_DATA *hnx;
  HELP_DATA *hc;
  DEFINE_COMMAND ("rld_help", do_reload_help, POSITION_DEAD, MAX_LEVEL, LOG_ALWAYS, "This command reloads the helpfiles from disk.")

  if (IS_MOB(ch))
    return;

  for (d = descriptor_list; d != NULL; d = d->next)
     {
       if (d->connected == CON_HEDITOR)
         {
           send_to_char("\n\rYou cannot reload help files while someone is in the editor.\n\r", ch);
           return;
         }
      }
  if ((fp = fopen ("help.are", "r")) == NULL)
    {
      send_to_char ("Unable to open the helpfile...", ch);
      return;
    }
  for (hc = help_first; hc != NULL; hc = hnx)
    {
      hnx = hc->next;
      free_string (hc->keyword);
      free_string (hc->text);
    }
  help_last = NULL;
  help_first = NULL;
  top_help = 0;
  word[0] = '\0';
  while (str_cmp ("#HELPS", word))
    strcpy (word, fread_word (fp));
  load_helps (fp);
  send_to_char ("Successfully reloaded.\n\r", ch);
  fclose (fp);
  return;
}

void
do_help (CHAR_DATA * ch, char *argy)
{
  char argall[SML_LENGTH];
  char argone[SML_LENGTH];
  HELP_DATA *pHelp;
  DEFINE_COMMAND ("help", do_help, POSITION_DEAD, 0, LOG_NORMAL, "This is the basic help command.  Syntax is 'help' or 'help <topic>'.")

    if (argy[0] == '\0')
      {
       send_to_char("Type help <word> for specific help. Typing commands will give you a list of all the commands available to you.\n\r", ch);
       return;
      }

  argall[0] = '\0';
  while (argy[0] != '\0')
    {
      argy = one_argy (argy, argone);
      if (argall[0] != '\0')
        strcat (argall, " ");
      strcat (argall, argone);
    }
  for (pHelp = help_first; pHelp && pHelp != NULL; pHelp = pHelp->next)
    {
      if (pHelp->level > LEVEL (ch))
        continue;
      if (is_name (argall, pHelp->keyword))
        {
	  int i;
	  int offset = (38- (strlen(pHelp->keyword))/2);
	  hugebuf_o[0] = '\0';
	  if (offset > 35) offset = 35;
	  if (offset < 0) offset = 0;


  if IS_SET(ch->pcdata->act2, PLR_ASCII)
    {
      strcat (hugebuf_o, "\n\r\x1B[1;30mÄÄÄÄÄÄ\x1B[0;34mÄÄÄÄÄÄÄÄÄÄÄÄÄ\x1B[1;34mÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ\x1B[0;34mÄÄÄÄÄÄÄÄÄÄÄÄÄ\x1B[1;30mÄÄÄÄÄÄ\x1B[0m\n\r");
    }
  else
    {
      strcat (hugebuf_o, "\n\r\x1B[1;30m------\x1B[0;34m-------------\x1B[1;34m-----------------------------------------\x1B[0;34m-------------\x1B[1;30m------\x1B[0m\n\r");
    }
	  for (i=0; i <offset; i++)
	    strcat(hugebuf_o, " ");
	  strcat(hugebuf_o, pHelp->keyword);

  if IS_SET(ch->pcdata->act2, PLR_ASCII)
    {
      strcat (hugebuf_o, "\n\r\x1B[1;30mÄÄÄÄÄÄ\x1B[0;34mÄÄÄÄÄÄÄÄÄÄÄÄÄ\x1B[1;34mÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ\x1B[0;34mÄÄÄÄÄÄÄÄÄÄÄÄÄ\x1B[1;30mÄÄÄÄÄÄ\x1B[0m\n\r\n\r");
    }
  else
    {
      strcat (hugebuf_o, "\n\r\x1B[1;30m------\x1B[0;34m-------------\x1B[1;34m-----------------------------------------\x1B[0;34m-------------\x1B[1;30m------\x1B[0m\n\r\n\r");
    }
          strcat(hugebuf_o, pHelp->text);
	  page_to_char(hugebuf_o, ch);
          return;
	}
    }
  send_to_char ("No help on that word.\n\r", ch);
  return;
}
void
show_help_text (CHAR_DATA * ch, char *argy)
{
  char argall[SML_LENGTH];
  char argone[SML_LENGTH];
  char j[50];
  HELP_DATA *pHelp;

    if (argy[0] == '\0')
      return;
/*
   * Tricky argy handling so 'help a b' doesn't match a.
 */
  argall[0] = '\0';
  while (argy[0] != '\0')
    {
      argy = one_argy (argy, argone);
      if (argall[0] != '\0')
        strcat (argall, " ");
      strcat (argall, argone);
    }
  for (pHelp = help_first; pHelp && pHelp != NULL; pHelp = pHelp->next)
    {
      if (is_name (argall, pHelp->keyword))
        {
	  char hugebuf_o[30000] = "\0";
         
          /*
             * Strip leading '.' to allow initial blanks.
	     */
	  if (pHelp->text[0] == '.')
	    strcat(hugebuf_o, pHelp->text);
	  else
	    strcat(hugebuf_o, pHelp->text);
	  page_to_char(hugebuf_o, ch);
          return;
	}
    }
  send_to_char ("There is no help file for that skill or spell.\n\r", ch);
  return;
}

void
do_who (CHAR_DATA * ch, char *argy)
{
  CHAR_DATA *wch;
  int pass;
  DESCRIPTOR_DATA *d;
  int vis;
  int ii;
  int nMatch;
  bool tempbool;
  int gMatch;
  int align;
  bool namey;
  char doe[STD_LENGTH];
  bool clanny;
  bool battle;
  DEFINE_COMMAND ("who", do_who, POSITION_DEAD, 0, LOG_NORMAL, "This command shows who is playing and visible to you at the moment.")

    ii = clan_number (ch);
  align = 0;
  nMatch = 0;
  clanny = FALSE;
  battle = FALSE;
  gMatch = 0;
  vis = 0;
  hugebuf_o[0] = '\0';

  if (IS_PLAYER(ch) && ch->pcdata->online_spot)
    {
       ch->pcdata->online_spot->typed_who = TRUE;
    }
    sprintf (hugebuf_o, "\x1B[1;34m-----------------------------------------------------------------------------\x1B[0m\n\r");

  namey = FALSE;
 

  /* In general, gods see all align = -2 means see all, align = -1 = see imms only, align = 0-NUM_ALIGN-1 means see that align only */

  if (LEVEL(ch) >=MAX_LEVEL)
    {
      if (!str_cmp (argy, "clan"))
        {
          clanny = TRUE;
          if (ii < 1)
            {
              send_to_char ("You aren't in a clan!\n\r", ch);
              return;
            }
        }
      else if (!str_cmp (argy, "battle") || !str_cmp (argy, "battleground"))
	battle = TRUE;
      else if (!str_cmp (argy, "god") || !str_cmp (argy, "immortal"))
        align = -1; /* Show imms only */
      else if (is_number (argy))
	{
	  align = atoi (argy);
	  if (align < 0 || align >= NUM_ALIGN)
	    return;
	}
      else if (argy[0] != '\0')
        {
          argy[0] = UPPER (argy[0]);
          namey = TRUE;
        }
      else align = -2;
    }
  else if (LEVEL(ch) > IMM_LEVEL && LEVEL(ch) <MAX_LEVEL)
    align = -1;
  else if (LEVEL(ch) < IMM_LEVEL)
    {
      if (detect_opp_align)
	align = -2;
      else
	align = ch->pcdata->alignment;
      if (argy[0] != '\0' || argy != "")
	{
	  if (!str_cmp (argy, "clan"))
	    {
	      clanny = TRUE;
	      if (ii < 1)
		{
		  send_to_char ("You aren't in a clan!\n\r", ch);
		  return;
		}
	    }
	  else if (!str_cmp (argy, "battle") || !str_cmp (argy, "battleground"))
	    battle = TRUE; /* Show only who is in battle */
	  else if (!str_cmp (argy, "god") || !str_cmp (argy, "immortal"))
	    align = -1;
	  else if (argy[0] != '\0')
	    {
	      argy[0] = UPPER (argy[0]);
	      namey = TRUE;
	    }
	}
    }
  tempbool = FALSE;
  for (pass = -1; pass < NUM_ALIGN; pass++)
    {
      if (!tempbool && pass != -1)
        {
          tempbool = TRUE;
	  if (LEVEL(ch) < MAX_LEVEL)
	    sprintf (hugebuf_o + strlen (hugebuf_o), "\x1B[0;36m- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\x1B[37;0m\n\r");
	  else
	    sprintf (hugebuf_o + strlen (hugebuf_o), "\x1B[0;36mAl Lv Rm Rc Cl- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\x1B[37;0m\n\r");
	  /*

	   {
              int j = 0;
		int len = strlen(align_info[pass].name);
		int flex = 38-(7+len/2);
		char buff[50];
		char bufg[50];
		sprintf(buff, "\x1b[1;34m");
		sprintf(bufg, "\x1b[1;34m");
		
		for (j = 0; j < flex; j++)
		  strcat(buff, "-");
		 for (j = 0; j < (flex-1); j++)
		  strcat(bufg, "-");
		 if (!IS_SET(len, 1))
		   strcat(bufg, "-");
		 
		 sprintf (hugebuf_o + strlen (hugebuf_o), "%s\x1b[0;37m[ \x1b[1;37m%s Characters\x1b[0;37m ]%s\x1B[0;37m\n\r", buff, capitalize(align_info(pass).name), bufg);
	      }
	    */
	  
        }
      for (d = descriptor_list; d != NULL; d = d->next)
        {
          wch = NULL;
          if (d->character == NULL || 
	      IS_MOB (d->character) ||
	      d->character->desc == NULL)
	    continue;
          if ((d->connected != CON_PLAYING
               && d->connected != CON_AEDITOR
               && d->connected != CON_REDITOR
               && d->connected != CON_CEDITOR
               && d->connected != CON_OEDITOR
	       && d->connected != CON_MEDITOR
	       && d->connected != CON_HEDITOR
	       && d->connected != CON_SEDITOR) || !can_see (ch, d->character))
            continue;
          if (d->connected != CON_PLAYING && !IS_IMMORTAL (ch))     continue;
          wch = (d->original != NULL) ? d->original : d->character;
          if (clanny && clan_number (wch) != ii)  continue;
          if (namey && str_prefix (capitalize (argy), NAME (wch))) continue;
          if (battle && !IN_BATTLE (wch)) continue;
         
	  if ((LEVEL (wch) > IMM_LEVEL) == (pass != -1)) continue;
 	  if (LEVEL (wch) <= IMM_LEVEL && (pass != ALIGN(wch) || align ==-1)) continue;
	  if (align != -2)
	    {
	      if (LEVEL(wch) < IMM_LEVEL && LEVEL(ch) < MAX_LEVEL &&
 		  (!alliance[align][ALIGN(wch)] ||
                  ch->pcdata->remort_times < wch->pcdata->remort_times/2)
                && !detect_opp_align)
		continue;
	       if (LEVEL (wch) < MAX_LEVEL && LEVEL (wch) > IMM_LEVEL && 
                  LEVEL (ch) < IMM_LEVEL) continue;
	    }
	  nMatch++;
          doe[0] = '\0';
          if (LEVEL (wch) > IMM_LEVEL)
            {
              if (wch->pcdata->wizinvis == 0)
                gMatch++;
              if (d->connected != CON_PLAYING)
		{
		  if (d->connected == CON_SEDITOR)
		    sprintf (doe, "\x1B[1;36m Spell Editing ");
		  else if (d->connected == CON_HEDITOR)
		    sprintf (doe, "\x1B[1;36mHelp Editing");
		  else
		    sprintf (doe, "\x1B[1;36m  Building ");
		}
              else
                {
                  switch (LEVEL (wch))
                    {
                    default:
                      sprintf (doe, "\x1B[1;33m  Builder  ");
                      break;
                    case TOP_LEVEL:
                      sprintf (doe, "\x1B[1;35m-* Admin *-");
                      break;
                    }
                }
              if (wch->pcdata->quiet == 1)
                sprintf (doe, "\x1B[1;35m- Quiet Mode -");
              if (wch->pcdata->quiet == 2)
                sprintf (doe, "\x1B[1;34m- Busy Mode - ");
            }
          {
            if (IS_PLAYER (ch) && LEVEL (ch) < IMM_LEVEL && !IS_MOB (wch) && !DIFF_ALIGN(ch, wch))
              vis++;
	    
            if (ii > 0 && LEVEL(ch) < MAX_LEVEL)
              {
                if (clan_number (wch) == ii)
                  {
                    sprintf (hugebuf_o + strlen (hugebuf_o), "<C>");
                  }
                else
                  sprintf (hugebuf_o + strlen (hugebuf_o), "   ");
              }
            if (LEVEL (ch) >= MAX_LEVEL && LEVEL (wch) <= IMM_LEVEL)
              {
                sprintf (hugebuf_o + strlen (hugebuf_o),
			 /*                   Align       Lev,Rmt,Rce,Clan,Sil,WtBtl,InBtl,PKILL */
                         "\x1B[1;30m[\x1B[1;31m%d%3d%3d%3d%3d %s%s\x1B[1;30m]\x1B[37;0m %s%s %s%s%s\x1B[0;37m\n\r", 
			 ALIGN(wch),  
			 LEVEL (wch), 
			 wch->pcdata->remort_times, 
			 wch->pcdata->race, 
			 wch->pcdata->clan,
			 (IS_SET (wch->pcdata->act2, PLR_SILENCE) ? "s" : " "),
			 (wch->pcdata->battleground == BATTLE_JOINING ? "-" : wch->pcdata->battleground == BATTLE_FIGHTING ? "+" : " "),
                         wch->timer > 49 ? "\x1B[1;37m<AFK> \x1B[37;0m" : "", 
			 NAME (wch),
			 wch->pcdata->title,
			 (IS_AFF (wch, INVIS)) ? " (Invis)" : "",
                         (wch->pcdata->wizinvis != 0 ? " (Invis)" : ""));
              }
            else
              {
                if (doe[0] == '\0')
                  {
                    if IS_SET(wch->pcdata->act2, PLR_ANONYMOUS)
                      sprintf (doe, "\x1B[1;34m- - - - ");
                    else
                      sprintf (doe, "\x1B[1;3%dmLevel %2d", UMIN(7,wch->pcdata->remort_times), LEVEL (wch));
                  }



                sprintf (hugebuf_o + strlen (hugebuf_o),
                         "\x1B[1;30m[ %s \x1B[1;30m] \x1b[0;37m %s%s %s%s\x1B[37;0m\n\r",
                         doe, 
                         wch->timer > 49 ? "\x1B[1;37m<AFK> \x1B[0;37m" : "", NAME (wch),   
			 wch->pcdata->title, 
			 (wch->pcdata->wizinvis != 0 ? " (Invis)" : ""));
              }
          }
        }
      /*end Pass */
    }
  sprintf (hugebuf_o + strlen (hugebuf_o), "\x1B[1;3%dm-----------------------------------------------------------------------------\x1B[0;37m\n\r", 4);
  sprintf (hugebuf_o + strlen (hugebuf_o), "There %s \x1b[1;37m%d\x1b[0;37m player%s visible to you, and \x1b[1;37m%d\x1b[0;37m player%s total online since reboot.\n\r" ,
            (LEVEL(ch) > IMM_LEVEL ? nMatch : vis)> 1 ? "are" : "is", (LEVEL(ch) > IMM_LEVEL ? nMatch : vis),
            (LEVEL(ch) > IMM_LEVEL ? nMatch : vis) > 1 ? "s" : "", max_connected,
	   max_connected > 1 ? "s" : "");
  page_to_char (hugebuf_o, ch);
  return;
}


char *const day_name[] =
{
  "Monday", "Tuesday", "Wednesday", "Thursday",
  "Friday", "Saturday", "Sunday"
}

 ;
char *const month_name[] =
{
  "Winter", "Winter", "Midwinter", "Midwinter",
  "Early Spring", "Spring", "Spring",
  "Late Spring", "Early Summer", "Summer",
  "Midsummer", "High Summer", "Late Summer", "Early Autumn",
  "Autumn", "Mid-Autumn", "Late Autumn", "Aturion Twilight",
  "Aturion Twilight", "The Frigid Moon", "Early Winter"
}

 ;
void
do_time (CHAR_DATA * ch, char *argy)
{
  char buf[STD_LENGTH];
  char *suf;
  int day;
  DEFINE_COMMAND ("time", do_time, POSITION_DEAD, 0, LOG_NORMAL, "This command shows you the current time.")

    day = time_info.day + 1;
  if (day > 4 && day < 20)
    suf = "th";
  else if (day % 10 == 1)
    suf = "st";
  else if (day % 10 == 2)
    suf = "nd";
  else if (day % 10 == 3)
    suf = "rd";
  else
    suf = "th";

  sprintf (buf,
  "It is %d o'clock %s on the day of %s.\n\r(The %d%s of %s. Year: %d)\n\r",
           (time_info.hour % 12 == 0) ? 12 : time_info.hour % 12,
           time_info.hour >= 12 ? "pm" : "am",
           day_name[day % 7],
           day, suf,
           month_name[time_info.month], time_info.year);
  send_to_char (buf, ch);
  return;
}

int
cur_temp (CHAR_DATA * ch)
{
  int temp_adj;
  int rweth;
  rweth = weather_info.temperature;
  temp_adj = 0;
  if (!ch->in_room || !ch->in_room->area)
    return 60;
  switch (ch->in_room->sector_type)
    {
    default:
       temp_adj = 0;
       break;
    case SECT_LAVA:
      temp_adj = 100;
      break; 
    case SECT_DESERT:
    case SECT_WASTELAND:
      temp_adj = 10;
      break;
    case SECT_TROPICAL:
    case SECT_SWAMP:
    case SECT_MARSH:
      temp_adj = 5;
      break;
    case SECT_SNOW:
    case SECT_ICE:
    case SECT_ARCTIC:
      temp_adj = -10;
      break;
    case SECT_INSIDE:
      temp_adj = 0;
      break;
    case SECT_MOUNTAIN:
    case SECT_HILLS:
    case SECT_ROCKY:
      temp_adj = -5;
      break;
    case SECT_AIR:
    case SECT_CANYON:
    case SECT_ASTRAL:
    case SECT_BRUSH:
      temp_adj = -3;
      break;

    }
  if (ch->in_room->sector_type >= SECT_CAVE)
    temp_adj = -10;
  rweth += temp_adj;
  return rweth;
}

// Some Weather crap borrowed from other codebases */

void
do_weather (CHAR_DATA * ch, char *argy)
{
  char buf[STD_LENGTH];
  char descr[STD_LENGTH];
  short wind;
  int temp_adj, sky, wt;
  static char *const sky_look[] =
  {
    "cloudless",
    "cloudy",
    "rainy",
    "lit by flashes of lightning",
    "thick with fog",
    "slightly sunny",
    "slightly overcast",
    "scattered with a few flakes",
    "filled with flakes",
    "a blizzard of white",
    "thick with fog",
    "not visible underwater.",
    "stormy"
  }
   ;
  static char *const wind_tmp[4] =
  {
    "cold", "cool", "warm", "hot"
  }
   ;
  DEFINE_COMMAND ("weather", do_weather, POSITION_RESTING, 0, LOG_NORMAL, "This command allows you to see the weather (outdoors).")

  wind = weather_info.windspeed;
  sky = weather_info.sky;
  temp_adj = 0;
  do_time (ch, "");
  switch (ch->in_room->sector_type)
    {
    case SECT_LAVA:
      temp_adj = 110;
      break; 
    case SECT_DESERT:
    case SECT_WASTELAND:
      temp_adj = 60;
      break;
    case SECT_TROPICAL:
    case SECT_SWAMP:
    case SECT_MARSH:
      temp_adj = 50;
      break;
    case SECT_SNOW:
    case SECT_ICE:
    case SECT_ARCTIC:
      temp_adj = -30;
      break;
    case SECT_INSIDE:
      temp_adj = 15;
      break;
    case SECT_MOUNTAIN:
    case SECT_HILLS:
    case SECT_ROCKY:
      temp_adj = -17;
      break;
    case SECT_AIR:
    case SECT_CANYON:
    case SECT_ASTRAL:
    case SECT_BRUSH:
      temp_adj = -15;
      break;
    }
  if (temp_adj + weather_info.temperature > 90)
    wt = 3;
  else if (temp_adj + weather_info.temperature > 75)
    wt = 2;
  else if (temp_adj + weather_info.temperature > 50)
    wt = 1;
  else
    wt = 0;
  if (!IS_OUTSIDE (ch) || ch->in_room->sector_type >= SECT_CAVE)
    {
      send_to_char ("You can only see the weather from the outdoors.\n\r", ch);
      return;
    }
  descr[0] = '\0';
  sprintf (buf, "The sky is %s ",
           ((time_info.month <= 4 || time_info.month >= 17)
            && (temp_adj + weather_info.temperature <= 32)) ?
           sky_look[sky + 5] : sky_look[sky]);
  strcat (descr, buf);
  if (wt != -1)
    {
      sprintf (buf, "and a %s %sward %s blows.\n\r",
               wind_tmp[wt],
               dir_name[abs (weather_info.winddir) % 3],
               wind < 10 ? "breeze" :
               wind < 20 ? "wind" :
               wind < 30 ? "gust" : "torrent");
      strcat (descr, buf);
    }
  sprintf (buf, "It is %d degrees right now.\n\r",
           (temp_adj + weather_info.temperature));
  strcat (descr, buf);
/*if ( IS_IMMORTAL( ch ) )
   {
   sprintf( buf, "(temp: %d, windspd: %d, wind dir: %d, sky: %d, mmhg: %d, change: %d)\n\r",
   (temp_adj+weather_info.temperature),
   weather_info.windspeed,
   weather_info.winddir,
   weather_info.sky,
   weather_info.mmhg,
   weather_info.change );
   strcat( descr, buf );
   }
 */
  send_to_char (descr, ch);
  return;
}

Site Stats

Snippets: 1791
Codebases: 571