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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
|
/* $OpenBSD: monster.c,v 1.3 1998/09/15 05:12:32 pjanzen Exp $ */
/* $NetBSD: monster.c,v 1.5 1997/10/18 20:03:29 christos Exp $ */
/*
* monster.c Larn is copyrighted 1986 by Noah Morgan.
*
* This file contains the following functions:
* ----------------------------------------------------------------------------
*
* createmonster(monstno) Function to create a monster next to the player
* int monstno;
*
* int cgood(x,y,itm,monst)Function to check location for emptiness
* int x,y,itm,monst;
*
* createitem(it,arg) Routine to place an item next to the player
* int it,arg;
*
* cast() Subroutine called by parse to cast a spell for the user
*
* speldamage(x) Function to perform spell functions cast by the player
* int x;
*
* loseint() Routine to decrement your int (intelligence) if > 3
*
* isconfuse() Routine to check to see if player is confused
*
* nospell(x,monst) Routine to return 1 if a spell doesn't affect a monster
* int x,monst;
*
* fullhit(xx) Function to return full damage against a monst (aka web)
* int xx;
*
* direct(spnum,dam,str,arg)Routine to direct spell damage 1 square in 1 dir
* int spnum,dam,arg;
* char *str;
*
* godirect(spnum,dam,str,delay,cshow) Function to perform missile attacks
* int spnum,dam,delay;
* char *str,cshow;
*
* ifblind(x,y) Routine to put "monster" or the monster name into lastmosnt
* int x,y;
*
* tdirect(spnum) Routine to teleport away a monster
* int spnum;
*
* omnidirect(sp,dam,str) Routine to damage all monsters 1 square from player
* int sp,dam;
* char *str;
*
* dirsub(x,y) Routine to ask for direction, then modify x,y for it
* int *x,*y;
*
* vxy(x,y) Routine to verify/fix (*x,*y) for being within bounds
* int *x,*y;
*
* dirpoly(spnum) Routine to ask for a direction and polymorph a monst
* int spnum;
*
* hitmonster(x,y) Function to hit a monster at the designated coordinates
* int x,y;
*
* hitm(x,y,amt) Function to just hit a monster at a given coordinates
* int x,y,amt;
*
* hitplayer(x,y) Function for the monster to hit the player from (x,y)
* int x,y;
*
* dropsomething(monst) Function to create an object when a monster dies
* int monst;
*
* dropgold(amount) Function to drop some gold around player
* int amount;
*
* something(level) Function to create a random item around player
* int level;
*
* newobject(lev,i) Routine to return a randomly selected new object
* int lev,*i;
*
* spattack(atckno,xx,yy) Function to process special attacks from monsters
* int atckno,xx,yy;
*
* checkloss(x) Routine to subtract hp from user and flag bottomline display
* int x;
*
* annihilate() Routine to annihilate monsters around player, playerx,playery
*
* newsphere(x,y,dir,lifetime) Function to create a new sphere of annihilation
* int x,y,dir,lifetime;
*
* rmsphere(x,y) Function to delete a sphere of annihilation from list
* int x,y;
*
* sphboom(x,y) Function to perform the effects of a sphere detonation
* int x,y;
*
* genmonst() Function to ask for monster and genocide from game
*
*/
#ifndef lint
static char rcsid[] = "$OpenBSD: monster.c,v 1.3 1998/09/15 05:12:32 pjanzen Exp $";
#endif /* not lint */
#include <string.h>
#include <stdlib.h>
#include "header.h"
#include "extern.h"
struct isave { /* used for altar reality */
char type; /* 0=item, 1=monster */
char id; /* item number or monster number */
short arg; /* the type of item or hitpoints of monster */
};
static int dirsub __P((int *, int *));
/*
* createmonster(monstno) Function to create a monster next to the player
* int monstno;
*
* Enter with the monster number (1 to MAXMONST+8)
* Returns no value.
*/
void
createmonster(mon)
int mon;
{
int x, y, k, i;
if (mon < 1 || mon > MAXMONST + 8) { /* check for monster number
* out of bounds */
lbeep();
lprintf("\ncan't createmonst(%d)\n", (long) mon);
nap(3000);
return;
}
while (monster[mon].genocided && mon < MAXMONST)
mon++; /* genocided? */
for (k = rnd(8), i = -8; i < 0; i++, k++) { /* choose direction,
* then try all */
if (k > 8)
k = 1; /* wraparound the diroff arrays */
x = playerx + diroffx[k];
y = playery + diroffy[k];
if (cgood(x, y, 0, 1)) { /* if we can create here */
mitem[x][y] = mon;
hitp[x][y] = monster[mon].hitpoints;
stealth[x][y] = know[x][y] = 0;
switch (mon) {
case ROTHE:
case POLTERGEIST:
case VAMPIRE:
stealth[x][y] = 1;
};
return;
}
}
}
/*
* int cgood(x,y,itm,monst) Function to check location for emptiness
* int x,y,itm,monst;
*
* Routine to return TRUE if a location does not have itm or monst there
* returns FALSE (0) otherwise
* Enter with itm or monst TRUE or FALSE if checking it
* Example: if itm==TRUE check for no item at this location
* if monst==TRUE check for no monster at this location
* This routine will return FALSE if at a wall or the dungeon exit on level 1
*/
int
cgood(x, y, itm, monst)
int x, y;
int itm, monst;
{
if ((y >= 0) && (y <= MAXY - 1) && (x >= 0) && (x <= MAXX - 1))
/* within bounds? */
if (item[x][y] != OWALL) /* can't make anything on walls */
/* is it free of items? */
if (itm == 0 || (item[x][y] == 0))
/* is it free of monsters? */
if (monst == 0 || (mitem[x][y] == 0))
if ((level != 1) || (x != 33) ||
(y != MAXY - 1))
/* not exit to level 1 */
return (1);
return (0);
}
/*
* createitem(it,arg) Routine to place an item next to the player
* int it,arg;
*
* Enter with the item number and its argument (iven[], ivenarg[])
* Returns no value, thus we don't know about createitem() failures.
*/
void
createitem(it, arg)
int it, arg;
{
int x, y, k, i;
if (it >= MAXOBJ)
return; /* no such object */
for (k = rnd(8), i = -8; i < 0; i++, k++) { /* choose direction,
* then try all */
if (k > 8)
k = 1; /* wraparound the diroff arrays */
x = playerx + diroffx[k];
y = playery + diroffy[k];
if (cgood(x, y, 1, 0)) { /* if we can create here */
item[x][y] = it;
know[x][y] = 0;
iarg[x][y] = arg;
return;
}
}
}
/*
* cast() Subroutine called by parse to cast a spell for the user
*
* No arguments and no return value.
*/
static char eys[] = "\nEnter your spell: ";
void
cast()
{
int i, j, a, b, d;
cursors();
if (c[SPELLS] <= 0) {
lprcat("\nYou don't have any spells!");
return;
}
lprcat(eys);
--c[SPELLS];
while ((a = lgetchar()) == 'D') {
seemagic(-1);
cursors();
lprcat(eys);
}
if (a == '\33')
goto over; /* to escape casting a spell */
if ((b = lgetchar()) == '\33')
goto over; /* to escape casting a spell */
if ((d = lgetchar()) == '\33') {
over: lprcat(aborted);
c[SPELLS]++;
return;
} /* to escape casting a spell */
#ifdef EXTRA
c[SPELLSCAST]++;
#endif
for (lprc('\n'), j = -1, i = 0; i < SPNUM; i++) /* seq search for his
* spell, hash? */
if ((spelcode[i][0] == a) && (spelcode[i][1] == b) && (spelcode[i][2] == d))
if (spelknow[i]) {
speldamage(i);
j = 1;
i = SPNUM;
}
if (j == -1)
lprcat(" Nothing Happened ");
bottomline();
}
/*
* speldamage(x) Function to perform spell functions cast by the player
* int x;
*
* Enter with the spell number, returns no value.
* Please insure that there are 2 spaces before all messages here
*/
void
speldamage(x)
int x;
{
int i, j, clev;
int xl, xh, yl, yh;
char *p, *kn, *pm;
if (x >= SPNUM)
return; /* no such spell */
if (c[TIMESTOP]) {
lprcat(" It didn't seem to work");
return;
} /* not if time stopped */
clev = c[LEVEL];
if ((rnd(23) == 7) || (rnd(18) > c[INTELLIGENCE])) {
lprcat(" It didn't work!");
return;
}
if (clev * 3 + 2 < x) {
lprcat(" Nothing happens. You seem inexperienced at this");
return;
}
switch (x) {
/* ----- LEVEL 1 SPELLS ----- */
case 0:
if (c[PROTECTIONTIME] == 0)
c[MOREDEFENSES] += 2; /* protection field +2 */
c[PROTECTIONTIME] += 250;
return;
case 1:
i = rnd(((clev + 1) << 1)) + clev + 3;
godirect(x, i, (clev >= 2) ? " Your missiles hit the %s" : " Your missile hit the %s", 100, '+'); /* magic missile */
return;
case 2:
if (c[DEXCOUNT] == 0)
c[DEXTERITY] += 3; /* dexterity */
c[DEXCOUNT] += 400;
return;
case 3:
i = rnd(3) + 1;
p = " While the %s slept, you smashed it %d times";
ws: direct(x, fullhit(i), p, i); /* sleep */
return;
case 4: /* charm monster */
c[CHARMCOUNT] += c[CHARISMA] << 1;
return;
case 5:
godirect(x, rnd(10) + 15 + clev, " The sound damages the %s", 70, '@'); /* sonic spear */
return;
/* ----- LEVEL 2 SPELLS ----- */
case 6:
i = rnd(3) + 2;
p = " While the %s is entangled, you hit %d times";
goto ws; /* web */
case 7:
if (c[STRCNT] == 0)
c[STREXTRA] += 3; /* strength */
c[STRCNT] += 150 + rnd(100);
return;
case 8:
yl = playery - 5; /* enlightenment */
yh = playery + 6;
xl = playerx - 15;
xh = playerx + 16;
vxy(&xl, &yl);
vxy(&xh, &yh); /* check bounds */
for (i = yl; i <= yh; i++) /* enlightenment */
for (j = xl; j <= xh; j++)
know[j][i] = 1;
draws(xl, xh + 1, yl, yh + 1);
return;
case 9:
raisehp(20 + (clev << 1));
return; /* healing */
case 10:
c[BLINDCOUNT] = 0;
return; /* cure blindness */
case 11:
createmonster(makemonst(level + 1) + 8);
return;
case 12:
if (rnd(11) + 7 <= c[WISDOM])
direct(x, rnd(20) + 20 + clev, " The %s believed!", 0);
else
lprcat(" It didn't believe the illusions!");
return;
case 13: /* if he has the amulet of invisibility then
* add more time */
for (j = i = 0; i < 26; i++)
if (iven[i] == OAMULET)
j += 1 + ivenarg[i];
c[INVISIBILITY] += (j << 7) + 12;
return;
/* ----- LEVEL 3 SPELLS ----- */
case 14:
godirect(x, rnd(25 + clev) + 25 + clev, " The fireball hits the %s", 40, '*');
return; /* fireball */
case 15:
godirect(x, rnd(25) + 20 + clev, " Your cone of cold strikes the %s", 60, 'O'); /* cold */
return;
case 16:
dirpoly(x);
return; /* polymorph */
case 17:
c[CANCELLATION] += 5 + clev;
return; /* cancellation */
case 18:
c[HASTESELF] += 7 + clev;
return; /* haste self */
case 19:
omnidirect(x, 30 + rnd(10), " The %s gasps for air"); /* cloud kill */
return;
case 20:
xh = min(playerx + 1, MAXX - 2);
yh = min(playery + 1, MAXY - 2);
for (i = max(playerx - 1, 1); i <= xh; i++) /* vaporize rock */
for (j = max(playery - 1, 1); j <= yh; j++) {
kn = &know[i][j];
pm = &mitem[i][j];
switch (*(p = &item[i][j])) {
case OWALL:
if (level < MAXLEVEL + MAXVLEVEL - 1)
*p = *kn = 0;
break;
case OSTATUE:
if (c[HARDGAME] < 3) {
*p = OBOOK;
iarg[i][j] = level;
*kn = 0;
}
break;
case OTHRONE:
*pm = GNOMEKING;
*kn = 0;
*p = OTHRONE2;
hitp[i][j] = monster[GNOMEKING].hitpoints;
break;
case OALTAR:
*pm = DEMONPRINCE;
*kn = 0;
hitp[i][j] = monster[DEMONPRINCE].hitpoints;
break;
};
switch (*pm) {
case XORN:
ifblind(i, j);
hitm(i, j, 200);
break; /* Xorn takes damage from vpr */
}
}
return;
/* ----- LEVEL 4 SPELLS ----- */
case 21:
direct(x, 100 + clev, " The %s shrivels up", 0); /* dehydration */
return;
case 22:
godirect(x, rnd(25) + 20 + (clev << 1), " A lightning bolt hits the %s", 1, '~'); /* lightning */
return;
case 23:
i = min(c[HP] - 1, c[HPMAX] / 2); /* drain life */
direct(x, i + i, "", 0);
c[HP] -= i;
return;
case 24:
if (c[GLOBE] == 0)
c[MOREDEFENSES] += 10;
c[GLOBE] += 200;
loseint(); /* globe of invulnerability */
return;
case 25:
omnidirect(x, 32 + clev, " The %s struggles for air in your flood!"); /* flood */
return;
case 26:
if (rnd(151) == 63) {
lbeep();
lprcat("\nYour heart stopped!\n");
nap(4000);
died(270);
return;
}
if (c[WISDOM] > rnd(10) + 10)
direct(x, 2000, " The %s's heart stopped", 0); /* finger of death */
else
lprcat(" It didn't work");
return;
/* ----- LEVEL 5 SPELLS ----- */
case 27:
c[SCAREMONST] += rnd(10) + clev;
return; /* scare monster */
case 28:
c[HOLDMONST] += rnd(10) + clev;
return; /* hold monster */
case 29:
c[TIMESTOP] += rnd(20) + (clev << 1);
return; /* time stop */
case 30:
tdirect(x);
return; /* teleport away */
case 31:
omnidirect(x, 35 + rnd(10) + clev, " The %s cringes from the flame"); /* magic fire */
return;
/* ----- LEVEL 6 SPELLS ----- */
case 32:
if ((rnd(23) == 5) && (wizard == 0)) { /* sphere of
* annihilation */
lbeep();
lprcat("\nYou have been enveloped by the zone of nothingness!\n");
nap(4000);
died(258);
return;
}
xl = playerx;
yl = playery;
loseint();
i = dirsub(&xl, &yl); /* get direction of sphere */
newsphere(xl, yl, i, rnd(20) + 11); /* make a sphere */
return;
case 33:
genmonst();
spelknow[33] = 0; /* genocide */
loseint();
return;
case 34: /* summon demon */
if (rnd(100) > 30) {
direct(x, 150, " The demon strikes at the %s", 0);
return;
}
if (rnd(100) > 15) {
lprcat(" Nothing seems to have happened");
return;
}
lprcat(" The demon turned on you and vanished!");
lbeep();
i = rnd(40) + 30;
lastnum = 277;
losehp(i); /* must say killed by a demon */
return;
case 35: /* walk through walls */
c[WTW] += rnd(10) + 5;
return;
case 36: /* alter reality */
{
struct isave *save; /* pointer to item save
* structure */
int sc;
sc = 0; /* # items saved */
save = (struct isave *) malloc(sizeof(struct isave) * MAXX * MAXY * 2);
for (j = 0; j < MAXY; j++)
for (i = 0; i < MAXX; i++) { /* save all items and
* monsters */
xl = item[i][j];
if (xl && xl != OWALL && xl != OANNIHILATION) {
save[sc].type = 0;
save[sc].id = item[i][j];
save[sc++].arg = iarg[i][j];
}
if (mitem[i][j]) {
save[sc].type = 1;
save[sc].id = mitem[i][j];
save[sc++].arg = hitp[i][j];
}
item[i][j] = OWALL;
mitem[i][j] = 0;
if (wizard)
know[i][j] = 1;
else
know[i][j] = 0;
}
eat(1, 1);
if (level == 1)
item[33][MAXY - 1] = 0;
for (j = rnd(MAXY - 2), i = 1; i < MAXX - 1; i++)
item[i][j] = 0;
while (sc > 0) { /* put objects back in level */
--sc;
if (save[sc].type == 0) {
int trys;
for (trys = 100, i = j = 1; --trys > 0 && item[i][j]; i = rnd(MAXX - 1), j = rnd(MAXY - 1));
if (trys) {
item[i][j] = save[sc].id;
iarg[i][j] = save[sc].arg;
}
} else { /* put monsters back in */
int trys;
for (trys = 100, i = j = 1; --trys > 0 && (item[i][j] == OWALL || mitem[i][j]); i = rnd(MAXX - 1), j = rnd(MAXY - 1));
if (trys) {
mitem[i][j] = save[sc].id;
hitp[i][j] = save[sc].arg;
}
}
}
loseint();
draws(0, MAXX, 0, MAXY);
if (wizard == 0)
spelknow[36] = 0;
free((char *) save);
positionplayer();
return;
}
case 37: /* permanence */
adjusttime(-99999L);
spelknow[37] = 0; /* forget */
loseint();
return;
default:
lprintf(" spell %d not available!", (long) x);
lbeep();
return;
};
}
/*
* loseint() Routine to subtract 1 from your int (intelligence) if > 3
*
* No arguments and no return value
*/
void
loseint()
{
if (--c[INTELLIGENCE] < 3)
c[INTELLIGENCE] = 3;
}
/*
* isconfuse() Routine to check to see if player is confused
*
* This routine prints out a message saying "You can't aim your magic!"
* returns 0 if not confused, non-zero (time remaining confused) if confused
*/
int
isconfuse()
{
if (c[CONFUSE]) {
lprcat(" You can't aim your magic!");
lbeep();
}
return (c[CONFUSE]);
}
/*
* nospell(x,monst) Routine to return 1 if a spell doesn't affect a monster
* int x,monst;
*
* Subroutine to return 1 if the spell can't affect the monster
* otherwise returns 0
* Enter with the spell number in x, and the monster number in monst.
*/
int
nospell(x, monst)
int x, monst;
{
int tmp;
if (x >= SPNUM || monst >= MAXMONST + 8 || monst < 0 || x < 0)
return (0); /* bad spell or monst */
if ((tmp = spelweird[monst - 1][x]) == 0)
return (0);
cursors();
lprc('\n');
lprintf(spelmes[tmp], monster[monst].name);
return (1);
}
/*
* fullhit(xx) Function to return full damage against a monster (aka web)
* int xx;
*
* Function to return hp damage to monster due to a number of full hits
* Enter with the number of full hits being done
*/
int
fullhit(xx)
int xx;
{
int i;
if (xx < 0 || xx > 20)
return (0); /* fullhits are out of range */
if (c[LANCEDEATH])
return (10000); /* lance of death */
i = xx * ((c[WCLASS] >> 1) + c[STRENGTH] + c[STREXTRA] - c[HARDGAME] - 12 + c[MOREDAM]);
return ((i >= 1) ? i : xx);
}
/*
* direct(spnum,dam,str,arg) Routine to direct spell damage 1 square in 1 dir
* int spnum,dam,arg;
* char *str;
*
* Routine to ask for a direction to a spell and then hit the monster
* Enter with the spell number in spnum, the damage to be done in dam,
* lprintf format string in str, and lprintf's argument in arg.
* Returns no value.
*/
void
direct(spnum, dam, str, arg)
int spnum, dam, arg;
char *str;
{
int x, y;
int m;
if (spnum < 0 || spnum >= SPNUM || str == 0)
return; /* bad arguments */
if (isconfuse())
return;
dirsub(&x, &y);
m = mitem[x][y];
if (item[x][y] == OMIRROR) {
if (spnum == 3) { /* sleep */
lprcat("You fall asleep! ");
lbeep();
fool:
arg += 2;
while (arg-- > 0) {
parse2();
nap(1000);
}
return;
} else if (spnum == 6) { /* web */
lprcat("You get stuck in your own web! ");
lbeep();
goto fool;
} else {
lastnum = 278;
lprintf(str, "spell caster (thats you)", (long) arg);
lbeep();
losehp(dam);
return;
}
}
if (m == 0) {
lprcat(" There wasn't anything there!");
return;
}
ifblind(x, y);
if (nospell(spnum, m)) {
lasthx = x;
lasthy = y;
return;
}
lprintf(str, lastmonst, (long) arg);
hitm(x, y, dam);
}
/*
* godirect(spnum,dam,str,delay,cshow) Function to perform missile attacks
* int spnum,dam,delay;
* char *str,cshow;
*
* Function to hit in a direction from a missile weapon and have it keep
* on going in that direction until its power is exhausted
* Enter with the spell number in spnum, the power of the weapon in hp,
* lprintf format string in str, the # of milliseconds to delay between
* locations in delay, and the character to represent the weapon in cshow.
* Returns no value.
*/
void
godirect(spnum, dam, str, delay, cshow)
int spnum, dam, delay;
char *str, cshow;
{
char *p;
int x, y, m;
int dx, dy;
if (spnum < 0 || spnum >= SPNUM || str == 0 || delay < 0)
return; /* bad args */
if (isconfuse())
return;
dirsub(&dx, &dy);
x = dx;
y = dy;
dx = x - playerx;
dy = y - playery;
x = playerx;
y = playery;
while (dam > 0) {
x += dx;
y += dy;
if ((x > MAXX - 1) || (y > MAXY - 1) || (x < 0) || (y < 0)) {
dam = 0;
break; /* out of bounds */
}
if ((x == playerx) && (y == playery)) { /* if energy hits player */
cursors();
lprcat("\nYou are hit my your own magic!");
lbeep();
lastnum = 278;
losehp(dam);
return;
}
if (c[BLINDCOUNT] == 0) { /* if not blind show effect */
cursor(x + 1, y + 1);
lprc(cshow);
nap(delay);
show1cell(x, y);
}
if ((m = mitem[x][y])) { /* is there a monster there? */
ifblind(x, y);
if (nospell(spnum, m)) {
lasthx = x;
lasthy = y;
return;
}
cursors();
lprc('\n');
lprintf(str, lastmonst);
dam -= hitm(x, y, dam);
show1cell(x, y);
nap(1000);
x -= dx;
y -= dy;
} else
switch (*(p = &item[x][y])) {
case OWALL:
cursors();
lprc('\n');
lprintf(str, "wall");
if (dam >= 50 + c[HARDGAME]) /* enough damage? */
if (level < MAXLEVEL + MAXVLEVEL - 1) /* not on V3 */
if ((x < MAXX - 1) && (y < MAXY - 1) && (x) && (y)) {
lprcat(" The wall crumbles");
god3: *p = 0;
god: know[x][y] = 0;
show1cell(x, y);
}
god2: dam = 0;
break;
case OCLOSEDDOOR:
cursors();
lprc('\n');
lprintf(str, "door");
if (dam >= 40) {
lprcat(" The door is blasted apart");
goto god3;
}
goto god2;
case OSTATUE:
cursors();
lprc('\n');
lprintf(str, "statue");
if (c[HARDGAME] < 3)
if (dam > 44) {
lprcat(" The statue crumbles");
*p = OBOOK;
iarg[x][y] = level;
goto god;
}
goto god2;
case OTHRONE:
cursors();
lprc('\n');
lprintf(str, "throne");
if (dam > 39) {
mitem[x][y] = GNOMEKING;
hitp[x][y] = monster[GNOMEKING].hitpoints;
*p = OTHRONE2;
goto god;
}
goto god2;
case OMIRROR:
dx *= -1;
dy *= -1;
break;
};
dam -= 3 + (c[HARDGAME] >> 1);
}
}
/*
* ifblind(x,y) Routine to put "monster" or the monster name into lastmosnt
* int x,y;
*
* Subroutine to copy the word "monster" into lastmonst if the player is blind
* Enter with the coordinates (x,y) of the monster
* Returns no value.
*/
void
ifblind(x, y)
int x, y;
{
char *p;
vxy(&x, &y); /* verify correct x,y coordinates */
if (c[BLINDCOUNT]) {
lastnum = 279;
p = "monster";
} else {
lastnum = mitem[x][y];
p = monster[lastnum].name;
}
strcpy(lastmonst, p);
}
/*
* tdirect(spnum) Routine to teleport away a monster
* int spnum;
*
* Routine to ask for a direction to a spell and then teleport away monster
* Enter with the spell number that wants to teleport away
* Returns no value.
*/
void
tdirect(spnum)
int spnum;
{
int x, y;
int m;
if (spnum < 0 || spnum >= SPNUM)
return; /* bad args */
if (isconfuse())
return;
dirsub(&x, &y);
if ((m = mitem[x][y]) == 0) {
lprcat(" There wasn't anything there!");
return;
}
ifblind(x, y);
if (nospell(spnum, m)) {
lasthx = x;
lasthy = y;
return;
}
fillmonst(m);
mitem[x][y] = know[x][y] = 0;
}
/*
* omnidirect(sp,dam,str) Routine to damage all monsters 1 square from player
* int sp,dam;
* char *str;
*
* Routine to cast a spell and then hit the monster in all directions
* Enter with the spell number in sp, the damage done to wach square in dam,
* and the lprintf string to identify the spell in str.
* Returns no value.
*/
void
omnidirect(spnum, dam, str)
int spnum, dam;
char *str;
{
int x, y, m;
if (spnum < 0 || spnum >= SPNUM || str == 0)
return; /* bad args */
for (x = playerx - 1; x < playerx + 2; x++)
for (y = playery - 1; y < playery + 2; y++) {
if ((m = mitem[x][y]) != 0) {
if (nospell(spnum, m) == 0) {
ifblind(x, y);
cursors();
lprc('\n');
lprintf(str, lastmonst);
hitm(x, y, dam);
nap(800);
} else {
lasthx = x;
lasthy = y;
}
}
}
}
/*
* static dirsub(x,y) Routine to ask for direction, then modify x,y for it
* int *x,*y;
*
* Function to ask for a direction and modify an x,y for that direction
* Enter with the origination coordinates in (x,y).
* Returns index into diroffx[] (0-8).
*/
static int
dirsub(x, y)
int *x, *y;
{
int i;
lprcat("\nIn What Direction? ");
for (i = 0;;)
switch (lgetchar()) {
case 'b':
i++;
case 'n':
i++;
case 'y':
i++;
case 'u':
i++;
case 'h':
i++;
case 'k':
i++;
case 'l':
i++;
case 'j':
i++;
goto out;
};
out:
*x = playerx + diroffx[i];
*y = playery + diroffy[i];
vxy(x, y);
return (i);
}
/*
* vxy(x,y) Routine to verify/fix coordinates for being within bounds
* int *x,*y;
*
* Function to verify x & y are within the bounds for a level
* If *x or *y is not within the absolute bounds for a level, fix them so that
* they are on the level.
* Returns TRUE if it was out of bounds, and the *x & *y in the calling
* routine are affected.
*/
int
vxy(x, y)
int *x, *y;
{
int flag = 0;
if (*x < 0) {
*x = 0;
flag++;
}
if (*y < 0) {
*y = 0;
flag++;
}
if (*x >= MAXX) {
*x = MAXX - 1;
flag++;
}
if (*y >= MAXY) {
*y = MAXY - 1;
flag++;
}
return (flag);
}
/*
* dirpoly(spnum) Routine to ask for a direction and polymorph a monst
* int spnum;
*
* Subroutine to polymorph a monster and ask for the direction its in
* Enter with the spell number in spmun.
* Returns no value.
*/
void
dirpoly(spnum)
int spnum;
{
int x, y, m;
if (spnum < 0 || spnum >= SPNUM)
return; /* bad args */
if (isconfuse())
return; /* if he is confused, he can't aim his magic */
dirsub(&x, &y);
if (mitem[x][y] == 0) {
lprcat(" There wasn't anything there!");
return;
}
ifblind(x, y);
if (nospell(spnum, mitem[x][y])) {
lasthx = x;
lasthy = y;
return;
}
while (monster[m = mitem[x][y] = rnd(MAXMONST + 7)].genocided);
hitp[x][y] = monster[m].hitpoints;
show1cell(x, y); /* show the new monster */
}
/*
* hitmonster(x,y) Function to hit a monster at the designated coordinates
* int x,y;
*
* This routine is used for a bash & slash type attack on a monster
* Enter with the coordinates of the monster in (x,y).
* Returns no value.
*/
void
hitmonster(x, y)
int x, y;
{
int tmp, monst, damag = 0, flag;
if (c[TIMESTOP])
return; /* not if time stopped */
vxy(&x, &y); /* verify coordinates are within range */
if ((monst = mitem[x][y]) == 0)
return;
hit3flag = 1;
ifblind(x, y);
tmp = monster[monst].armorclass + c[LEVEL] + c[DEXTERITY] +
c[WCLASS] / 4 - 12;
cursors();
/* need at least random chance to hit */
if ((rnd(20) < tmp - c[HARDGAME]) || (rnd(71) < 5)) {
lprcat("\nYou hit");
flag = 1;
damag = fullhit(1);
if (damag < 9999)
damag = rnd(damag) + 1;
} else {
lprcat("\nYou missed");
flag = 0;
}
lprcat(" the ");
lprcat(lastmonst);
if (flag) /* if the monster was hit */
if ((monst == RUSTMONSTER) || (monst == DISENCHANTRESS) || (monst == CUBE))
if (c[WIELD] > 0)
if (ivenarg[c[WIELD]] > -10) {
lprintf("\nYour weapon is dulled by the %s", lastmonst);
lbeep();
--ivenarg[c[WIELD]];
}
if (flag)
hitm(x, y, damag);
if (monst == VAMPIRE)
if (hitp[x][y] < 25) {
mitem[x][y] = BAT;
know[x][y] = 0;
}
}
/*
* hitm(x,y,amt) Function to just hit a monster at a given coordinates
* int x,y,amt;
*
* Returns the number of hitpoints the monster absorbed
* This routine is used to specifically damage a monster at a location (x,y)
* Called by hitmonster(x,y)
*/
int
hitm(x, y, amt)
int x, y;
int amt;
{
int monst;
int hpoints, amt2;
vxy(&x, &y); /* verify coordinates are within range */
amt2 = amt; /* save initial damage so we can return it */
monst = mitem[x][y];
if (c[HALFDAM])
amt >>= 1; /* if half damage curse adjust damage points */
if (amt <= 0)
amt2 = amt = 1;
lasthx = x;
lasthy = y;
stealth[x][y] = 1; /* make sure hitting monst breaks stealth
* condition */
c[HOLDMONST] = 0; /* hit a monster breaks hold monster spell */
switch (monst) { /* if a dragon and orb(s) of dragon slaying */
case WHITEDRAGON:
case REDDRAGON:
case GREENDRAGON:
case BRONZEDRAGON:
case PLATINUMDRAGON:
case SILVERDRAGON:
amt *= 1 + (c[SLAYING] << 1);
break;
}
/* invincible monster fix is here */
if (hitp[x][y] > monster[monst].hitpoints)
hitp[x][y] = monster[monst].hitpoints;
if ((hpoints = hitp[x][y]) <= amt) {
#ifdef EXTRA
c[MONSTKILLED]++;
#endif
lprintf("\nThe %s died!", lastmonst);
raiseexperience((long) monster[monst].experience);
amt = monster[monst].gold;
if (amt > 0)
dropgold(rnd(amt) + amt);
dropsomething(monst);
disappear(x, y);
bottomline();
return (hpoints);
}
hitp[x][y] = hpoints - amt;
return (amt2);
}
/*
* hitplayer(x,y) Function for the monster to hit the player from (x,y)
* int x,y;
*
* Function for the monster to hit the player with monster at location x,y
* Returns nothing of value.
*/
void
hitplayer(x, y)
int x, y;
{
int dam, tmp, mster, bias;
vxy(&x, &y); /* verify coordinates are within range */
lastnum = mster = mitem[x][y];
/*
* spirit naga's and poltergeist's do nothing if scarab of negate
* spirit
*/
if (c[NEGATESPIRIT] || c[SPIRITPRO])
if ((mster == POLTERGEIST) || (mster == SPIRITNAGA))
return;
/* if undead and cube of undead control */
if (c[CUBEofUNDEAD] || c[UNDEADPRO])
if ((mster == VAMPIRE) || (mster == WRAITH) || (mster == ZOMBIE))
return;
if ((know[x][y] & 1) == 0) {
know[x][y] = 1;
show1cell(x, y);
}
bias = (c[HARDGAME]) + 1;
hitflag = hit2flag = hit3flag = 1;
yrepcount = 0;
cursors();
ifblind(x, y);
if (c[INVISIBILITY])
if (rnd(33) < 20) {
lprintf("\nThe %s misses wildly", lastmonst);
return;
}
if (c[CHARMCOUNT])
if (rnd(30) + 5 * monster[mster].level - c[CHARISMA] < 30) {
lprintf("\nThe %s is awestruck at your magnificence!", lastmonst);
return;
}
if (mster == BAT)
dam = 1;
else {
dam = monster[mster].damage;
dam += rnd((int) ((dam < 1) ? 1 : dam)) + monster[mster].level;
}
tmp = 0;
if (monster[mster].attack > 0)
if (((dam + bias + 8) > c[AC]) || (rnd((int) ((c[AC] > 0) ? c[AC] : 1)) == 1)) {
if (spattack(monster[mster].attack, x, y)) {
flushall();
return;
}
tmp = 1;
bias -= 2;
cursors();
}
if (((dam + bias) > c[AC]) || (rnd((int) ((c[AC] > 0) ? c[AC] : 1)) == 1)) {
lprintf("\n The %s hit you ", lastmonst);
tmp = 1;
if ((dam -= c[AC]) < 0)
dam = 0;
if (dam > 0) {
losehp(dam);
bottomhp();
flushall();
}
}
if (tmp == 0)
lprintf("\n The %s missed ", lastmonst);
}
/*
* dropsomething(monst) Function to create an object when a monster dies
* int monst;
*
* Function to create an object near the player when certain monsters are killed
* Enter with the monster number
* Returns nothing of value.
*/
void
dropsomething(monst)
int monst;
{
switch (monst) {
case ORC:
case NYMPH:
case ELF:
case TROGLODYTE:
case TROLL:
case ROTHE:
case VIOLETFUNGI:
case PLATINUMDRAGON:
case GNOMEKING:
case REDDRAGON:
something(level);
return;
case LEPRECHAUN:
if (rnd(101) >= 75)
creategem();
if (rnd(5) == 1)
dropsomething(LEPRECHAUN);
return;
}
}
/*
* dropgold(amount) Function to drop some gold around player
* int amount;
*
* Enter with the number of gold pieces to drop
* Returns nothing of value.
*/
void
dropgold(amount)
int amount;
{
if (amount > 250)
createitem(OMAXGOLD, amount / 100);
else
createitem(OGOLDPILE, amount);
}
/*
* something(level) Function to create a random item around player
* int level;
*
* Function to create an item from a designed probability around player
* Enter with the cave level on which something is to be dropped
* Returns nothing of value.
*/
void
something(level)
int level;
{
int j;
int i;
if (level < 0 || level > MAXLEVEL + MAXVLEVEL)
return; /* correct level? */
if (rnd(101) < 8)
something(level); /* possibly more than one item */
j = newobject(level, &i);
createitem(j, i);
}
/*
* newobject(lev,i) Routine to return a randomly selected new object
* int lev,*i;
*
* Routine to return a randomly selected object to be created
* Returns the object number created, and sets *i for its argument
* Enter with the cave level and a pointer to the items arg
*/
static char nobjtab[] = {
0, OSCROLL, OSCROLL, OSCROLL, OSCROLL, OPOTION, OPOTION,
OPOTION, OPOTION, OGOLDPILE, OGOLDPILE, OGOLDPILE, OGOLDPILE,
OBOOK, OBOOK, OBOOK, OBOOK, ODAGGER, ODAGGER, ODAGGER,
OLEATHER, OLEATHER, OLEATHER, OREGENRING, OPROTRING,
OENERGYRING, ODEXRING, OSTRRING, OSPEAR, OBELT, ORING,
OSTUDLEATHER, OSHIELD, OFLAIL, OCHAIN, O2SWORD, OPLATE,
OLONGSWORD};
int
newobject(lev, i)
int lev, *i;
{
int tmp = 32, j;
if (level < 0 || level > MAXLEVEL + MAXVLEVEL)
return (0); /* correct level? */
if (lev > 6)
tmp = 37;
else if (lev > 4)
tmp = 35;
j = nobjtab[tmp = rnd(tmp)]; /* the object type */
switch (tmp) {
case 1:
case 2:
case 3:
case 4:
*i = newscroll();
break;
case 5:
case 6:
case 7:
case 8:
*i = newpotion();
break;
case 9:
case 10:
case 11:
case 12:
*i = rnd((lev + 1) * 10) + lev * 10 + 10;
break;
case 13:
case 14:
case 15:
case 16:
*i = lev;
break;
case 17:
case 18:
case 19:
if (!(*i = newdagger()))
return (0);
break;
case 20:
case 21:
case 22:
if (!(*i = newleather()))
return (0);
break;
case 23:
case 32:
case 35:
*i = rund(lev / 3 + 1);
break;
case 24:
case 26:
*i = rnd(lev / 4 + 1);
break;
case 25:
*i = rund(lev / 4 + 1);
break;
case 27:
*i = rnd(lev / 2 + 1);
break;
case 30:
case 33:
*i = rund(lev / 2 + 1);
break;
case 28:
*i = rund(lev / 3 + 1);
if (*i == 0)
return (0);
break;
case 29:
case 31:
*i = rund(lev / 2 + 1);
if (*i == 0)
return (0);
break;
case 34:
*i = newchain();
break;
case 36:
*i = newplate();
break;
case 37:
*i = newsword();
break;
}
return (j);
}
/*
* spattack(atckno,xx,yy) Function to process special attacks from monsters
* int atckno,xx,yy;
*
* Enter with the special attack number, and the coordinates (xx,yy)
* of the monster that is special attacking
* Returns 1 if must do a show1cell(xx,yy) upon return, 0 otherwise
*
* atckno monster effect
* ---------------------------------------------------
* 0 none
* 1 rust monster eat armor
* 2 hell hound breathe light fire
* 3 dragon breathe fire
* 4 giant centipede weakening sing
* 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 bite
*
* char rustarm[ARMORTYPES][2];
* special array for maximum rust damage to armor from rustmonster
* format is: { armor type , minimum attribute
*/
#define ARMORTYPES 6
static char rustarm[ARMORTYPES][2] = {
{ OSTUDLEATHER, -2 },
{ ORING, -4 },
{ OCHAIN, -5 },
{ OSPLINT, -6 },
{ OPLATE, -8 },
{ OPLATEARMOR, -9}
};
static char spsel[] = {1, 2, 3, 5, 6, 8, 9, 11, 13, 14};
int
spattack(x, xx, yy)
int x, xx, yy;
{
int i, j = 0, k, m;
char *p = 0;
if (c[CANCELLATION])
return (0);
vxy(&xx, &yy); /* verify x & y coordinates */
switch (x) {
case 1: /* rust your armor, j=1 when rusting has occurred */
m = k = c[WEAR];
if ((i = c[SHIELD]) != -1) {
if (--ivenarg[i] < -1)
ivenarg[i] = -1;
else
j = 1;
}
if ((j == 0) && (k != -1)) {
m = iven[k];
for (i = 0; i < ARMORTYPES; i++)
/* find his armor in table */
if (m == rustarm[i][0]) {
if (--ivenarg[k] < rustarm[i][1])
ivenarg[k] = rustarm[i][1];
else
j = 1;
break;
}
}
if (j == 0) /* if rusting did not occur */
switch (m) {
case OLEATHER:
p = "\nThe %s hit you -- You're lucky you have leather on";
break;
case OSSPLATE:
p = "\nThe %s hit you -- You're fortunate to have stainless steel armor!";
break;
}
else {
lbeep();
p = "\nThe %s hit you -- your armor feels weaker";
}
break;
case 2:
i = rnd(15) + 8 - c[AC];
spout: p = "\nThe %s breathes fire at you!";
if (c[FIRERESISTANCE])
p = "\nThe %s's flame doesn't phase you!";
else
spout2: if (p) {
lprintf(p, lastmonst);
lbeep();
}
checkloss(i);
return (0);
case 3:
i = rnd(20) + 25 - c[AC];
goto spout;
case 4:
if (c[STRENGTH] > 3) {
p = "\nThe %s stung you! You feel weaker";
lbeep();
--c[STRENGTH];
} else
p = "\nThe %s stung you!";
break;
case 5:
p = "\nThe %s blasts you with his cold breath";
i = rnd(15) + 18 - c[AC];
goto spout2;
case 6:
lprintf("\nThe %s drains you of your life energy!", lastmonst);
loselevel();
lbeep();
return (0);
case 7:
p = "\nThe %s got you with a gusher!";
i = rnd(15) + 25 - c[AC];
goto spout2;
case 8:
if (c[NOTHEFT])
return (0); /* he has a device of no theft */
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";
lprintf(p, lastmonst);
disappear(xx, yy);
lbeep();
bottomgold();
return (1);
case 9:
for (j = 50;;) {/* disenchant */
i = rund(26);
m = iven[i]; /* randomly select item */
if (m > 0 && ivenarg[i] > 0 && m != OSCROLL && m != OPOTION) {
if ((ivenarg[i] -= 3) < 0)
ivenarg[i] = 0;
lprintf("\nThe %s hits you -- you feel a sense of loss", lastmonst);
srcount = 0;
lbeep();
show3(i);
bottomline();
return (0);
}
if (--j <= 0) {
p = "\nThe %s nearly misses";
break;
}
break;
}
break;
case 10:
p = "\nThe %s hit you with his barbed tail";
i = rnd(25) - c[AC];
goto spout2;
case 11:
p = "\nThe %s has confused you";
lbeep();
c[CONFUSE] += 10 + rnd(10);
break;
case 12: /* performs any number of other special
* attacks */
return (spattack(spsel[rund(10)], xx, yy));
case 13:
p = "\nThe %s flattens you with his psionics!";
i = rnd(15) + 30 - c[AC];
goto spout2;
case 14:
if (c[NOTHEFT])
return (0); /* he has device of no theft */
if (emptyhanded() == 1) {
p = "\nThe %s couldn't find anything to steal";
break;
}
lprintf("\nThe %s picks your pocket and takes:", lastmonst);
lbeep();
if (stealsomething() == 0)
lprcat(" nothing");
disappear(xx, yy);
bottomline();
return (1);
case 15:
i = rnd(10) + 5 - c[AC];
spout3: p = "\nThe %s bit you!";
goto spout2;
case 16:
i = rnd(15) + 10 - c[AC];
goto spout3;
};
if (p) {
lprintf(p, lastmonst);
bottomline();
}
return (0);
}
/*
* checkloss(x) Routine to subtract hp from user and flag bottomline display
* int x;
*
* Routine to subtract hitpoints from the user and flag the bottomline display
* Enter with the number of hit points to lose
* Note: if x > c[HP] this routine could kill the player!
*/
void
checkloss(x)
int x;
{
if (x > 0) {
losehp(x);
bottomhp();
}
}
/*
* annihilate() Routine to annihilate all monsters around player (playerx,playery)
*
* Gives player experience, but no dropped objects
* Returns the experience gained from all monsters killed
*/
int
annihilate()
{
int i, j;
long k;
u_char *p;
for (k = 0, i = playerx - 1; i <= playerx + 1; i++)
for (j = playery - 1; j <= playery + 1; j++)
if (!vxy(&i, &j)) { /* if not out of bounds */
if (*(p = &mitem[i][j])) { /* if a monster there */
if (*p < DEMONLORD + 2) {
k += monster[*p].experience;
*p = know[i][j] = 0;
} else {
lprintf("\nThe %s barely escapes being annihilated!", monster[*p].name);
hitp[i][j] = (hitp[i][j] >> 1) + 1; /* lose half hit points */
}
}
}
if (k > 0) {
lprcat("\nYou hear loud screams of agony!");
raiseexperience((long) k);
}
return (k);
}
/*
* newsphere(x,y,dir,lifetime) Function to create a new sphere of annihilation
* int x,y,dir,lifetime;
*
* Enter with the coordinates of the sphere in x,y
* the direction (0-8 diroffx format) in dir, and the lifespan of the
* sphere in lifetime (in turns)
* Returns the number of spheres currently in existence
*/
int
newsphere(x, y, dir, life)
int x, y, dir, life;
{
int m;
struct sphere *sp;
if (((sp = (struct sphere *) malloc(sizeof(struct sphere)))) == 0)
return (c[SPHCAST]); /* can't malloc, therefore failure */
if (dir >= 9)
dir = 0; /* no movement if direction not found */
if (level == 0)
vxy(&x, &y); /* don't go out of bounds */
else {
if (x < 1)
x = 1;
if (x >= MAXX - 1)
x = MAXX - 2;
if (y < 1)
y = 1;
if (y >= MAXY - 1)
y = MAXY - 2;
}
if ((m = mitem[x][y]) >= DEMONLORD + 4) { /* demons dispel spheres */
know[x][y] = 1;
show1cell(x, y);/* show the demon (ha ha) */
cursors();
lprintf("\nThe %s dispels the sphere!", monster[m].name);
lbeep();
rmsphere(x, y); /* remove any spheres that are here */
return (c[SPHCAST]);
}
if (m == DISENCHANTRESS) { /* disenchantress cancels spheres */
cursors();
lprintf("\nThe %s causes cancellation of the sphere!", monster[m].name);
lbeep();
boom: sphboom(x, y); /* blow up stuff around sphere */
rmsphere(x, y); /* remove any spheres that are here */
return (c[SPHCAST]);
}
if (c[CANCELLATION]) { /* cancellation cancels spheres */
cursors();
lprcat("\nAs the cancellation takes effect, you hear a great earth shaking blast!");
lbeep();
goto boom;
}
if (item[x][y] == OANNIHILATION) { /* collision of spheres
* detonates spheres */
cursors();
lprcat("\nTwo spheres of annihilation collide! You hear a great earth shaking blast!");
lbeep();
rmsphere(x, y);
goto boom;
}
if (playerx == x && playery == y) { /* collision of sphere and
* player! */
cursors();
lprcat("\nYou have been enveloped by the zone of nothingness!\n");
lbeep();
rmsphere(x, y); /* remove any spheres that are here */
nap(4000);
died(258);
}
item[x][y] = OANNIHILATION;
mitem[x][y] = 0;
know[x][y] = 1;
show1cell(x, y); /* show the new sphere */
sp->x = x;
sp->y = y;
sp->lev = level;
sp->dir = dir;
sp->lifetime = life;
sp->p = 0;
if (spheres == 0)
spheres = sp; /* if first node in the sphere list */
else { /* add sphere to beginning of linked list */
sp->p = spheres;
spheres = sp;
}
return (++c[SPHCAST]); /* one more sphere in the world */
}
/*
* rmsphere(x,y) Function to delete a sphere of annihilation from list
* int x,y;
*
* Enter with the coordinates of the sphere (on current level)
* Returns the number of spheres currently in existence
*/
int
rmsphere(x, y)
int x, y;
{
struct sphere *sp, *sp2 = 0;
for (sp = spheres; sp; sp2 = sp, sp = sp->p)
if (level == sp->lev) /* is sphere on this level? */
if ((x == sp->x) && (y == sp->y)) { /* locate sphere at this
* location */
item[x][y] = mitem[x][y] = 0;
know[x][y] = 1;
show1cell(x, y); /* show the now missing
* sphere */
--c[SPHCAST];
if (sp == spheres) {
sp2 = sp;
spheres = sp->p;
free((char *) sp2);
} else {
sp2->p = sp->p;
free((char *) sp);
}
break;
}
return (c[SPHCAST]); /* return number of spheres in the world */
}
/*
* sphboom(x,y) Function to perform the effects of a sphere detonation
* int x,y;
*
* Enter with the coordinates of the blast, Returns no value
*/
void
sphboom(x, y)
int x, y;
{
int i, j;
if (c[HOLDMONST])
c[HOLDMONST] = 1;
if (c[CANCELLATION])
c[CANCELLATION] = 1;
for (j = max(1, x - 2); j < min(x + 3, MAXX - 1); j++)
for (i = max(1, y - 2); i < min(y + 3, MAXY - 1); i++) {
item[j][i] = mitem[j][i] = 0;
show1cell(j, i);
if (playerx == j && playery == i) {
cursors();
lbeep();
lprcat("\nYou were too close to the sphere!");
nap(3000);
died(283); /* player killed in explosion */
}
}
}
/*
* genmonst() Function to ask for monster and genocide from game
*
* This is done by setting a flag in the monster[] structure
*/
void
genmonst()
{
int i, j;
cursors();
lprcat("\nGenocide what monster? ");
for (i = 0; (!isalpha(i)) && (i != ' ');
i = lgetchar());
lprc(i);
for (j = 0; j < MAXMONST; j++) /* search for the monster type */
if (monstnamelist[j] == i) { /* have we found it? */
monster[j].genocided = 1; /* genocided from game */
lprintf(" There will be no more %s's", monster[j].name);
/* now wipe out monsters on this level */
newcavelevel(level);
draws(0, MAXX, 0, MAXY);
bot_linex();
return;
}
lprcat(" You sense failure!");
}
|