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.61 by root, Tue May 5 04:51:56 2009 UTC vs.
Revision 1.65 by root, Wed Nov 4 18:17:57 2009 UTC

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 6 * Deliantra is free software: you can redistribute it and/or modify it under
9 * it under the terms of the GNU General Public License as published by 7 * the terms of the Affero GNU General Public License as published by the
10 * the Free Software Foundation, either version 3 of the License, or 8 * Free Software Foundation, either version 3 of the License, or (at your
11 * (at your option) any later version. 9 * option) any later version.
12 * 10 *
13 * This program is distributed in the hope that it will be useful, 11 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 14 * GNU General Public License for more details.
17 * 15 *
18 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the Affero GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 * and the GNU General Public License along with this program. If not, see
18 * <http://www.gnu.org/licenses/>.
20 * 19 *
21 * The authors can be reached via e-mail to <support@deliantra.net> 20 * The authors can be reached via e-mail to <support@deliantra.net>
22 */ 21 */
23 22
24#include <global.h> 23#include <global.h>
125 // spiral path algorithm below, except when very little 124 // spiral path algorithm below, except when very little
126 // area is visible, in which case it is slower. which evens 125 // area is visible, in which case it is slower. which evens
127 // out los calculation times between large and small los maps. 126 // out los calculation times between large and small los maps.
128 // apply_lights also iterates over this area, maybe these 127 // apply_lights also iterates over this area, maybe these
129 // two passes could be combined somehow. 128 // two passes could be combined somehow.
130 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)
131 { 130 {
132 los_info &l = los [LOS_X0 + dx][LOS_Y0 + dy]; 131 los_info &l = los [LOS_X0 + dx][LOS_Y0 + dy];
133 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;
134 } 133 }
135 } 134 }
302 for (int distance = 0; distance <= MAX_VISION * 3 / 2; ++distance) 301 for (int distance = 0; distance <= MAX_VISION * 3 / 2; ++distance)
303 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;
304 } 303 }
305} los_init; 304} los_init;
306 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
307sint8 314sint8
308los_brighten (sint8 b, sint8 l) 315los_brighten (sint8 b, sint8 l)
309{ 316{
310 return b == LOS_BLOCKED ? b : min (b, l); 317 return b == LOS_BLOCKED ? b : min (b, l);
311} 318}
312 319
320// darken area, respect los
313sint8 321sint8
314los_darken (sint8 b, sint8 l) 322los_darken (sint8 b, sint8 l)
315{ 323{
316 return max (b, l); 324 return max (b, l);
317} 325}
342 * mark those squares specially. 350 * mark those squares specially.
343 */ 351 */
344static void 352static void
345apply_lights (player *pl) 353apply_lights (player *pl)
346{ 354{
347 object *op = pl->observe; 355 object *op = pl->viewpoint;
348 int darklevel = op->map->darklevel (); 356 int darklevel = op->map->darklevel ();
349 357
350 int half_x = pl->ns->mapx / 2; 358 int half_x = pl->ns->mapx / 2;
351 int half_y = pl->ns->mapy / 2; 359 int half_y = pl->ns->mapy / 2;
352 360
353 int pass2 = 0; // negative lights have an extra pass 361 int pass2 = 0; // negative lights have an extra pass
354 362
355 maprect *rects = pl->observe->map->split_to_tiles ( 363 maprect *rects = pl->viewpoint->map->split_to_tiles (
356 pl->observe->x - half_x - MAX_LIGHT_RADIUS, 364 pl->viewpoint->x - half_x - MAX_LIGHT_RADIUS,
357 pl->observe->y - half_y - MAX_LIGHT_RADIUS, 365 pl->viewpoint->y - half_y - MAX_LIGHT_RADIUS,
358 pl->observe->x + half_x + MAX_LIGHT_RADIUS + 1, 366 pl->viewpoint->x + half_x + MAX_LIGHT_RADIUS + 1,
359 pl->observe->y + half_y + MAX_LIGHT_RADIUS + 1 367 pl->viewpoint->y + half_y + MAX_LIGHT_RADIUS + 1
360 ); 368 );
361 369
362 /* 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 */
363 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;
364 372
388 if (light < 0) 396 if (light < 0)
389 pass2 = 1; 397 pass2 = 1;
390 else 398 else
391 { 399 {
392 light = clamp (light + bonus, 0, MAX_LIGHT_RADIUS); 400 light = clamp (light + bonus, 0, MAX_LIGHT_RADIUS);
393 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]);
394 } 402 }
395 } 403 }
396 404
397 /* 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 */
398 { 406 {
408 light = clamp (light + bonus, 0, MAX_VISION); 416 light = clamp (light + bonus, 0, MAX_VISION);
409 417
410 apply_light<los_brighten> (pl, 0, 0, light, vision_atten [light]); 418 apply_light<los_brighten> (pl, 0, 0, light, vision_atten [light]);
411 } 419 }
412 } 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]);
413 425
414 // possibly do 2nd pass for rare negative glow radii 426 // possibly do 2nd pass for rare negative glow radii
415 // 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
416 // but they can't darken a place completely 428 // but they can't darken a place completely
417 if (pass2) 429 if (pass2)
423 sint8 light = ms.light; 435 sint8 light = ms.light;
424 436
425 if (expect_false (light < 0)) 437 if (expect_false (light < 0))
426 { 438 {
427 light = clamp (light - bonus, 0, MAX_DARKNESS); 439 light = clamp (light - bonus, 0, MAX_DARKNESS);
428 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]);
429 } 441 }
430 } 442 }
431} 443}
432 444
433/* blinded_sight() - sets all viewable squares to blocked except 445/* blinded_sight() - sets all viewable squares to blocked except
451 if (ob->flag [FLAG_REMOVED])//D really needed? 463 if (ob->flag [FLAG_REMOVED])//D really needed?
452 return; 464 return;
453 465
454 if (ob->flag [FLAG_WIZLOOK]) 466 if (ob->flag [FLAG_WIZLOOK])
455 clear_los (0); 467 clear_los (0);
456 else if (observe->flag [FLAG_BLIND]) /* player is blind */ 468 else if (viewpoint->flag [FLAG_BLIND]) /* player is blind */
457 { 469 {
458 clear_los (); 470 clear_los ();
459 blinded_sight (this); 471 blinded_sight (this);
460 } 472 }
461 else 473 else
463 clear_los (); 475 clear_los ();
464 calculate_los (this); 476 calculate_los (this);
465 apply_lights (this); 477 apply_lights (this);
466 } 478 }
467 479
468 if (observe->flag [FLAG_XRAYS]) 480 if (viewpoint->flag [FLAG_XRAYS])
469 for (int dx = -2; dx <= 2; dx++) 481 for (int dx = -2; dx <= 2; dx++)
470 for (int dy = -2; dy <= 2; dy++) 482 for (int dy = -2; dy <= 2; dy++)
471 min_it (los[dx + LOS_X0][dy + LOS_Y0], 1); 483 min_it (los[dx + LOS_X0][dy + LOS_Y0], 1);
472} 484}
473 485

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines