viewing paste Unknown #384 | C

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
/// Executes 'func' for each guild member on the same map and in range (0:whole map)
int guild_foreachsamemap(int (*func)(struct block_list*,va_list),struct map_session_data *sd,int range,...)
{
    struct guild *g = NULL;
    int i,x0,y0,x1,y1;
    struct block_list *list[MAX_GUILD];
    int blockcount=0;
    int total = 0; //Return value.
    
    nullpo_ret(sd);
    
    if( (g = guild_search(sd->status.guild_id)) == NULL )
            return 0;
 
    x0=sd->bl.x-range;
    y0=sd->bl.y-range;
    x1=sd->bl.x+range;
    y1=sd->bl.y+range;
 
    if( g )
    {
        for(i=0;i<MAX_GUILD;i++)
        {
        struct map_session_data *psd = g->member[i].sd;
        if(!psd) continue;
            if(psd->bl.m!=sd->bl.m || !psd->bl.prev)
                continue;
            if(range &&
                (psd->bl.x<x0 || psd->bl.y<y0 ||
                 psd->bl.x>x1 || psd->bl.y>y1 ) )
                continue;
            list[blockcount++]=&psd->bl; 
        }
    }
    else return 0;
 
    map_freeblock_lock();
    
    for(i=0;i<blockcount;i++)
    {
        va_list ap;
        va_start(ap, range);
        total += func(list[i], ap);
        va_end(ap);
    }
 
    map_freeblock_unlock();
 
    return total;
}
Viewed 1254 times, submitted by lighta.