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
|
/**
* @file
* @brief Misc monster poly/mimic functions.
**/
#include "AppHdr.h"
#include "mon-poly.h"
#include "areas.h"
#include "artefact.h"
#include "art-enum.h"
#include "attitude-change.h"
#include "colour.h"
#include "delay.h"
#include "describe.h"
#include "dgn-overview.h"
#include "dungeon.h"
#include "fineff.h"
#include "god-conduct.h"
#include "god-passive.h"
#include "god-wrath.h"
#include "hints.h"
#include "item-prop.h"
#include "item-status-flag-type.h"
#include "items.h"
#include "level-state-type.h"
#include "libutil.h"
#include "message.h"
#include "mon-act.h"
#include "mon-death.h"
#include "mon-gear.h"
#include "mon-place.h"
#include "mon-tentacle.h"
#include "mutation.h"
#include "notes.h"
#include "output.h"
#include "player-notices.h"
#include "religion.h"
#include "spl-transloc.h"
#include "shout.h"
#include "state.h"
#include "stringutil.h"
#include "terrain.h"
#include "transform.h"
#include "traps.h"
#include "view.h"
#include "xom.h"
#define ORIG_HD_KEY "orig_hd"
bool base_feature_is_mimic_at(coord_def c)
{
return map_masked(c, MMT_MIMIC);
}
bool current_feature_is_mimic_at(coord_def c)
{
return base_feature_is_mimic_at(c) && !is_temp_terrain(c);
}
item_def* item_mimic_at(const coord_def &c)
{
for (stack_iterator si(c); si; ++si)
if (si->flags & ISFLAG_MIMIC)
return &*si;
return nullptr;
}
bool mimic_at(const coord_def &c)
{
return current_feature_is_mimic_at(c) || item_mimic_at(c);
}
void monster_drop_things(monster* mons,
bool mark_item_origins,
bool (*suitable)(const item_def& item))
{
// Drop weapons and missiles last (i.e., on top), so others pick up.
for (int i = NUM_MONSTER_SLOTS - 1; i >= 0; --i)
{
int item = mons->inv[i];
if (item == NON_ITEM || !suitable(env.item[item]))
continue;
mons->do_unequip_effects(env.item[item], false, true);
int old_halo = mons->halo_radius();
int old_umbra = mons->umbra_radius();
if (testbits(env.item[item].flags, ISFLAG_SUMMONED))
{
item_was_destroyed(env.item[item]);
destroy_item(item);
}
else
{
if (mark_item_origins && env.item[item].defined())
origin_set_monster(env.item[item], mons);
env.item[item].props[DROPPER_MID_KEY].get_int() = mons->mid;
if (env.item[item].props.exists("autoinscribe"))
{
add_inscription(env.item[item],
env.item[item].props["autoinscribe"].get_string());
env.item[item].props.erase("autoinscribe");
}
// If a monster is swimming, the items are ALREADY underwater.
if (move_item_to_grid(&item, mons->pos(), mons->swimming())
&& player_under_penance(GOD_GOZAG)
// Dropping items into water/lava may have destroyed them
&& item != NON_ITEM
&& env.item[item].base_type == OBJ_GOLD
&& you.see_cell(mons->pos())
&& x_chance_in_y(env.item[item].quantity, 100))
{
string msg = make_stringf("%s dazzles you with the glint of coin.",
god_name(GOD_GOZAG).c_str());
mprf(MSGCH_GOD, GOD_GOZAG, "%s", msg.c_str());
blind_player(10 + random2(8), ETC_GOLD);
}
mons->inv[i] = NON_ITEM;
}
int new_halo = mons->halo_radius();
int new_umbra = mons->umbra_radius();
if (old_halo != new_halo || old_umbra != new_umbra)
invalidate_agrid(true);
}
// If the monster died in a wall, try to push the items out of it.
if (cell_is_solid(mons->pos()))
dgn_check_terrain_items(mons->pos(), true, you.see_cell(mons->pos()));
}
static bool _valid_type_morph(const monster &mons, monster_type new_mclass)
{
// Shapeshifters cannot polymorph into glowing shapeshifters or
// vice versa.
if ((new_mclass == MONS_GLOWING_SHAPESHIFTER
&& mons.has_ench(ENCH_SHAPESHIFTER))
|| (new_mclass == MONS_SHAPESHIFTER
&& mons.has_ench(ENCH_GLOWING_SHAPESHIFTER)))
{
return false;
}
// Various inappropriate polymorph targets.
if ( new_mclass == MONS_PROGRAM_BUG
|| new_mclass == MONS_NO_MONSTER
|| mons_class_flag(new_mclass, M_UNFINISHED) // no unfinished monsters
|| mons_class_flag(new_mclass, M_CANT_SPAWN) // no dummy monsters
|| mons_class_flag(new_mclass, M_NO_POLY_TO) // explicitly disallowed
|| mons_class_flag(new_mclass, M_UNIQUE) // no uniques
|| !mons_class_gives_xp(new_mclass) // no tentacle parts or
// harmless things
|| !(mons_class_holiness(new_mclass) & mons_class_holiness(mons.type))
// normally holiness just needs to overlap, but we don't want
// shapeshifters to become demons
|| mons.is_shapeshifter() && !(mons_class_holiness(new_mclass) & MH_NATURAL)
|| !mons_class_is_threatening(new_mclass)
// 'morph targets are _always_ "base" classes, not derived ones.
|| new_mclass != mons_species(new_mclass)
|| new_mclass == mons_species(mons.type)
// They act as separate polymorph classes on their own.
|| mons_class_is_zombified(new_mclass)
// Pan lords aren't uniques, but they might as well be.
|| new_mclass == MONS_PANDEMONIUM_LORD
// Other poly-unsuitable things.
|| mons_is_statue(new_mclass)
|| mons_is_projectile(new_mclass)
// The spell on Prince Ribbit can't be broken so easily.
|| (new_mclass == MONS_HUMAN
&& (mons.type == MONS_PRINCE_RIBBIT
|| mons.mname == "Prince Ribbit")))
{
return false;
}
return true;
}
static bool _valid_morph(monster* mons, monster_type new_mclass)
{
if (!_valid_type_morph(*mons, new_mclass))
return false;
// [hm] Lower base draconian chances since there are nine of them,
// and they shouldn't each count for a full chance.
if (mons_genus(new_mclass) == MONS_DRACONIAN
&& new_mclass != MONS_DRACONIAN
&& !one_chance_in(9))
{
return false;
}
// Determine if the monster is happy on current tile.
return monster_habitable_grid(new_mclass, mons->pos());
}
static bool _jiyva_slime_target(monster_type targetc)
{
return you_worship(GOD_JIYVA)
&& (targetc == MONS_ENDOPLASM
|| targetc == MONS_JELLY
|| targetc == MONS_SLIME_CREATURE
|| targetc == MONS_ACID_BLOB
|| targetc == MONS_AZURE_JELLY);
}
void change_monster_type(monster* mons, monster_type targetc, bool do_seen)
{
ASSERT(mons); // XXX: change to monster &mons
bool could_see = you.can_see(*mons);
// NOTE(pf): This logic is wrong! FIXME!
bool slimified = _jiyva_slime_target(targetc);
// Quietly remove the old monster's invisibility before transforming
// it. If we don't do this, it'll stay invisible even after losing
// the invisibility enchantment below.
mons->del_ench(ENCH_INVIS, false, false);
// Remove replacement tile, since it probably doesn't work for the
// new monster.
mons->props.erase(MONSTER_TILE_NAME_KEY);
mons->props.erase(MONSTER_TILE_KEY);
// Even if the monster transforms from one type that can behold the
// player into a different type which can also behold the player,
// the polymorph disrupts the beholding process. Do this before
// changing mons->type, since unbeholding can only happen while
// the monster is still a siren/merfolk avatar.
you.remove_beholder(*mons);
you.remove_fearmonger(mons);
if (mons_is_tentacle_head(mons_base_type(*mons)))
destroy_tentacles(mons);
// trj spills out jellies when polied, as if he'd been hit for mhp.
if (mons->type == MONS_ROYAL_JELLY)
{
simple_monster_message(*mons, " form twists and warps, and jellies "
"spill out!", true);
schedule_trj_spawn_fineff(nullptr, mons, mons->pos(),
mons->hit_points);
}
// Inform listeners that the original monster is gone.
fire_monster_death_event(mons, KILL_NON_ACTOR, true);
// the actual polymorphing:
auto flags =
mons->flags & ~(MF_SEEN | MF_ATT_CHANGE_ATTEMPT
| MF_WAS_IN_VIEW | MF_BAND_FOLLOWER | MF_KNOWN_SHIFTER
| MF_MELEE_MASK);
flags |= MF_POLYMORPHED;
string name;
// Preserve the names of uniques and named monsters.
if (mons_is_mons_class(mons, MONS_ROYAL_JELLY))
{
name = "shaped Royal Jelly";
flags |= MF_NAME_SUFFIX;
}
else if (mons_is_mons_class(mons, MONS_LERNAEAN_HYDRA))
{
name = "shaped Lernaean hydra";
flags |= MF_NAME_SUFFIX;
}
else if (mons_is_mons_class(mons, MONS_ENCHANTRESS))
{
name = "shaped Enchantress";
flags |= MF_NAME_SUFFIX;
}
else if (mons_is_mons_species(mons, MONS_SERPENT_OF_HELL))
{
name = "shaped Serpent of Hell";
flags |= MF_NAME_SUFFIX;
}
else if (!mons->mname.empty())
{
if (flags & MF_NAME_MASK)
// Remove the replacement name from the new monster
flags &= ~MF_ALL_NAMES;
else
name = mons->mname;
}
else if (mons_is_unique(mons->type))
{
name = mons->name(DESC_PLAIN, true);
// "Blorkula the orcula" and similar.
const size_t the_pos = name.find(" the ");
if (the_pos != string::npos)
name = name.substr(0, the_pos);
}
const god_type old_god = mons->god;
const int old_hp = mons->hit_points;
const int old_hp_max = mons->max_hit_points;
const char old_ench_countdown = mons->ench_countdown;
const caught_type old_caught = mons->caught_by();
mon_enchant held = mons->get_ench(ENCH_HELD);
const bool old_mon_unique = mons_is_or_was_unique(*mons);
if (!mons->props.exists(ORIGINAL_TYPE_KEY))
{
const monster_type type = mons_is_draconian_job(mons->type)
? draconian_subspecies(*mons)
: mons->type;
mons->props[ORIGINAL_TYPE_KEY].get_int() = type;
if (mons->has_hydra_multi_attack())
mons->props[OLD_HEADS_KEY].get_int() = mons->num_heads;
}
if (!mons->props.exists(ORIG_HD_KEY))
mons->props[ORIG_HD_KEY] = mons->get_experience_level();
mon_enchant timer = mons->get_ench(ENCH_SUMMON_TIMER);
mon_enchant charm = mons->get_ench(ENCH_CHARM);
mon_enchant shifter = mons->get_ench(ENCH_GLOWING_SHAPESHIFTER,
ENCH_SHAPESHIFTER);
mon_enchant summon = mons->get_ench(ENCH_SUMMON);
mon_enchant tp = mons->get_ench(ENCH_TP);
mon_enchant forest = mons->get_ench(ENCH_AWAKEN_FOREST);
mon_enchant hexed = mons->get_ench(ENCH_HEXED);
mon_enchant insanity = mons->get_ench(ENCH_FRENZIED);
mon_enchant vengeance = mons->get_ench(ENCH_VENGEANCE_TARGET);
mon_enchant tempered = mons->get_ench(ENCH_TEMPERED);
mon_enchant thrall = mons->get_ench(ENCH_VAMPIRE_THRALL);
mons->number = 0;
// Note: define_monster(*) will clear out all enchantments! - bwr
if (!slimified && mons_is_zombified(*mons))
define_zombie(mons, targetc, mons->type);
else
{
mons->type = targetc;
mons->base_monster = MONS_NO_MONSTER;
define_monster(*mons);
}
mons->mname = name;
mons->props[NO_ANNOTATE_KEY] = slimified && old_mon_unique;
mons->props.erase(DBNAME_KEY);
// Forget seen spells, since they are likely to have changed.
mons->props.erase(SEEN_SPELLS_KEY);
mons->flags = flags;
// Line above might clear melee flags; restore.
mons->bind_melee_flags();
// Forget various speech/shout Lua functions.
mons->props.erase(SPEECH_PREFIX_KEY);
// Make sure we have a god if we've been polymorphed into a priest.
mons->god = (mons->is_priest() && old_god == GOD_NO_GOD) ? GOD_NAMELESS
: old_god;
mons->add_ench(timer);
mons->add_ench(charm);
mons->add_ench(shifter);
mons->add_ench(summon);
mons->add_ench(tp);
mons->add_ench(forest);
mons->add_ench(hexed);
mons->add_ench(insanity);
mons->add_ench(vengeance);
mons->add_ench(tempered);
mons->add_ench(thrall);
mons->ench_countdown = old_ench_countdown;
if (mons_class_flag(mons->type, M_INVIS))
mons->add_ench(ENCH_INVIS);
if (mons_class_flag(mons->type, M_WARDED))
mons->add_ench(mon_enchant(ENCH_WARDING, mons, INFINITE_DURATION));
mons->hit_points = mons->max_hit_points * old_hp / old_hp_max;
// Slimifying monsters gets you a fresh, delicious jiggly buddy.
if (slimified)
mons->hit_points = mons->max_hit_points;
// Shapeshifters heal when they shift. Wow, why can't players do that?
else if (shifter.ench != ENCH_NONE)
mons->hit_points += random2(mons->max_hit_points);
mons->hit_points = min(mons->max_hit_points, mons->hit_points);
// Don't kill it.
mons->hit_points = max(mons->hit_points, 1);
mons->speed_increment = 67 + random2(6);
monster_drop_things(mons);
// If new monster is visible to player, then we've seen it.
if (you.can_see(*mons))
{
// If the player saw both the beginning and end results of a
// shifter changing, then s/he knows it must be a shifter.
if (could_see && shifter.ench != ENCH_NONE)
discover_shifter(*mons);
if (do_seen)
seen_monster(mons);
}
// generate a new polymorph set
mons->props.erase(POLY_SET_KEY);
init_poly_set(mons);
// Try to keep the monster caught in any existing nets, but if the new form
// is net immune, remember to drop the net on the ground.
if (old_caught >= CAUGHT_NET)
{
if (mons->trap_in_net(old_caught == CAUGHT_NET, true))
mons->update_ench(held); // Preserve damage to the net.
else if (old_caught == CAUGHT_NET)
drop_net_at(mons->pos());
}
// Even if the new form can constrict, it might be with a different
// body part. Likewise, the new form might be too large for its
// current constrictor. Rather than trying to handle these as special
// cases, just stop the constriction entirely. The usual message about
// evaporating and reforming justifies this behaviour.
mons->stop_constricting_all();
mons->stop_being_constricted();
}
// Is the new monster able to live in *any* habitat that the original
// monster could?
// NOTE: this doesn't check for item-based flight, so if we
// poly an item-using flying monster into a non-item-using,
// non-flying monster, they could be in trouble. Not much way
// around this and it's a very very niche case.
// Also assumes the monster is not a derived (zombie etc) monster.
static bool _habitat_matches(bool orig_flies, habitat_type orig_hab,
monster_type new_type)
{
if (monster_class_flies(new_type))
return true;
if (orig_flies)
return false;
const habitat_type new_hab = mons_habitat_type(new_type, new_type, false);
return (new_hab & orig_hab) == orig_hab;
}
static int _goal_hd(int orig_hd, poly_power_type ppt)
{
switch (ppt)
{
case PPT_LESS:
return max(orig_hd - 3, 1);
case PPT_MORE:
return min(orig_hd + 2, 27);
case PPT_SAME:
default:
return orig_hd;
}
}
static int _poly_weight(int orig_hd, int orig_tier, monster_type new_species,
poly_power_type ppt)
{
const int new_tier = mons_demon_tier(new_species);
const int new_hd = mons_power(new_species);
const int goal_hd = _goal_hd(orig_hd, ppt);
int hd_delta = abs(goal_hd - new_hd);
if (ppt != PPT_MORE && new_hd > goal_hd)
hd_delta *= 2; // make upgrades less likely
const int tier_delta = abs(orig_tier - new_tier);
const int total_delta = hd_delta + tier_delta;
const int max_delta = 8;
if (total_delta > max_delta)
return 0;
// halve weight for each HD of difference and each demon tier level apart
return 1 << (max_delta - total_delta);
}
static void _fill_poly_weights(const monster &mons, poly_power_type ppt,
bool hab_match,
map<monster_type, int> &weights)
{
const int orig_tier = mons_demon_tier(mons.type);
if (orig_tier == -1)
{
// panlords & hell lords get poly immunity. why? unclear to me
// TODO: allow polying panlords into other random panlords, ha
return;
}
const int orig_hd = mons.props.exists(ORIG_HD_KEY) ?
mons.props[ORIG_HD_KEY].get_int() :
mons.get_experience_level();
const bool orig_flies = monster_inherently_flies(mons);
const habitat_type orig_hab
= mons_habitat_type(mons.type, mons_base_type(mons), false);
for (monster_type mt = MONS_0; mt < NUM_MONSTERS; ++mt)
{
if (invalid_monster_type(mt))
continue; // no polying into bugs
const monster_type species = mons_species(mt);
if (weights.find(species) != weights.end())
continue; // already saw this one
if (!_valid_type_morph(mons, species))
continue; // no polying into statues, same species, etc
if (hab_match && !_habitat_matches(orig_flies, orig_hab, species))
continue;
const int weight = _poly_weight(orig_hd, orig_tier, species, ppt);
if (weight > 0)
weights[species] = weight;
}
}
void init_poly_set(monster *mons)
{
rng::subgenerator poly_rng;
if (mons->props.exists(POLY_SET_KEY))
return;
const int orig_tier = mons_demon_tier(mons->type);
if (orig_tier == -1)
{
// panlords & hell lords get poly immunity. why? unclear to me
// TODO: allow polying panlords into other random panlords, ha
return;
}
map<monster_type, int> weights;
_fill_poly_weights(*mons, PPT_SAME, true, weights);
CrawlVector &set = mons->props[POLY_SET_KEY];
for (int i = 0; i < 3; i++)
{
if (weights.empty())
return; // can't choose any more
const monster_type *chosen = random_choose_weighted<map<monster_type,int>>(weights);
ASSERT(chosen);
set.push_back(*chosen);
weights.erase(*chosen);
}
}
static monster_type _poly_from_set(monster &mons)
{
if (!mons.props.exists(POLY_SET_KEY))
return MONS_NO_MONSTER;
const CrawlVector &set = mons.props[POLY_SET_KEY];
if (set.size() <= 0)
return MONS_NO_MONSTER;
return (monster_type)set[random2(set.size())].get_int();
}
static monster_type _concretize_target(monster &mons, monster_type target,
poly_power_type ppt)
{
switch (target)
{
case RANDOM_POLYMORPH_MONSTER:
return _poly_from_set(mons);
case RANDOM_MONSTER:
{
map<monster_type, int> weights;
_fill_poly_weights(mons, ppt, false, weights);
if (weights.empty())
return MONS_NO_MONSTER;
const monster_type *chosen = random_choose_weighted<map<monster_type,int>>(weights);
ASSERT(chosen);
return *chosen;
}
default:
return target;
}
}
// If targetc == RANDOM_MONSTER, then relpower indicates the desired
// power of the new monster, relative to the current monster.
// Relaxation still takes effect when needed, no matter what relpower
// says.
bool monster_polymorph(monster* mons, monster_type targetc,
poly_power_type power)
{
// Don't attempt to polymorph a monster that is busy using the stairs.
if (mons->flags & MF_TAKING_STAIRS)
return false;
ASSERT(!(mons->flags & MF_BANISHED) || player_in_branch(BRANCH_ABYSS));
// There's not a single valid target on the '&' demon tier, so unless we
// make one, let's ban this outright.
if (mons_demon_tier(mons->type) == -1)
{
return simple_monster_message(*mons,
" appearance momentarily alters.", true);
}
targetc = _concretize_target(*mons, targetc, power);
if (targetc == MONS_NO_MONSTER)
return simple_monster_message(*mons, " shudders.");
const bool was_invisible = mons->has_ench(ENCH_INVIS) && !mons->friendly();
bool could_see = you.can_see(*mons);
bool need_note = could_see && mons_is_notable(*mons);
string old_name_a = mons->full_name(DESC_A);
string old_name_the = mons->full_name(DESC_THE);
monster_type oldc = mons->type;
if (power != PPT_SLIME && !_valid_morph(mons, targetc))
return simple_monster_message(*mons, " looks momentarily different.");
change_monster_type(mons, targetc, false);
bool can_see = you.can_see(*mons);
// Messaging
bool player_messaged = true;
if (could_see)
{
string verb = "";
string obj = can_see ? mons_type_name(targetc, DESC_A)
: "something you cannot see";
if (oldc == MONS_OGRE && targetc == MONS_TWO_HEADED_OGRE)
{
verb = "grows a second head";
obj = "";
}
else if (mons->is_shapeshifter())
verb = "changes into ";
else if (_jiyva_slime_target(targetc))
verb = "quivers uncontrollably and liquefies into ";
else
verb = "evaporates and reforms as ";
mprf("%s %s%s!", old_name_the.c_str(), verb.c_str(), obj.c_str());
}
else if (can_see)
mprf("%s appears out of thin air!", mons->name(DESC_A).c_str());
else
player_messaged = false;
if (need_note || could_see && can_see && mons_is_notable(*mons))
{
string new_name = can_see ? mons->full_name(DESC_A)
: "something unseen";
take_note(Note(NOTE_POLY_MONSTER, 0, 0, old_name_a, new_name));
}
const bool is_invisible = mons->has_ench(ENCH_INVIS) && !mons->friendly();
if (you.see_cell(mons->pos()))
{
if (was_invisible && !is_invisible)
{
// If we poly an invisible monster reactivate autopickup.
// We need to check for actual invisibility rather than
// whether we can see the monster. There are several edge
// cases where a monster is visible to the player but we
// still need to turn autopickup back on, such as
// TSO's halo or sticky flame.
autotoggle_autopickup(false);
}
else if (could_see && !can_see)
autotoggle_autopickup(true);
}
// do this here, so that any "changes into" notes come first
if (can_see)
seen_monster(mons);
// Xom likes watching monsters being polymorphed.
if (can_see)
{
xom_is_stimulated(mons->is_shapeshifter() ? 12 :
power == PPT_LESS || mons->friendly() ? 25 :
power == PPT_SAME ? 50
: 100);
}
return player_messaged;
}
bool mon_can_be_slimified(const monster* mons)
{
const mon_holy_type holi = mons->holiness();
return !mons->is_insubstantial()
&& !mons_is_tentacle_or_tentacle_segment(mons->type)
&& (holi & (MH_UNDEAD | MH_NATURAL) && !mons_is_slime(*mons));
}
static monster_type _slime_target(const monster &mon)
{
// Easter egg!
if (mons_genus(mon.type) == MONS_HYDRA)
return MONS_SLYMDRA;
const int hd = mon.get_hit_dice();
const int target = random_range(hd - 4, hd + 4);
if (!feat_has_solid_floor(env.grid(mon.pos())))
{
// Don't drown.
return target < 7 ? MONS_JELLY
: target < 12 ? MONS_SLIME_CREATURE
: MONS_ROCKSLIME;
}
if (target < 3)
return MONS_ENDOPLASM;
if (target < 5)
return MONS_JELLY;
if (target < 12)
return MONS_SLIME_CREATURE;
else
return royal_jelly_ejectable_monster();
}
void slimify_monster(monster* mon)
{
const monster_type target = _slime_target(*mon);
// Bail out if jellies can't live here.
if (!monster_habitable_grid(target, mon->pos()))
{
simple_monster_message(*mon, " quivers momentarily.");
return;
}
record_monster_defeat(mon, KILL_SLIMIFIED);
remove_unique_annotation(mon);
monster_polymorph(mon, target, PPT_SLIME);
// If a monster slimifies and you're not with Jiyva, it shouldn't change
// that monster's attitude any more than other polymorph does. If you are
// with Jiyva, either let it stay friendly or make it non-hostile.
if (you_worship(GOD_JIYVA) && mon->attitude != ATT_FRIENDLY)
mon->attitude = ATT_GOOD_NEUTRAL;
mons_make_god_gift(*mon, GOD_JIYVA);
// Don't want shape-shifters to shift into non-slimes.
mon->del_ench(ENCH_GLOWING_SHAPESHIFTER);
mon->del_ench(ENCH_SHAPESHIFTER);
mons_att_changed(mon);
if (mons_is_elven_twin(mon))
elven_twin_died(mon, false, KILL_YOU, MID_PLAYER);
}
|