diff options
author | Neil Moore <neil@s-z.org> | 2014-07-30 09:07:00 -0400 |
---|---|---|
committer | Neil Moore <neil@s-z.org> | 2014-07-30 09:14:01 -0400 |
commit | b1c1c6f16f31c4aa68dad351b0559f11bc928d9f (patch) | |
tree | 1873ba2f0871cfc72376b4de17a535dc75482cae /crawl-ref/source/mon-abil.cc | |
parent | d040ba69b158247ddb906c04c2a40325234606fb (diff) | |
download | crawl-ref-b1c1c6f16f31c4aa68dad351b0559f11bc928d9f.tar.gz crawl-ref-b1c1c6f16f31c4aa68dad351b0559f11bc928d9f.zip |
Improve battlecry message table.
Make it static, store const char *s rather than strings, add a compile
check on the array size, use a local enum to identify the columns,
add a run-time assertion that we weren't passed NUM_BATTLECRIES.
Diffstat (limited to 'crawl-ref/source/mon-abil.cc')
-rw-r--r-- | crawl-ref/source/mon-abil.cc | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/crawl-ref/source/mon-abil.cc b/crawl-ref/source/mon-abil.cc index 0ec73b9b84..e26f081689 100644 --- a/crawl-ref/source/mon-abil.cc +++ b/crawl-ref/source/mon-abil.cc @@ -1115,13 +1115,17 @@ static bool _is_battlecry_compatible(monster* mons, battlecry_type type) static int _battle_cry(monster* chief, battlecry_type type) { + ASSERT(type != NUM_BATTLECRIES); const actor *foe = chief->get_foe(); int affected = 0; enchant_type battlecry = (type == BATTLECRY_ORC ? ENCH_BATTLE_FRENZY : ENCH_ROUSED); - const string messages[NUM_BATTLECRIES][4] = + // Columns 0 and 1 should have one instance of %s (for the monster), + // column 2 two (for a determiner and the monsters), and column 3 none. + enum { CRY, AFFECT_ONE, AFFECT_MANY, GENERIC_ALLIES }; + static const char * const messages[][4] = { { "%s roars a battle-cry!", @@ -1142,6 +1146,7 @@ static int _battle_cry(monster* chief, battlecry_type type) "satyr's allies" }, }; + COMPILE_CHECK(ARRAYSZ(messages) == NUM_BATTLECRIES); if (foe && (!foe->is_player() || !chief->friendly()) @@ -1193,7 +1198,7 @@ static int _battle_cry(monster* chief, battlecry_type type) { if (you.can_see(chief) && player_can_hear(chief->pos())) { - mprf(MSGCH_SOUND, messages[type][0].c_str(), + mprf(MSGCH_SOUND, messages[type][CRY], chief->name(DESC_THE).c_str()); } @@ -1211,7 +1216,7 @@ static int _battle_cry(monster* chief, battlecry_type type) if (seen_affected.size() == 1) { who = seen_affected[0]->name(DESC_THE); - mprf(channel, messages[type][1].c_str(), who.c_str()); + mprf(channel, messages[type][AFFECT_ONE], who.c_str()); } else { @@ -1228,10 +1233,10 @@ static int _battle_cry(monster* chief, battlecry_type type) } who = get_monster_data(mon_type)->name; - mprf(channel, messages[type][2].c_str(), + mprf(channel, messages[type][AFFECT_MANY], chief->friendly() ? "Your" : "The", (!generic ? pluralise(who).c_str() - : messages[type][3].c_str())); + : messages[type][GENERIC_ALLIES])); } } } |