1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
|
|
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
|
|
7 | * |
5 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
6 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * the terms of the Affero GNU General Public License as published by the |
7 | * the terms of the Affero GNU General Public License as published by the |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
8 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * option) any later version. |
9 | * option) any later version. |
… | |
… | |
126 | // spiral path algorithm below, except when very little |
124 | // spiral path algorithm below, except when very little |
127 | // area is visible, in which case it is slower. which evens |
125 | // area is visible, in which case it is slower. which evens |
128 | // out los calculation times between large and small los maps. |
126 | // out los calculation times between large and small los maps. |
129 | // apply_lights also iterates over this area, maybe these |
127 | // apply_lights also iterates over this area, maybe these |
130 | // two passes could be combined somehow. |
128 | // two passes could be combined somehow. |
131 | unordered_mapwalk (pl->observe, -half_x, -half_y, half_x, half_y) |
129 | unordered_mapwalk (pl->viewpoint, -half_x, -half_y, half_x, half_y) |
132 | { |
130 | { |
133 | los_info &l = los [LOS_X0 + dx][LOS_Y0 + dy]; |
131 | los_info &l = los [LOS_X0 + dx][LOS_Y0 + dy]; |
134 | l.flags = m->at (nx, ny).flags () & P_BLOCKSVIEW ? FLG_BLOCKED : 0; |
132 | l.flags = m->at (nx, ny).flags () & P_BLOCKSVIEW ? FLG_BLOCKED : 0; |
135 | } |
133 | } |
136 | } |
134 | } |
… | |
… | |
303 | for (int distance = 0; distance <= MAX_VISION * 3 / 2; ++distance) |
301 | for (int distance = 0; distance <= MAX_VISION * 3 / 2; ++distance) |
304 | vision_atten [radius][distance] = distance <= radius ? clamp (lerp (radius, 0, MAX_DARKNESS, 3, 0), 0, 3) : 4; |
302 | vision_atten [radius][distance] = distance <= radius ? clamp (lerp (radius, 0, MAX_DARKNESS, 3, 0), 0, 3) : 4; |
305 | } |
303 | } |
306 | } los_init; |
304 | } los_init; |
307 | |
305 | |
|
|
306 | // brighten area, ignore los |
|
|
307 | sint8 |
|
|
308 | los_brighten_nolos (sint8 b, sint8 l) |
|
|
309 | { |
|
|
310 | return min (b, l); |
|
|
311 | } |
|
|
312 | |
|
|
313 | // brighten area, but respect los |
308 | sint8 |
314 | sint8 |
309 | los_brighten (sint8 b, sint8 l) |
315 | los_brighten (sint8 b, sint8 l) |
310 | { |
316 | { |
311 | return b == LOS_BLOCKED ? b : min (b, l); |
317 | return b == LOS_BLOCKED ? b : min (b, l); |
312 | } |
318 | } |
313 | |
319 | |
|
|
320 | // darken area, respect los |
314 | sint8 |
321 | sint8 |
315 | los_darken (sint8 b, sint8 l) |
322 | los_darken (sint8 b, sint8 l) |
316 | { |
323 | { |
317 | return max (b, l); |
324 | return max (b, l); |
318 | } |
325 | } |
… | |
… | |
343 | * mark those squares specially. |
350 | * mark those squares specially. |
344 | */ |
351 | */ |
345 | static void |
352 | static void |
346 | apply_lights (player *pl) |
353 | apply_lights (player *pl) |
347 | { |
354 | { |
348 | object *op = pl->observe; |
355 | object *op = pl->viewpoint; |
349 | int darklevel = op->map->darklevel (); |
356 | int darklevel = op->map->darklevel (); |
|
|
357 | maptile::outdoor_darkness = 4;//D |
350 | |
358 | |
351 | int half_x = pl->ns->mapx / 2; |
359 | int half_x = pl->ns->mapx / 2; |
352 | int half_y = pl->ns->mapy / 2; |
360 | int half_y = pl->ns->mapy / 2; |
353 | |
361 | |
354 | int pass2 = 0; // negative lights have an extra pass |
362 | int pass2 = 0; // negative lights have an extra pass |
355 | |
363 | |
356 | maprect *rects = pl->observe->map->split_to_tiles ( |
364 | maprect *rects = pl->viewpoint->map->split_to_tiles ( |
357 | pl->observe->x - half_x - MAX_LIGHT_RADIUS, |
365 | pl->viewpoint->x - half_x - MAX_LIGHT_RADIUS, |
358 | pl->observe->y - half_y - MAX_LIGHT_RADIUS, |
366 | pl->viewpoint->y - half_y - MAX_LIGHT_RADIUS, |
359 | pl->observe->x + half_x + MAX_LIGHT_RADIUS + 1, |
367 | pl->viewpoint->x + half_x + MAX_LIGHT_RADIUS + 1, |
360 | pl->observe->y + half_y + MAX_LIGHT_RADIUS + 1 |
368 | pl->viewpoint->y + half_y + MAX_LIGHT_RADIUS + 1 |
361 | ); |
369 | ); |
362 | |
370 | |
363 | /* If the player can see in the dark, increase light/vision radius */ |
371 | /* If the player can see in the dark, increase light/vision radius */ |
364 | int bonus = op->flag [FLAG_SEE_IN_DARK] ? SEE_IN_DARK_RADIUS : 0; |
372 | int bonus = op->flag [FLAG_SEE_IN_DARK] ? SEE_IN_DARK_RADIUS : 0; |
365 | |
373 | |
… | |
… | |
389 | if (light < 0) |
397 | if (light < 0) |
390 | pass2 = 1; |
398 | pass2 = 1; |
391 | else |
399 | else |
392 | { |
400 | { |
393 | light = clamp (light + bonus, 0, MAX_LIGHT_RADIUS); |
401 | light = clamp (light + bonus, 0, MAX_LIGHT_RADIUS); |
394 | apply_light<los_brighten> (pl, dx - pl->observe->x, dy - pl->observe->y, light, light_atten [light + MAX_LIGHT_RADIUS]); |
402 | apply_light<los_brighten> (pl, dx - pl->viewpoint->x, dy - pl->viewpoint->y, light, light_atten [light + MAX_LIGHT_RADIUS]); |
395 | } |
403 | } |
396 | } |
404 | } |
397 | |
405 | |
398 | /* grant some vision to the player, based on outside, outdoor, and darklevel */ |
406 | /* grant some vision to the player, based on outside, outdoor, and darklevel */ |
399 | { |
407 | { |
… | |
… | |
409 | light = clamp (light + bonus, 0, MAX_VISION); |
417 | light = clamp (light + bonus, 0, MAX_VISION); |
410 | |
418 | |
411 | apply_light<los_brighten> (pl, 0, 0, light, vision_atten [light]); |
419 | apply_light<los_brighten> (pl, 0, 0, light, vision_atten [light]); |
412 | } |
420 | } |
413 | } |
421 | } |
|
|
422 | |
|
|
423 | // when we fly high, we have some minimum viewable area around us, like x-ray |
|
|
424 | if (op->move_type & MOVE_FLY_HIGH) |
|
|
425 | apply_light<los_brighten_nolos> (pl, 0, 0, 9, vision_atten [9]); |
414 | |
426 | |
415 | // possibly do 2nd pass for rare negative glow radii |
427 | // possibly do 2nd pass for rare negative glow radii |
416 | // for effect, those are always considered to be stronger than anything else |
428 | // for effect, those are always considered to be stronger than anything else |
417 | // but they can't darken a place completely |
429 | // but they can't darken a place completely |
418 | if (pass2) |
430 | if (pass2) |
… | |
… | |
424 | sint8 light = ms.light; |
436 | sint8 light = ms.light; |
425 | |
437 | |
426 | if (expect_false (light < 0)) |
438 | if (expect_false (light < 0)) |
427 | { |
439 | { |
428 | light = clamp (light - bonus, 0, MAX_DARKNESS); |
440 | light = clamp (light - bonus, 0, MAX_DARKNESS); |
429 | apply_light<los_darken> (pl, dx - pl->observe->x, dy - pl->observe->y, -light, light_atten [light + MAX_LIGHT_RADIUS]); |
441 | apply_light<los_darken> (pl, dx - pl->viewpoint->x, dy - pl->viewpoint->y, -light, light_atten [light + MAX_LIGHT_RADIUS]); |
430 | } |
442 | } |
431 | } |
443 | } |
432 | } |
444 | } |
433 | |
445 | |
434 | /* blinded_sight() - sets all viewable squares to blocked except |
446 | /* blinded_sight() - sets all viewable squares to blocked except |
… | |
… | |
452 | if (ob->flag [FLAG_REMOVED])//D really needed? |
464 | if (ob->flag [FLAG_REMOVED])//D really needed? |
453 | return; |
465 | return; |
454 | |
466 | |
455 | if (ob->flag [FLAG_WIZLOOK]) |
467 | if (ob->flag [FLAG_WIZLOOK]) |
456 | clear_los (0); |
468 | clear_los (0); |
457 | else if (observe->flag [FLAG_BLIND]) /* player is blind */ |
469 | else if (viewpoint->flag [FLAG_BLIND]) /* player is blind */ |
458 | { |
470 | { |
459 | clear_los (); |
471 | clear_los (); |
460 | blinded_sight (this); |
472 | blinded_sight (this); |
461 | } |
473 | } |
462 | else |
474 | else |
… | |
… | |
464 | clear_los (); |
476 | clear_los (); |
465 | calculate_los (this); |
477 | calculate_los (this); |
466 | apply_lights (this); |
478 | apply_lights (this); |
467 | } |
479 | } |
468 | |
480 | |
469 | if (observe->flag [FLAG_XRAYS]) |
481 | if (viewpoint->flag [FLAG_XRAYS]) |
470 | for (int dx = -2; dx <= 2; dx++) |
482 | for (int dx = -2; dx <= 2; dx++) |
471 | for (int dy = -2; dy <= 2; dy++) |
483 | for (int dy = -2; dy <= 2; dy++) |
472 | min_it (los[dx + LOS_X0][dy + LOS_Y0], 1); |
484 | min_it (los[dx + LOS_X0][dy + LOS_Y0], 1); |
473 | } |
485 | } |
474 | |
486 | |