phantasmal_dgd_v1/
phantasmal_dgd_v1/bin/
phantasmal_dgd_v1/doc/
phantasmal_dgd_v1/mud/doc/
phantasmal_dgd_v1/mud/doc/api/
phantasmal_dgd_v1/mud/doc/kernel/
phantasmal_dgd_v1/mud/doc/kernel/hook/
phantasmal_dgd_v1/mud/doc/kernel/lfun/
phantasmal_dgd_v1/mud/include/
phantasmal_dgd_v1/mud/include/kernel/
phantasmal_dgd_v1/mud/kernel/lib/
phantasmal_dgd_v1/mud/kernel/lib/api/
phantasmal_dgd_v1/mud/kernel/obj/
phantasmal_dgd_v1/mud/kernel/sys/
phantasmal_dgd_v1/mud/tmp/
phantasmal_dgd_v1/mud/usr/System/
phantasmal_dgd_v1/mud/usr/System/keys/
phantasmal_dgd_v1/mud/usr/System/obj/
phantasmal_dgd_v1/mud/usr/System/open/lib/
phantasmal_dgd_v1/mud/usr/common/data/
phantasmal_dgd_v1/mud/usr/common/lib/parsed/
phantasmal_dgd_v1/mud/usr/common/obj/telopt/
phantasmal_dgd_v1/mud/usr/common/obj/ustate/
phantasmal_dgd_v1/mud/usr/game/
phantasmal_dgd_v1/mud/usr/game/include/
phantasmal_dgd_v1/mud/usr/game/obj/
phantasmal_dgd_v1/mud/usr/game/object/
phantasmal_dgd_v1/mud/usr/game/object/stuff/
phantasmal_dgd_v1/mud/usr/game/sys/
phantasmal_dgd_v1/mud/usr/game/text/
phantasmal_dgd_v1/mud/usr/game/users/
phantasmal_dgd_v1/src/host/
phantasmal_dgd_v1/src/host/beos/
phantasmal_dgd_v1/src/host/mac/
phantasmal_dgd_v1/src/host/unix/
phantasmal_dgd_v1/src/host/win32/res/
phantasmal_dgd_v1/src/kfun/
phantasmal_dgd_v1/src/lpc/
phantasmal_dgd_v1/src/parser/
#include <kernel/kernel.h>

#include <phantasmal/timed.h>
#include <phantasmal/log.h>
#include <phantasmal/lpc_names.h>

inherit MOBILE;

/* Member variables */
private int registered;

/* Inherited mobile data */
static int aggression;

/* prototypes */
void upgraded(varargs int clone);


static void create(varargs int clone) {
  ::create(clone);

  upgraded(clone);
}


void upgraded(varargs int clone) {
  if(clone && !registered) {
    LOGD->write_syslog("Setting up heart_beat in wander mobile",
		       LOG_VERBOSE);
    TIMED->set_heart_beat(TIMED_HALF_MINUTE, "__vol_hook");
    registered = 1;
  }

  if(clone) {
    /* This is mainly just an example at this point */
    aggression = 0;
  }
}

string get_type(void) {
  return "animal";
}

void __vol_hook(void) {
  int    num_ex, ctr;
  object exit, dest;
  string reason;

  if(previous_program() != TIMED) {
    error("animal_mobile::__vol_hook should only be called by TIMED!");
  }

  if(random(100) < 70) {
    /* Do nothing for the moment */
    if(aggression && (random(100) < 25)) {
      social("growl", nil);
    }
    return;
  }

  num_ex = location->num_exits();
  if(num_ex > 0) {
    int dir;

    ctr = random(num_ex);
    exit = location->get_exit_num(ctr);
    if(!exit)
      error("Internal error!  Can't get exit!");

    dir = exit->get_direction();
    dest = exit->get_destination();

    reason = this_object()->move(dir);
    if(reason) {
      this_object()->say("I'm blocked!  I can't move there!");
      return;
    }
  }
}

static mixed *animal_from_dtd_unq(mixed* unq) {
  mixed *ret, *ctr;
  int    bodynum, aggr;

  ret = ({ });
  ctr = unq;

  while(sizeof(ctr) > 0) {
    if(!STRINGD->stricmp(ctr[0][0], "aggression")) {
      if(sscanf(ctr[0][1], "%*d %*s") != 2
	 && sscanf(ctr[0][1], "%d", aggr) == 1) {
	aggression = aggr;
      }
    } else {
      ret += ({ ctr[0] });
    }
    ctr = ctr[1..];
  }

  return ret;
}

void from_dtd_unq(mixed* unq) {
  /* Set the body, location and number fields */
  unq = mobile_from_dtd_unq(unq);

  /* Now parse the data section */
  unq = animal_from_dtd_unq(unq);

  /* Now signal error if there's anything funky in the data
     section that we don't recognize. */
  if(sizeof(unq) > 0) {
    LOGD->write_syslog("Extra fields: " + STRINGD->mixed_sprint(unq),
		       LOG_ERROR);
    error("Unrecognized UNQ content in animal mobile data section!");
  }
}

string mobile_unq_fields(void) {
  return "    ~aggression{" + aggression + "}\n";
}