|
|
1 | |
1 | /* |
2 | /* |
2 | CrossFire, A Multiplayer game for X-windows |
3 | CrossFire, A Multiplayer game for X-windows |
3 | |
4 | |
4 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | Copyright (C) 1992 Frank Tore Johansen |
6 | Copyright (C) 1992 Frank Tore Johansen |
… | |
… | |
95 | |
96 | |
96 | static void |
97 | static void |
97 | print_message (int colr, const object *pl, const char *tmp) |
98 | print_message (int colr, const object *pl, const char *tmp) |
98 | { |
99 | { |
99 | |
100 | |
100 | if (tmp == (char *) NULL) |
101 | if (!tmp) |
101 | { |
|
|
102 | tmp = "[NULL]"; |
102 | tmp = "[NULL]"; |
103 | } |
|
|
104 | |
103 | |
105 | if (!pl || (pl->type == PLAYER && pl->contr == NULL)) |
104 | if (!pl || (pl->type == PLAYER && pl->contr == NULL)) |
106 | return; |
105 | return; |
107 | |
106 | |
108 | if (pl->type == PLAYER) |
107 | if (pl->type == PLAYER) |
109 | { |
108 | { |
110 | esrv_print_msg (&pl->contr->socket, colr, (char *) tmp); |
109 | esrv_print_msg (&pl->contr->socket, colr, (char *) tmp); |
111 | return; |
110 | return; |
112 | } |
111 | } |
113 | } |
112 | } |
114 | |
|
|
115 | |
113 | |
116 | /** |
114 | /** |
117 | * Prints out the contents of specified buffer structures, |
115 | * Prints out the contents of specified buffer structures, |
118 | * and clears the string. |
116 | * and clears the string. |
119 | */ |
117 | */ |
… | |
… | |
216 | { |
214 | { |
217 | |
215 | |
218 | if (flags & NDI_ALL) |
216 | if (flags & NDI_ALL) |
219 | { |
217 | { |
220 | player *tmppl; |
218 | player *tmppl; |
221 | int i; |
|
|
222 | |
219 | |
223 | for (tmppl = first_player; tmppl != NULL; tmppl = tmppl->next) |
220 | for (tmppl = first_player; tmppl != NULL; tmppl = tmppl->next) |
224 | new_draw_info ((flags & ~NDI_ALL), pri, tmppl->ob, buf); |
221 | new_draw_info ((flags & ~NDI_ALL), pri, tmppl->ob, buf); |
225 | |
222 | |
226 | for (i = 1; i < socket_info.allocated_sockets; i++) |
|
|
227 | { |
|
|
228 | if (init_sockets[i].status == Ns_Old && init_sockets[i].old_mode != Old_Listen && pri < 10) |
|
|
229 | { |
|
|
230 | cs_write_string (&init_sockets[i], buf, strlen (buf)); |
|
|
231 | /* Most messages don't have a newline, so add one */ |
|
|
232 | cs_write_string (&init_sockets[i], "\n", 1); |
|
|
233 | } |
|
|
234 | } |
|
|
235 | |
|
|
236 | return; |
223 | return; |
237 | } |
224 | } |
|
|
225 | |
238 | if (!pl || (pl->type == PLAYER && pl->contr == NULL)) |
226 | if (!pl || (pl->type == PLAYER && pl->contr == NULL)) |
239 | { |
227 | { |
240 | /* Write to the socket? */ |
228 | /* Write to the socket? */ |
241 | print_message (0, NULL, buf); |
229 | print_message (0, NULL, buf); |
242 | return; |
230 | return; |
243 | } |
231 | } |
|
|
232 | |
244 | if (pl->type != PLAYER) |
233 | if (pl->type != PLAYER) |
245 | return; |
234 | return; |
|
|
235 | |
246 | if (pri >= pl->contr->listening) |
236 | if (pri >= pl->contr->listening) |
247 | return; |
237 | return; |
248 | |
238 | |
249 | if ((flags & NDI_COLOR_MASK) == NDI_BLACK && !(flags & NDI_UNIQUE)) |
239 | if ((flags & NDI_COLOR_MASK) == NDI_BLACK && !(flags & NDI_UNIQUE)) |
250 | { |
|
|
251 | /* following prints stuff out, as appropriate */ |
240 | /* following prints stuff out, as appropriate */ |
252 | check_output_buffers (pl, buf); |
241 | check_output_buffers (pl, buf); |
253 | } |
|
|
254 | else |
242 | else |
255 | { |
|
|
256 | print_message (flags & NDI_COLOR_MASK, pl, buf); |
243 | print_message (flags & NDI_COLOR_MASK, pl, buf); |
257 | } |
|
|
258 | } |
244 | } |
259 | |
245 | |
260 | /** |
246 | /** |
261 | * Wrapper for new_draw_info printf-like. |
247 | * Wrapper for new_draw_info printf-like. |
262 | * |
248 | * |
… | |
… | |
349 | /** |
335 | /** |
350 | * Writes to everyone on the map *except* op. This is useful for emotions. |
336 | * Writes to everyone on the map *except* op. This is useful for emotions. |
351 | */ |
337 | */ |
352 | |
338 | |
353 | void |
339 | void |
354 | new_info_map_except (int color, mapstruct *map, object *op, const char *str) |
340 | new_info_map_except (int color, maptile * map, object *op, const char *str) |
355 | { |
341 | { |
356 | player *pl; |
342 | player *pl; |
357 | |
343 | |
358 | for (pl = first_player; pl != NULL; pl = pl->next) |
344 | for (pl = first_player; pl != NULL; pl = pl->next) |
359 | if (pl->ob != NULL && pl->ob->map == map && pl->ob != op) |
345 | if (pl->ob != NULL && pl->ob->map == map && pl->ob != op) |
… | |
… | |
365 | /** |
351 | /** |
366 | * Writes to everyone on the map except op1 and op2 |
352 | * Writes to everyone on the map except op1 and op2 |
367 | */ |
353 | */ |
368 | |
354 | |
369 | void |
355 | void |
370 | new_info_map_except2 (int color, mapstruct *map, object *op1, object *op2, const char *str) |
356 | new_info_map_except2 (int color, maptile * map, object *op1, object *op2, const char *str) |
371 | { |
357 | { |
372 | player *pl; |
358 | player *pl; |
373 | |
359 | |
374 | for (pl = first_player; pl != NULL; pl = pl->next) |
360 | for (pl = first_player; pl != NULL; pl = pl->next) |
375 | if (pl->ob != NULL && pl->ob->map == map && pl->ob != op1 && pl->ob != op2) |
361 | if (pl->ob != NULL && pl->ob->map == map && pl->ob != op1 && pl->ob != op2) |
… | |
… | |
381 | /** |
367 | /** |
382 | * Writes to everyone on the specified map |
368 | * Writes to everyone on the specified map |
383 | */ |
369 | */ |
384 | |
370 | |
385 | void |
371 | void |
386 | new_info_map (int color, mapstruct *map, const char *str) |
372 | new_info_map (int color, maptile * map, const char *str) |
387 | { |
373 | { |
388 | player *pl; |
374 | player *pl; |
389 | |
375 | |
390 | for (pl = first_player; pl != NULL; pl = pl->next) |
376 | for (pl = first_player; pl != NULL; pl = pl->next) |
391 | if (pl->ob != NULL && pl->ob->map == map) |
377 | if (pl->ob != NULL && pl->ob->map == map) |
… | |
… | |
411 | void |
397 | void |
412 | rangetostring (object *pl, char *obuf) |
398 | rangetostring (object *pl, char *obuf) |
413 | { |
399 | { |
414 | switch (pl->contr->shoottype) |
400 | switch (pl->contr->shoottype) |
415 | { |
401 | { |
416 | case range_none: |
402 | case range_none: |
417 | strcpy (obuf, "Range: nothing"); |
403 | strcpy (obuf, "Range: nothing"); |
418 | break; |
404 | break; |
419 | |
405 | |
420 | case range_bow: |
406 | case range_bow: |
|
|
407 | { |
|
|
408 | object *op; |
|
|
409 | |
|
|
410 | for (op = pl->inv; op; op = op->below) |
|
|
411 | if (op->type == BOW && QUERY_FLAG (op, FLAG_APPLIED)) |
|
|
412 | break; |
|
|
413 | |
|
|
414 | if (op == NULL) |
|
|
415 | break; |
|
|
416 | |
|
|
417 | sprintf (obuf, "Range: %s (%s)", query_base_name (op, 0), op->race ? (const char *) op->race : "nothing"); |
|
|
418 | } |
|
|
419 | break; |
|
|
420 | |
|
|
421 | case range_magic: |
|
|
422 | if (settings.casting_time == TRUE) |
421 | { |
423 | { |
422 | object *op; |
424 | if (pl->casting_time > -1) |
423 | |
425 | { |
424 | for (op = pl->inv; op; op = op->below) |
426 | if (pl->casting_time == 0) |
425 | if (op->type == BOW && QUERY_FLAG (op, FLAG_APPLIED)) |
427 | sprintf (obuf, "Range: Holding spell (%s)", &pl->spell->name); |
426 | break; |
428 | else |
427 | if (op == NULL) |
429 | sprintf (obuf, "Range: Casting spell (%s)", &pl->spell->name); |
428 | break; |
430 | } |
429 | |
431 | else |
430 | sprintf (obuf, "Range: %s (%s)", query_base_name (op, 0), op->race ? (const char *) op->race : "nothing"); |
432 | sprintf (obuf, "Range: spell (%s)", &pl->contr->ranges[range_magic]->name); |
431 | } |
433 | } |
432 | break; |
|
|
433 | |
|
|
434 | case range_magic: |
|
|
435 | if (settings.casting_time == TRUE) |
|
|
436 | { |
|
|
437 | if (pl->casting_time > -1) |
|
|
438 | { |
|
|
439 | if (pl->casting_time == 0) |
|
|
440 | sprintf (obuf, "Range: Holding spell (%s)", (const char *) pl->spell->name); |
|
|
441 | else |
|
|
442 | sprintf (obuf, "Range: Casting spell (%s)", (const char *) pl->spell->name); |
|
|
443 | } |
|
|
444 | else |
|
|
445 | sprintf (obuf, "Range: spell (%s)", &pl->contr->ranges[range_magic]->name); |
|
|
446 | } |
|
|
447 | else |
434 | else |
448 | sprintf (obuf, "Range: spell (%s)", &pl->contr->ranges[range_magic]->name); |
435 | sprintf (obuf, "Range: spell (%s)", &pl->contr->ranges[range_magic]->name); |
449 | break; |
436 | break; |
450 | |
437 | |
451 | case range_misc: |
438 | case range_misc: |
452 | sprintf (obuf, "Range: %s", pl->contr->ranges[range_misc] ? query_base_name (pl->contr->ranges[range_misc], 0) : "none"); |
439 | sprintf (obuf, "Range: %s", pl->contr->ranges[range_misc] ? query_base_name (pl->contr->ranges[range_misc], 0) : "none"); |
453 | break; |
440 | break; |
454 | |
441 | |
455 | /* range_scroll is only used for controlling golems. If the |
442 | /* range_scroll is only used for controlling golems. If the |
456 | * the player does not have a golem, reset some things. |
443 | * the player does not have a golem, reset some things. |
457 | */ |
444 | */ |
458 | case range_golem: |
445 | case range_golem: |
459 | if (pl->contr->ranges[range_golem] != NULL) |
446 | if (pl->contr->ranges[range_golem] != NULL) |
460 | sprintf (obuf, "Range: golem (%s)", &pl->contr->ranges[range_golem]->name); |
447 | sprintf (obuf, "Range: golem (%s)", &pl->contr->ranges[range_golem]->name); |
461 | else |
448 | else |
462 | { |
449 | { |
463 | pl->contr->shoottype = range_none; |
450 | pl->contr->shoottype = range_none; |
464 | strcpy (obuf, "Range: nothing"); |
451 | strcpy (obuf, "Range: nothing"); |
465 | } |
452 | } |
466 | break; |
453 | break; |
467 | |
454 | |
468 | case range_skill: |
455 | case range_skill: |
469 | sprintf (obuf, "Skill: %s", pl->chosen_skill != NULL ? (const char *) pl->chosen_skill->name : "none"); |
456 | sprintf (obuf, "Skill: %s", pl->chosen_skill != NULL ? (const char *) pl->chosen_skill->name : "none"); |
470 | break; |
457 | break; |
471 | |
458 | |
472 | case range_builder: |
459 | case range_builder: |
473 | sprintf (obuf, "Builder: %s", query_base_name (pl->contr->ranges[range_builder], 0)); |
460 | sprintf (obuf, "Builder: %s", query_base_name (pl->contr->ranges[range_builder], 0)); |
474 | break; |
461 | break; |
475 | |
462 | |
476 | default: |
463 | default: |
477 | strcpy (obuf, "Range: illegal"); |
464 | strcpy (obuf, "Range: illegal"); |
478 | } |
465 | } |
479 | } |
466 | } |
480 | |
467 | |
481 | /** |
468 | /** |
482 | * Sets player title. |
469 | * Sets player title. |
… | |
… | |
506 | static void |
493 | static void |
507 | magic_mapping_mark_recursive (object *pl, char *map_mark, int px, int py) |
494 | magic_mapping_mark_recursive (object *pl, char *map_mark, int px, int py) |
508 | { |
495 | { |
509 | int x, y, dx, dy, mflags; |
496 | int x, y, dx, dy, mflags; |
510 | sint16 nx, ny; |
497 | sint16 nx, ny; |
511 | mapstruct *mp; |
498 | maptile *mp; |
512 | New_Face *f; |
499 | New_Face *f; |
513 | |
500 | |
514 | for (dx = -1; dx <= 1; dx++) |
501 | for (dx = -1; dx <= 1; dx++) |
515 | { |
502 | { |
516 | for (dy = -1; dy <= 1; dy++) |
503 | for (dy = -1; dy <= 1; dy++) |
… | |
… | |
572 | void |
559 | void |
573 | magic_mapping_mark (object *pl, char *map_mark, int strength) |
560 | magic_mapping_mark (object *pl, char *map_mark, int strength) |
574 | { |
561 | { |
575 | int x, y, mflags; |
562 | int x, y, mflags; |
576 | sint16 nx, ny; |
563 | sint16 nx, ny; |
577 | mapstruct *mp; |
564 | maptile *mp; |
578 | New_Face *f; |
565 | New_Face *f; |
579 | |
566 | |
580 | for (x = -strength; x < strength; x++) |
567 | for (x = -strength; x < strength; x++) |
581 | { |
568 | { |
582 | for (y = -strength; y < strength; y++) |
569 | for (y = -strength; y < strength; y++) |
… | |
… | |
618 | */ |
605 | */ |
619 | |
606 | |
620 | void |
607 | void |
621 | draw_magic_map (object *pl) |
608 | draw_magic_map (object *pl) |
622 | { |
609 | { |
623 | int x, y; |
|
|
624 | char *map_mark = (char *) calloc (MAGIC_MAP_SIZE * MAGIC_MAP_SIZE, 1); |
610 | char *map_mark = (char *)calloc (MAGIC_MAP_SIZE * MAGIC_MAP_SIZE, 1); |
625 | int xmin, xmax, ymin, ymax; |
611 | int xmin, xmax, ymin, ymax; |
626 | SockList sl; |
|
|
627 | |
612 | |
628 | if (pl->type != PLAYER) |
613 | if (pl->type != PLAYER) |
629 | { |
614 | { |
630 | LOG (llevError, "Non player object called draw_map.\n"); |
615 | LOG (llevError, "Non player object called draw_map.\n"); |
631 | return; |
616 | return; |
… | |
… | |
641 | */ |
626 | */ |
642 | xmin = MAGIC_MAP_SIZE; |
627 | xmin = MAGIC_MAP_SIZE; |
643 | ymin = MAGIC_MAP_SIZE; |
628 | ymin = MAGIC_MAP_SIZE; |
644 | xmax = 0; |
629 | xmax = 0; |
645 | ymax = 0; |
630 | ymax = 0; |
|
|
631 | |
646 | for (x = 0; x < MAGIC_MAP_SIZE; x++) |
632 | for (int x = 0; x < MAGIC_MAP_SIZE; x++) |
647 | { |
|
|
648 | for (y = 0; y < MAGIC_MAP_SIZE; y++) |
633 | for (int y = 0; y < MAGIC_MAP_SIZE; y++) |
649 | { |
|
|
650 | if (map_mark[x + MAP_WIDTH (pl->map) * y] | FACE_FLOOR) |
634 | if (map_mark[x + MAP_WIDTH (pl->map) * y] | FACE_FLOOR) |
651 | { |
635 | { |
652 | xmin = x < xmin ? x : xmin; |
636 | xmin = x < xmin ? x : xmin; |
653 | xmax = x > xmax ? x : xmax; |
637 | xmax = x > xmax ? x : xmax; |
654 | ymin = y < ymin ? y : ymin; |
638 | ymin = y < ymin ? y : ymin; |
655 | ymax = y > ymax ? y : ymax; |
639 | ymax = y > ymax ? y : ymax; |
656 | } |
640 | } |
657 | } |
|
|
658 | } |
|
|
659 | |
641 | |
660 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
642 | SockList sl (MAXSOCKBUF); |
661 | snprintf ((char *) sl.buf, MAXSOCKBUF, "magicmap %d %d %d %d ", (xmax - xmin + 1), (ymax - ymin + 1), |
643 | sl.printf ("magicmap %d %d %d %d ", (xmax - xmin + 1), (ymax - ymin + 1), |
662 | MAGIC_MAP_HALF - xmin, MAGIC_MAP_HALF - ymin); |
644 | MAGIC_MAP_HALF - xmin, MAGIC_MAP_HALF - ymin); |
663 | sl.len = strlen ((char *) sl.buf); |
|
|
664 | |
645 | |
665 | for (y = ymin; y <= ymax; y++) |
646 | for (int y = ymin; y <= ymax; y++) |
666 | { |
|
|
667 | for (x = xmin; x <= xmax; x++) |
647 | for (int x = xmin; x <= xmax; x++) |
668 | { |
|
|
669 | sl.buf[sl.len++] = map_mark[x + MAGIC_MAP_SIZE * y] & ~FACE_FLOOR; |
648 | sl << uint8 (map_mark[x + MAGIC_MAP_SIZE * y] & ~FACE_FLOOR); |
670 | } /* x loop */ |
|
|
671 | } /* y loop */ |
|
|
672 | |
649 | |
673 | Send_With_Handling (&pl->contr->socket, &sl); |
650 | Send_With_Handling (&pl->contr->socket, &sl); |
674 | free (sl.buf); |
651 | |
|
|
652 | sl.free (); |
|
|
653 | |
675 | free (map_mark); |
654 | free (map_mark); |
676 | } |
655 | } |
677 | |
656 | |
678 | |
657 | |
679 | /** |
658 | /** |
… | |
… | |
681 | */ |
660 | */ |
682 | |
661 | |
683 | void |
662 | void |
684 | Log_Kill (const char *Who, const char *What, int WhatType, const char *With, int WithType) |
663 | Log_Kill (const char *Who, const char *What, int WhatType, const char *With, int WithType) |
685 | { |
664 | { |
686 | int i; |
|
|
687 | size_t len; |
665 | size_t len; |
688 | char buf[MAX_BUF]; |
666 | char buf[MAX_BUF]; |
689 | |
667 | |
690 | if (With != NULL) |
668 | if (With != NULL) |
691 | { |
|
|
692 | snprintf (buf, MAX_BUF, "%s\t%s\t%d\t%s\t%d\n", Who, What, WhatType, With, WithType); |
669 | snprintf (buf, MAX_BUF, "%s\t%s\t%d\t%s\t%d\n", Who, What, WhatType, With, WithType); |
693 | } |
|
|
694 | else |
670 | else |
695 | { |
|
|
696 | snprintf (buf, MAX_BUF, "%s\t%s\t%d\n", Who, What, WhatType); |
671 | snprintf (buf, MAX_BUF, "%s\t%s\t%d\n", Who, What, WhatType); |
697 | } |
672 | |
698 | len = strlen (buf); |
673 | len = strlen (buf); |
699 | for (i = 1; i < socket_info.allocated_sockets; i++) |
|
|
700 | { |
|
|
701 | if (init_sockets[i].old_mode == Old_Listen) |
|
|
702 | { |
|
|
703 | cs_write_string (&init_sockets[i], buf, len); |
|
|
704 | } |
|
|
705 | } |
|
|
706 | } |
674 | } |