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 <phantasmal/lpc_names.h>

object user;
object next_state;

/*
  The user_state object is used on a state stack of user input/output
  processing.  When it is pushed or everything above it has been
  popped, switch_to is called on it.  When another state is pushed
  "over" it, switch_from is called.  When it is the current state,
  input from the user first passes to from_user and output meant for
  the user first passes through to_user.  The state determines how the
  user or login object receive these messages, if at all.

  A user_state may pass messages to the next state in the stack, thus
  "filtering" a previous state.
*/

static void create(varargs int clone) {
  if(clone) {

  }
}

/* By default, this does nothing and accepts any parameters.  Subtypes
   may restrict it appropriately. */
void set_up_func(mixed params...) {
}

void init(object new_user, object new_next_state) {
  if(previous_program() != SYSTEM_USER_IO)
    error("Use push_new_state and pop_state functions for user states!");

  user = new_user;
  next_state = new_next_state;
}

static object get_user(void) {
  return user;
}

int from_user(string input) {
  error("Implement from_user!");
}

void to_user(string output) {
  if(next_state) {
    next_state->to_user(output);
  } else {
    user->ustate_send_string(output);
  }
}

void switch_to(int pushp) {
  /* Defaults to no-op */
}

void switch_from(int popp) {
  /* Defaults to no-op */
}

static int send_string(string str) {
  return user->ustate_send_string(str);
}

static void pop_state(void) {
  user->pop_state(this_object());
}

static void push_state(object state) {
  user->push_state(state);
}

static void push_new_state(mixed state_type, mixed params...) {
  user->push_new_state(state_type, params...);
}

static void pass_data(mixed data) {
  if(next_state) {
    next_state->pass_data(data);
  } else {
    user->user_state_data(data);
  }
}