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.36 by root, Mon Dec 8 15:40:13 2008 UTC vs.
Revision 1.37 by root, Thu Dec 18 02:49:22 2008 UTC

30 * An object is 1.0 wide, so if set to 0.5, it means the object 30 * An object is 1.0 wide, so if set to 0.5, it means the object
31 * that blocks half the view (0.0 is complete block) will 31 * that blocks half the view (0.0 is complete block) will
32 * block view in our tables. 32 * block view in our tables.
33 * .4 or less lets you see through walls. .5 is about right. 33 * .4 or less lets you see through walls. .5 is about right.
34 */ 34 */
35
36#define SPACE_BLOCK 0.5 35#define SPACE_BLOCK 0.5
37 36
38typedef struct blstr 37typedef struct blstr
39{ 38{
40 int x[4], y[4]; 39 int x[4], y[4];
87/* since we are only doing the upper left quadrant, only 86/* since we are only doing the upper left quadrant, only
88 * these spaces could possibly get blocked, since these 87 * these spaces could possibly get blocked, since these
89 * are the only ones further out that are still possibly in the 88 * are the only ones further out that are still possibly in the
90 * sightline. 89 * sightline.
91 */ 90 */
92
93void 91void
94init_block (void) 92init_block (void)
95{ 93{
96 int x, y, dx, dy, i;
97 static int block_x[3] = { -1, -1, 0 }, 94 static int block_x[3] = { -1, -1, 0 },
98 block_y[3] = { -1, 0, -1 }; 95 block_y[3] = { -1, 0, -1 };
99 96
100 for (x = 0; x < MAP_CLIENT_X; x++) 97 for (int x = 0; x < MAP_CLIENT_X; x++)
101 for (y = 0; y < MAP_CLIENT_Y; y++) 98 for (int y = 0; y < MAP_CLIENT_Y; y++)
102 block[x][y].index = 0; 99 block[x][y].index = 0;
103
104 100
105 /* The table should be symmetric, so only do the upper left 101 /* The table should be symmetric, so only do the upper left
106 * quadrant - makes the processing easier. 102 * quadrant - makes the processing easier.
107 */ 103 */
108 for (x = 1; x <= MAP_CLIENT_X / 2; x++) 104 for (int x = 1; x <= MAP_CLIENT_X / 2; x++)
109 { 105 {
110 for (y = 1; y <= MAP_CLIENT_Y / 2; y++) 106 for (int y = 1; y <= MAP_CLIENT_Y / 2; y++)
111 { 107 {
112 for (i = 0; i < 3; i++) 108 for (int i = 0; i < 3; i++)
113 { 109 {
114 dx = x + block_x[i]; 110 int dx = x + block_x[i];
115 dy = y + block_y[i]; 111 int dy = y + block_y[i];
116 112
117 /* center space never blocks */ 113 /* center space never blocks */
118 if (x == MAP_CLIENT_X / 2 && y == MAP_CLIENT_Y / 2) 114 if (x == MAP_CLIENT_X / 2 && y == MAP_CLIENT_Y / 2)
119 continue; 115 continue;
120 116
132 } 128 }
133 else 129 else
134 { 130 {
135 float d1, r, s, l; 131 float d1, r, s, l;
136 132
137 /* We use the algorihm that found out how close the point 133 /* We use the algorithm that found out how close the point
138 * (x,y) is to the line from dx,dy to the center of the viewable 134 * (x,y) is to the line from dx,dy to the center of the viewable
139 * area. l is the distance from x,y to the line. 135 * area. l is the distance from x,y to the line.
140 * r is more a curiosity - it lets us know what direction (left/right) 136 * r is more a curiosity - it lets us know what direction (left/right)
141 * the line is off 137 * the line is off
142 */ 138 */
143 139
144 d1 = (float) (pow (MAP_CLIENT_X / 2 - dx, 2.f) + pow (MAP_CLIENT_Y / 2 - dy, 2.f)); 140 d1 = (powf (MAP_CLIENT_X / 2 - dx, 2.f) + powf (MAP_CLIENT_Y / 2 - dy, 2.f));
145 r = (float) ((dy - y) * (dy - MAP_CLIENT_Y / 2) - (dx - x) * (MAP_CLIENT_X / 2 - dx)) / d1; 141 r = ((dy - y) * (dy - MAP_CLIENT_Y / 2) - (dx - x) * (MAP_CLIENT_X / 2 - dx)) / d1;
146 s = (float) ((dy - y) * (MAP_CLIENT_X / 2 - dx) - (dx - x) * (MAP_CLIENT_Y / 2 - dy)) / d1; 142 s = ((dy - y) * (MAP_CLIENT_X / 2 - dx) - (dx - x) * (MAP_CLIENT_Y / 2 - dy)) / d1;
147 l = FABS (sqrt (d1) * s); 143 l = fabs (sqrtf (d1) * s);
148 144
149 if (l <= SPACE_BLOCK) 145 if (l <= SPACE_BLOCK)
150 { 146 {
151 /* For simplicity, we mirror the coordinates to block the other 147 /* For simplicity, we mirror the coordinates to block the other
152 * quadrants. 148 * quadrants.
173 * In this way, the chain of visibility is set. 169 * In this way, the chain of visibility is set.
174 */ 170 */
175static void 171static void
176set_wall (object *op, int x, int y) 172set_wall (object *op, int x, int y)
177{ 173{
178 int i;
179
180 for (i = 0; i < block[x][y].index; i++) 174 for (int i = 0; i < block[x][y].index; i++)
181 { 175 {
182 int dx = block[x][y].x[i], dy = block[x][y].y[i], ax, ay; 176 int dx = block[x][y].x[i], dy = block[x][y].y[i], ax, ay;
183 177
184 /* ax, ay are the values as adjusted to be in the 178 /* ax, ay are the values as adjusted to be in the
185 * socket look structure. 179 * socket look structure.
204/* 198/*
205 * Used to initialise the array used by the LOS routines. 199 * Used to initialise the array used by the LOS routines.
206 * op is the object, x and y values based on MAP_CLIENT_X and Y. 200 * op is the object, x and y values based on MAP_CLIENT_X and Y.
207 * this is because they index the blocked[][] arrays. 201 * this is because they index the blocked[][] arrays.
208 */ 202 */
209
210static void 203static void
211check_wall (object *op, int x, int y) 204check_wall (object *op, int x, int y)
212{ 205{
213 int ax, ay; 206 int ax, ay;
214 207
261 * expand_sight goes through the array of what the given player is 254 * expand_sight goes through the array of what the given player is
262 * able to see, and expands the visible area a bit, so the player will, 255 * able to see, and expands the visible area a bit, so the player will,
263 * to a certain degree, be able to see into corners. 256 * to a certain degree, be able to see into corners.
264 * This is somewhat suboptimal, would be better to improve the formula. 257 * This is somewhat suboptimal, would be better to improve the formula.
265 */ 258 */
266
267static void 259static void
268expand_sight (object *op) 260expand_sight (object *op)
269{ 261{
270 int i, x, y, dx, dy;
271
272 for (x = 1; x < op->contr->ns->mapx - 1; x++) /* loop over inner squares */ 262 for (int x = 1; x < op->contr->ns->mapx - 1; x++) /* loop over inner squares */
273 for (y = 1; y < op->contr->ns->mapy - 1; y++) 263 for (int y = 1; y < op->contr->ns->mapy - 1; y++)
274 {
275 if (!op->contr->blocked_los[x][y] && 264 if (!op->contr->blocked_los[x][y] &&
276 !(get_map_flags (op->map, NULL, 265 !(get_map_flags (op->map, NULL,
277 op->x - op->contr->ns->mapx / 2 + x, 266 op->x - op->contr->ns->mapx / 2 + x,
278 op->y - op->contr->ns->mapy / 2 + y, NULL, NULL) & (P_BLOCKSVIEW | P_OUT_OF_MAP))) 267 op->y - op->contr->ns->mapy / 2 + y, NULL, NULL) & (P_BLOCKSVIEW | P_OUT_OF_MAP)))
279 { 268 {
280
281 for (i = 1; i <= 8; i += 1) 269 for (int i = 1; i <= 8; i += 1)
282 { /* mark all directions */ 270 { /* mark all directions */
283 dx = x + freearr_x[i]; 271 int dx = x + freearr_x[i];
284 dy = y + freearr_y[i]; 272 int dy = y + freearr_y[i];
273
285 if (op->contr->blocked_los[dx][dy] > 0) /* for any square blocked */ 274 if (op->contr->blocked_los[dx][dy] > 0) /* for any square blocked */
286 op->contr->blocked_los[dx][dy] = -1; 275 op->contr->blocked_los[dx][dy] = -1;
287 } 276 }
288 } 277 }
289 }
290 278
291 if (op->map->darkness > 0) /* player is on a dark map */ 279 if (op->map->darkness > 0) /* player is on a dark map */
292 expand_lighted_sight (op); 280 expand_lighted_sight (op);
293 281
294 /* clear mark squares */ 282 /* clear mark squares */
295 for (x = 0; x < op->contr->ns->mapx; x++) 283 for (int x = 0; x < op->contr->ns->mapx; x++)
296 for (y = 0; y < op->contr->ns->mapy; y++) 284 for (int y = 0; y < op->contr->ns->mapy; y++)
297 if (op->contr->blocked_los[x][y] < 0) 285 if (op->contr->blocked_los[x][y] < 0)
298 op->contr->blocked_los[x][y] = 0; 286 op->contr->blocked_los[x][y] = 0;
299} 287}
300 288
301/* returns true if op carries one or more lights 289/* returns true if op carries one or more lights
302 * This is a trivial function now days, but it used to 290 * This is a trivial function now days, but it used to
303 * be a bit longer. Probably better for callers to just 291 * be a bit longer. Probably better for callers to just
304 * check the op->glow_radius instead of calling this. 292 * check the op->glow_radius instead of calling this.
305 */ 293 */
306
307int 294int
308has_carried_lights (const object *op) 295has_carried_lights (const object *op)
309{ 296{
310 /* op may glow! */ 297 /* op may glow! */
311 if (op->glow_radius > 0) 298 if (op->glow_radius > 0)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines