--- deliantra/server/common/los.C 2009/01/08 19:23:44 1.56 +++ deliantra/server/common/los.C 2009/01/08 21:35:54 1.57 @@ -25,6 +25,7 @@ #include #define SEE_IN_DARK_RADIUS 2 +#define MAX_VISION 10 // maximum visible radius // los flags enum { @@ -272,7 +273,7 @@ /* radius, distance => lightness adjust */ static sint8 light_atten[MAX_LIGHT_RADIUS * 2 + 1][MAX_LIGHT_RADIUS * 3 / 2 + 1]; -static sint8 vision_atten[MAX_DARKNESS + SEE_IN_DARK_RADIUS + 1][(MAX_DARKNESS + SEE_IN_DARK_RADIUS) * 3 / 2 + 1]; +static sint8 vision_atten[MAX_VISION + 1][MAX_VISION * 3 / 2 + 1]; static struct los_init { @@ -297,9 +298,9 @@ } /* for general vision */ - for (int radius = 0; radius <= MAX_DARKNESS + SEE_IN_DARK_RADIUS; ++radius) - for (int distance = 0; distance <= (MAX_DARKNESS + SEE_IN_DARK_RADIUS) * 3 / 2; ++distance) - vision_atten [radius][distance] = distance <= radius ? 3 : 4; + for (int radius = 0; radius <= MAX_VISION; ++radius) + for (int distance = 0; distance <= MAX_VISION * 3 / 2; ++distance) + vision_atten [radius][distance] = distance <= radius ? clamp (lerp (radius, 0, MAX_DARKNESS, 3, 0), 0, 3) : 4; } } los_init; @@ -358,6 +359,9 @@ pl->observe->y + half_y + MAX_LIGHT_RADIUS + 1 ); + /* If the player can see in the dark, increase light/vision radius */ + int bonus = op->flag [FLAG_SEE_IN_DARK] ? SEE_IN_DARK_RADIUS : 0; + if (!darklevel) pass2 = 1; else @@ -384,16 +388,24 @@ if (light < 0) pass2 = 1; else - apply_light (pl, dx - pl->observe->x, dy - pl->observe->y, light, light_atten [light + MAX_LIGHT_RADIUS]); + { + light = clamp (light + bonus, 0, MAX_LIGHT_RADIUS); + apply_light (pl, dx - pl->observe->x, dy - pl->observe->y, light, light_atten [light + MAX_LIGHT_RADIUS]); + } } - /* grant some vision to the player, based on the darklevel */ + /* grant some vision to the player, based on outside, outdoor, and darklevel */ { - int light = clamp (MAX_DARKNESS - darklevel, 0, MAX_DARKNESS); + int light; - /* If the player can see in the dark, lower the darklevel for him */ - if (op->flag [FLAG_SEE_IN_DARK]) - light += SEE_IN_DARK_RADIUS; + if (!op->map->outdoor) // not outdoor, darkness becomes light radius + light = op->map->darkness; + else if (op->map->darkness > 0) // outdoor and darkness > 0 => use darkness as max radius + light = lerp_rd (maptile::outdoor_darkness + 0, 0, MAX_DARKNESS, MAX_DARKNESS - op->map->darkness, 0); + else // outdoor and darkness <= 0 => start wide and decrease quickly + light = lerp (maptile::outdoor_darkness + op->map->darkness, 0, MAX_DARKNESS, MAX_VISION, 2); + + light = clamp (light, 0, MAX_VISION); apply_light (pl, 0, 0, light, vision_atten [light]); } @@ -411,7 +423,10 @@ sint8 light = ms.light; if (expect_false (light < 0)) - apply_light (pl, dx - pl->observe->x, dy - pl->observe->y, -light, light_atten [light + MAX_LIGHT_RADIUS]); + { + light = clamp (light - bonus, 0, MAX_DARKNESS); + apply_light (pl, dx - pl->observe->x, dy - pl->observe->y, -light, light_atten [light + MAX_LIGHT_RADIUS]); + } } }