1 | |
|
|
2 | /* |
|
|
3 | * static char *rcsid_item_c = |
|
|
4 | * "$Id: item.C,v 1.5 2006/09/10 13:43:33 root Exp $"; |
|
|
5 | */ |
|
|
6 | |
|
|
7 | /* |
1 | /* |
8 | CrossFire, A Multiplayer game for X-windows |
2 | CrossFire, A Multiplayer game for X-windows |
9 | |
3 | |
10 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
4 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
11 | Copyright (C) 1992 Frank Tore Johansen |
5 | Copyright (C) 1992 Frank Tore Johansen |
… | |
… | |
22 | |
16 | |
23 | You should have received a copy of the GNU General Public License |
17 | You should have received a copy of the GNU General Public License |
24 | along with this program; if not, write to the Free Software |
18 | along with this program; if not, write to the Free Software |
25 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
26 | |
20 | |
27 | The author can be reached via e-mail to crossfire-devel@real-time.com |
21 | The author can be reached via e-mail to <crossfire@schmorp.de> |
28 | */ |
22 | */ |
29 | |
23 | |
30 | /** |
24 | /** |
31 | * \file |
25 | * \file |
32 | * Client/server logic. |
26 | * Client/server logic. |
… | |
… | |
401 | /* we remove the check for op->env, because in theory, the object |
395 | /* we remove the check for op->env, because in theory, the object |
402 | * is hopefully in the same place, so the client should preserve |
396 | * is hopefully in the same place, so the client should preserve |
403 | * order. |
397 | * order. |
404 | */ |
398 | */ |
405 | } |
399 | } |
|
|
400 | |
406 | if (!QUERY_FLAG (op, FLAG_CLIENT_SENT)) |
401 | if (!QUERY_FLAG (op, FLAG_CLIENT_SENT)) |
407 | { |
402 | { |
408 | /* FLAG_CLIENT_SENT is debug only. We are using it to see where |
403 | /* FLAG_CLIENT_SENT is debug only. We are using it to see where |
409 | * this is happening - we can set a breakpoint here in the debugger |
404 | * this is happening - we can set a breakpoint here in the debugger |
410 | * and track back the call. |
405 | * and track back the call. |
411 | */ |
406 | */ |
412 | LOG (llevDebug, "We have not sent item %s (%d)\n", &op->name, op->count); |
407 | LOG (llevDebug, "We have not sent item %s (%d)\n", &op->name, op->count); |
413 | } |
408 | } |
|
|
409 | |
414 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
410 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
415 | |
411 | |
416 | strcpy ((char *) sl.buf, "upditem "); |
412 | strcpy ((char *) sl.buf, "upditem "); |
417 | sl.len = strlen ((char *) sl.buf); |
413 | sl.len = strlen ((char *) sl.buf); |
418 | |
414 | |
… | |
… | |
444 | { |
440 | { |
445 | if (!(pl->contr->socket.faces_sent[op->face->number] & NS_FACESENT_FACE)) |
441 | if (!(pl->contr->socket.faces_sent[op->face->number] & NS_FACESENT_FACE)) |
446 | esrv_send_face (&pl->contr->socket, op->face->number, 0); |
442 | esrv_send_face (&pl->contr->socket, op->face->number, 0); |
447 | SockList_AddInt (&sl, op->face->number); |
443 | SockList_AddInt (&sl, op->face->number); |
448 | } |
444 | } |
|
|
445 | |
449 | if (flags & UPD_NAME) |
446 | if (flags & UPD_NAME) |
450 | { |
447 | { |
451 | int len; |
448 | int len; |
452 | const char *item_p; |
449 | const char *item_p; |
453 | char item_n[MAX_BUF]; |
450 | char item_n[MAX_BUF]; |
… | |
… | |
472 | len += strlen (item_n + 1 + len) + 1; |
469 | len += strlen (item_n + 1 + len) + 1; |
473 | SockList_AddChar (&sl, (char) len); |
470 | SockList_AddChar (&sl, (char) len); |
474 | memcpy (sl.buf + sl.len, item_n, len); |
471 | memcpy (sl.buf + sl.len, item_n, len); |
475 | sl.len += len; |
472 | sl.len += len; |
476 | } |
473 | } |
|
|
474 | |
477 | if (flags & UPD_ANIM) |
475 | if (flags & UPD_ANIM) |
478 | SockList_AddShort (&sl, op->animation_id); |
476 | SockList_AddShort (&sl, op->animation_id); |
479 | |
477 | |
480 | if (flags & UPD_ANIMSPEED) |
478 | if (flags & UPD_ANIMSPEED) |
481 | { |
479 | { |
… | |
… | |
611 | |
609 | |
612 | /** Client wants to examine some object. So lets do so. */ |
610 | /** Client wants to examine some object. So lets do so. */ |
613 | void |
611 | void |
614 | ExamineCmd (char *buf, int len, player *pl) |
612 | ExamineCmd (char *buf, int len, player *pl) |
615 | { |
613 | { |
616 | long tag = atoi (buf); |
614 | tag_t tag = atoi (buf); |
|
|
615 | |
|
|
616 | /* If the high bit is set, player examined a pseudo object. */ |
|
|
617 | if (tag & 0x80000000) |
|
|
618 | return; |
|
|
619 | |
617 | object *op = esrv_get_ob_from_count (pl->ob, tag); |
620 | object *op = esrv_get_ob_from_count (pl->ob, tag); |
618 | |
621 | |
619 | if (!op) |
622 | if (!op) |
620 | { |
623 | { |
621 | LOG (llevDebug, "Player '%s' tried to examine the unknown object (%ld)\n", &pl->ob->name, tag); |
624 | LOG (llevDebug, "Player '%s' tried to examine the unknown object (%ld)\n", &pl->ob->name, tag); |
622 | return; |
625 | return; |
623 | } |
626 | } |
|
|
627 | |
624 | examine (pl->ob, op); |
628 | examine (pl->ob, op); |
625 | } |
629 | } |
626 | |
630 | |
627 | /** Client wants to apply some object. Lets do so. */ |
631 | /** Client wants to apply some object. Lets do so. */ |
628 | void |
632 | void |
629 | ApplyCmd (char *buf, int len, player *pl) |
633 | ApplyCmd (char *buf, int len, player *pl) |
630 | { |
634 | { |
631 | uint32 tag = atoi (buf); |
635 | tag_t tag = atoi (buf); |
632 | object *op = esrv_get_ob_from_count (pl->ob, tag); |
|
|
633 | |
636 | |
634 | /* sort of a hack, but if the player saves and the player then manually |
637 | /* sort of a hack, but if the player saves and the player then manually |
635 | * applies a savebed (or otherwise tries to do stuff), we run into trouble. |
638 | * applies a savebed (or otherwise tries to do stuff), we run into trouble. |
636 | */ |
639 | */ |
637 | if (QUERY_FLAG (pl->ob, FLAG_REMOVED)) |
640 | if (QUERY_FLAG (pl->ob, FLAG_REMOVED)) |
… | |
… | |
643 | pl->socket.look_position = tag & 0x7fffffff; |
646 | pl->socket.look_position = tag & 0x7fffffff; |
644 | pl->socket.update_look = 1; |
647 | pl->socket.update_look = 1; |
645 | return; |
648 | return; |
646 | } |
649 | } |
647 | |
650 | |
|
|
651 | object *op = esrv_get_ob_from_count (pl->ob, tag); |
|
|
652 | |
648 | if (!op) |
653 | if (!op) |
649 | { |
654 | { |
650 | LOG (llevDebug, "Player '%s' tried to apply the unknown object (%d)\n", &pl->ob->name, tag); |
655 | LOG (llevDebug, "Player '%s' tried to apply the unknown object (%d)\n", &pl->ob->name, tag); |
651 | return; |
656 | return; |
652 | } |
657 | } |
|
|
658 | |
653 | player_apply (pl->ob, op, 0, 0); |
659 | player_apply (pl->ob, op, 0, 0); |
654 | } |
660 | } |
655 | |
661 | |
656 | /** Client wants to apply some object. Lets do so. */ |
662 | /** Client wants to apply some object. Lets do so. */ |
657 | void |
663 | void |
… | |
… | |
683 | int tag; |
689 | int tag; |
684 | object *op; |
690 | object *op; |
685 | |
691 | |
686 | tag = GetInt_String (data); |
692 | tag = GetInt_String (data); |
687 | op = esrv_get_ob_from_count (pl->ob, tag); |
693 | op = esrv_get_ob_from_count (pl->ob, tag); |
|
|
694 | |
688 | if (!op) |
695 | if (!op) |
689 | { |
696 | { |
690 | new_draw_info (NDI_UNIQUE, 0, pl->ob, "Could not find object to mark"); |
697 | new_draw_info (NDI_UNIQUE, 0, pl->ob, "Could not find object to mark"); |
691 | return; |
698 | return; |
692 | } |
699 | } |
|
|
700 | |
693 | pl->mark = op; |
701 | pl->mark = op; |
694 | pl->mark_count = op->count; |
|
|
695 | new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "Marked item %s", query_name (op)); |
702 | new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "Marked item %s", query_name (op)); |
696 | } |
703 | } |
697 | |
704 | |
698 | |
705 | |
699 | /** |
706 | /** |
… | |
… | |
706 | look_at (object *op, int dx, int dy) |
713 | look_at (object *op, int dx, int dy) |
707 | { |
714 | { |
708 | object *tmp; |
715 | object *tmp; |
709 | int flag = 0; |
716 | int flag = 0; |
710 | sint16 x, y; |
717 | sint16 x, y; |
711 | mapstruct *m; |
718 | maptile *m; |
712 | |
719 | |
713 | x = op->x + dx; |
720 | x = op->x + dx; |
714 | y = op->y + dy; |
721 | y = op->y + dy; |
715 | |
722 | |
716 | if (out_of_map (op->map, x, y)) |
723 | if (out_of_map (op->map, x, y)) |