Portals part 4

It seems I was mistaken before.  I had intended to use OBJ_VAL 3 as a timer.  Adding this would require more code to count tics and decrement the timer every round.  Pretty complex.

But when I started testing the code, I realized that there’s already an object that does exactly what I want – player and NPC corpses.  These objects are created, have a countdown timer of some sort, and decay when the timer runs out, exactly what I want!  Of course, spell-made portals may need to have variable timers, but we can handle that pretty easily in the spell function, or more specifically, I don’t want to deal with it now so I won’t.

So lets get on with it.

After some searching, I found the TIMER function is controlled in limits.h (the function that controls hp/mana gains, hunger/thirst, and idle time), at the bottom of the function.

If you peek at the code, you may notice that the TIMER function actually doesn’t do anything unless the object is a corpse (that is, IS_CORPSE(j) is true), or if there’s a specific trigger attached to the object.

That should be easy enough to fix, we’ll add a new if statement at the end of the point_update function to check for an object of TYPE_PORTAL, and add countdowns.

if ((GET_OBJ_TYPE(j) == ITEM_PORTAL) && GET_OBJ_TIMER(j) > 0)
GET_OBJ_TIMER(j)–;             /* Only decrease if OBJ_TIMER > 0, so a 0 timer is still permanent */
if(!GET_OBJ_TIMER(j))
if (j->carried_by)
act(“$p fades out of existence.”, FALSE, j->carried_by, j, 0, TO_CHAR);
else if ((IN_ROOM(j) != NOWHERE) && (world[IN_ROOM(j)].people)) {
act(“$p contracts then snaps out of existence with a flash.”,
TRUE, world[IN_ROOM(j)].people, j, 0, TO_ROOM);
act(“$p contracts then snaps out of existence with a flash.”,
TRUE, world[IN_ROOM(j)].people, j, 0, TO_CHAR);
}
extract_obj(j);
}

Note that we’re only acting on portals that have a TIMER > 0, so if you want to make a portal permanent, just set the timer to 0 (or don’t edit the timer in oedit).

Problem resolved, quick and easy.  In fact, it wouldn’t be hard to edit the code to cover any type of object, for example to make weapons that are destroyed after some time (magical swords, or snowballs in a “hell” area, heh).

I’ve been also working on the spell_portal code, I should have a chance to test it in the next couple of days to see how things work.  As a brief teaser, creating portals are basically a combination of the SUMMON spell and the immortal LOAD OBJ command.

Leave a comment