Debian Codegraph @

common/los.c

raw symbols SCIP
1 /*
2 * Crossfire -- cooperative multi-player graphical RPG and adventure game
3 *
4 * Copyright (c) 1999-2014 Mark Wedel and the Crossfire Development Team
5 * Copyright (c) 1992 Frank Tore Johansen
6 *
7 * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
8 * welcome to redistribute it under certain conditions. For details, please
9 * see COPYING and LICENSE.
10 *
11 * The authors can be reached via e-mail at <[email protected]>.
12 */
13
14 /**
15 * @file los.c
16 * This handles the "line of sight" for players and monsters.
17 */
18
19 #include "global.h"
20
21 #include <math.h>
22 #include <stdlib.h>
23 #include <string.h>
24
25 /**
26 * Distance must be less than this for the object to be blocked.
27 * An object is 1.0 wide, so if set to 0.5, it means the object
28 * that blocks half the view (0.0 is complete block) will
29 * block view in our tables.
30 * .4 or less lets you see through walls. .5 is about right.
31 */
32 #define SPACE_BLOCK 0.5
33
34 typedef struct blstr {
35 int x[4], y[4];
36 int index;
37 } blocks;
38
39 static blocks block[MAP_CLIENT_X][MAP_CLIENT_Y];
40
41 static void expand_lighted_sight(object *op);
42
43 /**
44 * What this sets is that x,y blocks the view of bx,by
45 * This then sets up a relation - for example, something
46 * at 5,4 blocks view at 5,3 which blocks view at 5,2
47 * etc. So when we check 5,4 and find it blocks, we have
48 * the data to know that 5,3 and 5,2 and 5,1 should also
49 * be blocked.
50 * Used to initialise the array used by the LOS routines.
51 *
52 * @param x
53 * @param y
54 * coordinates that block.
55 * @param bx
56 * @param by
57 * coordinates that get blocked.
58 * @todo
59 * check index for overflow?
60 */
61 static void set_block(int x, int y, int bx, int by) {
62 int index = block[x][y].index, i;
63
64 /* Due to flipping, we may get duplicates - better safe than sorry.
65 */
66 for (i = 0; i < index; i++) {
67 if (block[x][y].x[i] == bx
68 && block[x][y].y[i] == by)
69 return;
70 }
71
72 block[x][y].x[index] = bx;
73 block[x][y].y[index] = by;
74 block[x][y].index++;
75 #ifdef LOS_DEBUG
76 LOG(llevDebug, "setblock: added %d %d -> %d %d (%d)\n", x, y, bx, by, block[x][y].index);
77 #endif
78 }
79
80 /**
81 * initialises the array used by the LOS routines.
82 *
83 * Since we are only doing the upper left quadrant, only
84 * these spaces could possibly get blocked, since these
85 * are the only ones further out that are still possibly in the
86 * sightline.
87 */
88 void init_block(void) {
89 int x, y, dx, dy, i;
90 static const int block_x[3] = {
91 -1, -1, 0
92 }, block_y[3] = {
93 -1, 0, -1
94 };
95
96 for (x = 0; x < MAP_CLIENT_X; x++)
97 for (y = 0; y < MAP_CLIENT_Y; y++) {
98 block[x][y].index = 0;
99 }
100
101 /* The table should be symmetric, so only do the upper left
102 * quadrant - makes the processing easier.
103 */
104 for (x = 1; x <= MAP_CLIENT_X/2; x++) {
105 for (y = 1; y <= MAP_CLIENT_Y/2; y++) {
106 /* center space never blocks */
107 if (x == MAP_CLIENT_X/2 && y == MAP_CLIENT_Y/2)
108 continue;
109
110 for (i = 0; i < 3; i++) {
111 dx = x+block_x[i];
112 dy = y+block_y[i];
113
114 /* If its a straight line, its blocked */
115 if ((dx == x && x == MAP_CLIENT_X/2)
116 || (dy == y && y == MAP_CLIENT_Y/2)) {
117 /* For simplicity, we mirror the coordinates to block the other
118 * quadrants.
119 */
120 set_block(x, y, dx, dy);
121 if (x == MAP_CLIENT_X/2) {
122 set_block(x, MAP_CLIENT_Y-y-1, dx, MAP_CLIENT_Y-dy-1);
123 } else if (y == MAP_CLIENT_Y/2) {
124 set_block(MAP_CLIENT_X-x-1, y, MAP_CLIENT_X-dx-1, dy);
125 }
126 } else {
127 float d1, s, l;
128
129 /* We use the algorihm that found out how close the point
130 * (x,y) is to the line from dx,dy to the center of the viewable
131 * area. l is the distance from x,y to the line.
132 * r is more a curiosity - it lets us know what direction (left/right)
133 * the line is off
134 */
135
136 d1 = (float)(pow(MAP_CLIENT_X/2-dx, 2)+pow(MAP_CLIENT_Y/2-dy, 2));
137 s = (float)((dy-y)*(MAP_CLIENT_X/2-dx)-(dx-x)*(MAP_CLIENT_Y/2-dy))/d1;
138 l = FABS(sqrt(d1)*s);
139
140 if (l <= SPACE_BLOCK) {
141 /* For simplicity, we mirror the coordinates to block the other
142 * quadrants.
143 */
144 set_block(x, y, dx, dy);
145 set_block(MAP_CLIENT_X-x-1, y, MAP_CLIENT_X-dx-1, dy);
146 set_block(x, MAP_CLIENT_Y-y-1, dx, MAP_CLIENT_Y-dy-1);
147 set_block(MAP_CLIENT_X-x-1, MAP_CLIENT_Y-y-1, MAP_CLIENT_X-dx-1, MAP_CLIENT_Y-dy-1);
148 }
149 }
150 }
151 }
152 }
153 }
154
155 /**
156 * This recursively sets the blocked line of sight view.
157 * From the blocked[][] array, we know for example
158 * that if some particular space is blocked, it blocks
159 * the view of the spaces 'behind' it, and those blocked
160 * spaces behind it may block other spaces, etc.
161 * In this way, the chain of visibility is set.
162 * Used to initialise the array used by the LOS routines.
163 *
164 * @param pl
165 * player for which we're computing.
166 * @param x
167 * @param y
168 * indexes into the blocked[][] array.
169 */
170 static void set_wall(player *pl, int x, int y) {
171 // Get this outside the loop -- now we can recycle x and y in the loop
172 // Trying less dereferencing for better efficiency
173 // Equivalent to &(block[x][y]), but faster.
174 const blocks * const at = block[x] + y;
175 /*
176 * Assume the mapsize will not change mid-drawing. This seemed to work in my testing
177 * Daniel Hawkins 2019-12-03
178 */
179 const int map_sock_x = (MAP_CLIENT_X-pl->socket.mapx)>>1,
180 map_sock_y = (MAP_CLIENT_Y-pl->socket.mapy)>>1;
181 for (int i = 0; i < at->index; i++) {
182 int dx = at->x[i], dy = at->y[i];
183
184 /* x, y are the values as adjusted to be in the
185 * socket look structure. Since the values are copied,
186 * we can safely store this in the x and y passed to the function,
187 * since they were only needed to find the element of the blocks array.
188 */
189 x = dx-map_sock_x;
190 y = dy-map_sock_y;
191
192 if (x < 0 || x >= pl->socket.mapx
193 || y < 0 || y >= pl->socket.mapy
194 /* If already set to 100, we probably hit this space through recursion already. */
195 || pl->blocked_los[x][y] == 100)
196 continue;
197 /* we need to adjust to the fact that the socket
198 * code wants the los to start from the 0,0
199 * and not be relative to middle of los array.
200 */
201 pl->blocked_los[x][y] = 100;
202 set_wall(pl, dx, dy);
203 }
204 }
205
206 /**
207 * Used to initialise the array used by the LOS routines.
208 * @param op
209 * player's object
210 * @param x
211 * @param y
212 * Values based on MAP_CLIENT_X and Y that index the blocked[][] arrays.
213 *
214 * @todo
215 * use player *instead of object *to show it must be a player?
216 */
217 static void check_wall(object *op, int x, int y) {
218 int ax, ay;
219
220 if (!block[x][y].index)
221 return;
222
223 /* ax, ay are coordinates as indexed into the look window */
224 ax = x-(MAP_CLIENT_X-op->contr->socket.mapx)/2;
225 ay = y-(MAP_CLIENT_Y-op->contr->socket.mapy)/2;
226
227 /* If the converted coordinates are outside the viewable
228 * area for the client, return now.
229 */
230 if (ax < 0 || ay < 0 || ax >= op->contr->socket.mapx || ay >= op->contr->socket.mapy)
231 return;
232
233 /* If this space is already blocked, prune the processing - presumably
234 * whatever has set this space to be blocked has done the work and already
235 * done the dependency chain.
236 */
237 if (op->contr->blocked_los[ax][ay] == 100)
238 return;
239
240
241 if (get_map_flags(op->map, NULL, op->x+x-MAP_CLIENT_X/2, op->y+y-MAP_CLIENT_Y/2, NULL, NULL)&(P_BLOCKSVIEW|P_OUT_OF_MAP))
242 set_wall(op->contr, x, y);
243 }
244
245 /**
246 * Clears/initialises the los-array associated to the player
247 * controlling the object.
248 *
249 * @param pl
250 * player to clear.
251 */
252 void clear_los(player *pl) {
253 /* This is safer than using the socket->mapx, mapy because
254 * we index the blocked_los as a 2 way array, so clearing
255 * the first z spaces may not not cover the spaces we are
256 * actually going to use
257 */
258 (void)memset((void *)pl->blocked_los, 0, MAP_CLIENT_X*MAP_CLIENT_Y);
259 }
260
261 /**
262 * Goes through the array of what the given player is
263 * able to see, and expands the visible area a bit, so the player will,
264 * to a certain degree, be able to see into corners.
265 * This is somewhat suboptimal, would be better to improve the formula.
266 *
267 * @param op
268 * player's object to process.
269 *
270 * @todo
271 * use player *instead of object *to show it must be a player? */
272 static void expand_sight(object *op) {
273 int i, x, y, dx, dy;
274
275 for (x = 1; x < op->contr->socket.mapx-1; x++) /* loop over inner squares */
276 for (y = 1; y < op->contr->socket.mapy-1; y++) {
277 if (!op->contr->blocked_los[x][y]
278 && !(get_map_flags(op->map, NULL,
279 op->x-op->contr->socket.mapx/2+x,
280 op->y-op->contr->socket.mapy/2+y,
281 NULL, NULL)&(P_BLOCKSVIEW|P_OUT_OF_MAP))) {
282 for (i = 1; i <= 8; i += 1) { /* mark all directions */
283 dx = x+freearr_x[i];
284 dy = y+freearr_y[i];
285 if (op->contr->blocked_los[dx][dy] > 0) /* for any square blocked */
286 op->contr->blocked_los[dx][dy] = -1;
287 }
288 }
289 }
290
291 if (MAP_DARKNESS(op->map) > 0) /* player is on a dark map */
292 expand_lighted_sight(op);
293
294
295 /* clear mark squares */
296 for (x = 0; x < op->contr->socket.mapx; x++)
297 for (y = 0; y < op->contr->socket.mapy; y++)
298 if (op->contr->blocked_los[x][y] < 0)
299 op->contr->blocked_los[x][y] = 0;
300 }
301
302 /**
303 * Checks if op has a light source.
304 *
305 * @param op
306 * object being checked.
307 * @return
308 * true if op carries one or more lights
309 *
310 * @note
311 * This is a trivial function now days, but it used to
312 * be a bit longer. Probably better for callers to just
313 * check the op->glow_radius instead of calling this.
314 */
315 int has_carried_lights(const object *op) {
316 /* op may glow! */
317 if (op->glow_radius > 0)
318 return 1;
319
320 return 0;
321 }
322
323 /**
324 * Propagate the light information.
325 *
326 * @param op
327 * player's object for which to compute the light values.
328 */
329 static void expand_lighted_sight(object *op) {
330 int x, y, darklevel, ax, ay, basex, basey, mflags, light, x1, y1;
331 mapstruct *m = op->map;
332 int16_t nx, ny;
333
334 darklevel = MAP_DARKNESS(m);
335
336 /* If the player can see in the dark, lower the darklevel for him */
337 if (QUERY_FLAG(op, FLAG_SEE_IN_DARK))
338 darklevel -= 2;
339
340 /* add light, by finding all (non-null) nearby light sources, then
341 * mark those squares specially. If the darklevel<1, there is no
342 * reason to do this, so we skip this function
343 */
344 if (darklevel < 1)
345 return;
346
347 /* Do a sanity check. If not valid, some code below may do odd
348 * things.
349 */
350 if (darklevel > MAX_DARKNESS) {
351 LOG(llevError, "Map darkness for %s on %s is too high (%d)\n", op->name, op->map->path, darklevel);
352 darklevel = MAX_DARKNESS;
353 }
354
355 /* First, limit player furthest (unlighted) vision */
356 for (x = 0; x < op->contr->socket.mapx; x++)
357 for (y = 0; y < op->contr->socket.mapy; y++)
358 if (op->contr->blocked_los[x][y] != 100)
359 op->contr->blocked_los[x][y] = MAX_LIGHT_RADII;
360
361 /* the spaces[] darkness value contains the information we need.
362 * Only process the area of interest.
363 * the basex, basey values represent the position in the op->contr->blocked_los
364 * array. Its easier to just increment them here (and start with the right
365 * value) than to recalculate them down below.
366 */
367 for (x = (op->x-op->contr->socket.mapx/2-MAX_LIGHT_RADII), basex = -MAX_LIGHT_RADII;
368 x <= (op->x+op->contr->socket.mapx/2+MAX_LIGHT_RADII); x++, basex++) {
369 for (y = (op->y-op->contr->socket.mapy/2-MAX_LIGHT_RADII), basey = -MAX_LIGHT_RADII;
370 y <= (op->y+op->contr->socket.mapy/2+MAX_LIGHT_RADII); y++, basey++) {
371 m = op->map;
372 nx = x;
373 ny = y;
374
375 mflags = get_map_flags(m, &m, nx, ny, &nx, &ny);
376
377 if (mflags&P_OUT_OF_MAP)
378 continue;
379
380 /* This space is providing light, so we need to brighten up the
381 * spaces around here.
382 */
383 light = GET_MAP_LIGHT(m, nx, ny);
384 if (light != 0) {
385 for (ax = basex-light; ax <= basex+light; ax++) {
386 if (ax < 0 || ax >= op->contr->socket.mapx)
387 continue;
388 for (ay = basey-light; ay <= basey+light; ay++) {
389 if (ay < 0 || ay >= op->contr->socket.mapy)
390 continue;
391
392 /* If the space is fully blocked, do nothing. Otherwise, we
393 * brighten the space. The further the light is away from the
394 * source (basex-x), the less effect it has. Though light used
395 * to dim in a square manner, it now dims in a circular manner
396 * using the the pythagorean theorem. glow_radius still
397 * represents the radius
398 */
399 if (op->contr->blocked_los[ax][ay] != 100) {
400 x1 = abs(basex-ax)*abs(basex-ax);
401 y1 = abs(basey-ay)*abs(basey-ay);
402 if (light > 0)
403 op->contr->blocked_los[ax][ay] -= MAX((light-isqrt(x1+y1)), 0);
404 if (light < 0)
405 op->contr->blocked_los[ax][ay] -= MIN((light+isqrt(x1+y1)), 0);
406 }
407 } /* for ay */
408 } /* for ax */
409 } /* if this space is providing light */
410 } /* for y */
411 } /* for x */
412
413 /* Outdoor should never really be completely pitch black dark like
414 * a dungeon, so let the player at least see a little around themselves
415 */
416 if (op->map->outdoor && darklevel > (MAX_DARKNESS-3)) {
417 if (op->contr->blocked_los[op->contr->socket.mapx/2][op->contr->socket.mapy/2] > (MAX_DARKNESS-3))
418 op->contr->blocked_los[op->contr->socket.mapx/2][op->contr->socket.mapy/2] = MAX_DARKNESS-3;
419
420 for (x = -1; x <= 1; x++)
421 for (y = -1; y <= 1; y++) {
422 if (op->contr->blocked_los[x+op->contr->socket.mapx/2][y+op->contr->socket.mapy/2] > (MAX_DARKNESS-2))
423 op->contr->blocked_los[x+op->contr->socket.mapx/2][y+op->contr->socket.mapy/2] = MAX_DARKNESS-2;
424 }
425 }
426 /* grant some vision to the player, based on the darklevel */
427 for (x = darklevel-MAX_DARKNESS; x < MAX_DARKNESS+1-darklevel; x++)
428 for (y = darklevel-MAX_DARKNESS; y < MAX_DARKNESS+1-darklevel; y++)
429 if (!(op->contr->blocked_los[x+op->contr->socket.mapx/2][y+op->contr->socket.mapy/2] == 100))
430 op->contr->blocked_los[x+op->contr->socket.mapx/2][y+op->contr->socket.mapy/2] -= MAX(0, 6-darklevel-MAX(abs(x), abs(y)));
431 }
432
433 /**
434 * Sets all veiwable squares to blocked except
435 * for the one the central one that the player occupies. A little
436 * odd that you can see yourself (and what your standing on), but
437 * really need for any reasonable game play.
438 *
439 * @param pl
440 * player for which to reset los.
441 */
442 static void blinded_sight(player *pl) {
443 int x, y;
444
445 for (x = 0; x < pl->socket.mapx; x++)
446 for (y = 0; y < pl->socket.mapy; y++)
447 pl->blocked_los[x][y] = 100;
448
449 pl->blocked_los[pl->socket.mapx/2][pl->socket.mapy/2] = 0;
450 }
451
452 /**
453 * Recalculates the array which specifies what is
454 * visible for the given player-object.
455 *
456 * @param op
457 * player's object for which to compute.
458 */
459 void update_los(object *op) {
460 int dx = op->contr->socket.mapx/2, dy = op->contr->socket.mapy/2, x, y;
461
462 if (QUERY_FLAG(op, FLAG_REMOVED))
463 return;
464
465 clear_los(op->contr);
466 if (QUERY_FLAG(op, FLAG_WIZ) /* || XRAYS(op) */)
467 return;
468
469 /* For larger maps, this is more efficient than the old way which
470 * used the chaining of the block array. Since many space views could
471 * be blocked by different spaces in front, this mean that a lot of spaces
472 * could be examined multile times, as each path would be looked at.
473 */
474 for (x = (MAP_CLIENT_X-op->contr->socket.mapx)/2+1; x < (MAP_CLIENT_X+op->contr->socket.mapx)/2-1; x++)
475 for (y = (MAP_CLIENT_Y-op->contr->socket.mapy)/2+1; y < (MAP_CLIENT_Y+op->contr->socket.mapy)/2-1; y++)
476 check_wall(op, x, y);
477
478
479 /* do the los of the player. 3 (potential) cases */
480 if (QUERY_FLAG(op, FLAG_BLIND)) /* player is blind */
481 blinded_sight(op->contr);
482 else
483 expand_sight(op);
484
485 if (QUERY_FLAG(op, FLAG_XRAYS)) {
486 int x, y;
487 for (x = -2; x <= 2; x++)
488 for (y = -2; y <= 2; y++)
489 op->contr->blocked_los[dx+x][dy+y] = 0;
490 }
491 }
492
493 /**
494 * update all_map_los is like update_all_los() below,
495 * but updates everyone on the map, no matter where they
496 * are. This generally should not be used, as a per
497 * specific map change doesn't make much sense when tiling
498 * is considered (lowering darkness would certainly be a
499 * strange effect if done on a tile map, as it makes
500 * the distinction between maps much more obvious to the
501 * players, which is should not be.
502 * Currently, this function is called from the
503 * change_map_light function
504 *
505 * @param map
506 * map on which affected players are.
507 */
508 void update_all_map_los(mapstruct *map) {
509 player *pl;
510
511 for (pl = first_player; pl != NULL; pl = pl->next) {
512 if (pl->ob->map == map)
513 pl->do_los = 1;
514 }
515 }
516
517 /**
518 * This function makes sure that update_los() will be called for all
519 * players on the given map within the next frame.
520 * It is triggered by removal or inserting of objects which blocks
521 * the sight in the map.
522 * Modified by MSW 2001-07-12 to take a coordinate of the changed
523 * position, and to also take map tiling into account. This change
524 * means that just being on the same map is not sufficient - the
525 * space that changes must be withing your viewable area.
526 *
527 * @param map
528 * map that changed.
529 * @param x
530 * @param y
531 * coordinates of the change.
532 *
533 * @todo
534 * check if this couldn't be simplified, especially tiling (isn't there a function somewhere that could help?)
535 */
536 void update_all_los(const mapstruct *map, int x, int y) {
537 player *pl;
538
539 for (pl = first_player; pl != NULL; pl = pl->next) {
540 /* Player should not have a null map, but do this
541 * check as a safety
542 */
543 if (!pl->ob->map)
544 continue;
545
546 /* Same map is simple case - see if pl is close enough.
547 * Note in all cases, we did the check for same map first,
548 * and then see if the player is close enough and update
549 * los if that is the case. If the player is on the
550 * corresponding map, but not close enough, then the
551 * player can't be on another map that may be closer,
552 * so by setting it up this way, we trim processing
553 * some.
554 */
555 if (pl->ob->map == map) {
556 if ((abs(pl->ob->x-x) <= pl->socket.mapx/2)
557 && (abs(pl->ob->y-y) <= pl->socket.mapy/2))
558 pl->do_los = 1;
559 }
560 /* Now we check to see if player is on adjacent
561 * maps to the one that changed and also within
562 * view. The tile_maps[] could be null, but in that
563 * case it should never match the pl->ob->map, so
564 * we want ever try to dereference any of the data in it.
565 */
566
567 /* The logic for 0 and 3 is to see how far the player is
568 * from the edge of the map (height/width) - pl->ob->(x,y)
569 * and to add current position on this map - that gives a
570 * distance.
571 * For 1 and 2, we check to see how far the given
572 * coordinate (x,y) is from the corresponding edge,
573 * and then add the players location, which gives
574 * a distance.
575 */
576 else if (pl->ob->map == map->tile_map[0]) {
577 if ((abs(pl->ob->x-x) <= pl->socket.mapx/2)
578 && (abs(y+MAP_HEIGHT(map->tile_map[0])-pl->ob->y) <= pl->socket.mapy/2))
579 pl->do_los = 1;
580 } else if (pl->ob->map == map->tile_map[2]) {
581 if ((abs(pl->ob->x-x) <= pl->socket.mapx/2)
582 && (abs(pl->ob->y+MAP_HEIGHT(map)-y) <= pl->socket.mapy/2))
583 pl->do_los = 1;
584 } else if (pl->ob->map == map->tile_map[1]) {
585 if ((abs(pl->ob->x+MAP_WIDTH(map)-x) <= pl->socket.mapx/2)
586 && (abs(pl->ob->y-y) <= pl->socket.mapy/2))
587 pl->do_los = 1;
588 } else if (pl->ob->map == map->tile_map[3]) {
589 if ((abs(x+MAP_WIDTH(map->tile_map[3])-pl->ob->x) <= pl->socket.mapx/2)
590 && (abs(pl->ob->y-y) <= pl->socket.mapy/2))
591 pl->do_los = 1;
592 }
593 }
594 }
595
596 /**
597 * Debug-routine which dumps the array which specifies the visible
598 * area of a player. Triggered by the DM command printlos.
599 *
600 * @param op
601 * DM asking for information.
602 *
603 * @todo
604 * change the command to view another player's LOS?
605 */
606 void print_los(object *op) {
607 int x, y;
608 char buf[MAP_CLIENT_X*2+20], buf2[10];
609
610 snprintf(buf, sizeof(buf), "[fixed] ");
611 for (x = 0; x < op->contr->socket.mapx; x++) {
612 snprintf(buf2, sizeof(buf2), "%2d", x);
613 strncat(buf, buf2, sizeof(buf)-strlen(buf)-1);
614 }
615 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DEBUG, buf);
616 for (y = 0; y < op->contr->socket.mapy; y++) {
617 snprintf(buf, sizeof(buf), "[fixed]%2d:", y);
618 for (x = 0; x < op->contr->socket.mapx; x++) {
619 snprintf(buf2, sizeof(buf2), " %1d", op->contr->blocked_los[x][y] == 100 ? 1 : 0);
620 strncat(buf, buf2, sizeof(buf)-strlen(buf)-1);
621 }
622 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DEBUG, buf);
623 }
624 }
625
626 /**
627 * The object is supposed to be visible through walls, thus
628 * check if any players are nearby, and edit their LOS array.
629 *
630 * @param op
631 * object that should be visible.
632 *
633 * @todo
634 * what about tiled maps?
635 */
636 void make_sure_seen(const object *op) {
637 player *pl;
638
639 for (pl = first_player; pl; pl = pl->next)
640 if (pl->ob->map == op->map
641 && pl->ob->y-pl->socket.mapy/2 <= op->y
642 && pl->ob->y+pl->socket.mapy/2 >= op->y
643 && pl->ob->x-pl->socket.mapx/2 <= op->x
644 && pl->ob->x+pl->socket.mapx/2 >= op->x)
645 pl->blocked_los[pl->socket.mapx/2+op->x-pl->ob->x][pl->socket.mapy/2+op->y-pl->ob->y] = 0;
646 }
647
648 /**
649 * The object which is supposed to be visible through
650 * walls has just been removed from the map, so update the los of any
651 * players within its range
652 *
653 * @param op
654 * object that disappears.
655 *
656 * @todo
657 * what about tiled maps?
658 */
659 void make_sure_not_seen(const object *op) {
660 player *pl;
661
662 for (pl = first_player; pl; pl = pl->next)
663 if (pl->ob->map == op->map
664 && pl->ob->y-pl->socket.mapy/2 <= op->y
665 && pl->ob->y+pl->socket.mapy/2 >= op->y
666 && pl->ob->x-pl->socket.mapx/2 <= op->x
667 && pl->ob->x+pl->socket.mapx/2 >= op->x)
668 pl->do_los = 1;
669 }