… | |
… | |
23 | |
23 | |
24 | #include <global.h> |
24 | #include <global.h> |
25 | #include <cmath> |
25 | #include <cmath> |
26 | |
26 | |
27 | #define SEE_IN_DARK_RADIUS 2 |
27 | #define SEE_IN_DARK_RADIUS 2 |
|
|
28 | #define MAX_VISION 10 // maximum visible radius |
28 | |
29 | |
29 | // los flags |
30 | // los flags |
30 | enum { |
31 | enum { |
31 | FLG_XI = 0x01, // we have an x-parent |
32 | FLG_XI = 0x01, // we have an x-parent |
32 | FLG_YI = 0x02, // we have an y-parent |
33 | FLG_YI = 0x02, // we have an y-parent |
… | |
… | |
270 | } |
271 | } |
271 | } |
272 | } |
272 | |
273 | |
273 | /* radius, distance => lightness adjust */ |
274 | /* radius, distance => lightness adjust */ |
274 | static sint8 light_atten[MAX_LIGHT_RADIUS * 2 + 1][MAX_LIGHT_RADIUS * 3 / 2 + 1]; |
275 | static sint8 light_atten[MAX_LIGHT_RADIUS * 2 + 1][MAX_LIGHT_RADIUS * 3 / 2 + 1]; |
275 | static sint8 vision_atten[MAX_DARKNESS + SEE_IN_DARK_RADIUS + 1][(MAX_DARKNESS + SEE_IN_DARK_RADIUS) * 3 / 2 + 1]; |
276 | static sint8 vision_atten[MAX_VISION + 1][MAX_VISION * 3 / 2 + 1]; |
276 | |
277 | |
277 | static struct los_init |
278 | static struct los_init |
278 | { |
279 | { |
279 | los_init () |
280 | los_init () |
280 | { |
281 | { |
… | |
… | |
295 | ? min (3, intensity) |
296 | ? min (3, intensity) |
296 | : LOS_MAX - intensity; |
297 | : LOS_MAX - intensity; |
297 | } |
298 | } |
298 | |
299 | |
299 | /* for general vision */ |
300 | /* for general vision */ |
300 | for (int radius = 0; radius <= MAX_DARKNESS + SEE_IN_DARK_RADIUS; ++radius) |
301 | for (int radius = 0; radius <= MAX_VISION; ++radius) |
301 | for (int distance = 0; distance <= (MAX_DARKNESS + SEE_IN_DARK_RADIUS) * 3 / 2; ++distance) |
302 | for (int distance = 0; distance <= MAX_VISION * 3 / 2; ++distance) |
302 | vision_atten [radius][distance] = distance <= radius ? 3 : 4; |
303 | vision_atten [radius][distance] = distance <= radius ? clamp (lerp (radius, 0, MAX_DARKNESS, 3, 0), 0, 3) : 4; |
303 | } |
304 | } |
304 | } los_init; |
305 | } los_init; |
305 | |
306 | |
306 | sint8 |
307 | sint8 |
307 | los_brighten (sint8 b, sint8 l) |
308 | los_brighten (sint8 b, sint8 l) |
… | |
… | |
355 | pl->observe->x - half_x - MAX_LIGHT_RADIUS, |
356 | pl->observe->x - half_x - MAX_LIGHT_RADIUS, |
356 | pl->observe->y - half_y - MAX_LIGHT_RADIUS, |
357 | pl->observe->y - half_y - MAX_LIGHT_RADIUS, |
357 | pl->observe->x + half_x + MAX_LIGHT_RADIUS + 1, |
358 | pl->observe->x + half_x + MAX_LIGHT_RADIUS + 1, |
358 | pl->observe->y + half_y + MAX_LIGHT_RADIUS + 1 |
359 | pl->observe->y + half_y + MAX_LIGHT_RADIUS + 1 |
359 | ); |
360 | ); |
|
|
361 | |
|
|
362 | /* If the player can see in the dark, increase light/vision radius */ |
|
|
363 | int bonus = op->flag [FLAG_SEE_IN_DARK] ? SEE_IN_DARK_RADIUS : 0; |
360 | |
364 | |
361 | if (!darklevel) |
365 | if (!darklevel) |
362 | pass2 = 1; |
366 | pass2 = 1; |
363 | else |
367 | else |
364 | { |
368 | { |
… | |
… | |
382 | |
386 | |
383 | if (expect_false (light)) |
387 | if (expect_false (light)) |
384 | if (light < 0) |
388 | if (light < 0) |
385 | pass2 = 1; |
389 | pass2 = 1; |
386 | else |
390 | else |
|
|
391 | { |
|
|
392 | light = clamp (light + bonus, 0, MAX_LIGHT_RADIUS); |
387 | apply_light<los_brighten> (pl, dx - pl->observe->x, dy - pl->observe->y, light, light_atten [light + MAX_LIGHT_RADIUS]); |
393 | apply_light<los_brighten> (pl, dx - pl->observe->x, dy - pl->observe->y, light, light_atten [light + MAX_LIGHT_RADIUS]); |
|
|
394 | } |
388 | } |
395 | } |
389 | |
396 | |
390 | /* grant some vision to the player, based on the darklevel */ |
397 | /* grant some vision to the player, based on outside, outdoor, and darklevel */ |
391 | { |
398 | { |
392 | int light = clamp (MAX_DARKNESS - darklevel, 0, MAX_DARKNESS); |
399 | int light; |
393 | |
400 | |
394 | /* If the player can see in the dark, lower the darklevel for him */ |
401 | if (!op->map->outdoor) // not outdoor, darkness becomes light radius |
395 | if (op->flag [FLAG_SEE_IN_DARK]) |
402 | light = op->map->darkness; |
396 | light += SEE_IN_DARK_RADIUS; |
403 | else if (op->map->darkness > 0) // outdoor and darkness > 0 => use darkness as max radius |
|
|
404 | light = lerp_rd (maptile::outdoor_darkness + 0, 0, MAX_DARKNESS, MAX_DARKNESS - op->map->darkness, 0); |
|
|
405 | else // outdoor and darkness <= 0 => start wide and decrease quickly |
|
|
406 | light = lerp (maptile::outdoor_darkness + op->map->darkness, 0, MAX_DARKNESS, MAX_VISION, 2); |
|
|
407 | |
|
|
408 | light = clamp (light, 0, MAX_VISION); |
397 | |
409 | |
398 | apply_light<los_brighten> (pl, 0, 0, light, vision_atten [light]); |
410 | apply_light<los_brighten> (pl, 0, 0, light, vision_atten [light]); |
399 | } |
411 | } |
400 | } |
412 | } |
401 | |
413 | |
… | |
… | |
409 | mapspace &ms = m->at (nx, ny); |
421 | mapspace &ms = m->at (nx, ny); |
410 | ms.update (); |
422 | ms.update (); |
411 | sint8 light = ms.light; |
423 | sint8 light = ms.light; |
412 | |
424 | |
413 | if (expect_false (light < 0)) |
425 | if (expect_false (light < 0)) |
|
|
426 | { |
|
|
427 | light = clamp (light - bonus, 0, MAX_DARKNESS); |
414 | apply_light<los_darken> (pl, dx - pl->observe->x, dy - pl->observe->y, -light, light_atten [light + MAX_LIGHT_RADIUS]); |
428 | apply_light<los_darken> (pl, dx - pl->observe->x, dy - pl->observe->y, -light, light_atten [light + MAX_LIGHT_RADIUS]); |
|
|
429 | } |
415 | } |
430 | } |
416 | } |
431 | } |
417 | |
432 | |
418 | /* blinded_sight() - sets all viewable squares to blocked except |
433 | /* blinded_sight() - sets all viewable squares to blocked except |
419 | * for the one the central one that the player occupies. A little |
434 | * for the one the central one that the player occupies. A little |