1 /* File: variable.c */
2 
3 /* Purpose: Angband variables */
4 
5 /*
6  * Copyright (c) 1989 James E. Wilson, Robert A. Koeneke
7  *
8  * This software may be copied and distributed for educational, research, and
9  * not for profit purposes provided that this copyright and statement are
10  * included in all such copies.
11  */
12 
13 #include "angband.h"
14 
15 
16 /*
17  * Hack -- Link a copyright message into the executable
18  */
19 cptr copyright[5] =
20 {
21 	"Copyright (c) 1989 James E. Wilson, Robert A. Keoneke",
22 	"",
23 	"This software may be copied and distributed for educational, research,",
24 	"and not for profit purposes provided that this copyright and statement",
25 	"are included in all such copies."
26 };
27 
28 
29 /*
30  * Executable version
31  */
32 byte version_major = VER_MAJOR;
33 byte version_minor = VER_MINOR;
34 byte version_patch = VER_PATCH;
35 byte version_extra = VER_EXTRA;
36 
37 /*
38  * Savefile version
39  */
40 byte sf_extra;	/* Savefile's "version_extra" */
41 u32b sf_version;	/* Savefile's "version" */
42 
43 byte z_major;	/* Savefile version for Zangband */
44 byte z_minor;
45 byte z_patch;
46 
47 /*
48  * Savefile information
49  */
50 u32b sf_xtra;	/* Operating system info */
51 u32b sf_when;	/* Time when savefile created */
52 u16b sf_lives;	/* Number of past "lives" with this file */
53 u16b sf_saves;	/* Number of "saves" during this life */
54 
55 /*
56  * Run-time arguments
57  */
58 bool arg_fiddle;	/* Command arg -- Request fiddle mode */
59 bool arg_wizard;	/* Command arg -- Request wizard mode */
60 bool arg_sound;	/* Command arg -- Request special sounds */
61 byte arg_graphics;	/* Command arg -- Request graphics mode */
62 bool arg_bigtile;	/* Command arg -- Request bigtile mode */
63 bool arg_monochrome;	/* Command arg -- Request monochrome mode */
64 bool arg_force_original;	/* Command arg -- Request original keyset */
65 bool arg_force_roguelike;	/* Command arg -- Request roguelike keyset */
66 
67 /*
68  * Various things
69  */
70 bool character_generated = FALSE;	/* The character exists */
71 bool character_dungeon = FALSE;	/* The character has a dungeon */
72 bool character_loaded = FALSE;	/* The character was loaded from a savefile */
73 bool character_saved = FALSE;	/* The character was just saved to a savefile */
74 
75 bool character_icky = FALSE;	/* The game is in an icky full screen mode */
76 bool character_xtra = FALSE;	/* The game is in an icky startup mode */
77 
78 u32b seed_flavor;	/* Hack -- consistent object colors */
79 
80 bool msg_flag;	/* Used in msg_print() for "buffering" */
81 
82 s16b num_repro;	/* Current reproducer count */
83 
84 s32b turn;	/* Current game turn */
85 s32b old_turn;	/* Turn when level began (feelings) */
86 
87 bool use_sound;	/* The "sound" mode is enabled */
88 byte use_graphics;	/* The "graphics" mode enabled (0 is none) */
89 bool use_bigtile = FALSE;	/* Use square map tiles */
90 
91 bool use_transparency = FALSE;	/* Use transparent tiles */
92 
93 s16b signal_count;	/* Hack -- Count interupts */
94 
95 s16b o_max = 1;	/* Number of allocated objects */
96 s16b o_cnt = 0;	/* Number of live objects */
97 
98 s16b m_max = 1;	/* Number of allocated monsters */
99 s16b m_cnt = 0;	/* Number of live monsters */
100 
101 s16b fld_max = 1;	/* Number of allocated fields */
102 s16b fld_cnt = 0;	/* Number of live fields */
103 
104 s16b rg_max = 1;	/* Number of allocated regions */
105 s16b rg_cnt = 0;	/* Number of live regions */
106 
107 s16b q_max = 1;	/* Number of allocated quests */
108 
109 s16b hack_m_idx = 0;	/* Hack -- see "process_monsters()" */
110 
111 /* Can we get rid of this at all? */
112 char summon_kin_type;	/* Hack, by Julian Lighton: summon 'relatives' */
113 
114 /* This probably can be moved to player_type */
115 int total_friends = 0;
116 s32b total_friend_levels = 0;
117 s32b friend_align = 0;
118 
119 s16b store_cache_num = 0;	/* Number of stores with stock */
120 store_type **store_cache;	/* The cache of store stocks */
121 
122 
123 
124 /* Special options */
125 
126 byte hitpoint_warn;	/* Hitpoint warning (0 to 9) */
127 
128 byte delay_factor;	/* Delay factor (0 to 9) */
129 
130 byte autosave_l;	/* Autosave before entering new levels */
131 byte autosave_t;	/* Timed autosave */
132 s16b autosave_freq;	/* Autosave frequency */
133 
134 /* Cheating options */
135 bool cheat_peek;
136 bool cheat_hear;
137 bool cheat_room;
138 bool cheat_xtra;
139 bool cheat_know;
140 bool cheat_live;
141 
142 bool fake_monochrome;	/* Use fake monochrome for effects */
143 
144 
145 /*
146  * Dungeon size info
147  */
148 
149 s16b panel_row_min, panel_row_max;
150 s16b panel_col_min, panel_col_max;
151 
152 byte *mp_a = NULL;
153 char *mp_c = NULL;
154 byte *mp_ta = NULL;
155 char *mp_tc = NULL;
156 
157 
158 /*
159  * User info
160  */
161 int player_uid;
162 int player_euid;
163 int player_egid;
164 
165 /*
166  * Current player's character name
167  */
168 char player_name[32];
169 
170 /*
171  * Stripped version of "player_name"
172  */
173 char player_base[32];
174 
175 
176 /*
177  * Buffer to hold the current savefile name
178  */
179 char savefile[1024];
180 
181 
182 
183 /*
184  * Array of grids viewable to the player (see "cave.c")
185  */
186 s16b view_n;
187 s16b view_y[VIEW_MAX];
188 s16b view_x[VIEW_MAX];
189 
190 /*
191  * Array of grids for use by various functions (see "cave.c")
192  */
193 s16b temp_n;
194 s16b temp_y[TEMP_MAX];
195 s16b temp_x[TEMP_MAX];
196 
197 
198 /*
199  * Array of grids for use in monster lighting effects (see "cave.c")
200  */
201 s16b lite_n = 0;
202 s16b lite_y[LITE_MAX];
203 s16b lite_x[LITE_MAX];
204 
205 
206 
207 /*
208  * Number of active macros.
209  */
210 s16b macro__num;
211 
212 /*
213  * Array of macro patterns [MACRO_MAX]
214  */
215 cptr *macro__pat;
216 
217 /*
218  * Array of macro actions [MACRO_MAX]
219  */
220 cptr *macro__act;
221 
222 /*
223  * Array of macro types [MACRO_MAX]
224  */
225 bool *macro__cmd;
226 
227 /*
228  * Current macro action [1024]
229  */
230 char *macro__buf;
231 
232 
233 /*
234  * The array of window options
235  */
236 u32b window_flag[ANGBAND_TERM_MAX];
237 u32b window_mask[ANGBAND_TERM_MAX];
238 
239 /* Normal option masks */
240 u32b option_mask[8];
241 
242 
243 /*
244  * The array of window pointers
245  */
246 term *angband_term[ANGBAND_TERM_MAX];
247 
248 
249 /*
250  * Standard window names
251  */
252 char angband_term_name[ANGBAND_TERM_MAX][16] =
253 {
254 	VERSION_NAME,
255 	"Term-1",
256 	"Term-2",
257 	"Term-3",
258 	"Term-4",
259 	"Term-5",
260 	"Term-6",
261 	"Term-7"
262 };
263 
264 
265 /*
266  * Global table of color definitions
267  */
268 byte angband_color_table[256][4] =
269 {
270 	{0x00, 0x00, 0x00, 0x00},	/* TERM_DARK */
271 	{0x00, 0xFF, 0xFF, 0xFF},	/* TERM_WHITE */
272 	{0x00, 0x80, 0x80, 0x80},	/* TERM_SLATE */
273 	{0x00, 0xFF, 0x80, 0x00},	/* TERM_ORANGE */
274 	{0x00, 0xC0, 0x00, 0x00},	/* TERM_RED */
275 	{0x00, 0x00, 0x80, 0x40},	/* TERM_GREEN */
276 	{0x00, 0x00, 0x00, 0xFF},	/* TERM_BLUE */
277 	{0x00, 0x80, 0x40, 0x00},	/* TERM_UMBER */
278 	{0x00, 0x40, 0x40, 0x40},	/* TERM_L_DARK */
279 	{0x00, 0xC0, 0xC0, 0xC0},	/* TERM_L_WHITE */
280 	{0x00, 0xFF, 0x00, 0xFF},	/* TERM_VIOLET */
281 	{0x00, 0xFF, 0xFF, 0x00},	/* TERM_YELLOW */
282 	{0x00, 0xFF, 0x00, 0x00},	/* TERM_L_RED */
283 	{0x00, 0x00, 0xFF, 0x00},	/* TERM_L_GREEN */
284 	{0x00, 0x00, 0xFF, 0xFF},	/* TERM_L_BLUE */
285 	{0x00, 0xC0, 0x80, 0x40}	/* TERM_L_UMBER */
286 };
287 
288 
289 /*
290  * Standard sound names
291  */
292 char angband_sound_name[SOUND_MAX][16] =
293 {
294 	"",
295 	"hit",
296 	"miss",
297 	"flee",
298 	"drop",
299 	"kill",
300 	"level",
301 	"death",
302 	"study",
303 	"teleport",
304 	"shoot",
305 	"quaff",
306 	"zap",
307 	"walk",
308 	"tpother",
309 	"hitwall",
310 	"eat",
311 	"store1",
312 	"store2",
313 	"store3",
314 	"store4",
315 	"dig",
316 	"opendoor",
317 	"shutdoor",
318 	"tplevel",
319 	"scroll",
320 	"buy",
321 	"sell",
322 	"warn",
323 	"rocket",
324 	"n_kill",
325 	"u_kill",
326 	"quest",
327 	"heal",
328 	"x_heal",
329 	"bite",
330 	"claw",
331 	"m_spell",
332 	"summon",
333 	"breath",
334 	"ball",
335 	"m_heal",
336 	"atkspell",
337 	"evil",
338 	"touch",
339 	"sting",
340 	"crush",
341 	"slime",
342 	"wail",
343 	"winner",
344 	"fire",
345 	"acid",
346 	"elec",
347 	"cold",
348 	"illegal",
349 	"fail",
350 	"wakeup",
351 	"invuln",
352 	"fall",
353 	"pain",
354 	"destitem",
355 	"moan",
356 	"show",
357 	"unused",
358 	"explode",
359 };
360 
361 
362 /*
363  * The function pointer that is used to access the dungeon / wilderness.
364  * It points to a simple function when in the dungeon, that evaluates
365  * cave[y][x]
366  * In the wilderness, things are more complicated.
367  */
368 
369 cave_type *(*area_aux) (int, int);
370 
371 /*
372  * Equivalent function pointer used to get player information
373  * for each grid.
374  */
375 
376 pcave_type *(*parea_aux) (int, int);
377 
378 /*
379  * Variables used to access the scrollable wilderness.
380  * This is designed to be as fast as possible - whilst using as little
381  * RAM as possible to store a massive wilderness.
382  *
383  * The wilderness is generated "on the fly" as the player moves around it.
384  * To save time - blocks of 16x16 squares are saved in a cache so they
385  * don't need to be redone if the player moves back and forth.
386  */
387 
388 /* block used to generate plasma fractal for random wilderness */
389 u16b *temp_block[WILD_BLOCK_SIZE + 1];
390 
391 /* List of 16x16 blocks in the wilderness */
392 blk_ptr *wild_cache;
393 
394 /* Reference count of each 16x16 block in the wilderness */
395 int **wild_refcount;
396 
397 /* Counter of where in the list of cache blocks we are */
398 u32b wc_cnt = 0;
399 
400 /* The wilderness itself - grid of 16x16 blocks*/
401 blk_ptr **wild_grid;
402 
403 /* The data used to generate the wilderness */
404 wild_type **wild;
405 
406 /* The seed for the wilderness */
407 u32b wild_seed;
408 
409 /* Description of wilderness block types */
410 wild_gen_data_type *wild_gen_data;
411 
412 /* The decision tree for working out what block type to pick */
413 wild_choice_tree_type *wild_choice_tree;
414 
415 /* Bounds checking function pointers */
416 bool (*in_bounds) (int, int);
417 bool (*in_bounds2) (int, int);
418 bool (*in_boundsp) (int, int);
419 
420 /*
421  * Current size of the wilderness
422  */
423 s32b max_wild;
424 
425 /*
426  * The current global region.
427  */
428 region_type cave_data;
429 
430 /*
431  * Index of current global region
432  */
433 int cur_region;
434 
435 /*
436  * The array of dungeon items [z_info->o_max]
437  */
438 object_type *o_list;
439 
440 /*
441  * The array of dungeon monsters [z_info->m_max]
442  */
443 monster_type *m_list;
444 
445 /*
446  * The array of fields [z_info->fld_max]
447  */
448 field_type *fld_list;
449 
450 /*
451  * The array of regions [z_info->rg_max]
452  */
453 region_type *rg_list;
454 
455 /*
456  * The array of region information [z_info->rg_max]
457  */
458 region_info *ri_list;
459 
460 /*
461  * Number of towns used.
462  */
463 u16b place_count;
464 
465 /*
466  * Places in the wilderness [z_info->wp_max]
467  */
468 place_type *place;
469 
470 
471 /*
472  * The size of "alloc_kind_table" (at most z_info->k_max * 4)
473  */
474 s16b alloc_kind_size;
475 
476 /*
477  * The entries in the "kind allocator table"
478  */
479 alloc_entry *alloc_kind_table;
480 
481 
482 /*
483  * The size of "alloc_race_table" (at most z_info->r_max)
484  */
485 s16b alloc_race_size;
486 
487 /*
488  * The entries in the "race allocator table"
489  */
490 alloc_entry *alloc_race_table;
491 
492 
493 /*
494  * The size of the "alloc_ego_table" (at most z_info->e_max)
495  */
496 s16b alloc_ego_size;
497 
498 /*
499  * The entries in the "ego item allocator table"
500  */
501 alloc_entry *alloc_ego_table;
502 
503 
504 /*
505  * Specify attr/char pairs for visual special effects
506  * Be sure to use "index & 0x7F" to avoid illegal access
507  *
508  * Can we decrease the size to 128??
509  */
510 byte misc_to_attr[256];
511 char misc_to_char[256];
512 
513 
514 /*
515  * Specify attr/char pairs for inventory items (by tval)
516  * Be sure to use "index & 0x7F" to avoid illegal access
517  */
518 byte tval_to_attr[128];
519 char tval_to_char[128];
520 
521 
522 /*
523  * Keymaps for each "mode" associated with each keypress.
524  */
525 cptr keymap_act[KEYMAP_MODES][256];
526 
527 
528 
529 /*** Player information ***/
530 
531 /*
532  * Static player info record
533  */
534 player_type p_body;
535 
536 /*
537  * Pointer to the player info
538  */
539 player_type *p_ptr = &p_body;
540 
541 /*
542  * Pointer to the player tables
543  * (sex, race, class, magic)
544  */
545 player_sex *sp_ptr;
546 player_race *rp_ptr;
547 player_class *cp_ptr;
548 player_magic *mp_ptr;
549 
550 /**** Server Information ****/
551 
552 server_type s_body;
553 
554 /*
555  * Pointer to the server information
556  */
557 server_type *svr_ptr = &s_body;
558 
559 
560 
561 /*
562  * Structure (not array) of size limits
563  */
564 maxima *z_info;
565 
566 /*
567  * The vault generation arrays
568  */
569 vault_type *v_info;
570 char *v_name;
571 char *v_text;
572 
573 /*
574  * The terrain feature arrays
575  */
576 feature_type *f_info;
577 char *f_name;
578 char *f_text;
579 
580 /*
581  * The object kind arrays
582  */
583 object_kind *k_info;
584 char *k_name;
585 char *k_text;
586 
587 /*
588  * The artifact arrays
589  */
590 artifact_type *a_info;
591 char *a_name;
592 char *a_text;
593 
594 /*
595  * The ego-item arrays
596  */
597 ego_item_type *e_info;
598 char *e_name;
599 char *e_text;
600 
601 
602 /*
603  * The monster race arrays
604  */
605 monster_race *r_info;
606 char *r_name;
607 char *r_text;
608 
609 /*
610  * The field thaumatergical array
611  */
612 field_thaum *t_info;
613 
614 /*
615  * Quest data array
616  */
617 quest_type *quest;
618 
619 /*
620  * Hack -- The special Angband "System Suffix"
621  * This variable is used to choose an appropriate "pref-xxx" file
622  */
623 cptr ANGBAND_SYS = "xxx";
624 
625 
626 /*
627  * Path name: The main "lib" directory
628  * This variable is not actually used anywhere in the code
629  */
630 cptr ANGBAND_DIR;
631 
632 /*
633  * High score files (binary)
634  * These files may be portable between platforms
635  */
636 cptr ANGBAND_DIR_APEX;
637 
638 /*
639  * Bone files for player ghosts (ascii)
640  * These files are portable between platforms
641  */
642 cptr ANGBAND_DIR_BONE;
643 
644 /*
645  * Binary image files for the "*_info" arrays (binary)
646  * These files are not portable between platforms
647  */
648 cptr ANGBAND_DIR_DATA;
649 
650 /*
651  * Textual template files for the "*_info" arrays (ascii)
652  * These files are portable between platforms
653  */
654 cptr ANGBAND_DIR_EDIT;
655 
656 /*
657  * Script files
658  * These files are portable between platforms.
659  */
660 cptr ANGBAND_DIR_SCRIPT;
661 
662 /*
663  * Various extra files (ascii)
664  * These files may be portable between platforms
665  */
666 cptr ANGBAND_DIR_FILE;
667 
668 /*
669  * Help files (normal) for the online help (ascii)
670  * These files are portable between platforms
671  */
672 cptr ANGBAND_DIR_HELP;
673 
674 /*
675  * Help files (spoilers) for the online help (ascii)
676  * These files are portable between platforms
677  */
678 cptr ANGBAND_DIR_INFO;
679 
680 /*
681  * Default user "preference" files (ascii)
682  * These files are rarely portable between platforms
683  */
684 cptr ANGBAND_DIR_PREF;
685 
686 /*
687  * Savefiles for current characters (binary)
688  * These files are portable between platforms
689  */
690 cptr ANGBAND_DIR_SAVE;
691 
692 /*
693  * User "preference" files (ascii)
694  * These files are rarely portable between platforms
695  */
696 cptr ANGBAND_DIR_USER;
697 
698 /*
699  * Various extra files (binary)
700  * These files are rarely portable between platforms
701  */
702 cptr ANGBAND_DIR_XTRA;
703 
704 
705 /* Can these inventory hacks be cleaned up somehow? */
706 
707 /*
708  * Total Hack -- allow all items to be listed (even empty ones)
709  * This is only used by "do_cmd_inven_e()" and is cleared there.
710  */
711 bool item_tester_full;
712 
713 
714 /*
715  * Here is a "pseudo-hook" used during calls to "get_item()" and
716  * "show_inven()" and "show_equip()", and the choice window routines.
717  */
718 byte item_tester_tval;
719 
720 
721 /*
722  * Here is a "hook" used during calls to "get_item()" and
723  * "show_inven()" and "show_equip()", and the choice window routines.
724  */
725 bool (*item_tester_hook) (const object_type *);
726 
727 
728 /*
729  * Current "comp" function for ang_sort()
730  */
731 bool (*ang_sort_comp) (const vptr u, const vptr v, int a, int b);
732 
733 
734 /*
735  * Current "swap" function for ang_sort()
736  */
737 void (*ang_sort_swap) (const vptr u, const vptr v, int a, int b);
738 
739 
740 /*
741  * Default spell color table (quark index)
742  */
743 cptr gf_color[MAX_GF];
744 
745 
746 /*
747  * Store owner table sizes
748  */
749 int owner_names_max;
750 int owner_suffix_max;
751 
752 /* Get rid of this? */
753 
754 /*
755  * Flags for initialization
756  */
757 int init_flags;
758 
759