1 | /* |
1 | /* |
2 | * static char *rcsid_sock_info_c = |
2 | * static char *rcsid_sock_info_c = |
3 | * "$Id: info.C,v 1.1 2006/08/13 17:16:05 elmex Exp $"; |
3 | * "$Id: info.C,v 1.2 2006/08/29 08:01:38 root 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 | |
… | |
… | |
51 | static void esrv_print_msg(NewSocket *ns,int color, const char *str) |
51 | static void esrv_print_msg(NewSocket *ns,int color, const char *str) |
52 | { |
52 | { |
53 | char buf[HUGE_BUF]; |
53 | char buf[HUGE_BUF]; |
54 | |
54 | |
55 | if (ns->status == Ns_Old) { |
55 | if (ns->status == Ns_Old) { |
56 | snprintf(buf,HUGE_BUF,"%s\n", str); |
56 | snprintf(buf,HUGE_BUF,"%s\n", str); |
57 | } else { |
57 | } else { |
58 | snprintf(buf,HUGE_BUF, "drawinfo %d %s", color, str); |
58 | snprintf(buf,HUGE_BUF, "drawinfo %d %s", color, str); |
59 | } |
59 | } |
60 | /* LOG(llevDebug,"sending %s to socket, len=%d\n", buf, strlen(buf));*/ |
60 | /* LOG(llevDebug,"sending %s to socket, len=%d\n", buf, strlen(buf));*/ |
61 | Write_String_To_Socket(ns, buf, strlen(buf)); |
61 | Write_String_To_Socket(ns, buf, strlen(buf)); |
62 | } |
62 | } |
63 | |
63 | |
… | |
… | |
72 | */ |
72 | */ |
73 | static void esrv_print_ext_msg(NewSocket *ns,int color,uint8 type, uint8 subtype, const char *message) |
73 | static void esrv_print_ext_msg(NewSocket *ns,int color,uint8 type, uint8 subtype, const char *message) |
74 | { |
74 | { |
75 | char buf[HUGE_BUF]; |
75 | char buf[HUGE_BUF]; |
76 | snprintf(buf,HUGE_BUF, "drawextinfo %d %hhu %hhu %s", color, type, subtype, message); |
76 | snprintf(buf,HUGE_BUF, "drawextinfo %d %hhu %hhu %s", color, type, subtype, message); |
77 | Write_String_To_Socket(ns, buf, strlen(buf)); |
77 | Write_String_To_Socket(ns, buf, strlen(buf)); |
78 | /* LOG(llevDebug,"sending %s to socket, len=%d", buf, strlen(buf));*/ |
78 | /* LOG(llevDebug,"sending %s to socket, len=%d", buf, strlen(buf));*/ |
79 | |
79 | |
80 | } |
80 | } |
81 | |
81 | |
82 | /** |
82 | /** |
… | |
… | |
145 | static void check_output_buffers(const object *pl, const char *buf) |
145 | static void check_output_buffers(const object *pl, const char *buf) |
146 | { |
146 | { |
147 | int i, oldest=0; |
147 | int i, oldest=0; |
148 | |
148 | |
149 | if (pl->contr->outputs_count<2) { |
149 | if (pl->contr->outputs_count<2) { |
150 | print_message(NDI_BLACK, pl, buf); |
150 | print_message(NDI_BLACK, pl, buf); |
151 | return; |
151 | return; |
152 | } |
152 | } |
153 | else { |
153 | else { |
154 | for (i=0; i<NUM_OUTPUT_BUFS; i++) { |
154 | for (i=0; i<NUM_OUTPUT_BUFS; i++) { |
155 | if (pl->contr->outputs[i].buf && |
155 | if (pl->contr->outputs[i].buf && |
156 | !strcmp(buf, pl->contr->outputs[i].buf)) break; |
156 | !strcmp(buf, pl->contr->outputs[i].buf)) break; |
157 | else if (pl->contr->outputs[i].first_update < |
157 | else if (pl->contr->outputs[i].first_update < |
158 | pl->contr->outputs[oldest].first_update) |
158 | pl->contr->outputs[oldest].first_update) |
159 | oldest=i; |
159 | oldest=i; |
160 | } |
160 | } |
161 | /* We found a match */ |
161 | /* We found a match */ |
162 | if (i<NUM_OUTPUT_BUFS) { |
162 | if (i<NUM_OUTPUT_BUFS) { |
163 | pl->contr->outputs[i].count++; |
163 | pl->contr->outputs[i].count++; |
164 | if (pl->contr->outputs[i].count>=pl->contr->outputs_count) { |
164 | if (pl->contr->outputs[i].count>=pl->contr->outputs_count) { |
165 | flush_output_element(pl, &pl->contr->outputs[i]); |
165 | flush_output_element(pl, &pl->contr->outputs[i]); |
166 | } |
166 | } |
167 | } |
167 | } |
168 | /* No match - flush the oldest, and put the new one in */ |
168 | /* No match - flush the oldest, and put the new one in */ |
169 | else { |
169 | else { |
170 | flush_output_element(pl, &pl->contr->outputs[oldest]); |
170 | flush_output_element(pl, &pl->contr->outputs[oldest]); |
171 | |
171 | |
172 | pl->contr->outputs[oldest].first_update = pticks; |
172 | pl->contr->outputs[oldest].first_update = pticks; |
173 | pl->contr->outputs[oldest].count = 1; |
173 | pl->contr->outputs[oldest].count = 1; |
174 | if (pl->contr->outputs[oldest].buf!=NULL) |
174 | if (pl->contr->outputs[oldest].buf!=NULL) |
175 | free_string(pl->contr->outputs[oldest].buf); |
175 | free_string(pl->contr->outputs[oldest].buf); |
176 | pl->contr->outputs[oldest].buf = add_string(buf); |
176 | pl->contr->outputs[oldest].buf = add_string(buf); |
177 | } |
177 | } |
178 | } |
178 | } |
179 | } |
179 | } |
180 | |
180 | |
181 | |
181 | |
182 | |
182 | |
183 | /** |
183 | /** |
184 | * Sends message to player(s). |
184 | * Sends message to player(s). |
185 | * |
185 | * |
… | |
… | |
199 | |
199 | |
200 | void new_draw_info(int flags, int pri, const object *pl, const char *buf) |
200 | void new_draw_info(int flags, int pri, const object *pl, const char *buf) |
201 | { |
201 | { |
202 | |
202 | |
203 | if (flags & NDI_ALL) { |
203 | if (flags & NDI_ALL) { |
204 | player *tmppl; |
204 | player *tmppl; |
205 | int i; |
205 | int i; |
206 | |
206 | |
207 | for (tmppl=first_player; tmppl!=NULL; tmppl=tmppl->next) |
207 | for (tmppl=first_player; tmppl!=NULL; tmppl=tmppl->next) |
208 | new_draw_info((flags & ~NDI_ALL), pri, tmppl->ob, buf); |
208 | new_draw_info((flags & ~NDI_ALL), pri, tmppl->ob, buf); |
209 | |
209 | |
210 | for (i=1; i<socket_info.allocated_sockets; i++) { |
210 | for (i=1; i<socket_info.allocated_sockets; i++) { |
211 | if (init_sockets[i].status == Ns_Old && init_sockets[i].old_mode != Old_Listen && pri< 10) { |
211 | if (init_sockets[i].status == Ns_Old && init_sockets[i].old_mode != Old_Listen && pri< 10) { |
212 | cs_write_string(&init_sockets[i], buf, strlen(buf)); |
212 | cs_write_string(&init_sockets[i], buf, strlen(buf)); |
213 | /* Most messages don't have a newline, so add one */ |
213 | /* Most messages don't have a newline, so add one */ |
214 | cs_write_string(&init_sockets[i], "\n", 1); |
214 | cs_write_string(&init_sockets[i], "\n", 1); |
215 | } |
215 | } |
216 | } |
216 | } |
217 | |
217 | |
218 | return; |
218 | return; |
219 | } |
219 | } |
220 | if(!pl || (pl->type==PLAYER && pl->contr==NULL)) { |
220 | if(!pl || (pl->type==PLAYER && pl->contr==NULL)) { |
221 | /* Write to the socket? */ |
221 | /* Write to the socket? */ |
222 | print_message(0, NULL, buf); |
222 | print_message(0, NULL, buf); |
223 | return; |
223 | return; |
224 | } |
224 | } |
225 | if (pl->type!=PLAYER) return; |
225 | if (pl->type!=PLAYER) return; |
226 | if (pri>=pl->contr->listening) return; |
226 | if (pri>=pl->contr->listening) return; |
227 | |
227 | |
228 | if ((flags&NDI_COLOR_MASK)==NDI_BLACK && !(flags &NDI_UNIQUE)) { |
228 | if ((flags&NDI_COLOR_MASK)==NDI_BLACK && !(flags &NDI_UNIQUE)) { |
229 | /* following prints stuff out, as appropriate */ |
229 | /* following prints stuff out, as appropriate */ |
230 | check_output_buffers(pl, buf); |
230 | check_output_buffers(pl, buf); |
231 | } |
231 | } |
232 | else { |
232 | else { |
233 | print_message(flags&NDI_COLOR_MASK, pl, buf); |
233 | print_message(flags&NDI_COLOR_MASK, pl, buf); |
234 | } |
234 | } |
235 | } |
235 | } |
236 | |
236 | |
237 | /** |
237 | /** |
238 | * Wrapper for new_draw_info printf-like. |
238 | * Wrapper for new_draw_info printf-like. |
… | |
… | |
285 | int flags, int pri, const object *pl, uint8 type, |
285 | int flags, int pri, const object *pl, uint8 type, |
286 | uint8 subtype, const char* old_format, |
286 | uint8 subtype, const char* old_format, |
287 | char* new_format, ...){ |
287 | char* new_format, ...){ |
288 | |
288 | |
289 | char buf[HUGE_BUF]; |
289 | char buf[HUGE_BUF]; |
290 | if(!pl || (pl->type!=PLAYER) || (pl->contr==NULL)) |
290 | if(!pl || (pl->type!=PLAYER) || (pl->contr==NULL)) |
291 | return; |
291 | return; |
292 | |
292 | |
293 | if (pri>=pl->contr->listening) return; |
293 | if (pri>=pl->contr->listening) return; |
294 | if (!CLIENT_SUPPORT_READABLES(&pl->contr->socket,type)){ |
294 | if (!CLIENT_SUPPORT_READABLES(&pl->contr->socket,type)){ |
295 | va_list ap; |
295 | va_list ap; |
296 | LOG(llevDebug,"Non supported extension text type for client.\n"); |
296 | LOG(llevDebug,"Non supported extension text type for client.\n"); |
297 | va_start(ap, new_format); |
297 | va_start(ap, new_format); |
298 | vsnprintf(buf, HUGE_BUF, old_format, ap); |
298 | vsnprintf(buf, HUGE_BUF, old_format, ap); |
299 | va_end(ap); |
299 | va_end(ap); |
300 | new_draw_info(flags, pri, pl, buf); |
300 | new_draw_info(flags, pri, pl, buf); |
301 | return; |
301 | return; |
302 | }else{ |
302 | }else{ |
303 | va_list ap; |
303 | va_list ap; |
304 | va_start(ap, new_format); |
304 | va_start(ap, new_format); |
305 | vsnprintf(buf, HUGE_BUF, new_format, ap); |
305 | vsnprintf(buf, HUGE_BUF, new_format, ap); |
306 | va_end(ap); |
306 | va_end(ap); |
307 | strip_media_tag(buf); |
307 | strip_media_tag(buf); |
… | |
… | |
314 | |
314 | |
315 | void new_info_map_except(int color, mapstruct *map, object *op, const char *str) { |
315 | void new_info_map_except(int color, mapstruct *map, object *op, const char *str) { |
316 | player *pl; |
316 | player *pl; |
317 | |
317 | |
318 | for(pl = first_player; pl != NULL; pl = pl->next) |
318 | for(pl = first_player; pl != NULL; pl = pl->next) |
319 | if(pl->ob != NULL && pl->ob->map == map && pl->ob != op) { |
319 | if(pl->ob != NULL && pl->ob->map == map && pl->ob != op) { |
320 | new_draw_info(color, 0, pl->ob, str); |
320 | new_draw_info(color, 0, pl->ob, str); |
321 | } |
321 | } |
322 | } |
322 | } |
323 | |
323 | |
324 | /** |
324 | /** |
325 | * Writes to everyone on the map except op1 and op2 |
325 | * Writes to everyone on the map except op1 and op2 |
326 | */ |
326 | */ |
327 | |
327 | |
328 | void new_info_map_except2(int color, mapstruct *map, object *op1, object *op2, |
328 | void new_info_map_except2(int color, mapstruct *map, object *op1, object *op2, |
329 | const char *str) { |
329 | const char *str) { |
330 | player *pl; |
330 | player *pl; |
331 | |
331 | |
332 | for(pl = first_player; pl != NULL; pl = pl->next) |
332 | for(pl = first_player; pl != NULL; pl = pl->next) |
333 | if(pl->ob != NULL && pl->ob->map == map |
333 | if(pl->ob != NULL && pl->ob->map == map |
334 | && pl->ob != op1 && pl->ob != op2) { |
334 | && pl->ob != op1 && pl->ob != op2) { |
335 | new_draw_info(color, 0, pl->ob, str); |
335 | new_draw_info(color, 0, pl->ob, str); |
336 | } |
336 | } |
337 | } |
337 | } |
338 | |
338 | |
339 | /** |
339 | /** |
340 | * Writes to everyone on the specified map |
340 | * Writes to everyone on the specified map |
341 | */ |
341 | */ |
342 | |
342 | |
343 | void new_info_map(int color, mapstruct *map, const char *str) { |
343 | void new_info_map(int color, mapstruct *map, const char *str) { |
344 | player *pl; |
344 | player *pl; |
345 | |
345 | |
346 | for(pl = first_player; pl != NULL; pl = pl->next) |
346 | for(pl = first_player; pl != NULL; pl = pl->next) |
347 | if(pl->ob != NULL && pl->ob->map == map) { |
347 | if(pl->ob != NULL && pl->ob->map == map) { |
348 | new_draw_info(color, 0, pl->ob, str); |
348 | new_draw_info(color, 0, pl->ob, str); |
349 | } |
349 | } |
350 | } |
350 | } |
351 | |
351 | |
352 | |
352 | |
353 | /** |
353 | /** |
354 | * This does nothing now. However, in theory, we should probably send |
354 | * This does nothing now. However, in theory, we should probably send |
… | |
… | |
363 | * Get player's current range attack in obuf. |
363 | * Get player's current range attack in obuf. |
364 | */ |
364 | */ |
365 | void rangetostring(object *pl,char *obuf) |
365 | void rangetostring(object *pl,char *obuf) |
366 | { |
366 | { |
367 | switch(pl->contr->shoottype) { |
367 | switch(pl->contr->shoottype) { |
368 | case range_none: |
368 | case range_none: |
369 | strcpy(obuf,"Range: nothing"); |
369 | strcpy(obuf,"Range: nothing"); |
370 | break; |
370 | break; |
371 | |
371 | |
372 | case range_bow: |
372 | case range_bow: |
373 | { |
373 | { |
374 | object *op; |
374 | object *op; |
375 | |
375 | |
376 | for (op = pl->inv; op; op=op->below) |
376 | for (op = pl->inv; op; op=op->below) |
377 | if (op->type == BOW && QUERY_FLAG (op, FLAG_APPLIED)) |
377 | if (op->type == BOW && QUERY_FLAG (op, FLAG_APPLIED)) |
378 | break; |
378 | break; |
379 | if(op==NULL) break; |
379 | if(op==NULL) break; |
380 | |
380 | |
381 | sprintf (obuf, "Range: %s (%s)", query_base_name(op, 0), |
381 | sprintf (obuf, "Range: %s (%s)", query_base_name(op, 0), |
382 | op->race ? op->race : "nothing"); |
382 | op->race ? op->race : "nothing"); |
383 | } |
383 | } |
384 | break; |
384 | break; |
385 | |
385 | |
386 | case range_magic: |
386 | case range_magic: |
387 | if (settings.casting_time == TRUE) { |
387 | if (settings.casting_time == TRUE) { |
388 | if (pl->casting_time > -1) { |
388 | if (pl->casting_time > -1) { |
389 | if (pl->casting_time == 0) |
389 | if (pl->casting_time == 0) |
390 | sprintf(obuf,"Range: Holding spell (%s)", |
390 | sprintf(obuf,"Range: Holding spell (%s)", |
391 | pl->spell->name); |
391 | pl->spell->name); |
392 | else |
392 | else |
393 | sprintf(obuf,"Range: Casting spell (%s)", |
393 | sprintf(obuf,"Range: Casting spell (%s)", |
394 | pl->spell->name); |
394 | pl->spell->name); |
395 | } else |
395 | } else |
|
|
396 | sprintf(obuf,"Range: spell (%s)", |
|
|
397 | pl->contr->ranges[range_magic]->name); |
|
|
398 | } else |
396 | sprintf(obuf,"Range: spell (%s)", |
399 | sprintf(obuf,"Range: spell (%s)", |
397 | pl->contr->ranges[range_magic]->name); |
400 | pl->contr->ranges[range_magic]->name); |
398 | } else |
401 | break; |
399 | sprintf(obuf,"Range: spell (%s)", |
|
|
400 | pl->contr->ranges[range_magic]->name); |
|
|
401 | break; |
|
|
402 | |
402 | |
403 | case range_misc: |
403 | case range_misc: |
404 | sprintf(obuf,"Range: %s", |
404 | sprintf(obuf,"Range: %s", |
405 | pl->contr->ranges[range_misc]? |
405 | pl->contr->ranges[range_misc]? |
406 | query_base_name(pl->contr->ranges[range_misc],0): "none"); |
406 | query_base_name(pl->contr->ranges[range_misc],0): "none"); |
407 | break; |
407 | break; |
408 | |
408 | |
409 | /* range_scroll is only used for controlling golems. If the |
409 | /* range_scroll is only used for controlling golems. If the |
410 | * the player does not have a golem, reset some things. |
410 | * the player does not have a golem, reset some things. |
411 | */ |
411 | */ |
412 | case range_golem: |
412 | case range_golem: |
413 | if (pl->contr->ranges[range_golem]!=NULL) |
413 | if (pl->contr->ranges[range_golem]!=NULL) |
414 | sprintf(obuf,"Range: golem (%s)",pl->contr->ranges[range_golem]->name); |
414 | sprintf(obuf,"Range: golem (%s)",pl->contr->ranges[range_golem]->name); |
415 | else { |
415 | else { |
416 | pl->contr->shoottype = range_none; |
416 | pl->contr->shoottype = range_none; |
417 | strcpy(obuf,"Range: nothing"); |
417 | strcpy(obuf,"Range: nothing"); |
418 | } |
418 | } |
419 | break; |
419 | break; |
420 | |
420 | |
421 | case range_skill: |
421 | case range_skill: |
422 | sprintf(obuf,"Skill: %s", pl->chosen_skill!=NULL ? |
422 | sprintf(obuf,"Skill: %s", pl->chosen_skill!=NULL ? |
423 | pl->chosen_skill->name : "none"); |
423 | pl->chosen_skill->name : "none"); |
424 | break; |
424 | break; |
425 | |
425 | |
426 | case range_builder: |
426 | case range_builder: |
427 | sprintf( obuf, "Builder: %s", query_base_name( pl->contr->ranges[ range_builder ], 0 ) ); |
427 | sprintf( obuf, "Builder: %s", query_base_name( pl->contr->ranges[ range_builder ], 0 ) ); |
428 | break; |
428 | break; |
429 | |
429 | |
430 | default: |
430 | default: |
431 | strcpy(obuf,"Range: illegal"); |
431 | strcpy(obuf,"Range: illegal"); |
432 | } |
432 | } |
433 | } |
433 | } |
434 | |
434 | |
435 | /** |
435 | /** |
436 | * Sets player title. |
436 | * Sets player title. |
437 | */ |
437 | */ |
438 | void set_title(object *pl, char *buf) |
438 | void set_title(object *pl, char *buf) |
439 | { |
439 | { |
440 | /* Eneq(@csd.uu.se): Let players define their own titles. */ |
440 | /* Eneq(@csd.uu.se): Let players define their own titles. */ |
441 | if (pl->contr->own_title[0]=='\0') |
441 | if (pl->contr->own_title[0]=='\0') |
442 | sprintf(buf,"Player: %s the %s",pl->name,pl->contr->title); |
442 | sprintf(buf,"Player: %s the %s",pl->name,pl->contr->title); |
443 | else |
443 | else |
444 | sprintf(buf,"Player: %s %s",pl->name,pl->contr->own_title); |
444 | sprintf(buf,"Player: %s %s",pl->name,pl->contr->own_title); |
445 | } |
445 | } |
446 | |
446 | |
447 | |
447 | |
448 | /** |
448 | /** |
449 | * Helper for magic map creation. |
449 | * Helper for magic map creation. |
… | |
… | |
462 | sint16 nx, ny; |
462 | sint16 nx, ny; |
463 | mapstruct *mp; |
463 | mapstruct *mp; |
464 | New_Face *f; |
464 | New_Face *f; |
465 | |
465 | |
466 | for (dx = -1; dx <= 1; dx++) { |
466 | for (dx = -1; dx <= 1; dx++) { |
467 | for (dy = -1; dy <= 1; dy++) { |
467 | for (dy = -1; dy <= 1; dy++) { |
468 | x = px + dx; |
468 | x = px + dx; |
469 | y = py + dy; |
469 | y = py + dy; |
470 | |
470 | |
471 | if (FABS(x) >= MAGIC_MAP_HALF || FABS(y) >= MAGIC_MAP_HALF) continue; |
471 | if (FABS(x) >= MAGIC_MAP_HALF || FABS(y) >= MAGIC_MAP_HALF) continue; |
472 | |
472 | |
473 | mp = pl->map; |
473 | mp = pl->map; |
474 | nx = pl->x + x; |
474 | nx = pl->x + x; |
475 | ny = pl->y + y; |
475 | ny = pl->y + y; |
476 | |
476 | |
477 | mflags = get_map_flags(pl->map, &mp, nx, ny, &nx, &ny); |
477 | mflags = get_map_flags(pl->map, &mp, nx, ny, &nx, &ny); |
478 | if (mflags & P_OUT_OF_MAP) continue; |
478 | if (mflags & P_OUT_OF_MAP) continue; |
479 | |
479 | |
480 | if (map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE* (MAGIC_MAP_HALF + y)] == 0) { |
480 | if (map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE* (MAGIC_MAP_HALF + y)] == 0) { |
481 | f= GET_MAP_FACE(mp, nx, ny, 0); |
|
|
482 | if (f == blank_face) |
|
|
483 | f= GET_MAP_FACE(mp, nx, ny, 1); |
481 | f= GET_MAP_FACE(mp, nx, ny, 0); |
484 | if (f == blank_face) |
482 | if (f == blank_face) |
|
|
483 | f= GET_MAP_FACE(mp, nx, ny, 1); |
|
|
484 | if (f == blank_face) |
485 | f= GET_MAP_FACE(mp, nx, ny, 2); |
485 | f= GET_MAP_FACE(mp, nx, ny, 2); |
486 | |
486 | |
487 | /* Should probably have P_NO_MAGIC here also, but then shops don't |
487 | /* Should probably have P_NO_MAGIC here also, but then shops don't |
488 | * work. |
488 | * work. |
489 | */ |
489 | */ |
490 | if (mflags & P_BLOCKSVIEW) |
490 | if (mflags & P_BLOCKSVIEW) |
491 | map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE* (MAGIC_MAP_HALF + y)] = FACE_WALL | (f?f->magicmap:0); |
491 | map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE* (MAGIC_MAP_HALF + y)] = FACE_WALL | (f?f->magicmap:0); |
492 | else { |
492 | else { |
493 | map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE* (MAGIC_MAP_HALF + y)] = FACE_FLOOR | (f?f->magicmap:0); |
493 | map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE* (MAGIC_MAP_HALF + y)] = FACE_FLOOR | (f?f->magicmap:0); |
494 | magic_mapping_mark_recursive(pl, map_mark, x, y); |
494 | magic_mapping_mark_recursive(pl, map_mark, x, y); |
495 | } |
495 | } |
496 | } |
496 | } |
497 | } |
497 | } |
498 | } |
498 | } |
499 | } |
499 | } |
500 | |
500 | |
501 | |
501 | |
502 | /** |
502 | /** |
… | |
… | |
521 | sint16 nx, ny; |
521 | sint16 nx, ny; |
522 | mapstruct *mp; |
522 | mapstruct *mp; |
523 | New_Face *f; |
523 | New_Face *f; |
524 | |
524 | |
525 | for (x = -strength; x <strength; x++) { |
525 | for (x = -strength; x <strength; x++) { |
526 | for (y = -strength; y <strength; y++) { |
526 | for (y = -strength; y <strength; y++) { |
527 | mp = pl->map; |
527 | mp = pl->map; |
528 | nx = pl->x + x; |
528 | nx = pl->x + x; |
529 | ny = pl->y + y; |
529 | ny = pl->y + y; |
530 | mflags = get_map_flags(pl->map, &mp, nx, ny, &nx, &ny); |
530 | mflags = get_map_flags(pl->map, &mp, nx, ny, &nx, &ny); |
531 | if (mflags & P_OUT_OF_MAP) |
531 | if (mflags & P_OUT_OF_MAP) |
532 | continue; |
532 | continue; |
533 | else { |
533 | else { |
534 | f= GET_MAP_FACE(mp, nx, ny, 0); |
|
|
535 | if (f == blank_face) |
|
|
536 | f= GET_MAP_FACE(mp, nx, ny, 1); |
534 | f= GET_MAP_FACE(mp, nx, ny, 0); |
537 | if (f == blank_face) |
535 | if (f == blank_face) |
|
|
536 | f= GET_MAP_FACE(mp, nx, ny, 1); |
|
|
537 | if (f == blank_face) |
538 | f= GET_MAP_FACE(mp, nx, ny, 2); |
538 | f= GET_MAP_FACE(mp, nx, ny, 2); |
539 | } |
539 | } |
540 | |
540 | |
541 | if (mflags & P_BLOCKSVIEW) |
541 | if (mflags & P_BLOCKSVIEW) |
542 | map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE* (MAGIC_MAP_HALF + y)] = FACE_WALL | (f?f->magicmap:0); |
542 | map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE* (MAGIC_MAP_HALF + y)] = FACE_WALL | (f?f->magicmap:0); |
543 | else { |
543 | else { |
544 | map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE* (MAGIC_MAP_HALF + y)] = FACE_FLOOR | (f?f->magicmap:0); |
544 | map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE* (MAGIC_MAP_HALF + y)] = FACE_FLOOR | (f?f->magicmap:0); |
545 | magic_mapping_mark_recursive(pl, map_mark, x, y); |
545 | magic_mapping_mark_recursive(pl, map_mark, x, y); |
546 | } |
546 | } |
547 | } |
547 | } |
548 | } |
548 | } |
549 | } |
549 | } |
550 | |
550 | |
551 | |
551 | |
552 | /** |
552 | /** |
… | |
… | |
564 | char *map_mark = (char *) calloc(MAGIC_MAP_SIZE*MAGIC_MAP_SIZE, 1); |
564 | char *map_mark = (char *) calloc(MAGIC_MAP_SIZE*MAGIC_MAP_SIZE, 1); |
565 | int xmin, xmax, ymin, ymax; |
565 | int xmin, xmax, ymin, ymax; |
566 | SockList sl; |
566 | SockList sl; |
567 | |
567 | |
568 | if (pl->type!=PLAYER) { |
568 | if (pl->type!=PLAYER) { |
569 | LOG(llevError,"Non player object called draw_map.\n"); |
569 | LOG(llevError,"Non player object called draw_map.\n"); |
570 | return; |
570 | return; |
571 | } |
571 | } |
572 | |
572 | |
573 | /* First, we figure out what spaces are 'reachable' by the player */ |
573 | /* First, we figure out what spaces are 'reachable' by the player */ |
574 | magic_mapping_mark(pl, map_mark, 3); |
574 | magic_mapping_mark(pl, map_mark, 3); |
575 | |
575 | |
… | |
… | |
581 | xmin = MAGIC_MAP_SIZE; |
581 | xmin = MAGIC_MAP_SIZE; |
582 | ymin = MAGIC_MAP_SIZE; |
582 | ymin = MAGIC_MAP_SIZE; |
583 | xmax = 0; |
583 | xmax = 0; |
584 | ymax = 0; |
584 | ymax = 0; |
585 | for(x = 0; x < MAGIC_MAP_SIZE ; x++) { |
585 | for(x = 0; x < MAGIC_MAP_SIZE ; x++) { |
586 | for(y = 0; y < MAGIC_MAP_SIZE; y++) { |
586 | for(y = 0; y < MAGIC_MAP_SIZE; y++) { |
587 | if (map_mark[x + MAP_WIDTH(pl->map) * y] | FACE_FLOOR) { |
587 | if (map_mark[x + MAP_WIDTH(pl->map) * y] | FACE_FLOOR) { |
588 | xmin = x < xmin ? x : xmin; |
588 | xmin = x < xmin ? x : xmin; |
589 | xmax = x > xmax ? x : xmax; |
589 | xmax = x > xmax ? x : xmax; |
590 | ymin = y < ymin ? y : ymin; |
590 | ymin = y < ymin ? y : ymin; |
591 | ymax = y > ymax ? y : ymax; |
591 | ymax = y > ymax ? y : ymax; |
592 | } |
592 | } |
593 | } |
593 | } |
594 | } |
594 | } |
595 | |
595 | |
596 | sl.buf= (unsigned char*) malloc(MAXSOCKBUF); |
596 | sl.buf= (unsigned char*) malloc(MAXSOCKBUF); |
597 | snprintf((char*)sl.buf, MAXSOCKBUF, "magicmap %d %d %d %d ", (xmax-xmin+1), (ymax-ymin+1), |
597 | snprintf((char*)sl.buf, MAXSOCKBUF, "magicmap %d %d %d %d ", (xmax-xmin+1), (ymax-ymin+1), |
598 | MAGIC_MAP_HALF - xmin, MAGIC_MAP_HALF - ymin); |
598 | MAGIC_MAP_HALF - xmin, MAGIC_MAP_HALF - ymin); |
599 | sl.len=strlen((char*)sl.buf); |
599 | sl.len=strlen((char*)sl.buf); |
600 | |
600 | |
601 | for (y = ymin; y <= ymax; y++) { |
601 | for (y = ymin; y <= ymax; y++) { |
602 | for (x = xmin; x <= xmax; x++) { |
602 | for (x = xmin; x <= xmax; x++) { |
603 | sl.buf[sl.len++]= map_mark[x+MAGIC_MAP_SIZE*y] & ~FACE_FLOOR; |
603 | sl.buf[sl.len++]= map_mark[x+MAGIC_MAP_SIZE*y] & ~FACE_FLOOR; |
604 | } /* x loop */ |
604 | } /* x loop */ |
605 | } /* y loop */ |
605 | } /* y loop */ |
606 | |
606 | |
607 | Send_With_Handling(&pl->contr->socket, &sl); |
607 | Send_With_Handling(&pl->contr->socket, &sl); |
608 | free(sl.buf); |
608 | free(sl.buf); |
609 | free(map_mark); |
609 | free(map_mark); |
… | |
… | |
621 | int i; |
621 | int i; |
622 | size_t len; |
622 | size_t len; |
623 | char buf[MAX_BUF]; |
623 | char buf[MAX_BUF]; |
624 | |
624 | |
625 | if (With!=NULL) { |
625 | if (With!=NULL) { |
626 | snprintf(buf, MAX_BUF, "%s\t%s\t%d\t%s\t%d\n",Who,What,WhatType,With,WithType); |
626 | snprintf(buf, MAX_BUF, "%s\t%s\t%d\t%s\t%d\n",Who,What,WhatType,With,WithType); |
627 | } |
627 | } |
628 | else { |
628 | else { |
629 | snprintf(buf,MAX_BUF, "%s\t%s\t%d\n",Who,What,WhatType); |
629 | snprintf(buf,MAX_BUF, "%s\t%s\t%d\n",Who,What,WhatType); |
630 | } |
630 | } |
631 | len=strlen(buf); |
631 | len=strlen(buf); |
632 | for(i=1; i<socket_info.allocated_sockets; i++) { |
632 | for(i=1; i<socket_info.allocated_sockets; i++) { |
633 | if (init_sockets[i].old_mode == Old_Listen) { |
633 | if (init_sockets[i].old_mode == Old_Listen) { |
634 | cs_write_string(&init_sockets[i], buf, len); |
634 | cs_write_string(&init_sockets[i], buf, len); |
635 | } |
635 | } |
636 | } |
636 | } |
637 | } |
637 | } |