[CODE] Removing a mobile from room (zedit)

From: Julian Buckley (s348266@student.uq.edu.au)
Date: 01/07/99


I recently rebegun working on a bit of code I started way back.  It's
basically a mimic of the Remove Obj from Room code, but allows you to
remove a mobile from the room. (this is in zedit).

The zedit section was easy enough.  The problem I'm having is in
Believe it or not, this code does the job I want it to do, it's just
that I've had to chop and change stuff, and I'm hoping I aren't making
it hugely memory inefficient.

The first function I made was a mimic of get_obj_in_list_num.:
/* Search a given list for an mobile number, and return a ptr to that
mob */
struct char_data *get_mob_in_list_num(int num, struct char_data * list)
  struct char_data *i;

  for (i = character_list; i; i = i->next)
    if (GET_MOB_RNUM(i) == num)
      return i;

  return NULL;
which is called within db.c as:
    case 'B': /* rem mob from room */
      if ((mob = get_mob_in_list_num(ZCMD.arg2,
world[ZCMD.arg1].contents)) != NULL) {
      last_cmd = 1;

Now, once this was compiled, I attempted to boot up my mud.  Sure
enough, it pointed me to the fact that I could do an "extract_char(mob)"
in the above section. (hence the weird "extract_mob()" function).  I
took that line out (extract_char(mob)) and rebooted.  The mud booted,
and it actually was able to remove the mobile from the room.  However, I
assume the mob was still lurking in memory somewhere.  So I decided to
write my own "extract_mob()" code...:
/* Extract an mobile from the world */
void extract_mob(struct char_data * mob)
  struct char_data *temp;
//  char_from_room(mob);
  REMOVE_FROM_LIST(mob, character_list, next);
  if (GET_MOB_RNUM(mob) >= 0)
  if (SCRIPT(mob))
The char_from_room(mob) is commented out because it too was directing me
to the extracting from nowhere thing.  Besides, it gets called within
the db.c code.

What I need to know is, does this look ok and should it (is it?) working
as intended?  On the mud side, it's doing it's job, but I think I've
overlooked something...anyone?  I also tried using the get_char_num
function, but I don't know if I can change this:
   if ((mob = get_mob_in_list_num(ZCMD.arg2, world[ZCMD.arg1].contents))
!= NULL) {
to this:
  if ((mob = get_char_num(ZCMD.arg2)) != NULL) {

Any help appreciated.

Julian Buckley, 3rd Year Computer Systems Engineering
Dept. Computer Science and Electrical Engineering, Univ. of Qld
E-Mail: s348266@student.uq.edu.au
Web Page: http://student.uq.edu.au/~s348266/index.html

     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     |  http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html  |

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