diff options
author | Eugenio Favalli <elvenprogrammer@gmail.com> | 2005-04-21 12:52:08 +0000 |
---|---|---|
committer | Eugenio Favalli <elvenprogrammer@gmail.com> | 2005-04-21 12:52:08 +0000 |
commit | 8eb8602942d63661674d237d127c5f3ccfcf4ef4 (patch) | |
tree | 0d1e902e16c55f7742ead9a4c9f53506c373df48 /src | |
parent | d70c0ba4264dee317d1a60f2fa4d81f123dde016 (diff) | |
download | mana-8eb8602942d63661674d237d127c5f3ccfcf4ef4.tar.gz mana-8eb8602942d63661674d237d127c5f3ccfcf4ef4.tar.bz2 mana-8eb8602942d63661674d237d127c5f3ccfcf4ef4.tar.xz mana-8eb8602942d63661674d237d127c5f3ccfcf4ef4.zip |
Now shops get item names from the xml database
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/gui/buy.cpp | 7 | ||||
-rw-r--r-- | src/gui/sell.cpp | 7 | ||||
-rw-r--r-- | src/gui/shop.cpp | 119 | ||||
-rw-r--r-- | src/gui/shop.h | 2 | ||||
-rw-r--r-- | src/main.cpp | 1 | ||||
-rw-r--r-- | src/main.h | 3 | ||||
-rw-r--r-- | src/resources/itemmanager.cpp | 40 | ||||
-rw-r--r-- | src/resources/itemmanager.h | 1 |
9 files changed, 37 insertions, 144 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 7b2da568..69a24f1c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -59,7 +59,6 @@ tmw_SOURCES = graphic/spriteset.cpp \ gui/sell.h \ gui/setup.cpp \ gui/setup.h \ - gui/shop.cpp \ gui/shop.h \ gui/skill.cpp \ gui/skill.h \ diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index 2da38c36..c26be5d3 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -102,12 +102,7 @@ void BuyDialog::addItem(short id, int price) { ITEM_SHOP item_shop; - if (id >= 501 && id <= 2301) { - sprintf(item_shop.name, "%s %i gp", item_db[id - 501], price); - } - else { - sprintf(item_shop.name, "Unknown item %i gp", price); - } + sprintf(item_shop.name, "%s %i gp", itemDb.getName(id).c_str(), price); item_shop.price = price; item_shop.id = id; diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index d4bd1d8a..2c9e8745 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -93,12 +93,7 @@ void SellDialog::addItem(short index, int price) int id = inventoryWindow->items->getId(index); ITEM_SHOP item_shop; - if (id >= 501 && id <= 2301) { - sprintf(item_shop.name, "%s %i gp", item_db[id - 501], price); - } - else { - sprintf(item_shop.name, "Unknown item %i gp", price); - } + sprintf(item_shop.name, "%s %i gp", itemDb.getName(id).c_str(), price); item_shop.price = price; item_shop.index = index; item_shop.id = id; diff --git a/src/gui/shop.cpp b/src/gui/shop.cpp index 09d99669..1dd498a8 100644 --- a/src/gui/shop.cpp +++ b/src/gui/shop.cpp @@ -23,122 +23,3 @@ #include "shop.h" -// TODO: replace it with item database - -char *item_db[] = { - "Cactus Drink", - "Cactus potion", - "Casino coins", - "Decor Candy", - "Maggot Slime", - "Candy Cane", - "Scorpion Stinger", - "Xmas Cake", - "Chocolate", - "Candy", - "Santa Hat", - "Ginger bread man", - "Slice of cake", - "Xmas candy cane", - "Purple present", - "Yellow present", - "Red scorpion stinger", - "Bug leg", - "Cherry cake", - "Easter Egg", - "Dagger", - "Sharp knife", - "Leather shirt", - "Fancy hat","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - - // 601 - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - - // 701 - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - - // 801 - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - - // 901 - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - - // 1001 - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - - // 1101 - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","Arrow","Bow", - - // 1201 - "Knife","Cotton Shirt","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", - "","","","","","","","","","", -}; diff --git a/src/gui/shop.h b/src/gui/shop.h index 635075a1..c3d85780 100644 --- a/src/gui/shop.h +++ b/src/gui/shop.h @@ -35,6 +35,4 @@ struct ITEM_SHOP { int quantity; }; -extern char *item_db[]; - #endif diff --git a/src/main.cpp b/src/main.cpp index f7340ff2..5c62700f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -29,7 +29,6 @@ #include "sound.h" #include "graphics.h" #include "resources/resourcemanager.h" -#include "resources/itemmanager.h" #include "net/protocol.h" #include <iostream> @@ -29,6 +29,7 @@ #include "gui/skill.h" #include "graphic/spriteset.h" #include "resources/image.h" +#include "resources/itemmanager.h" #include "configuration.h" #include "game.h" #include "log.h" @@ -104,5 +105,5 @@ extern Map *tiledMap; extern Logger logger; extern int screenW, screenH, bitDepth, displayFlags; extern bool useOpenGL; - +extern ItemManager itemDb; #endif diff --git a/src/resources/itemmanager.cpp b/src/resources/itemmanager.cpp index 5ad4e66d..4bb6555b 100644 --- a/src/resources/itemmanager.cpp +++ b/src/resources/itemmanager.cpp @@ -36,7 +36,8 @@ #define xmlFree(x) ; #endif -ItemManager::ItemManager() +ItemManager::ItemManager() : + minId(10000), maxId(0) { // Check that file exists before trying to parse it std::fstream dbFile; @@ -62,6 +63,8 @@ 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); @@ -115,35 +118,56 @@ ItemManager::~ItemManager() short ItemManager::getImage(int id) { - return db[id]->getImage(); + if (id >= minId && id <= maxId) + return db[id]->getImage(); + else + return 0; } short ItemManager::getArt(int id) { - return db[id]->getArt(); + if (id >= minId && id <= maxId) + return db[id]->getArt(); + else + return 0; } std::string ItemManager::getName(int id) { - return db[id]->getName(); + if (id >= minId && id <= maxId) + return db[id]->getName(); + else + return "Unknown"; } std::string ItemManager::getDescription(int id) { - return db[id]->getDescription(); + if (id >= minId && id <= maxId) + return db[id]->getDescription(); + else + return ""; } short ItemManager::getType(int id) { - return db[id]->getType(); + if (id >= minId && id <= maxId) + return db[id]->getType(); + else + return 0; } short ItemManager::getWeight(int id) { - return db[id]->getWeight(); + if (id >= minId && id <= maxId) + return db[id]->getWeight(); + else + return 0; } char ItemManager::getSlot(int id) { - return db[id]->getSlot(); + 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 0db5893f..3f014ad6 100644 --- a/src/resources/itemmanager.h +++ b/src/resources/itemmanager.h @@ -63,6 +63,7 @@ class ItemManager protected: // Items database std::map <int, ItemInfo *> db; + int minId, maxId; }; |