Skip to content

Commit

Permalink
[10296] Move ChooseDisplayId to Creature class for access from script…
Browse files Browse the repository at this point in the history
… side

Signed-off-by: NoFantasy <nofantasy@nf.no>
  • Loading branch information
NoFantasy committed Jul 30, 2010
1 parent 1cf3b3d commit 3f4f217
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 60 deletions.
53 changes: 52 additions & 1 deletion src/game/Creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/game/Creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/game/CreatureEventAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/game/GameEventMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
53 changes: 1 addition & 52 deletions src/game/ObjectMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -902,57 +902,6 @@ CreatureModelInfo const* ObjectMgr::GetCreatureModelInfo(uint32 modelid)
return sCreatureModelStorage.LookupEntry<CreatureModelInfo>(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)
{
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/game/ObjectMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand Down
6 changes: 3 additions & 3 deletions src/game/SpellAuras.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/shared/revision_nr.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "10295"
#define REVISION_NR "10296"
#endif // __REVISION_NR_H__

0 comments on commit 3f4f217

Please sign in to comment.