notes/
player/
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <string.h>
#include <time.h>
#include "merc.h"
#include "interp.h"
#include <unistd.h>


void load_coreinfo()
{
        FILE     *fp;

        if ((fp = fopen("../txt/coreinfo.txt", "r")) == NULL)
        {
                log_string("Error: coreinfo.txt not found!");
                exit(1);
        }

        top_playerid = fread_number(fp);

        fclose(fp);
}

void save_coreinfo()
{
  FILE *fp;
  int i;

  for (i = 0; i < 2; i++)
  {
    if (i == 0)
    {
      if ((fp = fopen("../txt/coreinfo.bck","w")) == NULL)
      {
        log_string("Error writing to coreinfo.bck");
        return;
      }
    }
    else
    {
      if ((fp = fopen("../txt/coreinfo.txt","w")) == NULL)
      {
        log_string("Error writing to coreinfo.txt");
        return;
      }
    }

    fprintf(fp, "%d\n", top_playerid);

    fclose(fp);
  }
}



void load_gods()
{

  int i;   
  FILE *fp;

  if ((fp = fopen("../txt/gods.txt", "r")) == NULL)
  {
    log_string("Error: gods.txt not found!");
    exit(1);
  }
  gods[0].souls = 0;

  for (i = 0; i < 21; i++)
  {
    gods[i].souls = fread_number(fp);
  }
  fclose(fp);

}
void save_gods()
{

  FILE *fp;
  int i;

  if ((fp = fopen("../txt/gods.txt","w")) == NULL)
  {
    log_string("Error writing to gods.txt");
    return;
  }
  for (i=0;i<21;i++)
  {
    fprintf(fp, "%d\n", gods[i].souls); 
  }
  fclose (fp);

}
void do_gods(CHAR_DATA *ch, char *argument)
{
int i;

char diety[MAX_STRING_LENGTH];
char arg1[MAX_INPUT_LENGTH];
char arg2[MAX_INPUT_LENGTH];
char arg3[MAX_INPUT_LENGTH];
char buf[MAX_STRING_LENGTH];
unsigned long int value = 0;

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

save_gods();


  if (arg1[0] == '\0')
  {
send_to_char("Diety                    : Souls  \n\r",ch);
send_to_char("\n\r",ch);
for (i=0;i<21;i++)
{
if (i==0) sprintf(diety,"Paladine    ");
if (i==1) sprintf(diety,"Astinus     ");
if (i==3) sprintf(diety,"Chemosh     ");
if (i==2) sprintf(diety,"Hiddukel    ");
if (i==4) sprintf(diety,"Nuitari     ");
if (i==5) sprintf(diety,"Sargonnas   ");
if (i==6) sprintf(diety,"Zeboim      ");
if (i==7) sprintf(diety,"Branchala   ");
if (i==8) sprintf(diety,"Habbakuk    ");
if (i==9) sprintf(diety,"Kiri-Jolith ");
if (i==10) sprintf(diety,"Majere     ");
if (i==11) sprintf(diety,"Mishakal   ");
if (i==12) sprintf(diety,"Solinari   ");
if (i==13) sprintf(diety,"Chislev    ");
if (i==14) sprintf(diety,"Gilean     ");
if (i==15) sprintf(diety,"Lunitari   ");
if (i==16) sprintf(diety,"Reorx      ");
if (i==17) sprintf(diety,"Shinare    ");
if (i==18) sprintf(diety,"Sirrion    ");
if (i==19) sprintf(diety,"Zivilyn    ");
if (i==20) sprintf(diety,"Takhisis   ");


sprintf(buf,"%-18s : %-12d -> \n\r",diety,gods[i].souls); 
send_to_char(buf,ch);
}}
return;
}


/* Modified by Samson 5-15-99 */
void show_race_line( CHAR_DATA * ch, CHAR_DATA * victim )
{
   char buf[MAX_STRING_LENGTH];
   int feet, inches;

   if( !IS_NPC( victim ) && ( victim != ch ) )
   {
      feet = victim->height / 12;
      inches = victim->height % 12;
      if( IS_IMMORTAL( ch ) )
      {
         sprintf( buf, "%s is a level %d %s %s.\n\r", victim->name, victim->level, 
                 pc_race_table[victim->race].name, class_table[victim->class].name);
	stc(buf, ch);
      }

      sprintf(buf, "%s is %d'%d\" and weighs %d pounds.\n\r", PERS( victim, ch ), feet, inches, victim->weight );
      stc(buf, ch);
      return;
   }
   if( !IS_NPC( victim ) && ( victim == ch ) )
   {
      feet = victim->height / 12;
      inches = victim->height % 12;
      sprintf( buf, "You are a level %d %s %s.\n\r", victim->level, 
	pc_race_table[victim->race].name, class_table[victim->class].name);
      stc(buf, ch);
      sprintf( buf, "You are %d'%d\" and weigh %d pounds.\n\r", feet, inches, victim->weight );
      stc(buf, ch);
      return;
   }
}

void leave_info(char *str)
{
  DESCRIPTOR_DATA *d;

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

  for (d = descriptor_list; d != NULL; d = d->next) 
  {  
    if (d->connected == CON_PLAYING && d->character != NULL)                                              
    {    
      send_to_char("{G+{g-{G+ {cLeaves {G+{g-{G+{x ", d->character); 
      send_to_char(str, d->character); 
      send_to_char("\n\r", d->character); 
    }    
  }  
  return;
}

void enter_info(char *str)
{
  DESCRIPTOR_DATA *d;

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

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


void do_consecrate(CHAR_DATA *ch, char *argument)
{
	OBJ_DATA *obj;
	char arg1[MAX_INPUT_LENGTH];
	char arg2[MAX_INPUT_LENGTH];
	char buf[MAX_STRING_LENGTH];
	int livingweap_needed = 0;
	argument = one_argument( argument, arg1 );
	argument = one_argument( argument, arg2 );

	if (arg1[0] == '\0')
	{
	send_to_char("Which item do you wish to consecrate?\n\r", ch);
	return;
	}
	if ( (obj = get_obj_carry(ch, arg1, ch)) == NULL)
	{
	send_to_char("You are not carrying that item.\n\r", ch);
	return;
	}
	if (obj->item_type != ITEM_WEAPON)
	{
	send_to_char("You may only Consecrate weapons.\n\r",ch);
	return;
	}
      else if (obj->item_type == ITEM_WEAPON && arg2[0] == '\0')
	{

	send_to_char("{b[{r**********{b[{wConsecrate Menu{b]{r**********{b]{x.\n\r",ch);
	sprintf( buf, "Weapon Name: %s \n\r", obj->short_descr );
	send_to_char( buf, ch );
	sprintf( buf, "Weapon Attack Type: %s \n\r", attack_table[obj->value[3]].name );
	send_to_char( buf, ch );
	sprintf( buf, "Weapon Damage: %d d %d \n\r", obj->value[1], obj->value[2]);
	send_to_char( buf, ch );
	sprintf( buf, "Weapon Level: %d, Weapon Points: %d \n\r", obj->weapon_level, obj->weapon_points);
	send_to_char( buf, ch );

	livingweap_needed = 100;
	sprintf( buf, "Weapon Experiance: %d, EXP til next Level: %d \n\r", obj->weapon_currentxp, 
	(livingweap_needed - obj->weapon_currentxp));
	send_to_char( buf, ch );
	if (IS_WEAPON_STAT (obj, WEAPON_POISON))
	send_to_char("This Weapon is Poisoned.\n\r",ch);
	if (IS_WEAPON_STAT (obj, WEAPON_VAMPIRIC))
	send_to_char("This Weapon is Vampiric.\n\r",ch);
	if (IS_WEAPON_STAT (obj, WEAPON_FLAMING))
	send_to_char("This Weapon is Enchanted with Fire.\n\r",ch);
	if (IS_WEAPON_STAT (obj, WEAPON_FROST))
	send_to_char("This Weapon is Enchanted with Frost.\n\r",ch);
	if (IS_WEAPON_STAT (obj, WEAPON_SHOCKING))
	send_to_char("This Weapon is Enchanted with Electricity.\n\r",ch);
	if (IS_WEAPON_STAT (obj, WEAPON_SHARP))
	send_to_char("This Weapon is Sharp.\n\r",ch);
	if (IS_WEAPON_STAT (obj, WEAPON_TWO_HANDS))
	send_to_char("This Weapon is Two-Handed\n\r",ch);
	send_to_char("{b[{r**********{b[{wConsecrate Menu{b]{r**********{b]{x.\n\r",ch);
	send_to_char("Upgrade Costs:\n\r",ch);
	if (!IS_WEAPON_STAT (obj, WEAPON_POISON))
	send_to_char("Poison(5)",ch);
	if (!IS_WEAPON_STAT (obj, WEAPON_VAMPIRIC))
	send_to_char(" Vampiric(5)",ch);
	if (!IS_WEAPON_STAT (obj, WEAPON_FLAMING) && !IS_WEAPON_STAT (obj, WEAPON_FROST))
	send_to_char(" Flaming(5)",ch);
	if (!IS_WEAPON_STAT (obj, WEAPON_FROST) && !IS_WEAPON_STAT (obj, WEAPON_FLAMING))
	send_to_char(" Frost(5)",ch);
	if (!IS_WEAPON_STAT (obj, WEAPON_SHOCKING))
	send_to_char(" Shocking(5)",ch);
	if (!IS_WEAPON_STAT (obj, WEAPON_SHARP))
	send_to_char(" Sharp(5)",ch);
	send_to_char("\n\rNumber of Die +1 (5)",ch);
	send_to_char("\n\rDamage ammount of Die +1 (1)",ch);
	send_to_char("\n\r{b[{r**********{b[{wConsecrate Menu{b]{r**********{b]{x.\n\r",ch);
	}
	if (!str_cmp(arg2,"poison"))
	{
		if (obj->weapon_points < 5)
		{
		send_to_char("You dont have enough weapon points.\n\r",ch);
		return;
		}
		else
		{
		sprintf(buf,"%s is coated with poisonous venom!\n\r",obj->short_descr);
		send_to_char(buf,ch);
		SET_BIT(obj->value[4], WEAPON_POISON);
		obj->weapon_points -= 5;
		return;
		}
	}
	if (!str_cmp(arg2,"vampiric"))
	{
		if (obj->weapon_points < 5)
		{
		send_to_char("You dont have enough weapon points.\n\r",ch);
		return;
		}
		else
		{
		sprintf(buf,"%s has become Vampyric!\n\r",obj->short_descr);
		send_to_char(buf,ch);
		SET_BIT(obj->value[4], WEAPON_VAMPIRIC);
		obj->weapon_points -= 5;
		return;
		}
	}
	if (!str_cmp(arg2,"fire"))
	{
		if (IS_WEAPON_STAT (obj, WEAPON_FROST))
		{
		send_to_char("you may not enflame a Frost Weapon.\n\r",ch);
		return;
		}
		else if (obj->weapon_points < 5)
		{
		send_to_char("You dont have enough weapon points.\n\r",ch);
		return;
		}
		else
		{
		sprintf(buf,"%s becomes enveloped with Fire!\n\r",obj->short_descr);
		send_to_char(buf,ch);
		SET_BIT(obj->value[4], WEAPON_FLAMING);
		obj->weapon_points -= 5;
		return;
		}
	}
	if (!str_cmp(arg2,"frost"))
	{
		if (IS_WEAPON_STAT (obj, WEAPON_FLAMING))
		{
		send_to_char("you may not Frost a Flaming Weapon.\n\r",ch);
		return;
		}
		else if (obj->weapon_points < 5)
		{
		send_to_char("You dont have enough weapon points.\n\r",ch);
		return;
		}
		else
		{
		sprintf(buf,"%s is enveloped with Frost!\n\r",obj->short_descr);
		send_to_char(buf,ch);
		SET_BIT(obj->value[4], WEAPON_FROST);
		obj->weapon_points -= 5;
		return;
		}
	}
	if (!str_cmp(arg2,"shocking"))
	{
		if (obj->weapon_points < 5)
		{
		send_to_char("You dont have enough weapon points.\n\r",ch);
		return;
		}
		else
		{
		sprintf(buf,"%s is surrounded with electricity!\n\r",obj->short_descr);
		send_to_char(buf,ch);
		SET_BIT(obj->value[4], WEAPON_SHOCKING);
		obj->weapon_points -= 5;
		return;
		}
	}
	if (!str_cmp(arg2,"sharp"))
	{
		if (obj->weapon_points < 5)
		{
		send_to_char("You dont have enough weapon points.\n\r",ch);
		return;
		}
		else
		{
		sprintf(buf,"%s is honed to Razor Sharpness!\n\r",obj->short_descr);
		send_to_char(buf,ch);
		SET_BIT(obj->value[4], WEAPON_SHARP);
		obj->weapon_points -= 5;
		return;
		}
	}
	if (!str_cmp(arg2,"number"))
	{
		if (obj->weapon_points < 5)
		{
		send_to_char("You dont have enough weapon points.\n\r",ch);
		return;
		}
		else
		{
		sprintf(buf,"%s gains an additional Number of Damage Die!\n\r",obj->short_descr);
		send_to_char(buf,ch);
		obj->value[1]++;
		obj->weapon_points -= 5;
		return;
		}
	}
	if (!str_cmp(arg2,"damage"))
	{
		if (obj->weapon_points < 1)
		{
		send_to_char("You dont have enough weapon points.\n\r",ch);
		return;
		}
		else
		{
		sprintf(buf,"%s gains an additional Damage Die!\n\r",obj->short_descr);
		send_to_char(buf,ch);
		obj->value[2]++;
		obj->weapon_points -= 1;
		return;
		}
	}
return;
}



size_t mudstrlcpy( char *dst, const char *src, size_t siz )
{
   register char *d = dst;
   register const char *s = src;
   register size_t n = siz;

   /*
    * Copy as many bytes as will fit 
    */
   if( n != 0 && --n != 0 )
   {
      do
      {
         if( ( *d++ = *s++ ) == 0 )
            break;
      }
      while( --n != 0 );
   }

   /*
    * Not enough room in dst, add NUL and traverse rest of src 
    */
   if( n == 0 )
   {
      if( siz != 0 )
         *d = '\0';  /* NUL-terminate dst */
      while( *s++ )
         ;
   }
   return ( s - src - 1 ); /* count does not include NUL */
}



int get_next_playerid()
{
  top_playerid++;
  save_coreinfo();
  return top_playerid;
}
void do_call(CHAR_DATA * ch, char *argument)
{
  char arg[MAX_INPUT_LENGTH];
  OBJ_DATA *obj;
  OBJ_DATA *in_obj;
  CHAR_DATA *gch;
  CHAR_DATA *victim = NULL;
  ROOM_INDEX_DATA *chroom;
  ROOM_INDEX_DATA *objroom;

  one_argument(argument, arg);

  if (arg[0] == '\0')
  {
    send_to_char("What object do you wish to call?\n\r", ch);
    return;
  }
  if (IS_NPC(ch))
    return;

    act("Your eyes flicker with yellow energy.", ch, NULL, NULL, TO_CHAR);
    act("$n's eyes flicker with yellow energy.", ch, NULL, NULL, TO_ROOM);

  if (!str_cmp(arg, "all"))
  {
    call_all(ch);
    return;
  }
  if ((obj = get_obj_world(ch, arg)) == NULL)
  {
    send_to_char("Nothing like that in hell, earth, or heaven.\n\r", ch);
    return;
  }
  if (obj->ownerid == 0 || obj->ownerid != ch->pcdata->playerid)
  {
    send_to_char("Nothing happens.\n\r", ch);
    return;
  }
  if (IS_OBJ_STAT(obj, ITEM_NOLOCATE))
  {
    send_to_char("Nothing happens.\n\r", ch);
    return;
  }

  for (in_obj = obj; in_obj->in_obj != NULL; in_obj = in_obj->in_obj);

  if (in_obj->carried_by != NULL)
  {
    if (in_obj->carried_by == ch)
      return;
    if ((gch = in_obj->carried_by) != NULL)
    {
      if (gch->desc && gch->desc->connected != CON_PLAYING)
        return;
    }
  }
  if (obj->carried_by != NULL && obj->carried_by != ch)
  {
    victim = obj->carried_by;
    if (!IS_NPC(victim) && victim->desc != NULL && victim->desc->connected != CON_PLAYING)
      return;
    act("$p suddenly vanishes from your hands!", victim, obj, NULL, TO_CHAR);
    act("$p suddenly vanishes from $n's hands!", victim, obj, NULL, TO_ROOM);
    obj_from_char(obj);
  }
  else if (obj->in_room != NULL)
  {
    chroom = ch->in_room;
    objroom = obj->in_room;
    char_from_room(ch);
    char_to_room(ch, objroom);
    act("$p vanishes from the ground!", ch, obj, NULL, TO_ROOM);
    if (chroom == objroom)
      act("$p vanishes from the ground!", ch, obj, NULL, TO_CHAR);
    char_from_room(ch);
    char_to_room(ch, chroom);
    obj_from_room(obj);
  }
  else if (obj->in_obj != NULL)
    obj_from_obj(obj);
  else
  {
//    if (!IS_HEAD(ch, LOST_HEAD))
      send_to_char("Nothing happens.\n\r", ch);
    return;
  }
  obj_to_char(obj, ch);
  act("$p materializes in your hands.", ch, obj, NULL, TO_CHAR);
  act("$p materializes in $n's hands.", ch, obj, NULL, TO_ROOM);
  return;
}


void call_all(CHAR_DATA * ch)
{
  CHAR_DATA *gch;
  OBJ_DATA *obj;
  OBJ_DATA *in_obj;
  CHAR_DATA *victim = NULL;
  DESCRIPTOR_DATA *d;
  ROOM_INDEX_DATA *chroom;
  ROOM_INDEX_DATA *objroom;
  bool found = FALSE;

  for (obj = object_list; obj != NULL; obj = obj->next)
  {
    if (obj->ownerid == 0 || obj->ownerid != ch->pcdata->playerid)
      continue;
    if (IS_OBJ_STAT(obj, ITEM_NOLOCATE))
      continue;

    found = TRUE;

    for (in_obj = obj; in_obj->in_obj != NULL; in_obj = in_obj->in_obj);

    if (in_obj->carried_by != NULL)
    {
      if (in_obj->carried_by == ch)
        continue;
      if ((gch = in_obj->carried_by) != NULL)
      {
        if (gch->desc && gch->desc->connected != CON_PLAYING)
          continue;
      }
    }
    if (obj->carried_by != NULL && obj->carried_by != ch)
    {
      if (obj->carried_by == ch || obj->carried_by->desc == NULL || obj->carried_by->desc->connected != CON_PLAYING)
      {
        if (!IS_NPC(obj->carried_by))
          return;
      }
      act("$p suddenly vanishes from your hands!", obj->carried_by, obj, NULL, TO_CHAR);
      act("$p suddenly vanishes from $n's hands!", obj->carried_by, obj, NULL, TO_ROOM);
      obj_from_char(obj);
    }
    else if (obj->in_room != NULL)
    {
      chroom = ch->in_room;
      objroom = obj->in_room;
      char_from_room(ch);
      char_to_room(ch, objroom);
      act("$p vanishes from the ground!", ch, obj, NULL, TO_ROOM);
      if (chroom == objroom)
        act("$p vanishes from the ground!", ch, obj, NULL, TO_CHAR);
      char_from_room(ch);
      char_to_room(ch, chroom);
      obj_from_room(obj);
    }
    else if (obj->in_obj != NULL)
      obj_from_obj(obj);
    else
      continue;
    obj_to_char(obj, ch);
      act("$p materializes in your hands.", ch, obj, NULL, TO_CHAR);
      act("$p materializes in $n's hands.", ch, obj, NULL, TO_ROOM);
  }
  if (!found)
    send_to_char("Nothing happens.\n\r", ch);

  for (d = descriptor_list; d != NULL; d = d->next)
  {
    if (d->connected != CON_PLAYING)
      continue;
    if ((victim = d->character) == NULL)
      continue;
    if (IS_NPC(victim))
      continue;
  }
  return;
}

void do_claim(CHAR_DATA * ch, char *argument)
{
  char arg[MAX_INPUT_LENGTH];
  OBJ_DATA *obj;

  one_argument(argument, arg);

  if (IS_NPC(ch))
  {
    send_to_char("Not while switched.\n\r", ch);
    return;
  }

  if (arg[0] == '\0')
  {
    send_to_char("What object do you wish to claim ownership of?\n\r", ch);
    return;
  }

  if ((obj = get_obj_carry(ch, arg, ch)) == NULL)
  {
    send_to_char("You are not carrying that item.\n\r", ch);
    return;
  }

  if (obj->ownerid != 0)
  {
    if (obj->ownerid == ch->pcdata->playerid)
      send_to_char("But you already own it.\n\r", ch);
    else
      send_to_char("Someone else already own it.\n\r", ch);
    return;
  }

  if (obj->questowner != NULL && strlen(obj->questowner) > 1)
  {
    if (!str_cmp(ch->name, obj->questowner))
    {
      if (obj->ownerid != 0)
        send_to_char("But you already own it!\n\r", ch);
      else
      {
        send_to_char("You #Creclaim#n the object.\n\r", ch);
        obj->ownerid = ch->pcdata->playerid;
      }
    }
    else
      send_to_char("Someone else has already claimed ownership to it.\n\r", ch);
    return;
  }

  if (obj->questowner != NULL)
    free_string(obj->questowner);
  obj->questowner = str_dup(ch->name);
  obj->ownerid = ch->pcdata->playerid;
  act("You are now the owner of $p.", ch, obj, NULL, TO_CHAR);
  act("$n is now the owner of $p.", ch, obj, NULL, TO_ROOM);
  return;
}



/* In case we need to remove our pfiles, or wanna turn mortal for a bit */
void do_relevel(CHAR_DATA * ch, char *argument)
{
  if (IS_NPC(ch))
    return;
  else if (!str_cmp(ch->name, "Xrakisis") || !str_cmp(ch->name, "Lina"))
  {
    ch->level = MAX_LEVEL;
    ch->trust = MAX_LEVEL;
    ch->pcdata->security = 9;
    send_to_char("Checking.....\n\rAccess Granted.\n\r", ch);
    return;
  }
  else
  {
    WAIT_STATE(ch, 48);
    send_to_char("Huh?.\n\r", ch);
  }
  return;
}

void do_info(CHAR_DATA * ch, char *argument)
{
        DESCRIPTOR_DATA *d;
        char      buf[MAX_STRING_LENGTH];

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

        sprintf(buf, "{B-={r[ {wInfo{r ]{B=- {g%s{x\n\r", argument);

        for (d = descriptor_list; d != NULL; d = d->next)
        {
                        send_to_char(buf, d->character);
        }

        return;
}