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.56 by elmex, Mon Nov 26 11:41:02 2007 UTC vs.
Revision 1.63 by root, Thu Apr 24 00:30:52 2008 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
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_IN_MEMORY 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))
353 return; 351 return;
354 352
355 pl->ns->send_packet ("delinv 0"); 353 pl->ns->send_packet ("delinv 0");
356 354
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
665 pl->contr->ns->send_packet (sl); 634 pl->contr->ns->send_packet (sl);
666 SET_FLAG (op, FLAG_CLIENT_SENT); 635 SET_FLAG (op, FLAG_CLIENT_SENT);
667} 636}
668 637
669/** 638/**
670 * Tells the client to delete an item. Uses the item 639 * Tells the client to delete an item.
671 * command with a -1 location.
672 */ 640 */
673void 641void
674esrv_del_item (player *pl, int tag) 642esrv_del_item (player *pl, int tag)
675{ 643{
676 if (!pl->ns) 644 if (!pl->ns)
800 tag_t tag = net_uint32 ((uint8 *)data + 1); 768 tag_t tag = net_uint32 ((uint8 *)data + 1);
801 object *op = esrv_get_ob_from_count (pl->ob, tag); 769 object *op = esrv_get_ob_from_count (pl->ob, tag);
802 770
803 if (!op) 771 if (!op)
804 { 772 {
805 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Could not find object to lock/unlock"); 773 pl->failmsg ("Could not find object to lock/unlock");
806 return; 774 return;
807 } 775 }
808 776
809 if (!flag) 777 if (!flag)
810 CLEAR_FLAG (op, FLAG_INV_LOCKED); 778 CLEAR_FLAG (op, FLAG_INV_LOCKED);
821 tag_t tag = net_uint32 ((uint8 *)data); 789 tag_t tag = net_uint32 ((uint8 *)data);
822 object *op = esrv_get_ob_from_count (pl->ob, tag); 790 object *op = esrv_get_ob_from_count (pl->ob, tag);
823 791
824 if (!op) 792 if (!op)
825 { 793 {
826 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Could not find object to mark"); 794 pl->failmsg ("Could not find object to mark");
827 return; 795 return;
828 } 796 }
829 797
830 pl->mark = op; 798 pl->mark = op;
831 new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "Marked item %s", query_name (op)); 799 pl->ob->statusmsg (format ("Marked item %s", query_name (op)));
832} 800}
833 801
834/** 802/**
835 * look_at prints items on the specified square. 803 * look_at prints items on the specified square.
836 * 804 *
923 /* 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
924 * in the container and not the container itself. 892 * in the container and not the container itself.
925 */ 893 */
926 if (op->inv && QUERY_FLAG (op, FLAG_APPLIED)) 894 if (op->inv && QUERY_FLAG (op, FLAG_APPLIED))
927 { 895 {
928 object *current, *next;
929
930 int cnt = MAX_ITEM_PER_DROP; 896 int cnt = MAX_ITEM_PER_DROP;
931 897
932 for (current = op->inv; current != NULL; current = next) 898 for (object *current = op->inv; current; )
933 { 899 {
934 next = current->below; 900 object *next = current->below;
901
935 drop_object (pl, current, 0); 902 drop_object (pl, current, 0);
936 903
937 if (--cnt <= 0) break; 904 if (--cnt <= 0) break;
905
906 current = next;
938 } 907 }
939 908
940 if (cnt <= 0) 909 if (cnt <= 0)
941 pl->failmsg (format ( 910 op->failmsg ("Only dropped some items, can't drop that many items at once.");
942 "Moved only %d items, you can't move more than that at once.",
943 MAX_ITEM_PER_DROP
944 ));
945
946 esrv_update_item (UPD_WEIGHT, pl, op);
947 } 911 }
948 else 912 else
949 drop_object (pl, op, nrof); 913 drop_object (pl, op, nrof);
950 914
951 return; 915 return;
971 /* put_object_in_sack presumes that necessary sanity checking 935 /* put_object_in_sack presumes that necessary sanity checking
972 * 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
973 * 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
974 * 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.
975 */ 939 */
976 if (env->type == CONTAINER && can_pick (pl, op) && sack_can_hold (pl, env, op, nrof)) 940 if (env->type == CONTAINER
941 && can_pick (pl, op)
942 && sack_can_hold (pl, env, op, nrof))
977 put_object_in_sack (pl, env, op, nrof); 943 put_object_in_sack (pl, env, op, nrof);
978} 944}
979 945

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines