--- deliantra/server/common/los.C 2006/08/13 17:16:00 1.1 +++ deliantra/server/common/los.C 2006/08/29 08:01:35 1.2 @@ -1,6 +1,6 @@ /* * static char *rcsid_los_c = - * "$Id: los.C,v 1.1 2006/08/13 17:16:00 elmex Exp $"; + * "$Id: los.C,v 1.2 2006/08/29 08:01:35 root Exp $"; */ /* @@ -67,7 +67,7 @@ /* Due to flipping, we may get duplicates - better safe than sorry. */ for (i=0; i %d %d (%d)\n", x, y, bx, by, - block[x][y].index); + block[x][y].index); #endif } @@ -94,62 +94,62 @@ static int block_x[3] = {-1, -1, 0}, block_y[3] = {-1, 0, -1}; for(x=0;xcontr->socket.mapx)/2; - ay = dy - (MAP_CLIENT_Y - op->contr->socket.mapy)/2; + /* ax, ay are the values as adjusted to be in the + * socket look structure. + */ + ax = dx - (MAP_CLIENT_X - op->contr->socket.mapx)/2; + ay = dy - (MAP_CLIENT_Y - op->contr->socket.mapy)/2; - if (ax < 0 || ax>=op->contr->socket.mapx || - ay < 0 || ay>=op->contr->socket.mapy) continue; + if (ax < 0 || ax>=op->contr->socket.mapx || + ay < 0 || ay>=op->contr->socket.mapy) continue; #if 0 - LOG(llevDebug, "blocked %d %d -> %d %d\n", - dx, dy, ax, ay); + LOG(llevDebug, "blocked %d %d -> %d %d\n", + dx, dy, ax, ay); #endif - /* we need to adjust to the fact that the socket - * code wants the los to start from the 0,0 - * and not be relative to middle of los array. - */ - op->contr->blocked_los[ax][ay]=100; - set_wall(op,dx,dy); + /* we need to adjust to the fact that the socket + * code wants the los to start from the 0,0 + * and not be relative to middle of los array. + */ + op->contr->blocked_los[ax][ay]=100; + set_wall(op,dx,dy); } } @@ -201,7 +201,7 @@ int ax, ay; if(!block[x][y].index) - return; + return; /* ax, ay are coordinates as indexed into the look window */ ax = x - (MAP_CLIENT_X - op->contr->socket.mapx)/2; @@ -211,11 +211,11 @@ * area for the client, return now. */ if (ax < 0 || ay < 0 || ax >= op->contr->socket.mapx || ay >= op->contr->socket.mapy) - return; + return; #if 0 LOG(llevDebug, "check_wall, ax,ay=%d, %d x,y = %d, %d blocksview = %d, %d\n", - ax, ay, x, y, op->x + x - MAP_CLIENT_X/2, op->y + y - MAP_CLIENT_Y/2); + ax, ay, x, y, op->x + x - MAP_CLIENT_X/2, op->y + y - MAP_CLIENT_Y/2); #endif /* If this space is already blocked, prune the processing - presumably @@ -226,9 +226,9 @@ if(get_map_flags(op->map, NULL, - op->x + x - MAP_CLIENT_X/2, op->y + y - MAP_CLIENT_Y/2, - NULL, NULL) & (P_BLOCKSVIEW | P_OUT_OF_MAP)) - set_wall(op,x,y); + op->x + x - MAP_CLIENT_X/2, op->y + y - MAP_CLIENT_Y/2, + NULL, NULL) & (P_BLOCKSVIEW | P_OUT_OF_MAP)) + set_wall(op,x,y); } /* @@ -243,7 +243,7 @@ * actually going to use */ (void)memset((void *) op->contr->blocked_los,0, - MAP_CLIENT_X * MAP_CLIENT_Y); + MAP_CLIENT_X * MAP_CLIENT_Y); } /* @@ -258,31 +258,31 @@ int i,x,y, dx, dy; for(x=1;xcontr->socket.mapx-1;x++) /* loop over inner squares */ - for(y=1;ycontr->socket.mapy-1;y++) { - if (!op->contr->blocked_los[x][y] && - !(get_map_flags(op->map,NULL, - op->x-op->contr->socket.mapx/2+x, - op->y-op->contr->socket.mapy/2+y, - NULL, NULL) & (P_BLOCKSVIEW | P_OUT_OF_MAP))) { - - for(i=1;i<=8;i+=1) { /* mark all directions */ - dx = x + freearr_x[i]; - dy = y + freearr_y[i]; - if(op->contr->blocked_los[dx][dy] > 0) /* for any square blocked */ - op->contr->blocked_los[dx][dy]= -1; - } - } - } + for(y=1;ycontr->socket.mapy-1;y++) { + if (!op->contr->blocked_los[x][y] && + !(get_map_flags(op->map,NULL, + op->x-op->contr->socket.mapx/2+x, + op->y-op->contr->socket.mapy/2+y, + NULL, NULL) & (P_BLOCKSVIEW | P_OUT_OF_MAP))) { + + for(i=1;i<=8;i+=1) { /* mark all directions */ + dx = x + freearr_x[i]; + dy = y + freearr_y[i]; + if(op->contr->blocked_los[dx][dy] > 0) /* for any square blocked */ + op->contr->blocked_los[dx][dy]= -1; + } + } + } if(MAP_DARKNESS(op->map)>0) /* player is on a dark map */ - expand_lighted_sight(op); + expand_lighted_sight(op); /* clear mark squares */ for (x = 0; x < op->contr->socket.mapx; x++) - for (y = 0; y < op->contr->socket.mapy; y++) - if (op->contr->blocked_los[x][y] < 0) - op->contr->blocked_los[x][y] = 0; + for (y = 0; y < op->contr->socket.mapy; y++) + if (op->contr->blocked_los[x][y] < 0) + op->contr->blocked_los[x][y] = 0; } @@ -323,16 +323,16 @@ * things. */ if (darklevel > MAX_DARKNESS) { - LOG(llevError,"Map darkness for %s on %s is too high (%d)\n", - op->name, op->map->path, darklevel); - darklevel = MAX_DARKNESS; + LOG(llevError,"Map darkness for %s on %s is too high (%d)\n", + op->name, op->map->path, darklevel); + darklevel = MAX_DARKNESS; } /* First, limit player furthest (unlighted) vision */ for (x = 0; x < op->contr->socket.mapx; x++) - for (y = 0; y < op->contr->socket.mapy; y++) - if(op->contr->blocked_los[x][y]!=100) - op->contr->blocked_los[x][y]= MAX_LIGHT_RADII; + for (y = 0; y < op->contr->socket.mapy; y++) + if(op->contr->blocked_los[x][y]!=100) + op->contr->blocked_los[x][y]= MAX_LIGHT_RADII; /* the spaces[] darkness value contains the information we need. * Only process the area of interest. @@ -343,36 +343,36 @@ for (x=(op->x - op->contr->socket.mapx/2 - MAX_LIGHT_RADII), basex=-MAX_LIGHT_RADII; x <= (op->x + op->contr->socket.mapx/2 + MAX_LIGHT_RADII); x++, basex++) { - for (y=(op->y - op->contr->socket.mapy/2 - MAX_LIGHT_RADII), basey=-MAX_LIGHT_RADII; - y <= (op->y + op->contr->socket.mapy/2 + MAX_LIGHT_RADII); y++, basey++) { - m = op->map; - nx = x; - ny = y; - - mflags = get_map_flags(m, &m, nx, ny, &nx, &ny); - - if (mflags & P_OUT_OF_MAP) continue; - - /* This space is providing light, so we need to brighten up the - * spaces around here. - */ - light = GET_MAP_LIGHT(m, nx, ny); - if (light != 0) { + for (y=(op->y - op->contr->socket.mapy/2 - MAX_LIGHT_RADII), basey=-MAX_LIGHT_RADII; + y <= (op->y + op->contr->socket.mapy/2 + MAX_LIGHT_RADII); y++, basey++) { + m = op->map; + nx = x; + ny = y; + + mflags = get_map_flags(m, &m, nx, ny, &nx, &ny); + + if (mflags & P_OUT_OF_MAP) continue; + + /* This space is providing light, so we need to brighten up the + * spaces around here. + */ + light = GET_MAP_LIGHT(m, nx, ny); + if (light != 0) { #if 0 - LOG(llevDebug, "expand_lighted_sight: Found light at x=%d, y=%d, basex=%d, basey=%d\n", - x, y, basex, basey); + LOG(llevDebug, "expand_lighted_sight: Found light at x=%d, y=%d, basex=%d, basey=%d\n", + x, y, basex, basey); #endif - for (ax=basex - light; ax<=basex+light; ax++) { - if (ax<0 || ax>=op->contr->socket.mapx) continue; - for (ay=basey - light; ay<=basey+light; ay++) { - if (ay<0 || ay>=op->contr->socket.mapy) continue; + for (ax=basex - light; ax<=basex+light; ax++) { + if (ax<0 || ax>=op->contr->socket.mapx) continue; + for (ay=basey - light; ay<=basey+light; ay++) { + if (ay<0 || ay>=op->contr->socket.mapy) continue; - /* If the space is fully blocked, do nothing. Otherwise, we - * brighten the space. The further the light is away from the + /* If the space is fully blocked, do nothing. Otherwise, we + * brighten the space. The further the light is away from the * source (basex-x), the less effect it has. Though light used * to dim in a square manner, it now dims in a circular manner * using the the pythagorean theorem. glow_radius still - * represents the radius + * represents the radius */ if(op->contr->blocked_los[ax][ay]!=100) { x1 = abs(basex-ax)*abs(basex-ax); @@ -380,31 +380,31 @@ if (light > 0) op->contr->blocked_los[ax][ay]-= MAX((light - isqrt(x1 + y1)), 0); if (light < 0) op->contr->blocked_los[ax][ay]-= MIN((light + isqrt(x1 + y1)), 0); } - } /* for ay */ - } /* for ax */ - } /* if this space is providing light */ - } /* for y */ + } /* for ay */ + } /* for ax */ + } /* if this space is providing light */ + } /* for y */ } /* for x */ /* Outdoor should never really be completely pitch black dark like * a dungeon, so let the player at least see a little around themselves */ if (op->map->outdoor && darklevel > (MAX_DARKNESS - 3)) { - if (op->contr->blocked_los[op->contr->socket.mapx/2][op->contr->socket.mapy/2] > (MAX_DARKNESS-3)) - op->contr->blocked_los[op->contr->socket.mapx/2][op->contr->socket.mapy/2] = MAX_DARKNESS - 3; + if (op->contr->blocked_los[op->contr->socket.mapx/2][op->contr->socket.mapy/2] > (MAX_DARKNESS-3)) + op->contr->blocked_los[op->contr->socket.mapx/2][op->contr->socket.mapy/2] = MAX_DARKNESS - 3; - for (x=-1; x<=1; x++) - for (y=-1; y<=1; y++) { - if (op->contr->blocked_los[x + op->contr->socket.mapx/2][y + op->contr->socket.mapy/2] > (MAX_DARKNESS-2)) - op->contr->blocked_los[x + op->contr->socket.mapx/2][y + op->contr->socket.mapy/2] = MAX_DARKNESS - 2; - } + for (x=-1; x<=1; x++) + for (y=-1; y<=1; y++) { + if (op->contr->blocked_los[x + op->contr->socket.mapx/2][y + op->contr->socket.mapy/2] > (MAX_DARKNESS-2)) + op->contr->blocked_los[x + op->contr->socket.mapx/2][y + op->contr->socket.mapy/2] = MAX_DARKNESS - 2; + } } /* grant some vision to the player, based on the darklevel */ for(x=darklevel-MAX_DARKNESS; xcontr->blocked_los[x+op->contr->socket.mapx/2][y+op->contr->socket.mapy/2]==100)) - op->contr->blocked_los[x+op->contr->socket.mapx/2][y+op->contr->socket.mapy/2]-= - MAX(0,6 -darklevel - MAX(abs(x),abs(y))); + for(y=darklevel-MAX_DARKNESS; ycontr->blocked_los[x+op->contr->socket.mapx/2][y+op->contr->socket.mapy/2]==100)) + op->contr->blocked_los[x+op->contr->socket.mapx/2][y+op->contr->socket.mapy/2]-= + MAX(0,6 -darklevel - MAX(abs(x),abs(y))); } /* blinded_sight() - sets all veiwable squares to blocked except @@ -417,8 +417,8 @@ int x,y; for (x = 0; x < op->contr->socket.mapx; x++) - for (y = 0; y < op->contr->socket.mapy; y++) - op->contr->blocked_los[x][y] = 100; + for (y = 0; y < op->contr->socket.mapy; y++) + op->contr->blocked_los[x][y] = 100; op->contr->blocked_los[ op->contr->socket.mapx/2][ op->contr->socket.mapy/2] = 0; } @@ -432,11 +432,11 @@ int dx = op->contr->socket.mapx/2, dy = op->contr->socket.mapy/2, x, y; if(QUERY_FLAG(op,FLAG_REMOVED)) - return; + return; clear_los(op); if(QUERY_FLAG(op,FLAG_WIZ) /* ||XRAYS(op) */) - return; + return; /* For larger maps, this is more efficient than the old way which * used the chaining of the block array. Since many space views could @@ -444,21 +444,21 @@ * could be examined multile times, as each path would be looked at. */ for (x=(MAP_CLIENT_X - op->contr->socket.mapx)/2 - 1; x<(MAP_CLIENT_X + op->contr->socket.mapx)/2 + 1; x++) - for (y=(MAP_CLIENT_Y - op->contr->socket.mapy)/2 - 1; y<(MAP_CLIENT_Y + op->contr->socket.mapy)/2 + 1; y++) - check_wall(op, x, y); + for (y=(MAP_CLIENT_Y - op->contr->socket.mapy)/2 - 1; y<(MAP_CLIENT_Y + op->contr->socket.mapy)/2 + 1; y++) + check_wall(op, x, y); /* do the los of the player. 3 (potential) cases */ if(QUERY_FLAG(op,FLAG_BLIND)) /* player is blind */ - blinded_sight(op); + blinded_sight(op); else - expand_sight(op); + expand_sight(op); if (QUERY_FLAG(op,FLAG_XRAYS)) { - int x, y; - for (x = -2; x <= 2; x++) - for (y = -2; y <= 2; y++) - op->contr->blocked_los[dx + x][dy + y] = 0; + int x, y; + for (x = -2; x <= 2; x++) + for (y = -2; y <= 2; y++) + op->contr->blocked_los[dx + x][dy + y] = 0; } } @@ -477,8 +477,8 @@ player *pl; for(pl=first_player;pl!=NULL;pl=pl->next) { - if(pl->ob->map==map) - pl->do_los=1; + if(pl->ob->map==map) + pl->do_los=1; } } @@ -500,61 +500,61 @@ player *pl; for(pl=first_player;pl!=NULL;pl=pl->next) { - /* Player should not have a null map, but do this - * check as a safety - */ - if (!pl->ob->map) continue; - - /* Same map is simple case - see if pl is close enough. - * Note in all cases, we did the check for same map first, - * and then see if the player is close enough and update - * los if that is the case. If the player is on the - * corresponding map, but not close enough, then the - * player can't be on another map that may be closer, - * so by setting it up this way, we trim processing - * some. - */ - if(pl->ob->map==map) { - if ((abs(pl->ob->x - x) <= pl->socket.mapx/2) && - (abs(pl->ob->y - y) <= pl->socket.mapy/2)) - pl->do_los=1; - } - /* Now we check to see if player is on adjacent - * maps to the one that changed and also within - * view. The tile_maps[] could be null, but in that - * case it should never match the pl->ob->map, so - * we want ever try to dereference any of the data in it. - */ - - /* The logic for 0 and 3 is to see how far the player is - * from the edge of the map (height/width) - pl->ob->(x,y) - * and to add current position on this map - that gives a - * distance. - * For 1 and 2, we check to see how far the given - * coordinate (x,y) is from the corresponding edge, - * and then add the players location, which gives - * a distance. - */ - else if (pl->ob->map == map->tile_map[0]) { - if ((abs(pl->ob->x - x) <= pl->socket.mapx/2) && - (abs(y + MAP_HEIGHT(map->tile_map[0]) - pl->ob->y) <= pl->socket.mapy/2)) - pl->do_los=1; - } - else if (pl->ob->map == map->tile_map[2]) { - if ((abs(pl->ob->x - x) <= pl->socket.mapx/2) && - (abs(pl->ob->y + MAP_HEIGHT(map) - y) <= pl->socket.mapy/2)) - pl->do_los=1; - } - else if (pl->ob->map == map->tile_map[1]) { - if ((abs(pl->ob->x + MAP_WIDTH(map) - x) <= pl->socket.mapx/2) && - (abs(pl->ob->y - y) <= pl->socket.mapy/2)) - pl->do_los=1; - } - else if (pl->ob->map == map->tile_map[3]) { - if ((abs(x + MAP_WIDTH(map->tile_map[3]) - pl->ob->x) <= pl->socket.mapx/2) && - (abs(pl->ob->y - y) <= pl->socket.mapy/2)) - pl->do_los=1; - } + /* Player should not have a null map, but do this + * check as a safety + */ + if (!pl->ob->map) continue; + + /* Same map is simple case - see if pl is close enough. + * Note in all cases, we did the check for same map first, + * and then see if the player is close enough and update + * los if that is the case. If the player is on the + * corresponding map, but not close enough, then the + * player can't be on another map that may be closer, + * so by setting it up this way, we trim processing + * some. + */ + if(pl->ob->map==map) { + if ((abs(pl->ob->x - x) <= pl->socket.mapx/2) && + (abs(pl->ob->y - y) <= pl->socket.mapy/2)) + pl->do_los=1; + } + /* Now we check to see if player is on adjacent + * maps to the one that changed and also within + * view. The tile_maps[] could be null, but in that + * case it should never match the pl->ob->map, so + * we want ever try to dereference any of the data in it. + */ + + /* The logic for 0 and 3 is to see how far the player is + * from the edge of the map (height/width) - pl->ob->(x,y) + * and to add current position on this map - that gives a + * distance. + * For 1 and 2, we check to see how far the given + * coordinate (x,y) is from the corresponding edge, + * and then add the players location, which gives + * a distance. + */ + else if (pl->ob->map == map->tile_map[0]) { + if ((abs(pl->ob->x - x) <= pl->socket.mapx/2) && + (abs(y + MAP_HEIGHT(map->tile_map[0]) - pl->ob->y) <= pl->socket.mapy/2)) + pl->do_los=1; + } + else if (pl->ob->map == map->tile_map[2]) { + if ((abs(pl->ob->x - x) <= pl->socket.mapx/2) && + (abs(pl->ob->y + MAP_HEIGHT(map) - y) <= pl->socket.mapy/2)) + pl->do_los=1; + } + else if (pl->ob->map == map->tile_map[1]) { + if ((abs(pl->ob->x + MAP_WIDTH(map) - x) <= pl->socket.mapx/2) && + (abs(pl->ob->y - y) <= pl->socket.mapy/2)) + pl->do_los=1; + } + else if (pl->ob->map == map->tile_map[3]) { + if ((abs(x + MAP_WIDTH(map->tile_map[3]) - pl->ob->x) <= pl->socket.mapx/2) && + (abs(pl->ob->y - y) <= pl->socket.mapy/2)) + pl->do_los=1; + } } } @@ -569,17 +569,17 @@ strcpy(buf," "); for(x=0;xcontr->socket.mapx;x++) { - sprintf(buf2,"%2d",x); - strcat(buf,buf2); + sprintf(buf2,"%2d",x); + strcat(buf,buf2); } new_draw_info(NDI_UNIQUE, 0, op, buf); for(y=0;ycontr->socket.mapy;y++) { - sprintf(buf,"%2d:",y); - for(x=0;xcontr->socket.mapx;x++) { - sprintf(buf2," %1d",op->contr->blocked_los[x][y]); - strcat(buf,buf2); - } - new_draw_info(NDI_UNIQUE, 0, op, buf); + sprintf(buf,"%2d:",y); + for(x=0;xcontr->socket.mapx;x++) { + sprintf(buf2," %1d",op->contr->blocked_los[x][y]); + strcat(buf,buf2); + } + new_draw_info(NDI_UNIQUE, 0, op, buf); } } @@ -592,13 +592,13 @@ player *pl; for (pl = first_player; pl; pl = pl->next) - if (pl->ob->map == op->map && - pl->ob->y - pl->socket.mapy/2 <= op->y && - pl->ob->y + pl->socket.mapy/2 >= op->y && - pl->ob->x - pl->socket.mapx/2 <= op->x && - pl->ob->x + pl->socket.mapx/2 >= op->x) - pl->blocked_los[pl->socket.mapx/2 + op->x - pl->ob->x] - [pl->socket.mapy/2 + op->y - pl->ob->y] = 0; + if (pl->ob->map == op->map && + pl->ob->y - pl->socket.mapy/2 <= op->y && + pl->ob->y + pl->socket.mapy/2 >= op->y && + pl->ob->x - pl->socket.mapx/2 <= op->x && + pl->ob->x + pl->socket.mapx/2 >= op->x) + pl->blocked_los[pl->socket.mapx/2 + op->x - pl->ob->x] + [pl->socket.mapy/2 + op->y - pl->ob->y] = 0; } /* @@ -610,10 +610,10 @@ void make_sure_not_seen(const object *op) { player *pl; for (pl = first_player; pl; pl = pl->next) - if (pl->ob->map == op->map && - pl->ob->y - pl->socket.mapy/2 <= op->y && - pl->ob->y + pl->socket.mapy/2 >= op->y && - pl->ob->x - pl->socket.mapx/2 <= op->x && - pl->ob->x + pl->socket.mapx/2 >= op->x) - pl->do_los = 1; + if (pl->ob->map == op->map && + pl->ob->y - pl->socket.mapy/2 <= op->y && + pl->ob->y + pl->socket.mapy/2 >= op->y && + pl->ob->x - pl->socket.mapx/2 <= op->x && + pl->ob->x + pl->socket.mapx/2 >= op->x) + pl->do_los = 1; }