summaryrefslogtreecommitdiff
path: root/src/map/map.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/map/map.c')
-rw-r--r--src/map/map.c260
1 files changed, 83 insertions, 177 deletions
diff --git a/src/map/map.c b/src/map/map.c
index c57f76987..0a7bd952d 100644
--- a/src/map/map.c
+++ b/src/map/map.c
@@ -310,7 +310,6 @@ int map_addblock_sub (struct block_list *bl, int flag)
bl->prev = &bl_head;
if (bl->next) bl->next->prev = bl;
map[m].block_mob[pos] = bl;
- map[m].block_mob_count[pos]++;
} else {
if (bl->type == BL_PC && flag)
{
@@ -331,7 +330,6 @@ int map_addblock_sub (struct block_list *bl, int flag)
bl->prev = &bl_head;
if (bl->next) bl->next->prev = bl;
map[m].block[pos] = bl;
- map[m].block_count[pos]++;
}
#ifdef CELL_NOSTACK
@@ -376,12 +374,8 @@ int map_delblock_sub (struct block_list *bl, int flag)
// リストの頭なので、map[]のblock_listを更新する
if (bl->type == BL_MOB) {
map[bl->m].block_mob[b] = bl->next;
- if ((map[bl->m].block_mob_count[b]--) < 0)
- map[bl->m].block_mob_count[b] = 0;
} else {
map[bl->m].block[b] = bl->next;
- if((map[bl->m].block_count[b]--) < 0)
- map[bl->m].block_count[b] = 0;
}
} else {
bl->prev->next = bl->next;
@@ -458,41 +452,12 @@ int map_moveblock(struct block_list *bl, int x1, int y1, unsigned int tick)
}
/*==========================================
- * 周?のPC人?を?える (unused)
- *------------------------------------------*/
-int map_countnearpc (int m, int x, int y)
-{
- int bx, by, c = 0;
- struct block_list *bl=NULL;
-
- if (map[m].users == 0)
- return 0;
- for (by = y/BLOCK_SIZE-AREA_SIZE/BLOCK_SIZE-1; by<=y/BLOCK_SIZE+AREA_SIZE/BLOCK_SIZE+1; by++) {
- if (by < 0 || by >= map[m].bys)
- continue;
- for (bx = x/BLOCK_SIZE-AREA_SIZE/BLOCK_SIZE-1; bx <= x/BLOCK_SIZE+AREA_SIZE/BLOCK_SIZE+1; bx++) {
- if (bx < 0 || bx >= map[m].bxs)
- continue;
- bl = map[m].block[bx+by*map[m].bxs];
- while(bl) {
- if (bl->type == BL_PC)
- c++;
- bl = bl->next;
- }
- }
- }
-
- return c;
-}
-
-/*==========================================
* Counts specified number of objects on given cell.
*------------------------------------------*/
int map_count_oncell(int m, int x, int y, int type)
{
int bx,by;
- struct block_list *bl=NULL;
- int i,c;
+ struct block_list *bl;
int count = 0;
if (x < 0 || y < 0 || (x >= map[m].xs) || (y >= map[m].ys))
@@ -502,20 +467,15 @@ int map_count_oncell(int m, int x, int y, int type)
by = y/BLOCK_SIZE;
if (type&~BL_MOB)
- {
- bl = map[m].block[bx+by*map[m].bxs];
- c = map[m].block_count[bx+by*map[m].bxs];
- for(i=0;i<c && bl;i++,bl=bl->next)
- if(bl->x == x && bl->y == y && bl->type&type) count++;
- }
+ for( bl = map[m].block[bx+by*map[m].bxs] ; bl != NULL ; bl = bl->next )
+ if(bl->x == x && bl->y == y && bl->type&type)
+ count++;
if (type&BL_MOB)
- {
- bl = map[m].block_mob[bx+by*map[m].bxs];
- c = map[m].block_mob_count[bx+by*map[m].bxs];
- for(i=0;i<c && bl;i++,bl=bl->next)
- if(bl->x == x && bl->y == y) count++;
- }
+ for( bl = map[m].block_mob[bx+by*map[m].bxs] ; bl != NULL ; bl = bl->next )
+ if(bl->x == x && bl->y == y)
+ count++;
+
return count;
}
/*
@@ -525,23 +485,21 @@ struct skill_unit *map_find_skill_unit_oncell(struct block_list *target,int x,in
{
int m,bx,by;
struct block_list *bl;
- int i,c;
struct skill_unit *unit;
m = target->m;
if (x < 0 || y < 0 || (x >= map[m].xs) || (y >= map[m].ys))
return NULL;
+
bx = x/BLOCK_SIZE;
by = y/BLOCK_SIZE;
- bl = map[m].block[bx+by*map[m].bxs];
- c = map[m].block_count[bx+by*map[m].bxs];
- for(i=0;i<c && bl;i++,bl=bl->next){
+ for( bl = map[m].block[bx+by*map[m].bxs] ; bl != NULL ; bl = bl->next )
+ {
if (bl->x != x || bl->y != y || bl->type != BL_SKILL)
continue;
unit = (struct skill_unit *) bl;
- if (unit==out_unit || !unit->alive ||
- !unit->group || unit->group->skill_id!=skill_id)
+ if (unit==out_unit || !unit->alive || !unit->group || unit->group->skill_id!=skill_id)
continue;
if (battle_check_target(&unit->bl,target,unit->group->target_flag)>0)
return unit;
@@ -557,8 +515,8 @@ int map_foreachinrange(int (*func)(struct block_list*,va_list), struct block_lis
va_list ap;
int bx,by,m;
int returnCount =0; //total sum of returned values of func() [Skotlex]
- struct block_list *bl=NULL;
- int blockcount=bl_list_count,i,c;
+ struct block_list *bl;
+ int blockcount=bl_list_count,i;
int x0,x1,y0,y1;
va_start(ap,type);
@@ -570,11 +528,10 @@ int map_foreachinrange(int (*func)(struct block_list*,va_list), struct block_lis
if (type&~BL_MOB)
for (by = y0 / BLOCK_SIZE; by <= y1 / BLOCK_SIZE; by++) {
- for(bx=x0/BLOCK_SIZE;bx<=x1/BLOCK_SIZE;bx++){
- bl = map[m].block[bx+by*map[m].bxs];
- c = map[m].block_count[bx+by*map[m].bxs];
- for(i=0;i<c && bl;i++,bl=bl->next){
- if(bl && bl->type&type
+ for(bx = x0 / BLOCK_SIZE; bx <= x1 / BLOCK_SIZE; bx++) {
+ for( bl = map[m].block[bx+by*map[m].bxs] ; bl != NULL ; bl = bl->next )
+ {
+ if( bl->type&type
&& bl->x>=x0 && bl->x<=x1 && bl->y>=y0 && bl->y<=y1
#ifdef CIRCULAR_AREA
&& check_distance_bl(center, bl, range)
@@ -587,11 +544,9 @@ int map_foreachinrange(int (*func)(struct block_list*,va_list), struct block_lis
if(type&BL_MOB)
for(by=y0/BLOCK_SIZE;by<=y1/BLOCK_SIZE;by++){
for(bx=x0/BLOCK_SIZE;bx<=x1/BLOCK_SIZE;bx++){
- bl = map[m].block_mob[bx+by*map[m].bxs];
- c = map[m].block_mob_count[bx+by*map[m].bxs];
- for(i=0;i<c && bl;i++,bl=bl->next){
- if(bl
- && bl->x>=x0 && bl->x<=x1 && bl->y>=y0 && bl->y<=y1
+ for( bl = map[m].block_mob[bx+by*map[m].bxs] ; bl != NULL ; bl = bl->next )
+ {
+ if( bl->x>=x0 && bl->x<=x1 && bl->y>=y0 && bl->y<=y1
#ifdef CIRCULAR_AREA
&& check_distance_bl(center, bl, range)
#endif
@@ -625,12 +580,14 @@ int map_foreachinshootrange(int (*func)(struct block_list*,va_list),struct block
va_list ap;
int bx,by,m;
int returnCount =0; //total sum of returned values of func() [Skotlex]
- struct block_list *bl=NULL;
- int blockcount=bl_list_count,i,c;
+ struct block_list *bl;
+ int blockcount=bl_list_count,i;
int x0,x1,y0,y1;
+
m = center->m;
if (m < 0)
return 0;
+
va_start(ap,type);
x0 = max(center->x-range, 0);
@@ -639,12 +596,11 @@ int map_foreachinshootrange(int (*func)(struct block_list*,va_list),struct block
y1 = min(center->y+range, map[m].ys-1);
if (type&~BL_MOB)
- for (by = y0 / BLOCK_SIZE; by <= y1 / BLOCK_SIZE; by++) {
- for(bx=x0/BLOCK_SIZE;bx<=x1/BLOCK_SIZE;bx++){
- bl = map[m].block[bx+by*map[m].bxs];
- c = map[m].block_count[bx+by*map[m].bxs];
- for(i=0;i<c && bl;i++,bl=bl->next){
- if(bl && bl->type&type
+ for(by = y0 / BLOCK_SIZE; by <= y1 / BLOCK_SIZE; by++) {
+ for(bx = x0 / BLOCK_SIZE; bx <= x1 / BLOCK_SIZE; bx++) {
+ for( bl = map[m].block[bx+by*map[m].bxs] ; bl != NULL ; bl = bl->next )
+ {
+ if( bl->type&type
&& bl->x>=x0 && bl->x<=x1 && bl->y>=y0 && bl->y<=y1
#ifdef CIRCULAR_AREA
&& check_distance_bl(center, bl, range)
@@ -658,11 +614,9 @@ int map_foreachinshootrange(int (*func)(struct block_list*,va_list),struct block
if(type&BL_MOB)
for(by=y0/BLOCK_SIZE;by<=y1/BLOCK_SIZE;by++){
for(bx=x0/BLOCK_SIZE;bx<=x1/BLOCK_SIZE;bx++){
- bl = map[m].block_mob[bx+by*map[m].bxs];
- c = map[m].block_mob_count[bx+by*map[m].bxs];
- for(i=0;i<c && bl;i++,bl=bl->next){
- if(bl
- && bl->x>=x0 && bl->x<=x1 && bl->y>=y0 && bl->y<=y1
+ for( bl = map[m].block_mob[bx+by*map[m].bxs] ; bl != NULL ; bl = bl->next )
+ {
+ if( bl->x>=x0 && bl->x<=x1 && bl->y>=y0 && bl->y<=y1
#ifdef CIRCULAR_AREA
&& check_distance_bl(center, bl, range)
#endif
@@ -699,8 +653,8 @@ int map_foreachinarea(int (*func)(struct block_list*,va_list), int m, int x0, in
va_list ap;
int bx,by;
int returnCount =0; //total sum of returned values of func() [Skotlex]
- struct block_list *bl=NULL;
- int blockcount=bl_list_count,i,c;
+ struct block_list *bl;
+ int blockcount=bl_list_count,i;
if (m < 0)
return 0;
@@ -723,27 +677,18 @@ int map_foreachinarea(int (*func)(struct block_list*,va_list), int m, int x0, in
if (y1 >= map[m].ys) y1 = map[m].ys-1;
if (type&~BL_MOB)
- for (by = y0 / BLOCK_SIZE; by <= y1 / BLOCK_SIZE; by++) {
- for(bx = x0 / BLOCK_SIZE; bx <= x1 / BLOCK_SIZE; bx++) {
- bl = map[m].block[bx+by*map[m].bxs];
- c = map[m].block_count[bx+by*map[m].bxs];
- for(i=0;i<c && bl;i++,bl=bl->next){
- if(bl && bl->type&type && bl->x>=x0 && bl->x<=x1 && bl->y>=y0 && bl->y<=y1 && bl_list_count<BL_LIST_MAX)
+ for(by = y0 / BLOCK_SIZE; by <= y1 / BLOCK_SIZE; by++)
+ for(bx = x0 / BLOCK_SIZE; bx <= x1 / BLOCK_SIZE; bx++)
+ for( bl = map[m].block[bx+by*map[m].bxs] ; bl != NULL ; bl = bl->next )
+ if(bl->type&type && bl->x>=x0 && bl->x<=x1 && bl->y>=y0 && bl->y<=y1 && bl_list_count<BL_LIST_MAX)
bl_list[bl_list_count++]=bl;
- }
- }
- }
+
if(type&BL_MOB)
- for(by=y0/BLOCK_SIZE;by<=y1/BLOCK_SIZE;by++){
- for(bx=x0/BLOCK_SIZE;bx<=x1/BLOCK_SIZE;bx++){
- bl = map[m].block_mob[bx+by*map[m].bxs];
- c = map[m].block_mob_count[bx+by*map[m].bxs];
- for(i=0;i<c && bl;i++,bl=bl->next){
- if(bl && bl->x>=x0 && bl->x<=x1 && bl->y>=y0 && bl->y<=y1 && bl_list_count<BL_LIST_MAX)
+ for(by=y0/BLOCK_SIZE;by<=y1/BLOCK_SIZE;by++)
+ for(bx=x0/BLOCK_SIZE;bx<=x1/BLOCK_SIZE;bx++)
+ for( bl = map[m].block_mob[bx+by*map[m].bxs] ; bl != NULL ; bl = bl->next )
+ if(bl->x>=x0 && bl->x<=x1 && bl->y>=y0 && bl->y<=y1 && bl_list_count<BL_LIST_MAX)
bl_list[bl_list_count++]=bl;
- }
- }
- }
if(bl_list_count>=BL_LIST_MAX)
ShowWarning("map_foreachinarea: block count too many!\n");
@@ -772,9 +717,9 @@ int map_foreachinmovearea(int (*func)(struct block_list*,va_list), struct block_
{
int bx,by,m;
int returnCount =0; //total sum of returned values of func() [Skotlex]
- struct block_list *bl=NULL;
+ struct block_list *bl;
va_list ap;
- int blockcount=bl_list_count,i,c;
+ int blockcount=bl_list_count,i;
int x0, x1, y0, y1;
if (!range) return 0;
@@ -819,9 +764,8 @@ int map_foreachinmovearea(int (*func)(struct block_list*,va_list), struct block_
for(by=y0/BLOCK_SIZE;by<=y1/BLOCK_SIZE;by++){
for(bx=x0/BLOCK_SIZE;bx<=x1/BLOCK_SIZE;bx++){
if (type&~BL_MOB) {
- bl = map[m].block[bx+by*map[m].bxs];
- c = map[m].block_count[bx+by*map[m].bxs];
- for(i=0;i<c && bl;i++,bl=bl->next){
+ for( bl = map[m].block[bx+by*map[m].bxs] ; bl != NULL ; bl = bl->next )
+ {
if(bl->type&type &&
bl->x>=x0 && bl->x<=x1 &&
bl->y>=y0 && bl->y<=y1 &&
@@ -830,9 +774,8 @@ int map_foreachinmovearea(int (*func)(struct block_list*,va_list), struct block_
}
}
if (type&BL_MOB) {
- bl = map[m].block_mob[bx+by*map[m].bxs];
- c = map[m].block_mob_count[bx+by*map[m].bxs];
- for(i=0;i<c && bl;i++,bl=bl->next){
+ for( bl = map[m].block_mob[bx+by*map[m].bxs] ; bl != NULL ; bl = bl->next )
+ {
if(bl->x>=x0 && bl->x<=x1 &&
bl->y>=y0 && bl->y<=y1 &&
bl_list_count<BL_LIST_MAX)
@@ -850,14 +793,12 @@ int map_foreachinmovearea(int (*func)(struct block_list*,va_list), struct block_
for(by=y0/BLOCK_SIZE;by<=y1/BLOCK_SIZE;by++){
for(bx=x0/BLOCK_SIZE;bx<=x1/BLOCK_SIZE;bx++){
if (type & ~BL_MOB) {
- bl = map[m].block[bx+by*map[m].bxs];
- c = map[m].block_count[bx+by*map[m].bxs];
- for(i=0;i<c && bl;i++,bl=bl->next){
- if(!(bl->type&type &&
+ for( bl = map[m].block[bx+by*map[m].bxs] ; bl != NULL ; bl = bl->next )
+ {
+ if( bl->type&type &&
bl->x>=x0 && bl->x<=x1 &&
bl->y>=y0 && bl->y<=y1 &&
- bl_list_count<BL_LIST_MAX))
- continue;
+ bl_list_count<BL_LIST_MAX )
if((dx>0 && bl->x<x0+dx) ||
(dx<0 && bl->x>x1+dx) ||
(dy>0 && bl->y<y0+dy) ||
@@ -866,19 +807,16 @@ int map_foreachinmovearea(int (*func)(struct block_list*,va_list), struct block_
}
}
if (type & BL_MOB) {
- bl = map[m].block_mob[bx+by*map[m].bxs];
- c = map[m].block_mob_count[bx+by*map[m].bxs];
- for(i=0;i<c && bl;i++,bl=bl->next){
- if(!(
- bl->x>=x0 && bl->x<=x1 &&
+ for( bl = map[m].block_mob[bx+by*map[m].bxs] ; bl != NULL ; bl = bl->next )
+ {
+ if( bl->x>=x0 && bl->x<=x1 &&
bl->y>=y0 && bl->y<=y1 &&
- bl_list_count<BL_LIST_MAX))
- continue;
+ bl_list_count<BL_LIST_MAX)
if((dx>0 && bl->x<x0+dx) ||
(dx<0 && bl->x>x1+dx) ||
(dy>0 && bl->y<y0+dy) ||
(dy<0 && bl->y>y1+dy))
- bl_list[bl_list_count++]=bl;
+ bl_list[bl_list_count++]=bl;
}
}
}
@@ -910,9 +848,9 @@ int map_foreachincell(int (*func)(struct block_list*,va_list), int m, int x, int
{
int bx,by;
int returnCount =0; //total sum of returned values of func() [Skotlex]
- struct block_list *bl=NULL;
+ struct block_list *bl;
va_list ap;
- int blockcount=bl_list_count,i,c;
+ int blockcount=bl_list_count,i;
if (x < 0 || y < 0 || x >= map[m].xs || y >= map[m].ys) return 0;
@@ -922,26 +860,14 @@ int map_foreachincell(int (*func)(struct block_list*,va_list), int m, int x, int
bx=x/BLOCK_SIZE;
if(type&~BL_MOB)
- {
- bl = map[m].block[bx+by*map[m].bxs];
- c = map[m].block_count[bx+by*map[m].bxs];
- for(i=0;i<c && bl;i++,bl=bl->next)
- {
- if(bl && bl->type&type && bl->x==x && bl->y==y && bl_list_count<BL_LIST_MAX)
+ for( bl = map[m].block[bx+by*map[m].bxs] ; bl != NULL ; bl = bl->next )
+ if(bl->type&type && bl->x==x && bl->y==y && bl_list_count<BL_LIST_MAX)
bl_list[bl_list_count++]=bl;
- }
- }
if(type&BL_MOB)
- {
- bl = map[m].block_mob[bx+by*map[m].bxs];
- c = map[m].block_mob_count[bx+by*map[m].bxs];
- for(i=0;i<c && bl;i++,bl=bl->next)
- {
- if(bl && bl->x==x && bl->y==y && bl_list_count<BL_LIST_MAX)
+ for( bl = map[m].block_mob[bx+by*map[m].bxs] ; bl != NULL ; bl = bl->next )
+ if(bl->x==x && bl->y==y && bl_list_count<BL_LIST_MAX)
bl_list[bl_list_count++]=bl;
- }
- }
if(bl_list_count>=BL_LIST_MAX)
ShowWarning("map_foreachincell: block count too many!\n");
@@ -1002,7 +928,7 @@ int map_foreachinpath(int (*func)(struct block_list*,va_list),int m,int x0,int y
va_list ap;
int i, blockcount = bl_list_count;
struct block_list *bl;
- int c, bx, by;
+ int bx, by;
//method specific variables
int magnitude2, len_limit; //The square of the magnitude
int k, xi, yi, xu, yu;
@@ -1070,10 +996,9 @@ int map_foreachinpath(int (*func)(struct block_list*,va_list),int m,int x0,int y
if (type & ~BL_MOB)
for (by = my0 / BLOCK_SIZE; by <= my1 / BLOCK_SIZE; by++) {
for(bx=mx0/BLOCK_SIZE;bx<=mx1/BLOCK_SIZE;bx++){
- bl = map[m].block[bx+by*map[m].bxs];
- c = map[m].block_count[bx+by*map[m].bxs];
- for(i=0;i<c && bl;i++,bl=bl->next){
- if(bl && bl->prev && bl->type&type && bl_list_count<BL_LIST_MAX)
+ for( bl = map[m].block[bx+by*map[m].bxs] ; bl != NULL ; bl = bl->next )
+ {
+ if(bl->prev && bl->type&type && bl_list_count<BL_LIST_MAX)
{
xi = bl->x;
yi = bl->y;
@@ -1103,13 +1028,13 @@ int map_foreachinpath(int (*func)(struct block_list*,va_list),int m,int x0,int y
}
}
}
+
if(type&BL_MOB)
for(by=my0/BLOCK_SIZE;by<=my1/BLOCK_SIZE;by++){
for(bx=mx0/BLOCK_SIZE;bx<=mx1/BLOCK_SIZE;bx++){
- bl = map[m].block_mob[bx+by*map[m].bxs];
- c = map[m].block_mob_count[bx+by*map[m].bxs];
- for(i=0;i<c && bl;i++,bl=bl->next){
- if(bl && bl->prev && bl_list_count<BL_LIST_MAX)
+ for( bl = map[m].block_mob[bx+by*map[m].bxs] ; bl != NULL ; bl = bl->next )
+ {
+ if(bl->prev && bl_list_count<BL_LIST_MAX)
{
xi = bl->x;
yi = bl->y;
@@ -1159,38 +1084,25 @@ int map_foreachinmap(int (*func)(struct block_list*,va_list), int m, int type,..
{
int b, bsize;
int returnCount =0; //total sum of returned values of func() [Skotlex]
- struct block_list *bl=NULL;
+ struct block_list *bl;
va_list ap;
- int blockcount=bl_list_count,i,c;
+ int blockcount=bl_list_count,i;
va_start(ap,type);
bsize = map[m].bxs * map[m].bys;
+
if(type&~BL_MOB)
- {
- for(b=0;b<bsize;b++){
- bl = map[m].block[b];
- c = map[m].block_count[b];
- for(i=0;i<c && bl;i++,bl=bl->next)
- {
- if(bl && bl->type&type && bl_list_count<BL_LIST_MAX)
+ for(b=0;b<bsize;b++)
+ for( bl = map[m].block[b] ; bl != NULL ; bl = bl->next )
+ if(bl->type&type && bl_list_count<BL_LIST_MAX)
bl_list[bl_list_count++]=bl;
- }
- }
- }
if(type&BL_MOB)
- {
- for(b=0;b<bsize;b++){
- bl = map[m].block_mob[b];
- c = map[m].block_mob_count[b];
- for(i=0;i<c && bl;i++,bl=bl->next)
- {
- if(bl && bl_list_count<BL_LIST_MAX)
+ for(b=0;b<bsize;b++)
+ for( bl = map[m].block_mob[b] ; bl != NULL ; bl = bl->next )
+ if(bl_list_count<BL_LIST_MAX)
bl_list[bl_list_count++]=bl;
- }
- }
- }
if(bl_list_count>=BL_LIST_MAX)
ShowWarning("map_foreachinmap: block count too many!\n");
@@ -1830,7 +1742,7 @@ struct map_session_data * map_nick2sd(const char *nick)
*------------------------------------------*/
struct block_list * map_id2bl(int id)
{
- struct block_list *bl=NULL;
+ struct block_list *bl;
if(id >= 0 && id < ARRAYLENGTH(objects))
bl = objects[id];
else
@@ -2612,10 +2524,6 @@ int map_readallmaps (void)
size = map[i].bxs * map[i].bys * sizeof(struct block_list*);
map[i].block = (struct block_list**)aCalloc(size, 1);
map[i].block_mob = (struct block_list**)aCalloc(size, 1);
-
- size = map[i].bxs * map[i].bys * sizeof(int);
- map[i].block_count = (int*)aCallocA(size, 1);
- map[i].block_mob_count = (int*)aCallocA(size, 1);
}
if( !enable_grf )
@@ -3093,8 +3001,6 @@ void do_final(void)
#endif
if(map[i].block) aFree(map[i].block);
if(map[i].block_mob) aFree(map[i].block_mob);
- if(map[i].block_count) aFree(map[i].block_count);
- if(map[i].block_mob_count) aFree(map[i].block_mob_count);
if(battle_config.dynamic_mobs) { //Dynamic mobs flag by [random]
for (j=0; j<MAX_MOB_LIST_PER_MAP; j++)
if (map[i].moblist[j]) aFree(map[i].moblist[j]);