forked from RoguelikeRestorationProject/urogue1.03
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsticks.c
1431 lines (1345 loc) · 36.2 KB
/
sticks.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
/*
sticks.c - Functions to implement the various sticks
UltraRogue
Copyright (C) 1984, 1985, 1986, 1987, 1990 Herb Chong
All rights reserved.
Based on "Advanced Rogue"
Copyright (C) 1983, 1984 Michael Morgan, Ken Dalka and AT&T
All rights reserved.
Based on "Super-Rogue"
Copyright (C) 1982, 1983 Robert D. Kindelberger
All rights reserved.
Based on "Rogue: Exploring the Dungeons of Doom"
Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
All rights reserved.
See the file LICENSE.TXT for full copyright and licensing information.
*/
/*
* Functions to implement the various sticks one might find while wandering
* around the dungeon.
*/
#include <ctype.h>
#include <string.h>
#include "rogue.h"
/*
* for WS_HIT, WS_WEB, etc
*/
static struct object obolt =
{
{0,0},NULL,NULL,"",0,"1d4",0,0,'*',0,0,0,100,1,0,0,0,0,0
};
struct object null_stick = {0};
char *bolt_name;
/*
* Mask for cancelling special abilities The flags listed here will be the
* ones left on after the cancellation takes place
*/
#define CANC0MASK ( ISBLIND | ISINWALL | ISRUN | \
ISFLEE | ISMEAN | ISGREED | \
CANSHOOT | ISHELD | ISHUH | \
ISSLOW | ISHASTE | ISCLEAR | \
ISUNIQUE)
#define CANC1MASK ( HASDISEASE | DIDSUFFOCATE | CARRYGOLD | \
HASITCH | CANSELL | CANBBURN | \
CANSPEAK | CANFLY | ISFRIENDLY)
#define CANC2MASK ( HASINFEST | NOMOVE | ISSCAVENGE | \
DOROT | HASSTINK | DIDHOLD)
#define CANC3MASK ( ISUNDEAD | CANBREATHE | CANCAST | \
HASOXYGEN)
#define CANC4MASK ( CANTRAMPLE | CANSWIM | CANWIELD | \
ISFAST | CANBARGAIN | CANSPORE | \
ISLARGE | ISSMALL | ISFLOCK | \
ISSWARM | CANSTICK | CANTANGLE | \
SHOOTNEEDLE | CANZAP | HASARMOR | \
CANTELEPORT | ISBERSERK | ISFAMILIAR | \
HASFAMILIAR | SUMMONING)
#define CANC5MASK ( CANREFLECT | MAGICATTRACT | HASSHIELD | \
HASMSHIELD)
#define CANC6MASK ( 0 )
#define CANC7MASK ( 0 )
#define CANC8MASK ( 0 )
#define CANC9MASK ( 0 )
#define CANCAMASK ( 0 )
#define CANCBMASK ( 0 )
#define CANCCMASK ( 0 )
#define CANCDMASK ( 0 )
#define CANCEMASK ( 0 )
#define CANCFMASK ( 0 )
void
fix_stick(struct object *cur)
{
if (strcmp(ws_type[cur->o_which], "staff") == 0) {
cur->o_weight = 100;
cur->o_charges = 5 + rnd(10);
cur->o_damage = "2d3";
switch (cur->o_which) {
when WS_HIT:
cur->o_hplus = 3;
cur->o_dplus = 3;
cur->o_damage = "2d8";
when WS_LIGHT:
cur->o_charges = 20 + rnd(10);
}
}
else { /* A wand */
cur->o_damage = "1d3";
cur->o_weight = 60;
cur->o_charges = 3 + rnd(5);
switch (cur->o_which) {
when WS_HIT:
cur->o_hplus = 3;
cur->o_dplus = 3;
cur->o_damage = "1d8";
when WS_LIGHT:
cur->o_charges = 10 + rnd(10);
}
}
cur->o_hurldmg = "1d1";
}
/*
* do_zap - zap a stick (or effect a stick-like spell)
*
* zapper: who does it
* got_dir: need to ask for direction?
* which: which WS_STICK (-1 means ask from pack)
* flags: ISBLESSED, ISCURSED
*/
void
do_zap(struct thing *zapper, int which, int flags)
{
struct linked_list *item, *nitem;
struct object *obj, *nobj;
struct room *rp;
struct thing *tp;
char *mname;
int y, x;
bool blessed = flags & ISBLESSED;
bool cursed = flags & ISCURSED;
bool is_stick = (which < 0 ? TRUE : FALSE);
bool got_one = TRUE;
if (zapper != &player) {
monster_do_zap(zapper, which, flags);
return;
}
if (is_stick) {
if ((obj = get_object(pack, "zap with", STICK, bff_zappable))
== NULL)
return;
if (obj->o_type != STICK && !(obj->o_flags & ISZAPPED)) {
msg("You can't zap with that!");
return;
}
if (obj->o_type != STICK) /* an electrified weapon */
which = WS_ELECT;
else
which = obj->o_which;
if (obj->o_charges < 1) {
nothing_message(flags);
return;
}
obj->o_charges--;
if (delta.y == 0 && delta.x == 0)
do {
delta.y = rnd(3) - 1;
delta.x = rnd(3) - 1;
} while (delta.y == 0 && delta.x == 0);
flags = obj->o_flags;
cursed = obj->o_flags & ISCURSED;
blessed = obj->o_flags & ISBLESSED;
}
else
obj = &null_stick;
/* Find out who the target is */
y = hero.y;
x = hero.x;
while (shoot_ok(winat(y, x))) {
y += delta.y;
x += delta.x;
}
if (x >= 0 && x < ur_cols && y >= 1 && y < ur_lines - 2 &&
isalpha(mvwinch(mw, y, x))) {
item = find_mons(y, x);
tp = THINGPTR(item);
mname = on(player, ISBLIND) ? "monster" :
monsters[tp->t_index].m_name;
if (on(*tp, CANSELL)) {
luck++;
aggravate();
}
}
else
got_one = FALSE;
switch (which) {
when WS_LIGHT:
/* Reddy Kilowat wand. Light up the room */
if (blue_light(flags) && is_stick)
if (is_stick)
know_items[TYP_STICK][WS_LIGHT] = TRUE;
when WS_DRAIN:
/*
* Take away 1/2 of hero's hit points, then take it away
* evenly from the monsters in the room or next to hero if he
* is in a passage. Leave the monsters alone if the stick is
* cursed. Drain 1/3rd of hero's hit points if blessed.
*/
if (pstats.s_hpt < 2) {
death(D_DRAINLIFE);
return;
}
if (cursed)
pstats.s_hpt /= 2;
else if ((rp = roomin(&hero)) == NULL)
drain(hero.y - 1, hero.y + 1, hero.x - 1,
hero.x + 1);
else
drain(rp->r_pos.y, rp->r_pos.y + rp->r_max.y,
rp->r_pos.x, rp->r_pos.x + rp->r_max.x);
if (blessed)
pstats.s_hpt *= 2.0 / 3.0;
when WS_POLYMORPH:
case WS_MONSTELEP:
case WS_CANCEL:{
char oldch;
int rm;
int save_adj = 0;
if (got_one) {
/*
* if the monster gets the saving throw,
* leave the case
*/
if (blessed)
save_adj = -5;
if (cursed)
if (which == WS_POLYMORPH)
save_adj = -5; /* not save vs becoming
* tougher */
else
save_adj = 5;
if (save_throw(VS_MAGIC - save_adj, tp)) {
nothing_message(flags);
break;
}
else if (is_stick)
know_items[TYP_STICK][which] = TRUE;
/* Unhold player */
if (on(*tp, DIDHOLD)) {
turn_off(*tp, DIDHOLD);
if (--hold_count == 0)
turn_off(player, ISHELD);
}
/* unsuffocate player */
if (on(*tp, DIDSUFFOCATE)) {
turn_off(*tp, DIDSUFFOCATE);
extinguish_fuse(FUSE_SUFFOCATE);
}
if (which == WS_POLYMORPH) {
int which_new;
int charmed;
detach(mlist, item);
charmed = on(*tp, ISCHARMED);
oldch = tp->t_oldch;
delta.y = y;
delta.x = x;
if (!blessed && !cursed)
which_new = randmonster(WANDER, GRAB);
else {
/*
* duplicate randmonster()
* for now
*/
/*
* Eventually fix to take
* level
*/
int cur_level, range, i;
if (blessed)
cur_level = level / 2;
if (cursed)
cur_level = level * 2;
range = 4 * NLEVMONS;
i = 0;
do {
if (i++ > range * 10) { /* just in case all have
* be genocided */
i = 0;
if (--cur_level <= 0)
fatal("Rogue could not find a monster to make");
}
which_new = NLEVMONS * (cur_level - 1) + (rnd(range) - (range - 1 - NLEVMONS));
if (which_new < 1)
which_new = rnd(NLEVMONS) + 1;
if (which_new > nummonst - NUMSUMMON - 1) {
if (blessed)
which_new = rnd(range) + (nummonst - NUMSUMMON - 1) - (range - 1);
else if (which_new > nummonst - 1)
which_new = rnd(range + NUMSUMMON) + (nummonst - 1) - (range + NUMSUMMON - 1);
}
}
while (!monsters[which_new].m_normal);
}
new_monster(item, which_new, &delta, NOMAXSTATS);
mname = on(player, ISBLIND) ? "monster" : monsters[tp->t_index].m_name;
if (!cursed && charmed)
turn_on(*tp, ISCHARMED);
if (off(*tp, ISRUN))
chase_it(&delta, &player);
if (isalpha(mvwinch(cw, y, x)))
mvwaddch(cw, y, x, tp->t_type);
tp->t_oldch = oldch;
seemsg(terse ? "A new %s!" : "You have created a new %s!", mname);
}
else if (which == WS_CANCEL) {
tp->t_flags[0] &= CANC0MASK;
tp->t_flags[1] &= CANC1MASK;
tp->t_flags[2] &= CANC2MASK;
tp->t_flags[3] &= CANC3MASK;
tp->t_flags[4] &= CANC4MASK;
tp->t_flags[5] &= CANC5MASK;
tp->t_flags[6] &= CANC5MASK;
tp->t_flags[7] &= CANC7MASK;
tp->t_flags[8] &= CANC8MASK;
tp->t_flags[9] &= CANC9MASK;
tp->t_flags[10] &= CANCAMASK;
tp->t_flags[11] &= CANCBMASK;
tp->t_flags[12] &= CANCCMASK;
tp->t_flags[13] &= CANCDMASK;
tp->t_flags[14] &= CANCEMASK;
tp->t_flags[15] &= CANCFMASK;
}
else { /* A teleport stick */
if (cursed) { /* Teleport monster to
* player */
if ((y == (hero.y + delta.y)) &&
(x == (hero.x + delta.x)))
nothing_message(flags);
else {
tp->t_pos.y = hero.y + delta.y;
tp->t_pos.x = hero.x + delta.x;
}
}
else if (blessed) { /* Get rid of monster */
killed(NULL, item, NOMESSAGE, NOPOINTS);
return;
}
else {
int i = 0;
do { /* Move monster to
* another room */
rm = rnd_room();
rnd_pos(&rooms[rm], &tp->t_pos);
} while (winat(tp->t_pos.y, tp->t_pos.x) !=
FLOOR && i++ < 500);
}
/* Now move the monster */
if (isalpha(mvwinch(cw, y, x)))
mvwaddch(cw, y, x, tp->t_oldch);
chase_it(&tp->t_pos, &player);
mvwaddch(mw, y, x, ' ');
mvwaddch(mw, tp->t_pos.y, tp->t_pos.x, tp->t_oldch);
if (tp->t_pos.y != y || tp->t_pos.x != x)
tp->t_oldch = mvwinch(cw, tp->t_pos.y, tp->t_pos.x);
}
}
}
when WS_MISSILE:{
int damage;
int nsides = 4;
char ch;
if (is_stick)
know_items[TYP_STICK][which] = TRUE;
/* Magic Missiles *always* hit, no saving throw */
obolt.o_type = '*';
do_motion(&obolt, delta.y, delta.x, &player);
ch = winat(obolt.o_pos.y, obolt.o_pos.x);
if (cursed)
nsides /= 2;
else if (blessed)
nsides *= 2;
damage = roll(pstats.s_lvl, nsides);
if (isalpha(ch)) {
debug("Missiled %s for %d (%d)",
mname, damage, tp->t_stats.s_hpt - damage);
if ((tp->t_stats.s_hpt -= damage) <= 0) {
seemsg("The missile kills the %s.", mname);
killed(&player, item, NOMESSAGE, POINTS);
}
else {
seemsg("The missile hits the %s", mname);
chase_it(&obolt.o_pos, &player);
summon_help(tp, NOFORCE);
}
}
if (obolt.o_pos.y >= 0 && obolt.o_pos.x >= 0 &&
obolt.o_pos.y < ur_lines && obolt.o_pos.x < ur_cols)
mvwaddch(cw, obolt.o_pos.y, obolt.o_pos.x,
show(obolt.o_pos.y, obolt.o_pos.x));
}
when WS_HIT:{
char ch;
struct object strike; /* don't want to change
* sticks attributes */
if (is_stick)
know_items[TYP_STICK][which] = TRUE;
obolt.o_type = '@';
do_motion(&obolt, delta.y, delta.x, &player);
ch = winat(obolt.o_pos.y, obolt.o_pos.x);
if (isalpha(ch)) {
static char buf[20];
int nsides, ndice;
strike = *obj;
if (blessed)
strike.o_hplus = 12;
else if (cursed)
strike.o_hplus = 3;
else
strike.o_hplus = 6;
if (!is_stick || strcmp(ws_type[which], "staff") == 0)
ndice = 3;
else
ndice = 2;
if (blessed)
nsides = 16;
else if (cursed)
nsides = 4;
else
nsides = 8;
sprintf(buf, "%dd%d", ndice, nsides);
strike.o_damage = buf;
fight(&tp->t_pos, &strike, NOTHROWN);
}
}
when WS_SLOW_M:
if (got_one) {
if (cursed) {
if (off(*tp, ISSLOW))
turn_on(*tp, ISHASTE);
else
turn_off(*tp, ISSLOW);
}
else if (blessed) {
if (is_stick)
know_items[TYP_STICK][which] = TRUE;
turn_off(*tp, ISRUN);
turn_on(*tp, ISHELD);
return;
}
else {
if (is_stick)
know_items[TYP_STICK][which] = TRUE;
if (off(*tp, ISHASTE))
turn_on(*tp, ISSLOW);
else
turn_off(*tp, ISHASTE);
tp->t_turn = TRUE;
}
delta.y = y;
delta.x = x;
chase_it(&delta, &player);
}
when WS_CHARGE:
if (know_items[TYP_STICK][which] != TRUE && is_stick) {
msg("This is a wand of charging.");
know_items[TYP_STICK][which] = TRUE;
}
if ((nitem = get_item("charge", STICK)) != NULL) {
nobj = OBJPTR(nitem);
if ((nobj->o_charges == 0) && (nobj->o_which != WS_CHARGE)) {
fix_stick(nobj);
if (blessed)
nobj->o_charges *= 2;
else if (cursed)
nobj->o_charges /= 2;
}
else {
if (blessed)
nobj->o_charges += 2;
else if (cursed)
nobj->o_charges -= 1;
else
nobj->o_charges += 1;
}
}
when WS_ELECT:
case WS_FIRE:
case WS_COLD:{
char *name;
int damage;
int ndice = 3 + pstats.s_lvl;
int nsides;
if (is_stick) {
know_items[TYP_STICK][which] = TRUE;
if (strcmp(ws_type[which], "staff") == 0)
nsides = 8;
else
nsides = 4;
}
else
nsides = 6;
if (cursed)
nsides /= 2;
else if (blessed)
nsides *= 2;
switch (which) {
when WS_ELECT:
name = "lightning bolt";
if (rnd(2))
ndice += rnd(obj->o_charges / 10);
else
nsides += rnd(obj->o_charges / 10);
when WS_FIRE:
name = "flame";
when WS_COLD:
name = "ice";
}
damage = roll(ndice, nsides);
shoot_bolt(&player, hero, delta, POINTS, D_BOLT, name, damage);
}
when WS_ANTIMATTER:{
int m1, m2, x1, y1;
char ch;
struct linked_list *ll;
struct thing *lt;
if (is_stick)
know_items[TYP_STICK][which] = TRUE;
y1 = hero.y;
x1 = hero.x;
do {
y1 += delta.y;
x1 += delta.x;
ch = winat(y1, x1);
} while (ch == PASSAGE || ch == FLOOR);
for (m1 = x1 - 1; m1 <= x1 + 1; m1++) {
for (m2 = y1 - 1; m2 <= y1 + 1; m2++) {
ch = winat(m2, m1);
if (m1 == hero.x && m2 == hero.y)
continue;
if (ch != ' ') {
ll = find_obj(m2, m1, TRUE);
while (ll != NULL) {
rem_obj(ll, TRUE);
ll = find_obj(m2, m1, TRUE);
}
ll = find_mons(m2, m1);
if (ll != NULL) {
lt = THINGPTR(ll);
if (on(*lt, CANSELL)) {
luck++;
aggravate();
}
if (off(*lt, CANINWALL)) {
check_residue(lt);
detach(mlist, ll);
discard(ll);
mvwaddch(mw, m2, m1, ' ');
}
}
mvaddch(m2, m1, ' ');
mvwaddch(cw, m2, m1, ' ');
}
}
}
touchwin(cw);
touchwin(mw);
}
when WS_CONFMON:
case WS_PARALYZE:
if (got_one) {
if (save_throw(VS_MAGIC - (blessed ? 5 : (cursed ? -5 : 0)), tp))
nothing_message(flags);
else {
if (is_stick)
know_items[TYP_STICK][which] = TRUE;
switch (which) {
when WS_CONFMON:
seemsg("The %s looks bewildered.", mname);
turn_on(*tp, ISHUH);
when WS_PARALYZE:
seemsg("The %s looks stunned.", mname);
tp->t_no_move = FREEZETIME;
}
}
delta.y = y;
delta.x = x;
chase_it(&delta, &player);
}
else
nothing_message(flags);
when WS_XENOHEALING:{
int hpt_gain = roll(zapper->t_stats.s_lvl, (blessed ? 8 : 4));
int mons_hpt = tp->t_stats.s_hpt;
if (got_one) {
if (cursed) {
if (!save_throw(VS_MAGIC, tp)) {
if ((mons_hpt -= hpt_gain) <= 0) {
seemsg("The %s shrivels up and dies!", mname);
killed(&player, item, NOMESSAGE, POINTS);
}
else
seemsg("Wounds appear all over the %s.", mname);
}
else
nothing_message(flags);
delta.y = y;
delta.x = x;
chase_it(&delta, &player);
}
else {
if (is_stick)
know_items[TYP_STICK][which] = TRUE;
mons_hpt = min(mons_hpt + hpt_gain, tp->maxstats.s_hpt);
seemsg("The %s appears less wounded!", mname);
}
}
else
nothing_message(flags);
}
when WS_DISINTEGRATE:
if (got_one) {
if (cursed) {
if (on(*tp, ISUNIQUE)) {
if (on(*tp, CANSUMMON))
summon_help(tp, FORCE);
else
msg("The %s is very upset.", mname);
turn_on(*tp, ISHASTE);
}
else {
int m1, m2;
coord mp;
struct linked_list *titem;
char ch;
struct thing *th;
for (m1 = tp->t_pos.x - 1; m1 <= tp->t_pos.x + 1; m1++) {
for (m2 = tp->t_pos.y - 1; m2 <= tp->t_pos.y + 1; m2++) {
ch = winat(m2, m1);
if (shoot_ok(ch) && ch != PLAYER) {
mp.x = m1; /* create it */
mp.y = m2;
titem = new_item(sizeof(struct thing));
new_monster(titem, (short) tp->t_index, &mp, NOMAXSTATS);
th = THINGPTR(titem);
turn_on(*th, ISMEAN);
chase_it(&mp, &player);
}
}
}
}
delta.y = y;
delta.x = x;
turn_on(*tp, ISMEAN);
chase_it(&delta, &player);
}
else { /* if its a UNIQUE it might still live */
if (is_stick)
know_items[TYP_STICK][which] = TRUE;
if (on(*tp, ISUNIQUE) &&
save_throw(VS_MAGIC - (blessed ? -5 : 0), tp)) {
tp->t_stats.s_hpt = tp->t_stats.s_hpt / 2 - 1;
if (tp->t_stats.s_hpt < 1) {
killed(&player, item, NOMESSAGE, POINTS);
seemsg("The %s fades away.", mname);
}
else {
delta.y = y;
delta.x = x;
chase_it(&delta, &player);
if (on(*tp, CANSUMMON))
summon_help(tp, FORCE);
else
seemsg("The %s is very upset.", mname);
}
}
else {
if (on(*tp, CANSELL)) {
luck++;
aggravate();
}
seemsg("The %s turns to dust and blows away.", mname);
killed(&player, item, NOMESSAGE, POINTS);
}
}
}
when WS_NOTHING:
nothing_message(flags);
when WS_INVIS:{
if (cursed) {
int x1, y1, x2, y2;
bool zapped = FALSE;
if ((rp = roomin(&hero)) == NULL) {
x1 = max(hero.x - 1, 0);
y1 = max(hero.y - 1, 0);
x2 = min(hero.x + 1, ur_cols - 1);
y2 = min(hero.y + 1, ur_lines - 3);
}
else {
x1 = rp->r_pos.x;
y1 = rp->r_pos.y;
x2 = rp->r_pos.x + rp->r_max.x;
y2 = rp->r_pos.y + rp->r_max.y;
}
for (item = mlist; item != NULL; item = next(item)) {
tp = THINGPTR(item);
if (tp->t_pos.x >= x1 && tp->t_pos.x <= x2 &&
tp->t_pos.y >= y1 && tp->t_pos.y <= y2) {
turn_on(*tp, ISINVIS);
turn_on(*tp, ISRUN);
turn_off(*tp, ISDISGUISE);
chase_it(&tp->t_pos, &player);
zapped = TRUE;
}
}
if (zapped)
seemsg("The monsters seem to have all disappeared.");
else
nothing_message(flags);
}
else {
if (got_one) {
if (is_stick)
know_items[TYP_STICK][which] = TRUE;
if (blessed) {
turn_off(*tp, ISINVIS);
turn_off(*tp, ISSHADOW);
seemsg("The %s appears.", mname);
}
else {
turn_on(*tp, ISINVIS);
seemsg("The %s disappears.", mname);
}
}
else
nothing_message(flags);
}
light(&hero);
}
when WS_BLAST:{
char ch;
struct linked_list *item, *ip;
struct object *obj;
struct trap *trp;
if (is_stick)
know_items[TYP_STICK][which] = TRUE;
item = spec_item(WEAPON, GRENADE, 0, 0);
obj = OBJPTR(item);
obj->o_count = 1;
obj->o_flags |= ISKNOW;
hearmsg("BOOOM!");
aggravate();
obj->o_pos.x = hero.x;
obj->o_pos.y = hero.y;
for (;;) {
obj->o_pos.y += delta.y;
obj->o_pos.x += delta.x;
if (!ce(obj->o_pos, hero) &&
cansee(obj->o_pos.y, obj->o_pos.x) &&
mvwinch(cw, obj->o_pos.y, obj->o_pos.x) != ' ') {
mvwaddch(cw, obj->o_pos.y, obj->o_pos.x,
show(obj->o_pos.y, obj->o_pos.x));
}
if (shoot_ok(ch = winat(obj->o_pos.y, obj->o_pos.x))
&& ch != DOOR && !ce(obj->o_pos, hero)) {
if (cansee(obj->o_pos.y, obj->o_pos.x) &&
ntraps + 1 < 2 * MAXTRAPS &&
mvwinch(cw, obj->o_pos.y, obj->o_pos.x) != ' ') {
mvwaddch(cw, obj->o_pos.y, obj->o_pos.x, TRAPDOOR);
wrefresh(cw);
}
if (isatrap(ch)) {
trp = trap_at(obj->o_pos.y, obj->o_pos.x);
if (trp != NULL) {
trp->tr_type = TRAPDOOR;
trp->tr_flags |= ISFOUND;
trp->tr_show = TRAPDOOR;
}
}
else if (isalpha(ch))
hit_monster(obj->o_pos.y, obj->o_pos.x, obj, &player);
else if ((ch == FLOOR || ch == PASSAGE)
&& ntraps + 1 < 2 * MAXTRAPS) {
mvaddch(obj->o_pos.y, obj->o_pos.x, TRAPDOOR);
traps[ntraps].tr_type = TRAPDOOR;
traps[ntraps].tr_flags = ISFOUND;
traps[ntraps].tr_show = TRAPDOOR;
traps[ntraps].tr_pos.y = obj->o_pos.y;
traps[ntraps++].tr_pos.x = obj->o_pos.x;
}
else if (ch == POTION || ch == SCROLL || ch == FOOD
|| ch == WEAPON || ch == RING || ch == ARMOR
|| ch == STICK || ch == ARTIFACT || ch == GOLD) {
ip = find_obj(obj->o_pos.y, obj->o_pos.x, TRUE);
while (ip) { /* BOOM destroys all
* stacked objects */
rem_obj(ip, TRUE);
ip = find_obj(obj->o_pos.y, obj->o_pos.x, TRUE);
}
mvaddch(obj->o_pos.y, obj->o_pos.x,
roomin(&obj->o_pos) == NULL ? PASSAGE : FLOOR);
}
continue;
}
break;
}
discard(item);
}
when WS_WEB:{
char ch;
if (is_stick)
know_items[TYP_STICK][which] = TRUE;
obolt.o_type = '#';
do_motion(&obolt, delta.y, delta.x, &player);
ch = winat(obolt.o_pos.y, obolt.o_pos.x);
if (isalpha(ch)) {
if (save_throw(VS_MAGIC, tp))
seemsg("The %s evades your web.", mname);
else {
seemsg("The %s is webbed.", mname);
turn_off(*tp, ISRUN);
turn_on(*tp, ISHELD);
}
}
if (obolt.o_pos.y >= 0 && obolt.o_pos.x >= 0 &&
obolt.o_pos.y < ur_lines && obolt.o_pos.x < ur_cols)
mvwaddch(cw, obolt.o_pos.y, obolt.o_pos.x,
show(obolt.o_pos.y, obolt.o_pos.x));
}
when WS_KNOCK:
case WS_CLOSE:
if (blessed) { /* Do all doors in room */
char new_door = (which == WS_KNOCK ? DOOR : SECRETDOOR);
struct room *rp = roomin(&hero);
if (rp != NULL)
for (x = 0; x < rp->r_nexits; x++) {
move(rp->r_exit[x].y, rp->r_exit[x].x);
addch(new_door);
}
else /* Do all adjacent doors */
for (x = hero.x - 1; x <= hero.x + 1; x++)
for (y = hero.y - 1; y <= hero.y + 1; y++)
switch (winat(y, x)) {
when DOOR:
case SECRETDOOR:
addch(new_door);
}
light(&hero);
}
else if (cursed)/* do opposite spell */
do_zap(zapper, (which == WS_KNOCK ? WS_CLOSE : WS_KNOCK), ISBLESSED);
else {
coord zap_loc;
char loc;
zap_loc.y = hero.y + delta.y;
zap_loc.x = hero.x + delta.x;
loc = winat(zap_loc.y, zap_loc.x);
switch (loc) {
when SECRETDOOR:
if (which == WS_KNOCK) {
mvaddch(zap_loc.y, zap_loc.x, DOOR);
seemsg("A secret door stands revealed before you!");
if (is_stick)
know_items[TYP_STICK][which] = TRUE;
}
else
goto n_doing;
when DOOR:
if (which == WS_CLOSE) {
mvaddch(zap_loc.y, zap_loc.x, SECRETDOOR);
msg("You sucessfully block off the door.");
if (is_stick)
know_items[TYP_STICK][which] = TRUE;
}
else
goto n_doing;
otherwise:
n_doing:
nothing_message(flags);
}
}
otherwise:
msg("What a bizarre schtick!");
}
}
/*
* drain: Do drain hit points from player shtick
*/
void
drain(int ymin, int ymax, int xmin, int xmax)
{
int i, j, count;
struct thing *ick;
struct linked_list *item;
/*
* First count how many things we need to spread the hit points among
*/
for (count = 0, i = ymin; i <= ymax; i++)
for (j = xmin; j <= xmax; j++)
if (isalpha(mvwinch(mw, i, j)))
count++;
if (count == 0) {
msg("You have a tingling feeling.");
return;
}
else
msg("You feel weaker.");
count = pstats.s_hpt / count;
pstats.s_hpt /= 2;
/*
* Now zot all of the monsters
*/
for (i = ymin; i <= ymax; i++)
for (j = xmin; j <= xmax; j++)
if (isalpha(mvwinch(mw, i, j)) && ((item = find_mons(i, j)) != NULL)) {
ick = THINGPTR(item);
if (on(*ick, CANSELL)) {
luck++;
aggravate();
}
if ((ick->t_stats.s_hpt -= count) < 1)
killed(&player, item,
cansee(i, j) && !on(*ick, ISINVIS), POINTS);
}
}
/*
* charge a wand for wizards.
*/
char *
charge_str(struct object *obj, char *buf)
{
if (!(obj->o_flags & ISKNOW))
buf[0] = '\0';
else if (terse)
sprintf(buf, " [%d]", obj->o_charges);
else if (obj->o_charges == 1)
sprintf(buf, " [%d charge]", obj->o_charges);
else
sprintf(buf, " [%d charges]", obj->o_charges);
return buf;
}
/*
* shoot_bolt fires a bolt from the given starting point in the given
* direction
*/
void
shoot_bolt(struct thing *shooter,
coord start,
coord dir,
bool get_points, /* should player get exp points? */
int reason, /* reason for dying */
char *name, /* fire, nerve, cold, etc */
int damage) /* make zapee suffer */
{
char dirch, ch;
bool change;
short y, x;
coord pos;
coord spotpos[BOLT_LENGTH];
bool ret_val = FALSE;/* True if breathing monster gets killed */
struct linked_list *item;
struct thing *tp;
char *mname;
int bounced; /* where along BOLT_LENGTH it hit a wall */
int player_damage; /* damage if player saved */
bool no_effect; /* zap does not effect zapee */