-
Notifications
You must be signed in to change notification settings - Fork 12
/
weapon.c
2274 lines (2058 loc) · 72.8 KB
/
weapon.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 weapon.c $NHDT-Date: 1607811730 2020/12/12 22:22:10 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.89 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Robert Patrick Rankin, 2011. */
/* NetHack may be freely redistributed. See license for details. */
/*
* This module contains code for calculation of "to hit" and damage
* bonuses for any given weapon used, as well as weapons selection
* code for monsters.
*/
#include "hack.h"
static void display_skill_db_info(int);
static int odd_material_damage(struct obj *);
static int weapon_distribution_bonus(int, boolean, int);
static void give_may_advance_msg(int);
static void finish_towel_change(struct obj *obj, int);
static boolean could_advance(int);
static boolean peaked_skill(int);
static int slots_required(int);
static void skill_advance(int);
/* Categories whose names don't come from OBJ_NAME(objects[type])
*/
#define PN_BARE_HANDED (-1) /* includes martial arts */
#define PN_TWO_WEAPONS (-2)
#define PN_RIDING (-3)
#define PN_POLEARMS (-4)
#define PN_SABER (-5)
#define PN_HAMMER (-6)
#define PN_FIREARMS (-7)
#define PN_WHIP (-8)
#define PN_ATTACK_SPELL (-9)
#define PN_HEALING_SPELL (-10)
#define PN_DIVINATION_SPELL (-11)
#define PN_ENCHANTMENT_SPELL (-12)
#define PN_CLERIC_SPELL (-13)
#define PN_ESCAPE_SPELL (-14)
#define PN_MATTER_SPELL (-15)
#define PN_POWER_ATTACK (-16)
#define PN_FLAMING_FISTS (-17)
#define PN_FREEZING_FISTS (-18)
#define PN_SHOCKING_FISTS (-19)
#define PN_STUNNING_FIST (-20)
#define PN_BACKSTAB (-21)
#define PN_CAREFUL_ATTACK (-22)
#define PN_RAT_TAMER (-23)
#define PN_DRAGON_TAMER (-24)
#define PN_ANIMAL_FRIENDSHIP (-25)
#define PN_BLOOD_RAGE (-26)
#define PN_PANACHE (-27)
#define PN_WILD_MAGIC (-28)
#define PN_BLOOD_MAGIC (-29)
#define PN_CODE_OF_HONOR (-30)
#define PN_DISARM (-31)
#define PN_SUNDER (-32)
#define PN_TUMBLING (-33)
#define PN_SPIDER_FRIEND (-34)
#define is_odd_material(obj, mat) \
((obj)->material == (mat) && !(objects[(obj)->otyp].oc_material == (mat)))
static NEARDATA const short skill_names_indices[P_NUM_SKILLS] = {
0, DAGGER, KNIFE, AXE, PICK_AXE, SHORT_SWORD, BROADSWORD, LONG_SWORD,
TWO_HANDED_SWORD, SCIMITAR, PN_SABER, CLUB, MACE, MORNING_STAR, FLAIL,
PN_HAMMER, QUARTERSTAFF, PN_POLEARMS, SPEAR, TRIDENT, LANCE, BOW, SLING,
PN_FIREARMS,
CROSSBOW, DART, SHURIKEN, BOOMERANG, PN_WHIP, UNICORN_HORN,
PN_ATTACK_SPELL, PN_HEALING_SPELL, PN_DIVINATION_SPELL,
PN_ENCHANTMENT_SPELL, PN_CLERIC_SPELL, PN_ESCAPE_SPELL, PN_MATTER_SPELL,
PN_BARE_HANDED, PN_TWO_WEAPONS, PN_RIDING,
PN_POWER_ATTACK,
PN_FLAMING_FISTS, PN_FREEZING_FISTS, PN_SHOCKING_FISTS, PN_STUNNING_FIST,
PN_BACKSTAB, PN_CAREFUL_ATTACK, PN_RAT_TAMER, PN_DRAGON_TAMER,
PN_ANIMAL_FRIENDSHIP, PN_BLOOD_RAGE, PN_PANACHE, PN_WILD_MAGIC,
PN_BLOOD_MAGIC, PN_CODE_OF_HONOR,
PN_DISARM, PN_SUNDER, PN_TUMBLING,
PN_SPIDER_FRIEND
};
/* note: entry [0] isn't used */
static NEARDATA const char *const odd_skill_names[] = {
"no skill", "bare hands", /* use barehands_or_martial[] instead */
"two weapon combat", "riding", "polearms", "saber", "hammer", "firearms",
"whip", "attack spells", "healing spells", "divination spells",
"enchantment spells", "clerical spells", "escape spells", "matter spells",
"power attack",
"flaming fists",
"freezing fists",
"shocking fists",
"stunning fist",
"backstab",
"careful attack",
"rat tamer",
"dragon tamer",
"animal friendship",
"blood rage",
"panache",
"wild magic",
"blood magic",
"code of honor",
"disarm",
"sunder",
"tumbling",
"spider friend"
};
/* indexed via is_martial() */
static NEARDATA const char *const barehands_or_martial[] = {
"bare handed combat", "martial arts"
};
#define P_NAME(type) \
((skill_names_indices[type] > 0) \
? OBJ_NAME(objects[skill_names_indices[type]]) \
: (type == P_BARE_HANDED_COMBAT) \
? barehands_or_martial[martial_bonus()] \
: odd_skill_names[-skill_names_indices[type]])
static NEARDATA const char kebabable[] = { S_XORN, S_DRAGON, S_JABBERWOCK,
S_NAGA, S_GIANT, '\0' };
static void
give_may_advance_msg(int skill)
{
if (!g.context.skip_enhance_msg) {
g.context.skip_enhance_msg = TRUE;
} else {
return;
}
You_feel("more confident in your %sskills.",
(skill == P_NONE) ? ""
: (skill <= P_LAST_WEAPON) ? "weapon "
: (skill <= P_LAST_SPELL) ? "spell casting "
: (skill < P_FIRST_ROLE) ? "fighting "
: (skill <= P_LAST_ROLE) ? "class "
: "cultural ");
if (!g.context.enhance_tip) {
g.context.enhance_tip = TRUE;
pline("(Use the #enhance command to advance them.)");
}
}
static void
display_skill_db_info(int skill) {
char tmpbuf[BUFSZ];
tmpbuf[0] = '\0';
Sprintf(tmpbuf, "skill: %s", P_NAME(skill));
checkfile(tmpbuf, (struct permonst *) 0, FALSE, TRUE, 0, (char *) 0);
}
/* weapon's skill category name for use as generalized description of weapon;
mostly used to shorten "you drop your <weapon>" messages when slippery
fingers or polymorph causes hero to involuntarily drop wielded weapon(s) */
const char *
weapon_descr(struct obj *obj)
{
int skill = weapon_type(obj);
const char *descr = P_NAME(skill);
/* assorted special cases */
switch (skill) {
case P_NONE:
/* not a weapon or weptool: use item class name;
override class name for things where it sounds strange and
for things that aren't unexpected to find being wielded:
corpses, tins, eggs, and globs avoid "food",
statues and boulders avoid "large rock",
and towels and tin openers avoid "tool" */
descr = (obj->otyp == CORPSE || obj->otyp == TIN || obj->otyp == EGG
|| obj->otyp == STATUE || obj->otyp == BOULDER
|| obj->otyp == TOWEL || obj->otyp == TIN_OPENER)
? OBJ_NAME(objects[obj->otyp])
: obj->globby ? "glob"
: def_oc_syms[(int) obj->oclass].name;
break;
case P_SLING:
if (is_ammo(obj))
descr = (obj->otyp == ROCK || is_graystone(obj))
? "stone"
/* avoid "rock"; what about known glass? */
: (obj->oclass == GEM_CLASS)
? "gem"
/* in case somebody adds odd sling ammo */
: def_oc_syms[(int) obj->oclass].name;
break;
case P_BOW:
if (is_ammo(obj))
descr = "arrow";
break;
case P_CROSSBOW:
if (is_ammo(obj))
descr = "bolt";
break;
case P_FIREARM:
if (is_ammo(obj))
descr = "bullet";
break;
case P_FLAIL:
if (obj->otyp == GRAPPLING_HOOK)
descr = "hook";
break;
case P_PICK_AXE:
/* even if "dwarvish mattock" hasn't been discovered yet */
if (obj->otyp == DWARVISH_MATTOCK)
descr = "mattock";
break;
default:
break;
}
return makesingular(descr);
}
int
base_hitbonus(struct obj *otmp) {
int tmp = 0;
boolean Is_weapon;
if (!otmp)
return 0;
Is_weapon = (otmp->oclass == WEAPON_CLASS || is_weptool(otmp));
if (Is_weapon)
tmp += otmp->spe;
/* Put weapon specific "to hit" bonuses in below: */
tmp += objects[otmp->otyp].oc_hitbon;
return tmp;
}
float
role_bab()
{
switch(Role_switch) {
case PM_WIZARD:
case PM_TOURIST:
case PM_CONVICT:
case PM_HEALER:
case PM_CARTOMANCER:
return 0.5;
case PM_MONK:
case PM_ARCHEOLOGIST:
case PM_CLERIC:
case PM_ROGUE:
case PM_DRAGON_RIDER:
return 0.75;
default:
return 1;
}
}
int
role_powregen()
{
switch(Role_switch) {
case PM_WIZARD:
return 2;
case PM_TOURIST:
case PM_MONK:
case PM_ARCHEOLOGIST:
case PM_CLERIC:
return 3;
default:
return 4;
}
}
int
botl_hitbonus()
{
int tmp, tmp2;
uchar aatyp = g.youmonst.data->mattk[0].aatyp;
struct obj *weapon = uwep;
/* tmp = abon() + u.uhitinc + maybe_polyd(g.youmonst.data->mlevel, u.ulevel); */
tmp = abon() + u.uhitinc + (int) (maybe_polyd(g.youmonst.data->mlevel, u.ulevel) * role_bab());
/* role/race adjustments */
if (Role_if(PM_MONK) && !Upolyd) {
if (uarm)
tmp -= g.urole.spelarmr;
else if (!uwep && !uarms)
tmp += (u.ulevel / 3) + 2;
}
/* Power attack penalty */
if (P_SKILL(P_POWER_ATTACK) > P_UNSKILLED
|| P_SKILL(P_CAREFUL_ATTACK) > P_UNSKILLED) {
tmp -= P_SKILL(P_POWER_ATTACK);
tmp += P_SKILL(P_CAREFUL_ATTACK);
tmp += P_SKILL(P_CODE_OF_HONOR);
}
if (uwep && (uwep->otyp == HEAVY_IRON_BALL)) {
tmp += 4;
}
if ((tmp2 = near_capacity()) != 0)
tmp -= (tmp2 * 2) - 1;
if (u.utrap)
tmp -= 3;
if (aatyp == AT_WEAP || aatyp == AT_CLAW) {
if (weapon)
tmp += base_hitbonus(uwep);
if (weapon && !weapon->known)
tmp -= max(0, weapon->spe);
tmp += weapon_hit_bonus(weapon);
} else if (aatyp == AT_KICK && martial_bonus()) {
tmp += weapon_hit_bonus((struct obj *) 0);
}
return tmp;
}
/*
* hitval returns an integer representing the "to hit" bonuses
* of "otmp" against the monster.
*/
int
hitval(struct obj *otmp, struct monst *mon)
{
int tmp = 0;
struct permonst *ptr = mon->data;
boolean Is_weapon = (otmp->oclass == WEAPON_CLASS || is_weptool(otmp));
/* Add the weapon's basic to-hit bonus */
tmp += base_hitbonus(otmp);
/* Power attack penalty */
tmp -= P_SKILL(P_POWER_ATTACK);
tmp += P_SKILL(P_CAREFUL_ATTACK);
tmp += P_SKILL(P_CODE_OF_HONOR);
/* Put weapon vs. monster type "to hit" bonuses in below: */
/* Blessed weapons used against undead or demons */
if (Is_weapon && otmp->blessed
&& (is_demon(ptr) || is_undead(ptr) || is_vampshifter(mon)))
tmp += 2;
if (is_spear(otmp) && index(kebabable, ptr->mlet))
tmp += 2;
/* trident is highly effective against swimmers */
if (otmp->otyp == TRIDENT && is_swimmer(ptr)) {
if (is_pool(mon->mx, mon->my))
tmp += 4;
else if (ptr->mlet == S_EEL || ptr->mlet == S_SNAKE)
tmp += 2;
}
/* Picks used against xorns and earth elementals */
if (is_pick(otmp) && (passes_walls(ptr) && thick_skinned(ptr)))
tmp += 2;
/* Check specially named weapon "to hit" bonuses */
if (otmp->oartifact)
tmp += spec_abon(otmp, mon);
return tmp;
}
#define LOW_ROLL 1
#define HIGH_ROLL 2
#define AVERAGE_ROLL 3
#define RANDOM_ROLL 4
char*
describe_dmgval(char *buf, struct obj *otmp, boolean bigmonst) {
boolean Is_weapon = (otmp->oclass == WEAPON_CLASS || is_weptool(otmp));
int otyp = otmp->otyp;
int flatbon = bigmonst ? (objects[otyp].oc_wldam ? objects[otyp].oc_wldam : 0)
: (objects[otyp].oc_wsdam ? objects[otyp].oc_wsdam : 0);
int spebon = 0;
int matbon = 0;
int low_dmg, high_dmg;
if (Is_weapon && otmp->known) {
spebon += otmp->spe;
}
matbon += odd_material_damage(otmp);
if (P_SKILL(P_POWER_ATTACK) > P_UNSKILLED
|| P_SKILL(P_CAREFUL_ATTACK) > P_UNSKILLED) {
matbon += P_SKILL(P_POWER_ATTACK);
matbon -= P_SKILL(P_CAREFUL_ATTACK);
}
flatbon -= greatest_erosion(otmp);
flatbon += spebon;
if (flatbon < 1)
flatbon = 1;
low_dmg = 1 + spebon + matbon + weapon_distribution_bonus(otyp, bigmonst, LOW_ROLL);
high_dmg = flatbon + matbon + weapon_distribution_bonus(otyp, bigmonst, HIGH_ROLL);
Sprintf(eos(buf), "%d-%d%s", low_dmg, high_dmg, otmp->oartifact ? "++" : "");
return buf;
}
static int
weapon_distribution_bonus(int otyp, boolean bigmonst, int distribution) {
int num_dice = 0;
int sides = 0;
if (bigmonst) {
switch (otyp) {
case IRON_CHAIN:
case CROSSBOW_BOLT:
case MORNING_STAR:
case NASTY_PIKE:
case RUNESWORD:
case ELVEN_BROADSWORD:
case BROADSWORD:
num_dice = 1;
sides = 1;
break;
case FLAIL:
case RANSEUR:
case VOULGE:
case SCYTHE:
num_dice = 1;
sides = 4;
break;
case ACIDIC_LIQUID:
case HALBERD:
case SPETUM:
num_dice = 1;
sides = 6;
break;
case BATTLE_AXE:
case BARDICHE:
case TRIDENT:
case SPIKED_CHAIN:
num_dice = 2;
sides = 4;
break;
case TSURUGI:
case DWARVISH_MATTOCK:
case TWO_HANDED_SWORD:
num_dice = 2;
sides = 6;
break;
}
} else {
switch (otyp) {
case IRON_CHAIN:
case CROSSBOW_BOLT:
case MACE:
case WAR_HAMMER:
case FLAIL:
case SPETUM:
case TRIDENT:
case SPIKED_CHAIN:
num_dice = 1;
sides = 1;
break;
case BATTLE_AXE:
case BARDICHE:
case BILL_GUISARME:
case GUISARME:
case LUCERN_HAMMER:
case MORNING_STAR:
case RANSEUR:
case BROADSWORD:
case ELVEN_BROADSWORD:
case RUNESWORD:
case VOULGE:
case SCYTHE:
num_dice = 1;
sides = 4;
break;
case ACIDIC_LIQUID:
num_dice = 1;
sides = 6;
break;
}
}
switch(distribution) {
case LOW_ROLL:
return num_dice;
case HIGH_ROLL:
return num_dice * sides;
case AVERAGE_ROLL:
return (int) (num_dice * sides / 2);
break;
case RANDOM_ROLL:
default:
d(num_dice, sides);
break;
}
return 0;
}
static int
odd_material_damage(struct obj * otmp) {
int tmp = 0;
if ((is_odd_material(otmp, GLASS) || is_odd_material(otmp, ADAMANTINE)
|| is_odd_material(otmp, GEMSTONE))
&& (objects[otmp->otyp].oc_dir & (PIERCE | SLASH))) {
/* glass, crystal, and adamantine are sharp */
tmp += 3;
}
else if (is_odd_material(otmp, GOLD) || is_odd_material(otmp, PLATINUM)) {
/* heavy metals */
if (objects[otmp->otyp].oc_dir == WHACK) {
tmp += 2;
}
}
else if (is_odd_material(otmp, MINERAL)) {
/* stone is heavy */
if (objects[otmp->otyp].oc_dir == WHACK) {
tmp += 1;
}
}
else if (is_odd_material(otmp, PLASTIC) || is_odd_material(otmp, PAPER)) {
/* just terrible weapons all around */
tmp -= 2;
}
else if (is_odd_material(otmp, SLIME)) {
/* even worse... */
tmp -= 4;
}
else if (is_odd_material(otmp, WOOD)) {
/* poor at holding an edge */
if (is_blade(otmp)) {
tmp -= 1;
}
}
return tmp;
}
/* Historical note: The original versions of Hack used a range of damage
* which was similar to, but not identical to the damage used in Advanced
* Dungeons and Dragons. I figured that since it was so close, I may as well
* make it exactly the same as AD&D, adding some more weapons in the process.
* This has the advantage that it is at least possible that the player would
* already know the damage of at least some of the weapons. This was circa
* 1987 and I used the table from Unearthed Arcana until I got tired of typing
* them in (leading to something of an imbalance towards weapons early in
* alphabetical order). The data structure still doesn't include fields that
* fully allow the appropriate damage to be described (there's no way to say
* 3d6 or 1d6+1) so we add on the extra damage in dmgval() if the weapon
* doesn't do an exact die of damage.
*
* Of course new weapons were added later in the development of Nethack. No
* AD&D consistency was kept, but most of these don't exist in AD&D anyway.
*
* Second edition AD&D came out a few years later; luckily it used the same
* table. As of this writing (1999), third edition is in progress but not
* released. Let's see if the weapon table stays the same. --KAA
* October 2000: It didn't. Oh, well.
*/
/*
* dmgval returns an integer representing the damage bonuses
* of "otmp" against the monster.
*/
int
dmgval(struct obj *otmp, struct monst *mon)
{
int tmp = 0, otyp = otmp->otyp;
struct permonst *ptr = mon->data;
boolean Is_weapon = (otmp->oclass == WEAPON_CLASS || is_weptool(otmp));
if (otyp == CREAM_PIE || otyp == APPLE_PIE || otyp == PUMPKIN_PIE)
return 0;
if (bigmonst(ptr) && objects[otyp].oc_wldam) {
tmp = rnd(objects[otyp].oc_wldam);
} else if (objects[otyp].oc_wsdam) {
tmp = rnd(objects[otyp].oc_wsdam);
}
tmp += weapon_distribution_bonus(otyp, bigmonst(ptr), RANDOM_ROLL);
if (Is_weapon) {
tmp += otmp->spe;
/* adjust for various materials */
tmp += odd_material_damage(otmp);
/* negative modifiers mustn't produce negative damage */
if (tmp < 0)
tmp = 0;
}
if (otmp->material <= LEATHER && thick_skinned(ptr))
/* thick skinned/scaled creatures don't feel it */
tmp = 0;
if (ptr == &mons[PM_SHADE] && !shade_glare(otmp))
tmp = 0;
/* "very heavy iron ball"; weight increase is in increments */
if (otyp == HEAVY_IRON_BALL && tmp > 0) {
int wt = (int) objects[HEAVY_IRON_BALL].oc_weight;
if ((int) otmp->owt > wt) {
wt = ((int) otmp->owt - wt) / IRON_BALL_W_INCR;
tmp += rnd(4 * wt);
if (tmp > 25)
tmp = 25; /* objects[].oc_wldam */
}
}
/* power attack yields a flat damage bonus increase. */
tmp += P_SKILL(P_POWER_ATTACK);
tmp -= P_SKILL(P_CAREFUL_ATTACK);
/* Put weapon vs. monster type damage bonuses in below: */
if (Is_weapon || otmp->oclass == GEM_CLASS || otmp->oclass == BALL_CLASS
|| otmp->oclass == CHAIN_CLASS) {
int bonus = 0;
if (otmp->blessed
&& (is_undead(ptr) || is_demon(ptr) || is_vampshifter(mon)))
bonus += rnd(4);
if (is_axe(otmp) && is_wooden(ptr))
bonus += rnd(4);
if (mon_hates_material(mon, otmp->material))
bonus += rnd(sear_damage(otmp->material));
if (artifact_light(otmp) && otmp->lamplit && hates_light(ptr))
bonus += rnd(8);
/* if the weapon is going to get a double damage bonus, adjust
this bonus so that effectively it's added after the doubling */
if (bonus > 1 && otmp->oartifact && spec_dbon(otmp, mon, 25) >= 25)
bonus = (bonus + 1) / 2;
tmp += bonus;
}
if (tmp > 0) {
/* It's debatable whether a rusted blunt instrument
should do less damage than a pristine one, since
it will hit with essentially the same impact, but
there ought to some penalty for using damaged gear
so always subtract erosion even for blunt weapons. */
tmp -= greatest_erosion(otmp);
if (tmp < 1)
tmp = 1;
}
return tmp;
}
/* Find an object that magr is wearing (or even magr's body itself) that has a
* special damaging effect on mdef, and return the amount of bonus damage done.
* The most damaging source has precedence; each source that causes special
* damage makes its own roll for damage, and the highest roll will be applied.
*/
#undef LOW_ROLL
#undef HIGH_ROLL
#undef AVERAGE_ROLL
#undef RANDOM_ROLL
/* Find an object that magr is wearing (or even magr's body itself) that has a
* special damaging effect on mdef, and return the amount of bonus damage done.
* The most damaging source has precedence; each source that causes special
* damage makes its own roll for damage, and the highest roll will be applied.
*
* hated_obj is set only on objects that cause material hatred; if none of the
* applicable objects are of a hated material, it will not be set.
*/
int
special_dmgval(struct monst *magr,
struct monst *mdef,
long armask, /* armor mask of all the slots that can be touching
* mdef */
struct obj **hated_obj) /* ptr to offending object, can be NULL
* if not wanted */
{
boolean youattack = (magr == &g.youmonst);
const int magr_material = monmaterial(monsndx(magr->data));
int bonus = 0;
int tmpbonus = 0;
boolean try_body = FALSE;
struct obj *gloves = which_armor(magr, W_ARMG),
*helm = which_armor(magr, W_ARMH),
*shield = which_armor(magr, W_ARMS),
*boots = which_armor(magr, W_ARMF),
*armor = which_armor(magr, W_ARM),
*cloak = which_armor(magr, W_ARMC),
*shirt = which_armor(magr, W_ARMU),
*leftring = (youattack ? uleft : which_armor(magr, W_RINGL)),
*rightring = (youattack ? uright : which_armor(magr, W_RINGR));
if (hated_obj) {
*hated_obj = 0;
}
/* Simple exclusions where we ignore a certain type of armor because it is
* covered by some other equipment. */
if (gloves) {
leftring = rightring = NULL;
}
if (cloak) {
armor = shirt = NULL;
}
if (armor) {
shirt = NULL;
}
/* Cases where we want to count magr's body: the caller indicates a certain
* slot is making contact, and magr is not wearing anything in that slot, so
* their body must be making contact.
* Note: in the gloves case, rings don't prevent magr's body from making
* contact. */
if (((armask & W_ARMG) && !gloves)
|| ((armask & W_ARMF) && !boots)
|| ((armask & W_ARMH) && !helm)
|| ((armask & (W_ARMC | W_ARM | W_ARMU))
&& !cloak && !armor && !shirt)) {
try_body = TRUE;
}
if (try_body && mon_hates_material(mdef, magr_material)) {
bonus = sear_damage(magr_material);
if (hated_obj)
*hated_obj = (struct obj *) &cg.zeroobj;
}
/* The order of armor slots in this array doesn't really matter because we
* roll for everything that applies and take the highest damage. */
struct {
long mask;
struct obj* obj;
} array[9] = {
{ W_ARMG, gloves },
{ W_ARMH, helm },
{ W_ARMS, shield },
{ W_ARMF, boots },
{ W_ARM, armor },
{ W_ARMC, cloak },
{ W_ARMU, shirt },
{ W_RINGL, leftring },
{ W_RINGR, rightring }
};
int i;
for (i = 0; i < 9; ++i) {
if (array[i].obj && (armask & array[i].mask)) {
tmpbonus = dmgval(array[i].obj, mdef);
if (tmpbonus > bonus) {
bonus = tmpbonus;
if (hated_obj) {
/* Select hated_obj based on the maximum possible amount of
* damage that can be caused by its material, not the actual
* random amount of damage.
* E.g. if you manage to hit a monster that hates both
* silver and iron with a silver and an iron item at the
* same time, silver has a more severe effect dealing more
* damage so hated_obj should always be set to the silver
* one, so that searmsg will get called with the most
* appropriate message.
*/
if (mon_hates_material(mdef, array[i].obj->material)
&& (*hated_obj == NULL
|| (sear_damage(array[i].obj->material)
> sear_damage((*hated_obj)->material)))) {
*hated_obj = array[i].obj;
}
}
}
}
}
return bonus;
}
/* give a "silver <item> sears <target>" message (or similar for other
* material); in addition to weapon hit, this is used for rings, boots for kick,
* gloves for punch, or helm for headbutt.
*/
void
searmsg(struct monst *magr, struct monst *mdef, const struct obj *obj, boolean minimal)
{
boolean youattack = (magr == &g.youmonst);
boolean youdefend = (mdef == &g.youmonst);
boolean has_flesh = (!noncorporeal(mdef->data) && !amorphous(mdef->data));
if (!obj) {
impossible("searmsg: nothing searing?");
return;
}
if (!youdefend && !canspotmon(mdef)) {
return;
}
char onamebuf[BUFSZ];
char whose[BUFSZ];
int mat;
if (obj == &cg.zeroobj) {
mat = monmaterial(monsndx(magr->data));
Sprintf(onamebuf, "%s touch", materialnm[mat]);
if (youattack) {
Strcpy(whose, "your ");
}
else if (!magr) {
impossible("searmsg: non-weapon attack with no aggressor?");
return;
}
else {
Strcpy(whose, s_suffix(y_monnam(magr)));
Strcat(whose, " ");
}
}
else {
mat = obj->material;
const char* matname = materialnm[mat];
/* Why doesn't cxname receive a const struct obj? */
char* cxnameobj = cxname((struct obj *) obj);
/* Make it explicit to the player that this effect is from the material,
* by prepending the material, but only if the object's name doesn't
* already contain the material string somewhere. (e.g. "sword" should
* turn into "iron sword", but "engraved silver bell" shouldn't turn
* into "silver engraved silver bell") */
boolean alreadyin = (strstri(cxnameobj, matname) != NULL);
if (!alreadyin) {
Sprintf(onamebuf, "%s %s", matname, cxnameobj);
}
else {
Strcpy(onamebuf, cxnameobj);
}
shk_your(whose, (struct obj *) obj);
}
if (minimal) {
/* instead of "foo's obj", it will be "the [touch of] <material>;
* whose becomes "the" in both cases */
Strcpy(whose, "the ");
if (mat == SILVER) { /* different formatting */
Strcpy(onamebuf, "silver");
}
else {
Sprintf(onamebuf, "touch of %s", materialnm[mat]);
}
}
/* "Extra-minimal" case where we don't know what is doing the searing.
* Note that this can assume it will be formatting some non-player entity
* because it only applies when the player isn't involved. */
if (!youattack && !youdefend && !canseemon(mdef) && minimal) {
if (mat == SILVER || mat == COLD_IRON) {
char defender[BUFSZ];
if (has_flesh) {
Sprintf(defender, "%s flesh", s_suffix(Monnam(mdef)));
}
else {
Strcpy(defender, Monnam(mdef));
}
pline("%s is seared!", defender);
}
else {
pline("%s recoils!", Monnam(mdef));
}
return;
}
/* char* whom = youdefend ? "you" : mon_nam(mdef); */
char* whom = mon_nam(mdef);
if (youdefend) {
Strcpy(whom, "you");
}
if (mat == SILVER || mat == COLD_IRON) { /* more dramatic effects than other materials */
/* note: s_suffix returns a modifiable buffer */
if (has_flesh)
whom = strcat(s_suffix(whom), " flesh");
pline("%s%s %s %s!", upstart(whose), onamebuf,
vtense(onamebuf, "sear"), whom);
}
else {
whom = upstart(whom);
pline("%s recoil%s from %s%s!", whom, (youdefend ? "" : "s"),
whose, onamebuf);
}
}
/* give a "silver <item> sears <target>" message;
not used for weapon hit, so we only handle rings */
void
silver_sears(struct monst *magr UNUSED, struct monst *mdef,
long silverhit)
{
char rings[20]; /* plenty of room for "rings" */
int ltyp = ((uleft && (silverhit & W_RINGL) != 0L)
? uleft->otyp : STRANGE_OBJECT),
rtyp = ((uright && (silverhit & W_RINGR) != 0L)
? uright->otyp : STRANGE_OBJECT);
boolean both,
l_ag = (objects[ltyp].oc_material == SILVER && uleft->dknown),
r_ag = (objects[rtyp].oc_material == SILVER && uright->dknown);
if ((silverhit & (W_RINGL | W_RINGR)) != 0L) {
/* plural if both the same type (so not multi_claw and both rings
are non-Null) and either both known or neither known, or both
silver (in case there is ever more than one type of silver ring)
and both known; singular if multi_claw (where one of ltyp or
rtyp will always be STRANGE_OBJECT) even if both rings are known
silver [see hmonas(uhitm.c) for explanation of 'multi_claw'] */
both = ((ltyp == rtyp && uleft->dknown == uright->dknown)
|| (l_ag && r_ag));
Sprintf(rings, "ring%s", both ? "s" : "");
Your("%s%s %s %s!",
(l_ag || r_ag) ? "silver "
: both ? ""
: ((silverhit & W_RINGL) != 0L) ? "left "
: "right ",
rings, vtense(rings, "sear"), mon_nam(mdef));
}
}
static struct obj *oselect(struct monst *, int);
#define Oselect(x) \
if ((otmp = oselect(mtmp, x)) != 0) \
return otmp;
static struct obj *
oselect(struct monst *mtmp, int x)
{
struct obj *otmp, *obest = 0;
for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) {
if (otmp->otyp == x
/* never select non-cockatrice corpses */
&& !((x == CORPSE || x == EGG)
&& !touch_petrifies(&mons[otmp->corpsenm]))
&& (!otmp->oartifact || touch_artifact(otmp, mtmp))
&& !mon_hates_material(mtmp, otmp->material)) {
if (!obest ||
dmgval(otmp, &g.youmonst) > dmgval(obest, &g.youmonst))
obest = otmp;
}
}
return obest;
}
/* TODO: have monsters use aklys' throw-and-return */
static NEARDATA const int rwep[] = {
FRAG_GRENADE, GAS_GRENADE, BULLET, SHOTGUN_SHELL,
DWARVISH_SPEAR, ELVEN_SPEAR, SPEAR, ORCISH_SPEAR, JAVELIN,
THROWING_AXE,
SHURIKEN, LIGHT_ARROW, YA, ELVEN_ARROW, DARK_ELVEN_ARROW,
ARROW, ORCISH_ARROW,
CROSSBOW_BOLT, ELVEN_DAGGER, DARK_ELVEN_DAGGER, DAGGER, ORCISH_DAGGER, KNIFE,
FLINT, ROCK, LOADSTONE, LUCKSTONE, DART, FRUITCAKE, PINEAPPLE,
/* CHAKRAM, BOOMERANG, */ CREAM_PIE
};
static NEARDATA const int pwep[] = { SPIKED_CHAIN,
HALBERD, BARDICHE, SPETUM,
BILL_GUISARME, VOULGE, RANSEUR,
GUISARME, GLAIVE, LUCERN_HAMMER,
BEC_DE_CORBIN, FAUCHARD, NASTY_PIKE,
LANCE };
/* select a ranged weapon for the monster */
struct obj *
select_rwep(struct monst *mtmp)
{
register struct obj *otmp;
struct obj *mwep;
boolean mweponly;
int i;
char mlet = mtmp->data->mlet;
g.propellor = (struct obj *) &cg.zeroobj;
Oselect(EGG); /* cockatrice egg */
if (mlet == S_KOP) /* pies are first choice for Kops */
Oselect(CREAM_PIE);
if (throws_rocks(mtmp->data)) /* ...boulders for giants */
Oselect(BOULDER);
/* Select polearms first; they do more damage and aren't expendable.
But don't pick one if monster's weapon is welded, because then
we'd never have a chance to throw non-wielding missiles. */
/* The limit of 13 here is based on the monster polearm range limit
* (defined as 5 in mthrowu.c). 5 corresponds to a distance of 2 in
* one direction and 1 in another; one space beyond that would be 3 in
* one direction and 2 in another; 3^2+2^2=13.
*/