forked from NetHack/NetHack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dokick.c
1960 lines (1800 loc) · 67.9 KB
/
dokick.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
/* NetHack 3.7 dokick.c $NHDT-Date: 1625963851 2021/07/11 00:37:31 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.167 $ */
/* Copyright (c) Izchak Miller, Mike Stephenson, Steve Linhart, 1989. */
/* NetHack may be freely redistributed. See license for details. */
#include "hack.h"
#define is_bigfoot(x) ((x) == &mons[PM_SASQUATCH])
#define martial() \
(martial_bonus() || is_bigfoot(gy.youmonst.data) \
|| (uarmf && uarmf->otyp == KICKING_BOOTS))
/* gk.kickedobj (decl.c) tracks a kicked object until placed or destroyed */
static void kickdmg(struct monst *, boolean);
static boolean maybe_kick_monster(struct monst *, coordxy, coordxy);
static void kick_monster(struct monst *, coordxy, coordxy);
static int kick_object(coordxy, coordxy, char *);
static int really_kick_object(coordxy, coordxy);
static char *kickstr(char *, const char *);
static boolean watchman_thief_arrest(struct monst *);
static boolean watchman_door_damage(struct monst *, coordxy, coordxy);
static void kick_dumb(coordxy, coordxy);
static void kick_ouch(coordxy, coordxy, const char *);
static void kick_door(coordxy, coordxy, int);
static void otransit_msg(struct obj *, boolean, boolean, long);
static void drop_to(coord *, schar, coordxy, coordxy);
static const char kick_passes_thru[] = "kick passes harmlessly through";
/* kicking damage when not poly'd into a form with a kick attack */
static void
kickdmg(struct monst *mon, boolean clumsy)
{
int mdx, mdy;
int dmg = (ACURRSTR + ACURR(A_DEX) + ACURR(A_CON)) / 15;
int specialdmg, kick_skill = P_NONE;
boolean trapkilled = FALSE;
if (uarmf && uarmf->otyp == KICKING_BOOTS)
dmg += 5;
/* excessive wt affects dex, so it affects dmg */
if (clumsy)
dmg /= 2;
/* kicking a dragon or an elephant will not harm it */
if (thick_skinned(mon->data))
dmg = 0;
/* attacking a shade is normally useless */
if (mon->data == &mons[PM_SHADE])
dmg = 0;
specialdmg = special_dmgval(&gy.youmonst, mon, W_ARMF, (long *) 0);
if (mon->data == &mons[PM_SHADE] && !specialdmg) {
pline_The("%s.", kick_passes_thru);
/* doesn't exercise skill or abuse alignment or frighten pet,
and shades have no passive counterattack */
return;
}
if (M_AP_TYPE(mon))
seemimic(mon);
check_caitiff(mon);
/* squeeze some guilt feelings... */
if (mon->mtame) {
abuse_dog(mon);
if (mon->mtame)
monflee(mon, (dmg ? rnd(dmg) : 1), FALSE, FALSE);
else
mon->mflee = 0;
}
if (dmg > 0) {
/* convert potential damage to actual damage */
dmg = rnd(dmg);
if (martial()) {
if (dmg > 1)
kick_skill = P_MARTIAL_ARTS;
dmg += rn2(ACURR(A_DEX) / 2 + 1);
}
/* a good kick exercises your dex */
exercise(A_DEX, TRUE);
}
dmg += specialdmg; /* for blessed (or hypothetically, silver) boots */
if (uarmf)
dmg += uarmf->spe;
dmg += u.udaminc; /* add ring(s) of increase damage */
if (dmg > 0)
mon->mhp -= dmg;
if (!DEADMONSTER(mon) && martial() && !bigmonst(mon->data) && !rn2(3)
&& mon->mcanmove && mon != u.ustuck && !mon->mtrapped) {
/* see if the monster has a place to move into */
mdx = mon->mx + u.dx;
mdy = mon->my + u.dy;
/* TODO: replace with mhurtle? */
if (goodpos(mdx, mdy, mon, 0)) {
pline("%s reels from the blow.", Monnam(mon));
if (m_in_out_region(mon, mdx, mdy)) {
remove_monster(mon->mx, mon->my);
newsym(mon->mx, mon->my);
place_monster(mon, mdx, mdy);
newsym(mon->mx, mon->my);
set_apparxy(mon);
if (mintrap(mon, NO_TRAP_FLAGS) == Trap_Killed_Mon)
trapkilled = TRUE;
}
}
}
(void) passive(mon, uarmf, TRUE, !DEADMONSTER(mon), AT_KICK, FALSE);
if (DEADMONSTER(mon) && !trapkilled)
killed(mon);
/* may bring up a dialog, so put this after all messages */
if (kick_skill != P_NONE) /* exercise proficiency */
use_skill(kick_skill, 1);
}
static boolean
maybe_kick_monster(struct monst *mon, coordxy x, coordxy y)
{
if (mon) {
boolean save_forcefight = gc.context.forcefight;
gb.bhitpos.x = x;
gb.bhitpos.y = y;
if (!mon->mpeaceful || !canspotmon(mon))
gc.context.forcefight = TRUE; /* attack even if invisible */
/* kicking might be halted by discovery of hidden monster,
by player declining to attack peaceful monster,
or by passing out due to encumbrance */
if (attack_checks(mon, (struct obj *) 0) || overexertion())
mon = 0; /* don't kick after all */
gc.context.forcefight = save_forcefight;
}
return (boolean) (mon != 0);
}
static void
kick_monster(struct monst *mon, coordxy x, coordxy y)
{
boolean clumsy = FALSE;
int i, j;
/* anger target even if wild miss will occur */
setmangry(mon, TRUE);
if (Levitation && !rn2(3) && verysmall(mon->data)
&& !is_flyer(mon->data)) {
pline("Floating in the air, you miss wildly!");
exercise(A_DEX, FALSE);
(void) passive(mon, uarmf, FALSE, 1, AT_KICK, FALSE);
return;
}
/* reveal hidden target even if kick ends up missing (note: being
hidden doesn't affect chance to hit so neither does this reveal) */
if (mon->mundetected
|| (M_AP_TYPE(mon) && M_AP_TYPE(mon) != M_AP_MONSTER)) {
if (M_AP_TYPE(mon))
seemimic(mon);
mon->mundetected = 0;
if (!canspotmon(mon))
map_invisible(x, y);
else
newsym(x, y);
There("is %s here.",
canspotmon(mon) ? a_monnam(mon) : "something hidden");
}
/* Kick attacks by kicking monsters are normal attacks, not special.
* This is almost always worthless, since you can either take one turn
* and do all your kicks, or else take one turn and attack the monster
* normally, getting all your attacks _including_ all your kicks.
* If you have >1 kick attack, you get all of them.
*/
if (Upolyd && attacktype(gy.youmonst.data, AT_KICK)) {
struct attack *uattk;
int sum, kickdieroll, armorpenalty, specialdmg,
attknum = 0,
tmp = find_roll_to_hit(mon, AT_KICK, (struct obj *) 0, &attknum,
&armorpenalty);
mon_maybe_unparalyze(mon);
for (i = 0; i < NATTK; i++) {
/* first of two kicks might have provoked counterattack
that has incapacitated the hero (ie, floating eye) */
if (gm.multi < 0)
break;
uattk = &gy.youmonst.data->mattk[i];
/* we only care about kicking attacks here */
if (uattk->aatyp != AT_KICK)
continue;
kickdieroll = rnd(20);
specialdmg = special_dmgval(&gy.youmonst, mon, W_ARMF, (long *) 0);
if (mon->data == &mons[PM_SHADE] && !specialdmg) {
/* doesn't matter whether it would have hit or missed,
and shades have no passive counterattack */
Your("%s %s.", kick_passes_thru, mon_nam(mon));
break; /* skip any additional kicks */
} else if (tmp > kickdieroll) {
You("kick %s.", mon_nam(mon));
sum = damageum(mon, uattk, specialdmg);
(void) passive(mon, uarmf, (sum != M_ATTK_MISS),
!(sum & M_ATTK_DEF_DIED), AT_KICK, FALSE);
if ((sum & M_ATTK_DEF_DIED))
break; /* Defender died */
} else {
missum(mon, uattk, (tmp + armorpenalty > kickdieroll));
(void) passive(mon, uarmf, FALSE, 1, AT_KICK, FALSE);
}
}
return;
}
i = -inv_weight();
j = weight_cap();
/* What the following confusing if statements mean:
* If you are over 70% of carrying capacity, you go through a "deal no
* damage" check, and if that fails, a "clumsy kick" check.
* At this % of carrycap | Chance of no damage | Chance of clumsiness
* [70%-80%) | 1/4 | 1/3
* [80%-90%) | 1/3 | 1/2
* [90%-100%) | 1/2 | 1
*/
if (i < (j * 3) / 10) {
if (!rn2((i < j / 10) ? 2 : (i < j / 5) ? 3 : 4)) {
if (martial())
goto doit;
Your("clumsy kick does no damage.");
(void) passive(mon, uarmf, FALSE, 1, AT_KICK, FALSE);
return;
}
if (i < j / 10)
clumsy = TRUE;
else if (!rn2((i < j / 5) ? 2 : 3))
clumsy = TRUE;
}
if (Fumbling)
clumsy = TRUE;
else if (uarm && objects[uarm->otyp].oc_bulky && ACURR(A_DEX) < rnd(25))
clumsy = TRUE;
doit:
You("kick %s.", mon_nam(mon));
if (!rn2(clumsy ? 3 : 4) && (clumsy || !bigmonst(mon->data))
&& mon->mcansee && !mon->mtrapped && !thick_skinned(mon->data)
&& mon->data->mlet != S_EEL && haseyes(mon->data) && mon->mcanmove
&& !mon->mstun && !mon->mconf && !mon->msleeping
&& mon->data->mmove >= 12) {
if (!nohands(mon->data) && !rn2(martial() ? 5 : 3)) {
pline("%s blocks your %skick.", Monnam(mon),
clumsy ? "clumsy " : "");
(void) passive(mon, uarmf, FALSE, 1, AT_KICK, FALSE);
return;
} else {
maybe_mnexto(mon);
if (mon->mx != x || mon->my != y) {
(void) unmap_invisible(x, y);
pline("%s %s, %s evading your %skick.", Monnam(mon),
(can_teleport(mon->data) && !noteleport_level(mon))
? "teleports"
: is_floater(mon->data)
? "floats"
: is_flyer(mon->data) ? "swoops"
: (nolimbs(mon->data)
|| slithy(mon->data))
? "slides"
: "jumps",
clumsy ? "easily" : "nimbly", clumsy ? "clumsy " : "");
(void) passive(mon, uarmf, FALSE, 1, AT_KICK, FALSE);
return;
}
}
}
kickdmg(mon, clumsy);
}
/*
* Return TRUE if caught (the gold taken care of), FALSE otherwise.
* The gold object is *not* attached to the fobj chain!
*/
boolean
ghitm(register struct monst *mtmp, register struct obj *gold)
{
boolean msg_given = FALSE;
if (!likes_gold(mtmp->data) && !mtmp->isshk && !mtmp->ispriest
&& !mtmp->isgd && !is_mercenary(mtmp->data)) {
wakeup(mtmp, TRUE);
} else if (!mtmp->mcanmove) {
/* too light to do real damage */
if (canseemon(mtmp)) {
pline_The("%s harmlessly %s %s.", xname(gold),
otense(gold, "hit"), mon_nam(mtmp));
msg_given = TRUE;
}
} else {
long umoney, value = gold->quan * objects[gold->otyp].oc_cost;
mtmp->msleeping = 0;
finish_meating(mtmp);
if (!mtmp->isgd && !rn2(4)) /* not always pleasing */
setmangry(mtmp, TRUE);
/* greedy monsters catch gold */
if (cansee(mtmp->mx, mtmp->my))
pline("%s catches the gold.", Monnam(mtmp));
(void) mpickobj(mtmp, gold);
gold = (struct obj *) 0; /* obj has been freed */
if (mtmp->isshk) {
long robbed = ESHK(mtmp)->robbed;
if (robbed) {
robbed -= value;
if (robbed < 0L)
robbed = 0L;
pline_The("amount %scovers %s recent losses.",
!robbed ? "" : "partially ", mhis(mtmp));
ESHK(mtmp)->robbed = robbed;
if (!robbed)
make_happy_shk(mtmp, FALSE);
} else {
SetVoice(mtmp, 0, 80, 0);
if (mtmp->mpeaceful) {
ESHK(mtmp)->credit += value;
You("have %ld %s in credit.", ESHK(mtmp)->credit,
currency(ESHK(mtmp)->credit));
} else
verbalize("Thanks, scum!");
}
} else if (mtmp->ispriest) {
SetVoice(mtmp, 0, 80, 0);
if (mtmp->mpeaceful)
verbalize("Thank you for your contribution.");
else
verbalize("Thanks, scum!");
} else if (mtmp->isgd) {
umoney = money_cnt(gi.invent);
/* Some of these are iffy, because a hostile guard
won't become peaceful and resume leading hero
out of the vault. If he did do that, player
could try fighting, then weasel out of being
killed by throwing his/her gold when losing. */
SetVoice(mtmp, 0, 80, 0);
verbalize(umoney ? "Drop the rest and follow me."
: hidden_gold(TRUE)
? "You still have hidden gold. Drop it now."
: mtmp->mpeaceful
? "I'll take care of that; please move along."
: "I'll take that; now get moving.");
} else if (is_mercenary(mtmp->data)) {
boolean was_angry = !mtmp->mpeaceful;
long goldreqd = 0L;
if (mtmp->data == &mons[PM_SOLDIER])
goldreqd = 100L;
else if (mtmp->data == &mons[PM_SERGEANT])
goldreqd = 250L;
else if (mtmp->data == &mons[PM_LIEUTENANT])
goldreqd = 500L;
else if (mtmp->data == &mons[PM_CAPTAIN])
goldreqd = 750L;
if (goldreqd && rn2(3)) {
umoney = money_cnt(gi.invent);
goldreqd += (umoney + u.ulevel * rn2(5)) / ACURR(A_CHA);
if (value > goldreqd)
mtmp->mpeaceful = TRUE;
}
if (!mtmp->mpeaceful) {
SetVoice(mtmp, 0, 80, 0);
if (goldreqd)
verbalize("That's not enough, coward!");
else /* unbribable (watchman) */
verbalize("I don't take bribes from scum like you!");
} else if (was_angry) {
SetVoice(mtmp, 0, 80, 0);
verbalize("That should do. Now beat it!");
} else {
SetVoice(mtmp, 0, 80, 0);
verbalize("Thanks for the tip, %s.",
flags.female ? "lady" : "buddy");
}
}
return TRUE;
}
if (!msg_given)
miss(xname(gold), mtmp);
return FALSE;
}
/* container is kicked, dropped, thrown or otherwise impacted by player.
* Assumes container is on floor. Checks contents for possible damage. */
void
container_impact_dmg(
struct obj *obj,
coordxy x, /* coordinates where object was */
coordxy y) /* before the impact, not after */
{
struct monst *shkp;
struct obj *otmp, *otmp2;
long loss = 0L;
boolean costly, insider, frominv;
/* only consider normal containers */
if (!Is_container(obj) || !Has_contents(obj) || Is_mbag(obj))
return;
costly = ((shkp = shop_keeper(*in_rooms(x, y, SHOPBASE)))
&& costly_spot(x, y));
insider = (*u.ushops && inside_shop(u.ux, u.uy)
&& *in_rooms(x, y, SHOPBASE) == *u.ushops);
/* if dropped or thrown, shop ownership flags are set on this obj */
frominv = (obj != gk.kickedobj);
for (otmp = obj->cobj; otmp; otmp = otmp2) {
const char *result = (char *) 0;
otmp2 = otmp->nobj;
if (objects[otmp->otyp].oc_material == GLASS
&& otmp->oclass != GEM_CLASS && !obj_resists(otmp, 33, 100)) {
result = "shatter";
} else if (otmp->otyp == EGG && !rn2(3)) {
result = "cracking";
}
if (result) {
if (otmp->otyp == MIRROR)
change_luck(-2);
/* eggs laid by you. penalty is -1 per egg, max 5,
* but it's always exactly 1 that breaks */
if (otmp->otyp == EGG && otmp->spe && otmp->corpsenm >= LOW_PM)
change_luck(-1);
if (otmp->otyp == EGG) {
Soundeffect(se_egg_cracking, 25);
} else {
Soundeffect(se_glass_shattering, 25);
}
You_hear("a muffled %s.", result);
if (costly) {
if (frominv && !otmp->unpaid)
otmp->no_charge = 1;
loss +=
stolen_value(otmp, x, y, (boolean) shkp->mpeaceful, TRUE);
}
if (otmp->quan > 1L) {
useup(otmp);
} else {
obj_extract_self(otmp);
obfree(otmp, (struct obj *) 0);
}
/* contents of this container are no longer known */
obj->cknown = 0;
}
}
if (costly && loss) {
if (!insider) {
You("caused %ld %s worth of damage!", loss, currency(loss));
make_angry_shk(shkp, x, y);
} else {
You("owe %s %ld %s for objects destroyed.", shkname(shkp), loss,
currency(loss));
}
}
}
/* jacket around really_kick_object */
static int
kick_object(coordxy x, coordxy y, char *kickobjnam)
{
int res = 0;
*kickobjnam = '\0';
/* if a pile, the "top" object gets kicked */
gk.kickedobj = gl.level.objects[x][y];
if (gk.kickedobj) {
/* kick object; if doing is fatal, done() will clean up gk.kickedobj */
Strcpy(kickobjnam, killer_xname(gk.kickedobj)); /* matters iff res==0 */
res = really_kick_object(x, y);
gk.kickedobj = (struct obj *) 0;
}
return res;
}
/* guts of kick_object */
static int
really_kick_object(coordxy x, coordxy y)
{
int range;
struct monst *mon, *shkp = 0;
struct trap *trap;
char bhitroom;
boolean costly, isgold, slide = FALSE;
/* gk.kickedobj should always be set due to conditions of call */
if (!gk.kickedobj || gk.kickedobj->otyp == BOULDER
|| gk.kickedobj == uball || gk.kickedobj == uchain)
return 0;
if ((trap = t_at(x, y)) != 0) {
if ((is_pit(trap->ttyp) && !Passes_walls) || trap->ttyp == WEB) {
if (!trap->tseen)
find_trap(trap);
You_cant("kick %s that's in a %s!", something,
Hallucination ? "tizzy"
: (trap->ttyp == WEB) ? "web"
: "pit");
return 1;
}
if (trap->ttyp == STATUE_TRAP) {
activate_statue_trap(trap, x, y, FALSE);
return 1;
}
}
if (Fumbling && !rn2(3)) {
Your("clumsy kick missed.");
return 1;
}
if (!uarmf && gk.kickedobj->otyp == CORPSE
&& touch_petrifies(&mons[gk.kickedobj->corpsenm])
&& !Stone_resistance) {
You("kick %s with your bare %s.",
corpse_xname(gk.kickedobj, (const char *) 0, CXN_PFX_THE),
makeplural(body_part(FOOT)));
if (poly_when_stoned(gy.youmonst.data) && polymon(PM_STONE_GOLEM)) {
; /* hero has been transformed but kick continues */
} else {
/* normalize body shape here; foot, not body_part(FOOT) */
Sprintf(gk.killer.name, "kicking %s barefoot",
killer_xname(gk.kickedobj));
instapetrify(gk.killer.name);
}
}
isgold = (gk.kickedobj->oclass == COIN_CLASS);
{
int k_owt = (int) gk.kickedobj->owt;
/* for non-gold stack, 1 item will be split off below (unless an
early return occurs, so we aren't moving the split to here);
calculate the range for that 1 rather than for the whole stack */
if (gk.kickedobj->quan > 1L && !isgold) {
long save_quan = gk.kickedobj->quan;
gk.kickedobj->quan = 1L;
k_owt = weight(gk.kickedobj);
gk.kickedobj->quan = save_quan;
}
/* range < 2 means the object will not move
(maybe dexterity should also figure here) */
range = ((int) ACURRSTR) / 2 - k_owt / 40;
}
if (martial())
range += rnd(3);
if (is_pool(x, y)) {
/* you're in the water too; significantly reduce range */
range = range / 3 + 1; /* {1,2}=>1, {3,4,5}=>2, {6,7,8}=>3 */
} else if (Is_airlevel(&u.uz) || Is_waterlevel(&u.uz)) {
/* you're in air, since is_pool did not match */
range += rnd(3);
} else {
if (is_ice(x, y))
range += rnd(3), slide = TRUE;
if (gk.kickedobj->greased)
range += rnd(3), slide = TRUE;
}
/* Mjollnir is magically too heavy to kick */
if (is_art(gk.kickedobj, ART_MJOLLNIR))
range = 1;
/* see if the object has a place to move into */
if (!ZAP_POS(levl[x + u.dx][y + u.dy].typ)
|| closed_door(x + u.dx, y + u.dy))
range = 1;
/* 3.7: this used to skip 'costly' handling if kickedobj->no_charge
was set but that optimization could result in no_charge staying set
for objects kicked out of the shop */
shkp = find_objowner(gk.kickedobj, x, y);
costly = (shkp && (costly_spot(x, y) || (costly_adjacent(shkp, x, y)
&& gk.kickedobj->unpaid)));
/* 3.7: give feedback about the item being kicked; some follow-on
messages refer to "it" */
Norep("You kick %s.",
!isgold ? singular(gk.kickedobj, doname) : doname(gk.kickedobj));
if (IS_ROCK(levl[x][y].typ) || closed_door(x, y)) {
if ((!martial() && rn2(20) > ACURR(A_DEX))
|| IS_ROCK(levl[u.ux][u.uy].typ) || closed_door(u.ux, u.uy)) {
if (Blind)
pline("It doesn't come loose.");
else
pline("%s %sn't come loose.",
The(distant_name(gk.kickedobj, xname)),
otense(gk.kickedobj, "do"));
return (!rn2(3) || martial());
}
if (Blind)
pline("It comes loose.");
else
pline("%s %s loose.", The(distant_name(gk.kickedobj, xname)),
otense(gk.kickedobj, "come"));
obj_extract_self(gk.kickedobj);
newsym(x, y);
if (costly && (!costly_spot(u.ux, u.uy)
|| !strchr(u.urooms, *in_rooms(x, y, SHOPBASE)))) {
if (!gk.kickedobj->no_charge)
addtobill(gk.kickedobj, FALSE, FALSE, FALSE);
else /* don't leave no_charge set when outside shop */
gk.kickedobj->no_charge = 0;
}
if (!flooreffects(gk.kickedobj, u.ux, u.uy, "fall")) {
place_object(gk.kickedobj, u.ux, u.uy);
stackobj(gk.kickedobj);
newsym(u.ux, u.uy);
}
return 1;
}
/* a box gets a chance of breaking open here */
if (Is_box(gk.kickedobj)) {
boolean otrp = gk.kickedobj->otrapped;
if (range < 2)
pline("THUD!");
container_impact_dmg(gk.kickedobj, x, y);
if (gk.kickedobj->olocked) {
if (!rn2(5) || (martial() && !rn2(2))) {
You("break open the lock!");
breakchestlock(gk.kickedobj, FALSE);
if (otrp)
(void) chest_trap(gk.kickedobj, LEG, FALSE);
return 1;
}
} else {
if (!rn2(3) || (martial() && !rn2(2))) {
pline_The("lid slams open, then falls shut.");
gk.kickedobj->lknown = 1;
if (otrp)
(void) chest_trap(gk.kickedobj, LEG, FALSE);
return 1;
}
}
if (range < 2)
return 1;
/* else let it fall through to the next cases... */
}
/* fragile objects should not be kicked */
if (hero_breaks(gk.kickedobj, gk.kickedobj->ox, gk.kickedobj->oy, 0))
return 1;
/* too heavy to move. range is calculated as potential distance from
* player, so range == 2 means the object may move up to one square
* from its current position
*/
if (range < 2) {
if (!Is_box(gk.kickedobj))
pline("Thump!");
return (!rn2(3) || martial());
}
if (gk.kickedobj->quan > 1L) {
if (!isgold) {
gk.kickedobj = splitobj(gk.kickedobj, 1L);
} else {
if (rn2(20)) {
static NEARDATA const char *const flyingcoinmsg[] = {
"scatter the coins", "knock coins all over the place",
"send coins flying in all directions",
};
if (!Deaf)
pline1("Thwwpingg!");
You("%s!", flyingcoinmsg[rn2(SIZE(flyingcoinmsg))]);
(void) scatter(x, y, rnd(3), VIS_EFFECTS | MAY_HIT,
gk.kickedobj);
newsym(x, y);
return 1;
}
if (gk.kickedobj->quan > 300L) {
pline("Thump!");
return (!rn2(3) || martial());
}
}
}
if (slide && !Blind)
pline("Whee! %s %s across the %s.", Doname2(gk.kickedobj),
otense(gk.kickedobj, "slide"), surface(x, y));
#if 0 /* now that 'costly' above includes no_charge items, this would
* clear their no_charge state (while declining to add to bill)
* and then costly handling below would end up charging for them
*
* [fixme? if there is anything which won't break when kicked
* but will be used up with hitting a monster, suppressing this
* results in the used-up item not being charged for]
*/
if (costly && !isgold) /* && !gk.kickedobj->no_charge) */
addtobill(gk.kickedobj, FALSE, FALSE, TRUE);
#endif
obj_extract_self(gk.kickedobj);
(void) snuff_candle(gk.kickedobj);
newsym(x, y);
mon = bhit(u.dx, u.dy, range, KICKED_WEAPON,
(int (*) (struct monst *, struct obj *)) 0,
(int (*) (struct obj *, struct obj *)) 0, &gk.kickedobj);
if (!gk.kickedobj)
return 1; /* object broken */
if (mon) {
if (mon->isshk && gk.kickedobj->where == OBJ_MINVENT
&& gk.kickedobj->ocarry == mon)
return 1; /* alert shk caught it */
gn.notonhead = (mon->mx != gb.bhitpos.x || mon->my != gb.bhitpos.y);
if (isgold ? ghitm(mon, gk.kickedobj) /* caught? */
: thitmonst(mon, gk.kickedobj)) /* hit && used up? */
return 1;
}
/* the object might have fallen down a hole;
ship_object() will have taken care of shop billing */
if (gk.kickedobj->where == OBJ_MIGRATING)
return 1;
bhitroom = *in_rooms(gb.bhitpos.x, gb.bhitpos.y, SHOPBASE);
/* if obj is marked no_charge, stolen_value() won't blame hero for
theft but will clear that flag */
if (costly && (!costly_spot(gb.bhitpos.x, gb.bhitpos.y)
|| *in_rooms(x, y, SHOPBASE) != bhitroom)) {
/* kicked from inside shop to somewhere outside shop */
if (isgold)
costly_gold(x, y, gk.kickedobj->quan, FALSE);
else
(void) stolen_value(gk.kickedobj, x, y, (boolean) shkp->mpeaceful,
FALSE);
costly = FALSE; /* already billed */
}
if (flooreffects(gk.kickedobj, gb.bhitpos.x, gb.bhitpos.y, "fall"))
return 1;
if (costly) {
long gtg = 0L;
/* costly + landed outside shop handled above; must be inside shop */
if (gk.kickedobj->unpaid)
subfrombill(gk.kickedobj, shkp);
/* if billed for contained gold during kick, get a refund now */
if (Has_contents(gk.kickedobj)
&& (gtg = contained_gold(gk.kickedobj, TRUE)) > 0L)
donate_gold(gtg, shkp, FALSE);
}
place_object(gk.kickedobj, gb.bhitpos.x, gb.bhitpos.y);
stackobj(gk.kickedobj);
newsym(gk.kickedobj->ox, gk.kickedobj->oy);
return 1;
}
/* cause of death if kicking kills kicker */
static char *
kickstr(char *buf, const char *kickobjnam)
{
const char *what;
if (*kickobjnam)
what = kickobjnam;
else if (gm.maploc == &gn.nowhere)
what = "nothing";
else if (IS_DOOR(gm.maploc->typ))
what = "a door";
else if (IS_TREE(gm.maploc->typ))
what = "a tree";
else if (IS_STWALL(gm.maploc->typ))
what = "a wall";
else if (IS_ROCK(gm.maploc->typ))
what = "a rock";
else if (IS_THRONE(gm.maploc->typ))
what = "a throne";
else if (IS_FOUNTAIN(gm.maploc->typ))
what = "a fountain";
else if (IS_GRAVE(gm.maploc->typ))
what = "a headstone";
else if (IS_SINK(gm.maploc->typ))
what = "a sink";
else if (IS_ALTAR(gm.maploc->typ))
what = "an altar";
else if (IS_DRAWBRIDGE(gm.maploc->typ))
what = "a drawbridge";
else if (gm.maploc->typ == STAIRS)
what = "the stairs";
else if (gm.maploc->typ == LADDER)
what = "a ladder";
else if (gm.maploc->typ == IRONBARS)
what = "an iron bar";
else
what = "something weird";
return strcat(strcpy(buf, "kicking "), what);
}
static boolean
watchman_thief_arrest(struct monst *mtmp)
{
if (is_watch(mtmp->data) && couldsee(mtmp->mx, mtmp->my)
&& mtmp->mpeaceful) {
mon_yells(mtmp, "Halt, thief! You're under arrest!");
(void) angry_guards(FALSE);
return TRUE;
}
return FALSE;
}
static boolean
watchman_door_damage(struct monst *mtmp, coordxy x, coordxy y)
{
if (is_watch(mtmp->data) && mtmp->mpeaceful
&& couldsee(mtmp->mx, mtmp->my)) {
if (levl[x][y].looted & D_WARNED) {
mon_yells(mtmp,
"Halt, vandal! You're under arrest!");
(void) angry_guards(FALSE);
} else {
mon_yells(mtmp, "Hey, stop damaging that door!");
levl[x][y].looted |= D_WARNED;
}
return TRUE;
}
return FALSE;
}
static void
kick_dumb(coordxy x, coordxy y)
{
exercise(A_DEX, FALSE);
if (martial() || ACURR(A_DEX) >= 16 || rn2(3)) {
You("kick at empty space.");
if (Blind)
feel_location(x, y);
} else {
pline("Dumb move! You strain a muscle.");
exercise(A_STR, FALSE);
set_wounded_legs(RIGHT_SIDE, 5 + rnd(5));
}
if ((Is_airlevel(&u.uz) || Levitation) && rn2(2))
hurtle(-u.dx, -u.dy, 1, TRUE);
}
static void
kick_ouch(coordxy x, coordxy y, const char *kickobjnam)
{
int dmg;
char buf[BUFSZ];
pline("Ouch! That hurts!");
exercise(A_DEX, FALSE);
exercise(A_STR, FALSE);
if (isok(x, y)) {
if (Blind)
feel_location(x, y); /* we know we hit it */
if (is_drawbridge_wall(x, y) >= 0) {
pline_The("drawbridge is unaffected.");
/* update maploc to refer to the drawbridge */
(void) find_drawbridge(&x, &y);
gm.maploc = &levl[x][y];
}
wake_nearto(x, y, 5 * 5);
}
if (!rn2(3))
set_wounded_legs(RIGHT_SIDE, 5 + rnd(5));
dmg = rnd(ACURR(A_CON) > 15 ? 3 : 5);
losehp(Maybe_Half_Phys(dmg), kickstr(buf, kickobjnam), KILLED_BY);
if (Is_airlevel(&u.uz) || Levitation)
hurtle(-u.dx, -u.dy, rn1(2, 4), TRUE); /* assume it's heavy */
}
static void
kick_door(coordxy x, coordxy y, int avrg_attrib)
{
if (gm.maploc->doormask == D_ISOPEN || gm.maploc->doormask == D_BROKEN
|| gm.maploc->doormask == D_NODOOR) {
kick_dumb(x, y);
return; /* uses a turn */
}
/* not enough leverage to kick open doors while levitating */
if (Levitation) {
kick_ouch(x, y, "");
return;
}
exercise(A_DEX, TRUE);
/* door is known to be CLOSED or LOCKED */
if (rnl(35) < avrg_attrib + (!martial() ? 0 : ACURR(A_DEX))) {
boolean shopdoor = *in_rooms(x, y, SHOPBASE) ? TRUE : FALSE;
/* break the door */
if (gm.maploc->doormask & D_TRAPPED) {
if (Verbose(0, dokick))
You("kick the door.");
exercise(A_STR, FALSE);
gm.maploc->doormask = D_NODOOR;
b_trapped("door", FOOT);
} else if (ACURR(A_STR) > 18 && !rn2(5) && !shopdoor) {
Soundeffect(se_kick_door_it_shatters, 50);
pline("As you kick the door, it shatters to pieces!");
exercise(A_STR, TRUE);
gm.maploc->doormask = D_NODOOR;
} else {
Soundeffect(se_kick_door_it_crashes_open, 50);
pline("As you kick the door, it crashes open!");
exercise(A_STR, TRUE);
gm.maploc->doormask = D_BROKEN;
}
feel_newsym(x, y); /* we know we broke it */
unblock_point(x, y); /* vision */
if (shopdoor) {
add_damage(x, y, SHOP_DOOR_COST);
pay_for_damage("break", FALSE);
}
if (in_town(x, y))
(void) get_iter_mons(watchman_thief_arrest);
} else {
if (Blind)
feel_location(x, y); /* we know we hit it */
exercise(A_STR, TRUE);
/* note: this used to be unconditional "WHAMMM!!!" but that has a
fairly strong connotation of noise that a deaf hero shouldn't
hear; we've kept the extra 'm's and one of the extra '!'s */
pline("%s!!", (Deaf || !rn2(3)) ? "Thwack" : "Whammm");
if (in_town(x, y))
(void) get_iter_mons_xy(watchman_door_damage, x, y);
}
}
/* the #kick command */
int
dokick(void)
{
coordxy x, y;
int avrg_attrib;
int glyph, oldglyph = -1;
register struct monst *mtmp;
boolean no_kick = FALSE;
char buf[BUFSZ];
if (nolimbs(gy.youmonst.data) || slithy(gy.youmonst.data)) {
You("have no legs to kick with.");
no_kick = TRUE;
} else if (verysmall(gy.youmonst.data)) {
You("are too small to do any kicking.");
no_kick = TRUE;
} else if (u.usteed) {
if (yn_function("Kick your steed?", ynchars, 'y', TRUE) == 'y') {
You("kick %s.", mon_nam(u.usteed));
kick_steed();
return ECMD_TIME;
} else {
return ECMD_OK;
}
} else if (Wounded_legs) {
legs_in_no_shape("kicking", FALSE);
no_kick = TRUE;
} else if (near_capacity() > SLT_ENCUMBER) {
Your("load is too heavy to balance yourself for a kick.");
no_kick = TRUE;
} else if (gy.youmonst.data->mlet == S_LIZARD) {
Your("legs cannot kick effectively.");
no_kick = TRUE;
} else if (u.uinwater && !rn2(2)) {
Your("slow motion kick doesn't hit anything.");
no_kick = TRUE;
} else if (u.utrap) {
no_kick = TRUE;
switch (u.utraptype) {
case TT_PIT:
if (!Passes_walls)
pline("There's not enough room to kick down here.");
else
no_kick = FALSE;
break;
case TT_WEB:
case TT_BEARTRAP:
You_cant("move your %s!", body_part(LEG));