1 | |
|
|
2 | /* |
1 | /* |
3 | CrossFire, A Multiplayer game for X-windows |
2 | * CrossFire, A Multiplayer game for X-windows |
4 | |
3 | * |
|
|
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
5 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
6 | Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (C) 1992 Frank Tore Johansen |
7 | |
7 | * |
8 | This program is free software; you can redistribute it and/or modify |
8 | * This program is free software; you can redistribute it and/or modify |
9 | it under the terms of the GNU General Public License as published by |
9 | * it under the terms of the GNU General Public License as published by |
10 | the Free Software Foundation; either version 2 of the License, or |
10 | * the Free Software Foundation; either version 2 of the License, or |
11 | (at your option) any later version. |
11 | * (at your option) any later version. |
12 | |
12 | * |
13 | This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | |
17 | * |
18 | You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
19 | * along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
21 | |
21 | * |
22 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
22 | * The authors can be reached via e-mail at <crossfire@schmorp.de> |
23 | */ |
23 | */ |
24 | |
24 | |
25 | /** |
25 | /** |
26 | * \file |
26 | * \file |
27 | * Basic client output functions. |
27 | * Basic client output functions. |
28 | * |
28 | * |
… | |
… | |
191 | new_draw_info (flags & ~NDI_ALL, pri, pl->ob, buf); |
191 | new_draw_info (flags & ~NDI_ALL, pri, pl->ob, buf); |
192 | |
192 | |
193 | return; |
193 | return; |
194 | } |
194 | } |
195 | |
195 | |
196 | if (!pl || (pl->type == PLAYER && pl->contr == NULL)) |
196 | if (!pl || pl->type != PLAYER || !pl->contr || !pl->contr->ns) |
197 | { |
|
|
198 | /* Write to the socket? */ |
|
|
199 | print_message (0, NULL, buf); |
|
|
200 | return; |
|
|
201 | } |
|
|
202 | |
|
|
203 | if (pl->type != PLAYER) |
|
|
204 | return; |
197 | return; |
205 | |
198 | |
206 | if (pri >= pl->contr->listening) |
199 | if (pri >= pl->contr->listening) |
207 | return; |
200 | return; |
208 | |
201 | |
209 | if ((flags & NDI_COLOR_MASK) == NDI_BLACK && !(flags & NDI_UNIQUE)) |
202 | if ((flags & NDI_COLOR_MASK) == NDI_BLACK && !(flags & NDI_UNIQUE)) |
210 | /* following prints stuff out, as appropriate */ |
|
|
211 | check_output_buffers (pl, buf); |
203 | check_output_buffers (pl, buf); |
212 | else |
204 | else |
213 | print_message (flags & NDI_COLOR_MASK, pl, buf); |
205 | print_message (flags & NDI_COLOR_MASK, pl, buf); |
214 | } |
206 | } |
215 | |
207 | |
… | |
… | |
225 | new_draw_info_format (int flags, int pri, const object *pl, const char *format, ...) |
217 | new_draw_info_format (int flags, int pri, const object *pl, const char *format, ...) |
226 | { |
218 | { |
227 | char buf[HUGE_BUF]; |
219 | char buf[HUGE_BUF]; |
228 | |
220 | |
229 | va_list ap; |
221 | va_list ap; |
230 | |
|
|
231 | va_start (ap, format); |
222 | va_start (ap, format); |
232 | |
|
|
233 | vsnprintf (buf, HUGE_BUF, format, ap); |
223 | vsnprintf (buf, HUGE_BUF, format, ap); |
234 | |
|
|
235 | va_end (ap); |
224 | va_end (ap); |
236 | |
225 | |
237 | new_draw_info (flags, pri, pl, buf); |
226 | new_draw_info (flags, pri, pl, buf); |
238 | } |
227 | } |
239 | |
228 | |
… | |
… | |
266 | } |
255 | } |
267 | |
256 | |
268 | void |
257 | void |
269 | draw_ext_info_format (int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *old_format, char *new_format, ...) |
258 | draw_ext_info_format (int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *old_format, char *new_format, ...) |
270 | { |
259 | { |
271 | |
|
|
272 | char buf[HUGE_BUF]; |
260 | char buf[HUGE_BUF]; |
273 | |
261 | |
274 | if (!pl || (pl->type != PLAYER) || (pl->contr == NULL)) |
262 | if (!pl || (pl->type != PLAYER) || (pl->contr == NULL)) |
275 | return; |
263 | return; |
276 | |
264 | |
… | |
… | |
305 | */ |
293 | */ |
306 | |
294 | |
307 | void |
295 | void |
308 | new_info_map_except (int color, maptile * map, object *op, const char *str) |
296 | new_info_map_except (int color, maptile * map, object *op, const char *str) |
309 | { |
297 | { |
310 | player *pl; |
|
|
311 | |
|
|
312 | for_all_players (pl) |
298 | for_all_players (pl) |
313 | if (pl->ob != NULL && pl->ob->map == map && pl->ob != op) |
299 | if (pl->ob != NULL && pl->ob->map == map && pl->ob != op) |
314 | { |
|
|
315 | new_draw_info (color, 0, pl->ob, str); |
300 | new_draw_info (color, 0, pl->ob, str); |
316 | } |
|
|
317 | } |
301 | } |
318 | |
302 | |
319 | /** |
303 | /** |
320 | * Writes to everyone on the map except op1 and op2 |
304 | * Writes to everyone on the map except op1 and op2 |
321 | */ |
305 | */ |
322 | |
306 | |
323 | void |
307 | void |
324 | new_info_map_except2 (int color, maptile * map, object *op1, object *op2, const char *str) |
308 | new_info_map_except2 (int color, maptile * map, object *op1, object *op2, const char *str) |
325 | { |
309 | { |
326 | player *pl; |
|
|
327 | |
|
|
328 | for_all_players (pl) |
310 | for_all_players (pl) |
329 | if (pl->ob != NULL && pl->ob->map == map && pl->ob != op1 && pl->ob != op2) |
311 | if (pl->ob != NULL && pl->ob->map == map && pl->ob != op1 && pl->ob != op2) |
330 | { |
|
|
331 | new_draw_info (color, 0, pl->ob, str); |
312 | new_draw_info (color, 0, pl->ob, str); |
332 | } |
|
|
333 | } |
313 | } |
334 | |
314 | |
335 | /** |
315 | /** |
336 | * Writes to everyone on the specified map |
316 | * Writes to everyone on the specified map |
337 | */ |
317 | */ |
338 | |
318 | |
339 | void |
319 | void |
340 | new_info_map (int color, maptile * map, const char *str) |
320 | new_info_map (int color, maptile * map, const char *str) |
341 | { |
321 | { |
342 | player *pl; |
|
|
343 | |
|
|
344 | for_all_players (pl) |
322 | for_all_players (pl) |
345 | if (pl->ob != NULL && pl->ob->map == map) |
323 | if (pl->ob != NULL && pl->ob->map == map) |
346 | { |
|
|
347 | new_draw_info (color, 0, pl->ob, str); |
324 | new_draw_info (color, 0, pl->ob, str); |
348 | } |
|
|
349 | } |
325 | } |
350 | |
|
|
351 | |
326 | |
352 | /** |
327 | /** |
353 | * This does nothing now. However, in theory, we should probably send |
328 | * This does nothing now. However, in theory, we should probably send |
354 | * something to the client and let the client figure out how it might want |
329 | * something to the client and let the client figure out how it might want |
355 | * to handle this |
330 | * to handle this |
… | |
… | |
444 | sprintf (buf, "Player: %s the %s", (const char *) pl->name, (const char *) pl->contr->title); |
419 | sprintf (buf, "Player: %s the %s", (const char *) pl->name, (const char *) pl->contr->title); |
445 | else |
420 | else |
446 | sprintf (buf, "Player: %s %s", (const char *) pl->name, (const char *) pl->contr->own_title); |
421 | sprintf (buf, "Player: %s %s", (const char *) pl->name, (const char *) pl->contr->own_title); |
447 | } |
422 | } |
448 | |
423 | |
449 | |
|
|
450 | /** |
424 | /** |
451 | * Helper for magic map creation. |
425 | * Helper for magic map creation. |
452 | * |
426 | * |
453 | * Takes a player, the map_mark array and an x and y starting position. |
427 | * Takes a player, the map_mark array and an x and y starting position. |
454 | * pl is the player. |
428 | * pl is the player. |
… | |
… | |
462 | magic_mapping_mark_recursive (object *pl, char *map_mark, int px, int py) |
436 | magic_mapping_mark_recursive (object *pl, char *map_mark, int px, int py) |
463 | { |
437 | { |
464 | int x, y, dx, dy, mflags; |
438 | int x, y, dx, dy, mflags; |
465 | sint16 nx, ny; |
439 | sint16 nx, ny; |
466 | maptile *mp; |
440 | maptile *mp; |
467 | New_Face *f; |
|
|
468 | |
441 | |
469 | for (dx = -1; dx <= 1; dx++) |
442 | for (dx = -1; dx <= 1; dx++) |
470 | { |
443 | { |
471 | for (dy = -1; dy <= 1; dy++) |
444 | for (dy = -1; dy <= 1; dy++) |
472 | { |
445 | { |
… | |
… | |
484 | if (mflags & P_OUT_OF_MAP) |
457 | if (mflags & P_OUT_OF_MAP) |
485 | continue; |
458 | continue; |
486 | |
459 | |
487 | if (map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE * (MAGIC_MAP_HALF + y)] == 0) |
460 | if (map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE * (MAGIC_MAP_HALF + y)] == 0) |
488 | { |
461 | { |
489 | f = GET_MAP_FACE (mp, nx, ny, 0); |
462 | int f = GET_MAP_FACE (mp, nx, ny, 0); |
490 | if (f == blank_face) |
463 | if (f == blank_face) |
|
|
464 | { |
491 | f = GET_MAP_FACE (mp, nx, ny, 1); |
465 | f = GET_MAP_FACE (mp, nx, ny, 1); |
492 | if (f == blank_face) |
466 | if (f == blank_face) |
493 | f = GET_MAP_FACE (mp, nx, ny, 2); |
467 | f = GET_MAP_FACE (mp, nx, ny, 2); |
|
|
468 | } |
|
|
469 | |
|
|
470 | int magicmap = faces [f].magicmap; |
494 | |
471 | |
495 | /* Should probably have P_NO_MAGIC here also, but then shops don't |
472 | /* Should probably have P_NO_MAGIC here also, but then shops don't |
496 | * work. |
473 | * work. |
497 | */ |
474 | */ |
498 | if (mflags & P_BLOCKSVIEW) |
475 | if (mflags & P_BLOCKSVIEW) |
499 | map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE * (MAGIC_MAP_HALF + y)] = FACE_WALL | (f ? f->magicmap : 0); |
476 | map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE * (MAGIC_MAP_HALF + y)] = FACE_WALL | magicmap; |
500 | else |
477 | else |
501 | { |
478 | { |
502 | map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE * (MAGIC_MAP_HALF + y)] = FACE_FLOOR | (f ? f->magicmap : 0); |
479 | map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE * (MAGIC_MAP_HALF + y)] = FACE_FLOOR | magicmap; |
503 | magic_mapping_mark_recursive (pl, map_mark, x, y); |
480 | magic_mapping_mark_recursive (pl, map_mark, x, y); |
504 | } |
481 | } |
505 | } |
482 | } |
506 | } |
483 | } |
507 | } |
484 | } |
508 | } |
485 | } |
509 | |
|
|
510 | |
486 | |
511 | /** |
487 | /** |
512 | * Creates magic map for player. |
488 | * Creates magic map for player. |
513 | * |
489 | * |
514 | * Note: For improved magic mapping display, the space that blocks |
490 | * Note: For improved magic mapping display, the space that blocks |
… | |
… | |
516 | * being nonzero have been changed to check for 1. Also, since |
492 | * being nonzero have been changed to check for 1. Also, since |
517 | * map_mark is a char value, putting 2 in should cause no problems. |
493 | * map_mark is a char value, putting 2 in should cause no problems. |
518 | * |
494 | * |
519 | * This function examines the map the player is on, and determines what |
495 | * This function examines the map the player is on, and determines what |
520 | * is visible. 2 is set for walls or objects that blocks view. 1 |
496 | * is visible. 2 is set for walls or objects that blocks view. 1 |
521 | * is for open spaces. map_mark should already have been initialized |
497 | * is for open spaces. map_mark should already have been initialised |
522 | * to zero before this is called. |
498 | * to zero before this is called. |
523 | * strength is an initial strength*2 rectangular area that we automatically |
499 | * strength is an initial strength*2 rectangular area that we automatically |
524 | * see in/penetrate through. |
500 | * see in/penetrate through. |
525 | */ |
501 | */ |
526 | |
|
|
527 | void |
502 | void |
528 | magic_mapping_mark (object *pl, char *map_mark, int strength) |
503 | magic_mapping_mark (object *pl, char *map_mark, int strength) |
529 | { |
504 | { |
530 | int x, y, mflags; |
505 | int x, y, mflags; |
531 | sint16 nx, ny; |
506 | sint16 nx, ny; |
532 | maptile *mp; |
507 | maptile *mp; |
533 | New_Face *f; |
|
|
534 | |
508 | |
535 | for (x = -strength; x < strength; x++) |
509 | for (x = -strength; x < strength; x++) |
536 | { |
510 | { |
537 | for (y = -strength; y < strength; y++) |
511 | for (y = -strength; y < strength; y++) |
538 | { |
512 | { |
539 | mp = pl->map; |
513 | mp = pl->map; |
540 | nx = pl->x + x; |
514 | nx = pl->x + x; |
541 | ny = pl->y + y; |
515 | ny = pl->y + y; |
|
|
516 | |
542 | mflags = get_map_flags (pl->map, &mp, nx, ny, &nx, &ny); |
517 | mflags = get_map_flags (pl->map, &mp, nx, ny, &nx, &ny); |
543 | if (mflags & P_OUT_OF_MAP) |
518 | if (mflags & P_OUT_OF_MAP) |
544 | continue; |
519 | continue; |
545 | else |
520 | |
|
|
521 | int f = GET_MAP_FACE (mp, nx, ny, 0); |
|
|
522 | if (f == blank_face) |
546 | { |
523 | { |
547 | f = GET_MAP_FACE (mp, nx, ny, 0); |
|
|
548 | if (f == blank_face) |
|
|
549 | f = GET_MAP_FACE (mp, nx, ny, 1); |
524 | f = GET_MAP_FACE (mp, nx, ny, 1); |
550 | if (f == blank_face) |
525 | if (f == blank_face) |
551 | f = GET_MAP_FACE (mp, nx, ny, 2); |
526 | f = GET_MAP_FACE (mp, nx, ny, 2); |
552 | } |
527 | } |
553 | |
528 | |
|
|
529 | int magicmap = faces [f].magicmap; |
|
|
530 | |
554 | if (mflags & P_BLOCKSVIEW) |
531 | if (mflags & P_BLOCKSVIEW) |
555 | map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE * (MAGIC_MAP_HALF + y)] = FACE_WALL | (f ? f->magicmap : 0); |
532 | map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE * (MAGIC_MAP_HALF + y)] = FACE_WALL | magicmap; |
556 | else |
533 | else |
557 | { |
534 | { |
558 | map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE * (MAGIC_MAP_HALF + y)] = FACE_FLOOR | (f ? f->magicmap : 0); |
535 | map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE * (MAGIC_MAP_HALF + y)] = FACE_FLOOR | magicmap; |
559 | magic_mapping_mark_recursive (pl, map_mark, x, y); |
536 | magic_mapping_mark_recursive (pl, map_mark, x, y); |
560 | } |
537 | } |
561 | } |
538 | } |
562 | } |
539 | } |
563 | } |
540 | } |
… | |
… | |
568 | * The following function is a lot messier than it really should be, |
545 | * The following function is a lot messier than it really should be, |
569 | * but there is no real easy solution. |
546 | * but there is no real easy solution. |
570 | * |
547 | * |
571 | * Mark Wedel |
548 | * Mark Wedel |
572 | */ |
549 | */ |
573 | |
|
|
574 | void |
550 | void |
575 | draw_magic_map (object *pl) |
551 | draw_magic_map (object *pl) |
576 | { |
552 | { |
577 | char *map_mark = (char *)calloc (MAGIC_MAP_SIZE * MAGIC_MAP_SIZE, 1); |
553 | char *map_mark = (char *)calloc (MAGIC_MAP_SIZE * MAGIC_MAP_SIZE, 1); |
578 | int xmin, xmax, ymin, ymax; |
554 | int xmin, xmax, ymin, ymax; |