forked from rogueforge/rogomatic14
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstrategy.c
More file actions
1289 lines (1042 loc) · 38.3 KB
/
Copy pathstrategy.c
File metadata and controls
1289 lines (1042 loc) · 38.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
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/>.
*/
/*
* strategy.c:
*
* This file contains all of the 'high level intelligence' of Rog-O-Matic.
*/
# include <stdio.h>
# include <ctype.h>
# include <string.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
/*
* foughtmonster records whether we engaged in battle recently. This
* information is used to tell whether we should sit still, waiting for a
* confused monster to come back, or to go on about our business.
* DIDFIGHT is the number of turns to sit still after a battle.
*/
# define DIDFIGHT 3
/* static declarations */
static int callitpending (void);
static int fightmonster (void);
static int tomonster (void);
static int wanttowake(char c);
static int aftermelee (void);
static int battlestations (int m, char *monster, int mbad, int danger, int mdir, int mdist, int alert, int adj);
static int tostuff (void);
static int fightinvisible (void);
static int archery (void);
static int pickupafter (void);
static int dropjunk (void);
/*
* strategize: Run through each rule until something fires. Return 1 if an
* action was taken, otherwise return 0 (and then play will read a command
* from the user).
*/
int
strategize (void)
{
dwait (D_CONTROL, __func__, "Strategizing");
/* If replaying, instead of making an action, return the old one */
if (replaying) return (replaycommand ());
/* Clear any messages we printed last turn */
if (msgonscreen) { at (0,0); clrtoeol (); msgonscreen = false; at (row,col); }
/* ----------------------- Production Rules --------------------------- */
if (callitpending ()) /* We have this to do */
return (1);
if (fightmonster ()) /* We are under attack! */
return (1);
if (fightinvisible ()) /* Claude Raines! */
return (1);
if (tomonster ()) /* Go play with the pretty monster */
return (1);
if (shootindark ()) /* Shoot arrows in dark rooms */
return (1);
if (handleweapon ()) /* Play with the nice sword */
{ dwait (D_BATTLE, __func__, "Switching to 1st sword"); return (1); }
if (light ()) /* Fiat lux! Especially if we lost */
return (1); /* a monster from view. */
if (dinnertime ()) /* Soups on! */
return (1);
/*
* These variables are short term memory. Slowed and
* cancelled are fuses which are disabled after a small
* number of turns.
*/
lyinginwait = false; /* No more monsters to wait for */
if (foughtmonster) foughtmonster--; /* Turns since fought monster */
if (slowed) slowed--; /* Turns since we slowed a monster */
if (cancelled) cancelled--; /* Turns since we zapped 'cancel' */
if (beingheld) beingheld--; /* Turns since held by a fungus */
/* ---- End of short term memory modification ---- */
if (goupstairs (NOTRUNNING)) /* Up we go! Make sure that we get */
return (1); /* a better rank on the board. */
if (dropjunk ()) /* Send it back */
return (1);
if (readscroll ()) /* Get out the reading glasses */
return (1); /* Must come before handlearmor() */
if (handlearmor ()) /* Play dressup */
return (1);
if (quaffpotion ()) /* Glug glug glug ... */
return (1); /* Must come before handlering() */
if (handlering ()) /* We are engaged! */
return (1);
if (blinded && grope (50)) /* Who turned out the lights */
{ display ("Blinded, groping..."); return (1); }
if (aftermelee ()) /* Wait for lingering monsters */
return (1);
if (tostuff ()) /* Pick up the play pretty */
return (1);
if (restup ()) /* Yawn! */
return (1);
if (trywand ()) /* Try to use a wand */
return (1);
if (gotowardsgoal ()) /* Keep on trucking */
return (1);
if (exploreroom ()) /* Search the room */
return (1);
if (archery ()) /* Try to position for fight */
return (1);
if (pickupafter ()) /* Look for stuff dropped by arched mon */
return (1);
if (plunge ()) /* Plunge mode */
return (1);
if (findarrow ()) /* Do we have an uninitialized arrow? */
return (1);
if (findroom ()) /* Look for another room */
return (1);
/*
* 'attempt' records the number of times we have completely searched
* this level for secret doors. If attempt is greater than 0, then we
* have failed once to find the stairs and go down. If this happens
* three times, there could be a monster sleeping on the stairs. We set
* the SLEEPER bit for each square with a sleeping monster. Go find
* such a monster and kill it to see whether (s)he was on the stairs).
*/
if (attempt > 4 && makemove (ATTACKSLEEP, genericinit, sleepvalue, REUSE)) {
display ("No stairs, attacking sleeping monster...");
return (1);
}
if (Level>1 && larder>0 && doorexplore ()) /* Grub around */
return (1);
if (godownstairs (NOTRUNNING)) /* Down we go! */
return (1);
if ((Level<2 || larder<1) && doorexplore()) /* Grub around anyway */
return (1);
/*
* If we think we are on the stairs, but arent, maybe they were moved
* (ie we were hallucinating when we saw them last time).
*/
if (on (STAIRS) && (atrow != stairrow || atcol != staircol))
{ dwait (D_ERROR, __func__, "Stairs moved"); findstairs (NONE, NONE); return (1); }
/*
* If we failed to find the stairs, explore each possible secret door
* another ten times.
*/
while (attempt++ < MAXATTEMPTS) {
timestosearch += max (3, k_door / 5);
foundnew ();
if (doorexplore ()) return (1);
}
/*
* Don't give up, start all over!
*/
newlevel ();
display ("I would give up, but I am too stubborn, starting over...");
return (grope (10));
}
/*
* callitpending : When going through the inventory we found this to
* do, but we wanted to wait until we were no longer
* in the middle of something else to tag this item
* with this name.
*/
static int
callitpending (void)
{
if (pending_call_letter != ' ') {
command (T_OTHER, "c%c%s\n", pending_call_letter, pending_call_name);
pending_call_letter = ' ';
memset (pending_call_name, '\0', sizeof(pending_call_name));
return (1);
}
return (0);
}
/*
* fightmonster: looks for adjacent monsters. If found, it calls
* battlestations to prepare for battle otherwise hacks with the
* weapon already in hand.
*/
static int
fightmonster (void)
{
int i, rr, cc, mdir = NONE, mbad = NONE, danger = 0;
int melee = 0, adjacent = 0, alertmonster = 0;
int wanddir = NONE, m = NONE, howmean;
char mon, monc = ':', *monster;
/* Check for adjacent monsters */
for (i = 0; i < mlistlen; i++) {
rr = mlist[i].mrow; cc = mlist[i].mcol;
if (max (abs (atrow-rr), abs (atcol-cc)) == 1) {
if (mlist[i].q != ASLEEP) {
if (mlist[i].q != HELD || Hp >= Hpmax || !havefood (1)) {
melee = 1;
if (mlist[i].q == AWAKE) alertmonster = 1;
}
}
}
}
if (!melee || monc == ':') return (0); /* No one to fight */
/* Loop to find worst monster and tally danger & number adjacent */
for (i = 0; i < mlistlen; i++) {
rr = mlist[i].mrow; cc = mlist[i].mcol; /* Monster position */
/*
* If the monster is adjacent and is either awake or
* we don't know yet whether he is asleep, but we havent
* see any alert monsters yet.
*/
if (max (abs (atrow-rr), abs (atcol-cc)) == 1 &&
(alertmonster ? mlist[i].q == AWAKE :
mlist[i].q != ASLEEP)) { /* DR Utexas 26 Jan 84 */
mon = mlist[i].chr; /* Record the monster type */
monster = monname (mon); /* Record the monster name */
danger += maxhitchar(mon); /* Add to the danger */
/* If he is adjacent, add to the adj count */
if (onrc (CANGO, rr, atcol) && onrc (CANGO, atrow, cc)) {
adjacent++; howmean = isholder (monster) ? 10000 : avghit(i);
/* If he is adjacent and the worst monster yet, save him */
if (howmean > mbad) {
wanddir = mdir = direc (rr-atrow, cc-atcol);
monc = mon; m = i; mbad = howmean;
}
/* If we haven't yet a line of sight, check this guy out */
} else if (wanddir == NONE) {
wanddir = direc (rr-atrow, cc-atcol);
}
/* Debugging breakpoint */
if (valrc (rr,cc)) {
dwait (D_BATTLE, __func__, "%c: (%d,%d) danger: %d worst %c: (%d,%d) total: %d",
screen[rr][cc], rr-atrow, cc-atcol,
danger, monc, mdir, mbad, adjacent);
}
}
}
/*
* The following variables have now been set:
*
* monc: The letter of the worst monster we can hit
* mbad: Relative scale 0 to 26, how bad is (s)he
* mdir: Which direction to him/her
* danger: How many hit points can (s)he/they do this round?
* wanddir: Direction of worst monster, even if we cant move to it.
*/
/*
* Check whether the battlestations expert has a suggested action.
*/
monster = monname (monc);
if (battlestations (m, monster, mbad, danger, adjacent ? mdir : wanddir,
adjacent ? 1 : 2, alertmonster, max (1, adjacent)))
{ foughtmonster = DIDFIGHT; return (1); }
/*
* If we did not wait for him last turn, and he is not adjacent,
* let him move to us (otherwise, he gets to hits us first).
*/
if (!lyinginwait && !adjacent) {
command (T_FIGHTING, "s");
dwait (D_BATTLE, __func__, "Lying in wait");
lyinginwait = true;
foughtmonster = DIDFIGHT;
return (1);
}
/* If we are here but have no direction, there was a bug somewhere */
if (mdir < 0) {
dwait (D_BATTLE, __func__, "Adjacent, but no direction known");
return (0);
}
/* If we could die this round, tell the user about it */
if (danger >= Hp) display ("In trouble...");
/* Well, nothing better than to hit the beast! Tell dwait about it */
dwait (D_BATTLE, __func__, "Attacking %s: %d direction: %d total danger: %d",
monster, mbad, mdir, danger);
/* Record the monster type */
lastmonster = monc-'A'+1;
/* Move towards the monster (this causes us to hit him) */
rmove (1, mdir, T_FIGHTING);
lyinginwait = false;
foughtmonster = DIDFIGHT;
return (1);
}
/*
* tomonster: if we can see a monster (and either it is awake or we
* think we can beat it) then pick the worst one, call battlestations,
* and then call gotowards to move toward the monster. If the monster
* is an odd number of turns away, sit once to assure initiative before
* charging after him. Special case for sitting on a door.
*/
static int
tomonster (void)
{
int i, dist, rr, cc, mdir = NONE, mbad = NONE;
int closest, which, danger = 0, adj = 0, alert = 0;
char monc = ':', monchar = ':', *monster;
/* If no monsters, fail */
if (mlistlen==0)
return (0);
/*
* Loop through the monsters, 'which' and 'closest' record the index
* and distance of the closest monster worth fighting.
*/
for (i = 0, which = NONE, closest = 999; i < mlistlen; i++) {
dist = max (abs (mlist[i].mrow - atrow), abs (mlist[i].mcol - atcol));
monchar = mlist[i].chr;
/*
* IF we are not using a magic arrow OR
* we want to wake this monster up AND we can beat him OR
* he is standing near something we want and we will have to
* fight him anywhay
* THEN consider fighting the monster.
*
* Don't pick fights with sleepers if cosmic. DR UTexas 25 Jan 84
*/
if (usingarrow || mlist[i].q == AWAKE ||
(!cosmic && wanttowake (monchar) &&
(avghit (i) <= 50 || (maxhit (i) + 50 - k_wake) < Hp)) ||
(mlist[i].q == HELD && Hp >= Hpmax)) {
danger += maxhit(i); /* track total danger */
adj++; /* count number of monsters */
/* If he is the closest monster, save his index and distance */
if (dist < closest) {
closest = dist; which = i; monc = mlist[i].chr; mbad = avghit(i);
/* Or if he is meaner than another equally close monster, save him */
} else if (dist == closest && avghit(i) > avghit(which)) {
dwait (D_BATTLE, __func__, "Chasing %c: %d rather than %c: %d at distance: %d",
mlist[i].chr, avghit(i), mlist[which].chr,
avghit(which), dist);
closest = dist; which = i; monc = mlist[i].chr; mbad = avghit(i);
}
}
}
/* No monsters worth bothering, return failure */
if (which < 0) return (0);
/* Save the monsters location in registers */
rr = mlist[which].mrow - atrow; cc = mlist[which].mcol - atcol;
/* If the monster is on an exact diagonal, record direction */
mdir = (rr==0 || cc==0 || abs(rr)==abs(cc)) ? direc (rr, cc) : -1;
/* Get a string which names the monster */
monster = monname (monc);
/* Is the monster alert */
alert = (mlist[which].q == AWAKE) ? 1 : 0;
/* If 'battlestations' has an action, use that action */
if (battlestations (which, monster, mbad, danger, mdir, closest, alert, adj))
return (1);
/* If he is an odd number of squares away, lie in wait for him */
if ((closest&1) == 0 && !lyinginwait) {
command (T_FIGHTING, "s");
dwait (D_BATTLE, __func__, "Waiting for monster an odd number of squares away");
lyinginwait = true;
return (1);
}
/* "We have him! Move toward him!" */
if (gotowards (mlist[which].mrow, mlist[which].mcol, 0)) {
goalr = mlist[which].mrow; goalc = mlist[which].mcol;
lyinginwait = false;
return (1);
}
/* Could not find a path to the monster, record failure */
return (0);
}
/*
* wanttowake is true for monsters without special attacks, such that the
* expected damage from hits is a reasonable estimate of their vorpalness.
* Some monsters are included here because we want to shoot arrows at them.
*/
static int
wanttowake(char c)
{
char *monster = monname (c);
if (missedstairs)
return (1);
/*
* If monster sleeping but won't wake up when we move around him,
* return wanttowake as false. DR UTexas 09 Jan 84
*/
if (streq (monster, "centaur") ||
streq (monster, "dragon") ||
streq (monster, "floating eye") ||
streq (monster, "ice monster") ||
streq (monster, "leprechaun") ||
streq (monster, "nymph") ||
streq (monster, "wraith") ||
streq (monster, "jabberwock") ||
streq (monster, "purple worm") )
return (0);
return (1);
}
/*
* aftermelee: called when we have just fought a monster, assures
* that it wasn't just a confused monster that backed
* away and might get a hit on us if we move. Now only
* used when we lost a monster from view.
*
* Also rest if we are critically weak and have some food.
*/
static int
aftermelee (void)
{
if (foughtmonster > 0) {
lyinginwait = true;
command (T_RESTING, "s");
dwait (D_BATTLE, __func__, "waiting for %d rounds", foughtmonster);
return (1);
}
/* If critically weak, rest up so traps won't kill us. DR Utexas */
if (Hp < 6 && larder > 0) {
command (T_RESTING, "s");
display ("Recovering from severe beating...");
return (1);
}
return (foughtmonster = 0);
}
/*
* battlestations:
*
* We are going into battle. Can we think of anything better to
* to than simply hacking at him with our weapon?
*/
# define die_in(n) (Hp/n < danger*50/(100-k_run))
# define live_for(n) (! die_in(n))
/* m - Monster index */
/* monster - What is it? */
/* mbad - How bad is it? */
/* danger - How many points damage per round? */
/* mdir - Which direction (clear line of sight)? */
/* mdist - How many turns until battle? */
/* alert - Is he known to be awake? */
/* adj - How many attackers are there? */
static int
battlestations (int m, char *monster, int mbad, int danger, int mdir, int mdist, int alert, int adj)
{
int obj, turns;
static int stepback = 0;
/* Ascertain whether we have a clear path to this monster */
if (mdir != NONE && !checkcango (mdir, mdist))
mdir = NONE;
/* Number of turns is one less than distance (modified if we are hasted) */
turns = hasted ? (mdist-1)*2 : (mdist-1);
/* No point in wasting resources when we are invulnerable */
if (on (SCAREM) &&
(turns > 0 || confused) &&
!streq(monster, "dragon") &&
(Hp < percent (Hpmax, 95))) {
command (T_RESTING, "s");
display ("Resting on scare monster");
dwait (D_BATTLE, __func__, "resting, on scaremonster");
return (1);
}
/*
* Take invisible stalkers into account into account,
* fightmonster() and tomonster() cant see stalkers.
*/
if (beingstalked > INVPRES) { turns = 0; danger += INVDAM; }
/* Debugging breakpoint */
dwait (D_BATTLE,
__func__, "%s: %d total danger: %d dir: %d, %d turns: %d adj",
monster, mbad, danger, mdir, turns, adj);
/*
* Switch back to our mace or sword?
*/
if (live_for (1) && turns < 2 && wielding (thrower) && handleweapon ())
{ dwait (D_BATTLE, __func__, "Switching to 2nd sword"); return (1); }
/*
* Don't waste magic when on a scare monster scroll
*/
if (on (SCAREM) && !streq (monster, "dragon")) {
dwait (D_BATTLE, __func__, "hitting from scaremonster");
return (0);
}
/*
* If we were busy resting on the stairs and we see a monster, go down
* Go on down if about to be attacked by a monster with an effective
* magic attack. DR UTexas 25 Jan 84
*
* or has a remote attack, or has a significant attack with a permanent
* effect on the player stats or inventory
*/
if (on(STAIRS) && ((Level>PLUNGE_LVL && Level<26) || exploredlevel) && !floating &&
(die_in(5) ||
((seeawakemonster ("rattlesnake") || seeawakemonster ("giant ant")) &&
(havenamed (ring, "sustain strength") < 0)) ||
((seeawakemonster ("aquator") || seeawakemonster ("rust monster")) &&
turns < 2 && willrust (currentarmor) &&
wearing ("maintain armor") == NONE) ||
seeawakemonster ("medusa") || seeawakemonster ("umber hulk") ||
seeawakemonster ("dragon") || seeawakemonster ("wraith") ||
seeawakemonster ("vampire") || seeawakemonster ("nymph") ||
seeawakemonster ("ice monster") || seeawakemonster ("leprechaun"))) {
if (goupstairs (RUNNING) || godownstairs (RUNNING))
return (1);
}
/*
* Are healing potions worthwhile?
*/
if (die_in (1) && Hpmax-Hp > 10 && turns > 0 &&
((obj = havenamed (potion, "extra healing")) != NONE ||
(obj = havenamed (potion, "healing")) != NONE))
return (quaff (obj));
/*
* Run away if we are sure of the direction and we are in trouble
* Don't try to run if a fungi has ahold of us. If we are confused,
* we will try other things, and we will decide to run later.
* If we are on a door, wait until the monster is on us (that way
* we can shoot arrows at him, if we want to).
* Don't run away from Dragons!!! They'll just flame you.
*/
if (!confused && !beingheld && (!on(DOOR) || turns < 1) &&
(!streq (monster, "dragon") || cosmic) && Hp+Explev < Hpmax &&
((die_in(1) || Hp <= danger + between (Level-10, 0, 10)) || chicken) &&
runaway ()) {
display ("Run away! Run away!");
darkdir = NONE; darkturns = 0;
return(1);
}
/*
* Be clever when facing multiple monsters?
*/
if (adj > 1 && !confused && !beingheld && !on (STAIRS | DOOR) &&
backtodoor (turns))
return (1);
/*
* stepback to see if he is awake.
*/
if (!alert && !beingheld && !stepback && mdir != NONE &&
turns == 0 && !on (DOOR | STAIRS)) {
int rdir = (mdir+4)%DNUM;
int new_r = atdrow (rdir);
int new_c = atdcol (rdir);
if (if_onrc (CANGO | TRAP, new_r, new_c) == CANGO)
{ move1 (rdir); stepback = 7; return (1); }
}
if (stepback) stepback--; /* Decrement turns until step back again */
/*
* Should we put on our ring of maintain armor? DR UTexas 19 Jan 84
*/
if (live_for (1) && currentarmor != NONE &&
(leftring == NONE || rightring == NONE) &&
(seemonster ("aquator") || seemonster ("rust monster")) &&
willrust (currentarmor) &&
wearing ("maintain armor") == NONE &&
(obj = havenamed (ring, "maintain armor")) != NONE &&
puton (obj))
return (1);
if (turns > 1 && live_for (2) && leftring != NONE && rightring != NONE &&
(seemonster ("aquator") || seemonster ("rust monster")) &&
wearing ("maintain armor") < 0 &&
findring ("maintain armor"))
return (1);
/*
* Should we put on our ring of sustain strength? DR UTexas 19 Jan 84
*/
if ((live_for (1) || turns > 0) &&
(leftring == NONE || rightring == NONE) &&
(seemonster ("giant ant") || seemonster ("rattlesnake")) &&
wearing ("sustain strength") < 0 &&
(obj = havenamed (ring, "sustain strength")) != NONE &&
puton (obj))
return (1);
if ((live_for (2) || turns > 1) &&
leftring != NONE && rightring != NONE &&
(seemonster ("giant ant") || seemonster ("rattlesnake")) &&
wearing ("sustain strength") < 0 &&
findring ("sustain strength"))
return (1);
/*
* Should we put on our ring of regeneration? Make sure we wont kill
* ourselves trying to do it, by checking how many turns it will take to
* get it on compared to the number of hits we can take.
*/
/* Have a ring and a free hand, one turn */
if (die_in (4) && (live_for (1) || turns > 0) &&
(leftring == NONE || rightring == NONE) &&
!(turns == 0 && (streq (monster, "rattlesnake") ||
streq (monster, "giant ant"))) &&
wearing ("regeneration") < 0 &&
(obj = havenamed (ring, "regeneration")) != NONE &&
puton (obj))
return (1);
/* Have a ring and both hands are full, takes two turns */
if (die_in (4) && (live_for (2) || turns > 1) &&
leftring != NONE && rightring != NONE &&
wearing ("regeneration") < 0 &&
findring ("regeneration"))
return (1);
/*
* Haste ourselves?
*/
if (!hasted && version > RV36B && (turns > 0 || live_for (1)) &&
die_in (2) && (obj = havenamed (potion, "haste self")) != NONE &&
quaff (obj))
return (1);
/*
* Confuse the poor beast?
*/
if (die_in (2) && turns > 0 && !redhands &&
((obj = havenamed (Scroll, "monster confusion")) != NONE))
return (reads (obj));
/*
* Put them all to sleep? This does us little good, since we cant
* currently infer that we have a scroll of Hold Monster. But we
* will read scrolls of identify on the second one. Bug, this
* does not put them to sleep, it just holds them in place.
* We have a lot more programming to do here!!!! Fuzzy
*/
if (die_in (1) && (obj = havenamed (Scroll, "hold monster")) != NONE &&
reads (obj)) {
holdmonsters ();
return (1);
}
/*
* Drop a scare monster?
*/
if (die_in (1) && !streq(monster, "dragon") &&
(obj = havenamed (Scroll, "scare monster")) != NONE &&
drop (obj)) {
set (SCAREM);
droppedscare++;
return (1);
}
/*
* Buy buy birdy!
*/
if (die_in (1) && mdir != NONE && turns == 0 &&
(obj = havewand ("teleport away")) != NONE &&
! (itemis (obj, WORTHLESS)) &&
point (obj, mdir)) {
if (streq (monster, "violet fungi")) beingheld = false;
if (streq (monster, "venus flytrap")) beingheld = false;
return (1);
}
/*
* Eat dust, turkey!
*/
if (die_in (1) && turns == 0 &&
(obj = havenamed (Scroll, "teleportation")) != NONE) {
beingheld = false;
return (reads (obj));
}
/*
* If we trust our magic arrow, give it a whirl
*/
if (!confused && creative && usingarrow && goodarrow > 10 && turns == 0)
return (0);
/*
* Try to protect our armor from Rusties.
*/
if (!cursedarmor && currentarmor != NONE &&
(seeawakemonster ("rust monster") || seeawakemonster ("aquator")) &&
live_for (1) &&
!(cosmic && Level < 8) && /* DR UTexas 25 Jan 84 */
willrust (currentarmor) &&
wearing ("maintain armor") == NONE &&
takeoff ())
{ return (1); }
/*
* Any life saving wands?
*/
if (die_in (2) && Hp > 40 && turns < 3 &&
!(streq (monster, "purple worm") || streq (monster, "jabberwock")) &&
(obj = havewand ("drain life")) != NONE &&
! (itemis (obj, WORTHLESS))
)
return (point (obj, 0));
if (mdir != NONE && die_in (2) &&
(!cosmic || Level > 18) && /* DR UTexas 31 Jan 84 */
(streq (monster, "dragon") || streq (monster, "purple worm") ||
streq (monster, "jabberwock") || streq (monster, "medusa") ||
streq (monster, "xorn") || streq (monster, "violet fungi") ||
streq (monster, "griffin") || streq (monster, "venus flytrap") ||
streq (monster, "umber hulk") || streq (monster, "black unicorn")) &&
(obj = havewand ("polymorph")) != NONE &&
! (itemis (obj, WORTHLESS))
)
return (point (obj, mdir));
/*
* Any life prolonging wands?
*/
if ((die_in (1) || (turns == 0 && streq (monster, "floating eye")) ||
(turns == 0 && streq (monster, "ice monster"))) &&
mdir != NONE && mdist < 6 && !on(DOOR) &&
(((obj = havewand ("fire")) != NONE && !streq(monster, "dragon")) ||
(obj = havewand ("cold")) != NONE ||
(obj = havewand ("lightning")) != NONE) &&
! (itemis (obj, WORTHLESS))
)
return (point (obj, mdir));
if (die_in (2) && mdir != NONE && !slowed && (turns>0 || live_for (2)) &&
(obj = havewand ("slow monster")) != NONE &&
(slowed = 5) &&
! (itemis (obj, WORTHLESS))
)
return (point (obj, mdir));
if (mdir != NONE && !cancelled && turns == 0 &&
(streq (monster, "wraith") ||
streq (monster, "vampire") ||
streq (monster, "floating eye") ||
streq (monster, "ice monster") ||
streq (monster, "leprechaun") ||
streq (monster, "violet fungi") ||
streq (monster, "venus flytrap")) &&
(obj = havewand ("cancellation")) != NONE &&
(cancelled = 10) &&
! (itemis (obj, WORTHLESS))
) {
if (streq (monster, "violet fungi") || streq (monster, "venus flytrap"))
beingheld = false;
return (point (obj, mdir));
}
if (((die_in (3) && live_for (1)) ||
(turns == 0 && streq (monster, "floating eye")) ||
(turns == 0 && streq (monster, "ice monster"))) &&
mdir != NONE &&
(((obj = havewand ("magic missile")) != NONE && turns > 0) ||
((obj = havewand ("striking")) != NONE && turns == 0)) &&
! (itemis (obj, WORTHLESS))
)
return (point (obj, mdir));
/*
* Since we have no directional things, we will try to run even though
* we are confused. Again, wait at door until the monster is on us.
* Don't run away from dragons, they'll just flame you!!
*/
if (confused && !beingheld && (!on(DOOR) || turns < 1) &&
! streq (monster, "dragon") &&
((die_in (1) && Hp+Explev/2+3 < Hpmax) || chicken) &&
runaway ())
{ display ("Run away! Run away!"); return(1); }
/*
* We can live for a while, try to get to a position where we can run
* away if we really get into trouble. Don't run away from dragons,
* they'll just flame you!!!
*/
if (!confused && !beingheld && ! streq (monster, "dragon") &&
(mdir < 0 || turns < 5) &&
(((adj > 1 || live_for (1)) && die_in (4) && !canrun ())) &&
unpin ())
{ display ("Unpinning!!!"); return(1); }
/*
* Light up the room if we are in combat.
*/
if (turns > 0 && die_in (3) && lightroom ())
return (1);
/*
* We arent yet in danger and can shoot at the old monster.
*/
if ((live_for (5) || turns > 1) && shootindark ())
return (1);
/*
* Try out an unknown wand? Try shooting unknown wands at
* rattlesnakes since they are such a pain. DR UTexas 19 Jan 84
*/
if (live_for (2) && (Level > 8 || streq (monster, "rattlesnake") ||
streq (monster, "giant ant")) &&
mdir != NONE && on(ROOM) && mdist < 6 &&
((obj = unknown (wand)) != NONE) && (!used (inven[obj].str)) &&
! (itemis (obj, WORTHLESS))
) {
point (obj, mdir);
usesynch = false;
return (1);
}
/*
* Wait to see if he is really awake.
*/
if (!alert && !lyinginwait && turns > 0) {
command (T_FIGHTING, "s");
dwait (D_BATTLE, __func__, "Waiting to see if he is awake");
lyinginwait = true;
return (1);
}
/*
* Archery: try to move into a better position, and after that, try to
* shoot an arrow at the beast. Conserve arrows below SAVEARROWS.
*/
if ((streq (monster, "leprechaun") ||
streq (monster, "nymph") ||
streq (monster, "floating eye") ||
streq (monster, "ice monster") ||
streq (monster, "giant ant") ||
streq (monster, "rattlesnake") ||
streq (monster, "wraith") ||
streq (monster, "vampire") ||
streq (monster, "centaur") || /* DR UTexas 21 Jan 84 */
die_in (1+k_arch/20) || ammo > SAVEARROWS+5-k_arch/10) &&
(obj = havemissile ()) != NONE) {