… | |
… | |
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 | { |
… | |
… | |
524 | return; |
382 | return; |
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 | |
|
|
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 | |
387 | |
539 | packet sl ("upditem"); |
388 | packet sl ("upditem"); |
540 | |
389 | |
541 | sl << uint8 (flags); |
390 | sl << uint8 (flags); |
542 | |
391 | |
… | |
… | |
651 | sl << uint32 (op->env ? op->env->count : 0); |
500 | sl << uint32 (op->env ? op->env->count : 0); |
652 | |
501 | |
653 | add_object_to_socklist (*pl->contr->ns, sl, op); |
502 | add_object_to_socklist (*pl->contr->ns, sl, op); |
654 | |
503 | |
655 | pl->contr->ns->send_packet (sl); |
504 | pl->contr->ns->send_packet (sl); |
656 | SET_FLAG (op, FLAG_CLIENT_SENT); |
|
|
657 | } |
505 | } |
658 | |
506 | |
659 | /** |
507 | /** |
660 | * Tells the client to delete an item. |
508 | * Tells the client to delete an item. |
661 | */ |
509 | */ |
… | |
… | |
749 | |
597 | |
750 | if (object *op = esrv_get_ob_from_count (pl->ob, tag)) |
598 | if (object *op = esrv_get_ob_from_count (pl->ob, tag)) |
751 | { |
599 | { |
752 | std::string s = op->describe (pl->ob); |
600 | std::string s = op->describe (pl->ob); |
753 | |
601 | |
754 | if (msg_is_special (s.c_str (), false)) |
|
|
755 | cfperl_expand_cfpod (pl, s); |
|
|
756 | |
|
|
757 | packet sl ("ex"); |
602 | packet sl ("ex"); |
758 | sl << ber32 (tag) << s.c_str (); |
603 | sl << ber32 (tag) |
|
|
604 | << data (*pl->expand_cfpod (s.c_str ())); |
759 | |
605 | |
760 | pl->ns->send_packet (sl); |
606 | pl->ns->send_packet (sl); |
761 | } |
607 | } |
762 | } |
608 | } |
763 | |
609 | |
… | |
… | |
848 | { |
694 | { |
849 | if (tmp->invisible && !QUERY_FLAG (ob, FLAG_WIZ)) |
695 | if (tmp->invisible && !QUERY_FLAG (ob, FLAG_WIZ)) |
850 | continue; |
696 | continue; |
851 | |
697 | |
852 | if (QUERY_FLAG (ob, FLAG_WIZ)) |
698 | if (QUERY_FLAG (ob, FLAG_WIZ)) |
853 | buf.printf ("- %s (%d).\n", query_name (tmp), tmp->count); |
699 | buf.printf (" - %s (%d).\n", query_name (tmp), tmp->count); |
854 | else |
700 | else |
855 | buf.printf ("- %s.\n", query_name (tmp)); |
701 | buf.printf (" - %s.\n", query_name (tmp)); |
856 | |
702 | |
857 | object *head = tmp->head_ (); |
703 | object *head = tmp->head_ (); |
858 | |
704 | |
859 | if (head->inv) |
705 | if (head->inv) |
860 | if ((head->type != CONTAINER && head->type != FLESH) |
706 | if ((head->type != CONTAINER && head->type != FLESH) |
861 | || QUERY_FLAG (ob, FLAG_WIZ)) |
707 | || QUERY_FLAG (ob, FLAG_WIZ)) |
862 | buf << head->query_inventory (ob, " "); |
708 | buf << head->query_inventory (ob, " "); |
863 | |
709 | |
864 | if (QUERY_FLAG (tmp, FLAG_IS_FLOOR) && !QUERY_FLAG (ob, FLAG_WIZ)) /* don't continue under the floor */ |
710 | if (QUERY_FLAG (tmp, FLAG_IS_FLOOR) && !QUERY_FLAG (ob, FLAG_WIZ)) /* don't continue under the floor */ |
865 | break; |
711 | break; |
866 | } |
712 | } |
867 | |
713 | |