ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/los.C
(Generate patch)

Comparing deliantra/server/common/los.C (file contents):
Revision 1.60 by root, Sun Jan 11 06:08:40 2009 UTC vs.
Revision 1.61 by root, Tue May 5 04:51:56 2009 UTC

288 { 288 {
289 // max intensity 289 // max intensity
290 int intensity = min (LOS_MAX, abs (radius) + 1); 290 int intensity = min (LOS_MAX, abs (radius) + 1);
291 291
292 // actual intensity 292 // actual intensity
293 intensity = max (0, lerp_rd (distance, 0, abs (radius) + 1, intensity, 0)); 293 intensity = max (0, lerp_ru (distance, 0, abs (radius) + 1, intensity, 0));
294 294
295 light_atten [radius + MAX_LIGHT_RADIUS][distance] = radius < 0 295 light_atten [radius + MAX_LIGHT_RADIUS][distance] = radius < 0
296 ? min (3, intensity) 296 ? min (3, intensity)
297 : LOS_MAX - intensity; 297 : LOS_MAX - intensity;
298 } 298 }
502 * map is the map that changed, x and y are the coordinates. 502 * map is the map that changed, x and y are the coordinates.
503 */ 503 */
504void 504void
505update_all_los (const maptile *map, int x, int y) 505update_all_los (const maptile *map, int x, int y)
506{ 506{
507 // no need to do anything if we don't have darkness
508 if (map->darklevel () <= 0)
509 return;
510
511 map->at (x, y).invalidate (); 507 map->at (x, y).invalidate ();
512 508
513 for_all_players (pl) 509 for_all_players (pl)
514 { 510 {
515 /* Player should not have a null map, but do this 511 /* Player should not have a null map, but do this
516 * check as a safety 512 * check as a safety
517 */ 513 */
518 if (!pl->ob || !pl->ob->map || !pl->ns) 514 if (!pl->ob || !pl->ob->map || !pl->ns)
519 continue; 515 continue;
520 516
521 /* Same map is simple case - see if pl is close enough. 517 rv_vector rv;
522 * Note in all cases, we did the check for same map first, 518
523 * and then see if the player is close enough and update 519 get_rangevector_from_mapcoord (map, x, y, pl->ob, &rv);
524 * los if that is the case. If the player is on the
525 * corresponding map, but not close enough, then the
526 * player can't be on another map that may be closer,
527 * so by setting it up this way, we trim processing
528 * some.
529 */ 520
530 if (pl->ob->map == map) 521 if ((abs (rv.distance_x) <= pl->ns->mapx / 2) && (abs (rv.distance_y) <= pl->ns->mapy / 2))
531 if ((abs (pl->ob->x - x) <= pl->ns->mapx / 2) && (abs (pl->ob->y - y) <= pl->ns->mapy / 2))
532 pl->do_los = 1; 522 pl->do_los = 1;
533
534 /* Now we check to see if player is on adjacent
535 * maps to the one that changed and also within
536 * view. The tile_maps[] could be null, but in that
537 * case it should never match the pl->ob->map, so
538 * we want ever try to dereference any of the data in it.
539 *
540 * The logic for 0 and 3 is to see how far the player is
541 * from the edge of the map (height/width) - pl->ob->(x,y)
542 * and to add current position on this map - that gives a
543 * distance.
544 * For 1 and 2, we check to see how far the given
545 * coordinate (x,y) is from the corresponding edge,
546 * and then add the players location, which gives
547 * a distance.
548 */
549 else if (pl->ob->map == map->tile_map[0])
550 {
551 if ((abs (pl->ob->x - x) <= pl->ns->mapx / 2) && (abs (y + map->tile_map[0]->height - pl->ob->y) <= pl->ns->mapy / 2))
552 pl->do_los = 1;
553 }
554 else if (pl->ob->map == map->tile_map[2])
555 {
556 if ((abs (pl->ob->x - x) <= pl->ns->mapx / 2) && (abs (pl->ob->y + map->height - y) <= pl->ns->mapy / 2))
557 pl->do_los = 1;
558 }
559 else if (pl->ob->map == map->tile_map[1])
560 {
561 if ((abs (pl->ob->x + map->width - x) <= pl->ns->mapx / 2) && (abs (pl->ob->y - y) <= pl->ns->mapy / 2))
562 pl->do_los = 1;
563 }
564 else if (pl->ob->map == map->tile_map[3])
565 {
566 if ((abs (x + map->tile_map[3]->width - pl->ob->x) <= pl->ns->mapx / 2) && (abs (pl->ob->y - y) <= pl->ns->mapy / 2))
567 pl->do_los = 1;
568 }
569 } 523 }
570} 524}
571 525
572static const int season_darkness[5][HOURS_PER_DAY] = { 526static const int season_darkness[5][HOURS_PER_DAY] = {
573 /*0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 2 3 4 5 6 7 8 9 10 11 12 13 */ 527 /*0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 2 3 4 5 6 7 8 9 10 11 12 13 */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines