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.44 by root, Sun Dec 21 21:20:35 2008 UTC vs.
Revision 1.47 by root, Tue Dec 23 01:51:27 2008 UTC

268 return 0; 268 return 0;
269} 269}
270 270
271/* radius, distance => lightness adjust */ 271/* radius, distance => lightness adjust */
272static sint8 light_atten[MAX_LIGHT_RADIUS * 2 + 1][MAX_LIGHT_RADIUS * 3 / 2 + 1]; 272static sint8 light_atten[MAX_LIGHT_RADIUS * 2 + 1][MAX_LIGHT_RADIUS * 3 / 2 + 1];
273static sint8 vision_atten[MAX_DARKNESS + 1][MAX_DARKNESS * 3 / 2 + 1];
273 274
274static struct los_init 275static struct los_init
275{ 276{
276 los_init () 277 los_init ()
277 { 278 {
279 /* for lights */
278 for (int radius = -MAX_LIGHT_RADIUS; radius <= MAX_LIGHT_RADIUS; ++radius) 280 for (int radius = -MAX_LIGHT_RADIUS; radius <= MAX_LIGHT_RADIUS; ++radius)
279 for (int distance = 0; distance <= MAX_LIGHT_RADIUS * 3 / 2; ++distance) 281 for (int distance = 0; distance <= MAX_LIGHT_RADIUS * 3 / 2; ++distance)
280 { 282 {
281 // max intensity 283 // max intensity
282 int intensity = min (LOS_MAX, abs (radius) + 1); 284 int intensity = min (LOS_MAX, abs (radius) + 1);
285 intensity = max (0, lerp_rd (distance, 0, abs (radius) + 1, intensity, 0)); 287 intensity = max (0, lerp_rd (distance, 0, abs (radius) + 1, intensity, 0));
286 288
287 light_atten [radius + MAX_LIGHT_RADIUS][distance] = radius < 0 289 light_atten [radius + MAX_LIGHT_RADIUS][distance] = radius < 0
288 ? min (3, intensity) 290 ? min (3, intensity)
289 : LOS_MAX - intensity; 291 : LOS_MAX - intensity;
292 }
293
294 /* for general vision */
295 for (int radius = 0; radius <= MAX_DARKNESS; ++radius)
296 for (int distance = 0; distance <= MAX_DARKNESS * 3 / 2; ++distance)
297 {
298 vision_atten [radius][distance] = distance <= radius ? 3 : 4;
290 } 299 }
291 } 300 }
292} los_init; 301} los_init;
293 302
294sint8 303sint8
335{ 344{
336 int darklevel, mflags, light, x1, y1; 345 int darklevel, mflags, light, x1, y1;
337 maptile *m = op->map; 346 maptile *m = op->map;
338 sint16 nx, ny; 347 sint16 nx, ny;
339 348
340 darklevel = m->darkness; 349 darklevel = m->darklevel ();
341 350
342 /* If the player can see in the dark, lower the darklevel for him */ 351 /* If the player can see in the dark, lower the darklevel for him */
343 if (QUERY_FLAG (op, FLAG_SEE_IN_DARK)) 352 if (QUERY_FLAG (op, FLAG_SEE_IN_DARK))
344 darklevel -= LOS_MAX / 2; 353 darklevel -= 2;
345 354
346 /* Do a sanity check. If not valid, some code below may do odd 355 /* Do a sanity check. If not valid, some code below may do odd
347 * things. 356 * things.
348 */ 357 */
349 if (darklevel > MAX_DARKNESS) 358 if (darklevel > MAX_DARKNESS)
399 apply_light<los_brighten> (op, x - op->x, y - op->y, light, light_atten [light + MAX_LIGHT_RADIUS]); 408 apply_light<los_brighten> (op, x - op->x, y - op->y, light, light_atten [light + MAX_LIGHT_RADIUS]);
400 } 409 }
401 410
402 /* grant some vision to the player, based on the darklevel */ 411 /* grant some vision to the player, based on the darklevel */
403 { 412 {
404 int light = clamp (MAX_DARKNESS - darklevel, 0, MAX_LIGHT_RADIUS); 413 int light = clamp (MAX_DARKNESS - darklevel, 0, MAX_DARKNESS);
405 414
406 apply_light<los_brighten> (op, 0, 0, light, light_atten [light + MAX_LIGHT_RADIUS]); 415 apply_light<los_brighten> (op, 0, 0, light, vision_atten [light]);
407 } 416 }
408 } 417 }
409 418
410 // possibly do 2nd pass for rare negative glow radii 419 // possibly do 2nd pass for rare negative glow radii
411 // for effect, those are always considered to be stronger than anything else 420 // for effect, those are always considered to be stronger than anything else
436 * really need for any reasonable game play. 445 * really need for any reasonable game play.
437 */ 446 */
438static void 447static void
439blinded_sight (object *op) 448blinded_sight (object *op)
440{ 449{
441 op->contr->los[LOS_X0][LOS_Y0] = 3; 450 op->contr->los[LOS_X0][LOS_Y0] = 1;
442} 451}
443 452
444/* 453/*
445 * update_los() recalculates the array which specifies what is 454 * update_los() recalculates the array which specifies what is
446 * visible for the given player-object. 455 * visible for the given player-object.
464 } 473 }
465 474
466 if (QUERY_FLAG (op, FLAG_XRAYS)) 475 if (QUERY_FLAG (op, FLAG_XRAYS))
467 for (int dx = -2; dx <= 2; dx++) 476 for (int dx = -2; dx <= 2; dx++)
468 for (int dy = -2; dy <= 2; dy++) 477 for (int dy = -2; dy <= 2; dy++)
469 op->contr->los[dx + LOS_X0][dy + LOS_X0] = 0; 478 min_it (op->contr->los[dx + LOS_X0][dy + LOS_X0], 1);
470} 479}
471 480
472/* update all_map_los is like update_all_los below, 481/* update all_map_los is like update_all_los below,
473 * but updates everyone on the map, no matter where they 482 * but updates everyone on the map, no matter where they
474 * are. This generally should not be used, as a per 483 * are. This generally should not be used, as a per
481 * change_map_light function 490 * change_map_light function
482 */ 491 */
483void 492void
484update_all_map_los (maptile *map) 493update_all_map_los (maptile *map)
485{ 494{
486 for_all_players (pl) 495 for_all_players_on_map (pl, map)
487 if (pl->ob && pl->ob->map == map)
488 pl->do_los = 1; 496 pl->do_los = 1;
489} 497}
490 498
491/* 499/*
492 * This function makes sure that update_los() will be called for all 500 * This function makes sure that update_los() will be called for all
493 * players on the given map within the next frame. 501 * players on the given map within the next frame.
501 * map is the map that changed, x and y are the coordinates. 509 * map is the map that changed, x and y are the coordinates.
502 */ 510 */
503void 511void
504update_all_los (const maptile *map, int x, int y) 512update_all_los (const maptile *map, int x, int y)
505{ 513{
514 map->at (x, y).invalidate ();
515
506 for_all_players (pl) 516 for_all_players (pl)
507 { 517 {
508 /* Player should not have a null map, but do this 518 /* Player should not have a null map, but do this
509 * check as a safety 519 * check as a safety
510 */ 520 */
562 pl->do_los = 1; 572 pl->do_los = 1;
563 } 573 }
564 } 574 }
565} 575}
566 576
577static const int season_timechange[5][HOURS_PER_DAY] = {
578 /* 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 */
579 { 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1},
580 { 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0},
581 { 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0},
582 { 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0},
583 { 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0}
584};
585
586void
587maptile::set_darkness_map ()
588{
589 timeofday_t tod;
590
591 if (!outdoor)
592 return;
593
594 get_tod (&tod);
595 darkness = 0;
596
597 for (int i = HOURS_PER_DAY / 2; i < HOURS_PER_DAY; i++)
598 change_map_light (season_timechange[tod.season][i]);
599
600 for (int i = 0; i <= tod.hour; i++)
601 change_map_light (season_timechange[tod.season][i]);
602}
603
604/*
605 * Compute the darkness level for all maps in the game. Requires the
606 * time of day as an argument.
607 */
608
609static void
610dawn_to_dusk (const timeofday_t * tod)
611{
612 /* If the light level isn't changing, no reason to do all
613 * the work below.
614 */
615 if (season_timechange[tod->season][tod->hour] == 0)
616 return;
617
618 maptile::change_all_map_light (season_timechange[tod->season][tod->hour]);
619}
620
621void
622adjust_daylight ()
623{
624 timeofday_t tod;
625
626 get_tod (&tod);
627 dawn_to_dusk (&tod);
628}
629
567/* 630/*
568 * make_sure_seen: The object is supposed to be visible through walls, thus 631 * make_sure_seen: The object is supposed to be visible through walls, thus
569 * check if any players are nearby, and edit their LOS array. 632 * check if any players are nearby, and edit their LOS array.
570 */ 633 */
571void 634void

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines