diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-05-05 20:58:21 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-05-05 20:58:21 +0300 |
commit | a87db81b6b7551a248e31e2850577aefda092538 (patch) | |
tree | f47c20512183113face758cf58ec71369c82806c /src/being | |
parent | 92c019dad798f1a84c5d3e8e8331a885f6458133 (diff) | |
download | manaverse-a87db81b6b7551a248e31e2850577aefda092538.tar.gz manaverse-a87db81b6b7551a248e31e2850577aefda092538.tar.bz2 manaverse-a87db81b6b7551a248e31e2850577aefda092538.tar.xz manaverse-a87db81b6b7551a248e31e2850577aefda092538.zip |
Replace most bools usage in playerinfo to strong typed bools.
Diffstat (limited to 'src/being')
-rw-r--r-- | src/being/localplayer.cpp | 20 | ||||
-rw-r--r-- | src/being/localplayer.h | 4 | ||||
-rw-r--r-- | src/being/playerinfo.cpp | 74 | ||||
-rw-r--r-- | src/being/playerinfo.h | 36 |
4 files changed, 71 insertions, 63 deletions
diff --git a/src/being/localplayer.cpp b/src/being/localplayer.cpp index ba7f4d794..e3adafc6d 100644 --- a/src/being/localplayer.cpp +++ b/src/being/localplayer.cpp @@ -157,7 +157,7 @@ LocalPlayer::LocalPlayer(const int id, const uint16_t subtype) : mUpdateName(true), mBlockAdvert(false), mTargetDeadPlayers(config.getBoolValue("targetDeadPlayers")), - mServerAttack(config.getBoolValue("serverAttack")), + mServerAttack(fromBool(config.getBoolValue("serverAttack"), Keep)), mEnableAdvert(config.getBoolValue("enableAdvert")), mTradebot(config.getBoolValue("tradebot")), mTargetOnlyReachable(config.getBoolValue("targetOnlyReachable")), @@ -488,7 +488,7 @@ bool LocalPlayer::pickUp(FloorItem *const item) { if (actorManager && actorManager->checkForPickup(item)) { - PlayerInfo::pickUpItem(item, true); + PlayerInfo::pickUpItem(item, Sfx_true); mPickUpTarget = nullptr; } } @@ -795,7 +795,7 @@ void LocalPlayer::stopAttack(const bool keepAttack) if (!PacketLimiter::limitPackets(PACKET_STOPATTACK)) return; - if (mServerAttack && mAction == BeingAction::ATTACK) + if (mServerAttack == Keep_true && mAction == BeingAction::ATTACK) playerHandler->stopAttack(); untarget(); @@ -1039,7 +1039,7 @@ void LocalPlayer::optionChanged(const std::string &value) else if (value == "drawPath") mDrawPath = config.getBoolValue("drawPath"); else if (value == "serverAttack") - mServerAttack = config.getBoolValue("serverAttack"); + mServerAttack = fromBool(config.getBoolValue("serverAttack"), Keep); else if (value == "attackMoving") mAttackMoving = config.getBoolValue("attackMoving"); else if (value == "attackNext") @@ -1327,7 +1327,7 @@ void LocalPlayer::changeEquipmentBeforeAttack(const Being *const target) const // if sword not equiped if (item->isEquipped() == Equipped_false) - PlayerInfo::equipItem(item, true); + PlayerInfo::equipItem(item, Sfx_true); // if need equip shield too if (settings.attackWeaponType == 3) @@ -1341,7 +1341,7 @@ void LocalPlayer::changeEquipmentBeforeAttack(const Being *const target) const break; } if (item && item->isEquipped() == Equipped_false) - PlayerInfo::equipItem(item, true); + PlayerInfo::equipItem(item, Sfx_true); } } // big distance. allowed only bow @@ -1361,7 +1361,7 @@ void LocalPlayer::changeEquipmentBeforeAttack(const Being *const target) const return; if (item->isEquipped() == Equipped_false) - PlayerInfo::equipItem(item, true); + PlayerInfo::equipItem(item, Sfx_true); } } @@ -2076,7 +2076,7 @@ void LocalPlayer::targetMoved() const /* if (mKeepAttacking) { - if (mTarget && mServerAttack) + if (mTarget && mServerAttack == Keep_true) { logger->log("LocalPlayer::targetMoved0"); if (!PacketLimiter::limitPackets(PACKET_ATTACK)) @@ -2312,7 +2312,7 @@ void LocalPlayer::imitateOutfit(const Being *const player, const Item *const item = inv->findItemBySprite(path, player->getGender(), player->getSubType()); if (item && item->isEquipped() == Equipped_false) - PlayerInfo::equipItem(item, false); + PlayerInfo::equipItem(item, Sfx_false); } else { @@ -2327,7 +2327,7 @@ void LocalPlayer::imitateOutfit(const Being *const player, if (item) { // logger->log("unequiping"); - PlayerInfo::unequipItem(item, false); + PlayerInfo::unequipItem(item, Sfx_false); } } } diff --git a/src/being/localplayer.h b/src/being/localplayer.h index 02c092f69..a4f26dcff 100644 --- a/src/being/localplayer.h +++ b/src/being/localplayer.h @@ -25,6 +25,8 @@ #include "being/being.h" +#include "enums/simpletypes.h" + #include "enums/being/pickup.h" #include "gui/userpalette.h" @@ -486,7 +488,7 @@ class LocalPlayer final : public Being, bool mUpdateName; bool mBlockAdvert; bool mTargetDeadPlayers; - bool mServerAttack; + Keep mServerAttack; bool mEnableAdvert; bool mTradebot; bool mTargetOnlyReachable; diff --git a/src/being/playerinfo.cpp b/src/being/playerinfo.cpp index 687ab5382..8ed30492f 100644 --- a/src/being/playerinfo.cpp +++ b/src/being/playerinfo.cpp @@ -66,7 +66,7 @@ Equipment *mEquipment = nullptr; int mPetBeingId = 0; GuildPositionFlags::Type mGuildPositionFlags = GuildPositionFlags::None; -bool mTrading = false; +Trading mTrading = Trading_false; bool mVending = false; int mLevelProgress = 0; std::set<int> mProtectedItems; @@ -95,11 +95,13 @@ int getAttribute(const int id) return 0; } -void setAttribute(const int id, const int value, const bool notify) +void setAttribute(const int id, + const int value, + const Notify notify) { const int old = mData.mAttributes[id]; mData.mAttributes[id] = value; - if (notify) + if (notify == Notify_true) triggerAttr(id, old); } @@ -128,11 +130,11 @@ int getStatBase(const int id) return 0; } -void setStatBase(const int id, const int value, const bool notify) +void setStatBase(const int id, const int value, const Notify notify) { const int old = mData.mStats[id].base; mData.mStats[id].base = value; - if (notify) + if (notify == Notify_true) triggerStat(id, old, 0); } @@ -145,11 +147,11 @@ int getStatMod(const int id) return 0; } -void setStatMod(const int id, const int value, const bool notify) +void setStatMod(const int id, const int value, const Notify notify) { const int old = mData.mStats[id].mod; mData.mStats[id].mod = value; - if (notify) + if (notify == Notify_true) triggerStat(id, old, 0); } @@ -179,8 +181,10 @@ const std::pair<int, int> getStatExperience(const int id) return std::pair<int, int>(a, b); } -void setStatExperience(const int id, const int have, - const int need, const bool notify) +void setStatExperience(const int id, + const int have, + const int need, + const Notify notify) { Stat &stat = mData.mStats[id]; @@ -188,7 +192,7 @@ void setStatExperience(const int id, const int have, const int oldExpNeed = stat.expNeed; stat.exp = have; stat.expNeed = need; - if (notify) + if (notify == Notify_true) triggerStat(id, oldExp, oldExpNeed); } @@ -238,28 +242,28 @@ void setEquipmentBackend(Equipment::Backend *const backend) mEquipment->setBackend(backend); } -void equipItem(const Item *const item, const bool sfx) +void equipItem(const Item *const item, const Sfx sfx) { - if (sfx) + if (sfx == Sfx_true) ItemSoundManager::playSfx(item, ItemSoundEvent::EQUIP); inventoryHandler->equipItem(item); } -void unequipItem(const Item *const item, const bool sfx) +void unequipItem(const Item *const item, const Sfx sfx) { - if (sfx) + if (sfx == Sfx_true) ItemSoundManager::playSfx(item, ItemSoundEvent::UNEQUIP); inventoryHandler->unequipItem(item); } -void useItem(const Item *const item, const bool sfx) +void useItem(const Item *const item, const Sfx sfx) { - if (sfx) + if (sfx == Sfx_true) ItemSoundManager::playSfx(item, ItemSoundEvent::USE); inventoryHandler->useItem(item); } -void useEquipItem(const Item *const item, const bool sfx) +void useEquipItem(const Item *const item, const Sfx sfx) { if (item) { @@ -267,13 +271,13 @@ void useEquipItem(const Item *const item, const bool sfx) { if (item->isEquipped() == Equipped_true) { - if (sfx) + if (sfx == Sfx_true) ItemSoundManager::playSfx(item, ItemSoundEvent::UNEQUIP); inventoryHandler->unequipItem(item); } else { - if (sfx) + if (sfx == Sfx_true) ItemSoundManager::playSfx(item, ItemSoundEvent::EQUIP); inventoryHandler->equipItem(item); } @@ -283,14 +287,14 @@ void useEquipItem(const Item *const item, const bool sfx) if (mProtectedItems.find(item->getId()) == mProtectedItems.end()) { inventoryHandler->useItem(item); - if (sfx) + if (sfx == Sfx_true) ItemSoundManager::playSfx(item, ItemSoundEvent::USE); } } } } -void useEquipItem2(const Item *const item, const bool sfx) +void useEquipItem2(const Item *const item, const Sfx sfx) { if (item) { @@ -298,13 +302,13 @@ void useEquipItem2(const Item *const item, const bool sfx) { if (item->isEquipped() == Equipped_true) { - if (sfx) + if (sfx == Sfx_true) ItemSoundManager::playSfx(item, ItemSoundEvent::UNEQUIP); inventoryHandler->unequipItem(item); } else { - if (sfx) + if (sfx == Sfx_true) ItemSoundManager::playSfx(item, ItemSoundEvent::EQUIP); inventoryHandler->equipItem(item); } @@ -313,7 +317,7 @@ void useEquipItem2(const Item *const item, const bool sfx) { if (mProtectedItems.find(item->getId()) == mProtectedItems.end()) { - if (sfx) + if (sfx == Sfx_true) ItemSoundManager::playSfx(item, ItemSoundEvent::USE); inventoryHandler->useItem(item); } @@ -321,19 +325,19 @@ void useEquipItem2(const Item *const item, const bool sfx) } } -void dropItem(const Item *const item, const int amount, const bool sfx) +void dropItem(const Item *const item, const int amount, const Sfx sfx) { if (item && mProtectedItems.find(item->getId()) == mProtectedItems.end()) { - if (sfx) + if (sfx == Sfx_true) ItemSoundManager::playSfx(item, ItemSoundEvent::DROP); inventoryHandler->dropItem(item, amount); } } -void pickUpItem(const FloorItem *const item, const bool sfx) +void pickUpItem(const FloorItem *const item, const Sfx sfx) { - if (sfx) + if (sfx == Sfx_true) ItemSoundManager::playSfx(item, ItemSoundEvent::PICKUP); playerHandler->pickUp(item); } @@ -359,12 +363,12 @@ void logic() { } -bool isTrading() +Trading isTrading() { return mTrading; } -void setTrading(const bool trading) +void setTrading(const Trading trading) { mTrading = trading; } @@ -375,14 +379,14 @@ void updateAttrs() if (attackDelay) { setStatBase(Attributes::ATTACK_SPEED, - getStatBase(Attributes::ATK) * 1000 / attackDelay, false); + getStatBase(Attributes::ATK) * 1000 / attackDelay, Notify_false); setStatMod(Attributes::ATTACK_SPEED, - getStatMod(Attributes::ATK) * 1000 / attackDelay, true); + getStatMod(Attributes::ATK) * 1000 / attackDelay, Notify_true); } else { - setStatBase(Attributes::ATTACK_SPEED, 0, false); - setStatMod(Attributes::ATTACK_SPEED, 0, true); + setStatBase(Attributes::ATTACK_SPEED, 0, Notify_false); + setStatMod(Attributes::ATTACK_SPEED, 0, Notify_true); } } @@ -569,7 +573,7 @@ void updateMoveAI() homunculusHandler->moveToMaster(); } -void updateAttackAi(const int targetId, const bool keep) +void updateAttackAi(const int targetId, const Keep keep) { if (mMercenary) mercenaryHandler->attack(targetId, keep); diff --git a/src/being/playerinfo.h b/src/being/playerinfo.h index d780c7da7..e405dbe06 100644 --- a/src/being/playerinfo.h +++ b/src/being/playerinfo.h @@ -25,6 +25,7 @@ #include "equipment.h" #include "enums/guildpositionflags.h" +#include "enums/simpletypes.h" #include "enums/state.h" #include <map> @@ -75,7 +76,6 @@ struct PetInfo; /** * A database like namespace which holds global info about the localplayer * - * NOTE: 'bool notify' is used to determine if a event is to be triggered. */ namespace PlayerInfo { @@ -90,7 +90,7 @@ namespace PlayerInfo * Changes the value of the given attribute. */ void setAttribute(const int id, const int value, - const bool notify = true); + const Notify notify = Notify_true); int getSkillLevel(const int id) A_WARN_UNUSED; @@ -107,7 +107,7 @@ namespace PlayerInfo * Changes the base value of the given stat. */ void setStatBase(const int id, const int value, - const bool notify = true); + const Notify notify = Notify_true); /** * Returns the modifier for the given stat. @@ -118,7 +118,7 @@ namespace PlayerInfo * Changes the modifier for the given stat. */ void setStatMod(const int id, const int value, - const bool notify = true); + const Notify notify = Notify_true); /** * Returns the current effective value of the given stat. Effective is base @@ -129,7 +129,7 @@ namespace PlayerInfo /** * Changes the level of the given stat. */ - void setStatLevel(int id, int value, bool notify = true); + void setStatLevel(int id, int value, Notify notify = Notify_true); /** * Returns the experience of the given stat. @@ -139,8 +139,10 @@ namespace PlayerInfo /** * Changes the experience of the given stat. */ - void setStatExperience(const int id, const int have, - const int need, const bool notify = true); + void setStatExperience(const int id, + const int have, + const int need, + const Notify notify = Notify_true); // --- Inventory / Equipment -------------------------------------------------- @@ -192,12 +194,12 @@ namespace PlayerInfo * Returns true if the player is involved in a trade at the moment, false * otherwise. */ - bool isTrading(); + Trading isTrading(); /** * Sets whether the player is currently involved in trade or not. */ - void setTrading(const bool trading); + void setTrading(const Trading trading); void updateAttrs(); @@ -222,19 +224,19 @@ namespace PlayerInfo void setEquipmentBackend(Equipment::Backend *const backend); - void equipItem(const Item *const item, const bool sfx); + void equipItem(const Item *const item, const Sfx sfx); - void unequipItem(const Item *const item, const bool sfx); + void unequipItem(const Item *const item, const Sfx sfx); - void useItem(const Item *const item, const bool sfx); + void useItem(const Item *const item, const Sfx sfx); - void useEquipItem(const Item *const item, const bool sfx); + void useEquipItem(const Item *const item, const Sfx sfx); - void useEquipItem2(const Item *const item, const bool sfx); + void useEquipItem2(const Item *const item, const Sfx sfx); - void dropItem(const Item *const item, const int amount, const bool sfx); + void dropItem(const Item *const item, const int amount, const Sfx sfx); - void pickUpItem(const FloorItem *const item, const bool sfx); + void pickUpItem(const FloorItem *const item, const Sfx sfx); void protectItem(const int id); @@ -269,7 +271,7 @@ namespace PlayerInfo void updateMoveAI(); - void updateAttackAi(const int targetId, const bool keep); + void updateAttackAi(const int targetId, const Keep keep); std::string getRoomName(); |