Skip to content

Commit

Permalink
improve: enable clang format to add braces and new line (EOF) (openti…
Browse files Browse the repository at this point in the history
…biabr#1490)

Updated clang to version 16.0.2 to use new options.
  • Loading branch information
dudantas authored Aug 24, 2023
1 parent ba0ac10 commit 9d7af22
Show file tree
Hide file tree
Showing 37 changed files with 371 additions and 199 deletions.
3 changes: 2 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ IndentGotoLabels: true
IndentPPDirectives: BeforeHash
IndentWidth: 4
IndentWrappedFunctionNames: false
#InsertNewlineAtEOF: true
InsertBraces: true
InsertNewlineAtEOF: true
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/clang-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/canary_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,4 +364,4 @@ void CanaryServer::modulesLoadHelper(bool loaded, std::string moduleName) {

void CanaryServer::shutdown() {
inject<ThreadPool>().shutdown();
}
}
5 changes: 3 additions & 2 deletions src/creatures/combat/condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
3 changes: 2 additions & 1 deletion src/creatures/monsters/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/creatures/monsters/monster.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
3 changes: 2 additions & 1 deletion src/creatures/players/imbuements/imbuements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t>(100, pugi::cast<int32_t>(attr.value()));
}

imbuement.skills[skillId - 1] = chance;
}
Expand Down
14 changes: 9 additions & 5 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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*/;
Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
15 changes: 9 additions & 6 deletions src/creatures/players/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
90 changes: 60 additions & 30 deletions src/creatures/players/wheel/player_wheel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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()) {
Expand Down
6 changes: 4 additions & 2 deletions src/database/databasetasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@ DatabaseTasks &DatabaseTasks::getInstance() {
void DatabaseTasks::execute(const std::string &query, std::function<void(DBResult_ptr, bool)> 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<void(DBResult_ptr, bool)> 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); });
}
});
}
Loading

0 comments on commit 9d7af22

Please sign in to comment.