-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
mon-util.cc
5749 lines (4922 loc) · 165 KB
/
mon-util.cc
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
* @brief Misc monster related functions.
**/
#include "AppHdr.h"
#include "mon-util.h"
#include <algorithm>
#include <cmath>
#include <sstream>
#include "act-iter.h"
#include "areas.h"
#include "artefact.h"
#include "attitude-change.h"
#include "beam.h"
#include "cloud.h"
#include "colour.h"
#include "coordit.h"
#include "database.h"
#include "delay.h"
#include "dgn-overview.h"
#include "directn.h"
#include "dungeon.h"
#include "english.h"
#include "env.h"
#include "errors.h"
#include "fight.h"
#include "files.h"
#include "food.h"
#include "fprop.h"
#include "ghost.h"
#include "god-abil.h"
#include "god-item.h"
#include "god-passive.h"
#include "item-name.h"
#include "item-prop.h"
#include "items.h"
#include "libutil.h"
#include "mapmark.h"
#include "message.h"
#include "mgen-data.h"
#include "misc.h"
#include "mon-abil.h"
#include "mon-behv.h"
#include "mon-book.h"
#include "mon-death.h"
#include "mon-place.h"
#include "mon-poly.h"
#include "mon-tentacle.h"
#include "mutant-beast.h"
#include "notes.h"
#include "options.h"
#include "random.h"
#include "religion.h"
#include "showsymb.h"
#include "species.h"
#include "spl-summoning.h"
#include "spl-util.h"
#include "state.h"
#include "stringutil.h"
#include "terrain.h"
#include "tiledef-player.h"
#include "tilepick.h"
#include "tileview.h"
#include "timed-effects.h"
#include "traps.h"
#include "unicode.h"
#include "unwind.h"
#include "view.h"
static FixedVector < int, NUM_MONSTERS > mon_entry;
struct mon_display
{
char32_t glyph;
colour_t colour;
mon_display(unsigned gly = 0, unsigned col = 0)
: glyph(gly), colour(col) { }
};
static mon_display monster_symbols[NUM_MONSTERS];
static bool initialised_randmons = false;
static vector<monster_type> monsters_by_habitat[NUM_HABITATS];
static vector<monster_type> species_by_habitat[NUM_HABITATS];
#include "mon-spell.h"
#include "mon-data.h"
#define MONDATASIZE ARRAYSZ(mondata)
static int _mons_exp_mod(monster_type mclass);
// Macro that saves some typing, nothing more.
#define smc get_monster_data(mc)
// ASSERT(smc) was getting really old
#define ASSERT_smc() \
do { \
if (!get_monster_data(mc)) \
die("bogus mc (no monster data): %s (%d)", \
mons_type_name(mc, DESC_PLAIN).c_str(), mc); \
} while (false)
/* ******************** BEGIN PUBLIC FUNCTIONS ******************** */
static habitat_type _grid2habitat(dungeon_feature_type grid)
{
if (feat_is_watery(grid))
return HT_WATER;
switch (grid)
{
case DNGN_LAVA:
return HT_LAVA;
case DNGN_FLOOR:
default:
return HT_LAND;
}
}
dungeon_feature_type habitat2grid(habitat_type ht)
{
switch (ht)
{
case HT_WATER:
return DNGN_DEEP_WATER;
case HT_LAVA:
return DNGN_LAVA;
case HT_LAND:
case HT_AMPHIBIOUS:
case HT_AMPHIBIOUS_LAVA:
default:
return DNGN_FLOOR;
}
}
static void _initialise_randmons()
{
for (int i = 0; i < NUM_HABITATS; ++i)
{
set<monster_type> tmp_species;
const dungeon_feature_type grid = habitat2grid(habitat_type(i));
for (monster_type mt = MONS_0; mt < NUM_MONSTERS; ++mt)
{
if (invalid_monster_type(mt))
continue;
if (monster_habitable_grid(mt, grid))
monsters_by_habitat[i].push_back(mt);
const monster_type species = mons_species(mt);
if (monster_habitable_grid(species, grid))
tmp_species.insert(species);
}
for (auto type : tmp_species)
species_by_habitat[i].push_back(type);
}
initialised_randmons = true;
}
monster_type random_monster_at_grid(const coord_def& p, bool species)
{
if (!initialised_randmons)
_initialise_randmons();
const habitat_type ht = _grid2habitat(grd(p));
const vector<monster_type> &valid_mons = species ? species_by_habitat[ht]
: monsters_by_habitat[ht];
ASSERT(!valid_mons.empty());
return valid_mons.empty() ? MONS_PROGRAM_BUG
: valid_mons[ random2(valid_mons.size()) ];
}
typedef map<string, monster_type> mon_name_map;
static mon_name_map Mon_Name_Cache;
void init_mon_name_cache()
{
if (!Mon_Name_Cache.empty())
return;
for (const monsterentry &me : mondata)
{
string name = me.name;
lowercase(name);
const int mtype = me.mc;
const monster_type mon = monster_type(mtype);
// Deal sensibly with duplicate entries; refuse or allow the
// insert, depending on which should take precedence. Some
// uniques of multiple forms can get away with this, though.
if (Mon_Name_Cache.count(name))
{
if (mon == MONS_PLAYER_SHADOW
|| mon == MONS_BAI_SUZHEN_DRAGON
|| mon != MONS_SERPENT_OF_HELL
&& mons_species(mon) == MONS_SERPENT_OF_HELL)
{
// Keep previous entry.
continue;
}
else
die("Un-handled duplicate monster name: %s", name.c_str());
}
Mon_Name_Cache[name] = mon;
}
}
static const char *_mon_entry_name(size_t idx)
{
return mondata[idx].name;
}
monster_type get_monster_by_name(string name, bool substring)
{
if (name.empty())
return MONS_PROGRAM_BUG;
lowercase(name);
if (!substring)
{
if (monster_type *mc = map_find(Mon_Name_Cache, name))
return *mc;
return MONS_PROGRAM_BUG;
}
size_t idx = find_earliest_match(name, (size_t) 0, ARRAYSZ(mondata),
always_true<size_t>, _mon_entry_name);
return idx == ARRAYSZ(mondata) ? MONS_PROGRAM_BUG
: (monster_type) mondata[idx].mc;
}
void init_monsters()
{
// First, fill static array with dummy values. {dlb}
mon_entry.init(-1);
// Next, fill static array with location of entry in mondata[]. {dlb}:
for (unsigned int i = 0; i < MONDATASIZE; ++i)
mon_entry[mondata[i].mc] = i;
// Finally, monsters yet with dummy entries point to TTTSNB(tm). {dlb}:
for (int &entry : mon_entry)
if (entry == -1)
entry = mon_entry[MONS_PROGRAM_BUG];
init_monster_symbols();
}
void init_monster_symbols()
{
map<unsigned, monster_type> base_mons;
for (monster_type mc = MONS_0; mc < NUM_MONSTERS; ++mc)
{
mon_display &md = monster_symbols[mc];
if (const monsterentry *me = get_monster_data(mc))
{
md.glyph = me->basechar;
md.colour = me->colour;
auto it = base_mons.find(md.glyph);
if (it == base_mons.end() || it->first == MONS_PROGRAM_BUG)
base_mons[md.glyph] = mc;
}
}
// Let those follow the feature settings, unless specifically overridden.
monster_symbols[MONS_ANIMATED_TREE].glyph = get_feat_symbol(DNGN_TREE);
for (monster_type mc = MONS_0; mc < NUM_MONSTERS; ++mc)
if (mons_genus(mc) == MONS_STATUE)
monster_symbols[mc].glyph = get_feat_symbol(DNGN_GRANITE_STATUE);
// Validate all glyphs, even those which didn't come from an override.
for (monster_type i = MONS_PROGRAM_BUG; i < NUM_MONSTERS; ++i)
if (wcwidth(monster_symbols[i].glyph) != 1)
monster_symbols[i].glyph = mons_base_char(i);
}
void set_resist(resists_t &all, mon_resist_flags res, int lev)
{
if (res > MR_LAST_MULTI)
{
ASSERT_RANGE(lev, 0, 2);
if (lev)
all |= res;
else
all &= ~res;
return;
}
ASSERT_RANGE(lev, -3, 5);
all = (all & ~(res * 7)) | (res * (lev & 7));
}
int get_mons_class_ac(monster_type mc)
{
const monsterentry *me = get_monster_data(mc);
return me ? me->AC : get_monster_data(MONS_PROGRAM_BUG)->AC;
}
int get_mons_class_ev(monster_type mc)
{
const monsterentry *me = get_monster_data(mc);
return me ? me->ev : get_monster_data(MONS_PROGRAM_BUG)->ev;
}
static resists_t _apply_holiness_resists(resists_t resists, mon_holy_type mh)
{
// Undead and non-living beings get full poison resistance.
if (mh & (MH_UNDEAD | MH_NONLIVING))
resists = (resists & ~(MR_RES_POISON * 7)) | (MR_RES_POISON * 3);
// Everything but natural creatures have full rNeg. Set here for the
// benefit of the monster_info constructor. If you change this, also
// change monster::res_negative_energy.
if (!(mh & MH_NATURAL))
resists = (resists & ~(MR_RES_NEG * 7)) | (MR_RES_NEG * 3);
return resists;
}
/**
* What special resistances does the given mutant beast facet provide?
*
* @param facet The beast_facet in question, e.g. BF_FIRE.
* @return A bitfield of resists corresponding to the given facet;
* e.g. MR_RES_FIRE for BF_FIRE.
*/
static resists_t _beast_facet_resists(beast_facet facet)
{
static const map<beast_facet, resists_t> resists = {
{ BF_STING, MR_RES_POISON },
{ BF_FIRE, MR_RES_FIRE },
{ BF_SHOCK, MR_RES_ELEC },
{ BF_OX, MR_RES_COLD },
};
return lookup(resists, facet, 0);
}
resists_t get_mons_class_resists(monster_type mc)
{
const monsterentry *me = get_monster_data(mc);
const resists_t resists = me ? me->resists
: get_monster_data(MONS_PROGRAM_BUG)->resists;
// Don't apply fake holiness resists.
if (mons_is_sensed(mc))
return resists;
// Assumes that, when a monster's holiness differs from other monsters
// of the same type, that only adds resistances, never removes them.
// Currently the only such case is MF_FAKE_UNDEAD.
return _apply_holiness_resists(resists, mons_class_holiness(mc));
}
resists_t get_mons_resists(const monster& m)
{
const monster& mon = get_tentacle_head(m);
resists_t resists = get_mons_class_resists(mon.type);
if (mons_is_ghost_demon(mon.type))
resists |= mon.ghost->resists;
if (mons_genus(mon.type) == MONS_DRACONIAN
&& mon.type != MONS_DRACONIAN
|| mon.type == MONS_TIAMAT
|| mons_genus(mon.type) == MONS_DEMONSPAWN
&& mon.type != MONS_DEMONSPAWN)
{
monster_type subspecies = draco_or_demonspawn_subspecies(mon);
if (subspecies != mon.type)
resists |= get_mons_class_resists(subspecies);
}
if (mon.props.exists(MUTANT_BEAST_FACETS))
for (auto facet : mon.props[MUTANT_BEAST_FACETS].get_vector())
resists |= _beast_facet_resists((beast_facet)facet.get_int());
// This is set from here in case they're undead due to the
// MF_FAKE_UNDEAD flag. See the comment in get_mons_class_resists.
return _apply_holiness_resists(resists, mon.holiness());
}
int get_mons_resist(const monster& mon, mon_resist_flags res)
{
return get_resist(get_mons_resists(mon), res);
}
// Returns true if the monster successfully resists this attempt to poison it.
const bool monster_resists_this_poison(const monster& mons, bool force)
{
const int res = mons.res_poison();
if (res >= 3)
return true;
if (!force && res >= 1 && x_chance_in_y(2, 3))
return true;
return false;
}
monster* monster_at(const coord_def &pos)
{
if (!in_bounds(pos))
return nullptr;
const int mindex = mgrd(pos);
if (mindex == NON_MONSTER)
return nullptr;
ASSERT(mindex <= MAX_MONSTERS);
return &menv[mindex];
}
/// Are any of the bits set?
bool mons_class_flag(monster_type mc, monclass_flags_t bits)
{
const monsterentry * const me = get_monster_data(mc);
return me && (me->bitfields & bits);
}
int monster::wearing(equipment_type slot, int sub_type, bool calc_unid) const
{
int ret = 0;
const item_def *item = 0;
if (!alive())
return 0;
switch (slot)
{
case EQ_WEAPON:
case EQ_STAFF:
{
const mon_inv_type end = mons_wields_two_weapons(*this)
? MSLOT_ALT_WEAPON : MSLOT_WEAPON;
for (int i = MSLOT_WEAPON; i <= end; i = i + 1)
{
item = mslot_item((mon_inv_type) i);
if (item && item->base_type == (slot == EQ_WEAPON ? OBJ_WEAPONS
: OBJ_STAVES)
&& item->sub_type == sub_type
// Weapon subtypes are always known, staves not.
&& (slot == EQ_WEAPON || calc_unid
|| item_type_known(*item)))
{
ret++;
}
}
}
break;
case EQ_ALL_ARMOUR:
case EQ_CLOAK:
case EQ_HELMET:
case EQ_GLOVES:
case EQ_BOOTS:
case EQ_SHIELD:
item = mslot_item(MSLOT_SHIELD);
if (item && item->is_type(OBJ_ARMOUR, sub_type))
ret++;
// Don't check MSLOT_ARMOUR for EQ_SHIELD
if (slot == EQ_SHIELD)
break;
// intentional fall-through
case EQ_BODY_ARMOUR:
item = mslot_item(MSLOT_ARMOUR);
if (item && item->is_type(OBJ_ARMOUR, sub_type))
ret++;
break;
case EQ_AMULET:
case EQ_AMULET_PLUS:
case EQ_RINGS:
case EQ_RINGS_PLUS:
item = mslot_item(MSLOT_JEWELLERY);
if (item && item->is_type(OBJ_JEWELLERY, sub_type)
&& (calc_unid || item_type_known(*item)))
{
if (slot == EQ_RINGS_PLUS || slot == EQ_AMULET_PLUS)
ret += item->plus;
else
ret++;
}
break;
default:
die("invalid slot %d for monster::wearing()", slot);
}
return ret;
}
int monster::wearing_ego(equipment_type slot, int special, bool calc_unid) const
{
int ret = 0;
const item_def *item = 0;
if (!alive())
return 0;
switch (slot)
{
case EQ_WEAPON:
{
const mon_inv_type end = mons_wields_two_weapons(*this)
? MSLOT_ALT_WEAPON : MSLOT_WEAPON;
for (int i = MSLOT_WEAPON; i <= end; i++)
{
item = mslot_item((mon_inv_type) i);
if (item && item->base_type == OBJ_WEAPONS
&& get_weapon_brand(*item) == special
&& (calc_unid || item_type_known(*item)))
{
ret++;
}
}
}
break;
case EQ_ALL_ARMOUR:
case EQ_CLOAK:
case EQ_HELMET:
case EQ_GLOVES:
case EQ_BOOTS:
case EQ_SHIELD:
item = mslot_item(MSLOT_SHIELD);
if (item && item->base_type == OBJ_ARMOUR
&& get_armour_ego_type(*item) == special
&& (calc_unid || item_type_known(*item)))
{
ret++;
}
// Don't check MSLOT_ARMOUR for EQ_SHIELD
if (slot == EQ_SHIELD)
break;
// intentional fall-through
case EQ_BODY_ARMOUR:
item = mslot_item(MSLOT_ARMOUR);
if (item && item->base_type == OBJ_ARMOUR
&& get_armour_ego_type(*item) == special
&& (calc_unid || item_type_known(*item)))
{
ret++;
}
break;
case EQ_AMULET:
case EQ_STAFF:
case EQ_RINGS:
case EQ_RINGS_PLUS:
// No egos.
break;
default:
die("invalid slot %d for monster::wearing_ego()", slot);
}
return ret;
}
int monster::scan_artefacts(artefact_prop_type ra_prop, bool calc_unid,
vector<item_def> *matches) const
{
UNUSED(matches); //TODO: implement this when it will be required somewhere
if (!alive())
return 0;
int ret = 0;
// TODO: do we really want to prevent randarts from working for zombies?
if (mons_itemuse(*this) >= MONUSE_STARTING_EQUIPMENT)
{
const int weap = inv[MSLOT_WEAPON];
const int second = inv[MSLOT_ALT_WEAPON]; // Two-headed ogres, etc.
const int armour = inv[MSLOT_ARMOUR];
const int shld = inv[MSLOT_SHIELD];
const int jewellery = inv[MSLOT_JEWELLERY];
if (weap != NON_ITEM && mitm[weap].base_type == OBJ_WEAPONS
&& is_artefact(mitm[weap]))
{
ret += artefact_property(mitm[weap], ra_prop);
}
if (second != NON_ITEM && mitm[second].base_type == OBJ_WEAPONS
&& is_artefact(mitm[second]) && mons_wields_two_weapons(*this))
{
ret += artefact_property(mitm[second], ra_prop);
}
if (armour != NON_ITEM && mitm[armour].base_type == OBJ_ARMOUR
&& is_artefact(mitm[armour]))
{
ret += artefact_property(mitm[armour], ra_prop);
}
if (shld != NON_ITEM && mitm[shld].base_type == OBJ_ARMOUR
&& is_artefact(mitm[shld]))
{
ret += artefact_property(mitm[shld], ra_prop);
}
if (jewellery != NON_ITEM && mitm[jewellery].base_type == OBJ_JEWELLERY
&& is_artefact(mitm[jewellery]))
{
ret += artefact_property(mitm[jewellery], ra_prop);
}
}
return ret;
}
mon_holy_type holiness_by_name(string name)
{
lowercase(name);
for (const auto bit : mon_holy_type::range())
{
if (name == holiness_name(mon_holy_type::exponent(bit)))
return mon_holy_type::exponent(bit);
}
return MH_NONE;
}
const char * holiness_name(mon_holy_type_flags which_holiness)
{
switch (which_holiness)
{
case MH_HOLY:
return "holy";
case MH_NATURAL:
return "natural";
case MH_UNDEAD:
return "undead";
case MH_DEMONIC:
return "demonic";
case MH_NONLIVING:
return "nonliving";
case MH_PLANT:
return "plant";
case MH_EVIL:
return "evil";
default:
return "bug";
}
}
string holiness_description(mon_holy_type holiness)
{
string description = "";
for (const auto bit : mon_holy_type::range())
{
if (holiness & bit)
{
if (!description.empty())
description += ",";
description += holiness_name(bit);
}
}
return description;
}
mon_holy_type mons_class_holiness(monster_type mc)
{
ASSERT_smc();
return smc->holiness;
}
bool mons_class_is_stationary(monster_type mc)
{
return mons_class_flag(mc, M_STATIONARY);
}
/**
* Can killing this class of monster ever reward xp?
*
* This answers whether any agent could receive XP for killing a monster of
* this class. Monsters that fail this have M_NO_EXP_GAIN set.
* @param mc The monster type
* @param indirect If true this will count monsters that are parts of a parent
* monster as xp rewarding even if the parts themselves don't
* reward xp (e.g. tentacles).
* @returns True if killing a monster of this class could reward xp, false
* otherwise.
*/
bool mons_class_gives_xp(monster_type mc, bool indirect)
{
return !mons_class_flag(mc, M_NO_EXP_GAIN)
|| (indirect && mons_is_tentacle_or_tentacle_segment(mc));
}
/**
* Can killing this monster reward xp to the given actor?
*
* This answers whether the player or a monster could ever receive XP for
* killing the monster, assuming an appropriate kill_type.
* @param mon The monster.
* @param agent The actor who would be responsible for the kill.
* @returns True if killing the monster will reward the agent with xp, false
* otherwise.
*/
bool mons_gives_xp(const monster& victim, const actor& agent)
{
const bool mon_killed_friend
= agent.is_monster() && mons_aligned(&victim, &agent);
return !victim.is_summoned() // no summons
&& !victim.has_ench(ENCH_ABJ) // not-really-summons
&& !victim.has_ench(ENCH_FAKE_ABJURATION) // no animated remains
&& mons_class_gives_xp(victim.type) // class must reward xp
&& !testbits(victim.flags, MF_WAS_NEUTRAL) // no neutral monsters
&& !testbits(victim.flags, MF_NO_REWARD) // no reward for no_reward
&& !mon_killed_friend;
}
bool mons_class_is_threatening(monster_type mo)
{
return !mons_class_flag(mo, M_NO_THREAT);
}
bool mons_is_threatening(const monster& mons)
{
return mons_class_is_threatening(mons.type) || mons_is_active_ballisto(mons);
}
/**
* Is this an active ballistomycete?
*
* @param mon The monster
* @returns True if the monster is an active ballistomycete, false otherwise.
*/
bool mons_is_active_ballisto(const monster& mon)
{
return mon.type == MONS_BALLISTOMYCETE && mon.ballisto_activity;
}
/**
* Is this monster class firewood?
*
* Firewood monsters are harmless stationary monsters than don't give xp. These
* are worthless obstacles: not to be attacked by default, but may be cut down
* to get to target even if coaligned.
* @param mc The monster type
* @returns True if the monster class is firewood, false otherwise.
*/
bool mons_class_is_firewood(monster_type mc)
{
return mons_class_is_stationary(mc)
&& mons_class_flag(mc, M_NO_THREAT)
&& !mons_is_tentacle_or_tentacle_segment(mc);
}
/**
* Is this monster firewood?
*
* Firewood monsters are stationary monsters than don't give xp.
* @param mon The monster
* @returns True if the monster is firewood, false otherwise.
*/
bool mons_is_firewood(const monster& mon)
{
return mons_class_is_firewood(mon.type);
}
// "body" in a purely grammatical sense.
bool mons_has_body(const monster& mon)
{
if (mon.type == MONS_FLYING_SKULL
|| mon.type == MONS_CURSE_SKULL
|| mon.type == MONS_CURSE_TOE
|| mons_class_is_animated_weapon(mon.type))
{
return false;
}
switch (mons_base_char(mon.type))
{
case 'P':
case 'v':
case 'G':
case '*':
case '%':
case 'J':
return false;
}
return true;
}
bool mons_has_flesh(const monster& mon)
{
if (mon.is_skeletal() || mon.is_insubstantial())
return false;
// Dictionary says:
// 1. (12) flesh -- (the soft tissue of the body of a vertebrate:
// mainly muscle tissue and fat)
// 3. pulp, flesh -- (a soft moist part of a fruit)
// yet I exclude sense 3 anyway but include arthropods and molluscs.
return !(mon.holiness() & (MH_PLANT | MH_NONLIVING))
&& mons_genus(mon.type) != MONS_FLOATING_EYE
&& mons_genus(mon.type) != MONS_GLOWING_ORANGE_BRAIN
&& mons_genus(mon.type) != MONS_JELLY
&& mon.type != MONS_DEATH_COB; // plant!
}
// Difference in speed between monster and the player for Cheibriados'
// purposes. This is the speed difference disregarding the player's
// slow status.
int cheibriados_monster_player_speed_delta(const monster& mon)
{
// Ignore the Slow effect.
unwind_var<int> ignore_slow(you.duration[DUR_SLOW], 0);
const int pspeed = 1000 / (player_movement_speed() * player_speed());
dprf("Your delay: %d, your speed: %d, mon speed: %d",
player_movement_speed(), pspeed, mon.speed);
return mon.speed - pspeed;
}
bool cheibriados_thinks_mons_is_fast(const monster& mon)
{
return cheibriados_monster_player_speed_delta(mon) > 0;
}
// Dithmenos also hates fire users, flaming weapons, and generally fiery beings.
bool mons_is_fiery(const monster& mon)
{
if (mons_genus(mon.type) == MONS_DRACONIAN
&& draco_or_demonspawn_subspecies(mon) == MONS_RED_DRACONIAN)
{
return true;
}
if (mons_genus(mon.type) == MONS_DANCING_WEAPON
&& mon.weapon() && mon.weapon()->brand == SPWPN_FLAMING)
{
return true;
}
return mon.has_attack_flavour(AF_FIRE)
|| mon.has_attack_flavour(AF_PURE_FIRE)
|| mon.has_attack_flavour(AF_STICKY_FLAME)
|| mon.has_spell_of_type(SPTYP_FIRE);
}
bool mons_is_projectile(monster_type mc)
{
return mons_class_flag(mc, M_PROJECTILE);
}
bool mons_is_projectile(const monster& mon)
{
return mons_is_projectile(mon.type);
}
static bool _mons_class_is_clingy(monster_type type)
{
return mons_genus(type) == MONS_SPIDER || type == MONS_LEOPARD_GECKO
|| type == MONS_GIANT_COCKROACH || type == MONS_DEMONIC_CRAWLER
|| type == MONS_DART_SLUG;
}
bool mons_can_cling_to_walls(const monster& mon)
{
return _mons_class_is_clingy(mon.type);
}
// Conjuration or Hexes. Summoning and Necromancy make the monster a creature
// at least in some degree, golems have a chem granting them that.
bool mons_is_object(monster_type mc)
{
return mons_is_conjured(mc)
|| mc == MONS_TWISTER
// unloading seeds helps the species
|| mc == MONS_BALLISTOMYCETE_SPORE
|| mc == MONS_LURKING_HORROR
|| mc == MONS_DANCING_WEAPON
|| mc == MONS_LIGHTNING_SPIRE;
}
bool mons_has_blood(monster_type mc)
{
return mons_class_flag(mc, M_COLD_BLOOD)
|| mons_class_flag(mc, M_WARM_BLOOD);
}
bool mons_is_sensed(monster_type mc)
{
return mc == MONS_SENSED
|| mc == MONS_SENSED_FRIENDLY
|| mc == MONS_SENSED_TRIVIAL
|| mc == MONS_SENSED_EASY
|| mc == MONS_SENSED_TOUGH
|| mc == MONS_SENSED_NASTY;
}
bool mons_allows_beogh(const monster& mon)
{
if (!species_is_orcish(you.species) || you_worship(GOD_BEOGH))
return false; // no one else gives a damn
return mons_genus(mon.type) == MONS_ORC
&& mon.is_priest() && mon.god == GOD_BEOGH;
}
bool mons_allows_beogh_now(const monster& mon)
{
// Do the expensive LOS check last.
return mons_allows_beogh(mon)
&& !mon.is_summoned() && !mon.friendly()
&& !silenced(mon.pos()) && !mon.has_ench(ENCH_MUTE)
&& !mons_is_confused(mon) && mons_is_seeking(mon)
&& mon.foe == MHITYOU && !mons_is_immotile(mon)
&& you.visible_to(&mon) && you.can_see(mon);
}
// Returns true for monsters that obviously (to the player) feel
// "thematically at home" in a branch. Currently used for native
// monsters recognising traps and patrolling branch entrances.
bool mons_is_native_in_branch(const monster& mons,
const branch_type branch)
{
switch (branch)
{
case BRANCH_ELF:
return mons_genus(mons.type) == MONS_ELF;