diff options
author | shennetsind <ind@henn.et> | 2013-09-27 18:44:46 -0300 |
---|---|---|
committer | shennetsind <ind@henn.et> | 2013-09-27 18:44:46 -0300 |
commit | 346ea5f138e5baee36cf1e986c12fff84277f4ca (patch) | |
tree | 91de00aab2b611989b832c9256ba5228cc96765b /src/map | |
parent | c728c1f7d1ccff7c1a1bcf4b7a4dd4ef15a0b599 (diff) | |
download | hercules-346ea5f138e5baee36cf1e986c12fff84277f4ca.tar.gz hercules-346ea5f138e5baee36cf1e986c12fff84277f4ca.tar.bz2 hercules-346ea5f138e5baee36cf1e986c12fff84277f4ca.tar.xz hercules-346ea5f138e5baee36cf1e986c12fff84277f4ca.zip |
HPM: Guild.c Completed
Moved missing vars and declarations of interest into the interface.
Signed-off-by: shennetsind <ind@henn.et>
Diffstat (limited to 'src/map')
-rw-r--r-- | src/map/guild.c | 262 | ||||
-rw-r--r-- | src/map/guild.h | 63 |
2 files changed, 186 insertions, 139 deletions
diff --git a/src/map/guild.c b/src/map/guild.c index 797b3b370..b66961262 100644 --- a/src/map/guild.c +++ b/src/map/guild.c @@ -32,50 +32,10 @@ struct guild_interface guild_s; -static DBMap* guild_db; // int guild_id -> struct guild* -static DBMap* castle_db; // int castle_id -> struct guild_castle* -static DBMap* guild_expcache_db; // int char_id -> struct guild_expcache* -static DBMap* guild_infoevent_db; // int guild_id -> struct eventlist* - -struct eventlist { - char name[EVENT_NAME_LENGTH]; - struct eventlist *next; -}; - -//Constant related to the flash of the Guild EXP cache -#define GUILD_SEND_XY_INVERVAL 5000 // Interval of sending coordinates and HP -#define GUILD_PAYEXP_INVERVAL 10000 //Interval (maximum survival time of the cache, in milliseconds) -#define GUILD_PAYEXP_LIST 8192 //The maximum number of cache - -//Guild EXP cache - -struct guild_expcache { - int guild_id, account_id, char_id; - uint64 exp; -}; -static struct eri *expcache_ers; //For handling of guild exp payment. - -#define MAX_GUILD_SKILL_REQUIRE 5 -struct{ - int id; - int max; - struct{ - short id; - short lv; - }need[MAX_GUILD_SKILL_REQUIRE]; -} guild_skill_tree[MAX_GUILDSKILL]; - -int guild_payexp_timer(int tid, unsigned int tick, int id, intptr_t data); -static int guild_send_xy_timer(int tid, unsigned int tick, int id, intptr_t data); - -/* guild flags cache */ -struct npc_data **guild_flags; -unsigned short guild_flags_count; - /*========================================== * Retrieves and validates the sd pointer for this guild member [Skotlex] *------------------------------------------*/ -static TBL_PC* guild_sd_check(int guild_id, int account_id, int char_id) { +TBL_PC* guild_sd_check(int guild_id, int account_id, int char_id) { TBL_PC* sd = map->id2sd(account_id); if (!(sd && sd->status.char_id == char_id)) @@ -90,15 +50,14 @@ static TBL_PC* guild_sd_check(int guild_id, int account_id, int char_id) { return sd; } - // Modified [Komurka] +// Modified [Komurka] int guild_skill_get_max (int id) { if (id < GD_SKILLBASE || id >= GD_SKILLBASE+MAX_GUILDSKILL) return 0; - return guild_skill_tree[id-GD_SKILLBASE].max; + return guild->skill_tree[id-GD_SKILLBASE].max; } // Retrive skill_lv learned by guild - int guild_checkskill(struct guild *g, int id) { int idx = id - GD_SKILLBASE; if (idx < 0 || idx >= MAX_GUILDSKILL) @@ -109,7 +68,7 @@ int guild_checkskill(struct guild *g, int id) { /*========================================== * guild_skill_tree.txt reading - from jA [Komurka] *------------------------------------------*/ -static bool guild_read_guildskill_tree_db(char* split[], int columns, int current) +bool guild_read_guildskill_tree_db(char* split[], int columns, int current) {// <skill id>,<max lv>,<req id1>,<req lv1>,<req id2>,<req lv2>,<req id3>,<req lv3>,<req id4>,<req lv4>,<req id5>,<req lv5> int k, id, skill_id; @@ -122,18 +81,18 @@ static bool guild_read_guildskill_tree_db(char* split[], int columns, int curren return false; } - guild_skill_tree[id].id = skill_id; - guild_skill_tree[id].max = atoi(split[1]); + guild->skill_tree[id].id = skill_id; + guild->skill_tree[id].max = atoi(split[1]); - if( guild_skill_tree[id].id == GD_GLORYGUILD && battle_config.require_glory_guild && guild_skill_tree[id].max == 0 ) + if( guild->skill_tree[id].id == GD_GLORYGUILD && battle_config.require_glory_guild && guild->skill_tree[id].max == 0 ) {// enable guild's glory when required for emblems - guild_skill_tree[id].max = 1; + guild->skill_tree[id].max = 1; } for( k = 0; k < MAX_GUILD_SKILL_REQUIRE; k++ ) { - guild_skill_tree[id].need[k].id = atoi(split[k*2+2]); - guild_skill_tree[id].need[k].lv = atoi(split[k*2+3]); + guild->skill_tree[id].need[k].id = atoi(split[k*2+2]); + guild->skill_tree[id].need[k].lv = atoi(split[k*2+3]); } return true; @@ -155,14 +114,14 @@ int guild_check_skill_require(struct guild *g,int id) for(i=0;i<MAX_GUILD_SKILL_REQUIRE;i++) { - if(guild_skill_tree[idx].need[i].id == 0) break; - if(guild_skill_tree[idx].need[i].lv > guild->checkskill(g,guild_skill_tree[idx].need[i].id)) + if(guild->skill_tree[idx].need[i].id == 0) break; + if(guild->skill_tree[idx].need[i].lv > guild->checkskill(g,guild->skill_tree[idx].need[i].id)) return 0; } return 1; } -static bool guild_read_castledb(char* str[], int columns, int current) +bool guild_read_castledb(char* str[], int columns, int current) {// <castle id>,<map name>,<castle name>,<castle event>[,<reserved/unused switch flag>] struct guild_castle *gc; int mapindex = mapindex_name2id(str[1]); @@ -176,7 +135,7 @@ static bool guild_read_castledb(char* str[], int columns, int current) safestrncpy(gc->castle_name, str[2], sizeof(gc->castle_name)); safestrncpy(gc->castle_event, str[3], sizeof(gc->castle_event)); - idb_put(castle_db,gc->castle_id,gc); + idb_put(guild->castle_db,gc->castle_id,gc); //intif->guild_castle_info(gc->castle_id); @@ -186,14 +145,14 @@ static bool guild_read_castledb(char* str[], int columns, int current) /// lookup: guild id -> guild* struct guild* guild_search(int guild_id) { - return (struct guild*)idb_get(guild_db,guild_id); + return (struct guild*)idb_get(guild->db,guild_id); } /// lookup: guild name -> guild* struct guild* guild_searchname(char* str) { struct guild* g; - DBIterator *iter = db_iterator(guild_db); + DBIterator *iter = db_iterator(guild->db); for( g = dbi_first(iter); dbi_exists(iter); g = dbi_next(iter) ) { @@ -208,14 +167,14 @@ struct guild* guild_searchname(char* str) /// lookup: castle id -> castle* struct guild_castle* guild_castle_search(int gcid) { - return (struct guild_castle*)idb_get(castle_db,gcid); + return (struct guild_castle*)idb_get(guild->castle_db,gcid); } /// lookup: map index -> castle* struct guild_castle* guild_mapindex2gc(short mapindex) { struct guild_castle* gc; - DBIterator *iter = db_iterator(castle_db); + DBIterator *iter = db_iterator(guild->castle_db); for( gc = dbi_first(iter); dbi_exists(iter); gc = dbi_next(iter) ) { @@ -303,7 +262,7 @@ int guild_payexp_timer_sub(DBKey key, DBData *data, va_list ap) { (g = guild->search(c->guild_id)) == NULL || (i = guild->getindex(g, c->account_id, c->char_id)) < 0 ) { - ers_free(expcache_ers, c); + ers_free(guild->expcache_ers, c); return 0; } @@ -316,13 +275,13 @@ int guild_payexp_timer_sub(DBKey key, DBData *data, va_list ap) { GMI_EXP,&g->member[i].exp,sizeof(g->member[i].exp)); c->exp=0; - ers_free(expcache_ers, c); + ers_free(guild->expcache_ers, c); return 0; } int guild_payexp_timer(int tid, unsigned int tick, int id, intptr_t data) { - guild_expcache_db->clear(guild_expcache_db,guild_payexp_timer_sub); + guild->expcache_db->clear(guild->expcache_db,guild->payexp_timer_sub); return 0; } @@ -355,9 +314,9 @@ int guild_send_xy_timer_sub(DBKey key, DBData *data, va_list ap) } //Code from party_send_xy_timer [Skotlex] -static int guild_send_xy_timer(int tid, unsigned int tick, int id, intptr_t data) +int guild_send_xy_timer(int tid, unsigned int tick, int id, intptr_t data) { - guild_db->foreach(guild_db,guild_send_xy_timer_sub,tick); + guild->db->foreach(guild->db,guild->send_xy_timer_sub,tick); return 0; } @@ -392,7 +351,7 @@ int guild_create(struct map_session_data *sd, const char *name) return 0; } - guild_makemember(&m,sd); + guild->makemember(&m,sd); m.position=0; intif->guild_create(name,&m); return 1; @@ -440,7 +399,7 @@ int guild_npc_request_info(int guild_id,const char *event) ev=(struct eventlist *)aCalloc(sizeof(struct eventlist),1); memcpy(ev->name,event,strlen(event)); //The one in the db (if present) becomes the next event from this. - if (guild_infoevent_db->put(guild_infoevent_db, DB->i2key(guild_id), DB->ptr2data(ev), &prev)) + if (guild->infoevent_db->put(guild->infoevent_db, DB->i2key(guild_id), DB->ptr2data(ev), &prev)) ev->next = DB->data2ptr(&prev); } @@ -501,12 +460,12 @@ int guild_recv_info(struct guild *sg) { nullpo_ret(sg); - if((g = (struct guild*)idb_get(guild_db,sg->guild_id))==NULL) { + if((g = (struct guild*)idb_get(guild->db,sg->guild_id))==NULL) { guild_new = true; g=(struct guild *)aCalloc(1,sizeof(struct guild)); g->instance = NULL; g->instances = 0; - idb_put(guild_db,sg->guild_id,g); + idb_put(guild->db,sg->guild_id,g); if( hChSys.ally ) { struct hChSysCh *channel; @@ -554,7 +513,7 @@ int guild_recv_info(struct guild *sg) { } before=*sg; //Perform the check on the user because the first load - guild_check_member(sg); + guild->check_member(sg); if ((sd = map->nick2sd(sg->master)) != NULL) { //If the guild master is online the first time the guild_info is received, //that means he was the first to join, so apply guild skill blocking here. @@ -583,7 +542,7 @@ int guild_recv_info(struct guild *sg) { for(i=bm=m=0;i<g->max_member;i++){ if(g->member[i].account_id>0){ - sd = g->member[i].sd = guild_sd_check(g->guild_id, g->member[i].account_id, g->member[i].char_id); + sd = g->member[i].sd = guild->sd_check(g->guild_id, g->member[i].account_id, g->member[i].char_id); if (sd) clif->charnameupdate(sd); // [LuzZza] m++; }else @@ -618,7 +577,7 @@ int guild_recv_info(struct guild *sg) { } //Occurrence of an event - if (guild_infoevent_db->remove(guild_infoevent_db, DB->i2key(sg->guild_id), &data)) { + if (guild->infoevent_db->remove(guild->infoevent_db, DB->i2key(sg->guild_id), &data)) { struct eventlist *ev = DB->data2ptr(&data), *ev2; while(ev) { npc->event_do(ev->name); @@ -731,7 +690,7 @@ int guild_reply_invite(struct map_session_data* sd, int guild_id, int flag) { return 0; } - guild_makemember(&m,sd); + guild->makemember(&m,sd); intif->guild_addmember(guild_id, &m); //TODO: send a minimap update to this player } @@ -1015,7 +974,7 @@ int guild_recv_memberinfoshort(int guild_id,int account_id,int char_id,int onlin g->connect_member=om; //Ensure validity of pointer (ie: player logs in/out, changes map-server) - g->member[idx].sd = guild_sd_check(guild_id, account_id, char_id); + g->member[idx].sd = guild->sd_check(guild_id, account_id, char_id); if(oldonline!=online) clif->guild_memberlogin_notice(g, idx, online); @@ -1095,8 +1054,7 @@ int guild_memberposition_changed(struct guild *g,int idx,int pos) /*==================================================== * Change guild title or member *---------------------------------------------------*/ -int guild_change_position(int guild_id,int idx, - int mode,int exp_mode,const char *name) +int guild_change_position(int guild_id,int idx,int mode,int exp_mode,const char *name) { struct guild_position p; @@ -1202,7 +1160,7 @@ int guild_emblem_changed(int len,int guild_id,int emblem_id,const char *data) } } {// update guardians (mobs) - DBIterator* iter = db_iterator(castle_db); + DBIterator* iter = db_iterator(guild->castle_db); struct guild_castle* gc; for( gc = (struct guild_castle*)dbi_first(iter) ; dbi_exists(iter); gc = (struct guild_castle*)dbi_next(iter) ) { @@ -1228,9 +1186,9 @@ int guild_emblem_changed(int len,int guild_id,int emblem_id,const char *data) dbi_destroy(iter); } {// update npcs (flags or other npcs that used flagemblem to attach to this guild) - for( i = 0; i < guild_flags_count; i++ ) { - if( guild_flags[i] && guild_flags[i]->u.scr.guild_id == guild_id ) { - clif->guild_emblem_area(&guild_flags[i]->bl); + for( i = 0; i < guild->flags_count; i++ ) { + if( guild->flags[i] && guild->flags[i]->u.scr.guild_id == guild_id ) { + clif->guild_emblem_area(&guild->flags[i]->bl); } } } @@ -1240,12 +1198,12 @@ int guild_emblem_changed(int len,int guild_id,int emblem_id,const char *data) /** * @see DBCreateData */ -static DBData create_expcache(DBKey key, va_list args) +DBData create_expcache(DBKey key, va_list args) { struct guild_expcache *c; struct map_session_data *sd = va_arg(args, struct map_session_data*); - c = ers_alloc(expcache_ers, struct guild_expcache); + c = ers_alloc(guild->expcache_ers, struct guild_expcache); c->guild_id = sd->status.guild_id; c->account_id = sd->status.account_id; c->char_id = sd->status.char_id; @@ -1276,7 +1234,7 @@ unsigned int guild_payexp(struct map_session_data *sd,unsigned int exp) { exp = exp * per / 100; //Otherwise tax everything. - c = DB->data2ptr(guild_expcache_db->ensure(guild_expcache_db, DB->i2key(sd->status.char_id), create_expcache, sd)); + c = DB->data2ptr(guild->expcache_db->ensure(guild->expcache_db, DB->i2key(sd->status.char_id), guild->create_expcache, sd)); if (c->exp > UINT64_MAX - exp) c->exp = UINT64_MAX; @@ -1299,7 +1257,7 @@ int guild_getexp(struct map_session_data *sd,int exp) if (sd->status.guild_id == 0 || sd->guild == NULL) return 0; - c = DB->data2ptr(guild_expcache_db->ensure(guild_expcache_db, DB->i2key(sd->status.char_id), create_expcache, sd)); + c = DB->data2ptr(guild->expcache_db->ensure(guild->expcache_db, DB->i2key(sd->status.char_id), guild->create_expcache, sd)); if (c->exp > UINT64_MAX - exp) c->exp = UINT64_MAX; else @@ -1459,11 +1417,11 @@ int guild_reqalliance(struct map_session_data *sd,struct map_session_data *tsd) if(sd->status.guild_id == tsd->status.guild_id) return 0; - if( guild_get_alliance_count(g[0],0) >= battle_config.max_guild_alliance ) { + if( guild->get_alliance_count(g[0],0) >= battle_config.max_guild_alliance ) { clif->guild_allianceack(sd,4); return 0; } - if( guild_get_alliance_count(g[1],0) >= battle_config.max_guild_alliance ) { + if( guild->get_alliance_count(g[1],0) >= battle_config.max_guild_alliance ) { clif->guild_allianceack(sd,3); return 0; } @@ -1511,12 +1469,12 @@ int guild_reply_reqalliance(struct map_session_data *sd,int account_id,int flag) g=sd->guild; tg=tsd->guild; - if(g==NULL || guild_get_alliance_count(g,0) >= battle_config.max_guild_alliance){ + if(g==NULL || guild->get_alliance_count(g,0) >= battle_config.max_guild_alliance){ clif->guild_allianceack(sd,4); clif->guild_allianceack(tsd,3); return 0; } - if(tg==NULL || guild_get_alliance_count(tg,0) >= battle_config.max_guild_alliance){ + if(tg==NULL || guild->get_alliance_count(tg,0) >= battle_config.max_guild_alliance){ clif->guild_allianceack(sd,3); clif->guild_allianceack(tsd,4); return 0; @@ -1582,7 +1540,7 @@ int guild_opposition(struct map_session_data *sd,struct map_session_data *tsd) if(sd->status.guild_id == tsd->status.guild_id) return 0; - if( guild_get_alliance_count(g,1) >= battle_config.max_guild_alliance ) { + if( guild->get_alliance_count(g,1) >= battle_config.max_guild_alliance ) { clif->guild_oppositionack(sd,1); return 0; } @@ -1765,15 +1723,15 @@ int guild_broken(int guild_id,int flag) } } - guild_db->foreach(guild_db,guild_broken_sub,guild_id); - castle_db->foreach(castle_db,castle_guild_broken_sub,guild_id); + guild->db->foreach(guild->db,guild->broken_sub,guild_id); + guild->castle_db->foreach(guild->castle_db,guild->castle_broken_sub,guild_id); gstorage->delete(guild_id); if( hChSys.ally ) { if( g->channel != NULL ) { clif->chsys_delete(( struct hChSysCh * )g->channel); } } - idb_remove(guild_db,guild_id); + idb_remove(guild->db,guild_id); return 0; } @@ -1911,7 +1869,7 @@ int guild_break(struct map_session_data *sd,char *name) { void guild_castle_map_init(void) { DBIterator* iter = NULL; - int num = db_size(castle_db); + int num = db_size(guild->castle_db); if (num > 0) { struct guild_castle* gc = NULL; @@ -1919,7 +1877,7 @@ void guild_castle_map_init(void) CREATE(castle_ids, int, num); cursor = castle_ids; - iter = db_iterator(castle_db); + iter = db_iterator(guild->castle_db); for (gc = dbi_first(iter); dbi_exists(iter); gc = dbi_next(iter)) { *(cursor++) = gc->castle_id; } @@ -2015,7 +1973,7 @@ void guild_castle_reconnect(int castle_id, int index, int value) static struct linkdb_node *gc_save_pending = NULL; if (castle_id < 0) { // char-server reconnected - linkdb_foreach(&gc_save_pending, guild_castle_reconnect_sub); + linkdb_foreach(&gc_save_pending, guild->castle_reconnect_sub); linkdb_final(&gc_save_pending); } else { int *data; @@ -2107,7 +2065,7 @@ int guild_checkcastles(struct guild *g) { int nb_cas = 0; struct guild_castle* gc = NULL; - DBIterator *iter = db_iterator(castle_db); + DBIterator *iter = db_iterator(guild->castle_db); for (gc = dbi_first(iter); dbi_exists(iter); gc = dbi_next(iter)) { if (gc->guild_id == g->guild_id) { @@ -2133,38 +2091,38 @@ void guild_flag_add(struct npc_data *nd) { int i; /* check */ - for( i = 0; i < guild_flags_count; i++ ) { - if( guild_flags[i] && guild_flags[i]->bl.id == nd->bl.id ) { + for( i = 0; i < guild->flags_count; i++ ) { + if( guild->flags[i] && guild->flags[i]->bl.id == nd->bl.id ) { return;/* exists, most likely updated the id. */ } } - i = guild_flags_count;/* save the current slot */ + i = guild->flags_count;/* save the current slot */ /* add */ - RECREATE(guild_flags,struct npc_data*,++guild_flags_count); + RECREATE(guild->flags,struct npc_data*,++guild->flags_count); /* save */ - guild_flags[i] = nd; + guild->flags[i] = nd; } void guild_flag_remove(struct npc_data *nd) { int i, cursor; - if( guild_flags_count == 0 ) + if( guild->flags_count == 0 ) return; /* find it */ - for( i = 0; i < guild_flags_count; i++ ) { - if( guild_flags[i] && guild_flags[i]->bl.id == nd->bl.id ) {/* found */ - guild_flags[i] = NULL; + for( i = 0; i < guild->flags_count; i++ ) { + if( guild->flags[i] && guild->flags[i]->bl.id == nd->bl.id ) {/* found */ + guild->flags[i] = NULL; break; } } /* compact list */ - for( i = 0, cursor = 0; i < guild_flags_count; i++ ) { - if( guild_flags[i] == NULL ) + for( i = 0, cursor = 0; i < guild->flags_count; i++ ) { + if( guild->flags[i] == NULL ) continue; if( cursor != i ) { - memmove(&guild_flags[cursor], &guild_flags[i], sizeof(struct npc_data*)); + memmove(&guild->flags[cursor], &guild->flags[i], sizeof(struct npc_data*)); } cursor++; @@ -2175,7 +2133,7 @@ void guild_flag_remove(struct npc_data *nd) { /** * @see DBApply */ -static int eventlist_db_final(DBKey key, DBData *data, va_list ap) { +int eventlist_db_final(DBKey key, DBData *data, va_list ap) { struct eventlist *next = NULL; struct eventlist *current = DB->data2ptr(data); while (current != NULL) { @@ -2189,15 +2147,15 @@ static int eventlist_db_final(DBKey key, DBData *data, va_list ap) { /** * @see DBApply */ -static int guild_expcache_db_final(DBKey key, DBData *data, va_list ap) { - ers_free(expcache_ers, DB->data2ptr(data)); +int guild_expcache_db_final(DBKey key, DBData *data, va_list ap) { + ers_free(guild->expcache_ers, DB->data2ptr(data)); return 0; } /** * @see DBApply */ -static int guild_castle_db_final(DBKey key, DBData *data, va_list ap) { +int guild_castle_db_final(DBKey key, DBData *data, va_list ap) { struct guild_castle* gc = DB->data2ptr(data); if( gc->temp_guardians ) aFree(gc->temp_guardians); @@ -2208,36 +2166,33 @@ static int guild_castle_db_final(DBKey key, DBData *data, va_list ap) { /* called when scripts are reloaded/unloaded */ void guild_flags_clear(void) { int i; - for( i = 0; i < guild_flags_count; i++ ) { - if( guild_flags[i] ) - guild_flags[i] = NULL; + for( i = 0; i < guild->flags_count; i++ ) { + if( guild->flags[i] ) + guild->flags[i] = NULL; } - guild_flags_count = 0; + guild->flags_count = 0; } void do_init_guild(void) { - guild_db = idb_alloc(DB_OPT_RELEASE_DATA); - castle_db = idb_alloc(DB_OPT_BASE); - guild_expcache_db = idb_alloc(DB_OPT_BASE); - guild_infoevent_db = idb_alloc(DB_OPT_BASE); - expcache_ers = ers_new(sizeof(struct guild_expcache),"guild.c::expcache_ers",ERS_OPT_NONE); - - guild_flags_count = 0; - - sv->readdb(map->db_path, "castle_db.txt", ',', 4, 5, -1, &guild_read_castledb); + guild->db = idb_alloc(DB_OPT_RELEASE_DATA); + guild->castle_db = idb_alloc(DB_OPT_BASE); + guild->expcache_db = idb_alloc(DB_OPT_BASE); + guild->infoevent_db = idb_alloc(DB_OPT_BASE); + guild->expcache_ers = ers_new(sizeof(struct guild_expcache),"guild.c::expcache_ers",ERS_OPT_NONE); + + sv->readdb(map->db_path, "castle_db.txt", ',', 4, 5, -1, guild->read_castledb); - memset(guild_skill_tree,0,sizeof(guild_skill_tree)); - sv->readdb(map->db_path, "guild_skill_tree.txt", ',', 2+MAX_GUILD_SKILL_REQUIRE*2, 2+MAX_GUILD_SKILL_REQUIRE*2, -1, &guild_read_guildskill_tree_db); //guild skill tree [Komurka] + sv->readdb(map->db_path, "guild_skill_tree.txt", ',', 2+MAX_GUILD_SKILL_REQUIRE*2, 2+MAX_GUILD_SKILL_REQUIRE*2, -1, guild->read_guildskill_tree_db); //guild skill tree [Komurka] - timer->add_func_list(guild_payexp_timer,"guild_payexp_timer"); - timer->add_func_list(guild_send_xy_timer, "guild_send_xy_timer"); - timer->add_interval(timer->gettick()+GUILD_PAYEXP_INVERVAL,guild_payexp_timer,0,0,GUILD_PAYEXP_INVERVAL); - timer->add_interval(timer->gettick()+GUILD_SEND_XY_INVERVAL,guild_send_xy_timer,0,0,GUILD_SEND_XY_INVERVAL); + timer->add_func_list(guild->payexp_timer,"guild_payexp_timer"); + timer->add_func_list(guild->send_xy_timer, "guild_send_xy_timer"); + timer->add_interval(timer->gettick()+GUILD_PAYEXP_INVERVAL,guild->payexp_timer,0,0,GUILD_PAYEXP_INVERVAL); + timer->add_interval(timer->gettick()+GUILD_SEND_XY_INVERVAL,guild->send_xy_timer,0,0,GUILD_SEND_XY_INVERVAL); } void do_final_guild(void) { - DBIterator *iter = db_iterator(guild_db); + DBIterator *iter = db_iterator(guild->db); struct guild *g; for( g = dbi_first(iter); dbi_exists(iter); g = dbi_next(iter) ) { @@ -2251,13 +2206,14 @@ void do_final_guild(void) { dbi_destroy(iter); - db_destroy(guild_db); - castle_db->destroy(castle_db,guild_castle_db_final); - guild_expcache_db->destroy(guild_expcache_db,guild_expcache_db_final); - guild_infoevent_db->destroy(guild_infoevent_db,eventlist_db_final); - ers_destroy(expcache_ers); - - aFree(guild_flags);/* never empty; created on boot */ + db_destroy(guild->db); + guild->castle_db->destroy(guild->castle_db,guild->castle_db_final); + guild->expcache_db->destroy(guild->expcache_db,guild->expcache_db_final); + guild->infoevent_db->destroy(guild->infoevent_db,guild->eventlist_db_final); + ers_destroy(guild->expcache_ers); + + if( guild->flags ) + aFree(guild->flags); } void guild_defaults(void) { guild = &guild_s; @@ -2265,6 +2221,18 @@ void guild_defaults(void) { guild->init = do_init_guild; guild->final = do_final_guild; /* */ + guild->db = NULL; + guild->castle_db = NULL; + guild->expcache_db = NULL; + guild->infoevent_db = NULL; + /* */ + guild->expcache_ers = NULL; + /* */ + memset(guild->skill_tree, 0, sizeof(guild->skill_tree)); + /* guild flags cache */ + guild->flags = NULL; + guild->flags_count = 0; + /* */ guild->skill_get_max = guild_skill_get_max; /* */ guild->checkskill = guild_checkskill; @@ -2341,4 +2309,22 @@ void guild_defaults(void) { guild->flags_clear = guild_flags_clear; /* guild aura */ guild->aura_refresh = guild_guildaura_refresh; + /* */ + guild->payexp_timer = guild_payexp_timer; + guild->sd_check = guild_sd_check; + guild->read_guildskill_tree_db = guild_read_guildskill_tree_db; + guild->read_castledb = guild_read_castledb; + guild->payexp_timer_sub = guild_payexp_timer_sub; + guild->send_xy_timer_sub = guild_send_xy_timer_sub; + guild->send_xy_timer = guild_send_xy_timer; + guild->create_expcache = create_expcache; + guild->eventlist_db_final = eventlist_db_final; + guild->expcache_db_final = guild_expcache_db_final; + guild->castle_db_final = guild_castle_db_final; + guild->broken_sub = guild_broken_sub; + guild->castle_broken_sub = castle_guild_broken_sub; + guild->makemember = guild_makemember; + guild->check_member = guild_check_member; + guild->get_alliance_count = guild_get_alliance_count; + guild->castle_reconnect_sub = guild_castle_reconnect_sub; } diff --git a/src/map/guild.h b/src/map/guild.h index 1f61df09e..566ca7ce4 100644 --- a/src/map/guild.h +++ b/src/map/guild.h @@ -6,14 +6,32 @@ #define _GUILD_H_ //#include "../common/mmo.h" +#include "map.h" // NAME_LENGTH + +/** + * Declarations + **/ struct guild; struct guild_member; struct guild_position; struct guild_castle; -#include "map.h" // NAME_LENGTH struct map_session_data; struct mob_data; +/** + * Defines + **/ +#define GUILD_SEND_XY_INVERVAL 5000 // Interval of sending coordinates and HP +#define GUILD_PAYEXP_INVERVAL 10000 //Interval (maximum survival time of the cache, in milliseconds) +#define MAX_GUILD_SKILL_REQUIRE 5 + +/** + * Structures + **/ +struct eventlist { + char name[EVENT_NAME_LENGTH]; + struct eventlist *next; +}; //For quick linking to a guardian's info. [Skotlex] struct guardian_data { int number; //0-MAX_GUARDIANS-1 = Guardians. MAX_GUARDIANS = Emperium. @@ -23,11 +41,36 @@ struct guardian_data { char guild_name[NAME_LENGTH]; struct guild_castle* castle; }; +struct guild_expcache { + int guild_id, account_id, char_id; + uint64 exp; +}; +struct s_guild_skill_tree { + int id; + int max; + struct { + short id; + short lv; + } need[MAX_GUILD_SKILL_REQUIRE]; +}; + struct guild_interface { void (*init) (void); void (*final) (void); /* */ + DBMap* db; // int guild_id -> struct guild* + DBMap* castle_db; // int castle_id -> struct guild_castle* + DBMap* expcache_db; // int char_id -> struct guild_expcache* + DBMap* infoevent_db; // int guild_id -> struct eventlist* + /* */ + struct eri *expcache_ers; //For handling of guild exp payment. + /* */ + struct s_guild_skill_tree skill_tree[MAX_GUILDSKILL]; + /* guild flags cache */ + struct npc_data **flags; + unsigned short flags_count; + /* */ int (*skill_get_max) (int id); /* */ int (*checkskill) (struct guild *g,int id); @@ -104,6 +147,24 @@ struct guild_interface { void (*flags_clear) (void); /* guild aura */ void (*aura_refresh) (struct map_session_data *sd, uint16 skill_id, uint16 skill_lv); + /* */ + int (*payexp_timer) (int tid, unsigned int tick, int id, intptr_t data); + TBL_PC* (*sd_check) (int guild_id, int account_id, int char_id); + bool (*read_guildskill_tree_db) (char* split[], int columns, int current); + bool (*read_castledb) (char* str[], int columns, int current); + int (*payexp_timer_sub) (DBKey key, DBData *data, va_list ap); + int (*send_xy_timer_sub) (DBKey key, DBData *data, va_list ap); + int (*send_xy_timer) (int tid, unsigned int tick, int id, intptr_t data); + DBData (*create_expcache) (DBKey key, va_list args); + int (*eventlist_db_final) (DBKey key, DBData *data, va_list ap); + int (*expcache_db_final) (DBKey key, DBData *data, va_list ap); + int (*castle_db_final) (DBKey key, DBData *data, va_list ap); + int (*broken_sub) (DBKey key, DBData *data, va_list ap); + int (*castle_broken_sub) (DBKey key, DBData *data, va_list ap); + void (*makemember) (struct guild_member *m,struct map_session_data *sd); + int (*check_member) (struct guild *g); + int (*get_alliance_count) (struct guild *g,int flag); + void (*castle_reconnect_sub) (void *key, void *data, va_list ap); }; struct guild_interface *guild; |