/* * File: MakePref.c * * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke * * This software may be copied and distributed for educational, research, * and not for profit purposes provided that this copyright and statement * are included in all such copies. Other copyrights may also apply. */ /* * This is a helper utility designed to create a suitable `graf-ibm.prf' * preference file that matches the graphic tile set defined in angband.fnt * * The matching is done against the internal types of the monsters, items, * and floor locations. * * Any changes to this file must also be reflected in angband.fnt and * gredit.ini. This program will not be distributed with the compiled version * since it is only of use to those editing the game, not playing it. The * `graf-ibm.prf' file generated by MakePref will be distributed. * * Usage: Just run makepref in the base angband directory. It will read * in the input data files and write out the output files automatically. * * Note that this utility ONLY uses the .RAW versions of the data files. Hence * you need to run Angband once to generate those files after they have been * changed. */ #include #include #include "angband.h" char basepath[4096]; void die(const char *format, ...) { va_list ar; va_start(ar, format); vprintf(format, ar); va_end(ar); exit(0); }; #define suffix(a,b) ((a)[strlen(a)-1]==(*b)) static void init_path(void) { cptr tail; /* Get the environment variable */ tail = getenv("ANGBAND_PATH"); /* Use the angband_path, or a default */ strcpy(basepath, tail ? tail : DEFAULT_PATH); /* Hack -- Add a path separator (only if needed) */ if (!suffix(basepath, PATH_SEP)) strcat(basepath, PATH_SEP); } void main(int argc, char **argv) { header head; FILE *f, *pref; char *ftext; int outsym; char filename[256]; init_path(); sprintf(filename,"%suser/%s",basepath,(argc==2)?argv[1]:"graf-ibm.prf"); pref = fopen(filename,"w"); if (!pref) die("Cannot create %s",filename); fprintf(pref,"# Graphics definition preference file.\n#\n" "# Generated automatically by `makepref' by Mike Marcelais\n#\n"); { /* Do F_INFO.RAW Feature types */ feature_type *ftype = NULL; int i; fprintf(stderr,"Processing F_INFO.RAW...\n"); fprintf(pref,"# Feature Graphic Definitions\n\n"); sprintf(filename,"%sdata/f_info.raw",basepath); f = fopen(filename,"rb"); if (!f) die("Cannot open f_info.raw\n"); fread(&head,sizeof(header),1,f); ftype = (feature_type *)malloc(sizeof(feature_type)*head.info_num); fread(ftype,head.info_num,sizeof(feature_type),f); ftext = (char *)malloc((head.name_size|0x0F)+1); fread(ftext,(head.name_size+15)/16,16,f); fclose(f); for(i=0;i': outsym = 206; break; /* Dn stairs */ case '1': outsym = 195; break; /* General Store */ case '2': outsym = 196; break; /* Armory */ case '3': outsym = 197; break; /* Weapon Shop */ case '4': outsym = 198; break; /* Temple */ case '5': outsym = 199; break; /* Alchemist */ case '6': outsym = 200; break; /* Magic Shop */ case '7': outsym = 201; break; /* Black Market */ case '8': outsym = 202; break; /* Home */ case '^': switch((i & 0x0F)>>2) /* Trap */ { case 0: outsym = 222; break; /* Pit */ case 1: outsym = 223; break; /* Rune */ case 2: outsym = 220; break; /* Dart */ case 3: outsym = 221; break; /* Gas */ }; break; case '+': if (i & 0x08) /* Secured Door */ outsym = 213; /* Jammed Door */ else if (i & 0x07) outsym = 214; /* Locked Door */ else outsym = 205; /* Closed Door */ break; case '#': outsym = 212; break; /* Granite Wall */ case ':': outsym = 219; break; /* Rubble */ case '%': if (i & 0x01) outsym = 218; /* Quartz */ else outsym = 215; /* Magma */ break; case '*': if (i & 0x01) outsym = 211; /* Gold in Quartz */ else outsym = 210; /* Gold in Magma */ break; default: fprintf(stderr,"Warning: Don't know how to handle feature %d (%c).\n",i,ftype[i].f_char); break; }; if (outsym) { fprintf(pref,"# %s\n",&ftext[ftype[i].name]); fprintf(pref,"F:%d:%d/%d\n\n",i,ftype[i].f_attr,(signed char)outsym); }; }; fprintf(pref,"\n"); free(ftype); free(ftext); } { /* Do K_INFO.RAW Item types */ object_kind *ftype = NULL; int i; fprintf(stderr,"Processing K_INFO.RAW...\n"); fprintf(pref,"# Item Graphic Definitions\n\n"); sprintf(filename,"%sdata/k_info.raw",basepath); f = fopen(filename,"rb"); fread(&head,sizeof(header),1,f); ftype = (object_kind *)malloc(sizeof(object_kind)*head.info_num); fread(ftype,head.info_num,sizeof(object_kind),f); ftext = (char *)malloc((head.name_size|0x0F)+1); fread(ftext,(head.name_size+15)/16,16,f); fclose(f); for(i=0;i= 'A') && (ftype[i].d_char <= 'Z')) outsym = 165+ftype[i].d_char-'A'; /* Uppercase letters */ else if ((ftype[i].d_char >= 'a') && (ftype[i].d_char <= 'z')) outsym = 225+ftype[i].d_char-'a'; /* Lowercase letters */ else switch (ftype[i].d_char) { case 0: break; /* Unused */ case '@': outsym = 251; break; case ',': outsym = 252; break; case '.': outsym = 217; break; case '$': outsym = 209; break; case '!': outsym = 146; break; case '=': outsym = 147; break; case '?': outsym = 149; break; default: fprintf(stderr,"Warning: Don't know how to handle monster %d (%c)\n",i,ftype[i].d_char); break; }; if (outsym) { fprintf(pref,"# %s\n",&ftext[ftype[i].name]); fprintf(pref,"R:%d:%d/%d\n\n",i,ftype[i].d_attr,(signed char)outsym); }; }; fprintf(pref,"\n"); free(ftype); free(ftext); }; /* Don't process V_INFO.RAW -- no need */ fclose(pref); fprintf(stderr,"Finished.\n"); };