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.65 by root, Tue May 6 16:32:34 2008 UTC vs.
Revision 1.69 by root, Mon Jul 14 23:47:06 2008 UTC

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
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
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 *
526 client *ns = pl->contr->ns; 386 client *ns = pl->contr->ns;
527 if (!ns) 387 if (!ns)
528 return; 388 return;
529 389
530 if (!QUERY_FLAG (op, FLAG_CLIENT_SENT)) 390 if (!QUERY_FLAG (op, FLAG_CLIENT_SENT))
531 {
532 /* FLAG_CLIENT_SENT is debug only. We are using it to see where 391 /* 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 392 * this is happening - we can set a breakpoint here in the debugger
534 * and track back the call. 393 * and track back the call.
535 */ 394 */
536 LOG (llevDebug, "We have not sent item %s (%d)\n", &op->name, op->count); 395 LOG (llevDebug | logBacktrace, "We have not sent item %s (%d)\n", &op->name, op->count);
537 }
538 396
539 packet sl ("upditem"); 397 packet sl ("upditem");
540 398
541 sl << uint8 (flags); 399 sl << uint8 (flags);
542 400
749 607
750 if (object *op = esrv_get_ob_from_count (pl->ob, tag)) 608 if (object *op = esrv_get_ob_from_count (pl->ob, tag))
751 { 609 {
752 std::string s = op->describe (pl->ob); 610 std::string s = op->describe (pl->ob);
753 611
612 if (msg_is_special (s.c_str (), false))
613 cfperl_expand_cfpod (pl, s);
614
754 packet sl ("ex"); 615 packet sl ("ex");
755 sl << ber32 (tag) << s.c_str (); 616 sl << ber32 (tag) << s.c_str ();
756 617
757 pl->ns->send_packet (sl); 618 pl->ns->send_packet (sl);
758 } 619 }
895 756
896/** Move an object to a new location */ 757/** Move an object to a new location */
897void 758void
898esrv_move_object (object *pl, tag_t to, tag_t tag, long nrof) 759esrv_move_object (object *pl, tag_t to, tag_t tag, long nrof)
899{ 760{
900 object *op, *env;
901
902 op = esrv_get_ob_from_count (pl, tag); 761 object *op = esrv_get_ob_from_count (pl, tag);
903 if (!op) 762 if (!op)
904 { 763 {
905 LOG (llevDebug, "Player '%s' tried to move an unknown object (%ld)\n", &pl->name, tag); 764 LOG (llevDebug, "Player '%s' tried to move an unknown object (%ld)\n", &pl->name, tag);
906 return; 765 return;
907 } 766 }
916 */ 775 */
917 if (op->inv && QUERY_FLAG (op, FLAG_APPLIED)) 776 if (op->inv && QUERY_FLAG (op, FLAG_APPLIED))
918 { 777 {
919 int cnt = MAX_ITEM_PER_DROP; 778 int cnt = MAX_ITEM_PER_DROP;
920 779
921 for (object *current = op->inv; current; ) 780 for (object *current = op->inv; current && cnt--; )
922 { 781 {
923 object *next = current->below; 782 object *next = current->below;
924
925 drop_object (pl, current, 0); 783 drop_object (pl, current, 0);
926
927 if (--cnt <= 0) break;
928
929 current = next; 784 current = next;
930 } 785 }
931 786
932 if (cnt <= 0) 787 if (cnt <= 0)
933 op->failmsg ("Only dropped some items, can't drop that many items at once."); 788 op->failmsg ("Only dropped some items, can't drop that many items at once.");
946 pl->contr->count = nrof; 801 pl->contr->count = nrof;
947 pick_up (pl, op); 802 pick_up (pl, op);
948 return; 803 return;
949 } 804 }
950 805
951 env = esrv_get_ob_from_count (pl, to); 806 object *env = esrv_get_ob_from_count (pl, to);
952 if (!env) 807 if (!env)
953 { 808 {
954 LOG (llevDebug, "Player '%s' tried to move object to the unknown location (%d)\n", &pl->name, to); 809 LOG (llevDebug, "Player '%s' tried to move object to the unknown location (%d)\n", &pl->name, to);
955 return; 810 return;
956 } 811 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines