summaryrefslogtreecommitdiff
path: root/src/map/itemdb.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/map/itemdb.c')
-rw-r--r--src/map/itemdb.c339
1 files changed, 216 insertions, 123 deletions
diff --git a/src/map/itemdb.c b/src/map/itemdb.c
index a225cff83..91ec58c81 100644
--- a/src/map/itemdb.c
+++ b/src/map/itemdb.c
@@ -12,6 +12,7 @@
#include "itemdb.h"
#include "script.h"
#include "pc.h"
+#include "showmsg.h"
#ifdef MEMWATCH
#include "memwatch.h"
@@ -25,9 +26,9 @@
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;
+static struct random_item_data blue_box[MAX_RANDITEM], violet_box[MAX_RANDITEM], card_album[MAX_RANDITEM], gift_box[MAX_RANDITEM], scroll[MAX_RANDITEM], finding_ore[MAX_RANDITEM];
+static int blue_box_count=0, violet_box_count=0, card_album_count=0, gift_box_count=0, scroll_count=0, finding_ore_count = 0;
+static int blue_box_default=0, violet_box_default=0, card_album_default=0, gift_box_default=0, scroll_default=0, finding_ore_default = 0;
// Function declarations
@@ -39,7 +40,11 @@ static int itemdb_read_sqldb(void);
static int itemdb_read_randomitem();
static int itemdb_read_itemavail(void);
static int itemdb_read_itemnametable(void);
+static int itemdb_read_itemslottable(void);
+static int itemdb_read_itemslotcounttable(void);
+static int itemdb_read_cardillustnametable(void);
static int itemdb_read_noequip(void);
+static int itemdb_read_norefine(void);
void itemdb_reload(void);
/*==========================================
@@ -97,16 +102,18 @@ int itemdb_searchrandomid(int flags)
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){
+ } data[7];
+
+ // for BCC32 compile error
+ data[0].nameid = 0; data[0].count = 0; data[0].list = NULL;
+ data[1].nameid = blue_box_default; data[1].count = blue_box_count; data[1].list = blue_box;
+ data[2].nameid = violet_box_default; data[2].count = violet_box_count; data[2].list = violet_box;
+ data[3].nameid = card_album_default; data[3].count = card_album_count; data[3].list = card_album;
+ data[4].nameid = gift_box_default; data[4].count = gift_box_count; data[4].list = gift_box;
+ data[5].nameid = scroll_default; data[5].count = scroll_count; data[5].list = scroll;
+ data[6].nameid = finding_ore_default; data[6].count = finding_ore_count; data[6].list = finding_ore;
+
+ if(flags>=1 && flags<=6){
nameid=data[flags].nameid;
count=data[flags].count;
list=data[flags].list;
@@ -130,7 +137,7 @@ int itemdb_searchrandomid(int flags)
*/
struct item_data* itemdb_exists(int nameid)
{
- return numdb_search(item_db,nameid);
+ return (struct item_data *) numdb_search(item_db,nameid);
}
/*==========================================
* DBの検索
@@ -140,7 +147,7 @@ struct item_data* itemdb_search(int nameid)
{
struct item_data *id;
- id=numdb_search(item_db,nameid);
+ id=(struct item_data *) numdb_search(item_db,nameid);
if(id) return id;
id=(struct item_data *)aCalloc(1,sizeof(struct item_data));
@@ -152,7 +159,7 @@ struct item_data* itemdb_search(int nameid)
id->weight=10;
id->sex=2;
id->elv=0;
- id->class=0xffffffff;
+ id->class_=0xffffffff;
id->flag.available=0;
id->flag.value_notdc=0; //一応・・・
id->flag.value_notoc=0;
@@ -237,66 +244,40 @@ int itemdb_isdropable(int nameid)
return 1;
}
-//
-// 初期化
-//
-/*==========================================
- *
- *------------------------------------------
- */
-static int itemdb_read_itemslottable(void)
-{
- char *buf,*p;
- int s;
-
- buf=grfio_read("data\\itemslottable.txt");
- if(buf==NULL)
- return -1;
- s=grfio_size("data\\itemslottable.txt");
- buf[s]=0;
- for(p=buf;p-buf<s;){
- int nameid,equip;
- sscanf(p,"%d#%d#",&nameid,&equip);
- itemdb_search(nameid)->equip=equip;
- p=strchr(p,10);
- if(!p) break;
- p++;
- p=strchr(p,10);
- if(!p) break;
- p++;
- }
- free(buf);
-
- return 0;
-}
-
-#ifndef TXT_ONLY
/*====================================
* Removed item_value_db, don't re-add
*------------------------------------
*/
static void itemdb_read(void)
{
- itemdb_read_itemslottable();
-
- if (db_use_sqldbs)
- {
- itemdb_read_sqldb();
- }
- else
- {
+ #ifndef TXT_ONLY
+ if (db_use_sqldbs)
+ {
+ itemdb_read_sqldb();
+ }
+ else
+ {
+ itemdb_readdb();
+ }
+ /* not TXT_ONLY */
+ #else
itemdb_readdb();
- }
+ #endif /* TXT_ONLY */
itemdb_read_randomitem();
itemdb_read_itemavail();
itemdb_read_noequip();
-
- if (!battle_config.item_name_override_grffile)
+ itemdb_read_norefine();
+ if (battle_config.cardillust_read_grffile)
+ itemdb_read_cardillustnametable();
+ if (battle_config.item_equip_override_grffile)
+ itemdb_read_itemslottable();
+ if (battle_config.item_slots_override_grffile)
+ itemdb_read_itemslotcounttable();
+ if (battle_config.item_name_override_grffile)
itemdb_read_itemnametable();
}
-#endif /* not TXT_ONLY */
/*==========================================
* アイテムデータベースの読み込み
*------------------------------------------
@@ -346,20 +327,36 @@ static int itemdb_readdb(void)
memcpy(id->name,str[1],24);
memcpy(id->jname,str[2],24);
id->type=atoi(str[3]);
- // buy≠sell*2 は item_value_db.txt で指定してください。
- if (atoi(str[5])) { // sell値を優先とする
- id->value_buy=atoi(str[5])*2;
- id->value_sell=atoi(str[5]);
- } else {
- id->value_buy=atoi(str[4]);
- id->value_sell=atoi(str[4])/2;
+
+ {
+ int buy = atoi(str[4]), sell = atoi(str[5]);
+ // if buying price > selling price * 2 consider it valid and don't change it [celest]
+ if (buy && sell && buy > sell*2){
+ id->value_buy = buy;
+ id->value_sell = sell;
+ } else {
+ // buy≠sell*2 は item_value_db.txt で指定してください。
+ if (sell) { // sell値を優先とする
+ id->value_buy = sell*2;
+ id->value_sell = sell;
+ } else {
+ id->value_buy = buy;
+ id->value_sell = buy/2;
+ }
+ }
+ // check for bad prices that can possibly cause exploits
+ if (id->value_buy*75/100 < id->value_sell*124/100) {
+ sprintf (tmp_output, "Item %s [%d] buying:%d < selling:%d\n",
+ id->name, id->nameid, id->value_buy*75/100, id->value_sell*124/100);
+ ShowWarning (tmp_output);
+ }
}
id->weight=atoi(str[6]);
id->atk=atoi(str[7]);
id->def=atoi(str[8]);
id->range=atoi(str[9]);
id->slot=atoi(str[10]);
- id->class=atoi(str[11]);
+ id->class_=atoi(str[11]);
id->sex=atoi(str[12]);
if(id->equip != atoi(str[13])){
id->equip=atoi(str[13]);
@@ -377,13 +374,17 @@ static int itemdb_readdb(void)
if((p=strchr(np,'{'))==NULL)
continue;
- id->use_script = parse_script(p,lines);
+ id->use_script = parse_script((unsigned char *) p,lines);
if((p=strchr(p+1,'{'))==NULL)
continue;
- id->equip_script = parse_script(p,lines);
+ id->equip_script = parse_script((unsigned char *) p,lines);
}
fclose(fp);
- printf("read %s done (count=%d)\n",filename[i],ln);
+ if (ln > 0) {
+ sprintf(tmp_output,"Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n",ln,filename[i]);
+ ShowStatus(tmp_output);
+ }
+ ln=0; // reset to 0
}
return 0;
}
@@ -410,15 +411,16 @@ static int itemdb_read_randomitem()
{"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 },
+ {"db/item_giftbox.txt", gift_box, &gift_box_count, &gift_box_default },
+ {"db/item_scroll.txt", scroll, &scroll_count, &scroll_default },
+ {"db/item_findingore.txt", finding_ore,&finding_ore_count, &finding_ore_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;
- char *fn=data[i].filename;
+ char *fn=(char *) data[i].filename;
*pdefault = 0;
if( (fp=fopen(fn,"r"))==NULL ){
@@ -458,7 +460,10 @@ static int itemdb_read_randomitem()
ln++;
}
fclose(fp);
- printf("read %s done (count=%d)\n",fn,*pc);
+ if (*pc > 0) {
+ sprintf(tmp_output,"Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n",*pc,fn);
+ ShowStatus(tmp_output);
+ }
}
return 0;
@@ -507,7 +512,8 @@ static int itemdb_read_itemavail(void)
ln++;
}
fclose(fp);
- printf("read db/item_avail.txt done (count=%d)\n",ln);
+ sprintf(tmp_output,"Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n",ln,"db/item_avail.txt");
+ ShowStatus(tmp_output);
return 0;
}
@@ -520,7 +526,7 @@ static int itemdb_read_itemnametable(void)
char *buf,*p;
int s;
- buf=grfio_reads("data\\idnum2itemdisplaynametable.txt",&s);
+ buf=(char *) grfio_reads("data\\idnum2itemdisplaynametable.txt",&s);
if(buf==NULL)
return -1;
@@ -547,12 +553,13 @@ static int itemdb_read_itemnametable(void)
if(!p) break;
p++;
}
- free(buf);
- printf("read data\\idnum2itemdisplaynametable.txt done.\n");
+ aFree(buf);
+ sprintf(tmp_output,"Done reading '"CL_WHITE"%s"CL_RESET"'.\n","data\\idnum2itemdisplaynametable.txt");
+ ShowStatus(tmp_output);
return 0;
}
-#ifdef TXT_ONLY
+
/*==========================================
* カードイラストのリソース名前テーブルを読み込む
*------------------------------------------
@@ -562,7 +569,7 @@ static int itemdb_read_cardillustnametable(void)
char *buf,*p;
int s;
- buf=grfio_reads("data\\num2cardillustnametable.txt",&s);
+ buf=(char *) grfio_reads("data\\num2cardillustnametable.txt",&s);
if(buf==NULL)
return -1;
@@ -582,12 +589,83 @@ static int itemdb_read_cardillustnametable(void)
if(!p) break;
p++;
}
- free(buf);
- printf("read data\\num2cardillustnametable.txt done.\n");
+ aFree(buf);
+ sprintf(tmp_output,"Done reading '"CL_WHITE"%s"CL_RESET"'.\n","data\\num2cardillustnametable.txt");
+ ShowStatus(tmp_output);
+
+ return 0;
+}
+
+//
+// 初期化
+//
+/*==========================================
+ *
+ *------------------------------------------
+ */
+static int itemdb_read_itemslottable(void)
+{
+ char *buf,*p;
+ int s;
+
+ buf=(char *) grfio_read("data\\itemslottable.txt");
+ if(buf==NULL)
+ return -1;
+ s=grfio_size("data\\itemslottable.txt");
+ buf[s]=0;
+ for(p=buf;p-buf<s;){
+ int nameid,equip;
+ struct item_data* item;
+ sscanf(p,"%d#%d#",&nameid,&equip);
+ item = itemdb_search(nameid);
+ if (item && itemdb_isequip2(item))
+ item->equip=equip;
+ p=strchr(p,10);
+ if(!p) break;
+ p++;
+ p=strchr(p,10);
+ if(!p) break;
+ p++;
+ }
+ aFree(buf);
+ sprintf(tmp_output,"Done reading '"CL_WHITE"%s"CL_RESET"'.\n","data\\itemslottable.txt");
+ ShowStatus(tmp_output);
+
+ return 0;
+}
+
+/*==========================================
+ *
+ *------------------------------------------
+ */
+static int itemdb_read_itemslotcounttable(void)
+{
+ char *buf,*p;
+ int s;
+
+ buf=(char *) grfio_read("data\\itemslotcounttable.txt");
+ if(buf==NULL)
+ return -1;
+ s=grfio_size("data\\itemslotcounttable.txt");
+ buf[s]=0;
+ for(p=buf;p-buf<s;){
+ int nameid,slot;
+ sscanf(p,"%d#%d#",&nameid,&slot);
+ itemdb_search(nameid)->slot=slot;
+ p=strchr(p,10);
+ if(!p) break;
+ p++;
+ p=strchr(p,10);
+ if(!p) break;
+ p++;
+ }
+ aFree(buf);
+ sprintf(tmp_output,"Done reading '"CL_WHITE"%s"CL_RESET"'.\n","data\\itemslotcounttable.txt");
+ ShowStatus(tmp_output);
return 0;
}
-#endif /* TXT_ONLY */
+
/*==========================================
* 装備制限ファイル読み出し
*------------------------------------------
@@ -627,9 +705,47 @@ static int itemdb_read_noequip(void)
}
fclose(fp);
- printf("read db/item_noequip.txt done (count=%d)\n",ln);
+ if (ln > 0) {
+ sprintf(tmp_output,"Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n",ln,"db/item_noequip.txt");
+ ShowStatus(tmp_output);
+ }
return 0;
}
+
+/*================================================
+ * Whether the item can be refined or not [Celest]
+ *------------------------------------------------
+ */
+static int itemdb_read_norefine(void)
+{
+ int i, nameid;
+ struct item_data *id;
+ // To-do: let it read from a text file later
+ int cant_refine[] = {
+ 1243, 1530, 2110, 2112, 2201, 2202, 2203, 2204, 2205, 2210,
+ 2212, 2218, 2219, 2237, 2238, 2239, 2240, 2241, 2242, 2243,
+ 2250, 2253, 2260, 2262, 2263, 2264, 2265, 2266, 2267, 2268,
+ 2269, 2270, 2271, 2276, 2278, 2279, 2281, 2282, 2286, 2288,
+ 2289, 2290, 2291, 2292, 2293, 2295, 2296, 2297, 2298, 2352,
+ 2410, 2413, 2414, 2509, 2510, 2601, 2602, 2603, 2604, 2605,
+ 2607, 2608, 2609, 2610, 2611, 2612, 2613, 2614, 2615, 2616,
+ 2617, 2618, 2619, 2620, 2621, 2622, 2623, 2624, 2625, 2626,
+ 2627, 2628, 2629, 2630, 2631, 2634, 2635, 2636, 2637, 2638,
+ 2639, 2640, 5004, 5005, 5006, 5008, 5014, 5015, 5037, 5039,
+ 5040, 5043, 5046, 5049, 5050, 5051, 5053, 5054, 5055, 5058,
+ 5068, 5074, 5085, 5086, 5087, 5088, 5089, 5090, 5096, 5098, 0
+ };
+
+ for (i=0; i < (int)(sizeof(cant_refine) / sizeof(cant_refine[0])); i++) {
+ nameid = cant_refine[i];
+ if(nameid<=0 || nameid>=20000 || !(id=itemdb_exists(nameid)))
+ continue;
+ id->flag.no_refine = 1;
+ }
+
+ return 1;
+}
+
#ifndef TXT_ONLY
/*======================================
@@ -673,7 +789,7 @@ static int itemdb_read_sqldb(void)
// Insert a new row into the item database
- /*id = calloc(sizeof(struct item_data), 1);
+ /*id = aCalloc(sizeof(struct item_data), 1);
if (id == NULL)
{
@@ -723,7 +839,7 @@ static int itemdb_read_sqldb(void)
id->def = (sql_row[8] != NULL) ? atoi(sql_row[8]) : 0;
id->range = (sql_row[9] != NULL) ? atoi(sql_row[9]) : 0;
id->slot = (sql_row[10] != NULL) ? atoi(sql_row[10]) : 0;
- id->class = (sql_row[11] != NULL) ? atoi(sql_row[11]) : 0;
+ id->class_ = (sql_row[11] != NULL) ? atoi(sql_row[11]) : 0;
id->sex = (sql_row[12] != NULL) ? atoi(sql_row[12]) : 0;
id->equip = (sql_row[13] != NULL) ? atoi(sql_row[13]) : 0;
id->wlv = (sql_row[14] != NULL) ? atoi(sql_row[14]) : 0;
@@ -737,10 +853,10 @@ static int itemdb_read_sqldb(void)
if (sql_row[17] != NULL)
{
if (sql_row[17][0] == '{')
- id->use_script = parse_script(sql_row[17], 0);
+ id->use_script = parse_script((unsigned char *) sql_row[17], 0);
else {
sprintf(script, "{%s}", sql_row[17]);
- id->use_script = parse_script(script, 0);
+ id->use_script = parse_script((unsigned char *) script, 0);
}
}
else
@@ -751,10 +867,10 @@ static int itemdb_read_sqldb(void)
if (sql_row[18] != NULL)
{
if (sql_row[18][0] == '{')
- id->equip_script = parse_script(sql_row[18], 0);
+ id->equip_script = parse_script((unsigned char *) sql_row[18], 0);
else {
sprintf(script, "{%s}", sql_row[18]);
- id->equip_script = parse_script(script, 0);
+ id->equip_script = parse_script((unsigned char *) script, 0);
}
}
else
@@ -774,8 +890,8 @@ static int itemdb_read_sqldb(void)
{
printf("Database server error (retrieving rows from %s): %s\n", item_db_db, mysql_error(&mmysql_handle));
}
-
- printf("read %s done (count = %lu)\n", item_db_db, (unsigned long) mysql_num_rows(sql_res));
+ sprintf(tmp_output,"Done reading '"CL_WHITE"%lu"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n",(unsigned long) mysql_num_rows(sql_res),item_db_db);
+ ShowStatus(tmp_output);
}
else
{
@@ -802,26 +918,20 @@ static int itemdb_final(void *key,void *data,va_list ap)
{
struct item_data *id;
- nullpo_retr(0, id=data);
+ nullpo_retr(0, id= (struct item_data *) data);
if(id->use_script)
- free(id->use_script);
+ aFree(id->use_script);
if(id->equip_script)
- free(id->equip_script);
- free(id);
+ aFree(id->equip_script);
+ aFree(id);
return 0;
}
void itemdb_reload(void)
{
- /*
-
- <empty item databases>
- itemdb_read();
-
- */
-
+ numdb_final(item_db,itemdb_final);
do_init_itemdb();
}
@@ -851,23 +961,6 @@ void itemdebugtxt()
fclose(dfp);
}
*/
-#ifdef TXT_ONLY
-/*====================================
- * Removed item_value_db, don't re-add
- *------------------------------------
- */
-static void itemdb_read(void)
-{
- itemdb_read_itemslottable();
- itemdb_readdb();
- itemdb_read_randomitem();
- itemdb_read_itemavail();
- itemdb_read_noequip();
- itemdb_read_cardillustnametable();
- if (!battle_config.item_name_override_grffile)
- itemdb_read_itemnametable();
-}
-#endif /* TXT_ONLY */
/*==========================================
*
*------------------------------------------