btmux/autom4te.cache/
btmux/doc/.svn/
btmux/event/.svn/
btmux/game/.svn/
btmux/game/bin/.svn/
btmux/game/data/.svn/
btmux/game/logs/.svn/
btmux/game/maps/
btmux/game/maps/.svn/
btmux/game/maps/.svn/prop-base/
btmux/game/maps/.svn/props/
btmux/game/maps/.svn/text-base/
btmux/game/maps/.svn/wcprops/
btmux/game/mechs/
btmux/game/mechs/.svn/
btmux/game/mechs/.svn/prop-base/
btmux/game/mechs/.svn/props/
btmux/game/mechs/.svn/text-base/
btmux/game/mechs/.svn/wcprops/
btmux/game/text/.svn/
btmux/include/.svn/
btmux/misc/
btmux/misc/.svn/
btmux/misc/.svn/prop-base/
btmux/misc/.svn/props/
btmux/misc/.svn/text-base/
btmux/misc/.svn/wcprops/
btmux/python/
btmux/python/.svn/
btmux/python/.svn/prop-base/
btmux/python/.svn/props/
btmux/python/.svn/text-base/
btmux/python/.svn/wcprops/
btmux/src/.svn/prop-base/
btmux/src/.svn/props/
btmux/src/.svn/text-base/
btmux/src/.svn/wcprops/
btmux/src/hcode/.svn/
btmux/src/hcode/btech/
btmux/src/hcode/btech/.svn/
btmux/src/hcode/btech/.svn/prop-base/
btmux/src/hcode/btech/.svn/props/
btmux/src/hcode/btech/.svn/text-base/
btmux/src/hcode/btech/.svn/wcprops/
btmux/src/hcode/include/.svn/
/*
 * $Id: map.coding.c,v 1.1.1.1 2005/01/11 21:18:07 kstevens Exp $
 *
 * Author: Markus Stenberg <fingon@iki.fi>
 *
 *  Copyright (c) 1996 Markus Stenberg
 *  Copyright (c) 1998-2002 Thomas Wouters
 *  Copyright (c) 2000-2002 Cord Awtry
 *       All rights reserved
 *
 * Created: Tue Oct  8 16:46:12 1996 fingon
 * Last modified: Sat Jun  6 21:44:08 1998 fingon
 *
 */


/* Simple coding scheme to reduce space used by map hexes to 1 byte/hex */

/* NOTE: if we _ever_ use more than 255 terrain/elevation combinations,
   this code becomes a bomb. */

#include <string.h>
#include "map.coding.h"

static int first_free = 0;

/* terr / height -> index mapping */
static unsigned char data_to_id[LASTCHAR][ELEVATIONS];

typedef struct hex_struct {
    char terrain;
    char elev;
} HS;

static HS id_to_data[ENTRIES];

void init_map_coding()
{
    bzero(id_to_data, sizeof(id_to_data));
    bzero(data_to_id, sizeof(data_to_id));
}

int Coding_GetIndex(char terrain, char elevation)
{
    int i;

    if ((i = data_to_id[(short) terrain][(short) elevation]))
	return i - 1;
    id_to_data[first_free].terrain = terrain;
    id_to_data[first_free].elev = elevation;
    first_free++;
    data_to_id[(short) terrain][(short) elevation] = first_free;
    return first_free - 1;
}

char Coding_GetElevation(int index)
{
    return id_to_data[index].elev;
}

char Coding_GetTerrain(int index)
{
    return id_to_data[index].terrain;
}