refactor(Core/Game): restyle game lib with astyle (#3466)

This commit is contained in:
Kargatum
2020-10-12 15:08:15 +07:00
committed by GitHub
parent e99b526e17
commit a2b26272d2
338 changed files with 52196 additions and 50944 deletions

View File

@@ -61,7 +61,7 @@ struct LootGroupInvalidSelector : public acore::unary_function<LootStoreItem*, b
{
++foundDuplicates;
if (_proto->InventoryType == 0 && foundDuplicates == 3 && _proto->ItemId != 47242 /*Trophy of the Crusade*/) // Non-equippable items are limited to 3 drops
return true;
return true;
else if (_proto->InventoryType != 0 && foundDuplicates == 1) // Equippable item are limited to 1 drop
return true;
}
@@ -76,39 +76,39 @@ private:
class LootTemplate::LootGroup // A set of loot definitions for items (refs are not allowed)
{
public:
LootGroup() { }
~LootGroup();
public:
LootGroup() { }
~LootGroup();
void AddEntry(LootStoreItem* item); // Adds an entry to the group (at loading stage)
bool HasQuestDrop() const; // True if group includes at least 1 quest drop entry
bool HasQuestDropForPlayer(Player const* player) const;
// The same for active quests of the player
void Process(Loot& loot, Player const *player, LootStore const& lootstore, uint16 lootMode) const; // Rolls an item from the group (if any) and adds the item to the loot
float RawTotalChance() const; // Overall chance for the group (without equal chanced items)
float TotalChance() const; // Overall chance for the group
void AddEntry(LootStoreItem* item); // Adds an entry to the group (at loading stage)
bool HasQuestDrop() const; // True if group includes at least 1 quest drop entry
bool HasQuestDropForPlayer(Player const* player) const;
// The same for active quests of the player
void Process(Loot& loot, Player const* player, LootStore const& lootstore, uint16 lootMode) const; // Rolls an item from the group (if any) and adds the item to the loot
float RawTotalChance() const; // Overall chance for the group (without equal chanced items)
float TotalChance() const; // Overall chance for the group
void Verify(LootStore const& lootstore, uint32 id, uint8 group_id) const;
void CollectLootIds(LootIdSet& set) const;
void CheckLootRefs(LootTemplateMap const& store, LootIdSet* ref_set) const;
LootStoreItemList* GetExplicitlyChancedItemList() { return &ExplicitlyChanced; }
LootStoreItemList* GetEqualChancedItemList() { return &EqualChanced; }
void CopyConditions(ConditionList conditions);
private:
LootStoreItemList ExplicitlyChanced; // Entries with chances defined in DB
LootStoreItemList EqualChanced; // Zero chances - every entry takes the same chance
void Verify(LootStore const& lootstore, uint32 id, uint8 group_id) const;
void CollectLootIds(LootIdSet& set) const;
void CheckLootRefs(LootTemplateMap const& store, LootIdSet* ref_set) const;
LootStoreItemList* GetExplicitlyChancedItemList() { return &ExplicitlyChanced; }
LootStoreItemList* GetEqualChancedItemList() { return &EqualChanced; }
void CopyConditions(ConditionList conditions);
private:
LootStoreItemList ExplicitlyChanced; // Entries with chances defined in DB
LootStoreItemList EqualChanced; // Zero chances - every entry takes the same chance
LootStoreItem const* Roll(Loot& loot, Player const *player, LootStore const& store, uint16 lootMode) const; // Rolls an item from the group, returns NULL if all miss their chances
LootStoreItem const* Roll(Loot& loot, Player const* player, LootStore const& store, uint16 lootMode) const; // Rolls an item from the group, returns NULL if all miss their chances
// This class must never be copied - storing pointers
LootGroup(LootGroup const&);
LootGroup& operator=(LootGroup const&);
// This class must never be copied - storing pointers
LootGroup(LootGroup const&);
LootGroup& operator=(LootGroup const&);
};
//Remove all data and free all memory
void LootStore::Clear()
{
for (LootTemplateMap::const_iterator itr=m_LootTemplates.begin(); itr != m_LootTemplates.end(); ++itr)
for (LootTemplateMap::const_iterator itr = m_LootTemplates.begin(); itr != m_LootTemplates.end(); ++itr)
delete itr->second;
m_LootTemplates.clear();
}
@@ -173,7 +173,7 @@ uint32 LootStore::LoadLootTable()
}
// Looking for the template of the entry
// often entries are put together
// often entries are put together
if (m_LootTemplates.empty() || tab->first != entry)
{
// Searching the template (in case template Id changed)
@@ -190,8 +190,7 @@ uint32 LootStore::LoadLootTable()
// Adds current row to the template
tab->second->AddEntry(storeitem);
++count;
}
while (result->NextRow());
} while (result->NextRow());
Verify(); // Checks validity of the loot store
@@ -286,7 +285,7 @@ void LootStore::ReportNonExistingId(uint32 lootId, const char* ownerType, uint32
// Checks if the entry (quest, non-quest, reference) takes it's chance (at loot generation)
// RATE_DROP_ITEMS is no longer used for all types of entries
bool LootStoreItem::Roll(bool rate, Player const *player, Loot& loot, LootStore const& store) const
bool LootStoreItem::Roll(bool rate, Player const* player, Loot& loot, LootStore const& store) const
{
float _chance = chance;
@@ -296,13 +295,13 @@ bool LootStoreItem::Roll(bool rate, Player const *player, Loot& loot, LootStore
return true;
if (reference > 0) // reference case
return roll_chance_f(_chance* (rate ? sWorld->getRate(RATE_DROP_ITEM_REFERENCED) : 1.0f));
return roll_chance_f(_chance * (rate ? sWorld->getRate(RATE_DROP_ITEM_REFERENCED) : 1.0f));
ItemTemplate const* pProto = sObjectMgr->GetItemTemplate(itemid);
float qualityModifier = pProto && rate ? sWorld->getRate(qualityToRate[pProto->Quality]) : 1.0f;
return roll_chance_f(_chance*qualityModifier);
return roll_chance_f(_chance * qualityModifier);
}
// Checks correctness of values
@@ -338,7 +337,7 @@ bool LootStoreItem::IsValid(LootStore const& store, uint32 entry) const
if (chance != 0 && chance < 0.000001f) // loot with low chance
{
sLog->outErrorDb("Table '%s' Entry %d Item %d: low chance (%f) - skipped",
store.GetName(), entry, itemid, chance);
store.GetName(), entry, itemid, chance);
return false;
}
@@ -529,7 +528,7 @@ void Loot::FillNotNormalLootFor(Player* player, bool presentAtLooting)
if (i < items.size())
item = &items[i];
else
item = &quest_items[i-itemsSize];
item = &quest_items[i - itemsSize];
if (!item->is_looted && item->freeforall && item->AllowedForPlayer(player))
if (ItemTemplate const* proto = sObjectMgr->GetItemTemplate(item->itemid))
@@ -544,7 +543,7 @@ QuestItemList* Loot::FillFFALoot(Player* player)
for (uint8 i = 0; i < items.size(); ++i)
{
LootItem &item = items[i];
LootItem& item = items[i];
if (!item.is_looted && item.freeforall && item.AllowedForPlayer(player))
{
ql->push_back(QuestItem(i));
@@ -570,7 +569,7 @@ QuestItemList* Loot::FillQuestLoot(Player* player)
for (uint8 i = 0; i < quest_items.size(); ++i)
{
LootItem &item = quest_items[i];
LootItem& item = quest_items[i];
if (!item.is_looted && (item.AllowedForPlayer(player) || (item.follow_loot_rules && player->GetGroup() && ((player->GetGroup()->GetLootMethod() == MASTER_LOOT && player->GetGroup()->GetMasterLooterGuid() == player->GetGUID()) || player->GetGroup()->GetLootMethod() != MASTER_LOOT ))))
{
@@ -605,7 +604,7 @@ QuestItemList* Loot::FillNonQuestNonFFAConditionalLoot(Player* player, bool pres
for (uint8 i = 0; i < items.size(); ++i)
{
LootItem &item = items[i];
LootItem& item = items[i];
if (!item.is_looted && !item.freeforall && (item.AllowedForPlayer(player) || (item.follow_loot_rules && player->GetGroup() && ((player->GetGroup()->GetLootMethod() == MASTER_LOOT && player->GetGroup()->GetMasterLooterGuid() == player->GetGUID()) || player->GetGroup()->GetLootMethod() != MASTER_LOOT ))))
{
if (presentAtLooting)
@@ -690,7 +689,7 @@ void Loot::NotifyQuestItemRemoved(uint8 questIndex)
break;
if (j < pql.size())
player->SendNotifyLootItemRemoved(items.size()+j);
player->SendNotifyLootItemRemoved(items.size() + j);
}
}
else
@@ -711,7 +710,7 @@ void Loot::generateMoneyLoot(uint32 minAmount, uint32 maxAmount)
}
}
LootItem* Loot::LootItemInSlot(uint32 lootSlot, Player* player, QuestItem* *qitem, QuestItem* *ffaitem, QuestItem* *conditem)
LootItem* Loot::LootItemInSlot(uint32 lootSlot, Player* player, QuestItem * *qitem, QuestItem * *ffaitem, QuestItem * *conditem)
{
LootItem* item = nullptr;
bool is_looted = true;
@@ -739,10 +738,10 @@ LootItem* Loot::LootItemInSlot(uint32 lootSlot, Player* player, QuestItem* *qite
QuestItemMap::const_iterator itr = PlayerFFAItems.find(player->GetGUIDLow());
if (itr != PlayerFFAItems.end())
{
for (QuestItemList::const_iterator iter=itr->second->begin(); iter!= itr->second->end(); ++iter)
for (QuestItemList::const_iterator iter = itr->second->begin(); iter != itr->second->end(); ++iter)
if (iter->index == lootSlot)
{
QuestItem* ffaitem2 = (QuestItem*)&(*iter);
QuestItem* ffaitem2 = (QuestItem*) & (*iter);
if (ffaitem)
*ffaitem = ffaitem2;
is_looted = ffaitem2->is_looted;
@@ -755,11 +754,11 @@ LootItem* Loot::LootItemInSlot(uint32 lootSlot, Player* player, QuestItem* *qite
QuestItemMap::const_iterator itr = PlayerNonQuestNonFFAConditionalItems.find(player->GetGUIDLow());
if (itr != PlayerNonQuestNonFFAConditionalItems.end())
{
for (QuestItemList::const_iterator iter=itr->second->begin(); iter!= itr->second->end(); ++iter)
for (QuestItemList::const_iterator iter = itr->second->begin(); iter != itr->second->end(); ++iter)
{
if (iter->index == lootSlot)
{
QuestItem* conditem2 = (QuestItem*)&(*iter);
QuestItem* conditem2 = (QuestItem*) & (*iter);
if (conditem)
*conditem = conditem2;
is_looted = conditem2->is_looted;
@@ -792,7 +791,7 @@ bool Loot::hasItemFor(Player* player) const
QuestItemList* q_list = q_itr->second;
for (QuestItemList::const_iterator qi = q_list->begin(); qi != q_list->end(); ++qi)
{
const LootItem &item = quest_items[qi->index];
const LootItem& item = quest_items[qi->index];
if (!qi->is_looted && !item.is_looted)
return true;
}
@@ -805,7 +804,7 @@ bool Loot::hasItemFor(Player* player) const
QuestItemList* ffa_list = ffa_itr->second;
for (QuestItemList::const_iterator fi = ffa_list->begin(); fi != ffa_list->end(); ++fi)
{
const LootItem &item = items[fi->index];
const LootItem& item = items[fi->index];
if (!fi->is_looted && !item.is_looted)
return true;
}
@@ -818,7 +817,7 @@ bool Loot::hasItemFor(Player* player) const
QuestItemList* conditional_list = nn_itr->second;
for (QuestItemList::const_iterator ci = conditional_list->begin(); ci != conditional_list->end(); ++ci)
{
const LootItem &item = items[ci->index];
const LootItem& item = items[ci->index];
if (!ci->is_looted && !item.is_looted)
return true;
}
@@ -859,7 +858,7 @@ ByteBuffer& operator<<(ByteBuffer& b, LootView const& lv)
return b; // nothing output more
}
Loot &l = lv.loot;
Loot& l = lv.loot;
uint8 itemsShown = 0;
@@ -873,97 +872,97 @@ ByteBuffer& operator<<(ByteBuffer& b, LootView const& lv)
case GROUP_PERMISSION:
case MASTER_PERMISSION:
case RESTRICTED_PERMISSION:
{
// if you are not the round-robin group looter, you can only see
// blocked rolled items and quest items, and !ffa items
for (uint8 i = 0; i < l.items.size(); ++i)
{
if (!l.items[i].is_looted && !l.items[i].freeforall && l.items[i].conditions.empty() && l.items[i].AllowedForPlayer(lv.viewer))
// if you are not the round-robin group looter, you can only see
// blocked rolled items and quest items, and !ffa items
for (uint8 i = 0; i < l.items.size(); ++i)
{
uint8 slot_type = 0;
if (l.items[i].is_blocked) // for ML & restricted is_blocked = !is_underthreshold
if (!l.items[i].is_looted && !l.items[i].freeforall && l.items[i].conditions.empty() && l.items[i].AllowedForPlayer(lv.viewer))
{
switch (lv.permission)
uint8 slot_type = 0;
if (l.items[i].is_blocked) // for ML & restricted is_blocked = !is_underthreshold
{
case GROUP_PERMISSION:
slot_type = LOOT_SLOT_TYPE_ROLL_ONGOING;
break;
case MASTER_PERMISSION:
switch (lv.permission)
{
if (lv.viewer->GetGroup())
{
if (lv.viewer->GetGroup()->GetMasterLooterGuid() == lv.viewer->GetGUID())
slot_type = LOOT_SLOT_TYPE_MASTER;
else
slot_type = LOOT_SLOT_TYPE_LOCKED;
}
break;
case GROUP_PERMISSION:
slot_type = LOOT_SLOT_TYPE_ROLL_ONGOING;
break;
case MASTER_PERMISSION:
{
if (lv.viewer->GetGroup())
{
if (lv.viewer->GetGroup()->GetMasterLooterGuid() == lv.viewer->GetGUID())
slot_type = LOOT_SLOT_TYPE_MASTER;
else
slot_type = LOOT_SLOT_TYPE_LOCKED;
}
break;
}
case RESTRICTED_PERMISSION:
slot_type = LOOT_SLOT_TYPE_LOCKED;
break;
default:
continue;
}
case RESTRICTED_PERMISSION:
slot_type = LOOT_SLOT_TYPE_LOCKED;
break;
default:
}
else if (l.items[i].rollWinnerGUID)
{
if (l.items[i].rollWinnerGUID == lv.viewer->GetGUID())
slot_type = LOOT_SLOT_TYPE_OWNER;
else
continue;
}
}
else if (l.items[i].rollWinnerGUID)
{
if (l.items[i].rollWinnerGUID == lv.viewer->GetGUID())
slot_type = LOOT_SLOT_TYPE_OWNER;
else if (l.roundRobinPlayer == 0 || lv.viewer->GetGUID() == l.roundRobinPlayer || !l.items[i].is_underthreshold)
{
// no round robin owner or he has released the loot
// or it IS the round robin group owner
// => item is lootable
slot_type = LOOT_SLOT_TYPE_ALLOW_LOOT;
}
else
// item shall not be displayed.
continue;
}
else if (l.roundRobinPlayer == 0 || lv.viewer->GetGUID() == l.roundRobinPlayer || !l.items[i].is_underthreshold)
{
// no round robin owner or he has released the loot
// or it IS the round robin group owner
// => item is lootable
slot_type = LOOT_SLOT_TYPE_ALLOW_LOOT;
}
else
// item shall not be displayed.
continue;
b << uint8(i) << l.items[i];
b << uint8(slot_type);
++itemsShown;
b << uint8(i) << l.items[i];
b << uint8(slot_type);
++itemsShown;
}
}
break;
}
break;
}
case ROUND_ROBIN_PERMISSION:
{
for (uint8 i = 0; i < l.items.size(); ++i)
{
if (!l.items[i].is_looted && !l.items[i].freeforall && l.items[i].conditions.empty() && l.items[i].AllowedForPlayer(lv.viewer))
for (uint8 i = 0; i < l.items.size(); ++i)
{
if (l.roundRobinPlayer != 0 && lv.viewer->GetGUID() != l.roundRobinPlayer)
// item shall not be displayed.
continue;
if (!l.items[i].is_looted && !l.items[i].freeforall && l.items[i].conditions.empty() && l.items[i].AllowedForPlayer(lv.viewer))
{
if (l.roundRobinPlayer != 0 && lv.viewer->GetGUID() != l.roundRobinPlayer)
// item shall not be displayed.
continue;
b << uint8(i) << l.items[i];
b << uint8(LOOT_SLOT_TYPE_ALLOW_LOOT);
++itemsShown;
b << uint8(i) << l.items[i];
b << uint8(LOOT_SLOT_TYPE_ALLOW_LOOT);
++itemsShown;
}
}
break;
}
break;
}
case ALL_PERMISSION:
case OWNER_PERMISSION:
{
uint8 slot_type = lv.permission == OWNER_PERMISSION ? LOOT_SLOT_TYPE_OWNER : LOOT_SLOT_TYPE_ALLOW_LOOT;
for (uint8 i = 0; i < l.items.size(); ++i)
{
if (!l.items[i].is_looted && !l.items[i].freeforall && l.items[i].conditions.empty() && l.items[i].AllowedForPlayer(lv.viewer))
uint8 slot_type = lv.permission == OWNER_PERMISSION ? LOOT_SLOT_TYPE_OWNER : LOOT_SLOT_TYPE_ALLOW_LOOT;
for (uint8 i = 0; i < l.items.size(); ++i)
{
b << uint8(i) << l.items[i];
b << uint8(slot_type);
++itemsShown;
if (!l.items[i].is_looted && !l.items[i].freeforall && l.items[i].conditions.empty() && l.items[i].AllowedForPlayer(lv.viewer))
{
b << uint8(i) << l.items[i];
b << uint8(slot_type);
++itemsShown;
}
}
break;
}
break;
}
default:
return b;
}
@@ -980,7 +979,7 @@ ByteBuffer& operator<<(ByteBuffer& b, LootView const& lv)
QuestItemList* q_list = q_itr->second;
for (QuestItemList::const_iterator qi = q_list->begin(); qi != q_list->end(); ++qi)
{
LootItem &item = l.quest_items[qi->index];
LootItem& item = l.quest_items[qi->index];
if (!qi->is_looted && !item.is_looted)
{
b << uint8(l.items.size() + (qi - q_list->begin()));
@@ -1023,7 +1022,7 @@ ByteBuffer& operator<<(ByteBuffer& b, LootView const& lv)
QuestItemList* ffa_list = ffa_itr->second;
for (QuestItemList::const_iterator fi = ffa_list->begin(); fi != ffa_list->end(); ++fi)
{
LootItem &item = l.items[fi->index];
LootItem& item = l.items[fi->index];
if (!fi->is_looted && !item.is_looted)
{
b << uint8(fi->index);
@@ -1042,7 +1041,7 @@ ByteBuffer& operator<<(ByteBuffer& b, LootView const& lv)
QuestItemList* conditional_list = nn_itr->second;
for (QuestItemList::const_iterator ci = conditional_list->begin(); ci != conditional_list->end(); ++ci)
{
LootItem &item = l.items[ci->index];
LootItem& item = l.items[ci->index];
if (!ci->is_looted && !item.is_looted)
{
b << uint8(ci->index);
@@ -1051,22 +1050,22 @@ ByteBuffer& operator<<(ByteBuffer& b, LootView const& lv)
{
switch (lv.permission)
{
case MASTER_PERMISSION:
b << uint8(LOOT_SLOT_TYPE_MASTER);
break;
case RESTRICTED_PERMISSION:
b << (item.is_blocked ? uint8(LOOT_SLOT_TYPE_LOCKED) : uint8(slotType));
break;
case GROUP_PERMISSION:
case ROUND_ROBIN_PERMISSION:
if (!item.is_blocked)
b << uint8(LOOT_SLOT_TYPE_ALLOW_LOOT);
else
b << uint8(LOOT_SLOT_TYPE_ROLL_ONGOING);
break;
default:
b << uint8(slotType);
break;
case MASTER_PERMISSION:
b << uint8(LOOT_SLOT_TYPE_MASTER);
break;
case RESTRICTED_PERMISSION:
b << (item.is_blocked ? uint8(LOOT_SLOT_TYPE_LOCKED) : uint8(slotType));
break;
case GROUP_PERMISSION:
case ROUND_ROBIN_PERMISSION:
if (!item.is_blocked)
b << uint8(LOOT_SLOT_TYPE_ALLOW_LOOT);
else
b << uint8(LOOT_SLOT_TYPE_ROLL_ONGOING);
break;
default:
b << uint8(slotType);
break;
}
}
else if (!item.freeforall)
@@ -1113,7 +1112,7 @@ void LootTemplate::LootGroup::AddEntry(LootStoreItem* item)
}
// Rolls an item from the group, returns NULL if all miss their chances
LootStoreItem const* LootTemplate::LootGroup::Roll(Loot& loot, Player const *player, LootStore const& store, uint16 lootMode) const
LootStoreItem const* LootTemplate::LootGroup::Roll(Loot& loot, Player const* player, LootStore const& store, uint16 lootMode) const
{
LootStoreItemList possibleLoot = ExplicitlyChanced;
possibleLoot.remove_if(LootGroupInvalidSelector(loot, lootMode));
@@ -1126,7 +1125,7 @@ LootStoreItem const* LootTemplate::LootGroup::Roll(Loot& loot, Player const *pla
{
LootStoreItem* item = *itr;
float chance = item->chance;
sScriptMgr->OnItemRoll(player, item, chance, loot, store);
if (chance >= 100.0f)
@@ -1184,7 +1183,7 @@ void LootTemplate::LootGroup::CopyConditions(ConditionList /*conditions*/)
}
// Rolls an item from the group (if any takes its chance) and adds the item to the loot
void LootTemplate::LootGroup::Process(Loot& loot, Player const *player, LootStore const& store, uint16 lootMode) const
void LootTemplate::LootGroup::Process(Loot& loot, Player const* player, LootStore const& store, uint16 lootMode) const
{
if (LootStoreItem const* item = Roll(loot, player, store, lootMode))
loot.AddItem(*item);
@@ -1195,7 +1194,7 @@ float LootTemplate::LootGroup::RawTotalChance() const
{
float result = 0;
for (LootStoreItemList::const_iterator i=ExplicitlyChanced.begin(); i != ExplicitlyChanced.end(); ++i)
for (LootStoreItemList::const_iterator i = ExplicitlyChanced.begin(); i != ExplicitlyChanced.end(); ++i)
if (!(*i)->needs_quest)
result += (*i)->chance;
@@ -1315,7 +1314,7 @@ void LootTemplate::CopyConditions(LootItem* li) const
void LootTemplate::Process(Loot& loot, LootStore const& store, uint16 lootMode, Player const* player, uint8 groupId) const
{
bool rate = store.IsRatesAllowed();
if (groupId) // Group reference uses own processing of the group
{
if (groupId > Groups.size())
@@ -1348,7 +1347,9 @@ void LootTemplate::Process(Loot& loot, LootStore const& store, uint16 lootMode,
sScriptMgr->OnAfterRefCount(player, loot, rate, lootMode, item, maxcount, store);
for (uint32 loop = 0; loop < maxcount; ++loop) // Ref multiplicator
Referenced->Process(loot, store, lootMode, player, item->groupid);
} else {
}
else
{
// Plain entries (not a reference, not grouped)
sScriptMgr->OnBeforeDropAddItem(player, loot, rate, lootMode, item, store);
loot.AddItem(*item); // Chance is already checked, just add
@@ -1372,7 +1373,7 @@ bool LootTemplate::HasQuestDrop(LootTemplateMap const& store, uint8 groupId) con
if (!Groups[groupId - 1])
return false;
return Groups[groupId-1]->HasQuestDrop();
return Groups[groupId - 1]->HasQuestDrop();
}
for (LootStoreItemList::const_iterator i = Entries.begin(); i != Entries.end(); ++i)