diff options
author | Bardur Arantsson <bardur@scientician.net> | 2014-06-07 09:40:26 +0200 |
---|---|---|
committer | Bardur Arantsson <bardur@scientician.net> | 2014-06-26 04:19:42 +0200 |
commit | 62bcb16ba7fdda8f87d5b698546c4b3ba4b721cd (patch) | |
tree | 664b12659dcaf223c6141e3b6e1f53b8d516e922 | |
parent | 41b65b07a5ac89bad9533487b2233d309e7fc86d (diff) |
Remove a usage of vstrnfmt()
-rw-r--r-- | src/externs.h | 1 | ||||
-rw-r--r-- | src/melee2.cc | 12 | ||||
-rw-r--r-- | src/monster2.cc | 87 | ||||
-rw-r--r-- | src/z-form.c | 14 | ||||
-rw-r--r-- | src/z-util.c | 22 | ||||
-rw-r--r-- | src/z-util.h | 3 |
6 files changed, 80 insertions, 59 deletions
diff --git a/src/externs.h b/src/externs.h index 42b13912..59e246c8 100644 --- a/src/externs.h +++ b/src/externs.h @@ -956,6 +956,7 @@ extern void monster_description_out(int r_idx, int ego); extern void monster_set_level(int m_idx, int level); extern s32b modify_aux(s32b a, s32b b, char mod); extern void monster_msg(cptr fmt, ...); +extern void monster_msg_simple(cptr s); extern void cmonster_msg(char a, cptr fmt, ...); extern bool_ mego_ok(int r_idx, int ego); extern void monster_check_experience(int m_idx, bool_ silent); diff --git a/src/melee2.cc b/src/melee2.cc index 0a139f89..5b3251ef 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -962,12 +962,20 @@ void monster_msg(cptr fmt, ...) /* End the Varargs Stuff */ va_end(vp); + /* Print */ + monster_msg_simple(buf); +} + +void monster_msg_simple(cptr s) +{ /* Display */ if (disturb_other) - msg_print(buf); + { + msg_print(s); + } else { - message_add(buf, TERM_WHITE); + message_add(s, TERM_WHITE); p_ptr->window |= PW_MESSAGE; } } diff --git a/src/monster2.cc b/src/monster2.cc index 6ffc4649..c9892e49 100644 --- a/src/monster2.cc +++ b/src/monster2.cc @@ -13,6 +13,8 @@ #include "angband.h" #include "hooks.h" +#include <string> + #define MAX_HORROR 20 #define MAX_FUNNY 22 #define MAX_COMMENT 5 @@ -3682,25 +3684,21 @@ bool_ multiply_monster(int m_idx, bool_ charm, bool_ clone) * Technically should attempt to treat "Beholder"'s as jelly's */ bool_ hack_message_pain_may_silent = FALSE; -void message_pain_hook(cptr fmt, ...) +void message_pain_hook(cptr message, cptr name) { - va_list vp; - - char buf[1024]; - - /* Begin the Varargs Stuff */ - va_start(vp, fmt); - - /* Format the args, save the length */ - (void)vstrnfmt(buf, 1024, fmt, vp); - - /* End the Varargs Stuff */ - va_end(vp); + std::string buf; + buf += name; + buf += " "; + buf += message; if (hack_message_pain_may_silent) - monster_msg(buf); + { + monster_msg_simple(buf.c_str()); + } else - msg_print(buf); + { + msg_print(buf.c_str()); + } } void message_pain(int m_idx, int dam) @@ -3713,11 +3711,12 @@ void message_pain(int m_idx, int dam) /* Get the monster name */ monster_desc(m_name, m_ptr, 0); + capitalize(m_name); /* Notice non-damage */ if (dam == 0) { - message_pain_hook("%^s is unharmed.", m_name); + message_pain_hook("is unharmed.", m_name); return; } @@ -3732,76 +3731,76 @@ void message_pain(int m_idx, int dam) if (strchr("jmvQ", r_ptr->d_char)) { if (percentage > 95) - message_pain_hook("%^s barely notices.", m_name); + message_pain_hook("barely notices.", m_name); else if (percentage > 75) - message_pain_hook("%^s flinches.", m_name); + message_pain_hook("flinches.", m_name); else if (percentage > 50) - message_pain_hook("%^s squelches.", m_name); + message_pain_hook("squelches.", m_name); else if (percentage > 35) - message_pain_hook("%^s quivers in pain.", m_name); + message_pain_hook("quivers in pain.", m_name); else if (percentage > 20) - message_pain_hook("%^s writhes about.", m_name); + message_pain_hook("writhes about.", m_name); else if (percentage > 10) - message_pain_hook("%^s writhes in agony.", m_name); + message_pain_hook("writhes in agony.", m_name); else - message_pain_hook("%^s jerks limply.", m_name); + message_pain_hook("jerks limply.", m_name); } /* Dogs and Hounds */ else if (strchr("CZ", r_ptr->d_char)) { if (percentage > 95) - message_pain_hook("%^s shrugs off the attack.", m_name); + message_pain_hook("shrugs off the attack.", m_name); else if (percentage > 75) - message_pain_hook("%^s snarls with pain.", m_name); + message_pain_hook("snarls with pain.", m_name); else if (percentage > 50) - message_pain_hook("%^s yelps in pain.", m_name); + message_pain_hook("yelps in pain.", m_name); else if (percentage > 35) - message_pain_hook("%^s howls in pain.", m_name); + message_pain_hook("howls in pain.", m_name); else if (percentage > 20) - message_pain_hook("%^s howls in agony.", m_name); + message_pain_hook("howls in agony.", m_name); else if (percentage > 10) - message_pain_hook("%^s writhes in agony.", m_name); + message_pain_hook("writhes in agony.", m_name); else - message_pain_hook("%^s yelps feebly.", m_name); + message_pain_hook("yelps feebly.", m_name); } /* One type of monsters (ignore,squeal,shriek) */ else if (strchr("FIKMRSXabclqrst", r_ptr->d_char)) { if (percentage > 95) - message_pain_hook("%^s ignores the attack.", m_name); + message_pain_hook("ignores the attack.", m_name); else if (percentage > 75) - message_pain_hook("%^s grunts with pain.", m_name); + message_pain_hook("grunts with pain.", m_name); else if (percentage > 50) - message_pain_hook("%^s squeals in pain.", m_name); + message_pain_hook("squeals in pain.", m_name); else if (percentage > 35) - message_pain_hook("%^s shrieks in pain.", m_name); + message_pain_hook("shrieks in pain.", m_name); else if (percentage > 20) - message_pain_hook("%^s shrieks in agony.", m_name); + message_pain_hook("shrieks in agony.", m_name); else if (percentage > 10) - message_pain_hook("%^s writhes in agony.", m_name); + message_pain_hook("writhes in agony.", m_name); else - message_pain_hook("%^s cries out feebly.", m_name); + message_pain_hook("cries out feebly.", m_name); } /* Another type of monsters (shrug,cry,scream) */ else { if (percentage > 95) - message_pain_hook("%^s shrugs off the attack.", m_name); + message_pain_hook("shrugs off the attack.", m_name); else if (percentage > 75) - message_pain_hook("%^s grunts with pain.", m_name); + message_pain_hook("grunts with pain.", m_name); else if (percentage > 50) - message_pain_hook("%^s cries out in pain.", m_name); + message_pain_hook("cries out in pain.", m_name); else if (percentage > 35) - message_pain_hook("%^s screams in pain.", m_name); + message_pain_hook("screams in pain.", m_name); else if (percentage > 20) - message_pain_hook("%^s screams in agony.", m_name); + message_pain_hook("screams in agony.", m_name); else if (percentage > 10) - message_pain_hook("%^s writhes in agony.", m_name); + message_pain_hook("writhes in agony.", m_name); else - message_pain_hook("%^s cries out feebly.", m_name); + message_pain_hook("cries out feebly.", m_name); } } diff --git a/src/z-form.c b/src/z-form.c index 2cd9ebe9..ab195c76 100644 --- a/src/z-form.c +++ b/src/z-form.c @@ -531,19 +531,7 @@ uint vstrnfmt(char *buf, uint max, cptr fmt, va_list vp) /* Mega-Hack -- handle "capitilization" */ if (do_xtra) { - /* Now append "tmp" to "buf" */ - for (q = 0; tmp[q]; q++) - { - /* Notice first non-space */ - if (!isspace(tmp[q])) - { - /* Capitalize if possible */ - if (islower(tmp[q])) tmp[q] = toupper(tmp[q]); - - /* Done */ - break; - } - } + capitalize(tmp); } /* Now append "tmp" to "buf" */ diff --git a/src/z-util.c b/src/z-util.c index 7c5374f3..4e10a67b 100644 --- a/src/z-util.c +++ b/src/z-util.c @@ -4,6 +4,7 @@ #include "z-util.h" +#include <assert.h> /* @@ -150,6 +151,27 @@ bool_ suffix(cptr s, cptr t) } +/** + * Captialize letter + */ +void capitalize(char *s) +{ + char *p = s; + assert(s != NULL); + + for (; *p; p++) + { + if (!isspace(*p)) + { + if (islower(*p)) + { + *p = toupper(*p); + } + /* Done */ + break; + } + } +} /* diff --git a/src/z-util.h b/src/z-util.h index 05544145..ef277e00 100644 --- a/src/z-util.h +++ b/src/z-util.h @@ -70,6 +70,9 @@ extern bool_ prefix(cptr s, cptr t); extern bool_ suffix(cptr s, cptr t); +/* Capitalize the first letter of string. Ignores whitespace at the start of string. */ +extern void capitalize(char *s); + /* Print an error message */ extern void plog(cptr str); |