musicmud-2.1.6/data/
musicmud-2.1.6/data/help/
musicmud-2.1.6/data/policy/
musicmud-2.1.6/data/wild/
musicmud-2.1.6/data/world/
musicmud-2.1.6/doc/
musicmud-2.1.6/src/ident/
musicmud-2.1.6/src/lua/
musicmud-2.1.6/src/lua/include/
musicmud-2.1.6/src/lua/src/lib/
musicmud-2.1.6/src/lua/src/lua/
musicmud-2.1.6/src/lua/src/luac/
/*
 * MusicMUD - Ships and Docs modle
 * Copyright (C) 1998-2003 Abigail Brady
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 * 
 */

#include <stdio.h>
#include <ctype.h>
#include <math.h>

#include "musicmud.h"
#include "util.h"
#include "verbs.h"
#include "State.h"
#include "Player.h"
#include "misc.h"
#include "msi.h"
#include "Socket.h"
#include "Library.h"
#include "aberchat.h"
#include "config.h"
#include "flags.h"
#include "pflags.h"
#include "flagnames.h"
#include "rooms.h"
#include "zoneload.h"
#include "events.h"
#include "trap.h"
#include "nations.h"

#define MODULE "ship"

static bool verb_file_plan (MudObject * player, int argc, const char **argv)
{
  /* copies the plan to a temporary place(!plan) so that its plan is 
   * not lost, and can be used again. if the calling object doesnt have
   * the 'timer' flag, an error is logged */

  if (is_player(player) && !player->get_priv(PFL_GOD)
      && !player->ilc) {
    player->printf("You can't do that.\n");
    return true;
  }

  string str = "plan";
  int delay = 0;

  if (argc >= 2) {
    if (argv[1][0]=='!') 
      str = ssprintf("!plan.%s", argv[1]);
    else
      str = ssprintf("plan.%s", argv[1]);
  }

  if (argc >= 3) {
    delay = atoi(argv[2]);
  }
  
  const char *pl = player->get(str.c_str());
  if (!pl) {
    log(PFL_SEEINFO, 0, "wiz", "file_plan on nonexistant plan %s by %s", str, player->id);
    return true;
  }
  
  player->set("!plan", pl);
  if (delay)
    player->set("!when", delay+now);
  else
    player->set("!when", 1);
  player->set("!what", "");
  
  player->set_flag(FL_TIMER, 1);
  
  return true;
}

static bool verb_tube(MudObject *who, int argc, const char **argv) {
  if (streq(argv[1], "stophere")) {
    shipmsg(who, "You hear a voice say ^`^{sThis is %s. Mind the gap, please^}^'.\n", 
	    who->owner->get("station")?:
	    who->owner->get("name"));
    who->set("!reschedule", 1);
    who->set("!what", "tube opendoors");
    return true;
  }

  const char *noun = who->get("doorname");
  if (!noun)
    noun = "door";

  if (streq(argv[1], "opendoors")) {
    MudObject *who2 = who->get_object("doorsat");
    if (!who2) 
      who2 = who->get_object("link")?:who;
    MudObject *o;
    int i;
    foreach(who2->children, o, i) {
      o->printf("The %s has opened.\n", noun);
    }

    who->oprintf("The %s has opened.\n", noun);

    if (MudObject *oth=who->get_object("other")) {
      oth->set(KEY_STATE, 0);
    }

    who->set(KEY_STATE, 0);
    who->set("!reschedule", 10);
    who->set("!what", "tube closedoors");
    return true;
  }

  if (streq(argv[1], "closedoors")) {
    MudObject *who2 = who->get_object("doorsat");
    if (!who2) 
      who2 = who->get_object("link")?:who;
    MudObject *o;
    int i;
    foreach(who2->children, o, i) {
      o->printf("The %s has closed.\n", noun);
    }

    who->oprintf("The %s has closed.\n", noun);

    if (MudObject *oth=who->get_object("other")) {
      oth->set(KEY_STATE, 1);
    }

    who->set(KEY_STATE, 1);
    return true;
  }

  MudObject *which=who;
  int scount = which->array_size("stop");
  const char *tunnel=which->get("tunnel");
  if (!tunnel)
    tunnel = "lstone_57";
  if (!scount)
    return true;

  int circ = which->get_int("stop.circle", 0);

  int i;
  string s;
  for (i=0;i<scount;i++) {
    MudObject *stat = which->array_get_object("stop", i);
    if (stat) {
      s += "1 route ";
      s += stat->id;
      s += ";1 tube stophere;";
    }
  }
  if (!circ) {
    int j = i;
    for (i=scount-2;i>0;i--) {
      MudObject *stat = which->array_get_object("stop", i);
      if (stat) {
	s += "1 route ";
	s += stat->id;
	s += ";1 tube stophere;";
      }
      j++;
    }
  }
  s += "0 tube";
  who->printf("plan would be %s.\n", s.c_str());
  which->set("!plan.!tube", s.c_str());
  which->interpret("file_plan !tube");
  return true;
}

#include "verbmodule.h"


void startup() {
	AUTO_VERB(file_plan, 5, 0, PFL_NONE);
	AUTO_VERB(dslist, 6, 0, PFL_AWAKE);
	AUTO_VERB(tube, 4, 0, PFL_GOD);
}