|
|
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 | */ |
… | |
… | |
221 | int i; |
219 | int i; |
222 | |
220 | |
223 | for (tmppl = first_player; tmppl != NULL; tmppl = tmppl->next) |
221 | for (tmppl = first_player; tmppl != NULL; tmppl = tmppl->next) |
224 | new_draw_info ((flags & ~NDI_ALL), pri, tmppl->ob, buf); |
222 | new_draw_info ((flags & ~NDI_ALL), pri, tmppl->ob, buf); |
225 | |
223 | |
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; |
224 | return; |
237 | } |
225 | } |
|
|
226 | |
238 | if (!pl || (pl->type == PLAYER && pl->contr == NULL)) |
227 | if (!pl || (pl->type == PLAYER && pl->contr == NULL)) |
239 | { |
228 | { |
240 | /* Write to the socket? */ |
229 | /* Write to the socket? */ |
241 | print_message (0, NULL, buf); |
230 | print_message (0, NULL, buf); |
242 | return; |
231 | return; |
243 | } |
232 | } |
|
|
233 | |
244 | if (pl->type != PLAYER) |
234 | if (pl->type != PLAYER) |
245 | return; |
235 | return; |
|
|
236 | |
246 | if (pri >= pl->contr->listening) |
237 | if (pri >= pl->contr->listening) |
247 | return; |
238 | return; |
248 | |
239 | |
249 | if ((flags & NDI_COLOR_MASK) == NDI_BLACK && !(flags & NDI_UNIQUE)) |
240 | if ((flags & NDI_COLOR_MASK) == NDI_BLACK && !(flags & NDI_UNIQUE)) |
250 | { |
|
|
251 | /* following prints stuff out, as appropriate */ |
241 | /* following prints stuff out, as appropriate */ |
252 | check_output_buffers (pl, buf); |
242 | check_output_buffers (pl, buf); |
253 | } |
|
|
254 | else |
243 | else |
255 | { |
|
|
256 | print_message (flags & NDI_COLOR_MASK, pl, buf); |
244 | print_message (flags & NDI_COLOR_MASK, pl, buf); |
257 | } |
|
|
258 | } |
245 | } |
259 | |
246 | |
260 | /** |
247 | /** |
261 | * Wrapper for new_draw_info printf-like. |
248 | * Wrapper for new_draw_info printf-like. |
262 | * |
249 | * |
… | |
… | |
349 | /** |
336 | /** |
350 | * Writes to everyone on the map *except* op. This is useful for emotions. |
337 | * Writes to everyone on the map *except* op. This is useful for emotions. |
351 | */ |
338 | */ |
352 | |
339 | |
353 | void |
340 | void |
354 | new_info_map_except (int color, maptile *map, object *op, const char *str) |
341 | new_info_map_except (int color, maptile * map, object *op, const char *str) |
355 | { |
342 | { |
356 | player *pl; |
343 | player *pl; |
357 | |
344 | |
358 | for (pl = first_player; pl != NULL; pl = pl->next) |
345 | for (pl = first_player; pl != NULL; pl = pl->next) |
359 | if (pl->ob != NULL && pl->ob->map == map && pl->ob != op) |
346 | if (pl->ob != NULL && pl->ob->map == map && pl->ob != op) |
… | |
… | |
365 | /** |
352 | /** |
366 | * Writes to everyone on the map except op1 and op2 |
353 | * Writes to everyone on the map except op1 and op2 |
367 | */ |
354 | */ |
368 | |
355 | |
369 | void |
356 | void |
370 | new_info_map_except2 (int color, maptile *map, object *op1, object *op2, const char *str) |
357 | new_info_map_except2 (int color, maptile * map, object *op1, object *op2, const char *str) |
371 | { |
358 | { |
372 | player *pl; |
359 | player *pl; |
373 | |
360 | |
374 | for (pl = first_player; pl != NULL; pl = pl->next) |
361 | for (pl = first_player; pl != NULL; pl = pl->next) |
375 | if (pl->ob != NULL && pl->ob->map == map && pl->ob != op1 && pl->ob != op2) |
362 | if (pl->ob != NULL && pl->ob->map == map && pl->ob != op1 && pl->ob != op2) |
… | |
… | |
381 | /** |
368 | /** |
382 | * Writes to everyone on the specified map |
369 | * Writes to everyone on the specified map |
383 | */ |
370 | */ |
384 | |
371 | |
385 | void |
372 | void |
386 | new_info_map (int color, maptile *map, const char *str) |
373 | new_info_map (int color, maptile * map, const char *str) |
387 | { |
374 | { |
388 | player *pl; |
375 | player *pl; |
389 | |
376 | |
390 | for (pl = first_player; pl != NULL; pl = pl->next) |
377 | for (pl = first_player; pl != NULL; pl = pl->next) |
391 | if (pl->ob != NULL && pl->ob->map == map) |
378 | if (pl->ob != NULL && pl->ob->map == map) |
… | |
… | |
411 | void |
398 | void |
412 | rangetostring (object *pl, char *obuf) |
399 | rangetostring (object *pl, char *obuf) |
413 | { |
400 | { |
414 | switch (pl->contr->shoottype) |
401 | switch (pl->contr->shoottype) |
415 | { |
402 | { |
416 | case range_none: |
403 | case range_none: |
417 | strcpy (obuf, "Range: nothing"); |
404 | strcpy (obuf, "Range: nothing"); |
418 | break; |
405 | break; |
419 | |
406 | |
420 | case range_bow: |
407 | case range_bow: |
|
|
408 | { |
|
|
409 | object *op; |
|
|
410 | |
|
|
411 | for (op = pl->inv; op; op = op->below) |
|
|
412 | if (op->type == BOW && QUERY_FLAG (op, FLAG_APPLIED)) |
|
|
413 | break; |
|
|
414 | |
|
|
415 | if (op == NULL) |
|
|
416 | break; |
|
|
417 | |
|
|
418 | sprintf (obuf, "Range: %s (%s)", query_base_name (op, 0), op->race ? (const char *) op->race : "nothing"); |
|
|
419 | } |
|
|
420 | break; |
|
|
421 | |
|
|
422 | case range_magic: |
|
|
423 | if (settings.casting_time == TRUE) |
421 | { |
424 | { |
422 | object *op; |
425 | if (pl->casting_time > -1) |
423 | |
426 | { |
424 | for (op = pl->inv; op; op = op->below) |
427 | if (pl->casting_time == 0) |
425 | if (op->type == BOW && QUERY_FLAG (op, FLAG_APPLIED)) |
428 | sprintf (obuf, "Range: Holding spell (%s)", &pl->spell->name); |
426 | break; |
429 | else |
427 | if (op == NULL) |
430 | sprintf (obuf, "Range: Casting spell (%s)", &pl->spell->name); |
428 | break; |
431 | } |
429 | |
432 | else |
430 | sprintf (obuf, "Range: %s (%s)", query_base_name (op, 0), op->race ? (const char *) op->race : "nothing"); |
433 | sprintf (obuf, "Range: spell (%s)", &pl->contr->ranges[range_magic]->name); |
431 | } |
434 | } |
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 |
435 | else |
448 | sprintf (obuf, "Range: spell (%s)", &pl->contr->ranges[range_magic]->name); |
436 | sprintf (obuf, "Range: spell (%s)", &pl->contr->ranges[range_magic]->name); |
449 | break; |
437 | break; |
450 | |
438 | |
451 | case range_misc: |
439 | case range_misc: |
452 | sprintf (obuf, "Range: %s", pl->contr->ranges[range_misc] ? query_base_name (pl->contr->ranges[range_misc], 0) : "none"); |
440 | sprintf (obuf, "Range: %s", pl->contr->ranges[range_misc] ? query_base_name (pl->contr->ranges[range_misc], 0) : "none"); |
453 | break; |
441 | break; |
454 | |
442 | |
455 | /* range_scroll is only used for controlling golems. If the |
443 | /* range_scroll is only used for controlling golems. If the |
456 | * the player does not have a golem, reset some things. |
444 | * the player does not have a golem, reset some things. |
457 | */ |
445 | */ |
458 | case range_golem: |
446 | case range_golem: |
459 | if (pl->contr->ranges[range_golem] != NULL) |
447 | if (pl->contr->ranges[range_golem] != NULL) |
460 | sprintf (obuf, "Range: golem (%s)", &pl->contr->ranges[range_golem]->name); |
448 | sprintf (obuf, "Range: golem (%s)", &pl->contr->ranges[range_golem]->name); |
461 | else |
449 | else |
462 | { |
450 | { |
463 | pl->contr->shoottype = range_none; |
451 | pl->contr->shoottype = range_none; |
464 | strcpy (obuf, "Range: nothing"); |
452 | strcpy (obuf, "Range: nothing"); |
465 | } |
453 | } |
466 | break; |
454 | break; |
467 | |
455 | |
468 | case range_skill: |
456 | case range_skill: |
469 | sprintf (obuf, "Skill: %s", pl->chosen_skill != NULL ? (const char *) pl->chosen_skill->name : "none"); |
457 | sprintf (obuf, "Skill: %s", pl->chosen_skill != NULL ? (const char *) pl->chosen_skill->name : "none"); |
470 | break; |
458 | break; |
471 | |
459 | |
472 | case range_builder: |
460 | case range_builder: |
473 | sprintf (obuf, "Builder: %s", query_base_name (pl->contr->ranges[range_builder], 0)); |
461 | sprintf (obuf, "Builder: %s", query_base_name (pl->contr->ranges[range_builder], 0)); |
474 | break; |
462 | break; |
475 | |
463 | |
476 | default: |
464 | default: |
477 | strcpy (obuf, "Range: illegal"); |
465 | strcpy (obuf, "Range: illegal"); |
478 | } |
466 | } |
479 | } |
467 | } |
480 | |
468 | |
481 | /** |
469 | /** |
482 | * Sets player title. |
470 | * Sets player title. |
… | |
… | |
686 | int i; |
674 | int i; |
687 | size_t len; |
675 | size_t len; |
688 | char buf[MAX_BUF]; |
676 | char buf[MAX_BUF]; |
689 | |
677 | |
690 | if (With != NULL) |
678 | if (With != NULL) |
691 | { |
|
|
692 | snprintf (buf, MAX_BUF, "%s\t%s\t%d\t%s\t%d\n", Who, What, WhatType, With, WithType); |
679 | snprintf (buf, MAX_BUF, "%s\t%s\t%d\t%s\t%d\n", Who, What, WhatType, With, WithType); |
693 | } |
|
|
694 | else |
680 | else |
695 | { |
|
|
696 | snprintf (buf, MAX_BUF, "%s\t%s\t%d\n", Who, What, WhatType); |
681 | snprintf (buf, MAX_BUF, "%s\t%s\t%d\n", Who, What, WhatType); |
697 | } |
682 | |
698 | len = strlen (buf); |
683 | 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 | } |
684 | } |