summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source
diff options
context:
space:
mode:
authordolorous <dolorous@c06c8d41-db1a-0410-9941-cceddc491573>2008-03-21 02:22:03 +0000
committerdolorous <dolorous@c06c8d41-db1a-0410-9941-cceddc491573>2008-03-21 02:22:03 +0000
commit0c496e0be392bbf839533c9d69da1499b883b3ac (patch)
tree113f5b56928b11cbd7049535cdbb815d49f6d6d4 /crawl-ref/source
parentd07a34ba115b47a74496b1810c5ede4b0e86c748 (diff)
downloadcrawl-ref-0c496e0be392bbf839533c9d69da1499b883b3ac.tar.gz
crawl-ref-0c496e0be392bbf839533c9d69da1499b883b3ac.zip
Revert the splitting out of monster_change_type() from
monster_polymorph(), as it still doesn't do everything needed. Replace it with monsters::change_type(), split out from monsters::level_up_change(), which does do everything needed, and in a cleaner way. Unfortunately, it's still a hack, but it should be easier to deal with for now. Sorry for the mess. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@3783 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source')
-rw-r--r--crawl-ref/source/externs.h5
-rw-r--r--crawl-ref/source/mgrow.cc57
-rw-r--r--crawl-ref/source/monstuff.cc100
-rw-r--r--crawl-ref/source/monstuff.h2
-rw-r--r--crawl-ref/source/religion.cc6
5 files changed, 76 insertions, 94 deletions
diff --git a/crawl-ref/source/externs.h b/crawl-ref/source/externs.h
index a6c10bb785..a24a2f4b5c 100644
--- a/crawl-ref/source/externs.h
+++ b/crawl-ref/source/externs.h
@@ -1210,13 +1210,14 @@ public:
actor_type atype() const { return ACT_MONSTER; }
- // Hack, with a capital H.
+ // Hacks, with a capital H.
void fix_speed();
void check_speed();
+ void change_type(monster_type after, bool adjust_hp);
std::string describe_enchantments() const;
- int action_energy(energy_use_type et) const;
+ int action_energy(energy_use_type et) const;
static int base_speed(int mcls);
bool do_shaft();
diff --git a/crawl-ref/source/mgrow.cc b/crawl-ref/source/mgrow.cc
index 520aa1117b..679f2643aa 100644
--- a/crawl-ref/source/mgrow.cc
+++ b/crawl-ref/source/mgrow.cc
@@ -95,39 +95,44 @@ static const monster_level_up *monster_level_up_target(
return (NULL);
}
-bool monsters::level_up_change()
+void monsters::change_type(monster_type after, bool adjust_hp)
{
- if (const monster_level_up *lup =
- monster_level_up_target(static_cast<monster_type>(type), hit_dice))
- {
- const monsterentry *orig = get_monster_data(type);
- // Ta-da!
- type = lup->after;
+ const monsterentry *orig = get_monster_data(type);
+ // Ta-da!
+ type = after;
- // Initialise a dummy monster to save work.
- monsters dummy;
- dummy.type = type;
- define_monster(dummy);
+ // Initialise a dummy monster to save work.
+ monsters dummy;
+ dummy.type = after;
+ define_monster(dummy);
- colour = dummy.colour;
- speed = dummy.speed;
- spells = dummy.spells;
- fix_speed();
+ colour = dummy.colour;
+ speed = dummy.speed;
+ spells = dummy.spells;
+ fix_speed();
- const monsterentry *m = get_monster_data(type);
- ac += m->AC - orig->AC;
- ev += m->ev - orig->ev;
+ const monsterentry *m = get_monster_data(after);
+ ac += m->AC - orig->AC;
+ ev += m->ev - orig->ev;
- if (lup->adjust_hp)
+ if (adjust_hp)
+ {
+ const int minhp = dummy.max_hit_points;
+ if (max_hit_points < minhp)
{
- const int minhp = dummy.max_hit_points;
- if (max_hit_points < minhp)
- {
- hit_points += minhp - max_hit_points;
- max_hit_points = minhp;
- hit_points = std::min(hit_points, max_hit_points);
- }
+ hit_points += minhp - max_hit_points;
+ max_hit_points = minhp;
+ hit_points = std::min(hit_points, max_hit_points);
}
+ }
+}
+
+bool monsters::level_up_change()
+{
+ if (const monster_level_up *lup =
+ monster_level_up_target(static_cast<monster_type>(type), hit_dice))
+ {
+ change_type(lup->after, lup->adjust_hp);
return (true);
}
return (false);
diff --git a/crawl-ref/source/monstuff.cc b/crawl-ref/source/monstuff.cc
index 8321035178..b293160a48 100644
--- a/crawl-ref/source/monstuff.cc
+++ b/crawl-ref/source/monstuff.cc
@@ -1305,49 +1305,6 @@ static bool is_poly_power_unsuitable(
}
}
-// Change one monster type into another. This preserves as much as
-// possible between types, so, if the two types are radically different,
-// some special handling may be needed after calling this.
-void monster_change_type(monsters *monster, monster_type targetc)
-{
- const unsigned long old_flags = monster->flags;
- const unsigned long old_exp = monster->experience;
- const int old_hp = monster->hit_points;
- const int old_hp_max = monster->max_hit_points;
- const char old_ench_countdown = monster->ench_countdown;
- const bool old_mon_caught = mons_is_caught(monster);
-
- /* deal with mons_sec */
- monster->type = targetc;
- monster->number = MONS_PROGRAM_BUG;
-
- mon_enchant abj = monster->get_ench(ENCH_ABJ);
- mon_enchant shifter = monster->get_ench(ENCH_GLOWING_SHAPESHIFTER,
- ENCH_SHAPESHIFTER);
-
- // Note: define_monster() will clear out all enchantments! -- bwr
- define_monster( monster_index(monster) );
-
- monster->flags = old_flags;
- monster->gain_exp(old_exp);
-
- monster->add_ench(abj);
- monster->add_ench(shifter);
-
- monster->ench_countdown = old_ench_countdown;
-
- if (mons_class_flag( monster->type, M_INVIS ))
- monster->add_ench(ENCH_INVIS);
-
- monster->hit_points = monster->max_hit_points
- * ((old_hp * 100) / old_hp_max) / 100;
-
- monster->fix_speed();
-
- if (old_mon_caught)
- monster->add_ench(ENCH_HELD);
-}
-
/*
* if targetc == RANDOM_MONSTER then relpower indicates the desired
* power of the new monster relative to the current monster.
@@ -1428,7 +1385,6 @@ bool monster_polymorph( monsters *monster, monster_type targetc,
}
bool player_messaged = simple_monster_message(monster, str_polymon.c_str());
- const bool old_mon_caught = mons_is_caught(monster);
// Even if the monster transforms from one type that can behold the
// player into a different type which can also behold the player,
@@ -1438,29 +1394,48 @@ bool monster_polymorph( monsters *monster, monster_type targetc,
update_beholders(monster, true);
// the actual polymorphing:
- monster_change_type(monster, targetc);
+ const int old_hp = monster->hit_points;
+ const int old_hp_max = monster->max_hit_points;
+ const bool old_mon_caught = mons_is_caught(monster);
+ const char old_ench_countdown = monster->ench_countdown;
- // randomize things:
- monster->flags = 0L;
- monster->experience = 0L;
+ /* deal with mons_sec */
+ monster->type = targetc;
+ monster->number = MONS_PROGRAM_BUG;
- monster->hit_points += random2(monster->max_hit_points);
+ mon_enchant abj = monster->get_ench(ENCH_ABJ);
+ mon_enchant shifter = monster->get_ench(ENCH_GLOWING_SHAPESHIFTER,
+ ENCH_SHAPESHIFTER);
- if (monster->hit_points > monster->max_hit_points)
- monster->hit_points = monster->max_hit_points;
+ // Note: define_monster() will clear out all enchantments! -- bwr
+ define_monster( monster_index(monster) );
- monster->speed_increment = 67 + random2(6);
+ monster->add_ench(abj);
+ monster->add_ench(shifter);
- // drop entire inventory:
- monster_drop_ething(monster);
+ monster->ench_countdown = old_ench_countdown;
- if (!player_messaged && player_monster_visible(monster)
- && mons_near(monster))
+ if (mons_class_flag( monster->type, M_INVIS ))
+ monster->add_ench(ENCH_INVIS);
+
+ if (!player_messaged && mons_near(monster)
+ && player_monster_visible(monster))
{
- player_messaged = true;
mprf("%s appears out of thin air!", monster->name(DESC_CAP_A).c_str());
+ player_messaged = true;
}
+ monster->hit_points = monster->max_hit_points
+ * ((old_hp * 100) / old_hp_max) / 100
+ + random2(monster->max_hit_points);
+
+ if (monster->hit_points > monster->max_hit_points)
+ monster->hit_points = monster->max_hit_points;
+
+ monster->speed_increment = 67 + random2(6);
+
+ monster_drop_ething(monster);
+
// New monster type might be interesting
mark_interesting_monst(monster);
@@ -1474,10 +1449,7 @@ bool monster_polymorph( monsters *monster, monster_type targetc,
{
int net = get_trapping_net(monster->x, monster->y);
if (net != NON_ITEM)
- {
destroy_item(net);
- monster->del_ench(ENCH_HELD, true);
- }
if (see_grid(monster->x, monster->y))
{
@@ -1496,8 +1468,10 @@ bool monster_polymorph( monsters *monster, monster_type targetc,
|| monster->type == MONS_OOZE
|| monster->type == MONS_PULSATING_LUMP)
{
- mons_clear_trapping_net(monster);
-
+ const int net = get_trapping_net(monster->x, monster->y);
+ if (net != NON_ITEM)
+ remove_item_stationary(mitm[net]);
+
if (mons_is_insubstantial(monster->type))
{
simple_monster_message(monster,
@@ -1509,6 +1483,8 @@ bool monster_polymorph( monsters *monster, monster_type targetc,
" oozes right through the net!");
}
}
+ else
+ monster->add_ench(ENCH_HELD);
}
return (player_messaged);
diff --git a/crawl-ref/source/monstuff.h b/crawl-ref/source/monstuff.h
index 622c7d587f..dca415f0ec 100644
--- a/crawl-ref/source/monstuff.h
+++ b/crawl-ref/source/monstuff.h
@@ -63,8 +63,6 @@ enum poly_power_type {
PPT_SAME
};
-void monster_change_type(monsters *monster, monster_type targetc);
-
bool monster_polymorph(monsters *monster, monster_type targetc,
poly_power_type p = PPT_SAME);
diff --git a/crawl-ref/source/religion.cc b/crawl-ref/source/religion.cc
index eba2d3b207..b3cd603876 100644
--- a/crawl-ref/source/religion.cc
+++ b/crawl-ref/source/religion.cc
@@ -764,8 +764,10 @@ static bool promote_to_priest(monsters* mon)
if (priest_type != MONS_PROGRAM_BUG)
{
- // Turn an ordinary monster into a priestly monster.
- monster_change_type(mon, priest_type);
+ // Turn an ordinary monster into a priestly monster, using a
+ // function normally used when going up an experience level.
+ // This is a hack, but there seems to be no better way for now.
+ mon->change_type(priest_type, true);
return true;
}