Example #1
0
void make_corpse(struct char_data * ch)
{
  struct obj_data *corpse, *o;
  struct obj_data *money;
  int i;

  corpse = create_obj();

  corpse->item_number = NOTHING;
  IN_ROOM(corpse) = NOWHERE;
  corpse->name = str_dup("corpse");

  sprintf(buf2, "The corpse of %s is lying here.", GET_NAME(ch));
  corpse->description = str_dup(buf2);

  sprintf(buf2, "the corpse of %s", GET_NAME(ch));
  corpse->short_description = str_dup(buf2);

  GET_OBJ_TYPE(corpse) = ITEM_CONTAINER;
  GET_OBJ_WEAR(corpse) = ITEM_WEAR_TAKE;
  GET_OBJ_EXTRA(corpse) = ITEM_NODONATE;
  GET_OBJ_VAL(corpse, 0) = 0;	/* You can't store stuff in a corpse */
  GET_OBJ_VAL(corpse, 3) = 1;	/* corpse identifier */
  GET_OBJ_WEIGHT(corpse) = GET_WEIGHT(ch) + IS_CARRYING_W(ch);
  GET_OBJ_RENT(corpse) = 100000;
  if (IS_NPC(ch))
    GET_OBJ_TIMER(corpse) = max_npc_corpse_time;
  else
    GET_OBJ_TIMER(corpse) = max_pc_corpse_time;

  /* transfer character's inventory to the corpse */
  corpse->contains = ch->carrying;
  for (o = corpse->contains; o != NULL; o = o->next_content)
    o->in_obj = corpse;
  object_list_new_owner(corpse, NULL);

  /* transfer character's equipment to the corpse */
  for (i = 0; i < NUM_WEARS; i++)
    if (GET_EQ(ch, i)) {
      remove_otrigger(GET_EQ(ch, i), ch);
      obj_to_obj(unequip_char(ch, i), corpse);
    }

  /* transfer gold */
  if (GET_GOLD(ch) > 0) {
    /* following 'if' clause added to fix gold duplication loophole */
    if (IS_NPC(ch) || (!IS_NPC(ch) && ch->desc)) {
      money = create_money(GET_GOLD(ch));
      obj_to_obj(money, corpse);
    }
    GET_GOLD(ch) = 0;
  }
  ch->carrying = NULL;
  IS_CARRYING_N(ch) = 0;
  IS_CARRYING_W(ch) = 0;

  obj_to_room(corpse, IN_ROOM(ch));
}
Example #2
0
void weight_change_object(struct obj_data *obj, int weight)
{
	struct obj_data *tmp_obj;
	struct char_data *tmp_ch;

	if (obj->in_room != NOWHERE) {
		GET_OBJ_WEIGHT(obj) += weight;
	} else if (tmp_ch = obj->carried_by) {
		obj_from_char(obj);
		GET_OBJ_WEIGHT(obj) += weight;
		obj_to_char(obj, tmp_ch);
	} else if (tmp_obj = obj->in_obj) {
		obj_from_obj(obj);
		GET_OBJ_WEIGHT(obj) += weight;
		obj_to_obj(obj, tmp_obj);
	} else {
		log("Unknown attempt to subtract weight from an object.");
	}
}
void handle_waterwheel_destruction(OBJ_DATA & obj)
{
    // Verify a room
    ROOM_INDEX_DATA * room(get_room_for_obj(obj));
    if (room == NULL)
        return;

    // Load up the remains and transfer the contents
    OBJ_DATA * remains(create_object(get_obj_index(OBJ_VNUM_WATERWHEEL_REMAINS), 0));
    remains->level = obj.level;

    for (OBJ_DATA * item(obj.contains); item != NULL; item = obj.contains)
    {
        obj_from_obj(item);
        obj_to_obj(item, remains);
    }

    obj_to_room(remains, room);
}
Example #4
0
//
// try performing an object load, based on the reset data we have
bool try_reset_load_object(RESET_DATA *reset, void *initiator, 
			   int initiator_type, const char *locale) {
  const char *fullkey = get_fullkey_relative(resetGetArg(reset), locale);
  PROTO_DATA   *proto = worldGetType(gameworld, "oproto", fullkey);
  // if there's no prototype, break out
  if(proto == NULL || protoIsAbstract(proto))
    return FALSE;

  // see if we're already at our max
  if(resetGetMax(reset) != 0 && 
     count_objs(NULL, object_list, NULL, fullkey, FALSE) >= 
     resetGetMax(reset))
    return FALSE;
  if(initiator_type == INITIATOR_ROOM && resetGetRoomMax(reset) != 0 &&
     (count_objs(NULL, roomGetContents(initiator), NULL, fullkey,
		 FALSE) >= resetGetRoomMax(reset)))
    return FALSE;

  OBJ_DATA *obj = protoObjRun(proto);
  if(obj == NULL)
    return FALSE;

  // to the room
  if(initiator_type == INITIATOR_ROOM)
    obj_to_room(obj, initiator);
  // inside of the object
  else if(initiator_type == INITIATOR_IN_OBJ)
    obj_to_obj(obj, initiator);
  // to inventory
  else if(initiator_type == INITIATOR_IN_MOB)
    obj_to_char(obj, initiator);
  // equip the mobile
  else if(initiator_type == INITIATOR_ON_MOB) {
    // see if we can equip it
    bool equipped = (objIsType(obj, "worn") && 
		     try_equip(initiator, obj, NULL, wornGetPositions(obj)));
    // we failed! Extract the object
    if(!equipped) {
      extract_obj(obj);
      return FALSE;
    }
  }

  // we're being loaded after a mobile was loaded... let's go to the same room
  else if(initiator_type == INITIATOR_THEN_MOB)
    obj_to_room(obj, charGetRoom(initiator));
  // we're being loaded after an object was loaded... let's go wherever it went
  else if(initiator_type == INITIATOR_THEN_OBJ) {
    if(objGetRoom(initiator))
      obj_to_room(obj, objGetRoom(initiator));
    else if(objGetContainer(initiator))
      obj_to_obj(obj, objGetContainer(initiator));
    else if(objGetCarrier(initiator))
      obj_to_char(obj, objGetCarrier(initiator));
    else if(objGetWearer(initiator)) {
      bool equipped = (objIsType(obj, "worn") && 
		       try_equip(objGetWearer(initiator), obj, NULL, 
				 wornGetPositions(obj)));
      // we failed! Extract the object
      if(!equipped) {
	extract_obj(obj);
	return FALSE;
      }
    }
  }
  // hmmm... we shouldn't get this far
  else {
    extract_obj(obj);
    return FALSE;
  }

  // now, run all of our stuff
  resetRunOn(reset->on,   obj, INITIATOR_ON_OBJ,   locale);
  resetRunOn(reset->in,   obj, INITIATOR_IN_OBJ,   locale);
  resetRunOn(reset->then, obj, INITIATOR_THEN_OBJ, locale);

  return TRUE;
}
Example #5
0
/*
 * Update all objs.
 * This function is performance sensitive.
 */
void obj_update( void )
{   
    OBJ_DATA *obj;
    OBJ_DATA *obj_next;
    AFFECT_DATA *paf, *paf_next;

    for ( obj = object_list; obj != NULL; obj = obj_next )
    {
	CHAR_DATA *rch;
	char *message;

	obj_next = obj->next;

	/* go through affects and decrement */
        for ( paf = obj->affected; paf != NULL; paf = paf_next )
        {
            paf_next    = paf->next;
            if ( paf->duration > 0 )
            {
                paf->duration--;
                if (number_range(0,4) == 0 && paf->level > 0)
                  paf->level--;  /* spell strength fades with time */
            }
            else if ( paf->duration < 0 )
                ;
            else
            {
                if ( paf_next == NULL
                ||   paf_next->type != paf->type
                ||   paf_next->duration > 0 )
                {
                    if ( paf->type > 0 && skill_table[paf->type].msg_obj )
                    {
			if (obj->carried_by != NULL)
			{
			    rch = obj->carried_by;
			    act(skill_table[paf->type].msg_obj,
				rch,obj,NULL,TO_CHAR);
			}
			if (obj->in_room != NULL 
			&& obj->in_room->people != NULL)
			{
			    rch = obj->in_room->people;
			    act(skill_table[paf->type].msg_obj,
				rch,obj,NULL,TO_ALL);
			}
                    }
                }

                affect_remove_obj( obj, paf );
            }
        }


	if ( obj->timer <= 0 || --obj->timer > 0 )
	    continue;

	switch ( obj->item_type )
	{
	default:              message = "$p crumbles into dust.";  break;
	case ITEM_FOUNTAIN:   message = "$p dries up.";         break;
	case ITEM_CORPSE_NPC: message = "$p decays into dust."; break;
	case ITEM_CORPSE_PC:  message = "$p decays into dust."; break;
	case ITEM_FOOD:       message = "$p decomposes.";	break;
	case ITEM_POTION:     message = "$p has evaporated from disuse.";	
								break;
	case ITEM_PORTAL:     message = "$p fades out of existence."; break;
	case ITEM_CONTAINER: 
	    if (CAN_WEAR(obj,ITEM_WEAR_FLOAT))
		if (obj->contains)
		    message = 
		"$p flickers and vanishes, spilling its contents on the floor.";
		else
		    message = "$p flickers and vanishes.";
	    else
		message = "$p crumbles into dust.";
	    break;
	}

	if ( obj->carried_by != NULL )
	{
	    if (IS_NPC(obj->carried_by) 
	    &&  obj->carried_by->pIndexData->pShop != NULL)
		obj->carried_by->silver += obj->cost/5;
	    else
	    {
	    	act( message, obj->carried_by, obj, NULL, TO_CHAR );
		if ( obj->wear_loc == WEAR_FLOAT)
		    act(message,obj->carried_by,obj,NULL,TO_ROOM);
	    }
	}
	else if ( obj->in_room != NULL
	&&      ( rch = obj->in_room->people ) != NULL )
	{
	    if (! (obj->in_obj && obj->in_obj->pIndexData->vnum == OBJ_VNUM_PIT
	           && !CAN_WEAR(obj->in_obj,ITEM_TAKE)))
	    {
	    	act( message, rch, obj, NULL, TO_ROOM );
	    	act( message, rch, obj, NULL, TO_CHAR );
	    }
	}

        if ((obj->item_type == ITEM_CORPSE_PC || obj->wear_loc == WEAR_FLOAT)
	&&  obj->contains)
	{   /* save the contents */
     	    OBJ_DATA *t_obj, *next_obj;

	    for (t_obj = obj->contains; t_obj != NULL; t_obj = next_obj)
	    {
		next_obj = t_obj->next_content;
		obj_from_obj(t_obj);

		if (obj->in_obj) /* in another object */
		    obj_to_obj(t_obj,obj->in_obj);

		else if (obj->carried_by)  /* carried */
		    if (obj->wear_loc == WEAR_FLOAT)
			if (obj->carried_by->in_room == NULL)
			    extract_obj(t_obj);
			else
			    obj_to_room(t_obj,obj->carried_by->in_room);
		    else
		    	obj_to_char(t_obj,obj->carried_by);

		else if (obj->in_room == NULL)  /* destroy it */
		    extract_obj(t_obj);

		else /* to a room */
		    obj_to_room(t_obj,obj->in_room);
	    }
	}

	extract_obj( obj );
    }

    return;
}
Example #6
0
void do_cdonate( CHAR_DATA *ch, char *arg )
{
    OBJ_DATA *container;
    OBJ_DATA *obj;
    OBJ_DATA *obj_next;
    char      arg1 [ MAX_INPUT_LENGTH ];

    if ( !is_clan( ch ) )
    {
	send_to_char( "You aren't a clansman!\n\r", ch );
	return;
    }

    arg = one_argument( arg, arg1 );

    if ( arg1[0] == '\0' )
    {
	send_to_char( "Donate to your clan what?\n\r", ch );
	return;
    }

    for ( container = object_list; container; container = container->next )
    {
        if ( can_see_obj( ch, container )
	    && container->pIndexData->vnum == ch->pcdata->clan->donation )
	    break;
    }

    if ( !container )
    {
	send_to_char( "The donation pit is missing from the world.\n\r", ch );
	return;
    }

    if ( str_cmp( arg1, "all" ) && str_prefix( "all.", arg1 ) )
    {
	if ( !( obj = get_obj_carry( ch, arg1 ) ) )
	{
	    send_to_char( "You do not have that item.\n\r", ch );
	    return;
	}

	if ( !can_drop_obj( ch, obj ) )
	{
	    send_to_char( "You can't let go of it.\n\r", ch );
	    return;
	}
	
	if ( get_obj_weight( obj ) + get_obj_weight( container ) 
	  > container->value[0] )
	{
	    send_to_char( "It won't fit.\n\r", ch );
	    return;
	}

	if ( obj->item_type == ITEM_TRASH
	    || obj->item_type == ITEM_FOOD
	    || obj->item_type == ITEM_KEY
	    || obj->item_type == ITEM_PILL )
	{
	    act( "You send $p flying to the $P.", ch, obj, container,
		TO_CHAR );
	    extract_obj( obj );
	    return;
	}

	obj_from_char( obj );
	obj_to_obj( obj, container );
	act( "$n sends $p flying to the $P.", ch, obj, container, TO_ROOM );
	act( "You send $p flying to the $P.", ch, obj, container, TO_CHAR );
	send_to_room( "A loud clank is heard from the pit!",
		     container->in_room );
    }
    else
    {
	for ( obj = ch->carrying; obj; obj = obj_next )
	{
	    obj_next = obj->next_content;

	    if ( obj->deleted )
		continue;

	    if ( ( arg1[3] == '\0' || is_name( &arg1[4], obj->name ) )
		&& can_see_obj( ch, obj )
		&& obj->wear_loc == WEAR_NONE
		&& obj != container
		&& can_drop_obj( ch, obj )
		&& get_obj_weight( obj ) + get_obj_weight( container )
		<= container->value[0] )
	    {

	        if ( obj->item_type == ITEM_TRASH
		    || obj->item_type == ITEM_FOOD
		    || obj->item_type == ITEM_KEY
		    || obj->item_type == ITEM_PILL )
		{
		    act( "You send $p flying to the $P.", ch, obj, container,
			TO_CHAR );
		    extract_obj( obj );
		    continue;
		}

		obj_from_char( obj );
		obj_to_obj( obj, container );
		act( "$n sends $p flying to the $P.", ch, obj, container,
		    TO_ROOM );
		act( "You send $p flying to the $P.", ch, obj, container,
		    TO_CHAR );
		send_to_room( "A loud clank is heard from the pit!\n\r",
		     container->in_room );

		ch->pcdata->clan->score += 1;
	    }
	}
    }

    return;

}
Example #7
0
/*
 * return values:
 * 0 - successful load, keep char in rent room.
 * 1 - load failure or load of crash items -- put char in temple.
 * 2 - rented equipment lost (no $)
 */
int Crash_load(struct char_data * ch)
{
  FILE *fl;
  char fname[MAX_STRING_LENGTH];
  struct obj_file_elem object;
  struct rent_info rent;
  int    cost, orig_rent_code, num_objs = 0, j;
  float  num_of_days;
  struct obj_data *obj, *obj2, *cont_row[MAX_BAG_ROWS];
  int    location;

  /* Empty all of the container lists (you never know ...) */
  for (j = 0; j < MAX_BAG_ROWS; j++)
    cont_row[j] = NULL;

  if (!get_filename(GET_NAME(ch), fname, CRASH_FILE))
    return 1;

  if (!(fl = fopen(fname, "r+b"))) {
    if (errno != ENOENT) {      /* if it fails, NOT because of no file */
      sprintf(buf1, "SYSERR: READING OBJECT FILE %s (5)", fname);
      perror(buf1);
      send_to_char("\r\n********************* NOTICE *********************\r\n"
		   "There was a problem loading your objects from disk.\r\n"
		   "Contact a God for assistance.\r\n", ch);
    }
    sprintf(buf, "%s entering game with NO equipment.", GET_NAME(ch));
    mudlog(buf, NRM, MAX((int)LVL_IMMORT, (int)GET_INVIS_LEV(ch)), TRUE);
    return 1;
  }
  if (!feof(fl))
    fread(&rent, sizeof(struct rent_info), 1, fl);
  else {
    plog("SYSERR: Crash_load: %s's rent file was empty!", GET_NAME(ch));
    return 1;
  }

  if (rent.rentcode == RENT_RENTED || rent.rentcode == RENT_TIMEDOUT) {
    num_of_days = (float) (time(0) - rent.time) / SECS_PER_REAL_DAY;
    cost = (int) (rent.net_cost_per_diem * num_of_days);
    if (cost > GET_GOLD(ch) + GET_BANK_GOLD(ch)) {
      fclose(fl);
      sprintf(buf, "%s entering game, rented equipment lost (no $).",
	      GET_NAME(ch));
      mudlog(buf, BRF, MAX((int)LVL_IMMORT, (int)GET_INVIS_LEV(ch)), TRUE);
      Crash_crashsave(ch);
      return 2;
    } else {
      GET_BANK_GOLD(ch) -= MAX((long)cost - GET_GOLD(ch), 0L);
      GET_GOLD(ch) = MAX((long)GET_GOLD(ch) - cost, 0L);
      save_char(ch, NOWHERE);
    }
  }
  switch (orig_rent_code = rent.rentcode) {
  case RENT_RENTED:
    sprintf(buf, "%s un-renting and entering game.", GET_NAME(ch));
    mudlog(buf, NRM, MAX((int)LVL_IMMORT, (int)GET_INVIS_LEV(ch)), TRUE);
    break;
  case RENT_CRASH:
    sprintf(buf, "%s retrieving crash-saved items and entering game.", GET_NAME(ch));
    mudlog(buf, NRM, MAX((int)LVL_IMMORT, (int)GET_INVIS_LEV(ch)), TRUE);
    break;
  case RENT_CRYO:
    sprintf(buf, "%s un-cryo'ing and entering game.", GET_NAME(ch));
    mudlog(buf, NRM, MAX((int)LVL_IMMORT, (int)GET_INVIS_LEV(ch)), TRUE);
    break;
  case RENT_FORCED:
  case RENT_TIMEDOUT:
    sprintf(buf, "%s retrieving force-saved items and entering game.", GET_NAME(ch));
    mudlog(buf, NRM, MAX((int)LVL_IMMORT, (int)GET_INVIS_LEV(ch)), TRUE);
    break;
  default:
    sprintf(buf, "WARNING: %s entering game with undefined rent code.", GET_NAME(ch));
    mudlog(buf, BRF, MAX((int)LVL_IMMORT, (int)GET_INVIS_LEV(ch)), TRUE);
    break;
  }

  while (!feof(fl)) {
    fread(&object, sizeof(struct obj_file_elem), 1, fl);
    if (ferror(fl)) {
      perror("Reading crash file: Crash_load.");
      fclose(fl);
      return 1;
    }

    if (feof(fl))
      break;

    ++num_objs;
    if ( (obj = Obj_from_store(object, &location)) == NULL )
      continue;

    auto_equip( ch, obj, location );

    /*
     * What to do with a new loaded item:
     *
     * If there's a list with location less than 1 below this, then its
     * container has disappeared from the file so we put the list back into
     * the character's inventory. (Equipped items are 0 here.)
     *
     * If there's a list of contents with location of 1 below this, then we
     * check if it is a container:
     *   - Yes: Get it from the character, fill it, and give it back so we
     *          have the correct weight.
     *   -  No: The container is missing so we put everything back into the
     *          character's inventory.
     *
     * For items with negative location, we check if there is already a list
     * of contents with the same location.  If so, we put it there and if not,
     * we start a new list.
     *
     * Since location for contents is < 0, the list indices are switched to
     * non-negative.
     *
     * This looks ugly, but it works.
     */
    if (location > 0) {		/* Equipped */
      for (j = MAX_BAG_ROWS - 1; j > 0; j--) {
        if (cont_row[j]) {	/* No container, back to inventory. */
          for (; cont_row[j]; cont_row[j] = obj2) {
            obj2 = cont_row[j]->next_content;
            obj_to_char(cont_row[j], ch);
          }
          cont_row[j] = NULL;
        }
      }
      if (cont_row[0]) {	/* Content list existing. */
        if (GET_OBJ_TYPE(obj) == ITEM_CONTAINER) {
	/* Remove object, fill it, equip again. */
          obj = unequip_char(ch, location - 1);
          obj->contains = NULL;	/* Should be NULL anyway, but just in case. */
          for (; cont_row[0]; cont_row[0] = obj2) {
            obj2 = cont_row[0]->next_content;
            obj_to_obj(cont_row[0], obj);
          }
          equip_char(ch, obj, location - 1);
        } else {			/* Object isn't container, empty the list. */
          for (; cont_row[0]; cont_row[0] = obj2) {
            obj2 = cont_row[0]->next_content;
            obj_to_char(cont_row[0], ch);
          }
          cont_row[0] = NULL;
        }
      }
    } else {	/* location <= 0 */
      for (j = MAX_BAG_ROWS - 1; j > -location; j--) {
        if (cont_row[j]) {	/* No container, back to inventory. */
          for (; cont_row[j]; cont_row[j] = obj2) {
            obj2 = cont_row[j]->next_content;
            obj_to_char(cont_row[j], ch);
          }
          cont_row[j] = NULL;
        }
      }
      if (j == -location && cont_row[j]) {	/* Content list exists. */
        if (GET_OBJ_TYPE(obj) == ITEM_CONTAINER) {
		/* Take the item, fill it, and give it back. */
          obj_from_char(obj);
          obj->contains = NULL;
          for (; cont_row[j]; cont_row[j] = obj2) {
            obj2 = cont_row[j]->next_content;
            obj_to_obj(cont_row[j], obj);
          }
          obj_to_char(obj, ch);	/* Add to inventory first. */
        } else {	/* Object isn't container, empty content list. */
          for (; cont_row[j]; cont_row[j] = obj2) {
            obj2 = cont_row[j]->next_content;
            obj_to_char(cont_row[j], ch);
          }
          cont_row[j] = NULL;
        }
      }
      if (location < 0 && location >= -MAX_BAG_ROWS) {
        /*
         * Let the object be part of the content list but put it at the
         * list's end.  Thus having the items in the same order as before
         * the character rented.
         */
        obj_from_char(obj);
        if ((obj2 = cont_row[-location - 1]) != NULL) {
          while (obj2->next_content)
            obj2 = obj2->next_content;
          obj2->next_content = obj;
        } else
          cont_row[-location - 1] = obj;
      }
    }
  }

  /* Little hoarding check. -gg 3/1/98 */
  sprintf(fname, "%s (level %d) has %d object%s (max %d).",
          GET_NAME(ch), GET_LEVEL(ch), num_objs,
          num_objs != 1 ? "s" : "", max_obj_save);
  mudlog(fname, NRM, MAX(GET_INVIS_LEV(ch), LVL_GOD), TRUE);

  /* turn this into a crash file by re-writing the control block */
  rent.rentcode = RENT_CRASH;
  rent.time = time(0);
  rewind(fl);
  Crash_write_rentcode(ch, fl, &rent);

  fclose(fl);

  if ((orig_rent_code == RENT_RENTED) || (orig_rent_code == RENT_CRYO))
    return (0);
  else
    return (1);
}
Example #8
0
void do_buy( CHAR_DATA *ch, char *argument )
{
    char arg[MAX_INPUT_LENGTH];
    int maxgold;
    bool debit;
    OBJ_DATA *obj;    

    argument = one_argument( argument, arg );

    if ( arg[0] == '\0' )
    {
	send_to_char( "Buy what?\n\r", ch );
	return;
    }

    if ( IS_SET(ch->in_room->room_flags, ROOM_PET_SHOP) )
    {
	char buf[MAX_STRING_LENGTH];
	CHAR_DATA *pet;
	ROOM_INDEX_DATA *pRoomIndexNext;
	ROOM_INDEX_DATA *in_room;

   if ( argument[0] == '\0' )
      debit = FALSE;
   else if ( !str_cmp( "atm", argument ) || !str_cmp( "debit", argument ) )
   {
      bool has_card = FALSE;
      
      for ( obj = ch->last_carrying; obj; obj = obj->prev_content )        
      {
          if ( obj->item_type == ITEM_DEBIT_CARD )
            has_card = TRUE;
      }   
      
     if ( has_card == TRUE )
      debit = TRUE;
     else
     {
       send_to_char( "You don't even have your card with you!\n\r", ch );
       return;    
     }    
    }

	if ( IS_NPC(ch) )
	    return;

	pRoomIndexNext = get_room_index( ch->in_room->vnum + 1 );
	if ( !pRoomIndexNext )
	{
	    bug( "Do_buy: bad pet shop at vnum %d.", ch->in_room->vnum );
	    send_to_char( "Sorry, you can't buy that here.\n\r", ch );
	    return;
	}

	in_room     = ch->in_room;
	ch->in_room = pRoomIndexNext;
	pet         = get_char_room( ch, arg );
	ch->in_room = in_room;

	if ( pet == NULL || !IS_NPC( pet ) || !IS_SET(pet->act, ACT_PET) )
	{
	    send_to_char( "Sorry, you can't buy that here.\n\r", ch );
	    return;
	}

	if (( ch->gold < 10 * pet->top_level * pet->top_level ) && debit == FALSE)
	{
	    send_to_char( "You can't afford it.\n\r", ch );
	    return;
	}
	else if ( (ch->pcdata->bank < 10 * pet->top_level * pet->top_level) && debit == TRUE )
	{
	  send_to_char( "You dont have enough money in your bank account for it.\n\r", ch );
          return;    
        } 

	maxgold = 10 * pet->top_level * pet->top_level;
        if ( debit == FALSE )
	  ch->gold	-= maxgold; /* this was already here, btw */
	else
	  ch->pcdata->bank  -= maxgold;

	boost_economy( ch->in_room->area, maxgold );
	pet		= create_mobile( pet->pIndexData );
	SET_BIT(pet->act, ACT_PET);
	SET_BIT(pet->affected_by, AFF_CHARM);

	argument = one_argument( argument, arg );
	if ( arg[0] != '\0' )
	{
	    sprintf( buf, "%s %s", pet->name, arg );
	    STRFREE( pet->name );
	    pet->name = STRALLOC( buf );
	}

	sprintf( buf, "%sA neck tag says 'I belong to %s'.\n\r",
	    pet->description, ch->name );
	STRFREE( pet->description );
	pet->description = STRALLOC( buf );

	char_to_room( pet, ch->in_room );
	add_follower( pet, ch );
	send_to_char( "Enjoy your pet.\n\r", ch );
    	act( AT_ACTION, "$n bought $N as a pet.", ch, NULL, pet, TO_ROOM );
	return;
    }
    else
    {
	CHAR_DATA *keeper;
	int cost;
	int noi = 1;		/* Number of items */
	sh_int mnoi = 20;	/* Max number of items to be bought at once */

	if ( ( keeper = find_keeper( ch ) ) == NULL )
	    return;

	maxgold = keeper->top_level * 10;

	if ( is_number( arg ) )
	{
	    noi = atoi( arg );
	    argument = one_argument( argument, arg );
	    if ( noi > mnoi )
	    {
		act( AT_TELL, "$n tells you 'I don't sell that many items at"
		  " once.'", keeper, NULL, ch, TO_VICT );
		ch->reply = keeper;
		return;
	    }
	}

    if ( argument[0] == '\0' )
      debit = FALSE;
    else if ( !str_cmp( "atm", argument ) || !str_cmp( "debit", argument ) )
    {
      bool has_card = FALSE;
      
      for ( obj = ch->last_carrying; obj; obj = obj->prev_content )        
      {
          if ( obj->item_type == ITEM_DEBIT_CARD )
            has_card = TRUE;
      }   
      
      if ( has_card == TRUE )
       debit = TRUE;
      else
      {
        send_to_char( "You don't even have your card with you!\n\r", ch );
        return;    
      }    
     }  

	obj  = get_obj_carry( keeper, arg );
	
	if ( !obj && arg[0] == '#' )
        {     
              int onum, oref;
              bool ofound = FALSE;
              
              onum =0;
              oref = atoi(arg+1);
              for ( obj = keeper->last_carrying; obj; obj = obj->prev_content )
	      { 
	        if ( obj->wear_loc == WEAR_NONE
	        &&   can_see_obj( ch, obj ) )
	            onum++;
                if ( onum == oref ) 
                {
                    ofound = TRUE;
                    break;
                }
                else if ( onum > oref )
                   break;
	      }
	      if (!ofound)
	         obj = NULL;
        }
	if (keeper->home != NULL && obj->cost > 0)
          cost= obj->cost;
	cost = ( get_cost( ch, keeper, obj, TRUE ) * noi );

	if( !IS_NPC(ch) && ch->pcdata->learned[gsn_bargain] > 0 && ch->pcdata->learned[gsn_bargain] > number_percent())
	 {
	   ch_printf(ch,"You are able to bargain from %d credits to %d credits!\n\r", cost, (cost/3)+(cost/2));
	   cost = (cost/3) + (cost/2);
	   if(number_percent() > 50)
	    learn_from_success(ch, gsn_bargain);
	 }

	if ( cost <= 0 || !can_see_obj( ch, obj ) )
	{
	    act( AT_TELL, "$n tells you 'I don't sell that -- try 'list'.'",
		keeper, NULL, ch, TO_VICT );
	    ch->reply = keeper;
	    return;
	}

	if ( !IS_OBJ_STAT( obj, ITEM_INVENTORY ) && ( noi > 1 ) )
	{
	    interpret( keeper, "laugh" );
	    act( AT_TELL, "$n tells you 'I don't have enough of those in stock"
	     " to sell more than one at a time.'", keeper, NULL, ch, TO_VICT );
	    ch->reply = keeper;
	    return;
	}
	
	if ( ch->gold < cost && debit == FALSE)
	{
	    act( AT_TELL, "$n tells you 'You can't afford to buy $p.'",
		keeper, obj, ch, TO_VICT );
	    ch->reply = keeper;
	    return;
	}
	
        if ( ch->pcdata->bank < cost && debit == TRUE)
	{
	    send_to_char( "You are almost slide your card through, but you remember you don't have enough money!\n\r", ch );
	    return;	    
        }  

	if ( IS_SET(obj->extra_flags, ITEM_PROTOTYPE) 
             && get_trust( ch ) < LEVEL_IMMORTAL )
	{
	    act( AT_TELL, "$n tells you 'This is a only a prototype!  I can't sell you that...'", 
		keeper, NULL, ch, TO_VICT );
      	    ch->reply = keeper;
	    return;
	}

	if ( ch->carry_number + get_obj_number( obj ) > can_carry_n( ch ) )
	{
	    send_to_char( "You can't carry that many items.\n\r", ch );
	    return;
	}

	if ( ch->carry_weight + ( get_obj_weight( obj ) * noi )
		+ (noi > 1 ? 2 : 0) > can_carry_w( ch ) )
	{
	    send_to_char( "You can't carry that much weight.\n\r", ch );
	    return;
	}

	if ( noi == 1 )
	{
	    if ( !IS_OBJ_STAT( obj, ITEM_INVENTORY ) )  
	       separate_obj( obj );
	    act( AT_ACTION, "$n buys $p.", ch, obj, NULL, TO_ROOM );
    	    act( AT_ACTION, "You buy $p.", ch, obj, NULL, TO_CHAR );
	}
        else
	{
	    sprintf( arg, "$n buys %d $p%s.", noi,
		( obj->short_descr[strlen(obj->short_descr)-1] == 's'
		? "" : "s" ) );
	    act( AT_ACTION, arg, ch, obj, NULL, TO_ROOM );
	    sprintf( arg, "You buy %d $p%s.", noi,
		( obj->short_descr[strlen(obj->short_descr)-1] == 's'
		? "" : "s" ) );
	    act( AT_ACTION, arg, ch, obj, NULL, TO_CHAR );
	    act( AT_ACTION, "$N puts them into a bag and hands it to you.",
		ch, NULL, keeper, TO_CHAR );
	}

        if ( debit == FALSE )
	  ch->gold     -= cost; /* this line was already here, btw */
        else if ( debit == TRUE )
          ch->pcdata->bank     -= cost;
	keeper->gold += cost;

	if ( keeper->gold > maxgold )
	{
	    boost_economy( keeper->in_room->area, keeper->gold - maxgold/2 );
	    keeper->gold = maxgold/2;
	    act( AT_ACTION, "$n puts some credits into a large safe.", keeper, NULL, NULL, TO_ROOM );
	}

	if ( IS_OBJ_STAT( obj, ITEM_INVENTORY ) )
	{
	    OBJ_DATA *buy_obj, *bag;

	    buy_obj = create_object( obj->pIndexData, obj->level );

	    /*
	     * Due to grouped objects and carry limitations in SMAUG
	     * The shopkeeper gives you a bag with multiple-buy,
	     * and also, only one object needs be created with a count
	     * set to the number bought.		-Thoric
	     */
	    if ( noi > 1 )
	    {
		bag = create_object( get_obj_index( OBJ_VNUM_SHOPPING_BAG ), 1 );
		/* perfect size bag ;) */
		bag->value[0] = bag->weight + (buy_obj->weight * noi);
		buy_obj->count = noi;
		obj->pIndexData->count += (noi - 1);
		numobjsloaded += (noi - 1);
		obj_to_obj( buy_obj, bag );
		obj_to_char( bag, ch );
	    }
	    else
		obj_to_char( buy_obj, ch );
	}
        else
	{
	    obj_from_char( obj );
	    obj_to_char( obj, ch );
	}

	return;
    }
}
Example #9
0
/*
 * Make a corpse out of a character.
 */
void make_corpse( CHAR_DATA *ch )
{
	char buf[MSL]={'\0'};
    OBJ_DATA *corpse;
    OBJ_DATA *obj;
    OBJ_DATA *obj_next;
    char *name;

    if ( IS_NPC(ch) )
    {
	name		= ch->short_descr;
	corpse		= create_object(get_obj_index(OBJ_VNUM_CORPSE_NPC));
	corpse->timer	= number_range( 3, 6 );
	if ( ch->dollars > 0 )
	{
	    obj_to_obj( create_money( ch->dollars, ch->cents ), corpse );
	    ch->cents = 0;
	    ch->dollars = 0;
	}
	corpse->cost = 0;
    }
    else
    {
	name		= ch->name;
	corpse		= create_object(get_obj_index(OBJ_VNUM_CORPSE_PC));
	corpse->timer	= number_range( 25, 40 );
	    corpse->owner = NULL;
	    if (ch->dollars > 1 || ch->cents > 1)
	    {
		obj_to_obj(create_money(ch->dollars / 2, ch->cents/2), corpse);
	        ch->cents = 0;
	        ch->dollars = 0;
	    }
		
	corpse->cost = 0;
    }

    snprintf( buf, sizeof(buf), corpse->short_descr, name );
    PURGE_DATA( corpse->short_descr );
    corpse->short_descr = str_dup( buf );

    snprintf( buf, sizeof(buf), corpse->description, name );
    PURGE_DATA( corpse->description );
    corpse->description = str_dup( buf );

    PURGE_DATA( corpse->full_desc );
    corpse->full_desc = str_dup( Format("The corpse of someone who in life looked like:\n\r%s", ch->description) );

    if(!str_cmp(ch->material, "flesh") && !str_cmp(ch->material, "none") && (material_lookup(ch->material) != material_lookup("unknown")))
	{
    	PURGE_DATA( corpse->material );
	corpse->material = str_dup(ch->material);
	}

    for ( obj = ch->carrying; obj != NULL; obj = obj_next )
    {
	obj_next = obj->next_content;
	obj_from_char( obj );
	if (obj->item_type == ITEM_POTION)
	    obj->timer = number_range(500,1000);
	if (obj->item_type == ITEM_SCROLL)
	    obj->timer = number_range(1000,2500);
	if (IS_SET(obj->extra_flags,ITEM_ROT_DEATH))
	{
	    obj->timer = number_range(1,3);
	    REMOVE_BIT(obj->extra_flags,ITEM_ROT_DEATH);
	}
	REMOVE_BIT(obj->extra_flags,ITEM_VIS_DEATH);

	if(obj != NULL)
	{
	    if(IS_SET(ch->act, ACT_UMBRA))
		obj_to_plane(obj, 1);
	    if(IS_SET(ch->act, ACT_DREAMING))
		obj_to_plane(obj, 2);
	}
	obj_to_obj( obj, corpse );
    }

    if(IS_SET(ch->act, ACT_UMBRA))
	obj_to_plane(corpse, 1);
    if(IS_SET(ch->act, ACT_DREAMING))
	obj_to_plane(corpse, 2);
    obj_to_room( corpse, ch->in_room );
    return;
}
Example #10
0
bool Object::fread_obj (Character * ch, std::ifstream & fp)
{
  std::string word;
  int iNest = 0;
  bool fMatch;
  bool fNest = false;
  bool fVnum = true;

  for (;;) {
    word = fp.eof() ? std::string("End") : fread_word (fp);
    fMatch = false;

    switch (toupper (word[0])) {
    case '*':
      fMatch = true;
      fread_to_eol (fp);
      break;

    case 'A':
      if (!str_cmp (word, "Affect")) {
        Affect *paf;

        paf = new Affect();

        paf->type = fread_number (fp);
        paf->duration = fread_number (fp);
        paf->modifier = fread_number (fp);
        paf->location = fread_number (fp);
        paf->bitvector = fread_number (fp);
        affected.push_back(paf);
        fMatch = true;
        break;
      }
      break;

    case 'C':
      KEY ("Cost", cost, fread_number (fp));
      break;

    case 'D':
      KEY ("Description", description, fread_string (fp));
      break;

    case 'E':
      KEY ("ExtraFlags", extra_flags, fread_number (fp));

      if (!str_cmp (word, "ExtraDescr")) {
        ExtraDescription *ed;

        ed = new ExtraDescription();

        ed->keyword = fread_string (fp);
        ed->description = fread_string (fp);
        extra_descr.push_back(ed);
        fMatch = true;
      }

      if (!str_cmp (word, "End")) {
        if (!fNest || !fVnum) {
          bug_printf ("Fread_obj: incomplete object.");
          return false;
        } else {
          object_list.push_back(this);
          pIndexData->count++;
          if (iNest == 0 || rgObjNest[iNest] == NULL)
            obj_to_char (ch);
          else
            obj_to_obj (rgObjNest[iNest - 1]);
          return true;
        }
      }
      break;

    case 'I':
      KEY ("ItemType", item_type, fread_number (fp));
      break;

    case 'L':
      KEY ("Level", level, fread_number (fp));
      break;

    case 'N':
      KEY ("Name", name, fread_string (fp));

      if (!str_cmp (word, "Nest")) {
        iNest = fread_number (fp);
        if (iNest < 0 || iNest >= MAX_NEST) {
          bug_printf ("Fread_obj: bad nest %d.", iNest);
        } else {
          rgObjNest[iNest] = this;
          fNest = true;
        }
        fMatch = true;
      }
      break;

    case 'S':
      KEY ("ShortDescr", short_descr, fread_string (fp));

      if (!str_cmp (word, "Spell")) {
        int iValue;
        int sn;

        iValue = fread_number (fp);
        sn = skill_lookup (fread_word (fp));
        if (iValue < 0 || iValue > 3) {
          bug_printf ("Fread_obj: bad iValue %d.", iValue);
        } else if (sn < 0) {
          bug_printf ("Fread_obj: unknown skill.");
        } else {
          value[iValue] = sn;
        }
        fMatch = true;
        break;
      }

      break;

    case 'T':
      KEY ("Timer", timer, fread_number (fp));
      break;

    case 'V':
      if (!str_cmp (word, "Values")) {
        value[0] = fread_number (fp);
        value[1] = fread_number (fp);
        value[2] = fread_number (fp);
        value[3] = fread_number (fp);
        fMatch = true;
        break;
      }

      if (!str_cmp (word, "Vnum")) {
        int vnum;

        vnum = fread_number (fp);
        if ((pIndexData = get_obj_index (vnum)) == NULL)
          bug_printf ("Fread_obj: bad vnum %d.", vnum);
        else
          fVnum = true;
        fMatch = true;
        break;
      }
      break;

    case 'W':
      KEY ("WearFlags", wear_flags, fread_number (fp));
      KEY ("WearLoc", wear_loc, fread_number (fp));
      KEY ("Weight", weight, fread_number (fp));
      break;

    }

    if (!fMatch) {
      bug_printf ("Fread_obj: no match.");
      fread_to_eol (fp);
    }
  }
  return false;
}
Example #11
0
void fread_obj( CHAR_DATA *ch, FILE *fp )
{
    static OBJ_DATA obj_zero;
    OBJ_DATA *obj;
    char *word;
    int iNest;
    bool fMatch;
    bool fNest;
    bool fVnum;

    if ( obj_free == NULL )
    {
	obj		= alloc_perm( sizeof(*obj) );
    }
    else
    {
	obj		= obj_free;
	obj_free	= obj_free->next;
    }

    *obj		= obj_zero;
    obj->name		= str_dup( "" );
    obj->short_descr	= str_dup( "" );
    obj->description	= str_dup( "" );

    fNest		= FALSE;
    fVnum		= TRUE;
    iNest		= 0;

    for ( ; ; )
    {
	word   = feof( fp ) ? "End" : fread_word( fp );
	fMatch = FALSE;

	switch ( UPPER(word[0]) )
	{
	case '*':
	    fMatch = TRUE;
	    fread_to_eol( fp );
	    break;

	case 'A':
	    if ( !str_cmp( word, "Affect" ) )
	    {
		AFFECT_DATA *paf;

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

		paf->type	= fread_number( fp );
		paf->duration	= fread_number( fp );
		paf->modifier	= fread_number( fp );
		paf->location	= fread_number( fp );
		paf->bitvector	= fread_number( fp );
		paf->next	= obj->affected;
		obj->affected	= paf;
		fMatch		= TRUE;
		break;
	    }
	    break;

	case 'C':
	    KEY( "Cost",	obj->cost,		fread_number( fp ) );
	    break;

	case 'D':
	    KEY( "Description",	obj->description,	fread_string( fp ) );
	    break;

	case 'E':
	    KEY( "ExtraFlags",	obj->extra_flags,	fread_number( fp ) );

	    if ( !str_cmp( word, "ExtraDescr" ) )
	    {
		EXTRA_DESCR_DATA *ed;

		if ( extra_descr_free == NULL )
		{
		    ed			= alloc_perm( sizeof(*ed) );
		}
		else
		{
		    ed			= extra_descr_free;
		    extra_descr_free	= extra_descr_free->next;
		}

		ed->keyword		= fread_string( fp );
		ed->description		= fread_string( fp );
		ed->next		= obj->extra_descr;
		obj->extra_descr	= ed;
		fMatch = TRUE;
	    }

	    if ( !str_cmp( word, "End" ) )
	    {
		if ( !fNest || !fVnum )
		{
		    bug( "Fread_obj: incomplete object.", 0 );
		    free_string( obj->name        );
		    free_string( obj->description );
		    free_string( obj->short_descr );
		    obj->next = obj_free;
		    obj_free  = obj;
		    return;
		}
		else
		{
		    obj->next	= object_list;
		    object_list	= obj;
		    obj->pIndexData->count++;
		    if ( iNest == 0 || rgObjNest[iNest] == NULL )
			obj_to_char( obj, ch );
		    else
			obj_to_obj( obj, rgObjNest[iNest-1] );
		    return;
		}
	    }
	    break;

	case 'I':
	    KEY( "ItemType",	obj->item_type,		fread_number( fp ) );
	    break;

	case 'L':
	    KEY( "Level",	obj->level,		fread_number( fp ) );
	    break;

	case 'N':
	    KEY( "Name",	obj->name,		fread_string( fp ) );

	    if ( !str_cmp( word, "Nest" ) )
	    {
		iNest = fread_number( fp );
		if ( iNest < 0 || iNest >= MAX_NEST )
		{
		    bug( "Fread_obj: bad nest %d.", iNest );
		}
		else
		{
		    rgObjNest[iNest] = obj;
		    fNest = TRUE;
		}
		fMatch = TRUE;
	    }
	    break;

	case 'S':
	    KEY( "ShortDescr",	obj->short_descr,	fread_string( fp ) );

	    if ( !str_cmp( word, "Spell" ) )
	    {
		int iValue;
		int sn;

		iValue = fread_number( fp );
		sn     = skill_lookup( fread_word( fp ) );
		if ( iValue < 0 || iValue > 3 )
		{
		    bug( "Fread_obj: bad iValue %d.", iValue );
		}
		else if ( sn < 0 )
		{
		    bug( "Fread_obj: unknown skill.", 0 );
		}
		else
		{
		    obj->value[iValue] = sn;
		}
		fMatch = TRUE;
		break;
	    }

	    break;

	case 'T':
	    KEY( "Timer",	obj->timer,		fread_number( fp ) );
	    break;

	case 'V':
	    if ( !str_cmp( word, "Values" ) )
	    {
		obj->value[0]	= fread_number( fp );
		obj->value[1]	= fread_number( fp );
		obj->value[2]	= fread_number( fp );
		obj->value[3]	= fread_number( fp );
		fMatch		= TRUE;
		break;
	    }

	    if ( !str_cmp( word, "Vnum" ) )
	    {
		int vnum;

		vnum = fread_number( fp );
		if ( ( obj->pIndexData = get_obj_index( vnum ) ) == NULL )
		    bug( "Fread_obj: bad vnum %d.", vnum );
		else
		    fVnum = TRUE;
		fMatch = TRUE;
		break;
	    }
	    break;

	case 'W':
	    KEY( "WearFlags",	obj->wear_flags,	fread_number( fp ) );
	    KEY( "WearLoc",	obj->wear_loc,		fread_number( fp ) );
	    KEY( "Weight",	obj->weight,		fread_number( fp ) );
	    break;

	}

	if ( !fMatch )
	{
	    bug( "Fread_obj: no match.", 0 );
	    fread_to_eol( fp );
	}
    }
}
Example #12
0
//to calkowita obsluga ladowania artefactow
//sprawdzanie czy mozna + ladowanie + ew. zakladanie
void load_artefact( ROOM_INDEX_DATA *room, OBJ_DATA *obj, CHAR_DATA *ch )
{
	char buf[ MAX_INPUT_LENGTH ];
	ARTEFACT_DATA *atmp = NULL;
	ARTEFACT_LOADER *ltmp = NULL;
	OBJ_DATA *loaded_obj;

	int type;
	int vnum = 0;


	if ( room != NULL )
	{
		vnum = room->vnum;type = 0;
	}
	else if ( obj != NULL )
	{
		vnum = obj->pIndexData->vnum;type = 1;
	}
	else if ( ch != NULL )
	{
		vnum = ch->pIndexData->vnum;type = 2;
	}
	else return ;


	//gdzie
	for ( atmp = artefact_system;atmp;atmp = atmp->next )
	{
		for ( ltmp = atmp->loader;ltmp;ltmp = ltmp->next )
		{
			//jesli nie zgadza sie typ (np: obj=obj) i vnumy to wychodzimy
			if (!( ltmp->type == type && ltmp->vnum == vnum ))
			{
                                continue;
                        }

                        //jesli room to sprawdzanie czy juz tam nie ma
			if (( type == 0 ) &&
                            ( count_obj_list( get_obj_index( atmp->avnum ), room->contents ) > 0 ) )
			{
				sprintf( buf, "NIE LADUJE do room a (juz jest): %d do %d", atmp->avnum, room->vnum );
				wiznet( buf, NULL, NULL, WIZ_ARTEFACTLOAD, 0, 39 );
				continue;
			}

                        //aktualizacja ilosci
			atmp->count = artefact_new_count( atmp );


			//tera prawd. jesli mniejsze to nastepny loader
			if ( number_range( 1, ltmp->probup ) > ltmp->probdown )
			{
				continue;
			}

                        //juz max artefaktu, nastepny loader
			if ( atmp->count >= atmp->max_count ) continue;


			//ladujemy bo wsie warunki spelnione
			loaded_obj = create_object ( get_obj_index( atmp->avnum ), FALSE );
			create_artefact( loaded_obj->pIndexData->vnum );

			//dokad ladujemy
			if ( type == 0 )   //do rooma
			{
				sprintf( buf, "Artefakt [%d] za³adowany do rooma [%d].", loaded_obj->pIndexData->vnum, room->vnum );
				obj_to_room( loaded_obj, room );
				wiznet( buf, NULL, NULL, WIZ_ARTEFACTLOAD, 0, 39 );
			}
			else if ( type == 1 )   //do srodka objectu
			{
				sprintf( buf, "Artefakt [%d] za³adowany do wnêtrza obiektu [%d],", loaded_obj->pIndexData->vnum, obj->pIndexData->vnum );
				obj_to_obj( loaded_obj, obj );
				wiznet( buf, NULL, NULL, WIZ_ARTEFACTLOAD, 0, 39 );
					//okresla room
				if ( obj->in_room )
					sprintf( buf, "	w roomie [%d]", obj->in_room->vnum );
				if ( obj->carried_by )
					sprintf( buf, "	na mobie [%d] w roomie [%d]", obj->carried_by->pIndexData->vnum, obj->carried_by->in_room->vnum );
				wiznet( buf, NULL, NULL, WIZ_ARTEFACTLOAD, 0, 39 );
				}
			else if ( type == 2 )   //mobowi
			{
				sprintf( buf, "Artefakt [%d] za³adowany mobowi [%d] roomie [%d].", loaded_obj->pIndexData->vnum, ch->pIndexData->vnum, ch->in_room->vnum );
				obj_to_char( loaded_obj, ch );
				wiznet( buf, NULL, NULL, WIZ_ARTEFACTLOAD, 0, 39 );
					//+zakladanie jesli moze (nie sprzedawca)
				if ( ch->pIndexData->pShop == NULL && loaded_obj->wear_loc == WEAR_NONE && can_see_obj( ch, loaded_obj ) )
				{
					if ( loaded_obj->item_type == ITEM_WEAPON )
					{
						if ( !get_eq_char( ch, WEAR_WIELD ) )
							wield_weapon( ch, loaded_obj, TRUE );
					}
					else
						wear_obj( ch, loaded_obj, FALSE );
				}

			} //end dokad
//		} //end typ=typ, vnum=vnum
	} //end po loaderach
} //end po artefaktach
}
Example #13
0
/* toss $n $dice $table for $face */
void
char__do_toss (CHAR_DATA * ch, char *argument, int cmd)
{
    register short int nArg = 0;
    register short int nDiceArg = 0;
    register short int nTableArg = 0;
    register short int nFaceArg = 0;
    register short int nFacet = 0;
    register short int nMaxFacet = 0;
    size_t nIndex = 0;
    register int nCount = 0;

    char *p = NULL;
    char buf[AVG_STRING_LENGTH * 10] = "";
    char arg[5][AVG_STRING_LENGTH / 5] = { "", "", "", "", "" };
    char key[AVG_STRING_LENGTH] = "";
    char strFacet[AVG_STRING_LENGTH] = "";
    char strFacetList[AVG_STRING_LENGTH] = "";
    OBJ_DATA *dice = NULL;
    OBJ_DATA *table = NULL;

    nArg =
        sscanf (argument, "%s %s %s %s %s", arg[0], arg[1], arg[2], arg[3],
                arg[4]);

    if (nArg <= 0)
    {
        send_to_char ("Toss what?\n", ch);
        return;
    }

    nCount = strtol (arg[0], &p, 10);
    if (errno == ERANGE || nCount == 0 || strlen (p) != 0)
    {
        nCount = 0;
    }
    else
    {
        nDiceArg = 1;
    }

    switch (nArg - nDiceArg)
    {
    case 3:
        nFaceArg = (strcmp ("for", arg[nDiceArg + 1]) == 0) ? nDiceArg + 2 : -1;
        break;
    case 4:
        nFaceArg = (strcmp ("for", arg[nDiceArg + 2]) == 0) ? nDiceArg + 3 : -1;	/* NO BREAK HERE goes to next case */
    case 2:
        nTableArg = nDiceArg + 1;
        break;
    default:
        break;
    }

    if (nFaceArg < 0)
    {
        send_to_char ("Toss them how?\n", ch);
        return;
    }

    if (!(dice = get_obj_in_dark (ch, arg[nDiceArg], ch->right_hand)) &&
            !(dice = get_obj_in_dark (ch, arg[nDiceArg], ch->left_hand)))
    {
        sprintf (buf, "You don't have a '%s'.\n", arg[nDiceArg]);
        send_to_char (buf, ch);
        return;
    }
    if (dice->obj_flags.type_flag != ITEM_TOSSABLE
            && dice->obj_flags.type_flag != ITEM_MONEY)
    {
        send_to_char ("Did you mean to #6throw#0 that object?\n", ch);
        return;
    }

    if (dice->count > 12 && (nCount == 0 || nCount > 12))
    {
        send_to_char ("You can't toss that many at once.\n", ch);
        return;
    }

    if (nTableArg && arg[nTableArg][0] &&
            (!(table = get_obj_in_list_vis (ch, arg[nTableArg], ch->room->contents))
             || !IS_TABLE(table)))
    {
        sprintf (buf, "You don't see any furniture like '%s'.\n",
                 arg[nTableArg]);
        send_to_char (buf, ch);
        return;
    }

    obj_from_char (&dice, nCount);

    if (dice->obj_flags.type_flag == ITEM_MONEY)
    {
        strcpy (key, " obverse reverse ");
        nMaxFacet = 2;
    }
    else if (dice->desc_keys)
    {
        sprintf (key, " %s ", dice->desc_keys);
    }
    else
    {
        strcpy (key,
                " one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen twenty ");
    }

    if (nFaceArg && dice->o.od.value[1])
    {
        /*
           nFacet = strtol(arg[nFaceArg],&p,10);
           if ( errno == ERANGE || nFacet == 0 || strlen(p) != 0 ) {
           strcpy(strFacet,strstr(key,arg[nFaceArg]));
           if () {
           }
           else {
           nFacet = 0;
           }
           }
           else {
           }
         */

    }
    nMaxFacet = (nMaxFacet) ? nMaxFacet : dice->o.od.value[0];
    for (nCount = 0; nCount < dice->count; nCount++)
    {

        nFacet = number (1, nMaxFacet);

        for (nIndex = 0; nIndex < strlen (key); nIndex++)
        {
            if (key[nIndex] == ' ' && --nFacet <= 0)
                break;
        }

        sscanf (key + nIndex + 1, "%s %s", strFacet, buf);
        sprintf (strFacetList + strlen (strFacetList), "#6%s%s#0%s",
                 (nMaxFacet == 2) ? "the " : "a ", strFacet,
                 (nCount ==
                  dice->count - 2) ? " and " : ((nCount !=
                                                dice->count - 1) ? ", " : ""));
    }

    sprintf (buf, "You toss $p onto %s%s%s%s. The upright face%s show%s: %s.\n",
             (nTableArg) ? "$P" : "the ground",
             (nFaceArg) ? ", trying for #6a " : "",
             (nFaceArg) ? arg[nFaceArg] : "", (nFaceArg) ? "#0" : "",
             (nCount > 1) ? "s" : "", (nCount > 1) ? "" : "s", strFacetList);
    act (buf, true, ch, dice, table, TO_CHAR | _ACT_FORMAT);

    sprintf (buf, "$n tosses $p onto %s. The upright face%s show%s: %s.\n",
             (nTableArg) ? "$P" : "the ground", (nCount > 1) ? "s" : "",
             (nCount > 1) ? "" : "s", strFacetList);
    act (buf, true, ch, dice, table, TO_ROOM | _ACT_FORMAT);

    if (nTableArg)
    {
        obj_to_obj (dice, table);
    }
    else
    {
        obj_to_room (dice, ch->in_room);
    }
}
Example #14
0
/* return values:
 0 - successful load, keep char in rent room.
 1 - load failure or load of crash items -- put char in temple.
 2 - rented equipment lost (no $)
 */
int Crash_load(struct char_data * ch)
{
  void Crash_save(struct char_data * ch, int type);
  FILE *fl;
  char fname[MAX_STRING_LENGTH];
  char buf[MAX_STRING_LENGTH];
  char input[MAX_INPUT_LENGTH + 1];
  char tag[MAX_INPUT_LENGTH + 1];
  char tag_arguments[MAX_INPUT_LENGTH + 1];
  int val;
  struct obj_data *tmpobj = NULL;
  struct obj_data *tmpobj2;
  struct obj_data *next_obj;
  int found_begin = 0;
  int affect_counter = 0;
  int found;
  char *p;
  struct corpse_obj_save *crash_load_stack = NULL;
  struct corpse_obj_save *temp_stack = NULL;
  struct corpse_obj_save *temp_stack_next = NULL;
  int chg;
  int ovnum = 0;
  int j;

  if (!get_filename(GET_NAME(ch), fname, CRASH_FILE)) {
    return 1;
  }
  if (!(fl = fopen(fname, "r"))) {
    if (errno != ENOENT) { /* if it fails, NOT because of no file */
      sprintf(buf1, "SYSERR: READING OBJECT FILE %s (5)", fname);
      perror(buf1);
      send_to_char("\r\n********************* NOTICE *********************\r\n"
          "There was a problem loading your objects from disk.\r\n"
          "Contact a God for assistance.\r\n", ch);
    }
    sprintf(buf, "%s entering game with no equipment.", GET_NAME(ch));
    mudlog(buf, 'R', COM_IMMORT, TRUE);
    plog(buf, ch, 0);
    return 1;
  }

  while (get_line(fl, input)) {
    parse_pline(input, tag, tag_arguments);
    while ((p = strrchr(tag_arguments, '\n')) != NULL) {
      *p = '\0';
    }

    val = atoi(tag_arguments);
    switch (tag[4]) {
      case 'a':
      case 'A':
        if (strcasecmp(tag, "obj_affect_loc") == 0 && affect_counter < MAX_OBJ_AFFECT) {
          tmpobj->affected[affect_counter].location = val;
        } else if (strcasecmp(tag, "obj_affect_mod") == 0 && affect_counter < MAX_OBJ_AFFECT) {
          tmpobj->affected[affect_counter].modifier = val;
          affect_counter++;
        } else {
          sprintf(buf, "Unknown Rent-File Tag: %s", tag);
          stderr_log(buf);
        }
        break;
      case 'b':
      case 'B':
        if (strcasecmp(tag, "obj_begin") == 0) {
          if (found_begin) {
            send_to_char("\r\n********************* NOTICE *********************\r\n"
                "There was a problem loading your objects from disk.\r\n"
                "Contact a God for assistance.\r\n", ch);
            return 1;
          }
          found_begin = 1;
        } else if (strcasecmp(tag, "obj_bitvector") == 0) {
          GET_OBJ_BITV(tmpobj) = asciiflag_conv(tag_arguments);
        } else if (strcasecmp(tag, "obj_bitvector2") == 0) {
          GET_OBJ_BITV2(tmpobj) = asciiflag_conv(tag_arguments);
        } else {
          sprintf(buf, "Unknown Rent-File Tag: %s", tag);
          stderr_log(buf);
        }
        break;
      case 'e':
      case 'E':
        if (strcasecmp(tag, "obj_extra_flags") == 0) {
          GET_OBJ_EXTRA(tmpobj) = asciiflag_conv(tag_arguments);
        } else if (strcasecmp(tag, "obj_end") == 0) {
          if (ovnum >= 0) {
            if (!found_begin) {
              send_to_char("\r\n********************* NOTICE *********************\r\n"
                  "There was a problem loading your objects from disk.\r\n"
                  "Contact a God for assistance.\r\n", ch);
              return 1;
            }
            found_begin = 0;
            affect_counter = 0;

            CREATE(crash_load_stack, struct corpse_obj_save, 1);
            crash_load_stack->level = 0;
            crash_load_stack->prev = NULL;

            for (tmpobj2 = ch->carrying, found = 0; tmpobj2 && !found; tmpobj2 = next_obj) {
              next_obj = tmpobj2->next_content;
              if (tmpobj2->objnum == tmpobj->inobj) {
                obj_to_obj(tmpobj, tmpobj2);
                found = 1;
              }
              if (tmpobj2->contains) {
                crash_load_stack->next_obj = next_obj;
                CREATE(temp_stack, struct corpse_obj_save, 1);
                temp_stack->level = crash_load_stack->level + 1;
                temp_stack->prev = crash_load_stack;
                crash_load_stack = temp_stack;
                next_obj = tmpobj2->contains;
                if (tmpobj2 == next_obj) {
                  /* infinite loop */
                  next_obj = NULL;
                  continue;
                }
              } else if (next_obj == NULL && crash_load_stack->level > 0) {
                temp_stack = crash_load_stack;
                crash_load_stack = crash_load_stack->prev;
                FREE(temp_stack);
                next_obj = crash_load_stack->next_obj;
              }
            }
            for (temp_stack = crash_load_stack; temp_stack; temp_stack = temp_stack_next) {
              temp_stack_next = temp_stack->prev;
              FREE(temp_stack);
            }
            if (!found) {
              obj_to_char(tmpobj, ch);
            }
          } else {
            extract_obj(tmpobj);
            found_begin = 0;
            affect_counter = 0;
            ovnum = 0;
          }
        } else {
Example #15
0
int delete_object(obj_rnum rnum)
{
  obj_rnum i;
  zone_rnum zrnum;
  struct obj_data *obj, *tmp, *next_tmp;
  int shop, j, zone, cmd_no;

  if (rnum == NOTHING || rnum > top_of_objt)
    return NOTHING;
  
  obj = &obj_proto[rnum];

  zrnum = real_zone_by_thing(GET_OBJ_VNUM(obj));

  /* This is something you might want to read about in the logs. */
  log("GenOLC: delete_object: Deleting object #%d (%s).", GET_OBJ_VNUM(obj), obj->short_description);

  for (tmp = object_list; tmp; tmp = next_tmp) {
    next_tmp = tmp->next;
    if (tmp->item_number != obj->item_number)
      continue;

    /* extract_obj() will just axe contents. */
    if (tmp->contains) {
      struct obj_data *this_content, *next_content;
      for (this_content = tmp->contains; this_content; this_content = next_content) {
        next_content = this_content->next_content;
        if (IN_ROOM(tmp)) {
          /* Transfer stuff from object to room. */
          obj_from_obj(this_content);
          obj_to_room(this_content, IN_ROOM(tmp));
        } else if (tmp->worn_by || tmp->carried_by) {
          /* Transfer stuff from object to person inventory. */
          obj_from_char(this_content);
          obj_to_char(this_content, tmp->carried_by);
        } else if (tmp->in_obj) {
          /* Transfer stuff from object to containing object. */
          obj_from_obj(this_content);
          obj_to_obj(this_content, tmp->in_obj);
        }
      }
    }
    /* Remove from object_list, etc. - handles weightchanges, and similar. */
    extract_obj(tmp);
  }

  /* Make sure all are removed. */
  assert(obj_index[rnum].number == 0);

  /* Adjust rnums of all other objects. */
  for (tmp = object_list; tmp; tmp = tmp->next) {
    GET_OBJ_RNUM(tmp) -= (GET_OBJ_RNUM(tmp) > rnum);
  }

  for (i = rnum; i < top_of_objt; i++) {
    obj_index[i] = obj_index[i + 1];
    obj_proto[i] = obj_proto[i + 1];
    obj_proto[i].item_number = i;
  }

  top_of_objt--;
  RECREATE(obj_index, struct index_data, top_of_objt + 1);
  RECREATE(obj_proto, struct obj_data, top_of_objt + 1);

  /* Renumber notice boards. */
  for (j = 0; j < NUM_OF_BOARDS; j++)
    BOARD_RNUM(j) -= (BOARD_RNUM(j) > rnum);

  /* Renumber shop produce. */
  for (shop = 0; shop <= top_shop; shop++)
    for (j = 0; SHOP_PRODUCT(shop, j) != NOTHING; j++)
      SHOP_PRODUCT(shop, j) -= (SHOP_PRODUCT(shop, j) > rnum);

  /* Renumber zone table. */
  for (zone = 0; zone <= top_of_zone_table; zone++) {
    for (cmd_no = 0; ZCMD(zone, cmd_no).command != 'S'; cmd_no++) {
      switch (ZCMD(zone, cmd_no).command) {
      case 'P':
        if (ZCMD(zone, cmd_no).arg3 == rnum) {
          delete_command(&zone_table[zone], cmd_no);
        } else
          ZCMD(zone, cmd_no).arg3 -= (ZCMD(zone, cmd_no).arg3 > rnum);
	break;
      case 'O':
      case 'G':
      case 'E':
        if (ZCMD(zone, cmd_no).arg1 == rnum) {
          delete_command(&zone_table[zone], cmd_no);
        } else
          ZCMD(zone, cmd_no).arg1 -= (ZCMD(zone, cmd_no).arg1 > rnum);
	break;
      case 'R':
        if (ZCMD(zone, cmd_no).arg2 == rnum) {
          delete_command(&zone_table[zone], cmd_no);
        } else
          ZCMD(zone, cmd_no).arg2 -= (ZCMD(zone, cmd_no).arg2 > rnum);
	break;
      }
    }
  }

  save_objects(zrnum);

  return rnum;
}
Example #16
0
/*
 * Reset one area.
 */
void reset_area( AREA_DATA *pArea )
{
    RESET_DATA *pReset;
    CHAR_DATA *mob;
    bool last;
    int level;

    mob 	= NULL;
    last	= TRUE;
    level	= 0;
    for ( pReset = pArea->reset_first; pReset != NULL; pReset = pReset->next )
    {
	ROOM_INDEX_DATA *pRoomIndex;
	MOB_INDEX_DATA *pMobIndex;
	OBJ_INDEX_DATA *pObjIndex;
	OBJ_INDEX_DATA *pObjToIndex;
	EXIT_DATA *pexit;
	OBJ_DATA *obj;
	OBJ_DATA *obj_to;

	switch ( pReset->command )
	{
	default:
	    bug( "Reset_area: bad command %c.", pReset->command );
	    break;

	case 'M':
	    if ( ( pMobIndex = get_mob_index( pReset->arg1 ) ) == NULL )
	    {
		bug( "Reset_area: 'M': bad vnum %d.", pReset->arg1 );
		continue;
	    }

	    if ( ( pRoomIndex = get_room_index( pReset->arg3 ) ) == NULL )
	    {
		bug( "Reset_area: 'R': bad vnum %d.", pReset->arg3 );
		continue;
	    }

	    level = URANGE( 0, pMobIndex->level - 2, LEVEL_HERO );
	    if ( pMobIndex->count >= pReset->arg2 )
	    {
		last = FALSE;
		break;
	    }

	    mob = create_mobile( pMobIndex );

	    /*
	     * Check for pet shop.
	     */
	    {
		ROOM_INDEX_DATA *pRoomIndexPrev;
		pRoomIndexPrev = get_room_index( pRoomIndex->vnum - 1 );
		if ( pRoomIndexPrev != NULL
		&&   IS_SET(pRoomIndexPrev->room_flags, ROOM_PET_SHOP) )
		    SET_BIT(mob->act, ACT_PET);
	    }

	    if ( room_is_dark( pRoomIndex ) )
		SET_BIT(mob->affected_by, AFF_INFRARED);

	    char_to_room( mob, pRoomIndex );
	    level = URANGE( 0, mob->level - 2, LEVEL_HERO );
	    last  = TRUE;
	    break;

	case 'O':
	    if ( ( pObjIndex = get_obj_index( pReset->arg1 ) ) == NULL )
	    {
		bug( "Reset_area: 'O': bad vnum %d.", pReset->arg1 );
		continue;
	    }

	    if ( ( pRoomIndex = get_room_index( pReset->arg3 ) ) == NULL )
	    {
		bug( "Reset_area: 'R': bad vnum %d.", pReset->arg3 );
		continue;
	    }

	    if ( pArea->nplayer > 0
	    ||   count_obj_list( pObjIndex, pRoomIndex->contents ) > 0 )
	    {
		last = FALSE;
		break;
	    }

	    obj       = create_object( pObjIndex, number_fuzzy( level ) );
	    obj->cost = 0;
	    obj_to_room( obj, pRoomIndex );
	    last = TRUE;
	    break;

	case 'P':
	    if ( ( pObjIndex = get_obj_index( pReset->arg1 ) ) == NULL )
	    {
		bug( "Reset_area: 'P': bad vnum %d.", pReset->arg1 );
		continue;
	    }

	    if ( ( pObjToIndex = get_obj_index( pReset->arg3 ) ) == NULL )
	    {
		bug( "Reset_area: 'P': bad vnum %d.", pReset->arg3 );
		continue;
	    }

	    if ( pArea->nplayer > 0
	    || ( obj_to = get_obj_type( pObjToIndex ) ) == NULL
	    ||   obj_to->in_room == NULL
	    ||   count_obj_list( pObjIndex, obj_to->contains ) > 0 )
	    {
		last = FALSE;
		break;
	    }
	    
	    obj = create_object( pObjIndex, number_fuzzy( obj_to->level ) );
	    obj_to_obj( obj, obj_to );
	    last = TRUE;
	    break;

	case 'G':
	case 'E':
	    if ( ( pObjIndex = get_obj_index( pReset->arg1 ) ) == NULL )
	    {
		bug( "Reset_area: 'E' or 'G': bad vnum %d.", pReset->arg1 );
		continue;
	    }

	    if ( !last )
		break;

	    if ( mob == NULL )
	    {
		bug( "Reset_area: 'E' or 'G': null mob for vnum %d.",
		    pReset->arg1 );
		last = FALSE;
		break;
	    }

	    if ( mob->pIndexData->pShop != NULL )
	    {
		int olevel;

		switch ( pObjIndex->item_type )
		{
		default:		olevel = 0;                      break;
		case ITEM_PILL:		olevel = number_range(  0, 10 ); break;
		case ITEM_POTION:	olevel = number_range(  0, 10 ); break;
		case ITEM_SCROLL:	olevel = number_range(  5, 15 ); break;
		case ITEM_WAND:		olevel = number_range( 10, 20 ); break;
		case ITEM_STAFF:	olevel = number_range( 15, 25 ); break;
		case ITEM_ARMOR:	olevel = number_range(  5, 15 ); break;
		case ITEM_WEAPON:	olevel = number_range(  5, 15 ); break;
		}

		obj = create_object( pObjIndex, olevel );
		SET_BIT( obj->extra_flags, ITEM_INVENTORY );
	    }
	    else
	    {
		obj = create_object( pObjIndex, number_fuzzy( level ) );
	    }
	    obj_to_char( obj, mob );
	    if ( pReset->command == 'E' )
		equip_char( mob, obj, pReset->arg3 );
	    last = TRUE;
	    break;

	case 'D':
	    if ( ( pRoomIndex = get_room_index( pReset->arg1 ) ) == NULL )
	    {
		bug( "Reset_area: 'D': bad vnum %d.", pReset->arg1 );
		continue;
	    }

	    if ( ( pexit = pRoomIndex->exit[pReset->arg2] ) == NULL )
		break;

	    switch ( pReset->arg3 )
	    {
	    case 0:
		REMOVE_BIT( pexit->exit_info, EX_CLOSED );
		REMOVE_BIT( pexit->exit_info, EX_LOCKED );
		break;

	    case 1:
		SET_BIT(    pexit->exit_info, EX_CLOSED );
		REMOVE_BIT( pexit->exit_info, EX_LOCKED );
		break;

	    case 2:
		SET_BIT(    pexit->exit_info, EX_CLOSED );
		SET_BIT(    pexit->exit_info, EX_LOCKED );
		break;
	    }

	    last = TRUE;
	    break;

	case 'R':
	    if ( ( pRoomIndex = get_room_index( pReset->arg1 ) ) == NULL )
	    {
		bug( "Reset_area: 'R': bad vnum %d.", pReset->arg1 );
		continue;
	    }

	    {
		int d0;
		int d1;

		for ( d0 = 0; d0 < pReset->arg2 - 1; d0++ )
		{
		    d1                   = number_range( d0, pReset->arg2-1 );
		    pexit                = pRoomIndex->exit[d0];
		    pRoomIndex->exit[d0] = pRoomIndex->exit[d1];
		    pRoomIndex->exit[d1] = pexit;
		}
	    }
	    break;
	}
    }

    return;
}
Example #17
0
int handle_obj(struct obj_data *temp, struct char_data *ch, int locate, struct obj_data **cont_row)
{
  int j;
  struct obj_data *obj1;

  if (!temp)  /* this should never happen, but.... */
    return (0);

  auto_equip(ch, temp, locate);

  /* 
     what to do with a new loaded item:

     if there's a list with <locate> less than 1 below this:
     (equipped items are assumed to have <locate>==0 here) then its
     container has disappeared from the file   *gasp*
     -> put all the list back to ch's inventory
     if there's a list of contents with <locate> 1 below this:
     check if it's a container
     - if so: get it from ch, fill it, and give it back to ch (this way the
     container has its correct weight before modifying ch)
     - if not: the container is missing -> put all the list to ch's inventory

     for items with negative <locate>:
     if there's already a list of contents with the same <locate> put obj to it
     if not, start a new list

     Confused? Well maybe you can think of some better text to be put here ...

     since <locate> for contents is < 0 the list indices are switched to
     non-negative
  */

  if (locate > 0) { /* item equipped */

    for (j = MAX_BAG_ROWS-1;j > 0;j--)
      if (cont_row[j]) { /* no container -> back to ch's inventory */
        for (;cont_row[j];cont_row[j] = obj1) {
          obj1 = cont_row[j]->next_content;
          obj_to_char(cont_row[j], ch);
        }
        cont_row[j] = NULL;
      }
    if (cont_row[0]) { /* content list existing */
      if (GET_OBJ_TYPE(temp) == ITEM_CONTAINER) {
        /* rem item ; fill ; equip again */
        temp = unequip_char(ch, locate-1);
        temp->contains = NULL; /* should be empty - but who knows */
        for (;cont_row[0];cont_row[0] = obj1) {
          obj1 = cont_row[0]->next_content;
          obj_to_obj(cont_row[0], temp);
        }
        equip_char(ch, temp, locate-1);
      } else { /* object isn't container -> empty content list */
        for (;cont_row[0];cont_row[0] = obj1) {
          obj1 = cont_row[0]->next_content;
          obj_to_char(cont_row[0], ch);
        }
        cont_row[0] = NULL;
      }
    }
  } else { /* locate <= 0 */
    for (j = MAX_BAG_ROWS-1;j > -locate;j--)
      if (cont_row[j]) { /* no container -> back to ch's inventory */
        for (;cont_row[j];cont_row[j] = obj1) {
          obj1 = cont_row[j]->next_content;
          obj_to_char(cont_row[j], ch);
        } 
        cont_row[j] = NULL;
      }

    if (j == -locate && cont_row[j]) { /* content list existing */
      if (GET_OBJ_TYPE(temp) == ITEM_CONTAINER) {
        /* take item ; fill ; give to char again */
        obj_from_char(temp);
        temp->contains = NULL;
        for (;cont_row[j];cont_row[j] = obj1) {
          obj1 = cont_row[j]->next_content;
          obj_to_obj(cont_row[j], temp);
        }
        obj_to_char(temp, ch); /* add to inv first ... */
      } else { /* object isn't container -> empty content list */
        for (;cont_row[j];cont_row[j] = obj1) {
          obj1 = cont_row[j]->next_content;
          obj_to_char(cont_row[j], ch);
        }
        cont_row[j] = NULL;
      }
    }

    if (locate < 0 && locate >= -MAX_BAG_ROWS) {
      /* let obj be part of content list
         but put it at the list's end thus having the items
         in the same order as before renting */
      obj_from_char(temp);
      if ((obj1 = cont_row[-locate-1])) {
        while (obj1->next_content)
          obj1 = obj1->next_content;
        obj1->next_content = temp;
      } else
        cont_row[-locate-1] = temp;
    }
  } /* locate less than zero */

  return (1);
}
Example #18
0
/*
 * Reset one room.
 */
void reset_room( ROOM_INDEX_DATA * room )
{
	RESET_DATA *pReset, *tReset, *gReset;
	OBJ_DATA *nestmap[MAX_NEST];
	CHAR_DATA *mob;
	OBJ_DATA *obj, *lastobj, *to_obj;
	ROOM_INDEX_DATA *pRoomIndex = NULL;
	MOB_INDEX_DATA *pMobIndex = NULL;
	OBJ_INDEX_DATA *pObjIndex = NULL, *pObjToIndex;
	EXIT_DATA *pexit;
	const char *filename = room->area->filename;
	int level = 0, n, num = 0, lastnest, onreset = 0;

	mob = NULL;
	obj = NULL;
	lastobj = NULL;
	if ( !room->first_reset )
		return;
	level = 0;
	for ( pReset = room->first_reset; pReset; pReset = pReset->next )
	{
		++onreset;
		switch ( pReset->command )
		{
			default:
				bug( "%s: %s: bad command %c.", __FUNCTION__, filename, pReset->command );
				break;

			case 'M':
				if ( !( pMobIndex = get_mob_index( pReset->arg1 ) ) )
				{
					bug( "%s: %s: 'M': bad mob vnum %d.", __FUNCTION__, filename, pReset->arg1 );
					continue;
				}
				if ( !( pRoomIndex = get_room_index( pReset->arg3 ) ) )
				{
					bug( "%s: %s: 'M': bad room vnum %d.", __FUNCTION__, filename, pReset->arg3 );
					continue;
				}
				if ( !pReset->sreset )
				{
					mob = NULL;
					break;
				}
				mob = create_mobile( pMobIndex );
				{
					ROOM_INDEX_DATA *pRoomPrev = get_room_index( pReset->arg3 - 1 );

					if ( pRoomPrev && xIS_SET( pRoomPrev->room_flags, ROOM_PET_SHOP ) )
						xSET_BIT( mob->act, ACT_PET );
				}
				if ( room_is_dark( pRoomIndex ) )
					xSET_BIT( mob->affected_by, AFF_INFRARED );
				mob->resetvnum = pRoomIndex->vnum;
				mob->resetnum = onreset;
				pReset->sreset = false;
				char_to_room( mob, pRoomIndex );
				level = URANGE( 0, mob->level - 2, LEVEL_AVATAR );

				if ( pReset->first_reset )
				{
					for ( tReset = pReset->first_reset; tReset; tReset = tReset->next_reset )
					{
						++onreset;
						switch ( tReset->command )
						{
							case 'G':
							case 'E':
								if ( !( pObjIndex = get_obj_index( tReset->arg1 ) ) )
								{
									bug( "%s: %s: 'E' or 'G': bad obj vnum %d.", __FUNCTION__, filename, tReset->arg1 );
									continue;
								}
								if ( !mob )
								{
									lastobj = NULL;
									break;
								}

								if ( mob->pIndexData->pShop )
								{
									int olevel = generate_itemlevel( room->area, pObjIndex );

									obj = create_object( pObjIndex, olevel );
									xSET_BIT( obj->extra_flags, ITEM_INVENTORY );
								}
								else
									obj = create_object( pObjIndex, number_fuzzy( level ) );
								obj->level = URANGE( 0, obj->level, LEVEL_AVATAR );
								obj = obj_to_char( obj, mob );
								if ( tReset->command == 'E' )
								{
									if ( obj->carried_by != mob )
									{
										bug( "'E' reset: can't give object %d to mob %d.", obj->pIndexData->vnum, mob->pIndexData->vnum );
										break;
									}
									equip_char( mob, obj, tReset->arg3 );
								}
								for ( n = 0; n < MAX_NEST; n++ )
									nestmap[n] = NULL;
								nestmap[0] = obj;
								lastobj = nestmap[0];
								lastnest = 0;

								if ( tReset->first_reset )
								{
									for ( gReset = tReset->first_reset; gReset; gReset = gReset->next_reset )
									{
										int iNest;

										to_obj = lastobj;

										++onreset;
										switch ( gReset->command )
										{
											case 'H':
												if ( !lastobj )
													break;
												xSET_BIT( lastobj->extra_flags, ITEM_HIDDEN );
												break;

											case 'P':
												if ( !( pObjIndex = get_obj_index( gReset->arg1 ) ) )
												{
													bug( "%s: %s: 'P': bad obj vnum %d.", __FUNCTION__, filename, gReset->arg1 );
													continue;
												}
												iNest = gReset->extra;

												if ( !( pObjToIndex = get_obj_index( gReset->arg3 ) ) )
												{
													bug( "%s: %s: 'P': bad objto vnum %d.", __FUNCTION__, filename, gReset->arg3 );
													continue;
												}
												if ( iNest >= MAX_NEST )
												{
													bug( "%s: %s: 'P': Exceeded nesting limit of %d", __FUNCTION__, filename, MAX_NEST );
													obj = NULL;
													break;
												}
												if ( count_obj_list( pObjIndex, to_obj->first_content ) > 0 )
												{
													obj = NULL;
													break;
												}

												if ( iNest < lastnest )
													to_obj = nestmap[iNest];
												else if ( iNest == lastnest )
													to_obj = nestmap[lastnest];
												else
													to_obj = lastobj;

												obj = create_object( pObjIndex, number_fuzzy( UMAX( generate_itemlevel( room->area, pObjIndex ), to_obj->level ) ) );
												if ( num > 1 )
													pObjIndex->count += ( num - 1 );
												obj->count = gReset->arg2;
												obj->level = UMIN( obj->level, LEVEL_AVATAR );
												obj->count = gReset->arg2;
												obj_to_obj( obj, to_obj );
												if ( iNest > lastnest )
												{
													nestmap[iNest] = to_obj;
													lastnest = iNest;
												}
												lastobj = obj;
												/*
												 * Hackish fix for nested puts 
												 */
												if ( gReset->arg3 == OBJ_VNUM_MONEY_ONE )
													gReset->arg3 = to_obj->pIndexData->vnum;
												break;
										}
									}
								}
								break;
						}
					}
				}
				break;

			case 'O':
				if ( !( pObjIndex = get_obj_index( pReset->arg1 ) ) )
				{
					bug( "%s: %s: 'O': bad obj vnum %d.", __FUNCTION__, filename, pReset->arg1 );
					continue;
				}
				if ( !( pRoomIndex = get_room_index( pReset->arg3 ) ) )
				{
					bug( "%s: %s: 'O': bad room vnum %d.", __FUNCTION__, filename, pReset->arg3 );
					continue;
				}

				if ( count_obj_list( pObjIndex, pRoomIndex->first_content ) < 1 )
				{
					obj = create_object( pObjIndex, number_fuzzy( generate_itemlevel( room->area, pObjIndex ) ) );
					if ( num > 1 )
						pObjIndex->count += ( num - 1 );
					obj->count = pReset->arg2;
					obj->level = UMIN( obj->level, LEVEL_AVATAR );
					obj->cost = 0;
					obj_to_room( obj, pRoomIndex );
				}
				else
				{
					int x;

					if ( !( obj = get_obj_room( pObjIndex, pRoomIndex ) ) )
					{
						obj = NULL;
						lastobj = NULL;
						break;
					}
					obj->extra_flags = pObjIndex->extra_flags;
					for ( x = 0; x < 6; ++x )
						obj->value[x] = pObjIndex->value[x];
				}
				for ( n = 0; n < MAX_NEST; n++ )
					nestmap[n] = NULL;
				nestmap[0] = obj;
				lastobj = nestmap[0];
				lastnest = 0;
				if ( pReset->first_reset )
				{
					for ( tReset = pReset->first_reset; tReset; tReset = tReset->next_reset )
					{
						int iNest;

						to_obj = lastobj;
						++onreset;

						switch ( tReset->command )
						{
							case 'H':
								if ( !lastobj )
									break;
								xSET_BIT( lastobj->extra_flags, ITEM_HIDDEN );
								break;

							case 'T':
								if ( !IS_SET( tReset->extra, TRAP_OBJ ) )
								{
									bug( "%s: Room reset found on object reset list", __FUNCTION__ );
									break;
								}
								else
								{
									/*
									 * We need to preserve obj for future 'T' checks 
									 */
									OBJ_DATA *pobj;

									if ( tReset->arg3 > 0 )
									{
										if ( !( pObjToIndex = get_obj_index( tReset->arg3 ) ) )
										{
											bug( "%s: %s: 'T': bad objto vnum %d.", __FUNCTION__, filename, tReset->arg3 );
											continue;
										}
										if ( room->area->nplayer > 0 || !( to_obj = get_obj_type( pObjToIndex ) ) ||
											( to_obj->carried_by && !IS_NPC( to_obj->carried_by ) ) || is_trapped( to_obj ) )
											break;
									}
									else
									{
										if ( !lastobj || !obj )
											break;
										to_obj = obj;
									}
									pobj = make_trap( tReset->arg2, tReset->arg1, number_fuzzy( to_obj->level ), tReset->extra );
									obj_to_obj( pobj, to_obj );
								}
								break;

							case 'P':
								if ( !( pObjIndex = get_obj_index( tReset->arg1 ) ) )
								{
									bug( "%s: %s: 'P': bad obj vnum %d.", __FUNCTION__, filename, tReset->arg1 );
									continue;
								}
								iNest = tReset->extra;

								if ( !( pObjToIndex = get_obj_index( tReset->arg3 ) ) )
								{
									bug( "%s: %s: 'P': bad objto vnum %d.", __FUNCTION__, filename, tReset->arg3 );
									continue;
								}

								if ( iNest >= MAX_NEST )
								{
									bug( "%s: %s: 'P': Exceeded nesting limit of %d. Room %d.", __FUNCTION__, filename, MAX_NEST, room->vnum );
									obj = NULL;
									break;
								}

								if ( count_obj_list( pObjIndex, to_obj->first_content ) > 0 )
								{
									obj = NULL;
									break;
								}
								if ( iNest < lastnest )
									to_obj = nestmap[iNest];
								else if ( iNest == lastnest )
									to_obj = nestmap[lastnest];
								else
									to_obj = lastobj;

								obj = create_object( pObjIndex, number_fuzzy( UMAX( generate_itemlevel( room->area, pObjIndex ), to_obj->level ) ) );
								if ( num > 1 )
									pObjIndex->count += ( num - 1 );
								obj->count = tReset->arg2;
								obj->level = UMIN( obj->level, LEVEL_AVATAR );
								obj->count = tReset->arg2;
								obj_to_obj( obj, to_obj );
								if ( iNest > lastnest )
								{
									nestmap[iNest] = to_obj;
									lastnest = iNest;
								}
								lastobj = obj;
								/*
								 * Hackish fix for nested puts 
								 */
								if ( tReset->arg3 == OBJ_VNUM_MONEY_ONE )
									tReset->arg3 = to_obj->pIndexData->vnum;
								break;
						}
					}
				}
				break;

			case 'T':
				if ( IS_SET( pReset->extra, TRAP_OBJ ) )
				{
					bug( "%s: Object trap found in room %d reset list", __FUNCTION__, room->vnum );
					break;
				}
				else
				{
					if ( !( pRoomIndex = get_room_index( pReset->arg3 ) ) )
					{
						bug( "%s: %s: 'T': bad room %d.", __FUNCTION__, filename, pReset->arg3 );
						continue;
					}
					if ( room->area->nplayer > 0 || count_obj_list( get_obj_index( OBJ_VNUM_TRAP ), pRoomIndex->first_content ) > 0 )
						break;
					to_obj = make_trap( pReset->arg1, pReset->arg1, 10, pReset->extra );
					obj_to_room( to_obj, pRoomIndex );
				}
				break;

			case 'D':
				if ( !( pRoomIndex = get_room_index( pReset->arg1 ) ) )
				{
					bug( "%s: %s: 'D': bad room vnum %d.", __FUNCTION__, filename, pReset->arg1 );
					continue;
				}
				if ( !( pexit = get_exit( pRoomIndex, pReset->arg2 ) ) )
					break;
				switch ( pReset->arg3 )
				{
					case 0:
						REMOVE_BIT( pexit->exit_info, EX_CLOSED );
						REMOVE_BIT( pexit->exit_info, EX_LOCKED );
						break;
					case 1:
						SET_BIT( pexit->exit_info, EX_CLOSED );
						REMOVE_BIT( pexit->exit_info, EX_LOCKED );
						if ( IS_SET( pexit->exit_info, EX_xSEARCHABLE ) )
							SET_BIT( pexit->exit_info, EX_SECRET );
						break;
					case 2:
						SET_BIT( pexit->exit_info, EX_CLOSED );
						SET_BIT( pexit->exit_info, EX_LOCKED );
						if ( IS_SET( pexit->exit_info, EX_xSEARCHABLE ) )
							SET_BIT( pexit->exit_info, EX_SECRET );
						break;
				}
				break;

			case 'R':
				if ( !( pRoomIndex = get_room_index( pReset->arg1 ) ) )
				{
					bug( "%s: %s: 'R': bad room vnum %d.", __FUNCTION__, filename, pReset->arg1 );
					continue;
				}
				randomize_exits( pRoomIndex, pReset->arg2 - 1 );
				break;
		}
	}
}
Example #19
0
void make_corpse(struct char_data *ch)
{
	struct obj_data *corpse, *o;
	struct obj_data *money;	
	char buf[MAX_STRING_LENGTH];
	int i;

	char *strdup(char *source);
	struct obj_data *create_money( int amount );

	CREATE(corpse, struct obj_data, 1);
	clear_object(corpse);

	
	corpse->item_number = NOWHERE;
	corpse->in_room = NOWHERE;
	corpse->name = strdup("corpse");

	sprintf(buf, "Corpse of %s is lying here.", 
	  (IS_NPC(ch) ? ch->player.short_descr : GET_NAME(ch)));
	corpse->description = strdup(buf);

	sprintf(buf, "Corpse of %s",
	  (IS_NPC(ch) ? ch->player.short_descr : GET_NAME(ch)));
	corpse->short_description = strdup(buf);

	corpse->contains = ch->carrying;
	if ( (GET_GOLD(ch)>0) &&
        ( IS_NPC(ch) || (ch->desc) ) )
	{
		money = create_money(GET_GOLD(ch));
		GET_GOLD(ch)=0;
		obj_to_obj(money,corpse);
	}

	corpse->obj_flags.type_flag = ITEM_CONTAINER;
	corpse->obj_flags.wear_flags = ITEM_TAKE;
	corpse->obj_flags.value[0] = 0; /* You can't store stuff in a corpse */
	corpse->obj_flags.value[3] = 1; /* corpse identifyer */
	corpse->obj_flags.weight = GET_WEIGHT(ch)+IS_CARRYING_W(ch);
	corpse->obj_flags.cost_per_day = 100000;
	if (IS_NPC(ch))
		corpse->obj_flags.timer = MAX_NPC_CORPSE_TIME;
	else
		corpse->obj_flags.timer = MAX_PC_CORPSE_TIME;

	for (i=0; i<MAX_WEAR; i++)
		if (ch->equipment[i])
			obj_to_obj(unequip_char(ch, i), corpse);

	ch->carrying = 0;
	IS_CARRYING_N(ch) = 0;
	IS_CARRYING_W(ch) = 0;

	corpse->next = object_list;
	object_list = corpse;

	for(o = corpse->contains; o; o->in_obj = corpse, o = o->next_content);
	object_list_new_owner(corpse, 0);

	obj_to_room(corpse, ch->in_room);
}
Example #20
0
void make_corpse(struct char_data *ch)
{
  char buf2[MAX_NAME_LENGTH + 64];
  struct obj_data *corpse, *o;
  struct obj_data *money;
  int i;

  corpse = create_obj();

  corpse->item_number = NOTHING;
  IN_ROOM(corpse) = NOWHERE;
  corpse->name = strdup("corpse");

  snprintf(buf2, sizeof(buf2), "The corpse of %s is lying here.", GET_NAME(ch));
  corpse->description = strdup(buf2);

  snprintf(buf2, sizeof(buf2), "the corpse of %s", GET_NAME(ch));
  corpse->short_description = strdup(buf2);

  GET_OBJ_TYPE(corpse) = ITEM_CONTAINER;
  GET_OBJ_WEAR(corpse) = ITEM_WEAR_TAKE;
  GET_OBJ_EXTRA(corpse) = ITEM_NODONATE;
  GET_OBJ_VAL(corpse, 0) = 0;	/* You can't store stuff in a corpse */
  GET_OBJ_VAL(corpse, 3) = 1;	/* corpse identifier */
  GET_OBJ_WEIGHT(corpse) = GET_WEIGHT(ch) + IS_CARRYING_W(ch);
  GET_OBJ_RENT(corpse) = 100000;
  if (IS_NPC(ch))
    GET_OBJ_TIMER(corpse) = max_npc_corpse_time;
  else
    GET_OBJ_TIMER(corpse) = max_pc_corpse_time;

  /* transfer character's inventory to the corpse */
  corpse->contains = ch->carrying;
  for (o = corpse->contains; o != NULL; o = o->next_content)
    o->in_obj = corpse;
  object_list_new_owner(corpse, NULL);

  /* transfer character's equipment to the corpse */
  for (i = 0; i < NUM_WEARS; i++)
    if (GET_EQ(ch, i))
      obj_to_obj(unequip_char(ch, i), corpse);

  /* transfer gold */
  if (GET_GOLD(ch) > 0) {
    /*
     * following 'if' clause added to fix gold duplication loophole
     * The above line apparently refers to the old "partially log in,
     * kill the game character, then finish login sequence" duping
     * bug. The duplication has been fixed (knock on wood) but the
     * test below shall live on, for a while. -gg 3/3/2002
     */
    if (IS_NPC(ch) || ch->desc) {
      money = create_money(GET_GOLD(ch));
      obj_to_obj(money, corpse);
    }
    GET_GOLD(ch) = 0;
  }
  ch->carrying = NULL;
  IS_CARRYING_N(ch) = 0;
  IS_CARRYING_W(ch) = 0;

  obj_to_room(corpse, IN_ROOM(ch));
}
Example #21
0
void do_buy( CHAR_DATA * ch, char *argument )
{
  char arg[MAX_INPUT_LENGTH];
  int maxgold = 0;

  argument = one_argument( argument, arg );

  if( arg[0] == '\0' )
  {
    send_to_char( "Buy what?\r\n", ch );
    return;
  }

  /* in case of different shop types */
  {
    CHAR_DATA *keeper = NULL;
    OBJ_DATA *obj = NULL;
    int cost = 0;
    int noi = 1;		/* Number of items */
    short mnoi = 20;		/* Max number of items to be bought at once */

    if( ( keeper = find_keeper( ch ) ) == NULL )
      return;

    maxgold = keeper->top_level * 10;

    if( is_number( arg ) )
    {
      noi = atoi( arg );
      argument = one_argument( argument, arg );

      if( noi > mnoi )
      {
	act( AT_TELL, "$n tells you 'I don't sell that many items at"
	    " once.'", keeper, NULL, ch, TO_VICT );
	ch->reply = keeper;
	return;
      }
    }

    obj = get_obj_carry( keeper, arg );

    if( !obj && arg[0] == '#' )
    {
      int onum = 0, oref = atoi( arg + 1 );
      bool ofound = FALSE;

      for( obj = keeper->last_carrying; obj; obj = obj->prev_content )
      {
	if( obj->wear_loc == WEAR_NONE && can_see_obj( ch, obj ) )
	  onum++;

	if( onum == oref )
	{
	  ofound = TRUE;
	  break;
	}
	else if( onum > oref )
	  break;
      }
      if( !ofound )
	obj = NULL;
    }

    cost = ( get_cost( ch, keeper, obj, TRUE ) * noi );
    if( cost <= 0 || !can_see_obj( ch, obj ) )
    {
      act( AT_TELL, "$n tells you 'I don't sell that -- try 'list'.'",
	  keeper, NULL, ch, TO_VICT );
      ch->reply = keeper;
      return;
    }

    if( !IS_OBJ_STAT( obj, ITEM_INVENTORY ) && ( noi > 1 ) )
    {
      char buf[MAX_STRING_LENGTH];
      snprintf( buf, MAX_STRING_LENGTH, "%s", "laugh" );
      interpret( keeper, buf );
      act( AT_TELL, "$n tells you 'I don't have enough of those in stock"
	  " to sell more than one at a time.'", keeper, NULL, ch,
	  TO_VICT );
      ch->reply = keeper;
      return;
    }

    if( ch->gold < cost )
    {
      act( AT_TELL, "$n tells you 'You can't afford to buy $p.'",
	  keeper, obj, ch, TO_VICT );
      ch->reply = keeper;
      return;
    }

    if( IS_SET( obj->extra_flags, ITEM_PROTOTYPE ) && IS_IMMORTAL( ch ) )
    {
      act( AT_TELL,
	  "$n tells you 'This is a only a prototype!  I can't sell you that...'",
	  keeper, NULL, ch, TO_VICT );
      ch->reply = keeper;
      return;
    }

    if( ch->carry_number + get_obj_number( obj ) > can_carry_n( ch ) )
    {
      send_to_char( "You can't carry that many items.\r\n", ch );
      return;
    }

    if( ch->carry_weight + ( get_obj_weight( obj ) * noi )
	+ ( noi > 1 ? 2 : 0 ) > can_carry_w( ch ) )
    {
      send_to_char( "You can't carry that much weight.\r\n", ch );
      return;
    }

    if( noi == 1 )
    {
      if( !IS_OBJ_STAT( obj, ITEM_INVENTORY ) )
	separate_obj( obj );
      act( AT_ACTION, "$n buys $p.", ch, obj, NULL, TO_ROOM );
      act( AT_ACTION, "You buy $p.", ch, obj, NULL, TO_CHAR );
    }
    else
    {
      sprintf( arg, "$n buys %d $p%s.", noi,
	  ( obj->short_descr[strlen( obj->short_descr ) - 1] == 's'
	    ? "" : "s" ) );
      act( AT_ACTION, arg, ch, obj, NULL, TO_ROOM );
      sprintf( arg, "You buy %d $p%s.", noi,
	  ( obj->short_descr[strlen( obj->short_descr ) - 1] == 's'
	    ? "" : "s" ) );
      act( AT_ACTION, arg, ch, obj, NULL, TO_CHAR );
      act( AT_ACTION, "$N puts them into a bag and hands it to you.",
	  ch, NULL, keeper, TO_CHAR );
    }

    ch->gold -= cost;
    keeper->gold += cost;

    if( keeper->gold > maxgold )
    {
      keeper->gold = maxgold / 2;
      act( AT_ACTION, "$n puts some credits into a large safe.", keeper,
	  NULL, NULL, TO_ROOM );
    }

    if( IS_OBJ_STAT( obj, ITEM_INVENTORY ) )
    {
      OBJ_DATA *buy_obj = create_object( obj->pIndexData );
      OBJ_DATA *bag = NULL;

      /*
       * Due to grouped objects and carry limitations in SMAUG
       * The shopkeeper gives you a bag with multiple-buy,
       * and also, only one object needs be created with a count
       * set to the number bought.                -Thoric
       */
      if( noi > 1 )
      {
	bag = create_object( get_obj_index( OBJ_VNUM_SHOPPING_BAG ) );
	/* perfect size bag ;) */
	bag->value[0] = bag->weight + ( buy_obj->weight * noi );
	buy_obj->count = noi;
	obj->pIndexData->count += ( noi - 1 );
	numobjsloaded += ( noi - 1 );
	obj_to_obj( buy_obj, bag );
	obj_to_char( bag, ch );
      }
      else
	obj_to_char( buy_obj, ch );
    }
    else
    {
      obj_from_char( obj );
      obj_to_char( obj, ch );
    }

    return;
  }
}
Example #22
0
/*
** Update PCs, NPCs, and objects
*/
void
point_update( void )
{
    int slot;

    void update_char_objects(CharData * ch); /* handler.c */
    void extract_obj(ObjData * obj);	     /* handler.c */
    void update_char_quests(CharData * ch);  /* quest.c */
    CharData *i, *next_char;
    ObjData  *j, *next_thing, *jj, *next_thing2, *debugnext;
    int loopvar;

    /* characters */
    for( i = character_list; i; i = next_char )
    {
        next_char = i->next;

        // state flags
        i->tickstate = 0;

        /* dismount anyone who's gotten separated from their steed */
        /* Note that it's superfluous to check for both rider AND mount */
        if (i->rider && i->rider->in_room != i->in_room) {
            i->rider->mount = NULL;
            i->rider = NULL;
        }

        /* Prayer timer */
        if (i->player_specials->saved.prayer_time > 0) {
            if (i->player_specials->saved.prayer_time == 1) {
                i->player_specials->saved.prayer_time = 0;
                send_to_char("Your prayers will be heard once again.\r\n", i);
            } else
                i->player_specials->saved.prayer_time -= 1;
        }

        for(slot = 0; slot<4; slot++) {
            if (COOLDOWN(i, slot) ) {
                COOLDOWN(i, slot) -= 1;
                if (!COOLDOWN(i, slot) ) {
                    switch( GET_CLASS(i) ) {
                        case CLASS_DEATH_KNIGHT:
                            break;
                        case CLASS_SOLAMNIC_KNIGHT:
                            break;
                        case CLASS_MAGIC_USER:
                            break;
                        case CLASS_SHADOW_DANCER:
                            if(slot == SLOT_SLIPPERY_MIND)
                                break;
                            else if(slot == SLOT_NODESHIFT)
                                sendChar(i, "You may once again shift your spectrum.\r\n");
                            else sendChar(i, "ERROR!\r\n");
                            break;
                        case CLASS_THIEF:
                            if(slot== SLOT_BLACKJACK) {
                                sendChar(i, "You are able to use blackjack again.\r\n");
                                break;
                            }
                            else sendChar(i, "ERROR!\r\n");
                        case CLASS_ASSASSIN:
                            if(slot == SLOT_DETERRENCE)
                                sendChar(i, "You are able to use deterrence again.\r\n");
                            else sendChar(i, "ERROR!\r\n");
                            break;
                        case CLASS_CLERIC:
                            if(slot == SLOT_SHADOW_FORM)
                                sendChar(i, "You are ready to enter shadow form again..\r\n");
                            else sendChar(i, "ERROR!\r\n");
                        case CLASS_WARRIOR:
                            if(slot == SLOT_REDOUBT)
                                sendChar(i, "You can shield yourself again.\r\n");
                            else if(slot == SLOT_COMMANDING_SHOUT)
                                sendChar(i, "You can shout commands again.\r\n");
                            else sendChar(i, "ERROR!\r\n");
                            break;
                        case CLASS_SHOU_LIN:
                            break;
                        case CLASS_RANGER:
                            break;
                        case CLASS_NECROMANCER:
                            if(slot == SLOT_QUICKEN)
                                sendChar(i, "You may once again rise from the grave.\r\n");
                            else if(slot == SLOT_METAMORPHOSIS)
                                sendChar(i, "You may once again metamorphisize.\r\n");
                            else sendChar(i, "ERROR!\r\n");
                            break;

                        default:
                            sendChar(i, "ERROR!\r\n");
                            break;
                    }
                }
            }
        }

        if( IS_AFFECTED(i, AFF_PLAGUE )) infectious(i);

        if( !IS_NPC(i) )
        {
            update_char_objects(i);
            if( GET_LEVEL(i) < LVL_GOD )
                check_idling(i);
            update_char_quests(i);
        }
        gain_condition(i, HUNGER, IS_AFFECTED(i, AFF_REGENERATE)? -2:-1);
        gain_condition(i, DRUNK, -1);

        /* Amara get thirsty in different ways */
        if (IS_AMARA(i)) {
            if (IN_ROOM(i) >= 0 && IN_ROOM(i) <= top_of_world) {
                switch (SECT(IN_ROOM(i))) {
                    case SECT_WATER_SWIM:
                    case SECT_WATER_NOSWIM:
                        gain_condition(i, THIRST, 1);
                        break;
                    case SECT_UNDERWATER:
                    case SECT_UNDERWATER_RIVER:
                        gain_condition(i, THIRST, 24);
                        break;
                    default:
                        gain_condition(i, THIRST, -2);
                        break;
                }
            } else gain_condition(i, THIRST, -2);
        } else gain_condition(i, THIRST, -1);
    }/* for */

    debugnext = NULL;
    /* objects */
    for( j = object_list; j; j = next_thing )
    {
        next_thing = j->next;	/* Next in object list */
        debugnext = j;		// we didn't crash if we got here

        if( IS_SET_AR( j->obj_flags.extra_flags, ITEM_TIMED ))
        {
            if( GET_OBJ_TIMER(j) > 0 )
                GET_OBJ_TIMER(j)--;

            if (GET_OBJ_TIMER(j) == 0) {
                if(contains_soulbound(j)) {
                    GET_OBJ_TIMER(j) = 1;
                    continue;
                }

                if (SCRIPT_CHECK(j, OTRIG_TIMER)) {
                    REMOVE_BIT_AR(j->obj_flags.extra_flags, ITEM_TIMED);
                    timer_otrigger(j);
                    continue;    // don't do anything more with this
                }
            }

            if( GET_OBJ_TYPE(j) == ITEM_KEY )
            {
                static char *keyVaporMsgs[] = {
                    "$p vanishes with a flash.",
                    "$p begins to shake violently.",
                    "$p begins to vibrate.",
                    "$p begins to hum.",
                    "$p begins to glow."
                };

                if( GET_OBJ_TIMER(j) < (sizeof( keyVaporMsgs )/sizeof( *keyVaporMsgs )))
                {
                    int vaporMsg = GET_OBJ_TIMER(j);

                    if( j->carried_by )
                        act( keyVaporMsgs[ vaporMsg ], FALSE, j->carried_by, j, 0, TO_CHAR);

                    else if( j->worn_by )
                    {
                        act( keyVaporMsgs[ vaporMsg ], FALSE, j->worn_by, j, 0, TO_CHAR);
                        for( loopvar = 0; loopvar < NUM_WEARS; loopvar++ )
                        {
                            if( j->worn_by->equipment[loopvar] == j )
                                j->worn_by->equipment[loopvar] = 0;
                        }
                    }
                    else if( j->in_room != NOWHERE && world[j->in_room].people )
                    {
                        act( keyVaporMsgs[ vaporMsg ], FALSE, world[j->in_room].people, j, 0, TO_CHAR);
                        act( keyVaporMsgs[ vaporMsg ], FALSE, world[j->in_room].people, j, 0, TO_ROOM);
                    }
                    extract_obj(j);
                    continue;
                }/* ITEM_KEY has timed out */
            }/* if ITEM_KEY */
            else if (GET_OBJ_TYPE(j) == ITEM_AFFECT)
            {
                if (!GET_OBJ_TIMER(j)) {
                    if (j->in_room != NOWHERE && world[j->in_room].people) {
                        act(j->action_description, FALSE, world[j->in_room].people,
                                j, 0, TO_CHAR);
                        act(j->action_description, FALSE, world[j->in_room].people,
                                j, 0, TO_ROOM);
                    }
                    extract_obj(j);
                    continue; // object gone, don't act further on it!
                }
            }
            else if( !GET_OBJ_TIMER(j) )
            {
                /* The object timed out - delete it */
                if( j->carried_by )
                    act( "$p crumbles to dust and is blown away.", FALSE, j->carried_by, j, 0, TO_CHAR );

                else if( j->worn_by )
                {
                    act("$p crumbles to dust and is blown away.", FALSE, j->worn_by, j, 0, TO_CHAR);
                    unequip_char( j->worn_by, j->worn_at );
                }
                else if( j->in_room != NOWHERE && world[j->in_room].people )
                {
                    act( "$p crumbles to dust and is blown away.",
                            FALSE, world[j->in_room].people, j, 0, TO_CHAR);
                    act( "$p crumbles to dust and is blown away.",
                            FALSE, world[j->in_room].people, j, 0, TO_ROOM);
                }
                extract_obj(j);
                continue; // object gone, don't act further on it!
            }
        } /* if OBJ_TIMED */

        /* if this looks like a portal */
        if ( (GET_OBJ_RNUM(j) >= 0 && GET_OBJ_RNUM(j) <= top_of_objt) &&
                obj_index[GET_OBJ_RNUM(j)].func == portal_proc &&
                GET_OBJ_TYPE(j) == ITEM_OTHER )
        { /* Mage created portals are type other, permanent portals are type portal. */
            /* Permanent portals thus don't decay. */
            if (GET_OBJ_VAL(j, 2) > 0)
                GET_OBJ_VAL(j,2)--;
        }
        /*
         ** Digger
         */
        /* If this is a corpse */
        if ((GET_OBJ_TYPE(j) == ITEM_CONTAINER) && GET_OBJ_VAL(j, 3)) {
            /* timer count down */
            if (GET_OBJ_TIMER(j) > 0)
                GET_OBJ_TIMER(j)--;

            // PC corpses which are empty will decay eventually..
            if(!CAN_WEAR(j, ITEM_WEAR_TAKE) && !(j->contains))
            {
                GET_OBJ_TIMER(j) = MAX(GET_OBJ_TIMER(j) / 3, 0);
            }

            if (!GET_OBJ_TIMER(j)) {
                if(contains_soulbound(j)) {
                    GET_OBJ_TIMER(j) = 1;
                    continue;
                }

                if (j->carried_by)
                    act("$p decays in your hands.", FALSE, j->carried_by, j, 0, TO_CHAR);
                
                else if ((j->in_room != NOWHERE) && (world[j->in_room].people)) {
                    static char *decay_messages[] = {
                        "A quivering hoard of maggots consumes $p.",
                        "A flock of vultures swoop down from the sky to devour $p.",
                        "The $p rots and decays as the shards of bone are blown to the four winds.",
                        "The $p rots and decays leaving behind the pungent stench of death.",
                        "A bolt of holy fire streaks from the heavens to burn the corpse of $p to ash.",
                        "The $p rots to ash and is swept away by the winds of time."
                    };
                    int decay_idx = (int)( random() % ( sizeof( decay_messages ) / sizeof( *decay_messages )));

                    act( decay_messages[ decay_idx ], TRUE, world[j->in_room].people, j, 0, TO_ROOM);
                    act( decay_messages[ decay_idx ], TRUE, world[j->in_room].people, j, 0, TO_CHAR);
                }/* JBP */
                
                for (jj = j->contains; jj; jj = next_thing2) {
                    next_thing2 = jj->next_content;	/* Next in inventory */
                    obj_from_obj(jj);

                    if (j->in_obj) {
                        if ( GET_OBJ_TYPE(j) != ITEM_KEY    &&
                                GET_OBJ_TYPE(j) != ITEM_SCROLL &&
                                GET_OBJ_TYPE(j) != ITEM_POTION &&
                                GET_OBJ_TYPE(j) != ITEM_DUST   &&
                                (GET_OBJ_VNUM(j) == 1460 ||
                                GET_OBJ_VNUM(j) == 1461 ||
                                GET_OBJ_VNUM(j) == 1462   ) )
                            continue;  // Refrigeration to keep food from rotting.
                        obj_to_obj(jj, j->in_obj);
                    }
                    else if (j->carried_by)
                        obj_to_room(jj, j->carried_by->in_room);
                    else if (j->in_room != NOWHERE)
                        obj_to_room(jj, j->in_room);
                    else
                    {
                        /* OLD WAY: assert(FALSE); */
                        mudlog(NRM, LVL_IMMORT, TRUE, "SYSERR: Something is wrong with a container." );
                        obj_to_room(jj, real_room(1201));
                    }
                }
                extract_obj(j);
            }
        }

        /* Imhotep: Added support for ITEM_TROPHY pieces that decay after
         * a given MUD date */        
        if(IS_OBJ_STAT(j, ITEM_TROPHY)) {
            if(GET_OBJ_TIMER(j) < TICKS_SO_FAR) {
                if (j->carried_by)
                    act("$p shimmers and vanishes out of your hands!", FALSE, j->carried_by, j, 0,
                            TO_CHAR);
                else if (j->worn_by) {
                    act("$p shimmers and vanishes!", FALSE, j->worn_by, j, 0, TO_CHAR);
                    unequip_char(j->worn_by, j->worn_at);
                } else if (j->in_room != NOWHERE && world[j->in_room].people) {
                    act("$p shimmers and vanishes!", FALSE,
                            world[j->in_room].people, j, 0, TO_CHAR);
                    act("$p shimmers and vanishes!", FALSE,
                            world[j->in_room].people, j, 0, TO_ROOM);
                }
                extract_obj(j);
                continue;
            }
        }
    }
}/* point_update */
Example #23
0
/*
 * Update all objs.
 * This function is performance sensitive.
 */
void obj_update (void)
{
    OBJ_DATA *obj;
    OBJ_DATA *obj_next;

    for (obj = object_list; obj != NULL; obj = obj_next)
    {
        CHAR_DATA *rch;
        char *message;

        obj_next = obj->next;

        if (obj->timer <= 0 || --obj->timer > 0)
            continue;

        switch (obj->item_type)
        {
            default:
                message = "$p crumbles into dust.";
                break;
            case ITEM_FOUNTAIN:
                message = "$p dries up.";
                break;
            case ITEM_CORPSE_NPC:
                message = "$p decays into dust.";
                break;
            case ITEM_CORPSE_PC:
                message = "$p decays into dust.";
                break;
            case ITEM_FOOD:
                message = "$p decomposes.";
                break;
            case ITEM_POTION:
            case ITEM_HEAL_FIXED:
                message = "$p has evaporated from disuse.";
                break;
            case ITEM_PORTAL:
                message = "$p fades out of existence.";
                break;
            case ITEM_CONTAINER:
                    message = "$p crumbles into dust.";
                break;
        }

        if (obj->carried_by != NULL)
        {
            if (IS_NPC (obj->carried_by)
                && obj->carried_by->pIndexData->pShop != NULL)
                obj->carried_by->silver += obj->cost / 5;
            else
            {
                act (message, obj->carried_by, obj, NULL, TO_CHAR);
            }
        }
        else if (obj->in_room != NULL && (rch = obj->in_room->people) != NULL)
        {
            if (!(obj->in_obj 
                  && !CAN_WEAR (obj->in_obj, ITEM_TAKE)))
            {
                act (message, rch, obj, NULL, TO_ROOM);
                act (message, rch, obj, NULL, TO_CHAR);
            }
        }

        if ((obj->item_type == ITEM_CORPSE_PC )
            && obj->contains)
        {                        /* save the contents */
            OBJ_DATA *t_obj, *next_obj;

            for (t_obj = obj->contains; t_obj != NULL; t_obj = next_obj)
            {
                next_obj = t_obj->next_content;
                obj_from_obj (t_obj);

                if (obj->in_obj)    /* in another object */
                    obj_to_obj (t_obj, obj->in_obj);

                else if (obj->carried_by)    /* carried */
                        if (obj->carried_by->in_room == NULL)
                            extract_obj (t_obj);
                        else
                            obj_to_room (t_obj, obj->carried_by->in_room);
                    else
                        obj_to_char (t_obj, obj->carried_by);

                 if (obj->in_room == NULL)    /* destroy it */
                    extract_obj (t_obj);
                else            /* to a room */
                    obj_to_room (t_obj, obj->in_room);
            }
        }

        extract_obj (obj);
    }

    return;
}
Example #24
0
/* Update PCs, NPCs, and objects */
void point_update(void)
{
  struct char_data *i, *next_char;
  struct obj_data *j, *next_thing, *jj, *next_thing2;

  /* characters */
  for (i = character_list; i; i = next_char) {
    next_char = i->next;
	
    gain_condition(i, FULL, -1);
    gain_condition(i, DRUNK, -1);
    gain_condition(i, THIRST, -1);
	
    if (GET_POS(i) >= POS_STUNNED) {
      GET_HIT(i) = MIN(GET_HIT(i) + hit_gain(i), GET_MAX_HIT(i));
      GET_MANA(i) = MIN(GET_MANA(i) + mana_gain(i), GET_MAX_MANA(i));
      GET_MOVE(i) = MIN(GET_MOVE(i) + move_gain(i), GET_MAX_MOVE(i));
      if (AFF_FLAGGED(i, AFF_POISON))
	if (damage(i, i, 2, SPELL_POISON) == -1)
	  continue;	/* Oops, they died. -gg 6/24/98 */
      if (GET_POS(i) <= POS_STUNNED)
	update_pos(i);
    } else if (GET_POS(i) == POS_INCAP) {
      if (damage(i, i, 1, TYPE_SUFFERING) == -1)
	continue;
    } else if (GET_POS(i) == POS_MORTALLYW) {
      if (damage(i, i, 2, TYPE_SUFFERING) == -1)
	continue;
    }
    if (!IS_NPC(i)) {
      update_char_objects(i);
      if (GET_LEVEL(i) < idle_max_level)
	check_idling(i);
    }
  }

  /* objects */
  for (j = object_list; j; j = next_thing) {
    next_thing = j->next;	/* Next in object list */

    /* If this is a corpse */
    if (IS_CORPSE(j)) {
      /* timer count down */
      if (GET_OBJ_TIMER(j) > 0)
	GET_OBJ_TIMER(j)--;

      if (!GET_OBJ_TIMER(j)) {

	if (j->carried_by)
	  act("$p decays in your hands.", FALSE, j->carried_by, j, 0, TO_CHAR);
	else if ((IN_ROOM(j) != NOWHERE) && (world[IN_ROOM(j)].people)) {
	  act("A quivering horde of maggots consumes $p.",
	      TRUE, world[IN_ROOM(j)].people, j, 0, TO_ROOM);
	  act("A quivering horde of maggots consumes $p.",
	      TRUE, world[IN_ROOM(j)].people, j, 0, TO_CHAR);
	}
	for (jj = j->contains; jj; jj = next_thing2) {
	  next_thing2 = jj->next_content;	/* Next in inventory */
	  obj_from_obj(jj);

	  if (j->in_obj)
	    obj_to_obj(jj, j->in_obj);
	  else if (j->carried_by)
	    obj_to_room(jj, IN_ROOM(j->carried_by));
	  else if (IN_ROOM(j) != NOWHERE)
	    obj_to_room(jj, IN_ROOM(j));
	  else
	    core_dump();
	}
	extract_obj(j);
      }
    }
    /* If the timer is set, count it down and at 0, try the trigger */
    /* note to .rej hand-patchers: make this last in your point-update() */
    else if (GET_OBJ_TIMER(j)>0) {
      GET_OBJ_TIMER(j)--; 
      if (!GET_OBJ_TIMER(j))
        timer_otrigger(j);
    }
  }
}
Example #25
0
/*
 * Make a corpse out of a character.
 */
OBJ_DATA *make_corpse( CHAR_DATA * ch, CHAR_DATA * killer )
{
   char buf[MAX_STRING_LENGTH];
   OBJ_DATA *corpse;
   OBJ_DATA *obj;
   OBJ_DATA *obj_next;
   const char *name;

   if( IS_NPC( ch ) )
   {
      name = ch->short_descr;
      corpse = create_object( get_obj_index( OBJ_VNUM_CORPSE_NPC ), 0 );
      corpse->timer = 6;
      if( ch->gold > 0 )
      {
         if( ch->in_room )
         {
            ch->in_room->area->gold_looted += ch->gold;
            sysdata.global_looted += ch->gold / 100;
         }
         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;
   }
   else
   {
      name = ch->name;
      corpse = create_object( get_obj_index( OBJ_VNUM_CORPSE_PC ), 0 );
      if( in_arena( ch ) )
         corpse->timer = 0;
      else
         corpse->timer = 40;
      corpse->value[2] = ( int )( corpse->timer / 8 );
      corpse->value[4] = ch->level;
      if( CAN_PKILL( ch ) && sysdata.pk_loot )
         xSET_BIT( corpse->extra_flags, ITEM_CLANCORPSE );
      /*
       * Pkill corpses get save timers, in ticks (approx 70 seconds)
       * This should be anough for the killer to type 'get all corpse'. 
       */
      if( !IS_NPC( ch ) && !IS_NPC( killer ) )
         corpse->value[3] = 1;
      else
         corpse->value[3] = 0;
   }

   if( CAN_PKILL( ch ) && CAN_PKILL( killer ) && ch != killer )
   {
      snprintf( buf, MAX_STRING_LENGTH, "%s", killer->name );
      STRFREE( corpse->action_desc );
      corpse->action_desc = STRALLOC( buf );
   }

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

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

   snprintf( buf, MAX_STRING_LENGTH, 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 );
   }
   return obj_to_room( corpse, ch->in_room );
}