tijer.c

demise/src/tijer.c · 9.1 KB

From the archive dodbackup-final.tar.gz

Download the archive   « Back to the archive contents

/*************************************************************
 * Everything in this file is used here under permission     *
 * from Tijer (Matthew Little).                              *
 * Code orignally from Legend of Chrystancia (C) 1999 - 2001 *
 * by Matthew Little.  All Rights Reserved.                  *
 * This code may be used as long as this header remains      *
 * unchanged, and intact. This code remains the property of  *
 * Matthew Little (Matthew@godwars.net)                      *
 *************************************************************/

#if defined(macintosh)
#include <types.h>
#else
#include <sys/types.h>
#endif
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "merc.h"

/*************************************************************
 * Online Relevel setting code, allows the addition of       *
 * Immortals to "do_relevel" without the need for a copyover *
 * Immortal data is saved to a file, and read in on bootup   *
 * of MUD                                                    *
 *                                                           *
 * Tijer 27/8/2002                                           *
 *************************************************************/

/*
 * Location of file
 */

#define IMMORTAL_FILE   "../txt/immortals.dat"	/* List of Relevel Imms                 */

/*
 * Local Variables
 */

int immortal_num;

/*
 * Prototypes needed
 */
struct immortal_list immlist[999];
void load_immortals ();


/* 
 * Structures for Immortals
 */

struct immortal_list
{
  char name[32];
  int level;
  int trust;
  int security;
  int se;
};
/* 
 * Save the Info to file.
 */

void
save_immortals ()
{
  FILE *fp;
  int f = 0;

/* 
 * Just incase the file gets wiped!!
 */

  if ((fp = fopen (IMMORTAL_FILE, "w")) == NULL)
    {
      bug ("Cannot open Immortal file for writing", 0);
      return;
    }
  if (immortal_num >= 0)
    for (f = 0; f <= immortal_num; f++)
      {
//       if (immlist[f].se < 0)
//        immlist[f].se = 0;

	fprintf (fp, "%s %d %d %d %d\n",
		 immlist[f].name,
		 immlist[f].level, immlist[f].trust, immlist[f].security,
		 immlist[f].se);
      }
  fprintf (fp, "END\n");
  fclose (fp);

}

/*
 * Load the File on disk on bootup of mud
 */

void
load_immortals ()
{
  FILE *fp;
  int j;
  char *name;

  fp = fopen (IMMORTAL_FILE, "r");

  if (!fp)
    {
      bug ("Cannot open Immortal file for reading", 0);
      return;
    }
  immortal_num = 0;
  for (j = 0;; j++)
    {
      name = fread_word (fp);
      if (!str_cmp (name, "END"))
	{
	  break;
	}
      strcpy (immlist[j].name, name);
      immlist[j].level = fread_number (fp);
      immlist[j].trust = fread_number (fp);
      immlist[j].security = fread_number (fp);
      immlist[j].se = fread_number (fp);
      immortal_num = j;

    }
  fclose (fp);

  return;
}

/* 
 * The actual relevel setting command (should only be immortal level
 */

void
do_setrelevel (CHAR_DATA * ch, char *argument)
{
  int cmd, f;
  char arg1[MSL];
  char arg2[MSL];
  char arg3[MSL];
  char immbuf[MSL];
  char buf2[MSL];
  char buf3[MSL];
  bool found;
  CHAR_DATA *victim;


  found = FALSE;

  if (IS_NPC (ch))
    return;

  argument = one_argument (argument, arg1);
  argument = one_argument (argument, arg2);
  argument = one_argument (argument, arg3);


  if (!str_cmp (arg1, "list"))
    {
      stc ("#L-----------------#7[ #yIMMORTALS #7]#L------------------#n\n\r",
	   ch);
      stc ("#7NAME:        LVL:  TRUST:  SECURITY:\n\r\n\r", ch);
      for (cmd = 0; *immlist[cmd].name; cmd++)
	{

	  immlist[cmd].name[0] = UPPER (immlist[cmd].name[0]);
	  sprintf (immbuf,
		   "#7%-13s #R%2d     %2d      %2d#n\n\r",
		   immlist[cmd].name,
		   immlist[cmd].level, immlist[cmd].trust,
		   immlist[cmd].security);
	  if (immlist[cmd].se > 0 && ch->level >= 12)
	    stc (immbuf, ch);
	  else if (immlist[cmd].se < 1)
	    stc (immbuf, ch);
	}
      stc ("#L------------------------------------------------#n\n\r", ch);
      sprintf (buf2, "Current Immortals: %d\n\r\n\r", immortal_num + 1);
      stc (buf2, ch);
      if (IS_CREATOR (ch) || IS_LINKSYS (ch))
	{
	  stc
	    ("Syntax: editlevel <option> <victim> <trust/level/security>\n\r",
	     ch);
	  stc ("Option being one of:\n\r", ch);
	  stc ("   list add remove set\n\r", ch);
	}
      return;
    }

  if (!IS_CREATOR (ch) && !IS_LINKSYS (ch))
    {
      do_setrelevel (ch, "list");
      return;
    }

  if (!str_cmp (arg1, "set"))
    {
      for (cmd = 0; cmd <= immortal_num; cmd++)
	{
	  if (!str_cmp (immlist[cmd].name, arg2))
	    {
	      f = cmd;
	      found = TRUE;
	      break;
	    }
	}
      if (!found)
	{
	  stc ("That person isn't on the list, add them first.\n\r", ch);
	  return;
	}

      if (!str_cmp (arg3, "level"))
	{
	  if (atoi (argument) > MAX_LEVEL + 1)
	    {
	      stc ("Invalid LEVEL\n\r", ch);
	      return;
	    }
	  if (is_number (argument))
	    {
	      immlist[f].level = atoi (argument);
	      stc ("Done.\n\r", ch);
	    }
	  else
	    stc ("Level has to be a number", ch);
	  save_immortals ();
	  return;
	}
      if (!str_cmp (arg3, "trust"))
	{
	  if (atoi (argument) > MAX_LEVEL + 1)
	    {
	      stc ("Invalid LEVEL\n\r", ch);
	      return;
	    }

	  if (is_number (argument))
	    {
	      immlist[f].trust = atoi (argument);
	      stc ("Done.\n\r", ch);
	    }
	  else
	    stc ("Trust has to be a number.\n\r", ch);
	  save_immortals ();
	  return;
	}
      if (!str_cmp (arg3, "security"))
	{
	  if (is_number (argument))
	    {
	      immlist[f].security = atoi (argument);
	      stc ("Done.\n\r", ch);
	    }
	  else
	    stc ("Security has to be a number.\n\r", ch);
	  save_immortals ();
	  return;
	}
      if (!str_cmp (arg3, "se"))
	{
	  if (atoi (argument) > 1)
	    {
	      stc ("Invalid se setting\n\r", ch);
	      return;
	    }
	  if (is_number (argument))
	    {
	      immlist[f].se = atoi (argument);
	      stc ("Done.\n\r", ch);
	    }
	  else
	    stc ("se has to be a number", ch);
	  save_immortals ();
	  return;
	}


      stc ("Choices to set are: Level, Trust, Security, Se.\n\r", ch);
      return;

    }

  if (!str_cmp (arg1, "add"))
    {

      if ((victim = get_char_world (ch, arg2)) == NULL)
	{
	  stc ("They aren't currently connected", ch);
	  return;
	}

/*      if (!IS_IMMORTAL (victim))
	{
	  stc
	    ("They MUST be an immortal before you add them to the relevel list!!\n\r",
	     ch);
	  return;
	}*/
      for (cmd = 0; cmd <= immortal_num; cmd++)
	{
	  if (!str_cmp (arg2, immlist[cmd].name))
	    {
	      stc ("They are already on the relevel list.\n\r", ch);
	      return;
	    }
	}

      strcpy (immlist[immortal_num + 1].name, arg2);
      immlist[immortal_num + 1].level = 1;
      immlist[immortal_num + 1].trust = 1;
      immlist[immortal_num + 1].security = 1;
      immlist[immortal_num + 1].se = 0;
      immortal_num += 1;
      sprintf (buf3, "Added %s to relevel.\n\r", victim->name);
      stc (buf3, ch);
      save_immortals ();
      return;
    }
  if (!str_cmp (arg1, "remove"))
    {
      for (cmd = 0; cmd <= immortal_num; cmd++)
	{
	  if (!str_cmp (immlist[cmd].name, arg2))
	    {
	      for (f = cmd; f <= immortal_num; f++)
		{
		  immlist[f] = immlist[f + 1];
		}
	      immortal_num--;
	      save_immortals ();
	      return;
	    }
	}
    }
  do_setrelevel (ch, "list");
  return;
}

/*
 * The NEW Relevel command :)
 */

void
do_relevel2 (CHAR_DATA * ch, char *argument)
{
  int cmd;

  if (IS_NPC (ch))
    return;

  for (cmd = 0; *immlist[cmd].name; cmd++)
    {
      if (!str_cmp (ch->name, immlist[cmd].name) && immlist[cmd].se < 1)
	{
	  ch->level = immlist[cmd].level;
	  ch->trust = immlist[cmd].trust;
	  ch->pcdata->security = immlist[cmd].security;
	  stc ("Done.\n\r", ch);
	  return;
	}
      else if (!str_cmp (ch->name, immlist[cmd].name) && immlist[cmd].se > 0)
	{
	  SET_BIT (ch->xxxbits, XXX_SE);
	  stc ("Done.\n\r", ch);
	  act ("A look of concentration crosses $n's face.", ch, NULL, NULL,
	       TO_ROOM);
	  act ("$n disappears.", ch, NULL, NULL, TO_ROOM);
	  return;
	}
    }
  waiting (ch, 48);
  send_to_char ("Huh?\n\r", ch);;
  return;
}


/*
 * Line Indent, Allows you to put in correct line breaks
 * and indent the break correctly
 *
 * Originally Coded by Brian Graversen (Jobo)
 * Ammended and tidied by Matthew Little (Tijer)
 */

char *
line_indent (char *text, int wBegin, int wMax)
{
  static char buf[MSL];
  char *ptr;
  char *ptr2;
  int count = 0;
  bool stop = FALSE;
  int wEnd;

  buf[0] = '\0';
  ptr = text;
  ptr2 = buf;

  while (!stop)
    {
      if (count == 0)
	{
	  if (*ptr == '\0')
	    wEnd = wMax - wBegin;
	  else if (strlen (ptr) < (wMax - wBegin))
	    wEnd = wMax - wBegin;
	  else
	    {
	      int x = 0;

	      while (*(ptr + (wMax - wBegin - x)) != ' ')
		x++;
	      wEnd = wMax - wBegin - (x - 1);
	      if (wEnd < 1)
		wEnd = wMax - wBegin;
	    }
	}
      if (count == 0 && *ptr == ' ')
	ptr++;
      else if (++count != wEnd)
	{
	  if ((*ptr2++ = *ptr++) == '\0')
	    stop = TRUE;
	}
      else if (*ptr == '\0')
	{
	  stop = TRUE;
	  *ptr2 = '\0';
	}
      else
	{
	  int k;

	  count = 0;
	  *ptr2++ = '\n';
	  *ptr2++ = '\r';
	  for (k = 0; k < wBegin; k++)
	    *ptr2++ = ' ';
	}
    }
  return buf;
}

Site Stats

Snippets: 1791
Codebases: 571