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.48 by root, Tue Dec 23 06:58:23 2008 UTC vs.
Revision 1.61 by root, Tue May 5 04:51:56 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 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 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
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/* Nov 95 - inserted USE_LIGHTING code stuff in here - b.t. */
25
26#include <global.h> 24#include <global.h>
27#include <cmath> 25#include <cmath>
28 26
29static void expand_lighted_sight (object *op); 27#define SEE_IN_DARK_RADIUS 2
28#define MAX_VISION 10 // maximum visible radius
30 29
30// los flags
31enum { 31enum {
32 LOS_XI = 0x01, 32 FLG_XI = 0x01, // we have an x-parent
33 LOS_YI = 0x02, 33 FLG_YI = 0x02, // we have an y-parent
34 FLG_BLOCKED = 0x04, // this space blocks the view
35 FLG_QUEUED = 0x80 // already queued in queue, or border
34}; 36};
35 37
36struct los_info 38struct los_info
37{ 39{
40 uint8 flags; // FLG_xxx
41 uint8 culled; // culled from "tree"
42 uint8 visible;
43 uint8 pad0;
44
38 sint8 xo, yo; // obscure angle 45 sint8 xo, yo; // obscure angle
39 sint8 xe, ye; // angle deviation 46 sint8 xe, ye; // angle deviation
40 uint8 culled; // culled from "tree"
41 uint8 queued; // already queued
42 uint8 visible;
43 uint8 flags; // LOS_XI/YI
44}; 47};
45 48
46// temporary storage for the los algorithm, 49// temporary storage for the los algorithm,
47// one los_info for each lightable map space 50// one los_info for each lightable map space
48static los_info los[MAP_CLIENT_X][MAP_CLIENT_Y]; 51static los_info los[MAP_CLIENT_X][MAP_CLIENT_Y];
75enqueue (sint8 dx, sint8 dy, uint8 flags = 0) 78enqueue (sint8 dx, sint8 dy, uint8 flags = 0)
76{ 79{
77 sint8 x = LOS_X0 + dx; 80 sint8 x = LOS_X0 + dx;
78 sint8 y = LOS_Y0 + dy; 81 sint8 y = LOS_Y0 + dy;
79 82
80 if (x < 0 || x >= MAP_CLIENT_X) return;
81 if (y < 0 || y >= MAP_CLIENT_Y) return;
82
83 los_info &l = los[x][y]; 83 los_info &l = los[x][y];
84 84
85 l.flags |= flags; 85 l.flags |= flags;
86 86
87 if (l.queued) 87 if (l.flags & FLG_QUEUED)
88 return; 88 return;
89 89
90 l.queued = 1; 90 l.flags |= FLG_QUEUED;
91 91
92 queue[q1].x = dx; 92 queue[q1].x = dx;
93 queue[q1].y = dy; 93 queue[q1].y = dy;
94 94
95 q1 = (q1 + 1) & (QUEUE_LENGTH - 1); 95 q1 = (q1 + 1) & (QUEUE_LENGTH - 1);
101// which has been simplified and changed considerably, but 101// which has been simplified and changed considerably, but
102// still is basically the same algorithm. 102// still is basically the same algorithm.
103static void 103static void
104calculate_los (player *pl) 104calculate_los (player *pl)
105{ 105{
106 int max_radius = max (pl->ns->mapx, pl->ns->mapy) / 2; 106 {
107
108 memset (los, 0, sizeof (los)); 107 memset (los, 0, sizeof (los));
108
109 // we keep one line for ourselves, for the border flag
110 // so the client area is actually MAP_CLIENT_(X|Y) - 2
111 int half_x = min (LOS_X0 - 1, pl->ns->mapx / 2);
112 int half_y = min (LOS_Y0 - 1, pl->ns->mapy / 2);
113
114 // create borders, the corners are not touched
115 for (int dx = -half_x; dx <= half_x; ++dx)
116 los [dx + LOS_X0][LOS_Y0 - (half_y + 1)].flags =
117 los [dx + LOS_X0][LOS_Y0 + (half_y + 1)].flags = FLG_QUEUED;
118
119 for (int dy = -half_y; dy <= half_y; ++dy)
120 los [LOS_X0 - (half_x + 1)][dy + LOS_Y0].flags =
121 los [LOS_X0 + (half_x + 1)][dy + LOS_Y0].flags = FLG_QUEUED;
122
123 // now reset the los area and also add blocked flags
124 // which supposedly is faster than doing it inside the
125 // spiral path algorithm below, except when very little
126 // area is visible, in which case it is slower. which evens
127 // out los calculation times between large and small los maps.
128 // apply_lights also iterates over this area, maybe these
129 // two passes could be combined somehow.
130 unordered_mapwalk (pl->observe, -half_x, -half_y, half_x, half_y)
131 {
132 los_info &l = los [LOS_X0 + dx][LOS_Y0 + dy];
133 l.flags = m->at (nx, ny).flags () & P_BLOCKSVIEW ? FLG_BLOCKED : 0;
134 }
135 }
109 136
110 q1 = 0; q2 = 0; // initialise queue, not strictly required 137 q1 = 0; q2 = 0; // initialise queue, not strictly required
111 enqueue (0, 0); // enqueue center 138 enqueue (0, 0); // enqueue center
112 139
113 // treat the origin specially 140 // treat the origin specially
126 q2 = (q2 + 1) & (QUEUE_LENGTH - 1); 153 q2 = (q2 + 1) & (QUEUE_LENGTH - 1);
127 154
128 sint8 x = LOS_X0 + dx; 155 sint8 x = LOS_X0 + dx;
129 sint8 y = LOS_Y0 + dy; 156 sint8 y = LOS_Y0 + dy;
130 157
131 //int distance = idistance (dx, dy); if (distance > max_radius) continue;//D
132 int distance = 0;//D
133
134 los_info &l = los[x][y]; 158 los_info &l = los[x][y];
135 159
136 if (expect_true (l.flags & (LOS_XI | LOS_YI))) 160 if (expect_true (l.flags & (FLG_XI | FLG_YI)))
137 { 161 {
138 l.culled = 1; 162 l.culled = 1;
163 l.xo = l.yo = l.xe = l.ye = 0;
139 164
140 // check contributing spaces, first horizontal 165 // check contributing spaces, first horizontal
141 if (expect_true (l.flags & LOS_XI)) 166 if (expect_true (l.flags & FLG_XI))
142 { 167 {
143 los_info *xi = &los[x - sign (dx)][y]; 168 los_info *xi = &los[x - sign (dx)][y];
144 169
145 // don't cull unless obscured 170 // don't cull unless obscured
146 l.culled &= !xi->visible; 171 l.culled &= !xi->visible;
171 } 196 }
172 } 197 }
173 } 198 }
174 199
175 // check contributing spaces, last vertical, identical structure 200 // check contributing spaces, last vertical, identical structure
176 if (expect_true (l.flags & LOS_YI)) 201 if (expect_true (l.flags & FLG_YI))
177 { 202 {
178 los_info *yi = &los[x][y - sign (dy)]; 203 los_info *yi = &los[x][y - sign (dy)];
179 204
180 // don't cull unless obscured 205 // don't cull unless obscured
181 l.culled &= !yi->visible; 206 l.culled &= !yi->visible;
205 l.xo = yi->xo; 230 l.xo = yi->xo;
206 } 231 }
207 } 232 }
208 } 233 }
209 234
210 // check whether this space blocks the view 235 if (l.flags & FLG_BLOCKED)
211 maptile *m = pl->observe->map;
212 sint16 nx = pl->observe->x + dx;
213 sint16 ny = pl->observe->y + dy;
214
215 if (expect_true (!xy_normalise (m, nx, ny))
216 || expect_false (m->at (nx, ny).flags () & P_BLOCKSVIEW))
217 { 236 {
218 l.xo = l.xe = abs (dx); 237 l.xo = l.xe = abs (dx);
219 l.yo = l.ye = abs (dy); 238 l.yo = l.ye = abs (dy);
220 239
221 // we obscure dependents, but might be visible 240 // we obscure dependents, but might be visible
222 // copy the los from the square towards the player, 241 // copy the los from the square towards the player,
223 // so outward diagonal corners are lit. 242 // so outward diagonal corners are lit.
224 pl->los[x][y] = los[x - sign0 (dx)][y - sign0 (dy)].visible ? 0 : LOS_BLOCKED; 243 pl->los[x][y] = los[x - sign0 (dx)][y - sign0 (dy)].visible ? 0 : LOS_BLOCKED;
244
225 l.visible = false; 245 l.visible = false;
226 } 246 }
227 else 247 else
228 { 248 {
229 // we are not blocked, so calculate visibility, by checking 249 // we are not blocked, so calculate visibility, by checking
230 // whether we are inside or outside the shadow 250 // whether we are inside or outside the shadow
231 l.visible = (l.xe <= 0 || l.xe > l.xo) 251 l.visible = (l.xe <= 0 || l.xe > l.xo)
232 && (l.ye <= 0 || l.ye > l.yo); 252 && (l.ye <= 0 || l.ye > l.yo);
233 253
234 pl->los[x][y] = l.culled ? LOS_BLOCKED 254 pl->los[x][y] = l.culled ? LOS_BLOCKED
235 : l.visible ? max (0, 2 - max_radius + distance) 255 : l.visible ? 0
236 : 3; 256 : 3;
237 } 257 }
238 258
239 } 259 }
240 260
241 // Expands by the unit length in each component's current direction. 261 // Expands by the unit length in each component's current direction.
242 // If a component has no direction, then it is expanded in both of its 262 // If a component has no direction, then it is expanded in both of its
243 // positive and negative directions. 263 // positive and negative directions.
244 if (!l.culled) 264 if (!l.culled)
245 { 265 {
246 if (dx >= 0) enqueue (dx + 1, dy, LOS_XI); 266 if (dx >= 0) enqueue (dx + 1, dy, FLG_XI);
247 if (dx <= 0) enqueue (dx - 1, dy, LOS_XI); 267 if (dx <= 0) enqueue (dx - 1, dy, FLG_XI);
248 if (dy >= 0) enqueue (dx, dy + 1, LOS_YI); 268 if (dy >= 0) enqueue (dx, dy + 1, FLG_YI);
249 if (dy <= 0) enqueue (dx, dy - 1, LOS_YI); 269 if (dy <= 0) enqueue (dx, dy - 1, FLG_YI);
250 } 270 }
251 } 271 }
252} 272}
253 273
254/* returns true if op carries one or more lights
255 * This is a trivial function now days, but it used to
256 * be a bit longer. Probably better for callers to just
257 * check the op->glow_radius instead of calling this.
258 */
259int
260has_carried_lights (const object *op)
261{
262 /* op may glow! */
263 if (op->glow_radius > 0)
264 return 1;
265
266 return 0;
267}
268
269/* radius, distance => lightness adjust */ 274/* radius, distance => lightness adjust */
270static sint8 light_atten[MAX_LIGHT_RADIUS * 2 + 1][MAX_LIGHT_RADIUS * 3 / 2 + 1]; 275static sint8 light_atten[MAX_LIGHT_RADIUS * 2 + 1][MAX_LIGHT_RADIUS * 3 / 2 + 1];
271static sint8 vision_atten[MAX_DARKNESS + 1][MAX_DARKNESS * 3 / 2 + 1]; 276static sint8 vision_atten[MAX_VISION + 1][MAX_VISION * 3 / 2 + 1];
272 277
273static struct los_init 278static struct los_init
274{ 279{
275 los_init () 280 los_init ()
276 { 281 {
282 assert (("QUEUE_LENGTH, MAP_CLIENT_X and MAP_CLIENT_Y *must* be powers of two",
283 !(QUEUE_LENGTH & (QUEUE_LENGTH - 1))));
284
277 /* for lights */ 285 /* for lights */
278 for (int radius = -MAX_LIGHT_RADIUS; radius <= MAX_LIGHT_RADIUS; ++radius) 286 for (int radius = -MAX_LIGHT_RADIUS; radius <= MAX_LIGHT_RADIUS; ++radius)
279 for (int distance = 0; distance <= MAX_LIGHT_RADIUS * 3 / 2; ++distance) 287 for (int distance = 0; distance <= MAX_LIGHT_RADIUS * 3 / 2; ++distance)
280 { 288 {
281 // max intensity 289 // max intensity
282 int intensity = min (LOS_MAX, abs (radius) + 1); 290 int intensity = min (LOS_MAX, abs (radius) + 1);
283 291
284 // actual intensity 292 // actual intensity
285 intensity = max (0, lerp_rd (distance, 0, abs (radius) + 1, intensity, 0)); 293 intensity = max (0, lerp_ru (distance, 0, abs (radius) + 1, intensity, 0));
286 294
287 light_atten [radius + MAX_LIGHT_RADIUS][distance] = radius < 0 295 light_atten [radius + MAX_LIGHT_RADIUS][distance] = radius < 0
288 ? min (3, intensity) 296 ? min (3, intensity)
289 : LOS_MAX - intensity; 297 : LOS_MAX - intensity;
290 } 298 }
291 299
292 /* for general vision */ 300 /* for general vision */
293 for (int radius = 0; radius <= MAX_DARKNESS; ++radius) 301 for (int radius = 0; radius <= MAX_VISION; ++radius)
294 for (int distance = 0; distance <= MAX_DARKNESS * 3 / 2; ++distance) 302 for (int distance = 0; distance <= MAX_VISION * 3 / 2; ++distance)
295 { 303 vision_atten [radius][distance] = distance <= radius ? clamp (lerp (radius, 0, MAX_DARKNESS, 3, 0), 0, 3) : 4;
296 vision_atten [radius][distance] = distance <= radius ? 3 : 4;
297 }
298 } 304 }
299} los_init; 305} los_init;
300 306
301sint8 307sint8
302los_brighten (sint8 b, sint8 l) 308los_brighten (sint8 b, sint8 l)
339apply_lights (player *pl) 345apply_lights (player *pl)
340{ 346{
341 object *op = pl->observe; 347 object *op = pl->observe;
342 int darklevel = op->map->darklevel (); 348 int darklevel = op->map->darklevel ();
343 349
344 /* If the player can see in the dark, lower the darklevel for him */
345 if (op->flag [FLAG_SEE_IN_DARK])
346 darklevel = max (0, darklevel - 2);
347
348 int half_x = pl->ns->mapx / 2; 350 int half_x = pl->ns->mapx / 2;
349 int half_y = pl->ns->mapy / 2; 351 int half_y = pl->ns->mapy / 2;
350 352
351 int min_x = op->x - half_x - MAX_LIGHT_RADIUS;
352 int min_y = op->y - half_y - MAX_LIGHT_RADIUS;
353 int max_x = op->x + half_x + MAX_LIGHT_RADIUS;
354 int max_y = op->y + half_y + MAX_LIGHT_RADIUS;
355
356 int pass2 = 0; // negative lights have an extra pass 353 int pass2 = 0; // negative lights have an extra pass
354
355 maprect *rects = pl->observe->map->split_to_tiles (
356 pl->observe->x - half_x - MAX_LIGHT_RADIUS,
357 pl->observe->y - half_y - MAX_LIGHT_RADIUS,
358 pl->observe->x + half_x + MAX_LIGHT_RADIUS + 1,
359 pl->observe->y + half_y + MAX_LIGHT_RADIUS + 1
360 );
361
362 /* 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;
357 364
358 if (!darklevel) 365 if (!darklevel)
359 pass2 = 1; 366 pass2 = 1;
360 else 367 else
361 { 368 {
362 /* first, make everything totally dark */ 369 /* first, make everything totally dark */
363 for (int dx = -half_x; dx <= half_x; dx++) 370 for (int dx = -half_x; dx <= half_x; dx++)
364 for (int dy = -half_x; dy <= half_y; dy++) 371 for (int dy = -half_x; dy <= half_y; dy++)
365 if (pl->los[dx + LOS_X0][dy + LOS_Y0] != LOS_BLOCKED)
366 pl->los[dx + LOS_X0][dy + LOS_Y0] = LOS_MAX; 372 max_it (pl->los[dx + LOS_X0][dy + LOS_Y0], LOS_MAX);
367 373
368 /* 374 /*
369 * Only process the area of interest. 375 * Only process the area of interest.
370 * the basex, basey values represent the position in the op->contr->los 376 * the basex, basey values represent the position in the op->contr->los
371 * array. Its easier to just increment them here (and start with the right 377 * array. Its easier to just increment them here (and start with the right
372 * value) than to recalculate them down below. 378 * value) than to recalculate them down below.
373 */ 379 */
374 for (int x = min_x; x <= max_x; x++) 380 for (maprect *r = rects; r->m; ++r)
375 for (int y = min_y; y <= max_y; y++) 381 rect_mapwalk (r, 0, 0)
376 { 382 {
377 maptile *m = pl->observe->map;
378 sint16 nx = x;
379 sint16 ny = y;
380
381 if (!xy_normalise (m, nx, ny))
382 continue;
383
384 mapspace &ms = m->at (nx, ny); 383 mapspace &ms = m->at (nx, ny);
385 ms.update (); 384 ms.update ();
386 sint8 light = ms.light; 385 sint8 light = ms.light;
387 386
388 if (expect_false (light)) 387 if (expect_false (light))
389 if (light < 0) 388 if (light < 0)
390 pass2 = 1; 389 pass2 = 1;
391 else 390 else
391 {
392 light = clamp (light + bonus, 0, MAX_LIGHT_RADIUS);
392 apply_light<los_brighten> (pl, x - op->x, y - op->y, light, light_atten [light + MAX_LIGHT_RADIUS]); 393 apply_light<los_brighten> (pl, dx - pl->observe->x, dy - pl->observe->y, light, light_atten [light + MAX_LIGHT_RADIUS]);
394 }
393 } 395 }
394 396
395 /* grant some vision to the player, based on the darklevel */ 397 /* grant some vision to the player, based on outside, outdoor, and darklevel */
396 { 398 {
397 int light = clamp (MAX_DARKNESS - darklevel, 0, MAX_DARKNESS); 399 int light;
400
401 if (!op->map->outdoor) // not outdoor, darkness becomes light radius
402 light = MAX_DARKNESS - op->map->darkness;
403 else if (op->map->darkness > 0) // outdoor and darkness > 0 => use darkness as max radius
404 light = lerp_rd (maptile::outdoor_darkness + 0, 0, MAX_DARKNESS, MAX_DARKNESS - op->map->darkness, 0);
405 else // outdoor and darkness <= 0 => start wide and decrease quickly
406 light = lerp (maptile::outdoor_darkness + op->map->darkness, 0, MAX_DARKNESS, MAX_VISION, 2);
407
408 light = clamp (light + bonus, 0, MAX_VISION);
398 409
399 apply_light<los_brighten> (pl, 0, 0, light, vision_atten [light]); 410 apply_light<los_brighten> (pl, 0, 0, light, vision_atten [light]);
400 } 411 }
401 } 412 }
402 413
403 // possibly do 2nd pass for rare negative glow radii 414 // possibly do 2nd pass for rare negative glow radii
404 // for effect, those are always considered to be stronger than anything else 415 // for effect, those are always considered to be stronger than anything else
405 // but they can't darken a place completely 416 // but they can't darken a place completely
406 if (pass2) 417 if (pass2)
407 for (int x = min_x; x <= max_x; x++) 418 for (maprect *r = rects; r->m; ++r)
408 for (int y = min_y; y <= max_y; y++) 419 rect_mapwalk (r, 0, 0)
409 { 420 {
410 maptile *m = pl->observe->map;
411 sint16 nx = x;
412 sint16 ny = y;
413
414 if (!xy_normalise (m, nx, ny))
415 continue;
416
417 mapspace &ms = m->at (nx, ny); 421 mapspace &ms = m->at (nx, ny);
418 ms.update (); 422 ms.update ();
419 sint8 light = ms.light; 423 sint8 light = ms.light;
420 424
421 if (expect_false (light < 0)) 425 if (expect_false (light < 0))
426 {
427 light = clamp (light - bonus, 0, MAX_DARKNESS);
422 apply_light<los_darken> (pl, x - op->x, y - op->y, -light, light_atten [light + MAX_LIGHT_RADIUS]); 428 apply_light<los_darken> (pl, dx - pl->observe->x, dy - pl->observe->y, -light, light_atten [light + MAX_LIGHT_RADIUS]);
429 }
423 } 430 }
424} 431}
425 432
426/* blinded_sight() - sets all viewable squares to blocked except 433/* blinded_sight() - sets all viewable squares to blocked except
427 * for the one the central one that the player occupies. A little 434 * for the one the central one that the player occupies. A little
442player::update_los () 449player::update_los ()
443{ 450{
444 if (ob->flag [FLAG_REMOVED])//D really needed? 451 if (ob->flag [FLAG_REMOVED])//D really needed?
445 return; 452 return;
446 453
447 clear_los ();
448
449 if (ob->flag [FLAG_WIZLOOK]) 454 if (ob->flag [FLAG_WIZLOOK])
450 memset (los, 0, sizeof (los)); 455 clear_los (0);
451 else if (observe->flag [FLAG_BLIND]) /* player is blind */ 456 else if (observe->flag [FLAG_BLIND]) /* player is blind */
457 {
458 clear_los ();
452 blinded_sight (this); 459 blinded_sight (this);
460 }
453 else 461 else
454 { 462 {
463 clear_los ();
455 calculate_los (this); 464 calculate_los (this);
456 apply_lights (this); 465 apply_lights (this);
457 } 466 }
458 467
459 if (observe->flag [FLAG_XRAYS]) 468 if (observe->flag [FLAG_XRAYS])
460 for (int dx = -2; dx <= 2; dx++) 469 for (int dx = -2; dx <= 2; dx++)
461 for (int dy = -2; dy <= 2; dy++) 470 for (int dy = -2; dy <= 2; dy++)
462 min_it (los[dx + LOS_X0][dy + LOS_X0], 1); 471 min_it (los[dx + LOS_X0][dy + LOS_Y0], 1);
463} 472}
464 473
465/* update all_map_los is like update_all_los below, 474/* update all_map_los is like update_all_los below,
466 * but updates everyone on the map, no matter where they 475 * but updates everyone on the map, no matter where they
467 * are. This generally should not be used, as a per 476 * are. This generally should not be used, as a per
503 * check as a safety 512 * check as a safety
504 */ 513 */
505 if (!pl->ob || !pl->ob->map || !pl->ns) 514 if (!pl->ob || !pl->ob->map || !pl->ns)
506 continue; 515 continue;
507 516
508 /* Same map is simple case - see if pl is close enough. 517 rv_vector rv;
509 * Note in all cases, we did the check for same map first, 518
510 * and then see if the player is close enough and update 519 get_rangevector_from_mapcoord (map, x, y, pl->ob, &rv);
511 * los if that is the case. If the player is on the
512 * corresponding map, but not close enough, then the
513 * player can't be on another map that may be closer,
514 * so by setting it up this way, we trim processing
515 * some.
516 */ 520
517 if (pl->ob->map == map) 521 if ((abs (rv.distance_x) <= pl->ns->mapx / 2) && (abs (rv.distance_y) <= pl->ns->mapy / 2))
518 {
519 if ((abs (pl->ob->x - x) <= pl->ns->mapx / 2) && (abs (pl->ob->y - y) <= pl->ns->mapy / 2))
520 pl->do_los = 1; 522 pl->do_los = 1;
521 }
522
523 /* Now we check to see if player is on adjacent
524 * maps to the one that changed and also within
525 * view. The tile_maps[] could be null, but in that
526 * case it should never match the pl->ob->map, so
527 * we want ever try to dereference any of the data in it.
528 *
529 * The logic for 0 and 3 is to see how far the player is
530 * from the edge of the map (height/width) - pl->ob->(x,y)
531 * and to add current position on this map - that gives a
532 * distance.
533 * For 1 and 2, we check to see how far the given
534 * coordinate (x,y) is from the corresponding edge,
535 * and then add the players location, which gives
536 * a distance.
537 */
538 else if (pl->ob->map == map->tile_map[0])
539 {
540 if ((abs (pl->ob->x - x) <= pl->ns->mapx / 2) && (abs (y + map->tile_map[0]->height - pl->ob->y) <= pl->ns->mapy / 2))
541 pl->do_los = 1;
542 }
543 else if (pl->ob->map == map->tile_map[2])
544 {
545 if ((abs (pl->ob->x - x) <= pl->ns->mapx / 2) && (abs (pl->ob->y + map->height - y) <= pl->ns->mapy / 2))
546 pl->do_los = 1;
547 }
548 else if (pl->ob->map == map->tile_map[1])
549 {
550 if ((abs (pl->ob->x + map->width - x) <= pl->ns->mapx / 2) && (abs (pl->ob->y - y) <= pl->ns->mapy / 2))
551 pl->do_los = 1;
552 }
553 else if (pl->ob->map == map->tile_map[3])
554 {
555 if ((abs (x + map->tile_map[3]->width - pl->ob->x) <= pl->ns->mapx / 2) && (abs (pl->ob->y - y) <= pl->ns->mapy / 2))
556 pl->do_los = 1;
557 }
558 } 523 }
559} 524}
560 525
561static const int season_darkness[5][HOURS_PER_DAY] = { 526static const int season_darkness[5][HOURS_PER_DAY] = {
562 /*0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 2 3 4 5 6 7 8 9 10 11 12 13 */ 527 /*0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 2 3 4 5 6 7 8 9 10 11 12 13 */
618{ 583{
619 for_all_players (pl) 584 for_all_players (pl)
620 if (pl->ob->map == op->map && 585 if (pl->ob->map == op->map &&
621 pl->ob->y - pl->ns->mapy / 2 <= op->y && 586 pl->ob->y - pl->ns->mapy / 2 <= op->y &&
622 pl->ob->y + pl->ns->mapy / 2 >= op->y && pl->ob->x - pl->ns->mapx / 2 <= op->x && pl->ob->x + pl->ns->mapx / 2 >= op->x) 587 pl->ob->y + pl->ns->mapy / 2 >= op->y && pl->ob->x - pl->ns->mapx / 2 <= op->x && pl->ob->x + pl->ns->mapx / 2 >= op->x)
623 pl->los[op->x - pl->ob->x + LOS_X0][op->y - pl->ob->y + LOS_X0] = 0; 588 pl->los[op->x - pl->ob->x + LOS_X0][op->y - pl->ob->y + LOS_Y0] = 0;
624} 589}
625 590
626/* 591/*
627 * make_sure_not_seen: The object which is supposed to be visible through 592 * make_sure_not_seen: The object which is supposed to be visible through
628 * walls has just been removed from the map, so update the los of any 593 * walls has just been removed from the map, so update the los of any
635 if (pl->ob->map == op->map && 600 if (pl->ob->map == op->map &&
636 pl->ob->y - pl->ns->mapy / 2 <= op->y && 601 pl->ob->y - pl->ns->mapy / 2 <= op->y &&
637 pl->ob->y + pl->ns->mapy / 2 >= op->y && pl->ob->x - pl->ns->mapx / 2 <= op->x && pl->ob->x + pl->ns->mapx / 2 >= op->x) 602 pl->ob->y + pl->ns->mapy / 2 >= op->y && pl->ob->x - pl->ns->mapx / 2 <= op->x && pl->ob->x + pl->ns->mapx / 2 >= op->x)
638 pl->do_los = 1; 603 pl->do_los = 1;
639} 604}
605

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines