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.30 by root, Mon Apr 21 23:35:24 2008 UTC vs.
Revision 1.31 by root, Thu Dec 4 01:07:35 2008 UTC

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_UNLIGHTED_VISION 4
37 38
38typedef struct blstr 39typedef struct blstr
39{ 40{
40 int x[4], y[4]; 41 int x[4], y[4];
41 int index; 42 int index;
347 348
348 /* First, limit player furthest (unlighted) vision */ 349 /* First, limit player furthest (unlighted) vision */
349 for (x = 0; x < op->contr->ns->mapx; x++) 350 for (x = 0; x < op->contr->ns->mapx; x++)
350 for (y = 0; y < op->contr->ns->mapy; y++) 351 for (y = 0; y < op->contr->ns->mapy; y++)
351 if (op->contr->blocked_los[x][y] != 100) 352 if (op->contr->blocked_los[x][y] != 100)
352 op->contr->blocked_los[x][y] = MAX_LIGHT_RADII; 353 op->contr->blocked_los[x][y] = MAX_UNLIGHTED_VISION;
353 354
354 /* the spaces[] darkness value contains the information we need. 355 /* the spaces[] darkness value contains the information we need.
355 * Only process the area of interest. 356 * Only process the area of interest.
356 * the basex, basey values represent the position in the op->contr->blocked_los 357 * the basex, basey values represent the position in the op->contr->blocked_los
357 * array. Its easier to just increment them here (and start with the right 358 * array. Its easier to just increment them here (and start with the right
358 * value) than to recalculate them down below. 359 * value) than to recalculate them down below.
359 */ 360 */
360 for (x = (op->x - op->contr->ns->mapx / 2 - MAX_LIGHT_RADII), basex = -MAX_LIGHT_RADII; 361 for (x = (op->x - op->contr->ns->mapx / 2 - MAX_LIGHT_RADIUS), basex = -MAX_LIGHT_RADIUS;
361 x <= (op->x + op->contr->ns->mapx / 2 + MAX_LIGHT_RADII); x++, basex++) 362 x <= (op->x + op->contr->ns->mapx / 2 + MAX_LIGHT_RADIUS); x++, basex++)
362 { 363 {
363 364
364 for (y = (op->y - op->contr->ns->mapy / 2 - MAX_LIGHT_RADII), basey = -MAX_LIGHT_RADII; 365 for (y = (op->y - op->contr->ns->mapy / 2 - MAX_LIGHT_RADIUS), basey = -MAX_LIGHT_RADIUS;
365 y <= (op->y + op->contr->ns->mapy / 2 + MAX_LIGHT_RADII); y++, basey++) 366 y <= (op->y + op->contr->ns->mapy / 2 + MAX_LIGHT_RADIUS); y++, basey++)
366 { 367 {
367 m = op->map; 368 m = op->map;
368 nx = x; 369 nx = x;
369 ny = y; 370 ny = y;
370 371
375 376
376 /* This space is providing light, so we need to brighten up the 377 /* This space is providing light, so we need to brighten up the
377 * spaces around here. 378 * spaces around here.
378 */ 379 */
379 light = GET_MAP_LIGHT (m, nx, ny); 380 light = GET_MAP_LIGHT (m, nx, ny);
380 if (light != 0) 381 if (light)
381 { 382 {
382#if 0 383#if 0
383 LOG (llevDebug, "expand_lighted_sight: Found light at x=%d, y=%d, basex=%d, basey=%d\n", x, y, basex, basey); 384 LOG (llevDebug, "expand_lighted_sight: Found light at x=%d, y=%d, basex=%d, basey=%d\n", x, y, basex, basey);
384#endif 385#endif
385 for (ax = basex - light; ax <= basex + light; ax++) 386 for (ax = basex - light; ax <= basex + light; ax++)
386 { 387 {
387 if (ax < 0 || ax >= op->contr->ns->mapx) 388 if (ax < 0 || ax >= op->contr->ns->mapx)
388 continue; 389 continue;
389 390
391 x1 = (basex - ax) * (basex - ax);
392
390 for (ay = basey - light; ay <= basey + light; ay++) 393 for (ay = basey - light; ay <= basey + light; ay++)
391 { 394 {
392 if (ay < 0 || ay >= op->contr->ns->mapy) 395 if (ay < 0 || ay >= op->contr->ns->mapy)
393 continue; 396 continue;
394 397
395 /* If the space is fully blocked, do nothing. Otherwise, we 398 /* If the space is fully blocked, do nothing. Otherwise, we
396 * brighten the space. The further the light is away from the 399 * brighten the space. The further the light is away from the
397 * source (basex-x), the less effect it has. Though light used 400 * source (basex-x), the less effect it has. Though light used
398 * to dim in a square manner, it now dims in a circular manner 401 * to dim in a square manner, it now dims in a roughly circular
399 * using the the pythagorean theorem. glow_radius still
400 * represents the radius 402 * manner. glow_radius still represents the radius.
401 */ 403 */
402 if (op->contr->blocked_los[ax][ay] != 100) 404 if (op->contr->blocked_los[ax][ay] != 100)
403 { 405 {
404 x1 = abs (basex - ax) * abs (basex - ax);
405 y1 = abs (basey - ay) * abs (basey - ay); 406 y1 = (basey - ay) * (basey - ay);
406 407
407 if (light > 0) op->contr->blocked_los[ax][ay] -= max (light - isqrt (x1 + y1), 0); 408 op->contr->blocked_los[ax][ay] -= light > 0
408 if (light < 0) op->contr->blocked_los[ax][ay] -= min (light + isqrt (x1 + y1), 0); 409 ? max (light - isqrt (x1 + y1), 0)
410 : min (light + isqrt (x1 + y1), 0);
409 } 411 }
410 } 412 }
411 } 413 }
412 } 414 }
413 } 415 }
414 } 416 }
415 417
416 /* Outdoor should never really be completely pitch black dark like 418 /* Outdoor should never really be completely pitch black dark like
417 * a dungeon, so let the player at least see a little around themselves 419 * a dungeon, so let the player at least see a little around themselves
418 */ 420 */
419 if (op->map->outdoor && darklevel > (MAX_DARKNESS - 3)) 421 if (op->map->outdoor && darklevel > MAX_DARKNESS - 3)
420 { 422 {
421 if (op->contr->blocked_los[op->contr->ns->mapx / 2][op->contr->ns->mapy / 2] > (MAX_DARKNESS - 3)) 423 if (op->contr->blocked_los[op->contr->ns->mapx / 2][op->contr->ns->mapy / 2] > (MAX_DARKNESS - 3))
422 op->contr->blocked_los[op->contr->ns->mapx / 2][op->contr->ns->mapy / 2] = MAX_DARKNESS - 3; 424 op->contr->blocked_los[op->contr->ns->mapx / 2][op->contr->ns->mapy / 2] = MAX_DARKNESS - 3;
423 425
424 for (x = -1; x <= 1; x++) 426 for (x = -1; x <= 1; x++)
435 if (!(op->contr->blocked_los[x + op->contr->ns->mapx / 2][y + op->contr->ns->mapy / 2] == 100)) 437 if (!(op->contr->blocked_los[x + op->contr->ns->mapx / 2][y + op->contr->ns->mapy / 2] == 100))
436 op->contr->blocked_los[x + op->contr->ns->mapx / 2][y + op->contr->ns->mapy / 2] -= 438 op->contr->blocked_los[x + op->contr->ns->mapx / 2][y + op->contr->ns->mapy / 2] -=
437 MAX (0, 6 - darklevel - MAX (abs (x), abs (y))); 439 MAX (0, 6 - darklevel - MAX (abs (x), abs (y)));
438} 440}
439 441
440/* blinded_sight() - sets all veiwable squares to blocked except 442/* blinded_sight() - sets all viewable squares to blocked except
441 * for the one the central one that the player occupies. A little 443 * for the one the central one that the player occupies. A little
442 * odd that you can see yourself (and what your standing on), but 444 * odd that you can see yourself (and what your standing on), but
443 * really need for any reasonable game play. 445 * really need for any reasonable game play.
444 */ 446 */
445static void 447static void

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines