#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> #define WORLD_FILE "the_world.gz" #define IMAGE_FILE "world_image.raw" #define MAX_WIDTH 1024 #define MAX_HEIGHT 768 #define MAX_SECTOR 18 #define FALSE 0 #define TRUE 0 int map[MAX_WIDTH][MAX_HEIGHT]; struct wilderness_type { char * name; char * char_sm; int sector; int red; /* RBG: raw image numbers for load/save */ int green; int blue; int passable; int can_see_through; }; extern struct wilderness_type wilderness_table[]; void cmd_load_image(); int return_sector_number(int r, int g, int b); struct wilderness_type wilderness_table[] = { /*# Red Grn Blu */ {"Grass", "{g.", 0, 0, 255, 0, TRUE, TRUE }, /* 0 */ {"Mountain", "{D^", 1, 0, 0, 0, TRUE, TRUE }, /* 1 */ {"River", "{C~", 2, 0, 255, 255, TRUE, TRUE }, /* 2 */ {"Ocean", "{b~", 3, 0, 0, 255, TRUE, TRUE }, /* 3 */ {"Beach", "{y.", 4, 1, 1, 1, TRUE, TRUE }, /* 4 */ {"Desert", "{y^", 5, 255, 255, 0, TRUE, TRUE }, /* 5 */ {"Hills", "{w^", 6, 128, 128, 128, TRUE, TRUE }, /* 6 */ {"Tree", "{G*", 7, 0, 128, 0, TRUE, TRUE }, /* 7 */ {"Swamp", "{g&", 8, 128, 255, 128, TRUE, TRUE }, /* 8 */ {"Swamp", "{g&", 9, 129, 255, 128, TRUE, TRUE }, /* 8 */ {"Ground", "{D*", 10, 178, 147, 4, TRUE, TRUE }, /* 10 */ {"CityWall|", "{D|", 11, 100, 200, 0, FALSE, FALSE}, /* 11 */ {"CityWall-", "{D-", 12, 255, 0, 255, FALSE, FALSE}, /* 12 */ {"City_Street", "{w.", 13, 200, 0, 0, TRUE, TRUE }, /* 13 */ {"Door", "{y+", 14, 200, 200, 0, FALSE, FALSE}, /* 14 */ {"Fountain", "{C%", 15, 128, 64, 0, TRUE, TRUE }, /* 15 */ {"Inside", "{g.", 16, 235, 235, 235, TRUE, TRUE }, /* 16 */ {"unused", "{G*", 17, 0, 128, 0, TRUE, TRUE }, /* 17 */ {"CTree", "{G*", 18, 0, 128, 0, TRUE, TRUE }, /* 18 */ {"Door-open", "{y.", 19, 2, 2, 2, TRUE, TRUE }, /* 19 */ {"Nothing", " ", 20, 3, 4, 5, FALSE, FALSE}, /* 20 */ {NULL, "#R+", 21, 1, 2, 3, TRUE, TRUE}, /* END */ }; int main() { gzFile *fp; printf("Creating world file\n"); fp = gzopen(WORLD_FILE,"rb9"); gzread(fp,map,sizeof(map)); gzclose(fp); printf("Loading image file to world structure\n"); cmd_load_image(); printf("Saving world file\n"); fp = gzopen(WORLD_FILE,"wb9"); gzwrite(fp,map,sizeof(map)); gzclose(fp); printf("Sucess!\n"); return 1; } void cmd_load_image() { FILE * fp; int x, y, graph1, graph2, graph3; if( !( fp = fopen( "world_image.raw", "rb" ) ) ) { return; } for (y = 0; y < MAX_WIDTH; y++) { for (x = 0; x < MAX_HEIGHT; x++) { graph1 = fgetc(fp); graph2 = fgetc(fp); graph3 = fgetc(fp); map[y][x] = return_sector_number(graph1, graph2, graph3); } } fclose( fp ); return; } int return_sector_number(int r, int g, int b) { int i; int final; for (i = 0; i < MAX_SECTOR; i++) { if (wilderness_table[i].red == r && wilderness_table[i].green == g && wilderness_table[i].blue == b) { final = wilderness_table[i].sector; break; } else final = MAX_SECTOR + 1; } return final; }