diff options
-rw-r--r-- | src/map/clif.c | 32 | ||||
-rw-r--r-- | src/map/homunculus.h | 2 | ||||
-rw-r--r-- | src/map/instance.c | 171 | ||||
-rw-r--r-- | src/map/instance.h | 7 | ||||
-rw-r--r-- | src/map/map.c | 8 | ||||
-rw-r--r-- | src/map/party.c | 8 | ||||
-rw-r--r-- | src/map/pc.c | 18 | ||||
-rw-r--r-- | src/map/script.c | 30 | ||||
-rw-r--r-- | src/map/storage.c | 47 | ||||
-rw-r--r-- | src/map/storage.h | 10 | ||||
-rw-r--r-- | src/map/unit.c | 2 |
11 files changed, 171 insertions, 164 deletions
diff --git a/src/map/clif.c b/src/map/clif.c index ed75e9aa0..d69d501ac 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -9368,7 +9368,7 @@ void clif_parse_LoadEndAck(int fd,struct map_session_data *sd) { maplist[sd->bl.m].users_pvp++; } if( maplist[sd->bl.m].instance_id >= 0 ) { - instances[maplist[sd->bl.m].instance_id].users++; + instance->list[maplist[sd->bl.m].instance_id].users++; instance->check_idle(maplist[sd->bl.m].instance_id); } sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS] @@ -16017,20 +16017,20 @@ int clif_instance(int instance_id, int type, int flag) { unsigned char buf[255]; enum send_target target = PARTY; - switch( instances[instance_id].owner_type ) { + switch( instance->list[instance_id].owner_type ) { case IOT_NONE: return 0; case IOT_GUILD: target = GUILD; - sd = guild->getavailablesd(guild->search(instances[instance_id].owner_id)); + sd = guild->getavailablesd(guild->search(instance->list[instance_id].owner_id)); break; case IOT_PARTY: /* default is already PARTY */ - sd = party->getavailablesd(party->search(instances[instance_id].owner_id)); + sd = party->getavailablesd(party->search(instance->list[instance_id].owner_id)); break; case IOT_CHAR: target = SELF; - sd = map->id2sd(instances[instance_id].owner_id); + sd = map->id2sd(instance->list[instance_id].owner_id); break; } @@ -16043,7 +16043,7 @@ int clif_instance(int instance_id, int type, int flag) { // Required to start the instancing information window on Client // This window re-appear each "refresh" of client automatically until type 4 is send to client. WBUFW(buf,0) = 0x02CB; - memcpy(WBUFP(buf,2),instances[instance_id].name,INSTANCE_NAME_LENGTH); + memcpy(WBUFP(buf,2),instance->list[instance_id].name,INSTANCE_NAME_LENGTH); WBUFW(buf,63) = flag; clif->send(buf,packet_len(0x02CB),&sd->bl,target); break; @@ -16058,13 +16058,13 @@ int clif_instance(int instance_id, int type, int flag) { case 4: // S 0x2cd <Instance Name>.61B <Instance Remaining Time>.L <Instance Noplayers close time>.L WBUFW(buf,0) = 0x02CD; - memcpy(WBUFP(buf,2),instances[instance_id].name,61); + memcpy(WBUFP(buf,2),instance->list[instance_id].name,61); if( type == 3 ) { - WBUFL(buf,63) = instances[instance_id].progress_timeout; + WBUFL(buf,63) = instance->list[instance_id].progress_timeout; WBUFL(buf,67) = 0; } else { WBUFL(buf,63) = 0; - WBUFL(buf,67) = instances[instance_id].idle_timeout; + WBUFL(buf,67) = instance->list[instance_id].idle_timeout; } clif->send(buf,packet_len(0x02CD),&sd->bl,target); break; @@ -16086,24 +16086,24 @@ int clif_instance(int instance_id, int type, int flag) { void clif_instance_join(int fd, int instance_id) { - if( instances[instance_id].idle_timer != INVALID_TIMER ) { + if( instance->list[instance_id].idle_timer != INVALID_TIMER ) { WFIFOHEAD(fd,packet_len(0x02CD)); WFIFOW(fd,0) = 0x02CD; - memcpy(WFIFOP(fd,2),instances[instance_id].name,61); + memcpy(WFIFOP(fd,2),instance->list[instance_id].name,61); WFIFOL(fd,63) = 0; - WFIFOL(fd,67) = instances[instance_id].idle_timeout; + WFIFOL(fd,67) = instance->list[instance_id].idle_timeout; WFIFOSET(fd,packet_len(0x02CD)); - } else if( instances[instance_id].progress_timer != INVALID_TIMER ) { + } else if( instance->list[instance_id].progress_timer != INVALID_TIMER ) { WFIFOHEAD(fd,packet_len(0x02CD)); WFIFOW(fd,0) = 0x02CD; - memcpy(WFIFOP(fd,2),instances[instance_id].name,61); - WFIFOL(fd,63) = instances[instance_id].progress_timeout; + memcpy(WFIFOP(fd,2),instance->list[instance_id].name,61); + WFIFOL(fd,63) = instance->list[instance_id].progress_timeout; WFIFOL(fd,67) = 0; WFIFOSET(fd,packet_len(0x02CD)); } else { WFIFOHEAD(fd,packet_len(0x02CB)); WFIFOW(fd,0) = 0x02CB; - memcpy(WFIFOP(fd,2),instances[instance_id].name,61); + memcpy(WFIFOP(fd,2),instance->list[instance_id].name,61); WFIFOW(fd,63) = 0; WFIFOSET(fd,packet_len(0x02CB)); } diff --git a/src/map/homunculus.h b/src/map/homunculus.h index a90faf2e2..9562ed5c3 100644 --- a/src/map/homunculus.h +++ b/src/map/homunculus.h @@ -28,8 +28,6 @@ struct s_homunculus_db { unsigned char element, race, base_size, evo_size; }; -extern struct s_homunculus_db homunculus_db[MAX_HOMUNCULUS_CLASS]; - enum { HOMUNCULUS_CLASS, HOMUNCULUS_FOOD diff --git a/src/map/instance.c b/src/map/instance.c index 5ef089fae..17b66fa75 100644 --- a/src/map/instance.c +++ b/src/map/instance.c @@ -33,7 +33,7 @@ bool instance_is_valid(int instance_id) { return false; } - if( instances[instance_id].state == INSTANCE_FREE ) {// uninitialized/freed instance slot + if( instance->list[instance_id].state == INSTANCE_FREE ) {// uninitialized/freed instance slot return false; } @@ -88,30 +88,30 @@ int instance_create(int owner_id, const char *name, enum instance_owner_type typ } if( type != IOT_NONE && *icptr ) { - ARR_FIND(0, *icptr, i, strcmp(instances[iptr[i]].name,name) == 0 ); + ARR_FIND(0, *icptr, i, strcmp(instance->list[iptr[i]].name,name) == 0 ); if( i != *icptr ) return -4;/* already got this instance */ } - ARR_FIND(0, instance->instances, i, instances[i].state == INSTANCE_FREE); + ARR_FIND(0, instance->instances, i, instance->list[i].state == INSTANCE_FREE); if( i == instance->instances ) - RECREATE(instances, struct instance_data, ++instance->instances); - - instances[i].state = INSTANCE_IDLE; - instances[i].id = i; - instances[i].idle_timer = INVALID_TIMER; - instances[i].idle_timeout = instances[i].idle_timeoutval = 0; - instances[i].progress_timer = INVALID_TIMER; - instances[i].progress_timeout = 0; - instances[i].users = 0; - instances[i].map = NULL; - instances[i].num_map = 0; - instances[i].owner_id = owner_id; - instances[i].owner_type = type; - instances[i].vars = idb_alloc(DB_OPT_RELEASE_DATA); - - safestrncpy( instances[i].name, name, sizeof(instances[i].name) ); + RECREATE(instance->list, struct instance_data, ++instance->instances); + + instance->list[i].state = INSTANCE_IDLE; + instance->list[i].id = i; + instance->list[i].idle_timer = INVALID_TIMER; + instance->list[i].idle_timeout = instance->list[i].idle_timeoutval = 0; + instance->list[i].progress_timer = INVALID_TIMER; + instance->list[i].progress_timeout = 0; + instance->list[i].users = 0; + instance->list[i].map = NULL; + instance->list[i].num_map = 0; + instance->list[i].owner_id = owner_id; + instance->list[i].owner_type = type; + instance->list[i].vars = idb_alloc(DB_OPT_RELEASE_DATA); + + safestrncpy( instance->list[i].name, name, sizeof(instance->list[i].name) ); if( type != IOT_NONE ) { ARR_FIND(0, *icptr, j, iptr[j] == -1); @@ -244,9 +244,9 @@ int instance_add_map(const char *name, int instance_id, bool usebasename, const maplist[im].instance_src_map = m; maplist[m].flag.src4instance = 1; // Flag this map as a src map for instances - RECREATE(instances[instance_id].map, unsigned short, ++instances[instance_id].num_map); + RECREATE(instance->list[instance_id].map, unsigned short, ++instance->list[instance_id].num_map); - instances[instance_id].map[instances[instance_id].num_map - 1] = im; // Attach to actual instance + instance->list[instance_id].map[instance->list[instance_id].num_map - 1] = im; // Attach to actual instance map->addmap2db(&maplist[im]); return im; @@ -264,9 +264,9 @@ int instance_map2imap(int16 m, int instance_id) { return -1; } - for( i = 0; i < instances[instance_id].num_map; i++ ) { - if( instances[instance_id].map[i] && maplist[instances[instance_id].map[i]].instance_src_map == m ) - return instances[instance_id].map[i]; + for( i = 0; i < instance->list[instance_id].num_map; i++ ) { + if( instance->list[instance_id].map[i] && maplist[instance->list[instance_id].map[i]].instance_src_map == m ) + return instance->list[instance_id].map[i]; } return -1; } @@ -313,10 +313,10 @@ void instance_init(int instance_id) { if( !instance->valid(instance_id) ) return; // nothing to do - for( i = 0; i < instances[instance_id].num_map; i++ ) - map->foreachinmap(instance_map_npcsub, maplist[instances[instance_id].map[i]].instance_src_map, BL_NPC, instances[instance_id].map[i]); + for( i = 0; i < instance->list[instance_id].num_map; i++ ) + map->foreachinmap(instance_map_npcsub, maplist[instance->list[instance_id].map[i]].instance_src_map, BL_NPC, instance->list[instance_id].map[i]); - instances[instance_id].state = INSTANCE_BUSY; + instance->list[instance_id].state = INSTANCE_BUSY; } /*-------------------------------------- @@ -410,18 +410,18 @@ void instance_del_map(int16 m) { } // Remove from instance - for( i = 0; i < instances[maplist[m].instance_id].num_map; i++ ) { - if( instances[maplist[m].instance_id].map[i] == m ) { - instances[maplist[m].instance_id].num_map--; - for( ; i < instances[maplist[m].instance_id].num_map; i++ ) - instances[maplist[m].instance_id].map[i] = instances[maplist[m].instance_id].map[i+1]; + for( i = 0; i < instance->list[maplist[m].instance_id].num_map; i++ ) { + if( instance->list[maplist[m].instance_id].map[i] == m ) { + instance->list[maplist[m].instance_id].num_map--; + for( ; i < instance->list[maplist[m].instance_id].num_map; i++ ) + instance->list[maplist[m].instance_id].map[i] = instance->list[maplist[m].instance_id].map[i+1]; i = -1; break; } } - if( i == instances[maplist[m].instance_id].num_map ) - ShowError("map_instance_del: failed to remove %s from instance list (%s): %d\n", maplist[m].name, instances[maplist[m].instance_id].name, m); + if( i == instance->list[maplist[m].instance_id].num_map ) + ShowError("map_instance_del: failed to remove %s from instance list (%s): %d\n", maplist[m].name, instance->list[maplist[m].instance_id].name, m); if( maplist[m].channel ) clif->chsys_delete(maplist[m].channel); @@ -456,41 +456,41 @@ void instance_destroy(int instance_id) { if( !instance->valid(instance_id) ) return; // nothing to do - if( instances[instance_id].progress_timeout && instances[instance_id].progress_timeout <= now ) + if( instance->list[instance_id].progress_timeout && instance->list[instance_id].progress_timeout <= now ) type = 1; - else if( instances[instance_id].idle_timeout && instances[instance_id].idle_timeout <= now ) + else if( instance->list[instance_id].idle_timeout && instance->list[instance_id].idle_timeout <= now ) type = 2; else type = 3; clif->instance(instance_id, 5, type); // Report users this instance has been destroyed - switch ( instances[instance_id].owner_type ) { + switch ( instance->list[instance_id].owner_type ) { case IOT_NONE: break; case IOT_CHAR: - if( ( sd = map->id2sd(instances[instance_id].owner_id) ) == NULL ) { + if( ( sd = map->id2sd(instance->list[instance_id].owner_id) ) == NULL ) { break; } iptr = sd->instance; icptr = &sd->instances; break; case IOT_PARTY: - if( ( p = party->search(instances[instance_id].owner_id) ) == NULL ) { + if( ( p = party->search(instance->list[instance_id].owner_id) ) == NULL ) { break; } iptr = p->instance; icptr = &p->instances; break; case IOT_GUILD: - if( ( g = guild->search(instances[instance_id].owner_id) ) == NULL ) { + if( ( g = guild->search(instance->list[instance_id].owner_id) ) == NULL ) { break; } iptr = g->instance; icptr = &g->instances; break; default: - ShowError("instance_destroy: unknown type %d for owner_id %d and name '%s'.\n", instances[instance_id].owner_type,instances[instance_id].owner_id,instances[instance_id].name); + ShowError("instance_destroy: unknown type %d for owner_id %d and name '%s'.\n", instance->list[instance_id].owner_type,instance->list[instance_id].owner_id,instance->list[instance_id].name); break; } @@ -500,27 +500,27 @@ void instance_destroy(int instance_id) { iptr[j] = -1; } - while( instances[instance_id].num_map && last != instances[instance_id].map[0] ) { // Remove all maps from instance - last = instances[instance_id].map[0]; - instance->del_map( instances[instance_id].map[0] ); + while( instance->list[instance_id].num_map && last != instance->list[instance_id].map[0] ) { // Remove all maps from instance + last = instance->list[instance_id].map[0]; + instance->del_map( instance->list[instance_id].map[0] ); } - if( instances[instance_id].vars ) - db_destroy(instances[instance_id].vars); + if( instance->list[instance_id].vars ) + db_destroy(instance->list[instance_id].vars); - if( instances[instance_id].progress_timer != INVALID_TIMER ) - timer->delete( instances[instance_id].progress_timer, instance_destroy_timer); - if( instances[instance_id].idle_timer != INVALID_TIMER ) - timer->delete( instances[instance_id].idle_timer, instance_destroy_timer); + if( instance->list[instance_id].progress_timer != INVALID_TIMER ) + timer->delete( instance->list[instance_id].progress_timer, instance->destroy_timer); + if( instance->list[instance_id].idle_timer != INVALID_TIMER ) + timer->delete( instance->list[instance_id].idle_timer, instance->destroy_timer); - instances[instance_id].vars = NULL; + instance->list[instance_id].vars = NULL; - if( instances[instance_id].map ) - aFree(instances[instance_id].map); + if( instance->list[instance_id].map ) + aFree(instance->list[instance_id].map); - instances[instance_id].map = NULL; - instances[instance_id].state = INSTANCE_FREE; - instances[instance_id].num_map = 0; + instance->list[instance_id].map = NULL; + instance->list[instance_id].state = INSTANCE_FREE; + instance->list[instance_id].num_map = 0; } /*-------------------------------------- @@ -530,20 +530,20 @@ void instance_check_idle(int instance_id) { bool idle = true; unsigned int now = (unsigned int)time(NULL); - if( !instance->valid(instance_id) || instances[instance_id].idle_timeoutval == 0 ) + if( !instance->valid(instance_id) || instance->list[instance_id].idle_timeoutval == 0 ) return; - if( instances[instance_id].users ) + if( instance->list[instance_id].users ) idle = false; - if( instances[instance_id].idle_timer != INVALID_TIMER && !idle ) { - timer->delete(instances[instance_id].idle_timer, instance_destroy_timer); - instances[instance_id].idle_timer = INVALID_TIMER; - instances[instance_id].idle_timeout = 0; + if( instance->list[instance_id].idle_timer != INVALID_TIMER && !idle ) { + timer->delete(instance->list[instance_id].idle_timer, instance->destroy_timer); + instance->list[instance_id].idle_timer = INVALID_TIMER; + instance->list[instance_id].idle_timeout = 0; clif->instance(instance_id, 3, 0); // Notify instance users normal instance expiration - } else if( instances[instance_id].idle_timer == INVALID_TIMER && idle ) { - instances[instance_id].idle_timeout = now + instances[instance_id].idle_timeoutval; - instances[instance_id].idle_timer = timer->add( timer->gettick() + instances[instance_id].idle_timeoutval * 1000, instance_destroy_timer, instance_id, 0); + } else if( instance->list[instance_id].idle_timer == INVALID_TIMER && idle ) { + instance->list[instance_id].idle_timeout = now + instance->list[instance_id].idle_timeoutval; + instance->list[instance_id].idle_timer = timer->add( timer->gettick() + instance->list[instance_id].idle_timeoutval * 1000, instance->destroy_timer, instance_id, 0); clif->instance(instance_id, 4, 0); // Notify instance users it will be destroyed of no user join it again in "X" time } } @@ -558,30 +558,30 @@ void instance_set_timeout(int instance_id, unsigned int progress_timeout, unsign if( !instance->valid(instance_id) ) return; - if( instances[instance_id].progress_timer != INVALID_TIMER ) - timer->delete( instances[instance_id].progress_timer, instance_destroy_timer); - if( instances[instance_id].idle_timer != INVALID_TIMER ) - timer->delete( instances[instance_id].idle_timer, instance_destroy_timer); + if( instance->list[instance_id].progress_timer != INVALID_TIMER ) + timer->delete( instance->list[instance_id].progress_timer, instance->destroy_timer); + if( instance->list[instance_id].idle_timer != INVALID_TIMER ) + timer->delete( instance->list[instance_id].idle_timer, instance->destroy_timer); if( progress_timeout ) { - instances[instance_id].progress_timeout = now + progress_timeout; - instances[instance_id].progress_timer = timer->add( timer->gettick() + progress_timeout * 1000, instance_destroy_timer, instance_id, 0); + instance->list[instance_id].progress_timeout = now + progress_timeout; + instance->list[instance_id].progress_timer = timer->add( timer->gettick() + progress_timeout * 1000, instance->destroy_timer, instance_id, 0); } else { - instances[instance_id].progress_timeout = 0; - instances[instance_id].progress_timer = INVALID_TIMER; + instance->list[instance_id].progress_timeout = 0; + instance->list[instance_id].progress_timer = INVALID_TIMER; } if( idle_timeout ) { - instances[instance_id].idle_timeoutval = idle_timeout; - instances[instance_id].idle_timer = INVALID_TIMER; - instance_check_idle(instance_id); + instance->list[instance_id].idle_timeoutval = idle_timeout; + instance->list[instance_id].idle_timer = INVALID_TIMER; + instance->check_idle(instance_id); } else { - instances[instance_id].idle_timeoutval = 0; - instances[instance_id].idle_timeout = 0; - instances[instance_id].idle_timer = INVALID_TIMER; + instance->list[instance_id].idle_timeoutval = 0; + instance->list[instance_id].idle_timeout = 0; + instance->list[instance_id].idle_timer = INVALID_TIMER; } - if( instances[instance_id].idle_timer == INVALID_TIMER && instances[instance_id].progress_timer != INVALID_TIMER ) + if( instance->list[instance_id].idle_timer == INVALID_TIMER && instance->list[instance_id].progress_timer != INVALID_TIMER ) clif->instance(instance_id, 3, 0); } @@ -607,14 +607,15 @@ void do_final_instance(void) { instance->destroy(i); } - if( instances ) - aFree(instances); + if( instance->list ) + aFree(instance->list); + instance->list = NULL; instance->instances = 0; } void do_init_instance(void) { - timer->add_func_list(instance_destroy_timer, "instance_destroy_timer"); + timer->add_func_list(instance->destroy_timer, "instance_destroy_timer"); } void instance_defaults(void) { @@ -627,7 +628,8 @@ void instance_defaults(void) { instance->start_id = 0; /* count */ instance->instances = 0; - + /* */ + instance->list = NULL; /* */ instance->create = instance_create; instance->add_map = instance_add_map; @@ -640,4 +642,5 @@ void instance_defaults(void) { instance->check_kick = instance_check_kick; instance->set_timeout = instance_set_timeout; instance->valid = instance_is_valid; + instance->destroy_timer = instance_destroy_timer; } diff --git a/src/map/instance.h b/src/map/instance.h index 164aaf662..ba6d26d59 100644 --- a/src/map/instance.h +++ b/src/map/instance.h @@ -42,14 +42,14 @@ struct instance_data { unsigned int idle_timeout, idle_timeoutval; }; -struct instance_data *instances; - struct instance_interface { void (*init) (void); void (*final) (void); /* start point */ unsigned short start_id; - unsigned short instances; + unsigned short instances;/* count */ + /* */ + struct instance_data *list;/* pointer to a chunk of consecutive memory, access via instance->list[0]..etc */ /* */ int (*create) (int party_id, const char *name, enum instance_owner_type type); int (*add_map) (const char *name, int instance_id, bool usebasename, const char *map_name); @@ -62,6 +62,7 @@ struct instance_interface { void (*check_kick) (struct map_session_data *sd); void (*set_timeout) (int instance_id, unsigned int progress_timeout, unsigned int idle_timeout); bool (*valid) (int instance_id); + int (*destroy_timer) (int tid, unsigned int tick, int id, intptr_t data); }; struct instance_interface *instance; diff --git a/src/map/map.c b/src/map/map.c index 8641f7011..37f0817c4 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -624,8 +624,8 @@ int map_foreachininstance(int (*func)(struct block_list*, va_list), int16 instan int i; int returnCount = 0; - for (i = 0; i < instances[instance_id].num_map; i++) { - int m = instances[instance_id].map[i]; + for (i = 0; i < instance->list[instance_id].num_map; i++) { + int m = instance->list[instance_id].map[i]; va_list ap; va_start(ap, type); returnCount += map_vforeachinmap(func, m, type, ap); @@ -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/party.c b/src/map/party.c index a4eb38629..db4b88f7d 100644 --- a/src/map/party.c +++ b/src/map/party.c @@ -319,7 +319,7 @@ int party_recv_info(struct party* sp, int char_id) clif->party_info(p,NULL); for( j = 0; j < p->instances; j++ ) { if( p->instance[j] >= 0 ) { - if( instances[p->instance[j]].idle_timer == INVALID_TIMER && instances[p->instance[j]].progress_timer == INVALID_TIMER ) + if( instance->list[p->instance[j]].idle_timer == INVALID_TIMER && instance->list[p->instance[j]].progress_timer == INVALID_TIMER ) continue; clif->instance_join(sd->fd, p->instance[j]); break; @@ -442,7 +442,7 @@ void party_member_joined(struct map_session_data *sd) p->data[i].sd = sd; for( j = 0; j < p->instances; j++ ) { if( p->instance[j] >= 0 ) { - if( instances[p->instance[j]].idle_timer == INVALID_TIMER && instances[p->instance[j]].progress_timer == INVALID_TIMER ) + if( instance->list[p->instance[j]].idle_timer == INVALID_TIMER && instance->list[p->instance[j]].progress_timer == INVALID_TIMER ) continue; clif->instance_join(sd->fd, p->instance[j]); break; @@ -504,7 +504,7 @@ int party_member_added(int party_id,int account_id,int char_id, int flag) { for( j = 0; j < p->instances; j++ ) { if( p->instance[j] >= 0 ) { - if( instances[p->instance[j]].idle_timer == INVALID_TIMER && instances[p->instance[j]].progress_timer == INVALID_TIMER ) + if( instance->list[p->instance[j]].idle_timer == INVALID_TIMER && instance->list[p->instance[j]].progress_timer == INVALID_TIMER ) continue; clif->instance_join(sd->fd, p->instance[j]); break; @@ -604,7 +604,7 @@ int party_broken(int party_id) for( j = 0; j < p->instances; j++ ) { if( p->instance[j] >= 0 ) { instance->destroy( p->instance[j] ); - instances[p->instance[j]].owner_id = 0; + instance->list[p->instance[j]].owner_id = 0; } } diff --git a/src/map/pc.c b/src/map/pc.c index 393caa627..1a5efe48a 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -4791,13 +4791,13 @@ int pc_setpos(struct map_session_data* sd, unsigned short mapindex, int x, int y if( sd->instances ) { for( i = 0; i < sd->instances; i++ ) { if( sd->instance[i] >= 0 ) { - ARR_FIND(0, instances[sd->instance[i]].num_map, j, maplist[instances[sd->instance[i]].map[j]].instance_src_map == m && !maplist[instances[sd->instance[i]].map[j]].custom_name); - if( j != instances[sd->instance[i]].num_map ) + ARR_FIND(0, instance->list[sd->instance[i]].num_map, j, maplist[instance->list[sd->instance[i]].map[j]].instance_src_map == m && !maplist[instance->list[sd->instance[i]].map[j]].custom_name); + if( j != instance->list[sd->instance[i]].num_map ) break; } } if( i != sd->instances ) { - m = instances[sd->instance[i]].map[j]; + m = instance->list[sd->instance[i]].map[j]; mapindex = map_id2index(m); stop = true; } @@ -4805,13 +4805,13 @@ int pc_setpos(struct map_session_data* sd, unsigned short mapindex, int x, int y if ( !stop && sd->status.party_id && (p = party->search(sd->status.party_id)) && p->instances ) { for( i = 0; i < p->instances; i++ ) { if( p->instance[i] >= 0 ) { - ARR_FIND(0, instances[p->instance[i]].num_map, j, maplist[instances[p->instance[i]].map[j]].instance_src_map == m && !maplist[instances[p->instance[i]].map[j]].custom_name); - if( j != instances[p->instance[i]].num_map ) + ARR_FIND(0, instance->list[p->instance[i]].num_map, j, maplist[instance->list[p->instance[i]].map[j]].instance_src_map == m && !maplist[instance->list[p->instance[i]].map[j]].custom_name); + if( j != instance->list[p->instance[i]].num_map ) break; } } if( i != p->instances ) { - m = instances[p->instance[i]].map[j]; + m = instance->list[p->instance[i]].map[j]; mapindex = map_id2index(m); stop = true; } @@ -4819,13 +4819,13 @@ int pc_setpos(struct map_session_data* sd, unsigned short mapindex, int x, int y if ( !stop && sd->status.guild_id && sd->guild && sd->guild->instances ) { for( i = 0; i < sd->guild->instances; i++ ) { if( sd->guild->instance[i] >= 0 ) { - ARR_FIND(0, instances[sd->guild->instance[i]].num_map, j, maplist[instances[sd->guild->instance[i]].map[j]].instance_src_map == m && !maplist[instances[sd->guild->instance[i]].map[j]].custom_name); - if( j != instances[sd->guild->instance[i]].num_map ) + ARR_FIND(0, instance->list[sd->guild->instance[i]].num_map, j, maplist[instance->list[sd->guild->instance[i]].map[j]].instance_src_map == m && !maplist[instance->list[sd->guild->instance[i]].map[j]].custom_name); + if( j != instance->list[sd->guild->instance[i]].num_map ) break; } } if( i != sd->guild->instances ) { - m = instances[sd->guild->instance[i]].map[j]; + m = instance->list[sd->guild->instance[i]].map[j]; mapindex = map_id2index(m); stop = true; } diff --git a/src/map/script.c b/src/map/script.c index 06c97bbe6..59af8d2b7 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -2361,7 +2361,7 @@ void get_val(struct script_state* st, struct script_data* data) break; case '\'': if ( st->instance_id >= 0 ) { - data->u.str = (char*)idb_get(instances[st->instance_id].vars,reference_getuid(data)); + data->u.str = (char*)idb_get(instance->list[st->instance_id].vars,reference_getuid(data)); } else { ShowWarning("script_get_val: cannot access instance variable '%s', defaulting to \"\"\n", name); data->u.str = NULL; @@ -2416,7 +2416,7 @@ void get_val(struct script_state* st, struct script_data* data) break; case '\'': if( st->instance_id >= 0 ) - data->u.num = (int)idb_iget(instances[st->instance_id].vars,reference_getuid(data)); + data->u.num = (int)idb_iget(instance->list[st->instance_id].vars,reference_getuid(data)); else { ShowWarning("script_get_val: cannot access instance variable '%s', defaulting to 0\n", name); data->u.num = 0; @@ -2474,8 +2474,8 @@ static int set_reg(struct script_state* st, TBL_PC* sd, int num, const char* nam return 1; case '\'': if( st->instance_id >= 0 ) { - idb_remove(instances[st->instance_id].vars, num); - if( str[0] ) idb_put(instances[st->instance_id].vars, num, aStrdup(str)); + idb_remove(instance->list[st->instance_id].vars, num); + if( str[0] ) idb_put(instance->list[st->instance_id].vars, num, aStrdup(str)); } return 1; default: @@ -2522,9 +2522,9 @@ static int set_reg(struct script_state* st, TBL_PC* sd, int num, const char* nam return 1; case '\'': if( st->instance_id >= 0 ) { - idb_remove(instances[st->instance_id].vars, num); + idb_remove(instance->list[st->instance_id].vars, num); if( val != 0 ) - idb_iput(instances[st->instance_id].vars, num, val); + idb_iput(instance->list[st->instance_id].vars, num, val); } return 1; default: @@ -15930,7 +15930,7 @@ BUILDIN(instance_init) { return true; } - if( instances[instance_id].state != INSTANCE_IDLE ) { + if( instance->list[instance_id].state != INSTANCE_IDLE ) { ShowError("instance_init: instance already initialized.\n"); return true; } @@ -15961,8 +15961,8 @@ BUILDIN(instance_announce) { if( !instance->valid(instance_id) ) return true; - for( i = 0; i < instances[instance_id].num_map; i++ ) - map->foreachinmap(buildin_announce_sub, instances[instance_id].map[i], BL_PC, + for( i = 0; i < instance->list[instance_id].num_map; i++ ) + map->foreachinmap(buildin_announce_sub, instance->list[instance_id].map[i], BL_PC, mes, strlen(mes)+1, flag&BC_COLOR_MASK, fontColor, fontType, fontSize, fontAlign, fontY); return true; @@ -16015,8 +16015,8 @@ BUILDIN(has_instance) { if( sd->instances ) { for( i = 0; i < sd->instances; i++ ) { if( sd->instance[i] >= 0 ) { - ARR_FIND(0, instances[sd->instance[i]].num_map, j, maplist[instances[sd->instance[i]].map[j]].instance_src_map == m); - if( j != instances[sd->instance[i]].num_map ) + ARR_FIND(0, instance->list[sd->instance[i]].num_map, j, maplist[instance->list[sd->instance[i]].map[j]].instance_src_map == m); + if( j != instance->list[sd->instance[i]].num_map ) break; } } @@ -16026,8 +16026,8 @@ BUILDIN(has_instance) { if( instance_id == -1 && sd->status.party_id && (p = party->search(sd->status.party_id)) && p->instances ) { for( i = 0; i < p->instances; i++ ) { if( p->instance[i] >= 0 ) { - ARR_FIND(0, instances[p->instance[i]].num_map, j, maplist[instances[p->instance[i]].map[j]].instance_src_map == m); - if( j != instances[p->instance[i]].num_map ) + ARR_FIND(0, instance->list[p->instance[i]].num_map, j, maplist[instance->list[p->instance[i]].map[j]].instance_src_map == m); + if( j != instance->list[p->instance[i]].num_map ) break; } } @@ -16037,8 +16037,8 @@ BUILDIN(has_instance) { if( instance_id == -1 && sd->guild && sd->guild->instances ) { for( i = 0; i < sd->guild->instances; i++ ) { if( sd->guild->instance[i] >= 0 ) { - ARR_FIND(0, instances[sd->guild->instance[i]].num_map, j, maplist[instances[sd->guild->instance[i]].map[j]].instance_src_map == m); - if( j != instances[sd->guild->instance[i]].num_map ) + ARR_FIND(0, instance->list[sd->guild->instance[i]].num_map, j, maplist[instance->list[sd->guild->instance[i]].map[j]].instance_src_map == m); + if( j != instance->list[sd->guild->instance[i]].num_map ) break; } } 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,13 +716,16 @@ 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; /* */ storage->delitem = storage_delitem; @@ -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; diff --git a/src/map/unit.c b/src/map/unit.c index 9d6f107e3..488a210bf 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -2197,7 +2197,7 @@ int unit_remove_map(struct block_list *bl, clr_type clrtype, const char* file, i --maplist[bl->m].users_pvp; } if( maplist[bl->m].instance_id >= 0 ) { - instances[maplist[bl->m].instance_id].users--; + instance->list[maplist[bl->m].instance_id].users--; instance->check_idle(maplist[bl->m].instance_id); } sd->state.debug_remove_map = 1; // temporary state to track double remove_map's [FlavioJS] |