-
Notifications
You must be signed in to change notification settings - Fork 635
Expand file tree
/
Copy pathbotl.c
More file actions
4586 lines (4155 loc) · 156 KB
/
Copy pathbotl.c
File metadata and controls
4586 lines (4155 loc) · 156 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
/* NetHack 5.0 botl.c $NHDT-Date: 1781973042 2026/06/20 16:30:42 $ $NHDT-Branch: NetHack-5.0 $:$NHDT-Revision: 1.286 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Michael Allison, 2006. */
/* NetHack may be freely redistributed. See license for details. */
#include "hack.h"
extern const char *const hu_stat[]; /* defined in eat.c */
/* also used in insight.c */
const char *const enc_stat[] = {
"", "Burdened", "Stressed",
"Strained", "Overtaxed", "Overloaded"
};
staticfn const char *rank(void);
staticfn void bot_via_windowport(void);
staticfn void stat_update_time(void);
char *
get_strength_str(void)
{
static char buf[32];
int st = ACURR(A_STR);
if (st > 18) {
if (st > STR18(100))
Sprintf(buf, "%2d", st - 100);
else if (st < STR18(100))
Sprintf(buf, "18/%02d", st - 18);
else
Sprintf(buf, "18/**");
} else
Sprintf(buf, "%-1d", st);
return buf;
}
void
check_gold_symbol(void)
{
nhsym goldch = gs.showsyms[COIN_CLASS + SYM_OFF_O];
iflags.invis_goldsym = (goldch <= (nhsym) ' ');
}
char *
do_statusline1(void)
{
static char newbot1[BUFSZ];
char *nb;
int i, j;
if (suppress_map_output())
return strcpy(newbot1, "");
Strcpy(newbot1, svp.plname);
if ('a' <= newbot1[0] && newbot1[0] <= 'z')
newbot1[0] += 'A' - 'a';
newbot1[BOTL_NSIZ] = 0;
Sprintf(nb = eos(newbot1), " the ");
if (Upolyd) {
char mbot[BUFSZ];
int k = 0;
Strcpy(mbot, pmname(&mons[u.umonnum], Ugender));
while (mbot[k] != 0) {
if ((k == 0 || (k > 0 && mbot[k - 1] == ' ')) && 'a' <= mbot[k]
&& mbot[k] <= 'z')
mbot[k] += 'A' - 'a';
k++;
}
Strcpy(nb = eos(nb), mbot);
} else {
Strcpy(nb = eos(nb), rank());
}
Sprintf(nb = eos(nb), " ");
i = gm.mrank_sz + 15;
j = (int) ((nb + 2) - newbot1); /* strlen(newbot1) but less computation */
if ((i - j) > 0)
Sprintf(nb = eos(nb), "%*s", i - j, " "); /* pad with spaces */
Sprintf(nb = eos(nb), "St:%s Dx:%-1d Co:%-1d In:%-1d Wi:%-1d Ch:%-1d",
get_strength_str(),
ACURR(A_DEX), ACURR(A_CON), ACURR(A_INT), ACURR(A_WIS),
ACURR(A_CHA));
Sprintf(nb = eos(nb), "%s",
(u.ualign.type == A_CHAOTIC) ? " Chaotic"
: (u.ualign.type == A_NEUTRAL) ? " Neutral"
: " Lawful");
#ifdef SCORE_ON_BOTL
if (flags.showscore)
Sprintf(nb = eos(nb), " S:%ld", botl_score());
#endif
return newbot1;
}
char *
do_statusline2(void)
{
static char newbot2[BUFSZ], /* MAXCO: botl.h */
/* dungeon location (and gold), hero health (HP, PW, AC),
experience (HD if poly'd, else Exp level and maybe Exp points),
time (in moves), varying number of status conditions */
dloc[QBUFSZ], hlth[QBUFSZ], expr[QBUFSZ],
tmmv[QBUFSZ], cond[QBUFSZ], vers[QBUFSZ];
char *nb;
size_t dln, dx, hln, xln, tln, cln, vrn;
int hp, hpmax, cap;
long money;
if (suppress_map_output())
return strcpy(newbot2, "");
/*
* Various min(x,9999)'s are to avoid having excessive values
* violate the field width assumptions in botl.h and should not
* impact normal play. Particularly 64-bit long for gold which
* could require many more digits if someone figures out a way
* to get and carry a really large (or negative) amount of it.
* Turn counter is also long, but we'll risk that.
*/
/* dungeon location plus gold */
(void) describe_level(dloc, 1); /* includes at least one trailing space */
if ((money = money_cnt(gi.invent)) < 0L)
money = 0L; /* ought to issue impossible() and then discard gold */
Sprintf(eos(dloc), "%s:%-2ld", /* strongest hero can lift ~300000 gold */
(iflags.in_dumplog || iflags.invis_goldsym) ? "$"
: encglyph(objnum_to_glyph(GOLD_PIECE)),
min(money, 999999L));
dln = strlen(dloc);
/* '$' encoded as \GXXXXNNNN is 9 chars longer than display will need */
dx = strstri(dloc, "\\G") ? 9 : 0;
/* health and armor class (has trailing space for AC 0..9) */
hp = Upolyd ? u.mh : u.uhp;
hpmax = Upolyd ? u.mhmax : u.uhpmax;
if (hp < 0)
hp = 0;
Sprintf(hlth, "HP:%d(%d) Pw:%d(%d) AC:%-2d",
min(hp, 9999), min(hpmax, 9999),
min(u.uen, 9999), min(u.uenmax, 9999), u.uac);
hln = strlen(hlth);
/* experience */
if (Upolyd)
Sprintf(expr, "HD:%d", mons[u.umonnum].mlevel);
else if (flags.showexp)
Sprintf(expr, "Xp:%d/%-1ld", u.ulevel, u.uexp);
else
Sprintf(expr, "Xp:%d", u.ulevel);
xln = strlen(expr);
/* time/move counter */
if (flags.time)
Sprintf(tmmv, "T:%ld", svm.moves);
else
tmmv[0] = '\0';
tln = strlen(tmmv);
/* status conditions; worst ones first */
cond[0] = '\0'; /* once non-empty, cond will have a leading space */
nb = cond;
/*
* Stoned, Slimed, Strangled, and both types of Sick are all fatal
* unless remedied before timeout expires. Should we order them by
* shortest time left? [Probably not worth the effort, since it's
* unusual for more than one of them to apply at a time.]
*/
if (Stoned)
Strcpy(nb = eos(nb), " Stone");
if (Slimed)
Strcpy(nb = eos(nb), " Slime");
if (Strangled)
Strcpy(nb = eos(nb), " Strngl");
if (Sick) {
if (u.usick_type & SICK_VOMITABLE)
Strcpy(nb = eos(nb), " FoodPois");
if (u.usick_type & SICK_NONVOMITABLE)
Strcpy(nb = eos(nb), " TermIll");
}
if (u.uhs != NOT_HUNGRY)
Sprintf(nb = eos(nb), " %s", hu_stat[u.uhs]);
if ((cap = near_capacity()) > UNENCUMBERED)
Sprintf(nb = eos(nb), " %s", enc_stat[cap]);
if (Blind)
Strcpy(nb = eos(nb), " Blind");
if (Deaf)
Strcpy(nb = eos(nb), " Deaf");
if (Stunned)
Strcpy(nb = eos(nb), " Stun");
if (Confusion)
Strcpy(nb = eos(nb), " Conf");
if (Hallucination)
Strcpy(nb = eos(nb), " Hallu");
/* levitation and flying are mutually exclusive; riding is not */
if (Levitation)
Strcpy(nb = eos(nb), " Lev");
if (Flying)
Strcpy(nb = eos(nb), " Fly");
if (u.usteed)
Strcpy(nb = eos(nb), " Ride");
cln = strlen(cond);
/* version on status line, with leading space */
if (flags.showvers)
(void) status_version(vers, sizeof vers, TRUE);
else
vers[0] = '\0';
vrn = strlen(vers);
/*
* Put the pieces together. If they all fit, keep the traditional
* sequence. Otherwise, move least important parts to the end in
* case the interface side of things has to truncate. Note that
* dloc[] contains '$' encoded in ten character sequence \GXXXXNNNN
* so we want to test its display length rather than buffer length.
*
* We don't have an actual display limit here, so have to go by the
* width of the map. Since we're reordering rather than truncating,
* wider displays can still show wider status than the map if the
* interface supports that.
*/
if ((dln - dx) + 1 + hln + 1 + xln + 1 + tln + 1 + cln + vrn <= COLNO) {
Snprintf(newbot2, sizeof newbot2, "%s %s %s %s %s%s", dloc, hlth,
expr, tmmv, cond, vers);
} else {
if (dln + 1 + hln + 1 + xln + 1 + tln + 1 + cln + vrn > MAXCO) {
panic("bot2: second status line exceeds MAXCO (%u > %d)",
(unsigned) (dln + 1 + hln + 1 + xln + 1 + tln + 1 + cln
+ vrn),
MAXCO);
} else if ((dln - dx) + 1 + hln + 1 + xln + 1 + cln <= COLNO) {
Snprintf(newbot2, sizeof newbot2, "%s %s %s %s %s%s", dloc, hlth,
expr, cond, tmmv, vers);
} else if ((dln - dx) + 1 + hln + 1 + cln <= COLNO) {
Snprintf(newbot2, sizeof newbot2, "%s %s %s %s %s%s", dloc, hlth,
cond, expr, tmmv, vers);
} else {
Snprintf(newbot2, sizeof newbot2, "%s %s %s %s %s%s", hlth, cond,
dloc, expr, tmmv, vers);
}
/* only two or three consecutive spaces available to squeeze out */
mungspaces(newbot2);
}
return newbot2;
}
void
bot(void)
{
if (gb.bot_disabled)
return;
/* dosave() flags completion by setting u.uhp to -1; suppress_map_output()
covers program_state.restoring and is used for status as well as map */
if (u.uhp != -1 && gy.youmonst.data
&& iflags.status_updates && !suppress_map_output()) {
if (VIA_WINDOWPORT()) {
bot_via_windowport();
} else {
curs(WIN_STATUS, 1, 0);
putstr(WIN_STATUS, 0, do_statusline1());
curs(WIN_STATUS, 1, 1);
putmixed(WIN_STATUS, 0, do_statusline2());
}
}
disp.botl = disp.botlx = disp.time_botl = FALSE;
}
/* special purpose status update: move counter ('time' status) only */
void
timebot(void)
{
if (gb.bot_disabled)
return;
/* we're called when disp.time_botl is set and general disp.botl
is clear; disp.time_botl gets set whenever svm.moves changes value
so there's no benefit in tracking previous value to decide whether
to skip update; suppress_map_output() handles program_state.restoring
and program_state.done_hup (tty hangup => no further output at all)
and we use it for maybe skipping status as well as for the map */
if (flags.time && iflags.status_updates && !suppress_map_output()) {
if (VIA_WINDOWPORT()) {
stat_update_time();
} else {
/* old status display updates everything */
bot();
}
}
disp.time_botl = FALSE;
}
/* convert experience level (1..30) to rank index (0..8) */
int
xlev_to_rank(int xlev)
{
/*
* 1..2 => 0
* 3..5 => 1
* 6..9 => 2
* 10..13 => 3
* ...
* 26..29 => 7
* 30 => 8
* Conversion is precise but only partially reversible.
*/
return (xlev <= 2) ? 0 : (xlev <= 30) ? ((xlev + 2) / 4) : 8;
}
/* convert rank index (0..8) to experience level (1..30) */
int
rank_to_xlev(int rank)
{
/*
* 0 => 1..2
* 1 => 3..5
* 2 => 6..9
* 3 => 10..13
* ...
* 7 => 26..29
* 8 => 30
* We return the low end of each range.
*/
return (rank < 1) ? 1 : (rank < 2) ? 3
: (rank < 8) ? ((rank * 4) - 2) : 30;
}
const char *
rank_of(int lev, short monnum, boolean female)
{
const struct Role *role;
int i;
/* Find the role */
for (role = roles; role->name.m; role++)
if (monnum == role->mnum)
break;
if (!role->name.m)
role = &gu.urole;
/* Find the rank */
for (i = xlev_to_rank((int) lev); i >= 0; i--) {
if (female && role->rank[i].f)
return role->rank[i].f;
if (role->rank[i].m)
return role->rank[i].m;
}
/* Try the role name, instead */
if (female && role->name.f)
return role->name.f;
else if (role->name.m)
return role->name.m;
return "Player";
}
staticfn const char *
rank(void)
{
return rank_of(u.ulevel, Role_switch, flags.female);
}
int
title_to_mon(
const char *str,
int *rank_indx,
int *title_length)
{
int i, j;
/* Loop through each of the roles */
for (i = 0; roles[i].name.m; i++) {
/* loop through each of the rank titles for role #i */
for (j = 0; j < 9; j++) {
if (roles[i].rank[j].m
&& str_start_is(str, roles[i].rank[j].m, TRUE)) {
if (rank_indx)
*rank_indx = j;
if (title_length)
*title_length = Strlen(roles[i].rank[j].m);
return roles[i].mnum;
}
if (roles[i].rank[j].f
&& str_start_is(str, roles[i].rank[j].f, TRUE)) {
if (rank_indx)
*rank_indx = j;
if (title_length)
*title_length = Strlen(roles[i].rank[j].f);
return roles[i].mnum;
}
}
}
if (title_length)
*title_length = 0;
return NON_PM;
}
void
max_rank_sz(void)
{
int i;
size_t r, maxr = 0;
for (i = 0; i < 9; i++) {
if (gu.urole.rank[i].m && (r = strlen(gu.urole.rank[i].m)) > maxr)
maxr = r;
if (gu.urole.rank[i].f && (r = strlen(gu.urole.rank[i].f)) > maxr)
maxr = r;
}
gm.mrank_sz = (int) maxr;
return;
}
#ifdef SCORE_ON_BOTL
long
botl_score(void)
{
long deepest = (long) deepest_lev_reached(FALSE);
long umoney, depthbonus;
/* hidden_gold(False): only gold in containers whose contents are known */
umoney = money_cnt(gi.invent) + hidden_gold(FALSE);
/* don't include initial gold; don't impose penalty if it's all gone */
if ((umoney -= u.umoney0) < 0L)
umoney = 0L;
depthbonus = (50L * (deepest - 1L))
+ ((deepest > 30L) ? 10000L
: (deepest > 20L) ? (1000L * (deepest - 20L))
: 0L);
/* neither umoney nor depthbonus can grow unusually big (gold due to
weight); u.urexp might */
return nowrap_add(u.urexp, umoney + depthbonus);
}
#endif /* SCORE_ON_BOTL */
/* provide the name of the current level for display by various ports */
int
describe_level(
char *buf, /* output buffer */
int dflgs) /* 1: append trailing space; 2: include dungeon branch name */
{
boolean addspace = (dflgs & 1) != 0, /* (used to be unconditional) */
addbranch = (dflgs & 2) != 0; /* False: status, True: livelog */
int ret = 1;
if (Is_knox(&u.uz)) {
Sprintf(buf, "%s", svd.dungeons[u.uz.dnum].dname);
addbranch = FALSE;
} else if (In_quest(&u.uz)) {
Sprintf(buf, "Home %d", dunlev(&u.uz));
} else if (In_endgame(&u.uz)) {
/* [3.6.2: this used to be "Astral Plane" or generic "End Game"] */
(void) endgamelevelname(buf, depth(&u.uz));
if (!addbranch)
(void) strsubst(buf, "Plane of ", ""); /* just keep <element> */
addbranch = FALSE;
} else {
/* ports with more room may expand this one */
if (!addbranch)
Sprintf(buf, "%s:%-2d", /* "Dlvl:n" (grep fodder) */
In_tutorial(&u.uz) ? "Tutorial" : "Dlvl", depth(&u.uz));
else
Sprintf(buf, "level %d", depth(&u.uz));
ret = 0;
}
if (addbranch) {
Sprintf(eos(buf), ", %s", svd.dungeons[u.uz.dnum].dname);
(void) strsubst(buf, "The ", "the ");
}
if (addspace)
Strcat(buf, " ");
return ret;
}
/* weapon description for status lines; started as a terser version of
what ^X shows but has diverged to some extent */
char *
weapon_status(char *outbuf)
{
const char *res = 0;
*outbuf = '\0'; /* lint suppression */
if (!uwep) {
/* no weapon; gloves imply hands; humanoid also implies hands;
otherwise make no assumptions */
res = uarmg ? "Empty-hnd" /* empty handed means "gloves only" */
: humanoid(gy.youmonst.data) ? "Bare-hnds" /* bare hands */
: "No-weapon";
} else if (u.twoweap) {
/* two-weaponing implies hands and a weapon or wep-tool
(not other odd stuff) in each hand */
res = "Dual-weps";
/* note: dual wielding two lances doesn't produce double joust */
if (u.usteed && (weapon_type(uwep) == P_LANCE
|| weapon_type(uswapwep) == P_LANCE))
res = "Dual+joust"; /* lance behaves specially when mounted */
} else {
/* report most weapons by their skill class (so a katana will be
described as a long sword, for instance; mattock and hook are
exceptions), or wielded non-weapon item by its object class */
char *p;
int skill = weapon_type(uwep);
if (u.usteed && skill == P_LANCE) {
/* lance behaves specially when hero is mounted */
res = "joust";
} else if (uwep->otyp == AKLYS) {
/* aklys behaves specially when thrown while wielded, so
give it a distinct name instead of skill name of "club";
[maybe FIXME?] for the time being
use real name even if 'obj' is undiscovered "thonged club" */
res = "aklys";
} else if (is_sword(uwep)) {
/* simplify short short/broad sword/long sword/two-handed sword
(similar to messages when dropped due to slippery fingers) */
res = "sword";
} else {
/* shorten several */
switch (skill) {
case P_QUARTERSTAFF:
res = "staff";
break;
case P_MORNING_STAR:
res = "mrng-star"; /* still pretty long */
break;
case P_POLEARMS:
res = "pole";
break;
case P_UNICORN_HORN:
res = "unihorn";
break;
default:
res = weapon_descr(uwep);
/* [should this be moved into weapon_descr()?] */
if (!strcmpi(res, "food") && uwep->otyp == CREAM_PIE)
res = "pie";
break;
}
}
if ((uwep->oclass == WEAPON_CLASS || is_weptool(uwep))
&& bimanual(uwep) && *res != '2' && strncmpi(res, "two", 3))
Strcat(outbuf, "2H-");
Strcpy(p = eos(outbuf), res), res = outbuf;
*p = highc(*p);
/* avoid embedded spaces since its designed to appear as part
of a space-separated status line */
(void) strNsubst(outbuf, " ", "-", 0);
}
return (outbuf == res) ? outbuf : strcpy(outbuf, res);
}
/* armor description for status lines */
char *
armor_status(char *armbuf)
{
int n = !!uarmg + !!uarmc + !!uarm + !!uarmu + !!uarmh + !!uarmf + !!uarms;
/*
* FIXME: ^X needs to provide non-abbreviated version of this info.
* At present it just reports the "no armor" case.
*/
if (n == 0) { /* no armor */
Strcpy(armbuf, "naked");
} else if (n == 1) { /* just one piece; spell it out */
Strcpy(armbuf, uarmg ? "gloves"
: uarmc ? "cloak"
: uarm ? "suit"
: uarmu ? "shirt"
: uarmh ? helm_simple_name(uarmh) /* hat|helm */
: uarmf ? "boots"
: uarms ? "shield"
: ""); /* not possible */
} else { /* more than one piece */
char *p = armbuf;
/* gloves first since this is expected to follow weapon_status();
cloak next since it tends to provide the most protection
aside from raw AC */
if (uarmg)
*p++ = 'G'; /* gloves */
if (uarmc)
*p++ = 'C'; /* cloak */
if (uarm)
*p++ = 'A'; /* suit but 's' is for shield */
if (uarmu)
*p++ = 'U'; /* underwear? => shirt */
if (uarmh)
*p++ = 'H'; /* hat/helm */
if (uarmf)
*p++ = 'B'; /* footwear => boots */
if (uarms)
*p++ = 'S'; /* shield */
*p = '\0';
}
/*
* Add a hint about MC by appending a plus sign if that's augmented.
* Bug: we should modfiy magical_negation() to return extra info and
* call it to scan whole inventory looking for sources of protection.
* This is a hack for efficiency to avoid that during status updates.
*/
if ((uright && uright->otyp == RIN_PROTECTION)
|| (uleft && uleft->otyp == RIN_PROTECTION)
|| (uamul && uamul->otyp == AMULET_OF_GUARDING)
|| (uarmc && uarmc->otyp == CLOAK_OF_PROTECTION)
|| (uarmh && uarmh->oartifact == ART_MITRE_OF_HOLINESS)
|| (uwep && uwep->oartifact == ART_TSURUGI_OF_MURAMASA))
(void) strkitten(armbuf, '+');
return upstart(armbuf);
}
/* =======================================================================*/
/* statusnew routines */
/* =======================================================================*/
/* structure that tracks the status details in the core */
#ifdef STATUS_HILITES
#endif /* STATUS_HILITES */
staticfn boolean eval_notify_windowport_field(int, boolean *, int);
staticfn void evaluate_and_notify_windowport(boolean *, int);
staticfn void init_blstats(void);
staticfn int compare_blstats(struct istat_s *, struct istat_s *);
staticfn char *anything_to_s(char *, anything *, int);
staticfn int percentage(struct istat_s *, struct istat_s *);
staticfn int exp_percentage(void);
staticfn int QSORTCALLBACK cond_cmp(const genericptr, const genericptr);
staticfn int QSORTCALLBACK menualpha_cmp(const genericptr, const genericptr);
#ifdef STATUS_HILITES
staticfn void s_to_anything(anything *, char *, int);
staticfn enum statusfields fldname_to_bl_indx(const char *);
staticfn boolean hilite_reset_needed(struct istat_s *, long);
staticfn boolean noneoftheabove(const char *);
staticfn struct hilite_s *get_hilite(int, int, genericptr_t, int, int, int *);
staticfn void split_clridx(int, int *, int *);
staticfn boolean is_ltgt_percentnumber(const char *);
staticfn boolean has_ltgt_percentnumber(const char *);
staticfn int splitsubfields(char *, char ***, int);
staticfn boolean is_fld_arrayvalues(const char *, const char *const *,
int, int, int *);
staticfn int query_arrayvalue(const char *, const char *const *, int, int);
staticfn void status_hilite_add_threshold(int, struct hilite_s *);
staticfn boolean parse_status_hl2(char (*)[QBUFSZ], boolean);
staticfn unsigned long query_conditions(void);
staticfn char *conditionbitmask2str(unsigned long);
staticfn unsigned long match_str2conditionbitmask(const char *);
staticfn unsigned long str2conditionbitmask(char *);
staticfn boolean parse_condition(char (*)[QBUFSZ], int);
staticfn char *hlattr2attrname(int, char *, size_t);
staticfn void status_hilite_linestr_add(int, struct hilite_s *, unsigned long,
const char *);
staticfn void status_hilite_linestr_done(void);
staticfn int status_hilite_linestr_countfield(int);
staticfn void status_hilite_linestr_gather_conditions(void);
staticfn void status_hilite_linestr_gather(void);
staticfn char *status_hilite2str(struct hilite_s *);
staticfn int status_hilite_menu_choose_field(void);
staticfn int status_hilite_menu_choose_behavior(int);
staticfn int status_hilite_menu_choose_updownboth(int, const char *, boolean,
boolean);
staticfn boolean status_hilite_menu_add(int);
staticfn boolean status_hilite_remove(int);
staticfn boolean status_hilite_menu_fld(int);
staticfn void status_hilites_viewall(void);
#define has_hilite(i) (gb.blstats[0][(i)].thresholds)
/* TH_UPDOWN encompasses specific 'up' and 'down' also general 'changed' */
#define Is_Temp_Hilite(rule) ((rule) && (rule)->behavior == BL_TH_UPDOWN)
/* pointers to current hilite rule and list of this field's defined rules */
#define INIT_THRESH , (struct hilite_s *) 0, (struct hilite_s *) 0
#else /* !STATUS_HILITES */
#define INIT_THRESH /*empty*/
#endif
#define INIT_BLSTAT(name, fmtstr, anytyp, wid, fld) \
{ name, fmtstr, 0L, FALSE, FALSE, 0, anytyp, \
{ (genericptr_t) 0 }, { (genericptr_t) 0 }, (char *) 0, \
wid, -1, fld INIT_THRESH }
#define INIT_BLSTATP(name, fmtstr, anytyp, wid, maxfld, fld) \
{ name, fmtstr, 0L, FALSE, TRUE, 0, anytyp, \
{ (genericptr_t) 0 }, { (genericptr_t) 0 }, (char *) 0, \
wid, maxfld, fld INIT_THRESH }
/*
* If entries are added to this, botl.h will require updating too.
*
* 'max' values of BL_XP and BL_EXP get special handling since the
* percentage involved isn't a direct 100*current/maximum calculation.
*
* long int fields are given a buffer size of 30 which is guaranteed to
* be big enough for short prefix followed by a 20+ digit 64-bit long
* even though the actual values will be much smaller. The gold field
* is even bigger due to its encoded dollar sign prefix.
*/
static struct istat_s initblstats[MAXBLSTATS] = {
INIT_BLSTAT("title", "%s", ANY_STR, MAXVALWIDTH, BL_TITLE),
INIT_BLSTAT("strength", " St:%s", ANY_INT, 10, BL_STR),
INIT_BLSTAT("dexterity", " Dx:%s", ANY_INT, 10, BL_DX),
INIT_BLSTAT("constitution", " Co:%s", ANY_INT, 10, BL_CO),
INIT_BLSTAT("intelligence", " In:%s", ANY_INT, 10, BL_IN),
INIT_BLSTAT("wisdom", " Wi:%s", ANY_INT, 10, BL_WI),
INIT_BLSTAT("charisma", " Ch:%s", ANY_INT, 10, BL_CH),
INIT_BLSTAT("alignment", " %s", ANY_STR, 20, BL_ALIGN),
INIT_BLSTAT("score", " S:%s", ANY_LONG, 30, BL_SCORE),
INIT_BLSTAT("carrying-capacity", " %s", ANY_INT, 20, BL_CAP),
INIT_BLSTAT("gold", " %s", ANY_LONG, 40, BL_GOLD),
INIT_BLSTATP("power", " Pw:%s", ANY_INT, 10, BL_ENEMAX, BL_ENE),
INIT_BLSTAT("power-max", "(%s)", ANY_INT, 10, BL_ENEMAX),
INIT_BLSTATP("experience-level", " Xp:%s", ANY_INT, 10, BL_XP, BL_XP),
INIT_BLSTAT("armor-class", " AC:%s", ANY_INT, 10, BL_AC),
INIT_BLSTAT("HD", " HD:%s", ANY_INT, 10, BL_HD),
INIT_BLSTAT("time", " T:%s", ANY_LONG, 30, BL_TIME),
/* hunger used to be 'ANY_UINT'; see note below in bot_via_windowport() */
INIT_BLSTAT("hunger", " %s", ANY_INT, 20, BL_HUNGER),
INIT_BLSTATP("hitpoints", " HP:%s", ANY_INT, 10, BL_HPMAX, BL_HP),
INIT_BLSTAT("hitpoints-max", "(%s)", ANY_INT, 10, BL_HPMAX),
INIT_BLSTAT("dungeon-level", "%s", ANY_STR, MAXVALWIDTH, BL_LEVELDESC),
INIT_BLSTATP("experience", "/%s", ANY_LONG, 30, BL_EXP, BL_EXP),
INIT_BLSTAT("condition", "%s", ANY_MASK32, 0, BL_CONDITION),
/* optional; once set it doesn't change unless 'showvers' option is
toggled or player modifies the 'versinfo' option;
available mostly for screenshots or someone looking over shoulder;
blstat[][BL_VERS] is actually an int copy of flags.versinfo (0...7) */
INIT_BLSTAT("version", " %s", ANY_STR, MAXVALWIDTH, BL_VERS),
/* weapon and armor are constructed strings with no particular numeric
equivalent */
INIT_BLSTAT("weapon", " %s", ANY_STR, 20, BL_WEAPON),
INIT_BLSTAT("armor", " %s", ANY_STR, 20, BL_ARMOR),
/* terrain is tracked by a number but designating it as type 'int'
isn't useful; using type 'string' allows highlighting based on text
matching which is potentially useful */
INIT_BLSTAT("terrain", " %s", ANY_STR, 20, BL_TERRAIN),
};
#undef INIT_BLSTATP
#undef INIT_BLSTAT
#undef INIT_THRESH
#ifdef STATUS_HILITES
static const struct condmap condition_aliases[] = {
{ "strangled", BL_MASK_STRNGL },
{ "all", BL_MASK_BAREH | BL_MASK_BLIND | BL_MASK_BUSY
| BL_MASK_CONF | BL_MASK_DEAF | BL_MASK_ELF_IRON
| BL_MASK_FLY | BL_MASK_FOODPOIS | BL_MASK_GLOWHANDS
| BL_MASK_GRAB | BL_MASK_HALLU | BL_MASK_HELD
| BL_MASK_ICY | BL_MASK_INLAVA | BL_MASK_LEV
| BL_MASK_PARLYZ | BL_MASK_RIDE | BL_MASK_SLEEPING
| BL_MASK_SLIME | BL_MASK_SLIPPERY | BL_MASK_STONE
| BL_MASK_STRNGL | BL_MASK_STUN | BL_MASK_SUBMERGED
| BL_MASK_TERMILL | BL_MASK_TETHERED
| BL_MASK_TRAPPED | BL_MASK_UNCONSC
| BL_MASK_WOUNDEDL | BL_MASK_HOLDING },
{ "major_troubles", BL_MASK_FOODPOIS | BL_MASK_GRAB | BL_MASK_INLAVA
| BL_MASK_SLIME | BL_MASK_STONE | BL_MASK_STRNGL
| BL_MASK_TERMILL },
{ "minor_troubles", BL_MASK_BLIND | BL_MASK_CONF | BL_MASK_DEAF
| BL_MASK_HALLU | BL_MASK_PARLYZ | BL_MASK_SUBMERGED
| BL_MASK_STUN },
{ "movement", BL_MASK_LEV | BL_MASK_FLY | BL_MASK_RIDE },
{ "opt_in", BL_MASK_BAREH | BL_MASK_BUSY | BL_MASK_GLOWHANDS
| BL_MASK_HELD | BL_MASK_ICY | BL_MASK_PARLYZ
| BL_MASK_SLEEPING | BL_MASK_SLIPPERY
| BL_MASK_SUBMERGED | BL_MASK_TETHERED
| BL_MASK_TRAPPED
| BL_MASK_UNCONSC | BL_MASK_WOUNDEDL
| BL_MASK_HOLDING },
};
#endif /* STATUS_HILITES */
/* condition names and their abbreviations are used by windowport code */
const struct conditions_t conditions[] = {
/* ranking, mask, identifier, txt1, txt2, txt3 */
{ 20, BL_MASK_BAREH, bl_bareh, { "Bare", "Bar", "Bh" } },
{ 10, BL_MASK_BLIND, bl_blind, { "Blind", "Blnd", "Bl" } },
{ 20, BL_MASK_BUSY, bl_busy, { "Busy", "Bsy", "By" } },
{ 10, BL_MASK_CONF, bl_conf, { "Conf", "Cnf", "Cf" } },
{ 10, BL_MASK_DEAF, bl_deaf, { "Deaf", "Def", "Df" } },
{ 15, BL_MASK_ELF_IRON, bl_elf_iron, { "Iron", "Irn", "Fe" } },
{ 10, BL_MASK_FLY, bl_fly, { "Fly", "Fly", "Fl" } },
{ 6, BL_MASK_FOODPOIS, bl_foodpois, { "FoodPois", "Fpois", "Poi" } },
{ 20, BL_MASK_GLOWHANDS, bl_glowhands, { "Glow", "Glo", "Gl" } },
{ 2, BL_MASK_GRAB, bl_grab, { "Grab", "Grb", "Gr" } },
{ 10, BL_MASK_HALLU, bl_hallu, { "Hallu", "Hal", "Hl" } },
{ 20, BL_MASK_HELD, bl_held, { "Held", "Hld", "Hd" } },
{ 20, BL_MASK_ICY, bl_icy, { "Icy", "Icy", "Ic" } },
{ 8, BL_MASK_INLAVA, bl_inlava, { "InLava", "Lav", "La" } },
{ 10, BL_MASK_LEV, bl_lev, { "Lev", "Lev", "Lv" } },
{ 20, BL_MASK_PARLYZ, bl_parlyz, { "Parlyz", "Para", "Par" } },
{ 10, BL_MASK_RIDE, bl_ride, { "Ride", "Rid", "Rd" } },
{ 20, BL_MASK_SLEEPING, bl_sleeping, { "Zzz", "Zzz", "Zz" } },
{ 6, BL_MASK_SLIME, bl_slime, { "Slime", "Slim", "Slm" } },
{ 20, BL_MASK_SLIPPERY, bl_slippery, { "Slip", "Slp", "Sl" } },
{ 6, BL_MASK_STONE, bl_stone, { "Stone", "Ston", "Sto" } },
{ 4, BL_MASK_STRNGL, bl_strngl, { "Strngl", "Stngl", "Str" } },
{ 10, BL_MASK_STUN, bl_stun, { "Stun", "Stun", "St" } },
{ 15, BL_MASK_SUBMERGED, bl_submerged, { "Submrg", "Subm", "Sm" } },
{ 6, BL_MASK_TERMILL, bl_termill, { "TermIll", "Ill", "Ill" } },
{ 20, BL_MASK_TETHERED, bl_tethered, { "Teth", "Tth", "Te" } },
{ 20, BL_MASK_TRAPPED, bl_trapped, { "Trap", "Trp", "Tr" } },
{ 20, BL_MASK_UNCONSC, bl_unconsc, { "Out", "Out", "KO" } },
{ 20, BL_MASK_WOUNDEDL, bl_woundedl, { "WLegs", "Leg", "Lg" } },
{ 20, BL_MASK_HOLDING, bl_holding, { "UHold", "UHld", "UHd" } },
};
/* [perhaps these should all be opt_out with default of 'in';
otherwise some players may never learn about them] */
struct condtests_t condtests[CONDITION_COUNT] = {
/* id, useropt, opt_in or out, enabled, configchoice, testresult;
default value for enabled is !opt_in but can get changed via options */
{ bl_bareh, "barehanded", opt_in, FALSE, FALSE, FALSE },
{ bl_blind, "blind", opt_out, TRUE, FALSE, FALSE },
{ bl_busy, "busy", opt_in, FALSE, FALSE, FALSE },
{ bl_conf, "conf", opt_out, TRUE, FALSE, FALSE },
{ bl_deaf, "deaf", opt_out, TRUE, FALSE, FALSE },
{ bl_elf_iron, "iron", opt_out, TRUE, FALSE, FALSE },
{ bl_fly, "fly", opt_out, TRUE, FALSE, FALSE },
{ bl_foodpois, "foodPois", opt_out, TRUE, FALSE, FALSE },
{ bl_glowhands, "glowhands", opt_in, FALSE, FALSE, FALSE },
{ bl_grab, "grab", opt_out, TRUE, FALSE, FALSE },
{ bl_hallu, "hallucinat", opt_out, TRUE, FALSE, FALSE },
{ bl_held, "held", opt_in, FALSE, FALSE, FALSE },
{ bl_icy, "ice", opt_in, FALSE, FALSE, FALSE },
{ bl_inlava, "lava", opt_out, TRUE, FALSE, FALSE },
{ bl_lev, "levitate", opt_out, TRUE, FALSE, FALSE },
{ bl_parlyz, "paralyzed", opt_in, FALSE, FALSE, FALSE },
{ bl_ride, "ride", opt_out, TRUE, FALSE, FALSE },
{ bl_sleeping, "sleep", opt_in, FALSE, FALSE, FALSE },
{ bl_slime, "slime", opt_out, TRUE, FALSE, FALSE },
{ bl_slippery, "slip", opt_in, FALSE, FALSE, FALSE },
{ bl_stone, "stone", opt_out, TRUE, FALSE, FALSE },
{ bl_strngl, "strngl", opt_out, TRUE, FALSE, FALSE },
{ bl_stun, "stun", opt_out, TRUE, FALSE, FALSE },
{ bl_submerged, "submerged", opt_in, FALSE, FALSE, FALSE },
{ bl_termill, "termIll", opt_out, TRUE, FALSE, FALSE },
{ bl_tethered, "tethered", opt_in, FALSE, FALSE, FALSE },
{ bl_trapped, "trap", opt_in, FALSE, FALSE, FALSE },
{ bl_unconsc, "unconscious", opt_in, FALSE, FALSE, FALSE },
{ bl_woundedl, "woundedlegs", opt_in, FALSE, FALSE, FALSE },
{ bl_holding, "holding", opt_in, FALSE, FALSE, FALSE },
};
/* condition indexing */
int cond_idx[CONDITION_COUNT] = { 0 };
static const char c_Wall[] = "Wall";
/*
* Terrain descriptions for flags.terrainstatus; simplified from
* def_syms[].name and indexed by iflags.terrain_typ; should be
* kept in sync with rm.h types and the first half of def_syms[].
* The extra pseudo-types are specified by classify_terrain()
* when it sets up iflags.terrain_typ. Walls and a few of the
* others can only occur when hero has the Passes_walls ability.
*/
const char *terrain_descr[] = {
/* 0*/ "Stone", /* stone */
c_Wall, /* vwall */
c_Wall, /* hwall */
c_Wall, /* tlcorner */
c_Wall, /* trcorner */
c_Wall, /* blcorner */
c_Wall, /* brcorner */
c_Wall, /* crosswall */
c_Wall, /* tuwall */
c_Wall, /* tdwall */
/*10*/ c_Wall, /* tlwall */
c_Wall, /* trwall */
"Portcullis", /* dbwall, closed drawbridge 'door' */
"Tree",
c_Wall, /* sdoor: secret door */
"Stone", /* scorr: secret corridor */
"Pool", /* pool or non-moat water; can be boiled away */
"Moat", /* water that can't be boiled away */
"Water", /* water on Water level; can't be boiled or frozen */
"(gap)", /* drawbridge_up; replaced by whatever is under */
/*20*/ "Lava", /* lavapool */
"LavaWall", /* lava that extends to ceiling */
"Bars", /* ironbars */
"Doorway", /* doorless or broken door; diagonal movement is ok */
"Corridor", /* replaced by "Floor" */
"Room", /* also replaced by "Floor" */
"Stairs",
"Ladder",
"Fountain",
"Throne",
/*30*/ "Sink",
"Grave",
"Altar",
"Ice",
"Bridge", /* drawbridge_down, span across moat/ice/lava/floor */
"Air", /* open air on Air level or bubble on Water level */
"Cloud", /* [part of] a cloud or Air level */
/*
*/
/*37*/ "", /* MAX_TYPE; skipped ratther than overloaded */
/*38*/ c_Wall, /* MATCH_WALL for special levels; shouldn't happen */
/*
* additional terrain names that aren't simple levl[][].typ values
*/
/*39*/ "Floor", /* substituted for room or corridor */
/*40*/ "Ground", /* 'room' on Earth level */
"Open-door", /* open (not broken or doorless) */
"Shut-door", /* closed or locked (or trapped) */
"Swamp", /* Juiblex level */
"Submerged", /* under water */
"Sea", /* moat terrain on Medusa's level: "shallow sea" */
"WaterWall", /* water that extends to the ceiling */
};
/* cache-related */
static boolean cache_avail[3] = { FALSE, FALSE, FALSE };
static boolean cache_reslt[3] = { FALSE, FALSE, FALSE };
static const char *cache_nomovemsg = NULL, *cache_multi_reason = NULL;
#define cond_cache_prepA() \
do { \
boolean clear_cache = FALSE, refresh_cache = FALSE; \
\
if (gm.multi < 0) { \
if (gn.nomovemsg || gm.multi_reason) { \
if (cache_nomovemsg != gn.nomovemsg) \
refresh_cache = TRUE; \
if (cache_multi_reason != gm.multi_reason) \
refresh_cache = TRUE; \
} else { \
clear_cache = TRUE; \
} \
} else { \
clear_cache = TRUE; \
} \
if (clear_cache) { \
cache_nomovemsg = (const char *) 0; \
cache_multi_reason = (const char *) 0; \
} \
if (refresh_cache) { \
cache_nomovemsg = gn.nomovemsg; \
cache_multi_reason = gm.multi_reason; \
} \
if (clear_cache || refresh_cache) { \
cache_reslt[0] = cache_avail[0] = FALSE; \
cache_reslt[1] = cache_avail[1] = FALSE; \
} \
} while (0)
/* we don't put this next declaration in #ifdef STATUS_HILITES.
* In the absence of STATUS_HILITES, each array
* element will be 0 however, and quite meaningless,
* but we need to pass the first array element as
* the final argument of status_update, with or
* without STATUS_HILITES.
*/
staticfn void
bot_via_windowport(void)
{
char buf[BUFSZ];
const char *titl;
char *nb;
int i, idx, cap;
long money;
if (!gb.blinit)
panic("bot before init.");
/* toggle from previous iteration */
idx = 1 - gn.now_or_before_idx; /* 0 -> 1, 1 -> 0 */
gn.now_or_before_idx = idx;
/* clear the "value set" indicators */
(void) memset((genericptr_t) gv.valset, 0, MAXBLSTATS * sizeof (boolean));
/*
* Note: min(x,9999) - we enforce the same maximum on hp, maxhp,
* pw, maxpw, and gold as basic status formatting so that the two
* modes of status display don't produce different information.
*/
/*
* Player name and title.
*/
Strcpy(nb = buf, svp.plname);
nb[0] = highc(nb[0]);
titl = !Upolyd ? rank() : pmname(&mons[u.umonnum], Ugender);
i = (int) (strlen(buf) + sizeof " the " + strlen(titl) - sizeof "");
/* if "Name the Rank/monster" is too long, we truncate the name but
always keep at least BOTL_NSIZ characters of it; when hitpointbar is
enabled, anything beyond 30 (long monster name) will be truncated */
if (i > 30) {
i = 30 - (int) (sizeof " the " + strlen(titl) - sizeof "");
nb[max(i, BOTL_NSIZ)] = '\0';
}
Strcpy(nb = eos(nb), " the ");