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.51 by root, Wed Dec 24 01:37:23 2008 UTC vs.
Revision 1.78 by root, Wed Dec 5 19:03:26 2018 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 (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team
4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 5 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 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 * 6 *
8 * Deliantra is free software: you can redistribute it and/or modify 7 * 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 8 * 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 9 * Free Software Foundation, either version 3 of the License, or (at your
11 * (at your option) any later version. 10 * option) any later version.
12 * 11 *
13 * This program is distributed in the hope that it will be useful, 12 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 15 * GNU General Public License for more details.
17 * 16 *
18 * You should have received a copy of the GNU General Public License 17 * 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/>. 18 * and the GNU General Public License along with this program. If not, see
19 * <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 <global.h> 24#include <global.h>
25#include <cmath> 25#include <cmath>
26 26
27#define SEE_IN_DARK_RADIUS 3 27#define SEE_IN_DARK_RADIUS 2
28#define MAX_VISION 10 // maximum visible radius
28 29
29// los flags 30// los flags
30enum { 31enum {
31 FLG_XI = 0x01, // we have an x-parent 32 FLG_XI = 0x01, // we have an x-parent
32 FLG_YI = 0x02, // we have an y-parent 33 FLG_YI = 0x02, // we have an y-parent
33 FLG_BLOCKED = 0x04, // this space blocks the view 34 FLG_BLOCKED = 0x04, // this space blocks the view
34 FLG_QUEUED = 0x80 // already queued in queue, or border 35 FLG_QUEUED = 0x80 // already queued in queue, or border
35}; 36};
36 37
38// it is important for performance reasons that this structure
39// has a size easily computable by the cpu (*8 is perfect).
40// it is possible to move culled and visible into flags, at
41// some speed loss.
37struct los_info 42struct los_info
38{ 43{
39 uint8 flags; // FLG_xxx 44 uint8 flags; // FLG_xxx
40 uint8 culled; // culled from "tree" 45 uint8 culled; // culled from "tree"
41 uint8 visible; 46 uint8 visible;
47 52
48// temporary storage for the los algorithm, 53// temporary storage for the los algorithm,
49// one los_info for each lightable map space 54// one los_info for each lightable map space
50static los_info los[MAP_CLIENT_X][MAP_CLIENT_Y]; 55static los_info los[MAP_CLIENT_X][MAP_CLIENT_Y];
51 56
52struct point 57struct point8
53{ 58{
54 sint8 x, y; 59 sint8 x, y;
55}; 60};
56 61
57// minimum size, but must be a power of two 62// minimum size, but must be a power of two
58#define QUEUE_LENGTH ((MAP_CLIENT_X + MAP_CLIENT_Y) * 2) 63#define QUEUE_LENGTH ((MAP_CLIENT_X + MAP_CLIENT_Y) * 2)
59 64
60// a queue of spaces to calculate 65// a queue of spaces to calculate
61static point queue [QUEUE_LENGTH]; 66static point8 queue [QUEUE_LENGTH];
62static int q1, q2; // queue start, end 67static int q1, q2; // queue start, end
63 68
64/* 69/*
65 * Clears/initialises the los-array associated to the player 70 * Clears/initialises the los-array associated to the player
66 * controlling the object. 71 * controlling the object.
81 86
82 los_info &l = los[x][y]; 87 los_info &l = los[x][y];
83 88
84 l.flags |= flags; 89 l.flags |= flags;
85 90
86 if (l.flags & FLG_QUEUED) 91 if (ecb_expect_false (l.flags & FLG_QUEUED))
87 return; 92 return;
88 93
89 l.flags |= FLG_QUEUED; 94 l.flags |= FLG_QUEUED;
90 95
91 queue[q1].x = dx; 96 queue[q1].x = dx;
101// still is basically the same algorithm. 106// still is basically the same algorithm.
102static void 107static void
103calculate_los (player *pl) 108calculate_los (player *pl)
104{ 109{
105 { 110 {
111 memset (los, 0, sizeof (los));
112
106 // we keep one line for ourselves, for the border flag 113 // we keep one line for ourselves, for the border flag
107 // so the client area is actually MAP_CLIENT_(X|Y) - 2 114 // so the client area is actually MAP_CLIENT_(X|Y) - 2
108 int half_x = min (LOS_X0 - 1, pl->ns->mapx / 2); 115 int half_x = min (LOS_X0 - 1, pl->ns->mapx / 2);
109 int half_y = min (LOS_Y0 - 1, pl->ns->mapy / 2); 116 int half_y = min (LOS_Y0 - 1, pl->ns->mapy / 2);
110 117
118 los [LOS_X0 + (half_x + 1)][dy + LOS_Y0].flags = FLG_QUEUED; 125 los [LOS_X0 + (half_x + 1)][dy + LOS_Y0].flags = FLG_QUEUED;
119 126
120 // now reset the los area and also add blocked flags 127 // now reset the los area and also add blocked flags
121 // which supposedly is faster than doing it inside the 128 // which supposedly is faster than doing it inside the
122 // spiral path algorithm below, except when very little 129 // spiral path algorithm below, except when very little
123 // area is visible, in which case it is slower, evening 130 // area is visible, in which case it is slower. which evens
124 // out los calculation times between large and small los maps. 131 // out los calculation times between large and small los maps.
125 // apply_lights also iterates over this area, maybe these 132 // apply_lights also iterates over this area, maybe these
126 // two passes could be combined somehow. 133 // two passes could be combined somehow.
127 rectangular_mapspace_iterate_begin (pl->observe, -half_x, half_x, -half_y, half_y) 134 unordered_mapwalk (mapwalk_buf, pl->viewpoint, -half_x, -half_y, half_x, half_y)
135 {
128 los_info &l = los [LOS_X0 + dx][LOS_Y0 + dy]; 136 los_info &l = los [LOS_X0 + dx][LOS_Y0 + dy];
129 l.flags = m && m->at (nx, ny).flags () & P_BLOCKSVIEW ? FLG_BLOCKED : 0; 137 l.flags = m->at (nx, ny).flags () & P_BLOCKSVIEW ? FLG_BLOCKED : 0;
130 rectangular_mapspace_iterate_end 138 }
131 } 139 }
132 140
133 q1 = 0; q2 = 0; // initialise queue, not strictly required 141 q1 = 0; q2 = 0; // initialise queue, not strictly required
134 enqueue (0, 0); // enqueue center 142 enqueue (0, 0); // enqueue center
135 143
151 sint8 x = LOS_X0 + dx; 159 sint8 x = LOS_X0 + dx;
152 sint8 y = LOS_Y0 + dy; 160 sint8 y = LOS_Y0 + dy;
153 161
154 los_info &l = los[x][y]; 162 los_info &l = los[x][y];
155 163
156 if (expect_true (l.flags & (FLG_XI | FLG_YI))) 164 if (ecb_expect_true (l.flags & (FLG_XI | FLG_YI)))
157 { 165 {
158 l.culled = 1; 166 l.culled = 1;
159 l.xo = l.yo = l.xe = l.ye = 0; 167 l.xo = l.yo = l.xe = l.ye = 0;
160 168
161 // check contributing spaces, first horizontal 169 // check contributing spaces, first horizontal
162 if (expect_true (l.flags & FLG_XI)) 170 if (ecb_expect_true (l.flags & FLG_XI))
163 { 171 {
164 los_info *xi = &los[x - sign (dx)][y]; 172 los_info *xi = &los[x - sign (dx)][y];
165 173
166 // don't cull unless obscured 174 // don't cull unless obscured
167 l.culled &= !xi->visible; 175 l.culled &= !xi->visible;
168 176
169 /* merge input space */ 177 /* merge input space */
170 if (expect_false (xi->xo || xi->yo)) 178 if (ecb_expect_false (xi->xo || xi->yo))
171 { 179 {
172 // The X input can provide two main pieces of information: 180 // The X input can provide two main pieces of information:
173 // 1. Progressive X obscurity. 181 // 1. Progressive X obscurity.
174 // 2. Recessive Y obscurity. 182 // 2. Recessive Y obscurity.
175 183
176 // Progressive X obscurity, favouring recessive input angle 184 // Progressive X obscurity, favouring recessive input angle
177 if (xi->xe > 0 && l.xo == 0) 185 if (xi->xe > 0 && l.xo == 0)
192 } 200 }
193 } 201 }
194 } 202 }
195 203
196 // check contributing spaces, last vertical, identical structure 204 // check contributing spaces, last vertical, identical structure
197 if (expect_true (l.flags & FLG_YI)) 205 if (ecb_expect_true (l.flags & FLG_YI))
198 { 206 {
199 los_info *yi = &los[x][y - sign (dy)]; 207 los_info *yi = &los[x][y - sign (dy)];
200 208
201 // don't cull unless obscured 209 // don't cull unless obscured
202 l.culled &= !yi->visible; 210 l.culled &= !yi->visible;
203 211
204 /* merge input space */ 212 /* merge input space */
205 if (expect_false (yi->yo || yi->xo)) 213 if (ecb_expect_false (yi->yo || yi->xo))
206 { 214 {
207 // The Y input can provide two main pieces of information: 215 // The Y input can provide two main pieces of information:
208 // 1. Progressive Y obscurity. 216 // 1. Progressive Y obscurity.
209 // 2. Recessive X obscurity. 217 // 2. Recessive X obscurity.
210 218
211 // Progressive Y obscurity, favouring recessive input angle 219 // Progressive Y obscurity, favouring recessive input angle
212 if (yi->ye > 0 && l.yo == 0) 220 if (yi->ye > 0 && l.yo == 0)
253 } 261 }
254 262
255 } 263 }
256 264
257 // Expands by the unit length in each component's current direction. 265 // Expands by the unit length in each component's current direction.
258 // If a component has no direction, then it is expanded in both of its 266 // If a component has no direction, then it is expanded in both of its
259 // positive and negative directions. 267 // positive and negative directions.
260 if (!l.culled) 268 if (!l.culled)
261 { 269 {
262 if (dx >= 0) enqueue (dx + 1, dy, FLG_XI); 270 if (dx >= 0) enqueue (dx + 1, dy, FLG_XI);
263 if (dx <= 0) enqueue (dx - 1, dy, FLG_XI); 271 if (dx <= 0) enqueue (dx - 1, dy, FLG_XI);
265 if (dy <= 0) enqueue (dx, dy - 1, FLG_YI); 273 if (dy <= 0) enqueue (dx, dy - 1, FLG_YI);
266 } 274 }
267 } 275 }
268} 276}
269 277
270/* returns true if op carries one or more lights
271 * This is a trivial function now days, but it used to
272 * be a bit longer. Probably better for callers to just
273 * check the op->glow_radius instead of calling this.
274 */
275int
276has_carried_lights (const object *op)
277{
278 /* op may glow! */
279 if (op->glow_radius > 0)
280 return 1;
281
282 return 0;
283}
284
285/* radius, distance => lightness adjust */ 278/* radius, distance => lightness adjust */
286static sint8 light_atten[MAX_LIGHT_RADIUS * 2 + 1][MAX_LIGHT_RADIUS * 3 / 2 + 1]; 279static sint8 light_atten[MAX_LIGHT_RADIUS * 2 + 1][MAX_LIGHT_RADIUS * 3 / 2 + 1];
287static sint8 vision_atten[MAX_DARKNESS + SEE_IN_DARK_RADIUS + 1][(MAX_DARKNESS + SEE_IN_DARK_RADIUS) * 3 / 2 + 1]; 280static sint8 vision_atten[MAX_VISION + 1][MAX_VISION * 3 / 2 + 1];
288 281
289static struct los_init 282static struct los_init
290{ 283{
291 los_init () 284 los_init ()
292 { 285 {
299 { 292 {
300 // max intensity 293 // max intensity
301 int intensity = min (LOS_MAX, abs (radius) + 1); 294 int intensity = min (LOS_MAX, abs (radius) + 1);
302 295
303 // actual intensity 296 // actual intensity
304 intensity = max (0, lerp_rd (distance, 0, abs (radius) + 1, intensity, 0)); 297 intensity = max (0, lerp_ru (distance, 0, abs (radius) + 1, intensity, 0));
305 298
306 light_atten [radius + MAX_LIGHT_RADIUS][distance] = radius < 0 299 light_atten [radius + MAX_LIGHT_RADIUS][distance] = radius < 0
307 ? min (3, intensity) 300 ? min (3, intensity)
308 : LOS_MAX - intensity; 301 : LOS_MAX - intensity;
309 } 302 }
310 303
311 /* for general vision */ 304 /* for general vision */
312 for (int radius = 0; radius <= MAX_DARKNESS + SEE_IN_DARK_RADIUS; ++radius) 305 for (int radius = 0; radius <= MAX_VISION; ++radius)
313 for (int distance = 0; distance <= (MAX_DARKNESS + SEE_IN_DARK_RADIUS) * 3 / 2; ++distance) 306 for (int distance = 0; distance <= MAX_VISION * 3 / 2; ++distance)
314 vision_atten [radius][distance] = distance <= radius ? 3 : 4; 307 vision_atten [radius][distance] = distance <= radius ? clamp (lerp (radius, 0, MAX_DARKNESS, 3, 0), 0, 3) : 4;
315 } 308 }
316} los_init; 309} los_init;
317 310
311// the following functions cannot be static, due to c++ stupidity :/
312namespace {
313 // brighten area, ignore los
318sint8 314 sint8
315 los_brighten_nolos (sint8 b, sint8 l)
316 {
317 return min (b, l);
318 }
319
320 // brighten area, but respect los
321 sint8
319los_brighten (sint8 b, sint8 l) 322 los_brighten (sint8 b, sint8 l)
320{ 323 {
321 return b == LOS_BLOCKED ? b : min (b, l); 324 return b == LOS_BLOCKED ? b : min (b, l);
322} 325 }
323 326
327 // darken area, respect los
324sint8 328 sint8
325los_darken (sint8 b, sint8 l) 329 los_darken (sint8 b, sint8 l)
326{ 330 {
327 return max (b, l); 331 return max (b, l);
328} 332 }
333};
329 334
330template<sint8 change_it (sint8, sint8)> 335template<sint8 change_it (sint8, sint8)>
331static void 336static void
332apply_light (player *pl, int dx, int dy, int light, const sint8 *atten_table) 337apply_light (player *pl, int dx, int dy, int light, const sint8 *atten_table)
333{ 338{
347 for (int ay = ay0; ay <= ay1; ay++) 352 for (int ay = ay0; ay <= ay1; ay++)
348 pl->los[ax][ay] = 353 pl->los[ax][ay] =
349 change_it (pl->los[ax][ay], atten_table [idistance (ax - dx, ay - dy)]); 354 change_it (pl->los[ax][ay], atten_table [idistance (ax - dx, ay - dy)]);
350} 355}
351 356
352/* add light, by finding all (non-null) nearby light sources, then 357/* add light, by finding all (non-null) nearby light sources, then
353 * mark those squares specially. 358 * mark those squares specially.
354 */ 359 */
355static void 360static void
356apply_lights (player *pl) 361apply_lights (player *pl)
357{ 362{
358 object *op = pl->observe; 363 object *op = pl->viewpoint;
359 int darklevel = op->map->darklevel (); 364 int darklevel = op->map->darklevel ();
360 365
361 int half_x = pl->ns->mapx / 2; 366 int half_x = pl->ns->mapx / 2;
362 int half_y = pl->ns->mapy / 2; 367 int half_y = pl->ns->mapy / 2;
363 368
364 int pass2 = 0; // negative lights have an extra pass 369 int pass2 = 0; // negative lights have an extra pass
370
371 maprect *rects = pl->viewpoint->map->split_to_tiles (
372 mapwalk_buf,
373 pl->viewpoint->x - half_x - MAX_LIGHT_RADIUS,
374 pl->viewpoint->y - half_y - MAX_LIGHT_RADIUS,
375 pl->viewpoint->x + half_x + MAX_LIGHT_RADIUS + 1,
376 pl->viewpoint->y + half_y + MAX_LIGHT_RADIUS + 1
377 );
378
379 /* If the player can see in the dark, increase light/vision radius */
380 int bonus = op->flag [FLAG_SEE_IN_DARK] ? SEE_IN_DARK_RADIUS : 0;
365 381
366 if (!darklevel) 382 if (!darklevel)
367 pass2 = 1; 383 pass2 = 1;
368 else 384 else
369 { 385 {
376 * Only process the area of interest. 392 * Only process the area of interest.
377 * the basex, basey values represent the position in the op->contr->los 393 * the basex, basey values represent the position in the op->contr->los
378 * array. Its easier to just increment them here (and start with the right 394 * array. Its easier to just increment them here (and start with the right
379 * value) than to recalculate them down below. 395 * value) than to recalculate them down below.
380 */ 396 */
381 rectangular_mapspace_iterate_begin (pl->observe, -half_x - MAX_LIGHT_RADIUS, half_x + MAX_LIGHT_RADIUS, -half_y - MAX_LIGHT_RADIUS, half_y + MAX_LIGHT_RADIUS) 397 for (maprect *r = rects; r->m; ++r)
382 if (m) 398 rect_mapwalk (r, 0, 0)
383 { 399 {
384 mapspace &ms = m->at (nx, ny); 400 mapspace &ms = m->at (nx, ny);
385 ms.update (); 401 ms.update ();
386 sint8 light = ms.light; 402 sint8 light = ms.light;
387 403
388 if (expect_false (light)) 404 if (ecb_expect_false (light))
389 if (light < 0) 405 if (light < 0)
390 pass2 = 1; 406 pass2 = 1;
391 else 407 else
408 {
409 light = clamp (light + bonus, 0, MAX_LIGHT_RADIUS);
392 apply_light<los_brighten> (pl, dx, dy, light, light_atten [light + MAX_LIGHT_RADIUS]); 410 apply_light<los_brighten> (pl, dx - pl->viewpoint->x, dy - pl->viewpoint->y, light, light_atten [light + MAX_LIGHT_RADIUS]);
411 }
393 } 412 }
394 rectangular_mapspace_iterate_end
395 413
396 /* grant some vision to the player, based on the darklevel */ 414 /* grant some vision to the player, based on outside, outdoor, and darklevel */
397 { 415 {
398 int light = clamp (MAX_DARKNESS - darklevel, 0, MAX_DARKNESS); 416 int light;
399 417
400 /* If the player can see in the dark, lower the darklevel for him */ 418 if (!op->map->outdoor) // not outdoor, darkness becomes light radius
401 if (op->flag [FLAG_SEE_IN_DARK]) 419 light = MAX_DARKNESS - op->map->darkness;
402 light += SEE_IN_DARK_RADIUS; 420 else if (op->map->darkness > 0) // outdoor and darkness > 0 => use darkness as max radius
421 light = lerp_rd (maptile::outdoor_darkness + 0, 0, MAX_DARKNESS, MAX_DARKNESS - op->map->darkness, 0);
422 else // outdoor and darkness <= 0 => start wide and decrease quickly
423 light = lerp (maptile::outdoor_darkness + op->map->darkness, 0, MAX_DARKNESS, MAX_VISION, 2);
424
425 light = clamp (light + bonus, 0, MAX_VISION);
403 426
404 apply_light<los_brighten> (pl, 0, 0, light, vision_atten [light]); 427 apply_light<los_brighten> (pl, 0, 0, light, vision_atten [light]);
405 } 428 }
406 } 429 }
430
431 // when we fly high, we have some minimum viewable area around us, like x-ray
432 if (op->move_type & MOVE_FLY_HIGH)
433 apply_light<los_brighten_nolos> (pl, 0, 0, 9, vision_atten [9]);
407 434
408 // possibly do 2nd pass for rare negative glow radii 435 // possibly do 2nd pass for rare negative glow radii
409 // for effect, those are always considered to be stronger than anything else 436 // for effect, those are always considered to be stronger than anything else
410 // but they can't darken a place completely 437 // but they can't darken a place completely
411 if (pass2) 438 if (pass2)
412 rectangular_mapspace_iterate_begin (pl->observe, -half_x - MAX_LIGHT_RADIUS, half_x + MAX_LIGHT_RADIUS, -half_y - MAX_LIGHT_RADIUS, half_y + MAX_LIGHT_RADIUS) 439 for (maprect *r = rects; r->m; ++r)
413 if (m) 440 rect_mapwalk (r, 0, 0)
414 { 441 {
415 mapspace &ms = m->at (nx, ny); 442 mapspace &ms = m->at (nx, ny);
416 ms.update (); 443 ms.update ();
417 sint8 light = ms.light; 444 sint8 light = ms.light;
418 445
419 if (expect_false (light < 0)) 446 if (ecb_expect_false (light < 0))
447 {
448 light = clamp (light - bonus, 0, MAX_DARKNESS);
420 apply_light<los_darken> (pl, dx, dy, -light, light_atten [light + MAX_LIGHT_RADIUS]); 449 apply_light<los_darken> (pl, dx - pl->viewpoint->x, dy - pl->viewpoint->y, -light, light_atten [light + MAX_LIGHT_RADIUS]);
450 }
421 } 451 }
422 rectangular_mapspace_iterate_end
423} 452}
424 453
425/* blinded_sight() - sets all viewable squares to blocked except 454/* blinded_sight() - sets all viewable squares to blocked except
426 * for the one the central one that the player occupies. A little 455 * for the one the central one that the player occupies. A little
427 * odd that you can see yourself (and what your standing on), but 456 * odd that you can see yourself (and what your standing on), but
428 * really need for any reasonable game play. 457 * really need for any reasonable game play.
429 */ 458 */
430static void 459static void
443 if (ob->flag [FLAG_REMOVED])//D really needed? 472 if (ob->flag [FLAG_REMOVED])//D really needed?
444 return; 473 return;
445 474
446 if (ob->flag [FLAG_WIZLOOK]) 475 if (ob->flag [FLAG_WIZLOOK])
447 clear_los (0); 476 clear_los (0);
448 else if (observe->flag [FLAG_BLIND]) /* player is blind */ 477 else if (viewpoint->flag [FLAG_BLIND]) /* player is blind */
449 { 478 {
450 clear_los (); 479 clear_los ();
451 blinded_sight (this); 480 blinded_sight (this);
452 } 481 }
453 else 482 else
455 clear_los (); 484 clear_los ();
456 calculate_los (this); 485 calculate_los (this);
457 apply_lights (this); 486 apply_lights (this);
458 } 487 }
459 488
460 if (observe->flag [FLAG_XRAYS]) 489 if (viewpoint->flag [FLAG_XRAYS])
461 for (int dx = -2; dx <= 2; dx++) 490 for (int dx = -2; dx <= 2; dx++)
462 for (int dy = -2; dy <= 2; dy++) 491 for (int dy = -2; dy <= 2; dy++)
463 min_it (los[dx + LOS_X0][dy + LOS_Y0], 1); 492 min_it (los[dx + LOS_X0][dy + LOS_Y0], 1);
464} 493}
465 494
504 * check as a safety 533 * check as a safety
505 */ 534 */
506 if (!pl->ob || !pl->ob->map || !pl->ns) 535 if (!pl->ob || !pl->ob->map || !pl->ns)
507 continue; 536 continue;
508 537
509 /* Same map is simple case - see if pl is close enough. 538 rv_vector rv;
510 * Note in all cases, we did the check for same map first, 539
511 * and then see if the player is close enough and update 540 get_rangevector_from_mapcoord (pl->ob->map, x, y, pl->ob, &rv);
512 * los if that is the case. If the player is on the
513 * corresponding map, but not close enough, then the
514 * player can't be on another map that may be closer,
515 * so by setting it up this way, we trim processing
516 * some.
517 */ 541
518 if (pl->ob->map == map) 542 if ((abs (rv.distance_x) <= pl->ns->mapx / 2) && (abs (rv.distance_y) <= pl->ns->mapy / 2))
519 {
520 if ((abs (pl->ob->x - x) <= pl->ns->mapx / 2) && (abs (pl->ob->y - y) <= pl->ns->mapy / 2))
521 pl->do_los = 1; 543 pl->do_los = 1;
522 }
523
524 /* Now we check to see if player is on adjacent
525 * maps to the one that changed and also within
526 * view. The tile_maps[] could be null, but in that
527 * case it should never match the pl->ob->map, so
528 * we want ever try to dereference any of the data in it.
529 *
530 * The logic for 0 and 3 is to see how far the player is
531 * from the edge of the map (height/width) - pl->ob->(x,y)
532 * and to add current position on this map - that gives a
533 * distance.
534 * For 1 and 2, we check to see how far the given
535 * coordinate (x,y) is from the corresponding edge,
536 * and then add the players location, which gives
537 * a distance.
538 */
539 else if (pl->ob->map == map->tile_map[0])
540 {
541 if ((abs (pl->ob->x - x) <= pl->ns->mapx / 2) && (abs (y + map->tile_map[0]->height - pl->ob->y) <= pl->ns->mapy / 2))
542 pl->do_los = 1;
543 }
544 else if (pl->ob->map == map->tile_map[2])
545 {
546 if ((abs (pl->ob->x - x) <= pl->ns->mapx / 2) && (abs (pl->ob->y + map->height - y) <= pl->ns->mapy / 2))
547 pl->do_los = 1;
548 }
549 else if (pl->ob->map == map->tile_map[1])
550 {
551 if ((abs (pl->ob->x + map->width - x) <= pl->ns->mapx / 2) && (abs (pl->ob->y - y) <= pl->ns->mapy / 2))
552 pl->do_los = 1;
553 }
554 else if (pl->ob->map == map->tile_map[3])
555 {
556 if ((abs (x + map->tile_map[3]->width - pl->ob->x) <= pl->ns->mapx / 2) && (abs (pl->ob->y - y) <= pl->ns->mapy / 2))
557 pl->do_los = 1;
558 }
559 } 544 }
560} 545}
561 546
562static const int season_darkness[5][HOURS_PER_DAY] = { 547static const int season_darkness[5][HOURS_PER_DAY] = {
563 /*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 */ 548 /*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 */
636 if (pl->ob->map == op->map && 621 if (pl->ob->map == op->map &&
637 pl->ob->y - pl->ns->mapy / 2 <= op->y && 622 pl->ob->y - pl->ns->mapy / 2 <= op->y &&
638 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->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)
639 pl->do_los = 1; 624 pl->do_los = 1;
640} 625}
626

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines