… | |
… | |
124 | // spiral path algorithm below, except when very little |
124 | // spiral path algorithm below, except when very little |
125 | // area is visible, in which case it is slower. which evens |
125 | // area is visible, in which case it is slower. which evens |
126 | // out los calculation times between large and small los maps. |
126 | // out los calculation times between large and small los maps. |
127 | // apply_lights also iterates over this area, maybe these |
127 | // apply_lights also iterates over this area, maybe these |
128 | // two passes could be combined somehow. |
128 | // two passes could be combined somehow. |
129 | 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) |
130 | { |
130 | { |
131 | los_info &l = los [LOS_X0 + dx][LOS_Y0 + dy]; |
131 | los_info &l = los [LOS_X0 + dx][LOS_Y0 + dy]; |
132 | 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; |
133 | } |
133 | } |
134 | } |
134 | } |
… | |
… | |
301 | for (int distance = 0; distance <= MAX_VISION * 3 / 2; ++distance) |
301 | for (int distance = 0; distance <= MAX_VISION * 3 / 2; ++distance) |
302 | 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; |
303 | } |
303 | } |
304 | } los_init; |
304 | } los_init; |
305 | |
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 |
306 | sint8 |
314 | sint8 |
307 | los_brighten (sint8 b, sint8 l) |
315 | los_brighten (sint8 b, sint8 l) |
308 | { |
316 | { |
309 | return b == LOS_BLOCKED ? b : min (b, l); |
317 | return b == LOS_BLOCKED ? b : min (b, l); |
310 | } |
318 | } |
311 | |
319 | |
|
|
320 | // darken area, respect los |
312 | sint8 |
321 | sint8 |
313 | los_darken (sint8 b, sint8 l) |
322 | los_darken (sint8 b, sint8 l) |
314 | { |
323 | { |
315 | return max (b, l); |
324 | return max (b, l); |
316 | } |
325 | } |
… | |
… | |
341 | * mark those squares specially. |
350 | * mark those squares specially. |
342 | */ |
351 | */ |
343 | static void |
352 | static void |
344 | apply_lights (player *pl) |
353 | apply_lights (player *pl) |
345 | { |
354 | { |
346 | object *op = pl->observe; |
355 | object *op = pl->viewpoint; |
347 | int darklevel = op->map->darklevel (); |
356 | int darklevel = op->map->darklevel (); |
348 | |
357 | |
349 | int half_x = pl->ns->mapx / 2; |
358 | int half_x = pl->ns->mapx / 2; |
350 | int half_y = pl->ns->mapy / 2; |
359 | int half_y = pl->ns->mapy / 2; |
351 | |
360 | |
352 | int pass2 = 0; // negative lights have an extra pass |
361 | int pass2 = 0; // negative lights have an extra pass |
353 | |
362 | |
354 | maprect *rects = pl->observe->map->split_to_tiles ( |
363 | maprect *rects = pl->viewpoint->map->split_to_tiles ( |
355 | pl->observe->x - half_x - MAX_LIGHT_RADIUS, |
364 | pl->viewpoint->x - half_x - MAX_LIGHT_RADIUS, |
356 | pl->observe->y - half_y - MAX_LIGHT_RADIUS, |
365 | pl->viewpoint->y - half_y - MAX_LIGHT_RADIUS, |
357 | pl->observe->x + half_x + MAX_LIGHT_RADIUS + 1, |
366 | pl->viewpoint->x + half_x + MAX_LIGHT_RADIUS + 1, |
358 | pl->observe->y + half_y + MAX_LIGHT_RADIUS + 1 |
367 | pl->viewpoint->y + half_y + MAX_LIGHT_RADIUS + 1 |
359 | ); |
368 | ); |
360 | |
369 | |
361 | /* If the player can see in the dark, increase light/vision radius */ |
370 | /* If the player can see in the dark, increase light/vision radius */ |
362 | int bonus = op->flag [FLAG_SEE_IN_DARK] ? SEE_IN_DARK_RADIUS : 0; |
371 | int bonus = op->flag [FLAG_SEE_IN_DARK] ? SEE_IN_DARK_RADIUS : 0; |
363 | |
372 | |
… | |
… | |
387 | if (light < 0) |
396 | if (light < 0) |
388 | pass2 = 1; |
397 | pass2 = 1; |
389 | else |
398 | else |
390 | { |
399 | { |
391 | light = clamp (light + bonus, 0, MAX_LIGHT_RADIUS); |
400 | light = clamp (light + bonus, 0, MAX_LIGHT_RADIUS); |
392 | apply_light<los_brighten> (pl, dx - pl->observe->x, dy - pl->observe->y, light, light_atten [light + MAX_LIGHT_RADIUS]); |
401 | apply_light<los_brighten> (pl, dx - pl->viewpoint->x, dy - pl->viewpoint->y, light, light_atten [light + MAX_LIGHT_RADIUS]); |
393 | } |
402 | } |
394 | } |
403 | } |
395 | |
404 | |
396 | /* grant some vision to the player, based on outside, outdoor, and darklevel */ |
405 | /* grant some vision to the player, based on outside, outdoor, and darklevel */ |
397 | { |
406 | { |
… | |
… | |
407 | light = clamp (light + bonus, 0, MAX_VISION); |
416 | light = clamp (light + bonus, 0, MAX_VISION); |
408 | |
417 | |
409 | apply_light<los_brighten> (pl, 0, 0, light, vision_atten [light]); |
418 | apply_light<los_brighten> (pl, 0, 0, light, vision_atten [light]); |
410 | } |
419 | } |
411 | } |
420 | } |
|
|
421 | |
|
|
422 | // when we fly high, we have some minimum viewable area around us, like x-ray |
|
|
423 | if (op->move_type & MOVE_FLY_HIGH) |
|
|
424 | apply_light<los_brighten_nolos> (pl, 0, 0, 9, vision_atten [9]); |
412 | |
425 | |
413 | // possibly do 2nd pass for rare negative glow radii |
426 | // possibly do 2nd pass for rare negative glow radii |
414 | // for effect, those are always considered to be stronger than anything else |
427 | // for effect, those are always considered to be stronger than anything else |
415 | // but they can't darken a place completely |
428 | // but they can't darken a place completely |
416 | if (pass2) |
429 | if (pass2) |
… | |
… | |
422 | sint8 light = ms.light; |
435 | sint8 light = ms.light; |
423 | |
436 | |
424 | if (expect_false (light < 0)) |
437 | if (expect_false (light < 0)) |
425 | { |
438 | { |
426 | light = clamp (light - bonus, 0, MAX_DARKNESS); |
439 | light = clamp (light - bonus, 0, MAX_DARKNESS); |
427 | apply_light<los_darken> (pl, dx - pl->observe->x, dy - pl->observe->y, -light, light_atten [light + MAX_LIGHT_RADIUS]); |
440 | apply_light<los_darken> (pl, dx - pl->viewpoint->x, dy - pl->viewpoint->y, -light, light_atten [light + MAX_LIGHT_RADIUS]); |
428 | } |
441 | } |
429 | } |
442 | } |
430 | } |
443 | } |
431 | |
444 | |
432 | /* blinded_sight() - sets all viewable squares to blocked except |
445 | /* blinded_sight() - sets all viewable squares to blocked except |
… | |
… | |
450 | if (ob->flag [FLAG_REMOVED])//D really needed? |
463 | if (ob->flag [FLAG_REMOVED])//D really needed? |
451 | return; |
464 | return; |
452 | |
465 | |
453 | if (ob->flag [FLAG_WIZLOOK]) |
466 | if (ob->flag [FLAG_WIZLOOK]) |
454 | clear_los (0); |
467 | clear_los (0); |
455 | else if (observe->flag [FLAG_BLIND]) /* player is blind */ |
468 | else if (viewpoint->flag [FLAG_BLIND]) /* player is blind */ |
456 | { |
469 | { |
457 | clear_los (); |
470 | clear_los (); |
458 | blinded_sight (this); |
471 | blinded_sight (this); |
459 | } |
472 | } |
460 | else |
473 | else |
… | |
… | |
462 | clear_los (); |
475 | clear_los (); |
463 | calculate_los (this); |
476 | calculate_los (this); |
464 | apply_lights (this); |
477 | apply_lights (this); |
465 | } |
478 | } |
466 | |
479 | |
467 | if (observe->flag [FLAG_XRAYS]) |
480 | if (viewpoint->flag [FLAG_XRAYS]) |
468 | for (int dx = -2; dx <= 2; dx++) |
481 | for (int dx = -2; dx <= 2; dx++) |
469 | for (int dy = -2; dy <= 2; dy++) |
482 | for (int dy = -2; dy <= 2; dy++) |
470 | min_it (los[dx + LOS_X0][dy + LOS_Y0], 1); |
483 | min_it (los[dx + LOS_X0][dy + LOS_Y0], 1); |
471 | } |
484 | } |
472 | |
485 | |