From 4a337b7a42d0c92bc2ed26b7e206188dc04c569d Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 11 Feb 2015 12:16:03 +0300 Subject: Add typed bool type Equipm. --- src/being/playerinfo.cpp | 4 ++-- src/beingequipbackend.cpp | 3 ++- src/enums/simpletypes.h | 1 + src/gui/popups/popupmenu.cpp | 3 ++- src/gui/widgets/itemcontainer.cpp | 10 +++++++--- src/gui/windows/equipmentwindow.cpp | 6 +++--- src/gui/windows/inventorywindow.cpp | 3 ++- src/gui/windows/itemamountwindow.cpp | 3 ++- src/gui/windows/npcdialog.cpp | 13 +++++++++---- src/gui/windows/outfitwindow.cpp | 2 +- src/gui/windows/tradewindow.cpp | 26 +++++++++++++++++++++----- src/gui/windows/tradewindow.h | 2 +- src/inventory.cpp | 4 ++-- src/inventory.h | 4 ++-- src/item.cpp | 5 +++-- src/item.h | 8 ++++---- src/itemshortcut.cpp | 4 ++-- src/net/ea/inventoryitem.h | 4 ++-- src/net/eathena/inventoryhandler.cpp | 23 ++++++++++++++--------- src/net/eathena/tradehandler.cpp | 19 +++++++++++++------ src/net/tmwa/inventoryhandler.cpp | 32 ++++++++++++++++++++------------ src/net/tmwa/tradehandler.cpp | 4 ++-- src/shopitem.cpp | 6 ++++-- 23 files changed, 121 insertions(+), 68 deletions(-) diff --git a/src/being/playerinfo.cpp b/src/being/playerinfo.cpp index 91d0119b9..5b2b60433 100644 --- a/src/being/playerinfo.cpp +++ b/src/being/playerinfo.cpp @@ -263,7 +263,7 @@ void useEquipItem(const Item *const item, const bool sfx) { if (item) { - if (item->isEquipment()) + if (item->isEquipment() == Equipm_true) { if (item->isEquipped()) { @@ -294,7 +294,7 @@ void useEquipItem2(const Item *const item, const bool sfx) { if (item) { - if (!item->isEquipment()) + if (item->isEquipment() == Equipm_false) { if (item->isEquipped()) { diff --git a/src/beingequipbackend.cpp b/src/beingequipbackend.cpp index 7491eeec8..106f7edb9 100644 --- a/src/beingequipbackend.cpp +++ b/src/beingequipbackend.cpp @@ -47,7 +47,8 @@ BeingEquipBackend::BeingEquipBackend(Being *const being) Identified_true, Damaged_false, Favorite_false, - true, true); + Equipm_true, + true); } } } diff --git a/src/enums/simpletypes.h b/src/enums/simpletypes.h index 818d3e281..a377ae003 100644 --- a/src/enums/simpletypes.h +++ b/src/enums/simpletypes.h @@ -50,5 +50,6 @@ defBoolEnum(Identified); defBoolEnum(Damaged); defBoolEnum(Favorite); +defBoolEnum(Equipm); #endif // ENUMS_SIMPLETYPES_H diff --git a/src/gui/popups/popupmenu.cpp b/src/gui/popups/popupmenu.cpp index e46f4bec4..47334c407 100644 --- a/src/gui/popups/popupmenu.cpp +++ b/src/gui/popups/popupmenu.cpp @@ -2554,7 +2554,8 @@ void PopupMenu::addProtection() void PopupMenu::addUseDrop(const Item *const item, const bool isProtected) { const ItemInfo &info = item->getInfo(); - const std::string &str = (item->isEquipment() && item->isEquipped()) + const std::string &str + = (item->isEquipment() == Equipm_true && item->isEquipped()) ? info.getUseButton2() : info.getUseButton(); if (str.empty()) diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp index c557b960d..dfb5a94cf 100644 --- a/src/gui/widgets/itemcontainer.cpp +++ b/src/gui/widgets/itemcontainer.cpp @@ -593,10 +593,14 @@ void ItemContainer::mouseReleased(MouseEvent &event) if (item && !PlayerInfo::isItemProtected(item->getId())) { mInventory->addItem(item->getId(), item->getType(), - 1, 1, item->getColor(), - item->getIdentified(), item->getDamaged(), + 1, + 1, + item->getColor(), + item->getIdentified(), + item->getDamaged(), item->getFavorite(), - false, false); + Equipm_false, + false); } return; } diff --git a/src/gui/windows/equipmentwindow.cpp b/src/gui/windows/equipmentwindow.cpp index 24bda1f0d..74bcaaafb 100644 --- a/src/gui/windows/equipmentwindow.cpp +++ b/src/gui/windows/equipmentwindow.cpp @@ -322,7 +322,7 @@ void EquipmentWindow::action(const ActionEvent &event) if (dragDrop.getSource() == DRAGDROP_SOURCE_INVENTORY) { - if (item->isEquipment()) + if (item->isEquipment() == Equipm_true) { if (!item->isEquipped()) PlayerInfo::equipItem(item, true); @@ -466,7 +466,7 @@ void EquipmentWindow::mouseReleased(MouseEvent &event) if (dragDrop.getSource() == DRAGDROP_SOURCE_INVENTORY) { - if (item->isEquipment()) + if (item->isEquipment() == Equipm_true) { if (!item->isEquipped()) PlayerInfo::equipItem(item, true); @@ -474,7 +474,7 @@ void EquipmentWindow::mouseReleased(MouseEvent &event) } else if (dragDrop.getSource() == DRAGDROP_SOURCE_EQUIPMENT) { - if (item->isEquipment()) + if (item->isEquipment() == Equipm_true) { const int x = event.getX(); const int y = event.getY(); diff --git a/src/gui/windows/inventorywindow.cpp b/src/gui/windows/inventorywindow.cpp index 7bd21e258..b788039a9 100644 --- a/src/gui/windows/inventorywindow.cpp +++ b/src/gui/windows/inventorywindow.cpp @@ -741,7 +741,8 @@ void InventoryWindow::updateButtons(const Item *item) if (mUseButton) { const ItemInfo &info = item->getInfo(); - const std::string &str = (item->isEquipment() && item->isEquipped()) + const std::string &str + = (item->isEquipment() == Equipm_true && item->isEquipped()) ? info.getUseButton2() : info.getUseButton(); if (str.empty()) { diff --git a/src/gui/windows/itemamountwindow.cpp b/src/gui/windows/itemamountwindow.cpp index f4203092f..6ffd857bc 100644 --- a/src/gui/windows/itemamountwindow.cpp +++ b/src/gui/windows/itemamountwindow.cpp @@ -338,7 +338,8 @@ void ItemAmountWindow::action(const ActionEvent &event) Identified_true, Damaged_true, Favorite_false, - false, false); + Equipm_false, + false); if (mUsage == ShopBuyAdd) mMax = 10000; diff --git a/src/gui/windows/npcdialog.cpp b/src/gui/windows/npcdialog.cpp index fa5cb21d7..9c93b7474 100644 --- a/src/gui/windows/npcdialog.cpp +++ b/src/gui/windows/npcdialog.cpp @@ -470,11 +470,16 @@ void NpcDialog::action(const ActionEvent &event) const Item *const item = inventoryWindow->getSelectedItem(); if (item) { - mInventory->addItem(item->getId(), item->getType(), - 1, 1, item->getColor(), - item->getIdentified(), item->getDamaged(), + mInventory->addItem(item->getId(), + item->getType(), + 1, + 1, + item->getColor(), + item->getIdentified(), + item->getDamaged(), item->getFavorite(), - false, false); + Equipm_false, + false); } } } diff --git a/src/gui/windows/outfitwindow.cpp b/src/gui/windows/outfitwindow.cpp index 3393a1337..d73f86a05 100644 --- a/src/gui/windows/outfitwindow.cpp +++ b/src/gui/windows/outfitwindow.cpp @@ -283,7 +283,7 @@ void OutfitWindow::wearOutfit(const int outfit, const bool unwearEmpty, mItems[outfit][i], mItemColors[outfit][i]); if (item && !item->isEquipped() && item->getQuantity()) { - if (item->isEquipment()) + if (item->isEquipment() == Equipm_true) { PlayerInfo::equipItem(item, false); isEmpty = false; diff --git a/src/gui/windows/tradewindow.cpp b/src/gui/windows/tradewindow.cpp index 41bde7c19..1dc1a9882 100644 --- a/src/gui/windows/tradewindow.cpp +++ b/src/gui/windows/tradewindow.cpp @@ -205,8 +205,16 @@ void TradeWindow::addItem(const int id, const Favorite favorite) const { Inventory *inv = own ? mMyInventory : mPartnerInventory; - inv->addItem(id, type, quantity, refine, color, - identified, damaged, favorite, false, false); + inv->addItem(id, + type, + quantity, + refine, + color, + identified, + damaged, + favorite, + Equipm_false, + false); } void TradeWindow::addItem2(const int id, @@ -220,11 +228,19 @@ void TradeWindow::addItem2(const int id, const Identified identified, const Damaged damaged, const Favorite favorite, - const bool equipment) const + const Equipm equipment) const { Inventory *inv = own ? mMyInventory : mPartnerInventory; - const int slot = inv->addItem(id, type, quantity, refine, color, - identified, damaged, favorite, equipment, false); + const int slot = inv->addItem(id, + type, + quantity, + refine, + color, + identified, + damaged, + favorite, + equipment, + false); if (slot >= 0) inv->setCards(slot, cards, sz); } diff --git a/src/gui/windows/tradewindow.h b/src/gui/windows/tradewindow.h index 89cf36a6a..c774d521d 100644 --- a/src/gui/windows/tradewindow.h +++ b/src/gui/windows/tradewindow.h @@ -98,7 +98,7 @@ class TradeWindow final : public Window, const Identified identified, const Damaged damaged, const Favorite favorite, - const bool equipment) const; + const Equipm equipment) const; /** * Change quantity of an item. diff --git a/src/inventory.cpp b/src/inventory.cpp index 20731ad10..dc5e59717 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -113,7 +113,7 @@ int Inventory::addItem(const int id, const Identified identified, const Damaged damaged, const Favorite favorite, - const bool equipment, + const Equipm equipment, const bool equipped) { const int slot = getFreeSlot(); @@ -131,7 +131,7 @@ void Inventory::setItem(const int index, const Identified identified, const Damaged damaged, const Favorite favorite, - const bool equipment, + const Equipm equipment, const bool equipped) { if (index < 0 || index >= static_cast(mSize)) diff --git a/src/inventory.h b/src/inventory.h index 29cb6ad77..d5045c941 100644 --- a/src/inventory.h +++ b/src/inventory.h @@ -88,7 +88,7 @@ class Inventory final const Identified identified, const Damaged damaged, const Favorite favorite, - const bool equipment, + const Equipm equipment, const bool equipped); /** @@ -103,7 +103,7 @@ class Inventory final const Identified identified, const Damaged damaged, const Favorite favorite, - const bool equipment, + const Equipm equipment, const bool equipped); void setCards(const int index, diff --git a/src/item.cpp b/src/item.cpp index 07c33dc49..bd4cb25de 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -45,7 +45,7 @@ Item::Item(const int id, const Identified identified, const Damaged damaged, const Favorite favorite, - const bool equipment, + const Equipm equipment, const bool equipped) : mId(0), mColor(0), @@ -85,7 +85,8 @@ void Item::setId(const int id, const unsigned char color) mColor = color; // Types 0 and 1 are not equippable items. - mEquipment = id && static_cast(getInfo().getType()) >= 2; + mEquipment = fromBool(id && static_cast(getInfo().getType()) + >= 2, Equipm); if (mImage) mImage->decRef(); diff --git a/src/item.h b/src/item.h index cd423ccf8..1581bb993 100644 --- a/src/item.h +++ b/src/item.h @@ -52,7 +52,7 @@ class Item notfinal const Identified identified, const Damaged damaged, const Favorite favorite, - const bool equipment, + const Equipm equipment, const bool equipped); A_DELETE_COPY(Item) @@ -100,13 +100,13 @@ class Item notfinal /** * Sets whether this item is considered equipment. */ - void setEquipment(const bool equipment) + void setEquipment(const Equipm equipment) { mEquipment = equipment; } /** * Returns whether this item is considered equipment. */ - bool isEquipment() const A_WARN_UNUSED + Equipm isEquipment() const A_WARN_UNUSED { return mEquipment; } /** @@ -221,7 +221,7 @@ class Item notfinal uint8_t mRefine; /**< Item refine level. */ int mInvIndex; /**< Inventory index. */ int mType; /**< Item type. */ - bool mEquipment; /**< Item is equipment. */ + Equipm mEquipment; /**< Item is equipment. */ bool mEquipped; /**< Item is equipped. */ bool mInEquipment; /**< Item is in equipment */ Identified mIdentified; diff --git a/src/itemshortcut.cpp b/src/itemshortcut.cpp index 54f317ef3..f2c5e92c0 100644 --- a/src/itemshortcut.cpp +++ b/src/itemshortcut.cpp @@ -157,7 +157,7 @@ void ItemShortcut::equipItem(const int index) const const Item *const item = inv->findItem(itemId, mItemColors[index]); if (item && item->getQuantity()) { - if (item->isEquipment()) + if (item->isEquipment() == Equipm_true) { if (!item->isEquipped()) PlayerInfo::equipItem(item, true); @@ -177,7 +177,7 @@ void ItemShortcut::unequipItem(const int index) const const Item *const item = inv->findItem(itemId, mItemColors[index]); if (item && item->getQuantity()) { - if (item->isEquipment()) + if (item->isEquipment() == Equipm_true) { if (item->isEquipped()) PlayerInfo::unequipItem(item, true); diff --git a/src/net/ea/inventoryitem.h b/src/net/ea/inventoryitem.h index 936e4a4ee..bd2d115cd 100644 --- a/src/net/ea/inventoryitem.h +++ b/src/net/ea/inventoryitem.h @@ -52,7 +52,7 @@ class InventoryItem final Identified identified; Damaged damaged; Favorite favorite; - bool equip; + Equipm equip; InventoryItem(const int slot0, const int id0, @@ -64,7 +64,7 @@ class InventoryItem final const Identified identified0, const Damaged damaged0, const Favorite favorite0, - const bool equip0) : + Equipm equip0) : slot(slot0), id(id0), type(type0), diff --git a/src/net/eathena/inventoryhandler.cpp b/src/net/eathena/inventoryhandler.cpp index 162b69f2b..835b341a8 100644 --- a/src/net/eathena/inventoryhandler.cpp +++ b/src/net/eathena/inventoryhandler.cpp @@ -386,7 +386,8 @@ void InventoryHandler::processPlayerEquipment(Net::MessageIn &msg) fromBool(flags.bits.isIdentified, Identified), fromBool(flags.bits.isDamaged, Damaged), fromBool(flags.bits.isFavorite, Favorite), - true, false); + Equipm_true, + false); inventory->setCards(index, cards, 4); } @@ -486,7 +487,8 @@ void InventoryHandler::processPlayerInventoryAdd(Net::MessageIn &msg) fromBool(identified, Identified), fromBool(damaged, Damaged), Favorite_false, - equipType != 0, false); + fromBool(equipType, Equipm), + false); inventory->setCards(index, cards, 4); } ArrowsListener::distributeEvent(); @@ -534,7 +536,8 @@ void InventoryHandler::processPlayerInventory(Net::MessageIn &msg) fromBool(flags.bits.isIdentified, Identified), fromBool(flags.bits.isDamaged, Damaged), fromBool(flags.bits.isFavorite, Favorite), - false, false); + Equipm_false, + false); inventory->setCards(index, cards, 4); } } @@ -570,7 +573,7 @@ void InventoryHandler::processPlayerStorage(Net::MessageIn &msg) fromBool(flags.bits.isIdentified, Identified), fromBool(flags.bits.isDamaged, Damaged), fromBool(flags.bits.isFavorite, Favorite), - false)); + Equipm_false)); } BLOCK_END("InventoryHandler::processPlayerInventory") } @@ -671,7 +674,7 @@ void InventoryHandler::processPlayerStorageEquip(Net::MessageIn &msg) fromBool(flags.bits.isIdentified, Identified), fromBool(flags.bits.isDamaged, Damaged), fromBool(flags.bits.isFavorite, Favorite), - false)); + Equipm_false)); } BLOCK_END("InventoryHandler::processPlayerStorageEquip") } @@ -705,7 +708,8 @@ void InventoryHandler::processPlayerStorageAdd(Net::MessageIn &msg) fromBool(identified, Identified), Damaged_false, Favorite_false, - false, false); + Equipm_false, + false); mStorage->setCards(index, cards, 4); } } @@ -848,7 +852,8 @@ void InventoryHandler::processPlayerCartAdd(Net::MessageIn &msg) fromBool(identified, Identified), Damaged_false, Favorite_false, - false, false); + Equipm_false, + false); inventory->setCards(index, cards, 4); } BLOCK_END("InventoryHandler::processPlayerCartAdd") @@ -882,7 +887,7 @@ void InventoryHandler::processPlayerCartEquip(Net::MessageIn &msg) fromBool(flags.bits.isIdentified, Identified), fromBool(flags.bits.isDamaged, Damaged), fromBool(flags.bits.isFavorite, Favorite), - false)); + Equipm_false)); } BLOCK_END("InventoryHandler::processPlayerCartEquip") } @@ -914,7 +919,7 @@ void InventoryHandler::processPlayerCartItems(Net::MessageIn &msg) fromBool(flags.bits.isIdentified, Identified), fromBool(flags.bits.isDamaged, Damaged), fromBool(flags.bits.isFavorite, Favorite), - false)); + Equipm_false)); } BLOCK_END("InventoryHandler::processPlayerCartItems") } diff --git a/src/net/eathena/tradehandler.cpp b/src/net/eathena/tradehandler.cpp index d6240c580..c2ff5553c 100644 --- a/src/net/eathena/tradehandler.cpp +++ b/src/net/eathena/tradehandler.cpp @@ -210,7 +210,7 @@ void TradeHandler::processTradeItemAdd(Net::MessageIn &msg) fromBool(identify, Identified), Damaged_false, Favorite_false, - false); + Equipm_false); } } } @@ -230,11 +230,18 @@ void TradeHandler::processTradeItemAddResponse(Net::MessageIn &msg) return; if (tradeWindow) { - tradeWindow->addItem2(item->getId(), item->getType(), - item->getCards(), 4, - true, mQuantity, item->getRefine(), item->getColor(), - item->getIdentified(), item->getDamaged(), - item->getFavorite(), item->isEquipment()); + tradeWindow->addItem2(item->getId(), + item->getType(), + item->getCards(), + 4, + true, + mQuantity, + item->getRefine(), + item->getColor(), + item->getIdentified(), + item->getDamaged(), + item->getFavorite(), + item->isEquipment()); } item->increaseQuantity(-mQuantity); mItemIndex = -1; diff --git a/src/net/tmwa/inventoryhandler.cpp b/src/net/tmwa/inventoryhandler.cpp index 45b9d47eb..0d0611122 100644 --- a/src/net/tmwa/inventoryhandler.cpp +++ b/src/net/tmwa/inventoryhandler.cpp @@ -301,7 +301,8 @@ void InventoryHandler::processPlayerEquipment(Net::MessageIn &msg) Identified_true, Damaged_false, Favorite_false, - true, false); + Equipm_true, + false); } else { @@ -310,7 +311,8 @@ void InventoryHandler::processPlayerEquipment(Net::MessageIn &msg) fromBool(identified, Identified), Damaged_false, Favorite_false, - true, false); + Equipm_true, + false); } inventory->setCards(index, cards, 4); } @@ -411,7 +413,8 @@ void InventoryHandler::processPlayerInventoryAdd(Net::MessageIn &msg) Identified_true, Damaged_false, Favorite_false, - equipType != 0, false); + fromBool(equipType, Equipm), + false); } else { @@ -420,7 +423,8 @@ void InventoryHandler::processPlayerInventoryAdd(Net::MessageIn &msg) fromBool(identified, Identified), Damaged_false, Favorite_false, - equipType != 0, false); + fromBool(equipType, Equipm), + false); } inventory->setCards(index, cards, 4); } @@ -480,7 +484,8 @@ void InventoryHandler::processPlayerInventory(Net::MessageIn &msg) Identified_true, Damaged_false, Favorite_false, - isEquipment, false); + fromBool(isEquipment, Equipm), + false); } else { @@ -489,7 +494,8 @@ void InventoryHandler::processPlayerInventory(Net::MessageIn &msg) fromBool(identified, Identified), Damaged_false, Favorite_false, - isEquipment, false); + fromBool(isEquipment, Equipm), + false); } inventory->setCards(index, cards, 4); } @@ -532,7 +538,7 @@ void InventoryHandler::processPlayerStorage(Net::MessageIn &msg) Identified_true, Damaged_false, Favorite_false, - false)); + Equipm_false)); } else { @@ -541,7 +547,7 @@ void InventoryHandler::processPlayerStorage(Net::MessageIn &msg) fromBool(identified, Identified), Damaged_false, Favorite_false, - false)); + Equipm_false)); } } BLOCK_END("InventoryHandler::processPlayerInventory") @@ -613,7 +619,7 @@ void InventoryHandler::processPlayerStorageEquip(Net::MessageIn &msg) Identified_true, Damaged_false, Favorite_false, - false)); + Equipm_false)); } else { @@ -622,7 +628,7 @@ void InventoryHandler::processPlayerStorageEquip(Net::MessageIn &msg) fromBool(identified, Identified), Damaged_false, Favorite_false, - false)); + Equipm_false)); } } BLOCK_END("InventoryHandler::processPlayerStorageEquip") @@ -658,7 +664,8 @@ void InventoryHandler::processPlayerStorageAdd(Net::MessageIn &msg) Identified_true, Damaged_false, Favorite_false, - false, false); + Equipm_false, + false); } else { @@ -667,7 +674,8 @@ void InventoryHandler::processPlayerStorageAdd(Net::MessageIn &msg) fromBool(identified, Identified), Damaged_false, Favorite_false, - false, false); + Equipm_false, + false); } mStorage->setCards(index, cards, 4); } diff --git a/src/net/tmwa/tradehandler.cpp b/src/net/tmwa/tradehandler.cpp index 5411a59f5..2ec2c90d7 100644 --- a/src/net/tmwa/tradehandler.cpp +++ b/src/net/tmwa/tradehandler.cpp @@ -199,7 +199,7 @@ void TradeHandler::processTradeItemAdd(Net::MessageIn &msg) Identified_true, Damaged_false, Favorite_false, - false); + Equipm_false); } else { @@ -210,7 +210,7 @@ void TradeHandler::processTradeItemAdd(Net::MessageIn &msg) fromBool(identify, Identified), Damaged_false, Favorite_false, - false); + Equipm_false); } } } diff --git a/src/shopitem.cpp b/src/shopitem.cpp index be7e232eb..227d1d1b2 100644 --- a/src/shopitem.cpp +++ b/src/shopitem.cpp @@ -42,7 +42,8 @@ ShopItem::ShopItem(const int inventoryIndex, Identified_true, Damaged_false, Favorite_false, - false, false), + Equipm_false, + false), mDisplayName(), mDuplicates(), mPrice(price), @@ -61,7 +62,8 @@ ShopItem::ShopItem(const int id, Identified_true, Damaged_false, Favorite_false, - false, false), + Equipm_false, + false), mDisplayName(), mDuplicates(), mPrice(price), -- cgit v1.2.3-70-g09d2