Skip to content

Commit

Permalink
[z2674] Add two extra model fields to creature_template
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobschinski authored and cala committed Aug 29, 2015
1 parent 103e1eb commit cd32eab
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 8 deletions.
4 changes: 3 additions & 1 deletion sql/mangos.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ DROP TABLE IF EXISTS `db_version`;
CREATE TABLE `db_version` (
`version` varchar(120) DEFAULT NULL,
`creature_ai_version` varchar(120) DEFAULT NULL,
`required_z2621_s2263_12823_04_mangos_creature` bit(1) DEFAULT NULL
`required_z2674_sxxxx_xxxxx_01_mangos_creature_template` bit(1) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED COMMENT='Used DB version notes';

--
Expand Down Expand Up @@ -1184,6 +1184,8 @@ CREATE TABLE `creature_template` (
`MaxLevel` tinyint(3) unsigned NOT NULL DEFAULT '1',
`ModelId1` mediumint(8) unsigned NOT NULL DEFAULT '0',
`ModelId2` mediumint(8) unsigned NOT NULL DEFAULT '0',
`ModelId3` mediumint(8) unsigned NOT NULL DEFAULT '0',
`ModelId4` mediumint(8) unsigned NOT NULL DEFAULT '0',
`FactionAlliance` smallint(5) unsigned NOT NULL DEFAULT '0',
`FactionHorde` smallint(5) unsigned NOT NULL DEFAULT '0',
`Scale` float NOT NULL DEFAULT '1',
Expand Down
5 changes: 5 additions & 0 deletions sql/updates/z2674_sxxxx_xxxxx_01_mangos_creature_template.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ALTER TABLE db_version CHANGE COLUMN required_z2621_s2263_12823_04_mangos_creature required_z2674_sxxxx_xxxxx_01_mangos_creature_template bit;

ALTER TABLE `creature_template`
ADD COLUMN `ModelId3` MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT '0' AFTER `ModelId2`,
ADD COLUMN `ModelId4` MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT '0' AFTER `ModelId3`;
21 changes: 19 additions & 2 deletions src/game/Creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,13 +436,26 @@ uint32 Creature::ChooseDisplayId(const CreatureInfo* cinfo, const CreatureData*
// use defaults from the template
uint32 display_id = 0;

// The follow decision tree needs to be updated if MAX_CREATURE_MODEL is changed.
static_assert(MAX_CREATURE_MODEL == 4, "Need to update model selection code for new or removed model fields");

// model selected here may be replaced with other_gender using own function
if (!cinfo->ModelId[1])
{
display_id = cinfo->ModelId[0];
}
else
else if (!cinfo->ModelId[2])
{
display_id = cinfo->ModelId[urand(0, 1)];
}
else if (!cinfo->ModelId[3])
{
display_id = cinfo->ModelId[urand(0, 2)];
}
else
{
display_id = cinfo->ModelId[urand(0, 3)];
}

// fail safe, we use creature entry 1 and make error
if (!display_id)
Expand Down Expand Up @@ -1084,7 +1097,11 @@ void Creature::SaveToDB(uint32 mapid)
CreatureInfo const* cinfo = GetCreatureInfo();
if (cinfo)
{
if (displayId != cinfo->ModelId[0] && displayId != cinfo->ModelId[1])
// The following if-else assumes that there are 4 model fields and needs updating if this is changed.
static_assert(MAX_CREATURE_MODEL == 4, "Need to update custom model check for new/removed model fields.");

if (displayId != cinfo->ModelId[0] && displayId != cinfo->ModelId[1] &&
displayId != cinfo->ModelId[2] && displayId != cinfo->ModelId[3])
{
for (int i = 0; i < MAX_CREATURE_MODEL && displayId; ++i)
if (cinfo->ModelId[i])
Expand Down
2 changes: 1 addition & 1 deletion src/game/Creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ enum CreatureFlagsExtra
#endif

#define MAX_KILL_CREDIT 2
#define MAX_CREATURE_MODEL 2 // only single send to client in static data
#define MAX_CREATURE_MODEL 4 // only single send to client in static data

// from `creature_template` table
struct CreatureInfo
Expand Down
4 changes: 2 additions & 2 deletions src/game/SQLStorages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

#include "SQLStorages.h"

const char CreatureInfosrcfmt[] = "issiiiiiifiiiiliiiiiffiiffffffiiiiffffiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiss";
const char CreatureInfodstfmt[] = "issiiiiiifiiiiliiiiiffiiffffffiiiiffffiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiisi";
const char CreatureInfosrcfmt[] = "issiiiiiiiifiiiiliiiiiffiiffffffiiiiffffiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiss";
const char CreatureInfodstfmt[] = "issiiiiiiiifiiiiliiiiiffiiffffffiiiiffffiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiisi";
const char CreatureDataAddonInfofmt[] = "iiibbiis";
const char CreatureModelfmt[] = "iffbii";
const char CreatureInfoAddonInfofmt[] = "iiibbiis";
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 "2673"
#define REVISION_NR "2674"
#endif // __REVISION_NR_H__
2 changes: 1 addition & 1 deletion src/shared/revision_sql.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef __REVISION_SQL_H__
#define __REVISION_SQL_H__
#define REVISION_DB_CHARACTERS "required_z2559_s2204_12756_01_characters_pvpstats"
#define REVISION_DB_MANGOS "required_z2621_s2263_12823_04_mangos_creature"
#define REVISION_DB_MANGOS "required_z2674_sxxxx_xxxxx_01_mangos_creature_template"
#define REVISION_DB_REALMD "required_10008_01_realmd_realmd_db_version"
#endif // __REVISION_SQL_H__

2 comments on commit cd32eab

@evil-at-wow
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cala Did you actually build this? I'm asking because static_assert is C++11, so this is going to break several GCC builds.

Sorry for the noise. I've been told this is still a macro, so crisis averted.

@cala
Copy link
Contributor

@cala cala commented on cd32eab Sep 1, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I did. But from your edit, I assume that was expected. 😉

Please sign in to comment.