overland.c

toc/code/overland.c · 250.5 KB

From the archive fear2.1.3.tar.gz

Download the archive   « Back to the archive contents

    /****************************************************************************
 * [S]imulated [M]edieval [A]dventure multi[U]ser [G]ame      |   \\._.//   *
 * -----------------------------------------------------------|   (0...0)   *
 * SMAUG 1.4 (C) 1994, 1995, 1996, 1998  by Derek Snider      |    ).:.(    *
 * -----------------------------------------------------------|    {o o}    *
 * SMAUG code team: Thoric, Altrag, Blodkai, Narn, Haus,      |   / ' ' \   *
 * Scryn, Rennard, Swordbearer, Gorog, Grishnakh, Nivek,      |~'~.VxvxV.~'~*
 * Tricops and Fireblade                                      |             *
 * ------------------------------------------------------------------------ *
 * Merc 2.1 Diku Mud improvments copyright (C) 1992, 1993 by Michael        *
 * Chastain, Michael Quan, and Mitchell Tse.                                *
 * Original Diku Mud copyright (C) 1990, 1991 by Sebastian Hammer,          *
 * Michael Seifert, Hans Henrik St{rfeldt, Tom Madsen, and Katja Nyboe.     *
 * Win32 port by Nick Gammon                                                *
 * ------------------------------------------------------------------------ *
 *			    Overland Map Display and Support Code			    *
 ****************************************************************************/

#include <sys/types.h>
#include <ctype.h>
#include <stdio.h>
#include <time.h>
#include <string.h>
#include "mud.h"

unsigned char map_sector[MAP_MAX][MAX_X + 1][MAX_Y + 1]; /* Initializes the sector array */
char weather_sector[MAP_MAX][MAX_X + 1][MAX_Y + 1]; /* Initializes the weather array */
short resource_sector[MAP_MAX][MAX_X + 1][MAX_Y + 1]; /* Initalizes the resource array */
unsigned char kingdom_sector[MAP_MAX][MAX_X + 1][MAX_Y + 1]; /* Initalizes the kingdom array */
int winddir;
int windstr;
int snows;
int cur_ship_uid;

//Use this instead of the table to show colors, uses less color parsing
char *show_room args((int sector, int x, int y, int map, int begin));
int get_distform args((int x, int y, int vx, int vy));
int check_ship_borders args((SHIP_DATA *ship));

ENTRANCE_DATA *first_entrance;
ENTRANCE_DATA *last_entrance;
FRONT_DATA *first_front;
FRONT_DATA *last_front;

void shutdown_mud args((char *reason));

char *const map_names[MAP_MAX] = {
   "Solan"
};

char *const map_name[MAP_MAX] = {
   "solan"
};

/* Sectortypes
 */
char *const sector_message[SECT_MAX] = {
   "Inside",
   "City",
   "Field",
   "Forest",
   "Hills",
   "Mountain",
   "Water Swim",
   "Water Noswim",
   "Underwater",
   "Air",
   "Desert",
   "Dunno",
   "Oceanfloor",
   "Underground",
   "Road",
   "Enter",
   "Mine Gold",
   "Mine Iron",
   "Corn Field",
   "Grain Field",
   "Chopped Trees",
   "Completely Chopped Trees",
   "Mined Gold mine",
   "Empty Gold mine",
   "Mined Iron mine",
   "Empty Iron mine",
   "Harvested Corn Field",
   "Empty Corn Field",
   "Harvested Grain Field",
   "Empty Grain Field",
   "River",
   "Jungle",
   "Shore",
   "Tundra",
   "Ice",
   "Ocean",
   "Lava",
   "Impass-Tree",
   "Impass-Stone",
   "Impass-Quicksand",
   "Wall",
   "Impass-Glacier",
   "Exit",
   "Swamp",
   "Path",
   "Plains",
   "Pavement",
   "Bridge",
   "Void",
   "Stable",
   "Fire",
   "Burnt",
   "Stone",
   "Some Stone",
   "No Stone",
   "Damaged Wall",
   "Broken Wall",
   "Door",
   "Closed Door",
   "Locked Door",
   "Hold",
   "Exit",
   "Ship"
};

/* Note - this message array is used to broadcast both the in sector messages,
 *  as well as the messages sent to PCs when they can't move into the sector
 */
char *const impass_message[SECT_MAX] = {
   "Inside",
   "City",
   "Field",
   "Forest",
   "Hills",
   "Mountain",
   "Water Swim",
   "Water Noswim",
   "Underwater",
   "Air",
   "Desert",
   "It is unknown, not quite safe to go into.",
   "Oceanfloor",
   "Underground",
   "Road",
   "Enter",
   "Mine Gold",
   "Mine Iron",
   "Corn Field",
   "Grain Field",
   "Chopped Trees",
   "Completely Chopped Trees",
   "Mined Gold mine",
   "Empty Gold mine",
   "Mined Iron mine",
   "Empty Iron mine",
   "Harvested Corn Field",
   "Empty Corn Field",
   "Harvested Grain Field",
   "Empty Grain Field",
   "River",
   "Jungle",
   "Shore",
   "Tundra",
   "Ice",
   "Ocean",
   "Lava",
   "The trees are too dense for you to pass through",
   "A huge massive boulder blocks your passage this direction",
   "Walking that direction into the quicksand is not a good idea.",
   "The wall is a little too big for you to pass over.",
   "A huge chunk of ice blocks you passage.",
   "Exit",
   "Swamp",
   "Path",
   "Plains",
   "Pavement",
   "Bridge",
   "That direction is blocked, you cannot enter.",
   "Stable",
   "Fire",
   "Burnt",
   "Stone",
   "Some Stone",
   "No Stone",
   "The damaged wall is a little too big for you to pass over.",
   "The nearly broken wall is a little too big for you to pass over."
   "Door",
   "You need to open the door first.",
   "You need to unlock and open the door first.",
   "Hold",
   "Exit",
   "Ship"
};

/* Changing this to use numbers instead SECT_, it really isn't needed and will allow for a ton
   of sectors and easy addition online */

void do_showascii(CHAR_DATA * ch, char *argument)
{
   int x;
   int sp;
   int mf;

   sp = 0;
   ch_printf(ch, "&R* &c&w Symbol for your location on the Map.\n\r");
   ch_printf(ch, "&G&W* &c&wSymbol for the location of another player on the Map.\n\r");
   ch_printf(ch, "^cC^x &c&wThe teal background indicated a mob (can be over any symbol.)\n\r");
   ch_printf(ch, "F &c&wAn F indicated there is a Fight going at that point on the map.\n\r");
   ch_printf(ch, "&BO &c&wA portal, help portal for more info.\n\r");
   ch_printf(ch, "&C# &c&wA transporter, typically used for intro to Fsanc.\n\r");
   ch_printf(ch, "&p+ &c&wAnything that uses the purple color has an item in the room.\n\r\n\r");
   ch_printf(ch, "symbol mv   Sector Type               symbol mv   Sector Type\n\r");
   ch_printf(ch, "     ratio                                 ratio\n\r");
   for (x = 0; x < SECT_MAX; x++)
   {
      if (sp % 2 == 0)
         ch_printf(ch, "\n\r");
      mf = sect_show[x].move / 5;
      ch_printf(ch, "   %s&c&w   %2d   %-23s   ", show_room(x, -10, -10, -10, -1), mf, sect_show[x].desc);
      sp += 1;
   }
   ch_printf(ch, "\n\r");
}

/*
const struct portal_data portal_show[] =
{
    { 259, 254, 0, "Rafermand City and Niemria" },
    { 279, 247, 0, "Wolf Forest and Shattered Refuge" },
    { 305, 224, 0, "Dwarven City and Anirandi Village" },
    { 333, 228, 0, "Unholy Grounds" },
    { 310, 268, 0, "Fire Newts" },
    { 298, 299, 0, "Field of Combat" },
    { 241, 307, 0, "Redferne" },
    { 214, 299, 0, "Dulavan Village" },
    { 274, 346, 0, "Midennir" },
    { 472, 372, 0, "Tree Village and Bluehaven" },
    { 280, 385, 0, "North Lake Alternity" },
    { 277, 404, 0, "Middle Lake Alternity" },
    { 315, 450, 0, "South Lake Alternity" },
    { 378, 419, 0, "East Lake Alternity" },
    { 243, 412, 0, "West Lake Alternity" },
    { 454, 332, 0, "Crystal Skull Palace" },
    { 429, 263, 0, "Seregon" },
    { 402, 262, 0, "New Thalos" },
    { 156, 375, 0, "Shadow Forest" },
    { 227, 238, 0, "Pixie Forest" },
    { 206, 220, 0, "Gallery" },
    { 239, 200, 0, "Nature's Retreat" },
    { 189, 194, 0, "Berum Manor" },
    { 191, 171, 0, "Black Hand Kingdom and Berum Manor" },
    { 294, 151, 0, "Aquarian Caves" },
    { 430, 45,  0, "Dragon Valley" },
    { 410, 127, 0, "Tree of Wisdom" },
    { 360, 95,  0, "Trail of Blood" },
    { 277, 222, 0, "Graveyard" },
    {  46, 442, 0, "Cove of Fire" },
    { 126, 167, 0, "Bood Caves" },
    { 360, 328, 0, "Fortress Morgond" },
    { 390, 420, 1, "Argoth Portal" },
    { 400, 211, 1, "Shikara Portal" },
    { 235, 330, 0, "Midnight Patch" },
    { 320, 340, 0, "PureLand" } 
};
 */
//Going to use functions instead of structures to give the information, will save on color usage.
char *show_room(int sector, int x, int y, int map, int begin)
{
   // -10 Use Color auto
   // -20 Don't use Color auto

   int type = 0; //no color
   int otype;

   if (x > -1 || y > -1 || map > -1)
   {
      if (map_sector[map][x - 1][y] != sector)
         type = 1;
      if (weather_sector[map][x - 1][y] >= 10)
         type = 1;
      if (begin == x)
         type = 1;
   }
   else
   {
      if (x == -10 || y == -10 || map == -10)
         type = 1;
   }

   otype = type;
   if (x > -1 && y > -1 && map > -1 && weather_sector[map][x][y] >= 10)
   {
      type = 2;
      if (NO_SNOW(map_sector[map][x][y]))
      {
         type = otype;
      }
   }

   if (type == 2 && snows == 0)
   {
      snows = 1;
      switch (sector)
      {
         case SECT_INSIDE:
            return "&w&W%";
         case SECT_CITY:
            return "&w&W#";
         case SECT_FIELD:
            return "&w&W\"";
         case SECT_FOREST:
            return "&w&W@";
         case SECT_HILLS:
            return "&w&W^^";
         case SECT_MOUNTAIN:
            return "&w&W^^";
         case SECT_WATER_SWIM:
            return "&w&W~";
         case SECT_WATER_NOSWIM:
            return "&w&W~";
         case SECT_UNDERWATER:
            return "&w&W~";
         case SECT_AIR:
            return "&w&W%";
         case SECT_DESERT:
            return "&w&W=";
         case SECT_DUNNO:
            return "&w&W?";
         case SECT_OCEANFLOOR:
            return "&w&W~";
         case SECT_UNDERGROUND:
            return "&w&W#";
         case SECT_ROAD:
            return "&w&W+";
         case SECT_ENTER:
            return "&w&W#";
         case SECT_MINEGOLD:
            return "&w&W^^";
         case SECT_MINEIRON:
            return "&w&W^^";
         case SECT_HCORN:
            return "&w&W\"";
         case SECT_HGRAIN:
            return "&w&W\"";
         case SECT_STREE:
            return "&w&W@";
         case SECT_NTREE:
            return "&w&W@";
         case SECT_SGOLD:
            return "&w&W^^";
         case SECT_NGOLD:
            return "&w&W^^";
         case SECT_SIRON:
            return "&w&W^^";
         case SECT_NIRON:
            return "&w&W^^";
         case SECT_SCORN:
            return "&w&W\"";
         case SECT_NCORN:
            return "&w&W\"";
         case SECT_SGRAIN:
            return "&w&W\"";
         case SECT_NGRAIN:
            return "&w&W\"";
         case SECT_RIVER:
            return "&w&W-";
         case SECT_JUNGLE:
            return "&w&W*";
         case SECT_SHORE:
            return "&w&W.";
         case SECT_TUNDRA:
            return "&w&W+";
         case SECT_ICE:
            return "&w&WI";
         case SECT_OCEAN:
            return "&w&W~";
         case SECT_LAVA:
            return "&w&W:";
         case SECT_TREE:
            return "&w&W*";
         case SECT_NOSTONE:
            return "&w&W^^";
         case SECT_QUICKSAND:
            return "&w&W%";
         case SECT_WALL:
            return "&w&WI";
         case SECT_DWALL:
            return "&w&OI";
         case SECT_NBWALL:
            return "&w&RI";
         case SECT_DOOR:
            return "&w&GD";
         case SECT_CDOOR:
            return "&w&YD";
         case SECT_LDOOR:
            return "&w&RD";
         case SECT_GLACIER:
            return "&w&W=";
         case SECT_EXIT:
            return "&w&W#";
         case SECT_SWAMP:
            return "&w&W%";
         case SECT_PATH:
            return "&w&W+";
         case SECT_PLAINS:
            return "&w&W~";
         case SECT_PAVE:
            return "&w&W#";
         case SECT_BRIDGE:
            return "&w&W=";
         case SECT_VOID:
            return "&w&W ";
         case SECT_STABLE:
            return "&w&W#";
         case SECT_FIRE:
            return "&w&W#";
         case SECT_BURNT:
            return "&w&W+";
         case SECT_STONE:
            return "&w&W*";
         case SECT_SSTONE:
            return "&w&W*";
         case SECT_NSTONE:
            return "&w&W*";
         case SECT_HOLD:
            return "&w&W0";
         case SECT_QEXIT:
            return "&w&W#";
         case SECT_SHIP:
            return "&w&RS";
         default:
            return "&w&W?";
      }
   }
   if (type == 2 && snows == 1)
   {
      switch (sector)
      {
         case SECT_INSIDE:
            return "%";
         case SECT_CITY:
            return "#";
         case SECT_FIELD:
            return "\"";
         case SECT_FOREST:
            return "@";
         case SECT_HILLS:
            return "^^";
         case SECT_MOUNTAIN:
            return "^^";
         case SECT_WATER_SWIM:
            return "~";
         case SECT_WATER_NOSWIM:
            return "~";
         case SECT_UNDERWATER:
            return "~";
         case SECT_AIR:
            return "%";
         case SECT_DESERT:
            return "=";
         case SECT_DUNNO:
            return "?";
         case SECT_OCEANFLOOR:
            return "~";
         case SECT_UNDERGROUND:
            return "#";
         case SECT_ROAD:
            return "+";
         case SECT_ENTER:
            return "#";
         case SECT_MINEGOLD:
            return "^^";
         case SECT_MINEIRON:
            return "^^";
         case SECT_HCORN:
            return "\"";
         case SECT_HGRAIN:
            return "\"";
         case SECT_STREE:
            return "@";
         case SECT_NTREE:
            return "@";
         case SECT_SGOLD:
            return "^^";
         case SECT_NGOLD:
            return "^^";
         case SECT_SIRON:
            return "^^";
         case SECT_NIRON:
            return "^^";
         case SECT_SCORN:
            return "\"";
         case SECT_NCORN:
            return "\"";
         case SECT_SGRAIN:
            return "\"";
         case SECT_NGRAIN:
            return "\"";
         case SECT_RIVER:
            return "-";
         case SECT_JUNGLE:
            return "*";
         case SECT_SHORE:
            return ".";
         case SECT_TUNDRA:
            return "+";
         case SECT_ICE:
            return "I";
         case SECT_OCEAN:
            return "~";
         case SECT_LAVA:
            return ":";
         case SECT_TREE:
            return "*";
         case SECT_NOSTONE:
            return "^^";
         case SECT_QUICKSAND:
            return "%";
         case SECT_WALL: case SECT_DWALL: case SECT_NBWALL:
            return "I";
         case SECT_DOOR: case SECT_CDOOR: case SECT_LDOOR:
            return "D";
         case SECT_GLACIER:
            return "=";
         case SECT_EXIT:
            return "#";
         case SECT_SWAMP:
            return "%";
         case SECT_PATH:
            return "+";
         case SECT_PLAINS:
            return "~";
         case SECT_PAVE:
            return "#";
         case SECT_BRIDGE:
            return "=";
         case SECT_VOID:
            return " ";
         case SECT_STABLE:
            return "#";
         case SECT_FIRE:
            return "#";
         case SECT_BURNT:
            return "+";
         case SECT_STONE:
            return "*";
         case SECT_SSTONE:
            return "*";
         case SECT_NSTONE:
            return "*";
         case SECT_HOLD:
            return "0";
         case SECT_QEXIT:
            return "#";
         case SECT_SHIP:
            return "S";
         default:
            return "?";
      }
   }

   snows = 0;
   if (type == 1)
   {
      switch (sector)
      {
         case SECT_INSIDE:
            return "&G&W%";
         case SECT_CITY:
            return "&G&W#";
         case SECT_FIELD:
            return "&G\"";
         case SECT_FOREST:
            return "&G@";
         case SECT_HILLS:
            return "&G^^";
         case SECT_MOUNTAIN:
            return "&O^^";
         case SECT_WATER_SWIM:
            return "&C~";
         case SECT_WATER_NOSWIM:
            return "&c~";
         case SECT_UNDERWATER:
            return "&B~";
         case SECT_AIR:
            return "&C%";
         case SECT_DESERT:
            return "&Y=";
         case SECT_DUNNO:
            return "&x?";
         case SECT_OCEANFLOOR:
            return "&b~";
         case SECT_UNDERGROUND:
            return "&O#";
         case SECT_ROAD:
            return "&c&w+";
         case SECT_ENTER:
            return "&G&W#";
         case SECT_MINEGOLD:
            return "&Y^^";
         case SECT_MINEIRON:
            return "&R^^";
         case SECT_HCORN:
            return "&Y\"";
         case SECT_HGRAIN:
            return "&z\"";
         case SECT_STREE:
            return "&g@";
         case SECT_NTREE:
            return "&c&w@";
         case SECT_SGOLD:
            return "&c&w^^";
         case SECT_NGOLD:
            return "&b^^";
         case SECT_SIRON:
            return "&B^^";
         case SECT_NIRON:
            return "&z^^";
         case SECT_SCORN:
            return "&O\"";
         case SECT_NCORN:
            return "&b\"";
         case SECT_SGRAIN:
            return "&z\"";
         case SECT_NGRAIN:
            return "&G\"";
         case SECT_RIVER:
            return "&B-";
         case SECT_JUNGLE:
            return "&g*";
         case SECT_SHORE:
            return "&Y.";
         case SECT_TUNDRA:
            return "&G&W+";
         case SECT_ICE:
            return "&G&WI";
         case SECT_OCEAN:
            return "&b~";
         case SECT_LAVA:
            return "&R:";
         case SECT_TREE:
            return "&G*";
         case SECT_NOSTONE:
            return "&c&w^^";
         case SECT_QUICKSAND:
            return "&O%";
         case SECT_WALL:
            return "&c&wI";
         case SECT_DWALL:
            return "&OI";
         case SECT_NBWALL:
            return "&RI";
         case SECT_DOOR:
            return "&w&GD";
         case SECT_CDOOR:
            return "&w&YD";
         case SECT_LDOOR:
            return "&w&RD";
         case SECT_GLACIER:
            return "&G&W=";
         case SECT_EXIT:
            return "&G&W#";
         case SECT_SWAMP:
            return "&g%";
         case SECT_PATH:
            return "&g+";
         case SECT_PLAINS:
            return "&O~";
         case SECT_PAVE:
            return "&z#";
         case SECT_BRIDGE:
            return "&C=";
         case SECT_VOID:
            return "&x ";
         case SECT_STABLE:
            return "&c&w#";
         case SECT_FIRE:
            return "&R#";
         case SECT_BURNT:
            return "&r+";
         case SECT_STONE:
            return "&c&w*";
         case SECT_SSTONE:
            return "&z*";
         case SECT_NSTONE:
            return "&Y*";
         case SECT_HOLD:
            return "&w&R0";
         case SECT_QEXIT:
            return "&w&P#";
         case SECT_SHIP:
            return "&w&RS";
         default:
            return "&G?";
      }
   }
   else
   {
      if (begin == x)
      {
         return show_room(sector, -10, -10, -10, -1);
      }
      switch (sector)
      {
         case SECT_INSIDE:
            return "%";
         case SECT_CITY:
            return "#";
         case SECT_FIELD:
            return "\"";
         case SECT_FOREST:
            return "@";
         case SECT_HILLS:
            return "^^";
         case SECT_MOUNTAIN:
            return "^^";
         case SECT_WATER_SWIM:
            return "~";
         case SECT_WATER_NOSWIM:
            return "~";
         case SECT_UNDERWATER:
            return "~";
         case SECT_AIR:
            return "%";
         case SECT_DESERT:
            return "=";
         case SECT_DUNNO:
            return "?";
         case SECT_OCEANFLOOR:
            return "~";
         case SECT_UNDERGROUND:
            return "#";
         case SECT_ROAD:
            return "+";
         case SECT_ENTER:
            return "#";
         case SECT_MINEGOLD:
            return "^^";
         case SECT_MINEIRON:
            return "^^";
         case SECT_HCORN:
            return "\"";
         case SECT_HGRAIN:
            return "\"";
         case SECT_STREE:
            return "@";
         case SECT_NTREE:
            return "@";
         case SECT_SGOLD:
            return "^^";
         case SECT_NGOLD:
            return "^^";
         case SECT_SIRON:
            return "^^";
         case SECT_NIRON:
            return "^^";
         case SECT_SCORN:
            return "\"";
         case SECT_NCORN:
            return "\"";
         case SECT_SGRAIN:
            return "\"";
         case SECT_NGRAIN:
            return "\"";
         case SECT_RIVER:
            return "-";
         case SECT_JUNGLE:
            return "*";
         case SECT_SHORE:
            return ".";
         case SECT_TUNDRA:
            return "+";
         case SECT_ICE:
            return "I";
         case SECT_OCEAN:
            return "~";
         case SECT_LAVA:
            return ":";
         case SECT_TREE:
            return "*";
         case SECT_NOSTONE:
            return "^^";
         case SECT_QUICKSAND:
            return "%";
         case SECT_WALL: case SECT_DWALL: case SECT_NBWALL:
            return "I";
         case SECT_DOOR: case SECT_CDOOR: case SECT_LDOOR:
            return "D";
         case SECT_GLACIER:
            return "=";
         case SECT_EXIT:
            return "#";
         case SECT_SWAMP:
            return "%";
         case SECT_PATH:
            return "+";
         case SECT_PLAINS:
            return "~";
         case SECT_PAVE:
            return "#";
         case SECT_BRIDGE:
            return "=";
         case SECT_VOID:
            return " ";
         case SECT_STABLE:
            return "#";
         case SECT_FIRE:
            return "#";
         case SECT_BURNT:
            return "+";
         case SECT_STONE:
            return "*";
         case SECT_SSTONE:
            return "*";
         case SECT_NSTONE:
            return "*";
         case SECT_HOLD:
            return "0";
         case SECT_QEXIT:
            return "#";
         case SECT_SHIP:
            return "S";
         default:
            return "?";
      }
   }
   return "&G?";
}

/* Values are base 9, 9 being good, 1 being bad */
const struct sect_color_type sect_show[] = {
   {SECT_INSIDE, "&G&W", "%", "%", "", 0, 5, "inside", TRUE, "c.gif"},
   {SECT_CITY, "&G&W", "#", "#", "", 0, 10, "city", TRUE, "c.gif"},
   {SECT_FIELD, "&G", "\"", "\"", "", 2, 14, "field", TRUE, "f.gif"},
   {SECT_FOREST, "&G", "@", "@", "", 4, 25, "forest", TRUE, "f2.gif"},
   {SECT_HILLS, "&G", "^^", "^", "", 3, 32, "hills", TRUE, "h.gif"},
   {SECT_MOUNTAIN, "&O", "^^", "^", "", 5, 45, "mountain", TRUE, "m.gif"},
   {SECT_WATER_SWIM, "&C", "~", "~", "", 2, 35, "shallow water", TRUE, "w3.gif"},
   {SECT_WATER_NOSWIM, "&c", "~", "~", "", 3, 40, "deep water", TRUE, "w2.gif"},
   {SECT_UNDERWATER, "&B", "~", "~", "", 3, 42, "underwater", TRUE, "o.gif"},
   {SECT_AIR, "&C", "%", "%", "", 2, 70, "air", TRUE, "f.gif"},
   {SECT_DESERT, "&Y", "=", "=", "", 2, 45, "desert", TRUE, "d.gif"},
   {SECT_DUNNO, "&x", "?", "?", "", 2, 39, "Unknown", FALSE, "f.gif"},
   {SECT_OCEANFLOOR, "&b", "~", "~", "", 3, 50, "ocean floor", TRUE, "o.gif"},
   {SECT_UNDERGROUND, "&O", "#", "#", "", 3, 34, "underground", TRUE, "f.gif"},
   {SECT_ROAD, "&c&w", "+", "+", "", 1, 5, "road", TRUE, "r.gif"},
   {SECT_ENTER, "&G&W", "#", "#", "", 0, 12, "enter", TRUE, "e.gif"},
   {SECT_MINEGOLD, "&Y", "^^", "^", "", 5, 45, "gold mine", TRUE, "m.gif"},
   {SECT_MINEIRON, "&R", "^^", "^", "", 5, 45, "iron mine", TRUE, "m.gif"},
   {SECT_HCORN, "&Y", "\"", "\"", "", 2, 14, "corn field", TRUE, "f.gif"},
   {SECT_HGRAIN, "&z", "\"", "\"", "", 2, 14, "grain field", TRUE, "f.gif"},
   {SECT_STREE, "&g", "@", "@", "", 3, 25, "chopped trees", TRUE, "f2.gif"},
   {SECT_NTREE, "&c&w", "@", "@", "", 3, 25, "tree stumps", TRUE, "f2.gif"},
   {SECT_SGOLD, "&c&w", "^^", "^", "", 5, 45, "mined gold mine", TRUE, "m.gif"},
   {SECT_NGOLD, "&b", "^^", "^", "", 5, 45, "empty gold mine", TRUE, "m.gif"},
   {SECT_SIRON, "&B", "^^", "^", "", 5, 45, "mined iron mine", TRUE, "m.gif"},
   {SECT_NIRON, "&z", "^^", "^", "", 5, 45, "empty iron mine", TRUE, "m.gif"},
   {SECT_SCORN, "&O", "\"", "\"", "", 2, 14, "havested corn field", TRUE, "f.gif"},
   {SECT_NCORN, "&b", "\"", "\"", "", 2, 14, "empty corn field", TRUE, "f.gif"},
   {SECT_SGRAIN, "&z", "\"", "\"", "", 2, 14, "harvested grain field", TRUE, "f.gif"},
   {SECT_NGRAIN, "&G", "\"", "\"", "", 2, 14, "empty grain field", TRUE, "f.gif"},
   {SECT_RIVER, "&B", "-", "-", "", 2, 42, "river", TRUE, "r2.gif"},
   {SECT_JUNGLE, "&g", "*", "*", "", 3, 35, "jungle", TRUE, "j.gif"},
   {SECT_SHORE, "&Y", ".", ".", "", 2, 9, "shoreline", TRUE, "s.gif"},
   {SECT_TUNDRA, "&G&W", "+", "+", "", 3, 21, "tundra", TRUE, "i.gif"},
   {SECT_ICE, "&G&W", "I", "I", "", 4, 40, "ice", TRUE, "i.gif"},
   {SECT_OCEAN, "&b", "~", "~", "", 4, 80, "ocean", FALSE, "o.gif"},
   {SECT_LAVA, "&R", ":", ":", "", 5, 68, "lava", TRUE, "l.gif"},
   {SECT_TREE, "&G", "*", "*", "", 0, 0, "impassable forest", FALSE, "f2.gif"},
   {SECT_NOSTONE, "&c&w", "^^", "^", "", 0, 0, "impassable mountain", FALSE, "m.gif"},
   {SECT_QUICKSAND, "&O", "%", "%", "", 0, 0, "quicksand(nopass swamp)", FALSE, "f.gif"},
   {SECT_WALL, "&c&w", "I", "I", "", 0, 0, "wall", FALSE, "w.gif"},
   {SECT_GLACIER, "&W", "=", "=", "", 0, 0, "glacier(nopass ice)", FALSE, "f.gif"},
   {SECT_EXIT, "&G&W", "#", "#", "", 0, 0, "exit", TRUE, "e.gif"},
   {SECT_SWAMP, "&g", "%", "%", "", 4, 38, "swamp", TRUE, "s4.gif"},
   {SECT_PATH, "&g", "+", "+", "", 1, 5, "path", TRUE, "r.gif"},
   {SECT_PLAINS, "&O", "~", "~", "", 2, 12, "plains", TRUE, "p.gif"},
   {SECT_PAVE, "&z", "#", "#", "", 2, 7, "pavement", TRUE, "r.gif"},
   {SECT_BRIDGE, "&C", "=", "=", "", 2, 7, "bridge", TRUE, "r.gif"},
   {SECT_VOID, "&x", " ", " ", "", 0, 0, "void", FALSE, "v.gif"},
   {SECT_STABLE, "&c&w", "#", "#", "", 0, 0, "stable", TRUE, "r.gif"},
   {SECT_FIRE, "&R", "#", "#", "", 0, 20, "fire", TRUE, "f.gif"},
   {SECT_BURNT, "&r", "+", "+", "", 2, 14, "burnt", TRUE, "f.gif"},
   {SECT_STONE, "&c&w", "*", "*", "", 3, 27, "stone", TRUE, "s3.gif"},
   {SECT_SSTONE, "&z", "*", "*", "", 3, 27, "some stone", TRUE, "s3.gif"},
   {SECT_NSTONE, "&Y", "*", "*", "", 3, 27, "no stone", TRUE, "s3.gif"},
   {SECT_DWALL, "&O", "I", "I", "", 0, 0, "damaged wall", FALSE, "w.gif"},
   {SECT_NBWALL, "&R", "I", "I", "", 0, 0, "nearly broke wall", FALSE, "w.gif"},
   {SECT_DOOR, "&G", "D", "D", "", 0, 5, "door", TRUE, "d2.gif"},
   {SECT_CDOOR, "&Y", "D", "D", "", 0, 0, "closed door", FALSE, "d2.gif"},
   {SECT_LDOOR, "&R", "D", "D", "", 0, 0, "locked door", FALSE, "d2.gif"},
   {SECT_HOLD,  "&R", "0", "0", "", 0, 5, "hold", TRUE, "s2.gif"},
   {SECT_QEXIT, "&w&P", "#", "#", "", 0, 0, "exit", TRUE, "q.gif"},
   {SECT_SHIP, "&w&R", "S", "S", "", 0, 0, "ship", FALSE, "q.gif"}
   
};

//Checks to see if the movement is valid, and changes the pointers
//to x and y with the new coords.  Passes back failure messages if
//ch is passed to it!

bool is_valid_movement(int *px, int *py, char *arg, CHAR_DATA *ch)
{
   int x, y;
   x = *px;
   y = *py;
   if (!str_cmp(arg, "n") || !str_cmp(arg, "north"))
      y = y-1;
   if (!str_cmp(arg, "s") || !str_cmp(arg, "south"))
      y = y+1;
   if (!str_cmp(arg, "e") || !str_cmp(arg, "east"))
      x = x+1;
   if (!str_cmp(arg, "w") || !str_cmp(arg, "west"))
      x = x-1;
   if (!str_cmp(arg, "nw") || !str_cmp(arg, "northwest"))
   {
      y = y-1;
      x = x-1;    
   }
   if (!str_cmp(arg, "ne") || !str_cmp(arg, "northeast"))
   {
      y = y-1;
      x = x+1;
   }
   if (!str_cmp(arg, "sw") || !str_cmp(arg, "southwest"))
   {
      y = y+1;
      x = x-1; 
   }
   if (!str_cmp(arg, "se") || !str_cmp(arg, "southeast"))
   {
      y = y+1;
      x = x+1; 
   }   
   if (x < 1 || x > MAX_X || y < 1 || y > MAX_Y)
   {
      if (ch)
         send_to_char("That is off the map, you cannot do that.\n\r", ch);
      return FALSE;
   }
   if (*px == x && *py == y)
   {
      if (ch)
         send_to_char("You have to choose a direction, ex: n nw n northwest\n\r", ch);
      return FALSE;
   }
   *px = x;
   *py = y;
   return TRUE;
}
   

void add_entrance(int tomap, int onmap, int hereX, int hereY, int thereX, int thereY, int vnum)
{
   ENTRANCE_DATA *enter;

   CREATE(enter, ENTRANCE_DATA, 1);
   LINK(enter, first_entrance, last_entrance, next, prev);
   enter->tomap = tomap;
   enter->onmap = onmap;
   CREATE(enter->here, COORD_DATA, 1);
   CREATE(enter->there, COORD_DATA, 1);
   enter->here->x = hereX;
   enter->here->y = hereY;
   enter->there->x = thereX;
   enter->there->y = thereY;
   enter->vnum = vnum;

   return;
}

void delete_entrance(ENTRANCE_DATA * enter)
{
   enter->tomap = 0;
   enter->onmap = 0;
   enter->here->x = 0;
   enter->here->y = 0;
   enter->there->x = 0;
   enter->there->y = 0;
   enter->vnum = 0;
   UNLINK(enter, first_entrance, last_entrance, next, prev);

   return;
}

#if defined(KEY)
#undef KEY
#endif

#define KEY( literal, field, value )					\
				if ( !str_cmp( word, literal ) )	\
				{					\
				      field = value;			\
				      fMatch = TRUE;			\
				      break;				\
				}

void fread_entrance(ENTRANCE_DATA * enter, FILE * fp)
{
   char buf[MSL];
   char *word;
   bool fMatch;

   for (;;)
   {
      word = feof(fp) ? "End" : fread_word(fp);
      fMatch = FALSE;

      switch (UPPER(word[0]))
      {
         case '*':
            fMatch = TRUE;
            fread_to_eol(fp);
            break;

         case 'E':
            if (!str_cmp(word, "End"))
            {
               return;
            }
            break;

         case 'H':
            if (!str_cmp(word, "Here"))
            {
               enter->here->x = fread_number(fp);
               enter->here->y = fread_number(fp);
               fMatch = TRUE;
               break;
            }
            break;

         case 'O':
            KEY("OnMap", enter->onmap, fread_number(fp));
            break;

         case 'T':
            if (!str_cmp(word, "There"))
            {
               enter->there->x = fread_number(fp);
               enter->there->y = fread_number(fp);
               fMatch = TRUE;
               break;
            }
            KEY("ToMap", enter->tomap, fread_number(fp));
            break;

         case 'V':
            KEY("Vnum", enter->vnum, fread_number(fp));
            break;
      }

      if (!fMatch)
      {
         sprintf(buf, "Fread_entrance: no match: %s", word);
         bug(buf, 0);
      }
   }
}

void load_entrances()
{
   char filename[256];
   ENTRANCE_DATA *enter;
   FILE *fp;

   first_entrance = NULL;
   last_entrance = NULL;

   sprintf(filename, "%s%s", MAP_DIR, ENTRANCE_FILE);

   if ((fp = fopen(filename, "r")) != NULL)
   {
      for (;;)
      {
         char letter;
         char *word;

         letter = fread_letter(fp);
         if (letter == '*')
         {
            fread_to_eol(fp);
            continue;
         }

         if (letter != '#')
         {
            bug("Load_entrances: # not found.", 0);
            break;
         }

         word = fread_word(fp);
         if (!str_cmp(word, "ENTRANCE"))
         {
            CREATE(enter, ENTRANCE_DATA, 1);
            CREATE(enter->here, COORD_DATA, 1);
            CREATE(enter->there, COORD_DATA, 1);
            fread_entrance(enter, fp);
            LINK(enter, first_entrance, last_entrance, next, prev);
            continue;
         }
         else if (!str_cmp(word, "END"))
            break;
         else
         {
            char buf[MSL];

            sprintf(buf, "Load_entrances: bad section: %s.", word);
            bug(buf, 0);
            continue;
         }
      }
      FCLOSE(fp);
   }

   return;
}

char *get_area_from_vnum(int vnum)
{
   static char area[200];
   AREA_DATA *tarea;
   
   for (tarea = first_asort; tarea; tarea = tarea->next)
   {
      if (vnum >= tarea->low_r_vnum && vnum <= tarea->hi_r_vnum)
         break;
   }
   if (!tarea)
   {
      for (tarea = first_bsort; tarea; tarea = tarea->next)
      {
         if (vnum >= tarea->low_r_vnum && vnum <= tarea->hi_r_vnum)
            break;
      }
   }
   if (!tarea)
      return "Unknown";
   else
   {
      sprintf(area, "%s", tarea->name);
      return &area[0];
   }
}

//sorts and cleans entrances.  Removing those that are linked oddly
void sort_entrances()
{
   ENTRANCE_DATA *enter;
   ENTRANCE_DATA *senter;
   ENTRANCE_DATA *nenter;
   ENTRANCE_DATA *next_entrance;
   ENTRANCE_DATA *first_sort_entrance = NULL;
   ENTRANCE_DATA *last_sort_entrance = NULL;
   
   for (enter = first_entrance; enter; enter = next_entrance)
   {
     next_entrance = enter->next;
     if (!first_sort_entrance)
        LINK(enter, first_sort_entrance, last_sort_entrance, next, prev);
     else
     {
        if (enter->vnum <= first_sort_entrance->vnum)
        {
           nenter = first_sort_entrance;
           enter->prev = NULL;
           nenter->prev = enter;
           enter->next = nenter;
           first_sort_entrance = enter;
           continue;
        }
        for (senter = first_sort_entrance; senter; senter = senter->next)
        {
           if (senter->next == NULL)
           {
              LINK(enter, first_sort_entrance, last_sort_entrance, next, prev);
              break;
           }
           if (enter->vnum <= senter->next->vnum)
           {
              nenter = senter->next;
              nenter->prev->next = enter;
              enter->prev = nenter->prev;
              nenter->prev = enter;
              enter->next = nenter;
              break;
           }
        }
     }
  }
  first_entrance = first_sort_entrance;
  last_entrance = last_sort_entrance;
  for (enter = first_entrance; enter; enter = next_entrance)
  {
     next_entrance = enter->next;
     
     if (enter->next && enter->next->vnum == enter->vnum && enter->next->here->x == enter->here->x && enter->next->here->y == enter->here->y)
     {
        UNLINK(enter, first_entrance, last_entrance, next, prev);
     }
  }
  for (enter = first_entrance; enter; enter = next_entrance)
  {
     next_entrance = enter->next;
     
     if (!str_cmp(get_area_from_vnum(enter->vnum), "Unknown"))
     {
        UNLINK(enter, first_entrance, last_entrance, next, prev);
     }
  }
}

void do_showentrances(CHAR_DATA *ch, char *argument)
{
   ENTRANCE_DATA *enter;
   int num = 1;
   
   sort_entrances();
   send_to_char("Num  ToMap  Onmap  Here       There       Vnum   Area\n\r-----------------------------------------------------------\n\r", ch);
   for (enter = first_entrance; enter; enter = enter->next)
   {
      ch_printf(ch, "%-3d  %-2d     %-2d     %-4d %-4d  %-4d  %-4d  %-5d  %s\n\r", num, enter->tomap, enter->onmap, enter->here->x, enter->here->y,
                     enter->there->x, enter->there->y, enter->vnum, get_area_from_vnum(enter->vnum));
      num++;
   }
}    

void save_entrances()
{
   ENTRANCE_DATA *enter;
   FILE *fp;
   char filename[256];

   sprintf(filename, "%s%s", MAP_DIR, ENTRANCE_FILE);

   FCLOSE(fpReserve);
   if ((fp = fopen(filename, "w")) == NULL)
   {
      bug("save_entrances: fopen", 0);
      perror(filename);
   }
   else
   {
      for (enter = first_entrance; enter; enter = enter->next)
      {
         fprintf(fp, "#ENTRANCE\n");
         fprintf(fp, "ToMap	%d\n", enter->tomap);
         fprintf(fp, "OnMap	%d\n", enter->onmap);
         fprintf(fp, "Here	%d %d\n", enter->here->x, enter->here->y);
         fprintf(fp, "There	%d %d\n", enter->there->x, enter->there->y);
         fprintf(fp, "Vnum	%d\n", enter->vnum);
         fprintf(fp, "End\n\n");
      }
      fprintf(fp, "#END\n");
      FCLOSE(fp);
   }
   fpReserve = fopen(NULL_FILE, "r");
   return;
}

ENTRANCE_DATA *check_entrance(CHAR_DATA * ch, int map, int x, int y)
{
   ENTRANCE_DATA *enter;

   for (enter = first_entrance; enter; enter = enter->next)
   {
      if (enter->onmap == map)
      {
         if (enter->here->x == x && enter->here->y == y)
            return enter;
      }
   }
   return NULL;
}
char *get_map_name(int map)
{
   if (map < 0 || map > MAP_MAX)
      return "unknown";
   else
      return map_names[map];
}

bool can_see_room(int x, int y, int map, int sector)
{
   TOWN_DATA *town;
   DOOR_DATA *ddata;
   int z;
   
   //the map does a lot of processing, lets not do more than is needed...
   if (sector != SECT_INSIDE)
      return TRUE;
   if (kingdom_sector[map][x][y] < 2 || kingdom_sector[map][x][y] > sysdata.max_kingdom)
      return TRUE;
      
   town = find_town(x, y, map);
   
   if (town)
   {
      for (ddata = town->first_doorlist->first_door; ddata; ddata = ddata->next)
      {
         for (z = 0; z <= MAX_HPOINTS-1; z++)
         {
            if (ddata->roomcoordx[z] == x && ddata->roomcoordy[z] == y && ddata->roomcoordmap[z] == map)
            {
               if (ddata->cansee == 0)
                  return FALSE;
               else
                  return TRUE;
            }
         }
      }
   }
   return TRUE;
}

int update_inside_stat(int fnddoor[], CHAR_DATA *ch, TOWN_DATA *town, int x, int y, int map)
{
   int udoornum;
   DOOR_DATA *ddata;
   int z;
   int fnx;
   int cnt;
   int fnd;
   int fx;
   int dx;
   
   fx = 0;
   cnt = -1;
   
   for (ddata = town->first_doorlist->first_door; ddata; ddata = ddata->next)
   {
      for (z = 0; z <= MAX_HPOINTS-1; z++)
      {
         if (ddata->roomcoordx[z] == x && ddata->roomcoordy[z] == y && ddata->roomcoordmap[z] == map)
            break;
      }
      if (z != MAX_HPOINTS)
      {
         for (dx = 0; dx <= 9; dx++)
         {
            if (ddata->doorvalue[dx] > 0)
            {
               for (fnx = 0; fnx <= 99; fnx++)
               {
                  if (town->doorstate[4][fnx] == ddata->doorvalue[dx] && town->doorstate[0][fnx] == 0)
                  {
                     fnddoor[fx++] = town->doorstate[4][fnx];
                     ddata->cannotsee = 1;
                     break;
                  }
               }
               if (fnx <= 99)
                  break;
            }
         }
      }
   }
   if (fx == 0)
      return 0;
   
   for (;;)
   {
      if (fx == ++cnt) //we managed to exhaust all the doors, lets exit
         break;        
      udoornum = fnddoor[cnt];
      for (ddata = town->first_doorlist->first_door; ddata; ddata = ddata->next)
      {
         fnd = 1;
         for (z = 0; z <= 9; z++)
         {
            if (ddata->doorvalue[z] == udoornum)
              break;
         }
         if (z != 10)
         {
            ddata->cannotsee = 1;
            //lets look for open doors....
            for (z = 0; z <= 9; z++)
            {
               if (ddata->doorvalue[z] > 0)
               {
                  for (fnx = 0; fnx <= 99; fnx++)
                  {
                     if (town->doorstate[4][fnx] == ddata->doorvalue[z])
                        break;
                  }
                  if (town->doorstate[0][fnx] == 0 && town->doorstate[3][fnx] == 1) //Open Master Door, I can see light!!!
                     return 1;
                  if (fnx <= 99 && town->doorstate[0][fnx] == 0) //open
                  {
                     for (fnx = 0; fnx <= 99; fnx++)
                     {
                        if (fnddoor[fnx] == 0)
                        {
                           fnd = 0;
                           break;
                        }
                        if (fnddoor[fnx] == ddata->doorvalue[z])
                        {
                           break;
                        }
                     }
                     if (fnx == 100) //err this shouldn't happen....
                     {
                        bug("update_inside_stat:  The fnddoor array is full for town %s", town->name);
                        return 1;
                     }
                     if (fnd == 0)
                     {
                        fnddoor[fx++] = ddata->doorvalue[z];
                     }
                  }
               }
            }
         }
      }//end ddata for check for open
   }//end infinite loop for open
   return 0;
}

void do_mxp(CHAR_DATA *ch, char *argument)
{
   char arg[MIL];
   
   if (check_npc(ch))
      return;
   if (argument[0] == '\0')
   {
      send_to_char("Syntax:  mxp mapwindow [on/off]\n\r", ch);
      send_to_char("Syntax:  mxp mapwindow [close/open]\n\r", ch);
      send_to_char("Syntax:  mxp wildernesstiles [on/off]\n\r", ch);
      return;
   }
   argument = one_argument(argument, arg);
   if (!str_cmp(arg, "wildernesstiles"))
   {
      if (!str_cmp(argument, "on"))
      {
         xSET_BIT(ch->act, PLR_WILDERTILES);
         send_to_char("Wilderness Tiles set to load, make sure you have downloaded them or you will get nothing.\n\r", ch);
         return;
      }
      if (!str_cmp(argument, "off"))
      {
         xREMOVE_BIT(ch->act, PLR_WILDERTILES);
         send_to_char("Wilderness Tiles set to not load.\n\r", ch);
         return;
      }
   }
   if (!str_cmp(arg, "mapwindow"))
   {
      if (!str_cmp(argument, "on"))
      {
         xSET_BIT(ch->act, PLR_MAPWINDOW);
         ch->pcdata->xsize = 0;
         ch->pcdata->ysize = 0;
         ch_printf(ch, "%s", MXPTAG("FRAME Name=\"Map\" FLOATING Left=\"-21c\" Top=\"0\" Width=\"21c\" Height=\"21c\"")); 
         send_to_char("The window was turned on and loaded, if you do not see it, you might not have mxp support.\n\r", ch);
         return;
      }
      if (!str_cmp(argument, "off"))
      {
         xREMOVE_BIT(ch->act, PLR_MAPWINDOW);
         ch->pcdata->xsize = 0;
         ch->pcdata->ysize = 0;
         ch_printf(ch, "%s", MXPTAG("FRAME Map CLOSE"));
         send_to_char("The window was turned off and the window was closed.\n\r", ch);
         return;
      }
      if (!str_cmp(argument, "close"))
      {
         ch_printf(ch, "%s", MXPTAG("FRAME Map CLOSE"));
         send_to_char("Window closed, but not turned off.\n\r", ch);
         return;
      }
      if (!str_cmp(argument, "open"))
      {
         ch_printf(ch, "%s", MXPTAG("FRAME Name=\"Map\" FLOATING Left=\"-21c\" Top=\"0\" Width=\"21c\" Height=\"21c\"")); 
         send_to_char("Window opened but not turned on/off.\n\r", ch);
         return;
      }
   }
   do_mxp(ch, "");
   return;
}  
        
void do_portal(CHAR_DATA *ch, char *argument)
{
   char arg1[MIL];
   char arg2[MIL];
   char arg3[MIL];
   char arg4[MIL];
   int p;
   int count = 0;
   int x, y, map;
   PORTAL_DATA *portal;
   
   x=y=0;
   map=-1;
   
   if (argument[0] == '\0')
   {
      send_to_char("Syntax:  portal list\n\r", ch);
      send_to_char("Syntax:  portal add [x] [y] [map] <Description>\n\r", ch);
      send_to_char("Syntax:  portal remove [x] [y] [map]\n\r", ch);
      return;
   }
   
   argument = one_argument(argument, arg1);
   
   if (!str_cmp(arg1, "list"))
   {
      for (p = 0; p < sysdata.last_portal; p++)
      {
         ch_printf(ch, "[%2d]  %-4dX  %-4dY  %s\n\r", ++count, portal_show[p]->x, portal_show[p]->y, portal_show[p]->desc);
      }
      return;
   }    
   if (!str_cmp(arg1, "remove"))
   {
      if (atoi(argument) > 0)
      {
         argument = one_argument(argument, arg2);
         argument = one_argument(argument, arg3);
         argument = one_argument(argument, arg4);
         x = atoi(arg2);
         y = atoi(arg3);
         map = atoi(arg4);
      }
      if (x == 0)
      {
         if (!IN_WILDERNESS(ch))
         {
            send_to_char("You need to be in the wilderness to remove a portal.\n\r", ch);
            return;
         }
         x = ch->coord->x;
         y = ch->coord->y;
         map = ch->map;         
      }
      if (x < 1 || x > MAX_X || y < 1 || y > MAX_Y || map < 0 || map >= MAP_MAX)
      {
         send_to_char("That is not a valid coordinates.\n\r", ch);
         return;
      }
      for (p = 0; p < sysdata.last_portal; p++)
      {
         if (portal_show[p]->x == x && portal_show[p]->y == y && portal_show[p]->map == map)
            break;
      }
      if (p == sysdata.last_portal)
      {
         send_to_char("There is no portal to remove!!!\n\r", ch);
         return;
      }
      STRFREE(portal_show[p]->desc);
      for (x = p+1; x < sysdata.last_portal; x++)
      {
         portal_show[x-1] = portal_show[x];
      }
      portal_show[x-1] = NULL;
      sysdata.last_portal--;
      send_to_char("Done.\n\r", ch);
      save_portal_file();
      return;
   }
   if (!str_cmp(arg1, "add"))
   {
      if (sysdata.last_portal == LAST_PORTAL)
      {
         send_to_char("There are 100 portals, that is the max, increase LAST_PORTAL variable to add more.\n\r", ch);
         return;
      }
      if (atoi(argument) > 0)
      {
         argument = one_argument(argument, arg2);
         argument = one_argument(argument, arg3);
         argument = one_argument(argument, arg4);
         x = atoi(arg2);
         y = atoi(arg3);
         map = atoi(arg4);
      }
      if (x == 0)
      {
         if (!IN_WILDERNESS(ch))
         {
            send_to_char("You need to be in the wilderness to add a portal.\n\r", ch);
            return;
         }
         x = ch->coord->x;
         y = ch->coord->y;
         map = ch->map;         
      }
      if (x < 1 || x > MAX_X || y < 1 || y > MAX_Y || map < 0 || map >= MAP_MAX)
      {
         send_to_char("That is not a valid coordinates.\n\r", ch);
         return;
      }
      for (p = 0; p < sysdata.last_portal; p++)
      {
         if (portal_show[p]->x == x && portal_show[p]->y == y && portal_show[p]->map == map)
            break;
      }
      if (p < sysdata.last_portal)
      {
         send_to_char("There is already a portal here, remove it first if you want to add a new one.\n\r", ch);
         return;
      }
      CREATE(portal, PORTAL_DATA, 1);
      portal->x = x;
      portal->y = y;
      portal->map = map;
      portal->desc = STRALLOC(argument);
      portal_show[sysdata.last_portal++] = portal;
      send_to_char("Done.\n\r", ch);
      save_portal_file();
      return;
   }
   do_portal(ch, "");
   return;
}

void do_ships(CHAR_DATA *ch, char *argument)
{
   SHIP_DATA *ship;
   int num = 1;
   char arg1[MIL];
   char arg2[MIL];
   char arg3[MIL];
   
   if (argument[0] == '\0')
   {
      send_to_char("Syntax:  ships create\n\r", ch);
      send_to_char("Syntax:  ships list\n\r", ch);
      send_to_char("Syntax:  ships delete <number>\n\r", ch);
      send_to_char("Syntax:  ships edit <number> <size/route/routetime/occupants> <value>\n\r", ch);
      return;
   }  
   if (!str_cmp(argument, "list"))
   {
      send_to_char("Num   X     Y     TX    TY    Dir    Occupants  Routetime  Route  Size\n\r-----------------------------------------------\n\r", ch);
      for (ship = first_ship; ship; ship = ship->next)
      {
         ch_printf(ch, "%-3d>  %-4d  %-4d  %-4d  %-4d  %-5s  %-3d        %-3d         %-3s    %d\n\r", num++, ship->x, ship->y, ship->tx, ship->ty,
            dir_name[ship->direction], ship->occupants, ship->routetime, ship->travelroute ? ship->travelroute[0] != '\0' ? "Yes" : "No" : "No", 
            ship->size);
      }
      return;
   }
   if (!str_cmp(argument, "create"))
   {
      CREATE(ship, SHIP_DATA, 1);
      ship->x = ch->coord->x;
      ship->y = ch->coord->y;
      ship->map = ch->map;
      ship->tx = ship->ty = ship->tmap = -1;
      ship->direction = 0;
      ship->size = 2;
      if (!check_ship_borders(ship))
      {
         send_to_char("Something is blocking you from creating the ship, move a bit further into the ocean.\n\r", ch);
         DISPOSE(ship);
         return;
      }
      ship->travelroute = STRALLOC("");
      ship->uid = ++cur_ship_uid;
      LINK(ship, first_ship, last_ship, next, prev);
      set_ship_sector(ship, 0, 1);
      send_to_char("Done.\n\r", ch);
      fwrite_ship_data();
      return;
   }
   argument = one_argument(argument, arg1);
   argument = one_argument(argument, arg2);
   argument = one_argument(argument, arg3);
   if (!str_cmp(arg1, "delete"))
   {
      for (ship = first_ship; ship; ship = ship->next)
      {
         if (atoi(arg2) == num++)
            break;
      }
      if (!ship)
      {
         send_to_char("The number you specified does not exist.\n\r", ch);
         return;
      }
      if (ship->occupants > 0)
      {
         send_to_char("There is someone on that ship, you cannot delete it.\n\r", ch);
         return;
      }
      set_ship_sector(ship, 1, 0);
      STRFREE(ship->travelroute);
      UNLINK(ship, first_ship, last_ship, next, prev);
      DISPOSE(ship);
      send_to_char("Deleted.\n\r", ch);
      return;
   }
   if (!str_cmp(arg1, "edit"))
   {
      for (ship = first_ship; ship; ship = ship->next)
      {
         if (atoi(arg2) == num++)
            break;
      }
      if (!ship)
      {
         send_to_char("The number you specified does not exist.\n\r", ch);
         return;
      }
      if (!str_cmp(arg3, "size"))
      {
         int oldsize = ship->size;
         if (atoi(argument) < 1 || atoi(argument) > 10)
         {
            send_to_char("Range is 1 to 10.\n\r", ch);
            return;
         }
         set_ship_sector(ship, 1, 0);
         ship->size = atoi(argument);
         if (check_ship_borders(ship))
         {
            set_ship_sector(ship, 0, 1);
            fwrite_ship_data();
            send_to_char("Done.\n\r", ch);
            return;
         }
         else
         {
            ship->size = oldsize;
            set_ship_sector(ship, 0, 1);
            send_to_char("Cannot change the size, something is blocking you from doing so.\n\r", ch);
            return;
         }
      }
      if (!str_cmp(arg3, "route"))
      {
         if (ship->travelroute)
            STRFREE(ship->travelroute);
         ship->travelroute = STRALLOC(argument);
         if (argument[0] == '\0')
         {
            ship->routeplace = 0;
            ship->routedir = 0;
            ship->routetick = 0;
         }
         send_to_char("Done.\n\r", ch);
         fwrite_ship_data();
         return;
      }
      if (!str_cmp(arg3, "occupants"))
      {
         if (atoi(argument) < 0 || atoi(argument) > 600)
         {
            send_to_char("Range is 0 to 600.\n\r", ch);
            return;
         }
         ship->occupants = atoi(argument);
         send_to_char("Done.\n\r", ch);
         fwrite_ship_data();
         return;
      }
      if (!str_cmp(arg3, "routetime"))
      {
         if (atoi(argument) < 0 || atoi(argument) > 600)
         {
            send_to_char("Range is 0 to 600.\n\r", ch);
            return;
         }
         ship->routetime = atoi(argument);
         send_to_char("Done.\n\r", ch);
         fwrite_ship_data();
         return;
      }
   }
   do_ships(ch, "");
   return;
}
/* Below are the ship designs for the 10 sizes.  The design will shift for north/south and
east/west facing

 x

 x
xxx
 x

 x
xxx
xxx
xxx
 x

 xxx
xxxxx
xxxxx
xxxxx
 xxx
 
 xxx
xxxxx
xxxxx
xxxxx
xxxxx
xxxxx
 xxx
 
 xxxxx
xxxxxxx
xxxxxxx
xxxxxxx
xxxxxxx
xxxxxxx
 xxxxx
 
 xxxxx
xxxxxxx
xxxxxxx
xxxxxxx
xxxxxxx
xxxxxxx
xxxxxxx
xxxxxxx
 xxxxx

  xxxxx
 xxxxxxx
xxxxxxxxx
xxxxxxxxx
xxxxxxxxx
xxxxxxxxx
xxxxxxxxx
 xxxxxxx
  xxxxx
 
  xxxxx
 xxxxxxx
xxxxxxxxx
xxxxxxxxx
xxxxxxxxx
xxxxxxxxx
xxxxxxxxx
xxxxxxxxx
xxxxxxxxx
 xxxxxxx
  xxxxx
 
   xxxxx
  xxxxxxx
 xxxxxxxxx
xxxxxxxxxxx
xxxxxxxxxxx
xxxxxxxxxxx
xxxxxxxxxxx
xxxxxxxxxxx
 xxxxxxxxx
  xxxxxxx
   xxxxx
               */
   

//Reset 0 - Do not reset sectors (make ship sectors) 1 - Reset (make ocean sectors)
void set_ship_sector(SHIP_DATA *ship, int reset, int save)
{
   int sector;
   int sy, sx;
   
   if (reset == 0)
      sector = SECT_SHIP;
   else
      sector = SECT_OCEAN;
      
   map_sector[ship->map][ship->x][ship->y] = sector;
   
   if (ship->direction == 0 || ship->direction == 2) //North - South
   {
      if (ship->size == 2)
      {
         for (sy = ship->y-3; sy <= ship->y+3; sy++)
         {
            for (sx = ship->x-1; sx <= ship->x+1; sx++)
            {
               if ((sy == ship->y-3 || sy == ship->y+3) && sx != ship->x)
                  continue;
               map_sector[ship->map][sx][sy] = sector;
            }
         }
      }
      if (ship->size == 3)
      {
         for (sy = ship->y-4; sy <= ship->y+4; sy++)
         {
            for (sx = ship->x-1; sx <= ship->x+1; sx++)
            {
               if ((sy == ship->y-4 || sy == ship->y+4) && sx != ship->x)
                  continue;
               map_sector[ship->map][sx][sy] = sector;
            }
         }
      }
      if (ship->size == 4)
      {
         for (sy = ship->y-4; sy <= ship->y+4; sy++)
         {
            for (sx = ship->x-2; sx <= ship->x+2; sx++)
            {
               if ((sy == ship->y-4 || sy == ship->y+4) && (sx == ship->x-2 || sx == ship->x+2))
                  continue;
               map_sector[ship->map][sx][sy] = sector;
            }
         }
      }
      if (ship->size == 5)
      {
         for (sy = ship->y-5; sy <= ship->y+5; sy++)
         {
            for (sx = ship->x-2; sx <= ship->x+2; sx++)
            {
               if ((sy == ship->y-5 || sy == ship->y+5) && (sx == ship->x-2 || sx == ship->x+2))
                  continue;
               map_sector[ship->map][sx][sy] = sector;
            }
         }
      }
      if (ship->size == 6)
      {
         for (sy = ship->y-5; sy <= ship->y+5; sy++)
         {
            for (sx = ship->x-3; sx <= ship->x+3; sx++)
            {
               if ((sy == ship->y-5 || sy == ship->y+5) && (sx == ship->x-3 || sx == ship->x+3))
                  continue;
               map_sector[ship->map][sx][sy] = sector;
            }
         }
      }
      if (ship->size == 7)
      {
         for (sy = ship->y-6; sy <= ship->y+6; sy++)
         {
            for (sx = ship->x-3; sx <= ship->x+3; sx++)
            {
               if ((sy == ship->y-6 || sy == ship->y+6) && (sx == ship->x-3 || sx == ship->x+3))
                  continue;
               map_sector[ship->map][sx][sy] = sector;
            }
         }
      }
      if (ship->size == 8)
      {
         for (sy = ship->y-6; sy <= ship->y+6; sy++)
         {
            for (sx = ship->x-4; sx <= ship->x+4; sx++)
            {
               if ((sy == ship->y-5 || sy == ship->y+5) && (sx == ship->x-4 || sx == ship->x+4))
                  continue;
               if ((sy == ship->y-6 || sy == ship->y+6) && (sx <= ship->x-3 || sx >= ship->x+3))
                  continue;
               map_sector[ship->map][sx][sy] = sector;
            }
         }
      }
      if (ship->size == 9)
      {
         for (sy = ship->y-7; sy <= ship->y+7; sy++)
         {
            for (sx = ship->x-4; sx <= ship->x+4; sx++)
            {
               if ((sy == ship->y-6 || sy == ship->y+6) && (sx == ship->x-4 || sx == ship->x+4))
                  continue;
               if ((sy == ship->y-7 || sy == ship->y+7) && (sx <= ship->x-3 || sx >= ship->x+3))
                  continue;
               map_sector[ship->map][sx][sy] = sector;
            }
         }
      }
      if (ship->size == 10)
      {
         for (sy = ship->y-7; sy <= ship->y+7; sy++)
         {
            for (sx = ship->x-5; sx <= ship->x+5; sx++)
            {
               if ((sy == ship->y-5 || sy == ship->y+5) && (sx == ship->x-5 || sx == ship->x+5))
                  continue;
               if ((sy == ship->y-6 || sy == ship->y+6) && (sx <= ship->x-4 || sx >= ship->x+4))
                  continue;
               if ((sy == ship->y-7 || sy == ship->y+7) && (sx <= ship->x-3 || sx >= ship->x+3))
                  continue;
               map_sector[ship->map][sx][sy] = sector;
            }
         }
      }
   }
   else
   {
      if (ship->size == 2)
      {
         for (sy = ship->y-1; sy <= ship->y+1; sy++)
         {
            for (sx = ship->x-3; sx <= ship->x+3; sx++)
            {
               if ((sx == ship->x-3 || sx == ship->x+3) && sy != ship->y)
                  continue;
               map_sector[ship->map][sx][sy] = sector;
            }
         }
      }
      if (ship->size == 3)
      {
         for (sy = ship->y-1; sy <= ship->y+1; sy++)
         {
            for (sx = ship->x-4; sx <= ship->x+4; sx++)
            {
               if ((sx == ship->x-4 || sx == ship->x+4) && sy != ship->y)
                  continue;
               map_sector[ship->map][sx][sy] = sector;
            }
         }
      }
      if (ship->size == 4)
      {
         for (sy = ship->y-2; sy <= ship->y+2; sy++)
         {
            for (sx = ship->x-4; sx <= ship->x+4; sx++)
            {
               if ((sx == ship->x-4 || sx == ship->x+4) && (sy == ship->y-2 || sy == ship->y+2))
                  continue;
               map_sector[ship->map][sx][sy] = sector;
            }
         }
      }
      if (ship->size == 5)
      {
         for (sy = ship->y-2; sy <= ship->y+2; sy++)
         {
            for (sx = ship->x-5; sx <= ship->x+5; sx++)
            {
               if ((sx == ship->x-5 || sx == ship->x+5) && (sy == ship->y-2 || sy == ship->y+2))
                  continue;
               map_sector[ship->map][sx][sy] = sector;
            }
         }
      }
      if (ship->size == 6)
      {
         for (sy = ship->y-3; sy <= ship->y+3; sy++)
         {
            for (sx = ship->x-5; sx <= ship->x+5; sx++)
            {
               if ((sx == ship->x-5 || sx == ship->x+5) && (sy == ship->y-3 || sy == ship->y+3))
                  continue;
               map_sector[ship->map][sx][sy] = sector;
            }
         }
      }
      if (ship->size == 7)
      {
         for (sy = ship->y-3; sy <= ship->y+3; sy++)
         {
            for (sx = ship->x-6; sx <= ship->x+6; sx++)
            {
               if ((sx == ship->x-6 || sx == ship->x+6) && (sy == ship->y-3 || sy == ship->y+3))
                  continue;
               map_sector[ship->map][sx][sy] = sector;
            }
         }
      }
      if (ship->size == 8)
      {
         for (sy = ship->y-4; sy <= ship->y+4; sy++)
         {
            for (sx = ship->x-6; sx <= ship->x+6; sx++)
            {
               if ((sx == ship->x-5 || sx == ship->x+5) && (sy == ship->y-4 || sy == ship->y+4))
                  continue;
               if ((sx == ship->x-6 || sx == ship->x+6) && (sy <= ship->y-3 || sy >= ship->y+3))
                  continue;
               map_sector[ship->map][sx][sy] = sector;
            }
         }
      }
      if (ship->size == 9)
      {
         for (sy = ship->y-4; sy <= ship->y+4; sy++)
         {
            for (sx = ship->x-7; sx <= ship->x+7; sx++)
            {
               if ((sx == ship->x-6 || sx == ship->x+6) && (sy == ship->y-4 || sy == ship->y+4))
                  continue;
               if ((sx == ship->x-7 || sx == ship->x+7) && (sy <= ship->y-3 || sy >= ship->y+3))
                  continue;
               map_sector[ship->map][sx][sy] = sector;
            }
         }
      }
      if (ship->size == 10)
      {
         for (sy = ship->y-5; sy <= ship->y+5; sy++)
         {
            for (sx = ship->x-7; sx <= ship->x+7; sx++)
            {
               if ((sx == ship->x-5 || sx == ship->x+5) && (sy == ship->y-5 || sy == ship->y+5))
                  continue;
               if ((sx == ship->x-6 || sx == ship->x+6) && (sy <= ship->y-4 || sy >= ship->y+4))
                  continue;
               if ((sx == ship->x-7 || sx == ship->x+7) && (sy <= ship->y-3 || sy >= ship->y+3))
                  continue;
               map_sector[ship->map][sx][sy] = sector;
            }
         }
      }
   }   
   //if (save)
   //   save_map("solan", 0);   
}

int check_ship_borders(SHIP_DATA *ship)
{
   int sx;
   int sy;
   
   if (ship->x < 1 || ship->x > MAX_X || ship->y < 1 || ship->y > MAX_Y)
      return 0;
   if (map_sector[ship->map][ship->x][ship->y] != SECT_OCEAN)
      return 0;
      
   if (ship->direction == 0 || ship->direction == 2) //North - South
   {
      if (ship->size == 2)
      {
         for (sy = ship->y-3; sy <= ship->y+3; sy++)
         {
            for (sx = ship->x-1; sx <= ship->x+1; sx++)
            {
               if ((sy == ship->y-3 || sy == ship->y+3) && sx != ship->x)
                  continue;
               if (sx < 1 || sx > MAX_X || sy < 1 || sy > MAX_Y)
                  return 0;
               if (map_sector[ship->map][sx][sy] != SECT_OCEAN)
                  return 0;
            }
         }
      }
      if (ship->size == 3)
      {
         for (sy = ship->y-4; sy <= ship->y+4; sy++)
         {
            for (sx = ship->x-1; sx <= ship->x+1; sx++)
            {
               if ((sy == ship->y-4 || sy == ship->y+4) && sx != ship->x)
                  continue;
               if (sx < 1 || sx > MAX_X || sy < 1 || sy > MAX_Y)
                  return 0;
               if (map_sector[ship->map][sx][sy] != SECT_OCEAN)
                  return 0;
            }
         }
      }
      if (ship->size == 4)
      {
         for (sy = ship->y-4; sy <= ship->y+4; sy++)
         {
            for (sx = ship->x-2; sx <= ship->x+2; sx++)
            {
               if ((sy == ship->y-4 || sy == ship->y+4) && (sx == ship->x-2 || sx == ship->x+2))
                  continue;
               if (sx < 1 || sx > MAX_X || sy < 1 || sy > MAX_Y)
                  return 0;
               if (map_sector[ship->map][sx][sy] != SECT_OCEAN)
                  return 0;
            }
         }
      }
      if (ship->size == 5)
      {
         for (sy = ship->y-5; sy <= ship->y+5; sy++)
         {
            for (sx = ship->x-2; sx <= ship->x+2; sx++)
            {
               if ((sy == ship->y-5 || sy == ship->y+5) && (sx == ship->x-2 || sx == ship->x+2))
                  continue;
               if (sx < 1 || sx > MAX_X || sy < 1 || sy > MAX_Y)
                  return 0;
               if (map_sector[ship->map][sx][sy] != SECT_OCEAN)
                  return 0;
            }
         }
      }
      if (ship->size == 6)
      {
         for (sy = ship->y-5; sy <= ship->y+5; sy++)
         {
            for (sx = ship->x-3; sx <= ship->x+3; sx++)
            {
               if ((sy == ship->y-5 || sy == ship->y+5) && (sx == ship->x-3 || sx == ship->x+3))
                  continue;
               if (sx < 1 || sx > MAX_X || sy < 1 || sy > MAX_Y)
                  return 0;
               if (map_sector[ship->map][sx][sy] != SECT_OCEAN)
                  return 0;
            }
         }
      }
      if (ship->size == 7)
      {
         for (sy = ship->y-6; sy <= ship->y+6; sy++)
         {
            for (sx = ship->x-3; sx <= ship->x+3; sx++)
            {
               if ((sy == ship->y-6 || sy == ship->y+6) && (sx == ship->x-3 || sx == ship->x+3))
                  continue;
               if (sx < 1 || sx > MAX_X || sy < 1 || sy > MAX_Y)
                  return 0;
               if (map_sector[ship->map][sx][sy] != SECT_OCEAN)
                  return 0;
            }
         }
      }
      if (ship->size == 8)
      {
         for (sy = ship->y-6; sy <= ship->y+6; sy++)
         {
            for (sx = ship->x-4; sx <= ship->x+4; sx++)
            {
               if ((sy == ship->y-5 || sy == ship->y+5) && (sx == ship->x-4 || sx == ship->x+4))
                  continue;
               if ((sy == ship->y-6 || sy == ship->y+6) && (sx <= ship->x-3 || sx >= ship->x+3))
                  continue;
               if (sx < 1 || sx > MAX_X || sy < 1 || sy > MAX_Y)
                  return 0;
               if (map_sector[ship->map][sx][sy] != SECT_OCEAN)
                  return 0;
            }
         }
      }
      if (ship->size == 9)
      {
         for (sy = ship->y-7; sy <= ship->y+7; sy++)
         {
            for (sx = ship->x-4; sx <= ship->x+4; sx++)
            {
               if ((sy == ship->y-6 || sy == ship->y+6) && (sx == ship->x-4 || sx == ship->x+4))
                  continue;
               if ((sy == ship->y-7 || sy == ship->y+7) && (sx <= ship->x-3 || sx >= ship->x+3))
                  continue;
               if (sx < 1 || sx > MAX_X || sy < 1 || sy > MAX_Y)
                  return 0;
               if (map_sector[ship->map][sx][sy] != SECT_OCEAN)
                  return 0;
            }
         }
      }
      if (ship->size == 10)
      {
         for (sy = ship->y-7; sy <= ship->y+7; sy++)
         {
            for (sx = ship->x-5; sx <= ship->x+5; sx++)
            {
               if ((sy == ship->y-5 || sy == ship->y+5) && (sx == ship->x-5 || sx == ship->x+5))
                  continue;
               if ((sy == ship->y-6 || sy == ship->y+6) && (sx <= ship->x-4 || sx >= ship->x+4))
                  continue;
               if ((sy == ship->y-7 || sy == ship->y+7) && (sx <= ship->x-3 || sx >= ship->x+3))
                  continue;
               if (sx < 1 || sx > MAX_X || sy < 1 || sy > MAX_Y)
                  return 0;
               if (map_sector[ship->map][sx][sy] != SECT_OCEAN)
                  return 0;
            }
         }
      }
   }
   else
   {
      if (ship->size == 2)
      {
         for (sy = ship->y-1; sy <= ship->y+1; sy++)
         {
            for (sx = ship->x-3; sx <= ship->x+3; sx++)
            {
               if ((sx == ship->x-3 || sx == ship->x+3) && sy != ship->y)
                  continue;
               if (sx < 1 || sx > MAX_X || sy < 1 || sy > MAX_Y)
                  return 0;
               if (map_sector[ship->map][sx][sy] != SECT_OCEAN)
                  return 0;
            }
         }
      }
      if (ship->size == 3)
      {
         for (sy = ship->y-1; sy <= ship->y+1; sy++)
         {
            for (sx = ship->x-4; sx <= ship->x+4; sx++)
            {
               if ((sx == ship->x-4 || sx == ship->x+4) && sy != ship->y)
                  continue;
               if (sx < 1 || sx > MAX_X || sy < 1 || sy > MAX_Y)
                  return 0;
               if (map_sector[ship->map][sx][sy] != SECT_OCEAN)
                  return 0;
            }
         }
      }
      if (ship->size == 4)
      {
         for (sy = ship->y-2; sy <= ship->y+2; sy++)
         {
            for (sx = ship->x-4; sx <= ship->x+4; sx++)
            {
               if ((sx == ship->x-4 || sx == ship->x+4) && (sy == ship->y-2 || sy == ship->y+2))
                  continue;
               if (sx < 1 || sx > MAX_X || sy < 1 || sy > MAX_Y)
                  return 0;
               if (map_sector[ship->map][sx][sy] != SECT_OCEAN)
                  return 0;
            }
         }
      }
      if (ship->size == 5)
      {
         for (sy = ship->y-2; sy <= ship->y+2; sy++)
         {
            for (sx = ship->x-5; sx <= ship->x+5; sx++)
            {
               if ((sx == ship->x-5 || sx == ship->x+5) && (sy == ship->y-2 || sy == ship->y+2))
                  continue;
               if (sx < 1 || sx > MAX_X || sy < 1 || sy > MAX_Y)
                  return 0;
               if (map_sector[ship->map][sx][sy] != SECT_OCEAN)
                  return 0;
            }
         }
      }
      if (ship->size == 6)
      {
         for (sy = ship->y-3; sy <= ship->y+3; sy++)
         {
            for (sx = ship->x-5; sx <= ship->x+5; sx++)
            {
               if ((sx == ship->x-5 || sx == ship->x+5) && (sy == ship->y-3 || sy == ship->y+3))
                  continue;
               if (sx < 1 || sx > MAX_X || sy < 1 || sy > MAX_Y)
                  return 0;
               if (map_sector[ship->map][sx][sy] != SECT_OCEAN)
                  return 0;
            }
         }
      }
      if (ship->size == 7)
      {
         for (sy = ship->y-3; sy <= ship->y+3; sy++)
         {
            for (sx = ship->x-6; sx <= ship->x+6; sx++)
            {
               if ((sx == ship->x-6 || sx == ship->x+6) && (sy == ship->y-3 || sy == ship->y+3))
                  continue;
               if (sx < 1 || sx > MAX_X || sy < 1 || sy > MAX_Y)
                  return 0;
               if (map_sector[ship->map][sx][sy] != SECT_OCEAN)
                  return 0;
            }
         }
      }
      if (ship->size == 8)
      {
         for (sy = ship->y-4; sy <= ship->y+4; sy++)
         {
            for (sx = ship->x-6; sx <= ship->x+6; sx++)
            {
               if ((sx == ship->x-5 || sx == ship->x+5) && (sy == ship->y-4 || sy == ship->y+4))
                  continue;
               if ((sx == ship->x-6 || sx == ship->x+6) && (sy <= ship->y-3 || sy >= ship->y+3))
                  continue;
               if (sx < 1 || sx > MAX_X || sy < 1 || sy > MAX_Y)
                  return 0;
               if (map_sector[ship->map][sx][sy] != SECT_OCEAN)
                  return 0;
            }
         }
      }
      if (ship->size == 9)
      {
         for (sy = ship->y-4; sy <= ship->y+4; sy++)
         {
            for (sx = ship->x-7; sx <= ship->x+7; sx++)
            {
               if ((sx == ship->x-6 || sx == ship->x+6) && (sy == ship->y-4 || sy == ship->y+4))
                  continue;
               if ((sx == ship->x-7 || sx == ship->x+7) && (sy <= ship->y-3 || sy >= ship->y+3))
                  continue;
               if (sx < 1 || sx > MAX_X || sy < 1 || sy > MAX_Y)
                  return 0;
               if (map_sector[ship->map][sx][sy] != SECT_OCEAN)
                  return 0;
            }
         }
      }
      if (ship->size == 10)
      {
         for (sy = ship->y-5; sy <= ship->y+5; sy++)
         {
            for (sx = ship->x-7; sx <= ship->x+7; sx++)
            {
               if ((sx == ship->x-5 || sx == ship->x+5) && (sy == ship->y-5 || sy == ship->y+5))
                  continue;
               if ((sx == ship->x-6 || sx == ship->x+6) && (sy <= ship->y-4 || sy >= ship->y+4))
                  continue;
               if ((sx == ship->x-7 || sx == ship->x+7) && (sy <= ship->y-3 || sy >= ship->y+3))
                  continue;
               if (sx < 1 || sx > MAX_X || sy < 1 || sy > MAX_Y)
                  return 0;
               if (map_sector[ship->map][sx][sy] != SECT_OCEAN)
                  return 0;
            }
         }
      }
   }   
   return 1;
}   

SHIP_DATA *is_ship_sector(int x, int y, int map)
{
   SHIP_DATA *ship;
   int sx;
   int sy;
   
   for (ship = first_ship; ship; ship = ship->next)
   {
      if (ship->x == x && ship->y == y && ship->map == map)
         return ship;
      //Do a proximity check.  No need to loop through all of this if we aren't even near a ship
      if ((ship->direction == 0 || ship->direction == 2) && (abs(x + y - ship->x - ship->y) < ship->size+3))
      {
         if (ship->size == 2)
         {
            for (sy = ship->y-3; sy <= ship->y+3; sy++)
            {
               for (sx = ship->x-1; sx <= ship->x+1; sx++)
               {
                  if ((sy == ship->y-3 || sy == ship->y+3) && sx != ship->x)
                     continue;
                  if (sx == x && sy == y && ship->map == map)
                     return ship;
               }
            }
         }
         if (ship->size == 3)
         {
            for (sy = ship->y-4; sy <= ship->y+4; sy++)
            {
               for (sx = ship->x-1; sx <= ship->x+1; sx++)
               {
                  if ((sy == ship->y-4 || sy == ship->y+4) && sx != ship->x)
                     continue;
                  if (sx == x && sy == y && ship->map == map)
                     return ship;
               }
            }
         }
         if (ship->size == 4)
         {
            for (sy = ship->y-4; sy <= ship->y+4; sy++)
            {
               for (sx = ship->x-2; sx <= ship->x+2; sx++)
               {
                  if ((sy == ship->y-4 || sy == ship->y+4) && (sx == ship->x-2 || sx == ship->x+2))
                     continue;
                  if (sx == x && sy == y && ship->map == map)
                     return ship;
               }
            }
         }
         if (ship->size == 5)
         {
            for (sy = ship->y-5; sy <= ship->y+5; sy++)
            {
               for (sx = ship->x-2; sx <= ship->x+2; sx++)
               {
                  if ((sy == ship->y-5 || sy == ship->y+5) && (sx == ship->x-2 || sx == ship->x+2))
                     continue;
                  if (sx == x && sy == y && ship->map == map)
                     return ship;
               }
            }
         }
         if (ship->size == 6)
         {
            for (sy = ship->y-5; sy <= ship->y+5; sy++)
            {
               for (sx = ship->x-3; sx <= ship->x+3; sx++)
               {
                  if ((sy == ship->y-5 || sy == ship->y+5) && (sx == ship->x-3 || sx == ship->x+3))
                     continue;
                  if (sx == x && sy == y && ship->map == map)
                     return ship;
               }
            }
         }
         if (ship->size == 7)
         {
            for (sy = ship->y-6; sy <= ship->y+6; sy++)
            {
               for (sx = ship->x-3; sx <= ship->x+3; sx++)
               {
                  if ((sy == ship->y-6 || sy == ship->y+6) && (sx == ship->x-3 || sx == ship->x+3))
                     continue;
                  if (sx == x && sy == y && ship->map == map)
                     return ship;
               }
            }
         }
         if (ship->size == 8)
         {
            for (sy = ship->y-6; sy <= ship->y+6; sy++)
            {
               for (sx = ship->x-4; sx <= ship->x+4; sx++)
               {
                  if ((sy == ship->y-5 || sy == ship->y+5) && (sx == ship->x-4 || sx == ship->x+4))
                     continue;
                  if ((sy == ship->y-6 || sy == ship->y+6) && (sx <= ship->x-3 || sx >= ship->x+3))
                     continue;
                  if (sx == x && sy == y && ship->map == map)
                     return ship;
               }
            }
         }
         if (ship->size == 9)
         {
            for (sy = ship->y-7; sy <= ship->y+7; sy++)
            {
               for (sx = ship->x-4; sx <= ship->x+4; sx++)
               {
                  if ((sy == ship->y-6 || sy == ship->y+6) && (sx == ship->x-4 || sx == ship->x+4))
                     continue;
                  if ((sy == ship->y-7 || sy == ship->y+7) && (sx <= ship->x-3 || sx >= ship->x+3))
                     continue;
                  if (sx == x && sy == y && ship->map == map)
                     return ship;
               }
            }
         }
         if (ship->size == 10)
         {
            for (sy = ship->y-7; sy <= ship->y+7; sy++)
            {
               for (sx = ship->x-5; sx <= ship->x+5; sx++)
               {
                  if ((sy == ship->y-5 || sy == ship->y+5) && (sx == ship->x-5 || sx == ship->x+5))
                     continue;
                  if ((sy == ship->y-6 || sy == ship->y+6) && (sx <= ship->x-4 || sx >= ship->x+4))
                     continue;
                  if ((sy == ship->y-7 || sy == ship->y+7) && (sx <= ship->x-3 || sx >= ship->x+3))
                     continue;
                  if (sx == x && sy == y && ship->map == map)
                     return ship;
               }
            }
         }
      }
      else if ((ship->direction == 1 || ship->direction == 3) && (abs(x + y - ship->x - ship->y) < ship->size+3))
      {
         if (ship->size == 2)
         {
            for (sy = ship->y-1; sy <= ship->y+1; sy++)
            {
               for (sx = ship->x-3; sx <= ship->x+3; sx++)
               {
                  if ((sx == ship->x-3 || sx == ship->x+3) && sy != ship->y)
                     continue;
                  if (sx == x && sy == y && ship->map == map)
                     return ship;
               }
            }
         }
         if (ship->size == 3)
         {
            for (sy = ship->y-1; sy <= ship->y+1; sy++)
            {
               for (sx = ship->x-4; sx <= ship->x+4; sx++)
               {
                  if ((sx == ship->x-4 || sx == ship->x+4) && sy != ship->y)
                     continue;
                  if (sx == x && sy == y && ship->map == map)
                     return ship;
               }
            }
         }
         if (ship->size == 4)
         {
            for (sy = ship->y-2; sy <= ship->y+2; sy++)
            {
               for (sx = ship->x-4; sx <= ship->x+4; sx++)
               {
                  if ((sx == ship->x-4 || sx == ship->x+4) && (sy == ship->y-2 || sy == ship->y+2))
                     continue;
                  if (sx == x && sy == y && ship->map == map)
                     return ship;
               }
            }
         }
         if (ship->size == 5)
         {
            for (sy = ship->y-2; sy <= ship->y+2; sy++)
            {
               for (sx = ship->x-5; sx <= ship->x+5; sx++)
               {
                  if ((sx == ship->x-5 || sx == ship->x+5) && (sy == ship->y-2 || sy == ship->y+2))
                     continue;
                  if (sx == x && sy == y && ship->map == map)
                     return ship;
               }
            }
         }
         if (ship->size == 6)
         {
            for (sy = ship->y-3; sy <= ship->y+3; sy++)
            {
               for (sx = ship->x-5; sx <= ship->x+5; sx++)
               {
                  if ((sx == ship->x-5 || sx == ship->x+5) && (sy == ship->y-3 || sy == ship->y+3))
                     continue;
                  if (sx == x && sy == y && ship->map == map)
                     return ship;
               }
            }
         }
         if (ship->size == 7)
         {
            for (sy = ship->y-3; sy <= ship->y+3; sy++)
            {
               for (sx = ship->x-6; sx <= ship->x+6; sx++)
               {
                  if ((sx == ship->x-6 || sx == ship->x+6) && (sy == ship->y-3 || sy == ship->y+3))
                     continue;
                  if (sx == x && sy == y && ship->map == map)
                     return ship;
               }
            }
         }
         if (ship->size == 8)
         {
            for (sy = ship->y-4; sy <= ship->y+4; sy++)
            {
               for (sx = ship->x-6; sx <= ship->x+6; sx++)
               {
                  if ((sx == ship->x-5 || sx == ship->x+5) && (sy == ship->y-4 || sy == ship->y+4))
                     continue;
                  if ((sx == ship->x-6 || sx == ship->x+6) && (sy <= ship->y-3 || sy >= ship->y+3))
                     continue;
                  if (sx == x && sy == y && ship->map == map)
                     return ship;
               }
            }
         }
         if (ship->size == 9)
         {
            for (sy = ship->y-4; sy <= ship->y+4; sy++)
            {
               for (sx = ship->x-7; sx <= ship->x+7; sx++)
               {
                  if ((sx == ship->x-6 || sx == ship->x+6) && (sy == ship->y-4 || sy == ship->y+4))
                     continue;
                  if ((sx == ship->x-7 || sx == ship->x+7) && (sy <= ship->y-3 || sy >= ship->y+3))
                     continue;
                  if (sx == x && sy == y && ship->map == map)
                     return ship;
               }
            }
         }
         if (ship->size == 10)
         {
            for (sy = ship->y-5; sy <= ship->y+5; sy++)
            {
               for (sx = ship->x-7; sx <= ship->x+7; sx++)
               {
                  if ((sx == ship->x-5 || sx == ship->x+5) && (sy == ship->y-5 || sy == ship->y+5))
                     continue;
                  if ((sx == ship->x-6 || sx == ship->x+6) && (sy <= ship->y-4 || sy >= ship->y+4))
                     continue;
                  if ((sx == ship->x-7 || sx == ship->x+7) && (sy <= ship->y-3 || sy >= ship->y+3))
                     continue;
                  if (sx == x && sy == y && ship->map == map)
                     return ship;
               }
            }
         }
      }   
   }
   return NULL;
}

void update_ship_chars(SHIP_DATA *ship)
{
   CHAR_DATA *ch;
   
   for (ch = ship->first_char; ch; ch = ch->next_ship)
   {
      ch->coord->x = ship->x;
      ch->coord->y = ship->y;
      update_objects(ch, ch->coord->x, ch->coord->y, ch->map);
      do_look(ch, "auto");
   }
}

void update_object_contents(OBJ_DATA *obj, int x, int y)
{
   OBJ_DATA *cobj;
   obj->coord->x = x;
   obj->coord->y = y;
   
   for (cobj = obj->first_content; cobj; cobj = cobj->next_content)
   {
      update_object_contents(cobj, x, y);
   }
}

void steer_ship(CHAR_DATA *ch, SHIP_DATA *ship, int dir)
{
   int ox;
   int oy;
   int odir;
   int x;
   int y;
   ROOM_INDEX_DATA *room;
   char buf[MSL];
   OBJ_DATA *obj;
   
   x = y = 0;
   
   if (dir == 0)
      y = -1;
   if (dir == 1)
      x = 1;
   if (dir == 2)
      y = 1;
   if (dir == 3)
      x = -1;
   ox = ship->x;
   oy = ship->y;
   odir = ship->direction;
   set_ship_sector(ship, 1, 0);
   ship->x += x;
   ship->y += y;
   ship->direction = dir;
   if (!ch)
      ch = ship->first_char;
   if (check_ship_borders(ship))
   {
      if (ch)
      {
         sprintf(buf, "The ship sails to the %s", dir_name[dir]);
         act(AT_WHITE, buf, ch, NULL, NULL, TO_ROOM);
         act(AT_WHITE, buf, ch, NULL, NULL, TO_CHAR);
      }
      set_ship_sector(ship, 0, 1);
      update_ship_chars(ship);
      fwrite_ship_data();
      if (ch)
         room = ch->in_room;
      else
         room = get_room_index(OVERLAND_SOLAN);
      for (obj = room->first_content; obj; obj = obj->next_content)
      {
         if (obj->coord->x == ox && obj->coord->y == oy)
         {
            update_object_contents(obj, ship->x, ship->y);
         }
      }
      return;
   }
   else
   {
      ship->x -= x;
      ship->y -= y;
      ship->direction = odir;
      set_ship_sector(ship, 0, 0);
      if (ch)
         send_to_char("Something is blocking you from going that direction.\n\r", ch);
      return;
   }
}

void do_steership(CHAR_DATA *ch, char *argument)
{  
   int dir = -1;
   
   if (get_trust(ch) < LEVEL_IMMORTAL || IS_NPC(ch))
   {
      send_to_char("Huh?\n\r", ch);
      return;
   }
   if (argument[0] == '\0')
   {
      send_to_char("Syntax:  steership <direction>\n\r", ch);
      send_to_char("Ships can only move in 4 directions - north west south east.\n\r", ch);
      return;
   }
   if (!str_cmp(argument, "n") || !str_cmp(argument, "north"))
      dir = 0;
   if (!str_cmp(argument, "e") || !str_cmp(argument, "east"))
      dir = 1;
   if (!str_cmp(argument, "s") || !str_cmp(argument, "south"))
      dir = 2;
   if (!str_cmp(argument, "w") || !str_cmp(argument, "west"))
      dir = 3;
      
   if (dir == -1)
   {
      do_steership(ch, "");
      return;
   }
   if (!ch->ship)
   {
      send_to_char("You have to be on a ship to steer it.\n\r", ch);
      return;
   }
   steer_ship(ch, ch->ship, dir);
} 

void new_map_to_char(CHAR_DATA * ch, int startx, int starty, int endx, int endy, int showeoc)
{
   int x, y, p;
   int sx, sy;
   int stx, sty, enx, eny;
   int seeobj;
   int bfight, bobj, bportal, bcolor;
   sh_int seemap, seeportal, eoc, eeoc, istown;
   CMAP_DATA *mch;
   OMAP_DATA *mobj;
   //int bsize = ((endx - startx) * (endy - starty)) * 20;
   char buf[MSL];
   //char hbuf[bsize]; /* Sent in one huge buf, might save sending time */
   char hbuf[MSL];
   DESCRIPTOR_DATA *d;
   sh_int tbufx[10];
   sh_int tbufy[10];
   char fground[10];
   char rground[10];
   int cannotseeindoors = 0;
   sh_int tbx, ttorn, tcur, tlast;
   TORNADO_DATA *torn;
   TOWN_DATA *town;
   DOOR_DATA *ddata;
   int cnt, cx, cy;
   int curx, cury;
   int lastblank = 0;
   int isinside = 0;
   int dx;
   int fnddoor[100];
   int canseeinside[101][101];
   tcur = tlast = 0;

   for (tbx = 0; tbx < 10; tbx++)
   {
      tbufx[tbx] = 0;
      tbufy[tbx] = 0;
   }
   ttorn = 0; //Tornado present int

   sprintf(hbuf, "\n\r");
   bfight = bobj = bportal = 0;
   stx = startx;
   sty = starty;
   enx = endx;
   eny = endy;
   snows = 0;

   if (stx < 1)
      stx = 1;

   if (sty < 1)
      sty = 1;

   if (enx > MAX_X)
      enx = MAX_X;

   if (eny > MAX_Y)
      eny = MAX_Y;

   for (torn = first_tornado; torn; torn = torn->next)
   {
      tbx = 0;
      if (torn->x >= stx && torn->x <= enx && torn->y >= sty && torn->y <= eny && ch->map == torn->map)
      {
         tbufx[tbx] = torn->x;
         tbufy[tbx] = torn->y;
         tbx++;
         ttorn = 1;
      }
   }
   //time for Inside check....
   for (cx = 0; cx <= 99; cx++)
      fnddoor[cx] = 0;
        
   town = find_town(ch->coord->x, ch->coord->y, ch->map);
   
   if (town)
   {
      for (ddata = town->first_doorlist->first_door; ddata; ddata = ddata->next)
         ddata->cannotsee = 0; 
   }
      
   curx = ch->coord->x;
   cury = ch->coord->y;
      
   if (town && (map_sector[ch->map][curx][cury] == SECT_INSIDE || map_sector[ch->map][curx][cury] == SECT_DOOR
   ||  map_sector[ch->map][curx][cury] == SECT_CDOOR || map_sector[ch->map][curx][cury] == SECT_LDOOR))
   {
      if (map_sector[ch->map][curx][cury] != SECT_INSIDE) //door
      {
         for (dx = 0; dx <= 99; dx++)
         {
            if (town->doorstate[5][dx] == curx && town->doorstate[6][dx] == cury && town->doorstate[7][dx] == ch->map) 
            {
               for (ddata = town->first_doorlist->first_door; ddata; ddata = ddata->next)
               {
                  for (x = 0; x <= 9; x++)
                  {
                     if (ddata->doorvalue[x] == town->doorstate[4][dx])
                     {
                        for (y = 0; y <= MAX_HPOINTS-1; y++)
                        {
                           if (ddata->roomcoordx[y] > 0)
                           {
                              curx = ddata->roomcoordx[y];
                              cury = ddata->roomcoordy[y];
                              break;
                           }
                        }
                        if (curx != ch->coord->x && cury != ch->coord->y)
                           break;
                     }
                  }
                  if (curx != ch->coord->x && cury != ch->coord->y)
                     break;
               }
               if (curx != ch->coord->x && cury != ch->coord->y)
                  break;
            }
         }
      }
      if (map_sector[ch->map][curx][cury] == SECT_INSIDE)
      {
         for (ddata = town->first_doorlist->first_door; ddata; ddata = ddata->next)
         {
            for (dx = 0; dx <= MAX_HPOINTS-1; dx++)
            {
               if (ddata->roomcoordx[dx] == curx && ddata->roomcoordy[dx] == cury &&
                   ddata->roomcoordmap[dx] == ch->map)
               {
                  if (update_inside_stat(fnddoor, ch, town, curx, cury, ch->map) == 0) //are indeed inside
                  {
                     isinside = 1;
                     for (x = 0; x <= 100; x++)
                     {
                        for (y = 0; y <= 100; y++)
                        {  
                           canseeinside[x][y] = 0;
                        }
                     }
                     canseeinside[50][50] = 1;
                     for (dx = 0; dx <= MAX_HPOINTS-1; dx++)
                     {
                        if (ddata->roomcoordx[dx] > 0)
                        {
                           for (cnt = 1; cnt <= 8; cnt++)
                           {
                              cx = ddata->roomcoordx[dx];
                              cy = ddata->roomcoordy[dx];
            
                              if (cnt == 1 || cnt == 5 || cnt == 7) //east
                                 cx = cx+1;
                              if (cnt == 2 || cnt == 7 || cnt == 8) //south
                                 cy = cy+1;
                              if (cnt == 3 || cnt == 6 || cnt == 8) //west
                                 cx = cx-1;
                              if (cnt == 4 || cnt == 5 || cnt == 6) //north
                                 cy = cy-1;  
                                    
                              canseeinside[50+ch->coord->x-cx][50+ch->coord->y-cy] = 1;
                           }
                        }
                     }
                     for (ddata = town->first_doorlist->first_door; ddata; ddata = ddata->next)
                     {
                        if (ddata->cannotsee == 1)
                        {
                           for (dx = 0; dx <= MAX_HPOINTS-1; dx++)
                           {
                              if (ddata->roomcoordx[dx] > 0)
                              {
                                 canseeinside[50+ch->coord->x-ddata->roomcoordx[dx]][50+ch->coord->y-ddata->roomcoordy[dx]] = 1;
                                 for (cnt = 1; cnt <= 8; cnt++)
                                 {
                                    cx = ddata->roomcoordx[dx];
                                    cy = ddata->roomcoordy[dx];
         
                                    if (cnt == 1 || cnt == 5 || cnt == 7) //east
                                       cx = cx+1;
                                    if (cnt == 2 || cnt == 7 || cnt == 8) //south
                                       cy = cy+1;
                                    if (cnt == 3 || cnt == 6 || cnt == 8) //west
                                       cx = cx-1;
                                    if (cnt == 4 || cnt == 5 || cnt == 6) //north
                                       cy = cy-1;  
                                    
                                    canseeinside[50+ch->coord->x-cx][50+ch->coord->y-cy] = 1;
                                 }
                              }
                           }
                        }
                     }
                     break;
                  }//end update_inside_stat brace
               }
            }
            if (isinside == 1)
               break;
         }
      }
   }                   
   //ch_printf(ch, "%s", MXPTAG("FRAME Name=\"Map\" FLOATING Left=\"-55c\" Top=\"0\" Width=\"55c\" Height=\"21c\""));     
   //ch_printf(ch, "%s %s %s", MXPTAG("DEST Map EOF"),  MXPTAG("/DEST"), MXPTAG("DEST Map"));  
   //ch_printf(ch, "%s", MXPTAG("DEST Map"));      
   if (xIS_SET(ch->act, PLR_MAPWINDOW) && !IS_NPC(ch))
   {
      if (ch->pcdata->xsize != endx-startx+2 && ch->pcdata->ysize != endy-starty+1)
      {
         ch_printf(ch, "%s" "FRAME Name=\"Map\" FLOATING Left=\"-%dc\" Top=\"0\" Width=\"%dc\" Height=\"%dc\"" "%s", MXP_BEG,
            endx-startx+2, endx-startx+2, endy-starty+1, MXP_END);
         ch->pcdata->xsize = endx-startx+2;
         ch->pcdata->ysize = endy-starty+1;
      }
      ch_printf(ch, "%s %s %s", MXPTAG("DEST Map EOF"),  MXPTAG("/DEST"), MXPTAG("DEST Map"));  
   } 
   for (y = sty; y < eny + 1; y += 1)
   {
      int fnd = 0;

      sy = y;
      for (x = stx; x < enx + 1; x += 1)
      {
         if (tcur == 1)
            tlast = 1;
         tcur = 0;
         seemap = 0;
         seeobj = 0;
         seeportal = 0;
         bcolor = 0;
         eoc = 0;
         eeoc = 0;
         istown = 0;
         bfight = UMAX(0, bfight - 1);
         bobj = UMAX(0, bobj - 1);
         bportal = UMAX(0, bportal - 1);

         if (ttorn == 1)
         {
            for (tbx = 0; tbx < 9; tbx++) //Tornado Present at this location
            {
               if (x == tbufx[tbx] && y == tbufy[tbx])
               {
                  strcat(hbuf, "&PT");
                  snows = 0;
                  fnd = 0;
                  tcur = 1;
                  break;
               }
            }
         }
         if (tcur == 1)
            continue;

         if (bfight > 0 || bobj > 0 || bportal > 0 || (ch->coord->x + 1 == x && ch->coord->y == y))
            bcolor = 1;

         sx = x;
         for (d = first_descriptor; d; d = d->next)
         {
            if (d->connected == CON_PLAYING
               && d->character != ch
               && d->character->in_room
               && d->newstate != 2
               && can_see_map(ch, d->character) && (d->character->coord->x + 1 == x && d->character->coord->y == y && d->character->map == ch->map))
            {
               bcolor = 1;
            }

            if (d->connected == CON_PLAYING
               && d->character != ch
               && d->character->in_room
               && d->newstate != 2
               && can_see_map(ch, d->character) && (d->character->coord->x == x && d->character->coord->y == y && d->character->map == ch->map))
            {
               fnd = 1;
               if (IS_AFFECTED(d->character, AFF_INVISIBLE) && !IS_AFFECTED(ch, AFF_DETECT_INVIS))
                  fnd = 0;

               if (IS_AFFECTED(d->character, AFF_HIDE) && !IS_AFFECTED(ch, AFF_DETECT_HIDDEN))
                  fnd = 0;
                  
               if (IS_AFFECTED(d->character, AFF_STALK))
                  fnd = 0;

               if (xIS_SET(ch->act, PLR_HOLYLIGHT))
                  fnd = 1;

               if (xIS_SET(d->character->act, PLR_WIZINVIS) && get_trust(ch) < d->character->pcdata->wizinvis)
                  fnd = 0;
            }
         }
         for (p = 0; p < sysdata.last_portal; p++)
         {
            if (portal_show[p]->map == ch->map && portal_show[p]->x == x && portal_show[p]->y == y)
            {
               if (abs(x - ch->coord->x) <= 3 && abs(y - ch->coord->y) <= 3 && xIS_SET(ch->act, PLR_PORTALHUNT))
               {
                  seeportal = 1;
                  bportal = 2;
               }
               if (xIS_SET(ch->pcdata->portalfnd, p))
               {
                  seeportal = 1;
                  bportal = 2;
               }
            }
         }
         for (mobj = first_wilderobj; mobj; mobj = mobj->next)
         {
            if ((mobj->mapobj->coord->x == x && mobj->mapobj->coord->y == y && mobj->mapobj->map == ch->map))
            {
               seeobj = 1;
               bobj = 2;
            }
            else
               continue;
            if (IS_OBJ_STAT(mobj->mapobj, ITEM_INVIS))
            {
               if (!IS_AFFECTED(ch, AFF_DETECT_INVIS) && !IS_AFFECTED(ch, AFF_TRUESIGHT))
               {
                  seeobj = 0;
                  bobj = 0;
               }
            }
            if (mobj->mapobj->item_type == ITEM_PORTAL)
            {
               seeobj = 0;
               bobj = 0;
            }
            if (!IS_NPC(ch) && xIS_SET(ch->act, PLR_HOLYLIGHT))
            {
               seeobj = 1;
               bobj = 2;
            }
         }
         if (showeoc && kingdom_sector[ch->map][x][y] > 1 && kingdom_sector[ch->map][x][y] == ch->pcdata->hometown)
            eoc = 1;
         if (showeoc && kingdom_sector[ch->map][x][y] > 1 && kingdom_sector[ch->map][x][y] != ch->pcdata->hometown)
         {
            if (kingdom_table[ch->pcdata->hometown]->peace[kingdom_sector[ch->map][x][y]] == 0) //war
               eeoc = 1;
            if (kingdom_table[ch->pcdata->hometown]->peace[kingdom_sector[ch->map][x][y]] == 1) //neutral
               eeoc = 2;
            if (kingdom_table[ch->pcdata->hometown]->peace[kingdom_sector[ch->map][x][y]] == 2) //trading
               eeoc = 3;
            if (kingdom_table[ch->pcdata->hometown]->peace[kingdom_sector[ch->map][x][y]] == 3) //peace
               eeoc = 4;
         }
         if (eoc || eeoc)
         {
            for (town = kingdom_table[kingdom_sector[ch->map][x][y]]->first_town; town; town = town->next)
            {
               if (town->startx == x && town->starty == y && town->startmap == ch->map)
                  istown = 1;
            }
         }
         if (!can_see_room(x, y, ch->map, map_sector[ch->map][x][y]))
            cannotseeindoors = 1;
         if (isinside == 1 && canseeinside[50+ch->coord->x-x][50+ch->coord->y-y] == 0)
            cannotseeindoors = 1;
         if (isinside == 1 && canseeinside[50+ch->coord->x-x][50+ch->coord->y-y] == 1)
            cannotseeindoors = 0; 
         for (mch = first_wilderchar; mch; mch = mch->next)
         {
            if (mch->mapch->coord->x == x && mch->mapch->coord->y == y && mch->mapch->map == ch->map && cannotseeindoors == 0)
            {
               seemap = 1;
               /* seemap = 0 see only terrain 1 = see vis mobs 2 = see hide mobs 3 = see invis mobs 4 = see both */
               if (!xIS_SET(ch->act, PLR_HOLYLIGHT) || !IS_AFFECTED(ch, AFF_TRUESIGHT))
               {
                  if (IS_AFFECTED(mch->mapch, AFF_INVISIBLE) && !IS_AFFECTED(ch, AFF_DETECT_INVIS))
                     seemap = 0;
                  if (IS_AFFECTED(mch->mapch, AFF_HIDE) && !IS_AFFECTED(ch, AFF_DETECT_HIDDEN))
                     seemap = 0;
                  if (IS_AFFECTED(mch->mapch, AFF_STALK))
                     seemap = 0;


                  if (IS_AFFECTED(ch, AFF_BLIND))
                     seemap = 0;
               }
               if (IS_AFFECTED(ch, AFF_TRUESIGHT))
                  seemap = 1;

               if (xIS_SET(mch->mapch->act, ACT_MOBINVIS) && get_trust(ch) <= LEVEL_GUEST)
                  seemap = 0;
               if (xIS_SET(mch->mapch->act, ACT_TRAINER))
                  if ((abs(ch->coord->x - mch->mapch->coord->x) > 3) || (abs(ch->coord->y - mch->mapch->coord->y) > 3))
                     seemap = 0;
               if (!IS_NPC(ch) && xIS_SET(ch->act, PLR_HOLYLIGHT))
                  seemap = 1;

               if (seemap == 1 && (IS_NPC(ch) || !xIS_SET(ch->act, PLR_WILDERTILES)))
               {
                  if (eoc == 1)
                     sprintf(fground, "^b");
                  else if (eeoc == 1)
                     sprintf(fground, "^r");
                  else if (eeoc == 2)
                     sprintf(fground, "^g");
                  else if (eeoc == 3)
                     sprintf(fground, "^w");
                  else if (eeoc == 4)
                     sprintf(fground, "^O");
                  else
                     sprintf(fground, "^c");
                  if (istown)
                  {
                     snows = 0;
                     sprintf(buf, "%s&RT&w^x", fground);
                     strcat(hbuf, buf);
                     break;
                  }
                  else if ((global_x[0] == x && global_y[0] == y) && (abs(global_x[0] - ch->coord->x) <= 3 && abs(global_y[0] - ch->coord->y) <= 3))
                  {
                     snows = 0;
                     sprintf(buf, "%s&C#^x", fground);
                     strcat(hbuf, buf);
                     break;
                  }
                  else
                  {
                     if (x == ch->coord->x && y == ch->coord->y)
                     {
                        sprintf(buf, "%s&R*^x", fground);
                        strcat(hbuf, buf);
                        snows = 0;
                     }
                     else if (seeportal)
                     {                   
                        sprintf(buf, "%s&BO^x", fground);
                        strcat(hbuf, buf);
                        snows = 0;
                     }
                     else if (fnd == 1)
                     {
                        snows = 0;
                        if (seeobj == 1)
                           sprintf(buf, "%s&p*^x", fground);
                        else
                           sprintf(buf, "%s&G&W*^x", fground);
                        strcat(hbuf, buf);
                     }
                     else
                     {
                        if (seeobj == 1)
                        {
                           sprintf(buf, "%s&p%s^x", fground, show_room(map_sector[ch->map][x][y], -20, -20, -20, -1));
                           snows = 0;
                        }
                        else
                        {
                           if (bcolor == 1 || tlast == 1)
                              sprintf(buf, "%s%s^x", fground, show_room(map_sector[ch->map][x][y], x, y, ch->map, x));
                           else if (lastblank == 1)
                           {
                              sprintf(buf, "%s%s^x", fground, show_room(map_sector[ch->map][x][y], -10, -10, -10, -1));
                              lastblank = 0;
                           }
                           else
                              sprintf(buf, "%s%s^x", fground, show_room(map_sector[ch->map][x][y], x, y, ch->map, stx));
                        }
                        strcat(hbuf, buf);
                     }
                     break;
                  }
               }
               else if (seemap == 1 && !IS_NPC(ch) && xIS_SET(ch->act, PLR_WILDERTILES))
               {
                  if (!IS_NPC(ch) && xIS_SET(ch->act, PLR_WILDERTILES))
                  {
                     sprintf(buf, "\x03Image a3.gif align=bottom\x04");
                     strcat(hbuf, buf);
                     break;
                  }
               }
            }
         }//end mobile check
         if (seemap == 0 && cannotseeindoors == 0)
         {
            if (eoc == 1)
            {
               sprintf(fground, "^b");
               sprintf(rground, "^x");
            }
            else if (eeoc == 1)
            {
               sprintf(fground, "^r");
               sprintf(rground, "^x");
            }
            else if (eeoc == 2)
            {
               sprintf(fground, "^g");
               sprintf(rground, "^x");
            }
            else if (eeoc == 3)
            {
               sprintf(fground, "^w");
               sprintf(rground, "^x");
            }
            else if (eeoc == 4)
            {
               sprintf(fground, "^O");
               sprintf(rground, "^x");
            }
            else
            {
               strcpy(fground, "");
               strcpy(rground, "");
            }
            if (istown)
            {
               snows = 0;
               sprintf(buf, "%s&RT&w%s", fground, rground);
               strcat(hbuf, buf);
            }
            else if ((global_x[0] == x && global_y[0] == y) && (abs(global_x[0] - ch->coord->x) <= 3 && abs(global_y[0] - ch->coord->y) <= 3))
            {
               snows = 0;
               sprint

Showing the first 100 KB of 250.5 KB. Download the archive for the full file.

Site Stats

Snippets: 1791
Codebases: 571