summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--crawl-ref/source/externs.h10
-rw-r--r--crawl-ref/source/fight.cc2
-rw-r--r--crawl-ref/source/mon-util.cc81
-rw-r--r--crawl-ref/source/monstuff.cc2
-rw-r--r--crawl-ref/source/tags.cc2
5 files changed, 90 insertions, 7 deletions
diff --git a/crawl-ref/source/externs.h b/crawl-ref/source/externs.h
index e5ab195f50..0560a0e2be 100644
--- a/crawl-ref/source/externs.h
+++ b/crawl-ref/source/externs.h
@@ -881,8 +881,8 @@ public:
int hit_dice;
int ac;
int ev;
- unsigned int speed;
- unsigned int speed_increment;
+ int speed;
+ int speed_increment;
unsigned char x;
unsigned char y;
unsigned char target_x;
@@ -1008,6 +1008,12 @@ public:
actor_type atype() const { return ACT_MONSTER; }
+ // Hack, with a capital H.
+ void fix_speed();
+ void check_speed();
+
+ static int base_speed(int mcls);
+
private:
void init_with(const monsters &mons);
};
diff --git a/crawl-ref/source/fight.cc b/crawl-ref/source/fight.cc
index dc5c27120a..4ccd1cb207 100644
--- a/crawl-ref/source/fight.cc
+++ b/crawl-ref/source/fight.cc
@@ -1120,7 +1120,7 @@ int melee_attack::player_stab(int damage)
// Sleeping moster wakes up when stabbed but may be groggy
if (random2(200) <= you.skills[SK_STABBING] + you.dex)
{
- unsigned int stun = random2( you.dex + 1 );
+ int stun = random2( you.dex + 1 );
if (def->speed_increment > stun)
def->speed_increment -= stun;
diff --git a/crawl-ref/source/mon-util.cc b/crawl-ref/source/mon-util.cc
index 3b3415b31f..a6b34f08e4 100644
--- a/crawl-ref/source/mon-util.cc
+++ b/crawl-ref/source/mon-util.cc
@@ -1233,7 +1233,7 @@ void define_monster(int index)
ac = m->AC;
ev = m->ev;
- speed = m->speed;
+ speed = monsters::base_speed(mcls);
mons.god = GOD_NO_GOD;
@@ -1243,7 +1243,6 @@ void define_monster(int index)
hd = 4 + random2(4);
ac = 3 + random2(7);
ev = 7 + random2(6);
- speed = 7 + random2avg(9, 2);
if (monnumber == 250)
col = random_colour();
@@ -1261,7 +1260,6 @@ void define_monster(int index)
hd = 8 + random2(4);
ac = 5 + random2avg(9, 2);
ev = 3 + random2(5);
- speed = 6 + random2avg(7, 2);
if (monnumber == 250)
col = random_colour();
@@ -1271,7 +1269,6 @@ void define_monster(int index)
hd = 4 + random2(4);
ac = 2 + random2(5);
ev = 7 + random2(5);
- speed = 8 + random2(5);
break;
case MONS_HYDRA:
@@ -3628,6 +3625,82 @@ void monsters::sicken(int amount)
add_ench(mon_enchant(ENCH_SICK, amount));
}
+int monsters::base_speed(int mcls)
+{
+ const monsterentry *m = seekmonster(mcls);
+ if (!m)
+ return (10);
+
+ int speed = m->speed;
+
+ switch (mcls)
+ {
+ case MONS_ABOMINATION_SMALL:
+ speed = 7 + random2avg(9, 2);
+ break;
+ case MONS_ABOMINATION_LARGE:
+ speed = 6 + random2avg(7, 2);
+ break;
+ case MONS_BEAST:
+ speed = 8 + random2(5);
+ break;
+ }
+
+ return (speed);
+}
+
+// Recalculate movement speed.
+void monsters::fix_speed()
+{
+ if (mons_is_zombified(this))
+ speed = base_speed(number) - 2;
+ else
+ speed = base_speed(type);
+
+ if (has_ench(ENCH_HASTE))
+ speed *= 2;
+ else if (has_ench(ENCH_SLOW))
+ speed /= 2;
+}
+
+// Check speed and speed_increment sanity.
+void monsters::check_speed()
+{
+ // FIXME: If speed is borked, recalculate. Need to figure out how speed
+ // is getting borked.
+ if (speed < 0 || speed > 130)
+ {
+#ifdef DEBUG_DIAGNOSTICS
+ mprf(MSGCH_DIAGNOSTICS,
+ "Bad speed: %s, spd: %d, spi: %d, hd: %d, ench: %s",
+ name(DESC_PLAIN).c_str(),
+ speed, speed_increment, hit_dice,
+ comma_separated_line(enchantments.begin(),
+ enchantments.end()).c_str());
+#endif
+
+ fix_speed();
+
+#ifdef DEBUG_DIAGNOSTICS
+ mprf(MSGCH_DIAGNOSTICS, "Fixed speed for %s to %d",
+ name(DESC_PLAIN).c_str(), speed);
+#endif
+ }
+
+ if (speed_increment < 0)
+ speed_increment = 0;
+
+ if (speed_increment > 200)
+ {
+#ifdef DEBUG_DIAGNOSTICS
+ mprf(MSGCH_DIAGNOSTICS,
+ "Clamping speed increment on %s: %d",
+ name(DESC_PLAIN).c_str(), speed_increment);
+#endif
+ speed_increment = 140;
+ }
+}
+
/////////////////////////////////////////////////////////////////////////
// mon_enchant
diff --git a/crawl-ref/source/monstuff.cc b/crawl-ref/source/monstuff.cc
index f299b36fed..fd0cf3f637 100644
--- a/crawl-ref/source/monstuff.cc
+++ b/crawl-ref/source/monstuff.cc
@@ -3424,6 +3424,8 @@ static void handle_monster_move(int i, monsters *monster)
monster->behaviour = BEH_SEEK;
}
+ monster->check_speed();
+
while (monster->speed_increment >= 80)
{ // The continues & breaks are WRT this.
if (!monster->alive())
diff --git a/crawl-ref/source/tags.cc b/crawl-ref/source/tags.cc
index 2aa534d48a..deebe42670 100644
--- a/crawl-ref/source/tags.cc
+++ b/crawl-ref/source/tags.cc
@@ -1617,6 +1617,8 @@ static void unmarshall_monster(tagHeader &th, monsters &m)
if (m.type == MONS_PLAYER_GHOST || m.type == MONS_PANDEMONIUM_DEMON)
m.set_ghost( unmarshallGhost(th) );
+
+ m.check_speed();
}
static void tag_read_level_monsters(struct tagHeader &th, char minorVersion)