/
effects.c
5308 lines (4393 loc) · 128 KB
/
effects.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
/**
* \file effects.c
* \brief Handler and auxiliary functions for every effect in the game
*
* Copyright (c) 2007 Andi Sidwell
* Copyright (c) 2016 Ben Semmler, Nick McConnell
*
* This work is free software; you can redistribute it and/or modify it
* under the terms of either:
*
* a) the GNU General Public License as published by the Free Software
* Foundation, version 2, or
*
* b) the "Angband licence":
* This software may be copied and distributed for educational, research,
* and not for profit purposes provided that this copyright and statement
* are included in all such copies. Other copyrights may also apply.
*/
#include "angband.h"
#include "cave.h"
#include "effects.h"
#include "game-input.h"
#include "generate.h"
#include "init.h"
#include "mon-desc.h"
#include "mon-lore.h"
#include "mon-make.h"
#include "mon-msg.h"
#include "mon-predicate.h"
#include "mon-spell.h"
#include "mon-summon.h"
#include "mon-util.h"
#include "mon-timed.h"
#include "obj-chest.h"
#include "obj-curse.h"
#include "obj-desc.h"
#include "obj-gear.h"
#include "obj-ignore.h"
#include "obj-knowledge.h"
#include "obj-make.h"
#include "obj-pile.h"
#include "obj-power.h"
#include "obj-tval.h"
#include "obj-util.h"
#include "player-calcs.h"
#include "player-history.h"
#include "player-spell.h"
#include "player-timed.h"
#include "player-util.h"
#include "project.h"
#include "source.h"
#include "target.h"
#include "trap.h"
/**
* ------------------------------------------------------------------------
* Structures and helper functions for effects
* ------------------------------------------------------------------------ */
typedef struct effect_handler_context_s {
const effect_index effect;
const struct source origin;
const struct object *obj;
const bool aware;
const int dir;
const int beam;
const int boost;
const random_value value;
const int subtype, radius, other, y, x;
const char *msg;
bool ident;
} effect_handler_context_t;
typedef bool (*effect_handler_f)(effect_handler_context_t *);
/**
* Structure for effects
*/
struct effect_kind {
u16b index; /* Effect index */
bool aim; /* Whether the effect requires aiming */
const char *info; /* Effect info (for spell tips) */
effect_handler_f handler; /* Function to perform the effect */
const char *desc; /* Effect description */
};
/**
* Stat adjectives
*/
static const char *desc_stat(int stat, bool positive)
{
struct obj_property *prop = lookup_obj_property(OBJ_PROPERTY_STAT, stat);
if (positive) {
return prop->adjective;
}
return prop->neg_adj;
}
int effect_calculate_value(effect_handler_context_t *context, bool use_boost)
{
int final = 0;
if (context->value.base > 0 ||
(context->value.dice > 0 && context->value.sides > 0))
final = context->value.base +
damroll(context->value.dice, context->value.sides);
if (use_boost) {
final *= (100 + context->boost);
final /= 100;
}
return final;
}
static void get_target(struct source origin, int dir, struct loc *grid,
int *flags)
{
switch (origin.what) {
case SRC_MONSTER: {
struct monster *monster = cave_monster(cave, origin.which.monster);
int conf_level = monster_effect_level(monster, MON_TMD_CONF);
int accuracy = 100;
while (conf_level) {
accuracy *= (100 - CONF_RANDOM_CHANCE);
accuracy /= 100;
conf_level--;
}
*flags |= (PROJECT_PLAY);
if (randint1(100) > accuracy) {
dir = randint1(9);
*grid = loc_sum(monster->grid, ddgrid[dir]);
} else if (monster->target.midx > 0) {
struct monster *mon = cave_monster(cave, monster->target.midx);
*grid = mon->grid;
} else {
struct loc decoy = cave_find_decoy(cave);
if (!loc_is_zero(decoy)) {
*grid = decoy;
} else {
*grid = player->grid;
}
}
break;
}
case SRC_PLAYER:
if (dir == DIR_TARGET && target_okay()) {
target_get(grid);
} else {
/* Use the adjacent grid in the given direction as target */
*grid = loc_sum(player->grid, ddgrid[dir]);
}
break;
default:
*flags |= PROJECT_PLAY;
*grid = player->grid;
break;
}
}
/**
* Check for monster targeting another monster
*/
static struct monster *monster_target_monster(effect_handler_context_t *context)
{
if (context->origin.what == SRC_MONSTER) {
struct monster *mon = cave_monster(cave, context->origin.which.monster);
if (mon->target.midx > 0) {
struct monster *t_mon = cave_monster(cave, mon->target.midx);
assert(t_mon);
return t_mon;
}
}
return NULL;
}
/**
* Apply the project() function in a direction, or at a target
*/
static bool project_aimed(struct source origin,
int typ, int dir, int dam, int flg,
const struct object *obj)
{
struct loc grid = loc(-1, -1);
/* Pass through the target if needed */
flg |= (PROJECT_THRU);
get_target(origin, dir, &grid, &flg);
/* Aim at the target, do NOT explode */
return (project(origin, 0, grid, dam, typ, flg, 0, 0, obj));
}
/**
* Apply the project() function to grids around the target
*/
static bool project_touch(int dam, int rad, int typ, bool aware,
const struct object *obj)
{
struct loc pgrid = player->grid;
int flg = PROJECT_GRID | PROJECT_KILL | PROJECT_HIDE | PROJECT_ITEM | PROJECT_THRU;
if (aware) flg |= PROJECT_AWARE;
return (project(source_player(), rad, pgrid, dam, typ, flg, 0, 0, obj));
}
/**
* Selects items that have at least one removable curse.
*/
static bool item_tester_uncursable(const struct object *obj)
{
struct curse_data *c = obj->known->curses;
if (c) {
size_t i;
for (i = 1; i < z_info->curse_max; i++) {
if (c[i].power < 100) {
return true;
}
}
}
return false;
}
/**
* Removes an individual curse from an object.
*/
static void remove_object_curse(struct object *obj, int index, bool message)
{
struct curse_data *c = &obj->curses[index];
char *name = curses[index].name;
char *removed = format("The %s curse is removed!", name);
int i;
c->power = 0;
c->timeout = 0;
if (message) {
msg(removed);
}
/* Check to see if that was the last one */
for (i = 1; i < z_info->curse_max; i++) {
if (obj->curses[i].power) {
return;
}
}
mem_free(obj->curses);
obj->curses = NULL;
}
/**
* Attempts to remove a curse from an object.
*/
static bool uncurse_object(struct object *obj, int strength, char *dice_string)
{
int index = 0;
if (get_curse(&index, obj, dice_string)) {
struct curse_data curse = obj->curses[index];
char o_name[80];
if (curse.power >= 100) {
/* Curse is permanent */
return false;
} else if (strength >= curse.power) {
/* Successfully removed this curse */
remove_object_curse(obj->known, index, false);
remove_object_curse(obj, index, true);
} else if (!of_has(obj->flags, OF_FRAGILE)) {
/* Failure to remove, object is now fragile */
object_desc(o_name, sizeof(o_name), obj, ODESC_FULL);
msgt(MSG_CURSED, "The spell fails; your %s is now fragile.", o_name);
of_on(obj->flags, OF_FRAGILE);
player_learn_flag(player, OF_FRAGILE);
} else if (one_in_(4)) {
/* Failure - unlucky fragile object is destroyed */
struct object *destroyed;
bool none_left = false;
msg("There is a bang and a flash!");
take_hit(player, damroll(5, 5), "Failed uncursing");
if (object_is_carried(player, obj)) {
destroyed = gear_object_for_use(obj, 1, false, &none_left);
object_delete(&destroyed->known);
object_delete(&destroyed);
} else {
square_excise_object(cave, obj->grid, obj);
delist_object(cave, obj);
object_delete(&obj);
square_note_spot(cave, player->grid);
square_light_spot(cave, player->grid);
}
} else {
/* Non-destructive failure */
msg("The removal fails.");
}
} else {
return false;
}
player->upkeep->update |= (PU_BONUS);
player->upkeep->redraw |= (PR_EQUIP | PR_INVEN);
return true;
}
/**
* Selects items that have at least one unknown rune.
*/
static bool item_tester_unknown(const struct object *obj)
{
return object_runes_known(obj) ? false : true;
}
/**
* Bit flags for the enchant() function
*/
#define ENCH_TOHIT 0x01
#define ENCH_TODAM 0x02
#define ENCH_TOBOTH 0x03
#define ENCH_TOAC 0x04
/**
* Used by the enchant() function (chance of failure)
*/
static const int enchant_table[16] =
{
0, 10, 20, 40, 80,
160, 280, 400, 550, 700,
800, 900, 950, 970, 990,
1000
};
/**
* Hook to specify "weapon"
*/
static bool item_tester_hook_weapon(const struct object *obj)
{
return tval_is_weapon(obj);
}
/**
* Hook to specify "armour"
*/
static bool item_tester_hook_armour(const struct object *obj)
{
return tval_is_armor(obj);
}
/**
* Tries to increase an items bonus score, if possible.
*
* \returns true if the bonus was increased
*/
static bool enchant_score(s16b *score, bool is_artifact)
{
int chance;
/* Artifacts resist enchantment half the time */
if (is_artifact && randint0(100) < 50) return false;
/* Figure out the chance to enchant */
if (*score < 0) chance = 0;
else if (*score > 15) chance = 1000;
else chance = enchant_table[*score];
/* If we roll less-than-or-equal to chance, it fails */
if (randint1(1000) <= chance) return false;
/* Increment the score */
++*score;
return true;
}
/**
* Helper function for enchant() which tries increasing an item's bonuses
*
* \returns true if a bonus was increased
*/
static bool enchant2(struct object *obj, s16b *score)
{
bool result = false;
bool is_artifact = obj->artifact ? true : false;
if (enchant_score(score, is_artifact)) result = true;
return result;
}
/**
* Enchant an item
*
* Revamped! Now takes item pointer, number of times to try enchanting, and a
* flag of what to try enchanting. Artifacts resist enchantment some of the
* time. Also, any enchantment attempt (even unsuccessful) kicks off a parallel
* attempt to uncurse a cursed item.
*
* Note that an item can technically be enchanted all the way to +15 if you
* wait a very, very, long time. Going from +9 to +10 only works about 5% of
* the time, and from +10 to +11 only about 1% of the time.
*
* Note that this function can now be used on "piles" of items, and the larger
* the pile, the lower the chance of success.
*
* \returns true if the item was changed in some way
*/
bool enchant(struct object *obj, int n, int eflag)
{
int i, prob;
bool res = false;
/* Large piles resist enchantment */
prob = obj->number * 100;
/* Missiles are easy to enchant */
if (tval_is_ammo(obj)) prob = prob / 20;
/* Try "n" times */
for (i = 0; i < n; i++)
{
/* Roll for pile resistance */
if (prob > 100 && randint0(prob) >= 100) continue;
/* Try the three kinds of enchantment we can do */
if ((eflag & ENCH_TOHIT) && enchant2(obj, &obj->to_h)) res = true;
if ((eflag & ENCH_TODAM) && enchant2(obj, &obj->to_d)) res = true;
if ((eflag & ENCH_TOAC) && enchant2(obj, &obj->to_a)) res = true;
}
/* Update knowledge */
assert(obj->known);
obj->known->to_h = obj->to_h;
obj->known->to_d = obj->to_d;
obj->known->to_a = obj->to_a;
/* Failure */
if (!res) return (false);
/* Recalculate bonuses, gear */
player->upkeep->update |= (PU_BONUS | PU_INVEN);
/* Combine the pack (later) */
player->upkeep->notice |= (PN_COMBINE);
/* Redraw stuff */
player->upkeep->redraw |= (PR_INVEN | PR_EQUIP );
/* Success */
return (true);
}
/**
* Enchant an item (in the inventory or on the floor)
* Note that "num_ac" requires armour, else weapon
* Returns true if attempted, false if cancelled
*
* Enchanting with the TOBOTH flag will try to enchant
* both to_hit and to_dam with the same flag. This
* may not be the most desirable behavior (ACB).
*/
bool enchant_spell(int num_hit, int num_dam, int num_ac)
{
bool okay = false;
struct object *obj;
char o_name[80];
const char *q, *s;
/* Get an item */
q = "Enchant which item? ";
s = "You have nothing to enchant.";
if (!get_item(&obj, q, s, 0,
num_ac ? item_tester_hook_armour : item_tester_hook_weapon,
(USE_EQUIP | USE_INVEN | USE_QUIVER | USE_FLOOR)))
return false;
/* Description */
object_desc(o_name, sizeof(o_name), obj, ODESC_BASE);
/* Describe */
msg("%s %s glow%s brightly!",
(object_is_carried(player, obj) ? "Your" : "The"), o_name,
((obj->number > 1) ? "" : "s"));
/* Enchant */
if (num_dam && enchant(obj, num_hit, ENCH_TOBOTH)) okay = true;
else if (enchant(obj, num_hit, ENCH_TOHIT)) okay = true;
else if (enchant(obj, num_dam, ENCH_TODAM)) okay = true;
if (enchant(obj, num_ac, ENCH_TOAC)) okay = true;
/* Failure */
if (!okay) {
event_signal(EVENT_INPUT_FLUSH);
/* Message */
msg("The enchantment failed.");
}
/* Something happened */
return (true);
}
/**
* Brand weapons (or ammo)
*
* Turns the (non-magical) object into an ego-item of 'brand_type'.
*/
void brand_object(struct object *obj, const char *name)
{
int i;
struct ego_item *ego;
bool ok = false;
/* You can never modify artifacts, ego items or worthless items */
if (obj && obj->kind->cost && !obj->artifact && !obj->ego) {
char o_name[80];
char brand[20];
object_desc(o_name, sizeof(o_name), obj, ODESC_BASE);
strnfmt(brand, sizeof(brand), "of %s", name);
/* Describe */
msg("The %s %s surrounded with an aura of %s.", o_name,
(obj->number > 1) ? "are" : "is", name);
/* Get the right ego type for the object */
for (i = 0; i < z_info->e_max; i++) {
ego = &e_info[i];
/* Match the name */
if (!ego->name) continue;
if (streq(ego->name, brand)) {
struct poss_item *poss;
for (poss = ego->poss_items; poss; poss = poss->next)
if (poss->kidx == obj->kind->kidx)
ok = true;
}
if (ok) break;
}
/* Make it an ego item */
obj->ego = &e_info[i];
ego_apply_magic(obj, 0);
player_know_object(player, obj);
/* Update the gear */
player->upkeep->update |= (PU_INVEN);
/* Combine the pack (later) */
player->upkeep->notice |= (PN_COMBINE);
/* Window stuff */
player->upkeep->redraw |= (PR_INVEN | PR_EQUIP);
/* Enchant */
enchant(obj, randint0(3) + 4, ENCH_TOHIT | ENCH_TODAM);
} else {
event_signal(EVENT_INPUT_FLUSH);
msg("The branding failed.");
}
}
/**
* Hook for "get_item()". Determine if something is rechargable.
*/
static bool item_tester_hook_recharge(const struct object *obj)
{
/* Recharge staves and wands */
if (tval_can_have_charges(obj)) return true;
return false;
}
/**
* Hook to specify "ammo"
*/
static bool item_tester_hook_ammo(const struct object *obj)
{
return tval_is_ammo(obj);
}
/**
* Hook to specify bolts
*/
static bool item_tester_hook_bolt(const struct object *obj)
{
return obj->tval == TV_BOLT;
}
/**
* ------------------------------------------------------------------------
* Effect handlers
* ------------------------------------------------------------------------ */
/**
* Dummy effect, to tell the effect code to pick one of the next
* context->value.base effects at random.
*/
bool effect_handler_RANDOM(effect_handler_context_t *context)
{
return true;
}
/**
* Deal damage from the current monster or trap to the player
*/
bool effect_handler_DAMAGE(effect_handler_context_t *context)
{
int dam = effect_calculate_value(context, false);
char killer[80];
/* Always ID */
context->ident = true;
switch (context->origin.what) {
case SRC_MONSTER: {
struct monster *mon = cave_monster(cave,
context->origin.which.monster);
struct monster *t_mon = monster_target_monster(context);
struct loc decoy = cave_find_decoy(cave);
/* Damage another monster */
if (t_mon) {
bool fear = false;
mon_take_hit(t_mon, dam, &fear, " dies.");
if (fear && monster_is_visible(t_mon)) {
add_monster_message(t_mon, MON_MSG_FLEE_IN_TERROR, true);
}
return true;
}
/* Destroy a decoy */
if (decoy.y && decoy.x) {
square_destroy_decoy(cave, decoy);
return true;
}
monster_desc(killer, sizeof(killer), mon, MDESC_DIED_FROM);
break;
}
case SRC_TRAP: {
struct trap *trap = context->origin.which.trap;
char *article = is_a_vowel(trap->kind->desc[0]) ? "an " : "a ";
strnfmt(killer, sizeof(killer), "%s%s", article, trap->kind->desc);
break;
}
case SRC_OBJECT: {
/* Must be a cursed weapon */
struct object *obj = context->origin.which.object;
object_desc(killer, sizeof(killer), obj, ODESC_PREFIX | ODESC_BASE);
break;
}
case SRC_PLAYER: {
if (context->msg) {
my_strcpy(killer, context->msg, sizeof(killer));
} else {
my_strcpy(killer, "yourself", sizeof(killer));
}
break;
}
case SRC_NONE: {
my_strcpy(killer, "a bug", sizeof(killer));
break;
}
}
/* Hit the player */
take_hit(player, dam, killer);
return true;
}
/**
* Heal the player by a given percentage of their wounds, or a minimum
* amount, whichever is larger.
*
* context->value.base should be the minimum, and
* context->value.m_bonus the percentage
*/
bool effect_handler_HEAL_HP(effect_handler_context_t *context)
{
int num;
/* Paranoia */
if ((context->value.m_bonus <= 0) && (context->value.base <= 0))
return (true);
/* Always ID */
context->ident = true;
/* No healing needed */
if (player->chp >= player->mhp) return (true);
/* Figure percentage healing level */
num = ((player->mhp - player->chp) * context->value.m_bonus) / 100;
/* Enforce minimum */
if (num < context->value.base) num = context->value.base;
/* Gain hitpoints */
player->chp += num;
/* Enforce maximum */
if (player->chp >= player->mhp) {
player->chp = player->mhp;
player->chp_frac = 0;
}
/* Redraw */
player->upkeep->redraw |= (PR_HP);
/* Print a nice message */
if (num < 5)
msg("You feel a little better.");
else if (num < 15)
msg("You feel better.");
else if (num < 35)
msg("You feel much better.");
else
msg("You feel very good.");
return (true);
}
/**
* Monster self-healing.
*/
bool effect_handler_MON_HEAL_HP(effect_handler_context_t *context)
{
assert(context->origin.what == SRC_MONSTER);
int midx = context->origin.which.monster;
struct monster *mon = midx > 0 ? cave_monster(cave, midx) : NULL;
int amount = effect_calculate_value(context, false);
char m_name[80], m_poss[80];
bool seen;
if (!mon) return true;
/* Get the monster name (or "it") */
monster_desc(m_name, sizeof(m_name), mon, MDESC_STANDARD);
/* Get the monster possessive ("his"/"her"/"its") */
monster_desc(m_poss, sizeof(m_poss), mon, MDESC_PRO_VIS | MDESC_POSS);
seen = (!player->timed[TMD_BLIND] && monster_is_visible(mon));
/* Heal some */
mon->hp += amount;
/* Fully healed */
if (mon->hp >= mon->maxhp) {
mon->hp = mon->maxhp;
if (seen)
msg("%s looks REALLY healthy!", m_name);
else
msg("%s sounds REALLY healthy!", m_name);
} else if (seen) { /* Partially healed */
msg("%s looks healthier.", m_name);
} else {
msg("%s sounds healthier.", m_name);
}
/* Redraw (later) if needed */
if (player->upkeep->health_who == mon)
player->upkeep->redraw |= (PR_HEALTH);
/* Cancel fear */
if (mon->m_timed[MON_TMD_FEAR]) {
mon_clear_timed(mon, MON_TMD_FEAR, MON_TMD_FLG_NOMESSAGE, false);
msg("%s recovers %s courage.", m_name, m_poss);
}
/* ID */
context->ident = true;
return true;
}
/**
* Monster healing of kin.
*/
bool effect_handler_MON_HEAL_KIN(effect_handler_context_t *context)
{
assert(context->origin.what == SRC_MONSTER);
int midx = context->origin.which.monster;
struct monster *mon = midx > 0 ? cave_monster(cave, midx) : NULL;
if (!mon) return true;
int amount = effect_calculate_value(context, false);
char m_name[80], m_poss[80];
bool seen;
/* Find a nearby monster */
mon = choose_nearby_injured_kin(cave, mon);
if (!mon) return true;
/* Get the monster name (or "it") */
monster_desc(m_name, sizeof(m_name), mon, MDESC_STANDARD);
/* Get the monster possessive ("his"/"her"/"its") */
monster_desc(m_poss, sizeof(m_poss), mon, MDESC_PRO_VIS | MDESC_POSS);
seen = (!player->timed[TMD_BLIND] && monster_is_visible(mon));
/* Heal some */
mon->hp = MIN(mon->hp + amount, mon->maxhp);
if (seen) {
if (mon->hp == mon->maxhp) {
msg("%s looks REALLY healthy!", m_name);
} else if (seen) { /* Partially healed */
msg("%s looks healthier.", m_name);
}
}
/* Redraw (later) if needed */
if (player->upkeep->health_who == mon)
player->upkeep->redraw |= (PR_HEALTH);
/* Cancel fear */
if (mon->m_timed[MON_TMD_FEAR]) {
mon_clear_timed(mon, MON_TMD_FEAR, MON_TMD_FLG_NOMESSAGE, false);
msg("%s recovers %s courage.", m_name, m_poss);
}
/* ID */
context->ident = true;
return true;
}
/**
* Feed the player.
*/
bool effect_handler_NOURISH(effect_handler_context_t *context)
{
int amount = effect_calculate_value(context, false);
player_set_food(player, player->food + amount);
context->ident = true;
return true;
}
bool effect_handler_CRUNCH(effect_handler_context_t *context)
{
if (one_in_(2))
msg("It's crunchy.");
else
msg("It nearly breaks your tooth!");
context->ident = true;
return true;
}
/**
* Cure a player status condition.
*/
bool effect_handler_CURE(effect_handler_context_t *context)
{
int type = context->subtype;
(void) player_clear_timed(player, type, true);
context->ident = true;
return true;
}
/**
* Set a (positive or negative) player status condition.
*/
bool effect_handler_TIMED_SET(effect_handler_context_t *context)
{
int amount = effect_calculate_value(context, false);
player_set_timed(player, context->subtype, MAX(amount, 0), true);
context->ident = true;
return true;
}
/**
* Extend a (positive or negative) player status condition.
* If context->other is set, increase by that amount if the player already
* has the status
*/
bool effect_handler_TIMED_INC(effect_handler_context_t *context)
{
int amount = effect_calculate_value(context, false);
struct monster *t_mon = monster_target_monster(context);
struct loc decoy = cave_find_decoy(cave);
context->ident = true;
/* Destroy decoy */
if (decoy.y && decoy.x) {
square_destroy_decoy(cave, decoy);
return true;
}
/* Check for monster targeting another monster */
if (t_mon) {
int mon_tmd_effect = -1;
/* Will do until monster and player timed effects are fused */
switch (context->subtype) {
case TMD_CONFUSED: {
mon_tmd_effect = MON_TMD_CONF;
break;
}
case TMD_SLOW: {
mon_tmd_effect = MON_TMD_SLOW;
break;
}
case TMD_PARALYZED: {
mon_tmd_effect = MON_TMD_HOLD;
break;
}
case TMD_BLIND: {
mon_tmd_effect = MON_TMD_STUN;
break;
}
case TMD_AFRAID: {
mon_tmd_effect = MON_TMD_FEAR;
break;
}
case TMD_AMNESIA: {
mon_tmd_effect = MON_TMD_SLEEP;
break;
}
default: {
break;
}
}
if (mon_tmd_effect >= 0) {
mon_inc_timed(t_mon, mon_tmd_effect, MAX(amount, 0), 0, false);
}
return true;
}
if (!player->timed[context->subtype] || !context->other) {
player_inc_timed(player, context->subtype, MAX(amount, 0), true, true);
} else {
player_inc_timed(player, context->subtype, context->other, true, true);
}
return true;
}
/**
* Extend a (positive or negative) player status condition unresistably.
* If context->other is set, increase by that amount if the player already
* has the status
*/
bool effect_handler_TIMED_INC_NO_RES(effect_handler_context_t *context)
{
int amount = effect_calculate_value(context, false);
if (!player->timed[context->subtype] || !context->other)
player_inc_timed(player, context->subtype, MAX(amount, 0), true, false);
else
player_inc_timed(player, context->subtype, context->other, true, false);
context->ident = true;
return true;
}
/**
* Extend a (positive or negative) monster status condition.
*/
bool effect_handler_MON_TIMED_INC(effect_handler_context_t *context)
{
assert(context->origin.what == SRC_MONSTER);
int amount = effect_calculate_value(context, false);
struct monster *mon = cave_monster(cave, context->origin.which.monster);
if (mon) {
mon_inc_timed(mon, context->subtype, MAX(amount, 0), 0, false);
context->ident = true;
}
return true;
}
/**
* Reduce a (positive or negative) player status condition.
* If context->other is set, decrease by the current value / context->other
*/