summaryrefslogtreecommitdiff
path: root/src/map/party.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/map/party.c')
-rw-r--r--src/map/party.c147
1 files changed, 69 insertions, 78 deletions
diff --git a/src/map/party.c b/src/map/party.c
index db4b88f7d..29ab5044c 100644
--- a/src/map/party.c
+++ b/src/map/party.c
@@ -1,5 +1,6 @@
-// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
-// For more information, see LICENCE in the main folder
+// Copyright (c) Hercules Dev Team, licensed under GNU GPL.
+// See the LICENSE file
+// Portions Copyright (c) Athena Dev Teams
#include "../common/cbasetypes.h"
#include "../common/timer.h"
@@ -29,20 +30,13 @@
#include <string.h>
-static DBMap* party_db; // int party_id -> struct party_data* (releases data)
-static DBMap* party_booking_db; // int char_id -> struct party_booking_ad_info* (releases data) // Party Booking [Spiria]
-static unsigned long party_booking_nextid = 1;
-
struct party_interface party_s;
-int party_send_xy_timer(int tid, unsigned int tick, int id, intptr_t data);
-
/*==========================================
* Fills the given party_member structure according to the sd provided.
* Used when creating/adding people to a party. [Skotlex]
*------------------------------------------*/
-static void party_fill_member(struct party_member* member, struct map_session_data* sd, unsigned int leader)
-{
+void party_fill_member(struct party_member* member, struct map_session_data* sd, unsigned int leader) {
member->account_id = sd->status.account_id;
member->char_id = sd->status.char_id;
safestrncpy(member->name, sd->status.name, NAME_LENGTH);
@@ -54,8 +48,7 @@ static void party_fill_member(struct party_member* member, struct map_session_da
}
/// Get the member_id of a party member.
/// Return -1 if not in party.
-int party_getmemberid(struct party_data* p, struct map_session_data* sd)
-{
+int party_getmemberid(struct party_data* p, struct map_session_data* sd) {
int member_id;
nullpo_retr(-1, p);
if( sd == NULL )
@@ -68,7 +61,6 @@ int party_getmemberid(struct party_data* p, struct map_session_data* sd)
return member_id;
}
-
/*==========================================
* Request an available sd of this party
*------------------------------------------*/
@@ -83,8 +75,7 @@ struct map_session_data* party_getavailablesd(struct party_data *p)
/*==========================================
* Retrieves and validates the sd pointer for this party member [Skotlex]
*------------------------------------------*/
-
-static TBL_PC* party_sd_check(int party_id, int account_id, int char_id) {
+TBL_PC* party_sd_check(int party_id, int account_id, int char_id) {
TBL_PC* sd = map->id2sd(account_id);
if (!(sd && sd->status.char_id == char_id))
@@ -108,30 +99,12 @@ int party_db_final(DBKey key, DBData *data, va_list ap) {
return 0;
}
-/*==========================================
- * Destructor
- * Called in map shutdown, cleanup var
- *------------------------------------------*/
-void do_final_party(void)
-{
- party_db->destroy(party_db,party_db_final);
- party_booking_db->destroy(party_booking_db,NULL); // Party Booking [Spiria]
-}
-// Constructor, init vars
-void do_init_party(void)
-{
- party_db = idb_alloc(DB_OPT_RELEASE_DATA);
- party_booking_db = idb_alloc(DB_OPT_RELEASE_DATA); // Party Booking [Spiria]
- timer->add_func_list(party_send_xy_timer, "party_send_xy_timer");
- timer->add_interval(timer->gettick()+battle_config.party_update_interval, party_send_xy_timer, 0, 0, battle_config.party_update_interval);
-}
-
/// Party data lookup using party id.
struct party_data* party_search(int party_id)
{
if(!party_id)
return NULL;
- return (struct party_data*)idb_get(party_db,party_id);
+ return (struct party_data*)idb_get(party->db,party_id);
}
/// Party data lookup using party name.
@@ -139,7 +112,7 @@ struct party_data* party_searchname(const char* str)
{
struct party_data* p;
- DBIterator *iter = db_iterator(party_db);
+ DBIterator *iter = db_iterator(party->db);
for( p = dbi_first(iter); dbi_exists(iter); p = dbi_next(iter) )
{
if( strncmpi(p->party.name,str,NAME_LENGTH) == 0 )
@@ -171,7 +144,7 @@ int party_create(struct map_session_data *sd,char *name,int item,int item2)
sd->party_creating = true;
- party_fill_member(&leader, sd, 1);
+ party->fill_member(&leader, sd, 1);
intif->create_party(&leader,name,item,item2);
return 0;
@@ -219,29 +192,27 @@ int party_recv_noinfo(int party_id, int char_id) {
return 0;
}
-static void party_check_state(struct party_data *p)
-{
+void party_check_state(struct party_data *p) {
int i;
memset(&p->state, 0, sizeof(p->state));
- for (i = 0; i < MAX_PARTY; i ++)
- {
+ for (i = 0; i < MAX_PARTY; i ++) {
if (!p->party.member[i].online) continue; //Those not online shouldn't aport to skill usage and all that.
switch (p->party.member[i].class_) {
- case JOB_MONK:
- case JOB_BABY_MONK:
- case JOB_CHAMPION:
- p->state.monk = 1;
- break;
- case JOB_STAR_GLADIATOR:
- p->state.sg = 1;
- break;
- case JOB_SUPER_NOVICE:
- case JOB_SUPER_BABY:
- p->state.snovice = 1;
- break;
- case JOB_TAEKWON:
- p->state.tk = 1;
- break;
+ case JOB_MONK:
+ case JOB_BABY_MONK:
+ case JOB_CHAMPION:
+ p->state.monk = 1;
+ break;
+ case JOB_STAR_GLADIATOR:
+ p->state.sg = 1;
+ break;
+ case JOB_SUPER_NOVICE:
+ case JOB_SUPER_BABY:
+ p->state.snovice = 1;
+ break;
+ case JOB_TAEKWON:
+ p->state.tk = 1;
+ break;
}
}
}
@@ -260,7 +231,7 @@ int party_recv_info(struct party* sp, int char_id)
nullpo_ret(sp);
- p = (struct party_data*)idb_get(party_db, sp->party_id);
+ p = (struct party_data*)idb_get(party->db, sp->party_id);
if( p != NULL ) {// diff members
for( member_id = 0; member_id < MAX_PARTY; ++member_id ) {
member = &p->party.member[member_id];
@@ -289,7 +260,7 @@ int party_recv_info(struct party* sp, int char_id)
CREATE(p, struct party_data, 1);
p->instance = NULL;
p->instances = 0;
- idb_put(party_db, sp->party_id, p);
+ idb_put(party->db, sp->party_id, p);
}
while( removed_count > 0 ) {// no longer in party
member_id = removed[--removed_count];
@@ -305,9 +276,9 @@ int party_recv_info(struct party* sp, int char_id)
member = &p->party.member[member_id];
if ( member->char_id == 0 )
continue;// empty
- p->data[member_id].sd = party_sd_check(sp->party_id, member->account_id, member->char_id);
+ p->data[member_id].sd = party->sd_check(sp->party_id, member->account_id, member->char_id);
}
- party_check_state(p);
+ party->check_state(p);
while( added_count > 0 ) { // new in party
member_id = added[--added_count];
sd = p->data[member_id].sd;
@@ -412,7 +383,7 @@ void party_reply_invite(struct map_session_data *sd,int party_id,int flag) {
if( flag == 1 && !sd->party_creating && !sd->party_joining )
{// accepted and allowed
sd->party_joining = true;
- party_fill_member(&member, sd, 0);
+ party->fill_member(&member, sd, 0);
intif->party_addmember(sd->party_invite, &member);
}
else
@@ -571,7 +542,7 @@ int party_member_withdraw(int party_id, int account_id, int char_id)
memset(&p->party.member[i], 0, sizeof(p->party.member[0]));
memset(&p->data[i], 0, sizeof(p->data[0]));
p->party.count--;
- party_check_state(p);
+ party->check_state(p);
}
}
@@ -615,7 +586,7 @@ int party_broken(int party_id)
}
}
- idb_remove(party_db,party_id);
+ idb_remove(party->db,party_id);
return 0;
}
@@ -722,7 +693,7 @@ int party_recv_movemap(int party_id,int account_id,int char_id, unsigned short m
m->online = online;
m->lv = lv;
//Check if they still exist on this map server
- p->data[i].sd = party_sd_check(party_id, account_id, char_id);
+ p->data[i].sd = party->sd_check(party_id, account_id, char_id);
clif->party_info(p,NULL);
return 0;
@@ -864,7 +835,7 @@ int party_send_xy_timer(int tid, unsigned int tick, int id, intptr_t data)
{
struct party_data* p;
- DBIterator *iter = db_iterator(party_db);
+ DBIterator *iter = db_iterator(party->db);
// for each existing party,
for( p = dbi_first(iter); dbi_exists(iter); p = dbi_next(iter) )
{
@@ -1111,11 +1082,10 @@ int party_foreachsamemap(int (*func)(struct block_list*,va_list),struct map_sess
* Party Booking in KRO [Spiria]
*------------------------------------------*/
-static struct party_booking_ad_info* create_party_booking_data(void)
-{
+struct party_booking_ad_info* create_party_booking_data(void) {
struct party_booking_ad_info *pb_ad;
CREATE(pb_ad, struct party_booking_ad_info, 1);
- pb_ad->index = party_booking_nextid++;
+ pb_ad->index = party->booking_nextid++;
return pb_ad;
}
@@ -1130,12 +1100,12 @@ void party_booking_register(struct map_session_data *sd, short level, const char
int i;
#endif
- pb_ad = (struct party_booking_ad_info*)idb_get(party_booking_db, sd->status.char_id);
+ pb_ad = (struct party_booking_ad_info*)idb_get(party->booking_db, sd->status.char_id);
if( pb_ad == NULL )
{
- pb_ad = create_party_booking_data();
- idb_put(party_booking_db, sd->status.char_id, pb_ad);
+ pb_ad = party->create_booking_data();
+ idb_put(party->booking_db, sd->status.char_id, pb_ad);
}
else
{// already registered
@@ -1172,7 +1142,7 @@ void party_booking_update(struct map_session_data *sd, const char *notice)
#endif
struct party_booking_ad_info *pb_ad;
- pb_ad = (struct party_booking_ad_info*)idb_get(party_booking_db, sd->status.char_id);
+ pb_ad = (struct party_booking_ad_info*)idb_get(party->booking_db, sd->status.char_id);
if( pb_ad == NULL )
return;
@@ -1206,7 +1176,7 @@ void party_booking_search(struct map_session_data *sd, short level, short mapid,
int count = 0;
struct party_booking_ad_info* result_list[PARTY_BOOKING_RESULTS];
bool more_result = false;
- DBIterator* iter = db_iterator(party_booking_db);
+ DBIterator* iter = db_iterator(party->booking_db);
memset(result_list, 0, sizeof(result_list));
@@ -1250,14 +1220,24 @@ bool party_booking_delete(struct map_session_data *sd)
{
struct party_booking_ad_info* pb_ad;
- if((pb_ad = (struct party_booking_ad_info*)idb_get(party_booking_db, sd->status.char_id))!=NULL)
+ if((pb_ad = (struct party_booking_ad_info*)idb_get(party->booking_db, sd->status.char_id))!=NULL)
{
clif->PartyBookingDeleteNotify(sd, pb_ad->index);
- idb_remove(party_booking_db,sd->status.char_id);
+ idb_remove(party->booking_db,sd->status.char_id);
}
return true;
}
-
+void do_final_party(void) {
+ party->db->destroy(party->db,party->db_final);
+ db_destroy(party->booking_db); // Party Booking [Spiria]
+}
+// Constructor, init vars
+void do_init_party(void) {
+ party->db = idb_alloc(DB_OPT_RELEASE_DATA);
+ party->booking_db = idb_alloc(DB_OPT_RELEASE_DATA); // Party Booking [Spiria]
+ timer->add_func_list(party->send_xy_timer, "party_send_xy_timer");
+ timer->add_interval(timer->gettick()+battle_config.party_update_interval, party->send_xy_timer, 0, 0, battle_config.party_update_interval);
+}
/*=====================================
* Default Functions : party.h
* Generated by HerculesInterfaceMaker
@@ -1266,10 +1246,14 @@ bool party_booking_delete(struct map_session_data *sd)
void party_defaults(void) {
party = &party_s;
+ /* */
+ party->db = NULL;
+ party->booking_db = NULL;
+ party->booking_nextid = 1;
/* funcs */
-
- party->do_init_party = do_init_party;
- party->do_final_party = do_final_party;
+ party->init = do_init_party;
+ party->final = do_final_party;
+ /* */
party->search = party_search;
party->searchname = party_searchname;
party->getmemberid = party_getmemberid;
@@ -1307,4 +1291,11 @@ void party_defaults(void) {
party->booking_update = party_booking_update;
party->booking_search = party_booking_search;
party->booking_delete = party_booking_delete;
+ party->foreachsamemap = party_foreachsamemap;
+ party->send_xy_timer = party_send_xy_timer;
+ party->fill_member = party_fill_member;
+ party->sd_check = party_sd_check;
+ party->check_state = party_check_state;
+ party->create_booking_data = create_party_booking_data;
+ party->db_final = party_db_final;
}