… | |
… | |
36 | #include <object.h> |
36 | #include <object.h> |
37 | #include <sproto.h> |
37 | #include <sproto.h> |
38 | |
38 | |
39 | /** This is the maximum number of bytes we expect any one item to take up */ |
39 | /** This is the maximum number of bytes we expect any one item to take up */ |
40 | #define MAXITEMLEN 300 |
40 | #define MAXITEMLEN 300 |
41 | |
|
|
42 | #if 0 |
|
|
43 | tag_t |
|
|
44 | client_container::tag () const |
|
|
45 | { |
|
|
46 | switch (type) |
|
|
47 | { |
|
|
48 | case CC_INVENTORY: |
|
|
49 | return ns->pl->count; |
|
|
50 | case CC_MAPSPACE: |
|
|
51 | return 0; |
|
|
52 | case CC_CONTAINER: |
|
|
53 | return env->count; |
|
|
54 | } |
|
|
55 | |
|
|
56 | abort (); |
|
|
57 | } |
|
|
58 | |
|
|
59 | void |
|
|
60 | client_container::clear () |
|
|
61 | { |
|
|
62 | switch (type) |
|
|
63 | { |
|
|
64 | case CC_INVENTORY: |
|
|
65 | abort (); |
|
|
66 | |
|
|
67 | case CC_MAPSPACE: |
|
|
68 | case CC_CONTAINER: |
|
|
69 | ns->send_packet_printf ("delinv %d", tag ()); |
|
|
70 | break; |
|
|
71 | } |
|
|
72 | |
|
|
73 | for (iterator i = begin (); i != end (); ++i) |
|
|
74 | i->op->seen_by = 0; |
|
|
75 | |
|
|
76 | vector< refitem, slice_allocator<refitem> >::clear (); |
|
|
77 | } |
|
|
78 | |
|
|
79 | inline iterator |
|
|
80 | client_container::merge_item (iterator i, object *op) |
|
|
81 | { |
|
|
82 | if (i != end () && i->op == op) |
|
|
83 | return ++i; |
|
|
84 | |
|
|
85 | if (op->seen_by) |
|
|
86 | return; // seen by another entity already |
|
|
87 | |
|
|
88 | op->seen_by = this; |
|
|
89 | |
|
|
90 | refitem ref; |
|
|
91 | ref.op = op; |
|
|
92 | |
|
|
93 | return insert (i, ref); |
|
|
94 | } |
|
|
95 | |
|
|
96 | void |
|
|
97 | client_container::update (int offset) |
|
|
98 | { |
|
|
99 | iterator i = begin (); |
|
|
100 | |
|
|
101 | switch (type) |
|
|
102 | { |
|
|
103 | case CC_INVENTORY: |
|
|
104 | case CC_CONTAINER: |
|
|
105 | { |
|
|
106 | object *env = type == CC_INVENTORY |
|
|
107 | ? ns->pl->ob |
|
|
108 | : this->env; |
|
|
109 | |
|
|
110 | // pass 1, erase all objects no longer in container |
|
|
111 | for (iterator j = begin (); j != end (); ++j) |
|
|
112 | if (j->op->env != env) |
|
|
113 | { |
|
|
114 | j->op->seen_by = 0; |
|
|
115 | erase (j); |
|
|
116 | } |
|
|
117 | |
|
|
118 | // pass 2 merge items |
|
|
119 | for (object *op = env->inv; op; op = op->below) |
|
|
120 | { |
|
|
121 | if (--offset < 0) |
|
|
122 | i = merge_item (i, op); |
|
|
123 | else if (offset < -FLOORBOX_PAGESIZE) |
|
|
124 | break; |
|
|
125 | } |
|
|
126 | } |
|
|
127 | break; |
|
|
128 | |
|
|
129 | case CC_MAPSPACE: |
|
|
130 | { |
|
|
131 | // pass 1, erase all objects no longer on space |
|
|
132 | for (iterator j = begin (); j != end (); ++j) |
|
|
133 | if (j->op->x != x || j->op->y != y || j->op->map != map) |
|
|
134 | { |
|
|
135 | j->op->seen_by = 0; |
|
|
136 | erase (j); |
|
|
137 | } |
|
|
138 | |
|
|
139 | // pass 2 merge items |
|
|
140 | for (object *op = GET_MAP_OB (map, x, y); op; op = op->above) |
|
|
141 | { |
|
|
142 | if (--offset < 0) |
|
|
143 | i = merge_item (i, op); |
|
|
144 | else if (offset < -FLOORBOX_PAGESIZE) |
|
|
145 | break; |
|
|
146 | } |
|
|
147 | } |
|
|
148 | break; |
|
|
149 | } |
|
|
150 | |
|
|
151 | // pass 3, erase all extra items |
|
|
152 | for (iterator j = i; j != end (); ++j) |
|
|
153 | j->op->seen_by = 0; |
|
|
154 | |
|
|
155 | if (i != end ()) |
|
|
156 | erase (i, end ()); |
|
|
157 | } |
|
|
158 | |
|
|
159 | void |
|
|
160 | client_container::set_mapspace (maptile *map, int x, int y) |
|
|
161 | { |
|
|
162 | if (type == CC_MAPSPACE |
|
|
163 | && this->map == map |
|
|
164 | && this->x == x |
|
|
165 | && this->y == y) |
|
|
166 | return; |
|
|
167 | |
|
|
168 | clear (); |
|
|
169 | |
|
|
170 | type = CC_MAPSPACE; |
|
|
171 | this->map = map; |
|
|
172 | this->x = x; |
|
|
173 | this->y = y; |
|
|
174 | } |
|
|
175 | |
|
|
176 | void |
|
|
177 | client_container::set_container (object *env) |
|
|
178 | { |
|
|
179 | } |
|
|
180 | #endif |
|
|
181 | |
41 | |
182 | /******************************************************************************* |
42 | /******************************************************************************* |
183 | * |
43 | * |
184 | * Functions related to sending object data to the client. |
44 | * Functions related to sending object data to the client. |
185 | * |
45 | * |
… | |
… | |
304 | sl << uint8 (anim_speed) |
164 | sl << uint8 (anim_speed) |
305 | << uint32 (head->nrof); |
165 | << uint32 (head->nrof); |
306 | |
166 | |
307 | if (ns.itemcmd == 2) |
167 | if (ns.itemcmd == 2) |
308 | sl << uint16 (head->client_type); |
168 | sl << uint16 (head->client_type); |
309 | |
|
|
310 | SET_FLAG (head, FLAG_CLIENT_SENT); |
|
|
311 | } |
169 | } |
312 | |
170 | |
313 | static faceidx |
171 | static faceidx |
314 | need_face_now (player *pl, const char *name) |
172 | need_face_now (player *pl, const char *name) |
315 | { |
173 | { |
… | |
… | |
525 | |
383 | |
526 | client *ns = pl->contr->ns; |
384 | client *ns = pl->contr->ns; |
527 | if (!ns) |
385 | if (!ns) |
528 | return; |
386 | return; |
529 | |
387 | |
530 | if (!QUERY_FLAG (op, FLAG_CLIENT_SENT)) |
|
|
531 | { |
|
|
532 | /* FLAG_CLIENT_SENT is debug only. We are using it to see where |
|
|
533 | * this is happening - we can set a breakpoint here in the debugger |
|
|
534 | * and track back the call. |
|
|
535 | */ |
|
|
536 | LOG (llevDebug, "We have not sent item %s (%d)\n", &op->name, op->count); |
|
|
537 | } |
|
|
538 | |
|
|
539 | packet sl ("upditem"); |
388 | packet sl ("upditem"); |
540 | |
389 | |
541 | sl << uint8 (flags); |
390 | sl << uint8 (flags); |
542 | |
391 | |
543 | op = op->head_ (); |
392 | op = op->head_ (); |
… | |
… | |
550 | if (flags & UPD_FLAGS) |
399 | if (flags & UPD_FLAGS) |
551 | sl << uint32 (query_flags (op)); |
400 | sl << uint32 (query_flags (op)); |
552 | |
401 | |
553 | if (flags & UPD_WEIGHT) |
402 | if (flags & UPD_WEIGHT) |
554 | { |
403 | { |
555 | sint32 weight = op->flag [FLAG_NO_PICK] ? -1 : op->client_weight (); |
404 | sint32 weight = op->client_weight (); |
556 | |
405 | |
557 | if (op) |
406 | if (op == pl) |
558 | ns->last_weight = weight; |
407 | ns->last_weight = weight; |
559 | |
408 | |
560 | sl << uint32 (weight); |
409 | sl << uint32 (weight); |
561 | } |
410 | } |
562 | |
411 | |
… | |
… | |
569 | |
418 | |
570 | if (flags & UPD_NAME) |
419 | if (flags & UPD_NAME) |
571 | { |
420 | { |
572 | int len; |
421 | int len; |
573 | const char *item_p; |
422 | const char *item_p; |
574 | char item_n[MAX_BUF]; |
423 | char item_n[127 * 2]; |
575 | |
424 | |
576 | if (!op->custom_name) |
425 | if (!op->custom_name) |
577 | { |
426 | { |
578 | strncpy (item_n, query_base_name (op, 0), 127); |
427 | len = assign (item_n, query_base_name (op, 0), 127); |
579 | item_n[127] = 0; |
|
|
580 | len = strlen (item_n); |
|
|
581 | item_p = query_base_name (op, 1); |
428 | item_p = query_base_name (op, 1); |
582 | } |
429 | } |
583 | else |
430 | else |
584 | { |
431 | { |
585 | strncpy (item_n, op->custom_name, 127); |
432 | len = assign (item_n, &op->custom_name, 127); |
586 | item_n[127] = 0; |
|
|
587 | len = strlen (item_n); |
|
|
588 | item_p = op->custom_name; |
433 | item_p = &op->custom_name; |
589 | } |
434 | } |
590 | |
435 | |
591 | strncpy (item_n + len + 1, item_p, 127); |
436 | len += assign (item_n + len, item_p, 127); |
592 | item_n[254] = 0; |
|
|
593 | len += strlen (item_n + 1 + len) + 1; |
|
|
594 | |
437 | |
595 | sl << data8 (item_n, len); |
438 | sl << data8 (item_n, len); |
596 | } |
439 | } |
597 | |
440 | |
598 | if (flags & UPD_ANIM) |
441 | if (flags & UPD_ANIM) |
… | |
… | |
651 | sl << uint32 (op->env ? op->env->count : 0); |
494 | sl << uint32 (op->env ? op->env->count : 0); |
652 | |
495 | |
653 | add_object_to_socklist (*pl->contr->ns, sl, op); |
496 | add_object_to_socklist (*pl->contr->ns, sl, op); |
654 | |
497 | |
655 | pl->contr->ns->send_packet (sl); |
498 | pl->contr->ns->send_packet (sl); |
656 | SET_FLAG (op, FLAG_CLIENT_SENT); |
|
|
657 | } |
499 | } |
658 | |
500 | |
659 | /** |
501 | /** |
660 | * Tells the client to delete an item. |
502 | * Tells the client to delete an item. |
661 | */ |
503 | */ |
… | |
… | |
750 | if (object *op = esrv_get_ob_from_count (pl->ob, tag)) |
592 | if (object *op = esrv_get_ob_from_count (pl->ob, tag)) |
751 | { |
593 | { |
752 | std::string s = op->describe (pl->ob); |
594 | std::string s = op->describe (pl->ob); |
753 | |
595 | |
754 | packet sl ("ex"); |
596 | packet sl ("ex"); |
755 | sl << ber32 (tag) << s.c_str (); |
597 | sl << ber32 (tag) |
|
|
598 | << data (*pl->expand_cfpod (s.c_str ())); |
756 | |
599 | |
757 | pl->ns->send_packet (sl); |
600 | pl->ns->send_packet (sl); |
758 | } |
601 | } |
759 | } |
602 | } |
760 | |
603 | |
… | |
… | |
835 | object *ob = pl->ob; |
678 | object *ob = pl->ob; |
836 | |
679 | |
837 | if (!pl->observe->map) |
680 | if (!pl->observe->map) |
838 | return; |
681 | return; |
839 | |
682 | |
|
|
683 | bool wiz = ob->flag [FLAG_WIZ] || ob->flag [FLAG_WIZLOOK]; |
|
|
684 | |
840 | mapxy pos (pl->observe); |
685 | mapxy pos (pl->observe); |
841 | pos.move (dx, dy); |
686 | pos.move (dx, dy); |
842 | |
687 | |
|
|
688 | if (wiz) |
|
|
689 | { |
843 | if (pos.normalise ()) |
690 | if (pos.normalise ()) |
|
|
691 | { |
|
|
692 | mapspace &ms = *pos; |
|
|
693 | ms.update (); |
|
|
694 | |
|
|
695 | buf.printf (" map: %s%+d%+d (%+d%+d)\n" |
|
|
696 | " smell %u/%u; flags %x; light %d; block %x; slow %x; on %x; off %x; volume %lld\n\n", |
|
|
697 | &pos.m->path, pos.x, pos.y, dx, dy, |
|
|
698 | (unsigned int)ms.smell, (unsigned int)mapspace::smellcount, ms.flags (), ms.light, |
|
|
699 | ms.move_block, ms.move_slow, ms.move_on, ms.move_off, (long long)ms.volume () |
|
|
700 | ); |
|
|
701 | } |
|
|
702 | else |
|
|
703 | buf << "off-map\n\n"; |
|
|
704 | } |
|
|
705 | |
|
|
706 | int darkness = pl->blocked_los (dx, dy); |
|
|
707 | |
|
|
708 | if (darkness == LOS_BLOCKED) |
|
|
709 | buf << "You cannot see that place from your position. H<Something is in between or it is too far away.>"; |
|
|
710 | else if (darkness == LOS_MAX) |
|
|
711 | buf << "That place is too dark to see anything. H<Move nearer or find better lighting.>"; |
|
|
712 | else |
|
|
713 | { |
|
|
714 | if (pos.normalise ()) |
844 | for (object *tmp = pos->top; tmp; tmp = tmp->below) |
715 | for (object *tmp = pos->top; tmp; tmp = tmp->below) |
845 | { |
716 | { |
846 | if (tmp->invisible && !QUERY_FLAG (ob, FLAG_WIZ)) |
717 | if (tmp->invisible && !QUERY_FLAG (ob, FLAG_WIZ)) |
847 | continue; |
718 | continue; |
848 | |
719 | |
849 | if (QUERY_FLAG (ob, FLAG_WIZ)) |
720 | if (wiz) |
850 | buf.printf ("- %s (%d).\n", query_name (tmp), tmp->count); |
721 | buf.printf (" - %s (%d).\n", query_name (tmp), tmp->count); |
851 | else |
722 | else |
852 | buf.printf ("- %s.\n", query_name (tmp)); |
723 | buf.printf (" - %s.\n", query_name (tmp)); |
853 | |
724 | |
854 | object *head = tmp->head_ (); |
725 | object *head = tmp->head_ (); |
855 | |
726 | |
856 | if (head->inv) |
727 | if (head->inv) |
857 | if ((head->type != CONTAINER && head->type != FLESH) |
728 | if ((head->type != CONTAINER && head->type != FLESH) |
858 | || QUERY_FLAG (ob, FLAG_WIZ)) |
729 | || QUERY_FLAG (ob, FLAG_WIZ)) |
859 | buf << head->query_inventory (ob, " "); |
730 | buf << head->query_inventory (ob, " "); |
860 | |
731 | |
861 | if (QUERY_FLAG (tmp, FLAG_IS_FLOOR) && !QUERY_FLAG (ob, FLAG_WIZ)) /* don't continue under the floor */ |
732 | if (QUERY_FLAG (tmp, FLAG_IS_FLOOR) && !wiz) /* don't continue under the floor */ |
862 | break; |
733 | break; |
|
|
734 | } |
863 | } |
735 | } |
864 | |
736 | |
865 | if (buf.empty ()) |
737 | if (buf.empty ()) |
866 | pl->failmsg ("You see nothing there."); |
738 | buf << "You see nothing there."; |
867 | else |
739 | |
868 | pl->infobox (MSG_CHANNEL ("lookat"), buf); |
740 | pl->infobox (MSG_CHANNEL ("lookat"), buf); |
869 | } |
741 | } |
870 | |
742 | |
871 | /** Client wants to look at some object. Lets do so. */ |
743 | /** Client wants to look at some object. Lets do so. */ |
872 | void |
744 | void |
873 | LookAt (char *buf, int len, player *pl) |
745 | LookAt (char *buf, int len, player *pl) |
… | |
… | |
878 | if (!(cp = strchr (buf, ' '))) |
750 | if (!(cp = strchr (buf, ' '))) |
879 | return; |
751 | return; |
880 | |
752 | |
881 | int dy = atoi (cp); |
753 | int dy = atoi (cp); |
882 | |
754 | |
883 | if (player *opl = pl->observe->contr) |
|
|
884 | if (client *ns = opl->ns) |
|
|
885 | { |
|
|
886 | if (fabs (dx) > ns->mapx / 2 || fabs (dy) > ns->mapy / 2) |
|
|
887 | return; |
|
|
888 | |
|
|
889 | if (opl->blocked_los[dx + ns->mapx / 2][dy + ns->mapy / 2]) |
|
|
890 | return; |
|
|
891 | } |
|
|
892 | |
|
|
893 | look_at (pl, dx, dy); |
755 | look_at (pl, dx, dy); |
894 | } |
756 | } |
895 | |
757 | |
896 | /** Move an object to a new location */ |
758 | /** Move an object to a new location */ |
897 | void |
759 | void |
898 | esrv_move_object (object *pl, tag_t to, tag_t tag, long nrof) |
760 | esrv_move_object (object *pl, tag_t to, tag_t tag, long nrof) |
899 | { |
761 | { |
900 | object *op, *env; |
|
|
901 | |
|
|
902 | op = esrv_get_ob_from_count (pl, tag); |
762 | object *op = esrv_get_ob_from_count (pl, tag); |
903 | if (!op) |
763 | if (!op) |
904 | { |
764 | { |
905 | LOG (llevDebug, "Player '%s' tried to move an unknown object (%ld)\n", &pl->name, tag); |
765 | LOG (llevDebug, "Player '%s' tried to move an unknown object (%ld)\n", &pl->name, tag); |
906 | return; |
766 | return; |
907 | } |
767 | } |
… | |
… | |
916 | */ |
776 | */ |
917 | if (op->inv && QUERY_FLAG (op, FLAG_APPLIED)) |
777 | if (op->inv && QUERY_FLAG (op, FLAG_APPLIED)) |
918 | { |
778 | { |
919 | int cnt = MAX_ITEM_PER_DROP; |
779 | int cnt = MAX_ITEM_PER_DROP; |
920 | |
780 | |
921 | for (object *current = op->inv; current; ) |
781 | for (object *current = op->inv; current && cnt--; ) |
922 | { |
782 | { |
923 | object *next = current->below; |
783 | object *next = current->below; |
924 | |
|
|
925 | drop_object (pl, current, 0); |
784 | drop_object (pl, current, 0); |
926 | |
|
|
927 | if (--cnt <= 0) break; |
|
|
928 | |
|
|
929 | current = next; |
785 | current = next; |
930 | } |
786 | } |
931 | |
787 | |
932 | if (cnt <= 0) |
788 | if (cnt <= 0) |
933 | op->failmsg ("Only dropped some items, can't drop that many items at once."); |
789 | op->failmsg ("Only dropped some items, can't drop that many items at once."); |
… | |
… | |
946 | pl->contr->count = nrof; |
802 | pl->contr->count = nrof; |
947 | pick_up (pl, op); |
803 | pick_up (pl, op); |
948 | return; |
804 | return; |
949 | } |
805 | } |
950 | |
806 | |
951 | env = esrv_get_ob_from_count (pl, to); |
807 | object *env = esrv_get_ob_from_count (pl, to); |
952 | if (!env) |
808 | if (!env) |
953 | { |
809 | { |
954 | LOG (llevDebug, "Player '%s' tried to move object to the unknown location (%d)\n", &pl->name, to); |
810 | LOG (llevDebug, "Player '%s' tried to move object to the unknown location (%d)\n", &pl->name, to); |
955 | return; |
811 | return; |
956 | } |
812 | } |