Setting affects on rooms...

From: ed wrotniewski (
Date: 07/03/96

Ok, here's some abstract code of setting affects on rooms. Email me is ya'll
have any questions.

This struct must be added to structs.h, and in room_data there must be a
struct room_affects *<whatever you wanna call it, I used afs>

struct room_affects {
   sh_int duration;
   byte misc;
   byte type;
   struct room_affects *next;

Duration - Uh.. duh...
misc - this I used for different things. Like the level a spell was cast at,
       the room number the spell teleports people to, etc.
type - This is like the af.type for character affectsions. set the type = to
       the types you define in structs.h. Mine look like:

#define RAF_DARKNESS    1
#define RAF_SPIKES      2
#define RAF_BLADES      3
#define RAF_FIRE        4
#define RAF_POISON_GAS  6
#define RAF_EBON_MISTS  7
#define RAF_TOWER       8

That's the easy stuff... now for the room affecting crap in handler.c
pretty much just patch this code in handler.c somewhere.

void affect_to_room(struct room_data *rm, struct room_affects *af)
  struct room_affects *affected_alloc;

  CREATE(affected_alloc, struct room_affects, 1);

  memset((char *) affected_alloc, 0, sizeof(struct room_affects));

  *affected_alloc = *af;
  affected_alloc->next = rm->afs;
  rm->afs = affected_alloc;

void affect_from_room(struct room_data *rm, sh_int type)
  struct room_affects *hjp, *hjp2, *temp;

  for (hjp = rm->afs; hjp; hjp = hjp2) {
    hjp2 = hjp->next;
    if (hjp->type == type) {
      REMOVE_FROM_LIST(hjp, rm->afs, next);

bool room_affected(struct room_data *rm, sh_int type)
  struct room_affects *hjp;

  if (!rm)
    return FALSE;

  for (hjp = rm->afs; hjp; hjp = hjp->next)
    if (hjp->type == type)
      return TRUE;

  return FALSE;

struct room_affects find_room_affection(struct room_data *rm, sh_int type)
  struct room_affects *hjp, xx;

  for (hjp = rm->afs; hjp; hjp = hjp->next)
    if (hjp->type == type)
      return *hjp;

  xx.type = 0;
  xx.duration = 0;
  xx.misc = 0;
  return xx;

void room_affect_join(struct room_data *rm, struct room_affects *af, bool add_dur, bool avg_dur, bool add_misc, bool avg_misc)
  struct room_affects *hjp, *temp, *hjp2;
  bool found = FALSE;

  for (hjp = rm->afs; !found && hjp; hjp = hjp2) {
    hjp2 = hjp->next;
    if (hjp->type == af->type) {
      if (add_dur)
        af->duration += hjp->duration;
      if (avg_dur)
        af->duration = ((af->duration + hjp->duration) >> 1);

      if (add_misc)
        af->misc += hjp->misc;
      if (avg_misc)
        af->misc = ((af->misc + hjp->misc) >> 1);

      REMOVE_FROM_LIST(hjp, rm->afs, next);
      affect_to_room(rm, af);
      found = TRUE;
  if (!found)
    affect_to_room(rm, af);

That should do it... in magic.c you can add mag_affectroom and whatnot, and
room_affect_join or affect_to_room or whatever. Pretty self explanatory.

Aah shit... I just realized something. This code wont work on your muds.
I have rooms on Ebon Mists as objects and chars are... they arent in an
array, they are in a linked list, and all my room handling functions are
done with pointers and whatnot... I THINK you can (dont quote me, It's been
so long since I've changed it I cant remember right now) do something like
rm = real_room(number) or something like that... or in all the functions
above change struct room_data *rm to int rn, then inside the function put
the struct room_data *rm = <your favorite way to find a room>, I believe if
memory serves me right that the easiest way is:
If you already have the real num of the room:
struct room_data *rm = world[number];
and if not:
struct room_data *rm = world[real_room(number)];

Crap.. is the world array pointered? I cant remember. Well anyway, this
should at least be enough code to get you started.


Doh... forgotn something... add in limits.c or wherever it checks 
for ticks to check for and update the duration of room affects, otherwise
they'll last forever.

Systems Administrator of Send an Email to     M   T for info on how you can run     U   E
your mud or chat client on MudTech.                          D   C
Visit Ebon Mists MUD at 8888           H

This archive was generated by hypermail 2b30 : 12/07/00 PST