changes.c

demise/src/changes.c · 13.5 KB

From the archive dodbackup-final.tar.gz

Download the archive   « Back to the archive contents

#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"

void add_change args ((CHAR_DATA * ch, char *file, char *string));
void read_changes args ((char *file));
void save_changes args ((char *file));

CHANGES_DATA *first_change;
CHANGES_DATA *last_change;

void
do_changes (CHAR_DATA * ch, char *argument)
{
  CHANGES_DATA *change;
  CHANGES_DATA *starting_change;
  bool help_change = FALSE;
  char buf[MSL];
  char arg[MIL];
  char arg2[MIL];
  int num, totalnum, value;

  argument = one_argument (argument, arg);
  num = 0;
  totalnum = 0;

  {
    if (!str_cmp (arg, "add"))
      {
	if (!IS_IMMORTAL (ch))
	  {
	    do_changes (ch, "");
	    return;
	  }
	if (strlen (argument) < 1)
	  {
	    do_changes (ch, "");
	    return;
	  }
	add_change (ch, CHANGE_FILE, argument);
	sprintf (buf, "#7New Change by #R%s#C: #7%s#n", ch->name, argument);
	do_info (ch, buf);
	return;
      }
    read_changes (CHANGE_FILE);
    help_change = FALSE;
  }

  for (change = first_change; change != NULL; change = change->next)
    totalnum++;

  if (help_change)
    strcpy (arg, arg2);

  if (arg[0] == '\0' || !is_number (arg))
    value = (totalnum < 20) ? totalnum : 20;
  else
    value = atoi (arg);

  if (value < 1 || value > totalnum)
    {
      sprintf (buf, "Enter a number between 1 and %d.\n\r", totalnum);
      send_to_char (buf, ch);
      return;
    }

  if (value < 1 || value > 100)
    {
      sprintf (buf, "Enter a number between 1 and 100.\n\r");
      send_to_char (buf, ch);
      return;
    }

  line (ch);
  cent_to_char
    ("#7[#o***#7]#R Minor code changes and quick messages #7[#o***#7]#n", ch);
  line (ch);

  for (change = last_change;;)
    {
      num++;
      if (num == value)
	{
	  starting_change = change;
	  break;
	}
      change = change->prev;
    }

  for (change = starting_change;; change = change->next)
    {
      sprintf (buf, "#R[#7%-8s#R]#C:#7 %s#n\n\r", change->name,
	       line_indent (change->text, 12, 80));
      send_to_char (buf, ch);
      if (change->next == NULL)
	break;
    }

  line (ch);
  sprintf (buf, "#RThere is a total of #7%3d#R chang%s made.#n", totalnum,
	   totalnum == 1 ? "e" : "es");
  cent_to_char (buf, ch);
  sprintf (buf, "#RThere are currently #7%3d#R chang%s showing.#n", num,
	   num == 1 ? "e" : "es");
  cent_to_char (buf, ch);
  line (ch);
  return;
}

void
read_changes (char *file)
{
  CHANGES_DATA *change;
  CHANGES_DATA *prev_change = NULL;
  FILE *fp;
  char *name;

  first_change = NULL;
  last_change = NULL;

  if ((fp = fopen (file, "r")) == NULL)
    {
      bug ("READ_CHANGES: File doesn't exist.", 0);
      return;
    }

  name = fread_string (fp);
  while (str_cmp (name, "End"))
    {
      change = alloc_mem (sizeof (file));
      change->name = str_dup (name);
      change->text = str_dup (fread_string (fp));
      change->next = NULL;
      change->prev = NULL;
      if (prev_change != NULL)
	{
	  prev_change->next = change;
	  change->prev = prev_change;
	}
      else
	first_change = change;
      prev_change = change;
      last_change = change;
      name = fread_string (fp);
    }
  fclose (fp);
}

void
add_change (CHAR_DATA * ch, char *file, char *string)
{
  CHANGES_DATA *change;
  CHANGES_DATA *new_change = NULL;
  FILE *fp;

  read_changes (file);
  if (!IS_IMMORTAL (ch))
    {
      send_to_char ("But you can't code!\n\r", ch);
      return;
    }
  if ((fp = fopen (file, "w")) == NULL)
    {
      bug ("ADD_CHANGE: File doesn't exist.", 0);
      return;
    }
  for (change = first_change;; change = change->next)
    {
      fprintf (fp, "%s~\n%s~\n", change->name, change->text);
      if (change->next == NULL)
	{
	  new_change = alloc_mem (sizeof (file));
	  change->next = new_change;
	  new_change->name = str_dup (ch->name);
	  new_change->text = str_dup (string);
	  new_change->next = NULL;
	  fprintf (fp, "%s~\n%s~\n", new_change->name, new_change->text);
	  new_change = change;
	  break;
	}
    }
  fprintf (fp, "End~\n");
  fclose (fp);
  return;
}

bool
has_fighttimer (CHAR_DATA * ch)
{
  if (IS_NPC (ch))
    return FALSE;
  if (IS_IMMORTAL (ch))
    return FALSE;
  if (ch->fight_timer > 0)
    {
      send_to_char ("Not while you have your fight timer set!\n\r", ch);
      return TRUE;
    }
  return FALSE;
}

int
col_str_len (char *txt)
{
  int pos, len;

  len = 0;
  for (pos = 0; txt[pos] != '\0'; pos++)
    {
      if (txt[pos] != '#')
	{
	  len++;
	  continue;
	}

      pos++;
      if (txt[pos] == '\0')
	return len;
      if (txt[pos] == '#' || txt[pos] == '-')
	len++;
    }

  return len;
}

void
cent_to_char (char *txt, CHAR_DATA * ch)
{
  int len, pos;
  char buf[MSL];

  len = (80 - col_str_len (txt)) / 2;
  for (pos = 0; pos < len; pos++)
    {
      buf[pos] = ' ';
    }
  buf[pos] = '\0';
  send_to_char (buf, ch);
  send_to_char (txt, ch);
  send_to_char ("\n\r", ch);
}

void
divide_to_char (CHAR_DATA * ch)
{
  send_to_char
    ("#L--------------------------------------------------------------------------------#n\n\r",
     ch);
}

void
line2 (CHAR_DATA * ch)
{
  int number;

  if (ch == NULL)
    return;
  for (number = 0; number < 80; number++)
    send_to_char ("*", ch);
  send_to_char ("\n\r", ch);
  return;
}

void
line (CHAR_DATA * ch)
{
  int number;

  if (ch == NULL)
    return;
  for (number = 0; number < 80; number++)
    send_to_char ("-", ch);
  send_to_char ("\n\r", ch);
  return;
}

void
add_affect (OBJ_DATA * obj, int apply, long value)
{
  AFFECT_DATA *paf;

  if (affect_free == NULL)
    {
      paf = alloc_perm (sizeof (*paf));
    }
  else
    {
      paf = affect_free;
      affect_free = affect_free->next;
    }

  paf->type = 0;
  paf->duration = -1;
  paf->location = apply;
  paf->modifier = value;
  paf->bitvector = 0;
  paf->next = obj->affected;
  obj->affected = paf;

}

void
do_afk (CHAR_DATA * ch, char *argument)
{
  char buf[MSL];

  if (IS_NPC (ch))
    return;
  if (ch->position == POS_FIGHTING)
    {
      send_to_char ("No way!  You are still fighting!\n\r", ch);
      return;
    }
  if (!IS_IMMORTAL (ch) && has_fighttimer (ch))
    return;

  if (IS_SET (ch->evenmore, EM_AFK))
    {
      send_to_char ("You are no longer AFK.\n\r", ch);

      if (strlen (ch->secafkmsg) > 2)
	{
	  sprintf (buf, "#R%s#n %s#n", ch->name, ch->secafkmsg);
	}

      else
	{
	  if (!str_cmp (ch->name, "Rysdan"))
	    sprintf (buf,
		     "#C%s#c has finished with his '#Rfunny and original#c' stuff and is back#n!#n",
		     ch->name);
	  else if (!str_cmp (ch->name, "Victoria"))
	    sprintf (buf,
		     "#C%s#c returns from her shower, all clean and sparkly!#n",
		     ch->name);
	  else if (!str_cmp (ch->name, "Nymph"))
	    sprintf (buf,
		     "#C%s#c has finished #7cleaning, washing clothes, washing dishes, cooking dinner or taking care of Corim's every wish#n and is back!#n",
		     ch->name);
	  else if (!str_cmp (ch->name, "Corim"))
	    sprintf (buf,
		     "#C%s#c is back, wonder what kind of #RDooms Day Device#c he invented this time.#n",
		     ch->name);
	  else if (!str_cmp (ch->name, "Tijer"))
	    sprintf (buf, "#C%s#c is back in desperate need of a #RKleenex#n",
		     ch->name);
	  else if (!str_cmp (ch->name, "Dachi"))
	    sprintf (buf, "#C%s#c has come back from #CWorshiping #RNymph#n",
		     ch->name);
	  else if (!str_cmp (ch->name, "Ixia"))
	    sprintf (buf,
		     "#C%s#c has finished pondering who to punish.  Aren't you glad it wasn't #Ryou#n?",
		     ch->name);
	  else if (IS_BUILDER (ch))
	    sprintf (buf, "#C%s#c is no longer #RAFK#c#n", ch->name);
	  else if (IS_IMMORTAL (ch))
	    sprintf (buf, "#C%s#c is no longer #RAFK#c!#n", ch->name);
	  else
	    sprintf (buf, "#C%s#c is no longer #RAFK#c!#n", ch->name);
	}

      if (!IS_NPC (ch) && IS_IMMORTAL (ch) && !IS_SET (ch->act, PLR_WIZINVIS))
	do_info (ch, buf);
      else if (!IS_IMMORTAL (ch))
	do_info (ch, buf);
      REMOVE_BIT (ch->evenmore, EM_AFK);
      return;
    }

  else if (!IS_SET (ch->evenmore, EM_AFK))
    {
      send_to_char ("#7You are now #RAFK#7.#n\n\r", ch);

      if (strlen (ch->afkmsg) > 2)
	{
	  sprintf (buf, "#R%s#n %s#n", ch->name, ch->afkmsg);
	}
      else
	{
	  if (!str_cmp (ch->name, "Rysdan"))
	    sprintf (buf,
		     "#C%s#c has left for some '#Rfunny and original#c' reason!#n",
		     ch->name);
	  else if (!str_cmp (ch->name, "Victoria"))
	    sprintf (buf, "#C%s#c has left to go shower.#n", ch->name);
	  else if (!str_cmp (ch->name, "Nymph"))
	    sprintf (buf,
		     "#C%s#c has left to go #RClean, wash clothes, wash dishes, cook dinner, #7or is taking care of Corims every wish!#n",
		     ch->name);
	  else if (!str_cmp (ch->name, "Corim"))
	    sprintf (buf,
		     "#C%s#c has left for his tool box, to create his next #RDooms Day Device#c!#n",
		     ch->name);
	  else if (!str_cmp (ch->name, "Ixia"))
	    sprintf (buf,
		     "#C%s#c has gone to ponder who to punish next, make sure it isn't #RYou!#n",
		     ch->name);
	  else if (!str_cmp (ch->name, "Dachi"))
	    sprintf (buf, "#C%s#c has gone to go #RWorship #CNymph!#n",
		     ch->name);
	  else if (!str_cmp (ch->name, "Tijer"))
	    sprintf (buf, "#C%s#c has gone to go #RPick #chis #CNose!#n",
		     ch->name);
	  else if (IS_BUILDER (ch))
	    sprintf (buf, "#C%s#c is now #RAFK#n", ch->name);
	  else if (IS_IMMORTAL (ch))
	    sprintf (buf, "#C%s#c is now #RAFK#c!#n", ch->name);
	  else
	    sprintf (buf, "#C%s#c is now #RAFK#c!#n", ch->name);
	}
      if (!IS_NPC (ch) && IS_IMMORTAL (ch) && !IS_SET (ch->act, PLR_WIZINVIS))
	do_info (ch, buf);
      else if (!IS_IMMORTAL (ch))
	do_info (ch, buf);
      SET_BIT (ch->evenmore, EM_AFK);
      waiting (ch, 25);
      return;
    }

  else
    return;

}

void
do_tokenquest (CHAR_DATA * ch, char *argument)
{
  int room = 0;
  char buf[MSL];
  int i;
  char arg1[MSL];
  char arg2[MSL];
  ROOM_INDEX_DATA *location;
  OBJ_DATA *obj;
  int value;
  int type = 0;
  int quest = 0;

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

  if (!is_number (arg2) || arg1[0] == '\0')
    {
      stc ("Syntax is TokenQuest <Exp/Credit/Crystal> <Number of Tokens>\n\r",
	   ch);
      return;
    }

  if (!str_cmp (arg1, "exp"))
    quest = 2;
  else if (!str_cmp (arg1, "credit"))
    quest = 1;
  else if (!str_cmp (arg1, "crystal"))
    quest = 3;
  else
    {
      stc ("Syntax is TokenQuest <Exp/Credit/Crystal> <Number of Tokens>\n\r",
	   ch);
      return;
    }

  if (atoi (arg2) > 20)
    {
      stc ("Only 20 allowed.\n\r", ch);
      return;
    }
  if (quest == 2)
    {
      sprintf (buf,
	       "#y%d#7 Exp tokens have been distributed randomly across the mud.#n",
	       atoi (arg2));
      type = ITEM_EXP;
    }
  else if (quest == 1)
    {
      sprintf (buf,
	       "#y%d#7 Credit tokens have been distributed randomly across the mud.#n",
	       atoi (arg2));
      type = ITEM_QUEST;
    }
  else if (quest == 3)
    {
      sprintf (buf,
	       "#y%d#7 Crystal tokens have been distributed randomly across the mud.#n",
	       atoi (arg2));
      type = ITEM_CRYSTAL;
    }
  else
    {
      stc ("Major bug here, tell Corim Immediatly.\n\r", ch);
      return;
    }
  do_info (ch, buf);
  for (i = 0; i < atoi (arg2); i++)
    {
      location = NULL;
      room = 0;
      while ((location = get_room_index (room)) == NULL)
	{
	  (int) room = number_range (0, 32000);
	}
      value = number_range (2500, 15000);
      if (quest == 2)
	value *= 250;
      if (quest == 3)
	value = number_range (20, 35);

      obj = create_object (get_obj_index (OBJ_VNUM_PROTOPLASM), value);
      obj->value[0] = value;
      obj->level = 1;
      obj->cost = obj->value[0] * 1000;
      obj->item_type = type;

      obj_to_room (obj, location);
      free_string (obj->name);
      if (quest == 2)
	{
	  obj->name = str_dup ("exp token");
	  sprintf (buf, "a %d point exp token", value);
	  free_string (obj->short_descr);
	  obj->short_descr = str_dup (buf);
	  sprintf (buf, "A %d point exp token lies on the floor.", value);
	  free_string (obj->description);
	  obj->description = str_dup (buf);
	}
      else if (quest == 3)
	{
	  obj->name = str_dup ("crystal token");
	  sprintf (buf, "a %d point crystal token", value);
	  free_string (obj->short_descr);
	  obj->short_descr = str_dup (buf);
	  sprintf (buf, "A %d point crystal token lies on the floor.", value);
	  free_string (obj->description);
	  obj->description = str_dup (buf);
	}
      else
	{
	  obj->name = str_dup ("credit token");
	  sprintf (buf, "a %d point credit token", value);
	  free_string (obj->short_descr);
	  obj->short_descr = str_dup (buf);
	  sprintf (buf, "A %d point credit token lies on the floor.", value);
	  free_string (obj->description);
	  obj->description = str_dup (buf);
	}
    }
  return;
}

void
shoutout (char *argument)
{
  DESCRIPTOR_DATA *d;

//    if (ch->level < NO_WATCH) do_watching(ch,buf);

  if (argument[0] == '\0')
    return;

  for (d = descriptor_list; d != NULL; d = d->next)
    {
      if (d->connected == CON_PLAYING)
	{
	  send_to_char (argument, d->character);
	  send_to_char ("\n\r", d->character);
	}
    }
  return;
}

void
do_fakequit (CHAR_DATA * ch, char *argument)
{
  char buf[MSL];

  if (IS_NPC (ch))
    return;
  if (!IS_IMMORTAL (ch))
    return;

  if (IS_SET (ch->act, PLR_WIZINVIS))
    {
      stc ("You are already invis!\n\r", ch);
      return;
    }

  if (strlen (ch->logoutmsg) > 2)
    {
      sprintf (buf, "#R%s#n %s#n", ch->name, ch->logoutmsg);
    }
  else
    {
      sprintf (buf, "#R%s#7 has left #cDreams #7of #0Demise.#n", ch->name);
    }
  do_info (ch, buf);
  SET_BIT (ch->act, PLR_WIZINVIS);
  send_to_char ("Tadaa! You have fake-quit and are now wizinvis.\n\r", ch);
  return;
}

Site Stats

Snippets: 1791
Codebases: 571