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.49 by root, Tue Dec 23 22:03:06 2008 UTC vs.
Revision 1.51 by root, Wed Dec 24 01:37:23 2008 UTC

19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * 20 *
21 * The authors can be reached via e-mail to <support@deliantra.net> 21 * The authors can be reached via e-mail to <support@deliantra.net>
22 */ 22 */
23 23
24#include <bench.h>//D
25#include <global.h> 24#include <global.h>
26#include <cmath> 25#include <cmath>
26
27#define SEE_IN_DARK_RADIUS 3
27 28
28// los flags 29// los flags
29enum { 30enum {
30 FLG_XI = 0x01, // we have an x-parent 31 FLG_XI = 0x01, // we have an x-parent
31 FLG_YI = 0x02, // we have an y-parent 32 FLG_YI = 0x02, // we have an y-parent
281 return 0; 282 return 0;
282} 283}
283 284
284/* radius, distance => lightness adjust */ 285/* radius, distance => lightness adjust */
285static sint8 light_atten[MAX_LIGHT_RADIUS * 2 + 1][MAX_LIGHT_RADIUS * 3 / 2 + 1]; 286static sint8 light_atten[MAX_LIGHT_RADIUS * 2 + 1][MAX_LIGHT_RADIUS * 3 / 2 + 1];
286static sint8 vision_atten[MAX_DARKNESS + 1][MAX_DARKNESS * 3 / 2 + 1]; 287static sint8 vision_atten[MAX_DARKNESS + SEE_IN_DARK_RADIUS + 1][(MAX_DARKNESS + SEE_IN_DARK_RADIUS) * 3 / 2 + 1];
287 288
288static struct los_init 289static struct los_init
289{ 290{
290 los_init () 291 los_init ()
291 { 292 {
306 ? min (3, intensity) 307 ? min (3, intensity)
307 : LOS_MAX - intensity; 308 : LOS_MAX - intensity;
308 } 309 }
309 310
310 /* for general vision */ 311 /* for general vision */
311 for (int radius = 0; radius <= MAX_DARKNESS; ++radius) 312 for (int radius = 0; radius <= MAX_DARKNESS + SEE_IN_DARK_RADIUS; ++radius)
312 for (int distance = 0; distance <= MAX_DARKNESS * 3 / 2; ++distance) 313 for (int distance = 0; distance <= (MAX_DARKNESS + SEE_IN_DARK_RADIUS) * 3 / 2; ++distance)
313 {
314 vision_atten [radius][distance] = distance <= radius ? 3 : 4; 314 vision_atten [radius][distance] = distance <= radius ? 3 : 4;
315 }
316 } 315 }
317} los_init; 316} los_init;
318 317
319sint8 318sint8
320los_brighten (sint8 b, sint8 l) 319los_brighten (sint8 b, sint8 l)
356static void 355static void
357apply_lights (player *pl) 356apply_lights (player *pl)
358{ 357{
359 object *op = pl->observe; 358 object *op = pl->observe;
360 int darklevel = op->map->darklevel (); 359 int darklevel = op->map->darklevel ();
361
362 /* If the player can see in the dark, lower the darklevel for him */
363 if (op->flag [FLAG_SEE_IN_DARK])
364 darklevel = max (0, darklevel - 2);
365 360
366 int half_x = pl->ns->mapx / 2; 361 int half_x = pl->ns->mapx / 2;
367 int half_y = pl->ns->mapy / 2; 362 int half_y = pl->ns->mapy / 2;
368 363
369 int pass2 = 0; // negative lights have an extra pass 364 int pass2 = 0; // negative lights have an extra pass
399 rectangular_mapspace_iterate_end 394 rectangular_mapspace_iterate_end
400 395
401 /* grant some vision to the player, based on the darklevel */ 396 /* grant some vision to the player, based on the darklevel */
402 { 397 {
403 int light = clamp (MAX_DARKNESS - darklevel, 0, MAX_DARKNESS); 398 int light = clamp (MAX_DARKNESS - darklevel, 0, MAX_DARKNESS);
399
400 /* If the player can see in the dark, lower the darklevel for him */
401 if (op->flag [FLAG_SEE_IN_DARK])
402 light += SEE_IN_DARK_RADIUS;
404 403
405 apply_light<los_brighten> (pl, 0, 0, light, vision_atten [light]); 404 apply_light<los_brighten> (pl, 0, 0, light, vision_atten [light]);
406 } 405 }
407 } 406 }
408 407

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines