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 | * |
… | |
… | |
185 | void |
185 | void |
186 | new_draw_info (int flags, int pri, const object *pl, const char *buf) |
186 | new_draw_info (int flags, int pri, const object *pl, const char *buf) |
187 | { |
187 | { |
188 | if (flags & NDI_ALL) |
188 | if (flags & NDI_ALL) |
189 | { |
189 | { |
190 | player *tmppl; |
|
|
191 | |
|
|
192 | for_all_players (pl) |
190 | for_all_players (pl) |
193 | new_draw_info ((flags & ~NDI_ALL), pri, tmppl->ob, buf); |
191 | new_draw_info (flags & ~NDI_ALL, pri, pl->ob, buf); |
194 | |
192 | |
195 | return; |
193 | return; |
196 | } |
194 | } |
197 | |
195 | |
198 | if (!pl || (pl->type == PLAYER && pl->contr == NULL)) |
196 | if (!pl || pl->type != PLAYER || !pl->contr || !pl->contr->ns) |
199 | { |
|
|
200 | /* Write to the socket? */ |
|
|
201 | print_message (0, NULL, buf); |
|
|
202 | return; |
|
|
203 | } |
|
|
204 | |
|
|
205 | if (pl->type != PLAYER) |
|
|
206 | return; |
197 | return; |
207 | |
198 | |
208 | if (pri >= pl->contr->listening) |
199 | if (pri >= pl->contr->listening) |
209 | return; |
200 | return; |
210 | |
201 | |
211 | if ((flags & NDI_COLOR_MASK) == NDI_BLACK && !(flags & NDI_UNIQUE)) |
202 | if ((flags & NDI_COLOR_MASK) == NDI_BLACK && !(flags & NDI_UNIQUE)) |
212 | /* following prints stuff out, as appropriate */ |
|
|
213 | check_output_buffers (pl, buf); |
203 | check_output_buffers (pl, buf); |
214 | else |
204 | else |
215 | print_message (flags & NDI_COLOR_MASK, pl, buf); |
205 | print_message (flags & NDI_COLOR_MASK, pl, buf); |
216 | } |
206 | } |
217 | |
207 | |
… | |
… | |
227 | 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, ...) |
228 | { |
218 | { |
229 | char buf[HUGE_BUF]; |
219 | char buf[HUGE_BUF]; |
230 | |
220 | |
231 | va_list ap; |
221 | va_list ap; |
232 | |
|
|
233 | va_start (ap, format); |
222 | va_start (ap, format); |
234 | |
|
|
235 | vsnprintf (buf, HUGE_BUF, format, ap); |
223 | vsnprintf (buf, HUGE_BUF, format, ap); |
236 | |
|
|
237 | va_end (ap); |
224 | va_end (ap); |
238 | |
225 | |
239 | new_draw_info (flags, pri, pl, buf); |
226 | new_draw_info (flags, pri, pl, buf); |
240 | } |
227 | } |
241 | |
228 | |
… | |
… | |
268 | } |
255 | } |
269 | |
256 | |
270 | void |
257 | void |
271 | 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, ...) |
272 | { |
259 | { |
273 | |
|
|
274 | char buf[HUGE_BUF]; |
260 | char buf[HUGE_BUF]; |
275 | |
261 | |
276 | if (!pl || (pl->type != PLAYER) || (pl->contr == NULL)) |
262 | if (!pl || (pl->type != PLAYER) || (pl->contr == NULL)) |
277 | return; |
263 | return; |
278 | |
264 | |
… | |
… | |
307 | */ |
293 | */ |
308 | |
294 | |
309 | void |
295 | void |
310 | 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) |
311 | { |
297 | { |
312 | player *pl; |
|
|
313 | |
|
|
314 | for_all_players (pl) |
298 | for_all_players (pl) |
315 | if (pl->ob != NULL && pl->ob->map == map && pl->ob != op) |
299 | if (pl->ob != NULL && pl->ob->map == map && pl->ob != op) |
316 | { |
|
|
317 | new_draw_info (color, 0, pl->ob, str); |
300 | new_draw_info (color, 0, pl->ob, str); |
318 | } |
|
|
319 | } |
301 | } |
320 | |
302 | |
321 | /** |
303 | /** |
322 | * Writes to everyone on the map except op1 and op2 |
304 | * Writes to everyone on the map except op1 and op2 |
323 | */ |
305 | */ |
324 | |
306 | |
325 | void |
307 | void |
326 | 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) |
327 | { |
309 | { |
328 | player *pl; |
|
|
329 | |
|
|
330 | for_all_players (pl) |
310 | for_all_players (pl) |
331 | 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) |
332 | { |
|
|
333 | new_draw_info (color, 0, pl->ob, str); |
312 | new_draw_info (color, 0, pl->ob, str); |
334 | } |
|
|
335 | } |
313 | } |
336 | |
314 | |
337 | /** |
315 | /** |
338 | * Writes to everyone on the specified map |
316 | * Writes to everyone on the specified map |
339 | */ |
317 | */ |
340 | |
318 | |
341 | void |
319 | void |
342 | new_info_map (int color, maptile * map, const char *str) |
320 | new_info_map (int color, maptile * map, const char *str) |
343 | { |
321 | { |
344 | player *pl; |
|
|
345 | |
|
|
346 | for_all_players (pl) |
322 | for_all_players (pl) |
347 | if (pl->ob != NULL && pl->ob->map == map) |
323 | if (pl->ob != NULL && pl->ob->map == map) |
348 | { |
|
|
349 | new_draw_info (color, 0, pl->ob, str); |
324 | new_draw_info (color, 0, pl->ob, str); |
350 | } |
|
|
351 | } |
325 | } |
352 | |
|
|
353 | |
326 | |
354 | /** |
327 | /** |
355 | * This does nothing now. However, in theory, we should probably send |
328 | * This does nothing now. However, in theory, we should probably send |
356 | * 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 |
357 | * to handle this |
330 | * to handle this |
… | |
… | |
411 | |
384 | |
412 | /* range_scroll is only used for controlling golems. If the |
385 | /* range_scroll is only used for controlling golems. If the |
413 | * the player does not have a golem, reset some things. |
386 | * the player does not have a golem, reset some things. |
414 | */ |
387 | */ |
415 | case range_golem: |
388 | case range_golem: |
416 | if (pl->contr->ranges[range_golem] != NULL) |
389 | if (object *golem = pl->contr->ranges[range_golem]) |
417 | sprintf (obuf, "Range: golem (%s)", &pl->contr->ranges[range_golem]->name); |
390 | sprintf (obuf, "Range: golem (%s)", &golem->name); |
418 | else |
391 | else |
419 | { |
392 | { |
420 | pl->contr->shoottype = range_none; |
393 | pl->contr->shoottype = range_none; |
421 | strcpy (obuf, "Range: nothing"); |
394 | strcpy (obuf, "Range: nothing"); |
422 | } |
395 | } |
… | |
… | |
446 | 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); |
447 | else |
420 | else |
448 | 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); |
449 | } |
422 | } |
450 | |
423 | |
|
|
424 | // formerly a macro, used only by magic map, so optimised it out |
|
|
425 | static inline faceidx |
|
|
426 | GET_MAP_FACE (maptile *m, int x, int y, int layer) |
|
|
427 | { |
|
|
428 | if (object *op = GET_MAP_FACE_OBJ (m, x, y, layer)) |
|
|
429 | return op->face; |
|
|
430 | else |
|
|
431 | return 0; |
|
|
432 | } |
451 | |
433 | |
452 | /** |
434 | /** |
453 | * Helper for magic map creation. |
435 | * Helper for magic map creation. |
454 | * |
436 | * |
455 | * Takes a player, the map_mark array and an x and y starting position. |
437 | * Takes a player, the map_mark array and an x and y starting position. |
… | |
… | |
464 | magic_mapping_mark_recursive (object *pl, char *map_mark, int px, int py) |
446 | magic_mapping_mark_recursive (object *pl, char *map_mark, int px, int py) |
465 | { |
447 | { |
466 | int x, y, dx, dy, mflags; |
448 | int x, y, dx, dy, mflags; |
467 | sint16 nx, ny; |
449 | sint16 nx, ny; |
468 | maptile *mp; |
450 | maptile *mp; |
469 | New_Face *f; |
|
|
470 | |
451 | |
471 | for (dx = -1; dx <= 1; dx++) |
452 | for (dx = -1; dx <= 1; dx++) |
472 | { |
453 | { |
473 | for (dy = -1; dy <= 1; dy++) |
454 | for (dy = -1; dy <= 1; dy++) |
474 | { |
455 | { |
… | |
… | |
486 | if (mflags & P_OUT_OF_MAP) |
467 | if (mflags & P_OUT_OF_MAP) |
487 | continue; |
468 | continue; |
488 | |
469 | |
489 | if (map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE * (MAGIC_MAP_HALF + y)] == 0) |
470 | if (map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE * (MAGIC_MAP_HALF + y)] == 0) |
490 | { |
471 | { |
491 | f = GET_MAP_FACE (mp, nx, ny, 0); |
472 | int f = GET_MAP_FACE (mp, nx, ny, 0); |
492 | if (f == blank_face) |
473 | if (f == blank_face) |
|
|
474 | { |
493 | f = GET_MAP_FACE (mp, nx, ny, 1); |
475 | f = GET_MAP_FACE (mp, nx, ny, 1); |
494 | if (f == blank_face) |
476 | if (f == blank_face) |
495 | f = GET_MAP_FACE (mp, nx, ny, 2); |
477 | f = GET_MAP_FACE (mp, nx, ny, 2); |
|
|
478 | } |
|
|
479 | |
|
|
480 | int magicmap = faces [f].magicmap; |
496 | |
481 | |
497 | /* Should probably have P_NO_MAGIC here also, but then shops don't |
482 | /* Should probably have P_NO_MAGIC here also, but then shops don't |
498 | * work. |
483 | * work. |
499 | */ |
484 | */ |
500 | if (mflags & P_BLOCKSVIEW) |
485 | if (mflags & P_BLOCKSVIEW) |
501 | map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE * (MAGIC_MAP_HALF + y)] = FACE_WALL | (f ? f->magicmap : 0); |
486 | map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE * (MAGIC_MAP_HALF + y)] = FACE_WALL | magicmap; |
502 | else |
487 | else |
503 | { |
488 | { |
504 | map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE * (MAGIC_MAP_HALF + y)] = FACE_FLOOR | (f ? f->magicmap : 0); |
489 | map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE * (MAGIC_MAP_HALF + y)] = FACE_FLOOR | magicmap; |
505 | magic_mapping_mark_recursive (pl, map_mark, x, y); |
490 | magic_mapping_mark_recursive (pl, map_mark, x, y); |
506 | } |
491 | } |
507 | } |
492 | } |
508 | } |
493 | } |
509 | } |
494 | } |
510 | } |
495 | } |
511 | |
|
|
512 | |
496 | |
513 | /** |
497 | /** |
514 | * Creates magic map for player. |
498 | * Creates magic map for player. |
515 | * |
499 | * |
516 | * Note: For improved magic mapping display, the space that blocks |
500 | * Note: For improved magic mapping display, the space that blocks |
… | |
… | |
518 | * being nonzero have been changed to check for 1. Also, since |
502 | * being nonzero have been changed to check for 1. Also, since |
519 | * map_mark is a char value, putting 2 in should cause no problems. |
503 | * map_mark is a char value, putting 2 in should cause no problems. |
520 | * |
504 | * |
521 | * This function examines the map the player is on, and determines what |
505 | * This function examines the map the player is on, and determines what |
522 | * is visible. 2 is set for walls or objects that blocks view. 1 |
506 | * is visible. 2 is set for walls or objects that blocks view. 1 |
523 | * is for open spaces. map_mark should already have been initialized |
507 | * is for open spaces. map_mark should already have been initialised |
524 | * to zero before this is called. |
508 | * to zero before this is called. |
525 | * strength is an initial strength*2 rectangular area that we automatically |
509 | * strength is an initial strength*2 rectangular area that we automatically |
526 | * see in/penetrate through. |
510 | * see in/penetrate through. |
527 | */ |
511 | */ |
528 | |
|
|
529 | void |
512 | void |
530 | magic_mapping_mark (object *pl, char *map_mark, int strength) |
513 | magic_mapping_mark (object *pl, char *map_mark, int strength) |
531 | { |
514 | { |
532 | int x, y, mflags; |
515 | int x, y, mflags; |
533 | sint16 nx, ny; |
516 | sint16 nx, ny; |
534 | maptile *mp; |
517 | maptile *mp; |
535 | New_Face *f; |
|
|
536 | |
518 | |
537 | for (x = -strength; x < strength; x++) |
519 | for (x = -strength; x < strength; x++) |
538 | { |
520 | { |
539 | for (y = -strength; y < strength; y++) |
521 | for (y = -strength; y < strength; y++) |
540 | { |
522 | { |
541 | mp = pl->map; |
523 | mp = pl->map; |
542 | nx = pl->x + x; |
524 | nx = pl->x + x; |
543 | ny = pl->y + y; |
525 | ny = pl->y + y; |
|
|
526 | |
544 | mflags = get_map_flags (pl->map, &mp, nx, ny, &nx, &ny); |
527 | mflags = get_map_flags (pl->map, &mp, nx, ny, &nx, &ny); |
545 | if (mflags & P_OUT_OF_MAP) |
528 | if (mflags & P_OUT_OF_MAP) |
546 | continue; |
529 | continue; |
547 | else |
530 | |
|
|
531 | int f = GET_MAP_FACE (mp, nx, ny, 0); |
|
|
532 | if (f == blank_face) |
548 | { |
533 | { |
549 | f = GET_MAP_FACE (mp, nx, ny, 0); |
|
|
550 | if (f == blank_face) |
|
|
551 | f = GET_MAP_FACE (mp, nx, ny, 1); |
534 | f = GET_MAP_FACE (mp, nx, ny, 1); |
552 | if (f == blank_face) |
535 | if (f == blank_face) |
553 | f = GET_MAP_FACE (mp, nx, ny, 2); |
536 | f = GET_MAP_FACE (mp, nx, ny, 2); |
554 | } |
537 | } |
555 | |
538 | |
|
|
539 | int magicmap = faces [f].magicmap; |
|
|
540 | |
556 | if (mflags & P_BLOCKSVIEW) |
541 | if (mflags & P_BLOCKSVIEW) |
557 | 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 | magicmap; |
558 | else |
543 | else |
559 | { |
544 | { |
560 | map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE * (MAGIC_MAP_HALF + y)] = FACE_FLOOR | (f ? f->magicmap : 0); |
545 | map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE * (MAGIC_MAP_HALF + y)] = FACE_FLOOR | magicmap; |
561 | magic_mapping_mark_recursive (pl, map_mark, x, y); |
546 | magic_mapping_mark_recursive (pl, map_mark, x, y); |
562 | } |
547 | } |
563 | } |
548 | } |
564 | } |
549 | } |
565 | } |
550 | } |
… | |
… | |
570 | * The following function is a lot messier than it really should be, |
555 | * The following function is a lot messier than it really should be, |
571 | * but there is no real easy solution. |
556 | * but there is no real easy solution. |
572 | * |
557 | * |
573 | * Mark Wedel |
558 | * Mark Wedel |
574 | */ |
559 | */ |
575 | |
|
|
576 | void |
560 | void |
577 | draw_magic_map (object *pl) |
561 | draw_magic_map (object *pl) |
578 | { |
562 | { |
579 | char *map_mark = (char *)calloc (MAGIC_MAP_SIZE * MAGIC_MAP_SIZE, 1); |
563 | char *map_mark = (char *)calloc (MAGIC_MAP_SIZE * MAGIC_MAP_SIZE, 1); |
580 | int xmin, xmax, ymin, ymax; |
564 | int xmin, xmax, ymin, ymax; |