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

Comparing deliantra/server/server/apply.C (file contents):
Revision 1.95 by root, Mon May 14 19:08:26 2007 UTC vs.
Revision 1.107 by root, Mon May 28 21:28:35 2007 UTC

1/* 1/*
2 * CrossFire, A Multiplayer game 2 * This file is part of Crossfire TRT, the Roguelike Realtime MORPG.
3 * 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team 4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team
5 * Copyright (C) 2001 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * Crossfire TRT is free software; you can redistribute it and/or modify it
9 * it under the terms of the GNU General Public License as published by 9 * under the terms of the GNU General Public License as published by the Free
10 * the Free Software Foundation; either version 2 of the License, or 10 * Software Foundation; either version 2 of the License, or (at your option)
11 * (at your option) any later version. 11 * any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful, but
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 * GNU General Public License for more details. 16 * for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License along
19 * along with this program; if not, write to the Free Software 19 * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 * 21 *
22 * The authors can be reached via e-mail to <crossfire@schmorp.de> 22 * The authors can be reached via e-mail to <crossfire@schmorp.de>
23 */ 23 */
24 24
25#include <cmath> 25#include <cmath>
26 26
1006 LOG (llevDebug, "converter output price higher than input: %s at %s (%d, %d) in value %d, out value %d for %s\n", 1006 LOG (llevDebug, "converter output price higher than input: %s at %s (%d, %d) in value %d, out value %d for %s\n",
1007 &converter->name, &converter->map->path, converter->x, converter->y, price_in, item->nrof * item->value, &item->name); 1007 &converter->name, &converter->map->path, converter->x, converter->y, price_in, item->nrof * item->value, &item->name);
1008 1008
1009 /** 1009 /**
1010 * elmex: we are going to let the game continue, as the mapcreator 1010 * elmex: we are going to let the game continue, as the mapcreator
1011 * propably had something in mind when doing this 1011 * probably had something in mind when doing this
1012 */ 1012 */
1013 } 1013 }
1014 insert_ob_in_map_at (item, converter->map, converter, 0, converter->x, converter->y); 1014 insert_ob_in_map_at (item, converter->map, converter, 0, converter->x, converter->y);
1015 return 1; 1015 return 1;
1016} 1016}
1868 if (!QUERY_FLAG (tmp, FLAG_IDENTIFIED)) 1868 if (!QUERY_FLAG (tmp, FLAG_IDENTIFIED))
1869 identify (tmp); 1869 identify (tmp);
1870 1870
1871 new_draw_info_format (NDI_BLACK, 0, op, "The scroll of %s turns to dust.", &tmp->inv->name); 1871 new_draw_info_format (NDI_BLACK, 0, op, "The scroll of %s turns to dust.", &tmp->inv->name);
1872 1872
1873
1874 cast_spell (op, tmp, dir, tmp->inv, NULL); 1873 cast_spell (op, tmp, dir, tmp->inv, NULL);
1875 decrease_ob (tmp); 1874 decrease_ob (tmp);
1876} 1875}
1877 1876
1878/** 1877/**
1881 * chest. 1880 * chest.
1882 */ 1881 */
1883static void 1882static void
1884apply_treasure (object *op, object *tmp) 1883apply_treasure (object *op, object *tmp)
1885{ 1884{
1886 object *treas;
1887
1888
1889 /* Nice side effect of new treasure creation method is that the treasure 1885 /* Nice side effect of new treasure creation method is that the treasure
1890 * for the chest is done when the chest is created, and put into the chest 1886 * for the chest is done when the chest is created, and put into the chest
1891 * inventory. So that when the chest burns up, the items still exist. Also 1887 * inventory. So that when the chest burns up, the items still exist. Also
1892 * prevents people fromt moving chests to more difficult maps to get better 1888 * prevents people fromt moving chests to more difficult maps to get better
1893 * treasure 1889 * treasure
1894 */ 1890 */
1895
1896 treas = tmp->inv; 1891 object *treas = tmp->inv;
1897 if (treas == NULL) 1892
1893 if (!treas)
1898 { 1894 {
1899 new_draw_info (NDI_UNIQUE, 0, op, "The chest was empty."); 1895 new_draw_info (NDI_UNIQUE, 0, op, "The chest was empty.");
1900 decrease_ob (tmp); 1896 decrease_ob (tmp);
1901 return; 1897 return;
1902 } 1898 }
1899
1903 while (tmp->inv) 1900 while (tmp->inv)
1904 { 1901 {
1905 treas = tmp->inv; 1902 treas = tmp->inv;
1906 1903
1907 treas->remove (); 1904 treas->remove ();
2550 new_draw_info (NDI_UNIQUE, 0, pl, "But you are floating high " "above the ground!"); 2547 new_draw_info (NDI_UNIQUE, 0, pl, "But you are floating high " "above the ground!");
2551 return 0; 2548 return 0;
2552 } 2549 }
2553 } 2550 }
2554 2551
2555 /* Check for PLAYER to avoid a DM to disappear in a puff of smoke if
2556 * applied.
2557 */
2558 if (op->type != PLAYER && QUERY_FLAG (op, FLAG_WAS_WIZ) && !QUERY_FLAG (pl, FLAG_WAS_WIZ))
2559 {
2560 play_sound_map (pl->map, pl->x, pl->y, SOUND_OB_EVAPORATE);
2561 new_draw_info (NDI_UNIQUE, 0, pl, "The object disappears in a puff " "of smoke!");
2562 new_draw_info (NDI_UNIQUE, 0, pl, "It must have been an illusion.");
2563 op->destroy ();
2564 return 1;
2565 }
2566
2567 pl->contr->last_used = op; 2552 pl->contr->last_used = op;
2568 2553
2569 tmp = manual_apply (pl, op, aflag); 2554 tmp = manual_apply (pl, op, aflag);
2570 if (!quiet) 2555 if (!quiet)
2571 { 2556 {
2630{ 2615{
2631 if (INVOKE_OBJECT (BE_UNREADY, op, ARG_OBJECT (who), ARG_INT (aflags)) 2616 if (INVOKE_OBJECT (BE_UNREADY, op, ARG_OBJECT (who), ARG_INT (aflags))
2632 || INVOKE_OBJECT (UNREADY, who, ARG_OBJECT (op), ARG_INT (aflags))) 2617 || INVOKE_OBJECT (UNREADY, who, ARG_OBJECT (op), ARG_INT (aflags)))
2633 return RESULT_INT (0); 2618 return RESULT_INT (0);
2634 2619
2635 object *tmp2;
2636
2637 CLEAR_FLAG (op, FLAG_APPLIED); 2620 CLEAR_FLAG (op, FLAG_APPLIED);
2638 2621
2639 if (player *pl = who->contr)
2640 {
2641 if (op == pl->ranged_ob) pl->ranged_ob = 0;
2642 if (op == pl->combat_ob) pl->combat_ob = 0;
2643 }
2644
2645 switch (op->type) 2622 switch (op->type)
2646 { 2623 {
2624 case SKILL_TOOL:
2625 // unapplying a skill tool should also unapply the skill it governs
2626 // but this is hard, as it shouldn't do so when the skill can
2627 // be used for other reasons
2628 for (object *tmp = who->inv; tmp; tmp = tmp->below)
2629 if (tmp->skill == op->skill
2630 && tmp->type == SKILL
2631 && tmp->flag [FLAG_APPLIED]
2632 && !tmp->flag [FLAG_CAN_USE_SKILL])
2633 unapply_special (who, tmp, 0);
2634
2635 change_abil (who, op);
2636 break;
2637
2647 case WEAPON: 2638 case WEAPON:
2639 if (player *pl = who->contr)
2640 if (op == pl->combat_ob)
2641 {
2642 pl->combat_ob = 0;
2643 who->change_weapon (pl->ranged_ob);
2644 }
2645
2648 new_draw_info_format (NDI_UNIQUE, 0, who, "You unwield %s.", query_name (op)); 2646 new_draw_info_format (NDI_UNIQUE, 0, who, "You unwield %s.", query_name (op));
2649 2647
2650 change_abil (who, op); 2648 change_abil (who, op);
2651 CLEAR_FLAG (who, FLAG_READY_WEAPON); 2649 CLEAR_FLAG (who, FLAG_READY_WEAPON);
2652 clear_skill (who);
2653 break; 2650 break;
2654 2651
2655 case SKILL: /* allows objects to impart skills */
2656 case SKILL_TOOL: 2652 case SKILL:
2657 if (op != who->chosen_skill)
2658 LOG (llevError, "BUG: apply_special(): applied skill is not a chosen skill\n");
2659
2660 if (who->contr) 2653 if (who->contr)
2661 { 2654 {
2662 if (!op->invisible) 2655 if (!op->invisible)
2663 new_draw_info_format (NDI_UNIQUE, 0, who, "You stop using the %s.", query_name (op)); 2656 new_draw_info_format (NDI_UNIQUE, 0, who, "You stop using the %s.", query_name (op));
2664 else 2657 else
2665 new_draw_info_format (NDI_UNIQUE, 0, who, "You can no longer use the skill: %s.", &op->skill); 2658 new_draw_info_format (NDI_UNIQUE, 0, who, "You can no longer use the skill: %s.", &op->skill);
2666 } 2659 }
2667 2660
2668 change_abil (who, op); 2661 change_abil (who, op);
2669 who->chosen_skill = 0;
2670 CLEAR_FLAG (who, FLAG_READY_SKILL); 2662 CLEAR_FLAG (who, FLAG_READY_SKILL);
2671 break; 2663 break;
2672 2664
2673 case ARMOUR: 2665 case ARMOUR:
2674 case HELMET: 2666 case HELMET:
2683 new_draw_info_format (NDI_UNIQUE, 0, who, "You unwear %s.", query_name (op)); 2675 new_draw_info_format (NDI_UNIQUE, 0, who, "You unwear %s.", query_name (op));
2684 change_abil (who, op); 2676 change_abil (who, op);
2685 break; 2677 break;
2686 2678
2687 case LAMP: 2679 case LAMP:
2680 {
2688 new_draw_info_format (NDI_UNIQUE, 0, who, "You turn off your %s.", &op->name); 2681 new_draw_info_format (NDI_UNIQUE, 0, who, "You turn off your %s.", &op->name);
2682
2689 tmp2 = arch_to_object (op->other_arch); 2683 object *tmp2 = arch_to_object (op->other_arch);
2690 tmp2->x = op->x; 2684 tmp2->x = op->x;
2691 tmp2->y = op->y; 2685 tmp2->y = op->y;
2692 tmp2->map = op->map; 2686 tmp2->map = op->map;
2693 tmp2->below = op->below; 2687 tmp2->below = op->below;
2694 tmp2->above = op->above; 2688 tmp2->above = op->above;
2695 tmp2->stats.food = op->stats.food; 2689 tmp2->stats.food = op->stats.food;
2696 CLEAR_FLAG (tmp2, FLAG_APPLIED); 2690 CLEAR_FLAG (tmp2, FLAG_APPLIED);
2697 2691
2698 if (QUERY_FLAG (op, FLAG_INV_LOCKED)) 2692 if (QUERY_FLAG (op, FLAG_INV_LOCKED))
2699 SET_FLAG (tmp2, FLAG_INV_LOCKED); 2693 SET_FLAG (tmp2, FLAG_INV_LOCKED);
2700 2694
2701 if (who->contr) 2695 if (who->contr)
2702 esrv_del_item (who->contr, op->count); 2696 esrv_del_item (who->contr, op->count);
2703 2697
2704 op->destroy (); 2698 op->destroy ();
2705 insert_ob_in_ob (tmp2, who); 2699 insert_ob_in_ob (tmp2, who);
2706 who->update_stats (); 2700 who->update_stats ();
2707 2701
2708 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED)) 2702 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED))
2709 { 2703 {
2710 if (who->contr) 2704 if (who->contr)
2711 { 2705 {
2712 new_draw_info (NDI_UNIQUE, 0, who, "Oops, it feels deadly cold!"); 2706 new_draw_info (NDI_UNIQUE, 0, who, "Oops, it feels deadly cold!");
2713 SET_FLAG (tmp2, FLAG_KNOWN_CURSED); 2707 SET_FLAG (tmp2, FLAG_KNOWN_CURSED);
2714 } 2708 }
2715 } 2709 }
2716 2710
2717 if (who->contr) 2711 if (who->contr)
2718 esrv_send_item (who, tmp2); 2712 esrv_send_item (who, tmp2);
2713 }
2719 2714
2720 return 1; /* otherwise, an attempt to drop causes problems */ 2715 return 1; /* otherwise, an attempt to drop causes problems */
2721 2716
2722 case BOW: 2717 case BOW:
2723 case WAND: 2718 case WAND:
2724 case ROD: 2719 case ROD:
2725 case HORN: 2720 case HORN:
2726 clear_skill (who);
2727
2728 if (who->contr) 2721 if (player *pl = who->contr)
2729 { 2722 {
2723 if (op == pl->ranged_ob)
2724 {
2725 pl->ranged_ob = 0;
2726 who->change_weapon (pl->combat_ob);
2727 }
2728
2730 new_draw_info_format (NDI_UNIQUE, 0, who, "You unready %s.", query_name (op)); 2729 new_draw_info_format (NDI_UNIQUE, 0, who, "You unready %s.", query_name (op));
2731
2732 if (who->contr->ranged_ob == op)
2733 who->contr->ranged_ob = 0;
2734
2735 if (who->current_weapon == op)
2736 who->current_weapon = 0;
2737 } 2730 }
2738 else 2731 else
2739 { 2732 {
2733 who->change_skill (0);
2734
2740 if (op->type == BOW) 2735 if (op->type == BOW)
2741 CLEAR_FLAG (who, FLAG_READY_BOW); 2736 CLEAR_FLAG (who, FLAG_READY_BOW);
2742 else 2737 else
2743 CLEAR_FLAG (who, FLAG_READY_RANGE); 2738 CLEAR_FLAG (who, FLAG_READY_RANGE);
2744 } 2739 }
2745 2740
2746 break; 2741 break;
2747 2742
2748 case BUILDER: 2743 case BUILDER:
2749 if (who->contr) 2744 if (who->contr)
2750 {
2751 new_draw_info_format (NDI_UNIQUE, 0, who, "You unready %s.", query_name (op)); 2745 new_draw_info_format (NDI_UNIQUE, 0, who, "You unready %s.", query_name (op));
2752
2753 if (who->contr->ranged_ob == op)
2754 who->contr->ranged_ob = 0;
2755 }
2756 break; 2746 break;
2757 2747
2758 default: 2748 default:
2759 new_draw_info_format (NDI_UNIQUE, 0, who, "You unapply %s.", query_name (op)); 2749 new_draw_info_format (NDI_UNIQUE, 0, who, "You unapply %s.", query_name (op));
2760 break; 2750 break;
2784/** 2774/**
2785 * Returns the object that is using location 'loc'. 2775 * Returns the object that is using location 'loc'.
2786 * Note that 'start' is the first object to start examing - we 2776 * Note that 'start' is the first object to start examing - we
2787 * then go through the below of this. In this way, you can do 2777 * then go through the below of this. In this way, you can do
2788 * something like: 2778 * something like:
2789 * tmp = get_item_from_body_location(who->inv, 1); 2779 * tmp = get_next_item_from_body_location(who->inv, 1);
2790 * if (tmp) tmp1 = get_item_from_body_location(tmp->below, 1); 2780 * if (tmp) tmp1 = get_next_item_from_body_location(tmp->below, 1);
2791 * to find the second object that may use this location, etc. 2781 * to find the second object that may use this location, etc.
2792 * Returns NULL if no match is found. 2782 * Returns NULL if no match is found.
2793 * loc is the index into the array we are looking for a match. 2783 * loc is the index into the array we are looking for a match.
2794 * don't return invisible objects unless they are skill objects 2784 * don't return invisible objects unless they are skill objects
2795 * invisible other objects that use 2785 * invisible other objects that use
2796 * up body locations can be used as restrictions. 2786 * up body locations can be used as restrictions.
2797 */ 2787 */
2798static object * 2788static object *
2799get_item_from_body_location (int loc, object *start) 2789get_next_item_from_body_location (int loc, object *start)
2800{ 2790{
2801 if (start)
2802 for (object *tmp = start; tmp; tmp = tmp->below) 2791 for (object *tmp = start; tmp; tmp = tmp->below)
2803 if (QUERY_FLAG (tmp, FLAG_APPLIED) && tmp->slot[loc].info && (!tmp->invisible || tmp->type == SKILL)) 2792 if (tmp->flag [FLAG_APPLIED]
2793 && tmp->slot[loc].info
2794 && (!tmp->invisible || tmp->type == SKILL))
2804 return tmp; 2795 return tmp;
2805 2796
2806 return 0; 2797 return 0;
2807} 2798}
2808 2799
2809/** 2800/**
2850 /* We do a while loop - may need to remove several items in order 2841 /* We do a while loop - may need to remove several items in order
2851 * to free up enough slots. 2842 * to free up enough slots.
2852 */ 2843 */
2853 while ((who->slot[i].used + op->slot[i].info) < 0) 2844 while ((who->slot[i].used + op->slot[i].info) < 0)
2854 { 2845 {
2855 object *tmp = get_item_from_body_location (i, last); 2846 object *tmp = get_next_item_from_body_location (i, last);
2856 2847
2857 if (!tmp) 2848 if (!tmp)
2858 { 2849 {
2859#if 0 2850#if 0
2860 /* Not a bug - we'll get this if the player has cursed items 2851 /* Not a bug - we'll get this if the player has cursed items
2898 * Checks to see if 'who' can apply object 'op'. 2889 * Checks to see if 'who' can apply object 'op'.
2899 * Returns 0 if apply can be done without anything special. 2890 * Returns 0 if apply can be done without anything special.
2900 * Otherwise returns a bitmask - potentially several of these may be 2891 * Otherwise returns a bitmask - potentially several of these may be
2901 * set, but largely depends on circumstance - in the future, processing 2892 * set, but largely depends on circumstance - in the future, processing
2902 * may be pruned once we know some status (eg, once CAN_APPLY_NEVER 2893 * may be pruned once we know some status (eg, once CAN_APPLY_NEVER
2903 * is set, do we really are what the other flags may be?) 2894 * is set, do we really care what the other flags may be?)
2904 * 2895 *
2905 * See include/define.h for detailed description of the meaning of 2896 * See include/define.h for detailed description of the meaning of
2906 * these return values. 2897 * these return values.
2907 */ 2898 */
2908int 2899int
2917 for (int i = 0; i < NUM_BODY_LOCATIONS; i++) 2908 for (int i = 0; i < NUM_BODY_LOCATIONS; i++)
2918 { 2909 {
2919 if (op->slot[i].info) 2910 if (op->slot[i].info)
2920 { 2911 {
2921 /* Item uses more slots than we have */ 2912 /* Item uses more slots than we have */
2922 if (abs (op->slot[i].info) > who->slot[i].info) 2913 if (who->slot[i].info + op->slot [i].info < 0)
2923 { 2914 {
2924 /* Could return now for efficiency - rest of info below isn't 2915 /* Could return now for efficiency - rest of info below isn't
2925 * really needed. 2916 * really needed.
2926 */ 2917 */
2927 retval |= CAN_APPLY_NEVER; 2918 retval |= CAN_APPLY_NEVER;
2928 } 2919 }
2929 else if ((who->slot[i].used + op->slot[i].info) < 0) 2920 else if (who->slot[i].used + op->slot[i].info < 0)
2930 { 2921 {
2931 /* in this case, equipping this would use more free spots than 2922 /* in this case, equipping this would use more free spots than
2932 * we have. 2923 * we have.
2933 */ 2924 */
2934 2925
2945 { 2936 {
2946 retval |= CAN_APPLY_UNAPPLY; 2937 retval |= CAN_APPLY_UNAPPLY;
2947 continue; 2938 continue;
2948 } 2939 }
2949 2940
2950 object *tmp1 = get_item_from_body_location (i, who->inv); 2941 object *tmp1 = get_next_item_from_body_location (i, who->inv);
2951 if (!tmp1) 2942 if (!tmp1)
2952 { 2943 {
2953#if 0 2944#if 0
2954 /* This is sort of an error, but happens a lot when old players 2945 /* This is sort of an error, but happens a lot when old players
2955 * join in with more stuff equipped than they are now allowed. 2946 * join in with more stuff equipped than they are now allowed.
2963 /* need to unapply something. However, if this something 2954 /* need to unapply something. However, if this something
2964 * is different than we had found before, it means they need 2955 * is different than we had found before, it means they need
2965 * to apply multiple objects 2956 * to apply multiple objects
2966 */ 2957 */
2967 retval |= CAN_APPLY_UNAPPLY; 2958 retval |= CAN_APPLY_UNAPPLY;
2959
2968 if (!tmp) 2960 if (!tmp)
2969 tmp = tmp1; 2961 tmp = tmp1;
2970 else if (tmp != tmp1) 2962 else if (tmp != tmp1)
2971 retval |= CAN_APPLY_UNAPPLY_MULT; 2963 retval |= CAN_APPLY_UNAPPLY_MULT;
2972 2964
3034 * AP_UNAPPLY=always unapply). 3026 * AP_UNAPPLY=always unapply).
3035 * 3027 *
3036 * Optional flags: 3028 * Optional flags:
3037 * AP_NO_MERGE: don't merge an unapplied object with other objects 3029 * AP_NO_MERGE: don't merge an unapplied object with other objects
3038 * AP_IGNORE_CURSE: unapply cursed items 3030 * AP_IGNORE_CURSE: unapply cursed items
3031 * AP_NO_READY: do not ready skills when applying skill tools
3039 * 3032 *
3040 * Usage example: apply_special (who, op, AP_UNAPPLY | AP_IGNORE_CURSE) 3033 * Usage example: apply_special (who, op, AP_UNAPPLY | AP_IGNORE_CURSE)
3041 * 3034 *
3042 * apply_special() doesn't check for unpaid items. 3035 * apply_special() doesn't check for unpaid items.
3043 */ 3036 */
3081 switch (op->slottype ()) 3074 switch (op->slottype ())
3082 { 3075 {
3083 case slot_combat: who->change_weapon (pl->combat_ob); break; 3076 case slot_combat: who->change_weapon (pl->combat_ob); break;
3084 case slot_ranged: who->change_weapon (pl->ranged_ob); break; 3077 case slot_ranged: who->change_weapon (pl->ranged_ob); break;
3085 } 3078 }
3079
3080 splay (op);
3086 3081
3087 /* Can't just apply this object. Lets see what not and what to do */ 3082 /* Can't just apply this object. Lets see what not and what to do */
3088 if (int i = can_apply_object (who, op)) 3083 if (int i = can_apply_object (who, op))
3089 { 3084 {
3090 if (i & CAN_APPLY_NEVER) 3085 if (i & CAN_APPLY_NEVER)
3129 } 3124 }
3130 else 3125 else
3131 /* While experience will be credited properly, we want to change the 3126 /* While experience will be credited properly, we want to change the
3132 * skill so that the dam and wc get updated 3127 * skill so that the dam and wc get updated
3133 */ 3128 */
3134 change_skill (who, skop, 0); 3129 who->change_skill (skop);
3135 } 3130 }
3136 3131
3137 if (who->type == PLAYER 3132 if (who->type == PLAYER
3138 && op->item_power 3133 && op->item_power
3139 && op->item_power + who->contr->item_power > settings.item_power_factor * who->level) 3134 && op->item_power + who->contr->item_power > settings.item_power_factor * who->level)
3159 switch (op->type) 3154 switch (op->type)
3160 { 3155 {
3161 case WEAPON: 3156 case WEAPON:
3162 if (!check_weapon_power (who, op->last_eat)) 3157 if (!check_weapon_power (who, op->last_eat))
3163 { 3158 {
3164 new_draw_info (NDI_UNIQUE, 0, who, "This weapon is too powerful for you to use.\n" 3159 new_draw_info (NDI_UNIQUE, 0, who, "This weapon is too powerful for you to use. "
3165 "It would consume your soul!."); 3160 "It would consume your soul!.");
3166 3161
3167 if (tmp) 3162 if (tmp)
3168 insert_ob_in_ob (tmp, who); 3163 insert_ob_in_ob (tmp, who);
3169 3164
3189 new_draw_info_format (NDI_UNIQUE, 0, who, "The %s is broken, please report this to the dungeon master!", query_name (op));//TODO 3184 new_draw_info_format (NDI_UNIQUE, 0, who, "The %s is broken, please report this to the dungeon master!", query_name (op));//TODO
3190 return 1; 3185 return 1;
3191 } 3186 }
3192 3187
3193 SET_FLAG (op, FLAG_APPLIED); 3188 SET_FLAG (op, FLAG_APPLIED);
3194 change_skill (who, skop, 1); 3189 who->change_skill (skop);
3195 3190
3196 if (who->contr) 3191 if (who->contr)
3197 who->change_weapon (who->contr->combat_ob = op); 3192 who->change_weapon (who->contr->combat_ob = op);
3198 3193
3199 if (!QUERY_FLAG (who, FLAG_READY_WEAPON))
3200 SET_FLAG (who, FLAG_READY_WEAPON);
3201
3202 new_draw_info_format (NDI_UNIQUE, 0, who, "You wield %s.", query_name (op)); 3194 new_draw_info_format (NDI_UNIQUE, 0, who, "You wield %s.", query_name (op));
3203 3195
3196 SET_FLAG (who, FLAG_READY_WEAPON);
3204 change_abil (who, op); 3197 change_abil (who, op);
3205 break; 3198 break;
3206 3199
3207 case ARMOUR: 3200 case ARMOUR:
3208 case HELMET: 3201 case HELMET:
3262 if (who->type == PLAYER) 3255 if (who->type == PLAYER)
3263 esrv_send_item (who, tmp2); 3256 esrv_send_item (who, tmp2);
3264 3257
3265 return 0; 3258 return 0;
3266 3259
3267 /* this part is needed for skill-tools */ 3260 case SKILL_TOOL:
3261 // applying a skill tool also readies the skill
3262 SET_FLAG (op, FLAG_APPLIED);
3263
3264 if (!(aflags & AP_NO_READY))
3265 {
3266 skop = find_skill_by_name (who, op->skill);
3267 if (!skop->flag [FLAG_APPLIED])
3268 apply_special (who, skop, AP_APPLY);
3269 }
3270 break;
3271
3268 case SKILL: 3272 case SKILL:
3269 case SKILL_TOOL:
3270 if (who->chosen_skill)
3271 {
3272 LOG (llevError, "BUG: apply_special(): can't apply two skills\n");
3273 return 1;
3274 }
3275
3276 if (player *pl = who->contr) 3273 if (player *pl = who->contr)
3277 { 3274 {
3278 if (IS_COMBAT_SKILL (op->subtype)) 3275 if (IS_COMBAT_SKILL (op->subtype))
3279 { 3276 {
3280 if (skill_flags [op->subtype] & SF_NEED_WEAPON) 3277 if (skill_flags [op->subtype] & SF_NEED_WEAPON)
3281 { 3278 {
3282 for (object *item = who->inv; item; item = item->below) 3279 for (object *item = who->inv; item; item = item->below)
3283 if (item->type == WEAPON && item->flag [FLAG_APPLIED]) 3280 if (item->type == WEAPON && item->flag [FLAG_APPLIED])
3284 { 3281 {
3282 if (item->skill == op->skill)
3283 {
3285 who->change_weapon (pl->combat_ob = item); 3284 who->change_weapon (pl->combat_ob = item);
3286 goto found_weapon; 3285 goto found_weapon;
3286 }
3287 } 3287 }
3288 3288
3289 new_draw_info (NDI_UNIQUE, 0, who, "You need to apply a melee weapon before readying this skill"); 3289 new_draw_info_format (NDI_UNIQUE, 0, who, "You need to apply a '%s' melee weapon before readying this skill", &op->skill);
3290 return 1; 3290 return 1;
3291 3291
3292 found_weapon:; 3292 found_weapon:;
3293 } 3293 }
3294 else 3294 else
3299 if (skill_flags [op->subtype] & SF_NEED_BOW) 3299 if (skill_flags [op->subtype] & SF_NEED_BOW)
3300 { 3300 {
3301 for (object *item = who->inv; item; item = item->below) 3301 for (object *item = who->inv; item; item = item->below)
3302 if (item->type == BOW && item->flag [FLAG_APPLIED]) 3302 if (item->type == BOW && item->flag [FLAG_APPLIED])
3303 { 3303 {
3304 //TODO: bows should/must all have skill missile weapon right now
3304 who->change_weapon (pl->ranged_ob = item); 3305 who->change_weapon (pl->ranged_ob = item);
3305 goto found_bow; 3306 goto found_bow;
3306 } 3307 }
3307 3308
3308 new_draw_info (NDI_UNIQUE, 0, who, "You need to apply a missile weapon before readying this skill"); 3309 new_draw_info (NDI_UNIQUE, 0, who, "You need to apply a missile weapon before readying this skill");
3309 return 1; 3310 return 1;
3310 3311
3311 found_bow:; 3312 found_bow:;
3312 }
3313 else if (skill_flags [op->subtype] & SF_NEED_ITEM)
3314 {
3315 for (object *item = who->inv; item; item = item->below)
3316 if (item->flag [FLAG_APPLIED]
3317 && (item->type == WAND || item->type == ROD || item->type == HORN))
3318 {
3319 who->change_weapon (pl->ranged_ob = item);
3320 goto found_item;
3321 }
3322
3323 new_draw_info (NDI_UNIQUE, 0, who, "You need to apply a magic item before readying this skill");
3324 return 1;
3325
3326 found_item:;
3327 } 3313 }
3328 else 3314 else
3329 who->change_weapon (pl->ranged_ob = op); 3315 who->change_weapon (pl->ranged_ob = op);
3330 } 3316 }
3331 3317
3335 new_draw_info_format (NDI_UNIQUE, 0, who, "You can now use the skill: %s.", &op->skill); 3321 new_draw_info_format (NDI_UNIQUE, 0, who, "You can now use the skill: %s.", &op->skill);
3336 } 3322 }
3337 else 3323 else
3338 new_draw_info_format (NDI_UNIQUE, 0, who, "Readied skill: %s.", op->skill ? &op->skill : &op->name); 3324 new_draw_info_format (NDI_UNIQUE, 0, who, "Readied skill: %s.", op->skill ? &op->skill : &op->name);
3339 } 3325 }
3340 3326 else
3327 {
3341 SET_FLAG (op, FLAG_APPLIED); 3328 SET_FLAG (op, FLAG_APPLIED);
3342 change_abil (who, op); 3329 change_abil (who, op);
3343 who->chosen_skill = op; 3330 who->chosen_skill = op;
3344 SET_FLAG (who, FLAG_READY_SKILL); 3331 SET_FLAG (who, FLAG_READY_SKILL);
3332 }
3333
3345 break; 3334 break;
3346 3335
3347 case BOW: 3336 case BOW:
3348 if (!check_weapon_power (who, op->last_eat)) 3337 if (!check_weapon_power (who, op->last_eat))
3349 { 3338 {
3376 new_draw_info_format (NDI_UNIQUE, 0, who, "The %s is broken, please report this to the dungeon master!", query_name (op));//TODO 3365 new_draw_info_format (NDI_UNIQUE, 0, who, "The %s is broken, please report this to the dungeon master!", query_name (op));//TODO
3377 return 1; 3366 return 1;
3378 } 3367 }
3379 3368
3380 SET_FLAG (op, FLAG_APPLIED); 3369 SET_FLAG (op, FLAG_APPLIED);
3381 change_skill (who, skop, 0); 3370 who->change_skill (skop);
3382 3371
3383 if (who->contr) 3372 if (who->contr)
3384 { 3373 {
3385 who->contr->ranged_ob = op; 3374 who->contr->ranged_ob = op;
3386 3375
3405 break; 3394 break;
3406 3395
3407 case BUILDER: 3396 case BUILDER:
3408 if (who->type == PLAYER) 3397 if (who->type == PLAYER)
3409 { 3398 {
3399 //TODO: wtf does this do? shouldn't this be managed automatically (slots?)
3410 if (who->contr->ranged_ob && who->contr->ranged_ob->type == BUILDER) 3400 if (who->contr->ranged_ob && who->contr->ranged_ob->type == BUILDER)
3411 unapply_special (who, who->contr->ranged_ob, 0); 3401 unapply_special (who, who->contr->ranged_ob, 0);
3412 3402
3413 new_draw_info_format (NDI_UNIQUE, 0, who, "You ready your %s.", query_name (op)); 3403 new_draw_info_format (NDI_UNIQUE, 0, who, "You ready your %s.", query_name (op));
3414 3404

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines