forked from rogueforge/rogomatic14
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtactics.c
More file actions
959 lines (770 loc) · 26.3 KB
/
Copy pathtactics.c
File metadata and controls
959 lines (770 loc) · 26.3 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
/*
* 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/>.
*/
/*
* tactics.c:
*
* This file contains all of the 'medium level intelligence' of Rog-O-Matic.
*/
# include <stdio.h>
# include <ctype.h>
# include <setjmp.h>
# include "modern_curses.h"
# include "types.h"
# include "config.h"
# include "globals.h"
# include "install.h"
/*
* sanity check on PLUNGE_LVL
*/
# if !defined(PLUNGE_LVL)
# error "PLUNGE_LVL must be defined - try defining it as 13"
# endif
# if PLUNGE_LVL < 1
# error "PLUNGE_LVL cannot be < 1 - try a more reasonable value such as 13"
# endif
# if PLUNGE_LVL > 25
# error "PLUNGE_LVL cannot be > 25 - try a more reasonable value such as 13"
# endif
/* static declarations */
/*
* waitaround: Hang around here waiting for monsters.
*/
static struct {
int vertstart,
vertend,
vertdelt,
horstart,
horend,
hordelt;
} cb [4] = {
{ 3, R-3, 1, 1, C-2, 1}, /* Top left corner */
{ 3, R-3, 1, C-2, 1, -1}, /* Top right corner */
{ R-3, 3, -1, C-2, 1, -1}, /* Bottom right corner */
{ R-3, 3, -1, 1, C-2, 1}
}; /* Bottom left corner */
static int gc = 0; /* Goal corner from 0..3 */
static int waitaround (void);
/*
* handlearmor: This routine is called to determine whether we should
* take off or put on armor.
*
* Current strategy: Wear best armor on levels 1..7 or 19 on or
* if protected or have maintain armor.
* Wear 2nd best armor between levels 13..18.
* Wear best leather armor between levels 8..12
* or 2nd best if no leather armor. DR UTexas 12/15/83
*
* Note that leather armor does not rust.
*/
int
handlearmor (void)
{
int obj;
/* Only check when armor status is different */
if (!newarmor || cursedarmor) return (0);
/*
* Pick the armor we want to wear. If we are worried about rust monster
* we wear the second best armor, but if we wont see any rust monsters,
* if our armor is too good for a rust monster to hit it, or we have a
* ring of maintain armor, then we should wear our best armor. On
* levels 13-18 we wear our second best no matter what.
*/
obj = havearmor (1, NOPRINT, ANY); /* Get best armor */
if (Level > (version < RV52A ? 8 : 7) && Level < 19 &&
wearing ("maintain armor") == NONE &&
willrust (obj) &&
itemis (obj, KNOWN)) {
obj = NONE;
if (Level<13) obj = havearmor (1, NOPRINT, RUSTPROOF);
if (Level<13 && obj==NONE) obj = havearmor (3, NOPRINT, ANY);
if (obj==NONE) obj = havearmor (2, NOPRINT, ANY);
}
/* If the new armor is really bad, then don't bother wearing any */
if (obj != NONE && armorclass (obj) > 9 && itemis (obj, KNOWN))
{ obj = NONE; }
/* If we are wearing the right armor, then don't bother */
if (obj == currentarmor)
{ newarmor = false; return (0); }
/* Debugging */
dwait (D_PACK, __func__, "obj: %d currentarmor: %d", obj, currentarmor);
/* Take off the wrong armor */
if (currentarmor != NONE && takeoff ())
{ return (1); }
/* Put on the right armor, avoid wearing cursed armor */
if (obj != NONE)
{ return (wear (obj)); }
/* If we have no armor, then forget it */
newarmor = false;
return (0);
}
/*
* handleweapon: wield our best weapon. Calls haveweapon.
*
* The current strategy is to wield the best weapon from haveweapon.
*/
int
handleweapon (void)
{
int obj;
if ((!newweapon || cursedweapon) && !wielding (thrower)) return (0);
/* haveweapon (1) returns the index of the best weapon in the pack */
if ((obj = haveweapon (1, NOPRINT)) == NONE) return (0);
/* If we are not wielding our best weapon, do so */
if (obj == currentweapon) { newweapon = false; return (0); }
else if (obj != NONE) { return (wield (obj)); }
else { newweapon = false; return (0); }
}
/*
* quaffpotion: check whether we should quaff a potion, and call
* quaff if so. We quaff add strength, restore strength, healing,
* extra healing, and raise level here. Potions of seeinvisible
* are handled in 'fightinvisible'.
*
* If we are at or below the exp. level, then experiment with unknown potions.
*/
# define MAXSTR (version < RV52A ? 1900 : 3100)
int
quaffpotion (void)
{
int obj = NONE, obj2 = NONE;
/* Take advantage of double haste bug -- assures permanent haste */
if (!doublehasted && version < RV52A &&
((hasted && (obj = havenamed (potion, "haste self")) != NONE) ||
((obj = havemult (potion, "haste self", 2)) != NONE)) &&
quaff (obj))
return (1);
/*
* Can we use a gain strength to our advantage? Or a restore?
* If we have a Gain Strength, or our strength is very bad,
* then we quaff a Regain Strength.
*/
if (Str == Strmax && (obj = havenamed (potion, "gain strength")) != NONE &&
quaff (obj))
return (1);
if ((Str < 700 ||
(Str != Strmax && (havenamed (potion, "gain strength") != NONE))) &&
(obj = havenamed (potion, "restore strength")) != NONE &&
quaff (obj))
return (1);
if ((Str < 1600 || Level > 12) &&
(obj = havemult (potion, "restore strength", 2)) != NONE &&
quaff (obj))
return (1);
/* Try to get unblinded by quaffing a potion */
if (blinded &&
((obj = havenamed (potion, "healing")) != NONE ||
(obj = havenamed (potion, "extra healing")) != NONE ||
(obj = havenamed (potion, "see invisible")) != NONE) &&
quaff (obj))
return (1);
/* Try to get uncosmic by quaffing a potion */
if (cosmic &&
(obj = havenamed(potion, "extra healing")) != NONE &&
quaff (obj))
return (1);
if (cosmic && Str != Strmax &&
(obj = havenamed (potion, "poison")) != NONE) {
if ((wearing ("sustain strength") != NONE && quaff (obj)) ||
findring ("sustain strength"))
return (1);
}
/*
* Quaff healing to raise our MaxHp
* Wait for cosmic known to quaff extra healing. DR,TG UTexas
*/
if ((Hp == Hpmax) &&
((obj = havemult (potion, "healing", 2)) != NONE ||
(obj = havemult (potion, "extra healing", 2)) != NONE ||
(know ("blindness") && ((obj = havenamed (potion, "healing")) != NONE)) ||
(know ("blindness") && (know ("hallucination") || version < RV53A) &&
Level < 15 && ((obj = havenamed (potion, "extra healing")) != NONE))) &&
quaff (obj))
return (1);
/*
* Quaff a raise level potion?
*/
if ((Explev > 8 || Level > 13) &&
(obj = havenamed (potion, "raise level")) != NONE &&
quaff (obj))
return (1);
/* Quaff an unknown potion? */
if ((Level >= (k_exper/10) || objcount >= maxobj || Str<1000 || blinded) &&
(obj = unknown (potion)) != NONE) {
if ((obj2 = wearing ("add strength")) != NONE && removering (obj2))
return (1);
else if (wearing ("sustain strength") == NONE &&
(obj2 = havenamed (ring, "sustain strength")) != NONE &&
puton (obj2))
return (1);
else if (quaff (obj))
return (1);
}
return (0);
}
/*
* readscroll: check whether we should read a scroll, and call reads
* to actually read it.
*
* Scrolls of identify, remove curse, genocide, enchant weapon,
* enchant armor, magic mapping are defined. Scrolls of scare
* monster and confuse monster are handled in 'battlestations'.
*
* If we are at or below (k_exper/10), experiment with unknown scrolls.
* Make certain that we are wearing our best armor when reading
* enchant armor or an unknown scroll (which could be enchant
* armor).
*/
int
readscroll (void)
{
int obj, obj2;
/* Check the item specific identify scrolls first */
if ((((obj = havenamed (Scroll, "identify scroll")) != NONE) && (obj2 = unknown (Scroll)) != NONE) ||
(((obj = havenamed (Scroll, "identify armor")) != NONE) && (obj2 = unknown (armor)) != NONE) ||
(((obj = havenamed (Scroll, "identify weapon")) != NONE) && (obj2 = unknown (hitter)) != NONE) ||
(((obj = havenamed (Scroll, "identify potion")) != NONE) && (obj2 = unknown (potion)) != NONE) ||
((obj = havenamed (Scroll, "identify ring, wand or staff")) != NONE &&
((obj2 = unknown (ring)) != NONE || (obj2 = unknown (wand)) != NONE))) {
prepareident (obj2, obj);
return (reads (obj));
}
/* In older version, have multiple uses for generic identify scrolls */
if ((obj = havenamed (Scroll, "identify")) != NONE &&
(currentweapon != NONE) &&
(!itemis (currentweapon, KNOWN) &&
(!usingarrow || goodarrow > R-4))) {
prepareident (currentweapon, obj);
return (reads (obj));
}
if ((obj = havenamed (Scroll, "identify")) != NONE &&
((obj2 = unknown (ring)) != NONE ||
(obj2 = unidentified (wand)) != NONE ||
(obj2 = unidentified (Scroll)) != NONE ||
(Level > 10 && (obj2 = unknown (wand)) != NONE) ||
((cheat || version == RV36A) &&
((obj2 = unknown (potion)) != NONE ||
(obj2 = haveother (Scroll, obj)) != NONE)))) {
prepareident (obj2, obj);
return (reads (obj));
}
if ((cursedarmor || cursedweapon) &&
(obj = havenamed (Scroll, "remove curse")) != NONE)
return (reads (obj));
if ((obj = havenamed (Scroll, "genocide")) != NONE)
return (reads (obj));
if (currentweapon != NONE &&
(goodweapon || usingarrow || MaxLevel > 12) &&
(obj = havenamed (Scroll, "enchant weapon")) != NONE)
return (reads (obj));
if (Level != didreadmap && Level > 12 &&
(obj = havenamed (Scroll, "magic mapping")) != NONE)
return (reads (obj));
/* About to read an unknown scroll. We will assure that we have */
/* a weapon in hand, and put on our best armor for the occasion */
/* We must also prepare to identify something, just in case. */
if ((obj = havenamed (Scroll, "enchant armor")) != NONE ||
(obj = havenamed (Scroll, "protect armor")) != NONE ||
((currentweapon != NONE) &&
(Level >= (k_exper/10) || objcount >= maxobj ||
cursedarmor || cursedweapon) &&
(exploredlevel || Level > 18 || know ("aggravate monsters")) &&
(obj = unknown (Scroll)) != NONE)) {
prepareident (pickident (), obj);
/* Go to a corner to read the scroll */
if (version <= RV36B && !know ("create monster") && gotocorner ())
return (1);
/* Must put on our good armor first */
if (!cursedarmor &&
(!know("enchant armor") || stlmatch(inven[obj].str, "enchant armor") ||
!know("protect armor") || stlmatch(inven[obj].str, "protect armor"))) {
int obj2 = havearmor (1, NOPRINT, ANY); /* Pick our best armor */
if (obj2 == currentarmor);
/* Take off the bad stuff */
else if (currentarmor != NONE && takeoff ()) return (1);
/* Put on the good stuff */
else if (obj2 != NONE && wear (obj2)) return (1);
}
/* No armor handling, so read the scroll */
return (reads (obj));
}
return (0);
}
/*
* handlering: check whether we should put on a ring, and call
* puton to wear it. Calls 'havering' to find the two best rings
* and wears them if their evaluations are greater than 1000.
*
* 'havering' understands about when different rings are good, and how
* much food we need to use each ring.
*/
int
handlering (void)
{
int ring1, ring2;
if (!newring && !beingstalked) return (0);
ring1 = havering (1, NOPRINT);
ring2 = havering (2, NOPRINT);
dwait (D_PACK, __func__, "ring1: %d ring2: %d left: %d right: %d",
ring1, ring2, leftring, rightring);
if ((leftring == ring1 && rightring == ring2) ||
(rightring == ring1 && leftring == ring2)) {
newring = false; return (0);
}
if (leftring != NONE && leftring != ring1 && leftring != ring2 &&
removering (leftring)) {
return (1);
}
if (rightring != NONE && rightring != ring1 && rightring != ring2 &&
removering (rightring)) {
return (1);
}
if (ring1 != leftring && ring1 != rightring && puton (ring1)) {
return (1);
}
if (ring2 != leftring && ring2 != rightring && puton (ring2)) {
return (1);
}
return (0);
}
/*
* findring: called with the named of a ring, attempts to locate such
* a ring in the pack and wear it. It will remove rings (other than
* maintain armor) to accomplish this task if it we are wearing two
* rings.
*
* Could be extended to have an ordering of rings to wear.
*/
int
findring (char *name)
{
int obj;
if ((obj = havenamed (ring, name)) == NONE ||
wearing (name) != NONE)
return (0);
if (leftring != NONE && rightring != NONE) {
if (stlmatch (inven[leftring].str, "maintain armor"))
return (removering (rightring));
else
return (removering (leftring));
}
return (puton (obj));
}
/*
* grope: get to a safe square and sit and vibrate (move back and forth)
* and then sleep for 'turns' turns.
*
* Problem: We need to know which side of us the monster is on. Then
* we could zap him with wands or staves. This requires some kind of
* memory and the ability to detect when the motion command (ie 'hit'
* fails to move us). MLM
*/
int
grope (int turns)
{
int k, moves;
if (atrow < 2 || atcol < 1) {
command (T_GROPING, "%ds", (turns > 0) ? turns : 1);
return (1);
}
/* Count adjacent CANGO squares */
for (k=0, moves=0; k<8; k++)
if (onrc(CANGO, atdrow(k), atdcol(k))) moves++;
if (moves > 2 && findsafe ()) /* find a spot with 2 or fewer moves */
return (1);
/* blindir is direction of adjacent CANGO square which is not a trap */
for (k=0; k<4; k++, blindir = (blindir+2) % 8)
if ((onrc(CANGO|TRAP, atdrow(blindir), atdcol(blindir)) == CANGO))
break;
if (turns) command (T_GROPING, "%c%c%ds", keydir[blindir],
keydir[(blindir+4)&7], turns);
else command (T_GROPING, "%c%c", keydir[blindir],
keydir[(blindir+4)&7]);
blindir = (blindir+2) % 8;
return (1);
}
/*
* findarrow: This function tries to run over an arrow trap to get a
* magic arrow. Make certain we have some food.
*/
int
findarrow (void)
{
/* If wrong version, not cheating or must go find food, then forget it */
if (version > RV36B || !cheat || hungry())
return (0);
else if (!usingarrow && foundarrowtrap && !on (ARROW) &&
gotowards (trapr, trapc, 0))
{ display ("Trying for arrow..."); return (1); }
return (0);
}
/*
* checkcango: verify that a missile fired in direction 'dir' will
* travel 'turns' turns.
*
* Modified by mlm, 5/31/83: Return false if a monster is in the way.
* only return true if the missile will travel EXACTLY the distance
* specified. Also changed it to not check the current square (since
* we can fire from a door, even if we cant shoot through one).
*/
int
checkcango (int dir, int turns)
{
int r, c, dr, dc;
for (dr = deltr[dir], dc = deltc[dir], r=atrow+dr, c=atcol+dc;
turns > 0 && onrc (CANGO | DOOR, r, c) == CANGO;
r+=dr, c+=dc, turns--)
;
return (turns==0);
}
/*
* godownstairs: issues a down command and check for the halftimeshow.
*/
/* running - True ==> don't do anything fancy */
int
godownstairs (int running)
{
int p;
/* We don't want to go down if we have just gotten an arrow, since */
/* It is probably bad, and we will want to go back to the trap; */
/* Don't go down until we have killed five monsters in one blow. */
/* While waiting, run back and forth to look for monsters. */
if (cheat && version <= RV36B && !running &&
foundarrowtrap && usingarrow &&
have (food) != NONE && goodarrow < 5 && waitaround ()) {
saynow ("Checking out arrow...");
return (1);
}
/* Check for applicability of this rule */
if (! new_stairs) return (0);
/* If we are on the stairs, perhaps we should rest up some */
p = between ((Explev+larder)*10, 60, 100);
if (atrow == stairrow && atcol == staircol &&
!running && larder > 0 && Hp < max (10, percent (Hpmax, p))) {
command (T_RESTING, "s");
display ("Resting on stairs before next level");
return (1);
}
/* Allow other rules a chance to notice that we are done with the level */
if (on (STAIRS) && !exploredlevel)
{ exploredlevel = true; return (1); }
/* If we are floating, we cant go down, either rest or fail */
if (floating && running)
{ saynow ("Cannot escape, floating in mid-air!"); return (0); }
else if (floating) {
saynow ("Floating above stairs...");
command (T_RESTING, "s"); return (1);
}
/* If we are on the stairs, go down */
if (on (STAIRS)) {
halftimeshow (Level);
/* Send the DOWN command and return */
command (T_MOVING, ">");
return (1);
}
/* If we are running and can run to the next level, do that */
if (running && makemove (RUNDOWN, genericinit, downvalue, REEVAL)) {
return (1);
}
/* If we see the stairs or a trap door, go there */
if (!running && makemove (DOWNMOVE, genericinit, downvalue, REUSE)) {
goalr = targetrow; goalc = targetcol; /* Set a goal (CPU time hack) */
return (1);
}
new_stairs = false;
return (0);
}
/*
* plunge: Should we head down immediately?
*
* If we are being teleported too much or
* we are on a bad level (PLUNGE_LVL to 25) or
* we want to get past Aquators (level 19) or
* we have aggravated all of the monsters then
*
* we head down immediately.
*/
int
plunge (void)
{
/* Check for applicability of this rule */
if (stairrow == NONE && !foundtrapdoor) return (0);
if (have (amulet) != NONE) return (0);
if (teleported > (larder+1)*5 && godownstairs (NOTRUNNING)) {
if (!on (STAIRS)) saynow ("Giving up on level, too much teleporting");
return (1);
}
if (Level >= PLUNGE_LVL && Level < 26 && godownstairs (NOTRUNNING)) {
if (!on (STAIRS)) saynow ("Plunge mode!!!");
return (1);
}
if (aggravated && godownstairs (NOTRUNNING)) {
if (!on (STAIRS)) saynow ("Running from aggravated monsters");
return (1);
}
if (haveexplored (9) && godownstairs (NOTRUNNING)) {
if (!on (STAIRS)) saynow ("Level explored");
return (1);
}
return (0);
}
/*
* waitaround: For some reason we want to stay on this level for a while.
* Try running to each corner of the level.
*/
static int
waitaround (void)
{
int i, j;
if (gotowardsgoal ()) return (1);
++gc;
gc = gc % 4;
for (i = cb[gc].vertstart; i != cb[gc].vertend; i += cb[gc].vertdelt)
for (j = cb[gc].horstart; j != cb[gc].horend; j += cb[gc].hordelt)
if (onrc (BEEN | CANGO | ROOM, i, j) &&
!onrc (TRAP, i, j) && gotowards (i, j, 0))
{ goalr = i; goalc = j; return (1); }
return (0);
}
/*
* goupstairs:
*
* If we have the amulet, and our score is good enough, then
* go up stairs. This function also checks for the end of the
* game, and issues the proper calls to get the score written.
*/
int
goupstairs (int running)
{
int obj;
/* Check for applicability of this rule */
if (stairrow == NONE || have(amulet) == NONE || !running)
return (0);
/* If we are on the stairs, then check for win, else go up */
if (atrow == stairrow && atcol == staircol) {
/* If we are about to win, dump any magic arrows or minus things */
if (Level == 1 &&
((obj = havearrow ()) != NONE || (obj = haveminus ()) != NONE) &&
throw (obj, 0))
{ return (1); }
/* No magic arrows, time to leave */
else if (Level == 1) {
/* Send an up command and a space to clear the 'You Made It' */
sendnow ("< ");
/* Now read chars until we have the end of the inventory. */
/* Note misspelling in Rogue 'Peices', so don't assume anything */
waitfor ("Gold P");
/* Note that quitrogue sends a '\n' to get the score */
quitrogue ("total winner", Gold, 0);
/*
* record the final state to the end of the level log
*/
levellog_append ("total winner");
return (1);
}
/* Not at the top yet, keep on trucking */
else
{ command (T_MOVING, "<"); return (1); }
}
/* If we know where the stairs are, go there */
else if ((goalr = stairrow) > 0 && (goalc = staircol) > 0 &&
gotowards (goalr, goalc, running))
return (1);
return (0);
}
/*
* restup: If we are low on hit points, sit for a while. Since handlering
* was called first, we will be wearing a ring of regeneration if need be.
*
* First we find a good place to rest (we will move into a room, but not
* out of one). In lit rooms, stand far from doors so we can shoot
* arrows at things coming in. In dark rooms, stand diagonally away
* from doors (so we get a one turn warning of monsters coming in that
* door). In either case, stand on stairs or next to trap doors and
* teleport traps).
*
* Then rest by searching 's'. If one blow would not kill us, and we
* don't plan to shoot arrows, then rest up so as to heal one hit point.
* If we are critically low, rest up one turn at a time.
*
* Other considerations: Don't move if confused or cosmic.
* Drink healing potions if really low.
* Don't rest when hungry (and no food)
*/
int
restup (void)
{
int obj, turns;
/* If we are confused, sit still so we don't bump into anything bad */
if (confused) { command (T_RESTING, "s"); return (1); }
/* If cosmic and plenty of hit points and food, rest for long periods */
if (cosmic && (Hp >= percent (Hpmax, 80)) && larder > 2) {
display ("Oh wow man, I'm contemplating my navel!");
command (T_RESTING, "100s"); return (1);
}
/* If we are well, return */
if (Hp >= max (8, percent (Hpmax, between (Explev*10+k_rest-50, 40, 80))))
{ unrest (); return (0); }
/*
* If we are really ill then try a healing potion (save a healing
* potion for blindness, extra healing for hallucination).
*/
if (Hp < Level+10 && Hp < Hpmax/3 &&
((obj = havemult (potion, "extra healing", 2)) != NONE ||
(obj = havemult (potion, "healing", 2)) != NONE ||
(know ("hallucination") &&
(obj = havenamed (potion, "extra healing")) != NONE) ||
(know ("blindness") &&
(obj = havenamed (potion, "healing")) != NONE)) &&
quaff (obj))
{ return (1); }
/* Don't rest when we havent enough to eat */
if (hungry ()) return (0);
display ("Resting up...");
/*
* Look for a good place to rest
*/
if (movetorest ()) return (1);
/*
* If we are very ill, or we are very deep, or we are in a lit room
* and can shoot at things as they come ate us, rest only one turn so
* monsters don't get the first shot. Otherwise rest enough turns
* to heal one step.
*/
turns = (Level < 8) ? (20-Explev*2) : 3;
if ((!darkroom () && ammo) || Hp < Level*2+8 || Level > 15) turns = 1;
command (T_RESTING, "%ds", turns);
return (1);
}
/*
* If goalr and goalc are set (not -1,-1) then attempt to move towards
* that square. Calls gotowards which calls bfsearch.
*/
int
gotowardsgoal (void)
{
if (goalr > 0 && goalc > 0) { /* Keep on trucking */
if (goalr == atrow && goalc == atcol) { goalr = NONE; goalc = NONE; }
else if (gotowards (goalr, goalc, 0)) { return (1); }
else { goalr = NONE; goalc = NONE; }
}
return (0);
}
/*
* gotocorner: Find a corner using downright and try to go there.
* This is done so we can destroy old wands by throwing
* them into the corner (which destroys them).
*/
int
gotocorner (void)
{
int r, c;
if (!downright (&r, &c)) return (0);
if (debug (D_SCREEN))
{ saynow ("Gotocorner called:"); mvaddch (r, c, 'T'); at (row, col); }
if (gotowards (r, c, 0)) { goalr=r; goalc=c; return (1); }
return (0);
}
/*
* lightroom: Try to light up the room if we are below level 17.
*/
int
light (void)
{
if (Level < 17) return (0);
return (lightroom ());
}
/*
* shootindark: If we are arching at an old monster, fire another arrow.
*/
int
shootindark (void)
{
int obj, bow;
/* If no longer arching in the dark, fail */
if (darkturns < 1 || darkdir == NONE || !darkroom ()) return (0);
darkturns--; /* Count off turns till he reaches us */
/* If he is one turn away, switch back to our sword */
if (!cursedweapon && wielding (thrower) && darkturns==0 && handleweapon ())
{ dwait (D_BATTLE, __func__, "Switching to 4th sword"); return (1); }
/* If we have room, switch to our bow */
if (!cursedweapon && !wielding (thrower) && darkturns > 3 &&
(bow = havebow (1, NOPRINT)) != NONE && wield (bow))
return (1);
/* Fail if we have run out of arrows */
if ((obj = havemissile ()) == NONE) return (0);
/* Throw the arrow in the arching direction */
return (throw (obj, darkdir));
}
/*
* dinnertime: Eat if we are hungry or if we have a surplus of food.
*/
int
dinnertime (void)
{
if ((havefood (5) && objcount == maxobj && ! droppedscare) ||
(larder > 0 && hungry ()))
{ return (eat ()); }
return (0);
}
/*
* trywand: Zap a blank wall with an unknown and unused wand in an attempt
* to generate a message which identifies the wand.
*/
int
trywand (void)
{
int obj, dir, r, c, count;
/* If we aren't in a room, if there are monsters around, */
/* or we are in the dark, then we can't try this strategy */
if (!on (ROOM) || mlistlen || darkroom ()) return (0);
/* Have we a wand to identify? */
if (((obj = unknown (wand)) == NONE) || (itemis (obj, WORTHLESS)))
return (0);
else if (used (inven[obj].str))
return (0);
/* Look for a wall either 3 or 4 away */
for (dir = 0; dir < 8; dir += 2) {
for (count = 0, r=atrow, c=atcol;
onrc (CANGO | DOOR, r, c) == CANGO;
r += deltr[dir], c += deltc[dir])
count++;
if (count == 4 || count == 5) break; /* Found a likely wall */
}
/* If we couldnt find room, then fail */
if (dir > 7) return (0);
/* point the wand */
return (point (obj, dir));
}
/*
* eat: If we have food, eat it.
*/
int
eat (void)
{
int obj;
if ((obj = have (food)) != NONE) {
command (T_HANDLING, "e%c", LETTER (obj));
return (1);
}
return (0);
}