From f63b6a94ea8e3a8ad877ad401c6aff1eb4e1d45d Mon Sep 17 00:00:00 2001 From: shennetsind Date: Sat, 28 Sep 2013 12:25:07 -0300 Subject: HPM: Storage.c Completed Moved missing declarations of interest into the interface, init/final from storage into gstorage Signed-off-by: shennetsind --- src/map/map.c | 4 ++-- src/map/storage.c | 47 +++++++++++++++++++++++------------------------ src/map/storage.h | 10 ++++++++-- 3 files changed, 33 insertions(+), 28 deletions(-) (limited to 'src/map') diff --git a/src/map/map.c b/src/map/map.c index 8641f7011..5d58fd30e 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -4905,7 +4905,7 @@ void do_final(void) script->final(); itemdb->final(); instance->final(); - storage->final(); + gstorage->final(); guild->final(); party->do_final_party(); pc->do_final_pc(); @@ -5389,7 +5389,7 @@ int do_init(int argc, char *argv[]) status->init(); party->do_init_party(); guild->init(); - storage->init(); + gstorage->init(); pet->init(); homun->init(); mercenary->init(); diff --git a/src/map/storage.c b/src/map/storage.c index 041c2cd72..91515dfe1 100644 --- a/src/map/storage.c +++ b/src/map/storage.c @@ -30,7 +30,7 @@ struct guild_storage_interface gstorage_s; /*========================================== * Sort items in the warehouse *------------------------------------------*/ -static int storage_comp_item(const void *_i1, const void *_i2) +int storage_comp_item(const void *_i1, const void *_i2) { struct item *i1 = (struct item *)_i1; struct item *i2 = (struct item *)_i2; @@ -45,33 +45,21 @@ static int storage_comp_item(const void *_i1, const void *_i2) } //Sort item by storage_comp_item (nameid) -static void storage_sortitem(struct item* items, unsigned int size) +void storage_sortitem(struct item* items, unsigned int size) { nullpo_retv(items); if( battle_config.client_sort_storage ) { - qsort(items, size, sizeof(struct item), storage_comp_item); + qsort(items, size, sizeof(struct item), storage->comp_item); } } -/*========================================== - * Init/Terminate - *------------------------------------------*/ -/* ##TODO not really init_storage but init_gstorage, should rename/move */ -int do_init_storage(void) { // Called from map.c::do_init() - gstorage->db = idb_alloc(DB_OPT_RELEASE_DATA); - return 1; -} -void do_final_storage(void) { // by [MC Cameri] - gstorage->db->destroy(gstorage->db,NULL); -} - /** * Parses storage and saves 'dirty' ones upon reconnect. [Skotlex] * @see DBApply */ -static int storage_reconnect_sub(DBKey key, DBData *data, va_list ap) +int storage_reconnect_sub(DBKey key, DBData *data, va_list ap) { struct guild_storage *stor = DB->data2ptr(data); if (stor->dirty && stor->storage_status == 0) //Save closed storages. @@ -82,7 +70,7 @@ static int storage_reconnect_sub(DBKey key, DBData *data, va_list ap) //Function to be invoked upon server reconnection to char. To save all 'dirty' storages [Skotlex] void do_reconnect_storage(void) { - gstorage->db->foreach(gstorage->db, storage_reconnect_sub); + gstorage->db->foreach(gstorage->db, storage->reconnect_sub); } /*========================================== @@ -104,7 +92,7 @@ int storage_storageopen(struct map_session_data *sd) } sd->state.storage_flag = 1; - storage_sortitem(sd->status.storage.items, ARRAYLENGTH(sd->status.storage.items)); + storage->sortitem(sd->status.storage.items, ARRAYLENGTH(sd->status.storage.items)); clif->storagelist(sd, sd->status.storage.items, ARRAYLENGTH(sd->status.storage.items)); clif->updatestorageamount(sd, sd->status.storage.storage_amount, MAX_STORAGE); return 0; @@ -347,7 +335,7 @@ void storage_storage_quit(struct map_session_data* sd, int flag) { /** * @see DBCreateData */ -static DBData create_guildstorage(DBKey key, va_list args) +DBData create_guildstorage(DBKey key, va_list args) { struct guild_storage *gs = NULL; gs = (struct guild_storage *) aCalloc(sizeof(struct guild_storage), 1); @@ -359,7 +347,7 @@ struct guild_storage *guild2storage(int guild_id) { struct guild_storage *gs = NULL; if(guild->search(guild_id) != NULL) - gs = idb_ensure(gstorage->db,guild_id,create_guildstorage); + gs = idb_ensure(gstorage->db,guild_id,gstorage->create); return gs; } @@ -409,7 +397,7 @@ int storage_guild_storageopen(struct map_session_data* sd) gstor->storage_status = 1; sd->state.storage_flag = 2; - storage_sortitem(gstor->items, ARRAYLENGTH(gstor->items)); + storage->sortitem(gstor->items, ARRAYLENGTH(gstor->items)); clif->storagelist(sd, gstor->items, ARRAYLENGTH(gstor->items)); clif->updatestorageamount(sd, gstor->storage_amount, MAX_GUILD_STORAGE); return 0; @@ -728,12 +716,15 @@ int storage_guild_storage_quit(struct map_session_data* sd, int flag) { return 0; } +void do_init_gstorage(void) { + gstorage->db = idb_alloc(DB_OPT_RELEASE_DATA); +} +void do_final_gstorage(void) { + db_destroy(gstorage->db); +} void storage_defaults(void) { storage = &storage_s; - /* */ - storage->init = do_init_storage; - storage->final = do_final_storage; /* */ storage->reconnect = do_reconnect_storage; /* */ @@ -746,10 +737,17 @@ void storage_defaults(void) { storage->gettocart = storage_storagegettocart; storage->close = storage_storageclose; storage->pc_quit = storage_storage_quit; + storage->comp_item = storage_comp_item; + storage->sortitem = storage_sortitem; + storage->reconnect_sub = storage_reconnect_sub; } void gstorage_defaults(void) { gstorage = &gstorage_s; + /* */ + gstorage->init = do_init_gstorage; + gstorage->final = do_final_gstorage; + /* */ gstorage->id2storage = guild2storage; gstorage->id2storage2 = guild2storage2; gstorage->delete = guild_storage_delete; @@ -764,4 +762,5 @@ void gstorage_defaults(void) { gstorage->pc_quit = storage_guild_storage_quit; gstorage->save = storage_guild_storagesave; gstorage->saved = storage_guild_storagesaved; + gstorage->create = create_guildstorage; } diff --git a/src/map/storage.h b/src/map/storage.h index 83243a622..9258e0265 100644 --- a/src/map/storage.h +++ b/src/map/storage.h @@ -12,8 +12,6 @@ struct map_session_data; struct DBMap; struct storage_interface { - int (*init) (void); - void (*final) (void); /* */ void (*reconnect) (void); /* */ @@ -26,6 +24,9 @@ struct storage_interface { int (*gettocart) (struct map_session_data *sd,int index,int amount); void (*close) (struct map_session_data *sd); void (*pc_quit) (struct map_session_data *sd, int flag); + int (*comp_item) (const void *_i1, const void *_i2); + void (*sortitem) (struct item* items, unsigned int size); + int (*reconnect_sub) (DBKey key, DBData *data, va_list ap); }; struct storage_interface *storage; @@ -34,6 +35,10 @@ struct guild_storage_interface { /* */ struct guild_storage *(*id2storage) (int guild_id); struct guild_storage *(*id2storage2) (int guild_id); + /* */ + void (*init) (void); + void (*final) (void); + /* */ int (*delete) (int guild_id); int (*open) (struct map_session_data *sd); int (*additem) (struct map_session_data *sd,struct guild_storage *stor,struct item *item_data,int amount); @@ -46,6 +51,7 @@ struct guild_storage_interface { int (*pc_quit) (struct map_session_data *sd,int flag); int (*save) (int account_id, int guild_id, int flag); int (*saved) (int guild_id); //Ack from char server that guild store was saved. + DBData (*create) (DBKey key, va_list args); }; struct guild_storage_interface *gstorage; -- cgit v1.2.3-70-g09d2