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.1 by elmex, Sun Aug 13 17:16:06 2006 UTC vs.
Revision 1.5 by root, Sun Sep 10 13:43:33 2006 UTC

1 1
2/* 2/*
3 * static char *rcsid_item_c = 3 * static char *rcsid_item_c =
4 * "$Id: item.C,v 1.1 2006/08/13 17:16:06 elmex Exp $"; 4 * "$Id: item.C,v 1.5 2006/09/10 13:43:33 root Exp $";
5 */ 5 */
6 6
7/* 7/*
8 CrossFire, A Multiplayer game for X-windows 8 CrossFire, A Multiplayer game for X-windows
9 9
38 * the logic for what items should be sent. 38 * the logic for what items should be sent.
39 */ 39 */
40 40
41 41
42#include <global.h> 42#include <global.h>
43#include <object.h> /* LOOK_OBJ */ 43#include <object.h> /* LOOK_OBJ */
44#include <newclient.h> 44#include <newclient.h>
45#include <newserver.h> 45#include <newserver.h>
46#include <sproto.h> 46#include <sproto.h>
47 47
48/** This is the maximum number of bytes we expect any one item to take up */ 48/** This is the maximum number of bytes we expect any one item to take up */
60 * This is a simple function that we use a lot here. It basically 60 * This is a simple function that we use a lot here. It basically
61 * adds the specified buffer into the socklist, but prepends a 61 * adds the specified buffer into the socklist, but prepends a
62 * single byte in length. If the data is longer than that byte, it is 62 * single byte in length. If the data is longer than that byte, it is
63 * truncated approprately. 63 * truncated approprately.
64 */ 64 */
65inline void
65inline void add_stringlen_to_sockbuf(const char *buf, SockList *sl) 66add_stringlen_to_sockbuf (const char *buf, SockList * sl)
66{ 67{
67 int len; 68 int len;
68 69
69 len=strlen(buf); 70 len = strlen (buf);
70 if (len>255) len=255; 71 if (len > 255)
72 len = 255;
71 SockList_AddChar(sl, (char) len); 73 SockList_AddChar (sl, (char) len);
72 strncpy((char*)sl->buf+sl->len, buf,len); 74 strncpy ((char *) sl->buf + sl->len, buf, len);
73 sl->len += len; 75 sl->len += len;
74} 76}
75 77
76/** 78/**
77 * This is a similar to query_name, but returns flags 79 * This is a similar to query_name, but returns flags
78 * to be sended to client. 80 * to be sended to client.
79 */ 81 */
82unsigned int
80unsigned int query_flags (object *op) 83query_flags (object *op)
81{ 84{
82 unsigned int flags = 0; 85 unsigned int flags = 0;
83 86
84 if(QUERY_FLAG(op,FLAG_APPLIED)) { 87 if (QUERY_FLAG (op, FLAG_APPLIED))
85 switch(op->type) {
86 case BOW:
87 case WAND:
88 case ROD:
89 case HORN:
90 flags = a_readied;
91 break;
92 case WEAPON:
93 flags = a_wielded;
94 break;
95 case SKILL:
96 case ARMOUR:
97 case HELMET:
98 case SHIELD:
99 case RING:
100 case BOOTS:
101 case GLOVES:
102 case AMULET:
103 case GIRDLE:
104 case BRACERS:
105 case CLOAK:
106 flags = a_worn;
107 break;
108 case CONTAINER:
109 flags = a_active;
110 break;
111 default:
112 flags = a_applied;
113 break;
114 }
115 }
116 if (op->type == CONTAINER && ((op->env && op->env->container == op) ||
117 (!op->env && QUERY_FLAG(op,FLAG_APPLIED))))
118 flags |= F_OPEN;
119 88 {
89 switch (op->type)
90 {
91 case BOW:
92 case WAND:
93 case ROD:
94 case HORN:
95 flags = a_readied;
96 break;
97 case WEAPON:
98 flags = a_wielded;
99 break;
100 case SKILL:
101 case ARMOUR:
102 case HELMET:
103 case SHIELD:
104 case RING:
105 case BOOTS:
106 case GLOVES:
107 case AMULET:
108 case GIRDLE:
109 case BRACERS:
110 case CLOAK:
111 flags = a_worn;
112 break;
113 case CONTAINER:
114 flags = a_active;
115 break;
116 default:
117 flags = a_applied;
118 break;
119 }
120 }
121 if (op->type == CONTAINER && ((op->env && op->env->container == op) || (!op->env && QUERY_FLAG (op, FLAG_APPLIED))))
122 flags |= F_OPEN;
123
120 if (QUERY_FLAG(op,FLAG_KNOWN_CURSED)) { 124 if (QUERY_FLAG (op, FLAG_KNOWN_CURSED))
125 {
121 if(QUERY_FLAG(op,FLAG_DAMNED)) 126 if (QUERY_FLAG (op, FLAG_DAMNED))
122 flags |= F_DAMNED; 127 flags |= F_DAMNED;
123 else if(QUERY_FLAG(op,FLAG_CURSED)) 128 else if (QUERY_FLAG (op, FLAG_CURSED))
124 flags |= F_CURSED; 129 flags |= F_CURSED;
125 } 130 }
126 if (QUERY_FLAG(op,FLAG_KNOWN_MAGICAL) && !QUERY_FLAG(op,FLAG_IDENTIFIED)) 131 if (QUERY_FLAG (op, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (op, FLAG_IDENTIFIED))
127 flags |= F_MAGIC; 132 flags |= F_MAGIC;
128 if (QUERY_FLAG(op,FLAG_UNPAID)) 133 if (QUERY_FLAG (op, FLAG_UNPAID))
129 flags |= F_UNPAID; 134 flags |= F_UNPAID;
130 if (QUERY_FLAG(op,FLAG_INV_LOCKED)) 135 if (QUERY_FLAG (op, FLAG_INV_LOCKED))
131 flags |= F_LOCKED; 136 flags |= F_LOCKED;
132 137
133 return flags; 138 return flags;
134} 139}
135 140
136/* Used in the send_look to put object head into SockList 141/* Used in the send_look to put object head into SockList
137 * sl for socket ns. Need socket to know if we need to send 142 * sl for socket ns. Need socket to know if we need to send
138 * animation of face to the client. 143 * animation of face to the client.
139 */ 144 */
145static void
140static void add_object_to_socklist(NewSocket *ns, SockList *sl, object *head) 146add_object_to_socklist (NewSocket * ns, SockList * sl, object *head)
141{ 147{
142 int flags, len, anim_speed; 148 int flags, len, anim_speed;
143 char item_n[MAX_BUF]; 149 char item_n[MAX_BUF];
144 const char *item_p; 150 const char *item_p;
145 151
146 flags = query_flags (head); 152 flags = query_flags (head);
147 if (QUERY_FLAG(head, FLAG_NO_PICK)) 153 if (QUERY_FLAG (head, FLAG_NO_PICK))
148 flags |= F_NOPICK; 154 flags |= F_NOPICK;
149 155
150 if (!(ns->faces_sent[head->face->number] & NS_FACESENT_FACE)) 156 if (!(ns->faces_sent[head->face->number] & NS_FACESENT_FACE))
151 esrv_send_face(ns, head->face->number,0); 157 esrv_send_face (ns, head->face->number, 0);
152 158
153 if (QUERY_FLAG(head,FLAG_ANIMATE) && !ns->anims_sent[head->animation_id]) 159 if (QUERY_FLAG (head, FLAG_ANIMATE) && !ns->anims_sent[head->animation_id])
154 esrv_send_animation(ns, head->animation_id); 160 esrv_send_animation (ns, head->animation_id);
155 161
156 SockList_AddInt(sl, head->count); 162 SockList_AddInt (sl, head->count);
157 SockList_AddInt(sl, flags); 163 SockList_AddInt (sl, flags);
158 SockList_AddInt(sl, QUERY_FLAG(head, FLAG_NO_PICK) ? -1 : WEIGHT(head)); 164 SockList_AddInt (sl, QUERY_FLAG (head, FLAG_NO_PICK) ? -1 : WEIGHT (head));
159 SockList_AddInt(sl, head->face->number); 165 SockList_AddInt (sl, head->face->number);
160 166
161 if (!head->custom_name) { 167 if (!head->custom_name)
168 {
162 strncpy(item_n,query_base_name(head, 0),127); 169 strncpy (item_n, query_base_name (head, 0), 127);
163 item_n[127]=0; 170 item_n[127] = 0;
164 len=strlen(item_n); 171 len = strlen (item_n);
165 item_p=query_base_name(head, 1); 172 item_p = query_base_name (head, 1);
166 } else { 173 }
174 else
175 {
167 strncpy(item_n,head->custom_name,127); 176 strncpy (item_n, head->custom_name, 127);
168 item_n[127]=0; 177 item_n[127] = 0;
169 len=strlen(item_n); 178 len = strlen (item_n);
170 item_p=head->custom_name; 179 item_p = head->custom_name;
171 } 180 }
172 strncpy(item_n+len+1, item_p, 127); 181 strncpy (item_n + len + 1, item_p, 127);
173 item_n[254]=0; 182 item_n[254] = 0;
174 len += strlen(item_n+1+len) + 1; 183 len += strlen (item_n + 1 + len) + 1;
175 SockList_AddChar(sl, (char ) len); 184 SockList_AddChar (sl, (char) len);
176 memcpy(sl->buf+sl->len, item_n, len); 185 memcpy (sl->buf + sl->len, item_n, len);
177 sl->len += len; 186 sl->len += len;
178 187
179 SockList_AddShort(sl,head->animation_id); 188 SockList_AddShort (sl, head->animation_id);
180 anim_speed=0; 189 anim_speed = 0;
181 if (QUERY_FLAG(head,FLAG_ANIMATE)) { 190 if (QUERY_FLAG (head, FLAG_ANIMATE))
182 if (head->anim_speed) anim_speed=head->anim_speed;
183 else {
184 if (FABS(head->speed)<0.001) anim_speed=255;
185 else if (FABS(head->speed)>=1.0) anim_speed=1;
186 else anim_speed = (int) (1.0/FABS(head->speed));
187 }
188 if (anim_speed>255) anim_speed=255;
189 } 191 {
192 if (head->anim_speed)
193 anim_speed = head->anim_speed;
194 else
195 {
196 if (FABS (head->speed) < 0.001)
197 anim_speed = 255;
198 else if (FABS (head->speed) >= 1.0)
199 anim_speed = 1;
200 else
201 anim_speed = (int) (1.0 / FABS (head->speed));
202 }
203 if (anim_speed > 255)
204 anim_speed = 255;
205 }
190 SockList_AddChar(sl, (char) anim_speed); 206 SockList_AddChar (sl, (char) anim_speed);
191 SockList_AddInt(sl, head->nrof); 207 SockList_AddInt (sl, head->nrof);
192 208
193 if (ns->itemcmd == 2) 209 if (ns->itemcmd == 2)
194 SockList_AddShort(sl, head->client_type); 210 SockList_AddShort (sl, head->client_type);
195 211
196 SET_FLAG(head, FLAG_CLIENT_SENT); 212 SET_FLAG (head, FLAG_CLIENT_SENT);
197} 213}
198 214
199 215
200/** 216/**
201 * Send the look window. Don't need to do animations here 217 * Send the look window. Don't need to do animations here
202 * This sends all the faces to the client, not just updates. This is 218 * This sends all the faces to the client, not just updates. This is
203 * because object ordering would otherwise be inconsistent 219 * because object ordering would otherwise be inconsistent
204 */ 220 */
205 221
222void
206void esrv_draw_look(object *pl) 223esrv_draw_look (object *pl)
207{ 224{
208 object *tmp, *last; 225 object *tmp, *last;
209 int got_one=0,start_look=0, end_look=0; 226 int got_one = 0, start_look = 0, end_look = 0;
210 SockList sl; 227 SockList sl;
211 char buf[MAX_BUF]; 228 char buf[MAX_BUF];
212 229
213 if (!pl->contr->socket.update_look) { 230 if (!pl->contr->socket.update_look)
231 {
214 LOG(llevDebug,"esrv_draw_look called when update_look was not set\n"); 232 LOG (llevDebug, "esrv_draw_look called when update_look was not set\n");
215 return; 233 return;
216 } else { 234 }
235 else
236 {
217 pl->contr->socket.update_look=0; 237 pl->contr->socket.update_look = 0;
218 } 238 }
219 239
220 if(QUERY_FLAG(pl, FLAG_REMOVED) || pl->map == NULL || 240 if (QUERY_FLAG (pl, FLAG_REMOVED) || pl->map == NULL || pl->map->in_memory != MAP_IN_MEMORY || out_of_map (pl->map, pl->x, pl->y))
221 pl->map->in_memory != MAP_IN_MEMORY || out_of_map(pl->map,pl->x,pl->y))
222 return; 241 return;
223 242
224 if (pl->contr->transport)
225 for (tmp=pl->contr->transport->inv; tmp && tmp->above;tmp=tmp->above) ;
226 else
227 for (tmp=get_map_ob(pl->map,pl->x,pl->y); tmp && tmp->above;tmp=tmp->above) ; 243 for (tmp = get_map_ob (pl->map, pl->x, pl->y); tmp && tmp->above; tmp = tmp->above);
228 244
229 sl.buf= (unsigned char *) malloc(MAXSOCKBUF); 245 sl.buf = (unsigned char *) malloc (MAXSOCKBUF);
230 246
231 Write_String_To_Socket(&pl->contr->socket, "delinv 0", strlen("delinv 0")); 247 Write_String_To_Socket (&pl->contr->socket, "delinv 0", strlen ("delinv 0"));
232 sprintf((char*)sl.buf,"item%d ", pl->contr->socket.itemcmd); 248 sprintf ((char *) sl.buf, "item%d ", pl->contr->socket.itemcmd);
233 sl.len=strlen((char*)sl.buf); 249 sl.len = strlen ((char *) sl.buf);
234 250
235 SockList_AddInt(&sl, 0); 251 SockList_AddInt (&sl, 0);
236 252
237 if (!(pl->contr->socket.faces_sent[empty_face->number]&NS_FACESENT_FACE)) 253 if (!(pl->contr->socket.faces_sent[empty_face->number] & NS_FACESENT_FACE))
238 esrv_send_face(&pl->contr->socket, empty_face->number,0); 254 esrv_send_face (&pl->contr->socket, empty_face->number, 0);
239 255
240 if (pl->contr->socket.look_position) { 256 if (pl->contr->socket.look_position)
257 {
241 SockList_AddInt(&sl, 0x80000000 | (pl->contr->socket.look_position- NUM_LOOK_OBJECTS)); 258 SockList_AddInt (&sl, 0x80000000 | (pl->contr->socket.look_position - NUM_LOOK_OBJECTS));
242 SockList_AddInt(&sl, 0); 259 SockList_AddInt (&sl, 0);
243 SockList_AddInt(&sl, (uint32) -1); 260 SockList_AddInt (&sl, (uint32) - 1);
244 SockList_AddInt(&sl, empty_face->number); 261 SockList_AddInt (&sl, empty_face->number);
245 sprintf(buf,"Click here to see %d previous items", NUM_LOOK_OBJECTS); 262 sprintf (buf, "Click here to see %d previous items", NUM_LOOK_OBJECTS);
246 add_stringlen_to_sockbuf(buf, &sl); 263 add_stringlen_to_sockbuf (buf, &sl);
247 SockList_AddShort(&sl,0);
248 SockList_AddChar(&sl, 0);
249 SockList_AddInt(&sl, 0);
250 if (pl->contr->socket.itemcmd == 2)
251 SockList_AddShort(&sl, 0); 264 SockList_AddShort (&sl, 0);
265 SockList_AddChar (&sl, 0);
266 SockList_AddInt (&sl, 0);
267 if (pl->contr->socket.itemcmd == 2)
268 SockList_AddShort (&sl, 0);
252 } 269 }
253 270
254 if (pl->contr->transport) {
255 add_object_to_socklist(&pl->contr->socket, &sl, pl->contr->transport);
256 got_one++;
257 }
258
259 for (last=NULL; tmp!=last; tmp=tmp->below) { 271 for (last = NULL; tmp != last; tmp = tmp->below)
272 {
260 object *head; 273 object *head;
261 274
262 if (QUERY_FLAG(tmp, FLAG_IS_FLOOR) && !last) { 275 if (QUERY_FLAG (tmp, FLAG_IS_FLOOR) && !last)
276 {
263 last = tmp->below; /* assumes double floor mode */ 277 last = tmp->below; /* assumes double floor mode */
264 if (last && QUERY_FLAG(last, FLAG_IS_FLOOR)) 278 if (last && QUERY_FLAG (last, FLAG_IS_FLOOR))
265 last = last->below; 279 last = last->below;
266 } 280 }
267 if (LOOK_OBJ(tmp)) { 281 if (LOOK_OBJ (tmp))
282 {
268 if (++start_look < pl->contr->socket.look_position) continue; 283 if (++start_look < pl->contr->socket.look_position)
284 continue;
269 end_look++; 285 end_look++;
270 if (end_look > NUM_LOOK_OBJECTS) { 286 if (end_look > NUM_LOOK_OBJECTS)
287 {
271 /* What we basically do is make a 'fake' object - when the user applies it, 288 /* What we basically do is make a 'fake' object - when the user applies it,
272 * we notice the special tag the object has, and act accordingly. 289 * we notice the special tag the object has, and act accordingly.
273 */ 290 */
274 SockList_AddInt(&sl, 0x80000000 | (pl->contr->socket.look_position+ NUM_LOOK_OBJECTS)); 291 SockList_AddInt (&sl, 0x80000000 | (pl->contr->socket.look_position + NUM_LOOK_OBJECTS));
275 SockList_AddInt(&sl, 0); 292 SockList_AddInt (&sl, 0);
276 SockList_AddInt(&sl, (uint32) -1); 293 SockList_AddInt (&sl, (uint32) - 1);
277 SockList_AddInt(&sl, empty_face->number); 294 SockList_AddInt (&sl, empty_face->number);
278 sprintf(buf,"Click here to see next group of items"); 295 sprintf (buf, "Click here to see next group of items");
279 add_stringlen_to_sockbuf(buf, &sl); 296 add_stringlen_to_sockbuf (buf, &sl);
280 SockList_AddShort(&sl,0);
281 SockList_AddChar(&sl, 0);
282 SockList_AddInt(&sl, 0);
283 if (pl->contr->socket.itemcmd == 2)
284 SockList_AddShort(&sl, 0); 297 SockList_AddShort (&sl, 0);
285 break; 298 SockList_AddChar (&sl, 0);
286 } 299 SockList_AddInt (&sl, 0);
287 if (tmp->head) head = tmp->head; 300 if (pl->contr->socket.itemcmd == 2)
288 else head = tmp; 301 SockList_AddShort (&sl, 0);
302 break;
303 }
304 if (tmp->head)
305 head = tmp->head;
306 else
307 head = tmp;
289 308
290 add_object_to_socklist(&pl->contr->socket, &sl, head); 309 add_object_to_socklist (&pl->contr->socket, &sl, head);
291 got_one++; 310 got_one++;
292 311
293 if (sl.len >= (MAXSOCKBUF-MAXITEMLEN)) { 312 if (sl.len >= (MAXSOCKBUF - MAXITEMLEN))
313 {
294 Send_With_Handling(&pl->contr->socket, &sl); 314 Send_With_Handling (&pl->contr->socket, &sl);
295 sprintf((char*)sl.buf,"item%d ", pl->contr->socket.itemcmd); 315 sprintf ((char *) sl.buf, "item%d ", pl->contr->socket.itemcmd);
296 sl.len=strlen((char*)sl.buf); 316 sl.len = strlen ((char *) sl.buf);
297 SockList_AddInt(&sl, 0); 317 SockList_AddInt (&sl, 0);
298 got_one=0; 318 got_one = 0;
319 }
320 } /* If LOOK_OBJ() */
299 } 321 }
300 } /* If LOOK_OBJ() */
301 }
302 if (got_one) 322 if (got_one)
303 Send_With_Handling(&pl->contr->socket, &sl); 323 Send_With_Handling (&pl->contr->socket, &sl);
304 324
305 free(sl.buf); 325 free (sl.buf);
306} 326}
307 327
308/** 328/**
309 * Sends whole inventory. 329 * Sends whole inventory.
310 */ 330 */
331void
311void esrv_send_inventory(object *pl, object *op) 332esrv_send_inventory (object *pl, object *op)
312{ 333{
313 object *tmp; 334 object *tmp;
314 int got_one=0; 335 int got_one = 0;
315 SockList sl; 336 SockList sl;
316 337
317 sl.buf= (unsigned char *) malloc(MAXSOCKBUF); 338 sl.buf = (unsigned char *) malloc (MAXSOCKBUF);
318 339
319 sprintf((char*)sl.buf,"delinv %d", op->count); 340 sprintf ((char *) sl.buf, "delinv %d", op->count);
320 sl.len=strlen((char*)sl.buf); 341 sl.len = strlen ((char *) sl.buf);
342 Send_With_Handling (&pl->contr->socket, &sl);
343
344 sprintf ((char *) sl.buf, "item%d ", pl->contr->socket.itemcmd);
345 sl.len = strlen ((char *) sl.buf);
346
347 SockList_AddInt (&sl, op->count);
348
349 for (tmp = op->inv; tmp; tmp = tmp->below)
350 {
351 object *head;
352
353 if (tmp->head)
354 head = tmp->head;
355 else
356 head = tmp;
357
358 if (LOOK_OBJ (head))
359 {
360 add_object_to_socklist (&pl->contr->socket, &sl, head);
361
362 got_one++;
363
364 /* IT is possible for players to accumulate a huge amount of
365 * items (especially with some of the bags out there) to
366 * overflow the buffer. IF so, send multiple item commands.
367 */
368 if (sl.len >= (MAXSOCKBUF - MAXITEMLEN))
369 {
370 Send_With_Handling (&pl->contr->socket, &sl);
371 sprintf ((char *) sl.buf, "item%d ", pl->contr->socket.itemcmd);
372 sl.len = strlen ((char *) sl.buf);
373 SockList_AddInt (&sl, op->count);
374 got_one = 0;
375 }
376 } /* If LOOK_OBJ() */
377 }
378 if (got_one)
321 Send_With_Handling(&pl->contr->socket, &sl); 379 Send_With_Handling (&pl->contr->socket, &sl);
322
323 sprintf((char*)sl.buf,"item%d ", pl->contr->socket.itemcmd);
324 sl.len=strlen((char*)sl.buf);
325
326 SockList_AddInt(&sl, op->count);
327
328 for (tmp=op->inv; tmp; tmp=tmp->below) {
329 object *head;
330
331 if (tmp->head) head = tmp->head;
332 else head = tmp;
333
334 if (LOOK_OBJ(head)) {
335 add_object_to_socklist(&pl->contr->socket, &sl, head);
336
337 got_one++;
338
339 /* IT is possible for players to accumulate a huge amount of
340 * items (especially with some of the bags out there) to
341 * overflow the buffer. IF so, send multiple item commands.
342 */
343 if (sl.len >= (MAXSOCKBUF-MAXITEMLEN)) {
344 Send_With_Handling(&pl->contr->socket, &sl);
345 sprintf((char*)sl.buf,"item%d ", pl->contr->socket.itemcmd);
346 sl.len=strlen((char*)sl.buf);
347 SockList_AddInt(&sl, op->count);
348 got_one=0;
349 }
350 } /* If LOOK_OBJ() */
351 }
352 if (got_one)
353 Send_With_Handling(&pl->contr->socket, &sl);
354 free(sl.buf); 380 free (sl.buf);
355} 381}
356 382
357/** 383/**
358 * Updates object *op for player *pl. 384 * Updates object *op for player *pl.
359 * 385 *
360 * flags is a list of values to update 386 * flags is a list of values to update
361 * to the client (as defined in newclient.h - might as well use the 387 * to the client (as defined in newclient.h - might as well use the
362 * same value both places. 388 * same value both places.
363 */ 389 */
364 390
391void
365void esrv_update_item(int flags, object *pl, object *op) 392esrv_update_item (int flags, object *pl, object *op)
366{ 393{
367 SockList sl; 394 SockList sl;
368 395
369 /* If we have a request to send the player item, skip a few checks. */ 396 /* If we have a request to send the player item, skip a few checks. */
370 if (op!=pl) { 397 if (op != pl)
398 {
371 if (! LOOK_OBJ(op)) 399 if (!LOOK_OBJ (op))
372 return; 400 return;
373 /* we remove the check for op->env, because in theory, the object 401 /* we remove the check for op->env, because in theory, the object
374 * is hopefully in the same place, so the client should preserve 402 * is hopefully in the same place, so the client should preserve
375 * order. 403 * order.
376 */ 404 */
377 } 405 }
378 if (!QUERY_FLAG(op, FLAG_CLIENT_SENT)) { 406 if (!QUERY_FLAG (op, FLAG_CLIENT_SENT))
407 {
379 /* FLAG_CLIENT_SENT is debug only. We are using it to see where 408 /* FLAG_CLIENT_SENT is debug only. We are using it to see where
380 * this is happening - we can set a breakpoint here in the debugger 409 * this is happening - we can set a breakpoint here in the debugger
381 * and track back the call. 410 * and track back the call.
382 */ 411 */
383 LOG(llevDebug,"We have not sent item %s (%d)\n", op->name, op->count); 412 LOG (llevDebug, "We have not sent item %s (%d)\n", &op->name, op->count);
384 } 413 }
385 sl.buf= (unsigned char *) malloc(MAXSOCKBUF); 414 sl.buf = (unsigned char *) malloc (MAXSOCKBUF);
386 415
387 strcpy((char*)sl.buf,"upditem "); 416 strcpy ((char *) sl.buf, "upditem ");
388 sl.len=strlen((char*)sl.buf); 417 sl.len = strlen ((char *) sl.buf);
389 418
390 SockList_AddChar(&sl, (char) flags); 419 SockList_AddChar (&sl, (char) flags);
391 420
392 if (op->head) op=op->head; 421 if (op->head)
422 op = op->head;
393 423
394 SockList_AddInt(&sl, op->count); 424 SockList_AddInt (&sl, op->count);
395 425
396 if (flags & UPD_LOCATION) 426 if (flags & UPD_LOCATION)
397 SockList_AddInt(&sl, op->env? op->env->count:0); 427 SockList_AddInt (&sl, op->env ? op->env->count : 0);
398 428
399 if (flags & UPD_FLAGS) 429 if (flags & UPD_FLAGS)
400 SockList_AddInt(&sl, query_flags(op)); 430 SockList_AddInt (&sl, query_flags (op));
401 431
402 if (flags & UPD_WEIGHT) { 432 if (flags & UPD_WEIGHT)
433 {
403 sint32 weight = WEIGHT(op); 434 sint32 weight = WEIGHT (op);
404 435
405 /* TRANSPORTS are odd - they sort of look like containers, yet can't be
406 * picked up. So we don't to send the weight, as it is odd that you see
407 * weight sometimes and not other (the draw_look won't send it
408 * for example.
409 */
410 SockList_AddInt(&sl, QUERY_FLAG(op, FLAG_NO_PICK) ? -1 : weight); 436 SockList_AddInt (&sl, QUERY_FLAG (op, FLAG_NO_PICK) ? -1 : weight);
411 if (pl == op) { 437 if (pl == op)
438 {
412 op->contr->last_weight = weight; 439 op->contr->last_weight = weight;
413 } 440 }
414 } 441 }
415 442
416 if (flags & UPD_FACE) { 443 if (flags & UPD_FACE)
444 {
417 if (!(pl->contr->socket.faces_sent[op->face->number] & NS_FACESENT_FACE)) 445 if (!(pl->contr->socket.faces_sent[op->face->number] & NS_FACESENT_FACE))
418 esrv_send_face(&pl->contr->socket, op->face->number,0); 446 esrv_send_face (&pl->contr->socket, op->face->number, 0);
419 SockList_AddInt(&sl, op->face->number); 447 SockList_AddInt (&sl, op->face->number);
420 } 448 }
421 if (flags & UPD_NAME) { 449 if (flags & UPD_NAME)
422 int len; 450 {
451 int len;
423 const char *item_p; 452 const char *item_p;
424 char item_n[MAX_BUF]; 453 char item_n[MAX_BUF];
425 454
426 if (!op->custom_name) { 455 if (!op->custom_name)
456 {
427 strncpy(item_n,query_base_name(op, 0),127); 457 strncpy (item_n, query_base_name (op, 0), 127);
428 item_n[127]=0; 458 item_n[127] = 0;
429 len=strlen(item_n); 459 len = strlen (item_n);
430 item_p=query_base_name(op, 1); 460 item_p = query_base_name (op, 1);
431 } 461 }
432 else { 462 else
463 {
433 strncpy(item_n,op->custom_name,127); 464 strncpy (item_n, op->custom_name, 127);
434 item_n[127]=0; 465 item_n[127] = 0;
435 len=strlen(item_n); 466 len = strlen (item_n);
436 item_p=op->custom_name; 467 item_p = op->custom_name;
437 } 468 }
438 469
439 strncpy(item_n+len+1, item_p, 127); 470 strncpy (item_n + len + 1, item_p, 127);
440 item_n[254]=0; 471 item_n[254] = 0;
441 len += strlen(item_n+1+len) + 1; 472 len += strlen (item_n + 1 + len) + 1;
442 SockList_AddChar(&sl, (char)len); 473 SockList_AddChar (&sl, (char) len);
443 memcpy(sl.buf+sl.len, item_n, len); 474 memcpy (sl.buf + sl.len, item_n, len);
444 sl.len += len; 475 sl.len += len;
445 } 476 }
446 if (flags & UPD_ANIM) 477 if (flags & UPD_ANIM)
447 SockList_AddShort(&sl,op->animation_id); 478 SockList_AddShort (&sl, op->animation_id);
448 479
449 if (flags & UPD_ANIMSPEED) { 480 if (flags & UPD_ANIMSPEED)
481 {
450 int anim_speed=0; 482 int anim_speed = 0;
483
451 if (QUERY_FLAG(op,FLAG_ANIMATE)) { 484 if (QUERY_FLAG (op, FLAG_ANIMATE))
452 if (op->anim_speed) anim_speed=op->anim_speed; 485 {
453 else { 486 if (op->anim_speed)
454 if (FABS(op->speed)<0.001) anim_speed=255; 487 anim_speed = op->anim_speed;
455 else if (FABS(op->speed)>=1.0) anim_speed=1; 488 else
489 {
490 if (FABS (op->speed) < 0.001)
491 anim_speed = 255;
492 else if (FABS (op->speed) >= 1.0)
493 anim_speed = 1;
494 else
456 else anim_speed = (int) (1.0/FABS(op->speed)); 495 anim_speed = (int) (1.0 / FABS (op->speed));
496 }
497 if (anim_speed > 255)
498 anim_speed = 255;
499 }
500 SockList_AddChar (&sl, (char) anim_speed);
457 } 501 }
458 if (anim_speed>255) anim_speed=255;
459 }
460 SockList_AddChar(&sl, (char)anim_speed);
461 }
462 if (flags & UPD_NROF) 502 if (flags & UPD_NROF)
463 SockList_AddInt(&sl, op->nrof); 503 SockList_AddInt (&sl, op->nrof);
464 504
465 Send_With_Handling(&pl->contr->socket, &sl); 505 Send_With_Handling (&pl->contr->socket, &sl);
466 free(sl.buf); 506 free (sl.buf);
467} 507}
468 508
469/** 509/**
470 * Sends item's info to player. 510 * Sends item's info to player.
471 */ 511 */
512void
472void esrv_send_item(object *pl, object*op) 513esrv_send_item (object *pl, object *op)
473{ 514{
474 SockList sl; 515 SockList sl;
475 516
476 /* If this is not the player object, do some more checks */ 517 /* If this is not the player object, do some more checks */
477 if (op!=pl) { 518 if (op != pl)
519 {
478 /* We only send 'visibile' objects to the client */ 520 /* We only send 'visibile' objects to the client */
479 if (! LOOK_OBJ(op)) 521 if (!LOOK_OBJ (op))
480 return; 522 return;
481 /* if the item is on the ground, mark that the look needs to 523 /* if the item is on the ground, mark that the look needs to
482 * be updated. 524 * be updated.
483 */ 525 */
484 if (!op->env) { 526 if (!op->env)
527 {
485 pl->contr->socket.update_look=1; 528 pl->contr->socket.update_look = 1;
486 return; 529 return;
487 } 530 }
488 } 531 }
489 532
490 sl.buf= (unsigned char *) malloc(MAXSOCKBUF); 533 sl.buf = (unsigned char *) malloc (MAXSOCKBUF);
491 534
492 sprintf((char*)sl.buf,"item%d ", pl->contr->socket.itemcmd); 535 sprintf ((char *) sl.buf, "item%d ", pl->contr->socket.itemcmd);
493 sl.len=strlen((char*)sl.buf); 536 sl.len = strlen ((char *) sl.buf);
494 537
495 if (op->head) op=op->head; 538 if (op->head)
539 op = op->head;
496 540
497 SockList_AddInt(&sl, op->env? op->env->count:0); 541 SockList_AddInt (&sl, op->env ? op->env->count : 0);
498 542
499 add_object_to_socklist(&pl->contr->socket, &sl, op); 543 add_object_to_socklist (&pl->contr->socket, &sl, op);
500 544
501 Send_With_Handling(&pl->contr->socket, &sl); 545 Send_With_Handling (&pl->contr->socket, &sl);
502 SET_FLAG(op, FLAG_CLIENT_SENT); 546 SET_FLAG (op, FLAG_CLIENT_SENT);
503 free(sl.buf); 547 free (sl.buf);
504} 548}
505 549
506/** 550/**
507 * Tells the client to delete an item. Uses the item 551 * Tells the client to delete an item. Uses the item
508 * command with a -1 location. 552 * command with a -1 location.
509 */ 553 */
510 554
555void
511void esrv_del_item(player *pl, int tag) 556esrv_del_item (player *pl, int tag)
512{ 557{
513 SockList sl; 558 SockList sl;
514 559
515 sl.buf= (unsigned char *) malloc(MAXSOCKBUF); 560 sl.buf = (unsigned char *) malloc (MAXSOCKBUF);
516 561
517 strcpy((char*)sl.buf,"delitem "); 562 strcpy ((char *) sl.buf, "delitem ");
518 sl.len=strlen((char*)sl.buf); 563 sl.len = strlen ((char *) sl.buf);
519 SockList_AddInt(&sl, tag); 564 SockList_AddInt (&sl, tag);
520 565
521 Send_With_Handling(&pl->socket, &sl); 566 Send_With_Handling (&pl->socket, &sl);
522 free(sl.buf); 567 free (sl.buf);
523} 568}
524 569
525 570
526/******************************************************************************* 571/*******************************************************************************
527 * 572 *
532/** 577/**
533 * Takes a player and object count (tag) and returns the actual object 578 * Takes a player and object count (tag) and returns the actual object
534 * pointer, or null if it can't be found. 579 * pointer, or null if it can't be found.
535 */ 580 */
536 581
582object *
537object *esrv_get_ob_from_count(object *pl, tag_t count) 583esrv_get_ob_from_count (object *pl, tag_t count)
538{ 584{
539 object *op, *tmp; 585 object *op, *tmp;
540 586
541 if (pl->count == count) 587 if (pl->count == count)
542 return pl; 588 return pl;
543 589
544 for(op = pl->inv; op; op = op->below) 590 for (op = pl->inv; op; op = op->below)
545 if (op->count == count) 591 if (op->count == count)
546 return op; 592 return op;
547 else if (op->type == CONTAINER && pl->container == op) 593 else if (op->type == CONTAINER && pl->container == op)
548 for(tmp = op->inv; tmp; tmp = tmp->below) 594 for (tmp = op->inv; tmp; tmp = tmp->below)
549 if (tmp->count == count) 595 if (tmp->count == count)
550 return tmp; 596 return tmp;
551 597
552 for(op = get_map_ob (pl->map, pl->x, pl->y); op; op = op->above) 598 for (op = get_map_ob (pl->map, pl->x, pl->y); op; op = op->above)
553 if (op->head != NULL && op->head->count == count) 599 if (op->head != NULL && op->head->count == count)
554 return op; 600 return op;
555 else if (op->count == count) 601 else if (op->count == count)
556 return op; 602 return op;
557 else if (op->type == CONTAINER && pl->container == op) 603 else if (op->type == CONTAINER && pl->container == op)
558 for(tmp = op->inv; tmp; tmp = tmp->below) 604 for (tmp = op->inv; tmp; tmp = tmp->below)
559 if (tmp->count == count)
560 return tmp;
561
562 if (pl->contr->transport) {
563 for(tmp = pl->contr->transport->inv; tmp; tmp = tmp->below)
564 if (tmp->count == count) 605 if (tmp->count == count)
565 return tmp; 606 return tmp;
566 } 607
567 return NULL; 608 return NULL;
568} 609}
569 610
570 611
571/** Client wants to examine some object. So lets do so. */ 612/** Client wants to examine some object. So lets do so. */
613void
572void ExamineCmd(char *buf, int len,player *pl) 614ExamineCmd (char *buf, int len, player *pl)
573{ 615{
574 long tag = atoi(buf); 616 long tag = atoi (buf);
575 object *op = esrv_get_ob_from_count(pl->ob, tag); 617 object *op = esrv_get_ob_from_count (pl->ob, tag);
576 618
577 if (!op) { 619 if (!op)
620 {
578 LOG(llevDebug, "Player '%s' tried to examine the unknown object (%ld)\n", 621 LOG (llevDebug, "Player '%s' tried to examine the unknown object (%ld)\n", &pl->ob->name, tag);
579 pl->ob->name, tag); 622 return;
580 return;
581 } 623 }
582 examine (pl->ob, op); 624 examine (pl->ob, op);
583} 625}
584 626
585/** Client wants to apply some object. Lets do so. */ 627/** Client wants to apply some object. Lets do so. */
628void
586void ApplyCmd(char *buf, int len,player *pl) 629ApplyCmd (char *buf, int len, player *pl)
587{ 630{
588 uint32 tag = atoi(buf); 631 uint32 tag = atoi (buf);
589 object *op = esrv_get_ob_from_count(pl->ob, tag); 632 object *op = esrv_get_ob_from_count (pl->ob, tag);
590 633
591 /* sort of a hack, but if the player saves and the player then manually 634 /* sort of a hack, but if the player saves and the player then manually
592 * applies a savebed (or otherwise tries to do stuff), we run into trouble. 635 * applies a savebed (or otherwise tries to do stuff), we run into trouble.
593 */ 636 */
594 if (QUERY_FLAG(pl->ob, FLAG_REMOVED)) return; 637 if (QUERY_FLAG (pl->ob, FLAG_REMOVED))
638 return;
595 639
596 /* If the high bit is set, player applied a pseudo object. */ 640 /* If the high bit is set, player applied a pseudo object. */
597 if (tag & 0x80000000) { 641 if (tag & 0x80000000)
642 {
598 pl->socket.look_position = tag & 0x7fffffff; 643 pl->socket.look_position = tag & 0x7fffffff;
599 pl->socket.update_look = 1; 644 pl->socket.update_look = 1;
600 return; 645 return;
601 } 646 }
602 647
603 if (!op) { 648 if (!op)
649 {
604 LOG(llevDebug, "Player '%s' tried to apply the unknown object (%d)\n", 650 LOG (llevDebug, "Player '%s' tried to apply the unknown object (%d)\n", &pl->ob->name, tag);
605 pl->ob->name, tag); 651 return;
606 return;
607 } 652 }
608 player_apply (pl->ob, op, 0, 0); 653 player_apply (pl->ob, op, 0, 0);
609} 654}
610 655
611/** Client wants to apply some object. Lets do so. */ 656/** Client wants to apply some object. Lets do so. */
657void
612void LockItem(uint8 *data, int len,player *pl) 658LockItem (uint8 * data, int len, player *pl)
613{ 659{
614 int flag, tag; 660 int flag, tag;
615 object *op; 661 object *op;
616 662
617 flag = data[0]; 663 flag = data[0];
618 tag = GetInt_String(data+1); 664 tag = GetInt_String (data + 1);
619 op = esrv_get_ob_from_count(pl->ob, tag); 665 op = esrv_get_ob_from_count (pl->ob, tag);
620 666
621 if (!op) { 667 if (!op)
668 {
622 new_draw_info(NDI_UNIQUE, 0, pl->ob,"Could not find object to lock/unlock"); 669 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Could not find object to lock/unlock");
623 return; 670 return;
624 } 671 }
625 if (!flag) 672 if (!flag)
626 CLEAR_FLAG(op,FLAG_INV_LOCKED); 673 CLEAR_FLAG (op, FLAG_INV_LOCKED);
627 else 674 else
628 SET_FLAG(op,FLAG_INV_LOCKED); 675 SET_FLAG (op, FLAG_INV_LOCKED);
629 esrv_update_item(UPD_FLAGS, pl->ob, op); 676 esrv_update_item (UPD_FLAGS, pl->ob, op);
630} 677}
631 678
632/** Client wants to apply some object. Lets do so. */ 679/** Client wants to apply some object. Lets do so. */
680void
633void MarkItem(uint8 *data, int len,player *pl) 681MarkItem (uint8 * data, int len, player *pl)
634{ 682{
635 int tag; 683 int tag;
636 object *op; 684 object *op;
637 685
638 tag = GetInt_String(data); 686 tag = GetInt_String (data);
639 op = esrv_get_ob_from_count(pl->ob, tag); 687 op = esrv_get_ob_from_count (pl->ob, tag);
640 if (!op) { 688 if (!op)
689 {
641 new_draw_info(NDI_UNIQUE, 0, pl->ob,"Could not find object to mark"); 690 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Could not find object to mark");
642 return; 691 return;
643 } 692 }
644 pl->mark = op; 693 pl->mark = op;
645 pl->mark_count = op->count; 694 pl->mark_count = op->count;
646 new_draw_info_format(NDI_UNIQUE, 0, pl->ob, "Marked item %s", query_name(op)); 695 new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "Marked item %s", query_name (op));
647} 696}
648 697
649 698
650/** 699/**
651 * look_at prints items on the specified square. 700 * look_at prints items on the specified square.
652 * 701 *
653 * [ removed EARTHWALL check and added check for containers inventory. 702 * [ removed EARTHWALL check and added check for containers inventory.
654 * Tero.Haatanen@lut.fi ] 703 * Tero.Haatanen@lut.fi ]
655 */ 704 */
705void
656void look_at(object *op,int dx,int dy) { 706look_at (object *op, int dx, int dy)
707{
657 object *tmp; 708 object *tmp;
658 int flag=0; 709 int flag = 0;
659 sint16 x,y; 710 sint16 x, y;
660 mapstruct *m; 711 mapstruct *m;
661 712
662 x = op->x + dx; 713 x = op->x + dx;
663 y = op->y + dy; 714 y = op->y + dy;
664 715
665 if (out_of_map(op->map, x, y)) return; 716 if (out_of_map (op->map, x, y))
717 return;
666 718
667 m = get_map_from_coord(op->map, &x, &y); 719 m = get_map_from_coord (op->map, &x, &y);
668 if (!m) return; 720 if (!m)
721 return;
669 722
670 for(tmp=get_map_ob(m, x ,y);tmp!=NULL&&tmp->above!=NULL; 723 for (tmp = get_map_ob (m, x, y); tmp != NULL && tmp->above != NULL; tmp = tmp->above);
671 tmp=tmp->above);
672 724
673 for ( ; tmp != NULL; tmp=tmp->below ) { 725 for (; tmp != NULL; tmp = tmp->below)
726 {
674 if (tmp->invisible && !QUERY_FLAG(op, FLAG_WIZ)) continue; 727 if (tmp->invisible && !QUERY_FLAG (op, FLAG_WIZ))
728 continue;
675 729
676 if(!flag) { 730 if (!flag)
677 if(dx||dy) 731 {
732 if (dx || dy)
678 new_draw_info(NDI_UNIQUE, 0,op,"There you see:"); 733 new_draw_info (NDI_UNIQUE, 0, op, "There you see:");
679 else { 734 else
680 clear_win_info(op); 735 {
736 clear_win_info (op);
681 new_draw_info(NDI_UNIQUE, 0,op,"You see:"); 737 new_draw_info (NDI_UNIQUE, 0, op, "You see:");
682 } 738 }
683 flag=1; 739 flag = 1;
684 } 740 }
685 741
686 if (QUERY_FLAG(op, FLAG_WIZ)) 742 if (QUERY_FLAG (op, FLAG_WIZ))
687 new_draw_info_format(NDI_UNIQUE,0, op, "- %s (%d).",query_name(tmp),tmp->count); 743 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s (%d).", query_name (tmp), tmp->count);
688 else 744 else
689 new_draw_info_format(NDI_UNIQUE,0, op, "- %s.",query_name(tmp)); 745 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s.", query_name (tmp));
690 746
691 if (((tmp->inv!=NULL || (tmp->head && tmp->head->inv)) && 747 if (((tmp->inv != NULL || (tmp->head && tmp->head->inv)) &&
692 (tmp->type != CONTAINER && tmp->type!=FLESH)) || QUERY_FLAG(op, FLAG_WIZ)) 748 (tmp->type != CONTAINER && tmp->type != FLESH)) || QUERY_FLAG (op, FLAG_WIZ))
693 inventory(op,tmp->head==NULL?tmp:tmp->head); 749 inventory (op, tmp->head == NULL ? tmp : tmp->head);
694 750
695 if(QUERY_FLAG(tmp, FLAG_IS_FLOOR)&&!QUERY_FLAG(op, FLAG_WIZ)) /* don't continue under the floor */ 751 if (QUERY_FLAG (tmp, FLAG_IS_FLOOR) && !QUERY_FLAG (op, FLAG_WIZ)) /* don't continue under the floor */
696 break; 752 break;
697 } 753 }
698 754
699 if(!flag) { 755 if (!flag)
700 if(dx||dy) 756 {
757 if (dx || dy)
701 new_draw_info(NDI_UNIQUE, 0,op,"You see nothing there."); 758 new_draw_info (NDI_UNIQUE, 0, op, "You see nothing there.");
702 else 759 else
703 new_draw_info(NDI_UNIQUE, 0,op,"You see nothing."); 760 new_draw_info (NDI_UNIQUE, 0, op, "You see nothing.");
704 } 761 }
705} 762}
706 763
707 764
708 765
709/** Client wants to look at some object. Lets do so. */ 766/** Client wants to look at some object. Lets do so. */
767void
710void LookAt(char *buf, int len,player *pl) 768LookAt (char *buf, int len, player *pl)
711{ 769{
712 int dx, dy; 770 int dx, dy;
713 char *cp; 771 char *cp;
714 772
715 dx=atoi(buf); 773 dx = atoi (buf);
716 if (!(cp=strchr(buf,' '))) { 774 if (!(cp = strchr (buf, ' ')))
717 return;
718 } 775 {
776 return;
777 }
719 dy=atoi(cp); 778 dy = atoi (cp);
720 779
721 if (FABS(dx) > pl->socket.mapx / 2 || FABS(dy) > pl->socket.mapy / 2) 780 if (FABS (dx) > pl->socket.mapx / 2 || FABS (dy) > pl->socket.mapy / 2)
781 return;
782
783 if (pl->blocked_los[dx + pl->socket.mapx / 2][dy + pl->socket.mapy / 2])
784 return;
785
786 look_at (pl->ob, dx, dy);
787}
788
789/** Move an object to a new location */
790void
791esrv_move_object (object *pl, tag_t to, tag_t tag, long nrof)
792{
793 object *op, *env;
794
795 op = esrv_get_ob_from_count (pl, tag);
796 if (!op)
797 {
798 LOG (llevDebug, "Player '%s' tried to move an unknown object (%ld)\n", &pl->name, tag);
799 return;
800 }
801
802 if (!to)
803 { /* drop it to the ground */
804
805/* LOG(llevDebug, "Drop it on the ground.\n");*/
806
807 if (op->map && !op->env)
808 {
809
810/* LOG(llevDebug,"Dropping object to ground that is already on ground\n");*/
722 return; 811 return;
723 812 }
724 if(pl->blocked_los[dx + pl->socket.mapx / 2][dy + pl->socket.mapy / 2])
725 return;
726
727 look_at(pl->ob, dx, dy);
728}
729
730/** Move an object to a new location */
731void esrv_move_object (object *pl, tag_t to, tag_t tag, long nrof)
732{
733 object *op, *env;
734
735 op = esrv_get_ob_from_count(pl, tag);
736 if (!op) {
737 LOG(llevDebug, "Player '%s' tried to move an unknown object (%ld)\n",
738 pl->name, tag);
739 return;
740 }
741
742 /* If on a transport, you don't drop to the ground - you drop to the
743 * transport.
744 */
745 if (!to && !pl->contr->transport) { /* drop it to the ground */
746/* LOG(llevDebug, "Drop it on the ground.\n");*/
747
748 if (op->map && !op->env) {
749/* LOG(llevDebug,"Dropping object to ground that is already on ground\n");*/
750 return;
751 }
752 /* If it is an active container, then we should drop all objects 813 /* If it is an active container, then we should drop all objects
753 * in the container and not the container itself. 814 * in the container and not the container itself.
754 */ 815 */
755 if (op->inv && QUERY_FLAG(op, FLAG_APPLIED)) { 816 if (op->inv && QUERY_FLAG (op, FLAG_APPLIED))
817 {
756 object *current, *next; 818 object *current, *next;
819
757 for (current=op->inv; current!=NULL; current=next) { 820 for (current = op->inv; current != NULL; current = next)
758 next=current->below; 821 {
822 next = current->below;
759 drop_object(pl, current, 0); 823 drop_object (pl, current, 0);
760 } 824 }
761 esrv_update_item(UPD_WEIGHT, pl, op); 825 esrv_update_item (UPD_WEIGHT, pl, op);
762 } 826 }
763 else { 827 else
828 {
764 drop_object (pl, op, nrof); 829 drop_object (pl, op, nrof);
765 } 830 }
766 return; 831 return;
767 } else if (to == pl->count) { /* pick it up to the inventory */ 832 }
833 else if (to == pl->count)
834 { /* pick it up to the inventory */
768 /* return if player has already picked it up */ 835 /* return if player has already picked it up */
769 if (op->env == pl) return; 836 if (op->env == pl)
837 return;
770 838
771 pl->contr->count = nrof; 839 pl->contr->count = nrof;
772 pick_up(pl, op); 840 pick_up (pl, op);
773 return ; 841 return;
774 } 842 }
775 /* If not dropped or picked up, we are putting it into a sack */
776 if (pl->contr->transport) {
777 if (can_pick(pl, op) && transport_can_hold(pl->contr->transport, op, nrof)) {
778 put_object_in_sack (pl, pl->contr->transport, op, nrof);
779 }
780 } else {
781 env = esrv_get_ob_from_count(pl, to); 843 env = esrv_get_ob_from_count (pl, to);
782 if (!env) { 844 if (!env)
783 LOG(llevDebug, 845 {
784 "Player '%s' tried to move object to the unknown location (%d)\n", 846 LOG (llevDebug, "Player '%s' tried to move object to the unknown location (%d)\n", &pl->name, to);
785 pl->name, to);
786 return; 847 return;
787 } 848 }
788 /* put_object_in_sack presumes that necessary sanity checking 849 /* put_object_in_sack presumes that necessary sanity checking
789 * has already been done (eg, it can be picked up and fits in 850 * has already been done (eg, it can be picked up and fits in
790 * in a sack, so check for those things. We should also check 851 * in a sack, so check for those things. We should also check
791 * an make sure env is in fact a container for that matter. 852 * an make sure env is in fact a container for that matter.
792 */ 853 */
793 if (env->type == CONTAINER
794 && can_pick(pl, op) && sack_can_hold(pl, env, op, nrof)) { 854 if (env->type == CONTAINER && can_pick (pl, op) && sack_can_hold (pl, env, op, nrof))
855 {
795 put_object_in_sack (pl, env, op, nrof); 856 put_object_in_sack (pl, env, op, nrof);
796 }
797 } 857 }
798} 858}
799
800

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines