Repository navigation
Expand file tree
/
Copy pathtypes.h
More file actions
1103 lines (972 loc) · 35 KB
/
Copy pathtypes.h
File metadata and controls
1103 lines (972 loc) · 35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Rog-O-Matic
* Automatically exploring the dungeons of doom.
*
* Copyright (C) 2008 by Anthony Molinaro
* Copyright (C) 1985 by Appel, Jacobson, Hamey, and Mauldin.
*
* This file is part of Rog-O-Matic.
*
* Rog-O-Matic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Rog-O-Matic is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Rog-O-Matic. If not, see <http://www.gnu.org/licenses/>.
*/
#if !defined(INCLUDE_TYPES_H)
# define INCLUDE_TYPES_H
/*
* types.h:
*
* Miscellaneous Macros and Constants
*/
/*
* We need booleans, however the ANSI C committee, in their very finite wisdom,
* has decided to deprecate <stdbool.h>. So for those older compiler environments
* that still need <stdbool.h> because the bool type we need <stdbool.h>.
*
* For future environments where they may have removed <stdbool.h> because ANSI C
* deprecated it, we cannot simply expect to include it.
*
* The ANSI C committee needs to retire and leave the C language alone.
*
* Because we need the bool type in the external function declarations below we
* must include the contents of what might have been put into "bool.h", below.
*/
/*
* standard truth :-) for pre-c23 environments without <stdbool.h>
*/
# if _STDC_VERSION__ < 202311L
/* Avoid defines that could interfere with our ability to form a bool enum */
# if defined(true)
# undef true
# endif
# if defined(false)
# undef false
# endif
# if defined(bool)
# undef bool
# endif
/* make up for the lack of a <stdbool.h> and pre-c23 bool type */
typedef enum { false = 0, true = 1 } bool;
# endif
/*
* backward compatibility
*
* Not all compilers support __attribute__ nor do they suuport __has_builtin.
* For example, MSVC, TenDRAm and Little C Compiler doesn't support __attribute__.
* Early gcc does not support __attribute__.
*
* Not all compilers have __has_builtin
*/
# if !defined(__attribute__) && (defined(__cplusplus) || !defined(__GNUC__) || __GNUC__ == 2 && __GNUC_MINOR__ < 8)
# define __attribute__(A)
# endif
# if !defined __has_builtin
# define __has_builtin(x) 0
# endif
/*
* not_reached
*
* In the old days of lint, one could give lint and friends a hint by
* placing the token NOTREACHED immediately between opening and closing
* comments. Modern compilers do not honor such commented tokens
* and instead rely on features such as __builtin_unreachable
* and __attribute__((noreturn)).
*
* The not_reached will either yield a __builtin_unreachable() feature call,
* or it will call abort from stdlib.
*/
# if __has_builtin(__builtin_unreachable)
# define not_reached() __builtin_unreachable()
# else
# define not_reached() abort()
# endif
/* Critical buffer sizes */
/* BIGBUF - 2K (2048) is a good size */
# define BIGBUF 2048
/* SM_BUF MUST be smaller than BIGBUF - 1/2 BUFSIZ (1024) is a good size */
# define SM_BUF (BIGBUF / 2)
/* TY_BUF MUST be smaller than SM_BUF - 1/2 SM_BUF (512) is a good size */
# define TY_BUF (SM_BUF / 2)
/* MU_BUF MUST be smaller than TY_BUF - 1/2 SM_BUF (256) is a good size */
# define MU_BUF (TY_BUF / 2)
/* R is the number of characters rows in a 24x80 character rogue screen */
# define R (24)
/* C is the character length of row in a 24x80 character rogue screen */
# define C (80)
/* R_C is the linear (1D) length of character rogue screen */
# define R_C ((R) * (C))
/* Z is the number of monsters "A to Z" in a rogue game */
# define Z (26)
/* rogue as a 3x3 grin of possible rooms on each level */
# define RGRID (9)
/* rogue can move in one of 8 possible direction - MUST BE A POWER OF TWO */
# define DNUM (8)
/* mask a value into a valid direction */
# define DMASK ((DNUM) - 1)
/* Global Preprocessor constants */
# define ILL ";'"
# define MAXATTEMPTS (10)
# define ROGQUIT (-2)
# define DIED (1)
# define FINISHED (0)
# define SAVED (2)
# define MAXINV (26)
# define NONE (-1)
# define MAXSTUFF (100)
# define MAXMONST (40)
# define SAVEARROWS (30)
# define NAMSIZ (64)
# define MAXLEV (30)
# define MAXMON (128)
# define SUCCESS (1)
# define FAILURE (0)
/*
* Magic numbers for Invisible stalker strategies
*/
# define INVDAM (16)
# define INVHIT (1000)
# define INVPRES (INVHIT - 100)
# define INVLURK (INVPRES - 200)
/*
* Attribute bits for the screen map: If you change this list, be sure
* to change the flag names at the end of debug.c. MLM
*/
# define SCRMINIT (00000000000)
# define BEEN (00000000001)
# define CANGO (00000000002)
# define DOOR (00000000004)
# define HALL (00000000010)
# define PSD (00000000020)
# define ROOM (00000000040)
# define SAFE (00000000100)
# define SEEN (00000000200)
# define SEENPOS (7)
# define DEADEND (00000000400)
# define STUFF (00000001000)
# define TRAP (00000002000)
# define ARROW (00000004000)
# define TRAPDOR (00000010000)
# define TELTRAP (00000020000)
# define GASTRAP (00000040000)
# define BEARTRP (00000100000)
# define DARTRAP (00000200000)
# define WATERAP (00000400000)
# define MONSTER (00001000000)
# define WALL (00002000000)
# define USELESS (00004000000)
# define SCAREM (00010000000)
# define STAIRS (00020000000)
# define RUNOK (00040000000)
# define BOUNDARY (00100000000)
# define SLEEPER (00200000000)
# define EVERCLR (00400000000)
# define CHOKE (01000000000)
# define TOPW (0)
# define BOTW (1)
# define LEFTW (2)
# define RIGHTW (3)
# define NOTW (-1)
# define DOORW (-2)
# define CORNERW (-3)
# define ROGINFINITY (10000)
# define NOTAMOVE (-1)
# define FORCE (1)
# define OPTIONAL (0)
# define NEAR (0)
# define HERE (1)
# define NOPRINT (0)
# define DOPRINT (1)
# define NOTRUNNING (0)
# define RUNNING (1)
# define ANY (0)
# define RUSTPROOF (1)
/* Types of moves planned by makemove */
# define REUSE (0)
# define REEVAL (1)
# define EXPLORE (1)
# define EXPLORERUN (2)
# define RUNTODOOR (3)
# define RUNAWAY (4)
# define SECRETDOOR (5)
# define FINDSAFE (6)
# define GOTOMOVE (7)
# define ATTACKSLEEP (8)
# define ARCHERYMOVE (9)
# define UNPIN (10)
# define UNPINEXP (11)
# define EXPLOREROOM (12)
# define FINDROOM (13)
# define RESTMOVE (14)
# define DOWNMOVE (15)
# define RUNDOWN (16)
# define NUMMOVES (17)
/* Version numbers */
# define RV36A (361) /* OLDROG: Rogue 3.6 w/o wands */
# define RV36B (362) /* CURROG: Rogue 3.6 with wands */
# define RV52A (521) /* NEWROG: Rogue 5.2 */
# define RV52B (522) /* Rogue 5.2 with maze rooms */
# define RV53A (531) /* Rogue 5.3 new monsters */
# define RV54A (544) /* Rogue 5.4.4 mystery trap */
# define RV54B (545) /* Rogue 5.4.5 - Rogue 5.4.4 with lots of bug fixes */
# define supported_rogue() (version >= RV54B)
# define modern_rogue() (version >= RV52A)
/* Ways to spend time */
# define T_OTHER (0)
# define T_HANDLING (1)
# define T_FIGHTING (2)
# define T_RESTING (3)
# define T_MOVING (4)
# define T_EXPLORING (5)
# define T_RUNNING (6)
# define T_GROPING (7)
# define T_SEARCHING (8)
# define T_DOORSRCH (9)
# define T_LISTLEN (10)
/* Bit value for debugging types (for debugging function dwait and
screen message debugging). If D_MESSAGE is set the screen must
be at least 31x80 information displayed to fit. */
# define D_FATAL (00001)
# define D_ERROR (00002)
# define D_WARNING (00004)
# define D_INFORM (00010)
# define D_SEARCH (00020)
# define D_BATTLE (00040)
# define D_MESSAGE (00100)
# define D_PACK (00200)
# define D_CONTROL (00400)
# define D_SCREEN (01000)
# define D_MONSTER (02000)
# define D_SAY (04000)
# define D_ALL (01777)
# define D_NORMAL (D_FATAL | D_ERROR)
# define debugon(mask) (debugging |= (mask))
# define debugoff(mask) (debugging &= (~(mask)))
# define debug(mask) (debugging & (mask))
/* Parameters for genetic learning, knobs */
# define K_SRCH (0)
# define K_DOOR (1)
# define K_REST (2)
# define K_ARCH (3)
# define K_EXPER (4)
# define K_RUN (5)
# define K_WAKE (6)
# define K_FOOD (7)
# define MAXKNOB (8)
/* Monster attributes */
# define AWAKE (1)
# define ASLEEP (2)
# define ALL (9)
# define HELD (10)
/* Constants for handling inventory */
# define UNKNOWN -99
/* Pack item attributes DR UTexas 25 Jan 84 */
# define KNOWN (0000000001)
# define CURSED (0000000002)
# define ENCHANTED (0000000004)
# define PROTECTED (0000000010)
# define UNCURSED (0000000020)
# define INUSE (0000000040)
# define WORTHLESS (0000000100)
/* Miscellaneous macros */
# define LETTER(i) ((char)((i) + 'a'))
# define DIGIT(c) ((int)((c) - 'a'))
# define OBJECT(c) DIGIT(c)
# define ISDIGIT(c) ((c) >= '0' && (c) <= '9')
# define plural(n) ((n) == 1 ? "" : "s")
# define ordinal(n) \
((((n) / 10) % 10 == 1) ? "th" : ((n) % 10 == 1) ? "st" : ((n) % 10 == 2) ? "nd" : ((n) % 10 == 3) ? "rd" : "th")
# define ctrl(c) ((c) & 037)
# define ESC ctrl('[')
# define NEWLINE ctrl('J')
# define abs(a) ((a) >= 0 ? (a) : -(a))
# define max(a, b) (((a) > (b)) ? (a) : (b))
# define min(a, b) (((a) < (b)) ? (a) : (b))
# define between(v, a, b) ((v) < (a) ? (a) : (v) > (b) ? (b) : (v))
# define percent(v, p) (((v) * (p)) / 100)
# define SKIPARG \
while (*++(*argv)) \
; \
--(*argv)
# define SKIPDIG(s) \
while (ISDIGIT(*(s))) \
(s)++
# define SKIPCHAR(c, s) \
while (*(s) == (c)) \
(s)++
# define SKIPTO(c, s) \
{ \
while (*(s) && *(s) != (c)) \
(s)++; \
if (*(s) == (c)) \
(s)++; \
}
/*
* Dungeon level related macros
*/
/* deep level - historically level 18 was considered deep for some rogomatic reason */
# define LVL_DEEP (18)
/* first level that can have an Amulet of Yendor - historically defined by rogue */
# define LVL_AMULET (26)
/*
* rogomatic game log
*/
# define GAMELOG_FILENAME "gamelog" /* basename of rogomatic game log */
/*
* Utility Macros
*/
/*
* valrc (r,c) - test of r and c are a valid row and column location - no ERROR
*
* The row r, must be in 1/2 open interval: [0, R)
* The column c, must be in 1/2 open interval: [0, C)
*
* For a valid r and c location:
* true
*
* else:
* false
*/
# define valrc(r, c) (((r) >= 0) && ((r) < R) && ((c) >= 0) && ((c) < C))
/*
* valr_c (r_c) - test of r_c are a valid linear (1D) screen location - no ERROR
*
* The linear r_c, must be in 1/2 open interval: [0, R_C)
*
* For a valid r_c location:
* true
*
* else:
* false
*/
# define valr_c(r_c) (((r_c) >= 0) && ((r_c) < R_C))
/*
* onrc (attribute,r,c) - test if a screen map location has certain attribute bit(s) set
*
* For a valid r and c location:
* screen map at a given location, scrmap[r][c], masked with attribute
*
* else:
* quit with ERROR message
*/
# define onrc(attribute, r, c) \
(valrc((r), (c)) ? ((attribute) & scrmap[(r)][(c)]) \
: (quit(1, "ERROR: %s: dungeon: %u file: %s line: %d onrc(0x%x,%d,%d) out of range\n", __func__, dnum, \
__FILE__, __LINE__, (attribute), (r), (c)), \
not_reached(), 0))
/*
* if_onrc (attribute,r,c) - test if a screen map location has certain attribute bit(s) set - no ERROR
*
* For a valid r and c location:
* screen map at a given location, scrmap[r][c], masked with attribute
*
* else:
* 0
*/
# define if_onrc(attribute, r, c) (valrc((r), (c)) ? ((attribute) & scrmap[(r)][(c)]) : 0)
/*
* on (attribute) - test if current screen map location has certain attribute bit(s) set
*
* For a valid current position:
* current screen map location, scrmap[atlow][atcol], masked with attribute
*
* else:
* quit with ERROR message
*/
# define on(attribute) \
(valrc((atrow), (atcol)) ? ((attribute) & scrmap[(atrow)][(atcol)]) \
: (quit(1, "ERROR: %s: dungeon: %u file: %s line: %d on(0x%x) at (%d,%d) out of range\n", \
__func__, dnum, __FILE__, __LINE__, (attribute), (atrow), (atcol)), \
not_reached(), 0))
/*
* if_on (attribute) - test if current screen map location has certain attribute bit(s) set - no ERROR
*
* For a valid current position:
* current screen map location, scrmap[atlow][atcol], masked with attribute
*
* else:
* 0
*/
# define if_on(attribute) (valrc((atrow), (atcol)) ? ((attribute) & scrmap[(atrow)][(atcol)]) : 0)
/*
* seerc (character,r,c) - test if a given screen location is a given character
*
* For a valid r and c location:
* test if a given character is at a given screen[r][c] location
*
* else:
* quit with ERROR message
*/
# define seerc(character, r, c) \
(valrc((r), (c)) ? ((character) == screen[(r)][(c)]) \
: (quit(1, "ERROR: %s: dungeon: %u file: %s line: %d seerc('%c',%d,%d) out of range\n", __func__, dnum, \
__FILE__, __LINE__, (character), (r), (c)), \
not_reached(), false))
/*
* if_seerc (character,r,c) - test if a given screen location is a given character - no ERROR
*
* For a valid r and c location:
* test if a given character is at a given screen[r][c] location
*
* else:
* false
*/
# define if_seerc(character, r, c) (valrc((r), (c)) ? ((character) == screen[(r)][(c)]) : false)
/*
* see (character) - test if the current screen location is a given character
*
* For a valid r and c location:
* test if a given character is at the current screen[atrow][atcol] position
*
* else:
* quit with ERROR message
*/
# define see(character) \
(valrc((atrow), (atcol)) ? ((character) == screen[(atrow)][(atcol)]) \
: (quit(1, "ERROR: %s: dungeon: %u file: %s line: %d see('%c') at (%d,%d) out of range\n", \
__func__, dnum, __FILE__, __LINE__, (character), (atrow), (atcol)), \
not_reached(), false))
/*
* if_see (character) - test if the current screen location is a given character - no ERROR
*
* For a valid r and c location:
* test if a given character is at the current screen[atrow][atcol] position
*
* else:
* false
*/
# define if_see(character) (valrc((atrow), (atcol)) ? ((character) == screen[(atrow)][(atcol)]) : false)
/*
* setrc (attribute,r,c) - set attribute bit(s) at a given screen map location
*
* For a valid r and c location:
* set attribute bit(s) at a given screen map location, scrmap[r][c]
*
* else:
* quit with ERROR message
*/
# define setrc(attribute, r, c) \
(valrc((r), (c)) ? (scrmap[r][c] |= (attribute)) \
: (quit(1, "ERROR: %s: dungeon: %u file: %s line: %d seerc(0x%x,%d,%d) out of range\n", __func__, dnum, \
__FILE__, __LINE__, (attribute), (r), (c)), \
not_reached(), 0))
/*
* if_setrc (attribute,r,c) - set attribute bit(s) at a given screen map location - no ERROR
*
* For a valid r and c location:
* set attribute bit(s) at a given screen map location, scrmap[r][c]
*
* else:
* 0
*/
# define if_setrc(attribute, r, c) (valrc((atrow), (atcol)) ? (scrmap[atrow][atcol] |= (attribute)) : 0)
/*
* set (attribute) - set attribute bit(s) at the current screen map location
*
* For a valid r and c location:
* set attribute bit(s) at the current screen map location, scrmap[atlow][atcol]
*
* else:
* quit with ERROR message
*/
# define set(attribute) \
(valrc((atrow), (atcol)) ? (scrmap[atrow][atcol] |= (attribute)) \
: (quit(1, "ERROR: %s: dungeon: %u file: %s line: %d set(0x%x) at (%d,%d) out of range\n", \
__func__, dnum, __FILE__, __LINE__, (attribute), (atrow), (atcol)), \
not_reached(), 0))
/*
* if_set (attribute) - set attribute bit(s) at the current screen map location - no ERROR
*
* For a valid r and c location:
* set attribute bit(s) at the current screen map location, scrmap[atlow][atcol]
*
* else:
* 0
*/
# define if_set(attribute) (valrc((atrow), (atcol)) ? (scrmap[atrow][atcol] |= (attribute)) : 0)
/*
* unsetrc (attribute,r,c) - clear attribute bit(s) at a given screen map location
*
* For a valid r and c location:
* clear attribute bit(s) at a given screen map location, scrmap[r][c]
*
* else:
* quit with ERROR message
*/
# define unsetrc(attribute, r, c) \
(valrc((r), (c)) ? (scrmap[(r)][(c)] &= ~(attribute)) \
: (quit(1, "ERROR: %s: dungeon: %u file: %s line: %d unsetrc(0x%x,%d,%d) out of range\n", __func__, dnum, \
__FILE__, __LINE__, (attribute), (r), (c)), \
not_reached(), 0))
/*
* if_unsetrc (attribute,r,c) - clear attribute bit(s) at a given screen map location - no ERROR
*
* For a valid r and c location:
* clear attribute bit(s) at a given screen map location, scrmap[r][c]
*
* else:
* 0
*/
# define if_unsetrc(attribute, r, c) (valrc((r), (c)) ? (scrmap[(r)][(c)] &= ~(attribute)) : 0)
/*
* unset (attribute) - clear attribute bit(s) at the current screen map location
*
* For a valid r and c location:
* clear attribute bit(s) at the current screen map location, scrmap[r][c]
*
* else:
* quit with ERROR message
*/
# define unset(attribute) \
(valrc((atrow), (atcol)) ? (scrmap[(atrow)][(atcol)] &= ~(attribute)) \
: (quit(1, "ERROR: %s: dungeon: %u file: %s line: %d unsetrc(0x%x) at (%d,%d) out of range\n", \
__func__, dnum, __FILE__, __LINE__, (attribute), (atrow), (atcol)), \
not_reached(), 0))
/*
* if_unset (attribute) - clear attribute bit(s) at the current screen map location - no ERROR
*
* For a valid r and c location:
* clear attribute bit(s) at the current screen map location, scrmap[r][c]
*
* else:
* 0
*/
# define if_unset(attribute) (valrc((atrow), (atcol)) ? (scrmap[(atrow)][(atcol)] &= ~(attribute)) : 0)
/*
* direc (r,c) - give the vector from an xy difference - no ERROR
*/
# define direc(r, c) (r > 0 ? (c > 0 ? 7 : (c < 0 ? 5 : 6)) : (r < 0 ? (c > 0 ? 1 : (c < 0 ? 3 : 2)) : (c > 0 ? 0 : 4)))
/*
* valdir (dir) - test if direction is valid - no ERROR
*
* The direction, dir, must be in 1/2 open interval: [0, DNUM)
*
* For a valid direction:
* true
*
* else:
* false
*/
# define valdir(dir) (((dir) >= 0) && ((dir) < DNUM))
/*
* dirmask(dir) - mask a value down to a valid direction
*
* NOTE: The DNUM value MUST be a power, so that DMASK (DNUM-1) is a bitmask.
*/
# define dirmask(dir) ((dir) & DMASK)
/*
* atdrow (dir) - row number adjacent to the current location in a given direction
*
* For a valid direction:
* row number adjacent to the current location in a given direction
*
* else:
* quit with ERROR message
*/
# define atdrow(dir) \
(valdir((dir)) ? (atrow + deltr[(dir)]) \
: (quit(1, "ERROR: %s: dungeon: %u file: %s line: %d atdrow(%d) out of range\n", __func__, dnum, __FILE__, \
__LINE__, (dir)), \
not_reached(), 0))
/*
* is_atdrow (dir) - row number adjacent to the current location in a given direction - no ERROR
*
* For a valid direction:
* row number adjacent to the current location in a given direction
*
* else:
* 0
*/
# define if_atdrow(dir) (valdir((dir)) ? (atrow + deltr[(dir)]) : 0)
/*
* atdcol (dir) - column number adjacent to the current location in a given direction
*
* For a valid direction:
* column number adjacent to the current location in a given direction
*
* else:
* quit with ERROR message
*/
# define atdcol(dir) \
(valdir((dir)) ? (atcol + deltc[(dir)]) \
: (quit(1, "ERROR: %s: dungeon: %u file: %s line: %d atdcol(%d) out of range\n", __func__, dnum, __FILE__, \
__LINE__, (dir)), \
not_reached(), 0))
/*
* if_atdcol (dir) - column number adjacent to the current location in a given direction - no ERROR
*
* For a valid direction:
* column number adjacent to the current location in a given direction
*
* else:
* 0
*/
# define if_atdcol(dir) (valdir((dir)) ? (atcol + deltc[(dir)]) : 0)
/* Define a more mnemonic string comparison */
# define streq(s1, s2) (strcmp((s1), (s2)) == 0)
/* Monster value macros */
# define maxhitchar(m) (((((m) - 'A') >= 0) && (((m) - 'A') < Z)) ? (cosmic ? Level * 3 / 2 + 6 : monatt[(m) - 'A'].maxdam) : 0)
# define avghitchar(m) (((((m) - 'A') >= 0) && (((m) - 'A') < Z)) ? (cosmic ? Level * 2 / 3 + 4 : monatt[(m) - 'A'].expdam) : 0)
# define maxhit(m) ((((m) >= 0) && ((m) < MAXMONST)) ? (maxhitchar(mlist[(m)].chr)) : 0)
# define avghit(m) ((((m) >= 0) && ((m) < MAXMONST)) ? (avghitchar(mlist[(m)].chr)) : 0) /* times 10 */
/* Item knowledge macros DR UTexas 25 Jan 84 */
/* itemis - test pack item for traits */
# define itemis(obj, trait) ((((obj) >= 0) && ((obj) < MAXINV)) ? ((trait) & inven[(obj)].traits) : 0)
/* remember - set traits for pack item */
# define remember(obj, trait) ((((obj) >= 0) && ((obj) < MAXINV)) ? (inven[(obj)].traits |= (trait)) : 0)
/* forget - clear traits for pack item */
# define forget(obj, trait) ((((obj) >= 0) && ((obj) < MAXINV)) ? (inven[(obj)].traits &= ~(trait)) : 0)
/* The types of objects */
typedef enum { strange, food, potion, Scroll, wand, ring, hitter, thrower, missile, armor, amulet, gold, none } stuff;
typedef struct {
int fail, win;
} probability;
typedef struct {
int count;
double sum, sumsq, low, high;
} statistic;
typedef struct {
int scol, srow;
stuff what;
} stuffrec;
typedef struct {
int mcol, mrow;
char chr;
int q;
} monrec;
typedef struct {
int expdam, maxdam, mtokill;
} attrec;
typedef struct {
int gamecnt, gamesum, inittime, timeswritten;
} lrnrec;
typedef struct {
char m_name[NAMSIZ + 1]; /* +1 for paranoia */
probability wehit, theyhit, arrowhit;
statistic htokill, damage, atokill;
} ltmrec;
typedef struct {
stuff type;
int count, phit, pdam, charges, traits;
char *str;
} invrec;
typedef struct {
int activity[T_LISTLEN + 1]; /* +1 for paranoia */
int timestamp;
} timerec;
extern char *knob_name[MAXKNOB];
/*
* global function declarations
*/
/* arms.c */
extern int havearmor(int k, int print, int rustproof);
extern int armorclass(int i);
extern int haveweapon(int k, int print);
extern int weaponclass(int i);
extern int havering(int k, int print);
extern int ringclass(int i);
extern int havebow(int k, int print);
extern int bowclass(int i);
extern int havemissile(void);
extern int havearrow(void);
extern void setbonuses(void);
/* command.c */
extern void move1(int d);
extern void fmove(int d);
extern void rmove(int count, int d, int mode);
extern void mmove(int d, int mode);
extern void command(int tmode, char *f, ...) __attribute__((format(printf, 2, 3)));
extern char functionchar(char *cmd);
extern int replaycommand(void);
extern void showcommand(char *cmd);
/* config.c */
extern void set_rgmdir(bool time_subpath);
extern const char *getLockFile(void);
/* database.c */
extern int findentry(char *string);
extern char *findentry_getfakename(char *string, stuff item_type);
extern char *findentry_getrealname(char *string, stuff item_type);
extern void addobj(char *codename, int pack_index, stuff item_type);
extern void useobj(char *string);
extern void infername(char *codename, char *name, stuff item_type);
extern int used(char *codename);
extern int know(char *name);
extern void dumpdatabase(void);
/* debug.c */
extern int dwait(int msgtype, const char *from, char *f, ...) __attribute__((format(printf, 3, 4)));
extern void promptforflags(void);
extern void timehistory(FILE *f, char sep);
extern void toggledebug(void);
/* debuglog.c */
extern void debuglog_open(const char *dir, const char *log);
extern void debuglog_close(void);
extern void debuglog(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
extern void append_pidlog(const char *dir, const char *file);
extern void levellog_create(void);
extern void levellog_append(char *reason);
/* explore.c */
extern int genericinit(void);
extern int gotowards(int r, int c, int running);
extern int sleepvalue(int r, int c, int depth __attribute__((__unused__)), int *val, int *avd,
int *cont __attribute__((__unused__)));
extern int setpsd(int print);
extern int downvalue(int r, int c, int depth __attribute__((__unused__)), int *val, int *avd,
int *cont __attribute__((__unused__)));
extern int expruninit(void);
extern int exprunvalue(int r, int c, int depth, int *val, int *avd, int *cont);
extern int expunpininit(void);
extern int expunpinvalue(int r, int c, int depth, int *val, int *avd, int *cont);
extern int runinit(void);
extern int runvalue(int r, int c, int depth, int *val, int *avd, int *cont);
extern int unpininit(void);
extern int rundoorinit(void);
extern int rundoorvalue(int r, int c, int depth, int *val, int *avd, int *cont);
extern int secret(void);
extern int findroom(void);
extern int exploreroom(void);
extern int doorexplore(void);
extern int findsafe(void);
extern int archmonster(int m, int trns);
extern void unrest(void);
extern int movetorest(void);
/* findscore.c */
extern int findscore(char *rogue, char *roguename);
/* fork_exec.c */
extern int fork_exec(char *file, char *arglist[]);
/* getroguetoken.c */
extern int rogue_log_open(const char *filename);
extern void rogue_log_close(void);
extern void rogue_log_write_command(char c);
extern bool is_token(char ch);
extern void open_frogue_debuglog(const char *dir, const char *file);
extern void close_frogue_debuglog(void);
extern void open_frogue_fd(int frogue_fd);
extern char getroguetoken(void);
extern void getoldcommand(char *s);
extern void redirect_stderr(const char *dir, const char *file);
extern void close_errlog(void);
/* io.c */
extern void getrogue(char *waitstr, int onat);
extern void terpbot(void);
extern void dumpwalls(void);
extern void sendnow(char *f, ...) __attribute__((format(printf, 1, 2)));
extern void rogo_send(char *f, ...) __attribute__((format(printf, 1, 2)));
extern int resend(void);
extern void at(int r, int c);
extern void quitrogue(char *reason, int gld, int terminationtype);
extern void waitfor(char *mess);
extern void say(char *f, ...) __attribute__((format(printf, 1, 2)));
extern void saynow(char *f, ...) __attribute__((format(printf, 1, 2)));
extern void givehelp(void);
extern void pauserogue(void);
extern void getrogver(void);
extern int charsavail(void);
extern void redrawscreen(void);
extern void toggleecho(void);
extern void clearsendqueue(void);
extern void startreplay(FILE **logf, char *logfname);
extern void printsnap(FILE *f);
extern void dosnapshot(void);
extern void clearscreen(void);
extern char *statusline(void);
/* learn.c */
extern void initpool(int k, int m);
extern void analyzepool(int full);
extern void setknobs(int *newid, int *knb, int *best, int *avg);
extern void evalknobs(int gid, int score, int level);
extern FILE *rogo_openlog(char *genelog);
extern void rogo_closelog(void);
extern int readgenes(char *genepool);
extern void writegenes(char *genepool);
/* ltm.c */
extern void mapcharacter(char ch, char *str);
extern int addmonhist(char *monster);
extern int findmonster(char *monster);
extern void saveltm(int score);
extern void restoreltm(void);
extern void dumpmonstertable(void);
extern void analyzeltm(void);
/* mess.c */
extern void terpmes(void);
extern void infer(char *objname, stuff item_type);
extern void killed(char *monster);
extern void summary(FILE *f, char sep);
extern void versiondep(void);
/* monsters.c */
extern char *monname(char m);
extern void addmonster(char ch, int r, int c, int quiescence);
extern void deletemonster(int r, int c);
extern void dumpmonster(void);
extern void sleepmonster(void);
extern void holdmonsters(void);
extern void wakemonster(int dir);
extern int seemonster(char *monster);
extern int seeawakemonster(char *monster);
extern int monsternum(char *monster);
extern void newmonsterlevel(void);
extern int isholder(char *monster);
/* pack.c */
extern char *itemstr(int i);
extern void dumpinv(FILE *f);
extern void removeinv(int pos);
extern void deleteinv(int pos);
extern void resetinv(void);
extern void doresetinv(void);
extern int inventory(char *msgstart, char *msgend);
/* rand.c */
extern void rogo_srand(unsigned int seed);
extern int rogo_rand(void);
extern int rogo_randint(int beyond);
/* replay.c */
extern void positionreplay(void);
/* rooms.c */
extern void newlevel(void);
extern void markmissingrooms(void);
extern int whichroom(int r, int c);
extern void nametrap(int traptype, int standingonit);
extern void findstairs(int notr, int notc);
extern int downright(int *drow, int *dcol);
extern int lightroom(void);
extern int darkroom(void);
extern void currentrectangle(void);
extern void updateat(void);
extern void updatepos(char ch, int row, int col);
extern void mapinfer(void);
extern void markexplored(int row, int col);
extern int isexplored(int row, int col);
extern int haveexplored(int n);
extern void printexplored(void);
extern void inferhall(int r, int c);
extern bool canbedoor(int deadr, int deadc);
extern int mazedoor(int row, int col);
extern int nextto(int type, int r, int c);
extern int nexttowall(int r, int c);
extern void dumpmazedoor(void);
extern void foundnew(void);
/* search.c */
extern int makemove(int movetype, int (*evalinit)(void), int (*evaluate)(int, int, int, int *, int *, int *), int reevaluate);
extern int findmove(int movetype, int (*evalinit)(void), int (*evaluate)(int, int, int, int *, int *, int *), int reevaluate);
extern int followmap(int movetype);
extern void cancelmove(int movetype);
extern void setnewgoal(void);
/* scorefile.c */
extern void add_score(char *new_line, char *vers, int ntrm);
extern void dumpscore(char *vers);
/* strategy.c */
extern int strategize(void);
/* stats.c */
extern void clearprob(probability *p);
extern void addprob(probability *p, int success);
extern double prob(probability *p);
extern void parseprob(char *buf, probability *p);
extern void writeprob(FILE *f, probability *p);
extern void clearstat(statistic *s);
extern void addstat(statistic *s, int datum);
extern double mean(statistic *s);
extern double stdev(statistic *s);
extern void parsestat(char *buf, statistic *s);
extern void writestat(FILE *f, statistic *s);
/* survival.c */