From 21420b91c0efbec6b502dee06ed0bb2ca6b41706 Mon Sep 17 00:00:00 2001 From: evilstar Date: Sun, 9 Nov 2008 13:12:16 +0300 Subject: [PATCH] [6812] Implement localization of creature/gameobject name that say/yell. Original patch deeply rewrited. Signed-off-by: VladimirMangos --- src/game/Creature.cpp | 16 ++++++++++++++++ src/game/Creature.h | 3 +++ src/game/GameObject.cpp | 16 ++++++++++++++++ src/game/GameObject.h | 3 +++ src/game/Object.cpp | 2 +- src/game/Object.h | 2 ++ src/shared/revision_nr.h | 2 +- 7 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp index db1401031..db576c362 100644 --- a/src/game/Creature.cpp +++ b/src/game/Creature.cpp @@ -2028,3 +2028,19 @@ TrainerSpellData const* Creature::GetTrainerSpells() const { return objmgr.GetNpcTrainerSpells(GetEntry()); } + +// overwrite WorldObject function for proper name localization +const char* Creature::GetNameForLocaleIdx(int32 loc_idx) const +{ + if (loc_idx >= 0) + { + CreatureLocale const *cl = objmgr.GetCreatureLocale(GetEntry()); + if (cl) + { + if (cl->Name.size() > loc_idx && !cl->Name[loc_idx].empty()) + return cl->Name[loc_idx].c_str(); + } + } + + return GetName(); +} diff --git a/src/game/Creature.h b/src/game/Creature.h index eae23ff8d..941f4cf3d 100644 --- a/src/game/Creature.h +++ b/src/game/Creature.h @@ -513,6 +513,9 @@ class MANGOS_DLL_SPEC Creature : public Unit void TextEmote(int32 textId, uint64 TargetGuid, bool IsBossEmote = false) { MonsterTextEmote(textId,TargetGuid,IsBossEmote); } void Whisper(int32 textId, uint64 receiver, bool IsBossWhisper = false) { MonsterWhisper(textId,receiver,IsBossWhisper); } + // overwrite WorldObject function for proper name localization + const char* GetNameForLocaleIdx(int32 locale_idx) const; + void setDeathState(DeathState s); // overwrite virtual Unit::setDeathState bool LoadFromDB(uint32 guid, Map *map); diff --git a/src/game/GameObject.cpp b/src/game/GameObject.cpp index 085c7060d..116085b92 100644 --- a/src/game/GameObject.cpp +++ b/src/game/GameObject.cpp @@ -1245,3 +1245,19 @@ void GameObject::Use(Unit* user) spell->prepare(&targets); } + +// overwrite WorldObject function for proper name localization +const char* GameObject::GetNameForLocaleIdx(int32 loc_idx) const +{ + if (loc_idx >= 0) + { + GameObjectLocale const *cl = objmgr.GetGameObjectLocale(GetEntry()); + if (cl) + { + if (cl->Name.size() > loc_idx && !cl->Name[loc_idx].empty()) + return cl->Name[loc_idx].c_str(); + } + } + + return GetName(); +} diff --git a/src/game/GameObject.h b/src/game/GameObject.h index 1fab1492a..b029bf4ce 100644 --- a/src/game/GameObject.h +++ b/src/game/GameObject.h @@ -442,6 +442,9 @@ class MANGOS_DLL_SPEC GameObject : public WorldObject void TextEmote(int32 textId, uint64 TargetGuid) { MonsterTextEmote(textId,TargetGuid); } void Whisper(int32 textId, uint64 receiver) { MonsterWhisper(textId,receiver); } + // overwrite WorldObject function for proper name localization + const char* GetNameForLocaleIdx(int32 locale_idx) const; + void SaveToDB(); void SaveToDB(uint32 mapid, uint8 spawnMask); bool LoadFromDB(uint32 guid, Map *map); diff --git a/src/game/Object.cpp b/src/game/Object.cpp index 0b6bb2092..24ce65ded 100644 --- a/src/game/Object.cpp +++ b/src/game/Object.cpp @@ -1204,7 +1204,7 @@ namespace MaNGOS data = new WorldPacket(SMSG_MESSAGECHAT, 200); // TODO: i_object.GetName() also must be localized? - i_object.BuildMonsterChat(data,i_msgtype,text,i_language,i_object.GetName(),i_targetGUID); + i_object.BuildMonsterChat(data,i_msgtype,text,i_language,i_object.GetNameForLocaleIdx(loc_idx),i_targetGUID); i_data_cache[cache_idx] = data; } diff --git a/src/game/Object.h b/src/game/Object.h index 066e54438..1e7c12cd4 100644 --- a/src/game/Object.h +++ b/src/game/Object.h @@ -391,6 +391,8 @@ class MANGOS_DLL_SPEC WorldObject : public Object const char* GetName() const { return m_name.c_str(); } void SetName(std::string newname) { m_name=newname; } + virtual const char* GetNameForLocaleIdx(int32 /*locale_idx*/) const { return GetName(); } + float GetDistance( const WorldObject* obj ) const; float GetDistance(const float x, const float y, const float z) const; float GetDistance2d(const WorldObject* obj) const; diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 3148c14c1..3029a792a 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "6811" + #define REVISION_NR "6812" #endif // __REVISION_NR_H__ -- 2.11.4.GIT