summaryrefslogtreecommitdiff
path: root/src/map/guild.c
diff options
context:
space:
mode:
authorgepard1984 <gepard1984@54d463be-8e91-2dee-dedb-b68131a5f0ec>2012-03-13 14:46:28 +0000
committergepard1984 <gepard1984@54d463be-8e91-2dee-dedb-b68131a5f0ec>2012-03-13 14:46:28 +0000
commitdc5babf8c3fb943a22c440f5afd6957b121926c5 (patch)
treefcf7000486b4172803ff2929c0b746013d0fb6a9 /src/map/guild.c
parentd0932858a07e7df3159003c0b920c50e2e6a1b76 (diff)
downloadhercules-dc5babf8c3fb943a22c440f5afd6957b121926c5.tar.gz
hercules-dc5babf8c3fb943a22c440f5afd6957b121926c5.tar.bz2
hercules-dc5babf8c3fb943a22c440f5afd6957b121926c5.tar.xz
hercules-dc5babf8c3fb943a22c440f5afd6957b121926c5.zip
Enhanced `DBMap` implementation to allow storing integer type data in addition to void pointers.
- Added enum for data: `int`, `unsigned int` and `void*` - Replaced generic `void*` data with `DBData` struct to hold `int`, `unsigned int` or `void*` (member of `DBNode`) - Added `db_i2data`, `db_ui2data` and `db_ptr2data` functions to cast from `int`/`uint`/`void*` to `DBData` (used in `DBMap::put()`) - Added `db_data2i`, `db_data2ui` and `db_data2ptr` functions to get `int`/`uint`/`void*` from `DBData` - Enabled statistics for new functions in `db_stats` struct - `DBCreateData` functions (used in `DBMap::ensure()`) now return `DBData` instead of `void*` - `DBApply` functions (used in `DBMap::foreach()` and `DBMap::destroy()`) now take `DBData*` as a parameter instead of `void*` - `DBMatcher` functions (used in `DBMap::getall()`) now take `DBData` as a parameter instead of `void*` - `DBReleaser` functions now take `DBData` as parameter instead of `void*` - Default releasers release data if it is `void*` (`DB_DATA_PTR`) type - `DBIterator` functions: `first()`, `last()`, `next()` and `prev()` now return `DBData*` instead of `void*` - `DBIterator::remove()` now returns `int` (1 if node was found and removed, 0 otherwise) instead of `void*` and takes an extra `DBData*` parameter for the data of removed entry - `DBMap::get()` and `DBMap::ensure()` now return `DBData*` instead of `void*` - `DBMap::remove()` and `DBMap::put()` now return `int` (1 if node already existed, 0 otherwise) instead of `void*` and take an extra `DBData*` parameter for the data of removed entry - `DBMap::put()` now takes `DBData` as parameter instead of `void*` - `DBMap::getall()` now puts data into `DBData**` buffer instead of `void**` buffer - Updated macros: - (`i`/`ui`/`str`)`db_get` and (`i`/`ui`/`str`)`db_ensure` were wrapped with `db_data2ptr` to extract data from `DBData*` that is now returned by `DBMap::get()` - added (`i`/`ui`/`str`)`db_iget` and (`i`/`ui`/`str`)`db_uiget` that get `DBData` from `DBMap` and extract `int`/`unsigned int` from it (with `db_data2i`/`db_data2ui`) - `db_put`, `idb_put`, `uidb_put` and `strdb_put` data params were wrapped with `db_ptr2data` to match new signature of `DBMap::put()` (`DBData` instead of `void*`) - added (`i`/`ui`/`str`)`db_iput` and (`i`/`ui`/`str`)`db_uiput` that put `int`/`unsigned int` into `DBMap` (first wrapping it with `DBData`) - added `NULL` in place of extra parameter for removed data in `db_remove` macros - `dbi_first`, `dbi_last`, `dbi_next` and `dbi_prev` were wrapped with `db_data2ptr` to extract data from `DBData*` that is now returned by these `DBIterator` functions - Updated `DBMap` documentation, and fixed a dozen of typos in it. - Updated rest of rA code to reflect `DBMap` changes (mostly required signature changes of `DBCreateData` and `DBApply` functions). - Fixed a bug where `DBMap::put()` would return data of a deleted entry. - Removed some unnecessary pointer casts. - Increased `showmsg.c` static buffer size to fit entire DBMap stats report. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@15682 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/map/guild.c')
-rw-r--r--src/map/guild.c84
1 files changed, 56 insertions, 28 deletions
diff --git a/src/map/guild.c b/src/map/guild.c
index deb603473..528560ee8 100644
--- a/src/map/guild.c
+++ b/src/map/guild.c
@@ -282,14 +282,17 @@ void guild_makemember(struct guild_member *m,struct map_session_data *sd)
return;
}
-// ギルドのEXPキャッシュをinter鯖にフラッシュする
-int guild_payexp_timer_sub(DBKey dataid, void *data, va_list ap)
+/**
+ * ギルドのEXPキャッシュをinter鯖にフラッシュする
+ * @see DBApply
+ */
+int guild_payexp_timer_sub(DBKey key, DBData *data, va_list ap)
{
int i;
struct guild_expcache *c;
struct guild *g;
- c = (struct guild_expcache *)data;
+ c = db_data2ptr(data);
if (
(g = guild_search(c->guild_id)) == NULL ||
@@ -318,10 +321,13 @@ int guild_payexp_timer(int tid, unsigned int tick, int id, intptr_t data)
return 0;
}
-//Taken from party_send_xy_timer_sub. [Skotlex]
-int guild_send_xy_timer_sub(DBKey key,void *data,va_list ap)
+/**
+ * Taken from party_send_xy_timer_sub. [Skotlex]
+ * @see DBApply
+ */
+int guild_send_xy_timer_sub(DBKey key, DBData *data, va_list ap)
{
- struct guild *g=(struct guild *)data;
+ struct guild *g = db_data2ptr(data);
int i;
nullpo_ret(g);
@@ -425,11 +431,13 @@ int guild_npc_request_info(int guild_id,const char *event)
if( event && *event )
{
- struct eventlist* ev;
+ struct eventlist *ev;
+ DBData prev;
ev=(struct eventlist *)aCalloc(sizeof(struct eventlist),1);
memcpy(ev->name,event,strlen(event));
- //The one in the db becomes the next event from this.
- ev->next = (struct eventlist*)idb_put(guild_infoevent_db,guild_id,ev);
+ //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))
+ ev->next = db_data2ptr(&prev);
}
return guild_request_info(guild_id);
@@ -484,7 +492,7 @@ int guild_recv_info(struct guild *sg)
{
struct guild *g,before;
int i,bm,m;
- struct eventlist *ev,*ev2;
+ DBData data;
struct map_session_data *sd;
bool guild_new = false;
@@ -558,8 +566,9 @@ int guild_recv_info(struct guild *sg)
}
// イベントの発生
- if( (ev = (struct eventlist*)idb_remove(guild_infoevent_db,sg->guild_id))!=NULL )
+ 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);
ev2=ev->next;
@@ -1122,7 +1131,10 @@ int guild_emblem_changed(int len,int guild_id,int emblem_id,const char *data)
return 0;
}
-static void* create_expcache(DBKey key, va_list args)
+/**
+ * @see DBCreateData
+ */
+static DBData create_expcache(DBKey key, va_list args)
{
struct guild_expcache *c;
struct map_session_data *sd = va_arg(args, struct map_session_data*);
@@ -1132,7 +1144,7 @@ static void* create_expcache(DBKey key, va_list args)
c->account_id = sd->status.account_id;
c->char_id = sd->status.char_id;
c->exp = 0;
- return c;
+ return db_ptr2data(c);
}
// ギルドのEXP上納
@@ -1157,7 +1169,7 @@ unsigned int guild_payexp(struct map_session_data *sd,unsigned int exp)
exp = exp * per / 100;
//Otherwise tax everything.
- c = (struct guild_expcache*)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), create_expcache, sd));
if (c->exp > UINT64_MAX - exp)
c->exp = UINT64_MAX;
@@ -1176,7 +1188,7 @@ int guild_getexp(struct map_session_data *sd,int exp)
if (sd->status.guild_id == 0 || guild_search(sd->status.guild_id) == NULL)
return 0;
- c = (struct guild_expcache*)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), create_expcache, sd));
if (c->exp > UINT64_MAX - exp)
c->exp = UINT64_MAX;
else
@@ -1507,10 +1519,14 @@ int guild_allianceack(int guild_id1,int guild_id2,int account_id1,int account_id
}
return 0;
}
-// ギルド解散通知用
-int guild_broken_sub(DBKey key,void *data,va_list ap)
+
+/**
+ * ギルド解散通知用
+ * @see DBApply
+ */
+int guild_broken_sub(DBKey key, DBData *data, va_list ap)
{
- struct guild *g=(struct guild *)data;
+ struct guild *g = db_data2ptr(data);
int guild_id=va_arg(ap,int);
int i,j;
struct map_session_data *sd=NULL;
@@ -1529,11 +1545,14 @@ int guild_broken_sub(DBKey key,void *data,va_list ap)
return 0;
}
-//Invoked on Castles when a guild is broken. [Skotlex]
-int castle_guild_broken_sub(DBKey key, void *data, va_list ap)
+/**
+ * Invoked on Castles when a guild is broken. [Skotlex]
+ * @see DBApply
+ */
+int castle_guild_broken_sub(DBKey key, DBData *data, va_list ap)
{
char name[EVENT_NAME_LENGTH];
- struct guild_castle *gc = data;
+ struct guild_castle *gc = db_data2ptr(data);
int guild_id = va_arg(ap, int);
nullpo_ret(gc);
@@ -1900,10 +1919,13 @@ bool guild_isallied(int guild_id, int guild_id2)
return( i < MAX_GUILDALLIANCE && g->alliance[i].opposition == 0 );
}
-static int eventlist_db_final(DBKey key,void *data,va_list ap)
+/**
+ * @see DBApply
+ */
+static int eventlist_db_final(DBKey key, DBData *data, va_list ap)
{
struct eventlist *next = NULL;
- struct eventlist *current = data;
+ struct eventlist *current = db_data2ptr(data);
while (current != NULL) {
next = current->next;
aFree(current);
@@ -1912,18 +1934,24 @@ static int eventlist_db_final(DBKey key,void *data,va_list ap)
return 0;
}
-static int guild_expcache_db_final(DBKey key,void *data,va_list ap)
+/**
+ * @see DBApply
+ */
+static int guild_expcache_db_final(DBKey key, DBData *data, va_list ap)
{
- ers_free(expcache_ers, data);
+ ers_free(expcache_ers, db_data2ptr(data));
return 0;
}
-static int guild_castle_db_final(DBKey key, void* data,va_list ap)
+/**
+ * @see DBApply
+ */
+static int guild_castle_db_final(DBKey key, DBData *data, va_list ap)
{
- struct guild_castle* gc = (struct guild_castle*)data;
+ struct guild_castle* gc = db_data2ptr(data);
if( gc->temp_guardians )
aFree(gc->temp_guardians);
- aFree(data);
+ aFree(gc);
return 0;
}