… | |
… | |
32 | * block view in our tables. |
32 | * block view in our tables. |
33 | * .4 or less lets you see through walls. .5 is about right. |
33 | * .4 or less lets you see through walls. .5 is about right. |
34 | */ |
34 | */ |
35 | |
35 | |
36 | #define SPACE_BLOCK 0.5 |
36 | #define SPACE_BLOCK 0.5 |
37 | #define MAX_DARKNESS_LOS 4 /* 4 == totally dark */ |
|
|
38 | |
37 | |
39 | typedef struct blstr |
38 | typedef struct blstr |
40 | { |
39 | { |
41 | int x[4], y[4]; |
40 | int x[4], y[4]; |
42 | int index; |
41 | int index; |
… | |
… | |
195 | #endif |
194 | #endif |
196 | /* we need to adjust to the fact that the socket |
195 | /* we need to adjust to the fact that the socket |
197 | * code wants the los to start from the 0,0 |
196 | * code wants the los to start from the 0,0 |
198 | * and not be relative to middle of los array. |
197 | * and not be relative to middle of los array. |
199 | */ |
198 | */ |
200 | op->contr->blocked_los[ax][ay] = 100; |
199 | op->contr->blocked_los[ax][ay] = LOS_BLOCKED; |
201 | set_wall (op, dx, dy); |
200 | set_wall (op, dx, dy); |
202 | } |
201 | } |
203 | } |
202 | } |
204 | |
203 | |
205 | /* |
204 | /* |
… | |
… | |
233 | |
232 | |
234 | /* If this space is already blocked, prune the processing - presumably |
233 | /* If this space is already blocked, prune the processing - presumably |
235 | * whatever has set this space to be blocked has done the work and already |
234 | * whatever has set this space to be blocked has done the work and already |
236 | * done the dependency chain. |
235 | * done the dependency chain. |
237 | */ |
236 | */ |
238 | if (op->contr->blocked_los[ax][ay] == 100) |
237 | if (op->contr->blocked_los[ax][ay] == LOS_BLOCKED) |
239 | return; |
238 | return; |
240 | |
|
|
241 | |
239 | |
242 | if (get_map_flags (op->map, NULL, op->x + x - MAP_CLIENT_X / 2, op->y + y - MAP_CLIENT_Y / 2, NULL, NULL) & (P_BLOCKSVIEW | P_OUT_OF_MAP)) |
240 | if (get_map_flags (op->map, NULL, op->x + x - MAP_CLIENT_X / 2, op->y + y - MAP_CLIENT_Y / 2, NULL, NULL) & (P_BLOCKSVIEW | P_OUT_OF_MAP)) |
243 | set_wall (op, x, y); |
241 | set_wall (op, x, y); |
244 | } |
242 | } |
245 | |
243 | |
… | |
… | |
325 | { |
323 | { |
326 | for (int radius = -MAX_LIGHT_RADIUS; radius <= MAX_LIGHT_RADIUS; ++radius) |
324 | for (int radius = -MAX_LIGHT_RADIUS; radius <= MAX_LIGHT_RADIUS; ++radius) |
327 | for (int distance = 0; distance <= MAX_LIGHT_RADIUS * 3 / 2; ++distance) |
325 | for (int distance = 0; distance <= MAX_LIGHT_RADIUS * 3 / 2; ++distance) |
328 | { |
326 | { |
329 | // max intensity |
327 | // max intensity |
330 | int intensity = min (MAX_DARKNESS_LOS, abs (radius) + 1); |
328 | int intensity = min (LOS_MAX, abs (radius) + 1); |
331 | |
329 | |
332 | // actual intensity |
330 | // actual intensity |
333 | intensity = max (0, lerp_rd (distance, 0, abs (radius) + 1, intensity, 0)); |
331 | intensity = max (0, lerp_rd (distance, 0, abs (radius) + 1, intensity, 0)); |
334 | |
332 | |
335 | darkness [radius + MAX_LIGHT_RADIUS][distance] = radius < 0 |
333 | darkness [radius + MAX_LIGHT_RADIUS][distance] = radius < 0 |
336 | ? min (3, intensity) |
334 | ? min (3, intensity) |
337 | : MAX_DARKNESS_LOS - intensity; |
335 | : LOS_MAX - intensity; |
338 | } |
336 | } |
339 | } |
337 | } |
340 | } darkness_init; |
338 | } darkness_init; |
341 | |
339 | |
342 | static void |
340 | static void |
… | |
… | |
348 | |
346 | |
349 | darklevel = m->darkness; |
347 | darklevel = m->darkness; |
350 | |
348 | |
351 | /* If the player can see in the dark, lower the darklevel for him */ |
349 | /* If the player can see in the dark, lower the darklevel for him */ |
352 | if (QUERY_FLAG (op, FLAG_SEE_IN_DARK)) |
350 | if (QUERY_FLAG (op, FLAG_SEE_IN_DARK)) |
353 | darklevel -= MAX_DARKNESS_LOS / 2; |
351 | darklevel -= LOS_MAX / 2; |
354 | |
352 | |
355 | /* add light, by finding all (non-null) nearby light sources, then |
353 | /* add light, by finding all (non-null) nearby light sources, then |
356 | * mark those squares specially. If the darklevel<1, there is no |
354 | * mark those squares specially. If the darklevel<1, there is no |
357 | * reason to do this, so we skip this function |
355 | * reason to do this, so we skip this function |
358 | */ |
356 | */ |
… | |
… | |
370 | } |
368 | } |
371 | |
369 | |
372 | /* first, make everything totally dark */ |
370 | /* first, make everything totally dark */ |
373 | for (x = 0; x < op->contr->ns->mapx; x++) |
371 | for (x = 0; x < op->contr->ns->mapx; x++) |
374 | for (y = 0; y < op->contr->ns->mapy; y++) |
372 | for (y = 0; y < op->contr->ns->mapy; y++) |
375 | if (op->contr->blocked_los[x][y] != 100) |
373 | if (op->contr->blocked_los[x][y] != LOS_BLOCKED) |
376 | op->contr->blocked_los[x][y] = MAX_DARKNESS_LOS; |
374 | op->contr->blocked_los[x][y] = LOS_MAX; |
377 | |
375 | |
378 | int half_x = op->contr->ns->mapx / 2; |
376 | int half_x = op->contr->ns->mapx / 2; |
379 | int half_y = op->contr->ns->mapy / 2; |
377 | int half_y = op->contr->ns->mapy / 2; |
380 | |
378 | |
381 | int min_x = op->x - half_x - MAX_LIGHT_RADIUS; |
379 | int min_x = op->x - half_x - MAX_LIGHT_RADIUS; |
… | |
… | |
415 | */ |
413 | */ |
416 | const sint8 *darkness_table = darkness [light + MAX_LIGHT_RADIUS]; |
414 | const sint8 *darkness_table = darkness [light + MAX_LIGHT_RADIUS]; |
417 | |
415 | |
418 | for (int ax = max (0, basex - light); ax <= min (basex + light, op->contr->ns->mapx - 1); ax++) |
416 | for (int ax = max (0, basex - light); ax <= min (basex + light, op->contr->ns->mapx - 1); ax++) |
419 | for (int ay = max (0, basey - light); ay <= min (basey + light, op->contr->ns->mapy - 1); ay++) |
417 | for (int ay = max (0, basey - light); ay <= min (basey + light, op->contr->ns->mapy - 1); ay++) |
420 | if (op->contr->blocked_los[ax][ay] != 100) |
418 | if (op->contr->blocked_los[ax][ay] != LOS_BLOCKED) |
421 | min_it (op->contr->blocked_los[ax][ay], darkness_table [idistance (ax - basex, ay - basey)]); |
419 | min_it (op->contr->blocked_los[ax][ay], darkness_table [idistance (ax - basex, ay - basey)]); |
422 | } |
420 | } |
423 | } |
421 | } |
424 | |
422 | |
425 | // psosibly do 2nd pass for rare negative glow radii |
423 | // psosibly do 2nd pass for rare negative glow radii |
… | |
… | |
442 | { |
440 | { |
443 | const sint8 *darkness_table = darkness [light + MAX_LIGHT_RADIUS]; |
441 | const sint8 *darkness_table = darkness [light + MAX_LIGHT_RADIUS]; |
444 | |
442 | |
445 | for (int ax = max (0, basex + light); ax <= min (basex - light, op->contr->ns->mapx - 1); ax++) |
443 | for (int ax = max (0, basex + light); ax <= min (basex - light, op->contr->ns->mapx - 1); ax++) |
446 | for (int ay = max (0, basey + light); ay <= min (basey - light, op->contr->ns->mapy - 1); ay++) |
444 | for (int ay = max (0, basey + light); ay <= min (basey - light, op->contr->ns->mapy - 1); ay++) |
447 | if (op->contr->blocked_los[ax][ay] != 100) |
445 | if (op->contr->blocked_los[ax][ay] != LOS_BLOCKED) |
448 | max_it (op->contr->blocked_los[ax][ay], darkness_table [idistance (ax - basex, ay - basey)]); |
446 | max_it (op->contr->blocked_los[ax][ay], darkness_table [idistance (ax - basex, ay - basey)]); |
449 | } |
447 | } |
450 | } |
448 | } |
451 | |
449 | |
452 | /* Outdoor should never really be completely pitch black dark like |
450 | /* Outdoor should never really be completely pitch black dark like |
453 | * a dungeon, so let the player at least see a little around themselves |
451 | * a dungeon, so let the player at least see a little around themselves |
454 | */ |
452 | */ |
455 | if (op->map->outdoor && darklevel > MAX_DARKNESS - 3) |
453 | if (op->map->outdoor && darklevel > MAX_DARKNESS - 3) |
456 | { |
454 | { |
457 | if (op->contr->blocked_los[op->contr->ns->mapx / 2][op->contr->ns->mapy / 2] > (MAX_DARKNESS - 3)) |
455 | if (op->contr->blocked_los[op->contr->ns->mapx / 2][op->contr->ns->mapy / 2] > (LOS_MAX - 3)) |
458 | op->contr->blocked_los[op->contr->ns->mapx / 2][op->contr->ns->mapy / 2] = MAX_DARKNESS - 3; |
456 | op->contr->blocked_los[op->contr->ns->mapx / 2][op->contr->ns->mapy / 2] = LOS_MAX - 3; |
459 | |
457 | |
460 | for (x = -1; x <= 1; x++) |
458 | for (x = -1; x <= 1; x++) |
461 | for (y = -1; y <= 1; y++) |
459 | for (y = -1; y <= 1; y++) |
462 | { |
|
|
463 | if (op->contr->blocked_los[x + op->contr->ns->mapx / 2][y + op->contr->ns->mapy / 2] > (MAX_DARKNESS - 2)) |
460 | if (op->contr->blocked_los[x + op->contr->ns->mapx / 2][y + op->contr->ns->mapy / 2] > (LOS_MAX - 2)) |
464 | op->contr->blocked_los[x + op->contr->ns->mapx / 2][y + op->contr->ns->mapy / 2] = MAX_DARKNESS - 2; |
461 | op->contr->blocked_los[x + op->contr->ns->mapx / 2][y + op->contr->ns->mapy / 2] = LOS_MAX - 2; |
465 | } |
|
|
466 | } |
462 | } |
467 | |
463 | |
468 | /* grant some vision to the player, based on the darklevel */ |
464 | /* grant some vision to the player, based on the darklevel */ |
469 | for (x = darklevel - MAX_DARKNESS; x < MAX_DARKNESS + 1 - darklevel; x++) |
465 | for (x = darklevel - MAX_DARKNESS; x < MAX_DARKNESS + 1 - darklevel; x++) |
470 | for (y = darklevel - MAX_DARKNESS; y < MAX_DARKNESS + 1 - darklevel; y++) |
466 | for (y = darklevel - MAX_DARKNESS; y < MAX_DARKNESS + 1 - darklevel; y++) |
471 | if (!(op->contr->blocked_los[x + op->contr->ns->mapx / 2][y + op->contr->ns->mapy / 2] == 100)) |
467 | if (!(op->contr->blocked_los[x + op->contr->ns->mapx / 2][y + op->contr->ns->mapy / 2] == LOS_BLOCKED)) |
472 | op->contr->blocked_los[x + op->contr->ns->mapx / 2][y + op->contr->ns->mapy / 2] -= |
468 | op->contr->blocked_los[x + op->contr->ns->mapx / 2][y + op->contr->ns->mapy / 2] -= |
473 | max (0, 6 - darklevel - max (abs (x), abs (y))); |
469 | max (0, 6 - darklevel - max (abs (x), abs (y))); |
474 | } |
470 | } |
475 | |
471 | |
476 | /* blinded_sight() - sets all viewable squares to blocked except |
472 | /* blinded_sight() - sets all viewable squares to blocked except |
… | |
… | |
483 | { |
479 | { |
484 | int x, y; |
480 | int x, y; |
485 | |
481 | |
486 | for (x = 0; x < op->contr->ns->mapx; x++) |
482 | for (x = 0; x < op->contr->ns->mapx; x++) |
487 | for (y = 0; y < op->contr->ns->mapy; y++) |
483 | for (y = 0; y < op->contr->ns->mapy; y++) |
488 | op->contr->blocked_los[x][y] = 100; |
484 | op->contr->blocked_los[x][y] = LOS_BLOCKED; |
489 | |
485 | |
490 | op->contr->blocked_los[op->contr->ns->mapx / 2][op->contr->ns->mapy / 2] = 0; |
486 | op->contr->blocked_los[op->contr->ns->mapx / 2][op->contr->ns->mapy / 2] = 0; |
491 | } |
487 | } |
492 | |
488 | |
493 | /* |
489 | /* |