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

Comparing deliantra/server/server/c_object.C (file contents):
Revision 1.19 by root, Sat Sep 16 22:24:13 2006 UTC vs.
Revision 1.31 by root, Fri Dec 22 16:34:00 2006 UTC

34 34
35/* 35/*
36 * Object id parsing functions 36 * Object id parsing functions
37 */ 37 */
38 38
39#define OBLINKMALLOC(p) if(!((p)=(objectlink *)malloc(sizeof(objectlink))))\
40 fatal(OUT_OF_MEMORY);
41
42#define ADD_ITEM(NEW,COUNT)\ 39#define ADD_ITEM(NEW,COUNT)\
43 if(!first) {\ 40 if(!first) {\
44 OBLINKMALLOC(first);\ 41 first = new objectlink;\
45 last=first;\ 42 last=first;\
46 } else {\ 43 } else {\
47 OBLINKMALLOC(last->next);\ 44 last->next = new objectlink;\
48 last=last->next;\ 45 last=last->next;\
49 }\ 46 }\
50 last->next=NULL;\ 47 last->next=0;\
51 last->ob=(NEW);\ 48 last->ob=(NEW);\
52 last->id=(COUNT); 49 last->id=(COUNT);
53 50
54/** 51/**
55 * Search the inventory of 'pl' for what matches best with params. 52 * Search the inventory of 'pl' for what matches best with params.
262 /* IF the player is flying & trying to take the item out of a container 259 /* IF the player is flying & trying to take the item out of a container
263 * that is in his inventory, let him. tmp->env points to the container 260 * that is in his inventory, let him. tmp->env points to the container
264 * (sack, luggage, etc), tmp->env->env then points to the player (nested 261 * (sack, luggage, etc), tmp->env->env then points to the player (nested
265 * containers not allowed as of now) 262 * containers not allowed as of now)
266 */ 263 */
267 if ((pl->move_type & MOVE_FLYING) && !QUERY_FLAG (pl, FLAG_WIZ) && is_player_inv (tmp) != pl) 264 if ((pl->move_type & MOVE_FLYING) && !QUERY_FLAG (pl, FLAG_WIZ) && tmp->in_player () != pl)
268 { 265 {
269 new_draw_info (NDI_UNIQUE, 0, pl, "You are levitating, you can't reach the ground!"); 266 new_draw_info (NDI_UNIQUE, 0, pl, "You are levitating, you can't reach the ground!");
270 return; 267 return;
271 } 268 }
272 269
279 new_draw_info (NDI_UNIQUE, 0, pl, "It must have been an illusion."); 276 new_draw_info (NDI_UNIQUE, 0, pl, "It must have been an illusion.");
280 277
281 if (pl->type == PLAYER) 278 if (pl->type == PLAYER)
282 esrv_del_item (pl->contr, tmp->count); 279 esrv_del_item (pl->contr, tmp->count);
283 280
284 if (!QUERY_FLAG (tmp, FLAG_REMOVED)) 281 tmp->destroy ();
285 remove_ob (tmp);
286
287 free_object (tmp);
288 return; 282 return;
289 } 283 }
290 284
291 if (nrof > tmp_nrof || nrof == 0) 285 if (nrof > tmp_nrof || nrof == 0)
292 nrof = tmp_nrof; 286 nrof = tmp_nrof;
338 */ 332 */
339 if (!QUERY_FLAG (tmp, FLAG_REMOVED)) 333 if (!QUERY_FLAG (tmp, FLAG_REMOVED))
340 { 334 {
341 if (tmp->env && pl->type == PLAYER) 335 if (tmp->env && pl->type == PLAYER)
342 esrv_del_item (pl->contr, tmp->count); 336 esrv_del_item (pl->contr, tmp->count);
343 remove_ob (tmp); /* Unlink it */ 337 tmp->remove (); /* Unlink it */
344 } 338 }
345 } 339 }
346 if (QUERY_FLAG (tmp, FLAG_UNPAID)) 340 if (QUERY_FLAG (tmp, FLAG_UNPAID))
347 (void) sprintf (buf, "%s will cost you %s.", query_name (tmp), query_cost_string (tmp, pl, F_BUY | F_SHOP)); 341 (void) sprintf (buf, "%s will cost you %s.", query_name (tmp), query_cost_string (tmp, pl, F_BUY | F_SHOP));
348 else 342 else
439 if (alt->type == CONTAINER && QUERY_FLAG (alt, FLAG_APPLIED) && sack_can_hold (NULL, alt, tmp, count)) 433 if (alt->type == CONTAINER && QUERY_FLAG (alt, FLAG_APPLIED) && sack_can_hold (NULL, alt, tmp, count))
440 break; /* General container comes next */ 434 break; /* General container comes next */
441 if (!alt) 435 if (!alt)
442 alt = op; /* No free containers */ 436 alt = op; /* No free containers */
443 } 437 }
438
444 if (tmp->env == alt) 439 if (tmp->env == alt)
445 { 440 {
446 /* here it could be possible to check rent, 441 /* here it could be possible to check rent,
447 * if someone wants to implement it 442 * if someone wants to implement it
448 */ 443 */
490 else 485 else
491 { 486 {
492 tmp = op->above; 487 tmp = op->above;
493 if (tmp) 488 if (tmp)
494 while (tmp->above) 489 while (tmp->above)
495 {
496 tmp = tmp->above; 490 tmp = tmp->above;
497 } 491
498 if (!tmp) 492 if (!tmp)
499 tmp = op->below; 493 tmp = op->below;
500 } 494 }
501 495
502 if (tmp == NULL) 496 if (tmp == NULL)
635 esrv_del_item (op->contr, tmp2->count); 629 esrv_del_item (op->contr, tmp2->count);
636 else /* this can proably be replaced with an update */ 630 else /* this can proably be replaced with an update */
637 esrv_send_item (op, tmp2); 631 esrv_send_item (op, tmp2);
638 } 632 }
639 else 633 else
640 remove_ob (tmp); 634 tmp->remove ();
641 635
642 new_draw_info_format (NDI_UNIQUE, 0, op, "You put the %s in %s.", query_name (tmp), query_name (sack)); 636 new_draw_info_format (NDI_UNIQUE, 0, op, "You put the %s in %s.", query_name (tmp), query_name (sack));
643 tmp2 = insert_ob_in_ob (tmp, sack); 637 tmp2 = insert_ob_in_ob (tmp, sack);
644 fix_player (op); /* This is overkill, fix_player() is called somewhere */ 638 op->update_stats (); /* This is overkill, fix_player() is called somewhere */
645 /* in object.c */ 639 /* in object.c */
646 640
647 /* If an object merged (and thus, different object), we need to 641 /* If an object merged (and thus, different object), we need to
648 * delete the original. 642 * delete the original.
649 */ 643 */
673 667
674 if (QUERY_FLAG (tmp, FLAG_APPLIED)) 668 if (QUERY_FLAG (tmp, FLAG_APPLIED))
675 if (apply_special (op, tmp, AP_UNAPPLY | AP_NO_MERGE)) 669 if (apply_special (op, tmp, AP_UNAPPLY | AP_NO_MERGE))
676 return; /* can't unapply it */ 670 return; /* can't unapply it */
677 671
678 /* We are only dropping some of the items. We split the current objec 672 /* We are only dropping some of the items. We split the current object
679 * off 673 * off
680 */ 674 */
681 if (nrof && tmp->nrof != nrof) 675 if (nrof && tmp->nrof != nrof)
682 { 676 {
683 object *tmp2 = tmp; 677 object *tmp2 = tmp;
698 else 692 else
699 esrv_send_item (op, tmp2); 693 esrv_send_item (op, tmp2);
700 } 694 }
701 } 695 }
702 else 696 else
703 remove_ob (tmp); 697 tmp->remove ();
704 698
705 if (INVOKE_OBJECT (DROP, tmp, ARG_OBJECT (op))) 699 if (INVOKE_OBJECT (DROP, tmp, ARG_OBJECT (op)))
706 return; 700 return;
707 701
708 if (QUERY_FLAG (tmp, FLAG_STARTEQUIP)) 702 if (QUERY_FLAG (tmp, FLAG_STARTEQUIP))
709 { 703 {
710 sprintf (buf, "You drop the %s.", query_name (tmp)); 704 sprintf (buf, "You drop the %s.", query_name (tmp));
711 new_draw_info (NDI_UNIQUE, 0, op, buf); 705 new_draw_info (NDI_UNIQUE, 0, op, buf);
712 new_draw_info (NDI_UNIQUE, 0, op, "The gods who lent it to you retrieves it."); 706 new_draw_info (NDI_UNIQUE, 0, op, "The gods who lent it to you retrieves it.");
707
713 if (op->type == PLAYER) 708 if (op->type == PLAYER)
714 esrv_del_item (op->contr, tmp->count); 709 esrv_del_item (op->contr, tmp->count);
715 free_object (tmp); 710
716 fix_player (op); 711 tmp->destroy ();
712 op->update_stats ();
717 return; 713 return;
718 } 714 }
719 715
720/* If SAVE_INTERVAL is commented out, we never want to save 716/* If SAVE_INTERVAL is commented out, we never want to save
721 * the player here. 717 * the player here.
726 * of what he is dropping? 722 * of what he is dropping?
727 */ 723 */
728 if (op->type == PLAYER && !QUERY_FLAG (tmp, FLAG_UNPAID) && 724 if (op->type == PLAYER && !QUERY_FLAG (tmp, FLAG_UNPAID) &&
729 (tmp->nrof ? tmp->value * tmp->nrof : tmp->value > 2000) && (op->contr->last_save_time + SAVE_INTERVAL) <= time (NULL)) 725 (tmp->nrof ? tmp->value * tmp->nrof : tmp->value > 2000) && (op->contr->last_save_time + SAVE_INTERVAL) <= time (NULL))
730 { 726 {
731 save_player (op, 1); 727 op->contr->save ();
732 op->contr->last_save_time = time (NULL); 728 op->contr->last_save_time = time (NULL);
733 } 729 }
734#endif /* SAVE_INTERVAL */ 730#endif /* SAVE_INTERVAL */
735 731
736 if (op->type == PLAYER) 732 if (op->type == PLAYER)
737 esrv_del_item (op->contr, tmp->count); 733 esrv_del_item (op->contr, tmp->count);
738 734
739 /* Call this before we update the various windows/players. At least 735 /* Call this before we update the various windows/players. At least
740 * that we, we know the weight is correct. 736 * that we, we know the weight is correct.
741 */ 737 */
742 fix_player (op); /* This is overkill, fix_player() is called somewhere */ 738 op->update_stats (); /* This is overkill, fix_player() is called somewhere */
743 /* in object.c */ 739 /* in object.c */
744 740
745 if (op->type == PLAYER) 741 if (op->type == PLAYER)
746 { 742 {
747 op->contr->socket.update_look = 1;
748 /* Need to update the weight for the player */ 743 /* Need to update the weight for the player */
749 esrv_send_item (op, op); 744 esrv_send_item (op, op);
745 op->contr->ns->floorbox_update ();
750 } 746 }
751 747
752 for (floor = get_map_ob (op->map, op->x, op->y); floor; floor = floor->above) 748 for (floor = GET_MAP_OB (op->map, op->x, op->y); floor; floor = floor->above)
753 if (INVOKE_OBJECT (DROP_ON, floor, ARG_OBJECT (tmp), ARG_OBJECT (op))) 749 if (INVOKE_OBJECT (DROP_ON, floor, ARG_OBJECT (tmp), ARG_OBJECT (op)))
754 return; 750 return;
755 751
756 if (is_in_shop (op) && !QUERY_FLAG (tmp, FLAG_UNPAID) && tmp->type != MONEY) 752 if (is_in_shop (op) && !QUERY_FLAG (tmp, FLAG_UNPAID) && tmp->type != MONEY)
757 sell_item (tmp, op); 753 sell_item (tmp, op);
776 if (tmp->env && tmp->env->type != PLAYER) 772 if (tmp->env && tmp->env->type != PLAYER)
777 { 773 {
778 /* Just toss the object - probably shouldn't be hanging 774 /* Just toss the object - probably shouldn't be hanging
779 * around anyways 775 * around anyways
780 */ 776 */
781 remove_ob (tmp); 777 tmp->remove ();
782 free_object (tmp); 778 tmp->destroy ();
783 return; 779 return;
784 } 780 }
785 else 781 else
786 { 782 {
787 while (tmp != NULL && tmp->invisible) 783 while (tmp != NULL && tmp->invisible)
806 new_draw_info (NDI_UNIQUE, 0, op, "This item can't be dropped."); 802 new_draw_info (NDI_UNIQUE, 0, op, "This item can't be dropped.");
807#endif 803#endif
808 return; 804 return;
809 } 805 }
810 806
811 if (op->type == PLAYER) 807 if (op->type == PLAYER && op->contr->last_used == tmp)
812 { 808 op->contr->last_used = tmp->below ? tmp->below
813 if (op->contr->last_used == tmp && op->contr->last_used_id == tmp->count) 809 : tmp->above ? tmp->above
814 { 810 : 0;
815 object *n = NULL;
816
817 if (tmp->below != NULL)
818 n = tmp->below;
819 else if (tmp->above != NULL)
820 n = tmp->above;
821 op->contr->last_used = n;
822 if (n != NULL)
823 op->contr->last_used_id = n->count;
824 else
825 op->contr->last_used_id = 0;
826 }
827 };
828 811
829 if (op->container) 812 if (op->container)
830 { 813 {
831 if (op->type == PLAYER) 814 if (op->type == PLAYER)
832 {
833 put_object_in_sack (op, op->container, tmp, op->contr->count); 815 put_object_in_sack (op, op->container, tmp, op->contr->count);
834 }
835 else 816 else
836 {
837 put_object_in_sack (op, op->container, tmp, 0); 817 put_object_in_sack (op, op->container, tmp, 0);
838 };
839 } 818 }
840 else 819 else
841 { 820 {
842 if (op->type == PLAYER) 821 if (op->type == PLAYER)
843 {
844 drop_object (op, tmp, op->contr->count); 822 drop_object (op, tmp, op->contr->count);
845 }
846 else 823 else
847 {
848 drop_object (op, tmp, 0); 824 drop_object (op, tmp, 0);
849 };
850 } 825 }
826
851 if (op->type == PLAYER) 827 if (op->type == PLAYER)
852 op->contr->count = 0; 828 op->contr->count = 0;
853} 829}
854 830
855 831
963 } 939 }
964 } 940 }
965 curinv = nextinv; 941 curinv = nextinv;
966 } 942 }
967 } 943 }
968 op->contr->socket.update_look = 1; 944
945 op->contr->ns->floorbox_update ();
969 946
970/* draw_look(op);*/ 947/* draw_look(op);*/
971 return 0; 948 return 0;
972} 949}
973 950
1003 new_draw_info (NDI_UNIQUE, 0, op, "Nothing to drop."); 980 new_draw_info (NDI_UNIQUE, 0, op, "Nothing to drop.");
1004 } 981 }
1005 if (op->type == PLAYER) 982 if (op->type == PLAYER)
1006 { 983 {
1007 op->contr->count = 0; 984 op->contr->count = 0;
1008 op->contr->socket.update_look = 1; 985 op->contr->ns->floorbox_update ();
1009 }; 986 };
1010 987
1011/* draw_look(op);*/ 988/* draw_look(op);*/
1012 return 0; 989 return 0;
1013} 990}
1047{ 1024{
1048 object *tmp; 1025 object *tmp;
1049 1026
1050 if (!op || !op->contr) 1027 if (!op || !op->contr)
1051 return NULL; 1028 return NULL;
1029
1052 if (!op->contr->mark) 1030 if (!op->contr->mark)
1053 { 1031 {
1054
1055/* new_draw_info(NDI_UNIQUE,0,op,"You have no marked object");*/ 1032/* new_draw_info(NDI_UNIQUE,0,op,"You have no marked object");*/
1056 return NULL; 1033 return 0;
1057 } 1034 }
1035
1058 /* This may seem like overkill, but we need to make sure that they 1036 /* This may seem like overkill, but we need to make sure that they
1059 * player hasn't dropped the item. We use count on the off chance that 1037 * player hasn't dropped the item. We use count on the off chance that
1060 * an item got reincarnated at some point. 1038 * an item got reincarnated at some point.
1061 */ 1039 */
1062 for (tmp = op->inv; tmp; tmp = tmp->below) 1040 for (tmp = op->inv; tmp; tmp = tmp->below)
1063 { 1041 {
1064 if (tmp->invisible) 1042 if (tmp->invisible)
1065 continue; 1043 continue;
1044
1066 if (tmp == op->contr->mark) 1045 if (tmp == op->contr->mark)
1067 { 1046 {
1068 if (tmp->count == op->contr->mark_count) 1047 if (!tmp->destroyed ())
1069 return tmp; 1048 return tmp;
1070 else 1049 else
1071 { 1050 {
1072 op->contr->mark = NULL; 1051 op->contr->mark = 0;
1073 op->contr->mark_count = 0;
1074
1075/* new_draw_info(NDI_UNIQUE,0,op,"You have no marked object");*/ 1052/* new_draw_info(NDI_UNIQUE,0,op,"You have no marked object");*/
1076 return NULL; 1053 return 0;
1077 } 1054 }
1078 } 1055 }
1079 } 1056 }
1057
1080 return NULL; 1058 return 0;
1081} 1059}
1082 1060
1083 1061
1084/* op should be a player, params is any params. 1062/* op should be a player, params is any params.
1085 * If no params given, we print out the currently marked object. 1063 * If no params given, we print out the currently marked object.
1088int 1066int
1089command_mark (object *op, char *params) 1067command_mark (object *op, char *params)
1090{ 1068{
1091 if (!op->contr) 1069 if (!op->contr)
1092 return 1; 1070 return 1;
1071
1093 if (!params) 1072 if (!params)
1094 { 1073 {
1095 object *mark = find_marked_object (op); 1074 object *mark = find_marked_object (op);
1096 1075
1097 if (!mark) 1076 if (!mark)
1109 return 1; 1088 return 1;
1110 } 1089 }
1111 else 1090 else
1112 { 1091 {
1113 op->contr->mark = mark1; 1092 op->contr->mark = mark1;
1114 op->contr->mark_count = mark1->count;
1115 new_draw_info_format (NDI_UNIQUE, 0, op, "Marked item %s", query_name (mark1)); 1093 new_draw_info_format (NDI_UNIQUE, 0, op, "Marked item %s", query_name (mark1));
1116 return 0; 1094 return 0;
1117 } 1095 }
1118 } 1096 }
1097
1119 return 0; /*shouldnt get here */ 1098 return 0; /*shouldnt get here */
1120} 1099}
1121 1100
1122 1101
1123/* op is the player 1102/* op is the player
1456 new_draw_info_format (NDI_UNIQUE, 0, op, "%d MAGICDEVICE", i & PU_MAGIC_DEVICE ? 1 : 0); 1435 new_draw_info_format (NDI_UNIQUE, 0, op, "%d MAGICDEVICE", i & PU_MAGIC_DEVICE ? 1 : 0);
1457 1436
1458 new_draw_info_format (NDI_UNIQUE, 0, op, "%d NOT CURSED", i & PU_NOT_CURSED ? 1 : 0); 1437 new_draw_info_format (NDI_UNIQUE, 0, op, "%d NOT CURSED", i & PU_NOT_CURSED ? 1 : 0);
1459 1438
1460 new_draw_info_format (NDI_UNIQUE, 0, op, "%d JEWELS", i & PU_JEWELS ? 1 : 0); 1439 new_draw_info_format (NDI_UNIQUE, 0, op, "%d JEWELS", i & PU_JEWELS ? 1 : 0);
1440 new_draw_info_format (NDI_UNIQUE, 0, op, "%d FLESH", i & PU_FLESH ? 1 : 0);
1461 1441
1462 new_draw_info_format (NDI_UNIQUE, 0, op, ""); 1442 new_draw_info_format (NDI_UNIQUE, 0, op, "");
1463} 1443}
1464 1444
1465int 1445int
1467{ 1447{
1468 uint32 i; 1448 uint32 i;
1469 static const char *names[] = { 1449 static const char *names[] = {
1470 "debug", "inhibit", "stop", "food", "drink", "valuables", "bow", "arrow", "helmet", 1450 "debug", "inhibit", "stop", "food", "drink", "valuables", "bow", "arrow", "helmet",
1471 "shield", "armour", "boots", "gloves", "cloak", "key", "missile", "allweapon", 1451 "shield", "armour", "boots", "gloves", "cloak", "key", "missile", "allweapon",
1472 "magical", "potion", "spellbook", "skillscroll", "readables", "magicdevice", "notcursed", "jewels", NULL 1452 "magical", "potion", "spellbook", "skillscroll", "readables", "magicdevice", "notcursed",
1453 "jewels", "flesh", NULL
1473 }; 1454 };
1474 static uint32 modes[] = { 1455 static uint32 modes[] = {
1475 PU_DEBUG, PU_INHIBIT, PU_STOP, PU_FOOD, PU_DRINK, PU_VALUABLES, PU_BOW, PU_ARROW, PU_HELMET, 1456 PU_DEBUG, PU_INHIBIT, PU_STOP, PU_FOOD, PU_DRINK, PU_VALUABLES, PU_BOW, PU_ARROW, PU_HELMET,
1476 PU_SHIELD, PU_ARMOUR, PU_BOOTS, PU_GLOVES, PU_CLOAK, PU_KEY, PU_MISSILEWEAPON, PU_ALLWEAPON, 1457 PU_SHIELD, PU_ARMOUR, PU_BOOTS, PU_GLOVES, PU_CLOAK, PU_KEY, PU_MISSILEWEAPON, PU_ALLWEAPON,
1477 PU_MAGICAL, PU_POTION, PU_SPELLBOOK, PU_SKILLSCROLL, PU_READABLES, PU_MAGIC_DEVICE, PU_NOT_CURSED, PU_JEWELS, 0 1458 PU_MAGICAL, PU_POTION, PU_SPELLBOOK, PU_SKILLSCROLL, PU_READABLES, PU_MAGIC_DEVICE, PU_NOT_CURSED,
1459 PU_JEWELS, PU_FLESH, 0
1478 }; 1460 };
1479 1461
1480 if (!params) 1462 if (!params)
1481 { 1463 {
1482 /* if the new mode is used, just print the settings */ 1464 /* if the new mode is used, just print the settings */
1579 new_draw_info (NDI_UNIQUE, 0, op, "items containing the word 'magic+1'."); 1561 new_draw_info (NDI_UNIQUE, 0, op, "items containing the word 'magic+1'.");
1580 return 1; 1562 return 1;
1581 } 1563 }
1582 op->contr->search_str[0] = '\0'; 1564 op->contr->search_str[0] = '\0';
1583 new_draw_info (NDI_UNIQUE, 0, op, "Search mode turned off."); 1565 new_draw_info (NDI_UNIQUE, 0, op, "Search mode turned off.");
1584 fix_player (op); 1566 op->update_stats ();
1585 return 1; 1567 return 1;
1586 } 1568 }
1587 if ((int) strlen (params) >= MAX_BUF) 1569 if ((int) strlen (params) >= MAX_BUF)
1588 { 1570 {
1589 new_draw_info (NDI_UNIQUE, 0, op, "Search string too long."); 1571 new_draw_info (NDI_UNIQUE, 0, op, "Search string too long.");
1590 return 1; 1572 return 1;
1591 } 1573 }
1592 strcpy (op->contr->search_str, params); 1574 strcpy (op->contr->search_str, params);
1593 sprintf (buf, "Searching for '%s'.", op->contr->search_str); 1575 sprintf (buf, "Searching for '%s'.", op->contr->search_str);
1594 new_draw_info (NDI_UNIQUE, 0, op, buf); 1576 new_draw_info (NDI_UNIQUE, 0, op, buf);
1595 fix_player (op); 1577 op->update_stats ();
1596 return 1; 1578 return 1;
1597} 1579}
1598 1580

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines