summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/mon-message.cc
diff options
context:
space:
mode:
authorShmuale Mark <shm.mark@gmail.com>2014-06-19 16:05:04 -0400
committerShmuale Mark <shm.mark@gmail.com>2014-06-22 10:03:45 -0400
commit465957cba490a2a9d5444a64523572a90cfb837f (patch)
tree536c94ce0702e60217120aa2bb27325aff1b8f2d /crawl-ref/source/mon-message.cc
parent393eda0d444702a7eda580e6c363bbdcaba8d54e (diff)
downloadcrawl-ref-465957cba490a2a9d5444a64523572a90cfb837f.tar.gz
crawl-ref-465957cba490a2a9d5444a64523572a90cfb837f.zip
The great mon-stuff migration.
A good deal of functions move to the two new files, mon-poly and mon-message. Of the others, some go to where they are used, some to mon-util, and a few are made member methods of monster. This probably breaks Xcode compilation, and I'm not able to test the changes I made to MSVC that will (hopefully) keep it working.
Diffstat (limited to 'crawl-ref/source/mon-message.cc')
-rw-r--r--crawl-ref/source/mon-message.cc133
1 files changed, 133 insertions, 0 deletions
diff --git a/crawl-ref/source/mon-message.cc b/crawl-ref/source/mon-message.cc
new file mode 100644
index 0000000000..f3c9f0c797
--- /dev/null
+++ b/crawl-ref/source/mon-message.cc
@@ -0,0 +1,133 @@
+/**
+ * @file
+ * @brief Monster message-connected functions.
+**/
+
+#include "AppHdr.h"
+#include "mon-message.h"
+#include <sstream>
+
+#include "defines.h"
+#include "env.h"
+#include "libutil.h"
+#include "monster.h"
+#include "mon-util.h"
+#include "view.h"
+
+// Note that this function *completely* blocks messaging for monsters
+// distant or invisible to the player ... look elsewhere for a function
+// permitting output of "It" messages for the invisible {dlb}
+// Intentionally avoids info and str_pass now. - bwr
+bool simple_monster_message(const monster* mons, const char *event,
+ msg_channel_type channel,
+ int param,
+ description_level_type descrip)
+{
+ if (mons_near(mons)
+ && (channel == MSGCH_MONSTER_SPELL || channel == MSGCH_FRIEND_SPELL
+ || mons->visible_to(&you)))
+ {
+ string msg = mons->name(descrip);
+ msg += event;
+ msg = apostrophise_fixup(msg);
+
+ if (channel == MSGCH_PLAIN && mons->wont_attack())
+ channel = MSGCH_FRIEND_ACTION;
+
+ mprf(channel, param, "%s", msg.c_str());
+ return true;
+ }
+
+ return false;
+}
+
+mon_dam_level_type mons_get_damage_level(const monster* mons)
+{
+ if (!mons_can_display_wounds(mons))
+ return MDAM_OKAY;
+
+ if (mons->hit_points <= mons->max_hit_points / 5)
+ return MDAM_ALMOST_DEAD;
+ else if (mons->hit_points <= mons->max_hit_points * 2 / 5)
+ return MDAM_SEVERELY_DAMAGED;
+ else if (mons->hit_points <= mons->max_hit_points * 3 / 5)
+ return MDAM_HEAVILY_DAMAGED;
+ else if (mons->hit_points <= mons->max_hit_points * 4 / 5)
+ return MDAM_MODERATELY_DAMAGED;
+ else if (mons->hit_points < mons->max_hit_points)
+ return MDAM_LIGHTLY_DAMAGED;
+ else
+ return MDAM_OKAY;
+}
+
+string get_damage_level_string(mon_holy_type holi, mon_dam_level_type mdam)
+{
+ ostringstream ss;
+ switch (mdam)
+ {
+ case MDAM_ALMOST_DEAD:
+ ss << "almost";
+ ss << (wounded_damaged(holi) ? " destroyed" : " dead");
+ return ss.str();
+ case MDAM_SEVERELY_DAMAGED:
+ ss << "severely";
+ break;
+ case MDAM_HEAVILY_DAMAGED:
+ ss << "heavily";
+ break;
+ case MDAM_MODERATELY_DAMAGED:
+ ss << "moderately";
+ break;
+ case MDAM_LIGHTLY_DAMAGED:
+ ss << "lightly";
+ break;
+ case MDAM_OKAY:
+ default:
+ ss << "not";
+ break;
+ }
+ ss << (wounded_damaged(holi) ? " damaged" : " wounded");
+ return ss.str();
+}
+
+void print_wounds(const monster* mons)
+{
+ if (!mons->alive() || mons->hit_points == mons->max_hit_points)
+ return;
+
+ if (!mons_can_display_wounds(mons))
+ return;
+
+ mon_dam_level_type dam_level = mons_get_damage_level(mons);
+ string desc = get_damage_level_string(mons->holiness(), dam_level);
+
+ desc.insert(0, " is ");
+ desc += ".";
+ simple_monster_message(mons, desc.c_str(), MSGCH_MONSTER_DAMAGE,
+ dam_level);
+}
+
+// (true == 'damaged') [constructs, undead, etc.]
+// and (false == 'wounded') [living creatures, etc.] {dlb}
+bool wounded_damaged(mon_holy_type holi)
+{
+ // this schema needs to be abstracted into real categories {dlb}:
+ return holi == MH_UNDEAD || holi == MH_NONLIVING || holi == MH_PLANT;
+}
+
+bool mons_class_can_display_wounds(monster_type mc)
+{
+ // Zombified monsters other than spectral things don't show
+ // wounds.
+ if (mons_class_is_zombified(mc) && mc != MONS_SPECTRAL_THING)
+ return false;
+
+ return true;
+}
+
+bool mons_can_display_wounds(const monster* mon)
+{
+ get_tentacle_head(mon);
+
+ return mons_class_can_display_wounds(mon->type);
+}