summaryrefslogtreecommitdiff
path: root/src/map/itemdb.cpp
diff options
context:
space:
mode:
authorBen Longbons <b.r.longbons@gmail.com>2013-02-12 20:18:58 -0800
committerBen Longbons <b.r.longbons@gmail.com>2013-02-12 21:09:59 -0800
commitb17b9021ecf9b16c265d0a6b60faa761b34eae35 (patch)
treee8192de5b2458864f0f5ce5edd0e1ccf5605c644 /src/map/itemdb.cpp
parent80e36aa669274637bcd5956fbf4020dba1d4739c (diff)
downloadtmwa-b17b9021ecf9b16c265d0a6b60faa761b34eae35.tar.gz
tmwa-b17b9021ecf9b16c265d0a6b60faa761b34eae35.tar.bz2
tmwa-b17b9021ecf9b16c265d0a6b60faa761b34eae35.tar.xz
tmwa-b17b9021ecf9b16c265d0a6b60faa761b34eae35.zip
Replace mt_rand with <random>
Also add some utility methods and classes.
Diffstat (limited to 'src/map/itemdb.cpp')
-rw-r--r--src/map/itemdb.cpp158
1 files changed, 1 insertions, 157 deletions
diff --git a/src/map/itemdb.cpp b/src/map/itemdb.cpp
index 06b2873..9c6d4e6 100644
--- a/src/map/itemdb.cpp
+++ b/src/map/itemdb.cpp
@@ -5,7 +5,7 @@
#include "../common/cxxstdio.hpp"
#include "../common/db.hpp"
-#include "../common/mt_rand.hpp"
+#include "../common/random.hpp"
#include "../common/nullpo.hpp"
#include "../common/socket.hpp"
@@ -20,17 +20,6 @@ constexpr int MAX_RANDITEM = 2000;
static
struct dbt *item_db;
-static
-struct random_item_data blue_box[MAX_RANDITEM],
- violet_box[MAX_RANDITEM], card_album[MAX_RANDITEM],
- gift_box[MAX_RANDITEM], scroll[MAX_RANDITEM];
-static
-int blue_box_count = 0, violet_box_count = 0, card_album_count =
- 0, gift_box_count = 0, scroll_count = 0;
-static
-int blue_box_default = 0, violet_box_default = 0, card_album_default =
- 0, gift_box_default = 0, scroll_default = 0;
-
// Function declarations
static
@@ -38,8 +27,6 @@ void itemdb_read(void);
static
int itemdb_readdb(void);
static
-int itemdb_read_randomitem(void);
-static
int itemdb_read_itemavail(void);
static
int itemdb_read_noequip(void);
@@ -69,56 +56,6 @@ struct item_data *itemdb_searchname(const char *str)
}
/*==========================================
- * 箱系アイテム検索
- *------------------------------------------
- */
-int itemdb_searchrandomid(int flags)
-{
- int nameid = 0, i, index, count;
- struct random_item_data *list = NULL;
-
- struct
- {
- int nameid, count;
- struct random_item_data *list;
- } data[] =
- {
- {
- 0, 0, NULL},
- {
- blue_box_default, blue_box_count, blue_box},
- {
- violet_box_default, violet_box_count, violet_box},
- {
- card_album_default, card_album_count, card_album},
- {
- gift_box_default, gift_box_count, gift_box},
- {
- scroll_default, scroll_count, scroll},};
-
- if (flags >= 1 && flags <= 5)
- {
- nameid = data[flags].nameid;
- count = data[flags].count;
- list = data[flags].list;
-
- if (count > 0)
- {
- for (i = 0; i < 1000; i++)
- {
- index = MRAND(count);
- if (MRAND(1000000) < list[index].per)
- {
- nameid = list[index].nameid;
- break;
- }
- }
- }
- }
- return nameid;
-}
-
-/*==========================================
* DBの存在確認
*------------------------------------------
*/
@@ -323,98 +260,6 @@ int itemdb_readdb(void)
// Removed item_value_db, don't re-add!
/*==========================================
- * ランダムアイテム出現データの読み込み
- *------------------------------------------
- */
-static
-int itemdb_read_randomitem(void)
-{
- FILE *fp;
- char line[1024];
- int ln = 0;
- int nameid, i, j;
- char *str[10], *p;
-
- const struct
- {
- char filename[64];
- struct random_item_data *pdata;
- int *pcount, *pdefault;
- } data[] =
- {
- {
- "db/item_bluebox.txt", blue_box, &blue_box_count,
- &blue_box_default},
- {
- "db/item_violetbox.txt", violet_box, &violet_box_count,
- &violet_box_default},
- {
- "db/item_cardalbum.txt", card_album, &card_album_count,
- &card_album_default},
- {
- "db/item_giftbox.txt", gift_box, &gift_box_count,
- &gift_box_default},
- {
- "db/item_scroll.txt", scroll, &scroll_count, &scroll_default},};
-
- for (i = 0; i < sizeof(data) / sizeof(data[0]); i++)
- {
- struct random_item_data *pd = data[i].pdata;
- int *pc = data[i].pcount;
- int *pdefault = data[i].pdefault;
- const char *fn = data[i].filename;
-
- *pdefault = 0;
- if ((fp = fopen_(fn, "r")) == NULL)
- {
- PRINTF("can't read %s\n", fn);
- continue;
- }
-
- while (fgets(line, 1020, fp))
- {
- if (line[0] == '/' && line[1] == '/')
- continue;
- memset(str, 0, sizeof(str));
- for (j = 0, p = line; j < 3 && p; j++)
- {
- str[j] = p;
- p = strchr(p, ',');
- if (p)
- *p++ = 0;
- }
-
- if (str[0] == NULL)
- continue;
-
- nameid = atoi(str[0]);
- if (nameid < 0 || nameid >= 20000)
- continue;
- if (nameid == 0)
- {
- if (str[2])
- *pdefault = atoi(str[2]);
- continue;
- }
-
- if (str[2])
- {
- pd[*pc].nameid = nameid;
- pd[(*pc)++].per = atoi(str[2]);
- }
-
- if (ln >= MAX_RANDITEM)
- break;
- ln++;
- }
- fclose_(fp);
- PRINTF("read %s done (count=%d)\n", fn, *pc);
- }
-
- return 0;
-}
-
-/*==========================================
* アイテム使用可能フラグのオーバーライド
*------------------------------------------
*/
@@ -585,7 +430,6 @@ static
void itemdb_read(void)
{
itemdb_readdb();
- itemdb_read_randomitem();
itemdb_read_itemavail();
itemdb_read_noequip();
}