Author Topic: a fun little toy (reimplemented)  (Read 2882 times)

Offline mordain

  • Acquaintance
  • *
  • Posts: 12
    • View Profile
a fun little toy (reimplemented)
« on: April 25, 2009, 07:24:31 am »
Just because i wanted to do it another way... the first version was an experiment with rabbit breeder cloning, this is more about mappings and recursion.

does the same things tho basicly, in a different (better) way, traces thru connected rooms and optionally kills stuff.
Code: [Select]
/*
  Angel of death Ver2 -- Arron Cusimano (Mordain), 2009
  written for Dead Souls 2.9a16 mudlib

  - uses mapping keys to store room names as a hash table
  - skips virtuals rooms, since they are potentially huge, causing issues

  i save this to /realms/yourname/cmds/aod2.c
  then just type "aod2"
 
  enjoy  =)
*/
#include <lib.h>
#include <damage_types.h>
inherit LIB_DAEMON;

#define MAX_RECURSION_DEPTH   35

// set to 1 to kill stuff as well as load rooms
#define DO_DAMAGE  0

mapping rlist; /* the list of rooms */

/*-------------------------------------------------------------------
recursively follows room exits to a max recursion depth, 
loading those rooms as it goes
*/
void chk_rooms(object rob, int recurs) {
  string room_file;
 
  if (recurs > MAX_RECURSION_DEPTH) return;
 
  if (rob) {
    foreach(string direct in rob->GetExits()) {
      room_file = rob->GetExit(direct);
      if (undefinedp(rlist[room_file]) && strsrch(room_file, "virtual") < 0) {
        rlist[room_file] = recurs;
        chk_rooms(load_object(room_file), recurs + 1);
      }
    }
  }
}

mixed cmd(string str) {
  rlist = ([]);
 
  chk_rooms(environment(this_player()), 1);

  foreach(string room_file, int v in rlist) {
    write(""+v+"\t"+room_file);
#if DO_DAMAGE
    foreach(object o in filter(all_inventory(load_object(room_file)), (:living:))) {
      if (o != this_player()) {
        tell_room(environment(o), o->GetShort()+" sickens and withers.\n");
        o->eventReceiveDamage(0, DEATHRAY, 500+random(50));
      }
    }
#endif
  }
 
  rlist = ([]); // nuke the list when done, since it can chew a lot of memory
  return 1;
}

Sample output:
Code: [Select]
goto /domains/examples/room/entrance
/domains/examples/room/entrance
Entrance to Hall Of Rooms
[...]
Obvious exits: north, south
/realms/talsin >
update cmds/aod2
/realms/talsin/cmds/aod2: Ok
/realms/talsin >
aod2
2       /domains/examples/room/exroom2
1       /domains/examples/room/exroom1
4       /domains/examples/room/exroom2b
3       /domains/examples/room/exroom2a
2       /domains/examples/room/entrance
7       /domains/examples/room/exroom7
6       /domains/examples/room/exroom6
5       /domains/examples/room/exroom5
3       /domains/examples/room/start
4       /domains/examples/room/exroom4
3       /domains/examples/room/exroom3
/realms/talsin >