#include <sys.h>

object dest;
string name;
string long_desc;
object owner;
int flags;
int special;

self_destruct() { destruct(this_object()); return 1; }

get_special() { return special; }
set_special(s) { special=s; return 1; }
get_flags() { return flags; }
set_flags(f) { flags=f; return 1; }
get_owner() { return owner; }
set_owner(o) { owner=o; return 1; }
get_long() { return long_desc; }
get_type() { return TYPE_EXIT; }

id(arg) { return instr(name,1,";"+arg+";"); }

set_long(arg) {
  long_desc=arg;
  return 1;
}

get_name() { if (name) return midstr(name,2,strlen(name)-2); }
get_dest() { return dest; }

set_name(arg) {
  int pos;
  string x;

  while (name) {
    pos=instr(name,1,";");
    x=leftstr(name,pos-1);
    name=rightstr(name,strlen(name)-pos);
    if (x) remove_verb(x);
  }
  arg=";"+arg+";";
  name=arg;
  while (arg) {
    pos=instr(arg,1,";");
    x=leftstr(arg,pos-1);
    arg=rightstr(arg,strlen(arg)-pos);
    if (x) add_verb(x,"go");
  }
  return 1;
}

set_dest(arg) {
  dest=arg;
  return 1;
}

static go(arg) {
  int pos;
  string ename;

  if (arg) return 0;
  if (!dest) {
    tell_player(this_player(),"This exit is unlinked.\n");
    return 1;
  }
  ename=get_name();
  pos=instr(ename,1,";");
  if (pos)
    ename=leftstr(ename,pos-1);
  call_other(this_player(),"move_player",dest,ename);
  return 1;
}

stat() {
  tell_player(this_player(),"Object Type: EXIT\n");
  if (flags) tell_player(this_player(),"Flags: "+make_flags(flags)+"\n");
  if (special) tell_player(this_player(),"Special: "+itoa(special)+"\n");
  if (location(this_object()))
    tell_player(this_player(),"Location: "+make_num(location(this_object()))+
                "\n");
  else
    tell_player(this_player(),"Location: void\n");
  if (name)
    tell_player(this_player(),"Name: "+get_name()+"\n");
  if (long_desc)
    tell_player(this_player(),"Long: "+long_desc+"\n");
  if (dest)
    tell_player(this_player(),"Linked To: "+make_num(dest)+"\n");
  else
    tell_player(this_player(),"Linked To: UNLINKED\n");
  if (owner)
    tell_player(this_player(),"Owner: "+make_num(owner)+"\n");
  return 1;
}