summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFlavioJS <FlavioJS@54d463be-8e91-2dee-dedb-b68131a5f0ec>2008-05-02 17:14:00 +0000
committerFlavioJS <FlavioJS@54d463be-8e91-2dee-dedb-b68131a5f0ec>2008-05-02 17:14:00 +0000
commitdf801754db61508ccb447b26f6b2b2aa9a304f9e (patch)
treec92a997f8327b0256fe665c62ca1b2b35346af18 /src
parente67711acbe9d29a2feb9293fccc72cd15603ee76 (diff)
downloadhercules-df801754db61508ccb447b26f6b2b2aa9a304f9e.tar.gz
hercules-df801754db61508ccb447b26f6b2b2aa9a304f9e.tar.bz2
hercules-df801754db61508ccb447b26f6b2b2aa9a304f9e.tar.xz
hercules-df801754db61508ccb447b26f6b2b2aa9a304f9e.zip
* Changes to map_foreach* functions:
- removed the unecessary use of va_copy in map_foreachpc - applied the same function pattern to map_foreachmob and map_foreachiddb - created map_foreachnpc - extended the behaviour of map_foreach* functions to stop iterating when func returns -1 (also added missing changelog entries from ultramage >.>) git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@12684 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src')
-rw-r--r--src/map/map.c90
-rw-r--r--src/map/map.h5
-rw-r--r--src/map/mob.c5
-rw-r--r--src/map/npc.c9
-rw-r--r--src/map/status.c3
5 files changed, 80 insertions, 32 deletions
diff --git a/src/map/map.c b/src/map/map.c
index 1e7a48af7..fc9b41fde 100644
--- a/src/map/map.c
+++ b/src/map/map.c
@@ -1739,43 +1739,93 @@ struct block_list * map_id2bl(int id)
return bl;
}
+/// Applies func to all the players in the db.
+/// Stops iterating if func returns -1.
void map_foreachpc(int (*func)(struct map_session_data* sd, va_list args), ...)
{
DBIterator* iter;
struct map_session_data* sd;
- va_list args, argscopy;
- va_start(args,func);
iter = pc_db->iterator(pc_db);
for( sd = (struct map_session_data*)iter->first(iter,NULL); iter->exists(iter); sd = (struct map_session_data*)iter->next(iter,NULL) )
{
- va_copy(argscopy,args);
- func(sd, argscopy);
- va_end(argscopy);
+ va_list args;
+ int ret;
+
+ va_start(args, func);
+ ret = func(sd, args);
+ va_end(args);
+ if( ret == -1 )
+ break;// stop iterating
}
iter->destroy(iter);
- va_end(args);
}
-void map_foreachmob(int (*func)(DBKey,void*,va_list),...)
+/// Applies func to all the mobs in the db.
+/// Stops iterating if func returns -1.
+void map_foreachmob(int (*func)(struct mob_data* md, va_list args), ...)
{
- va_list ap;
- va_start(ap,func);
- mobid_db->vforeach(mobid_db,func,ap);
- va_end(ap);
+ DBIterator* iter;
+ struct mob_data* md;
+
+ iter = db_iterator(mobid_db);
+ for( md = (struct mob_data*)dbi_first(iter); dbi_exists(iter); md = (struct mob_data*)dbi_next(iter) )
+ {
+ va_list args;
+ int ret;
+
+ va_start(args, func);
+ ret = func(md, args);
+ va_end(args);
+ if( ret == -1 )
+ break;// stop iterating
+ }
}
-/*==========================================
- * id_db?の全てにfuncを?行
- *------------------------------------------*/
-int map_foreachiddb(int (*func)(DBKey,void*,va_list),...)
+/// Applies func to all the npcs in the db.
+/// Stops iterating if func returns -1.
+void map_foreachnpc(int (*func)(struct npc_data* nd, va_list args), ...)
{
- va_list ap;
+ DBIterator* iter;
+ struct block_list* bl;
- va_start(ap,func);
- id_db->vforeach(id_db,func,ap);
- va_end(ap);
- return 0;
+ iter = db_iterator(id_db);
+ for( bl = (struct block_list*)dbi_first(iter); dbi_exists(iter); bl = (struct block_list*)dbi_next(iter) )
+ {
+ if( bl->type == BL_NPC )
+ {
+ struct npc_data* nd = (struct npc_data*)bl;
+ va_list args;
+ int ret;
+
+ va_start(args, func);
+ ret = func(nd, args);
+ va_end(args);
+ if( ret == -1 )
+ break;// stop iterating
+ }
+ }
+}
+
+/// Applies func to everything in the db.
+/// Stops iterating if func returns -1.
+void map_foreachiddb(int (*func)(struct block_list* bl, va_list args), ...)
+{
+ DBIterator* iter;
+ struct block_list* bl;
+
+ iter = db_iterator(id_db);
+ for( bl = (struct block_list*)dbi_first(iter); dbi_exists(iter); bl = (struct block_list*)dbi_next(iter) )
+ {
+ va_list args;
+ int ret;
+
+ va_start(args, func);
+ ret = func(bl, args);
+ va_end(args);
+ if( ret == -1 )
+ break;// stop iterating
+ }
}
/// Iterator.
diff --git a/src/map/map.h b/src/map/map.h
index 5bbd41986..46cd966e0 100644
--- a/src/map/map.h
+++ b/src/map/map.h
@@ -563,8 +563,9 @@ int map_eraseallipport(void);
void map_addiddb(struct block_list *);
void map_deliddb(struct block_list *bl);
void map_foreachpc(int (*func)(struct map_session_data* sd, va_list args), ...);
-void map_foreachmob(int (*func)(DBKey,void*,va_list),...);
-int map_foreachiddb(int (*)(DBKey,void*,va_list),...);
+void map_foreachmob(int (*func)(struct mob_data* md, va_list args), ...);
+void map_foreachnpc(int (*func)(struct npc_data* bl, va_list args), ...);
+void map_foreachiddb(int (*func)(struct block_list* bl, va_list args), ...);
struct map_session_data * map_nick2sd(const char*);
/// Bitfield of flags for the iterator.
diff --git a/src/map/mob.c b/src/map/mob.c
index b8d833227..d50f9ddd0 100644
--- a/src/map/mob.c
+++ b/src/map/mob.c
@@ -1666,9 +1666,8 @@ static int mob_ai_sub_foreachclient(struct map_session_data *sd,va_list ap)
/*==========================================
* Negligent mode MOB AI (PC is not in near)
*------------------------------------------*/
-static int mob_ai_sub_lazy(DBKey key,void * data,va_list ap)
+static int mob_ai_sub_lazy(struct mob_data *md, va_list args)
{
- struct mob_data *md = (struct mob_data *)data;
unsigned int tick;
int mode;
@@ -1677,7 +1676,7 @@ static int mob_ai_sub_lazy(DBKey key,void * data,va_list ap)
if(md->bl.prev == NULL)
return 0;
- tick=va_arg(ap,unsigned int);
+ tick = va_arg(args,unsigned int);
if (md->nd || (battle_config.mob_ai&0x20 && map[md->bl.m].users>0))
return (int)mob_ai_sub_hard(md, tick);
diff --git a/src/map/npc.c b/src/map/npc.c
index 683be8620..24fe8787b 100644
--- a/src/map/npc.c
+++ b/src/map/npc.c
@@ -1311,15 +1311,14 @@ static int npc_unload_ev(DBKey key, void* data, va_list ap)
return 0;
}
-static int npc_unload_dup_sub(DBKey key, void* data, va_list ap)
+static int npc_unload_dup_sub(struct npc_data* nd, va_list args)
{
- struct npc_data *nd = (struct npc_data *)data;
int src_id;
- if(nd->bl.type!=BL_NPC || nd->subtype != SCRIPT)
+ if( nd->subtype != SCRIPT )
return 0;
- src_id=va_arg(ap,int);
+ src_id = va_arg(args, int);
if (nd->u.scr.src_id == src_id)
npc_unload(nd);
return 0;
@@ -1328,7 +1327,7 @@ static int npc_unload_dup_sub(DBKey key, void* data, va_list ap)
//Removes all npcs that are duplicates of the passed one. [Skotlex]
void npc_unload_duplicates(struct npc_data* nd)
{
- map_foreachiddb(npc_unload_dup_sub,nd->bl.id);
+ map_foreachnpc(npc_unload_dup_sub,nd->bl.id);
}
int npc_unload(struct npc_data* nd)
diff --git a/src/map/status.c b/src/map/status.c
index 6f170bb96..c30833314 100644
--- a/src/map/status.c
+++ b/src/map/status.c
@@ -7228,9 +7228,8 @@ int status_change_clear_buffs (struct block_list* bl, int type)
//Natural regen related stuff.
static unsigned int natural_heal_prev_tick,natural_heal_diff_tick;
-static int status_natural_heal(DBKey key,void * data,va_list ap)
+static int status_natural_heal(struct block_list* bl, va_list args)
{
- struct block_list *bl = (struct block_list*)data;
struct regen_data *regen;
struct status_data *status;
struct status_change *sc;