randart-062a.diff This patch is for Angband 2.9.2. It will not work with any older version of Angband. This patch allows you to build the standalone "randart" program which creates an a_info.rnd file for testing the random artifact generation. How to use it: $ gzip -dc /path/to/angband-2.9.2.tar.gz | tar xvf - $ cd angband-2.9.2 $ patch -p1 < /path/to/thispatch $ cd src $ vi Makefile.std # if you wish to change CFLAGS, etc. $ make -f Makefile.std randart $ cd .. $ src/randart [cc] Counter-copyright 2001 Greg Wooledge This file is in the public domain and may be used without restrictions. diff -u -r angband-2.9.2/src/init1.c angband-2.9.2-hacked/src/init1.c --- angband-2.9.2/src/init1.c Thu Jan 25 17:54:04 2001 +++ angband-2.9.2-hacked/src/init1.c Mon Jun 4 19:18:30 2001 @@ -366,7 +366,7 @@ /* * Object flags */ -static cptr k_info_flags1[] = +cptr k_info_flags1[] = { "STR", "INT", @@ -405,7 +405,7 @@ /* * Object flags */ -static cptr k_info_flags2[] = +cptr k_info_flags2[] = { "SUST_STR", "SUST_INT", @@ -444,7 +444,7 @@ /* * Object flags */ -static cptr k_info_flags3[] = +cptr k_info_flags3[] = { "SLOW_DIGEST", "FEATHER", diff -u -r angband-2.9.2/src/init2.c angband-2.9.2-hacked/src/init2.c --- angband-2.9.2/src/init2.c Sun Feb 4 12:44:09 2001 +++ angband-2.9.2-hacked/src/init2.c Mon Jun 4 19:37:14 2001 @@ -612,7 +612,7 @@ /* * Initialize the "z_info" array */ -static errr init_z_info(void) +errr init_z_info(void) { /* Init the header */ init_header(&z_head, 1, sizeof(maxima), init_z_info_txt); @@ -640,7 +640,7 @@ /* * Initialize the "k_info" array */ -static errr init_k_info(void) +errr init_k_info(void) { /* Init the header */ init_header(&k_head, z_info->k_max, sizeof(object_kind), @@ -655,7 +655,7 @@ /* * Initialize the "a_info" array */ -static errr init_a_info(void) +errr init_a_info(void) { /* Init the header */ init_header(&a_head, z_info->a_max, sizeof(artifact_type), diff -u -r angband-2.9.2/src/randart.c angband-2.9.2-hacked/src/randart.c --- angband-2.9.2/src/randart.c Thu Jan 25 17:54:05 2001 +++ angband-2.9.2-hacked/src/randart.c Mon Jun 4 19:34:40 2001 @@ -646,7 +646,7 @@ static s16b *kinds; /* Global just for convenience. */ -static int randart_verbose = 0; +int randart_verbose = 0; /* --- angband-2.9.2/src/Makefile.std Mon Jun 4 19:53:15 2001 +++ angband-2.9.2-hacked/src/Makefile.std Mon Jun 4 19:57:38 2001 @@ -249,6 +249,18 @@ # +# Build the standalone "randart" program (optional) +# + +ROBJS = randmain.o randart.o init1.o init2.o variable.o util.o tables.o \ + files.o load1.o load2.o save.o xtra1.o xtra2.o object1.o \ + object2.o monster1.o monster2.o cave.o z-form.o z-rand.o \ + z-term.o z-util.o z-virt.o +randart: $(ROBJS) + $(CC) $(LDFLAGS) -o randart $(ROBJS) + + +# # Clean up old junk # @@ -292,6 +304,7 @@ init1.o: init1.c $(INCS) init2.o: init2.c $(INCS) randart.o: randart.c $(INCS) +randmain.o: randmain.c $(INCS) load1.o: load1.c $(INCS) load2.o: load2.c $(INCS) main-cap.o: main-cap.c $(INCS) --- angband-2.9.2/src/randmain.c Mon Jun 4 20:19:44 2001 +++ angband-2.9.2-hacked/src/randmain.c Mon Jun 4 20:13:15 2001 @@ -0,0 +1,212 @@ +/* + * Greg's random artifact generator (randart). This is a stub program which + * prints a file in the a_info.txt format. + */ + +#include +#include +#include +#include +#define ALLOW_TEMPLATES +#include "init.h" +#include "angband.h" + +extern cptr k_info_flags1[]; +extern cptr k_info_flags2[]; +extern cptr k_info_flags3[]; +extern int randart_verbose; +extern header a_head; + +#define A_INFO_TXT "a_info.txt" +#define A_INFO_RND "a_info.rnd" +#define BUFLEN 1024 +#define MAX_NAMES 512 +#define MAX_TRIES 200 + +void usage (void); +int do_randart (u32b seed); +int write_a_info (u32b seed); +void copy_a_to_o (int a_idx, object_type *); +void dump_flags (FILE *, const artifact_type *); + +#define abs(x) ((x) > 0 ? (x) : (-(x))) + +int main (int argc, char *argv[]) +{ + int rc; + char path[1024]; + u32b randart_seed; + bool have_seed = FALSE; + + if (argc > 1) + { + while (--argc) + { + char *arg = *++argv; + if (arg[0] != '-') usage(); + switch (arg[1]) + { + case 'v': randart_verbose = 1; + break; + case 's': randart_seed = (u32b) atol (arg + 2); + have_seed = TRUE; + break; + default: usage(); + } + } + } + + /* Prepare to use the Angband ?_info parsing routines. */ + strcpy (path, DEFAULT_PATH); + init_file_paths (path); + +#ifdef SET_UID + player_uid = getuid(); + player_euid = geteuid(); + player_egid = getegid(); + safe_setuid_drop(); +#endif + + if ((rc = init_z_info()) != 0) return rc; + if ((rc = init_a_info()) != 0) return rc; + if ((rc = init_k_info()) != 0) return rc; + + if (!have_seed) randart_seed = time (NULL); + if ((rc = do_randart (randart_seed)) != 0) return rc; + + printf ("Writing to 'a_info.rnd'.\n"); + if ((rc = write_a_info (randart_seed)) != 0) return rc; + + return 0; +} + +void usage (void) +{ + fprintf (stderr, "usage: randart [-v] [-sSEED]\n"); + exit (1); +} + +int write_a_info (u32b randart_seed) +{ + FILE *f; + int i; + time_t tt; + char *timestr; + + if ((f = fopen (A_INFO_RND, "w")) == NULL) + { + fprintf (stderr, "Cannot create '" A_INFO_RND "'.\n"); + return 1; + } + + /* Write header information. */ + fprintf (f, + "# Random a_info file generated by randart version 0.%d.%d\n", + RANDART_VERSION / 10, RANDART_VERSION % 10); + time(&tt); + timestr = ctime (&tt); + if (timestr) fprintf (f, "# Generation time: %s", timestr); + fprintf (f, "# Random seed: %lu\n", (unsigned long) randart_seed); + fprintf (f, "V:%d.%d.%d\n\n", + a_head.v_major, a_head.v_minor, a_head.v_patch); + + /* Write each artifact's "paragraph". */ + for (i = 1; i < z_info->a_max; i++) + { + artifact_type *a_ptr = &a_info[i]; + object_type ot; + char buf[80]; + + /* Skip unused artifacts. */ + if (a_ptr->tval == 0) continue; + + /* Give some human-readable description. */ + copy_a_to_o (i, &ot); + object_desc (buf, &ot, 0, 2); + fprintf (f, "# %s\n", buf); + + fprintf (f, "N:%d:%s\n", i, a_name + a_info[i].name); + fprintf (f, "I:%d:%d:%d\n", + a_ptr->tval, a_ptr->sval, a_ptr->pval); + fprintf (f, "W:%d:%d:%d:%ld\n", + a_ptr->level, a_ptr->rarity, + a_ptr->weight, a_ptr->cost); + fprintf (f, "P:%d:%dd%d:%d:%d:%d\n", + a_ptr->ac, a_ptr->dd, a_ptr->ds, + a_ptr->to_h, a_ptr->to_d, a_ptr->to_a); + dump_flags (f, a_ptr); + } + + fclose (f); + return 0; +} + +void copy_a_to_o (int a_idx, object_type *o_ptr) +{ + artifact_type *a_ptr = &a_info[a_idx]; + + o_ptr->tval = a_ptr->tval; + o_ptr->sval = a_ptr->sval; + o_ptr->pval = a_ptr->pval; + o_ptr->to_h = a_ptr->to_h; + o_ptr->to_d = a_ptr->to_d; + o_ptr->to_a = a_ptr->to_a; + o_ptr->ac = a_ptr->ac; + o_ptr->dd = a_ptr->dd; + o_ptr->ds = a_ptr->ds; + o_ptr->weight = a_ptr->weight; + o_ptr->k_idx = lookup_kind (o_ptr->tval, o_ptr->sval); + o_ptr->ident = IDENT_KNOWN; + o_ptr->name1 = a_idx; + o_ptr->name2 = 0; + o_ptr->discount = 0; + o_ptr->number = 1; + o_ptr->timeout = 0; +} + +/* Write the artifact's flags to our already-opened file. Each flag will be + put on a separate line, just because it's easier that way. All but the + last flag will have " |" at the end of the line. */ +void dump_flags (FILE *f, const artifact_type *a_ptr) +{ + int i; + u32b f3; + int already_wrote = 0; + + /* Do a_ptr->flags1, a_ptr->flags2 and a_ptr->flags3 separately */ + for (i = 0; i < 32; i++) + { + if (a_ptr->flags1 & ((u32b)1<flags2 & ((u32b)1<flags3 & + ~(TR3_IGNORE_ACID | TR3_IGNORE_ELEC | + TR3_IGNORE_FIRE | TR3_IGNORE_COLD); + for (i = 0; i < 32; i++) + { + if (f3 & ((u32b)1<