diff --git a/.clang-format b/.clang-format index 58fc781e001..2e0a78842d6 100644 --- a/.clang-format +++ b/.clang-format @@ -84,7 +84,8 @@ IndentGotoLabels: true IndentPPDirectives: BeforeHash IndentWidth: 4 IndentWrappedFunctionNames: false -#InsertNewlineAtEOF: true +InsertBraces: true +InsertNewlineAtEOF: true JavaScriptQuotes: Leave JavaScriptWrapImports: true KeepEmptyLinesAtTheStartOfBlocks: true diff --git a/.github/workflows/clang-lint.yml b/.github/workflows/clang-lint.yml index 3773d738e16..070fd5ea997 100644 --- a/.github/workflows/clang-lint.yml +++ b/.github/workflows/clang-lint.yml @@ -34,12 +34,12 @@ jobs: - name: Run clang format lint if: ${{ github.ref != 'refs/heads/main' }} - uses: DoozyX/clang-format-lint-action@v0.15 + uses: DoozyX/clang-format-lint-action@v0.16.2 with: source: "src" exclude: "src/protobuf" extensions: "cpp,hpp,h" - clangFormatVersion: 15 + clangFormatVersion: 16 inplace: true - name: Run add and commit diff --git a/src/canary_server.cpp b/src/canary_server.cpp index fff0cc4d9a3..0e1c2f78c91 100644 --- a/src/canary_server.cpp +++ b/src/canary_server.cpp @@ -364,4 +364,4 @@ void CanaryServer::modulesLoadHelper(bool loaded, std::string moduleName) { void CanaryServer::shutdown() { inject().shutdown(); -} \ No newline at end of file +} diff --git a/src/creatures/combat/condition.cpp b/src/creatures/combat/condition.cpp index 3f920d7454c..bd94d9f9883 100644 --- a/src/creatures/combat/condition.cpp +++ b/src/creatures/combat/condition.cpp @@ -1334,10 +1334,11 @@ bool ConditionManaShield::setParam(ConditionParam_t param, int32_t value) { uint32_t ConditionManaShield::getIcons() const { uint32_t icons = Condition::getIcons(); - if (manaShield != 0) + if (manaShield != 0) { icons |= ICON_NEWMANASHIELD; - else + } else { icons |= ICON_MANASHIELD; + } return icons; } diff --git a/src/creatures/monsters/monster.cpp b/src/creatures/monsters/monster.cpp index 2daa5dfaf77..8ff84789985 100644 --- a/src/creatures/monsters/monster.cpp +++ b/src/creatures/monsters/monster.cpp @@ -315,8 +315,9 @@ void Monster::addTarget(Creature* creature, bool pushFront /* = false*/) { } else { targetList.push_back(creature); } - if (!master && getFaction() != FACTION_DEFAULT && creature->getPlayer()) + if (!master && getFaction() != FACTION_DEFAULT && creature->getPlayer()) { totalPlayersOnScreen++; + } } } diff --git a/src/creatures/monsters/monster.hpp b/src/creatures/monsters/monster.hpp index 30d5eab8eb2..6e45a6ce5d6 100644 --- a/src/creatures/monsters/monster.hpp +++ b/src/creatures/monsters/monster.hpp @@ -88,14 +88,16 @@ class Monster final : public Creature { } Faction_t getFaction() const override { - if (master) + if (master) { return master->getFaction(); + } return mType->info.faction; } bool isEnemyFaction(Faction_t faction) const { - if (master && master->getMonster()) + if (master && master->getMonster()) { return master->getMonster()->isEnemyFaction(faction); + } return mType->info.enemyFactions.empty() ? false : mType->info.enemyFactions.find(faction) != mType->info.enemyFactions.end(); } diff --git a/src/creatures/players/imbuements/imbuements.cpp b/src/creatures/players/imbuements/imbuements.cpp index 99ec4d34326..6830f1bf6fb 100644 --- a/src/creatures/players/imbuements/imbuements.cpp +++ b/src/creatures/players/imbuements/imbuements.cpp @@ -240,8 +240,9 @@ bool Imbuements::loadFromXml(bool /* reloading */) { } else if (usenormalskill == 3) { imbuement.skills[skillId] = bonus; int32_t chance = 100; - if ((attr = childNode.attribute("chance"))) + if ((attr = childNode.attribute("chance"))) { chance = std::min(100, pugi::cast(attr.value())); + } imbuement.skills[skillId - 1] = chance; } diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index 35b8dc50336..ba0120af504 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -3110,10 +3110,11 @@ ReturnValue Player::queryAdd(int32_t index, const Thing &thing, uint32_t count, const Item* leftItem = inventory[CONST_SLOT_LEFT]; if (leftItem) { if ((leftItem->getSlotPosition() | slotPosition) & SLOTP_TWO_HAND) { - if (item->isQuiver() && leftItem->getWeaponType() == WEAPON_DISTANCE) + if (item->isQuiver() && leftItem->getWeaponType() == WEAPON_DISTANCE) { ret = RETURNVALUE_NOERROR; - else + } else { ret = RETURNVALUE_BOTHHANDSNEEDTOBEFREE; + } } else { ret = RETURNVALUE_NOERROR; } @@ -3472,8 +3473,9 @@ Cylinder* Player::queryDestination(int32_t &index, const Thing &thing, Item** de } void Player::addThing(int32_t index, Thing* thing) { - if (!thing) + if (!thing) { return /*RETURNVALUE_NOTPOSSIBLE*/; + } if (index < CONST_SLOT_FIRST || index > CONST_SLOT_LAST) { return /*RETURNVALUE_NOTPOSSIBLE*/; @@ -4123,8 +4125,9 @@ void Player::postRemoveNotification(Thing* thing, const Cylinder* newParent, int // i will keep this function so it can be reviewed bool Player::updateSaleShopList(const Item* item) { uint16_t itemId = item->getID(); - if (!itemId || !item) + if (!itemId || !item) { return true; + } g_dispatcher().addTask(std::bind(&Game::updatePlayerSaleItems, &g_game(), getID())); scheduledSaleUpdate = true; @@ -4148,8 +4151,9 @@ void Player::internalAddThing(Thing* thing) { } void Player::internalAddThing(uint32_t index, Thing* thing) { - if (!thing) + if (!thing) { return; + } Item* item = thing->getItem(); if (!item) { diff --git a/src/creatures/players/player.hpp b/src/creatures/players/player.hpp index c84a62f01b0..a3bde0ead5f 100644 --- a/src/creatures/players/player.hpp +++ b/src/creatures/players/player.hpp @@ -357,10 +357,11 @@ class Player final : public Creature, public Cylinder, public Bankable { int32_t actualDamage = getPerfectShotDamage(range); bool aboveZero = (actualDamage != 0); actualDamage += damage; - if (actualDamage == 0 && aboveZero) + if (actualDamage == 0 && aboveZero) { perfectShot.erase(range); - else + } else { perfectShot[range] = actualDamage; + } } int32_t getSpecializedMagicLevel(CombatType_t combat, bool useCharges = false) const; @@ -2367,19 +2368,21 @@ class Player final : public Creature, public Cylinder, public Bankable { } void setSlotBossId(uint8_t slotId, uint32_t bossId) { - if (slotId == 1) + if (slotId == 1) { bossIdSlotOne = bossId; - else + } else { bossIdSlotTwo = bossId; + } if (client) { client->parseSendBosstiarySlots(); } } uint32_t getSlotBossId(uint8_t slotId) const { - if (slotId == 1) + if (slotId == 1) { return bossIdSlotOne; - else + } else { return bossIdSlotTwo; + } } void addRemoveTime() { diff --git a/src/creatures/players/wheel/player_wheel.cpp b/src/creatures/players/wheel/player_wheel.cpp index b42ad073dfa..81197c8b3de 100644 --- a/src/creatures/players/wheel/player_wheel.cpp +++ b/src/creatures/players/wheel/player_wheel.cpp @@ -1252,16 +1252,21 @@ void PlayerWheel::printPlayerWheelMethodsBonusData(const PlayerWheelMethodsBonus g_logger().debug("Initializing print of WhelPlayerBonusData informations for player {}", m_player.getName()); g_logger().debug("Stats:"); - if (bonusData.stats.health > 0) + if (bonusData.stats.health > 0) { g_logger().debug(" health: {}", bonusData.stats.health); - if (bonusData.stats.mana > 0) + } + if (bonusData.stats.mana > 0) { g_logger().debug(" mana: {}", bonusData.stats.mana); - if (bonusData.stats.capacity > 0) + } + if (bonusData.stats.capacity > 0) { g_logger().debug(" capacity: {}", bonusData.stats.capacity); - if (bonusData.stats.damage > 0) + } + if (bonusData.stats.damage > 0) { g_logger().debug(" damage: {}", bonusData.stats.damage); - if (bonusData.stats.healing > 0) + } + if (bonusData.stats.healing > 0) { g_logger().debug(" healing: {}", bonusData.stats.healing); + } g_logger().debug("Resistance:"); for (size_t i = 0; i < bonusData.resistance.size(); ++i) { @@ -1278,65 +1283,90 @@ void PlayerWheel::printPlayerWheelMethodsBonusData(const PlayerWheelMethodsBonus } g_logger().debug("Skills:"); - if (bonusData.skills.melee > 0) + if (bonusData.skills.melee > 0) { g_logger().debug(" melee: {}", bonusData.skills.melee); - if (bonusData.skills.distance > 0) + } + if (bonusData.skills.distance > 0) { g_logger().debug(" distance: {}", bonusData.skills.distance); - if (bonusData.skills.magic > 0) + } + if (bonusData.skills.magic > 0) { g_logger().debug(" magic: {}", bonusData.skills.magic); + } g_logger().debug("Leech:"); - if (bonusData.leech.manaLeech > 0) + if (bonusData.leech.manaLeech > 0) { g_logger().debug(" manaLeech: {}", bonusData.leech.manaLeech); - if (bonusData.leech.lifeLeech > 0) + } + if (bonusData.leech.lifeLeech > 0) { g_logger().debug(" lifeLeech: {}", bonusData.leech.lifeLeech); + } g_logger().debug("Instant:"); - if (bonusData.instant.battleInstinct) + if (bonusData.instant.battleInstinct) { g_logger().debug(" battleInstinct: {}", bonusData.instant.battleInstinct); - if (bonusData.instant.battleHealing) + } + if (bonusData.instant.battleHealing) { g_logger().debug(" battleHealing: {}", bonusData.instant.battleHealing); - if (bonusData.instant.positionalTatics) + } + if (bonusData.instant.positionalTatics) { g_logger().debug(" positionalTatics: {}", bonusData.instant.positionalTatics); - if (bonusData.instant.ballisticMastery) + } + if (bonusData.instant.ballisticMastery) { g_logger().debug(" ballisticMastery: {}", bonusData.instant.ballisticMastery); - if (bonusData.instant.healingLink) + } + if (bonusData.instant.healingLink) { g_logger().debug(" healingLink: {}", bonusData.instant.healingLink); - if (bonusData.instant.runicMastery) + } + if (bonusData.instant.runicMastery) { g_logger().debug(" runicMastery: {}", bonusData.instant.runicMastery); - if (bonusData.instant.focusMastery) + } + if (bonusData.instant.focusMastery) { g_logger().debug(" focusMastery: {}", bonusData.instant.focusMastery); + } g_logger().debug("Stages:"); - if (bonusData.stages.combatMastery > 0) + if (bonusData.stages.combatMastery > 0) { g_logger().debug(" combatMastery: {}", bonusData.stages.combatMastery); - if (bonusData.stages.giftOfLife > 0) + } + if (bonusData.stages.giftOfLife > 0) { g_logger().debug(" giftOfLife: {}", bonusData.stages.giftOfLife); - if (bonusData.stages.divineEmpowerment > 0) + } + if (bonusData.stages.divineEmpowerment > 0) { g_logger().debug(" divineEmpowerment: {}", bonusData.stages.divineEmpowerment); - if (bonusData.stages.blessingOfTheGrove > 0) + } + if (bonusData.stages.blessingOfTheGrove > 0) { g_logger().debug(" blessingOfTheGrove: {}", bonusData.stages.blessingOfTheGrove); - if (bonusData.stages.drainBody > 0) + } + if (bonusData.stages.drainBody > 0) { g_logger().debug(" drainBody: {}", bonusData.stages.drainBody); - if (bonusData.stages.beamMastery > 0) + } + if (bonusData.stages.beamMastery > 0) { g_logger().debug(" beamMastery: {}", bonusData.stages.beamMastery); - if (bonusData.stages.twinBurst > 0) + } + if (bonusData.stages.twinBurst > 0) { g_logger().debug(" twinBurst: {}", bonusData.stages.twinBurst); - if (bonusData.stages.executionersThrow > 0) + } + if (bonusData.stages.executionersThrow > 0) { g_logger().debug(" executionersThrow: {}", bonusData.stages.executionersThrow); + } g_logger().debug("Avatar:"); - if (bonusData.avatar.light > 0) + if (bonusData.avatar.light > 0) { g_logger().debug(" light: {}", bonusData.avatar.light); - if (bonusData.avatar.nature > 0) + } + if (bonusData.avatar.nature > 0) { g_logger().debug(" nature: {}", bonusData.avatar.nature); - if (bonusData.avatar.steel > 0) + } + if (bonusData.avatar.steel > 0) { g_logger().debug(" steel: {}", bonusData.avatar.steel); - if (bonusData.avatar.storm > 0) + } + if (bonusData.avatar.storm > 0) { g_logger().debug(" storm: {}", bonusData.avatar.storm); + } - if (bonusData.mitigation > 0) + if (bonusData.mitigation > 0) { g_logger().debug("mitigation: {}", bonusData.mitigation); + } auto &spellsVector = bonusData.spells; if (!spellsVector.empty()) { diff --git a/src/database/databasetasks.cpp b/src/database/databasetasks.cpp index 9151b9c2ffe..ab401d91b23 100644 --- a/src/database/databasetasks.cpp +++ b/src/database/databasetasks.cpp @@ -24,15 +24,17 @@ DatabaseTasks &DatabaseTasks::getInstance() { void DatabaseTasks::execute(const std::string &query, std::function callback /* nullptr */) { threadPool.addLoad([this, query, callback]() { bool success = db.executeQuery(query); - if (callback != nullptr) + if (callback != nullptr) { g_dispatcher().addTask([callback, success]() { callback(nullptr, success); }); + } }); } void DatabaseTasks::store(const std::string &query, std::function callback /* nullptr */) { threadPool.addLoad([this, query, callback]() { DBResult_ptr result = db.storeQuery(query); - if (callback != nullptr) + if (callback != nullptr) { g_dispatcher().addTask([callback, result]() { callback(result, true); }); + } }); } diff --git a/src/game/game.cpp b/src/game/game.cpp index aa693b490c3..e408159a0d8 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -232,12 +232,14 @@ void Game::loadBoostedCreature() { if (!monsterlist.empty()) { std::vector monsters; for (const auto &[raceId, _name] : BestiaryList) { - if (raceId != oldRace) + if (raceId != oldRace) { monsters.emplace_back(raceId, _name); + } } - if (!monsters.empty()) + if (!monsters.empty()) { selectedMonster = monsters[normal_random(0, monsters.size() - 1)]; + } } if (selectedMonster.raceId == 0) { @@ -2609,8 +2611,9 @@ bool Game::handleFallbackLogic(const Player* player, Container*&lootContainer, C } Item* fallbackItem = player->getInventoryItem(CONST_SLOT_BACKPACK); - if (!fallbackItem || !fallbackItem->getContainer()) + if (!fallbackItem || !fallbackItem->getContainer()) { return false; + } lootContainer = fallbackItem->getContainer(); containerIterator = lootContainer->iterator(); @@ -4032,8 +4035,9 @@ void Game::playerStowItem(uint32_t playerId, const Position &pos, uint16_t itemI } Thing* thing = internalGetThing(player, pos, stackpos, itemId, STACKPOS_TOPDOWN_ITEM); - if (!thing) + if (!thing) { return; + } Item* item = thing->getItem(); if (!item || item->getID() != itemId || item->getItemCount() < count || item->isStoreItem()) { @@ -5965,10 +5969,11 @@ bool Game::combatBlockHit(CombatDamage &damage, Creature* attacker, Creature* ta int32_t distanceY = Position::getDistanceY(target->getPosition(), attacker->getPosition()); if (target->getMonster() || damage.primary.type != COMBAT_PHYSICALDAMAGE || primaryReflectPercent > 0 || std::max(distanceX, distanceY) < 2) { damageReflected.primary.value = std::ceil(damage.primary.value * primaryReflectPercent / 100.) + std::max(-static_cast(std::ceil(attacker->getMaxHealth() * 0.01)), std::max(damage.primary.value, -(static_cast(primaryReflectFlat)))); - if (targetPlayer) + if (targetPlayer) { damageReflected.primary.type = COMBAT_NEUTRALDAMAGE; - else + } else { damageReflected.primary.type = damage.primary.type; + } if (!damageReflected.exString.empty()) { damageReflected.exString += ", "; } @@ -5990,10 +5995,12 @@ bool Game::combatBlockHit(CombatDamage &damage, Creature* attacker, Creature* ta canHeal = true; } } - if (targetPlayer && attacker->getAbsorbPercent(damage.primary.type) != 0) + if (targetPlayer && attacker->getAbsorbPercent(damage.primary.type) != 0) { damageAbsorbMessage = true; - if (attacker->getPlayer() && attacker->getIncreasePercent(damage.primary.type) != 0) + } + if (attacker->getPlayer() && attacker->getIncreasePercent(damage.primary.type) != 0) { damageIncreaseMessage = true; + } damage.primary.value *= attacker->getBuff(BUFF_DAMAGEDEALT) / 100.; } damage.primary.value *= target->getBuff(BUFF_DAMAGERECEIVED) / 100.; @@ -6038,10 +6045,12 @@ bool Game::combatBlockHit(CombatDamage &damage, Creature* attacker, Creature* ta damageHeal.primary.value += std::ceil((damage.secondary.value) * (secondaryHealing / 100.)); canHeal = true; } - if (targetPlayer && attacker->getAbsorbPercent(damage.secondary.type) != 0) + if (targetPlayer && attacker->getAbsorbPercent(damage.secondary.type) != 0) { damageAbsorbMessage = true; - if (attacker->getPlayer() && attacker->getIncreasePercent(damage.secondary.type) != 0) + } + if (attacker->getPlayer() && attacker->getIncreasePercent(damage.secondary.type) != 0) { damageIncreaseMessage = true; + } damage.secondary.value *= attacker->getBuff(BUFF_DAMAGEDEALT) / 100.; } damage.secondary.value *= target->getBuff(BUFF_DAMAGERECEIVED) / 100.; @@ -6054,8 +6063,9 @@ bool Game::combatBlockHit(CombatDamage &damage, Creature* attacker, Creature* ta secondaryBlockType = BLOCK_NONE; } - if (damage.primary.type == COMBAT_HEALING) + if (damage.primary.type == COMBAT_HEALING) { damage.primary.value *= target->getBuff(BUFF_HEALINGRECEIVED) / 100.; + } if (damageAbsorbMessage) { if (!damage.exString.empty()) { @@ -6479,8 +6489,9 @@ bool Game::combatChangeHealth(Creature* attacker, Creature* target, CombatDamage } if (damageX != 0 || damageY != 0) { int32_t totalDamage = damageX; - if (distanceX != distanceY) + if (distanceX != distanceY) { totalDamage += damageY; + } damage.primary.value += totalDamage; if (!damage.exString.empty()) { damage.exString += ", "; @@ -9375,8 +9386,9 @@ uint32_t Game::makeInfluencedMonster() { return 0; } - if (forgeableMonsters.empty()) + if (forgeableMonsters.empty()) { return 0; + } auto maxTries = forgeableMonsters.size(); uint16_t tries = 0; @@ -9543,10 +9555,11 @@ void Game::updateFiendishMonsterStatus(uint32_t monsterId, const std::string &mo } bool Game::removeForgeMonster(uint32_t id, ForgeClassifications_t monsterForgeClassification, bool create) { - if (monsterForgeClassification == ForgeClassifications_t::FORGE_FIENDISH_MONSTER) + if (monsterForgeClassification == ForgeClassifications_t::FORGE_FIENDISH_MONSTER) { removeFiendishMonster(id, create); - else if (monsterForgeClassification == ForgeClassifications_t::FORGE_INFLUENCED_MONSTER) + } else if (monsterForgeClassification == ForgeClassifications_t::FORGE_INFLUENCED_MONSTER) { removeInfluencedMonster(id, create); + } return true; } @@ -9592,8 +9605,9 @@ void Game::updateForgeableMonsters() { continue; } - if (monster->canBeForgeMonster() && !monsterTile->hasFlag(TILESTATE_NOLOGOUT)) + if (monster->canBeForgeMonster() && !monsterTile->hasFlag(TILESTATE_NOLOGOUT)) { forgeableMonsters.push_back(monster->getID()); + } } for (const auto monsterId : getFiendishMonsters()) { @@ -9603,8 +9617,9 @@ void Game::updateForgeableMonsters() { } uint32_t fiendishLimit = g_configManager().getNumber(FORGE_FIENDISH_CREATURES_LIMIT); // Fiendish Creatures limit - if (fiendishMonsters.size() < fiendishLimit) + if (fiendishMonsters.size() < fiendishLimit) { createFiendishMonsters(); + } } void Game::createFiendishMonsters() { diff --git a/src/game/movement/teleport.cpp b/src/game/movement/teleport.cpp index 6f98fab0060..31bd42d11cf 100644 --- a/src/game/movement/teleport.cpp +++ b/src/game/movement/teleport.cpp @@ -67,8 +67,9 @@ void Teleport::addThing(Thing* thing) { } void Teleport::addThing(int32_t, Thing* thing) { - if (!thing) + if (!thing) { return; + } Tile* destTile = g_game().map.getTile(destPos); if (!destTile) { diff --git a/src/game/scheduling/dispatcher.cpp b/src/game/scheduling/dispatcher.cpp index 042c04f510a..c89129b37c0 100644 --- a/src/game/scheduling/dispatcher.cpp +++ b/src/game/scheduling/dispatcher.cpp @@ -55,4 +55,4 @@ void Dispatcher::addTask(const std::shared_ptr &task, uint32_t expiresAfte ++dispatcherCycle; (*task)(); }); -} \ No newline at end of file +} diff --git a/src/game/zones/zone.cpp b/src/game/zones/zone.cpp index 1718605a352..773d8e00f80 100644 --- a/src/game/zones/zone.cpp +++ b/src/game/zones/zone.cpp @@ -115,8 +115,9 @@ phmap::parallel_flat_hash_set> Zone::getZones(const Positi const phmap::parallel_flat_hash_set> &Zone::getZones() { static phmap::parallel_flat_hash_set> zonesSet; for (const auto &[_, zone] : zones) { - if (zone) + if (zone) { zonesSet.insert(zone); + } } return zonesSet; } diff --git a/src/io/functions/iologindata_save_player.cpp b/src/io/functions/iologindata_save_player.cpp index ed13d229e1e..93187b0cdd0 100644 --- a/src/io/functions/iologindata_save_player.cpp +++ b/src/io/functions/iologindata_save_player.cpp @@ -35,8 +35,9 @@ bool IOLoginDataSave::saveItems(const Player* player, const ItemBlockList &itemL // Update container attributes if necessary if (Container* container = item->getContainer()) { - if (!container) + if (!container) { continue; // Check for null container + } if (container->getAttribute(ItemAttribute_t::OPENCONTAINER) > 0) { container->setAttribute(ItemAttribute_t::OPENCONTAINER, 0); @@ -85,13 +86,15 @@ bool IOLoginDataSave::saveItems(const Player* player, const ItemBlockList &itemL int32_t parentId = cb.second; queue.pop_front(); - if (!container) + if (!container) { continue; // Check for null container + } // Loop through items in container for (Item* item : container->getItemList()) { - if (!item) + if (!item) { continue; // Check for null item + } ++runningId; diff --git a/src/io/io_bosstiary.cpp b/src/io/io_bosstiary.cpp index 9479c7d97d4..16e642c6564 100644 --- a/src/io/io_bosstiary.cpp +++ b/src/io/io_bosstiary.cpp @@ -206,8 +206,9 @@ uint16_t IOBosstiary::calculateLootBonus(uint32_t bossPoints) const { uint32_t IOBosstiary::calculateBossPoints(uint16_t lootBonus) const { // Calculate Boss Points based on Bonus - if (lootBonus <= 25) + if (lootBonus <= 25) { return 0; + } if (lootBonus <= 50) { return 10 * lootBonus - 250; @@ -280,8 +281,9 @@ uint8_t IOBosstiary::getBossCurrentLevel(const Player* player, uint16_t bossId) } uint32_t IOBosstiary::calculteRemoveBoss(uint8_t removeTimes) const { - if (removeTimes < 2) + if (removeTimes < 2) { return 0; + } return 300000 * removeTimes - 500000; } diff --git a/src/io/iobestiary.cpp b/src/io/iobestiary.cpp index 1992092f872..4b1c0d253ad 100644 --- a/src/io/iobestiary.cpp +++ b/src/io/iobestiary.cpp @@ -232,8 +232,9 @@ void IOBestiary::addBestiaryKill(Player* player, const std::shared_ptrsendTextMessage(MESSAGE_STATUS, ss.str()); player->sendBestiaryEntryChanged(raceid); - if ((curCount + amount) >= mtype->info.bestiaryToUnlock) + if ((curCount + amount) >= mtype->info.bestiaryToUnlock) { addCharmPoints(player, mtype->info.bestiaryCharmsPoints); + } } const auto &trackerUnorderedSet = player->getCyclopediaMonsterTrackerSet(false); diff --git a/src/io/ioguild.cpp b/src/io/ioguild.cpp index 6f51f6763ef..e6aae24457f 100644 --- a/src/io/ioguild.cpp +++ b/src/io/ioguild.cpp @@ -34,8 +34,9 @@ std::shared_ptr IOGuild::loadGuild(uint32_t guildId) { } void IOGuild::saveGuild(const std::shared_ptr &guild) { - if (!guild) + if (!guild) { return; + } Database &db = Database::getInstance(); std::ostringstream updateQuery; updateQuery << "UPDATE `guilds` SET "; diff --git a/src/io/iomap.cpp b/src/io/iomap.cpp index 9124045fbf8..dc3fdd5ae45 100644 --- a/src/io/iomap.cpp +++ b/src/io/iomap.cpp @@ -46,8 +46,9 @@ void IOMap::loadMap(Map* map, const std::string &fileName, const Position &pos, FileStream stream { begin, fileByte.end() }; - if (!stream.startNode()) + if (!stream.startNode()) { throw IOMapException("Could not read map node."); + } stream.skip(1); // Type Node @@ -57,11 +58,13 @@ void IOMap::loadMap(Map* map, const std::string &fileName, const Position &pos, uint32_t majorVersionItems = stream.getU32(); stream.getU32(); // minorVersionItems - if (version > 2) + if (version > 2) { throw IOMapException("Unknown OTBM version detected."); + } - if (majorVersionItems < 3) + if (majorVersionItems < 3) { throw IOMapException("This map need to be upgraded by using the latest map editor version to be able to load correctly."); + } g_logger().info("Map size: {}x{}", map->width, map->height); @@ -120,8 +123,9 @@ void IOMap::parseTileArea(FileStream &stream, Map &map, const Position &pos) { while (stream.startNode()) { uint8_t tileType = stream.getU8(); - if (tileType != OTBM_HOUSETILE && tileType != OTBM_TILE) + if (tileType != OTBM_HOUSETILE && tileType != OTBM_TILE) { throw IOMapException("Could not read tile type node."); + } const auto &tile = std::make_shared(); @@ -134,8 +138,9 @@ void IOMap::parseTileArea(FileStream &stream, Map &map, const Position &pos) { if (tileType == OTBM_HOUSETILE) { tile->houseId = stream.getU32(); - if (!map.houses.addHouse(tile->houseId)) + if (!map.houses.addHouse(tile->houseId)) { throw IOMapException(fmt::format("[x:{}, y:{}, z:{}] Could not create house id: {}", x, y, z, tile->houseId)); + } } if (stream.isProp(OTBM_ATTR_TILE_FLAGS)) { @@ -158,8 +163,9 @@ void IOMap::parseTileArea(FileStream &stream, Map &map, const Position &pos) { const ItemType &iType = Item::items[id]; if (!tile->isHouse() || !iType.isBed()) { - if (iType.blockSolid) + if (iType.blockSolid) { tileIsStatic = true; + } const auto &item = std::make_shared(); item->id = id; @@ -193,8 +199,9 @@ void IOMap::parseTileArea(FileStream &stream, Map &map, const Position &pos) { const auto &item = std::make_shared(); item->id = id; - if (!item->unserializeItemNode(stream, x, y, z)) + if (!item->unserializeItemNode(stream, x, y, z)) { throw IOMapException(fmt::format("[x:{}, y:{}, z:{}] Failed to load item {}, Node Type.", x, y, z, id)); + } if (tile->isHouse() && iType.isBed()) { // nothing @@ -228,8 +235,9 @@ void IOMap::parseTileArea(FileStream &stream, Map &map, const Position &pos) { } void IOMap::parseTowns(FileStream &stream, Map &map) { - if (!stream.startNode(OTBM_TOWNS)) + if (!stream.startNode(OTBM_TOWNS)) { throw IOMapException("Could not read towns node."); + } while (stream.startNode(OTBM_TOWN)) { const uint32_t townId = stream.getU32(); @@ -242,17 +250,20 @@ void IOMap::parseTowns(FileStream &stream, Map &map) { town->setName(townName); town->setTemplePos(Position(x, y, z)); - if (!stream.endNode()) + if (!stream.endNode()) { throw IOMapException("Could not end node."); + } } - if (!stream.endNode()) + if (!stream.endNode()) { throw IOMapException("Could not end node."); + } } void IOMap::parseWaypoints(FileStream &stream, Map &map) { - if (!stream.startNode(OTBM_WAYPOINTS)) + if (!stream.startNode(OTBM_WAYPOINTS)) { throw IOMapException("Could not read waypoints node."); + } while (stream.startNode(OTBM_WAYPOINT)) { const auto &name = stream.getString(); @@ -262,10 +273,12 @@ void IOMap::parseWaypoints(FileStream &stream, Map &map) { map.waypoints[name] = Position(x, y, z); - if (!stream.endNode()) + if (!stream.endNode()) { throw IOMapException("Could not end node."); + } } - if (!stream.endNode()) + if (!stream.endNode()) { throw IOMapException("Could not end node."); + } } diff --git a/src/items/containers/container.cpp b/src/items/containers/container.cpp index 5e288d6d29b..8c1683c47cd 100644 --- a/src/items/containers/container.cpp +++ b/src/items/containers/container.cpp @@ -556,8 +556,9 @@ void Container::addThing(Thing* thing) { } void Container::addThing(int32_t index, Thing* thing) { - if (!thing) + if (!thing) { return /*RETURNVALUE_NOTPOSSIBLE*/; + } if (index >= static_cast(capacity())) { return /*RETURNVALUE_NOTPOSSIBLE*/; @@ -754,8 +755,9 @@ void Container::internalAddThing(Thing* thing) { } void Container::internalAddThing(uint32_t, Thing* thing) { - if (!thing) + if (!thing) { return; + } Item* item = thing->getItem(); if (item == nullptr) { diff --git a/src/items/containers/mailbox/mailbox.cpp b/src/items/containers/mailbox/mailbox.cpp index bf94ddf73e8..248c5c85367 100644 --- a/src/items/containers/mailbox/mailbox.cpp +++ b/src/items/containers/mailbox/mailbox.cpp @@ -39,8 +39,9 @@ void Mailbox::addThing(Thing* thing) { } void Mailbox::addThing(int32_t, Thing* thing) { - if (!thing) + if (!thing) { return; + } Item* item = thing->getItem(); if (item && Mailbox::canSend(item)) { diff --git a/src/items/item.cpp b/src/items/item.cpp index 17fc471fb53..354a97879c4 100644 --- a/src/items/item.cpp +++ b/src/items/item.cpp @@ -3066,17 +3066,19 @@ uint32_t Item::getWorth() const { } uint32_t Item::getForgeSlivers() const { - if (getID() == ITEM_FORGE_SLIVER) + if (getID() == ITEM_FORGE_SLIVER) { return getItemCount(); - else + } else { return 0; + } } uint32_t Item::getForgeCores() const { - if (getID() == ITEM_FORGE_CORE) + if (getID() == ITEM_FORGE_CORE) { return getItemCount(); - else + } else { return 0; + } } LightInfo Item::getLightInfo() const { diff --git a/src/items/items.cpp b/src/items/items.cpp index 0be81c22e64..6611af095b8 100644 --- a/src/items/items.cpp +++ b/src/items/items.cpp @@ -321,8 +321,9 @@ const ItemType &Items::getItemType(size_t id) const { uint16_t Items::getItemIdByName(const std::string &name) { auto result = nameToItems.find(asLowerCaseString(name)); - if (result == nameToItems.end()) + if (result == nameToItems.end()) { return 0; + } return result->second; } diff --git a/src/items/tile.cpp b/src/items/tile.cpp index e1e430faff6..9f56e68bffe 100644 --- a/src/items/tile.cpp +++ b/src/items/tile.cpp @@ -931,8 +931,9 @@ void Tile::addThing(Thing* thing) { } void Tile::addThing(int32_t, Thing* thing) { - if (!thing) + if (!thing) { return /*RETURNVALUE_NOTPOSSIBLE*/; + } Creature* creature = thing->getCreature(); if (creature) { @@ -1534,8 +1535,9 @@ void Tile::internalAddThing(Thing* thing) { } void Tile::internalAddThing(uint32_t, Thing* thing) { - if (!thing) + if (!thing) { return; + } thing->setParent(this); diff --git a/src/items/trashholder.cpp b/src/items/trashholder.cpp index d447037e6f8..353efabdcff 100644 --- a/src/items/trashholder.cpp +++ b/src/items/trashholder.cpp @@ -34,8 +34,9 @@ void TrashHolder::addThing(Thing* thing) { } void TrashHolder::addThing(int32_t, Thing* thing) { - if (!thing) + if (!thing) { return; + } Item* item = thing->getItem(); if (!item) { diff --git a/src/items/weapons/weapons.cpp b/src/items/weapons/weapons.cpp index 986676bc96a..aae19c09f74 100644 --- a/src/items/weapons/weapons.cpp +++ b/src/items/weapons/weapons.cpp @@ -390,15 +390,17 @@ bool WeaponMelee::useWeapon(Player* player, Item* item, Creature* target) const firstCleaveTargetPos.y++; secondCleaveTargetPos.y--; } else { - if (targetPos.x > playerPos.x) + if (targetPos.x > playerPos.x) { firstCleaveTargetPos.x--; - else + } else { firstCleaveTargetPos.x++; + } - if (targetPos.y > playerPos.y) + if (targetPos.y > playerPos.y) { secondCleaveTargetPos.y--; - else + } else { secondCleaveTargetPos.y++; + } } Tile* firstTile = g_game().map.getTile(firstCleaveTargetPos.x, firstCleaveTargetPos.y, firstCleaveTargetPos.z); Tile* secondTile = g_game().map.getTile(secondCleaveTargetPos.x, secondCleaveTargetPos.y, secondCleaveTargetPos.z); @@ -406,16 +408,18 @@ bool WeaponMelee::useWeapon(Player* player, Item* item, Creature* target) const if (firstTile) { if (CreatureVector* tileCreatures = firstTile->getCreatures()) { for (Creature* tileCreature : *tileCreatures) { - if (tileCreature->getMonster() || (tileCreature->getPlayer() && !player->hasSecureMode())) + if (tileCreature->getMonster() || (tileCreature->getPlayer() && !player->hasSecureMode())) { internalUseWeapon(player, item, tileCreature, damageModifier, cleavePercent); + } } } } if (secondTile) { if (CreatureVector* tileCreatures = secondTile->getCreatures()) { for (Creature* tileCreature : *tileCreatures) { - if (tileCreature->getMonster() || (tileCreature->getPlayer() && !player->hasSecureMode())) + if (tileCreature->getMonster() || (tileCreature->getPlayer() && !player->hasSecureMode())) { internalUseWeapon(player, item, tileCreature, damageModifier, cleavePercent); + } } } } diff --git a/src/lib/logging/logger.hpp b/src/lib/logging/logger.hpp index d19738a824d..4fef2c9a534 100644 --- a/src/lib/logging/logger.hpp +++ b/src/lib/logging/logger.hpp @@ -10,17 +10,29 @@ #define CANARY_LOGGER_HPP #define LOG_LEVEL_TRACE \ - std::string { "trace" } + std::string { \ + "trace" \ + } #define LOG_LEVEL_DEBUG \ - std::string { "debug" } + std::string { \ + "debug" \ + } #define LOG_LEVEL_INFO \ - std::string { "info" } + std::string { \ + "info" \ + } #define LOG_LEVEL_WARNING \ - std::string { "warning" } + std::string { \ + "warning" \ + } #define LOG_LEVEL_ERROR \ - std::string { "error" } + std::string { \ + "error" \ + } #define LOG_LEVEL_CRITICAL \ - std::string { "critical" } + std::string { \ + "critical" \ + } class Logger { public: diff --git a/src/lib/thread/thread_pool.cpp b/src/lib/thread/thread_pool.cpp index bc0c58e438b..14bc61c4089 100644 --- a/src/lib/thread/thread_pool.cpp +++ b/src/lib/thread/thread_pool.cpp @@ -65,4 +65,4 @@ void ThreadPool::addLoad(const std::function &load) { load(); }); -} \ No newline at end of file +} diff --git a/src/lua/functions/creatures/player/mount_functions.cpp b/src/lua/functions/creatures/player/mount_functions.cpp index 669f8361b85..501268bfd5c 100644 --- a/src/lua/functions/creatures/player/mount_functions.cpp +++ b/src/lua/functions/creatures/player/mount_functions.cpp @@ -81,4 +81,4 @@ int MountFunctions::luaMountGetSpeed(lua_State* L) { } return 1; -} \ No newline at end of file +} diff --git a/src/main.cpp b/src/main.cpp index 0058230d262..16e7b32d08f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,4 +12,4 @@ int main() { return inject().run(); -} \ No newline at end of file +} diff --git a/src/map/map.cpp b/src/map/map.cpp index f072e933f39..a07402554b5 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -61,12 +61,14 @@ bool Map::loadMap(const std::string &identifier, bool mainMap /*= false*/, bool g_game().createLuaItemsOnMap(); } - if (loadMonsters && !IOMap::loadMonsters(this)) + if (loadMonsters && !IOMap::loadMonsters(this)) { g_logger().warn("Failed to load spawn data"); + } if (loadHouses) { - if (!IOMap::loadHouses(this)) + if (!IOMap::loadHouses(this)) { g_logger().warn("Failed to load house data"); + } /** * Only load houses items if map custom load is disabled @@ -79,8 +81,9 @@ bool Map::loadMap(const std::string &identifier, bool mainMap /*= false*/, bool } } - if (loadNpcs && !IOMap::loadNpcs(this)) + if (loadNpcs && !IOMap::loadNpcs(this)) { g_logger().warn("Failed to load npc spawn data"); + } // Files need to be cleaned up if custom map is enabled to open, or will try to load main map files if (g_configManager().getBoolean(TOGGLE_MAP_CUSTOM)) { @@ -97,14 +100,17 @@ bool Map::loadMapCustom(const std::string &mapName, bool loadHouses, bool loadMo load(path, Position(0, 0, 0), true); load(path); - if (loadMonsters && !IOMap::loadMonstersCustom(this, mapName, customMapIndex)) + if (loadMonsters && !IOMap::loadMonstersCustom(this, mapName, customMapIndex)) { g_logger().warn("Failed to load monster custom data"); + } - if (loadHouses && !IOMap::loadHousesCustom(this, mapName, customMapIndex)) + if (loadHouses && !IOMap::loadHousesCustom(this, mapName, customMapIndex)) { g_logger().warn("Failed to load house custom data"); + } - if (loadNpcs && !IOMap::loadNpcsCustom(this, mapName, customMapIndex)) + if (loadNpcs && !IOMap::loadNpcsCustom(this, mapName, customMapIndex)) { g_logger().warn("Failed to load npc custom spawn data"); + } // Files need to be cleaned up or will try to load previous map files again monsterfile.clear(); @@ -134,10 +140,11 @@ bool Map::save() { Tile* Map::getOrCreateTile(uint16_t x, uint16_t y, uint8_t z, bool isDynamic) { auto tile = getTile(x, y, z); if (!tile) { - if (isDynamic) + if (isDynamic) { tile = new DynamicTile(x, y, z); - else + } else { tile = new StaticTile(x, y, z); + } setTile(x, y, z, tile); } @@ -146,16 +153,19 @@ Tile* Map::getOrCreateTile(uint16_t x, uint16_t y, uint8_t z, bool isDynamic) { } Tile* Map::getTile(uint16_t x, uint16_t y, uint8_t z) { - if (z >= MAP_MAX_LAYERS) + if (z >= MAP_MAX_LAYERS) { return nullptr; + } const auto leaf = getQTNode(x, y); - if (!leaf) + if (!leaf) { return nullptr; + } const auto &floor = leaf->getFloor(z); - if (!floor) + if (!floor) { return nullptr; + } const auto tile = floor->getTile(x, y); return tile ? tile : getOrCreateTileFromCache(floor, x, y); diff --git a/src/map/mapcache.cpp b/src/map/mapcache.cpp index 88b201e1234..f8539f25e8f 100644 --- a/src/map/mapcache.cpp +++ b/src/map/mapcache.cpp @@ -39,14 +39,17 @@ void MapCache::flush() { } void MapCache::parseItemAttr(const BasicItemPtr &BasicItem, Item* item) { - if (BasicItem->charges > 0) + if (BasicItem->charges > 0) { item->setSubType(BasicItem->charges); + } - if (BasicItem->actionId > 0) + if (BasicItem->actionId > 0) { item->setAttribute(ItemAttribute_t::ACTIONID, BasicItem->actionId); + } - if (BasicItem->uniqueId > 0) + if (BasicItem->uniqueId > 0) { item->addUniqueId(BasicItem->uniqueId); + } if (item->getTeleport() && (BasicItem->destX != 0 || BasicItem->destY != 0 || BasicItem->destZ != 0)) { auto dest = Position(BasicItem->destX, BasicItem->destY, BasicItem->destZ); @@ -71,21 +74,21 @@ void MapCache::parseItemAttr(const BasicItemPtr &BasicItem, Item* item) { } } - if (BasicItem->sleepStart > 0) + if (BasicItem->sleepStart > 0) { item->getBed()->sleepStart = static_cast(BasicItem->sleepStart); + } } - if (!BasicItem->text.empty()) + if (!BasicItem->text.empty()) { item->setAttribute(ItemAttribute_t::TEXT, BasicItem->text); - - /* if (BasicItem.description != 0) - item->setAttribute(ItemAttribute_t::DESCRIPTION, STRING_CACHE[BasicItem.description]);*/ + } } Item* MapCache::createItem(const BasicItemPtr &BasicItem, Position position) { auto item = Item::CreateItem(BasicItem->id, position); - if (!item) + if (!item) { return nullptr; + } parseItemAttr(BasicItem, item); @@ -98,8 +101,9 @@ Item* MapCache::createItem(const BasicItemPtr &BasicItem, Position position) { } } - if (item->getItemCount() == 0) + if (item->getItemCount() == 0) { item->setItemCount(1); + } item->startDecaying(); item->setLoadedFromMap(true); @@ -109,8 +113,9 @@ Item* MapCache::createItem(const BasicItemPtr &BasicItem, Position position) { Tile* MapCache::getOrCreateTileFromCache(const std::unique_ptr &floor, uint16_t x, uint16_t y) { const auto &cachedTile = floor->getTileCache(x, y); - if (!cachedTile) + if (!cachedTile) { return floor->getTile(x, y); + } const uint8_t z = floor->getZ(); @@ -123,16 +128,19 @@ Tile* MapCache::getOrCreateTileFromCache(const std::unique_ptr &floor, ui house->addTile(static_cast(tile)); } else if (cachedTile->isStatic) { tile = new StaticTile(x, y, z); - } else + } else { tile = new DynamicTile(x, y, z); + } auto pos = Position(x, y, z); - if (cachedTile->ground != nullptr) + if (cachedTile->ground != nullptr) { tile->internalAddThing(createItem(cachedTile->ground, pos)); + } - for (const auto &BasicItemd : cachedTile->items) + for (const auto &BasicItemd : cachedTile->items) { tile->internalAddThing(createItem(BasicItemd, pos)); + } tile->setFlag(static_cast(cachedTile->flags)); @@ -160,34 +168,40 @@ BasicItemPtr MapCache::tryReplaceItemFromCache(const BasicItemPtr &ref) { void BasicTile::hash(size_t &h) const { const uint32_t arr[] = { flags, houseId, type, isStatic }; for (const auto v : arr) { - if (v > 0) + if (v > 0) { stdext::hash_combine(h, v); + } } - if (ground != nullptr) + if (ground != nullptr) { ground->hash(h); + } if (!items.empty()) { stdext::hash_combine(h, items.size()); - for (const auto &item : items) + for (const auto &item : items) { item->hash(h); + } } } void BasicItem::hash(size_t &h) const { const uint32_t arr[] = { id, guid, sleepStart, charges, actionId, uniqueId, destX, destY, destZ, doorOrDepotId }; for (const auto v : arr) { - if (v > 0) + if (v > 0) { stdext::hash_combine(h, v); + } } - if (!text.empty()) + if (!text.empty()) { stdext::hash_combine(h, text); + } if (!items.empty()) { stdext::hash_combine(h, items.size()); - for (const auto &item : items) + for (const auto &item : items) { item->hash(h); + } } } @@ -200,21 +214,24 @@ bool BasicItem::unserializeItemNode(FileStream &stream, uint16_t x, uint16_t y, readAttr(stream); while (stream.startNode()) { - if (stream.getU8() != OTBM_ITEM) + if (stream.getU8() != OTBM_ITEM) { throw IOMapException(fmt::format("[x:{}, y:{}, z:{}] Could not read item node.", x, y, z)); + } const uint16_t streamId = stream.getU16(); const auto &item = std::make_shared(); item->id = streamId; - if (!item->unserializeItemNode(stream, x, y, z)) + if (!item->unserializeItemNode(stream, x, y, z)) { throw IOMapException(fmt::format("[x:{}, y:{}, z:{}] Failed to load item.", x, y, z)); + } items.emplace_back(static_tryGetItemFromCache(item)); - if (!stream.endNode()) + if (!stream.endNode()) { throw IOMapException(fmt::format("[x:{}, y:{}, z:{}] Could not end node.", x, y, z)); + } } return true; @@ -257,8 +274,9 @@ void BasicItem::readAttr(FileStream &stream) { case ATTR_TEXT: { const auto &str = stream.getString(); - if (!str.empty()) + if (!str.empty()) { text = str; + } } break; case ATTR_DESC: { diff --git a/src/map/utils/astarnodes.cpp b/src/map/utils/astarnodes.cpp index e3cfcc87a31..969a8996742 100644 --- a/src/map/utils/astarnodes.cpp +++ b/src/map/utils/astarnodes.cpp @@ -95,10 +95,11 @@ AStarNode* AStarNodes::getNodeByPosition(uint32_t x, uint32_t y) { int_fast32_t AStarNodes::getMapWalkCost(AStarNode* node, const Position &neighborPos, bool preferDiagonal) { if (std::abs(node->x - neighborPos.x) == std::abs(node->y - neighborPos.y)) { // diagonal movement extra cost - if (preferDiagonal) + if (preferDiagonal) { return MAP_PREFERDIAGONALWALKCOST; - else + } else { return MAP_DIAGONALWALKCOST; + } } return MAP_NORMALWALKCOST; } diff --git a/src/map/utils/qtreenode.cpp b/src/map/utils/qtreenode.cpp index 043a0dc7b67..4d990d81ee9 100644 --- a/src/map/utils/qtreenode.cpp +++ b/src/map/utils/qtreenode.cpp @@ -16,16 +16,18 @@ bool QTreeLeafNode::newLeaf = false; QTreeLeafNode* QTreeNode::getLeaf(uint32_t x, uint32_t y) { - if (leaf) + if (leaf) { return static_cast(this); + } const auto node = child[((x & 0x8000) >> 15) | ((y & 0x8000) >> 14)]; return node ? node->getLeaf(x << 1, y << 1) : nullptr; } QTreeLeafNode* QTreeNode::createLeaf(uint32_t x, uint32_t y, uint32_t level) { - if (isLeaf()) + if (isLeaf()) { return static_cast(this); + } const uint32_t index = ((x & 0x8000) >> 15) | ((y & 0x8000) >> 14); if (!child[index]) { diff --git a/src/server/network/protocol/protocolgame.cpp b/src/server/network/protocol/protocolgame.cpp index 79864690229..5152e34354a 100644 --- a/src/server/network/protocol/protocolgame.cpp +++ b/src/server/network/protocol/protocolgame.cpp @@ -2368,12 +2368,14 @@ void ProtocolGame::sendTeamFinderList() { msg.add(teamFinder.size()); for (auto it : teamFinder) { const Player* leader = g_game().getPlayerByGUID(it.first); - if (!leader) + if (!leader) { return; + } TeamFinder* teamAssemble = it.second; - if (!teamAssemble) + if (!teamAssemble) { return; + } uint8_t status = 0; uint16_t membersSize = 0; @@ -2386,11 +2388,13 @@ void ProtocolGame::sendTeamFinderList() { for (auto itt : teamAssemble->membersMap) { const Player* member = g_game().getPlayerByGUID(it.first); if (member) { - if (itt.first == player->getGUID()) + if (itt.first == player->getGUID()) { status = itt.second; + } - if (itt.second == 3) + if (itt.second == 3) { membersSize += 1; + } } } msg.add(std::max((teamAssemble->teamSlots - teamAssemble->freeSlots), membersSize)); @@ -2434,8 +2438,9 @@ void ProtocolGame::sendLeaderTeamFinder(bool reset) { teamAssemble = it->second; } - if (!teamAssemble) + if (!teamAssemble) { return; + } NetworkMessage msg; msg.addByte(0x2C); @@ -2481,8 +2486,9 @@ void ProtocolGame::sendLeaderTeamFinder(bool reset) { msg.add(membersSize); const Player* leader = g_game().getPlayerByGUID(teamAssemble->leaderGuid); - if (!leader) + if (!leader) { return; + } msg.add(leader->getGUID()); msg.addString(leader->getName()); @@ -2519,8 +2525,9 @@ void ProtocolGame::createLeaderTeamFinder(NetworkMessage &msg) { teamAssemble = it->second; } - if (!teamAssemble) + if (!teamAssemble) { teamAssemble = new TeamFinder(); + } teamAssemble->minLevel = msg.get(); teamAssemble->maxLevel = msg.get(); @@ -2621,8 +2628,9 @@ void ProtocolGame::parseLeaderFinderWindow(NetworkMessage &msg) { case 2: { uint32_t memberID = msg.get(); const Player* member = g_game().getPlayerByGUID(memberID); - if (!member) + if (!member) { return; + } std::map teamFinder = g_game().getTeamFinderList(); TeamFinder* teamAssemble = nullptr; @@ -2631,8 +2639,9 @@ void ProtocolGame::parseLeaderFinderWindow(NetworkMessage &msg) { teamAssemble = it->second; } - if (!teamAssemble) + if (!teamAssemble) { return; + } uint8_t memberStatus = msg.getByte(); for (auto &memberPair : teamAssemble->membersMap) { @@ -2683,8 +2692,9 @@ void ProtocolGame::parseMemberFinderWindow(NetworkMessage &msg) { } else { uint32_t leaderID = msg.get(); const Player* leader = g_game().getPlayerByGUID(leaderID); - if (!leader) + if (!leader) { return; + } std::map teamFinder = g_game().getTeamFinderList(); TeamFinder* teamAssemble = nullptr; @@ -2693,8 +2703,9 @@ void ProtocolGame::parseMemberFinderWindow(NetworkMessage &msg) { teamAssemble = it->second; } - if (!teamAssemble) + if (!teamAssemble) { return; + } if (action == 1) { leader->sendTextMessage(MESSAGE_STATUS, "There is a new request to join your team."); @@ -3646,12 +3657,13 @@ void ProtocolGame::sendCyclopediaCharacterOutfitsMounts() { msg.add(outfit->lookType); msg.addString(outfit->name); msg.addByte(addons); - if (from == "store") + if (from == "store") { msg.addByte(CYCLOPEDIA_CHARACTERINFO_OUTFITTYPE_STORE); - else if (from == "quest") + } else if (from == "quest") { msg.addByte(CYCLOPEDIA_CHARACTERINFO_OUTFITTYPE_QUEST); - else + } else { msg.addByte(CYCLOPEDIA_CHARACTERINFO_OUTFITTYPE_NONE); + } if (outfit->lookType == currentOutfit.lookType) { msg.add(1000); } else { @@ -3675,12 +3687,13 @@ void ProtocolGame::sendCyclopediaCharacterOutfitsMounts() { msg.add(mount->clientId); msg.addString(mount->name); - if (type == "store") + if (type == "store") { msg.addByte(CYCLOPEDIA_CHARACTERINFO_OUTFITTYPE_STORE); - else if (type == "quest") + } else if (type == "quest") { msg.addByte(CYCLOPEDIA_CHARACTERINFO_OUTFITTYPE_QUEST); - else + } else { msg.addByte(CYCLOPEDIA_CHARACTERINFO_OUTFITTYPE_NONE); + } msg.add(1000); } } @@ -3703,10 +3716,11 @@ void ProtocolGame::sendCyclopediaCharacterOutfitsMounts() { ++familiarsSize; msg.add(familiar.lookType); msg.addString(familiar.name); - if (type == "quest") + if (type == "quest") { msg.addByte(CYCLOPEDIA_CHARACTERINFO_OUTFITTYPE_QUEST); - else + } else { msg.addByte(CYCLOPEDIA_CHARACTERINFO_OUTFITTYPE_NONE); + } msg.add(0); } @@ -3939,8 +3953,9 @@ void ProtocolGame::sendBasicData() { } void ProtocolGame::sendBlessStatus() { - if (!player) + if (!player) { return; + } NetworkMessage msg; // uint8_t maxClientBlessings = (player->operatingSystem == CLIENTOS_NEW_WINDOWS) ? 8 : 6; (compartability for the client 10) @@ -6008,8 +6023,9 @@ void ProtocolGame::sendAddCreature(const Creature* creature, const Position &pos if (isLogin) { if (const Player* creaturePlayer = creature->getPlayer()) { - if (!creaturePlayer->isAccessPlayer() || creaturePlayer->getAccountType() == account::ACCOUNT_TYPE_NORMAL) + if (!creaturePlayer->isAccessPlayer() || creaturePlayer->getAccountType() == account::ACCOUNT_TYPE_NORMAL) { sendMagicEffect(pos, CONST_ME_TELEPORT); + } } else { sendMagicEffect(pos, CONST_ME_TELEPORT); } @@ -7780,8 +7796,9 @@ void ProtocolGame::sendItemsPrice() { } void ProtocolGame::reloadCreature(const Creature* creature) { - if (!creature || !canSee(creature)) + if (!creature || !canSee(creature)) { return; + } auto tile = creature->getTile(); if (!tile) { @@ -7790,8 +7807,9 @@ void ProtocolGame::reloadCreature(const Creature* creature) { uint32_t stackpos = tile->getClientIndexOfCreature(player, creature); - if (stackpos >= 10) + if (stackpos >= 10) { return; + } NetworkMessage msg; @@ -8020,8 +8038,9 @@ void ProtocolGame::sendUpdateCreature(const Creature* creature) { return; } - if (!canSee(creature)) + if (!canSee(creature)) { return; + } int32_t stackPos = tile->getClientIndexOfCreature(player, creature); if (stackPos == -1 || stackPos >= 10) { @@ -8255,8 +8274,9 @@ void ProtocolGame::parseSendBosstiarySlots() { uint16_t bossesCount = 0; msg.skipBytes(2); for (const auto &bossId : bossesUnlockedList) { - if (bossId == bossIdSlotOne || bossId == bossIdSlotTwo) + if (bossId == bossIdSlotOne || bossId == bossIdSlotTwo) { continue; + } const auto &mType = g_ioBosstiary().getMonsterTypeByBossRaceId(bossId); if (!mType) { diff --git a/src/utils/tools.cpp b/src/utils/tools.cpp index 8dcbb3fc26a..31cd2a5bee1 100644 --- a/src/utils/tools.cpp +++ b/src/utils/tools.cpp @@ -549,25 +549,31 @@ Direction getDirectionTo(const Position &from, const Position &to, bool exactDia /* * Only consider diagonal if dx and dy are equal (exact diagonal). */ - if (absDx > absDy) + if (absDx > absDy) { return dx < 0 ? DIRECTION_EAST : DIRECTION_WEST; - if (absDx < absDy) + } + if (absDx < absDy) { return dy > 0 ? DIRECTION_NORTH : DIRECTION_SOUTH; + } } if (dx < 0) { - if (dy < 0) + if (dy < 0) { return DIRECTION_SOUTHEAST; - if (dy > 0) + } + if (dy > 0) { return DIRECTION_NORTHEAST; + } return DIRECTION_EAST; } if (dx > 0) { - if (dy < 0) + if (dy < 0) { return DIRECTION_SOUTHWEST; - if (dy > 0) + } + if (dy > 0) { return DIRECTION_NORTHWEST; + } return DIRECTION_WEST; } @@ -1510,9 +1516,9 @@ NameEval_t validateName(const std::string &name) { } for (std::string str : toks) { - if (str.length() < 2) + if (str.length() < 2) { return INVALID_TOKEN_LENGTH; - else if (std::find(prohibitedWords.begin(), prohibitedWords.end(), str) != prohibitedWords.end()) { // searching for prohibited words + } else if (std::find(prohibitedWords.begin(), prohibitedWords.end(), str) != prohibitedWords.end()) { // searching for prohibited words return INVALID_FORBIDDEN; } } @@ -1587,29 +1593,37 @@ std::string getObjectCategoryName(ObjectCategory_t category) { uint8_t forgeBonus(int32_t number) { // None - if (number < 7400) + if (number < 7400) { return 0; + } // Dust not consumed - else if (number >= 7400 && number < 9000) + else if (number >= 7400 && number < 9000) { return 1; + } // Cores not consumed - else if (number >= 9000 && number < 9500) + else if (number >= 9000 && number < 9500) { return 2; + } // Gold not consumed - else if (number >= 9500 && number < 9525) + else if (number >= 9500 && number < 9525) { return 3; + } // Second item retained with decreased tier - else if (number >= 9525 && number < 9550) + else if (number >= 9525 && number < 9550) { return 4; + } // Second item retained with unchanged tier - else if (number >= 9550 && number < 9950) + else if (number >= 9550 && number < 9950) { return 5; + } // Second item retained with increased tier - else if (number >= 9950 && number < 9975) + else if (number >= 9950 && number < 9975) { return 6; + } // Gain two tiers - else if (number >= 9975) + else if (number >= 9975) { return 7; + } return 0; }