src/hcode/btech/map.coding.c

Go to the documentation of this file.
00001 
00002 /*
00003  * $Id: map.coding.c,v 1.1.1.1 2005/01/11 21:18:07 kstevens Exp $
00004  *
00005  * Author: Markus Stenberg <fingon@iki.fi>
00006  *
00007  *  Copyright (c) 1996 Markus Stenberg
00008  *  Copyright (c) 1998-2002 Thomas Wouters
00009  *  Copyright (c) 2000-2002 Cord Awtry
00010  *       All rights reserved
00011  *
00012  * Created: Tue Oct  8 16:46:12 1996 fingon
00013  * Last modified: Sat Jun  6 21:44:08 1998 fingon
00014  *
00015  */
00016 
00017 /* Simple coding scheme to reduce space used by map hexes to 1 byte/hex */
00018 
00019 /* NOTE: if we _ever_ use more than 255 terrain/elevation combinations,
00020    this code becomes a bomb. */
00021 
00022 #include <string.h>
00023 #include "map.coding.h"
00024 
00025 static int first_free = 0;
00026 
00027 /* terr / height -> index mapping */
00028 static unsigned char data_to_id[LASTCHAR][ELEVATIONS];
00029 
00030 typedef struct hex_struct {
00031         char terrain;
00032         char elev;
00033 } HS;
00034 
00035 static HS id_to_data[ENTRIES];
00036 
00037 void init_map_coding()
00038 {
00039         bzero(id_to_data, sizeof(id_to_data));
00040         bzero(data_to_id, sizeof(data_to_id));
00041 }
00042 
00043 int Coding_GetIndex(char terrain, char elevation)
00044 {
00045         int i;
00046 
00047         if((i = data_to_id[(short) terrain][(short) elevation]))
00048                 return i - 1;
00049         id_to_data[first_free].terrain = terrain;
00050         id_to_data[first_free].elev = elevation;
00051         first_free++;
00052         data_to_id[(short) terrain][(short) elevation] = first_free;
00053         return first_free - 1;
00054 }
00055 
00056 char Coding_GetElevation(int index)
00057 {
00058         return id_to_data[index].elev;
00059 }
00060 
00061 char Coding_GetTerrain(int index)
00062 {
00063         return id_to_data[index].terrain;
00064 }

Generated on Mon May 28 04:25:21 2007 for BattletechMUX by  doxygen 1.4.7