summaryrefslogtreecommitdiff
path: root/src/map/map.c
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/map/map.c
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/map/map.c')
-rw-r--r--src/map/map.c90
1 files changed, 70 insertions, 20 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.