summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-09-28 21:26:48 +0200
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-09-28 21:26:48 +0200
commit3c89797394c83db8bc2204fdf5841dd3068f09d0 (patch)
tree6fc2d3ad06b9d589851397ff723a32b231a100de /src
parent51f0c23ac190c83bebeace8a49cd2ecd1143fa8c (diff)
downloadmana-3c89797394c83db8bc2204fdf5841dd3068f09d0.tar.gz
mana-3c89797394c83db8bc2204fdf5841dd3068f09d0.tar.bz2
mana-3c89797394c83db8bc2204fdf5841dd3068f09d0.tar.xz
mana-3c89797394c83db8bc2204fdf5841dd3068f09d0.zip
Removed getter/setter cruft from ItemInfo
Made the class and the code in general more readable by removing all the needless getters and setters.
Diffstat (limited to 'src')
-rw-r--r--src/being.cpp18
-rw-r--r--src/flooritem.cpp5
-rw-r--r--src/gui/buydialog.cpp4
-rw-r--r--src/gui/inventorywindow.cpp8
-rw-r--r--src/gui/itempopup.cpp16
-rw-r--r--src/gui/popupmenu.cpp11
-rw-r--r--src/gui/widgets/browserbox.cpp2
-rw-r--r--src/gui/widgets/chattab.cpp6
-rw-r--r--src/gui/widgets/itemcontainer.cpp6
-rw-r--r--src/item.cpp4
-rw-r--r--src/itemshortcut.cpp6
-rw-r--r--src/localplayer.cpp10
-rw-r--r--src/resources/beinginfo.cpp2
-rw-r--r--src/resources/itemdb.cpp261
-rw-r--r--src/resources/itemdb.h23
-rw-r--r--src/resources/iteminfo.h163
-rw-r--r--src/resources/monsterdb.cpp9
-rw-r--r--src/resources/npcdb.cpp7
-rw-r--r--src/resources/spritedef.h15
-rw-r--r--src/shopitem.cpp2
20 files changed, 213 insertions, 365 deletions
diff --git a/src/being.cpp b/src/being.cpp
index b9a24509..0e344873 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -358,15 +358,11 @@ void Being::takeDamage(Being *attacker, int amount,
if (amount > 0)
{
+ auto &hurtSfx = mInfo->getSound(SOUND_EVENT_HURT);
if (attacker)
- {
- sound.playSfx(mInfo->getSound(SOUND_EVENT_HURT),
- attacker->getPixelX(), attacker->getPixelY());
- }
+ sound.playSfx(hurtSfx, attacker->getPixelX(), attacker->getPixelY());
else
- {
- sound.playSfx(mInfo->getSound(SOUND_EVENT_HURT));
- }
+ sound.playSfx(hurtSfx);
if (getType() == MONSTER)
{
@@ -382,9 +378,9 @@ void Being::takeDamage(Being *attacker, int amount,
if (attackerWeapon && attacker->getType() == PLAYER)
{
if (type != CRITICAL)
- hitEffectId = attackerWeapon->getHitEffectId();
+ hitEffectId = attackerWeapon->hitEffectId;
else
- hitEffectId = attackerWeapon->getCriticalHitEffectId();
+ hitEffectId = attackerWeapon->criticalHitEffectId;
}
else if (attacker && attacker->getType() == MONSTER)
{
@@ -421,7 +417,7 @@ void Being::handleAttack(Being *victim, int damage, int attackId)
lookAt(victim->getPosition());
if (getType() == PLAYER && victim && mEquippedWeapon)
- fireMissile(victim, mEquippedWeapon->getMissileParticleFile());
+ fireMissile(victim, mEquippedWeapon->missileParticleFile);
else
fireMissile(victim,
mInfo->getAttack(attackId).mMissileParticleFilename);
@@ -596,7 +592,7 @@ void Being::setAction(Action action, int attackId)
case ATTACK:
if (mEquippedWeapon)
{
- currentAction = mEquippedWeapon->getAttackAction();
+ currentAction = mEquippedWeapon->attackAction;
reset();
}
else
diff --git a/src/flooritem.cpp b/src/flooritem.cpp
index 9bd8ea9e..15975687 100644
--- a/src/flooritem.cpp
+++ b/src/flooritem.cpp
@@ -21,9 +21,6 @@
#include "flooritem.h"
-#include "net/net.h"
-#include "net/playerhandler.h"
-
#include "resources/itemdb.h"
#include "resources/iteminfo.h"
@@ -42,7 +39,7 @@ FloorItem::FloorItem(int id,
mX = (int)position.x / map->getTileWidth();
mY = (int)position.y / map->getTileHeight();
- setupSpriteDisplay(itemDb->get(itemId).getDisplay());
+ setupSpriteDisplay(itemDb->get(itemId).display);
}
const ItemInfo &FloorItem::getInfo() const
diff --git a/src/gui/buydialog.cpp b/src/gui/buydialog.cpp
index 1ac5cdaa..135c2119 100644
--- a/src/gui/buydialog.cpp
+++ b/src/gui/buydialog.cpp
@@ -26,8 +26,6 @@
#include "shopitem.h"
#include "units.h"
-#include "gui/setup.h"
-
#include "gui/widgets/button.h"
#include "gui/widgets/label.h"
#include "gui/widgets/layout.h"
@@ -255,7 +253,7 @@ void BuyDialog::updateButtonsAndLabels()
}
// Calculate how many the player can carry
- const int itemWeight = shopItem->getInfo().getWeight();
+ const int itemWeight = shopItem->getInfo().weight;
if (itemWeight > 0)
{
const int myTotalWeight = PlayerInfo::getAttribute(TOTAL_WEIGHT);
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp
index 8f810622..450ddfe5 100644
--- a/src/gui/inventorywindow.cpp
+++ b/src/gui/inventorywindow.cpp
@@ -250,12 +250,12 @@ void InventoryWindow::mouseClicked(gcn::MouseEvent &event)
if (event.getSource() == mItems && item && isDoubleClick(item->getInvIndex()))
{
- if (isMainInventory() && item->getInfo().getActivatable())
+ if (isMainInventory() && item->getInfo().activatable)
{
action(gcn::ActionEvent(mUseButton,
mUseButton->getActionEventId()));
}
- else if (isMainInventory() && item->getInfo().getEquippable())
+ else if (isMainInventory() && item->isEquippable())
{
action(gcn::ActionEvent(mEquipButton,
mEquipButton->getActionEventId()));
@@ -366,7 +366,7 @@ void InventoryWindow::updateButtons()
mDropButton->setEnabled(true);
- if (item->getInfo().getEquippable())
+ if (item->isEquippable())
{
if (item->isEquipped())
mEquipButton->setCaption(_("Unequip"));
@@ -379,7 +379,7 @@ void InventoryWindow::updateButtons()
mEquipButton->adjustSize();
- mUseButton->setEnabled(item->getInfo().getActivatable());
+ mUseButton->setEnabled(item->getInfo().activatable);
if (item->getQuantity() > 1)
mDropButton->setCaption(_("Drop..."));
diff --git a/src/gui/itempopup.cpp b/src/gui/itempopup.cpp
index 8208a5d8..7f1dec3b 100644
--- a/src/gui/itempopup.cpp
+++ b/src/gui/itempopup.cpp
@@ -145,7 +145,7 @@ void ItemPopup::setNoItem()
void ItemPopup::setItem(const ItemInfo &item, bool showImage)
{
- if (item.getName() == mItemName->getCaption())
+ if (item.name == mItemName->getCaption())
return;
int space = 0;
@@ -154,7 +154,7 @@ void ItemPopup::setItem(const ItemInfo &item, bool showImage)
{
ResourceManager *resman = ResourceManager::getInstance();
auto image = resman->getImageRef(paths.getStringValue("itemIcons") +
- item.getDisplay().image);
+ item.display.image);
mIcon->setImage(image);
if (image)
@@ -168,9 +168,9 @@ void ItemPopup::setItem(const ItemInfo &item, bool showImage)
mIcon->setImage(nullptr);
}
- mItemType = item.getItemType();
+ mItemType = item.type;
- std::string caption = item.getName();
+ std::string caption = item.name;
if (!mItemEquipSlot.empty())
caption += " (" + mItemEquipSlot + ")";
@@ -179,10 +179,10 @@ void ItemPopup::setItem(const ItemInfo &item, bool showImage)
mItemName->setForegroundColor(getColorFromItemType(mItemType));
mItemName->setPosition(space, 0);
- mItemDesc->setTextWrapped(item.getDescription(), ITEMPOPUP_WRAP_WIDTH);
- mItemEffect->setTextWrapped(join(item.getEffect(), "\n"), ITEMPOPUP_WRAP_WIDTH);
+ mItemDesc->setTextWrapped(item.description, ITEMPOPUP_WRAP_WIDTH);
+ mItemEffect->setTextWrapped(join(item.effect, "\n"), ITEMPOPUP_WRAP_WIDTH);
mItemWeight->setTextWrapped(strprintf(_("Weight: %s"),
- Units::formatWeight(item.getWeight()).c_str()),
+ Units::formatWeight(item.weight).c_str()),
ITEMPOPUP_WRAP_WIDTH);
int minWidth = mItemName->getWidth() + space;
@@ -201,7 +201,7 @@ void ItemPopup::setItem(const ItemInfo &item, bool showImage)
int nameHeight = std::max(mItemName->getHeight(), mIcon->getHeight());
nameHeight += getPadding();
- if (item.getEffect().empty())
+ if (item.effect.empty())
{
setContentSize(minWidth, nameHeight + descHeight + weightHeight + getPadding());
diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp
index 3c91a273..b1165f27 100644
--- a/src/gui/popupmenu.cpp
+++ b/src/gui/popupmenu.cpp
@@ -179,11 +179,10 @@ void PopupMenu::showPopup(int x, int y, Being *being)
void PopupMenu::showPopup(int x, int y, FloorItem *floorItem)
{
mFloorItem = floorItem;
- ItemInfo info = floorItem->getInfo();
mBrowserBox->clearRows();
// Floor item can be picked up (single option, candidate for removal)
- std::string name = info.getName();
+ const std::string &name = floorItem->getInfo().name;
mBrowserBox->addRow(strprintf("@@pickup|%s@@", strprintf(_("Pick up %s"),
name.c_str()).c_str()));
mBrowserBox->addRow(strprintf("@@chat|%s@@", _("Add to chat")));
@@ -285,9 +284,9 @@ void PopupMenu::handleLink(const std::string &link)
else if (link == "chat")
{
if (mItem)
- chatWindow->addItemText(mItem->getInfo().getName());
+ chatWindow->addItemText(mItem->getInfo().name);
else if (mFloorItem)
- chatWindow->addItemText(mFloorItem->getInfo().getName());
+ chatWindow->addItemText(mFloorItem->getInfo().name);
}
else if (link == "split")
@@ -360,14 +359,14 @@ void PopupMenu::showPopup(Window *parent, int x, int y, Item *item,
mBrowserBox->addRow(strprintf("@@store|%s@@", _("Store")));
}
- if (item->getInfo().getEquippable())
+ if (item->isEquippable())
{
if (item->isEquipped())
mBrowserBox->addRow(strprintf("@@unequip|%s@@", _("Unequip")));
else
mBrowserBox->addRow(strprintf("@@equip|%s@@", _("Equip")));
}
- if (item->getInfo().getActivatable())
+ if (item->getInfo().activatable)
mBrowserBox->addRow(strprintf("@@activate|%s@@", _("Activate")));
if (canDrop)
diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp
index 96feddb9..40c9b66a 100644
--- a/src/gui/widgets/browserbox.cpp
+++ b/src/gui/widgets/browserbox.cpp
@@ -102,7 +102,7 @@ void BrowserBox::addRow(const std::string &row)
{
const int id = atoi(link.link.c_str());
if (id)
- link.caption = itemDb->get(id).getName();
+ link.caption = itemDb->get(id).name;
else
link.caption = link.link;
}
diff --git a/src/gui/widgets/chattab.cpp b/src/gui/widgets/chattab.cpp
index 5097bffa..663464a8 100644
--- a/src/gui/widgets/chattab.cpp
+++ b/src/gui/widgets/chattab.cpp
@@ -282,12 +282,12 @@ void ChatTab::chatInput(const std::string &message)
std::string temp = msg.substr(start + 1, end - start - 1);
- const ItemInfo itemInfo = itemDb->get(temp);
- if (itemInfo.getId() != 0)
+ const ItemInfo &itemInfo = itemDb->get(temp);
+ if (itemInfo.id != 0)
{
msg.insert(end, "@@");
msg.insert(start + 1, "|");
- msg.insert(start + 1, toString(itemInfo.getId()));
+ msg.insert(start + 1, toString(itemInfo.id));
msg.insert(start + 1, "@@");
}
}
diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp
index 37a61c80..940c69f4 100644
--- a/src/gui/widgets/itemcontainer.cpp
+++ b/src/gui/widgets/itemcontainer.cpp
@@ -101,7 +101,7 @@ void ItemContainer::draw(gcn::Graphics *graphics)
if (!mFilter.empty())
{
- if (normalize(item->getInfo().getName()).find(mFilter) == std::string::npos)
+ if (normalize(item->getInfo().name).find(mFilter) == std::string::npos)
continue;
mFilteredMap[currentIndex] = item;
currentIndex++;
@@ -286,7 +286,7 @@ void ItemContainer::mousePressed(gcn::MouseEvent &event)
// put item name into chat window
if (mDescItems)
{
- chatWindow->addItemText(item->getInfo().getName());
+ chatWindow->addItemText(item->getInfo().name);
}
if (mSelectedIndex == index)
@@ -298,7 +298,7 @@ void ItemContainer::mousePressed(gcn::MouseEvent &event)
mSelectionStatus = SEL_SELECTING;
itemShortcut->setItemSelected(item->getId());
- if (item->getInfo().getEquippable())
+ if (item->isEquippable())
outfitWindow->setItemSelected(item->getId());
}
else
diff --git a/src/item.cpp b/src/item.cpp
index 5ce1fea5..cae545b1 100644
--- a/src/item.cpp
+++ b/src/item.cpp
@@ -44,7 +44,7 @@ void Item::setId(int id)
// Load the associated image
ResourceManager *resman = ResourceManager::getInstance();
- const SpriteDisplay &display = getInfo().getDisplay();
+ const SpriteDisplay &display = getInfo().display;
mImage = resman->getImage(paths.getStringValue("itemIcons") + display.image);
if (!mImage)
@@ -73,5 +73,5 @@ void Item::doEvent(Event::Type eventName, int amount)
bool Item::isEquippable() const
{
- return getInfo().getEquippable();
+ return getInfo().equippable;
}
diff --git a/src/itemshortcut.cpp b/src/itemshortcut.cpp
index 138c1d12..577f76ae 100644
--- a/src/itemshortcut.cpp
+++ b/src/itemshortcut.cpp
@@ -26,10 +26,6 @@
#include "itemshortcut.h"
#include "playerinfo.h"
-#include "net/inventoryhandler.h"
-
-#include "resources/iteminfo.h"
-
#include "utils/stringutils.h"
ItemShortcut *itemShortcut;
@@ -71,7 +67,7 @@ void ItemShortcut::useItem(int index)
Item *item = PlayerInfo::getInventory()->findItem(mItems[index]);
if (item && item->getQuantity())
{
- if (item->getInfo().getEquippable())
+ if (item->isEquippable())
{
if (item->isEquipped())
item->doEvent(Event::DoUnequip);
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index 3bc41b01..02ec4f14 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -914,7 +914,7 @@ void LocalPlayer::pickedUp(const ItemInfo &itemInfo, int amount,
// for different grammatical numbers (singular, plural, ...)
SERVER_NOTICE(strprintf(ngettext("You picked up %d "
"[@@%d|%s@@].", "You picked up %d [@@%d|%s@@].", amount),
- amount, itemInfo.getId(), itemInfo.getName().c_str()))
+ amount, itemInfo.id, itemInfo.name.c_str()))
}
if (mMap && config.getBoolValue("showpickupparticle"))
@@ -923,7 +923,7 @@ void LocalPlayer::pickedUp(const ItemInfo &itemInfo, int amount,
std::string msg;
if (amount > 1)
msg = strprintf("%i ", amount);
- msg += itemInfo.getName();
+ msg += itemInfo.name;
addMessageToQueue(msg, UserPalette::PICKUP_INFO);
}
}
@@ -942,9 +942,9 @@ void LocalPlayer::setAttackRange(int range)
Item *weapon = PlayerInfo::getEquipment(TmwAthena::EQUIP_FIGHT1_SLOT);
if (weapon)
{
- const ItemInfo info = weapon->getInfo();
- if (info.getAttackRange() > -1)
- mAttackRange = info.getAttackRange();
+ const ItemInfo &info = weapon->getInfo();
+ if (info.attackRange > -1)
+ mAttackRange = info.attackRange;
}
}
}
diff --git a/src/resources/beinginfo.cpp b/src/resources/beinginfo.cpp
index e76cb8e3..30c06080 100644
--- a/src/resources/beinginfo.cpp
+++ b/src/resources/beinginfo.cpp
@@ -60,7 +60,7 @@ BeingInfo::BeingInfo():
{
SpriteDisplay display;
- SpriteReference errorSprite(paths.getStringValue("spriteErrorFile"), 0);
+ SpriteReference errorSprite { paths.getStringValue("spriteErrorFile"), 0 };
display.sprites.push_back(errorSprite);
setDisplay(std::move(display));
diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp
index b4f959e9..2e59457d 100644
--- a/src/resources/itemdb.cpp
+++ b/src/resources/itemdb.cpp
@@ -63,14 +63,14 @@ static ItemType itemTypeFromString(const std::string &name, int id = 0)
void ItemDB::loadEmptyItemDefinition()
{
- mUnknown->mName = _("Unknown item");
- mUnknown->mDisplay = SpriteDisplay();
+ mUnknown->name = _("Unknown item");
+ mUnknown->display = SpriteDisplay();
std::string errFile = paths.getStringValue("spriteErrorFile");
mUnknown->setSprite(errFile, Gender::MALE, 0);
mUnknown->setSprite(errFile, Gender::FEMALE, 0);
mUnknown->setSprite(errFile, Gender::HIDDEN, 0);
- mUnknown->setHitEffectId(paths.getIntValue("hitEffectId"));
- mUnknown->setCriticalHitEffectId(paths.getIntValue("criticalHitEffectId"));
+ mUnknown->hitEffectId = paths.getIntValue("hitEffectId");
+ mUnknown->criticalHitEffectId = paths.getIntValue("criticalHitEffectId");
}
/*
@@ -116,32 +116,32 @@ const ItemInfo &ItemDB::get(const std::string &name) const
return *(i->second);
}
-void ItemDB::loadSpriteRef(ItemInfo *itemInfo, xmlNodePtr node)
+void ItemDB::loadSpriteRef(ItemInfo &itemInfo, xmlNodePtr node)
{
std::string gender = XML::getProperty(node, "gender", "unisex");
std::string filename = (const char*) node->xmlChildrenNode->content;
const int race = XML::getProperty(node, "race", 0);
if (gender == "male" || gender == "unisex")
- itemInfo->setSprite(filename, Gender::MALE, race);
+ itemInfo.setSprite(filename, Gender::MALE, race);
if (gender == "female" || gender == "unisex")
- itemInfo->setSprite(filename, Gender::FEMALE, race);
+ itemInfo.setSprite(filename, Gender::FEMALE, race);
if (gender == "hidden" || gender == "other" || gender == "unisex")
- itemInfo->setSprite(filename, Gender::HIDDEN, race);
+ itemInfo.setSprite(filename, Gender::HIDDEN, race);
}
-void ItemDB::loadSoundRef(ItemInfo *itemInfo, xmlNodePtr node)
+void ItemDB::loadSoundRef(ItemInfo &itemInfo, xmlNodePtr node)
{
- std::string event = XML::getProperty(node, "event", "");
+ std::string event = XML::getProperty(node, "event", std::string());
std::string filename = (const char*) node->xmlChildrenNode->content;
if (event == "hit")
{
- itemInfo->addSound(EQUIP_EVENT_HIT, filename);
+ itemInfo.addSound(EQUIP_EVENT_HIT, filename);
}
else if (event == "strike")
{
- itemInfo->addSound(EQUIP_EVENT_STRIKE, filename);
+ itemInfo.addSound(EQUIP_EVENT_STRIKE, filename);
}
else
{
@@ -150,21 +150,20 @@ void ItemDB::loadSoundRef(ItemInfo *itemInfo, xmlNodePtr node)
}
}
-void ItemDB::loadFloorSprite(SpriteDisplay *display, xmlNodePtr floorNode)
+void ItemDB::loadFloorSprite(SpriteDisplay &display, xmlNodePtr floorNode)
{
for (auto spriteNode : XML::Children(floorNode))
{
if (xmlStrEqual(spriteNode->name, BAD_CAST "sprite"))
{
- SpriteReference currentSprite;
+ SpriteReference &currentSprite = display.sprites.emplace_back();
currentSprite.sprite = (const char*)spriteNode->xmlChildrenNode->content;
currentSprite.variant = XML::getProperty(spriteNode, "variant", 0);
- display->sprites.push_back(currentSprite);
}
else if (xmlStrEqual(spriteNode->name, BAD_CAST "particlefx"))
{
- std::string particlefx = (const char*)spriteNode->xmlChildrenNode->content;
- display->particles.push_back(particlefx);
+ display.particles.emplace_back(
+ (const char*)spriteNode->xmlChildrenNode->content);
}
}
}
@@ -182,85 +181,62 @@ void ItemDB::unload()
mLoaded = false;
}
-void ItemDB::loadCommonRef(ItemInfo *itemInfo, xmlNodePtr node, const std::string &filename)
+void ItemDB::loadCommonRef(ItemInfo &itemInfo, xmlNodePtr node, const std::string &filename)
{
- int id = XML::getProperty(node, "id", 0);
+ itemInfo.id = XML::getProperty(node, "id", 0);
- if (!id)
+ if (!itemInfo.id)
+ {
+ logger->log("ItemDB: Invalid or missing item Id in %s!", filename.c_str());
+ return;
+ }
+ else if (mItemInfos.find(itemInfo.id) != mItemInfos.end())
+ {
+ logger->log("ItemDB: Redefinition of item Id %d in %s", itemInfo.id, filename.c_str());
+ }
+
+ itemInfo.mView = XML::getProperty(node, "view", 0);
+ itemInfo.name = XML::getProperty(node, "name", std::string());
+ itemInfo.display.image = XML::getProperty(node, "image", std::string());
+ itemInfo.description = XML::getProperty(node, "description", std::string());
+ itemInfo.attackAction = XML::getProperty(node, "attack-action", SpriteAction::INVALID);
+ itemInfo.attackRange = XML::getProperty(node, "attack-range", 0);
+ itemInfo.missileParticleFile = XML::getProperty(node, "missile-particle", std::string());
+ itemInfo.hitEffectId = XML::getProperty(node, "hit-effect-id",
+ paths.getIntValue("hitEffectId"));
+ itemInfo.criticalHitEffectId = XML::getProperty(node, "critical-hit-effect-id",
+ paths.getIntValue("criticalHitEffectId"));
+
+ // Load Ta Item Type
+ std::string typeStr = XML::getProperty(node, "type", "other");
+ itemInfo.type = itemTypeFromString(typeStr);
+ itemInfo.weight = XML::getProperty(node, "weight", 0);
+
+ for (auto itemChild : XML::Children(node))
+ {
+ if (xmlStrEqual(itemChild->name, BAD_CAST "sprite"))
{
- logger->log("ItemDB: Invalid or missing item Id in %s!", filename.c_str());
- return;
+ itemInfo.particle = XML::getProperty(
+ itemChild, "particle-effect", std::string());
+
+ loadSpriteRef(itemInfo, itemChild);
}
- else if (mItemInfos.find(id) != mItemInfos.end())
- logger->log("ItemDB: Redefinition of item Id %d in %s", id, filename.c_str());
-
- int view = XML::getProperty(node, "view", 0);
-
- std::string name = XML::getProperty(node, "name", "");
- std::string image = XML::getProperty(node, "image", "");
- std::string description = XML::getProperty(node, "description", "");
- std::string attackAction = XML::getProperty(node, "attack-action",
- SpriteAction::INVALID);
- int attackRange = XML::getProperty(node, "attack-range", 0);
- std::string missileParticleFile = XML::getProperty(node,
- "missile-particle",
- "");
- int hitEffectId = XML::getProperty(node, "hit-effect-id",
- paths.getIntValue("hitEffectId"));
- int criticalEffectId = XML::getProperty(node, "critical-hit-effect-id",
- paths.getIntValue("criticalHitEffectId"));
-
- // Load Ta Item Type
- std::string typeStr = XML::getProperty(node, "type", "other");
- itemInfo->mType = itemTypeFromString(typeStr);
-
- int weight = XML::getProperty(node, "weight", 0);
- itemInfo->mWeight = weight > 0 ? weight : 0;
-
- SpriteDisplay display;
- display.image = image;
-
- itemInfo->mId = id;
- itemInfo->mName = name;
- itemInfo->mDescription = description;
- itemInfo->mView = view;
- itemInfo->mWeight = weight;
- itemInfo->mAttackAction = attackAction;
- itemInfo->mAttackRange = attackRange;
- itemInfo->setMissileParticleFile(missileParticleFile);
- itemInfo->setHitEffectId(hitEffectId);
- itemInfo->setCriticalHitEffectId(criticalEffectId);
-
- // Load <sprite>, <sound>, and <floor>
- for (auto itemChild : XML::Children(node))
+ else if (xmlStrEqual(itemChild->name, BAD_CAST "sound"))
{
- if (xmlStrEqual(itemChild->name, BAD_CAST "sprite"))
- {
- itemInfo->mParticle = XML::getProperty(
- itemChild, "particle-effect", std::string());
-
- loadSpriteRef(itemInfo, itemChild);
- }
- else if (xmlStrEqual(itemChild->name, BAD_CAST "sound"))
- {
- loadSoundRef(itemInfo, itemChild);
- }
- else if (xmlStrEqual(itemChild->name, BAD_CAST "floor"))
- {
- loadFloorSprite(&display, itemChild);
- }
-
+ loadSoundRef(itemInfo, itemChild);
}
-
- // If the item has got a floor image, we bind the good reference.
- itemInfo->mDisplay = display;
+ else if (xmlStrEqual(itemChild->name, BAD_CAST "floor"))
+ {
+ loadFloorSprite(itemInfo.display, itemChild);
+ }
+ }
}
void ItemDB::addItem(ItemInfo *itemInfo)
{
- std::string itemName = itemInfo->mName;
- itemInfo->mName = itemName.empty() ? _("unnamed") : itemName;
- mItemInfos[itemInfo->mId] = itemInfo;
+ std::string itemName = itemInfo->name;
+ itemInfo->name = itemName.empty() ? _("unnamed") : itemName;
+ mItemInfos[itemInfo->id] = itemInfo;
if (!itemName.empty())
{
std::string temp = normalize(itemName);
@@ -270,7 +246,7 @@ void ItemDB::addItem(ItemInfo *itemInfo)
mNamedItemInfos[temp] = itemInfo;
else
logger->log("ItemDB: Duplicate name (%s) for item id %d found.",
- temp.c_str(), itemInfo->mId);
+ temp.c_str(), itemInfo->id);
}
}
@@ -286,19 +262,19 @@ static void checkParameter(int id, const T param, const T errorValue)
}
}
-void ItemDB::checkItemInfo(ItemInfo* itemInfo)
+void ItemDB::checkItemInfo(ItemInfo &itemInfo)
{
- int id = itemInfo->mId;
- if (!itemInfo->getAttackAction().empty())
- if (itemInfo->mAttackRange == 0)
+ int id = itemInfo.id;
+ if (!itemInfo.attackAction.empty())
+ if (itemInfo.attackRange == 0)
logger->log("ItemDB: Missing attack range from weapon %i!", id);
if (id >= 0)
{
- checkParameter(id, itemInfo->mName, std::string());
- checkParameter(id, itemInfo->mDescription, std::string());
- checkParameter(id, itemInfo->mDisplay.image, std::string());
- checkParameter(id, itemInfo->mWeight, 0);
+ checkParameter(id, itemInfo.name, std::string());
+ checkParameter(id, itemInfo.description, std::string());
+ checkParameter(id, itemInfo.display.image, std::string());
+ checkParameter(id, itemInfo.weight, 0);
}
}
@@ -322,14 +298,14 @@ void TaItemDB::init()
void TaItemDB::readItemNode(xmlNodePtr node, const std::string &filename)
{
- auto *itemInfo = new TaItemInfo;
+ auto *itemInfo = new ItemInfo;
- loadCommonRef(itemInfo, node, filename);
+ loadCommonRef(*itemInfo, node, filename);
// Everything not unusable or usable is equippable by the Ta type system.
- itemInfo->mEquippable = itemInfo->mType != ITEM_UNUSABLE
- && itemInfo->mType != ITEM_USABLE;
- itemInfo->mActivatable = itemInfo->mType == ITEM_USABLE;
+ itemInfo->equippable = itemInfo->type != ITEM_UNUSABLE
+ && itemInfo->type != ITEM_USABLE;
+ itemInfo->activatable = itemInfo->type == ITEM_USABLE;
// Load nano description
std::vector<std::string> effect;
@@ -347,24 +323,24 @@ void TaItemDB::readItemNode(xmlNodePtr node, const std::string &filename)
continue;
effect.push_back(strprintf(extraStat.mFormat.c_str(), value));
}
- std::string temp = XML::getProperty(node, "effect", "");
+ std::string temp = XML::getProperty(node, "effect", std::string());
if (!temp.empty())
effect.push_back(temp);
- itemInfo->mEffect = effect;
+ itemInfo->effect = effect;
- checkItemInfo(itemInfo);
+ checkItemInfo(*itemInfo);
addItem(itemInfo);
// Insert hairstyle id while letting the info as an item.
- if (itemInfo->mType == ITEM_SPRITE_HAIR)
- hairDB.addHairStyle(itemInfo->mId);
+ if (itemInfo->type == ITEM_SPRITE_HAIR)
+ hairDB.addHairStyle(itemInfo->id);
}
void TaItemDB::checkStatus()
{
- mUnknown = new TaItemInfo;
+ mUnknown = new ItemInfo;
loadEmptyItemDefinition();
checkHairWeaponsRacesSpecialIds();
@@ -372,7 +348,7 @@ void TaItemDB::checkStatus()
mLoaded = true;
}
-void TaItemDB::checkItemInfo(ItemInfo* itemInfo)
+void TaItemDB::checkItemInfo(ItemInfo &itemInfo)
{
ItemDB::checkItemInfo(itemInfo);
@@ -384,42 +360,33 @@ void TaItemDB::checkItemInfo(ItemInfo* itemInfo)
namespace ManaServ {
-static std::map<std::string, const char* > triggerTable;
-
-static void initTriggerTable()
-{
- if (triggerTable.empty())
- {
- // FIXME: This should ideally be softcoded via XML or similar.
- logger->log("Initializing ManaServ trigger table...");
- triggerTable["existence"] = " when it is in the inventory";
- triggerTable["activation"] = " upon activation";
- triggerTable["equip"] = " upon successful equip";
- triggerTable["leave-inventory"] = " when it leaves the inventory";
- triggerTable["unequip"] = " when it is unequipped";
- triggerTable["equip-change"] = " when it changes the way it is equipped";
- }
-}
-
void ManaServItemDB::init()
{
if (mLoaded)
unload();
-
- // Initialize the trigger table for effect descriptions
- initTriggerTable();
}
void ManaServItemDB::readItemNode(xmlNodePtr node, const std::string &filename)
{
- auto *itemInfo = new ManaServItemInfo;
+ // Trigger table for effect descriptions
+ // FIXME: This should ideally be softcoded via XML or similar.
+ static const std::map<std::string, const char* > triggerTable = {
+ { "existence", " when it is in the inventory" },
+ { "activation", " upon activation" },
+ { "equip", " upon successful equip" },
+ { "leave-inventory", " when it leaves the inventory" },
+ { "unequip", " when it is unequipped" },
+ { "equip-change", " when it changes the way it is equipped" },
+ };
+
+ auto *itemInfo = new ItemInfo;
- loadCommonRef(itemInfo, node, filename);
+ loadCommonRef(*itemInfo, node, filename);
// We default eqippable and activatable to false as their actual value will be set
// within the <equip> and <effect> sub-nodes..
- itemInfo->mActivatable = false;
- itemInfo->mEquippable = false;
+ itemInfo->activatable = false;
+ itemInfo->equippable = false;
// Load <equip>, and <effect> sub nodes.
std::vector<std::string> effect;
@@ -429,12 +396,12 @@ void ManaServItemDB::readItemNode(xmlNodePtr node, const std::string &filename)
{
// The fact that there is a way to equip is enough.
// Discard any details, but mark the item as equippable.
- itemInfo->mEquippable = true;
+ itemInfo->equippable = true;
}
else if (xmlStrEqual(itemChild->name, BAD_CAST "effect"))
{
std::string trigger = XML::getProperty(
- itemChild, "trigger", "");
+ itemChild, "trigger", std::string());
if (trigger.empty())
{
logger->log("Found empty trigger effect label in %s, skipping.", filename.c_str());
@@ -442,13 +409,13 @@ void ManaServItemDB::readItemNode(xmlNodePtr node, const std::string &filename)
}
if (trigger == "activation")
- itemInfo->mActivatable = true;
+ itemInfo->activatable = true;
auto triggerLabel = triggerTable.find(trigger);
if (triggerLabel == triggerTable.end())
{
logger->log("Warning: unknown trigger %s in item %d!",
- trigger.c_str(), itemInfo->mId);
+ trigger.c_str(), itemInfo->id);
continue;
}
@@ -457,7 +424,7 @@ void ManaServItemDB::readItemNode(xmlNodePtr node, const std::string &filename)
if (xmlStrEqual(effectChild->name, BAD_CAST "modifier"))
{
std::string attribute = XML::getProperty(
- effectChild, "attribute", "");
+ effectChild, "attribute", std::string());
double value = XML::getFloatProperty(
effectChild, "value", 0.0);
int duration = XML::getProperty(
@@ -495,34 +462,34 @@ void ManaServItemDB::readItemNode(xmlNodePtr node, const std::string &filename)
}
// FIXME: Load hair styles through the races.xml file
- if (itemInfo->mType == ITEM_SPRITE_HAIR)
- hairDB.addHairStyle(itemInfo->mId);
+ if (itemInfo->type == ITEM_SPRITE_HAIR)
+ hairDB.addHairStyle(itemInfo->id);
// Set Item Type based on subnodes info
// TODO: Improve it once the itemTypes are loaded through xml
- itemInfo->mType = ITEM_UNUSABLE;
- if (itemInfo->mActivatable)
- itemInfo->mType = ITEM_USABLE;
- else if (itemInfo->mEquippable)
- itemInfo->mType = ITEM_EQUIPMENT_TORSO;
+ itemInfo->type = ITEM_UNUSABLE;
+ if (itemInfo->activatable)
+ itemInfo->type = ITEM_USABLE;
+ else if (itemInfo->equippable)
+ itemInfo->type = ITEM_EQUIPMENT_TORSO;
} // end for (auto itemChild : XML::Children(node))
- itemInfo->mEffect = effect;
+ itemInfo->effect = effect;
- checkItemInfo(itemInfo);
+ checkItemInfo(*itemInfo);
addItem(itemInfo);
}
void ManaServItemDB::checkStatus()
{
- mUnknown = new ManaServItemInfo;
+ mUnknown = new ItemInfo;
loadEmptyItemDefinition();
mLoaded = true;
}
-void ManaServItemDB::checkItemInfo(ItemInfo* itemInfo)
+void ManaServItemDB::checkItemInfo(ItemInfo &itemInfo)
{
ItemDB::checkItemInfo(itemInfo);
diff --git a/src/resources/itemdb.h b/src/resources/itemdb.h
index 84fcf210..dd728e21 100644
--- a/src/resources/itemdb.h
+++ b/src/resources/itemdb.h
@@ -74,7 +74,6 @@ class ItemDB
{
public:
ItemDB() = default;
-
virtual ~ItemDB() = default;
/**
@@ -104,12 +103,12 @@ class ItemDB
* Permits to load item definitions which are common
* for each protocols to avoid code duplication.
*/
- void loadCommonRef(ItemInfo *itemInfo, xmlNodePtr node, const std::string &filename);
+ void loadCommonRef(ItemInfo &itemInfo, xmlNodePtr node, const std::string &filename);
/**
* Checks the items parameters consistency.
*/
- virtual void checkItemInfo(ItemInfo* itemInfo);
+ virtual void checkItemInfo(ItemInfo &itemInfo);
/**
* Registers the item to mItemInfos and mNamedItemsInfos
@@ -130,17 +129,17 @@ class ItemDB
/**
* Loads the sprite references contained in a <sprite> tag.
*/
- void loadSpriteRef(ItemInfo *itemInfo, xmlNodePtr node);
+ void loadSpriteRef(ItemInfo &itemInfo, xmlNodePtr node);
/**
* Loads the sound references contained in a <sound> tag.
*/
- void loadSoundRef(ItemInfo *itemInfo, xmlNodePtr node);
+ void loadSoundRef(ItemInfo &itemInfo, xmlNodePtr node);
/**
* Loads the floor item references contained in a <floor> tag.
*/
- void loadFloorSprite(SpriteDisplay *display, xmlNodePtr node);
+ void loadFloorSprite(SpriteDisplay &display, xmlNodePtr node);
// Items database
std::map<int, ItemInfo *> mItemInfos;
@@ -149,12 +148,10 @@ class ItemDB
namespace TmwAthena {
-class TaItemInfo;
-
/**
* Item information database TmwAthena specific class.
*/
-class TaItemDB: public ItemDB
+class TaItemDB : public ItemDB
{
public:
TaItemDB() = default;
@@ -176,19 +173,17 @@ class TaItemDB: public ItemDB
void checkHairWeaponsRacesSpecialIds()
{}
- void checkItemInfo(ItemInfo* itemInfo) override;
+ void checkItemInfo(ItemInfo &itemInfo) override;
};
} // namespace TmwAthena
namespace ManaServ {
-class ManaServItemInfo;
-
/**
* Item information database TmwAthena specific class.
*/
-class ManaServItemDB: public ItemDB
+class ManaServItemDB : public ItemDB
{
public:
ManaServItemDB() = default;
@@ -203,7 +198,7 @@ class ManaServItemDB: public ItemDB
void checkStatus() override;
private:
- void checkItemInfo(ItemInfo* itemInfo) override;
+ void checkItemInfo(ItemInfo &itemInfo) override;
};
} // namespace ManaServ
diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h
index c3a15376..90a70695 100644
--- a/src/resources/iteminfo.h
+++ b/src/resources/iteminfo.h
@@ -70,123 +70,65 @@ class ManaServItemDB;
/**
* Defines a class for storing generic item infos.
- * Specialized version for one or another protocol are defined below.
*/
class ItemInfo
{
friend class ItemDB;
- friend void loadSpriteRef(ItemInfo *itemInfo, xmlNodePtr node);
friend class TmwAthena::TaItemDB;
friend class ManaServ::ManaServItemDB;
- public:
- ItemInfo():
- mAttackAction(SpriteAction::INVALID)
- {
- }
+public:
+ ItemInfo() = default;
- int getId() const
- { return mId; }
+ // disable copying
+ ItemInfo(const ItemInfo &) = delete;
+ ItemInfo &operator=(const ItemInfo &) = delete;
- const std::string &getName() const
- { return mName; }
+ int id = 0; /**< Item ID */
+ std::string name;
+ std::string particle; /**< Particle effect used with this item */
+ SpriteDisplay display; /**< Display info (like icon) */
+ std::string description; /**< Short description. */
+ std::vector<std::string> effect; /**< Description of effects. */
+ int weight = 0; /**< Weight in grams. */
- const std::string &getParticleEffect() const
- { return mParticle; }
+ /** Effects to be shown when weapon attacks - see also effects.xml */
+ std::string missileParticleFile;
+ int hitEffectId = 0;
+ int criticalHitEffectId = 0;
- const SpriteDisplay &getDisplay() const
- { return mDisplay; }
+ /** Attack type, in case of weapon.
+ * See SpriteAction in spritedef.h for more info.
+ * Attack action sub-types (bow, sword, ...) are defined in items.xml.
+ */
+ std::string attackAction = SpriteAction::INVALID;
- const std::string &getDescription() const
- { return mDescription; }
+ /** Attack range, will be equal to ATTACK_RANGE_NOT_SET if no weapon. */
+ int attackRange = 0;
- const std::vector<std::string> &getEffect() const
- { return mEffect; }
+ bool equippable = false; /**< Whether this item can be equipped. */
+ bool activatable = false; /**< Whether this item can be activated. */
- int getWeight() const
- { return mWeight; }
+ ItemType type = ITEM_UNUSABLE; /**< Item type. */
- const std::string &getSprite(Gender gender, int race) const;
+ const std::string &getSprite(Gender gender, int race) const;
+ const std::string &getSound(EquipmentSoundEvent event) const;
- // Handlers for seting and getting the string used for particles when attacking
- void setMissileParticleFile(const std::string &s)
- { mMissileParticleFile = s; }
+private:
+ void setSprite(const std::string &animationFile, Gender gender, int race);
+ void addSound(EquipmentSoundEvent event, const std::string &filename);
- const std::string &getMissileParticleFile() const
- { return mMissileParticleFile; }
+ int mView = 0; /**< Item ID of how this item looks. */
- void setHitEffectId(int s)
- { mHitEffectId = s; }
+ /** Maps gender to sprite filenames. */
+ std::map<int, std::string> mAnimationFiles;
- int getHitEffectId() const
- { return mHitEffectId; }
-
- void setCriticalHitEffectId(int s)
- { mCriticalHitEffectId = s; }
-
- int getCriticalHitEffectId() const
- { return mCriticalHitEffectId; }
-
- const std::string &getAttackAction() const
- { return mAttackAction; }
-
- int getAttackRange() const
- { return mAttackRange; }
-
- const std::string &getSound(EquipmentSoundEvent event) const;
-
- bool getEquippable() const
- { return mEquippable; }
-
- bool getActivatable() const
- { return mActivatable; }
-
- ItemType getItemType() const
- { return mType; }
-
- private:
- void setSprite(const std::string &animationFile,
- Gender gender, int race);
-
- void addSound(EquipmentSoundEvent event, const std::string &filename);
-
- SpriteDisplay mDisplay; /**< Display info (like icon) */
- std::string mName;
- std::string mDescription; /**< Short description. */
- std::vector<std::string> mEffect; /**< Description of effects. */
- ItemType mType = ITEM_UNUSABLE; /**< Item type. */
- std::string mParticle; /**< Particle effect used with this item */
- int mWeight = 0; /**< Weight in grams. */
- int mView = 0; /**< Item ID of how this item looks. */
- int mId = 0; /**< Item ID */
-
- bool mEquippable = false; /**< Whether this item can be equipped. */
- bool mActivatable = false; /**< Whether this item can be activated. */
-
- // Equipment related members.
- /** Attack type, in case of weapon.
- * See SpriteAction in spritedef.h for more info.
- * Attack action sub-types (bow, sword, ...) are defined in items.xml.
- */
- std::string mAttackAction;
-
- /** Attack range, will be equal to ATTACK_RANGE_NOT_SET if no weapon. */
- int mAttackRange = 0;
-
- /** Effects to be shown when weapon attacks - see also effects.xml */
- std::string mMissileParticleFile;
- int mHitEffectId = 0;
- int mCriticalHitEffectId = 0;
-
- /** Maps gender to sprite filenames. */
- std::map<int, std::string> mAnimationFiles;
-
- /** Stores the names of sounds to be played at certain event. */
- std::map< EquipmentSoundEvent, std::vector<std::string> > mSounds;
+ /** Stores the names of sounds to be played at certain event. */
+ std::map<EquipmentSoundEvent, std::vector<std::string>> mSounds;
};
/*
- * TmwAthena specialization of the itemInfo for TmwAthena
+ * TmwAthena specialization of the ItemInfo for TmwAthena
*/
namespace TmwAthena {
@@ -220,37 +162,6 @@ enum EquipmentSlot
EQUIP_VECTOR_END = 11
};
-/**
- * Defines a class for storing TmwAthena specific item infos.
- * Specialized version for one or another protocol are defined below.
- */
-class TaItemInfo: public ItemInfo
-{
- friend class TaItemDB;
-
- public:
- TaItemInfo() = default;
-
- // Declare TmwAthena Specific item info here
-};
-
} // namespace TmwAthena
-namespace ManaServ {
-
-/**
- * Defines a class for storing Manaserv Specific item infos.
- * Specialized version for one or another protocol are defined below.
- */
-class ManaServItemInfo: public ItemInfo
-{
- public:
- ManaServItemInfo() = default;
-
- // Declare Manaserv Specific item info here
-};
-
-
-} // namespace ManaServ
-
#endif // ITEMINFO_H
diff --git a/src/resources/monsterdb.cpp b/src/resources/monsterdb.cpp
index 283d62e7..80f26fb2 100644
--- a/src/resources/monsterdb.cpp
+++ b/src/resources/monsterdb.cpp
@@ -86,21 +86,18 @@ void MonsterDB::readMonsterNode(xmlNodePtr node, const std::string &filename)
SpriteDisplay display;
- //iterate <sprite>s and <sound>s
for (auto spriteNode : XML::Children(node))
{
if (xmlStrEqual(spriteNode->name, BAD_CAST "sprite"))
{
- SpriteReference currentSprite;
+ SpriteReference &currentSprite = display.sprites.emplace_back();
currentSprite.sprite = (const char*)spriteNode->xmlChildrenNode->content;
currentSprite.variant = XML::getProperty(spriteNode, "variant", 0);
- display.sprites.push_back(currentSprite);
}
else if (xmlStrEqual(spriteNode->name, BAD_CAST "sound"))
{
- std::string event = XML::getProperty(spriteNode, "event", "");
- const char *soundFile;
- soundFile = (const char*) spriteNode->xmlChildrenNode->content;
+ std::string event = XML::getProperty(spriteNode, "event", std::string());
+ const char *soundFile = (const char*) spriteNode->children->content;
if (event == "hit")
{
diff --git a/src/resources/npcdb.cpp b/src/resources/npcdb.cpp
index 164dec18..09537c17 100644
--- a/src/resources/npcdb.cpp
+++ b/src/resources/npcdb.cpp
@@ -65,15 +65,14 @@ void NPCDB::readNPCNode(xmlNodePtr node, const std::string &filename)
{
if (xmlStrEqual(spriteNode->name, BAD_CAST "sprite"))
{
- SpriteReference currentSprite;
+ SpriteReference &currentSprite = display.sprites.emplace_back();
currentSprite.sprite = (const char*)spriteNode->xmlChildrenNode->content;
currentSprite.variant = XML::getProperty(spriteNode, "variant", 0);
- display.sprites.push_back(currentSprite);
}
else if (xmlStrEqual(spriteNode->name, BAD_CAST "particlefx"))
{
- std::string particlefx = (const char*)spriteNode->xmlChildrenNode->content;
- display.particles.push_back(particlefx);
+ display.particles.emplace_back(
+ (const char*)spriteNode->xmlChildrenNode->content);
}
}
diff --git a/src/resources/spritedef.h b/src/resources/spritedef.h
index 49798afc..ec5e8927 100644
--- a/src/resources/spritedef.h
+++ b/src/resources/spritedef.h
@@ -26,31 +26,24 @@
#include <libxml/tree.h>
-#include <list>
#include <map>
#include <string>
+#include <vector>
class Action;
class ImageSet;
struct SpriteReference
{
- SpriteReference() = default;
-
- SpriteReference(std::string sprite, int variant):
- sprite(sprite),
- variant(variant)
- {}
-
std::string sprite;
- int variant;
+ int variant = 0;
};
struct SpriteDisplay
{
std::string image;
- std::list<SpriteReference> sprites;
- std::list<std::string> particles;
+ std::vector<SpriteReference> sprites;
+ std::vector<std::string> particles;
};
/*
diff --git a/src/shopitem.cpp b/src/shopitem.cpp
index e966dbbf..2fb33778 100644
--- a/src/shopitem.cpp
+++ b/src/shopitem.cpp
@@ -30,7 +30,7 @@ ShopItem::ShopItem(int inventoryIndex, int id,
Item(id, 0),
mPrice(price)
{
- mDisplayName = getInfo().getName() +
+ mDisplayName = getInfo().name +
" (" + Units::formatCurrency(mPrice) + ")";
setInvIndex(inventoryIndex);
addDuplicate(inventoryIndex, quantity);