From 7bdf05901d94fbd2019e01301f787848bcf2fa84 Mon Sep 17 00:00:00 2001 From: NoFantasy Date: Fri, 30 Jul 2010 21:08:25 +0200 Subject: [PATCH] [10296] Move ChooseDisplayId to Creature class for access from script side Signed-off-by: NoFantasy --- src/game/Creature.cpp | 53 +++++++++++++++++++++++++++++++++++- src/game/Creature.h | 2 ++ src/game/CreatureEventAI.cpp | 2 +- src/game/GameEventMgr.cpp | 2 +- src/game/ObjectMgr.cpp | 53 +----------------------------------- src/game/ObjectMgr.h | 2 +- src/game/SpellAuras.cpp | 6 ++-- src/shared/revision_nr.h | 2 +- 8 files changed, 62 insertions(+), 60 deletions(-) diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp index da8cd754b..bb1f4f5bd 100644 --- a/src/game/Creature.cpp +++ b/src/game/Creature.cpp @@ -229,7 +229,7 @@ bool Creature::InitEntry(uint32 Entry, uint32 team, const CreatureData *data ) // known valid are: CLASS_WARRIOR,CLASS_PALADIN,CLASS_ROGUE,CLASS_MAGE SetByteValue(UNIT_FIELD_BYTES_0, 1, uint8(cinfo->unit_class)); - uint32 display_id = sObjectMgr.ChooseDisplayId(team, GetCreatureInfo(), data); + uint32 display_id = ChooseDisplayId(team, GetCreatureInfo(), data); if (!display_id) // Cancel load if no display id { sLog.outErrorDb("Creature (Entry: %u) has no model defined in table `creature_template`, can't load.", Entry); @@ -346,6 +346,57 @@ bool Creature::UpdateEntry(uint32 Entry, uint32 team, const CreatureData *data, return true; } +uint32 Creature::ChooseDisplayId(uint32 team, const CreatureInfo *cinfo, const CreatureData *data /*= NULL*/) +{ + // Use creature model explicit, override template (creature.modelid) + if (data && data->modelid_override) + return data->modelid_override; + + // use defaults from the template + uint32 display_id = 0; + + // models may be categorized as (in this order): + // if mod4 && mod3 && mod2 && mod1 use any, by 25%-chance (other gender is selected and replaced after this function) + // if mod3 && mod2 && mod1 use mod3 unless mod2 has modelid_alt_model (then all by 33%-chance) + // if mod2 use mod2 unless mod2 has modelid_alt_model (then both by 50%-chance) + // if mod1 use mod1 + + // model selected here may be replaced with other_gender using own function + + if (cinfo->ModelId[3] && cinfo->ModelId[2] && cinfo->ModelId[1] && cinfo->ModelId[0]) + { + display_id = cinfo->ModelId[urand(0,3)]; + } + else if (cinfo->ModelId[2] && cinfo->ModelId[1] && cinfo->ModelId[0]) + { + uint32 modelid_tmp = sObjectMgr.GetCreatureModelAlternativeModel(cinfo->ModelId[1]); + display_id = modelid_tmp ? cinfo->ModelId[urand(0,2)] : cinfo->ModelId[2]; + } + else if (cinfo->ModelId[1]) + { + // We use this to eliminate invisible models vs. "dummy" models (infernals, etc). + // Where it's expected to select one of two, model must have a alternative model defined (alternative model is normally the same as defined in ModelId1). + // Same pattern is used in the above model selection, but the result may be ModelId3 and not ModelId2 as here. + uint32 modelid_tmp = sObjectMgr.GetCreatureModelAlternativeModel(cinfo->ModelId[1]); + display_id = modelid_tmp ? modelid_tmp : cinfo->ModelId[1]; + } + else if (cinfo->ModelId[0]) + { + display_id = cinfo->ModelId[0]; + } + + // fail safe, we use creature entry 1 and make error + if (!display_id) + { + sLog.outErrorDb("Call customer support, ChooseDisplayId can not select native model for creature entry %u, model from creature entry 1 will be used instead.", cinfo->Entry); + + if (const CreatureInfo *creatureDefault = sObjectMgr.GetCreatureTemplate(1)) + display_id = creatureDefault->ModelId[0]; + } + + return display_id; +} + void Creature::Update(uint32 diff) { if(m_GlobalCooldown <= diff) diff --git a/src/game/Creature.h b/src/game/Creature.h index 56e034d91..8e6bbab38 100644 --- a/src/game/Creature.h +++ b/src/game/Creature.h @@ -507,6 +507,8 @@ class MANGOS_DLL_SPEC Creature : public Unit CreatureInfo const *GetCreatureInfo() const { return m_creatureInfo; } CreatureDataAddon const* GetCreatureAddon() const; + static uint32 ChooseDisplayId(uint32 team, const CreatureInfo *cinfo, const CreatureData *data = NULL); + std::string GetAIName() const; std::string GetScriptName() const; uint32 GetScriptId() const; diff --git a/src/game/CreatureEventAI.cpp b/src/game/CreatureEventAI.cpp index 7d71ba471..711d1be84 100644 --- a/src/game/CreatureEventAI.cpp +++ b/src/game/CreatureEventAI.cpp @@ -425,7 +425,7 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32 { if (CreatureInfo const* ci = GetCreatureTemplateStore(action.morph.creatureId)) { - uint32 display_id = sObjectMgr.ChooseDisplayId(0,ci); + uint32 display_id = Creature::ChooseDisplayId(0,ci); m_creature->SetDisplayId(display_id); } } diff --git a/src/game/GameEventMgr.cpp b/src/game/GameEventMgr.cpp index 74f68b442..f2ce58e68 100644 --- a/src/game/GameEventMgr.cpp +++ b/src/game/GameEventMgr.cpp @@ -762,7 +762,7 @@ void GameEventMgr::ChangeEquipOrModel(int16 event_id, bool activate) if (data2 && activate) { CreatureInfo const *cinfo = ObjectMgr::GetCreatureTemplate(data2->id); - uint32 display_id = sObjectMgr.ChooseDisplayId(0,cinfo,data2); + uint32 display_id = Creature::ChooseDisplayId(0,cinfo,data2); CreatureModelInfo const *minfo = sObjectMgr.GetCreatureModelRandomGender(display_id); if (minfo) display_id = minfo->modelid; diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp index da657400c..d40f86e47 100644 --- a/src/game/ObjectMgr.cpp +++ b/src/game/ObjectMgr.cpp @@ -902,57 +902,6 @@ CreatureModelInfo const* ObjectMgr::GetCreatureModelInfo(uint32 modelid) return sCreatureModelStorage.LookupEntry(modelid); } -uint32 ObjectMgr::ChooseDisplayId(uint32 team, const CreatureInfo *cinfo, const CreatureData *data /*= NULL*/) -{ - // Use creature model explicit, override template (creature.modelid) - if (data && data->modelid_override) - return data->modelid_override; - - // use defaults from the template - uint32 display_id = 0; - - // models may be categorized as (in this order): - // if mod4 && mod3 && mod2 && mod1 use any, by 25%-chance (other gender is selected and replaced after this function) - // if mod3 && mod2 && mod1 use mod3 unless mod2 has modelid_alt_model (then all by 33%-chance) - // if mod2 use mod2 unless mod2 has modelid_alt_model (then both by 50%-chance) - // if mod1 use mod1 - - // model selected here may be replaced with other_gender using own function - - if (cinfo->ModelId[3] && cinfo->ModelId[2] && cinfo->ModelId[1] && cinfo->ModelId[0]) - { - display_id = cinfo->ModelId[urand(0,3)]; - } - else if (cinfo->ModelId[2] && cinfo->ModelId[1] && cinfo->ModelId[0]) - { - uint32 modelid_tmp = GetCreatureModelAlternativeModel(cinfo->ModelId[1]); - display_id = modelid_tmp ? cinfo->ModelId[urand(0,2)] : cinfo->ModelId[2]; - } - else if (cinfo->ModelId[1]) - { - // We use this to eliminate invisible models vs. "dummy" models (infernals, etc). - // Where it's expected to select one of two, model must have a alternative model defined (alternative model is normally the same as defined in ModelId1). - // Same pattern is used in the above model selection, but the result may be ModelId3 and not ModelId2 as here. - uint32 modelid_tmp = GetCreatureModelAlternativeModel(cinfo->ModelId[1]); - display_id = modelid_tmp ? modelid_tmp : cinfo->ModelId[1]; - } - else if (cinfo->ModelId[0]) - { - display_id = cinfo->ModelId[0]; - } - - // fail safe, we use creature entry 1 and make error - if (!display_id) - { - sLog.outErrorDb("Call customer support, ChooseDisplayId can not select native model for creature entry %u, model from creature entry 1 will be used instead.", cinfo->Entry); - - if (const CreatureInfo *creatureDefault = GetCreatureTemplate(1)) - display_id = creatureDefault->ModelId[0]; - } - - return display_id; -} - // generally models that does not have a gender(2), or has alternative model for same gender uint32 ObjectMgr::GetCreatureModelAlternativeModel(uint32 modelId) { @@ -5383,7 +5332,7 @@ uint32 ObjectMgr::GetTaxiMountDisplayId( uint32 id, uint32 team, bool allowed_al if (!mount_info) return 0; - uint16 mount_id = ChooseDisplayId(team,mount_info); + uint16 mount_id = Creature::ChooseDisplayId(team,mount_info); if (!mount_id) return 0; diff --git a/src/game/ObjectMgr.h b/src/game/ObjectMgr.h index 124af36b9..83bf5427c 100644 --- a/src/game/ObjectMgr.h +++ b/src/game/ObjectMgr.h @@ -520,7 +520,7 @@ class ObjectMgr CreatureModelInfo const* GetCreatureModelRandomGender(uint32 display_id); uint32 GetCreatureModelAlternativeModel(uint32 modelId); uint32 GetCreatureModelOtherTeamModel(uint32 modelId); - uint32 ChooseDisplayId(uint32 team, const CreatureInfo *cinfo, const CreatureData *data = NULL); + EquipmentInfo const *GetEquipmentInfo( uint32 entry ); static CreatureDataAddon const *GetCreatureAddon( uint32 lowguid ) { diff --git a/src/game/SpellAuras.cpp b/src/game/SpellAuras.cpp index b9ae42432..a082435a2 100644 --- a/src/game/SpellAuras.cpp +++ b/src/game/SpellAuras.cpp @@ -2650,7 +2650,7 @@ void Aura::HandleAuraMounted(bool apply, bool Real) if (target->GetTypeId()==TYPEID_PLAYER) team = ((Player*)target)->GetTeam(); - uint32 display_id = sObjectMgr.ChooseDisplayId(team,ci); + uint32 display_id = Creature::ChooseDisplayId(team,ci); CreatureModelInfo const *minfo = sObjectMgr.GetCreatureModelRandomGender(display_id); if (minfo) display_id = minfo->modelid; @@ -3080,7 +3080,7 @@ void Aura::HandleAuraTransform(bool apply, bool Real) sLog.outError("Auras: unknown creature id = %d (only need its modelid) Form Spell Aura Transform in Spell ID = %d", m_modifier.m_miscvalue, GetId()); } else - model_id = sObjectMgr.ChooseDisplayId(0,ci);// Will use the default model here + model_id = Creature::ChooseDisplayId(0,ci); // Will use the default model here // Polymorph (sheep/penguin case) if (GetSpellProto()->SpellFamilyName == SPELLFAMILY_MAGE && GetSpellProto()->SpellIconID == 82) @@ -3156,7 +3156,7 @@ void Aura::HandleAuraTransform(bool apply, bool Real) if (target->GetTypeId() == TYPEID_PLAYER) team = ((Player*)target)->GetTeam(); - uint32 display_id = sObjectMgr.ChooseDisplayId(team, ci); + uint32 display_id = Creature::ChooseDisplayId(team, ci); CreatureModelInfo const *minfo = sObjectMgr.GetCreatureModelRandomGender(display_id); if (minfo) display_id = minfo->modelid; diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 324934b7e..2f1393a9b 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 "10295" + #define REVISION_NR "10296" #endif // __REVISION_NR_H__