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.1.1.2 by elmex, Wed Feb 22 18:01:21 2006 UTC vs.
Revision 1.2 by elmex, Sun Aug 13 17:16:00 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines