summaryrefslogtreecommitdiff
path: root/src/map/itemdb.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/map/itemdb.cpp')
-rw-r--r--src/map/itemdb.cpp50
1 files changed, 17 insertions, 33 deletions
diff --git a/src/map/itemdb.cpp b/src/map/itemdb.cpp
index 4ebb52c..edc9982 100644
--- a/src/map/itemdb.cpp
+++ b/src/map/itemdb.cpp
@@ -20,29 +20,27 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
-#include <cstdlib>
-#include <cstring>
-
-#include "../compat/nullpo.hpp"
+#include <algorithm>
#include "../strings/astring.hpp"
#include "../strings/zstring.hpp"
#include "../strings/xstring.hpp"
#include "../generic/db.hpp"
-#include "../generic/random.hpp"
#include "../io/cxxstdio.hpp"
#include "../io/read.hpp"
#include "../mmo/config_parse.hpp"
#include "../mmo/extract.hpp"
-#include "../mmo/socket.hpp"
#include "../poison.hpp"
+
+namespace tmwa
+{
static
-Map<int, struct item_data> item_db;
+Map<ItemNameId, struct item_data> item_db;
// Function declarations
@@ -67,7 +65,7 @@ struct item_data *itemdb_searchname(XString str_)
ItemName str = stringish<ItemName>(str_);
if (XString(str) != str_)
return nullptr;
- struct item_data *item = NULL;
+ struct item_data *item = nullptr;
for (auto& pair : item_db)
itemdb_searchname_sub(&pair.second, str, &item);
return item;
@@ -77,7 +75,7 @@ struct item_data *itemdb_searchname(XString str_)
* DBの存在確認
*------------------------------------------
*/
-struct item_data *itemdb_exists(int nameid)
+struct item_data *itemdb_exists(ItemNameId nameid)
{
return item_db.search(nameid);
}
@@ -86,7 +84,7 @@ struct item_data *itemdb_exists(int nameid)
* DBの検索
*------------------------------------------
*/
-struct item_data *itemdb_search(int nameid)
+struct item_data *itemdb_search(ItemNameId nameid)
{
struct item_data *id = item_db.search(nameid);
if (id)
@@ -101,22 +99,7 @@ struct item_data *itemdb_search(int nameid)
id->sex = SEX::NEUTRAL;
id->elv = 0;
- if (nameid > 500 && nameid < 600)
- id->type = ItemType::USE;
- else if (nameid > 600 && nameid < 700)
- id->type = ItemType::_2;
- else if ((nameid > 700 && nameid < 1100) ||
- (nameid > 7000 && nameid < 8000))
- id->type = ItemType::JUNK;
- else if (nameid >= 1750 && nameid < 1771)
- id->type = ItemType::ARROW;
- else if (nameid > 1100 && nameid < 2000)
- id->type = ItemType::WEAPON;
- else if ((nameid > 2100 && nameid < 3000) ||
- (nameid > 5000 && nameid < 6000))
- id->type = ItemType::ARMOR;
- else if (nameid > 4000 && nameid < 5000)
- id->type = ItemType::_6;
+ id->type = ItemType::JUNK;
return id;
}
@@ -125,7 +108,7 @@ struct item_data *itemdb_search(int nameid)
*
*------------------------------------------
*/
-int itemdb_isequip(int nameid)
+int itemdb_isequip(ItemNameId nameid)
{
ItemType type = itemdb_type(nameid);
return !(type == ItemType::USE
@@ -155,7 +138,7 @@ int itemdb_isequip2(struct item_data *data)
*
*------------------------------------------
*/
-int itemdb_isequip3(int nameid)
+int itemdb_isequip3(ItemNameId nameid)
{
ItemType type = itemdb_type(nameid);
return (type == ItemType::WEAPON
@@ -174,7 +157,7 @@ bool itemdb_readdb(ZString filename)
if (!in.is_open())
{
- PRINTF("can't read %s\n", filename);
+ PRINTF("can't read %s\n"_fmt, filename);
return false;
}
@@ -220,7 +203,7 @@ bool itemdb_readdb(ZString filename)
)
)
{
- PRINTF("%s:%d: error: bad item line: %s\n",
+ PRINTF("%s:%d: error: bad item line: %s\n"_fmt,
filename, lines, line);
rv = false;
continue;
@@ -242,8 +225,8 @@ bool itemdb_readdb(ZString filename)
id->value_sell = id->value_buy / 2;
}
- id->use_script = NULL;
- id->equip_script = NULL;
+ id->use_script = nullptr;
+ id->equip_script = nullptr;
if (!tail_part)
continue;
@@ -254,7 +237,7 @@ bool itemdb_readdb(ZString filename)
continue;
id->equip_script = parse_script(tail_part, lines, true);
}
- PRINTF("read %s done (count=%d)\n", filename, ln);
+ PRINTF("read %s done (count=%d)\n"_fmt, filename, ln);
}
return rv;
@@ -281,3 +264,4 @@ void do_final_itemdb(void)
itemdb_final(&pair.second);
item_db.clear();
}
+} // namespace tmwa