summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEugenio Favalli <elvenprogrammer@gmail.com>2005-04-21 15:36:49 +0000
committerEugenio Favalli <elvenprogrammer@gmail.com>2005-04-21 15:36:49 +0000
commit56fef6eed9e3145b5e7d33e066069f642873d7a1 (patch)
tree10ee9c20bfa294abbbb2b96901bc0b2830007288 /src
parent9db3ea6a43d78bc959eef9fd594141d3a4063c0b (diff)
downloadmana-client-56fef6eed9e3145b5e7d33e066069f642873d7a1.tar.gz
mana-client-56fef6eed9e3145b5e7d33e066069f642873d7a1.tar.bz2
mana-client-56fef6eed9e3145b5e7d33e066069f642873d7a1.tar.xz
mana-client-56fef6eed9e3145b5e7d33e066069f642873d7a1.zip
trying to follow Hammerbear suggestions
Diffstat (limited to 'src')
-rw-r--r--src/engine.cpp5
-rw-r--r--src/gui/buy.cpp3
-rw-r--r--src/gui/equipment.cpp3
-rw-r--r--src/gui/itemcontainer.cpp5
-rw-r--r--src/gui/sell.cpp3
-rw-r--r--src/resources/itemmanager.cpp60
-rw-r--r--src/resources/itemmanager.h17
7 files changed, 18 insertions, 78 deletions
diff --git a/src/engine.cpp b/src/engine.cpp
index 8a421041..85c737c9 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -341,8 +341,9 @@ void Engine::draw()
int sy = y - camera_y;
int absx = sx * 32 - offset_x;
int absy = sy * 32 - offset_y;
- if (itemDb.getImage(floorItem->id) > 0) {
- itemset->spriteset[itemDb.getImage(floorItem->id) - 1]->draw(screen,
+ if (itemDb.getItemInfo(floorItem->id)->getImage() > 0) {
+ itemset->spriteset[itemDb.getItemInfo(
+ floorItem->id)->getImage() - 1]->draw(screen,
absx, absy);
}
diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp
index c26be5d3..6876fb02 100644
--- a/src/gui/buy.cpp
+++ b/src/gui/buy.cpp
@@ -102,7 +102,8 @@ void BuyDialog::addItem(short id, int price)
{
ITEM_SHOP item_shop;
- sprintf(item_shop.name, "%s %i gp", itemDb.getName(id).c_str(), price);
+ sprintf(item_shop.name, "%s %i gp",
+ itemDb.getItemInfo(id)->getName().c_str(), price);
item_shop.price = price;
item_shop.id = id;
diff --git a/src/gui/equipment.cpp b/src/gui/equipment.cpp
index 1c559263..95e9998c 100644
--- a/src/gui/equipment.cpp
+++ b/src/gui/equipment.cpp
@@ -58,7 +58,8 @@ void EquipmentWindow::draw(gcn::Graphics *graphics)
for (int i = 0; i < 8; i++) {
if (equipments[i].id > 0) {
- itemset->spriteset[itemDb.getImage(equipments[i].id) - 1]->draw(
+ itemset->spriteset[itemDb.getItemInfo(
+ equipments[i].id)->getImage() - 1]->draw(
screen, x + 22, y + 24 * i + 20);
}
graphics->setColor(gcn::Color(0, 0, 0));
diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp
index 61dad053..bb10c5a9 100644
--- a/src/gui/itemcontainer.cpp
+++ b/src/gui/itemcontainer.cpp
@@ -75,8 +75,9 @@ void ItemContainer::draw(gcn::Graphics* graphics)
int itemY = (((i - 2) * 24) / (getWidth() - 24)) * 24;
itemX -= itemX % 24;
if (items[i].quantity > 0) {
- if (itemDb.getImage(items[i].id) > 0) {
- itemset->spriteset[itemDb.getImage(items[i].id) - 1]->draw(
+ if (itemDb.getItemInfo(items[i].id)->getImage() > 0) {
+ itemset->spriteset[itemDb.getItemInfo(
+ items[i].id)->getImage() - 1]->draw(
screen, x + itemX, y + itemY);
}
diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp
index 2c9e8745..711a417e 100644
--- a/src/gui/sell.cpp
+++ b/src/gui/sell.cpp
@@ -93,7 +93,8 @@ void SellDialog::addItem(short index, int price)
int id = inventoryWindow->items->getId(index);
ITEM_SHOP item_shop;
- sprintf(item_shop.name, "%s %i gp", itemDb.getName(id).c_str(), price);
+ sprintf(item_shop.name, "%s %i gp",
+ itemDb.getItemInfo(id)->getName().c_str(), price);
item_shop.price = price;
item_shop.index = index;
item_shop.id = id;
diff --git a/src/resources/itemmanager.cpp b/src/resources/itemmanager.cpp
index 4bb6555b..eb75321d 100644
--- a/src/resources/itemmanager.cpp
+++ b/src/resources/itemmanager.cpp
@@ -36,8 +36,7 @@
#define xmlFree(x) ;
#endif
-ItemManager::ItemManager() :
- minId(10000), maxId(0)
+ItemManager::ItemManager()
{
// Check that file exists before trying to parse it
std::fstream dbFile;
@@ -63,8 +62,6 @@ ItemManager::ItemManager() :
xmlChar *prop;
prop = xmlGetProp(node, BAD_CAST "id");
int id = atoi((const char*)prop);
- if (id < minId) minId = id;
- if (id > maxId) maxId = id;
xmlFree(prop);
prop = xmlGetProp(node, BAD_CAST "image");
int image = atoi((const char*)prop);
@@ -116,58 +113,11 @@ ItemManager::~ItemManager()
{
}
-short ItemManager::getImage(int id)
+ItemInfo *ItemManager::getItemInfo(int id)
{
- if (id >= minId && id <= maxId)
- return db[id]->getImage();
+ if (db.find(id) != db.end())
+ return db[id];
else
- return 0;
+ return NULL;
}
-short ItemManager::getArt(int id)
-{
- if (id >= minId && id <= maxId)
- return db[id]->getArt();
- else
- return 0;
-}
-
-std::string ItemManager::getName(int id)
-{
- if (id >= minId && id <= maxId)
- return db[id]->getName();
- else
- return "Unknown";
-}
-
-std::string ItemManager::getDescription(int id)
-{
- if (id >= minId && id <= maxId)
- return db[id]->getDescription();
- else
- return "";
-}
-
-short ItemManager::getType(int id)
-{
- if (id >= minId && id <= maxId)
- return db[id]->getType();
- else
- return 0;
-}
-
-short ItemManager::getWeight(int id)
-{
- if (id >= minId && id <= maxId)
- return db[id]->getWeight();
- else
- return 0;
-}
-
-char ItemManager::getSlot(int id)
-{
- if (id >= minId && id <= maxId)
- return db[id]->getSlot();
- else
- return 0;
-}
diff --git a/src/resources/itemmanager.h b/src/resources/itemmanager.h
index 3f014ad6..b4c98e5b 100644
--- a/src/resources/itemmanager.h
+++ b/src/resources/itemmanager.h
@@ -45,26 +45,11 @@ class ItemManager
*/
~ItemManager();
- short getImage(int id);
+ ItemInfo *getItemInfo(int id);
- short getArt(int id);
-
- std::string getName(int id);
-
- std::string getDescription(int id);
-
- short getType(int id);
-
- short getWeight(int id);
-
- char getSlot(int id);
-
-
protected:
// Items database
std::map <int, ItemInfo *> db;
- int minId, maxId;
-
};
#endif