Objects from corpses

  • JTP
  • JTP's Avatar Topic Author
  • Offline
  • Platinum Boarder
  • Platinum Boarder
More
2 weeks 3 days ago - 2 weeks 3 days ago #8032 by JTP
JTP created the topic: Objects from corpses
Hmm ok atm it seems that when a corpse vanish, Then what ever objects was in it, is dropped on the Ground.

Result is messy rooms.

How Could it be made so that corpse and objects is purged, when the corpse vanish ?
Last Edit: 2 weeks 3 days ago by JTP.

Please Log in or Create an account to join the conversation.

More
2 weeks 3 days ago - 2 weeks 3 days ago #8033 by lacrc
lacrc replied the topic: Objects from corpses
Corpse timers are checked in limits.c in the point_update() function that is called every tick. More specifically here:
github.com/tbamud/tbamud/blob/master/src/limits.c#L419

You can make it so that items are not dropped on the ground and extracted by changing the code that is called when the corpse timer expires, it starts in this line:
github.com/tbamud/tbamud/blob/master/src/limits.c#L425

In the end you would have something like this:
  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);
	}

	/* removed code that drops items on the ground from here 
       the extract_obj(j) below will purge the corpse j with all objects inside */

	extract_obj(j);
  }
Which would also make 2 variables (*jj and *next_thing2) unused so go ahead and remove their declarations from point_update().

I tested it (with just one corpse) and it worked. Hope it helps!
Last Edit: 2 weeks 3 days ago by lacrc.

Please Log in or Create an account to join the conversation.

  • JTP
  • JTP's Avatar Topic Author
  • Offline
  • Platinum Boarder
  • Platinum Boarder
More
2 weeks 3 days ago - 2 weeks 3 days ago #8034 by JTP
JTP replied the topic: Objects from corpses
So what If the char is carrying the corpse when it decays. What happends to the objects Then ?

Just came to think about player corpses, they would be mad If the objects is lost haha
Last Edit: 2 weeks 3 days ago by JTP.

Please Log in or Create an account to join the conversation.

More
2 weeks 3 days ago - 2 weeks 3 days ago #8035 by lacrc
lacrc replied the topic: Objects from corpses
Oh well I didn't consider that haha, in the example above they would be lost.
In that case, I think you can get away with a minor change extracting the item instead of dropping it on the room, but in the cases where the corpse is being carried or are inside a container no changes are made.
The code would be like this (it's a one line change from stock TBA code):
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)
	    extract_obj(jj); /* simply extract the obj <--- Change is here */
	  else
	    core_dump();
	}
	extract_obj(j);
      }
    }

But that would still make non-carried PC corpses (ie. a player died and didn't make their way back to their corpse in time) to lose their items when their corpse's timers expired.

A solution to that would be to somehow identify the corpses as being NPC or PC corpses, but that requires more changes in code and I'm not sure if it's worth or optimal though.

I would go about it like this, in fight.c look for the function make_corpse() and change this section as follows:
SET_BIT_AR(GET_OBJ_WEAR(corpse), ITEM_WEAR_TAKE);
  SET_BIT_AR(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))
+  if (IS_NPC(ch)) {
    GET_OBJ_TIMER(corpse) = CONFIG_MAX_NPC_CORPSE_TIME;
+  GET_OBJ_VAL(corpse, 3) = 1;	/* NPC corpse identifier */
 - else
+ } else {
    GET_OBJ_TIMER(corpse) = CONFIG_MAX_PC_CORPSE_TIME;
+  GET_OBJ_VAL(corpse, 3) = 2;	/* PC corpse identifier */
+  }
That way NPC corpses will be identified with Value 3 = 1 and PC corpses would be Value 3 = 2.
(It says 3 in there but it's the 4th value, the count starts from 0, remember that! lol)

Then in the point_update() function in limits.c you check for this value to know if an object should be dropped on the ground or left in the corpse to be thrown away:
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)
            if (GET_OBJ_VAL(j, 3) == 2) /* PC corpse, drop objects in the room */
	        obj_to_room(jj, IN_ROOM(j));
            else /* NPC corpse, extract obj */
                extract_obj(jj);
	   else
	    core_dump();
	}
	extract_obj(j);
      }
I won't be able to test those now so beware lol.
Last Edit: 2 weeks 3 days ago by lacrc.

Please Log in or Create an account to join the conversation.

More
2 weeks 3 days ago #8036 by Sascha
Sascha replied the topic: Objects from corpses
This sparked two additional thoughts from me.

1) Is there a way to set it so that PC corpses can't be taken/carried by players?

2) Has anyone made a snippet that moves the inventory of a PC's corpse to a location, such as a donation room, when it decays?

Dovie'andi se tovya sagain. After the Breaking MUD, now in beta testing...

Please Log in or Create an account to join the conversation.

Time to create page: 1.062 seconds