1 | /* |
1 | /* |
2 | * CrossFire, A Multiplayer game for X-windows |
2 | * This file is part of Crossfire TRT, the Multiplayer Online Role Playing Game. |
3 | * |
3 | * |
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team |
5 | * Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * This program is free software; you can redistribute it and/or modify |
8 | * Crossfire TRT is free software; you can redistribute it and/or modify it |
9 | * it under the terms of the GNU General Public License as published by |
9 | * under the terms of the GNU General Public License as published by the Free |
10 | * the Free Software Foundation; either version 2 of the License, or |
10 | * Software Foundation; either version 2 of the License, or (at your option) |
11 | * (at your option) any later version. |
11 | * 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, but |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
16 | * GNU General Public License for more details. |
16 | * 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 along |
19 | * along with this program; if not, write to the Free Software |
19 | * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51 |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
21 | * |
21 | * |
22 | * The author can be reached via e-mail to <crossfire@schmorp.de> |
22 | * The authors can be reached via e-mail to <crossfire@schmorp.de> |
23 | */ |
23 | */ |
24 | |
24 | |
25 | /** |
25 | /** |
26 | * \file |
26 | * \file |
27 | * Client/server logic. |
27 | * Client/server logic. |
… | |
… | |
691 | |
691 | |
692 | /** |
692 | /** |
693 | * Takes a player and object count (tag) and returns the actual object |
693 | * Takes a player and object count (tag) and returns the actual object |
694 | * pointer, or null if it can't be found. |
694 | * pointer, or null if it can't be found. |
695 | */ |
695 | */ |
696 | |
|
|
697 | object * |
696 | object * |
698 | esrv_get_ob_from_count (object *pl, tag_t count) |
697 | esrv_get_ob_from_count (object *pl, tag_t count) |
699 | { |
698 | { |
700 | object *op, *tmp; |
|
|
701 | |
|
|
702 | if (pl->count == count) |
699 | if (pl->count == count) |
703 | return pl; |
700 | return pl; |
704 | |
701 | |
705 | for (op = pl->inv; op; op = op->below) |
702 | for (object *op = pl->inv; op; op = op->below) |
706 | if (op->count == count) |
703 | if (op->count == count) |
707 | return op; |
704 | return op; |
708 | else if (op->type == CONTAINER && pl->container == op) |
705 | else if (op->type == CONTAINER && pl->container == op) |
709 | for (tmp = op->inv; tmp; tmp = tmp->below) |
706 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
710 | if (tmp->count == count) |
707 | if (tmp->count == count) |
711 | return tmp; |
708 | return tmp; |
712 | |
709 | |
713 | for (op = GET_MAP_OB (pl->map, pl->x, pl->y); op; op = op->above) |
710 | for (object *op = GET_MAP_OB (pl->map, pl->x, pl->y); op; op = op->above) |
714 | if (op->head && op->head->count == count) |
711 | if (op->head && op->head->count == count) |
715 | return op; |
712 | return op; |
716 | else if (op->count == count) |
713 | else if (op->count == count) |
717 | return op; |
714 | return op; |
718 | else if (op->type == CONTAINER && pl->container == op) |
715 | else if (op->type == CONTAINER && pl->container == op) |
719 | for (tmp = op->inv; tmp; tmp = tmp->below) |
716 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
720 | if (tmp->count == count) |
717 | if (tmp->count == count) |
721 | return tmp; |
718 | return tmp; |
722 | |
719 | |
|
|
720 | #if 0 |
|
|
721 | /* If the high bit is set, player examined a pseudo object. */ |
|
|
722 | if (count & 0x80000000) |
|
|
723 | return 0; |
|
|
724 | #endif |
|
|
725 | |
723 | return 0; |
726 | return 0; |
724 | } |
727 | } |
725 | |
728 | |
726 | |
|
|
727 | /** Client wants to examine some object. So lets do so. */ |
729 | /** Client wants to examine some object. So lets do so. */ |
728 | void |
730 | void |
729 | ExamineCmd (char *buf, int len, player *pl) |
731 | ExamineCmd (char *buf, int len, player *pl) |
730 | { |
732 | { |
731 | tag_t tag = atoi (buf); |
733 | tag_t tag = atoi (buf); |
732 | |
|
|
733 | /* If the high bit is set, player examined a pseudo object. */ |
|
|
734 | if (tag & 0x80000000) |
|
|
735 | return; |
|
|
736 | |
734 | |
737 | object *op = esrv_get_ob_from_count (pl->ob, tag); |
735 | object *op = esrv_get_ob_from_count (pl->ob, tag); |
738 | |
736 | |
739 | if (!op) |
737 | if (!op) |
740 | { |
738 | { |
741 | LOG (llevDebug, "Player '%s' tried to examine the unknown object (%ld)\n", &pl->ob->name, tag); |
739 | LOG (llevDebug, "Player '%s' tried to examine the unknown object (%ld)\n", &pl->ob->name, tag); |
742 | return; |
740 | return; |
743 | } |
741 | } |
744 | |
742 | |
745 | examine (pl->ob, op); |
743 | examine (pl->ob, op); |
|
|
744 | } |
|
|
745 | |
|
|
746 | /** Client wants to examine some object. So lets do so. */ |
|
|
747 | void |
|
|
748 | ExCmd (char *buf, int len, player *pl) |
|
|
749 | { |
|
|
750 | tag_t tag = atoi (buf); |
|
|
751 | |
|
|
752 | if (object *op = esrv_get_ob_from_count (pl->ob, tag)) |
|
|
753 | { |
|
|
754 | std::string s = op->describe (pl->ob); |
|
|
755 | |
|
|
756 | packet sl ("ex"); |
|
|
757 | sl << ber32 (tag) << s.c_str (); |
|
|
758 | |
|
|
759 | pl->ns->send_packet (sl); |
|
|
760 | } |
746 | } |
761 | } |
747 | |
762 | |
748 | /** Client wants to apply some object. Lets do so. */ |
763 | /** Client wants to apply some object. Lets do so. */ |
749 | void |
764 | void |
750 | ApplyCmd (char *buf, int len, player *pl) |
765 | ApplyCmd (char *buf, int len, player *pl) |
… | |
… | |
837 | |
852 | |
838 | m = get_map_from_coord (op->map, &x, &y); |
853 | m = get_map_from_coord (op->map, &x, &y); |
839 | if (!m) |
854 | if (!m) |
840 | return; |
855 | return; |
841 | |
856 | |
842 | for (tmp = GET_MAP_OB (m, x, y); tmp != NULL && tmp->above != NULL; tmp = tmp->above); |
857 | for (tmp = GET_MAP_OB (m, x, y); tmp && tmp->above; tmp = tmp->above) |
|
|
858 | ; |
843 | |
859 | |
844 | for (; tmp != NULL; tmp = tmp->below) |
860 | for (; tmp; tmp = tmp->below) |
845 | { |
861 | { |
846 | if (tmp->invisible && !QUERY_FLAG (op, FLAG_WIZ)) |
862 | if (tmp->invisible && !QUERY_FLAG (op, FLAG_WIZ)) |
847 | continue; |
863 | continue; |
848 | |
864 | |
849 | if (!flag) |
865 | if (!flag) |
… | |
… | |
887 | int dx, dy; |
903 | int dx, dy; |
888 | char *cp; |
904 | char *cp; |
889 | |
905 | |
890 | dx = atoi (buf); |
906 | dx = atoi (buf); |
891 | if (!(cp = strchr (buf, ' '))) |
907 | if (!(cp = strchr (buf, ' '))) |
892 | { |
|
|
893 | return; |
908 | return; |
894 | } |
909 | |
895 | dy = atoi (cp); |
910 | dy = atoi (cp); |
896 | |
|
|
897 | if (fabs (dx) > pl->ns->mapx / 2 || fabs (dy) > pl->ns->mapy / 2) |
911 | if (fabs (dx) > pl->ns->mapx / 2 || fabs (dy) > pl->ns->mapy / 2) |
898 | return; |
912 | return; |
899 | |
913 | |
900 | if (pl->blocked_los[dx + pl->ns->mapx / 2][dy + pl->ns->mapy / 2]) |
914 | if (pl->blocked_los[dx + pl->ns->mapx / 2][dy + pl->ns->mapy / 2]) |
901 | return; |
915 | return; |