/
area/city/
area/crypts/
area/guilds/
area/psuedowild/
area/religion/
data/documents/MPDocs/
data/html/
data/mobprogs/
data/quest/
data/world/
data/world/_utilities/
data/world/images/
design/html/
notes/
player/
#include <sys/types.h>
#include <sys/time.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <assert.h>
#include <zlib.h>
#include "merc.h"
#include "world.h"
#include "recycle.h"
#include "gdl.h"
#include "bounty.h"
#include "interp.h"
#define ptc printf_to_char

BEGIN_ELE_LIST(WEXIT)
STR(name)
STR(descr)
INT(x)
INT(y)
INT(to_room)
END_ELE_LIST

WEXIT * wexit_list;

void load_wexit()
{
    LOAD_LIST(wexit_list, WEXIT, WEXIT_FILE);
    log_string("*** WORLD ******* Loaded Exits");
    return;
}

void save_wexit()
{
    SAVE_LIST(wexit_list, WEXIT, WEXIT_FILE);
    return;
}


/*
 * do_wexit()
 *
 * Two fold command, creates and displays wilderness exits
 */
void do_wexits(CHAR_DATA * ch, char *argument)
{
    WEXIT * p;
    char buf[MSL];
    char arg1[MSL];
    char name[MSL];
    char to_room[MSL];
    char min_level[MSL];
    char descr_range[MSL];
    char description[MSL];
    char number[MSL];
    
    argument = one_argument (argument, arg1);
    argument = one_argument (argument, name);
    argument = one_argument (argument, to_room);
    argument = one_argument (argument, min_level);
    argument = one_argument (argument, descr_range);
    argument = one_argument (argument, description);
    argument = one_argument (argument, number);
    
    if (arg1[0] == '\0')
    {
        if (wexit_list == NULL)
        {
            stc("There are currently no exits from the wilderness.\n", ch);
            return;
        }
        
        stc("Num | Name                 | x/  y   | Room    | Lvl | Desc?\n", ch);
        stc("----|----------------------|---------|---------|-----|----------\n", ch);
        
        for (p = wexit_list; p ; p = p->next)
        {
            
            sprintf(buf, "%-30s   %-3d/%-3d\n",
                p->name,
                p->x,
                p->y);
            stc(buf, ch);
        }
        return;
    }
    return;
}

/*
 * check_wexit()
 *
 * checks to see if the player is currently in a wilderness exit sector
 */
void check_wexit(CHAR_DATA * ch)
{
    
    int x, y;
    int viewx = 31;
    int viewy = 15;
    int start_x = (ch->x - (viewx / 2));
    int start_y = (ch->y - (viewy / 2));
    WEXIT * p;
    int col = 0;

    if (wexit_list == NULL)
    {
        ptc(ch, "There are no exits from the wilderness in the world!\n\r");
        return;
    }
    
    
    for (y = start_y; y != (start_y + viewy); y++)
    {
        for (x = start_x; x != (start_x + viewx); x++)
        {
            for (p = wexit_list; p ; p = p->next)
            {
                if (x == p->x && y == p->y)
                {
                    ptc(ch, "[*] %-25s{x", p->descr);
                    if (++col % 2 == 0)
                        send_to_char ("{x\n\r", ch);
                }
            }
        }
    }
    stc("\n\r", ch);
}


bool check_wexit_move(CHAR_DATA * ch)
{
    WEXIT * p;
    ROOM_INDEX_DATA *location;

    if (wexit_list == NULL)
        return FALSE;
    
    for (p = wexit_list; p ; p = p->next)
    {
        if (ch->x == p->x && ch->y == p->y)
        {
            location = get_room_index(p->to_room);
            if (location == NULL)
            {
                stc("ERROR: Exit leads to a null room. Tell thri!\n", ch);
                return FALSE;
            }
            ch->on_wild = FALSE;
            ch->x = -1;
            ch->y = -1;
            char_from_room (ch);
            char_to_room (ch, location);
            stc("\n{x\n\n", ch);
            do_function (ch, &do_look, "auto");
            return TRUE;
        }
    }
    return FALSE;
}

/*
 * return_direction()
 *
 * returns direction/nsew of victim from the charater.
 */
int return_direction(CHAR_DATA * ch, CHAR_DATA * victim)
{
    if (ch->x == victim->x && ch->y == victim->y)
        return -1;
    
    if (ch->x >= victim->x && ch->y == victim->y)
        return DIR_WEST;
    if (ch->x <= victim->x && ch->y == victim->y)
        return DIR_EAST;
    if (ch->x == victim->x && ch->y <= victim->y)
        return DIR_SOUTH;
    if (ch->x == victim->x && ch->y >= victim->y)
        return DIR_NORTH;
    if (ch->x <= victim->x && ch->y <= victim->y)
        return DIR_SOUTHEAST;
    if (ch->x >= victim->x && ch->y <= victim->y)
        return DIR_SOUTHWEST;
    if (ch->x >= victim->x && ch->y >= victim->y)
        return DIR_NORTHWEST;
    if (ch->x <= victim->x && ch->y >= victim->y)
        return DIR_NORTHEAST;
    
    return -1;
}

/*
 * cmd_hunt
 *
 * Returns direction of the victim from the player.
 * Counts on both players being in room 99.
 *
 * TODO: Check max_distance, check over water, add gsn_hunt checks for
 * through woods/mountains, and add specialities and such
 */
void cmd_hunt (CHAR_DATA * ch, char *argument)
{
    char buf[MSL];
    char arg[MSL];
    CHAR_DATA * victim;
    int direction;
    
    one_argument (argument, arg);
    
    if ((victim = get_char_room (ch, argument)) == NULL)
    {
        send_to_char ("They aren't here.\n\r{x", ch);
        return;
    }
    
    direction = return_direction(ch, victim);
    
    switch(direction)
    {   default:
            stc("Error, no direction found.\n", ch);
            return;
            break;
        case DIR_NONE:
            sprintf(buf, "%s is here.\n", victim->short_descr);
            stc(buf, ch);
            return;
            break;
        case DIR_NORTH:
            sprintf(buf, "%s is north from here.\n", victim->short_descr);
            stc(buf, ch);
            return;
            break;
        case DIR_SOUTH:
            sprintf(buf, "%s is south from here.\n", victim->short_descr);
            stc(buf, ch);
            return;
            break;
        case DIR_EAST:
            sprintf(buf, "%s is east from here.\n", victim->short_descr);
            stc(buf, ch);
            return;
            break;
        case DIR_WEST:
            sprintf(buf, "%s is west from here.\n", victim->short_descr);
            stc(buf, ch);
            return;
            break;
        case DIR_NORTHWEST:
            sprintf(buf, "%s is northwest from here.\n", victim->short_descr);
            stc(buf, ch);
            return;
            break;
        case DIR_SOUTHWEST:
            sprintf(buf, "%s is southwest from here.\n", victim->short_descr);
            stc(buf, ch);
            return;
            break;
        case DIR_NORTHEAST:
            sprintf(buf, "%s is northeast from here.\n", victim->short_descr);
            stc(buf, ch);
            return;
            break;
        case DIR_SOUTHEAST:
            sprintf(buf, "%s is southeast from here.\n", victim->short_descr);
            stc(buf, ch);
            return;
            break;
    }
    return;
}

/*
 * cmd_approach()
 *
 * World movement command to approach a victim IF seen on
 * the world map.
 */
void cmd_approach(CHAR_DATA * ch, char *argument)
{
    char buf[MSL];
    char arg[MAX_INPUT_LENGTH];
    CHAR_DATA * victim;
    argument = one_argument (argument, arg);
    
    if (arg[0] == '\0')
    {
        stc("Approach whom?\n", ch);
        return;
    }
    
    if ((victim = get_char_room (ch, arg)) == NULL)
    {
        send_to_char ("They aren't here.\n\r{x", ch);
        return;
    }
    
    if (!ch->on_wild && !victim->on_wild)
    {
        stc("Either you, or your target are not on the wilderness.\n", ch);
        return;
    }
    
    if (victim->x == ch->x && victim->y == ch->y)
    {
        stc("You are already there!\n", ch);
        return;
    }
    
    if (victim->x < ch->x)
        cmd_west(ch, "");
    if (victim->x > ch->x)
        cmd_east(ch, "");
    if (victim->y < ch->y)
        cmd_north(ch, "");
    if (victim->y > ch->y)
        cmd_south(ch, "");

    sprintf(buf, "You approach %s.\n", victim->short_descr);
    stc(buf, ch);
    sprintf(buf, "%s approaches you.\n", ch->short_descr);
    stc(buf, victim);
}


/*
 * cmd_enter()
 *
 * enter command for the wilderness.
 * Syntax: enter <area>
 */
void cmd_enter(CHAR_DATA * ch, char * argument)
{
    WEXIT * p;
    ROOM_INDEX_DATA *location;

    p = get_wexit(ch, argument);
    
    if (p == NULL)
    {
        stc("There is no location by that name.\n\r", ch);
        return;
    }
    
    location = get_room_index(p->to_room);
    if (location == NULL)
    {
        stc("ERROR: Exit leads to a null room. Tell thri!\n", ch);
        return;
    }
    ch->on_wild = FALSE;
    ch->x = -1;
    ch->y = -1;
    char_from_room (ch);
    char_to_room (ch, location);
    stc("\n{x\n\n", ch);
    do_function (ch, &do_look, "auto");
    return;
}
    

WEXIT * get_wexit (CHAR_DATA * ch, char *argument)
{
    int x, y;
    int viewx = 31;
    int viewy = 15;
    int start_x = (ch->x - (viewx / 2));
    int start_y = (ch->y - (viewy / 2));
    WEXIT * p;

    for (y = start_y; y != (start_y + viewy); y++)
    {
        for (x = start_x; x != (start_x + viewx); x++)
        {
            for (p = wexit_list; p ; p = p->next)
            {
                if (is_name (argument, p->descr))
                        return p;
            }
        }
    }
    return NULL;
}