diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp index 55384e9226..bdc7bffea7 100644 --- a/src/server/game/Entities/Creature/Creature.cpp +++ b/src/server/game/Entities/Creature/Creature.cpp @@ -276,8 +276,7 @@ m_formation(nullptr), m_triggerJustAppeared(true), m_respawnCompatibilityMode(fa { m_valuesCount = UNIT_END; - for (uint8 i = 0; i < MAX_CREATURE_SPELLS; ++i) - m_spells[i] = 0; + m_spells = { }; DisableReputationGain = false; diff --git a/src/server/game/Entities/Creature/Creature.h b/src/server/game/Entities/Creature/Creature.h index c465b52b13..cc9f3c1fb3 100644 --- a/src/server/game/Entities/Creature/Creature.h +++ b/src/server/game/Entities/Creature/Creature.h @@ -218,7 +218,7 @@ class TC_GAME_API Creature : public Unit, public GridObject, public Ma SpellInfo const* reachWithSpellAttack(Unit* victim); SpellInfo const* reachWithSpellCure(Unit* victim); - uint32 m_spells[MAX_CREATURE_SPELLS]; + std::array m_spells; bool CanStartAttack(Unit const* u, bool force) const; float GetAttackDistance(Unit const* player) const; diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index 9906a4be65..ea251cfe3d 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -184,9 +184,7 @@ Player::Player(WorldSession* session): Unit(true) m_nextSave = sWorld->getIntConfig(CONFIG_INTERVAL_SAVE); - _resurrectionData = nullptr; - - memset(m_items, 0, sizeof(Item*)*PLAYER_SLOTS_COUNT); + m_items.fill(nullptr); m_social = nullptr; @@ -216,21 +214,17 @@ Player::Player(WorldSession* session): Unit(true) m_cinematic = 0; m_movie = 0; - PlayerTalkClass = new PlayerMenu(GetSession()); + PlayerTalkClass = std::make_unique(GetSession()); m_currentBuybackSlot = BUYBACK_SLOT_START; m_DailyQuestChanged = false; m_lastDailyQuestTime = 0; // Init rune flags - for (uint8 i = 0; i < MAX_RUNES; ++i) - { - SetRuneTimer(i, 0xFFFFFFFF); - SetLastRuneGraceTimer(i, 0); - } + m_runeGraceCooldown.fill(0xFFFFFFFF); + m_lastRuneGraceTimers = { }; - for (uint8 i=0; i < MAX_TIMERS; i++) - m_MirrorTimer[i] = DISABLED_MIRROR_TIMER; + m_MirrorTimer.fill(DISABLED_MIRROR_TIMER); m_MirrorTimerFlags = UNDERWATER_NONE; m_MirrorTimerFlagsLast = UNDERWATER_NONE; @@ -249,8 +243,7 @@ Player::Player(WorldSession* session): Unit(true) m_logintime = GameTime::GetGameTime(); m_Last_tick = m_logintime; - m_Played_time[PLAYED_TIME_TOTAL] = 0; - m_Played_time[PLAYED_TIME_LEVEL] = 0; + m_Played_time = { }; m_WeaponProficiency = 0; m_ArmorProficiency = 0; m_canParry = false; @@ -289,16 +282,12 @@ Player::Player(WorldSession* session): Unit(true) m_raidMapDifficulty = RAID_DIFFICULTY_10MAN_NORMAL; m_lastPotionId = 0; - _talentMgr = new PlayerTalentInfo(); + _talentMgr = std::make_unique(); - for (uint8 i = 0; i < BASEMOD_END; ++i) - { - m_auraBaseFlatMod[i] = 0.0f; - m_auraBasePctMod[i] = 1.0f; - } + m_auraBaseFlatMod.fill(0.0f); + m_auraBasePctMod.fill(1.0f); - for (uint8 i = 0; i < MAX_COMBAT_RATING; i++) - m_baseRatingValue[i] = 0; + m_baseRatingValue = { }; m_baseSpellPower = 0; m_baseManaRegen = 0; @@ -318,7 +307,6 @@ Player::Player(WorldSession* session): Unit(true) m_seer = this; - m_homebindMapId = 0; m_homebindAreaId = 0; m_homebindX = 0; @@ -327,12 +315,8 @@ Player::Player(WorldSession* session): Unit(true) m_contestedPvPTimer = 0; - m_declinedname = nullptr; - m_isActive = true; - m_runes = nullptr; - m_lastFallTime = 0; m_lastFallZ = 0; @@ -363,14 +347,13 @@ Player::Player(WorldSession* session): Unit(true) _maxPersonalArenaRate = 0; - memset(_voidStorageItems, 0, VOID_STORAGE_MAX_SLOT * sizeof(VoidStorageItem*)); + _voidStorageItems.fill(nullptr); - _cinematicMgr = new CinematicMgr(this); - - m_achievementMgr = new AchievementMgr(this); - m_reputationMgr = new ReputationMgr(this); + _cinematicMgr = std::make_unique(this); + m_achievementMgr = std::make_unique>(this); + m_reputationMgr = std::make_unique(this); _hasValidLFGLeavePoint = false; - _archaeology = new Archaeology(this); + _archaeology = std::make_unique(this); m_petScalingSynchTimer.Reset(1000); m_groupUpdateTimer.Reset(5000); } @@ -384,8 +367,6 @@ Player::~Player() for (uint8 i = 0; i < PLAYER_SLOTS_COUNT; ++i) delete m_items[i]; - delete _talentMgr; - //all mailed items should be deleted, also all mail should be deallocated for (PlayerMails::iterator itr = m_mail.begin(); itr != m_mail.end(); ++itr) delete *itr; @@ -393,19 +374,10 @@ Player::~Player() for (ItemMap::iterator iter = mMitems.begin(); iter != mMitems.end(); ++iter) delete iter->second; //if item is duplicated... then server may crash ... but that item should be deallocated - delete PlayerTalkClass; - for (size_t x = 0; x < ItemSetEff.size(); x++) delete ItemSetEff[x]; - delete m_declinedname; - delete m_runes; - delete m_achievementMgr; - delete m_reputationMgr; - delete _cinematicMgr; - delete _archaeology; - - for (uint8 i = 0; i < VOID_STORAGE_MAX_SLOT; ++i) + for (size_t i = 0; i < _voidStorageItems.size(); ++i) delete _voidStorageItems[i]; for (uint8 i = 0; i < PlayerPetDataStore.size(); i++) @@ -446,8 +418,7 @@ bool Player::Create(ObjectGuid::LowType guidlow, CharacterCreateInfo* createInfo return false; } - for (uint8 i = 0; i < PLAYER_SLOTS_COUNT; i++) - m_items[i] = nullptr; + m_items.fill(nullptr); Relocate(info->positionX, info->positionY, info->positionZ, info->orientation); @@ -13321,10 +13292,8 @@ void Player::SendNewItem(Item* item, uint32 count, bool received, bool created, void Player::PrepareGossipMenu(WorldObject* source, uint32 menuId /*= 0*/, bool showQuests /*= false*/) { - PlayerMenu* menu = PlayerTalkClass; - menu->ClearMenus(); - - menu->GetGossipMenu().SetMenuId(menuId); + PlayerTalkClass->ClearMenus(); + PlayerTalkClass->GetGossipMenu().SetMenuId(menuId); GossipMenuItemsMapBounds menuItemBounds = sObjectMgr->GetGossipMenuItemsMapBounds(menuId); @@ -13461,8 +13430,8 @@ void Player::PrepareGossipMenu(WorldObject* source, uint32 menuId /*= 0*/, bool } } - menu->GetGossipMenu().AddMenuItem(itr->second.OptionID, itr->second.OptionIcon, strOptionText, 0, itr->second.OptionType, strBoxText, itr->second.BoxMoney, itr->second.BoxCoded); - menu->GetGossipMenu().AddGossipMenuItemData(itr->second.OptionID, itr->second.ActionMenuID, itr->second.ActionPoiID); + PlayerTalkClass->GetGossipMenu().AddMenuItem(itr->second.OptionID, itr->second.OptionIcon, strOptionText, 0, itr->second.OptionType, strBoxText, itr->second.BoxMoney, itr->second.BoxCoded); + PlayerTalkClass->GetGossipMenu().AddGossipMenuItemData(itr->second.OptionID, itr->second.ActionMenuID, itr->second.ActionPoiID); } } } @@ -16211,8 +16180,7 @@ void Player::_LoadDeclinedNames(PreparedQueryResult result) if (!result) return; - delete m_declinedname; - m_declinedname = new DeclinedName; + m_declinedname = std::make_unique(); for (uint8 i = 0; i < MAX_DECLINED_NAME_CASES; ++i) m_declinedname->name[i] = (*result)[i].GetString(); } @@ -19439,7 +19407,7 @@ void Player::_SaveVoidStorage(CharacterDatabaseTransaction& trans) CharacterDatabasePreparedStatement* stmt = nullptr; uint32 lowGuid = GetGUID().GetCounter(); - for (uint8 i = 0; i < VOID_STORAGE_MAX_SLOT; ++i) + for (size_t i = 0; i < _voidStorageItems.size(); ++i) { if (!_voidStorageItems[i]) // unused item { @@ -21988,7 +21956,7 @@ void Player::UpdatePotionCooldown(Spell* spell) void Player::SetResurrectRequestData(WorldObject const* caster, uint32 health, uint32 mana, uint32 appliedAura) { ASSERT(!IsResurrectRequested()); - _resurrectionData = new ResurrectionData(); + _resurrectionData = std::make_unique(); _resurrectionData->GUID = caster->GetGUID(); _resurrectionData->Location.WorldRelocate(*caster); _resurrectionData->Health = health; @@ -24844,7 +24812,7 @@ void Player::InitRunes() if (getClass() != CLASS_DEATH_KNIGHT) return; - m_runes = new Runes; + m_runes = std::make_unique(); m_runes->runeState = 0; m_runes->lastUsedRune = RUNE_BLOOD; @@ -26953,7 +26921,7 @@ void Player::UpdateArmorSpecialization() uint8 Player::GetNextVoidStorageFreeSlot() const { - for (uint8 i = 0; i < VOID_STORAGE_MAX_SLOT; ++i) + for (size_t i = 0; i < _voidStorageItems.size(); ++i) if (!_voidStorageItems[i]) // unused item return i; @@ -26964,7 +26932,7 @@ uint8 Player::GetNumOfVoidStorageFreeSlots() const { uint8 count = 0; - for (uint8 i = 0; i < VOID_STORAGE_MAX_SLOT; ++i) + for (size_t i = 0; i < _voidStorageItems.size(); ++i) if (!_voidStorageItems[i]) count++; @@ -27039,7 +27007,7 @@ VoidStorageItem* Player::GetVoidStorageItem(uint8 slot) const VoidStorageItem* Player::GetVoidStorageItem(uint64 id, uint8& slot) const { - for (uint8 i = 0; i < VOID_STORAGE_MAX_SLOT; ++i) + for (size_t i = 0; i < _voidStorageItems.size(); ++i) { if (_voidStorageItems[i] && _voidStorageItems[i]->ItemId == id) { diff --git a/src/server/game/Entities/Player/Player.h b/src/server/game/Entities/Player/Player.h index 377d54c53a..8e6741ab62 100644 --- a/src/server/game/Entities/Player/Player.h +++ b/src/server/game/Entities/Player/Player.h @@ -1108,7 +1108,7 @@ class TC_GAME_API Player : public Unit, public GridObject // Played Time Stuff time_t m_logintime; time_t m_Last_tick; - uint32 m_Played_time[MAX_PLAYED_TIME_INDEX]; + std::array m_Played_time; uint32 GetTotalPlayedTime() const { return m_Played_time[PLAYED_TIME_TOTAL]; } uint32 GetLevelPlayedTime() const { return m_Played_time[PLAYED_TIME_LEVEL]; } @@ -1281,7 +1281,7 @@ class TC_GAME_API Player : public Unit, public GridObject TradeData* GetTradeData() const { return m_trade; } void TradeCancel(bool sendback); - CinematicMgr* GetCinematicMgr() const { return _cinematicMgr; } + CinematicMgr* GetCinematicMgr() const { return _cinematicMgr.get(); } void UpdateEnchantTime(uint32 time); void UpdateSoulboundTradeItems(); @@ -1658,11 +1658,7 @@ class TC_GAME_API Player : public Unit, public GridObject void UpdatePotionCooldown(Spell* spell = nullptr); void SetResurrectRequestData(WorldObject const* caster, uint32 health, uint32 mana, uint32 appliedAura); - void ClearResurrectRequestData() - { - delete _resurrectionData; - _resurrectionData = nullptr; - } + void ClearResurrectRequestData() { _resurrectionData.reset(); } bool IsResurrectRequestedBy(ObjectGuid const& guid) const { @@ -2059,7 +2055,7 @@ class TC_GAME_API Player : public Unit, public GridObject void SendAurasForTarget(Unit* target) const; - PlayerMenu* PlayerTalkClass; + std::unique_ptr PlayerTalkClass; std::vector ItemSetEff; void SendLoot(ObjectGuid guid, LootType loot_type); @@ -2298,7 +2294,7 @@ class TC_GAME_API Player : public Unit, public GridObject bool isAllowedToLoot(Creature const* creature); - DeclinedName const* GetDeclinedNames() const { return m_declinedname; } + DeclinedName const* GetDeclinedNames() const { return m_declinedname.get(); } uint8 GetRunesState() const { return m_runes->runeState; } RuneType GetBaseRune(uint8 index) const { return RuneType(m_runes->runes[index].BaseRune); } @@ -2533,7 +2529,7 @@ class TC_GAME_API Player : public Unit, public GridObject uint32 m_atLoginFlags; - Item* m_items[PLAYER_SLOTS_COUNT]; + std::array m_items; uint32 m_currentBuybackSlot; PlayerCurrenciesMap _currencyStorage; @@ -2557,7 +2553,7 @@ class TC_GAME_API Player : public Unit, public GridObject /// Updates weekly conquest point cap (dynamic cap) void UpdateConquestCurrencyCap(uint32 currency); - VoidStorageItem* _voidStorageItems[VOID_STORAGE_MAX_SLOT]; + std::array _voidStorageItems; std::vector m_itemUpdateQueue; bool m_itemUpdateQueueBlocked; @@ -2579,13 +2575,13 @@ class TC_GAME_API Player : public Unit, public GridObject PlayerSpellMap m_spells; uint32 m_lastPotionId; // last used health/mana potion in combat, that block next potion use - PlayerTalentInfo* _talentMgr; + std::unique_ptr _talentMgr; ActionButtonList m_actionButtons; - float m_auraBaseFlatMod[BASEMOD_END]; - float m_auraBasePctMod[BASEMOD_END]; - int16 m_baseRatingValue[MAX_COMBAT_RATING]; + std::array m_auraBaseFlatMod; + std::array m_auraBasePctMod; + std::array m_baseRatingValue; uint32 m_baseSpellPower; uint32 m_baseManaRegen; uint32 m_baseHealthRegen; @@ -2597,7 +2593,7 @@ class TC_GAME_API Player : public Unit, public GridObject ItemDurationList m_itemDuration; GuidUnorderedSet m_itemSoulboundTradeable; - ResurrectionData* _resurrectionData; + std::unique_ptr _resurrectionData; WorldSession* m_session; JoinedChannelsList m_channels; @@ -2663,8 +2659,8 @@ class TC_GAME_API Player : public Unit, public GridObject WorldLocation m_recall_location; uint32 m_recall_instanceId; - DeclinedName* m_declinedname; - Runes* m_runes; + std::unique_ptr m_declinedname; + std::unique_ptr m_runes; EquipmentSetContainer _equipmentSets; bool CanAlwaysSee(WorldObject const* obj) const override; @@ -2689,7 +2685,7 @@ class TC_GAME_API Player : public Unit, public GridObject Item* _StoreItem(uint16 pos, Item* pItem, uint32 count, bool clone, bool update); Item* _LoadItem(CharacterDatabaseTransaction& trans, uint32 zoneId, uint32 timeDiff, Field* fields); - CinematicMgr* _cinematicMgr; + std::unique_ptr _cinematicMgr; GuidSet m_refundableItems; void SendRefundInfo(Item* item); @@ -2714,13 +2710,13 @@ class TC_GAME_API Player : public Unit, public GridObject uint32 m_lastFallTime; float m_lastFallZ; - int32 m_MirrorTimer[MAX_TIMERS]; + std::array m_MirrorTimer; uint8 m_MirrorTimerFlags; uint8 m_MirrorTimerFlagsLast; // Rune type / Rune timer - uint32 m_runeGraceCooldown[MAX_RUNES]; - uint32 m_lastRuneGraceTimers[MAX_RUNES]; + std::array m_runeGraceCooldown; + std::array m_lastRuneGraceTimers; // Current teleport data WorldLocation m_teleport_dest; @@ -2737,8 +2733,8 @@ class TC_GAME_API Player : public Unit, public GridObject uint32 m_temporaryUnsummonedPetNumber; uint32 m_oldpetspell; - AchievementMgr* m_achievementMgr; - ReputationMgr* m_reputationMgr; + std::unique_ptr> m_achievementMgr; + std::unique_ptr m_reputationMgr; uint32 m_ChampioningFaction; @@ -2757,7 +2753,7 @@ class TC_GAME_API Player : public Unit, public GridObject WorldLocation _corpseLocation; - Archaeology* _archaeology; + std::unique_ptr _archaeology; std::vector PlayerPetDataStore; diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index 93289261c9..419788873e 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -296,14 +296,14 @@ bool DispelableAura::RollDispel() const Unit::Unit(bool isWorldObject) : WorldObject(isWorldObject), m_lastSanctuaryTime(0), - LastCharmerGUID(), m_ControlledByPlayer(false), movespline(new Movement::MoveSpline()), + LastCharmerGUID(), m_ControlledByPlayer(false), movespline(std::make_unique()), m_procDeep(0), m_removedAurasCount(0), m_interruptMask(SpellAuraInterruptFlags::None), m_interruptMask2(SpellAuraInterruptFlags2::None), m_charmer(nullptr), m_charmed(nullptr), - i_motionMaster(new MotionMaster(this)), m_vehicle(nullptr), - m_vehicleKit(nullptr), m_unitTypeMask(UNIT_MASK_NONE), m_Diminishing(), + i_motionMaster(std::make_unique(this)), m_vehicle(nullptr), + m_vehicleKit(nullptr), m_unitTypeMask(UNIT_MASK_NONE), m_isEngaged(false), m_combatManager(this), m_threatManager(this), - i_AI(nullptr), m_aiLocked(false), m_spellHistory(new SpellHistory(this)), + i_AI(nullptr), m_aiLocked(false), m_spellHistory(std::make_unique(this)), _isIgnoringCombat(false) { m_objectType |= TYPEMASK_UNIT; @@ -311,12 +311,8 @@ Unit::Unit(bool isWorldObject) : m_updateFlag = UPDATEFLAG_LIVING; - m_attackTimer[BASE_ATTACK] = 0; - m_attackTimer[OFF_ATTACK] = 0; - m_attackTimer[RANGED_ATTACK] = 0; - m_modAttackSpeedPct[BASE_ATTACK] = 1.0f; - m_modAttackSpeedPct[OFF_ATTACK] = 1.0f; - m_modAttackSpeedPct[RANGED_ATTACK] = 1.0f; + m_attackTimer = { }; + m_modAttackSpeedPct.fill(1.0f); m_extraAttacks = 0; m_canDualWield = false; @@ -326,14 +322,7 @@ Unit::Unit(bool isWorldObject) : m_state = 0; m_deathState = ALIVE; - for (uint8 i = 0; i < CURRENT_MAX_SPELL; ++i) - m_currentSpells[i] = nullptr; - - for (uint8 i = 0; i < MAX_SUMMON_SLOT; ++i) - m_SummonSlot[i].Clear(); - - for (uint8 i = 0; i < MAX_GAMEOBJECT_SLOT; ++i) - m_ObjectSlot[i].Clear(); + m_currentSpells.fill(nullptr); m_auraUpdateIterator = m_ownedAuras.end(); @@ -356,8 +345,7 @@ Unit::Unit(bool isWorldObject) : m_weaponDamage[i][MAXDAMAGE] = BASE_MAXDAMAGE; } - for (uint8 i = 0; i < MAX_STATS; ++i) - m_createStats[i] = 0.0f; + m_createStats.fill(0.0f); m_attacking = nullptr; m_modMeleeHitChance = 0.0f; @@ -365,16 +353,11 @@ Unit::Unit(bool isWorldObject) : m_modSpellHitChance = 0.0f; m_baseSpellCritChance = 5; - for (uint8 i = 0; i < MAX_MOVE_TYPE; ++i) - m_speed_rate[i] = 1.0f; - - m_charmInfo = nullptr; + m_speed_rate.fill(1.0f); _gameClientMovingMe = nullptr; // remove aurastates allowing special moves - for (uint8 i = 0; i < MAX_REACTIVE; ++i) - m_reactiveTimer[i] = 0; - + m_reactiveTimer = { }; m_cleanupDone = false; m_duringRemoveFromWorld = false; @@ -384,8 +367,7 @@ Unit::Unit(bool isWorldObject) : _powerBarId = 0; - for (uint8 i = 0; i < MAX_POWERS_PER_CLASS; ++i) - _powerFraction[i] = 0; + _powerFraction.fill(0.0f); _powerUpdateTimer = GetPowerUpdateInterval(); _healthRegenerationTimer = UNIT_HEALTH_REGENERATION_INTERVAL; @@ -399,22 +381,19 @@ Unit::Unit(bool isWorldObject) : Unit::~Unit() { // set current spells as deletable - for (uint8 i = 0; i < CURRENT_MAX_SPELL; ++i) + for (size_t i = 0; i < m_currentSpells.size(); ++i) + { if (m_currentSpells[i]) { m_currentSpells[i]->SetReferencedFromCurrent(false); m_currentSpells[i] = nullptr; } + } m_Events.KillAllEvents(true); _DeleteRemovedAuras(); - delete i_motionMaster; - delete m_charmInfo; - delete movespline; - delete m_spellHistory; - ASSERT(!m_duringRemoveFromWorld); ASSERT(!m_attacking); ASSERT(m_attackers.empty()); @@ -9671,9 +9650,9 @@ void Unit::UpdateCharmAI() CharmInfo* Unit::InitCharmInfo() { if (!m_charmInfo) - m_charmInfo = new CharmInfo(this); + m_charmInfo = std::make_unique(this); - return m_charmInfo; + return m_charmInfo.get(); } void Unit::DeleteCharmInfo() @@ -9682,8 +9661,7 @@ void Unit::DeleteCharmInfo() return; m_charmInfo->RestoreState(); - delete m_charmInfo; - m_charmInfo = nullptr; + m_charmInfo.reset(); } CharmInfo::CharmInfo(Unit* unit) @@ -11763,7 +11741,7 @@ bool Unit::CreateVehicleKit(uint32 id, uint32 creatureEntry, bool loading /*= fa if (!vehInfo) return false; - m_vehicleKit = new Vehicle(this, vehInfo, creatureEntry); + m_vehicleKit = std::make_unique(this, vehInfo, creatureEntry); m_updateFlag |= UPDATEFLAG_VEHICLE; m_unitTypeMask |= UNIT_MASK_VEHICLE; @@ -11782,9 +11760,7 @@ void Unit::RemoveVehicleKit(bool onRemoveFromWorld /*= false*/) SendSetVehicleRecId(0); m_vehicleKit->Uninstall(); - delete m_vehicleKit; - - m_vehicleKit = nullptr; + m_vehicleKit.reset(); m_updateFlag &= ~UPDATEFLAG_VEHICLE; m_unitTypeMask &= ~UNIT_MASK_VEHICLE; diff --git a/src/server/game/Entities/Unit/Unit.h b/src/server/game/Entities/Unit/Unit.h index 399afc3426..ca975a34ce 100644 --- a/src/server/game/Entities/Unit/Unit.h +++ b/src/server/game/Entities/Unit/Unit.h @@ -1274,7 +1274,7 @@ class TC_GAME_API Unit : public WorldObject bool isPossessing() const; bool isPossessing(Unit* u) const; - CharmInfo* GetCharmInfo() { return m_charmInfo; } + CharmInfo* GetCharmInfo() { return m_charmInfo.get(); } CharmInfo* InitCharmInfo(); void DeleteCharmInfo(); @@ -1469,11 +1469,11 @@ class TC_GAME_API Unit : public WorldObject virtual bool HasSpellFocus(Spell const* /*focusSpell*/ = nullptr) const { return false; } virtual bool IsMovementPreventedByCasting() const; - SpellHistory* GetSpellHistory() { return m_spellHistory; } - SpellHistory const* GetSpellHistory() const { return m_spellHistory; } + SpellHistory* GetSpellHistory() { return m_spellHistory.get(); } + SpellHistory const* GetSpellHistory() const { return m_spellHistory.get(); } - ObjectGuid m_SummonSlot[MAX_SUMMON_SLOT]; - ObjectGuid m_ObjectSlot[MAX_GAMEOBJECT_SLOT]; + std::array m_SummonSlot; + std::array m_ObjectSlot; ShapeshiftForm GetShapeshiftForm() const { return ShapeshiftForm(GetByteValue(UNIT_FIELD_BYTES_2, UNIT_BYTES_2_OFFSET_SHAPESHIFT_FORM)); } void SetShapeshiftForm(ShapeshiftForm form); @@ -1487,7 +1487,7 @@ class TC_GAME_API Unit : public WorldObject float m_modSpellHitChance; int32 m_baseSpellCritChance; - float m_modAttackSpeedPct[3]; + std::array m_modAttackSpeedPct; // stat system void HandleStatFlatModifier(UnitMods unitMod, UnitModifierFlatType modifierType, float amount, bool apply); @@ -1654,8 +1654,8 @@ class TC_GAME_API Unit : public WorldObject // Sets the target of all stored AbstractPursuers to nullptr, allowing the involved movement generators to do safe nullptr checks void RemoveAllPursuers(); - MotionMaster* GetMotionMaster() { return i_motionMaster; } - MotionMaster const* GetMotionMaster() const { return i_motionMaster; } + MotionMaster* GetMotionMaster() { return i_motionMaster.get(); } + MotionMaster const* GetMotionMaster() const { return i_motionMaster.get(); } bool IsStopped() const { return !(HasUnitState(UNIT_STATE_MOVING)); } void StopMoving(); @@ -1719,7 +1719,7 @@ class TC_GAME_API Unit : public WorldObject ObjectGuid LastCharmerGUID; bool CreateVehicleKit(uint32 id, uint32 creatureEntry, bool loading = false); void RemoveVehicleKit(bool onRemoveFromWorld = false); - Vehicle* GetVehicleKit()const { return m_vehicleKit; } + Vehicle* GetVehicleKit()const { return m_vehicleKit.get(); } Vehicle* GetVehicle() const { return m_vehicle; } void SetVehicle(Vehicle* vehicle) { m_vehicle = vehicle; } bool IsOnVehicle(Unit const* vehicle) const; @@ -1782,7 +1782,7 @@ class TC_GAME_API Unit : public WorldObject virtual void SetTarget(ObjectGuid /*guid*/) = 0; // Movement info - Movement::MoveSpline * movespline; + std::unique_ptr movespline; int32 GetHighestExclusiveSameEffectSpellGroupValue(AuraEffect const* aurEff, AuraType auraType, bool checkMiscValue = false, int32 miscValue = 0) const; bool IsHighestExclusiveAura(Aura const* aura, bool removeOtherAuraApplications = false); @@ -1823,9 +1823,9 @@ class TC_GAME_API Unit : public WorldObject void _UpdateAutoRepeatSpell(); - uint32 m_attackTimer[MAX_ATTACK]; + std::array m_attackTimer; - float m_createStats[MAX_STATS]; + std::array m_createStats; AttackerSet m_attackers; Unit* m_attacking; @@ -1842,7 +1842,7 @@ class TC_GAME_API Unit : public WorldObject uint32 m_transform; - Spell* m_currentSpells[CURRENT_MAX_SPELL]; + std::array m_currentSpells; AuraMap m_ownedAuras; AuraApplicationMap m_appliedAuras; @@ -1863,25 +1863,25 @@ class TC_GAME_API Unit : public WorldObject bool m_canModifyStats; VisibleAuraMap m_visibleAuras; - float m_speed_rate[MAX_MOVE_TYPE]; + std::array m_speed_rate; Unit* m_charmer; // Unit that is charming ME Unit* m_charmed; // Unit that is being charmed BY ME - CharmInfo* m_charmInfo; + std::unique_ptr m_charmInfo; SharedVisionList m_sharedVision; GameClient* _gameClientMovingMe; - MotionMaster* i_motionMaster; + std::unique_ptr i_motionMaster; - uint32 m_reactiveTimer[MAX_REACTIVE]; + std::array m_reactiveTimer; Vehicle* m_vehicle; - Vehicle* m_vehicleKit; + std::unique_ptr m_vehicleKit; uint32 m_unitTypeMask; LiquidTypeEntry const* _lastLiquid; uint32 _powerBarId; - float _powerFraction[MAX_POWERS_PER_CLASS]; + std::array _powerFraction; int32 _powerUpdateTimer; int32 _healthRegenerationTimer; @@ -1925,7 +1925,7 @@ class TC_GAME_API Unit : public WorldObject uint32 m_state; // Even derived shouldn't modify TimeTrackerSmall m_splineSyncTimer; - DiminishingReturn m_Diminishing[DIMINISHING_MAX]; + std::array m_Diminishing; // Threat+combat management bool m_isEngaged; @@ -1950,7 +1950,7 @@ class TC_GAME_API Unit : public WorldObject uint32 _oldFactionId; ///< faction before charm bool _isWalkingBeforeCharm; ///< Are we walking before we were charmed? - SpellHistory* m_spellHistory; + std::unique_ptr m_spellHistory; PositionUpdateInfo _positionUpdateInfo; diff --git a/src/server/game/Entities/Vehicle/Vehicle.h b/src/server/game/Entities/Vehicle/Vehicle.h index 79796c994d..7149516eae 100644 --- a/src/server/game/Entities/Vehicle/Vehicle.h +++ b/src/server/game/Entities/Vehicle/Vehicle.h @@ -30,14 +30,10 @@ class VehicleJoinEvent; class TC_GAME_API Vehicle : public TransportBase { - protected: - friend bool Unit::CreateVehicleKit(uint32 id, uint32 creatureEntry, bool loading /*= false*/); + public: Vehicle(Unit* unit, VehicleEntry const* vehInfo, uint32 creatureEntry); - - friend void Unit::RemoveVehicleKit(bool onRemoveFromWorld /*= false*/); ~Vehicle(); - public: void Install(); void Uninstall(); void Reset(bool evading = false);