Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

Commit

Permalink
Core/Movement: implement creature movement info table to override mov…
Browse files Browse the repository at this point in the history
…ement speeds based on movement IDs

thx to @xvwyh for providing initial table data for the most common entries
  • Loading branch information
Ovahlord committed Feb 16, 2021
1 parent c20838c commit c3e9861
Show file tree
Hide file tree
Showing 10 changed files with 403 additions and 10 deletions.
280 changes: 280 additions & 0 deletions sql/updates/world/4.3.4/2021_02_05_01_world.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,280 @@
DROP TABLE IF EXISTS `creature_movement_info`;
CREATE TABLE `creature_movement_info` (
`MovementID` int(8) unsigned NOT NULL DEFAULT '0' COMMENT 'creature_template.movementId value',
`WalkSpeed` float unsigned DEFAULT NULL,
`RunSpeed` float unsigned DEFAULT NULL,
PRIMARY KEY (`MovementID`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


INSERT INTO `creature_movement_info`(`MovementID`,`WalkSpeed`,`RunSpeed`) VALUES
(1,0,5),
(41,0.4,0),
(42,0.5,0),
(43,1,0),
(44,1.5,0),
(45,2,0),
(46,2.25,0),
(47,2.5,0),
(48,3,0),
(49,3.3,0),
(50,3.5,0),
(51,4,0),
(52,4.5,0),
(53,5,0),
(54,6,0),
(55,7,0),
(56,NULL,NULL),
(57,8,0),
(58,10,0),
(59,20,0),
(60,0.01,0.01),
(61,0.5,0.5),
(62,0.7,0.7),
(63,0,1),
(64,1,1),
(65,1,1.5),
(66,1.5,1.5),
(67,1.75,1.75),
(68,0,2),
(69,1,2),
(70,2,2),
(71,0,2.5),
(72,2.5,2.5),
(73,0,3),
(74,2,3),
(75,2.5,3),
(76,3,3),
(77,3.3,3.3),
(78,NULL,3.5),
(79,3.5,3.5),
(80,0,4),
(81,1.6,4),
(82,2,4),
(83,3,4),
(84,4,4),
(85,NULL,4.4),
(86,4.5,4.5),
(87,NULL,NULL),
(88,0,5),
(89,1,5),
(90,2,5),
(91,3,5),
(92,3.5,5),
(93,4,5),
(94,5,5),
(95,0,5.3),
(96,0,5.5),
(97,3,5.5),
(98,5.5,5.5),
(99,5.8,5.8),
(100,0,6),
(101,1.8,6),
(102,2,6),
(103,3,6),
(104,4,6),
(105,5,6),
(106,6,6),
(107,NULL,NULL),
(108,NULL,6.2),
(109,NULL,6.25),
(110,0,6.5),
(111,5,6.5),
(112,3,6.9),
(113,0,7),
(114,2,7),
(115,3,7),
(116,4,7),
(117,5,7),
(118,7,7),
(119,2.7,7.2),
(120,4,7.5),
(121,0,8),
(122,1,8),
(123,2,8),
(124,3,8),
(125,4,8),
(126,4.5,8),
(127,5,8),
(128,6,8),
(129,8,8),
(130,0,8.5),
(131,4,8.5),
(132,5,8.5),
(133,0,9),
(134,4,9),
(135,5,9),
(136,6,9),
(137,7,9),
(138,9,9),
(139,30,9),
(140,0,9.7),
(141,4,9.7),
(142,5,9.7),
(143,NULL,NULL),
(144,0,10),
(145,1,10),
(146,2.4,10),
(147,3,10),
(148,3.2,10),
(149,3.5,10),
(150,4,10),
(151,5,10),
(152,6,10),
(153,6.5,10),
(154,7,10),
(155,8,10),
(156,10,10),
(157,0,11),
(158,3,11),
(159,4,11),
(160,6,11),
(161,7,11),
(162,11,11),
(163,0,11.5),
(164,0,12),
(165,3,12),
(166,3.75,12),
(167,4,12),
(168,4.5,12),
(169,5,12),
(170,6,12),
(171,7,12),
(172,8,12),
(173,10,12),
(174,12,12),
(175,30,12),
(176,0,13),
(177,4,13),
(178,5,13),
(179,8,13),
(180,0,14),
(181,2,14),
(182,3,14),
(183,4,14),
(184,5,14),
(185,6,14),
(186,7,14),
(187,8,14),
(188,0,15),
(189,3,15),
(190,4,15),
(191,5,15),
(192,6,15),
(193,7,15),
(194,8,15),
(195,9,15),
(196,10,15),
(197,15,15),
(198,30,15),
(199,0,16),
(200,4,16),
(201,5,16),
(202,6,16),
(203,7,16),
(204,8,16),
(205,12,16),
(206,16,16),
(207,0,17),
(208,5,17),
(209,9,17),
(210,0,18),
(211,3.5,18),
(212,4,18),
(213,6,18),
(214,7,18),
(215,8,18),
(216,10,18),
(217,18,18),
(218,0,19),
(219,8,19),
(220,0,20),
(221,4,20),
(222,5,20),
(223,6,20),
(224,7,20),
(225,8,20),
(226,9,20),
(227,10,20),
(228,12,20),
(229,15,20),
(230,16,20),
(231,20,20),
(232,NULL,21),
(233,10,21),
(234,20,21),
(235,30,21),
(236,0,22),
(237,6,22),
(238,NULL,NULL),
(239,12,22),
(240,15,22),
(241,NULL,24),
(242,8,24),
(243,10,24),
(244,12,24),
(245,24,24),
(246,NULL,25),
(247,3,25),
(248,9,25),
(249,10,25),
(250,12,25),
(251,25,25),
(252,NULL,NULL),
(253,NULL,27),
(254,10,28),
(255,14,28),
(256,15,28),
(257,16,28),
(258,20,28),
(259,0,30),
(260,10,30),
(261,12,30),
(262,15,30),
(263,NULL,NULL),
(265,30,30),
(266,20,33),
(267,3,35),
(268,12,35),
(269,0,40),
(270,20,40),
(271,0,45),
(272,50,50),
(273,NULL,60),
(274,1.25,NULL),
(321,7,12),
(341,7,12),
(381,5,10),
(401,NULL,7),
(421,4.5,7),
(441,0,10),
(481,6.5,6.5),
(501,0,7),
(521,NULL,NULL),
(541,NULL,10),
(561,NULL,NULL),
(602,NULL,80),
(641,7,20),
(661,4,10),
(701,3,6.5),
(721,3,10),
(741,5,12),
(761,NULL,10),
(801,4,4),
(821,2,2),
(841,0,8),
(861,13,13),
(862,15,15),
(864,17,17),
(866,0,3),
(867,NULL,NULL),
(868,1.5,8),
(869,NULL,NULL),
(870,4,4),
(872,1,1),
(873,0.4,0.4),
(875,0,9.5),
(884,NULL,NULL),
(885,2,3),
(888,2,2),
(894,9,18);
42 changes: 38 additions & 4 deletions src/server/game/Entities/Creature/Creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,10 +543,8 @@ bool Creature::InitEntry(uint32 entry, CreatureData const* data /*= nullptr*/)
SetFloatValue(UNIT_MOD_CAST_SPEED, 1.0f);
SetFloatValue(UNIT_MOD_CAST_HASTE, 1.0f);

SetSpeedRate(MOVE_WALK, cinfo->speed_walk);
SetSpeedRate(MOVE_RUN, cinfo->speed_run);
SetSpeedRate(MOVE_SWIM, 1.0f); // using 1.0 rate
SetSpeedRate(MOVE_FLIGHT, 1.0f); // using 1.0 rate
InitializeCreatureMovementInfo(cinfo->movementId);
InitializeMovementSpeeds();

// Will set UNIT_FIELD_BOUNDINGRADIUS and UNIT_FIELD_COMBATREACH
SetObjectScale(GetNativeObjectScale());
Expand Down Expand Up @@ -2752,6 +2750,42 @@ void Creature::RefreshSwimmingFlag(bool recheck)
SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SWIMMING);
}

void Creature::InitializeCreatureMovementInfo(uint32 movementId)
{
if (CreatureMovementInfoOverride const* movementInfoOverride = sObjectMgr->GetCreatureMovementInfoOverride(movementId))
{
if (movementInfoOverride->RunSpeed > 0.f)
{
_creatureMovementInfo.RunSpeed = movementInfoOverride->RunSpeed;
_creatureMovementInfo.HasRunSpeedOverriden = true;
}

if (movementInfoOverride->WalkSpeed > 0.f)
{
_creatureMovementInfo.WalkSpeed = movementInfoOverride->WalkSpeed;
_creatureMovementInfo.HasWalkSpeedOverriden = true;
}
}
}

void Creature::InitializeMovementSpeeds()
{
// This segment needs to be removed once model based speeds are implemented and movementIds fully added.
SetSpeedRate(MOVE_WALK, m_creatureInfo->speed_walk);
SetSpeedRate(MOVE_RUN, m_creatureInfo->speed_run);
SetSpeedRate(MOVE_SWIM, 1.0f); // using 1.0 rate
SetSpeedRate(MOVE_FLIGHT, 1.0f); // using 1.0 rate

// Todo: movement speeds by model

// Overridden movement speed values by movementId data
if (_creatureMovementInfo.HasRunSpeedOverriden)
SetSpeed(MOVE_RUN, _creatureMovementInfo.RunSpeed);

if (_creatureMovementInfo.HasWalkSpeedOverriden)
SetSpeed(MOVE_WALK, _creatureMovementInfo.WalkSpeed);
}

void Creature::AllLootRemovedFromCorpse()
{
if (loot.loot_type != LOOT_SKINNING && !IsPet() && GetCreatureTemplate()->SkinLootId && hasLootRecipient())
Expand Down
10 changes: 10 additions & 0 deletions src/server/game/Entities/Creature/Creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,8 @@ class TC_GAME_API Creature : public Unit, public GridObject<Creature>, public Ma
}
void RefreshSwimmingFlag(bool recheck = false);

CreatureMovementInfo const& GetCreatureMovementInfo() const { return _creatureMovementInfo; }

protected:
bool CreateFromProto(ObjectGuid::LowType guidlow, uint32 entry, CreatureData const* data = nullptr, uint32 vehId = 0);
bool InitEntry(uint32 entry, CreatureData const* data = nullptr);
Expand Down Expand Up @@ -428,6 +430,12 @@ class TC_GAME_API Creature : public Unit, public GridObject<Creature>, public Ma
bool IsInvisibleDueToDespawn() const override;
bool CanAlwaysSee(WorldObject const* obj) const override;

// Initializes run and walk speed override data based on movementId override values stored in `creature_movement_info` table
void InitializeCreatureMovementInfo(uint32 movementId);

// Initializes move speed fields based on template and override data
void InitializeMovementSpeeds();

private:
void ForcedDespawn(uint32 timeMSToDespawn = 0, Seconds forceRespawnTimer = 0s);
bool CheckNoGrayAggroConfig(uint32 playerLevel, uint32 creatureLevel) const; // No aggro from gray creatures
Expand Down Expand Up @@ -456,6 +464,8 @@ class TC_GAME_API Creature : public Unit, public GridObject<Creature>, public Ma
CreatureTextRepeatGroup m_textRepeat;

bool _isMissingSwimmingFlagOutOfCombat;

CreatureMovementInfo _creatureMovementInfo;
};

class TC_GAME_API AssistDelayEvent : public BasicEvent
Expand Down
10 changes: 10 additions & 0 deletions src/server/game/Entities/Creature/CreatureData.h
Original file line number Diff line number Diff line change
Expand Up @@ -382,4 +382,14 @@ struct VendorItemData

typedef std::unordered_map<uint32, float /*SparringHealthLimit*/> CreatureSparringTemplateMap;

struct CreatureMovementInfo
{
float WalkSpeed = 0.f;
float RunSpeed = 0.f;

bool HasRunSpeedOverriden = false;
bool HasWalkSpeedOverriden = false;
};


#endif // CreatureData_h__
Loading

0 comments on commit c3e9861

Please sign in to comment.