wild_data.c
demise/src/wild_data.c · 5.2 KB
From the archive dodbackup-final.tar.gz
Download the archive « Back to the archive contents
/******************************************************************************
Snippet: Wilderness system (v1.0).
Author: Richard Woolcock (aka KaVir).
Date: 2nd September 1998.
******************************************************************************
File: wild_data.c
Purpose: Deals with map data.
******************************************************************************
This code is copyright (C) 1998 by Richard Woolcock. It may be used and
distributed freely, as long as you do not remove this copyright notice.
******************************************************************************/
/******************************************************************************
Required libraries
******************************************************************************/
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "merc.h"
#include "wild.h"
/******************************************************************************
Required variables
******************************************************************************/
static bool world_saving = FALSE;
static char vmap_data[WILDERNESS_SIZE][WILDERNESS_SIZE];
static bool vmap_changed[(WILDERNESS_SIZE / 100)][(WILDERNESS_SIZE / 100)];
static MAP_TYPE vmap_big[(WILDERNESS_SIZE / 100)][(WILDERNESS_SIZE / 100)] = {
{LAND, LAND, LAND, LAND, LAND, LAND, SEA, SEA, SEA, LAND},
{LAND, LAND, LAND, LAND, LAND, LAND, SEA, LAND, SEA, LAND},
{SEA, SEA, SEA, SEA, SEA, SEA, SEA, SEA, SEA, SEA},
{LAND, SEA, LAND, LAND, LAND, LAND, SEA, LAND, SEA, LAND},
{LAND, SEA, LAND, LAND, LAND, LAND, SEA, LAND, SEA, LAND},
{LAND, SEA, LAND, LAND, LAND, LAND, SEA, LAND, SEA, LAND},
{SEA, SEA, SEA, SEA, SEA, SEA, SEA, SEA, SEA, SEA},
{LAND, LAND, LAND, LAND, LAND, LAND, SEA, LAND, SEA, LAND},
{LAND, LAND, LAND, LAND, SEA, LAND, SEA, LAND, SEA, LAND},
{LAND, LAND, LAND, LAND, LAND, LAND, SEA, LAND, SEA, LAND}
};
/******************************************************************************
Local operation prototypes
******************************************************************************/
/* None. */
/******************************************************************************
Global operations
******************************************************************************/
char
map_data (int x, int y)
{
char return_value; /* This stores the return value from the call */
/* Check that the 'x' coordinate is valid */
if (x < 0 || x >= WILDERNESS_SIZE)
{
/* Return value is set to 0 as default */
return_value = 0;
}
/* Check that the 'y' coordinate is valid */
else if (y < 0 || y >= WILDERNESS_SIZE)
{
/* Return value is set to 0 as default */
return_value = 0;
}
else /* Both 'x' and 'y' coordinates are valid */
{
/* Return value is determined from the map_data array */
return_value = vmap_data[x][y];
}
/* Return the appropriate data */
return (return_value);
}
void
set_map_data (int x, int y, char room_type)
{
/* Check that the 'x' and 'y' coordinates are valid */
if (x >= 0 && x <= WILDERNESS_SIZE && y >= 0 && y <= WILDERNESS_SIZE)
{
/* Set the map_data structure to the room_type parameter */
vmap_data[x][y] = room_type;
}
return;
}
bool
map_changed (int x, int y)
{
bool return_value; /* This stores the return value from the call */
/* Check that the 'x' coordinate is valid */
if (x < 0 || x >= (WILDERNESS_SIZE / 100))
{
/* Return value is set to 0 as default */
return_value = 0;
}
/* Check that the 'y' coordinate is valid */
else if (y < 0 || y >= (WILDERNESS_SIZE / 100))
{
/* Return value is set to 0 as default */
return_value = 0;
}
else /* Both 'x' and 'y' coordinates are valid */
{
/* Return value is determined from the map_changed array */
return_value = vmap_changed[x][y];
}
/* Return the appropriate data */
return (return_value);
}
void
set_map_changed (int x, int y, bool changed)
{
/* Check that the 'x' and 'y' coordinates are valid */
if (x >= 0 && x <= (WILDERNESS_SIZE / 100) &&
y >= 0 && y <= (WILDERNESS_SIZE / 100))
{
/* Set the map_data structure to the room_type parameter */
vmap_changed[x][y] = changed;
}
return;
}
MAP_TYPE
map_big (int x, int y)
{
MAP_TYPE return_value; /* This stores the return value from the call */
/* Check that the 'x' coordinate is valid */
if (x < 0 || x >= (WILDERNESS_SIZE / 100))
{
/* Return value is set to 0 as default */
return_value = LAND;
}
/* Check that the 'y' coordinate is valid */
else if (y < 0 || y >= (WILDERNESS_SIZE / 100))
{
/* Return value is set to 0 as default */
return_value = LAND;
}
else /* Both 'x' and 'y' coordinates are valid */
{
/* Return value is determined from the map_changed array */
return_value = vmap_big[x][y];
}
/* Return the appropriate data */
return (return_value);
}
void
set_world_saving (bool save_world)
{
/* Store whether or not the world is autosaving */
world_saving = save_world;
return;
}
bool
check_world_saving (void)
{
/* Return whether or not the world is autosaving */
return (world_saving);
}