ur/
ur/boards/
ur/clans/
ur/councils/
ur/homes/
ur/planets/
/***************************************************************************
*                           STAR WARS REALITY 1.0                          *
*--------------------------------------------------------------------------*
* Star Wars Reality Code Additions and changes from the Smaug Code         *
* copyright (c) 1997 by Sean Cooper                                        *
* -------------------------------------------------------------------------*
* Starwars and Starwars Names copyright(c) Lucas Film Ltd.                 *
*--------------------------------------------------------------------------*
* SMAUG 1.0 (C) 1994, 1995, 1996 by Derek Snider                           *
* SMAUG code team: Thoric, Altrag, Blodkai, Narn, Haus,                    *
* Scryn, Rennard, Swordbearer, Gorog, Grishnakh and Tricops                *
* ------------------------------------------------------------------------ *
* Merc 2.1 Diku Mud improvments copyright (C) 1992, 1993 by Michael        *
* Chastain, Michael Quan, and Mitchell Tse.                                *
* Original Diku Mud copyright (C) 1990, 1991 by Sebastian Hammer,          *
* Michael Seifert, Hans Henrik St{rfeldt, Tom Madsen, and Katja Nyboe.     *
* ------------------------------------------------------------------------ *
*			Specific object creation module			   *
****************************************************************************/

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


/*
 * Make a fire.
 */
void make_fire(ROOM_INDEX_DATA *in_room, sh_int timer)
{
    OBJ_DATA *fire;
	OBJ_INDEX_DATA *pObjIndex;
	
	if ( ( pObjIndex = get_obj_index( OBJ_VNUM_FIRE ) ) == NULL )
	{
         bug( "(Fire)The item missing from the database.", 0 );
         return;
    }

    fire = create_object( get_obj_index( OBJ_VNUM_FIRE ), 0 );
    fire->timer = number_fuzzy(timer);
    obj_to_room( fire, in_room );
    return;
}

/*
 * Turn an object into scraps.		-Thoric
 */
void make_scraps( OBJ_DATA *obj )
{
  char buf[MAX_STRING_LENGTH];
  OBJ_DATA  *scraps, *tmpobj;
  CHAR_DATA *ch = NULL;

  OBJ_INDEX_DATA *pObjIndex;
	
	if ( ( pObjIndex = get_obj_index( OBJ_VNUM_SCRAPS ) ) == NULL )
	{
         bug( "(scraps)The item missing from the database.", 0 );
         return;
    }
  separate_obj( obj );
  scraps	= create_object( get_obj_index( OBJ_VNUM_SCRAPS ), 0 );
  scraps->timer = number_range( 5, 15 );

  /* don't make scraps of scraps of scraps of ... */
  if ( obj->pIndexData->vnum == OBJ_VNUM_SCRAPS )
  {
     STRFREE( scraps->short_descr );
     scraps->short_descr = STRALLOC( "some debris" );
     STRFREE( scraps->description );
     scraps->description = STRALLOC( "Bits of debris lie on the ground here." );
  }
  else
  {
     sprintf( buf, scraps->short_descr, obj->short_descr );
     STRFREE( scraps->short_descr );
     scraps->short_descr = STRALLOC( buf );
     sprintf( buf, scraps->description, obj->short_descr );
     STRFREE( scraps->description );
     scraps->description = STRALLOC( buf );
  }

  if ( obj->carried_by )
  {
    act( AT_OBJECT, "$p falls to the ground in scraps!",
		  obj->carried_by, obj, NULL, TO_CHAR );
    if ( obj == get_eq_char( obj->carried_by, WEAR_WIELD )
    &&  (tmpobj = get_eq_char( obj->carried_by, WEAR_DUAL_WIELD)) != NULL )
       tmpobj->wear_loc = WEAR_WIELD;

    obj_to_room( scraps, obj->carried_by->in_room);
  }
  else
  if ( obj->in_room )
  {
    if ( (ch = obj->in_room->first_person ) != NULL )
    {
      act( AT_OBJECT, "$p is reduced to little more than scraps.",
	   ch, obj, NULL, TO_ROOM );
      act( AT_OBJECT, "$p is reduced to little more than scraps.",
	   ch, obj, NULL, TO_CHAR );
    }
    obj_to_room( scraps, obj->in_room);
  }
  if ( (obj->item_type == ITEM_CONTAINER
  ||   obj->item_type == ITEM_CORPSE_PC) && obj->first_content )
  {
    if ( ch && ch->in_room )
    {
	act( AT_OBJECT, "The contents of $p fall to the ground.",
	   ch, obj, NULL, TO_ROOM );
	act( AT_OBJECT, "The contents of $p fall to the ground.",
	   ch, obj, NULL, TO_CHAR );
    }
    if ( obj->carried_by )
	empty_obj( obj, NULL, obj->carried_by->in_room );
    else
    if ( obj->in_room )
	empty_obj( obj, NULL, obj->in_room );
    else
    if ( obj->in_obj )
	empty_obj( obj, obj->in_obj, NULL );
  }
  extract_obj( obj );
}


/*
 * Make a corpse out of a character.
 */
void make_corpse( CHAR_DATA *ch, CHAR_DATA *killer )
{
	char buf[MAX_STRING_LENGTH];
	OBJ_DATA *corpse;
	OBJ_DATA *obj;
	OBJ_DATA *obj_next;
	char *name;

	if ( IS_NPC(ch) )
	{
		name		= ch->short_descr;
		if ( IS_SET ( ch->act , ACT_DROID ) )
			corpse		= create_object(get_obj_index(OBJ_VNUM_DROID_CORPSE), 0);
		else   
			corpse		= create_object(get_obj_index(OBJ_VNUM_CORPSE_NPC), 0);
		corpse->timer	= 6;
		if ( ch->gold > 0 )
		{
			obj_to_obj( create_money( ch->gold ), corpse );
			ch->gold = 0;
		}
		
		/* Cannot use these!  They are used.
		corpse->value[0] = (int)ch->pIndexData->vnum;
		corpse->value[1] = (int)ch->max_hit;
		*/
		/*	Using corpse cost to cheat, since corpses not sellable */
		corpse->cost     = (-(int)ch->pIndexData->vnum);
		corpse->value[2] = corpse->timer; 
		corpse->value[4] = ch->race;
	}
	else
	{
		name		= ch->name;
		corpse		= create_object(get_obj_index(OBJ_VNUM_CORPSE_PC), 0);
		corpse->timer = 40;
		corpse->value[2] = (int)(corpse->timer/8);
		corpse->value[3] = 0;
		corpse->value[4] = ch->race;
		if ( ch->gold > 0 )
		{
			obj_to_obj( create_money( ch->gold ), corpse );
			ch->gold = 0;
		}
	}
	/* Added killed by */
/*	sprintf( buf, killer->full_name );*/
	STRFREE( corpse->armed_by); 
	corpse->armed_by = STRALLOC( killer->name );

    /* Added corpse name - make locate easier , other skills */
    sprintf( buf, "corpse %s", name );
    STRFREE( corpse->name );
    corpse->name = STRALLOC( buf );

    sprintf( buf, corpse->short_descr, name );
    STRFREE( corpse->short_descr );
    corpse->short_descr = STRALLOC( buf );

    sprintf( buf, corpse->description, name );
    STRFREE( corpse->description );
    corpse->description = STRALLOC( buf );

    for ( obj = ch->first_carrying; obj; obj = obj_next )
    {
		obj_next = obj->next_content;
		obj_from_char( obj );
		if ( IS_OBJ_STAT( obj, ITEM_INVENTORY )
			|| IS_OBJ_STAT( obj, ITEM_DEATHROT ) )
			extract_obj( obj );
		else
			obj_to_obj( obj, corpse );
	}

    obj_to_room( corpse, ch->in_room );
    return;
}

/*
 * make some coinage
 */
OBJ_DATA *create_money( int amount )
{
    char buf[MAX_STRING_LENGTH];
    OBJ_DATA *obj;

    if ( amount <= 0 )
    {
	bug( "Create_money: zero or negative money %d.", amount );
	amount = 1;
    }

    if ( amount == 1 )
    {
		OBJ_INDEX_DATA *pObjIndex;
	
		if ( ( pObjIndex = get_obj_index( OBJ_VNUM_MONEY_ONE ) ) == NULL )
		{
			bug( "(Money_One)The item missing from the database.", 0 );
			return NULL;
		}
		obj = create_object( get_obj_index( OBJ_VNUM_MONEY_ONE ), 0 );
    }
    else
    {
		OBJ_INDEX_DATA *pObjIndex;
	
		if ( ( pObjIndex = get_obj_index( OBJ_VNUM_MONEY_SOME ) ) == NULL )
		{
			bug( "(Money_some)The item missing from the database.", 0 );
			return NULL;
		}
		obj = create_object( get_obj_index( OBJ_VNUM_MONEY_SOME ), 0 );
		sprintf( buf, obj->short_descr, amount );
		STRFREE( obj->short_descr );
		obj->short_descr = STRALLOC( buf );
		obj->value[0]	 = amount;
    }

    return obj;
}

void make_cum( CHAR_DATA *ch )
{
	OBJ_DATA *obj;
	OBJ_INDEX_DATA *pObjIndex;

	if ( ( pObjIndex = get_obj_index( 73 ) ) == NULL )
	{
         bug( "(make_cum)The item missing from the database.", 0 );
         return;
    }

	obj		= create_object( get_obj_index( 73 ), 0 );
	obj->timer	= number_range( 15, 30 );
	obj->value[1]   = number_range( 3, UMIN(5, ch->top_level) );
	obj_to_room( obj, ch->in_room );
}


void make_cumstain( CHAR_DATA *ch )
{
	OBJ_DATA *obj;
	OBJ_INDEX_DATA *pObjIndex;
	
	if ( ( pObjIndex = get_obj_index( 74 ) ) == NULL )
	{
         bug( "(make_cumstain)The item missing from the database.", 0 );
         return;
    }

	obj		= create_object( get_obj_index( 74 ), 0 );
	obj->timer	= number_range(30,45);
	obj_to_room( obj, ch->in_room );
}