3 * @brief Functions used when placing monsters in the dungeon.
10 #include "mon-place.h"
11 #include "mgen_data.h"
16 #include "attitude-change.h"
31 #include "losglobal.h"
34 #include "mon-death.h"
41 #include "spl-clouds.h"
42 #include "spl-damage.h"
45 #include "spl-summoning.h"
54 #include "tiledef-player.h"
57 band_type active_monster_band = BAND_NO_BAND;
59 static vector<int> vault_mon_types;
60 static vector<int> vault_mon_bases;
61 static vector<int> vault_mon_weights;
62 static vector<bool> vault_mon_bands;
64 #define VAULT_MON_TYPES_KEY "vault_mon_types"
65 #define VAULT_MON_BASES_KEY "vault_mon_bases"
66 #define VAULT_MON_WEIGHTS_KEY "vault_mon_weights"
67 #define VAULT_MON_BANDS_KEY "vault_mon_bands"
69 // proximity is the same as for mons_place:
70 // 0 is no restrictions
71 // 1 attempts to place near player
72 // 2 attempts to avoid player LOS
76 static monster_type _band_member(band_type band, int which);
77 static band_type _choose_band(monster_type mon_type, int &band_size,
78 bool& natural_leader);
80 static monster* _place_monster_aux(const mgen_data &mg, const monster *leader,
82 bool force_pos = false,
83 bool dont_place = false);
85 // Returns whether actual_feat is compatible with feat_wanted for monster
86 // movement and generation.
87 bool feat_compatible(dungeon_feature_type feat_wanted,
88 dungeon_feature_type actual_feat)
90 if (feat_wanted == DNGN_FLOOR)
91 return feat_has_solid_floor(actual_feat);
93 return feat_wanted == actual_feat
94 || (feat_wanted == DNGN_DEEP_WATER
95 && (actual_feat == DNGN_SHALLOW_WATER
96 || actual_feat == DNGN_FOUNTAIN_BLUE));
99 // Can this monster survive on actual_grid?
101 // If you have an actual monster, use this instead of the overloaded function
102 // that uses only the monster class to make decisions.
103 bool monster_habitable_grid(const monster* mon,
104 dungeon_feature_type actual_grid)
106 // Zombified monsters enjoy the same habitat as their original,
107 // except lava-based monsters.
108 const monster_type mt = fixup_zombie_type(mon->type,
109 mons_base_type(mon));
111 return monster_habitable_grid(mt,
115 mon->cannot_move() || mon->caught());
118 bool mons_airborne(monster_type mcls, int flies, bool paralysed)
121 flies = mons_class_flies(mcls);
123 return paralysed ? flies == FL_LEVITATE : flies != FL_NONE;
126 // Can monsters of class monster_class live happily on actual_grid?
127 // Use flies == true to pretend the monster can fly.
129 // [dshaligram] We're trying to harmonise the checks from various places into
130 // one check, so we no longer care if a water elemental springs into existence
131 // on dry land, because they're supposed to be able to move onto dry land
133 bool monster_habitable_grid(monster_type mt,
134 dungeon_feature_type actual_grid,
135 dungeon_feature_type wanted_grid_feature,
136 int flies, bool paralysed)
138 // No monster may be placed on open sea.
139 if (actual_grid == DNGN_OPEN_SEA || actual_grid == DNGN_LAVA_SEA)
142 // Monsters can't use teleporters, and standing there would look just wrong.
143 if (actual_grid == DNGN_TELEPORTER)
146 const dungeon_feature_type feat_preferred =
147 habitat2grid(mons_class_primary_habitat(mt));
148 const dungeon_feature_type feat_nonpreferred =
149 habitat2grid(mons_class_secondary_habitat(mt));
151 const bool monster_is_airborne = mons_airborne(mt, flies, paralysed);
153 // If the caller insists on a specific feature type, try to honour
154 // the request. This allows the builder to place amphibious
155 // creatures only on land, or flying creatures only on lava, etc.
156 if (wanted_grid_feature != DNGN_UNSEEN
157 && (feat_compatible(feat_preferred, wanted_grid_feature)
158 || feat_compatible(feat_nonpreferred, wanted_grid_feature)
159 || (monster_is_airborne && !feat_is_solid(wanted_grid_feature))))
161 return feat_compatible(wanted_grid_feature, actual_grid);
164 // Special check for fire elementals since their habitat is floor which
165 // is generally considered compatible with shallow water.
166 if (mt == MONS_FIRE_ELEMENTAL && feat_is_watery(actual_grid))
169 if (actual_grid == DNGN_MALIGN_GATEWAY)
171 if (mt == MONS_ELDRITCH_TENTACLE
172 || mt == MONS_ELDRITCH_TENTACLE_SEGMENT)
180 if (feat_compatible(feat_preferred, actual_grid)
181 || (feat_nonpreferred != feat_preferred
182 && feat_compatible(feat_nonpreferred, actual_grid)))
187 // [dshaligram] Flying creatures are all DNGN_FLOOR, so we
188 // only have to check for the additional valid grids of deep
190 if (monster_is_airborne
191 && (actual_grid == DNGN_LAVA || actual_grid == DNGN_DEEP_WATER))
199 // Returns true if the monster can submerge in the given grid.
200 bool monster_can_submerge(const monster* mon, dungeon_feature_type feat)
202 if (testbits(env.pgrid(mon->pos()), FPROP_NO_SUBMERGE))
204 if (!mon->is_habitable_feat(feat))
206 if (mons_class_flag(mon->type, M_SUBMERGES))
208 switch (mons_habitat(mon))
212 return feat_is_watery(feat);
214 case HT_AMPHIBIOUS_LAVA:
215 return feat == DNGN_LAVA;
217 // Currently, trapdoor spider and air elemental only.
218 return feat == DNGN_FLOOR;
227 static bool _is_spawn_scaled_area(const level_id &here)
229 return is_connected_branch(here.branch)
230 && !is_hell_subbranch(here.branch)
231 && here.branch != BRANCH_VESTIBULE
232 && here.branch != BRANCH_ZOT;
235 // Scale monster generation parameter with time spent on level. Note:
236 // (target_value - base_value) * dropoff_ramp_turns must be < INT_MAX!
237 static int _scale_spawn_parameter(int base_value,
240 int dropoff_start_turns = 3000,
241 int dropoff_ramp_turns = 12000)
243 if (!_is_spawn_scaled_area(level_id::current()))
246 const int turns_on_level = env.turns_on_level;
247 return turns_on_level <= dropoff_start_turns ? base_value :
248 turns_on_level > dropoff_start_turns + dropoff_ramp_turns ?
251 // Actual scaling, strictly linear at the moment:
253 (target_value - base_value)
254 * (turns_on_level - dropoff_start_turns)
255 / dropoff_ramp_turns);
258 static void _apply_ood(level_id &place)
260 // OODs do not apply to any portal vaults, any 1-level branches, Zot and
261 // hells. What with newnewabyss?
262 if (!is_connected_branch(place)
263 || place.branch == BRANCH_ZOT
264 || is_hell_subbranch(place.branch)
265 || brdepth[place.branch] <= 1)
270 // The OOD fuzz roll is not applied at level generation time on
271 // D:1, and is applied slightly less often (0.75*0.14) on D:2. All
272 // other levels have a straight 14% chance of moderate OOD fuzz
273 // for each monster at level generation, and the chances of
274 // moderate OODs go up to 100% after a ramp-up period.
276 if (place.branch == BRANCH_DUNGEON
277 && (place.depth == 1 && env.turns_on_level < 701
278 || place.depth == 2 && (env.turns_on_level < 584 || one_chance_in(4))))
283 #ifdef DEBUG_DIAGNOSTICS
284 level_id old_place = place;
287 if (x_chance_in_y(_scale_spawn_parameter(140, 1000, 1000, 3000, 4800),
290 const int fuzzspan = 5;
291 const int fuzz = max(0, random_range(-fuzzspan, fuzzspan, 2));
293 // Quite bizarre logic: why should we fail in >50% cases here?
297 dprf("Monster level fuzz: %d (old: %s, new: %s)",
298 fuzz, old_place.describe().c_str(), place.describe().c_str());
302 // On D:13 and deeper, and for those who tarry, something extreme:
303 if (env.turns_on_level > 1400 - place.absdepth() * 117
304 && x_chance_in_y(_scale_spawn_parameter(2, 10000, 10000, 3000, 9000),
307 // this maxes depth most of the time
308 place.depth += random2avg(27, 2);
309 dprf("Super OOD roll: Old: %s, New: %s",
310 old_place.describe().c_str(), place.describe().c_str());
314 static int _vestibule_spawn_rate()
316 // Monster generation in the Vestibule drops off quickly.
317 const int taper_off_turn = 500;
319 // genodds increases once you've spent more than 500 turns in Hell.
320 if (env.turns_on_level > taper_off_turn)
322 genodds += (env.turns_on_level - taper_off_turn);
323 genodds = (genodds < 0 ? 20000 : min(genodds, 20000));
329 //#define DEBUG_MON_CREATION
332 * Spawn random monsters.
334 * The spawn rate defaults to the current env.spawn_random_rate for the branch,
335 * but is modified by whether the player is in the abyss and on what level, as
336 * well as whether the player has the orb.
338 void spawn_random_monsters()
340 if (crawl_state.disables[DIS_SPAWNS])
343 if (crawl_state.game_is_arena()
344 || (crawl_state.game_is_sprint()
345 && player_in_connected_branch()
346 && you.char_direction == GDT_DESCENDING))
351 #ifdef DEBUG_MON_CREATION
352 mprf(MSGCH_DIAGNOSTICS, "in spawn_random_monsters()");
354 int rate = env.spawn_random_rate;
357 #ifdef DEBUG_MON_CREATION
358 mprf(MSGCH_DIAGNOSTICS, "random monster gen turned off");
363 if (player_in_branch(BRANCH_VESTIBULE))
364 rate = _vestibule_spawn_rate();
366 if (player_has_orb())
367 rate = you_worship(GOD_CHEIBRIADOS) ? 16 : 8;
368 else if (you.char_direction != GDT_GAME_START)
369 rate = _scale_spawn_parameter(rate, 6 * rate, 0);
373 dprf("random monster gen scaled off, %d turns on level",
378 if (player_in_branch(BRANCH_ABYSS))
380 if (you.char_direction != GDT_GAME_START)
382 if (you_worship(GOD_CHEIBRIADOS))
386 if (!x_chance_in_y(5, rate))
389 // Place normal dungeon monsters, but not in player LOS. Don't generate orb
390 // spawns in Abyss to show some mercy to players that get banished there on
392 if (player_in_connected_branch()
393 || (player_has_orb() && !player_in_branch(BRANCH_ABYSS)))
395 dprf("Placing monster, rate: %d, turns here: %d",
396 rate, env.turns_on_level);
397 proximity_type prox = (one_chance_in(10) ? PROX_NEAR_STAIRS
398 : PROX_AWAY_FROM_PLAYER);
400 // The rules change once the player has picked up the Orb...
401 if (player_has_orb())
402 prox = (one_chance_in(3) ? PROX_CLOSE_TO_PLAYER : PROX_ANYWHERE);
404 mgen_data mg(WANDERING_MONSTER);
406 mg.foe = (player_has_orb()) ? MHITYOU : MHITNOT;
412 mgen_data mg(WANDERING_MONSTER);
413 if (player_in_branch(BRANCH_PANDEMONIUM)
414 && !env.properties.exists("vault_mon_weights")
415 && !one_chance_in(40))
417 mg.cls = env.mons_alloc[random2(PAN_MONS_ALLOC)];
418 mg.flags |= MG_PERMIT_BANDS;
425 static bool _is_random_monster(monster_type mt)
427 return mt == RANDOM_MONSTER || mt == RANDOM_MOBILE_MONSTER
428 || mt == RANDOM_COMPATIBLE_MONSTER
429 || mt == RANDOM_BANDLESS_MONSTER
430 || mt == WANDERING_MONSTER;
433 static bool _is_not_zombifiable(monster_type mt)
435 return !mons_zombie_size(mt);
438 static bool _has_big_aura(monster_type mt)
440 return mt == MONS_SILENT_SPECTRE;
443 static bool _is_incompatible_monster(monster_type mt)
445 return mons_class_is_stationary(mt)
446 || player_will_anger_monster(mt);
449 static bool _is_banded_monster(monster_type mt)
453 return _choose_band(mt, idummy, bdummy) != BAND_NO_BAND;
456 // Caller must use !invalid_monster_type to check if the return value
457 // is a real monster.
458 monster_type pick_random_monster(level_id place,
460 level_id *final_place)
462 if (crawl_state.game_is_arena())
464 monster_type type = arena_pick_random_monster(place);
465 if (!_is_random_monster(type))
471 place.depth = min(place.depth, branch_ood_cap(place.branch));
474 *final_place = place;
476 if (crawl_state.game_is_arena())
477 return pick_monster(place, arena_veto_random_monster);
478 else if (kind == RANDOM_MOBILE_MONSTER)
479 return pick_monster(place, mons_class_is_stationary);
480 else if (kind == RANDOM_COMPATIBLE_MONSTER)
481 return pick_monster(place, _is_incompatible_monster);
482 else if (kind == RANDOM_BANDLESS_MONSTER)
483 return pick_monster(place, _is_banded_monster);
484 else if (mons_class_is_zombified(kind))
485 return pick_monster(place, _is_not_zombifiable);
486 else if (crawl_state.game_is_sprint())
487 return pick_monster(place, _has_big_aura);
489 return pick_monster(place);
492 bool can_place_on_trap(monster_type mon_type, trap_type trap)
494 if (mons_is_tentacle_segment(mon_type))
497 if (trap == TRAP_TELEPORT || trap == TRAP_TELEPORT_PERMANENT)
500 if (trap == TRAP_SHAFT)
502 if (_is_random_monster(mon_type))
505 return mons_class_flies(mon_type)
506 || get_monster_data(mon_type)->size == SIZE_TINY;
512 bool drac_colour_incompatible(int drac, int colour)
514 return drac == MONS_DRACONIAN_SCORCHER && colour == MONS_WHITE_DRACONIAN;
517 // Finds a random square as close to a staircase as possible
518 static bool _find_mon_place_near_stairs(coord_def& pos,
519 dungeon_char_type *stair_type,
522 pos = get_random_stair();
523 const dungeon_feature_type feat = grd(pos);
524 *stair_type = get_feature_dchar(feat);
526 // First, assume a regular stair.
527 switch (feat_stair_direction(feat))
529 case CMD_GO_UPSTAIRS:
533 case CMD_GO_DOWNSTAIRS:
534 if (place.depth < brdepth[place.branch])
540 // Is it a branch stair?
541 for (int i = 0; i < NUM_BRANCHES; ++i)
543 if (branches[i].entry_stairs == feat)
545 place = static_cast<branch_type>(i);
548 else if (branches[i].exit_stairs == feat)
551 // This can happen on D:1 and in wizmode with random spawns on the
552 // first floor of a branch that didn't generate naturally.
553 if (!place.is_valid())
558 const monster_type habitat_target = MONS_BAT;
560 if (crawl_state.game_is_zotdef())
562 pos = find_newmons_square_contiguous(habitat_target, pos, distance);
563 return in_bounds(pos);
566 bool needs_resolution(monster_type mon_type)
568 return mon_type == RANDOM_DRACONIAN || mon_type == RANDOM_BASE_DRACONIAN
569 || mon_type == RANDOM_NONBASE_DRACONIAN
570 || mon_type >= RANDOM_DEMON_LESSER && mon_type <= RANDOM_DEMON
571 || mon_type == RANDOM_DEMONSPAWN
572 || mon_type == RANDOM_BASE_DEMONSPAWN
573 || mon_type == RANDOM_NONBASE_DEMONSPAWN
574 || _is_random_monster(mon_type);
577 monster_type resolve_monster_type(monster_type mon_type,
578 monster_type &base_type,
579 proximity_type proximity,
582 dungeon_char_type *stair_type,
589 if (mon_type == RANDOM_DRACONIAN)
591 // Pick any random drac, constrained by colour if requested.
595 static_cast<monster_type>(
596 random_range(MONS_FIRST_BASE_DRACONIAN,
597 MONS_LAST_DRACONIAN));
599 while (base_type != MONS_PROGRAM_BUG
600 && mon_type != base_type
601 && (mons_species(mon_type) == mon_type
602 || drac_colour_incompatible(mon_type, base_type)));
604 else if (mon_type == RANDOM_BASE_DRACONIAN)
605 mon_type = random_draconian_monster_species();
606 else if (mon_type == RANDOM_NONBASE_DRACONIAN)
609 static_cast<monster_type>(
610 random_range(MONS_FIRST_NONBASE_DRACONIAN, MONS_LAST_DRACONIAN));
612 else if (mon_type >= RANDOM_DEMON_LESSER && mon_type <= RANDOM_DEMON)
613 mon_type = summon_any_demon(mon_type);
614 else if (mon_type == RANDOM_DEMONSPAWN)
619 static_cast<monster_type>(
620 random_range(MONS_FIRST_DEMONSPAWN,
621 MONS_LAST_DEMONSPAWN));
623 while (base_type != MONS_PROGRAM_BUG
624 && mon_type != base_type
625 && mons_species(mon_type) == mon_type);
627 else if (mon_type == RANDOM_BASE_DEMONSPAWN)
628 mon_type = random_demonspawn_monster_species();
629 else if (mon_type == RANDOM_NONBASE_DEMONSPAWN)
632 static_cast<monster_type>(
633 random_range(MONS_FIRST_NONBASE_DEMONSPAWN,
634 MONS_LAST_NONBASE_DEMONSPAWN));
637 // (2) Take care of non-draconian random monsters.
638 else if (_is_random_monster(mon_type))
640 // Respect destination level for staircases.
641 if (proximity == PROX_NEAR_STAIRS)
643 const level_id orig_place = *place;
645 if (_find_mon_place_near_stairs(*pos, stair_type, *place))
647 // No monsters spawned in the Temple.
648 if (branches[place->branch].id == BRANCH_TEMPLE)
649 proximity = PROX_AWAY_FROM_PLAYER;
652 proximity = PROX_AWAY_FROM_PLAYER;
653 if (proximity == PROX_NEAR_STAIRS)
654 dprf("foreign monster from %s", place->describe().c_str());
655 else // we dunt cotton to no ferrniers in these here parts
658 } // end proximity check
660 if (!vault_mon_types.empty())
667 i = choose_random_weighted(vault_mon_weights.begin(),
668 vault_mon_weights.end());
669 type = vault_mon_types[i];
671 // Give up after enough attempts: for example, a Yred
672 // worshipper casting Shadow Creatures in holy Pan.
674 type = MONS_NO_MONSTER;
675 // If the monster list says not to place, or to place
676 // by level, or to place a random monster, accept that.
677 // If it's random, we'll be recursively calling ourselves
678 // later on for the new monster type.
679 if (type == MONS_NO_MONSTER || type == -1
680 || needs_resolution((monster_type)type))
685 while (mon_type == RANDOM_MOBILE_MONSTER
686 && mons_class_is_stationary((monster_type)type)
687 || mon_type == RANDOM_COMPATIBLE_MONSTER
688 && _is_incompatible_monster((monster_type)type)
689 || mon_type == RANDOM_BANDLESS_MONSTER
690 && _is_banded_monster((monster_type)type));
692 int base = vault_mon_bases[i];
693 bool banded = vault_mon_bands[i];
696 *place = level_id::from_packed_place(base);
699 base_type = (monster_type) base;
700 mon_type = (monster_type) type;
703 if (needs_resolution(mon_type))
706 resolve_monster_type(mon_type, base_type,
707 proximity, pos, mmask,
717 while (tries++ < 300)
719 level_id orig_place = *place;
721 // Now pick a monster of the given branch and level.
722 mon_type = pick_random_monster(*place, mon_type, place);
724 // Don't allow monsters too stupid to use stairs (e.g.
725 // non-spectral zombified undead) to be placed near
727 if (proximity != PROX_NEAR_STAIRS
728 || mons_class_can_use_stairs(mon_type))
736 if (proximity == PROX_NEAR_STAIRS && tries >= 300)
737 mon_type = pick_random_monster(*place, mon_type, place);
742 // A short function to check the results of near_stairs().
743 // Returns 0 if the point is not near stairs.
744 // Returns 1 if the point is near unoccupied stairs.
745 // Returns 2 if the point is near player-occupied stairs.
746 static int _is_near_stairs(coord_def &p)
750 for (int i = -1; i <= 1; ++i)
751 for (int j = -1; j <= 1; ++j)
756 const dungeon_feature_type feat = grd(p);
757 if (feat_is_stair(feat))
759 // Shouldn't matter for escape hatches.
760 if (feat_is_escape_hatch(feat))
763 // Should there be several stairs, don't overwrite the
764 // player on stairs info.
766 result = (p == you.pos()) ? 2 : 1;
773 // For generation purposes, don't treat simulacra of lava enemies as
774 // being able to place on lava.
775 const monster_type fixup_zombie_type(const monster_type cls,
776 const monster_type base_type)
778 return (mons_class_is_zombified(cls)
779 && mons_class_secondary_habitat(base_type) != HT_LAVA)
784 // Checks if the monster is ok to place at mg_pos. If force_location
785 // is true, then we'll be less rigorous in our checks, in particular
786 // allowing land monsters to be placed in shallow water and water
787 // creatures in fountains.
788 static bool _valid_monster_generation_location(const mgen_data &mg,
789 const coord_def &mg_pos)
791 if (!in_bounds(mg_pos)
792 || monster_at(mg_pos)
793 || you.pos() == mg_pos && !fedhas_passthrough_class(mg.cls))
798 const monster_type montype = fixup_zombie_type(mg.cls, mg.base_type);
799 if (!monster_habitable_grid(montype, grd(mg_pos), mg.preferred_grid_feature,
800 mons_class_flies(montype), false)
801 || (mg.behaviour != BEH_FRIENDLY && !mons_is_mimic(montype)
802 && is_sanctuary(mg_pos)
803 && !mons_is_tentacle_segment(montype)))
808 // Check player proximity to avoid band members being placed
809 // close to the player erroneously.
810 // XXX: This is a little redundant with proximity checks in
812 if (mg.proximity == PROX_AWAY_FROM_PLAYER
813 && distance2(you.pos(), mg_pos) <= LOS_RADIUS_SQ)
818 // Don't generate monsters on top of teleport traps.
819 // (How did they get there?)
820 const trap_def* ptrap = find_trap(mg_pos);
821 if (ptrap && !can_place_on_trap(mg.cls, ptrap->type))
827 static bool _valid_monster_generation_location(mgen_data &mg)
829 return _valid_monster_generation_location(mg, mg.pos);
832 // Returns true if the player is on a level that should be sheltered from
833 // OOD packs, based on depth and time spent on-level.
834 static bool _in_ood_pack_protected_place()
836 return env.turns_on_level < 1400 - env.absdepth0 * 117;
839 monster* place_monster(mgen_data mg, bool force_pos, bool dont_place)
841 #ifdef DEBUG_MON_CREATION
842 mprf(MSGCH_DIAGNOSTICS, "in place_monster()");
846 dungeon_char_type stair_type = NUM_DCHAR_TYPES;
848 // (1) Early out (summoned to occupied grid).
849 if (mg.use_position() && monster_at(mg.pos))
852 if (!mg.place.is_valid())
853 mg.place = level_id::current();
855 bool want_band = false;
856 level_id place = mg.place;
857 mg.cls = resolve_monster_type(mg.cls, mg.base_type, mg.proximity,
858 &mg.pos, mg.map_mask,
862 bool chose_ood_monster = place.absdepth() > mg.place.absdepth() + 5;
864 mg.flags |= MG_PERMIT_BANDS;
866 if (mg.cls == MONS_NO_MONSTER || mg.cls == MONS_PROGRAM_BUG)
869 bool create_band = mg.permit_bands();
870 // If we drew an OOD monster and there hasn't been much time spent
871 // on level, disable band generation. This applies only to
872 // randomly picked monsters -- chose_ood_monster will never be set
873 // true for explicitly specified monsters in vaults and other
875 if (chose_ood_monster && _in_ood_pack_protected_place())
877 dprf("Chose monster with OOD roll: %s, disabling band generation",
878 get_monster_data(mg.cls)->name);
882 // Re-check for PROX_NEAR_STAIRS here - if original monster
883 // type wasn't RANDOM_MONSTER then the position won't
885 if (mg.proximity == PROX_NEAR_STAIRS && mg.pos.origin())
888 if (!_find_mon_place_near_stairs(mg.pos, &stair_type, lev))
889 mg.proximity = PROX_AWAY_FROM_PLAYER;
890 } // end proximity check
892 if (mg.cls == MONS_PROGRAM_BUG)
895 // (3) Decide on banding (good lord!)
898 monster_type band_monsters[BIG_BAND]; // band monster types
899 band_type band = BAND_NO_BAND;
900 band_monsters[0] = mg.cls;
902 // The (very) ugly thing band colour.
903 static colour_t ugly_colour = BLACK;
907 #ifdef DEBUG_MON_CREATION
908 mprf(MSGCH_DIAGNOSTICS, "Choose band members...");
910 band = _choose_band(mg.cls, band_size, leader);
912 for (int i = 1; i < band_size; ++i)
914 band_monsters[i] = _band_member(band, i);
916 // Get the (very) ugly thing band colour, so that all (very)
917 // ugly things in a band will start with it.
918 if ((band_monsters[i] == MONS_UGLY_THING
919 || band_monsters[i] == MONS_VERY_UGLY_THING)
920 && ugly_colour == BLACK)
922 ugly_colour = ugly_thing_random_colour();
927 // Set the (very) ugly thing band colour.
928 if (ugly_colour != BLACK)
929 mg.colour = ugly_colour;
931 // Returns 2 if the monster is placed near player-occupied stairs.
932 int pval = _is_near_stairs(mg.pos);
933 if (mg.proximity == PROX_NEAR_STAIRS)
935 // For some cases disallow monsters on stairs.
936 if (mons_class_is_stationary(mg.cls)
937 || (pval == 2 // Stairs occupied by player.
938 && (mons_class_base_speed(mg.cls) == 0
939 || grd(mg.pos) == DNGN_LAVA
940 || grd(mg.pos) == DNGN_DEEP_WATER)))
942 mg.proximity = PROX_AWAY_FROM_PLAYER;
946 // (4) For first monster, choose location. This is pretty intensive.
948 bool close_to_player;
950 // Player shoved out of the way?
953 if (!mg.use_position() && !force_pos)
957 // Try to pick a position that is
960 // c) in the 'correct' proximity to the player
967 // Placement already decided for PROX_NEAR_STAIRS.
968 // Else choose a random point on the map.
969 if (mg.proximity != PROX_NEAR_STAIRS)
970 mg.pos = random_in_bounds();
972 if (!_valid_monster_generation_location(mg))
975 // Is the grid verboten?
976 if (map_masked(mg.pos, mg.map_mask))
979 // Let's recheck these even for PROX_NEAR_STAIRS, just in case.
980 // Check proximity to player.
983 switch (mg.proximity)
986 if (distance2(you.pos(), mg.pos) < dist_range(2 + random2(3)))
990 case PROX_CLOSE_TO_PLAYER:
991 case PROX_AWAY_FROM_PLAYER:
992 // If this is supposed to measure los vs not los,
993 // then see_cell(mg.pos) should be used instead. (jpeg)
994 close_to_player = (distance2(you.pos(), mg.pos) <=
997 if (mg.proximity == PROX_CLOSE_TO_PLAYER && !close_to_player
998 || mg.proximity == PROX_AWAY_FROM_PLAYER && close_to_player)
1004 case PROX_NEAR_STAIRS:
1005 if (pval == 2) // player on stairs
1007 if (mons_class_base_speed(mg.cls) == 0)
1012 // Swap the monster and the player spots, unless the
1013 // monster was generated in lava or deep water.
1014 if (grd(mg.pos) == DNGN_LAVA
1015 || grd(mg.pos) == DNGN_DEEP_WATER)
1021 // You can't be shoved if you're caught in a net.
1029 coord_def mpos = mg.pos;
1033 proxOK = (pval > 0);
1040 // Cool.. passes all tests.
1042 } // end while... place first monster
1044 else if (!_valid_monster_generation_location(mg) && !dont_place)
1046 // Sanity check that the specified position is valid.
1050 // Reset the (very) ugly thing band colour.
1051 if (ugly_colour != BLACK)
1052 ugly_colour = BLACK;
1054 monster* mon = _place_monster_aux(mg, 0, place, force_pos, dont_place);
1056 // Bail out now if we failed.
1060 if (mg.props.exists("map"))
1061 mon->set_originating_map(mg.props["map"].get_string());
1063 if (mg.needs_patrol_point()
1064 || (mon->type == MONS_ALLIGATOR
1065 && !testbits(mon->flags, MF_BAND_MEMBER)))
1067 mon->patrol_point = mon->pos();
1068 #ifdef DEBUG_PATHFIND
1069 mprf("Monster %s is patrolling around (%d, %d).",
1070 mon->name(DESC_PLAIN).c_str(), mon->pos().x, mon->pos().y);
1074 if (player_in_branch(BRANCH_ABYSS) && !mg.summoner
1075 && in_bounds(mon->pos())
1076 && !(mg.extra_flags & MF_WAS_IN_VIEW)
1077 && !cell_is_solid(mon->pos()))
1079 big_cloud(CLOUD_TLOC_ENERGY, mon, mon->pos(), 3 + random2(3), 3, 3);
1082 // Message to player from stairwell/gate/abyss appearance.
1085 mprf("%s shoves you out of the %s!",
1086 mon->visible_to(&you) ? mon->name(DESC_A).c_str() : "Something",
1087 stair_type == DCHAR_ARCH ? "gateway" : "stairwell");
1089 else if (mg.proximity == PROX_NEAR_STAIRS && you.can_see(mon))
1093 case DCHAR_STAIRS_DOWN: mon->seen_context = SC_UPSTAIRS; break;
1094 case DCHAR_STAIRS_UP: mon->seen_context = SC_DOWNSTAIRS; break;
1095 case DCHAR_ARCH: mon->seen_context = SC_ARCH; break;
1099 else if (player_in_branch(BRANCH_ABYSS) && you.can_see(mon)
1100 && !crawl_state.generating_level
1101 && !mg.summoner && !mons_is_mimic(mon->type)
1102 && !crawl_state.is_god_acting()
1103 && !(mon->flags & MF_WAS_IN_VIEW)) // is this possible?
1105 mon->seen_context = SC_ABYSS;
1108 // Now, forget about banding if the first placement failed, or there are
1109 // too many monsters already, or we successfully placed by stairs.
1110 // Zotdef change - banding allowed on stairs for extra challenge!
1111 // Frequency reduced, though, and only after 2K turns.
1112 if (mon->mindex() >= MAX_MONSTERS - 30
1113 || (mg.proximity == PROX_NEAR_STAIRS && !crawl_state.game_is_zotdef())
1114 || (crawl_state.game_is_zotdef() && you.num_turns < 2000))
1119 // Not PROX_NEAR_STAIRS, so it will be part of a band, if there is any.
1121 mon->flags |= MF_BAND_MEMBER;
1123 const bool priest = mon->is_priest();
1125 mgen_data band_template = mg;
1127 if (leader && !mg.summoner)
1129 band_template.summoner = mon;
1130 band_template.flags |= MG_BAND_MINION;
1133 unwind_var<band_type> current_band(active_monster_band, band);
1134 // (5) For each band monster, loop call to place_monster_aux().
1135 for (int i = 1; i < band_size; i++)
1137 if (band_monsters[i] == MONS_NO_MONSTER)
1140 band_template.cls = band_monsters[i];
1142 // We don't want to place a unique that has already been
1144 if (mons_is_unique(band_template.cls)
1145 && you.unique_creatures[band_template.cls])
1150 if (monster *member = _place_monster_aux(band_template, mon, place))
1152 member->flags |= MF_BAND_MEMBER;
1153 member->props["band_leader"].get_int() = mon->mid;
1154 member->set_originating_map(mon->originating_map());
1156 // Priestly band leaders should have an entourage of the
1157 // same religion, unless members of that entourage already
1158 // have a different one.
1159 if (priest && member->god == GOD_NO_GOD)
1160 member->god = mon->god;
1162 if (mon->type == MONS_PIKEL)
1164 // Don't give XP for the slaves to discourage hunting. Pikel
1165 // has an artificially large XP modifier to compensate for
1167 member->flags |= MF_NO_REWARD;
1168 member->props["pikel_band"] = true;
1170 else if (mon->type == MONS_KIRKE)
1171 member->props["kirke_band"] = true;
1175 // Placement of first monster, at least, was a success.
1179 monster* get_free_monster()
1181 for (int i = 0; i < MAX_MONSTERS; ++i)
1182 if (env.mons[i].type == MONS_NO_MONSTER)
1184 env.mons[i].reset();
1185 return &env.mons[i];
1191 void mons_add_blame(monster* mon, const string &blame_string)
1193 const bool exists = mon->props.exists("blame");
1194 CrawlStoreValue& blame = mon->props["blame"];
1196 blame.new_vector(SV_STR, SFLAG_CONST_TYPE);
1197 blame.get_vector().push_back(blame_string);
1200 static void _place_twister_clouds(monster *mon)
1202 // Yay for the abj_degree having a huge granularity.
1203 if (mon->has_ench(ENCH_ABJ))
1205 mon_enchant abj = mon->get_ench(ENCH_ABJ);
1206 mon->lose_ench_duration(abj, abj.duration / 2);
1209 tornado_damage(mon, -10);
1212 static monster* _place_monster_aux(const mgen_data &mg, const monster *leader,
1214 bool force_pos, bool dont_place)
1218 // Some sanity checks.
1219 if (mons_is_unique(mg.cls) && you.unique_creatures[mg.cls]
1220 && !crawl_state.game_is_arena()
1221 || mons_class_flag(mg.cls, M_CANT_SPAWN))
1223 die("invalid monster to place: %s (%d)", mons_class_name(mg.cls), mg.cls);
1226 const monsterentry *m_ent = get_monster_data(mg.cls);
1228 monster* mon = get_free_monster();
1232 const monster_type montype = fixup_zombie_type(mg.cls, mg.base_type);
1234 // Setup habitat and placement.
1235 // If the space is occupied, try some neighbouring square instead.
1238 else if (leader == 0 && in_bounds(mg.pos)
1239 && (mg.behaviour == BEH_FRIENDLY ||
1240 (!is_sanctuary(mg.pos) || mons_is_tentacle_segment(montype))
1241 || mons_is_mimic(montype))
1242 && !monster_at(mg.pos)
1243 && (you.pos() != mg.pos || fedhas_passthrough_class(mg.cls))
1244 && (force_pos || monster_habitable_grid(montype, grd(mg.pos))))
1251 // We'll try 1000 times for a good spot.
1252 for (i = 0; i < 1000; ++i)
1254 fpos = mg.pos + coord_def(random_range(-3, 3),
1255 random_range(-3, 3));
1257 // Place members within LOS_SOLID of their leader.
1258 // TODO nfm - allow placing around corners but not across walls.
1259 if ((leader == 0 || cell_see_cell(fpos, leader->pos(), LOS_SOLID))
1260 && _valid_monster_generation_location(mg, fpos))
1266 // Did we really try 1000 times?
1271 ASSERT(!monster_at(fpos));
1273 if (crawl_state.game_is_arena()
1274 && arena_veto_place_monster(mg, leader == 0, fpos))
1279 // Now, actually create the monster. (Wheeee!)
1280 mon->set_new_monster_id();
1282 mon->base_monster = mg.base_type;
1283 mon->number = mg.number;
1285 // Set pos and link monster into monster grid.
1286 if (!dont_place && !mon->move_to_pos(fpos))
1288 env.mid_cache.erase(mon->mid);
1293 // Pick the correct Serpent of Hell.
1294 if (mon->type == MONS_SERPENT_OF_HELL)
1296 switch (place.branch)
1298 case BRANCH_COCYTUS:
1299 mon->type = MONS_SERPENT_OF_HELL_COCYTUS;
1302 mon->type = MONS_SERPENT_OF_HELL_DIS;
1304 case BRANCH_TARTARUS:
1305 mon->type = MONS_SERPENT_OF_HELL_TARTARUS;
1307 default: ; // if it spawns out of Hell (sprint, wizmode), use Gehenna
1311 // Generate a brand shiny new monster, or zombie.
1312 if (mons_class_is_zombified(mg.cls))
1314 monster_type ztype = mg.base_type;
1316 if (ztype == MONS_NO_MONSTER || ztype == RANDOM_MONSTER)
1317 ztype = pick_local_zombifiable_monster(place, mg.cls, fpos);
1319 define_zombie(mon, ztype, mg.cls);
1322 define_monster(mon);
1324 // Must do this early, as init_chimera calls define_monster again.
1325 if (mons_class_is_chimeric(mon->type))
1330 if (mg.chimera_mons.size() != 3)
1332 if (!ghost.init_chimera_for_place(mon, place, mg.cls, fpos))
1334 env.mid_cache.erase(mon->mid);
1341 monster_type parts[] =
1347 ghost.init_chimera(mon, parts);
1349 mon->set_ghost(ghost);
1350 mon->ghost_demon_init();
1353 // Is it a god gift?
1354 if (mg.god != GOD_NO_GOD)
1357 mon->flags |= MF_GOD_GIFT;
1359 // Not a god gift, give priestly monsters a god.
1360 else if (mons_class_flag(mg.cls, M_PRIEST))
1362 // Berserkers belong to Trog.
1363 if (mg.cls == MONS_SPRIGGAN_BERSERKER)
1364 mon->god = GOD_TROG;
1365 // Profane servitors and death knights belong to Yredelemnul.
1366 else if (mg.cls == MONS_PROFANE_SERVITOR
1367 || mg.cls == MONS_DEATH_KNIGHT)
1369 mon->god = GOD_YREDELEMNUL;
1371 // Wiglaf belongs to Okawaru.
1372 else if (mg.cls == MONS_WIGLAF)
1373 mon->god = GOD_OKAWARU;
1374 // Asterion belongs to Mahkleb.
1375 else if (mg.cls == MONS_ASTERION)
1376 mon->god = GOD_MAKHLEB;
1379 switch (mons_genus(mg.cls))
1382 mon->god = GOD_BEOGH;
1385 mon->god = GOD_JIYVA;
1388 case MONS_DRACONIAN:
1390 // [ds] Vault defs can request priest monsters of unusual types.
1392 mon->god = GOD_NAMELESS;
1397 // XXX: Unborn belong to Yredelemnul, but only so they'll get the right
1398 // message when casting Injury Mirror.
1399 else if (mg.cls == MONS_UNBORN)
1400 mon->god = GOD_YREDELEMNUL;
1401 // The royal jelly belongs to Jiyva.
1402 else if (mg.cls == MONS_ROYAL_JELLY)
1403 mon->god = GOD_JIYVA;
1404 // Mennas belongs to Zin.
1405 else if (mg.cls == MONS_MENNAS)
1407 // Yiuf is a faithful Xommite.
1408 else if (mg.cls == MONS_CRAZY_YIUF)
1410 // Grinder and Ignacio belong to Makhleb.
1411 else if (mg.cls == MONS_GRINDER
1412 || mg.cls == MONS_IGNACIO)
1414 mon->god = GOD_MAKHLEB;
1416 // 1 out of 7 non-priestly orcs are unbelievers.
1417 else if (mons_genus(mg.cls) == MONS_ORC)
1419 if (!one_chance_in(7))
1420 mon->god = GOD_BEOGH;
1422 else if (mg.cls == MONS_APIS)
1423 mon->god = GOD_ELYVILON;
1424 // Angels (other than Mennas) and daevas belong to TSO, but 1 out of
1425 // 7 in the Abyss are adopted by Xom.
1426 else if (mons_class_holiness(mg.cls) == MH_HOLY)
1428 if (mg.place != BRANCH_ABYSS || !one_chance_in(7))
1429 mon->god = GOD_SHINING_ONE;
1434 // Holy monsters need their halo!
1435 if (mon->holiness() == MH_HOLY)
1436 invalidate_agrid(true);
1437 if (mg.cls == MONS_SILENT_SPECTRE || mg.cls == MONS_PROFANE_SERVITOR)
1438 invalidate_agrid(true);
1440 // If the caller requested a specific colour for this monster, apply
1442 if (mg.colour != BLACK)
1443 mon->colour = mg.colour;
1446 mon->mname = mg.mname;
1450 int bonus1 = 0, bonus2 = 0, bonus3 = 0;
1451 if (mons_is_demonspawn(mg.cls)
1452 && mg.cls != MONS_DEMONSPAWN
1453 && mons_species(mg.cls) == MONS_DEMONSPAWN)
1455 // Nonbase demonspawn get bonuses from their base type.
1456 const monsterentry *mbase =
1457 get_monster_data(draco_or_demonspawn_subspecies(mon));
1458 bonus1 = mbase->hpdice[1];
1459 bonus2 = mbase->hpdice[2];
1460 bonus3 = mbase->hpdice[3];
1462 mon->set_hit_dice(mg.hd);
1464 int hp = hit_points(mg.hd, m_ent->hpdice[1] + bonus1,
1465 m_ent->hpdice[2] + bonus2);
1466 // But only for monsters with random HP.
1469 hp += m_ent->hpdice[3] + bonus3;
1470 mon->max_hit_points = hp;
1471 mon->hit_points = hp;
1477 mon->max_hit_points = mg.hp;
1478 mon->hit_points = mg.hp;
1481 if (!crawl_state.game_is_arena())
1483 mon->max_hit_points = min(mon->max_hit_points, MAX_MONSTER_HP);
1484 mon->hit_points = min(mon->hit_points, MAX_MONSTER_HP);
1487 // Store the extra flags here.
1488 mon->flags |= mg.extra_flags;
1490 // The return of Boris is now handled in monster_die(). Not setting
1491 // this for Boris here allows for multiple Borises in the dungeon at
1492 // the same time. - bwr
1493 if (mons_is_unique(mg.cls))
1494 you.unique_creatures.set(mg.cls);
1496 if (mons_class_flag(mg.cls, M_INVIS))
1497 mon->add_ench(ENCH_INVIS);
1499 if (mons_class_flag(mg.cls, M_CONFUSED))
1500 mon->add_ench(ENCH_CONFUSION);
1502 if (mg.cls == MONS_SHAPESHIFTER)
1503 mon->add_ench(ENCH_SHAPESHIFTER);
1505 if (mg.cls == MONS_GLOWING_SHAPESHIFTER)
1506 mon->add_ench(ENCH_GLOWING_SHAPESHIFTER);
1508 if (mg.cls == MONS_TOADSTOOL
1509 || mg.cls == MONS_PILLAR_OF_SALT
1510 || mg.cls == MONS_BLOCK_OF_ICE)
1512 // This enchantment is a timer that counts down until death.
1513 // It should last longer than the lifespan of a corpse, to avoid
1514 // spawning mushrooms in the same place over and over. Aside
1515 // from that, the value is slightly randomised to avoid
1516 // simultaneous die-offs of mushroom rings.
1517 mon->add_ench(ENCH_SLOWLY_DYING);
1519 else if (mg.cls == MONS_HYPERACTIVE_BALLISTOMYCETE)
1520 mon->add_ench(ENCH_EXPLODING);
1521 else if (mons_is_demonspawn(mon->type)
1522 && draco_or_demonspawn_subspecies(mon) == MONS_GELID_DEMONSPAWN)
1524 mon->add_ench(ENCH_ICEMAIL);
1527 if (mg.cls == MONS_TWISTER || mg.cls == MONS_DIAMOND_OBELISK)
1529 mon->props["tornado_since"].get_int() = you.elapsed_time;
1530 mon->add_ench(mon_enchant(ENCH_TORNADO, 0, 0, INFINITE_DURATION));
1533 if (mons_class_flag(mg.cls, M_OZOCUBUS_ARMOUR))
1535 const int power = (mon->spell_hd(SPELL_OZOCUBUS_ARMOUR) * 15) / 10;
1536 mon->add_ench(mon_enchant(ENCH_OZOCUBUS_ARMOUR,
1537 20 + random2(power) + random2(power),
1541 if (mons_class_flag(mg.cls, M_SHROUD))
1542 mon->add_ench(ENCH_SHROUD);
1544 mon->flags |= MF_JUST_SUMMONED;
1546 // Don't leave shifters in their starting shape.
1547 if (mg.cls == MONS_SHAPESHIFTER || mg.cls == MONS_GLOWING_SHAPESHIFTER)
1550 monster_polymorph(mon, mg.initial_shifter);
1552 // It's not actually a known shapeshifter if it happened to be
1553 // placed in LOS of the player.
1554 mon->flags &= ~MF_KNOWN_SHIFTER;
1557 // dur should always be 1-6 for monsters that can be abjured.
1558 const bool summoned = mg.abjuration_duration >= 1
1559 && mg.abjuration_duration <= 6;
1561 if (mons_class_is_animated_weapon(mg.cls))
1563 if (mg.props.exists(TUKIMA_WEAPON))
1564 give_specific_item(mon, mg.props[TUKIMA_WEAPON].get_item());
1566 give_item(mon, place.absdepth(), summoned);
1568 // Dancing weapons *always* have a weapon. Fail to create them
1570 const item_def* wpn = mon->mslot_item(MSLOT_WEAPON);
1573 mon->destroy_inventory();
1574 env.mid_cache.erase(mon->mid);
1576 mgrd(fpos) = NON_MONSTER;
1580 mon->colour = wpn->colour;
1582 else if (mons_class_itemuse(mg.cls) >= MONUSE_STARTING_EQUIPMENT)
1584 give_item(mon, place.absdepth(), summoned, false, mg.props.exists("mercenary items"));
1585 // Give these monsters a second weapon. - bwr
1586 if (mons_class_wields_two_weapons(mg.cls))
1587 give_weapon(mon, place.absdepth(), summoned);
1589 unwind_var<int> save_speedinc(mon->speed_increment);
1590 mon->wield_melee_weapon(false);
1593 if (mg.cls == MONS_SLIME_CREATURE)
1597 // Boost HP to what it would have been if it had grown this
1599 mon->hit_points *= mg.number;
1600 mon->max_hit_points *= mg.number;
1604 if (monster_can_submerge(mon, grd(fpos)) && !one_chance_in(5) && !summoned)
1605 mon->add_ench(ENCH_SUBMERGED);
1607 if (mons_is_mimic(mg.cls))
1608 mon->props = mg.props;
1610 // Set attitude, behaviour and target.
1611 mon->attitude = ATT_HOSTILE;
1612 mon->behaviour = mg.behaviour;
1614 // Statues cannot sleep (nor wander but it means they are a bit
1615 // more aware of the player than they'd be otherwise).
1616 if (mons_is_statue(mg.cls))
1617 mon->behaviour = BEH_WANDER;
1618 // Trapdoor spiders lurk, they don't sleep
1619 if (mg.cls == MONS_TRAPDOOR_SPIDER)
1620 mon->behaviour = BEH_LURK;
1622 mon->foe_memory = 0;
1624 // Setting attitude will always make the monster wander...
1625 // If you want sleeping hostiles, use BEH_SLEEP since the default
1626 // attitude is hostile.
1627 if (mg.behaviour > NUM_BEHAVIOURS)
1629 if (mg.behaviour == BEH_FRIENDLY)
1630 mon->attitude = ATT_FRIENDLY;
1632 if (mg.behaviour == BEH_GOOD_NEUTRAL)
1633 mon->attitude = ATT_GOOD_NEUTRAL;
1635 if (mg.behaviour == BEH_NEUTRAL)
1636 mon->attitude = ATT_NEUTRAL;
1638 if (mg.behaviour == BEH_STRICT_NEUTRAL)
1639 mon->attitude = ATT_STRICT_NEUTRAL;
1641 mon->behaviour = BEH_WANDER;
1646 // Instead of looking for dancing weapons, look for Tukima's dance.
1647 // Dancing weapons can be created with shadow creatures. {due}
1648 bool mark_items = mg.summon_type != SPELL_TUKIMAS_DANCE;
1650 mon->mark_summoned(mg.abjuration_duration,
1654 if (mg.summon_type > 0 && mg.summoner && !(mg.flags & MG_DONT_CAP))
1656 // If this is a band member created by shadow creatures, link its
1657 // ID and don't count it against the summon cap
1658 if ((mg.summon_type == SPELL_SHADOW_CREATURES
1659 || mg.summon_type == SPELL_WEAVE_SHADOWS)
1662 mon->props["summon_id"].get_int() = leader->mid;
1666 summoned_monster(mon, mg.summoner,
1667 static_cast<spell_type>(mg.summon_type));
1672 // Perm summons shouldn't leave gear either.
1673 if (mg.extra_flags & MF_HARD_RESET && mg.extra_flags & MF_NO_REWARD)
1674 mon->mark_summoned(0, true, 0, false);
1676 ASSERT(!invalid_monster_index(mg.foe)
1677 || mg.foe == MHITYOU || mg.foe == MHITNOT);
1680 string blame_prefix;
1682 if (mg.flags & MG_BAND_MINION)
1683 blame_prefix = "led by ";
1684 else if (mg.abjuration_duration > 0)
1686 blame_prefix = "summoned by ";
1688 if (mg.summoner != NULL && mg.summoner->alive()
1689 && mg.summoner->type == MONS_MARA)
1691 blame_prefix = "woven by ";
1694 if (mg.cls == MONS_DANCING_WEAPON)
1695 blame_prefix = "animated by ";
1697 else if (mons_class_is_zombified(mg.cls))
1698 blame_prefix = "animated by ";
1699 else if (mg.summon_type == SPELL_STICKS_TO_SNAKES)
1700 blame_prefix = "transmuted by ";
1701 else if (mg.cls == MONS_ELDRITCH_TENTACLE
1702 || mg.cls == MONS_ELDRITCH_TENTACLE_SEGMENT)
1704 blame_prefix = "called by ";
1706 else if (mons_is_child_tentacle(mg.cls))
1707 blame_prefix = "attached to ";
1709 blame_prefix = "created by ";
1711 if (!mg.non_actor_summoner.empty())
1712 mons_add_blame(mon, blame_prefix + mg.non_actor_summoner);
1713 // NOTE: The summoner might be dead if the summoned is placed by a
1714 // beam which killed the summoner first (like fire vortexes placed
1715 // by the Fire Storm spell); a deceased summoner's mindex might also
1716 // be reused to create its summon, so make sure the summon doesn't
1717 // think it has summoned itself.
1718 else if (mg.summoner != NULL && mg.summoner->alive()
1719 && mg.summoner != mon)
1721 ASSERT(mg.summoner->alive());
1722 mon->summoner = mg.summoner->mid;
1723 if (mg.summoner->is_player())
1724 mons_add_blame(mon, blame_prefix + "the player character");
1727 const monster* sum = mg.summoner->as_monster();
1728 mons_add_blame(mon, (blame_prefix
1729 + sum->full_name(DESC_A, true)));
1730 if (sum->props.exists("blame"))
1732 const CrawlVector& oldblame = sum->props["blame"].get_vector();
1733 for (CrawlVector::const_iterator i = oldblame.begin();
1734 i != oldblame.end(); ++i)
1736 mons_add_blame(mon, i->get_string());
1742 // Initialise (very) ugly things and pandemonium demons.
1743 if (mon->type == MONS_UGLY_THING
1744 || mon->type == MONS_VERY_UGLY_THING)
1747 ghost.init_ugly_thing(mon->type == MONS_VERY_UGLY_THING, false,
1749 mon->set_ghost(ghost);
1750 mon->uglything_init();
1752 #if TAG_MAJOR_VERSION == 34
1753 else if (mon->type == MONS_LABORATORY_RAT)
1754 mon->type = MONS_RAT;
1756 else if (mons_class_is_animated_weapon(mon->type))
1759 // We can't use monster::weapon here because it wants to look
1760 // at attack types, which are in the ghost structure we're
1762 ASSERT(mon->mslot_item(MSLOT_WEAPON));
1763 if (mon->type == MONS_DANCING_WEAPON)
1765 // Dancing weapons are placed at pretty high power. Remember, the
1766 // player is fighting them one-on-one, while he will often summon
1768 ghost.init_dancing_weapon(*(mon->mslot_item(MSLOT_WEAPON)),
1769 mg.props.exists(TUKIMA_POWER) ?
1770 mg.props[TUKIMA_POWER].get_int() : 100);
1774 // Spectral weapons are placed at pretty high power.
1775 // They shouldn't ever be placed in a normal game.
1776 ghost.init_spectral_weapon(*(mon->mslot_item(MSLOT_WEAPON)),
1777 mg.props.exists(TUKIMA_POWER) ?
1778 mg.props[TUKIMA_POWER].get_int() : 100,
1779 mg.props.exists(TUKIMA_SKILL) ?
1780 mg.props[TUKIMA_SKILL].get_int() : 270);
1782 mon->set_ghost(ghost);
1783 mon->ghost_demon_init();
1786 tile_init_props(mon);
1788 #ifndef DEBUG_DIAGNOSTICS
1789 // A rare case of a debug message NOT showing in the debug mode.
1790 if (mons_class_flag(mon->type, M_UNFINISHED))
1792 mprf(MSGCH_WARN, "Warning: monster '%s' is not yet fully coded.",
1793 mon->name(DESC_PLAIN, true).c_str());
1797 mark_interesting_monst(mon, mg.behaviour);
1799 if (crawl_state.game_is_arena())
1800 arena_placed_monster(mon);
1801 else if (!crawl_state.generating_level && !dont_place && you.can_see(mon))
1803 if (mg.flags & MG_DONT_COME)
1804 mon->seen_context = SC_JUST_SEEN;
1807 // Area effects can produce additional messages, and thus need to be
1808 // done after come in view ones.
1809 if (mon->type == MONS_TWISTER && !dont_place)
1810 _place_twister_clouds(mon);
1812 if (!(mg.flags & MG_FORCE_BEH)
1813 && !crawl_state.game_is_arena()
1814 && !crawl_state.generating_level)
1816 gozag_set_bribe(mon);
1822 monster_type pick_random_zombie()
1824 static vector<monster_type> zombifiable;
1826 if (zombifiable.empty())
1828 for (monster_type mcls = MONS_0; mcls < NUM_MONSTERS; ++mcls)
1830 if (mons_species(mcls) != mcls || mcls == MONS_PROGRAM_BUG)
1833 if (!mons_zombie_size(mcls) || mons_is_unique(mcls))
1835 if (mons_class_holiness(mcls) != MH_NATURAL)
1838 zombifiable.push_back(mcls);
1841 ASSERT(!zombifiable.empty());
1844 return zombifiable[random2(zombifiable.size())];
1847 // Check base monster class against zombie type and position if set.
1848 static bool _good_zombie(monster_type base, monster_type cs,
1849 const coord_def& pos)
1851 base = fixup_zombie_type(cs, base);
1853 // Actually pick a monster that is happy where we want to put it.
1854 // Fish zombies on land are helpless and uncool.
1855 if (in_bounds(pos) && !monster_habitable_grid(base, grd(pos)))
1858 if (cs == MONS_NO_MONSTER)
1861 // If skeleton, monster must have a skeleton.
1862 if (cs == MONS_SKELETON && !mons_skeleton(base))
1865 // If zombie, monster must have unrotted meat.
1866 if (cs == MONS_ZOMBIE && !mons_zombifiable(base))
1872 // Veto for the zombie picker class
1873 bool zombie_picker::veto(monster_type mt)
1875 monster_type corpse_type = mons_species(mt);
1877 // XXX: nonbase draconian leave base draconian corpses.
1878 if (mt != MONS_DRACONIAN && corpse_type == MONS_DRACONIAN)
1879 corpse_type = random_draconian_monster_species();
1881 // Zombifiability in general.
1882 if (!mons_class_can_leave_corpse(corpse_type))
1884 // Monsters that don't really exist
1885 if (mons_class_flag(mt, M_UNFINISHED))
1887 // Monsters that can have derived undead, but never randomly generated.
1888 if (mons_class_flag(mt, M_NO_GEN_DERIVED))
1890 if (!mons_zombie_size(corpse_type) || mons_is_unique(mt))
1892 if (mons_class_holiness(corpse_type) != MH_NATURAL)
1895 return !_good_zombie(corpse_type, zombie_kind, pos);
1898 monster_type pick_local_zombifiable_monster(level_id place,
1900 const coord_def& pos)
1902 if (crawl_state.game_is_zotdef())
1904 place = level_id(BRANCH_DUNGEON,
1905 you.num_turns / (2 * ZOTDEF_CYCLE_LENGTH) + 6);
1907 else if (place.branch == BRANCH_ZIGGURAT)
1909 // Get Zigs something reasonable to work with, if there's no place
1910 // explicitly defined.
1911 place = level_id(BRANCH_DEPTHS, 14 - (27 - place.depth) / 3);
1915 // Zombies tend to be weaker than their normal counterparts;
1916 // thus, make them OOD proportional to the current dungeon depth.
1917 place.depth += 1 + div_rand_round(place.absdepth(), 5);
1920 zombie_picker picker = zombie_picker(pos, cs);
1922 place.depth = max(1, min(place.depth, branch_ood_cap(place.branch)));
1924 if (monster_type mt =
1925 picker.pick_with_veto(zombie_population(place.branch),
1926 place.depth, MONS_0))
1931 return pick_monster_all_branches(place.absdepth(), picker);
1934 void roll_zombie_hp(monster* mon)
1936 ASSERT(mons_class_is_zombified(mon->type));
1943 hp = hit_points(mon->get_hit_dice(), 6, 5);
1947 hp = hit_points(mon->get_hit_dice(), 5, 4);
1950 case MONS_SIMULACRUM:
1951 // Simulacra aren't tough, but you can create piles of them. - bwr
1952 hp = hit_points(mon->get_hit_dice(), 1, 4);
1955 case MONS_SPECTRAL_THING:
1956 hp = hit_points(mon->get_hit_dice(), 4, 4);
1960 die("invalid zombie type %d (%s)", mon->type,
1961 mons_class_name(mon->type));
1964 mon->max_hit_points = max(hp, 1);
1965 mon->hit_points = mon->max_hit_points;
1968 static void _roll_zombie_ac_ev_mods(monster* mon, int& acmod, int& evmod)
1970 ASSERT(mons_class_is_zombified(mon->type));
1984 case MONS_SIMULACRUM:
1985 // Simulacra aren't tough, but you can create piles of them. - bwr
1990 case MONS_SPECTRAL_THING:
1996 die("invalid zombie type %d (%s)", mon->type,
1997 mons_class_name(mon->type));
2001 static void _roll_zombie_ac_ev(monster* mon)
2003 ASSERT(mons_class_is_zombified(mon->type));
2008 _roll_zombie_ac_ev_mods(mon, acmod, evmod);
2010 mon->ac = max(mon->ac + acmod, 0);
2011 mon->ev = max(mon->ev + evmod, 0);
2014 void define_zombie(monster* mon, monster_type ztype, monster_type cs)
2016 #if TAG_MAJOR_VERSION == 34
2017 // Upgrading monster enums is a losing battle, they sneak through too many
2018 // channels, like env props, etc. So convert them on placement, too.
2019 if (cs == MONS_ZOMBIE_SMALL || cs == MONS_ZOMBIE_LARGE)
2021 if (cs == MONS_SKELETON_SMALL || cs == MONS_SKELETON_LARGE)
2023 if (cs == MONS_SIMULACRUM_SMALL || cs == MONS_SIMULACRUM_LARGE)
2024 cs = MONS_SIMULACRUM;
2027 ASSERT(ztype != MONS_NO_MONSTER);
2028 ASSERT(!invalid_monster_type(ztype));
2029 ASSERT(mons_class_is_zombified(cs));
2031 monster_type base = mons_species(ztype);
2033 // Set type to the original type to calculate appropriate stats.
2035 mon->base_monster = MONS_PROGRAM_BUG;
2036 define_monster(mon);
2039 mon->base_monster = base;
2041 mon->colour = mons_class_colour(mon->type);
2042 mon->speed = (cs == MONS_SPECTRAL_THING
2043 ? mons_class_base_speed(mon->base_monster)
2044 : mons_class_zombie_base_speed(mon->base_monster));
2046 // Turn off all melee ability flags except dual-wielding.
2047 mon->flags &= (~MF_MELEE_MASK | MF_TWO_WEAPONS);
2049 // Turn off all spellcasting and priestly ability flags.
2050 // Hack - kraken get to keep their spell-like ability.
2051 if (mon->base_monster != MONS_KRAKEN)
2052 mon->flags &= ~MF_SPELL_MASK;
2054 // Turn off regeneration if the base monster cannot regenerate.
2055 // This is needed for e.g. spectral things of non-regenerating
2057 if (!mons_class_can_regenerate(mon->base_monster))
2058 mon->flags |= MF_NO_REGEN;
2060 roll_zombie_hp(mon);
2061 _roll_zombie_ac_ev(mon);
2064 bool downgrade_zombie_to_skeleton(monster* mon)
2066 if (mon->type != MONS_ZOMBIE || !mons_skeleton(mon->base_monster))
2072 _roll_zombie_ac_ev_mods(mon, acmod, evmod);
2074 // Reverse the zombie AC and EV mods, since they will be replaced
2075 // with the skeleton AC and EV mods below.
2076 mon->ac = max(mon->ac - acmod, 0);
2077 mon->ev = max(mon->ev - evmod, 0);
2079 const int old_hp = mon->hit_points;
2080 const int old_maxhp = mon->max_hit_points;
2082 mon->type = MONS_SKELETON;
2083 mon->colour = mons_class_colour(mon->type);
2084 mon->speed = mons_class_zombie_base_speed(mon->base_monster);
2086 roll_zombie_hp(mon);
2087 _roll_zombie_ac_ev(mon);
2089 // Scale the skeleton HP to the zombie HP.
2090 mon->hit_points = old_hp * mon->max_hit_points / old_maxhp;
2091 mon->hit_points = max(mon->hit_points, 1);
2096 static band_type _choose_band(monster_type mon_type, int &band_size,
2097 bool &natural_leader)
2099 #ifdef DEBUG_MON_CREATION
2100 mprf(MSGCH_DIAGNOSTICS, "in _choose_band()");
2102 // Band size describes the number of monsters in addition to
2104 band_size = 0; // Single monster, no band.
2105 natural_leader = false;
2106 band_type band = BAND_NO_BAND;
2113 // intentional fall-through {dlb}
2114 case MONS_ORC_WIZARD:
2116 band_size = 2 + random2(3);
2119 case MONS_ORC_PRIEST:
2120 case MONS_ORC_WARRIOR:
2121 band = BAND_ORC_WARRIOR;
2122 band_size = 2 + random2(3);
2125 case MONS_ORC_WARLORD:
2126 case MONS_SAINT_ROKA:
2127 band_size = 5 + random2(5); // warlords have large bands
2128 // intentional fall through
2129 case MONS_ORC_KNIGHT:
2130 band = BAND_ORC_KNIGHT; // orcs + knight
2131 band_size += 3 + random2(4);
2132 natural_leader = true;
2135 case MONS_ORC_HIGH_PRIEST:
2136 band = BAND_ORC_HIGH_PRIEST;
2137 band_size = 4 + random2(4);
2138 natural_leader = true;
2141 case MONS_BIG_KOBOLD:
2142 if (env.absdepth0 > 3)
2144 band = BAND_KOBOLDS;
2145 band_size = 2 + random2(6);
2149 case MONS_KILLER_BEE:
2150 band = BAND_KILLER_BEES;
2151 band_size = 2 + random2(4);
2154 case MONS_FLYING_SKULL:
2155 band = BAND_FLYING_SKULLS;
2156 band_size = 2 + random2(4);
2158 case MONS_SLIME_CREATURE:
2159 band = BAND_SLIME_CREATURES;
2160 band_size = 2 + random2(4);
2164 band_size = 2 + random2(4);
2166 case MONS_VERY_UGLY_THING:
2167 if (env.absdepth0 < 19)
2169 // fallthrough to ugly things...
2170 case MONS_UGLY_THING:
2171 if (env.absdepth0 < 13)
2173 band = BAND_UGLY_THINGS;
2174 band_size = 2 + random2(4);
2176 case MONS_HELL_HOUND:
2177 band = BAND_HELL_HOUNDS;
2178 band_size = 2 + random2(3);
2181 band = BAND_JACKALS;
2182 band_size = 1 + random2(3);
2185 natural_leader = true;
2186 case MONS_HELL_KNIGHT:
2187 band = BAND_HELL_KNIGHTS;
2188 band_size = 4 + random2(4);
2190 case MONS_JOSEPHINE:
2191 band_size = 1 + random2(2);
2192 // intentional fall-through
2193 case MONS_NECROMANCER:
2194 natural_leader = true;
2195 band = BAND_NECROMANCER;
2196 band_size += 3 + random2(3);
2198 case MONS_VAMPIRE_MAGE:
2199 if (one_chance_in(3))
2201 natural_leader = true;
2202 band = BAND_JIANGSHI;
2203 band_size = 2 + random2(2);
2207 band = BAND_JIANGSHI;
2208 band_size = random2(3);
2211 if (!player_in_branch(BRANCH_DUNGEON) || you.depth > 1)
2214 band_size = (coinflip() ? 3 : 2);
2217 case MONS_GNOLL_SHAMAN:
2218 case MONS_GNOLL_SERGEANT:
2220 band_size = 3 + random2(4);
2222 case MONS_DEATH_KNIGHT:
2223 if (x_chance_in_y(2, 3))
2225 natural_leader = true;
2226 band = BAND_DEATH_KNIGHT;
2227 band_size = 3 + random2(2);
2231 natural_leader = true;
2233 band_size = 2 + random2(3);
2235 case MONS_CENTAUR_WARRIOR:
2236 natural_leader = true;
2238 if (env.absdepth0 > 9 && one_chance_in(3) && !player_in_branch(BRANCH_SHOALS))
2240 band = BAND_CENTAURS;
2241 band_size = 2 + random2(4);
2245 case MONS_YAKTAUR_CAPTAIN:
2246 natural_leader = true;
2250 band = BAND_YAKTAURS;
2251 band_size = 2 + random2(3);
2255 case MONS_DEATH_YAK:
2256 band = BAND_DEATH_YAKS;
2257 band_size = 2 + random2(4);
2259 case MONS_INSUBSTANTIAL_WISP:
2260 band = BAND_INSUBSTANTIAL_WISPS;
2261 band_size = 3 + random2(4);
2263 case MONS_OGRE_MAGE:
2264 natural_leader = true;
2265 band = BAND_OGRE_MAGE;
2266 band_size = 4 + random2(4);
2269 natural_leader = true;
2271 band_size = 2 + random2(3);
2273 case MONS_CACODEMON:
2274 natural_leader = true;
2275 band = BAND_CACODEMON;
2276 band_size = 1 + random2(3);
2279 case MONS_EXECUTIONER:
2282 natural_leader = true;
2283 band = BAND_EXECUTIONER;
2284 band_size = 1 + random2(3);
2288 case MONS_PANDEMONIUM_LORD:
2289 natural_leader = true;
2290 band = BAND_PANDEMONIUM_LORD;
2291 band_size = random_range(1, 3);
2297 band = BAND_HELLWING;
2298 band_size = 1 + random2(4);
2302 case MONS_DEEP_ELF_FIGHTER:
2305 band = BAND_DEEP_ELF_FIGHTER;
2306 band_size = 2 + random2(3);
2310 case MONS_DEEP_ELF_KNIGHT:
2313 band = BAND_DEEP_ELF_KNIGHT;
2314 band_size = 3 + random2(2);
2318 case MONS_DEEP_ELF_HIGH_PRIEST:
2321 natural_leader = true;
2322 band = BAND_DEEP_ELF_HIGH_PRIEST;
2323 band_size = 3 + random2(4);
2327 case MONS_KOBOLD_DEMONOLOGIST:
2330 band = BAND_KOBOLD_DEMONOLOGIST;
2331 band_size = 3 + random2(6);
2335 case MONS_GUARDIAN_SERPENT:
2336 band = BAND_GUARDIAN_SERPENT;
2337 band_size = 2 + random2(4);
2340 case MONS_NAGA_MAGE:
2341 case MONS_NAGA_WARRIOR:
2342 // Spawn alone more frequently at shallow depths
2343 if (player_in_branch(BRANCH_SNAKE) && !x_chance_in_y(you.depth, 5))
2347 band_size = 2 + random2(3);
2350 case MONS_NAGA_SHARPSHOOTER:
2353 band = BAND_NAGA_SHARPSHOOTER;
2354 band_size = 1 + random2(3);
2358 case MONS_NAGA_RITUALIST:
2359 band = BAND_NAGA_RITUALIST;
2360 band_size = 3 + random2(3);
2365 band_size = 2 + random2(4);
2368 case MONS_GREEN_RAT:
2369 band = BAND_GREEN_RATS;
2370 band_size = 4 + random2(6);
2373 case MONS_ORANGE_RAT:
2374 band = BAND_ORANGE_RATS;
2375 band_size = 3 + random2(4);
2380 band_size = 3 + random2(5);
2385 band_size = 2 + random2(3);
2389 band_size = 2 + random2(3);
2390 natural_leader = true;
2393 band_size += 1 + random2(3);
2396 case MONS_VAMPIRE_MOSQUITO:
2397 band = BAND_VAMPIRE_MOSQUITOES;
2398 band_size = 1 + random2(3);
2402 band = BAND_FIRE_BATS;
2403 band_size = 1 + random2(3);
2406 case MONS_DEEP_TROLL_EARTH_MAGE:
2407 band = BAND_DEEP_TROLLS;
2408 band_size = 3 + random2(3);
2411 case MONS_DEEP_TROLL_SHAMAN:
2412 band = BAND_DEEP_TROLL_SHAMAN;
2413 band_size = 3 + random2(3);
2417 band = BAND_HELL_HOGS;
2418 band_size = 1 + random2(3);
2422 band = BAND_BOGGARTS;
2423 band_size = 2 + random2(3);
2426 case MONS_PRINCE_RIBBIT:
2427 natural_leader = true;
2428 // Intentional fallthrough
2429 case MONS_BLINK_FROG:
2430 band = BAND_BLINK_FROGS;
2431 band_size += 2 + random2(3);
2436 band_size = 2 + random2(3);
2439 case MONS_ANCIENT_CHAMPION:
2443 natural_leader = true;
2444 // Intentional fallthrough
2445 case MONS_SKELETAL_WARRIOR:
2446 band = BAND_SKELETAL_WARRIORS;
2447 band_size = 2 + random2(3);
2451 if (one_chance_in(5) || player_in_branch(BRANCH_SHOALS))
2453 natural_leader = true;
2454 band = BAND_SHEEP; // Odyssey reference
2455 band_size = 2 + random2(3);
2459 case MONS_ALLIGATOR:
2460 // Alligators with kids!
2461 if (one_chance_in(5))
2463 natural_leader = true;
2464 band = BAND_ALLIGATOR;
2465 band_size = 2 + random2(3);
2469 case MONS_POLYPHEMUS:
2470 natural_leader = true;
2471 band = BAND_POLYPHEMUS;
2472 band_size = 3 + random2(3);
2476 band = BAND_HARPIES;
2477 band_size = 2 + random2(3);
2480 // Journey -- Added Draconian Packs
2481 case MONS_WHITE_DRACONIAN:
2482 case MONS_RED_DRACONIAN:
2483 case MONS_PURPLE_DRACONIAN:
2484 case MONS_MOTTLED_DRACONIAN:
2485 case MONS_YELLOW_DRACONIAN:
2486 case MONS_BLACK_DRACONIAN:
2487 case MONS_GREEN_DRACONIAN:
2488 case MONS_GREY_DRACONIAN:
2489 case MONS_PALE_DRACONIAN:
2490 if (env.absdepth0 > 18 && one_chance_in(3) && player_in_connected_branch())
2492 band = BAND_DRACONIAN;
2493 band_size = random_range(2, 4);
2497 case MONS_DRACONIAN_CALLER:
2498 case MONS_DRACONIAN_MONK:
2499 case MONS_DRACONIAN_SCORCHER:
2500 case MONS_DRACONIAN_KNIGHT:
2501 case MONS_DRACONIAN_ANNIHILATOR:
2502 case MONS_DRACONIAN_ZEALOT:
2503 case MONS_DRACONIAN_SHIFTER:
2504 if (env.absdepth0 > 20 && player_in_connected_branch())
2506 band = BAND_DRACONIAN;
2507 band_size = random_range(3, 6);
2512 natural_leader = true;
2513 band = BAND_DRACONIAN;
2515 band_size = random_range(3,6) + random_range(3,6) + 2;
2520 band_size = 3 + random2(3);
2524 natural_leader = true;
2526 band_size = 4 + random2(5);
2530 // no natural_leader since this band is supposed to be symmetric
2531 band = BAND_DUVESSA;
2536 natural_leader = true;
2541 case MONS_GOLDEN_EYE:
2542 band = BAND_GOLDEN_EYE;
2543 band_size = 1 + random2(5);
2547 natural_leader = true;
2552 case MONS_MERFOLK_AQUAMANCER:
2553 band = BAND_MERFOLK_AQUAMANCER;
2554 band_size = random_range(3, 4);
2557 case MONS_MERFOLK_JAVELINEER:
2558 if (player_in_branch(BRANCH_DEPTHS))
2560 if (!player_in_branch(BRANCH_SHOALS) || x_chance_in_y(you.depth, 5))
2562 band = BAND_MERFOLK_JAVELINEER;
2563 band_size = random_range(2, 4);
2567 case MONS_MERFOLK_IMPALER:
2568 if (player_in_branch(BRANCH_DEPTHS))
2570 if (!player_in_branch(BRANCH_SHOALS) || x_chance_in_y(you.depth, 5))
2572 band = BAND_MERFOLK_IMPALER;
2573 band_size = random_range(2, 4);
2578 band = BAND_ELEPHANT;
2579 band_size = 2 + random2(4);
2583 band = BAND_REDBACK;
2584 band_size = 1 + random2(5);
2589 band_size = 1 + random2(4);
2592 case MONS_JUMPING_SPIDER:
2595 band = BAND_JUMPING_SPIDER;
2596 band_size = 1 + random2(5);
2600 case MONS_TARANTELLA:
2603 band = BAND_TARANTELLA;
2604 band_size = 1 + random2(4);
2608 case MONS_VAULT_WARDEN:
2609 natural_leader = true;
2612 band = BAND_YAKTAURS;
2613 band_size = 2 + random2(4);
2617 band = BAND_VAULT_WARDEN;
2618 band_size = 2 + random2(3);
2622 case MONS_IRONHEART_PRESERVER:
2623 natural_leader = true;
2627 band = BAND_DEEP_ELF_HIGH_PRIEST;
2628 band_size = 3 + random2(4);
2631 band = BAND_DEEP_TROLLS;
2632 band_size = 3 + random2(3);
2635 band = BAND_OGRE_MAGE_EXTERN;
2636 band_size = 4 + random2(4);
2642 if (!one_chance_in(3))
2644 natural_leader = true;
2645 band = one_chance_in(5) ? BAND_FAUN_PARTY : BAND_FAUNS;
2646 band_size = 3 + random2(2);
2651 if (!one_chance_in(3))
2653 band = coinflip() ? BAND_FAUNS : BAND_FAUN_PARTY;
2654 band_size = 2 + random2(2);
2658 case MONS_TENGU_CONJURER:
2659 case MONS_TENGU_WARRIOR:
2660 natural_leader = true;
2662 band_size = 2 + random2(3);
2666 natural_leader = true;
2671 case MONS_SPRIGGAN_AIR_MAGE:
2672 natural_leader = true;
2673 band = BAND_AIR_ELEMENTALS;
2674 band_size = random_range(2, 3);
2677 case MONS_SPRIGGAN_RIDER:
2678 if (!one_chance_in(3))
2680 band = BAND_SPRIGGAN_RIDERS;
2681 band_size = random_range(1, 2);
2684 case MONS_SPRIGGAN_DRUID:
2685 if (one_chance_in(3))
2687 band = BAND_SPRIGGAN_DRUID;
2688 natural_leader = true;
2689 band_size = (one_chance_in(4) ? 3 : 2);
2693 case MONS_SPRIGGAN_BERSERKER:
2696 natural_leader = true;
2697 band = BAND_SPRIGGANS;
2698 band_size = 2 + random2(2);
2702 case MONS_SPRIGGAN_DEFENDER:
2703 natural_leader = true;
2704 band = BAND_SPRIGGAN_ELITES;
2705 band_size = 2 + random2(3);
2708 case MONS_THE_ENCHANTRESS:
2709 natural_leader = true;
2710 band = BAND_ENCHANTRESS;
2711 band_size = 6 + random2avg(5, 2);
2714 case MONS_SHAMBLING_MANGROVE:
2715 if (one_chance_in(4))
2717 band = BAND_SPRIGGAN_RIDERS;
2722 case MONS_VAMPIRE_KNIGHT:
2723 if (one_chance_in(4))
2725 band = BAND_PHANTASMAL_WARRIORS;
2730 case MONS_THRASHING_HORROR:
2732 int depth = min(brdepth[BRANCH_ABYSS], you.depth);
2733 band = BAND_THRASHING_HORRORS;
2734 band_size = random2(depth);
2741 band_size = random_range(2, 3);
2748 band_size = random_range(1, 2);
2752 case MONS_SALAMANDER_MYSTIC:
2753 band = BAND_SALAMANDERS;
2754 band_size = random_range(2, 3);
2757 case MONS_SALAMANDER_FIREBRAND:
2760 band = BAND_SALAMANDER_ELITES;
2761 band_size = random_range(3, 4);
2766 case MONS_MONSTROUS_DEMONSPAWN:
2767 // Horrible hack for wizlab_wucad_mu.
2768 if (player_in_branch(BRANCH_WIZLAB))
2772 band = BAND_MONSTROUS_DEMONSPAWN;
2773 band_size = random_range(1, 2);
2777 case MONS_GELID_DEMONSPAWN:
2780 band = BAND_GELID_DEMONSPAWN;
2781 band_size = random_range(1, 2);
2785 case MONS_INFERNAL_DEMONSPAWN:
2788 band = BAND_INFERNAL_DEMONSPAWN;
2789 band_size = random_range(1, 2);
2793 case MONS_PUTRID_DEMONSPAWN:
2796 band = BAND_PUTRID_DEMONSPAWN;
2797 band_size = random_range(1, 2);
2801 case MONS_TORTUROUS_DEMONSPAWN:
2804 band = BAND_TORTUROUS_DEMONSPAWN;
2805 band_size = random_range(1, 2);
2809 case MONS_BLOOD_SAINT:
2810 band = BAND_BLOOD_SAINT;
2811 band_size = 1 + random2(4);
2814 case MONS_CHAOS_CHAMPION:
2815 band = BAND_CHAOS_CHAMPION;
2816 band_size = 1 + random2(3);
2819 case MONS_WARMONGER:
2820 band = BAND_WARMONGER;
2821 band_size = 2 + random2(3);
2824 case MONS_CORRUPTER:
2825 band = BAND_CORRUPTER;
2826 band_size = 1 + random2(4);
2829 case MONS_BLACK_SUN:
2830 band = BAND_BLACK_SUN;
2831 band_size = 2 + random2(3);
2835 natural_leader = true;
2836 band = BAND_VASHNIA;
2837 band_size = 3 + random2(3);
2841 if ((branch_has_monsters(you.where_are_you)
2842 || !vault_mon_types.empty())
2845 band = BAND_RANDOM_SINGLE;
2850 case MONS_TORPOR_SNAIL:
2851 natural_leader = true; // snails are natural-born leaders. fact.
2853 // would be nice to support more branches, generically...
2854 switch (you.where_are_you)
2857 band = random_choose_weighted(5, BAND_YAKS,
2863 band = coinflip() ? BAND_REDBACK : BAND_RANDOM_SINGLE;
2866 band = BAND_RANDOM_SINGLE;
2875 band_size = 2 + random2(4); // 2-5
2877 case BAND_DEATH_YAKS:
2878 band_size = 1 + random2(2); // 1-2
2881 band_size = 5 + random2(4); // 5-8
2884 band_size = 2 + random2(3); // 2-4
2886 case BAND_RANDOM_SINGLE:
2897 if (band != BAND_NO_BAND && band_size == 0)
2898 band = BAND_NO_BAND;
2900 if (band_size >= BIG_BAND)
2901 band_size = BIG_BAND - 1;
2907 * Return the type of the nth monster in a band.
2909 * @param band The type of band
2910 * @param which The index of the monster (starting from 1)
2911 * @return The type of monster to create
2913 static monster_type _band_member(band_type band, int which)
2915 if (band == BAND_NO_BAND)
2916 return MONS_PROGRAM_BUG;
2924 if (one_chance_in(8)) // 12.50%
2925 return MONS_ORC_PRIEST;
2926 if (one_chance_in(6)) // 14.58%
2927 return MONS_ORC_WIZARD;
2930 case BAND_ORC_WARRIOR:
2931 if (one_chance_in(7)) // 14.29%
2932 return MONS_ORC_PRIEST;
2933 if (one_chance_in(5)) // 17.14%
2934 return MONS_ORC_WIZARD;
2937 case BAND_ORC_KNIGHT:
2938 case BAND_ORC_HIGH_PRIEST:
2939 // XXX: For Beogh punishment, ogres and trolls look out of place...
2940 // (For normal generation, they're okay, of course.)
2941 return random_choose_weighted(12, MONS_ORC,
2942 9, MONS_ORC_WARRIOR,
2948 1, MONS_ORC_SORCERER,
2951 case BAND_KILLER_BEES:
2952 return MONS_KILLER_BEE;
2954 case BAND_FLYING_SKULLS:
2955 return MONS_FLYING_SKULL;
2957 case BAND_SLIME_CREATURES:
2958 return MONS_SLIME_CREATURE;
2966 case BAND_UGLY_THINGS:
2967 return (env.absdepth0 > 21 && one_chance_in(4)) ?
2968 MONS_VERY_UGLY_THING : MONS_UGLY_THING;
2970 case BAND_HELL_HOUNDS:
2971 return MONS_HELL_HOUND;
2980 return MONS_CENTAUR;
2983 return MONS_YAKTAUR;
2985 case BAND_INSUBSTANTIAL_WISPS:
2986 return MONS_INSUBSTANTIAL_WISP;
2988 case BAND_POLYPHEMUS:
2990 return MONS_CATOBLEPAS;
2991 case BAND_DEATH_YAKS:
2992 return MONS_DEATH_YAK;
2994 case BAND_NECROMANCER:
2995 return random_choose_weighted(6, MONS_ZOMBIE,
3001 return coinflip() ? MONS_SUN_DEMON : MONS_RED_DEVIL;
3003 case BAND_CACODEMON:
3004 return coinflip() ? MONS_SIXFIRHY : MONS_ORANGE_DEMON;
3007 case BAND_EXECUTIONER:
3008 return MONS_ABOMINATION_LARGE;
3011 case BAND_PANDEMONIUM_LORD:
3012 if (one_chance_in(7))
3014 return random_choose_weighted(50, MONS_LICH,
3015 10, MONS_ANCIENT_LICH,
3018 else if (one_chance_in(6))
3020 return random_choose_weighted(50, MONS_ABOMINATION_SMALL,
3021 40, MONS_ABOMINATION_LARGE,
3022 10, MONS_TENTACLED_MONSTROSITY,
3027 return summon_any_demon(random_choose_weighted(
3028 50, RANDOM_DEMON_COMMON,
3029 20, RANDOM_DEMON_GREATER,
3036 return coinflip() ? MONS_HELLWING : MONS_SMOKE_DEMON;
3038 case BAND_DEEP_ELF_FIGHTER:
3039 return random_choose_weighted(3, MONS_DEEP_ELF_FIGHTER,
3040 3, MONS_DEEP_ELF_MAGE,
3041 2, MONS_DEEP_ELF_PRIEST,
3042 1, MONS_DEEP_ELF_CONJURER,
3045 case BAND_DEEP_ELF_KNIGHT:
3046 return random_choose_weighted(66, MONS_DEEP_ELF_FIGHTER,
3047 52, MONS_DEEP_ELF_MAGE,
3048 28, MONS_DEEP_ELF_KNIGHT,
3049 20, MONS_DEEP_ELF_CONJURER,
3050 16, MONS_DEEP_ELF_PRIEST,
3051 12, MONS_DEEP_ELF_SUMMONER,
3052 3, MONS_DEEP_ELF_DEATH_MAGE,
3053 2, MONS_DEEP_ELF_DEMONOLOGIST,
3054 2, MONS_DEEP_ELF_ANNIHILATOR,
3055 2, MONS_DEEP_ELF_SORCERER,
3058 case BAND_DEEP_ELF_HIGH_PRIEST:
3059 return random_choose_weighted(5, MONS_DEEP_ELF_FIGHTER,
3060 2, MONS_DEEP_ELF_PRIEST,
3061 2, MONS_DEEP_ELF_MAGE,
3062 1, MONS_DEEP_ELF_SUMMONER,
3063 1, MONS_DEEP_ELF_CONJURER,
3064 1, MONS_DEEP_ELF_DEMONOLOGIST,
3065 1, MONS_DEEP_ELF_ANNIHILATOR,
3066 1, MONS_DEEP_ELF_SORCERER,
3067 1, MONS_DEEP_ELF_DEATH_MAGE,
3070 case BAND_HELL_KNIGHTS:
3071 if (one_chance_in(4))
3072 return MONS_NECROMANCER;
3073 return MONS_HELL_KNIGHT;
3075 case BAND_OGRE_MAGE_EXTERN:
3077 return MONS_OGRE_MAGE;
3078 // Deliberate fallthrough
3079 case BAND_OGRE_MAGE:
3080 if (one_chance_in(3))
3081 return MONS_TWO_HEADED_OGRE;
3084 case BAND_KOBOLD_DEMONOLOGIST:
3085 return random_choose_weighted(8, MONS_KOBOLD,
3087 2, MONS_KOBOLD_DEMONOLOGIST,
3091 case BAND_GUARDIAN_SERPENT:
3092 // Favor tougher naga suited to melee, compared to normal naga bands
3093 if (which == 1 || which == 2 && coinflip())
3094 return one_chance_in(3) ? MONS_NAGA_MAGE : MONS_NAGA_WARRIOR;
3096 return one_chance_in(5) ? MONS_SALAMANDER : MONS_NAGA;
3099 if (which == 1 && coinflip() || which == 2 && one_chance_in(4))
3101 return random_choose_weighted( 8, MONS_NAGA_WARRIOR,
3103 6, MONS_NAGA_RITUALIST,
3104 8, MONS_NAGA_SHARPSHOOTER,
3105 6, MONS_SALAMANDER_MYSTIC,
3109 return one_chance_in(7) ? MONS_SALAMANDER : MONS_NAGA;
3111 case BAND_NAGA_RITUALIST:
3112 return random_choose_weighted(15, MONS_BLACK_MAMBA,
3114 5, MONS_WATER_MOCCASIN,
3118 case BAND_NAGA_SHARPSHOOTER:
3119 return one_chance_in(3) ? MONS_NAGA_SHARPSHOOTER : MONS_NAGA;
3123 case BAND_GREEN_RATS:
3124 return MONS_GREEN_RAT;
3125 case BAND_ORANGE_RATS:
3126 return MONS_ORANGE_RAT;
3130 return random_choose_weighted(4, MONS_GHOUL,
3134 case BAND_DEEP_TROLL_SHAMAN:
3135 if (one_chance_in(4))
3136 return MONS_IRON_TROLL;
3137 // intentional fallthrough
3138 case BAND_DEEP_TROLLS:
3139 if (one_chance_in(4))
3141 return random_choose(MONS_DEEP_TROLL_EARTH_MAGE,
3142 MONS_DEEP_TROLL_SHAMAN,
3145 return MONS_DEEP_TROLL;
3148 case BAND_HELL_HOGS:
3149 return MONS_HELL_HOG;
3150 case BAND_VAMPIRE_MOSQUITOES:
3151 return MONS_VAMPIRE_MOSQUITO;
3152 case BAND_FIRE_BATS:
3153 return MONS_FIRE_BAT;
3155 return MONS_BOGGART;
3156 case BAND_BLINK_FROGS:
3157 return MONS_BLINK_FROG;
3160 case BAND_SKELETAL_WARRIORS:
3161 return MONS_SKELETAL_WARRIOR;
3163 case BAND_DRACONIAN:
3164 if (env.absdepth0 >= 24 && x_chance_in_y(13, 40))
3166 // Hack: race is rolled elsewhere.
3167 return random_choose_weighted(
3168 1, MONS_DRACONIAN_CALLER,
3169 2, MONS_DRACONIAN_KNIGHT,
3170 2, MONS_DRACONIAN_MONK,
3171 2, MONS_DRACONIAN_SHIFTER,
3172 2, MONS_DRACONIAN_ANNIHILATOR,
3173 2, MONS_DRACONIAN_SCORCHER,
3174 2, MONS_DRACONIAN_ZEALOT,
3178 return random_draconian_monster_species();
3181 return random_choose_weighted(30, MONS_MERMAID,
3183 10, MONS_MERFOLK_JAVELINEER,
3184 10, MONS_MERFOLK_IMPALER,
3188 return coinflip() ? MONS_FIRE_ELEMENTAL : MONS_HELL_HOUND;
3193 case BAND_ALLIGATOR:
3194 return MONS_BABY_ALLIGATOR;
3197 return coinflip() ? MONS_GREATER_MUMMY : MONS_MUMMY;
3199 case BAND_GOLDEN_EYE:
3200 return MONS_GOLDEN_EYE;
3205 case BAND_MERFOLK_AQUAMANCER:
3206 return random_choose_weighted( 4, MONS_MERFOLK,
3207 11, MONS_WATER_ELEMENTAL,
3210 case BAND_MERFOLK_IMPALER:
3211 case BAND_MERFOLK_JAVELINEER:
3212 return MONS_MERFOLK;
3215 return MONS_ELEPHANT;
3218 return random_choose_weighted(30, MONS_REDBACK,
3220 5, MONS_JUMPING_SPIDER,
3226 case BAND_JUMPING_SPIDER:
3227 return random_choose_weighted(12, MONS_JUMPING_SPIDER,
3228 8, MONS_WOLF_SPIDER,
3232 2, MONS_DEMONIC_CRAWLER,
3235 case BAND_TARANTELLA:
3236 return random_choose_weighted(10, MONS_TARANTELLA,
3237 7, MONS_WOLF_SPIDER,
3241 2, MONS_DEMONIC_CRAWLER,
3244 case BAND_VAULT_WARDEN:
3245 if (which == 1 || which == 2 && coinflip())
3247 return random_choose_weighted( 8, MONS_VAULT_SENTINEL,
3248 12, MONS_IRONBRAND_CONVOKER,
3249 10, MONS_IRONHEART_PRESERVER,
3253 return MONS_VAULT_GUARD;
3255 case BAND_DEATH_KNIGHT:
3256 if (which == 1 && x_chance_in_y(2, 3))
3257 return one_chance_in(3) ? MONS_GHOUL : MONS_FLAYED_GHOST;
3259 return random_choose_weighted(5, MONS_WRAITH,
3260 6, MONS_FREEZING_WRAITH,
3261 3, MONS_PHANTASMAL_WARRIOR,
3262 3, MONS_SKELETAL_WARRIOR,
3266 return MONS_JIANGSHI;
3271 case BAND_FAUN_PARTY:
3273 return MONS_MERMAID;
3278 if (which == 1 && coinflip())
3279 return coinflip() ? MONS_TENGU_WARRIOR : MONS_TENGU_CONJURER;
3283 return MONS_TENGU_REAVER;
3285 case BAND_ENCHANTRESS:
3287 return MONS_SPRIGGAN_DEFENDER;
3288 else if (which <= 4)
3289 return MONS_SPRIGGAN_AIR_MAGE;
3292 return random_choose(MONS_SPRIGGAN_AIR_MAGE,
3293 MONS_SPRIGGAN_BERSERKER,
3294 MONS_SPRIGGAN_RIDER,
3297 return MONS_SPRIGGAN;
3298 case BAND_SPRIGGAN_ELITES:
3299 if (which == 1 && coinflip())
3300 return MONS_SPRIGGAN_DEFENDER;
3301 case BAND_SPRIGGANS:
3302 return random_choose_weighted( 4, MONS_SPRIGGAN_AIR_MAGE,
3303 3, MONS_SPRIGGAN_BERSERKER,
3304 11, MONS_SPRIGGAN_RIDER,
3307 case BAND_AIR_ELEMENTALS:
3308 return MONS_AIR_ELEMENTAL;
3310 case BAND_SPRIGGAN_DRUID:
3311 return one_chance_in(3) ? MONS_SPRIGGAN_RIDER : MONS_SPRIGGAN;
3313 case BAND_SPRIGGAN_RIDERS:
3314 return MONS_SPRIGGAN_RIDER;
3316 case BAND_PHANTASMAL_WARRIORS:
3317 return MONS_PHANTASMAL_WARRIOR;
3319 case BAND_THRASHING_HORRORS:
3320 return MONS_THRASHING_HORROR;
3328 case BAND_SALAMANDERS:
3329 return MONS_SALAMANDER;
3331 case BAND_SALAMANDER_ELITES:
3332 if (which == 1 && coinflip())
3333 return MONS_SALAMANDER_MYSTIC;
3335 return MONS_SALAMANDER;
3337 case BAND_MONSTROUS_DEMONSPAWN:
3338 if (which == 1 || one_chance_in(5))
3340 return random_choose_weighted( 2, MONS_DEMONIC_CRAWLER,
3342 3, MONS_MONSTROUS_DEMONSPAWN,
3345 return random_demonspawn_monster_species();
3347 case BAND_GELID_DEMONSPAWN:
3348 if (which == 1 || one_chance_in(5))
3350 return random_choose_weighted( 2, MONS_BLUE_DEVIL,
3352 3, MONS_GELID_DEMONSPAWN,
3355 return random_demonspawn_monster_species();
3357 case BAND_INFERNAL_DEMONSPAWN:
3358 if (which == 1 || one_chance_in(5))
3360 return random_choose_weighted( 2, MONS_RED_DEVIL,
3362 3, MONS_INFERNAL_DEMONSPAWN,
3365 return random_demonspawn_monster_species();
3367 case BAND_PUTRID_DEMONSPAWN:
3368 if (which == 1 || one_chance_in(5))
3370 return random_choose_weighted( 2, MONS_HELLWING,
3371 2, MONS_ORANGE_DEMON,
3372 3, MONS_PUTRID_DEMONSPAWN,
3375 return random_demonspawn_monster_species();
3377 case BAND_TORTUROUS_DEMONSPAWN:
3378 if (which == 1 || one_chance_in(5))
3380 return random_choose_weighted( 2, MONS_ORANGE_DEMON,
3382 3, MONS_TORTUROUS_DEMONSPAWN,
3385 return random_demonspawn_monster_species();
3387 case BAND_BLOOD_SAINT:
3388 if (which == 1 || which == 2 && one_chance_in(5))
3390 if (x_chance_in_y(3, 5))
3391 return coinflip() ? MONS_BALRUG : MONS_BLIZZARD_DEMON;
3393 return static_cast<monster_type>(
3394 random_range(MONS_FIRST_NONBASE_DEMONSPAWN,
3395 MONS_LAST_NONBASE_DEMONSPAWN));
3397 return random_demonspawn_monster_species();
3399 case BAND_CHAOS_CHAMPION:
3400 if (which == 1 || which == 2 && one_chance_in(6))
3402 if (x_chance_in_y(2, 5))
3403 return one_chance_in(3) ? MONS_TORMENTOR : MONS_HELL_BEAST;
3406 return static_cast<monster_type>(
3407 random_range(MONS_FIRST_NONBASE_DEMONSPAWN,
3408 MONS_LAST_NONBASE_DEMONSPAWN));
3411 return random_demonspawn_monster_species();
3413 case BAND_WARMONGER:
3414 if (which == 1 || which == 2 && one_chance_in(5))
3416 if (x_chance_in_y(3, 5))
3417 return one_chance_in(4) ? MONS_EXECUTIONER : MONS_REAPER;
3420 return static_cast<monster_type>(
3421 random_range(MONS_FIRST_NONBASE_DEMONSPAWN,
3422 MONS_LAST_NONBASE_DEMONSPAWN));
3425 return random_demonspawn_monster_species();
3427 case BAND_CORRUPTER:
3428 if (which == 1 || which == 2 && one_chance_in(5))
3430 if (x_chance_in_y(3, 5))
3431 return one_chance_in(4) ? MONS_CACODEMON : MONS_SHADOW_DEMON;
3434 return static_cast<monster_type>(
3435 random_range(MONS_FIRST_NONBASE_DEMONSPAWN,
3436 MONS_LAST_NONBASE_DEMONSPAWN));
3439 return random_demonspawn_monster_species();
3441 case BAND_BLACK_SUN:
3442 if (which == 1 || which == 2 && one_chance_in(5))