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.63 by root, Tue Nov 3 23:44:20 2009 UTC vs.
Revision 1.64 by root, Wed Nov 4 17:24:00 2009 UTC

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
307sint8
308los_brighten_nolos (sint8 b, sint8 l)
309{
310 return min (b, l);
311}
312
313// brighten area, but respect los
306sint8 314sint8
307los_brighten (sint8 b, sint8 l) 315los_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
312sint8 321sint8
313los_darken (sint8 b, sint8 l) 322los_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 */
343static void 352static void
344apply_lights (player *pl) 353apply_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 ();
357 maptile::outdoor_darkness = 4;//D
348 358
349 int half_x = pl->ns->mapx / 2; 359 int half_x = pl->ns->mapx / 2;
350 int half_y = pl->ns->mapy / 2; 360 int half_y = pl->ns->mapy / 2;
351 361
352 int pass2 = 0; // negative lights have an extra pass 362 int pass2 = 0; // negative lights have an extra pass
353 363
354 maprect *rects = pl->observe->map->split_to_tiles ( 364 maprect *rects = pl->viewpoint->map->split_to_tiles (
355 pl->observe->x - half_x - MAX_LIGHT_RADIUS, 365 pl->viewpoint->x - half_x - MAX_LIGHT_RADIUS,
356 pl->observe->y - half_y - MAX_LIGHT_RADIUS, 366 pl->viewpoint->y - half_y - MAX_LIGHT_RADIUS,
357 pl->observe->x + half_x + MAX_LIGHT_RADIUS + 1, 367 pl->viewpoint->x + half_x + MAX_LIGHT_RADIUS + 1,
358 pl->observe->y + half_y + MAX_LIGHT_RADIUS + 1 368 pl->viewpoint->y + half_y + MAX_LIGHT_RADIUS + 1
359 ); 369 );
360 370
361 /* 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 */
362 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;
363 373
387 if (light < 0) 397 if (light < 0)
388 pass2 = 1; 398 pass2 = 1;
389 else 399 else
390 { 400 {
391 light = clamp (light + bonus, 0, MAX_LIGHT_RADIUS); 401 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]); 402 apply_light<los_brighten> (pl, dx - pl->viewpoint->x, dy - pl->viewpoint->y, light, light_atten [light + MAX_LIGHT_RADIUS]);
393 } 403 }
394 } 404 }
395 405
396 /* 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 */
397 { 407 {
407 light = clamp (light + bonus, 0, MAX_VISION); 417 light = clamp (light + bonus, 0, MAX_VISION);
408 418
409 apply_light<los_brighten> (pl, 0, 0, light, vision_atten [light]); 419 apply_light<los_brighten> (pl, 0, 0, light, vision_atten [light]);
410 } 420 }
411 } 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]);
412 426
413 // possibly do 2nd pass for rare negative glow radii 427 // possibly do 2nd pass for rare negative glow radii
414 // 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
415 // but they can't darken a place completely 429 // but they can't darken a place completely
416 if (pass2) 430 if (pass2)
422 sint8 light = ms.light; 436 sint8 light = ms.light;
423 437
424 if (expect_false (light < 0)) 438 if (expect_false (light < 0))
425 { 439 {
426 light = clamp (light - bonus, 0, MAX_DARKNESS); 440 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]); 441 apply_light<los_darken> (pl, dx - pl->viewpoint->x, dy - pl->viewpoint->y, -light, light_atten [light + MAX_LIGHT_RADIUS]);
428 } 442 }
429 } 443 }
430} 444}
431 445
432/* blinded_sight() - sets all viewable squares to blocked except 446/* blinded_sight() - sets all viewable squares to blocked except
450 if (ob->flag [FLAG_REMOVED])//D really needed? 464 if (ob->flag [FLAG_REMOVED])//D really needed?
451 return; 465 return;
452 466
453 if (ob->flag [FLAG_WIZLOOK]) 467 if (ob->flag [FLAG_WIZLOOK])
454 clear_los (0); 468 clear_los (0);
455 else if (observe->flag [FLAG_BLIND]) /* player is blind */ 469 else if (viewpoint->flag [FLAG_BLIND]) /* player is blind */
456 { 470 {
457 clear_los (); 471 clear_los ();
458 blinded_sight (this); 472 blinded_sight (this);
459 } 473 }
460 else 474 else
462 clear_los (); 476 clear_los ();
463 calculate_los (this); 477 calculate_los (this);
464 apply_lights (this); 478 apply_lights (this);
465 } 479 }
466 480
467 if (observe->flag [FLAG_XRAYS]) 481 if (viewpoint->flag [FLAG_XRAYS])
468 for (int dx = -2; dx <= 2; dx++) 482 for (int dx = -2; dx <= 2; dx++)
469 for (int dy = -2; dy <= 2; dy++) 483 for (int dy = -2; dy <= 2; dy++)
470 min_it (los[dx + LOS_X0][dy + LOS_Y0], 1); 484 min_it (los[dx + LOS_X0][dy + LOS_Y0], 1);
471} 485}
472 486

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines