Browse Source

Remove monster name member from monster struct (#4986)

pull/4998/head
Mikołaj Piróg 4 years ago committed by GitHub
parent
commit
c38db60d0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      Source/control.cpp
  2. 2
      Source/debug.cpp
  3. 4
      Source/engine/render/scrollrt.cpp
  4. 7
      Source/monster.cpp
  5. 15
      Source/monster.h
  6. 4
      Source/qol/monhealthbar.cpp

2
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;

2
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<int>(monster.mode), ", Var1 = ", monster.var1),

4
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<int>(frames)) {
Log(
"Draw Monster \"{}\" {}: facing {}, frame {} of {}",
monster.name,
monster.name(),
getMonsterModeDisplayName(monster.mode),
DirectionToString(monster.direction),
nCel,

7
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<size_t>(monster.uniqueType)].mName).data();
InitTRNForUniqueMonster(monster);
} else {
monster.name = pgettext("monster", monster.data().mName).data();
}
MonsterGraphic graphic = MonsterGraphic::Stand;
switch (monster.mode) {

15
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<uint8_t[]> 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<int8_t>(uniqueType)].mName);
return pgettext("monster", data().mName);
}
/**
* @brief Returns the network identifier for this monster
*

4
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);

Loading…
Cancel
Save