ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/socket/item.C
(Generate patch)

Comparing deliantra/server/socket/item.C (file contents):
Revision 1.26 by root, Tue Dec 19 05:41:22 2006 UTC vs.
Revision 1.28 by root, Wed Dec 20 09:14:22 2006 UTC

36#include <object.h> /* LOOK_OBJ */ 36#include <object.h> /* LOOK_OBJ */
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
43tag_t
44client_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
59void
60client_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
79inline iterator
80client_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
96void
97client_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
159void
160client_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
176void
177client_container::set_container (object *env)
178{
179}
180#endif
41 181
42/******************************************************************************* 182/*******************************************************************************
43 * 183 *
44 * Functions related to sending object data to the client. 184 * Functions related to sending object data to the client.
45 * 185 *
211 || !pl->map 351 || !pl->map
212 || pl->map->in_memory != MAP_IN_MEMORY 352 || pl->map->in_memory != MAP_IN_MEMORY
213 || out_of_map (pl->map, pl->x, pl->y)) 353 || out_of_map (pl->map, pl->x, pl->y))
214 return; 354 return;
215 355
216 for (tmp = get_map_ob (pl->map, pl->x, pl->y); tmp && tmp->above; tmp = tmp->above) 356 for (tmp = GET_MAP_OB (pl->map, pl->x, pl->y); tmp && tmp->above; tmp = tmp->above)
217 ; 357 ;
218 358
359 pl->contr->socket->send_packet ("delinv 0");
360
219 packet sl; 361 packet sl;
220
221 pl->contr->socket->send_packet ("delinv 0");
222
223 sl.printf ("item%d ", pl->contr->socket->itemcmd); 362 sl.printf ("item%d ", pl->contr->socket->itemcmd);
224 363
225 sl << uint32 (0); 364 sl << uint32 (0);
226 365
227 if (!(pl->contr->socket->faces_sent[empty_face->number] & NS_FACESENT_FACE)) 366 if (!(pl->contr->socket->faces_sent[empty_face->number] & NS_FACESENT_FACE))
315esrv_send_inventory (object *pl, object *op) 454esrv_send_inventory (object *pl, object *op)
316{ 455{
317 object *tmp; 456 object *tmp;
318 int got_one = 0; 457 int got_one = 0;
319 458
459
460 pl->contr->socket->send_packet_printf ("delinv %d", op->count);
461
320 packet sl; 462 packet sl;
321
322 sl.printf ("delinv %d", op->count);
323 pl->contr->socket->send_packet (sl);
324
325 sl.reset ();
326 sl.printf ("item%d ", pl->contr->socket->itemcmd); 463 sl.printf ("item%d ", pl->contr->socket->itemcmd);
327 464
328 sl << uint32 (op->count); 465 sl << uint32 (op->count);
329 466
330 for (tmp = op->inv; tmp; tmp = tmp->below) 467 for (tmp = op->inv; tmp; tmp = tmp->below)
391 * and track back the call. 528 * and track back the call.
392 */ 529 */
393 LOG (llevDebug, "We have not sent item %s (%d)\n", &op->name, op->count); 530 LOG (llevDebug, "We have not sent item %s (%d)\n", &op->name, op->count);
394 } 531 }
395 532
396 packet sl; 533 packet sl ("upditem");
397 534
398 sl << "upditem "
399 << uint8 (flags); 535 sl << uint8 (flags);
400 536
401 if (op->head) 537 if (op->head)
402 op = op->head; 538 op = op->head;
403 539
404 sl << uint32 (op->count); 540 sl << uint32 (op->count);
532 */ 668 */
533 669
534void 670void
535esrv_del_item (player *pl, int tag) 671esrv_del_item (player *pl, int tag)
536{ 672{
537 packet sl; 673 packet sl ("delitem");
538 674
539 sl << "delitem "
540 << uint32 (tag); 675 sl << uint32 (tag);
541 676
542 pl->socket->send_packet (sl); 677 pl->socket->send_packet (sl);
543} 678}
544 679
545 680
568 else if (op->type == CONTAINER && pl->container == op) 703 else if (op->type == CONTAINER && pl->container == op)
569 for (tmp = op->inv; tmp; tmp = tmp->below) 704 for (tmp = op->inv; tmp; tmp = tmp->below)
570 if (tmp->count == count) 705 if (tmp->count == count)
571 return tmp; 706 return tmp;
572 707
573 for (op = get_map_ob (pl->map, pl->x, pl->y); op; op = op->above) 708 for (op = GET_MAP_OB (pl->map, pl->x, pl->y); op; op = op->above)
574 if (op->head && op->head->count == count) 709 if (op->head && op->head->count == count)
575 return op; 710 return op;
576 else if (op->count == count) 711 else if (op->count == count)
577 return op; 712 return op;
578 else if (op->type == CONTAINER && pl->container == op) 713 else if (op->type == CONTAINER && pl->container == op)
697 832
698 m = get_map_from_coord (op->map, &x, &y); 833 m = get_map_from_coord (op->map, &x, &y);
699 if (!m) 834 if (!m)
700 return; 835 return;
701 836
702 for (tmp = get_map_ob (m, x, y); tmp != NULL && tmp->above != NULL; tmp = tmp->above); 837 for (tmp = GET_MAP_OB (m, x, y); tmp != NULL && tmp->above != NULL; tmp = tmp->above);
703 838
704 for (; tmp != NULL; tmp = tmp->below) 839 for (; tmp != NULL; tmp = tmp->below)
705 { 840 {
706 if (tmp->invisible && !QUERY_FLAG (op, FLAG_WIZ)) 841 if (tmp->invisible && !QUERY_FLAG (op, FLAG_WIZ))
707 continue; 842 continue;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines