itemdb.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268
  1. // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
  2. // For more information, see LICENCE in the main folder
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include "../common/nullpo.h"
  7. #include "../common/malloc.h"
  8. #include "../common/showmsg.h"
  9. #include "../common/grfio.h"
  10. #include "../common/strlib.h"
  11. #include "map.h"
  12. #include "battle.h"
  13. #include "itemdb.h"
  14. #include "script.h"
  15. #include "pc.h"
  16. // ** ITEMDB_OVERRIDE_NAME_VERBOSE **
  17. // 定義すると、itemdb.txtとgrfで名前が異なる場合、表示します.
  18. //#define ITEMDB_OVERRIDE_NAME_VERBOSE 1
  19. static struct dbt* item_db;
  20. static struct item_group itemgroup_db[MAX_ITEMGROUP];
  21. struct item_data dummy_item; //This is the default dummy item used for non-existant items. [Skotlex]
  22. /*==========================================
  23. * 名前で検索用
  24. *------------------------------------------
  25. */
  26. // name = item alias, so we should find items aliases first. if not found then look for "jname" (full name)
  27. int itemdb_searchname_sub(DBKey key,void *data,va_list ap)
  28. {
  29. struct item_data *item=(struct item_data *)data,**dst;
  30. char *str;
  31. str=va_arg(ap,char *);
  32. dst=va_arg(ap,struct item_data **);
  33. if(item == &dummy_item) return 0;
  34. if( strcmpi(item->name,str)==0 ) //by lupus
  35. *dst=item;
  36. return 0;
  37. }
  38. /*==========================================
  39. * 名前で検索用
  40. *------------------------------------------
  41. */
  42. int itemdb_searchjname_sub(int key,void *data,va_list ap)
  43. {
  44. struct item_data *item=(struct item_data *)data,**dst;
  45. char *str;
  46. str=va_arg(ap,char *);
  47. dst=va_arg(ap,struct item_data **);
  48. if( strcmpi(item->jname,str)==0 )
  49. *dst=item;
  50. return 0;
  51. }
  52. /*==========================================
  53. * 名前で検索
  54. *------------------------------------------
  55. */
  56. struct item_data* itemdb_searchname(const char *str)
  57. {
  58. struct item_data *item=NULL;
  59. item_db->foreach(item_db,itemdb_searchname_sub,str,&item);
  60. return item;
  61. }
  62. static int itemdb_searchname_array_sub(DBKey key,void * data,va_list ap)
  63. {
  64. struct item_data *item=(struct item_data *)data;
  65. char *str;
  66. str=va_arg(ap,char *);
  67. if (item == &dummy_item)
  68. return 1; //Invalid item.
  69. if(stristr(item->jname,str))
  70. return 0;
  71. if(stristr(item->name,str))
  72. return 0;
  73. return strcmpi(item->jname,str);
  74. }
  75. /*==========================================
  76. * Founds up to N matches. Returns number of matches [Skotlex]
  77. *------------------------------------------
  78. */
  79. int itemdb_searchname_array(struct item_data** data, int size, const char *str)
  80. {
  81. return item_db->getall(item_db,(void**)data,size,itemdb_searchname_array_sub,str);
  82. }
  83. /*==========================================
  84. * 箱系アイテム検索
  85. *------------------------------------------
  86. */
  87. int itemdb_searchrandomid(int group)
  88. {
  89. if(group<1 || group>=MAX_ITEMGROUP) {
  90. if (battle_config.error_log)
  91. ShowError("itemdb_searchrandomid: Invalid group id %d\n", group);
  92. return UNKNOWN_ITEM_ID;
  93. }
  94. if (itemgroup_db[group].qty)
  95. return itemgroup_db[group].nameid[rand()%itemgroup_db[group].qty];
  96. if (battle_config.error_log)
  97. ShowError("itemdb_searchrandomid: No item entries for group id %d\n", group);
  98. return UNKNOWN_ITEM_ID;
  99. }
  100. /*==========================================
  101. * Calculates total item-group related bonuses for the given item. [Skotlex]
  102. *------------------------------------------
  103. */
  104. int itemdb_group_bonus(struct map_session_data *sd, int itemid)
  105. {
  106. int bonus = 0, i, j;
  107. for (i=0; i < MAX_ITEMGROUP; i++) {
  108. if (!sd->itemgrouphealrate[i])
  109. continue;
  110. for (j=0; j < itemgroup_db[i].qty; j++) {
  111. if (itemgroup_db[i].id[j] == itemid)
  112. {
  113. bonus += sd->itemgrouphealrate[i];
  114. continue;
  115. }
  116. }
  117. }
  118. return bonus;
  119. }
  120. /*==========================================
  121. * DBの存在確認
  122. *------------------------------------------
  123. */
  124. struct item_data* itemdb_exists(int nameid)
  125. {
  126. struct item_data* id;
  127. if (!nameid) return NULL;
  128. id = idb_get(item_db,nameid);
  129. // if (id == &dummy_item) return NULL; //Let dummy items go through... technically they "exist" because someone already has them...
  130. return id;
  131. }
  132. /*==========================================
  133. * Converts the jobid from the format in itemdb
  134. * to the format used by the map server. [Skotlex]
  135. *------------------------------------------
  136. */
  137. static void itemdb_jobid2mapid(unsigned int *bclass, unsigned int jobmask)
  138. {
  139. int i;
  140. bclass[0]= bclass[1]= bclass[2]= 0;
  141. //Base classes
  142. if (jobmask & 1<<JOB_NOVICE)
  143. { //Both Novice/Super-Novice are counted with the same ID
  144. bclass[0] |= 1<<MAPID_NOVICE;
  145. bclass[1] |= 1<<MAPID_NOVICE;
  146. }
  147. for (i = JOB_NOVICE+1; i <= JOB_THIEF; i++)
  148. {
  149. if (jobmask & 1<<i)
  150. bclass[0] |= 1<<(MAPID_NOVICE+i);
  151. }
  152. //2-1 classes
  153. if (jobmask & 1<<JOB_KNIGHT)
  154. bclass[1] |= 1<<MAPID_SWORDMAN;
  155. if (jobmask & 1<<JOB_PRIEST)
  156. bclass[1] |= 1<<MAPID_ACOLYTE;
  157. if (jobmask & 1<<JOB_WIZARD)
  158. bclass[1] |= 1<<MAPID_MAGE;
  159. if (jobmask & 1<<JOB_BLACKSMITH)
  160. bclass[1] |= 1<<MAPID_MERCHANT;
  161. if (jobmask & 1<<JOB_HUNTER)
  162. bclass[1] |= 1<<MAPID_ARCHER;
  163. if (jobmask & 1<<JOB_ASSASSIN)
  164. bclass[1] |= 1<<MAPID_THIEF;
  165. //2-2 classes
  166. if (jobmask & 1<<JOB_CRUSADER)
  167. bclass[2] |= 1<<MAPID_SWORDMAN;
  168. if (jobmask & 1<<JOB_MONK)
  169. bclass[2] |= 1<<MAPID_ACOLYTE;
  170. if (jobmask & 1<<JOB_SAGE)
  171. bclass[2] |= 1<<MAPID_MAGE;
  172. if (jobmask & 1<<JOB_ALCHEMIST)
  173. bclass[2] |= 1<<MAPID_MERCHANT;
  174. if (jobmask & 1<<JOB_BARD)
  175. bclass[2] |= 1<<MAPID_ARCHER;
  176. if (jobmask & 1<<JOB_DANCER)
  177. bclass[2] |= 1<<MAPID_ARCHER;
  178. if (jobmask & 1<<JOB_ROGUE)
  179. bclass[2] |= 1<<MAPID_THIEF;
  180. //Special classes that don't fit above.
  181. if (jobmask & 1<<21) //Taekwon boy
  182. bclass[0] |= 1<<MAPID_TAEKWON;
  183. if (jobmask & 1<<22) //Star Gladiator
  184. bclass[1] |= 1<<MAPID_TAEKWON;
  185. if (jobmask & 1<<23) //Soul Linker
  186. bclass[2] |= 1<<MAPID_TAEKWON;
  187. if (jobmask & 1<<JOB_GUNSLINGER)
  188. bclass[0] |= 1<<MAPID_GUNSLINGER;
  189. if (jobmask & 1<<JOB_NINJA)
  190. bclass[0] |= 1<<MAPID_NINJA;
  191. }
  192. static void create_dummy_data(void) {
  193. memset(&dummy_item, 0, sizeof(struct item_data));
  194. dummy_item.nameid=500;
  195. dummy_item.weight=1;
  196. dummy_item.value_sell = 1;
  197. dummy_item.type=3; //Etc item
  198. strncpy(dummy_item.name,"UNKNOWN_ITEM",ITEM_NAME_LENGTH-1);
  199. strncpy(dummy_item.jname,"UNKNOWN_ITEM",ITEM_NAME_LENGTH-1);
  200. dummy_item.view_id = UNKNOWN_ITEM_ID;
  201. }
  202. static void* create_item_data(DBKey key, va_list args) {
  203. struct item_data *id;
  204. id=(struct item_data *)aCalloc(1,sizeof(struct item_data));
  205. id->nameid = key.i;
  206. id->weight=1;
  207. id->type=IT_ETC;
  208. return id;
  209. }
  210. /*==========================================
  211. * Loads (and creates if not found) an item from the db.
  212. *------------------------------------------
  213. */
  214. struct item_data* itemdb_load(int nameid)
  215. {
  216. struct item_data *id = idb_ensure(item_db,nameid,create_item_data);
  217. if (id == &dummy_item)
  218. { //Remove dummy_item, replace by real data.
  219. DBKey key;
  220. key.i = nameid;
  221. idb_remove(item_db,nameid);
  222. id = create_item_data(key, NULL);
  223. idb_put(item_db,nameid,id);
  224. }
  225. return id;
  226. }
  227. static void* return_dummy_data(DBKey key, va_list args) {
  228. if (battle_config.error_log)
  229. ShowWarning("itemdb_search: Item ID %d does not exists in the item_db. Using dummy data.\n", key.i);
  230. return &dummy_item;
  231. }
  232. /*==========================================
  233. * Loads an item from the db. If not found, it will return the dummy item.
  234. *------------------------------------------
  235. */
  236. struct item_data* itemdb_search(int nameid)
  237. {
  238. return idb_ensure(item_db,nameid,return_dummy_data);
  239. }
  240. /*==========================================
  241. * Returns if given item is a player-equippable piece.
  242. *------------------------------------------
  243. */
  244. int itemdb_isequip(int nameid)
  245. {
  246. int type=itemdb_type(nameid);
  247. switch (type) {
  248. case IT_WEAPON:
  249. case IT_ARMOR:
  250. case IT_AMMO:
  251. return 1;
  252. default:
  253. return 0;
  254. }
  255. }
  256. /*==========================================
  257. * Alternate version of itemdb_isequip
  258. *------------------------------------------
  259. */
  260. int itemdb_isequip2(struct item_data *data)
  261. {
  262. nullpo_retr(0, data);
  263. switch(data->type) {
  264. case IT_WEAPON:
  265. case IT_ARMOR:
  266. case IT_AMMO:
  267. return 1;
  268. default:
  269. return 0;
  270. }
  271. }
  272. /*==========================================
  273. * Returns if given item's type is stackable.
  274. *------------------------------------------
  275. */
  276. int itemdb_isstackable(int nameid)
  277. {
  278. int type=itemdb_type(nameid);
  279. switch(type) {
  280. case IT_WEAPON:
  281. case IT_ARMOR:
  282. case IT_PETEGG:
  283. case IT_PETARMOR:
  284. return 0;
  285. default:
  286. return 1;
  287. }
  288. }
  289. /*==========================================
  290. * Alternate version of itemdb_isstackable
  291. *------------------------------------------
  292. */
  293. int itemdb_isstackable2(struct item_data *data)
  294. {
  295. nullpo_retr(0, data);
  296. switch(data->type) {
  297. case IT_WEAPON:
  298. case IT_ARMOR:
  299. case IT_PETEGG:
  300. case IT_PETARMOR:
  301. return 0;
  302. default:
  303. return 1;
  304. }
  305. }
  306. /*==========================================
  307. * Trade Restriction functions [Skotlex]
  308. *------------------------------------------
  309. */
  310. int itemdb_isdropable_sub(struct item_data *item, int gmlv, int unused)
  311. {
  312. return (item && (!(item->flag.trade_restriction&1) || gmlv >= item->gm_lv_trade_override));
  313. }
  314. int itemdb_cantrade_sub(struct item_data* item, int gmlv, int gmlv2)
  315. {
  316. return (item && (!(item->flag.trade_restriction&2) || gmlv >= item->gm_lv_trade_override || gmlv2 >= item->gm_lv_trade_override));
  317. }
  318. int itemdb_canpartnertrade_sub(struct item_data* item, int gmlv, int gmlv2)
  319. {
  320. return (item && (item->flag.trade_restriction&4 || gmlv >= item->gm_lv_trade_override || gmlv2 >= item->gm_lv_trade_override));
  321. }
  322. int itemdb_cansell_sub(struct item_data* item, int gmlv, int unused)
  323. {
  324. return (item && (!(item->flag.trade_restriction&8) || gmlv >= item->gm_lv_trade_override));
  325. }
  326. int itemdb_cancartstore_sub(struct item_data* item, int gmlv, int unused)
  327. {
  328. return (item && (!(item->flag.trade_restriction&16) || gmlv >= item->gm_lv_trade_override));
  329. }
  330. int itemdb_canstore_sub(struct item_data* item, int gmlv, int unused)
  331. {
  332. return (item && (!(item->flag.trade_restriction&32) || gmlv >= item->gm_lv_trade_override));
  333. }
  334. int itemdb_canguildstore_sub(struct item_data* item, int gmlv, int unused)
  335. {
  336. return (item && (!(item->flag.trade_restriction&64) || gmlv >= item->gm_lv_trade_override));
  337. }
  338. int itemdb_isrestricted(struct item* item, int gmlv, int gmlv2, int (*func)(struct item_data*, int, int))
  339. {
  340. struct item_data* item_data = itemdb_search(item->nameid);
  341. int i;
  342. if (!func(item_data, gmlv, gmlv2))
  343. return 0;
  344. if(item_data->slot == 0 || itemdb_isspecial(item->card[0]))
  345. return 1;
  346. for(i = 0; i < item_data->slot; i++) {
  347. if (!item->card[i]) continue;
  348. if (!func(itemdb_search(item->card[i]), gmlv, gmlv2))
  349. return 0;
  350. }
  351. return 1;
  352. }
  353. /*==========================================
  354. * Specifies if item-type should drop unidentified.
  355. *------------------------------------------
  356. */
  357. int itemdb_isidentified(int nameid)
  358. {
  359. int type=itemdb_type(nameid);
  360. switch (type) {
  361. case IT_WEAPON:
  362. case IT_ARMOR:
  363. case IT_PETARMOR:
  364. return 0;
  365. default:
  366. return 1;
  367. }
  368. }
  369. /*==========================================
  370. * アイテム使用可能フラグのオーバーライド
  371. *------------------------------------------
  372. */
  373. static int itemdb_read_itemavail (void)
  374. {
  375. FILE *fp;
  376. int nameid, j, k, ln = 0;
  377. char line[1024], *str[10], *p;
  378. struct item_data *id;
  379. sprintf(line, "%s/item_avail.txt", db_path);
  380. if ((fp = fopen(line,"r")) == NULL) {
  381. ShowError("can't read %s\n", line);
  382. return -1;
  383. }
  384. while (fgets(line, sizeof(line) - 1, fp)) {
  385. if (line[0] == '/' && line[1] == '/')
  386. continue;
  387. memset(str, 0, sizeof(str));
  388. for (j = 0, p = line; j < 2 && p; j++) {
  389. str[j] = p;
  390. p = strchr(p, ',');
  391. if(p) *p++ = 0;
  392. }
  393. if (j < 2 || str[0] == NULL ||
  394. (nameid = atoi(str[0])) < 0 || !(id = itemdb_exists(nameid)))
  395. continue;
  396. k = atoi(str[1]);
  397. if (k > 0) {
  398. id->flag.available = 1;
  399. id->view_id = k;
  400. } else
  401. id->flag.available = 0;
  402. ln++;
  403. }
  404. fclose(fp);
  405. ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", ln, "item_avail.txt");
  406. return 0;
  407. }
  408. /*==========================================
  409. * read item group data
  410. *------------------------------------------
  411. */
  412. static void itemdb_read_itemgroup_sub(const char* filename)
  413. {
  414. FILE *fp;
  415. char line[1024];
  416. int ln=0;
  417. int groupid,j,k,nameid;
  418. char *str[3],*p;
  419. char w1[1024], w2[1024];
  420. if( (fp=fopen(filename,"r"))==NULL ){
  421. ShowError("can't read %s\n", line);
  422. return;
  423. }
  424. while(fgets(line,1020,fp)){
  425. ln++;
  426. if(line[0]=='/' && line[1]=='/')
  427. continue;
  428. if(strstr(line,"import")) {
  429. if (sscanf(line, "%[^:]: %[^\r\n]", w1, w2) == 2 &&
  430. strcmpi(w1, "import") == 0) {
  431. itemdb_read_itemgroup_sub(w2);
  432. continue;
  433. }
  434. }
  435. memset(str,0,sizeof(str));
  436. for(j=0,p=line;j<3 && p;j++){
  437. str[j]=p;
  438. p=strchr(p,',');
  439. if(p) *p++=0;
  440. }
  441. if(str[0]==NULL)
  442. continue;
  443. if (j<3)
  444. continue;
  445. groupid = atoi(str[0]);
  446. if (groupid < 0 || groupid >= MAX_ITEMGROUP) {
  447. ShowWarning("itemdb_read_itemgroup: Invalid group %d in %s:%d\n", groupid, filename, ln);
  448. continue;
  449. }
  450. nameid = atoi(str[1]);
  451. if (!itemdb_exists(nameid)) {
  452. ShowWarning("itemdb_read_itemgroup: Non-existant item %d in %s:%d\n", nameid, filename, ln);
  453. continue;
  454. }
  455. k = atoi(str[2]);
  456. if (itemgroup_db[groupid].qty+k > MAX_RANDITEM) {
  457. ShowWarning("itemdb_read_itemgroup: Group %d is full (%d entries) in %s:%d\n", groupid, MAX_RANDITEM, filename, ln);
  458. continue;
  459. }
  460. for(j=0;j<k;j++)
  461. itemgroup_db[groupid].nameid[itemgroup_db[groupid].qty++] = nameid;
  462. }
  463. fclose(fp);
  464. return;
  465. }
  466. static void itemdb_read_itemgroup(void)
  467. {
  468. char path[256];
  469. int i;
  470. const char* groups[] = {
  471. "Blue Box",
  472. "Violet Box",
  473. "Card Album",
  474. "Gift Box",
  475. "Scroll Box",
  476. "Finding Ore",
  477. "Cookie Bag",
  478. "Potion",
  479. "Herbs",
  480. "Fruits",
  481. "Meat",
  482. "Candy",
  483. "Juice",
  484. "Fish",
  485. "Boxes",
  486. "Gemstone",
  487. "Jellopy",
  488. "Ore",
  489. "Food",
  490. "Recovery",
  491. "Minerals",
  492. "Taming",
  493. "Scrolls",
  494. "Quivers",
  495. "Masks",
  496. "Accesory",
  497. "Jewels",
  498. "Gift Box 1",
  499. "Gift Box 2",
  500. "Gift Box 3",
  501. "Gift Box 4",
  502. "Egg Boy",
  503. "Egg Girl",
  504. "Gift Box China",
  505. "Lotto Box",
  506. };
  507. memset(&itemgroup_db, 0, sizeof(itemgroup_db));
  508. snprintf(path, 255, "%s/item_group_db.txt", db_path);
  509. itemdb_read_itemgroup_sub(path);
  510. ShowStatus("Done reading '"CL_WHITE"%s"CL_RESET"'.\n","item_group_db.txt");
  511. if (battle_config.etc_log) {
  512. for (i = 1; i < MAX_ITEMGROUP; i++)
  513. ShowInfo("Group %s: %d entries.\n", groups[i-1], itemgroup_db[i].qty);
  514. }
  515. return;
  516. }
  517. /*==========================================
  518. * アイテムの名前テーブルを読み込む
  519. *------------------------------------------
  520. */
  521. static int itemdb_read_itemnametable(void)
  522. {
  523. char *buf,*p;
  524. int s;
  525. buf=(char *) grfio_reads("data\\idnum2itemdisplaynametable.txt",&s);
  526. if(buf==NULL)
  527. return -1;
  528. buf[s]=0;
  529. for(p=buf;p-buf<s;){
  530. int nameid;
  531. char buf2[64]; //Why 64? What's this for, other than holding an item's name? [Skotlex]
  532. if( sscanf(p,"%d#%[^#]#",&nameid,buf2)==2 ){
  533. #ifdef ITEMDB_OVERRIDE_NAME_VERBOSE
  534. if( itemdb_exists(nameid) &&
  535. strncmp(itemdb_search(nameid)->jname,buf2,ITEM_NAME_LENGTH)!=0 ){
  536. ShowNotice("[override] %d %s => %s\n",nameid
  537. ,itemdb_search(nameid)->jname,buf2);
  538. }
  539. #endif
  540. strncpy(itemdb_search(nameid)->jname,buf2,ITEM_NAME_LENGTH-1);
  541. }
  542. p=strchr(p,10);
  543. if(!p) break;
  544. p++;
  545. }
  546. aFree(buf);
  547. ShowStatus("Done reading '"CL_WHITE"%s"CL_RESET"'.\n","data\\idnum2itemdisplaynametable.txt");
  548. return 0;
  549. }
  550. /*==========================================
  551. * カードイラストのリソース名前テーブルを読み込む
  552. *------------------------------------------
  553. */
  554. static int itemdb_read_cardillustnametable(void)
  555. {
  556. char *buf,*p;
  557. int s;
  558. buf=(char *) grfio_reads("data\\num2cardillustnametable.txt",&s);
  559. if(buf==NULL)
  560. return -1;
  561. buf[s]=0;
  562. for(p=buf;p-buf<s;){
  563. int nameid;
  564. char buf2[64];
  565. if( sscanf(p,"%d#%[^#]#",&nameid,buf2)==2 ){
  566. strcat(buf2,".bmp");
  567. memcpy(itemdb_search(nameid)->cardillustname,buf2,64);
  568. }
  569. p=strchr(p,10);
  570. if(!p) break;
  571. p++;
  572. }
  573. aFree(buf);
  574. ShowStatus("Done reading '"CL_WHITE"%s"CL_RESET"'.\n","data\\num2cardillustnametable.txt");
  575. return 0;
  576. }
  577. //
  578. // 初期化
  579. //
  580. /*==========================================
  581. *
  582. *------------------------------------------
  583. */
  584. static int itemdb_read_itemslottable(void)
  585. {
  586. char *buf, *p;
  587. int s;
  588. buf = (char *)grfio_reads("data\\itemslottable.txt", &s);
  589. if (buf == NULL)
  590. return -1;
  591. buf[s] = 0;
  592. for (p = buf; p - buf < s; ) {
  593. int nameid, equip;
  594. struct item_data* item;
  595. sscanf(p, "%d#%d#", &nameid, &equip);
  596. item = itemdb_search(nameid);
  597. if (equip && item && itemdb_isequip2(item))
  598. item->equip = equip;
  599. p = strchr(p, 10);
  600. if(!p) break;
  601. p++;
  602. p=strchr(p, 10);
  603. if(!p) break;
  604. p++;
  605. }
  606. aFree(buf);
  607. ShowStatus("Done reading '"CL_WHITE"%s"CL_RESET"'.\n","data\\itemslottable.txt");
  608. return 0;
  609. }
  610. /*==========================================
  611. *
  612. *------------------------------------------
  613. */
  614. static int itemdb_read_itemslotcounttable(void)
  615. {
  616. char *buf, *p;
  617. int s;
  618. buf = (char *)grfio_reads("data\\itemslotcounttable.txt", &s);
  619. if (buf == NULL)
  620. return -1;
  621. buf[s] = 0;
  622. for (p = buf; p - buf < s;){
  623. int nameid, slot;
  624. sscanf(p, "%d#%d#", &nameid, &slot);
  625. if (slot > MAX_SLOTS)
  626. {
  627. ShowWarning("itemdb_read_itemslotcounttable: Item %d specifies %d slots, but the server only supports up to %d\n", nameid, slot, MAX_SLOTS);
  628. slot = MAX_SLOTS;
  629. }
  630. itemdb_slot(nameid) = slot;
  631. p = strchr(p,10);
  632. if(!p) break;
  633. p++;
  634. p = strchr(p,10);
  635. if(!p) break;
  636. p++;
  637. }
  638. aFree(buf);
  639. ShowStatus("Done reading '"CL_WHITE"%s"CL_RESET"'.\n", "data\\itemslotcounttable.txt");
  640. return 0;
  641. }
  642. /*==========================================
  643. * 装備制限ファイル読み出し
  644. *------------------------------------------
  645. */
  646. static int itemdb_read_noequip(void)
  647. {
  648. FILE *fp;
  649. char line[1024];
  650. int ln=0;
  651. int nameid,j;
  652. char *str[32],*p;
  653. struct item_data *id;
  654. sprintf(line, "%s/item_noequip.txt", db_path);
  655. if( (fp=fopen(line,"r"))==NULL ){
  656. ShowError("can't read %s\n", line);
  657. return -1;
  658. }
  659. while(fgets(line,1020,fp)){
  660. if(line[0]=='/' && line[1]=='/')
  661. continue;
  662. memset(str,0,sizeof(str));
  663. for(j=0,p=line;j<2 && p;j++){
  664. str[j]=p;
  665. p=strchr(p,',');
  666. if(p) *p++=0;
  667. }
  668. if(str[0]==NULL)
  669. continue;
  670. nameid=atoi(str[0]);
  671. if(nameid<=0 || !(id=itemdb_exists(nameid)))
  672. continue;
  673. id->flag.no_equip=atoi(str[1]);
  674. ln++;
  675. }
  676. fclose(fp);
  677. if (ln > 0) {
  678. ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n",ln,"item_noequip.txt");
  679. }
  680. return 0;
  681. }
  682. /*==========================================
  683. * Reads item trade restrictions [Skotlex]
  684. *------------------------------------------
  685. */
  686. static int itemdb_read_itemtrade(void)
  687. {
  688. FILE *fp;
  689. int nameid, j, flag, gmlv, ln = 0;
  690. char line[1024], *str[10], *p;
  691. struct item_data *id;
  692. sprintf(line, "%s/item_trade.txt", db_path);
  693. if ((fp = fopen(line,"r")) == NULL) {
  694. ShowError("can't read %s\n", line);
  695. return -1;
  696. }
  697. while (fgets(line, sizeof(line) - 1, fp)) {
  698. if (line[0] == '/' && line[1] == '/')
  699. continue;
  700. memset(str, 0, sizeof(str));
  701. for (j = 0, p = line; j < 3 && p; j++) {
  702. str[j] = p;
  703. p = strchr(p, ',');
  704. if(p) *p++ = 0;
  705. }
  706. if (j < 3 || str[0] == NULL ||
  707. (nameid = atoi(str[0])) < 0 || !(id = itemdb_exists(nameid)))
  708. continue;
  709. flag = atoi(str[1]);
  710. gmlv = atoi(str[2]);
  711. if (flag > 0 && flag < 128 && gmlv > 0) { //Check range
  712. id->flag.trade_restriction = flag;
  713. id->gm_lv_trade_override = gmlv;
  714. ln++;
  715. }
  716. }
  717. fclose(fp);
  718. ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", ln, "item_trade.txt");
  719. return 0;
  720. }
  721. /*======================================
  722. * Applies gender restrictions according to settings. [Skotlex]
  723. *======================================
  724. */
  725. static int itemdb_gendercheck(struct item_data *id)
  726. {
  727. if (id->nameid == WEDDING_RING_M) //Grom Ring
  728. return 1;
  729. if (id->nameid == WEDDING_RING_F) //Bride Ring
  730. return 0;
  731. if (id->look == W_MUSICAL && id->type == IT_WEAPON) //Musical instruments are always male-only
  732. return 1;
  733. if (id->look == W_WHIP && id->type == IT_WEAPON) //Whips are always female-only
  734. return 0;
  735. return (battle_config.ignore_items_gender?2:id->sex);
  736. }
  737. #ifndef TXT_ONLY
  738. /*======================================
  739. * SQL
  740. *===================================
  741. */
  742. static int itemdb_read_sqldb(void)
  743. {
  744. unsigned short nameid;
  745. struct item_data *id;
  746. char script[65535 + 2 + 1]; // Maximum length of MySQL TEXT type (65535) + 2 bytes for curly brackets + 1 byte for terminator
  747. char *item_db_name[] = { item_db_db, item_db2_db };
  748. long unsigned int ln = 0;
  749. int i;
  750. // ----------
  751. for (i = 0; i < 2; i++) {
  752. sprintf(tmp_sql, "SELECT * FROM `%s`", item_db_name[i]);
  753. // Execute the query; if the query execution succeeded...
  754. if (mysql_query(&mmysql_handle, tmp_sql) == 0) {
  755. sql_res = mysql_store_result(&mmysql_handle);
  756. // If the storage of the query result succeeded...
  757. if (sql_res) {
  758. // Parse each row in the query result into sql_row
  759. while ((sql_row = mysql_fetch_row(sql_res)))
  760. { /*Table structure is:
  761. 00 id
  762. 01 name_english
  763. 02 name_japanese
  764. 03 type
  765. 04 price_buy
  766. 05 price_sell
  767. 06 weight
  768. 07 attack
  769. 08 defence
  770. 09 range
  771. 10 slots
  772. 11 equip_jobs
  773. 12 equip_upper
  774. 13 equip_genders
  775. 14 equip_locations
  776. 15 weapon_level
  777. 16 equip_level
  778. 17 refineable
  779. 18 view
  780. 19 script
  781. 20 equip_script
  782. 21 unequip_script
  783. */
  784. nameid = atoi(sql_row[0]);
  785. // If the identifier is not within the valid range, process the next row
  786. if (nameid == 0)
  787. continue;
  788. ln++;
  789. // ----------
  790. id = itemdb_load(nameid);
  791. strncpy(id->name, sql_row[1], ITEM_NAME_LENGTH-1);
  792. strncpy(id->jname, sql_row[2], ITEM_NAME_LENGTH-1);
  793. id->type = atoi(sql_row[3]);
  794. if (id->type == IT_DELAYCONSUME)
  795. { //Items that are consumed upon target confirmation
  796. //(yggdrasil leaf, spells & pet lures) [Skotlex]
  797. id->type = IT_USABLE;
  798. id->flag.delay_consume=1;
  799. }
  800. // If price_buy is not NULL and price_sell is not NULL...
  801. if ((sql_row[4] != NULL) && (sql_row[5] != NULL)) {
  802. id->value_buy = atoi(sql_row[4]);
  803. id->value_sell = atoi(sql_row[5]);
  804. }
  805. // If price_buy is not NULL and price_sell is NULL...
  806. else if ((sql_row[4] != NULL) && (sql_row[5] == NULL)) {
  807. id->value_buy = atoi(sql_row[4]);
  808. id->value_sell = atoi(sql_row[4]) / 2;
  809. }
  810. // If price_buy is NULL and price_sell is not NULL...
  811. else if ((sql_row[4] == NULL) && (sql_row[5] != NULL)) {
  812. id->value_buy = atoi(sql_row[5]) * 2;
  813. id->value_sell = atoi(sql_row[5]);
  814. }
  815. // If price_buy is NULL and price_sell is NULL...
  816. if ((sql_row[4] == NULL) && (sql_row[5] == NULL)) {
  817. id->value_buy = 0;
  818. id->value_sell = 0;
  819. }
  820. id->weight = atoi(sql_row[6]);
  821. id->atk = (sql_row[7] != NULL) ? atoi(sql_row[7]) : 0;
  822. id->def = (sql_row[8] != NULL) ? atoi(sql_row[8]) : 0;
  823. id->range = (sql_row[9] != NULL) ? atoi(sql_row[9]) : 0;
  824. id->slot = (sql_row[10] != NULL) ? atoi(sql_row[10]) : 0;
  825. if (id->slot > MAX_SLOTS)
  826. {
  827. ShowWarning("itemdb_read_sqldb: Item %d (%s) specifies %d slots, but the server only supports up to %d\n", nameid, id->jname, id->slot, MAX_SLOTS);
  828. id->slot = MAX_SLOTS;
  829. }
  830. itemdb_jobid2mapid(id->class_base, (sql_row[11] != NULL) ? (unsigned int)strtoul(sql_row[11], NULL, 0) : 0);
  831. id->class_upper= (sql_row[12] != NULL) ? atoi(sql_row[12]) : 0;
  832. id->sex = (sql_row[13] != NULL) ? atoi(sql_row[13]) : 0;
  833. id->equip = (sql_row[14] != NULL) ? atoi(sql_row[14]) : 0;
  834. if (!id->equip && itemdb_isequip2(id))
  835. {
  836. ShowWarning("Item %d (%s) is an equipment with no equip-field! Making it an etc item.\n", nameid, id->jname);
  837. id->type = 3;
  838. }
  839. id->wlv = (sql_row[15] != NULL) ? atoi(sql_row[15]) : 0;
  840. id->elv = (sql_row[16] != NULL) ? atoi(sql_row[16]) : 0;
  841. id->flag.no_refine = (sql_row[17] == NULL || atoi(sql_row[17]) == 1)?0:1;
  842. id->look = (sql_row[18] != NULL) ? atoi(sql_row[18]) : 0;
  843. id->view_id = 0;
  844. id->sex = itemdb_gendercheck(id); //Apply gender filtering.
  845. // ----------
  846. if (id->script)
  847. script_free_code(id->script);
  848. if (sql_row[19] != NULL) {
  849. if (sql_row[19][0] == '{')
  850. id->script = parse_script((unsigned char *) sql_row[19],item_db_name[i], 0);
  851. else {
  852. sprintf(script, "{%s}", sql_row[19]);
  853. id->script = parse_script((unsigned char *) script, item_db_name[i], 0);
  854. }
  855. } else id->script = NULL;
  856. if (id->equip_script)
  857. script_free_code(id->equip_script);
  858. if (sql_row[20] != NULL) {
  859. if (sql_row[20][0] == '{')
  860. id->equip_script = parse_script((unsigned char *) sql_row[20], item_db_name[i], 0);
  861. else {
  862. sprintf(script, "{%s}", sql_row[20]);
  863. id->equip_script = parse_script((unsigned char *) script, item_db_name[i], 0);
  864. }
  865. } else id->equip_script = NULL;
  866. if (id->unequip_script)
  867. script_free_code(id->unequip_script);
  868. if (sql_row[21] != NULL) {
  869. if (sql_row[21][0] == '{')
  870. id->unequip_script = parse_script((unsigned char *) sql_row[21],item_db_name[i], 0);
  871. else {
  872. sprintf(script, "{%s}", sql_row[21]);
  873. id->unequip_script = parse_script((unsigned char *) script, item_db_name[i], 0);
  874. }
  875. } else id->unequip_script = NULL;
  876. // ----------
  877. id->flag.available = 1;
  878. id->flag.value_notdc = 0;
  879. id->flag.value_notoc = 0;
  880. }
  881. ShowStatus("Done reading '"CL_WHITE"%lu"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", ln, item_db_name[i]);
  882. ln = 0;
  883. } else {
  884. ShowSQL("DB error (%s) - %s\n",item_db_name[i], mysql_error(&mmysql_handle));
  885. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  886. }
  887. // Free the query result
  888. mysql_free_result(sql_res);
  889. } else {
  890. ShowSQL("DB error (%s) - %s\n",item_db_name[i], mysql_error(&mmysql_handle));
  891. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  892. }
  893. }
  894. return 0;
  895. }
  896. #endif /* not TXT_ONLY */
  897. /*==========================================
  898. * アイテムデータベースの読み込み
  899. *------------------------------------------
  900. */
  901. static int itemdb_readdb(void)
  902. {
  903. FILE *fp;
  904. char line[1024];
  905. int ln=0,lines=0;
  906. int nameid,j;
  907. char *str[32],*p,*np;
  908. struct item_data *id;
  909. int i=0;
  910. char *filename[]={ "item_db.txt","item_db2.txt" };
  911. for(i=0;i<2;i++){
  912. sprintf(line, "%s/%s", db_path, filename[i]);
  913. fp=fopen(line,"r");
  914. if(fp==NULL){
  915. if(i>0)
  916. continue;
  917. ShowFatalError("can't read %s\n",line);
  918. exit(1);
  919. }
  920. lines=0;
  921. while(fgets(line,1020,fp)){
  922. lines++;
  923. if(line[0]=='/' && line[1]=='/')
  924. continue;
  925. memset(str,0,sizeof(str));
  926. for(j=0,np=p=line;j<19 && p;j++){
  927. str[j]=p;
  928. p=strchr(p,',');
  929. if(p){ *p++=0; np=p; }
  930. }
  931. if(str[0]==NULL)
  932. continue;
  933. nameid=atoi(str[0]);
  934. if(nameid<=0)
  935. continue;
  936. if (j < 19)
  937. { //Crash-fix on broken item lines. [Skotlex]
  938. ShowWarning("Reading %s: Insufficient fields for item with id %d, skipping.\n", filename[i], nameid);
  939. continue;
  940. }
  941. ln++;
  942. //ID,Name,Jname,Type,Price,Sell,Weight,ATK,DEF,Range,Slot,Job,Job Upper,Gender,Loc,wLV,eLV,refineable,View
  943. id=itemdb_load(nameid);
  944. strncpy(id->name, str[1], ITEM_NAME_LENGTH-1);
  945. strncpy(id->jname, str[2], ITEM_NAME_LENGTH-1);
  946. id->type=atoi(str[3]);
  947. if (id->type == IT_DELAYCONSUME)
  948. { //Items that are consumed upon target confirmation
  949. //(yggdrasil leaf, spells & pet lures) [Skotlex]
  950. id->type = IT_USABLE;
  951. id->flag.delay_consume=1;
  952. }
  953. {
  954. int buy = atoi(str[4]), sell = atoi(str[5]);
  955. // if buying price > selling price * 2 consider it valid and don't change it [celest]
  956. if (buy && sell && buy > sell*2){
  957. id->value_buy = buy;
  958. id->value_sell = sell;
  959. } else {
  960. // buy≠sell*2 は item_value_db.txt で指定してください。
  961. if (sell) { // sell値を優先とする
  962. id->value_buy = sell*2;
  963. id->value_sell = sell;
  964. } else {
  965. id->value_buy = buy;
  966. id->value_sell = buy/2;
  967. }
  968. }
  969. // check for bad prices that can possibly cause exploits
  970. if (id->value_buy*75/100 < id->value_sell*124/100) {
  971. ShowWarning ("Item %s [%d] buying:%d < selling:%d\n",
  972. id->name, id->nameid, id->value_buy*75/100, id->value_sell*124/100);
  973. }
  974. }
  975. id->weight=atoi(str[6]);
  976. id->atk=atoi(str[7]);
  977. id->def=atoi(str[8]);
  978. id->range=atoi(str[9]);
  979. id->slot=atoi(str[10]);
  980. if (id->slot > MAX_SLOTS)
  981. {
  982. ShowWarning("itemdb_readdb: Item %d (%s) specifies %d slots, but the server only supports up to %d\n", nameid, id->jname, id->slot, MAX_SLOTS);
  983. id->slot = MAX_SLOTS;
  984. }
  985. itemdb_jobid2mapid(id->class_base, (unsigned int)strtoul(str[11],NULL,0));
  986. id->class_upper = atoi(str[12]);
  987. id->sex = atoi(str[13]);
  988. if(id->equip != atoi(str[14])){
  989. id->equip=atoi(str[14]);
  990. }
  991. if (!id->equip && itemdb_isequip2(id))
  992. {
  993. ShowWarning("Item %d (%s) is an equipment with no equip-field! Making it an etc item.\n", nameid, id->jname);
  994. id->type = 3;
  995. }
  996. id->wlv=atoi(str[15]);
  997. id->elv=atoi(str[16]);
  998. id->flag.no_refine = atoi(str[17])?0:1; //If the refine column is 1, no_refine is 0
  999. id->look=atoi(str[18]);
  1000. id->flag.available=1;
  1001. id->flag.value_notdc=0;
  1002. id->flag.value_notoc=0;
  1003. id->view_id=0;
  1004. id->sex = itemdb_gendercheck(id); //Apply gender filtering.
  1005. if (id->script) {
  1006. script_free_code(id->script);
  1007. id->script=NULL;
  1008. }
  1009. if (id->equip_script) {
  1010. script_free_code(id->equip_script);
  1011. id->equip_script=NULL;
  1012. }
  1013. if (id->unequip_script) {
  1014. script_free_code(id->unequip_script);
  1015. id->unequip_script=NULL;
  1016. }
  1017. if((p=strchr(np,'{'))==NULL)
  1018. continue;
  1019. str[19] = p; //Script
  1020. np = strchr(p,'}');
  1021. while (np && np[1] && np[1] != ',')
  1022. np = strchr(np+1,'}'); //Jump close brackets until the next field is found.
  1023. if (!np || !np[1]) {
  1024. //Couldn't find the end of the script field.
  1025. id->script = parse_script((unsigned char *) str[19],filename[i],lines);
  1026. continue;
  1027. }
  1028. np[1] = '\0'; //Set end of script
  1029. id->script = parse_script((unsigned char *) str[19],filename[i],lines);
  1030. np+=2; //Skip to next field
  1031. if(!np || (p=strchr(np,'{'))==NULL)
  1032. continue;
  1033. str[20] = p; //Equip Script
  1034. np = strchr(p,'}');
  1035. while (np && np[1] && np[1] != ',')
  1036. np = strchr(np+1,'}'); //Jump close brackets until the next field is found.
  1037. if (!np || !np[1]) {
  1038. //Couldn't find the end of the script field.
  1039. id->equip_script = parse_script((unsigned char *) str[20],filename[i],lines);
  1040. continue;
  1041. }
  1042. np[1] = '\0'; //Set end of script
  1043. id->equip_script = parse_script((unsigned char *) str[20],filename[i],lines);
  1044. np+=2; //Skip comma, to next field
  1045. if(!np || (p=strchr(np,'{'))==NULL)
  1046. continue;
  1047. //Unequip script, last column.
  1048. id->unequip_script = parse_script((unsigned char *) p,filename[i],lines);
  1049. }
  1050. fclose(fp);
  1051. if (ln > 0) {
  1052. ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n",ln,filename[i]);
  1053. }
  1054. ln=0; // reset to 0
  1055. }
  1056. return 0;
  1057. }
  1058. /*====================================
  1059. * Removed item_value_db, don't re-add
  1060. *------------------------------------
  1061. */
  1062. static void itemdb_read(void)
  1063. {
  1064. #ifndef TXT_ONLY
  1065. if (db_use_sqldbs)
  1066. itemdb_read_sqldb();
  1067. else
  1068. #endif
  1069. itemdb_readdb();
  1070. itemdb_read_itemgroup();
  1071. itemdb_read_itemavail();
  1072. itemdb_read_noequip();
  1073. itemdb_read_itemtrade();
  1074. if (battle_config.cardillust_read_grffile)
  1075. itemdb_read_cardillustnametable();
  1076. if (battle_config.item_equip_override_grffile)
  1077. itemdb_read_itemslottable();
  1078. if (battle_config.item_slots_override_grffile)
  1079. itemdb_read_itemslotcounttable();
  1080. if (battle_config.item_name_override_grffile)
  1081. itemdb_read_itemnametable();
  1082. }
  1083. /*==========================================
  1084. * Initialize / Finalize
  1085. *------------------------------------------
  1086. */
  1087. static int itemdb_final_sub (DBKey key,void *data,va_list ap)
  1088. {
  1089. int flag;
  1090. struct item_data *id = (struct item_data *)data;
  1091. flag = va_arg(ap, int);
  1092. if (id->script)
  1093. {
  1094. script_free_code(id->script);
  1095. id->script = NULL;
  1096. }
  1097. if (id->equip_script)
  1098. {
  1099. script_free_code(id->equip_script);
  1100. id->equip_script = NULL;
  1101. }
  1102. if (id->unequip_script)
  1103. {
  1104. script_free_code(id->unequip_script);
  1105. id->unequip_script = NULL;
  1106. }
  1107. // Whether to clear the item data (exception: do not clear the dummy item data
  1108. if (flag && id != &dummy_item)
  1109. aFree(id);
  1110. return 0;
  1111. }
  1112. void itemdb_reload(void)
  1113. {
  1114. //Just read, the function takes care of freeing scripts.
  1115. itemdb_read();
  1116. }
  1117. void do_final_itemdb(void)
  1118. {
  1119. item_db->destroy(item_db, itemdb_final_sub, 1);
  1120. if (dummy_item.script) {
  1121. script_free_code(dummy_item.script);
  1122. dummy_item.script = NULL;
  1123. }
  1124. if (dummy_item.equip_script) {
  1125. script_free_code(dummy_item.equip_script);
  1126. dummy_item.equip_script = NULL;
  1127. }
  1128. if (dummy_item.unequip_script) {
  1129. script_free_code(dummy_item.unequip_script);
  1130. dummy_item.unequip_script = NULL;
  1131. }
  1132. }
  1133. int do_init_itemdb(void)
  1134. {
  1135. item_db = db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_BASE,sizeof(int));
  1136. create_dummy_data(); //Dummy data item.
  1137. itemdb_read();
  1138. return 0;
  1139. }