diff --git a/Source/control.cpp b/Source/control.cpp index 789627e6f..1a975093d 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -917,7 +917,7 @@ void DrawInfoBox(const Surface &out) if (leveltype != DTYPE_TOWN) { const auto &monster = Monsters[pcursmonst]; InfoColor = UiFlags::ColorWhite; - InfoString = string_view(monster.name); + InfoString = monster.name(); ClearPanel(); if (monster.isUnique()) { InfoColor = UiFlags::ColorWhitegold; diff --git a/Source/debug.cpp b/Source/debug.cpp index 05d57022d..6311349d3 100644 --- a/Source/debug.cpp +++ b/Source/debug.cpp @@ -97,7 +97,7 @@ void PrintDebugMonster(int m) auto &monster = Monsters[m]; EventPlrMsg(StrCat( - "Monster ", m, " = ", monster.name, + "Monster ", m, " = ", monster.name(), "\nX = ", monster.position.tile.x, ", Y = ", monster.position.tile.y, "\nEnemy = ", monster.enemy, ", HP = ", monster.hitPoints, "\nMode = ", static_cast(monster.mode), ", Var1 = ", monster.var1), diff --git a/Source/engine/render/scrollrt.cpp b/Source/engine/render/scrollrt.cpp index 6db50af9d..b11ba0eb4 100644 --- a/Source/engine/render/scrollrt.cpp +++ b/Source/engine/render/scrollrt.cpp @@ -367,7 +367,7 @@ void DrawMissile(const Surface &out, Point tilePosition, Point targetBufferPosit void DrawMonster(const Surface &out, Point tilePosition, Point targetBufferPosition, const Monster &monster) { if (!monster.animInfo.celSprite) { - Log("Draw Monster \"{}\": NULL Cel Buffer", monster.name); + Log("Draw Monster \"{}\": NULL Cel Buffer", monster.name()); return; } @@ -437,7 +437,7 @@ void DrawMonster(const Surface &out, Point tilePosition, Point targetBufferPosit if (nCel < 0 || frames > 50 || nCel >= static_cast(frames)) { Log( "Draw Monster \"{}\" {}: facing {}, frame {} of {}", - monster.name, + monster.name(), getMonsterModeDisplayName(monster.mode), DirectionToString(monster.direction), nCel, diff --git a/Source/monster.cpp b/Source/monster.cpp index b45555f48..9f74baad6 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -200,7 +200,6 @@ void InitMonster(Monster &monster, Direction rd, int mtype, Point position) monster.position.old = position; monster.levelType = mtype; monster.mode = MonsterMode::Stand; - monster.name = pgettext("monster", monster.data().mName).data(); monster.animInfo = {}; monster.changeAnimationData(MonsterGraphic::Stand); monster.animInfo.tickCounterOfCurrentFrame = GenerateRnd(monster.animInfo.ticksPerFrame - 1); @@ -532,7 +531,6 @@ void ClrAllMonsters() { for (auto &monster : Monsters) { ClearMVars(monster); - monster.name = "Invalid Monster"; monster.goal = MonsterGoal::None; monster.mode = MonsterMode::Stand; monster.var1 = 0; @@ -3396,7 +3394,6 @@ void PrepareUniqueMonst(Monster &monster, UniqueMonsterType monsterType, int min } monster.exp *= 2; - monster.name = pgettext("monster", uniqueMonsterData.mName).data(); monster.maxHitPoints = uniqueMonsterData.mmaxhp << 6; if (!gbIsMultiplayer) @@ -4367,12 +4364,8 @@ void SyncMonsterAnim(Monster &monster) } #endif if (monster.isUnique()) { - monster.name = pgettext("monster", UniqueMonstersData[static_cast(monster.uniqueType)].mName).data(); InitTRNForUniqueMonster(monster); - } else { - monster.name = pgettext("monster", monster.data().mName).data(); } - MonsterGraphic graphic = MonsterGraphic::Stand; switch (monster.mode) { diff --git a/Source/monster.h b/Source/monster.h index 73b9ce4ee..b736fac61 100644 --- a/Source/monster.h +++ b/Source/monster.h @@ -21,6 +21,7 @@ #include "monstdat.h" #include "spelldat.h" #include "textdat.h" +#include "utils/language.h" namespace devilution { @@ -169,7 +170,6 @@ struct CMonster { extern CMonster LevelMonsterTypes[MaxLvlMTypes]; struct Monster { // note: missing field _mAFNum - const char *name; std::unique_ptr uniqueMonsterTRN; /** * @brief Contains information for current animation @@ -285,6 +285,19 @@ struct Monster { // note: missing field _mAFNum return *type().data; } + /** + * @brief Returns monster's name + * Internally it returns a name stored in global array of monsters' data. + * @return Monster's name + */ + string_view name() const + { + if (uniqueType != UniqueMonsterType::None) + return pgettext("monster", UniqueMonstersData[static_cast(uniqueType)].mName); + + return pgettext("monster", data().mName); + } + /** * @brief Returns the network identifier for this monster * diff --git a/Source/qol/monhealthbar.cpp b/Source/qol/monhealthbar.cpp index bcb87f623..9a741125d 100644 --- a/Source/qol/monhealthbar.cpp +++ b/Source/qol/monhealthbar.cpp @@ -133,14 +133,14 @@ void DrawMonsterHealthBar(const Surface &out) } UiFlags style = UiFlags::AlignCenter | UiFlags::VerticalCenter; - DrawString(out, monster.name, { position + Displacement { -1, 1 }, { width, height } }, style | UiFlags::ColorBlack); + DrawString(out, monster.name(), { position + Displacement { -1, 1 }, { width, height } }, style | UiFlags::ColorBlack); if (monster.isUnique()) style |= UiFlags::ColorWhitegold; else if (monster.leader != Monster::NoLeader) style |= UiFlags::ColorBlue; else style |= UiFlags::ColorWhite; - DrawString(out, monster.name, { position, { width, height } }, style); + DrawString(out, monster.name(), { position, { width, height } }, style); if (multiplier > 0) DrawString(out, StrCat("x", multiplier), { position, { width - 2, height } }, UiFlags::ColorWhite | UiFlags::AlignRight | UiFlags::VerticalCenter);