-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmonster.c
1930 lines (1685 loc) · 51.1 KB
/
monster.c
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
/* =============================================================================
* PROGRAM: ularn
* FILENAME: monster.c
*
* DESCRIPTION:
* This module handles most aspects of monsters in the game.
* It provides the monster definitions.
* Handles monster creation.
* All monster movement, including attacking the player (including special
* attacks) is handled here.
* Also handles loading and saving monster state data.
*
* =============================================================================
* EXPORTED VARIABLES
*
* monstnamelist : The character code for displaying each monster
* monsttilelist : The gfx tile for each monster
* monster : The monster data
* lastmonst : The name of the last monster being processed.
* last_monst_id : The id of the last monster being processed.
* last_monst_hx : The x location of the last monster hit by the player
* last_monst_hy : The y location of the last monster hit by the player
* rmst : The random monster creation countdown.
*
* =============================================================================
* EXPORTED FUNCTIONS
*
* createmonster
* mon_has_item : Checks if a monster has a specific item
* fullhit : Do full damage to a monster
* ifblind : Display the monster hir, accounting for blindness
* hitmonster : Function to hit a monster
* hitm : Function to just hit a monster (no checks for AC)
* hitplayer : Function for a monster to hit the player
* makemonst : Make a monster number appropriate to a dungeon level
* randmonst : Create a random monster on the current cave level
* teleportmonst : Teleport a monster
* movemonst : Move monsters.
* parse2 : Function to call when player is not to move, but monsters are
* write_monster_data : Function to write the monster data to the save file
* read_monster_data : Function to read the monster data from the save file
*
* =============================================================================
*/
#include "monster.h"
#include "dungeon.h"
#include "header.h"
#include "itm.h"
#include "player.h"
#include "saveutils.h"
#include "show.h"
#include "sphere.h"
#include "ularn_game.h"
#include "ularn_win.h"
/* =============================================================================
* Exported variables
*/
char monstnamelist[MONST_COUNT] = {
' ', 'l', 'G', 'H', 'J', 'K', 'O', 'S', 'c', 'j', 't', 'A', 'E', 'L',
'N', 'Q', 'R', 'Z', 'a', 'b', 'h', 'i', 'C', 'T', 'Y', 'd', 'e', 'g',
'm', 'v', 'z', 'F', 'W', 'f', 'l', 'o', 'r', 'X', 'V', ' ', 'p', 'q',
's', 'y', 'U', 'k', 'M', 'w', 'D', 'D', 'P', 'x', 'n', 'D', 'D', 'u',
'D', '1', '2', '3', '4', '5', '6', '7', '9', '0'};
/*
* Tile numbers to use for monsters
*/
int monsttilelist[MONST_COUNT] = {
0, 0, 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, 56, 57, 58, 59, 60, 61, 62, 63};
/*
* for the monster data
*
* array to do rnd() to create monsters <= a given level
*/
char monstlevel[] = {5, 11, 17, 22, 27, 33, 39, 42, 46, 50, 53, 56};
struct monst monster[MONST_COUNT] = {
/* NAME LV AC DAM ATT INT GOLD HP EXP FLAGS
*-----------------------------------------------------------------------------------------------------------------------------*/
{"unseen attacker", 0, 0, 0, 0, 1, 0, 0, 0, 0},
{"lemming", 1, 0, 0, 0, 1, 0, 0, 1, FL_HEAD},
{"gnome", 1, 10, 1, 0, 8, 30, 2, 2, FL_HEAD | FL_INFRAVIS},
{"hobgoblin", 1, 13, 2, 0, 5, 25, 3, 2, FL_HEAD | FL_SLOW},
{"jackal", 1, 7, 1, 0, 4, 0, 1, 1, FL_HEAD},
{"kobold", 1, 15, 1, 0, 7, 10, 1, 1, FL_HEAD | FL_INFRAVIS},
{"orc", 2, 15, 3, 0, 9, 40, 5, 2, FL_HEAD},
{"snake", 2, 10, 1, 0, 3, 0, 3, 1, FL_HEAD},
{"giant centipede", 2, 13, 1, 4, 3, 0, 2, 2, FL_HEAD},
{"jaculi", 2, 9, 1, 0, 3, 0, 2, 1, FL_HEAD},
{"troglodyte", 2, 10, 2, 0, 5, 80, 5, 3, FL_HEAD | FL_SLOW},
{"giant ant", 2, 8, 1, 4, 4, 0, 5, 4, FL_HEAD},
{"floating eye", 3, 8, 2, 0, 3, 0, 7, 2, FL_FLY},
{"leprechaun", 3, 3, 0, 8, 3, 1500, 15, 40, FL_HEAD},
{"nymph", 3, 3, 0, 14, 9, 0, 20, 40, FL_HEAD},
{"quasit", 3, 5, 3, 0, 3, 0, 14, 10, FL_HEAD},
{"rust monster", 3, 5, 0, 1, 3, 0, 18, 20, FL_HEAD},
{"zombie", 3, 12, 3, 0, 3, 0, 9, 7, FL_HEAD | FL_UNDEAD},
{"assassin bug", 4, 4, 3, 0, 3, 0, 23, 13, FL_HEAD},
{"bugbear", 4, 5, 4, 15, 5, 40, 24, 33, FL_HEAD | FL_INFRAVIS},
{"hell hound", 4, 5, 2, 2, 6, 0, 20, 33, FL_HEAD},
{"ice lizard", 4, 11, 3, 10, 6, 50, 19, 23, FL_HEAD | FL_SLOW},
{"centaur", 4, 6, 4, 0, 10, 40, 25, 43, FL_HEAD},
{"troll", 5, 9, 5, 0, 9, 80, 55, 250, FL_HEAD},
{"yeti", 5, 8, 4, 0, 5, 50, 45, 90, FL_HEAD},
{"white dragon", 5, 4, 5, 5, 16, 500, 65, 1000, FL_HEAD},
{"elf", 5, 3, 3, 0, 15, 50, 25, 33, FL_HEAD | FL_INFRAVIS},
{"gelatinous cube", 5, 9, 3, 0, 3, 0, 24, 43, 0},
{"metamorph", 6, 9, 3, 0, 3, 0, 32, 40, FL_SLOW},
{"vortex", 6, 5, 4, 0, 3, 0, 33, 53, 0},
{"ziller", 6, 15, 3, 0, 3, 0, 34, 33, FL_HEAD},
{"violet fungus", 6, 12, 3, 0, 3, 0, 39, 90, 0},
{"wraith", 6, 3, 1, 6, 3, 0, 36, 300, FL_HEAD | FL_FLY | FL_UNDEAD},
{"forvalaka", 6, 3, 5, 0, 7, 0, 55, 270, FL_HEAD | FL_INFRAVIS},
{"lama nobe", 7, 14, 7, 0, 6, 0, 36, 70, FL_HEAD},
{"osequip", 7, 4, 7, 16, 4, 0, 36, 90, FL_HEAD},
{"rothe", 7, 15, 5, 0, 3, 100, 53, 230, FL_HEAD | FL_INFRAVIS},
{"xorn", 7, 6, 7, 0, 13, 0, 63, 290, FL_INFRAVIS},
{"vampire", 7, 5, 4, 6, 17, 0, 55, 950, FL_HEAD | FL_FLY | FL_UNDEAD},
{"invisible stalker", 7, 5, 6, 0, 5, 0, 55, 330, FL_HEAD | FL_SLOW},
{"poltergeist", 8, 1, 8, 0, 3, 0, 55, 430, FL_SPIRIT},
{"disenchantress", 8, 3, 1, 9, 3, 0, 57, 500, FL_HEAD},
{"shambling mound", 8, 13, 5, 0, 6, 0, 47, 390, 0},
{"yellow mold", 8, 12, 4, 0, 3, 0, 37, 240, 0},
{"umber hulk", 8, 6, 7, 11, 14, 0, 67, 600, FL_HEAD | FL_INFRAVIS},
{"gnome king", 9, -1, 10, 0, 18, 2000, 120, 3000, FL_HEAD | FL_INFRAVIS},
{"mimic", 9, 9, 7, 0, 8, 0, 57, 100, 0},
{"water lord", 9, -10, 15, 7, 20, 0, 155, 15000, FL_HEAD | FL_NOBEHEAD},
{"bronze dragon", 9, 5, 9, 3, 16, 300, 90, 4000, FL_HEAD | FL_FLY},
{"green dragon", 9, 4, 4, 10, 15, 200, 80, 2500, FL_HEAD | FL_FLY},
{"purple worm", 9, -1, 13, 0, 3, 100, 130, 15000, FL_HEAD},
{"xvart", 9, -2, 14, 0, 13, 0, 100, 1000, FL_HEAD | FL_SLOW},
{"spirit naga", 10, -20, 15, 12, 23, 0, 100, 20000, FL_HEAD | FL_NOBEHEAD | FL_FLY | FL_SPIRIT | FL_INFRAVIS},
{"silver dragon", 10, -4, 10, 3, 20, 700, 110, 10000, FL_HEAD | FL_FLY},
{"platinum dragon", 10, -7, 15, 13, 22, 1000, 150, 25000, FL_HEAD | FL_FLY},
{"green urchin", 10, -5, 12, 0, 3, 0, 95, 5000, 0},
{"red dragon", 10, -4, 13, 3, 19, 800, 120, 14000, FL_HEAD | FL_FLY},
{"type I demon lord", 12, -40, 20, 3, 20, 0, 150, 50000, FL_HEAD | FL_NOBEHEAD | FL_FLY | FL_INFRAVIS},
{"type II demon lord", 13, -45, 25, 5, 22, 0, 200, 75000, FL_HEAD | FL_NOBEHEAD | FL_FLY | FL_INFRAVIS},
{"type III demon lord", 14, -50, 30, 9, 24, 0, 250, 100000, FL_HEAD | FL_NOBEHEAD | FL_FLY | FL_INFRAVIS},
{"type IV demon lord", 15, -55, 35, 11, 26, 0, 300, 125000, FL_HEAD | FL_NOBEHEAD | FL_FLY | FL_INFRAVIS},
{"type V demon lord", 16, -60, 40, 13, 28, 0, 350, 150000, FL_HEAD | FL_NOBEHEAD | FL_FLY | FL_INFRAVIS},
{"type VI demon lord", 17, -65, 45, 13, 30, 0, 400, 175000, FL_HEAD | FL_NOBEHEAD | FL_FLY | FL_INFRAVIS},
{"type VII demon lord", 18, -70, 50, 6, 32, 0, 450, 200000, FL_HEAD | FL_NOBEHEAD | FL_FLY | FL_INFRAVIS},
{"demon prince", 19, -90, 80, 6, 40, 0, 1000, 500000, FL_HEAD | FL_NOBEHEAD | FL_FLY | FL_INFRAVIS},
{"God of Hellfire", 20, -120, 100, 6, 100, 0, 32767, 1000000, FL_HEAD | FL_NOBEHEAD | FL_FLY | FL_INFRAVIS}};
char lastmonst[40]; /* name of the current monster */
MonsterIdType last_monst_id =
MONST_NONE; /* the last monster hitting the player */
int last_monst_hx; /* x location of the last monster hit by player */
int last_monst_hy; /* y location of the last monster hit by player */
char rmst = 80; /* Random monster creation timer */
/* =============================================================================
* Local variables
*/
/*
* Monster movement area for the current monster movement
*/
static int move_xl, move_yl;
static int move_xh, move_yh;
/*
* The maximum path distance for smart monster movement
*/
static int distance;
/*
* The new location for the last monster moved
* These will be set to -1 if the monster died.
*/
static int movedx, movedy;
/*
* Rustable armour data
*/
#define ARMORTYPES 6
static short rustarm[ARMORTYPES][2] = {{OSTUDLEATHER, -2}, {ORING, -4},
{OCHAIN, -5}, {OSPLINT, -6},
{OPLATE, -8}, {OPLATEARMOR, -9}};
/* =============================================================================
* Local functions
*/
/* =============================================================================
* FUNCTION: checkloss
*
* DESCRIPTION:
* Function to subtract hp from user and flag bottomline display.
* Note: if x > c[HP] this routine could kill the player!
*
* PARAMETERS:
*
* x : The number of hitpoints for the player to lose.
*
* RETURN VALUE:
*
* None.
*/
static void checkloss(int x) {
if (x > 0) {
losehp(DIED_MONSTER, x);
UpdateStatus();
}
}
/* =============================================================================
* FUNCTION: dropsomething
*
* DESCRIPTION:
* Function to create an object when a monster dies
*
* PARAMETERS:
*
* x : The x location
*
* y : The y location
*
* monst : The monster id.
*
* RETURN VALUE:
*
* None.
*/
static void dropsomething(int x, int y, MonsterIdType monst) {
switch (monst) {
case ORC:
case NYMPH:
case ELF:
case TROGLODYTE:
case TROLL:
case ROTHE:
case VIOLETFUNGI:
case PLATINUMDRAGON:
case GNOMEKING:
case REDDRAGON:
something(x, y, level);
return;
case LEPRECHAUN:
if (rnd(101) >= 75)
creategem();
if (rnd(5) == 1)
dropsomething(x, y, LEPRECHAUN);
case LEMMING:
return;
default:
break;
}
}
/* =============================================================================
* FUNCTION: rust_armour
*
* DESCRIPTION:
* Function to rust armour.
*
* PARAMETERS:
*
* None.
*
* RETURN VALUE:
*
* Returns a pointer to the format string to print.
*/
static char *rust_armour(void) {
int Armour;
int ArmourId;
int Shield;
int Rusted = 0;
int i;
int Found;
char *p;
Armour = c[WEAR];
Shield = c[SHIELD];
/*
* Rust the shield, if present and rustable, first
*/
if (Shield != -1) {
if (ivenarg[Shield] > -1) {
adjustivenarg(Shield, -1);
Rusted = 1;
}
}
/*
* If nothing rusted yet then rust the armour if possible
*/
if (!Rusted && (Armour != -1)) {
/* find the armor in table */
ArmourId = iven[Armour];
i = 0;
Found = 0;
while ((i < ARMORTYPES) && !Found) {
if (ArmourId == rustarm[i][0])
Found = 1;
else
i++;
}
if (Found) {
if (ivenarg[Armour] > rustarm[i][1]) {
adjustivenarg(Armour, -1);
Rusted = 1;
}
}
}
/* if rusting did not occur */
if (!Rusted) {
switch (ArmourId) {
case OLEATHER:
p = "\nThe %s hit you -- you are lucky you have leather on.";
break;
case OSSPLATE:
p = "\nThe %s hit you -- you are fortunate to have stainless steel "
"armor!";
break;
case OELVENCHAIN:
p = "\nThe %s hit you -- you are very lucky to have such strong elven "
"chain!";
break;
default:
p = "\nThe %s hit you.";
break;
}
} else {
UlarnBeep();
p = "\nThe %s hit you -- your armor feels weaker.";
}
return p;
}
/* =============================================================================
* FUNCTION: spattack
*
* DESCRIPTION:
* Function to process special attacks from monsters
*
* atckno monster effect
* ---------------------------------------------------
* 0 none
* 1 rust eat armor
* 2 hell hound breathe light fire
* 3 dragon breathe fire
* 4 giant centipede weakening strength
* 5 white dragon cold breath
* 6 wraith drain level
* 7 waterlord water gusher
* 8 leprechaun steal gold
* 9 disenchantress disenchant weapon or armor
* 10 ice lizard hits with barbed tail
* 11 umber hulk confusion
* 12 spirit naga cast spells taken from special attacks
* 13 platinum dragon psionics
* 14 nymph steal objects
* 15 bugbear bite
* 16 osequip
*
* PARAMETERS:
*
* x : THe special attack number.
*
* xx : The x coordinate of the monster.
*
* yy : The y coordinate of the monster.
*
* RETURN VALUE:
*
* Returns 1 if must do a show1cell(xx,yy)
* return, 0 otherwise
*/
static char spsel[] = {1, 2, 3, 5, 6, 8, 9, 11, 13, 14};
static int spattack(int x, int xx, int yy) {
int i;
int m;
char *p = 0;
int need_beep = 0;
int need_show = 0;
int Attempt;
int Disenchant;
MonsterIdType monst;
vxy(xx, yy); /* verify x & y coordinates */
monst = mitem[xx][yy].mon;
/*
* cancel only works 5% of time for demon prince and god
*/
if (c[CANCELLATION]) {
if (monst >= DEMONPRINCE) {
if (rnd(100) >= 95)
return 0;
} else
return 0;
}
/* staff of power cancels demonlords/wraiths/vampires 75% of time */
/* lucifer is unaffected */
if (monst != LUCIFER) {
if ((monst >= DEMONLORD) || (monst == WRAITH) || (monst == VAMPIRE))
if (player_has_item(OPSTAFF))
if (rnd(100) < 75)
return 0;
}
/* if have cube of undead control, undead monsters do nothing */
if ((monster[monst].flags & FL_UNDEAD) != 0)
if ((c[CUBEofUNDEAD]) || (c[UNDEADPRO]))
return 0;
switch (x) {
case 1:
p = rust_armour();
/* Recalculate the AC and WC */
recalc();
break;
case 2:
i = rnd(15) + 8 - c[AC];
if (c[FIRERESISTANCE])
p = "\nThe %s's flame doesn't faze you!";
else {
p = "\nThe %s breathes fire at you!";
need_beep = 1;
}
checkloss(i);
break;
case 3:
i = rnd(20) + 25 - c[AC];
if (c[FIRERESISTANCE])
p = "\nThe %s's flame doesn't faze you!";
else {
p = "\nThe %s breathes fire at you!";
need_beep = 1;
}
checkloss(i);
break;
case 4:
if (c[STRENGTH] > 3) {
p = "\nThe %s stung you! You feel weaker.";
need_beep = 1;
adjust_ability(STRENGTH, -1);
} else
p = "\nThe %s stung you!";
break;
case 5:
p = "\nThe %s blasts you with his cold breath.";
i = rnd(15) + 18 - c[AC];
need_beep = 1;
checkloss(i);
break;
case 6:
if (player_has_item(OLIFEPRESERVER))
/* Life preserver prevents all drain life attacks */
return 0;
p = "\nThe %s drains you of your life energy!";
loselevel();
if (monst == DEMONPRINCE)
losemspells(1);
if (monst == LUCIFER) {
loselevel();
losemspells(2);
for (i = STRENGTH; i <= DEXTERITY; i++)
adjust_ability(i, -1);
}
need_beep = 1;
break;
case 7:
p = "\nThe %s got you with a gusher!";
i = rnd(15) + 25 - c[AC];
need_beep = 1;
checkloss(i);
break;
case 8:
/* he has a device of no theft */
if (c[NOTHEFT])
return 0;
if (c[GOLD]) {
p = "\nThe %s hit you. Your purse feels lighter.";
if (c[GOLD] > 32767)
c[GOLD] >>= 1;
else
c[GOLD] -= rnd((int)(1 + (c[GOLD] >> 1)));
if (c[GOLD] < 0)
c[GOLD] = 0;
} else
p = "\nThe %s couldn't find any gold to steal.";
disappear(xx, yy);
need_beep = 1;
need_show = 1;
break;
case 9:
/* disenchant */
Attempt = 50;
Disenchant = 0;
while ((Attempt > 0) && (!Disenchant)) {
/* randomly select item */
i = rund(IVENSIZE);
m = iven[i];
if ((m != ONOTHING) && (ivenarg[i] > 0) && (m != OSCROLL) &&
(m != OPOTION)) {
/* This item can be disenchanted */
Disenchant = 3;
if (ivenarg[i] < Disenchant)
Disenchant = ivenarg[i];
adjustivenarg(i, -Disenchant);
p = "\nThe %s hits you with a spell of disenchantment! ";
need_beep = 1;
show3(i);
Disenchant = 1;
}
Attempt--;
}
/*
* Set the message if the disenchant failed.
*/
if (!Disenchant)
p = "\nThe %s nearly misses.";
break;
case 10:
p = "\nThe %s hit you with its barbed tail.";
i = rnd(25) - c[AC];
need_beep = 1;
checkloss(i);
break;
case 11:
if (wizard)
return 0;
p = "\nThe %s has confused you.";
need_beep = 1;
c[CONFUSE] += 10 + rnd(10);
break;
case 12:
/* performs any number of other special attacks */
need_show = spattack(spsel[rund(10)], xx, yy);
break;
case 13:
p = "\nThe %s flattens you with it's psionics!";
i = rnd(15) + 30 - c[AC];
need_beep = 1;
checkloss(i);
break;
case 14:
/* he has device of no theft */
if (c[NOTHEFT])
return 0;
if (emptyhanded() == 1)
p = "\nThe %s couldn't find anything to steal.";
else {
Printf("\nThe %s picks your pocket and takes:", lastmonst);
if (stealsomething(xx, yy) == 0)
Print(" nothing");
teleportmonst(xx, yy, mitem[xx][yy].mon);
need_beep = 1;
need_show = 1;
}
break;
case 15:
i = rnd(10) + 5 - c[AC];
p = "\nThe %s bit you!";
need_beep = 1;
checkloss(i);
break;
case 16:
i = rnd(15) + 10 - c[AC];
p = "\nThe %s bit you!";
need_beep = 1;
checkloss(i);
break;
}
/*
* This attack needs a beep to be played to alert the player
* to bad things.
*/
if (need_beep)
UlarnBeep();
/*
* If a message has been set then display the message
*/
if (p) {
Printf(p, lastmonst);
recalc();
UpdateStatus();
}
return need_show;
}
/* =============================================================================
* FUNCTION:
*
* DESCRIPTION:
* Function to actually perform the monster movement.
* This function sets MovedX & MovedY to the new monster position, or -1
* if the monster was killed or otherwise removed from the level.
*
* PARAMETERS:
*
* sx : The starting x coordinate of the monster
*
* sy : The starting y coordinate of the monster
*
* dx : The destination x coordinate for the monster
*
* dy : The destination y coordinate for the monster
*
* RETURN VALUE:
*
* None.
*/
static void mmove(int sx, int sy, int dx, int dy) {
MonsterIdType monst_id;
int monst_killed = 0;
int have_talisman;
int trap_damage;
int it;
int i;
int n;
char *who;
char *trap_msg;
if ((dx == playerx) && (dy == playery)) {
/* The destination is the player, so the monster attacks */
hitplayer(sx, sy);
moved[sx][sy] = 1;
movedx = sx;
movedy = sy;
return;
}
monst_id = mitem[sx][sy].mon;
it = item[dx][dy];
/* Copy the monster and items it is carrying to the new location */
for (i = 0; i < mitem[sx][sy].n; i++) {
mitem[dx][dy].it[i].item = mitem[sx][sy].it[i].item;
mitem[dx][dy].it[i].itemarg = mitem[sx][sy].it[i].itemarg;
mitem[sx][sy].it[i].item = ONOTHING;
mitem[sx][sy].it[i].itemarg = 0;
}
mitem[dx][dy].n = mitem[sx][sy].n;
mitem[dx][dy].mon = mitem[sx][sy].mon;
/* monsters that move are obviously awake */
stealth[dx][dy] |= STEALTH_AWAKE;
hitp[dx][dy] = hitp[sx][sy];
/* clear the monster from the old location */
mitem[sx][sy].mon = MONST_NONE;
mitem[sx][sy].n = 0;
hitp[sx][sy] = 0;
/* mark this monster as moved */
moved[dx][dy] = 1;
/* perform special processing for monsters */
if (monst_id == LEMMING) {
if (rnd(150) <= 1) {
mitem[sx][sy].mon = LEMMING;
hitp[sx][sy] = hitp[dx][dy];
}
}
if (monst_id == LEPRECHAUN) {
/* leprechaun takes gold and gems */
switch (it) {
case OGOLDPILE:
case OMAXGOLD:
case OKGOLD:
case ODGOLD:
case ODIAMOND:
case ORUBY:
case OEMERALD:
case OSAPPHIRE:
if (mitem[dx][dy].n < 6) {
n = mitem[dx][dy].n;
mitem[dx][dy].it[n].item = item[dx][dy];
mitem[dx][dy].it[n].itemarg = iarg[dx][dy];
mitem[dx][dy].n++;
}
item[dx][dy] = ONOTHING;
iarg[dx][dy] = 0;
break;
default:
break;
}
}
if (monst_id == TROLL) {
/* if a troll regenerate him */
if ((gtime & 1) == 0)
if (monster[monst_id].hitpoints > hitp[dx][dy])
hitp[dx][dy]++;
}
/* check for monsters walking into traps and spheres of annihilation */
trap_damage = 0;
trap_msg = NULL;
who = "";
if (it == OANNIHILATION) {
/* demons dispel spheres */
if (monst_id >= DEMONLORD) {
have_talisman = player_has_item(OSPHTALISMAN);
if ((!have_talisman) ||
(have_talisman && (monst_id == LUCIFER) && (rnd(10) > 7))) {
/* delete the sphere */
trap_msg = "\nThe %s%s dispels the sphere!";
rmsphere(dx, dy);
} else {
/* monster annihilated */
trap_msg = "\nThe %s%s is destroyed by the sphere of annihilation!";
mitem[dx][dy].mon = MONST_NONE;
mitem[dx][dy].n = 0;
hitp[dx][dy] = 0;
monst_killed = 1;
}
} else {
/* monster annihilated */
trap_msg = "\nThe %s%s is destroyed by the sphere of annihilation!";
mitem[dx][dy].mon = MONST_NONE;
mitem[dx][dy].n = 0;
hitp[dx][dy] = 0;
monst_killed = 1;
}
} else if (it == OTRAPARROW) {
who = "An arrow";
trap_damage = rnd(10) + level;
} else if (it == ODARTRAP) {
who = "A dart";
trap_damage = rnd(6);
} else if (it == OTELEPORTER) {
/* monster hits teleport trap */
if (monst_id < DEMONLORD) {
trap_msg = "\nThe %s%s gets teleported.";
teleportmonst(dx, dy, mitem[dx][dy].mon);
dx = movedx;
dy = movedy;
}
} else if (it == OPIT) {
if ((monster[monst_id].flags & FL_FLY) == 0) {
/* non-flying monsters can fall into pits and trap doors */
trap_msg = "\nThe %s%s fell into a pit.";
mitem[dx][dy].mon = MONST_NONE;
hitp[dx][dy] = 0;
monst_killed = 1;
}
} else if (it == OTRAPDOOR) {
if ((monster[monst_id].flags & FL_FLY) == 0) {
/* non-flying monsters can fall into pits and trap doors */
trap_msg = "\nThe %s%s fell through a trapdoor.";
mitem[dx][dy].mon = MONST_NONE;
hitp[dx][dy] = 0;
monst_killed = 1;
}
} else if ((it == OELEVATORUP) || (it == OELEVATORDOWN)) {
/* The monster enters an elevator */
if (monst_id < DEMONLORD) {
trap_msg = "\nThe %s%s is carried away by an elevator!";
mitem[dx][dy].mon = MONST_NONE;
hitp[dx][dy] = 0;
monst_killed = 1;
}
}
if (trap_damage > 0) {
/* the monster was damaged by a trap */
hitp[dx][dy] -= (short)trap_damage;
if (hitp[dx][dy] <= 0) {
/* the trap killed the monster */
mitem[dx][dy].mon = MONST_NONE;
trap_msg = "\n%s hits and kills the %s.";
monst_killed = 1;
} else
trap_msg = "\n%s hits the %s.";
}
/*
* Store the location to which this monster has been moved, or -1 if
* the monster was destroyed
*/
if (monst_killed) {
movedx = -1;
movedy = -1;
} else {
movedx = dx;
movedy = dy;
}
/* if blind don't show where monsters are */
if (c[BLINDCOUNT])
return;
if (know[dx][dy] != OUNKNOWN) {
if (trap_msg != NULL) {
Printf(trap_msg, who, monster[monst_id].name);
UlarnBeep();
}
}
if ((monst_id >= DEMONLORD) && (monst_id <= LUCIFER) && (c[EYEOFLARN] == 0))
/*
* don't update the screen for demonlords and above if the player
* doesn't have the eye of larn as the player can't see the monster.
*/
return;
/* Update the screen */
if (know[sx][sy] != OUNKNOWN)
show1cell(sx, sy);
if (know[dx][dy] != OUNKNOWN)
show1cell(dx, dy);
}
/* =============================================================================
* FUNCTION: valid_monst_move
*
* DESCRIPTION:
* Check if the location x, y is a valid place for monster monst_id to move
* or attack.
* Does NOT check if the location is already occupied by another monster.
*
* PARAMETERS:
*
* x : The x coordinate to check
*
* y : THe y coordinate to check
*
* monst_id : The monster id
*
* RETURN VALUE:
*
* 0 if the monster cannot occupy to this position
* 1 if the monster can occupy to this postion
*/
static int valid_monst_move(int x, int y, MonsterIdType monst_id) {
int tmpitem;
int at_entrance; /* flag indicating that this is the dungeon entrance */
int at_player; /* flag that this is the player's location */
int blocked; /* flag that the monster canot move here (wall etc) */
int monster_special; /* flag that there is a special reason the monster */
/* can't move here */
tmpitem = item[x][y];
at_player = (x == playerx) && (y == playery);
at_entrance = (x == 33) && (y == MAXY - 1) && (level == 1);
/*
* A monster cannot pass through a closed door or a wall.
* However, while a monster cannot hit the player through a closed door
* a monster can hit a player who is walking through walls.
*/
blocked = (tmpitem == OCLOSEDDOOR) || ((tmpitem == OWALL) && !at_player);
/*
* Vampires will not move onto mirrors.
*/
monster_special = (monst_id == VAMPIRE) && (tmpitem == OMIRROR);
if (monst_id >= DEMONPRINCE)
/* walls and closed doors are no hindrance to a demon prince or above */
blocked = 0;
if (at_entrance || blocked || monster_special)
/* Return 0 (false) to indicate illegal position */
return 0;
else
return 1;
}
/* =============================================================================
* FUNCTION: smart_move
*
* DESCRIPTION:
* Function to move smart monsters.
*
* PARAMETERS:
*
* x : The x coordinate of the monster.
*
* y : The y coordinate of the monster.
*
* RETURN VALUE:
*
* None.
*/
static void smart_move(int x, int y) {
int sx, sy;
int xl, yl;
int xh, yh;
int xtmp, ytmp;
int path_dist;
int found_path;
MonsterIdType monst;
int on_map;
int z;
monst = mitem[x][y].mon;
/* get the screen region to check for monster movement */
xl = move_xl - 2;
yl = move_yl - 2;
xh = move_xh + 2;
yh = move_yh + 2;
vxy(xl, yl);
vxy(xh, yh);
for (sy = yl; sy <= yh; sy++) {
for (sx = xl; sx <= xh; sx++) {
if (valid_monst_move(sx, sy, monst)) {
if (monst >= DEMONPRINCE)
/* Monsters of rank DEMONPRICE and above ignore traps etc */
screen[sx][sy] = 0;
else {
/* smart monsters will avoid traps */
switch (item[sx][sy]) {
case OELEVATORUP:
case OELEVATORDOWN:
case OTRAPARROW:
case ODARTRAP:
case OTELEPORTER:
/* all monsters avoid there traps */
screen[sx][sy] = 127;
break;
case OPIT:
case OTRAPDOOR:
if ((monster[monst].flags & FL_FLY) != 0)
/* flying monsters ignore pits and trap doors. */
screen[sx][sy] = 0;
else
screen[sx][sy] = 127;
break;
default:
screen[sx][sy] = 0;
break;
}
}
} else
/* not valid for this monster to move here */
screen[sx][sy] = 127;
/* if valid move */
} /* for sx */