1 | /* |
1 | /* |
2 | * static char *rcsid_los_c = |
2 | * static char *rcsid_los_c = |
3 | * "$Id: los.c,v 1.1 2006/02/03 07:11:36 root Exp $"; |
3 | * "$Id: los.c,v 1.1.1.2 2006/02/22 18:01:21 elmex Exp $"; |
4 | */ |
4 | */ |
5 | |
5 | |
6 | /* |
6 | /* |
7 | CrossFire, A Multiplayer game for X-windows |
7 | CrossFire, A Multiplayer game for X-windows |
8 | |
8 | |
… | |
… | |
46 | int x[4],y[4]; |
46 | int x[4],y[4]; |
47 | int index; |
47 | int index; |
48 | } blocks; |
48 | } blocks; |
49 | |
49 | |
50 | blocks block[MAP_CLIENT_X][MAP_CLIENT_Y]; |
50 | blocks block[MAP_CLIENT_X][MAP_CLIENT_Y]; |
|
|
51 | |
|
|
52 | static void expand_lighted_sight(object *op); |
51 | |
53 | |
52 | /* |
54 | /* |
53 | * Used to initialise the array used by the LOS routines. |
55 | * Used to initialise the array used by the LOS routines. |
54 | * What this sets if that x,y blocks the view of bx,by |
56 | * What this sets if that x,y blocks the view of bx,by |
55 | * This then sets up a relation - for example, something |
57 | * This then sets up a relation - for example, something |
… | |
… | |
57 | * etc. So when we check 5,4 and find it block, we have |
59 | * etc. So when we check 5,4 and find it block, we have |
58 | * the data to know that 5,3 and 5,2 and 5,1 should also |
60 | * the data to know that 5,3 and 5,2 and 5,1 should also |
59 | * be blocked. |
61 | * be blocked. |
60 | */ |
62 | */ |
61 | |
63 | |
62 | void set_block(int x,int y,int bx, int by) { |
64 | static void set_block(int x, int y, int bx, int by) { |
63 | int index=block[x][y].index,i; |
65 | int index=block[x][y].index,i; |
64 | |
66 | |
65 | /* Due to flipping, we may get duplicates - better safe than sorry. |
67 | /* Due to flipping, we may get duplicates - better safe than sorry. |
66 | */ |
68 | */ |
67 | for (i=0; i<index; i++) { |
69 | for (i=0; i<index; i++) { |
… | |
… | |
249 | * able to see, and expands the visible area a bit, so the player will, |
251 | * able to see, and expands the visible area a bit, so the player will, |
250 | * to a certain degree, be able to see into corners. |
252 | * to a certain degree, be able to see into corners. |
251 | * This is somewhat suboptimal, would be better to improve the formula. |
253 | * This is somewhat suboptimal, would be better to improve the formula. |
252 | */ |
254 | */ |
253 | |
255 | |
254 | void expand_sight(object *op) |
256 | static void expand_sight(object *op) |
255 | { |
257 | { |
256 | int i,x,y, dx, dy; |
258 | int i,x,y, dx, dy; |
257 | |
259 | |
258 | for(x=1;x<op->contr->socket.mapx-1;x++) /* loop over inner squares */ |
260 | for(x=1;x<op->contr->socket.mapx-1;x++) /* loop over inner squares */ |
259 | for(y=1;y<op->contr->socket.mapy-1;y++) { |
261 | for(y=1;y<op->contr->socket.mapy-1;y++) { |
… | |
… | |
290 | * This is a trivial function now days, but it used to |
292 | * This is a trivial function now days, but it used to |
291 | * be a bit longer. Probably better for callers to just |
293 | * be a bit longer. Probably better for callers to just |
292 | * check the op->glow_radius instead of calling this. |
294 | * check the op->glow_radius instead of calling this. |
293 | */ |
295 | */ |
294 | |
296 | |
295 | int has_carried_lights(object *op) { |
297 | int has_carried_lights(const object *op) { |
296 | /* op may glow! */ |
298 | /* op may glow! */ |
297 | if(op->glow_radius>0) return 1; |
299 | if(op->glow_radius>0) return 1; |
298 | |
300 | |
299 | return 0; |
301 | return 0; |
300 | } |
302 | } |
301 | |
303 | |
302 | void expand_lighted_sight(object *op) |
304 | static void expand_lighted_sight(object *op) |
303 | { |
305 | { |
304 | int x,y,darklevel,ax,ay, basex, basey, mflags, light, x1, y1; |
306 | int x,y,darklevel,ax,ay, basex, basey, mflags, light, x1, y1; |
305 | mapstruct *m=op->map; |
307 | mapstruct *m=op->map; |
306 | sint16 nx, ny; |
308 | sint16 nx, ny; |
307 | |
309 | |
… | |
… | |
409 | * for the one the central one that the player occupies. A little |
411 | * for the one the central one that the player occupies. A little |
410 | * odd that you can see yourself (and what your standing on), but |
412 | * odd that you can see yourself (and what your standing on), but |
411 | * really need for any reasonable game play. |
413 | * really need for any reasonable game play. |
412 | */ |
414 | */ |
413 | |
415 | |
414 | void blinded_sight (object *op) { |
416 | static void blinded_sight(object *op) { |
415 | int x,y; |
417 | int x,y; |
416 | |
418 | |
417 | for (x = 0; x < op->contr->socket.mapx; x++) |
419 | for (x = 0; x < op->contr->socket.mapx; x++) |
418 | for (y = 0; y < op->contr->socket.mapy; y++) |
420 | for (y = 0; y < op->contr->socket.mapy; y++) |
419 | op->contr->blocked_los[x][y] = 100; |
421 | op->contr->blocked_los[x][y] = 100; |
… | |
… | |
492 | * space that changes must be withing your viewable area. |
494 | * space that changes must be withing your viewable area. |
493 | * |
495 | * |
494 | * map is the map that changed, x and y are the coordinates. |
496 | * map is the map that changed, x and y are the coordinates. |
495 | */ |
497 | */ |
496 | |
498 | |
497 | void update_all_los(mapstruct *map, int x, int y) { |
499 | void update_all_los(const mapstruct *map, int x, int y) { |
498 | player *pl; |
500 | player *pl; |
499 | |
501 | |
500 | for(pl=first_player;pl!=NULL;pl=pl->next) { |
502 | for(pl=first_player;pl!=NULL;pl=pl->next) { |
501 | /* Player should not have a null map, but do this |
503 | /* Player should not have a null map, but do this |
502 | * check as a safety |
504 | * check as a safety |
… | |
… | |
584 | /* |
586 | /* |
585 | * make_sure_seen: The object is supposed to be visible through walls, thus |
587 | * make_sure_seen: The object is supposed to be visible through walls, thus |
586 | * check if any players are nearby, and edit their LOS array. |
588 | * check if any players are nearby, and edit their LOS array. |
587 | */ |
589 | */ |
588 | |
590 | |
589 | void make_sure_seen(object *op) { |
591 | void make_sure_seen(const object *op) { |
590 | player *pl; |
592 | player *pl; |
591 | |
593 | |
592 | for (pl = first_player; pl; pl = pl->next) |
594 | for (pl = first_player; pl; pl = pl->next) |
593 | if (pl->ob->map == op->map && |
595 | if (pl->ob->map == op->map && |
594 | pl->ob->y - pl->socket.mapy/2 <= op->y && |
596 | pl->ob->y - pl->socket.mapy/2 <= op->y && |
… | |
… | |
603 | * make_sure_not_seen: The object which is supposed to be visible through |
605 | * make_sure_not_seen: The object which is supposed to be visible through |
604 | * walls has just been removed from the map, so update the los of any |
606 | * walls has just been removed from the map, so update the los of any |
605 | * players within its range |
607 | * players within its range |
606 | */ |
608 | */ |
607 | |
609 | |
608 | void make_sure_not_seen(object *op) { |
610 | void make_sure_not_seen(const object *op) { |
609 | player *pl; |
611 | player *pl; |
610 | for (pl = first_player; pl; pl = pl->next) |
612 | for (pl = first_player; pl; pl = pl->next) |
611 | if (pl->ob->map == op->map && |
613 | if (pl->ob->map == op->map && |
612 | pl->ob->y - pl->socket.mapy/2 <= op->y && |
614 | pl->ob->y - pl->socket.mapy/2 <= op->y && |
613 | pl->ob->y + pl->socket.mapy/2 >= op->y && |
615 | pl->ob->y + pl->socket.mapy/2 >= op->y && |