From 5514b1d63acfbe0fa0e51a855679769d4f013e35 Mon Sep 17 00:00:00 2001 From: ultramage Date: Sat, 26 Jan 2008 09:44:10 +0000 Subject: Some random cleaning git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@12141 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/map/map.c | 59 ++++++++++++++++++----------------------------------------- 1 file changed, 18 insertions(+), 41 deletions(-) (limited to 'src/map/map.c') 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;ibl,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; } -- cgit v1.2.3-60-g2f50