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.59 by root, Tue Apr 22 02:46:18 2008 UTC vs.
Revision 1.63 by root, Thu Apr 24 00:30:52 2008 UTC

193query_flags (object *op) 193query_flags (object *op)
194{ 194{
195 unsigned int flags = 0; 195 unsigned int flags = 0;
196 196
197 if (QUERY_FLAG (op, FLAG_APPLIED)) 197 if (QUERY_FLAG (op, FLAG_APPLIED))
198 {
199 switch (op->type) 198 switch (op->type)
200 { 199 {
201 case BOW: 200 case BOW:
202 case WAND: 201 case WAND:
203 case ROD: 202 case ROD:
204 case HORN: 203 case HORN:
205 flags = a_readied; 204 flags = a_readied;
206 break; 205 break;
207 case WEAPON: 206 case WEAPON:
208 flags = a_wielded; 207 flags = a_wielded;
209 break; 208 break;
210 case SKILL: 209 case SKILL:
211 case ARMOUR: 210 case ARMOUR:
212 case HELMET: 211 case HELMET:
213 case SHIELD: 212 case SHIELD:
214 case RING: 213 case RING:
215 case BOOTS: 214 case BOOTS:
216 case GLOVES: 215 case GLOVES:
217 case AMULET: 216 case AMULET:
218 case GIRDLE: 217 case GIRDLE:
219 case BRACERS: 218 case BRACERS:
220 case CLOAK: 219 case CLOAK:
221 flags = a_worn; 220 flags = a_worn;
222 break; 221 break;
223 case CONTAINER: 222 case CONTAINER:
224 flags = a_active; 223 flags = a_active;
225 break; 224 break;
226 default: 225 default:
227 flags = a_applied; 226 flags = a_applied;
228 break; 227 break;
229 } 228 }
230 }
231 229
232 if (op->type == CONTAINER && ((op->env && op->env->container == op) || (!op->env && QUERY_FLAG (op, FLAG_APPLIED)))) 230 if (op->type == CONTAINER && ((op->env && op->env->container == op) || (!op->env && QUERY_FLAG (op, FLAG_APPLIED))))
233 flags |= F_OPEN; 231 flags |= F_OPEN;
234 232
235 if (QUERY_FLAG (op, FLAG_KNOWN_CURSED)) 233 if (QUERY_FLAG (op, FLAG_KNOWN_CURSED))
271 if (QUERY_FLAG (head, FLAG_ANIMATE) && !ns.anims_sent[head->animation_id]) 269 if (QUERY_FLAG (head, FLAG_ANIMATE) && !ns.anims_sent[head->animation_id])
272 ns.send_animation (head->animation_id); 270 ns.send_animation (head->animation_id);
273 271
274 sl << uint32 (head->count) 272 sl << uint32 (head->count)
275 << uint32 (flags) 273 << uint32 (flags)
276 << uint32 (QUERY_FLAG (head, FLAG_NO_PICK) ? -1 : WEIGHT (head)) 274 << uint32 (QUERY_FLAG (head, FLAG_NO_PICK) ? -1 : head->client_weight ())
277 << uint32 (head->face); 275 << uint32 (head->face);
278 276
279 if (!head->custom_name) 277 if (!head->custom_name)
280 { 278 {
281 strncpy (item_n, query_base_name (head, 0), 127); 279 strncpy (item_n, query_base_name (head, 0), 127);
341 if (!pl->ns->update_look) 339 if (!pl->ns->update_look)
342 { 340 {
343 LOG (llevDebug, "esrv_draw_look called when update_look was not set (player %s)\n", &ob->name); 341 LOG (llevDebug, "esrv_draw_look called when update_look was not set (player %s)\n", &ob->name);
344 return; 342 return;
345 } 343 }
346 else 344
347 pl->ns->update_look = 0; 345 pl->ns->update_look = 0;
348 346
349 if (QUERY_FLAG (ob, FLAG_REMOVED) 347 if (QUERY_FLAG (ob, FLAG_REMOVED)
350 || !ob->map 348 || !ob->map
351 || ob->map->in_memory != MAP_ACTIVE 349 || ob->map->in_memory != MAP_ACTIVE
352 || out_of_map (ob->map, ob->x, ob->y)) 350 || out_of_map (ob->map, ob->x, ob->y))
381 } 379 }
382 380
383 object *tmp = ob->ms ().top; 381 object *tmp = ob->ms ().top;
384 for (object *last = 0; tmp != last; tmp = tmp->below) 382 for (object *last = 0; tmp != last; tmp = tmp->below)
385 { 383 {
386 object *head;
387
388 if (QUERY_FLAG (tmp, FLAG_IS_FLOOR) && !last) 384 if (QUERY_FLAG (tmp, FLAG_IS_FLOOR) && !last)
389 { 385 {
390 last = tmp->below; /* assumes double floor mode */ 386 last = tmp->below; /* assumes double floor mode */
391 if (last && QUERY_FLAG (last, FLAG_IS_FLOOR)) 387 if (last && QUERY_FLAG (last, FLAG_IS_FLOOR))
392 last = last->below; 388 last = last->below;
417 sl << uint16 (0); 413 sl << uint16 (0);
418 414
419 break; 415 break;
420 } 416 }
421 417
422 if (tmp->head)
423 head = tmp->head;
424 else
425 head = tmp;
426
427 add_object_to_socklist (*pl->ns, sl, head); 418 add_object_to_socklist (*pl->ns, sl, tmp->head_ ());
428 got_one++; 419 got_one++;
429 420
430 if (sl.length () > MAXSOCKBUF - MAXITEMLEN) 421 if (sl.length () > MAXSOCKBUF - MAXITEMLEN)
431 { 422 {
432 pl->ns->send_packet (sl); 423 pl->ns->send_packet (sl);
506 */ 497 */
507void 498void
508esrv_update_item (int flags, object *pl, object *op) 499esrv_update_item (int flags, object *pl, object *op)
509{ 500{
510 /* If we have a request to send the player item, skip a few checks. */ 501 /* If we have a request to send the player item, skip a few checks. */
511 if (op != pl)
512 {
513 if (!op->client_visible ()) 502 if (op != pl && !op->client_visible ())
514 return; 503 return;
515 /* we remove the check for op->env, because in theory, the object
516 * is hopefully in the same place, so the client should preserve
517 * order.
518 */
519 }
520 504
521 client *ns = pl->contr->ns; 505 client *ns = pl->contr->ns;
522 if (!ns) 506 if (!ns)
523 return; 507 return;
524 508
533 517
534 packet sl ("upditem"); 518 packet sl ("upditem");
535 519
536 sl << uint8 (flags); 520 sl << uint8 (flags);
537 521
538 if (op->head)
539 op = op->head; 522 op = op->head_ ();
540 523
541 sl << uint32 (op->count); 524 sl << uint32 (op->count);
542 525
543 if (flags & UPD_LOCATION) 526 if (flags & UPD_LOCATION)
544 sl << uint32 (op->env ? op->env->count : 0); 527 sl << uint32 (op->env ? op->env->count : 0);
546 if (flags & UPD_FLAGS) 529 if (flags & UPD_FLAGS)
547 sl << uint32 (query_flags (op)); 530 sl << uint32 (query_flags (op));
548 531
549 if (flags & UPD_WEIGHT) 532 if (flags & UPD_WEIGHT)
550 { 533 {
551 sint32 weight = WEIGHT (op); 534 sint32 weight = op->flag [FLAG_NO_PICK] ? -1 : op->client_weight ();
552 535
553 sl << uint32 (QUERY_FLAG (op, FLAG_NO_PICK) ? -1 : weight);
554
555 if (pl == op) 536 if (op)
556 ns->last_weight = weight; 537 ns->last_weight = weight;
538
539 sl << uint32 (weight);
557 } 540 }
558 541
559 if (flags & UPD_FACE) 542 if (flags & UPD_FACE)
560 { 543 {
561 ns->send_face (op->face, -50); 544 ns->send_face (op->face, -50);
632esrv_send_item (object *pl, object *op) 615esrv_send_item (object *pl, object *op)
633{ 616{
634 if (!pl->contr->ns) 617 if (!pl->contr->ns)
635 return; 618 return;
636 619
637 /* If this is not the player object, do some more checks */
638 if (op != pl)
639 {
640 /* We only send 'visibile' objects to the client */ 620 /* We only send 'visible' objects to the client, and sometimes the player */
641 if (!op->client_visible ()) 621 if (!op->client_visible () && op->type != PLAYER)
642 return; 622 return;
643
644 /* if the item is on the ground, mark that the look needs to
645 * be updated.
646 */
647 if (!op->env)
648 {
649 pl->contr->ns->floorbox_update ();
650 return;
651 }
652 }
653 623
654 packet sl; 624 packet sl;
655 625
656 sl.printf ("item%d ", pl->contr->ns->itemcmd); 626 sl.printf ("item%d ", pl->contr->ns->itemcmd);
657 627
658 if (op->head)
659 op = op->head; 628 op = op->head_ ();
660 629
661 sl << uint32 (op->env ? op->env->count : 0); 630 sl << uint32 (op->env ? op->env->count : 0);
662 631
663 add_object_to_socklist (*pl->contr->ns, sl, op); 632 add_object_to_socklist (*pl->contr->ns, sl, op);
664 633
922 /* If it is an active container, then we should drop all objects 891 /* If it is an active container, then we should drop all objects
923 * in the container and not the container itself. 892 * in the container and not the container itself.
924 */ 893 */
925 if (op->inv && QUERY_FLAG (op, FLAG_APPLIED)) 894 if (op->inv && QUERY_FLAG (op, FLAG_APPLIED))
926 { 895 {
927 object *current, *next;
928
929 int cnt = MAX_ITEM_PER_DROP; 896 int cnt = MAX_ITEM_PER_DROP;
930 897
931 for (current = op->inv; current != NULL; current = next) 898 for (object *current = op->inv; current; )
932 { 899 {
933 next = current->below; 900 object *next = current->below;
901
934 drop_object (pl, current, 0); 902 drop_object (pl, current, 0);
935 903
936 if (--cnt <= 0) break; 904 if (--cnt <= 0) break;
905
906 current = next;
937 } 907 }
938 908
939 if (cnt <= 0) 909 if (cnt <= 0)
940 op->failmsg ("Only dropped some items, can't drop that many items at once."); 910 op->failmsg ("Only dropped some items, can't drop that many items at once.");
941
942 esrv_update_item (UPD_WEIGHT, pl, op);
943 } 911 }
944 else 912 else
945 drop_object (pl, op, nrof); 913 drop_object (pl, op, nrof);
946
947 update_after_inventory_change (pl);
948 914
949 return; 915 return;
950 } 916 }
951 else if (to == pl->count) 917 else if (to == pl->count)
952 { /* pick it up to the inventory */ 918 { /* pick it up to the inventory */
969 /* put_object_in_sack presumes that necessary sanity checking 935 /* put_object_in_sack presumes that necessary sanity checking
970 * has already been done (eg, it can be picked up and fits in 936 * has already been done (eg, it can be picked up and fits in
971 * in a sack, so check for those things. We should also check 937 * in a sack, so check for those things. We should also check
972 * an make sure env is in fact a container for that matter. 938 * an make sure env is in fact a container for that matter.
973 */ 939 */
974 if (env->type == CONTAINER && can_pick (pl, op) && sack_can_hold (pl, env, op, nrof)) 940 if (env->type == CONTAINER
975 { 941 && can_pick (pl, op)
942 && sack_can_hold (pl, env, op, nrof))
976 put_object_in_sack (pl, env, op, nrof); 943 put_object_in_sack (pl, env, op, nrof);
977 update_after_inventory_change (pl);
978 }
979} 944}
980 945

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines