From af99be9bd11d716e0b8ef8eab4a36c9b9925e4c8 Mon Sep 17 00:00:00 2001 From: ultramage Date: Sun, 27 Apr 2008 11:06:55 +0000 Subject: Cleaning up the itemdb reload mess (see r12635, r12643, r12650, r12661, r12662, r12663) * the player data inventory-itemdb index is now refreshed using pc_setinventorydata() * mobdb will no longer initialize with nonexistent items, and mobs will no longer drop them in case of a reload * the clif_buylist() function once again hides invalid npc shop items * it is no longer possible to purchase nonexistent items from a npc shop * npc shop loading will not abort if there is a nonexistent item entry, it will just skip over it git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@12665 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/map/itemdb.c | 172 +++++++------------------------------------------------ 1 file changed, 20 insertions(+), 152 deletions(-) (limited to 'src/map/itemdb.c') diff --git a/src/map/itemdb.c b/src/map/itemdb.c index 979ba4a39..3bcd07cf1 100644 --- a/src/map/itemdb.c +++ b/src/map/itemdb.c @@ -10,10 +10,6 @@ #include "battle.h" // struct battle_config #include "script.h" // item script processing #include "pc.h" // W_MUSICAL, W_WHIP -#include "storage.h" -#include "npc.h" -#include "clif.h" -#include "mob.h" #include #include @@ -693,7 +689,7 @@ static int itemdb_gendercheck(struct item_data *id) /*========================================== * processes one itemdb entry *------------------------------------------*/ -static bool itemdb_parse_dbrow(char** str, const char* source, int line, int scriptopt, int db) +static bool itemdb_parse_dbrow(char** str, const char* source, int line, int scriptopt) { /* +----+--------------+---------------+------+-----------+------------+--------+--------+---------+-------+-------+------------+-------------+---------------+-----------------+--------------+-------------+------------+------+--------+--------------+----------------+ @@ -717,9 +713,6 @@ static bool itemdb_parse_dbrow(char** str, const char* source, int line, int scr safestrncpy(id->name, str[1], sizeof(id->name)); safestrncpy(id->jname, str[2], sizeof(id->jname)); - if(db == 1) - id->flag.db2 = 1; - id->type = atoi(str[3]); if (id->type == IT_DELAYCONSUME) { //Items that are consumed only after target confirmation @@ -907,7 +900,8 @@ static int itemdb_readdb(void) } str[21] = p; - if (!itemdb_parse_dbrow(str, path, lines, 0, fi)) + + if (!itemdb_parse_dbrow(str, path, lines, 0)) continue; count++; @@ -954,7 +948,7 @@ static int itemdb_read_sqldb(void) if( str[i] == NULL ) str[i] = dummy; // get rid of NULL columns } - if (!itemdb_parse_dbrow(str, item_db_name[fi], lines, SCRIPT_IGNORE_EXTERNAL_BRACKETS, fi)) + if (!itemdb_parse_dbrow(str, item_db_name[fi], lines, SCRIPT_IGNORE_EXTERNAL_BRACKETS)) continue; ++count; } @@ -1012,13 +1006,6 @@ static void destroy_item_data(struct item_data* self, int free_self) aFree(self); } -/*========================================== - * This comment shall be a monument to cake. - * The cake is NOT a lie in eAthena. - * We are so awesome we have our own cake. - * Please spam Cyxult with endless PMs to get your cake. - *------------------------------------------*/ - static int itemdb_final_sub(DBKey key,void *data,va_list ap) { struct item_data *id = (struct item_data *)data; @@ -1029,149 +1016,30 @@ static int itemdb_final_sub(DBKey key,void *data,va_list ap) return 0; } -//Uncomment this if you're an elitist jerk who thinks this code is unecessary -//#define I_HATE_KEVIN -#ifndef I_HATE_KEVIN -int itemdb_reload_check_npc(DBKey key,void * data,va_list ap) +void itemdb_reload(void) { - struct npc_data * nd = (struct npc_data *)data; - int offset = 0, i = 0; - - if(nd->subtype != SHOP && nd->subtype != CASHSHOP) - return 0; - - while(i < nd->u.shop.count) - { - - if(itemdb_exists(nd->u.shop.shop_item[i].nameid) == NULL) - { - - nd->u.shop.count--; - - //Shift array to left, overwriting old data - for(offset = i; offset+1 < nd->u.shop.count; offset++); - { - nd->u.shop.shop_item[offset].nameid = nd->u.shop.shop_item[offset+1].nameid; - nd->u.shop.shop_item[offset].value = nd->u.shop.shop_item[offset+1].value; - } - - } - //increment counter if we didn't delete something - else - i++; - - } - - //Resize array - RECREATE(nd->u.shop.shop_item, struct npc_item_list, nd->u.shop.count); - - return 0; -} + struct s_mapiterator* iter; + struct map_session_data* sd; -static int itemdb_reload_check(DBKey key,void *data,va_list ap) -{ int i; - struct map_session_data *sd = (struct map_session_data *)data; - struct storage * stor; - struct item_data * id; - struct npc_data * nd; - - if(sd->npc_shopid) - { - nd = (struct npc_data*)map_id2bl(sd->npc_shopid); - clif_buylist(sd, nd); - } - - //First, handle all items in inventories/equiped, cart, and storage - for(i = 0; i < MAX_INVENTORY; i++) - { - if(!sd->status.inventory[i].nameid) - continue; - - id = itemdb_exists(sd->status.inventory[i].nameid); - if(id == NULL) - { - sd->inventory_data[i] = NULL; - pc_delitem(sd, i, sd->status.inventory[i].amount, 4); - } - else - { - sd->inventory_data[i] = id; - } - } - //Delete nonexistant items from cart - for(i = 0; i < MAX_CART; i++) - { - if(!sd->status.cart[i].nameid) - continue; - - id = itemdb_exists(sd->status.cart[i].nameid); - if(id == NULL) - { - sd->inventory_data[i] = NULL; - pc_cart_delitem(sd, i, sd->status.cart[i].amount, 0); - } - } - - //Delete storage - if((stor = account2storage2(sd->status.account_id))) - { - //If storage isn't found, it will be deleted whenever storage is loaded again - if(stor) - { - for(i = 0; i < MAX_STORAGE; i++) - { - if(!sd->status.inventory[i].nameid) - continue; - - if(itemdb_exists(sd->status.inventory[i].nameid) == NULL) - storage_delitem(sd, stor, i, stor->storage_[i].amount); - } - } - } - - return 0; -} - -//Cleanup mob db drop tables -void itemdb_foreach_mobdb(void) -{ - int i = 0, j = 0; - struct item_data * id; - s_mob_db * mdb; + // clear the previous itemdb data + for( i = 0; i < ARRAYLENGTH(itemdb_array); ++i ) + if( itemdb_array[i] ) + destroy_item_data(itemdb_array[i], 1); - for(i=0; i < MAX_MOB_DB; i++) - { - mdb = mob_db(i); - if(mdb == mob_dummy) - continue; - for(j=0; j < MAX_MOB_DROP; j++) - { - id = itemdb_exists(mdb->dropitem[j].nameid); - if(id == NULL) - { - mdb->dropitem[j].nameid = 0; - mdb->dropitem[j].p = 0; - } - } - } -} -#endif + itemdb_other->clear(itemdb_other, itemdb_final_sub); -void itemdb_reload(int flag) -{ + memset(itemdb_array, 0, sizeof(itemdb_array)); - do_final_itemdb(); - do_init_itemdb(); + // read new data + itemdb_read(); - if(flag) - { - //Update ALL items on the server - map_foreachpc(itemdb_reload_check); - npc_foreach(itemdb_reload_check_npc); - itemdb_foreach_mobdb(); - } + // readjust itemdb pointer cache for each player + iter = mapit_geteachpc(); + for( sd = (struct map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (struct map_session_data*)mapit_next(iter) ) + pc_setinventorydata(sd); + mapit_free(iter); } void do_final_itemdb(void) -- cgit v1.2.3-60-g2f50