diff options
author | ultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2008-01-26 09:44:10 +0000 |
---|---|---|
committer | ultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2008-01-26 09:44:10 +0000 |
commit | 5514b1d63acfbe0fa0e51a855679769d4f013e35 (patch) | |
tree | 6c7e084b8b95398e2e35d9ca867a6d3e2af674e5 /src/map/map.c | |
parent | cece111a565a6d53790248eaa01bf68615d3a4b1 (diff) | |
download | hercules-5514b1d63acfbe0fa0e51a855679769d4f013e35.tar.gz hercules-5514b1d63acfbe0fa0e51a855679769d4f013e35.tar.bz2 hercules-5514b1d63acfbe0fa0e51a855679769d4f013e35.tar.xz hercules-5514b1d63acfbe0fa0e51a855679769d4f013e35.zip |
Some random cleaning
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@12141 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/map/map.c')
-rw-r--r-- | src/map/map.c | 59 |
1 files changed, 18 insertions, 41 deletions
diff --git a/src/map/map.c b/src/map/map.c index e713b7d4a..3900247fe 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -1770,17 +1770,19 @@ struct map_session_data** map_getallusers(int *users) all_count = pc_db->size(pc_db); //This is the real number of chars in the db, better use this than the actual "online" count. if (all_count < 1) all_count = 10; //Allow room for at least 10 chars. - all_sd = aCalloc(all_count, sizeof(struct map_session_data*)); //it's actually just the size of a pointer. + CREATE(all_sd, struct map_session_data*, all_count); } if (all_count < pc_db->size(pc_db)) { all_count = pc_db->size(pc_db)+10; //Give some room to prevent doing reallocs often. - all_sd = aRealloc(all_sd, all_count*sizeof(struct map_session_data*)); + RECREATE(all_sd, struct map_session_data*, all_count); } + *users = pc_db->getall(pc_db,(void**)all_sd,all_count,map_getallpc_sub); if (*users > (signed int)all_count) //Which should be impossible... *users = all_count; + return all_sd; } @@ -1819,18 +1821,18 @@ int map_foreachiddb(int (*func)(DBKey,void*,va_list),...) int map_addnpc(int m,struct npc_data *nd) { int i; - if(m<0 || m>=map_num) + if( m < 0 || m >= map_num ) return -1; - for(i=0;i<map[m].npc_num && i<MAX_NPC_PER_MAP;i++) - if(map[m].npc[i]==NULL) - break; - if(i==MAX_NPC_PER_MAP){ + + ARR_FIND( 0, MAX_NPC_PER_MAP, i, map[m].npc[i] == NULL ); + if( i == MAX_NPC_PER_MAP ) + { ShowWarning("too many NPCs in one map %s\n",map[m].name); return -1; } - if(i==map[m].npc_num){ + + if( i == map[m].npc_num ) map[m].npc_num++; - } nullpo_retr(0, nd); @@ -1841,44 +1843,19 @@ int map_addnpc(int m,struct npc_data *nd) return i; } -void map_removenpc(void) -{ - int i,m,n=0; - - for(m=0;m<map_num;m++) { - for(i=0;i<map[m].npc_num && i<MAX_NPC_PER_MAP;i++) { - if(map[m].npc[i]!=NULL) { - clif_clearunit_area(&map[m].npc[i]->bl,2); - map_delblock(&map[m].npc[i]->bl); - idb_remove(id_db,map[m].npc[i]->bl.id); - if(map[m].npc[i]->subtype==SCRIPT) { - aFree(map[m].npc[i]->u.scr.script); - aFree(map[m].npc[i]->u.scr.label_list); - } - aFree(map[m].npc[i]); - map[m].npc[i] = NULL; - n++; - } - } - } - - ShowStatus("Successfully removed and freed from memory '"CL_WHITE"%d"CL_RESET"' NPCs.\n",n); -} - /*========================================= * Dynamic Mobs [Wizputer] *-----------------------------------------*/ -// allocates a struct when it there is place free in the cache, -// and returns NULL otherwise -// -- i'll just leave the old code in case it's needed ^^; +// Stores the spawn data entry in the mob list. +// Returns the index of successful, or -1 if the list was full. int map_addmobtolist(unsigned short m, struct spawn_data *spawn) { size_t i; - for (i = 0; i < MAX_MOB_LIST_PER_MAP; i++) { - if (map[m].moblist[i] == NULL) { - map[m].moblist[i] = spawn; - return i; - } + ARR_FIND( 0, MAX_MOB_LIST_PER_MAP, i, map[m].moblist[i] == NULL ); + if( i < MAX_MOB_LIST_PER_MAP ) + { + map[m].moblist[i] = spawn; + return i; } return -1; } |