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.229 by root, Fri Mar 26 20:17:48 2010 UTC vs.
Revision 1.244 by root, Tue Apr 6 00:39:26 2010 UTC

30#include <skills.h> 30#include <skills.h>
31#include <tod.h> 31#include <tod.h>
32 32
33#include <sproto.h> 33#include <sproto.h>
34 34
35/* Want this regardless of rplay. */
36#include <sounds.h>
37
38/** 35/**
39 * Check if op should abort moving victim because of it's race or slaying. 36 * Check if op should abort moving victim because of it's race or slaying.
40 * Returns 1 if it should abort, returns 0 if it should continue. 37 * Returns 1 if it should abort, returns 0 if it should continue.
41 */ 38 */
42int 39int
951 item->nrof *= nr; 948 item->nrof *= nr;
952 949
953 if (converter->flag [FLAG_PRECIOUS]) 950 if (converter->flag [FLAG_PRECIOUS])
954 SET_FLAG (item, FLAG_UNPAID); 951 SET_FLAG (item, FLAG_UNPAID);
955 952
956 if (is_in_shop (converter)) 953 if (converter->is_in_shop ())
957 { 954 {
958 // converters on shop floors don't work anymore, bug lets check for it 955 // converters on shop floors don't work anymore, bug lets check for it
959 // and report in case someone still does it. 956 // and report in case someone still does it.
960 LOG (llevDebug, "ITEMBUG: broken converter, converters on shop floor don't work: %s\n", 957 LOG (llevDebug, "ITEMBUG: broken converter, converters on shop floor don't work: %s\n",
961 converter->debug_desc ()); 958 converter->debug_desc ());
1164 /* this is only used for players */ 1161 /* this is only used for players */
1165 rv = teleport (shop_mat, SHOP_MAT, op); 1162 rv = teleport (shop_mat, SHOP_MAT, op);
1166 1163
1167 if (has_unpaid) 1164 if (has_unpaid)
1168 op->contr->play_sound (sound_find ("shop_buy")); 1165 op->contr->play_sound (sound_find ("shop_buy"));
1169 else if (is_in_shop (op)) 1166 else if (op->is_in_shop ())
1170 op->contr->play_sound (sound_find ("shop_enter")); 1167 op->contr->play_sound (sound_find ("shop_enter"));
1171 else 1168 else
1172 op->contr->play_sound (sound_find ("shop_leave")); 1169 op->contr->play_sound (sound_find ("shop_leave"));
1173 1170
1174 if (shop_mat->msg) 1171 if (shop_mat->msg)
1175 op->statusmsg (shop_mat->msg); 1172 op->statusmsg (shop_mat->msg);
1176 /* This check below is a bit simplistic - generally it should be correct, 1173 /* This check below is a bit simplistic - generally it should be correct,
1177 * but there is never a guarantee that the bottom space on the map is 1174 * but there is never a guarantee that the bottom space on the map is
1178 * actually the shop floor. 1175 * actually the shop floor.
1179 */ 1176 */
1180 else if (!rv && !is_in_shop (op)) 1177 else if (!rv && !op->is_in_shop ())
1181 { 1178 {
1182 opinion = shopkeeper_approval (op->map, op); 1179 opinion = shopkeeper_approval (op->map, op);
1183 1180
1184 op->statusmsg ( 1181 op->statusmsg (
1185 opinion >= 0.90 ? "The shopkeeper gives you a friendly wave." 1182 opinion >= 0.90 ? "The shopkeeper gives you a friendly wave."
1742 LOG (llevError, "BUG: do_forget_spell(): spell not known\n"); 1739 LOG (llevError, "BUG: do_forget_spell(): spell not known\n");
1743 return; 1740 return;
1744 } 1741 }
1745 1742
1746 op->failmsg (format ("You lose knowledge of %s.", spell)); 1743 op->failmsg (format ("You lose knowledge of %s.", spell));
1747 player_unready_range_ob (op->contr, spob);
1748 esrv_remove_spell (op->contr, spob); 1744 esrv_remove_spell (op->contr, spob);
1749 spob->destroy (); 1745 spob->destroy ();
1750} 1746}
1751 1747
1752/** 1748/**
1809 op->failmsg (format ("You are unable to decipher the strange symbols. H<Your %s level is too low, it must be at least %d.>", 1805 op->failmsg (format ("You are unable to decipher the strange symbols. H<Your %s level is too low, it must be at least %d.>",
1810 &tmp->skill, learn_level)); 1806 &tmp->skill, learn_level));
1811 return; 1807 return;
1812 } 1808 }
1813 1809
1814 op->statusmsg (format ("The spellbook contains the %s level spell %s.", get_levelnumber (spell->level), &spell->name)); 1810 op->statusmsg (format ("The spellbook contains the %s level spell %s.", ordinal (spell->level), &spell->name));
1815 1811
1816 if (!QUERY_FLAG (tmp, FLAG_IDENTIFIED)) 1812 if (!QUERY_FLAG (tmp, FLAG_IDENTIFIED))
1817 identify (tmp); 1813 identify (tmp);
1818 1814
1819 /* I removed the check for special_prayer_mark here - it didn't make 1815 /* I removed the check for special_prayer_mark here - it didn't make
1831 { 1827 {
1832 spell_skill = find_skill_by_name (op, spell->skill); 1828 spell_skill = find_skill_by_name (op, spell->skill);
1833 1829
1834 if (!spell_skill) 1830 if (!spell_skill)
1835 { 1831 {
1836 op->failmsg (format ("You lack the skill %s to use this spell.", &spell->skill)); 1832 op->failmsg (format ("You lack the %s skill to use this spell.", &spell->skill));
1837 return; 1833 return;
1838 } 1834 }
1839 1835
1840 if (spell_skill->level < spell->level) 1836 if (spell_skill->level < spell->level)
1841 { 1837 {
2019 which is not to be considered a dragon -> bail out */ 2015 which is not to be considered a dragon -> bail out */
2020 if (skin == NULL || abil == NULL) 2016 if (skin == NULL || abil == NULL)
2021 return 0; 2017 return 0;
2022 2018
2023 /* now start by filling stomache and health, according to food-value */ 2019 /* now start by filling stomache and health, according to food-value */
2024 if ((999 - op->stats.food) < meal->stats.food) 2020 if ((MAX_FOOD - op->stats.food) < meal->stats.food)
2025 op->stats.hp += (999 - op->stats.food) / 50; 2021 op->stats.hp += (MAX_FOOD - op->stats.food) / 50;
2026 else 2022 else
2027 op->stats.hp += meal->stats.food / 50; 2023 op->stats.hp += meal->stats.food / 50;
2028 2024
2029 if (op->stats.hp > op->stats.maxhp) 2025 min_it (op->stats.hp, op->stats.maxhp);
2030 op->stats.hp = op->stats.maxhp;
2031
2032 op->stats.food = min (999, op->stats.food + meal->stats.food); 2026 op->stats.food = min (MAX_FOOD, op->stats.food + meal->stats.food);
2033 2027
2034 /*LOG(llevDebug, "-> player: %d, flesh: %d\n", op->level, meal->level); */ 2028 /*LOG(llevDebug, "-> player: %d, flesh: %d\n", op->level, meal->level); */
2035 2029
2036 /* on to the interesting part: chances for adding resistance */ 2030 /* on to the interesting part: chances for adding resistance */
2037 for (i = 0; i < NROFATTACKS; i++) 2031 for (i = 0; i < NROFATTACKS; i++)
2154 if (tmp->type == FLESH && op->is_dragon () && dragon_eat_flesh (op, tmp)) 2148 if (tmp->type == FLESH && op->is_dragon () && dragon_eat_flesh (op, tmp))
2155 ; 2149 ;
2156 else 2150 else
2157 { 2151 {
2158 /* usual case - no dragon meal: */ 2152 /* usual case - no dragon meal: */
2159 if (op->stats.food + tmp->stats.food > 999) 2153 if (op->stats.food + tmp->stats.food > MAX_FOOD)
2160 { 2154 {
2161 if (tmp->type == FOOD || tmp->type == FLESH) 2155 if (tmp->type == FOOD || tmp->type == FLESH)
2162 op->failmsg ("You feel full, but what a waste of food!"); 2156 op->failmsg ("You feel full, but what a waste of food!");
2163 else 2157 else
2164 op->statusmsg ("Most of the drink goes down your face not your throat!"); 2158 op->statusmsg ("Most of the drink goes down your face not your throat!");
2188 /* eating message for dragon players */ 2182 /* eating message for dragon players */
2189 buf = format ("The %s tasted terrible!", &tmp->name); 2183 buf = format ("The %s tasted terrible!", &tmp->name);
2190 2184
2191 op->statusmsg (buf); 2185 op->statusmsg (buf);
2192 2186
2193 capacity_remaining = 999 - op->stats.food; 2187 capacity_remaining = MAX_FOOD - op->stats.food;
2194 op->stats.food += tmp->stats.food; 2188 op->stats.food += tmp->stats.food;
2195 if (capacity_remaining < tmp->stats.food) 2189 if (capacity_remaining < tmp->stats.food)
2196 op->stats.hp += capacity_remaining / 50; 2190 op->stats.hp += capacity_remaining / 50;
2197 else 2191 else
2198 op->stats.hp += tmp->stats.food / 50; 2192 op->stats.hp += tmp->stats.food / 50;
2199 2193
2200 if (op->stats.hp > op->stats.maxhp) 2194 min_it (op->stats.hp, op->stats.maxhp);
2201 op->stats.hp = op->stats.maxhp; 2195 min_it (op->stats.food, MAX_FOOD);
2202 if (op->stats.food > 999)
2203 op->stats.food = 999;
2204 } 2196 }
2205 2197
2206 /* special food hack -b.t. */ 2198 /* special food hack -b.t. */
2207 if (tmp->title || QUERY_FLAG (tmp, FLAG_CURSED)) 2199 if (tmp->title || QUERY_FLAG (tmp, FLAG_CURSED))
2208 eat_special_food (op, tmp); 2200 eat_special_food (op, tmp);
2634 * being applied. 2626 * being applied.
2635 * 2627 *
2636 * aflag is special (always apply/unapply) flags. Nothing is done with 2628 * aflag is special (always apply/unapply) flags. Nothing is done with
2637 * them in this function - they are passed to apply_special 2629 * them in this function - they are passed to apply_special
2638 */ 2630 */
2639int 2631static int
2640manual_apply (object *who, object *op, int aflag) 2632manual_apply (object *who, object *op, int aflag)
2641{ 2633{
2642 op = op->head_ (); 2634 op = op->head_ ();
2643 2635
2644 if (QUERY_FLAG (op, FLAG_UNPAID) && !QUERY_FLAG (op, FLAG_APPLIED)) 2636 if (op->flag [FLAG_UNPAID] && !op->flag [FLAG_APPLIED])
2645 { 2637 {
2646 if (who->type == PLAYER) 2638 if (who->type == PLAYER)
2647 { 2639 {
2648 examine (who, op); 2640 examine (who, op);
2649 //who->failmsg ("You should pay for it first! H<You cannot use items marked as unpaid.>");//TODO remove 2641 //who->failmsg ("You should pay for it first! H<You cannot use items marked as unpaid.>");//TODO remove
2776 case CLOAK: 2768 case CLOAK:
2777 case WAND: 2769 case WAND:
2778 case ROD: 2770 case ROD:
2779 case HORN: 2771 case HORN:
2780 case SKILL: 2772 case SKILL:
2773 case SPELL:
2781 case BOW: 2774 case BOW:
2775 case RANGED:
2782 case BUILDER: 2776 case BUILDER:
2783 case SKILL_TOOL: 2777 case SKILL_TOOL:
2784 if (op->env != who) 2778 if (op->env != who)
2785 return 2; /* not in inventory */ 2779 who->failmsg (format ("You must get it first! H<You can only apply the %s if it is in your inventory.>\n", query_name (op)));
2786 2780 else
2787 apply_special (who, op, aflag); 2781 apply_special (who, op, aflag);
2782
2788 return 1; 2783 return 1;
2789 2784
2790 case DRINK: 2785 case DRINK:
2791 case FOOD: 2786 case FOOD:
2792 case FLESH: 2787 case FLESH:
2856 case ITEM_TRANSFORMER: 2851 case ITEM_TRANSFORMER:
2857 apply_item_transformer (who, op); 2852 apply_item_transformer (who, op);
2858 return 1; 2853 return 1;
2859 2854
2860 default: 2855 default:
2856 who->statusmsg (format ("I don't know how to apply the %s.", query_name (op)));
2861 return 0; 2857 return 0;
2862 } 2858 }
2863}
2864
2865/* quiet suppresses the "don't know how to apply" and "you must get it first"
2866 * messages as needed by player_apply_below(). But there can still be
2867 * "but you are floating high above the ground" messages.
2868 *
2869 * Same return value as apply() function.
2870 */
2871int
2872player_apply (object *pl, object *op, int aflag, int quiet)
2873{
2874 if (!op->env && (pl->move_type & MOVE_FLYING))
2875 {
2876 /* player is flying and applying object not in inventory */
2877 if (!QUERY_FLAG (pl, FLAG_WIZ) && !(op->move_type & MOVE_FLYING))
2878 {
2879 pl->failmsg ("But you are floating high above the ground! "
2880 "H<You have to stop levitating first, if you can, either by using your levitation skill, "
2881 "or waiting till the levitation effect wears off.>");
2882 return 0;
2883 }
2884 }
2885
2886 pl->contr->last_used = op;
2887
2888 int tmp = manual_apply (pl, op, aflag);
2889
2890 if (!quiet)
2891 {
2892 if (tmp == 0)
2893 pl->statusmsg (format ("I don't know how to apply the %s.", query_name (op)));
2894 else if (tmp == 2)
2895 pl->failmsg ("You must get it first!\n");
2896 }
2897
2898 return tmp;
2899} 2859}
2900 2860
2901/** 2861/**
2902 * player_apply_below attempts to apply the object 'below' the player. 2862 * player_apply_below attempts to apply the object 'below' the player.
2903 * If the player has an open container, we use that for below, otherwise 2863 * If the player has an open container, we use that for below, otherwise
2914 * we don't use a corrupt pointer for the next object, so we get the 2874 * we don't use a corrupt pointer for the next object, so we get the
2915 * next object in the stack before applying. This is can only be a 2875 * next object in the stack before applying. This is can only be a
2916 * problem if player_apply() has a bug in that it uses the object but does 2876 * problem if player_apply() has a bug in that it uses the object but does
2917 * not return a proper value. 2877 * not return a proper value.
2918 */ 2878 */
2879 //TODO: no longer at multiple floors
2880 // and also not on move_on floors. what was this for, anyways?
2919 for (object *next, *tmp = pl->container_ () ? pl->container_ ()->inv : pl->below; tmp; tmp = next) 2881 for (object *next, *tmp = pl->container_ () ? pl->container_ ()->inv : pl->below; tmp; tmp = next)
2920 { 2882 {
2921 next = tmp->below; 2883 next = tmp->below;
2922 2884
2923 if (QUERY_FLAG (tmp, FLAG_IS_FLOOR)) 2885 if (tmp->type == SPELL_EFFECT || tmp->invisible)
2924 floors++; 2886 continue;
2925 else if (floors > 0)
2926 return; /* process only floor objects after first floor object */
2927 2887
2928 /* If it is visible, player can apply it. If it is applied by 2888 /* If it is visible, player can apply it.
2929 * person moving on it, also activate. Added code to make it
2930 * so that at least one of players movement types be that which
2931 * the item needs.
2932 */ 2889 */
2933 if (!tmp->invisible || (tmp->move_on & pl->move_type)) 2890 if (pl->apply (tmp))
2934 if (player_apply (pl, tmp, 0, 1) == 1) 2891 break;
2935 return;
2936
2937 if (floors >= 2)
2938 return; /* process at most two floor objects */
2939 } 2892 }
2940} 2893}
2941 2894
2942/** 2895/**
2943 * Unapplies specified item. 2896 * Unapplies specified item.
2950{ 2903{
2951 if (INVOKE_OBJECT (BE_UNREADY, op, ARG_OBJECT (who), ARG_INT (aflags)) 2904 if (INVOKE_OBJECT (BE_UNREADY, op, ARG_OBJECT (who), ARG_INT (aflags))
2952 || INVOKE_OBJECT (UNREADY, who, ARG_OBJECT (op), ARG_INT (aflags))) 2905 || INVOKE_OBJECT (UNREADY, who, ARG_OBJECT (op), ARG_INT (aflags)))
2953 return RESULT_INT (0); 2906 return RESULT_INT (0);
2954 2907
2955 CLEAR_FLAG (op, FLAG_APPLIED); 2908 if (who->current_weapon == op)
2909 who->current_weapon = 0;
2910
2911 op->flag [FLAG_APPLIED] = false;
2956 2912
2957 switch (op->type) 2913 switch (op->type)
2958 { 2914 {
2959 case SKILL_TOOL: 2915 case SKILL:
2916 if (player *pl = who->contr)
2917 if (op->invisible)
2918 pl->statusmsg (format ("You can no longer use the %s skill.", &op->skill));
2919 else
2920 pl->statusmsg (format ("You stop using the %s.", query_name (op)));
2921
2922 change_abil (who, op);
2923 who->flag [FLAG_READY_SKILL] = false;
2924 break;
2925
2926 case WEAPON:
2927 who->statusmsg (format ("You unwield %s.", query_name (op)));
2928 change_abil (who, op);
2929 who->flag [FLAG_READY_WEAPON] = false;
2930
2960 // unapplying a skill tool should also unapply the skill it governs 2931 // unapplying a weapon or skill tool should also unapply the skill it governs
2961 // but this is hard, as it shouldn't do so when the skill can 2932 // but this is hard, as it shouldn't do so when the skill can
2962 // be used for other reasons 2933 // be used for other reasons
2963 for (object *tmp = who->inv; tmp; tmp = tmp->below) 2934 if (who->chosen_skill)
2964 if (tmp->skill == op->skill 2935 if (!who->chosen_skill->flag [FLAG_CAN_USE_SKILL])
2965 && tmp->type == SKILL
2966 && tmp->flag [FLAG_APPLIED]
2967 && !tmp->flag [FLAG_CAN_USE_SKILL])
2968 unapply_special (who, tmp, 0); 2936 unapply_special (who, op, 0);
2969 2937
2970 change_abil (who, op);
2971 break; 2938 break;
2972 2939
2940 case BOW:
2973 case WEAPON: 2941 case WAND:
2942 case ROD:
2943 case HORN:
2944 case RANGED:
2974 if (player *pl = who->contr) 2945 if (player *pl = who->contr)
2975 if (op == pl->combat_ob)
2976 {
2977 pl->combat_ob = 0;
2978 who->change_weapon (pl->ranged_ob);
2979 }
2980
2981 who->statusmsg (format ("You unwield %s.", query_name (op)));
2982
2983 change_abil (who, op);
2984 CLEAR_FLAG (who, FLAG_READY_WEAPON);
2985 break;
2986
2987 case SKILL:
2988 if (who->contr)
2989 { 2946 {
2990 if (IS_COMBAT_SKILL (op->subtype)) 2947 who->statusmsg (format ("You unready %s.", query_name (op)));
2991 who->change_weapon (who->contr->combat_ob = 0); 2948 change_abil (who, op);
2992 else if (IS_RANGED_SKILL (op->subtype)) 2949 }
2993 who->change_weapon (who->contr->ranged_ob = 0); 2950 else
2951 {
2952 who->change_skill (0);
2994 2953
2995 if (op->invisible) 2954 if (op->type == BOW)
2996 who->statusmsg (format ("You can no longer use the skill: %s.", &op->skill)); 2955 op->flag [FLAG_READY_BOW ] = false;
2997 else 2956 else
2998 who->statusmsg (format ("You stop using the %s.", query_name (op))); 2957 op->flag [FLAG_READY_RANGE] = false;
2999 } 2958 }
3000 2959
3001 change_abil (who, op);
3002 CLEAR_FLAG (who, FLAG_READY_SKILL);
3003 break; 2960 break;
3004 2961
3005 case ARMOUR: 2962 case ARMOUR:
3006 case HELMET: 2963 case HELMET:
3007 case SHIELD: 2964 case SHIELD:
3014 case CLOAK: 2971 case CLOAK:
3015 who->statusmsg (format ("You unwear %s.", query_name (op))); 2972 who->statusmsg (format ("You unwear %s.", query_name (op)));
3016 change_abil (who, op); 2973 change_abil (who, op);
3017 break; 2974 break;
3018 2975
2976 case SPELL:
3019 case BOW: 2977 case BUILDER:
3020 case WAND:
3021 case ROD:
3022 case HORN:
3023 if (player *pl = who->contr)
3024 {
3025 if (op == pl->ranged_ob)
3026 {
3027 pl->ranged_ob = 0;
3028 who->change_weapon (pl->combat_ob);
3029 }
3030
3031 who->statusmsg (format ("You unready %s.", query_name (op))); 2978 who->statusmsg (format ("You unready %s.", query_name (op)));
3032 }
3033 else
3034 {
3035 who->change_skill (0);
3036
3037 if (op->type == BOW)
3038 CLEAR_FLAG (who, FLAG_READY_BOW);
3039 else
3040 CLEAR_FLAG (who, FLAG_READY_RANGE);
3041 }
3042
3043 break; 2979 break;
3044 2980
3045 case BUILDER: 2981 //case SKILL_TOOL://TODO
3046 if (who->contr)
3047 who->statusmsg (format ("You unready %s.", query_name (op)));
3048 break;
3049
3050 default: 2982 default:
3051 who->statusmsg (format ("You unapply %s.", query_name (op))); 2983 who->statusmsg (format ("You unapply %s.", query_name (op)));
3052 break; 2984 break;
3053 } 2985 }
3054 2986
3078static object * 3010static object *
3079get_next_item_from_body_location (int loc, object *start) 3011get_next_item_from_body_location (int loc, object *start)
3080{ 3012{
3081 for (object *tmp = start; tmp; tmp = tmp->below) 3013 for (object *tmp = start; tmp; tmp = tmp->below)
3082 if (tmp->flag [FLAG_APPLIED] 3014 if (tmp->flag [FLAG_APPLIED]
3083 && tmp->slot[loc].info 3015 && tmp->slot [loc].info
3084 && (!tmp->invisible || tmp->type == SKILL)) 3016 && (!tmp->invisible || tmp->type == SKILL || tmp->type == SPELL))
3085 return tmp; 3017 return tmp;
3086 3018
3087 return 0; 3019 return 0;
3088} 3020}
3089 3021
3234 continue; 3166 continue;
3235 } 3167 }
3236 3168
3237 object *tmp1 = get_next_item_from_body_location (i, who->inv); 3169 object *tmp1 = get_next_item_from_body_location (i, who->inv);
3238 if (!tmp1) 3170 if (!tmp1)
3239 {
3240#if 0
3241 /* This is sort of an error, but happens a lot when old players
3242 * join in with more stuff equipped than they are now allowed.
3243 */
3244 LOG (llevError, "Can't find object using location %d on %s\n", i, who->name);
3245#endif
3246 retval |= CAN_APPLY_NEVER; 3171 retval |= CAN_APPLY_NEVER;
3247 }
3248 else 3172 else
3249 { 3173 {
3250 /* need to unapply something. However, if this something 3174 /* need to unapply something. However, if this something
3251 * is different than we had found before, it means they need 3175 * is different than we had found before, it means they need
3252 * to apply multiple objects 3176 * to apply multiple objects
3303 if (op->type == BOW && !QUERY_FLAG (who, FLAG_USE_BOW)) 3227 if (op->type == BOW && !QUERY_FLAG (who, FLAG_USE_BOW))
3304 retval |= CAN_APPLY_RESTRICTION; 3228 retval |= CAN_APPLY_RESTRICTION;
3305 } 3229 }
3306 3230
3307 return retval; 3231 return retval;
3232}
3233
3234// saner interface, returns successful status
3235bool
3236object::apply (object *ob, int aflags)
3237{
3238 if (!ob) // simplifies a lot of callers
3239 return true;
3240
3241 if (contr)
3242 {
3243 if (!ob->env && (move_type & MOVE_FLYING))
3244 {
3245 /* player is flying and applying object not in inventory */
3246 if (!flag [FLAG_WIZ] && !(ob->move_type & MOVE_FLYING))
3247 {
3248 failmsg ("But you are floating high above the ground! "
3249 "H<You have to stop levitating first, if you can, either by using your levitation skill, "
3250 "or waiting till the levitation effect wears off.>");
3251 return 0;
3252 }
3253 }
3254
3255 contr->last_used = ob;
3256 }
3257
3258 bool want_apply =
3259 aflags & AP_APPLY ? true
3260 : aflags & AP_UNAPPLY ? false
3261 : !ob->flag [FLAG_APPLIED]; // AP_TOGGLE
3262
3263 object_ptr *slot = 0;
3264
3265 // detect the slot, if this is a player
3266 if (contr && !(aflags & AP_NO_SLOT))
3267 {
3268 object *oslot;
3269
3270 switch (ob->type)
3271 {
3272 case WEAPON:
3273 slot = &contr->combat_ob;
3274 oslot = contr->ranged_ob;
3275 break;
3276
3277 case BOW:
3278 case RANGED:
3279 case SPELL:
3280 case WAND:
3281 case ROD:
3282 case HORN:
3283 case BUILDER:
3284 slot = &contr->ranged_ob;
3285 oslot = contr->combat_ob;
3286 break;
3287
3288 // oh, the humanity
3289 case SKILL:
3290 if (aflags & AP_NO_SLOT)
3291 break;
3292
3293 if (skill_flags [ob->subtype] & SF_NEED_ITEM)
3294 break;
3295
3296 if (skill_flags [ob->subtype] & SF_COMBAT)
3297 {
3298 slot = &contr->combat_ob;
3299 oslot = contr->ranged_ob;
3300 }
3301 else if (skill_flags [ob->subtype] & SF_RANGED)
3302 {
3303 slot = &contr->ranged_ob;
3304 oslot = contr->combat_ob;
3305 }
3306
3307 break;
3308 }
3309
3310 // now handle slot exclusions
3311 if (slot)
3312 {
3313 // only one slot can be active
3314 if (want_apply)
3315 {
3316 // clear slot unless we are in it already
3317 if (*slot != ob)
3318 apply (*slot, AP_UNAPPLY);
3319
3320 // unapply other slot, because we want to become active
3321 apply (oslot, AP_UNAPPLY);
3322 }
3323
3324 // clear item from slot if applied
3325 if (!want_apply && current_weapon == ob)
3326 current_weapon = 0;
3327 }
3328 }
3329
3330 if (ob->flag [FLAG_APPLIED] != want_apply)
3331 manual_apply (this, ob, aflags);
3332
3333 if (ob->flag [FLAG_APPLIED] != want_apply)
3334 return false;
3335
3336 if (slot && want_apply)
3337 current_weapon = *slot = ob;
3338
3339 return true;
3308} 3340}
3309 3341
3310/** 3342/**
3311 * who is the object using the object. It can be a monster. 3343 * who is the object using the object. It can be a monster.
3312 * op is the object they are using. op is an equipment type item, 3344 * op is the object they are using. op is an equipment type item,
3335 " H<You lack enough unused item power to use this weapon, see the skills command.>" 3367 " H<You lack enough unused item power to use this weapon, see the skills command.>"
3336 3368
3337int 3369int
3338apply_special (object *who, object *op, int aflags) 3370apply_special (object *who, object *op, int aflags)
3339{ 3371{
3340 int basic_flag = aflags & AP_BASIC_FLAGS; 3372 int basic_flag = aflags & AP_MODE;
3341 object *tmp, *tmp2, *skop = NULL; 3373 object *tmp, *tmp2, *skop = NULL;
3342 3374
3343 if (who == NULL) 3375 if (who == NULL)
3344 { 3376 {
3345 LOG (llevError, "apply_special() from object without environment.\n"); 3377 LOG (llevError, "apply_special() from object without environment.\n");
3364 3396
3365 return unapply_special (who, op, aflags); 3397 return unapply_special (who, op, aflags);
3366 } 3398 }
3367 else if (basic_flag == AP_UNAPPLY) 3399 else if (basic_flag == AP_UNAPPLY)
3368 return 0; 3400 return 0;
3369
3370 // if the item is combat/ranged, wield the relevant slot first
3371 // to resolve conflicts.
3372 if (player *pl = who->contr)
3373 switch (op->slottype ())
3374 {
3375 case slot_combat: who->change_weapon (pl->combat_ob); break;
3376 case slot_ranged: who->change_weapon (pl->ranged_ob); break;
3377 }
3378 3401
3379 splay (op); 3402 splay (op);
3380 3403
3381 /* Can't just apply this object. Lets see what not and what to do */ 3404 /* Can't just apply this object. Lets see what not and what to do */
3382 if (int i = can_apply_object (who, op)) 3405 if (int i = can_apply_object (who, op))
3416 } 3439 }
3417 } 3440 }
3418 3441
3419 if (op->skill && op->type != SKILL && op->type != SKILL_TOOL) 3442 if (op->skill && op->type != SKILL && op->type != SKILL_TOOL)
3420 { 3443 {
3444 // try to ready attached skill first
3421 skop = find_skill_by_name (who, op->skill); 3445 skop = find_skill_by_name (who, op->skill);
3422 3446
3423 if (!skop) 3447 if (!skop)
3424 { 3448 {
3425 who->failmsg (format ("You need the %s skill to use this item!", &op->skill)); 3449 who->failmsg (format ("You need the %s skill to use this item!", &op->skill));
3426 return 1; 3450 return 1;
3427 } 3451 }
3428 else 3452 else if (!who->apply (skop, AP_APPLY | AP_NO_SLOT))
3429 /* While experience will be credited properly, we want to change the
3430 * skill so that the dam and wc get updated
3431 */ 3453 {
3432 who->change_skill (skop); 3454 who->failmsg (format ("You can't use the required %s skill!", &op->skill));
3455 return 1;
3456 }
3433 } 3457 }
3434 3458
3435 if (!check_item_power (who, op->item_power)) 3459 if (!check_item_power (who, op->item_power))
3436 { 3460 {
3437 who->failmsg ("Equipping that combined with other items would consume your soul!" LACK_ITEM_POWER); 3461 who->failmsg ("Equipping that combined with other items would consume your soul!" LACK_ITEM_POWER);
3440 3464
3441 /* Ok. We are now at the state where we can apply the new object. 3465 /* Ok. We are now at the state where we can apply the new object.
3442 * Note that we don't have the checks for can_use_... 3466 * Note that we don't have the checks for can_use_...
3443 * below - that is already taken care of by can_apply_object. 3467 * below - that is already taken care of by can_apply_object.
3444 */ 3468 */
3469
3470 // split away all the other items from the stack, so only one item is left
3445 tmp = op->nrof > 1 ? op->split (op->nrof - 1) : 0; 3471 tmp = op->nrof > 1 ? op->split (op->nrof - 1) : 0;
3446 3472
3447 if (INVOKE_OBJECT (BE_READY, op, ARG_OBJECT (who)) || INVOKE_OBJECT (READY, who, ARG_OBJECT (op))) 3473 if (INVOKE_OBJECT (BE_READY, op, ARG_OBJECT (who)) || INVOKE_OBJECT (READY, who, ARG_OBJECT (op)))
3448 return RESULT_INT (0); 3474 return RESULT_INT (0);
3449 3475
3450 switch (op->type) 3476 switch (op->type)
3451 { 3477 {
3452 case WEAPON: 3478 case WEAPON:
3453 //TODO: this obviously fails for players using a shorter prefix 3479 if (op->level && (!op->name.starts_with (who->name) || op->name [who->name.length ()] != '\''))
3454 // i.e. "R" can use Ragnarok's sword.
3455 if (op->level && !op->name.starts_with (who->name))
3456 { 3480 {
3457 /* if the weapon does not have the name as the character, can't use it. */ 3481 /* if the weapon does not have the name as the character, can't use it. */
3458 /* (Ragnarok's sword attempted to be used by Foo: won't work) */ 3482 /* (Ragnarok's sword attempted to be used by Foo: won't work) */
3459 who->failmsg ("The weapon does not recognize you as its owner. H<Its name indicates that it belongs to somebody else.>"); 3483 who->failmsg ("The weapon does not recognize you as its owner. "
3460 3484 "H<Its name indicates that it belongs to somebody else.>");
3461 if (tmp) 3485 if (tmp) who->insert (tmp);
3462 insert_ob_in_ob (tmp, who);
3463
3464 return 1; 3486 return 1;
3465 } 3487 }
3466 3488
3467 if (!skop) 3489 op->flag [FLAG_APPLIED] = true;
3490
3491 if (player *pl = who->contr)
3468 { 3492 {
3469 who->failmsg (format ("The %s is broken, please report this to the dungeon master!", query_name (op)));//TODO 3493 who->statusmsg (format ("You wield %s.", query_name (op)));
3470 return 1; 3494 change_abil (who, op);
3471 } 3495 }
3472 3496 else
3473 SET_FLAG (op, FLAG_APPLIED);
3474 who->change_skill (skop); 3497 who->change_skill (skop);
3475 3498
3476 if (who->contr) 3499 op->flag [FLAG_READY_WEAPON] = true;
3477 who->change_weapon (who->contr->combat_ob = op);
3478
3479 who->statusmsg (format ("You wield %s.", query_name (op)));
3480
3481 SET_FLAG (who, FLAG_READY_WEAPON);
3482 change_abil (who, op);
3483 break; 3500 break;
3484 3501
3485 case ARMOUR: 3502 case ARMOUR:
3486 case HELMET: 3503 case HELMET:
3487 case SHIELD: 3504 case SHIELD:
3496 who->statusmsg (format ("You wear %s.", query_name (op))); 3513 who->statusmsg (format ("You wear %s.", query_name (op)));
3497 change_abil (who, op); 3514 change_abil (who, op);
3498 break; 3515 break;
3499 3516
3500 case SKILL_TOOL: 3517 case SKILL_TOOL:
3501 // applying a skill tool also readies the skill 3518 // applying a skill tool does not ready the skill
3519 // if something needs the skill, it has to ready it itself
3520 //TODO: unapplying should unapply the skill, though
3502 SET_FLAG (op, FLAG_APPLIED); 3521 SET_FLAG (op, FLAG_APPLIED);
3522 break;
3503 3523
3524 case SKILL:
3504 if (!(aflags & AP_NO_READY)) 3525 if (!(aflags & AP_NO_SLOT))
3505 { 3526 {
3506 skop = find_skill_by_name (who, op->skill); 3527 // skill is used on it's own, as opposed to being a chosen_skill
3507 if (!skop->flag [FLAG_APPLIED])
3508 apply_special (who, skop, AP_APPLY);
3509 }
3510 break;
3511 3528
3512 case SKILL: 3529 if (skill_flags [op->subtype] & (SF_NEED_ITEM | SF_MANA))
3513 if (player *pl = who->contr)
3514 {
3515 if (IS_COMBAT_SKILL (op->subtype))
3516 { 3530 {
3517 if (skill_flags [op->subtype] & SF_NEED_ITEM)
3518 {
3519 for (object *item = who->inv; item; item = item->below)
3520 if (item->type == item->weapontype && item->flag [FLAG_APPLIED])
3521 {
3522 if (item->skill == op->skill)
3523 {
3524 who->change_weapon (pl->combat_ob = item);
3525 goto found_weapon;
3526 }
3527 }
3528
3529 who->failmsg (format ( 3531 who->failmsg (format (
3530 "You need to apply a '%s' melee weapon before readying this skill. " 3532 "You feel as if you wanted to do something funny, but you can't remember what. "
3531 "H<Some skills need an item, in this case a melee weapon, to function.>", 3533 "H<The %s skill needs something else to function, for example a tool, weapon, rod, or spell. "
3532 &op->skill 3534 "It cannot be used on its own.>",
3533 ));
3534 return 1;
3535
3536 found_weapon:;
3537 }
3538 else
3539 who->change_weapon (pl->combat_ob = op);
3540 }
3541 else if (IS_RANGED_SKILL (op->subtype))
3542 {
3543 if (skill_flags [op->subtype] & SF_NEED_ITEM)
3544 {
3545 for (object *item = who->inv; item; item = item->below)
3546 if (item->type == item->weapontype && item->flag [FLAG_APPLIED])
3547 {
3548 //TODO: bows should/must all have skill missile weapon right now
3549 who->change_weapon (pl->ranged_ob = item);
3550 goto found_bow;
3551 }
3552
3553 who->failmsg (
3554 "You need to apply a missile weapon before readying this skill. "
3555 "H<Some skills need an item, in this case a missile weapon, to function.>"
3556 );
3557 return 1;
3558
3559 found_bow:;
3560 }
3561 else
3562 who->change_weapon (pl->ranged_ob = op);
3563 }
3564
3565 if (!op->invisible)
3566 {
3567 who->statusmsg (format (
3568 "You ready %s."
3569 "You can now use the skill: %s.",
3570 query_name (op),
3571 &op->skill 3535 &op->skill
3572 )); 3536 ));
3537 if (tmp) who->insert (tmp);
3538 return 1;
3573 } 3539 }
3540
3541 if (skill_flags [op->subtype] & SF_AUTARK
3542 || !(skill_flags [op->subtype] & (SF_COMBAT | SF_RANGED)))
3543 {
3544 if (skill_flags [op->subtype] & SF_USE)
3545 who->failmsg (format (
3546 "You feel as if you wanted to do something funny, but you can't remember what. "
3547 "H<The %s skill cannot be readied, instead, try C<use_skill %s>.>",
3548 &op->skill, &op->skill
3549 ));
3550 else
3551 who->failmsg (format (
3552 "You feel as if you wanted to do something funny, but you can't remember what. "
3553 "H<The %s skill cannot be readied or used, it is always active.>",
3554 &op->skill
3555 ));
3556
3557 if (tmp) who->insert (tmp);
3558
3559 return 1;
3560 }
3561
3562 if (who->contr)
3563 if (op->invisible)
3564 who->statusmsg (format ("You can now use the %s skill.", &op->skill));
3574 else 3565 else
3575 who->statusmsg (format ("Readied skill: %s.", op->skill ? &op->skill : &op->name)); 3566 who->statusmsg (format ("You ready %s.", query_name (op)));
3576 } 3567 }
3577 else 3568
3578 {
3579 SET_FLAG (op, FLAG_APPLIED);
3580 change_abil (who, op);
3581 who->chosen_skill = op;
3582 SET_FLAG (who, FLAG_READY_SKILL); 3569 SET_FLAG (who, FLAG_READY_SKILL);
3583 } 3570 SET_FLAG (op, FLAG_APPLIED);
3584 3571 change_abil (who, op);
3585 break; 3572 break;
3586 3573
3587 case BOW: 3574 case BOW:
3588 if (op->level && !op->name.starts_with (who->name)) 3575 if (op->level && (!op->name.starts_with (who->name) || op->name [who->name.length ()] != '\''))
3589 { 3576 {
3590 who->failmsg ("The weapon does not recognize you as its owner. " 3577 who->failmsg ("The weapon does not recognize you as its owner. "
3591 "H<Its name indicates that it belongs to somebody else.>"); 3578 "H<Its name indicates that it belongs to somebody else.>");
3592 if (tmp) 3579 if (tmp) who->insert (tmp);
3593 insert_ob_in_ob (tmp, who);
3594
3595 return 1; 3580 return 1;
3596 } 3581 }
3582
3583 if (player *pl = who->contr)
3584 {
3585 op->flag [FLAG_APPLIED] = true;
3586 who->statusmsg (format ("You wield the %s.", query_name (op)));
3587 change_abil (who, op);
3588 }
3589 break;
3590
3591 case RANGED:
3592 if (player *pl = who->contr)
3593 {
3594 op->flag [FLAG_APPLIED] = true;
3595 who->statusmsg (format ("You applied the %s.", query_name (op)));
3596 }
3597 break;
3598
3599 case SPELL:
3600 if (player *pl = who->contr)
3601 {
3602 op->flag [FLAG_APPLIED] = true;
3603 who->statusmsg (format ("You ready the spell %s.", query_name (op)));
3604 }
3605 break;
3597 3606
3598 /*FALLTHROUGH*/ 3607 /*FALLTHROUGH*/
3599 case WAND: 3608 case WAND:
3600 case ROD: 3609 case ROD:
3601 case HORN: 3610 case HORN:
3602 /* check for skill, alter player status */ 3611 /* check for skill, alter player status */
3603 3612
3604 if (!skop) 3613 if (!skop)
3605 { 3614 {
3606 who->failmsg (format ("The %s is broken, please report this to the dungeon master!", query_name (op)));//TODO 3615 who->failmsg (format ("The %s is broken, please report this to the dungeon master!", query_name (op)));//TODO
3616 if (tmp) who->insert (tmp);
3607 return 1; 3617 return 1;
3608 } 3618 }
3609 3619
3610 SET_FLAG (op, FLAG_APPLIED); 3620 op->flag [FLAG_APPLIED] = true;
3611 who->change_skill (skop);
3612 3621
3613 if (who->contr) 3622 if (player *pl = who->contr)
3614 { 3623 {
3615 who->contr->ranged_ob = op;
3616
3617 who->statusmsg (format ("You ready %s.", query_name (op))); 3624 who->statusmsg (format ("You ready %s.", query_name (op)));
3618 3625
3619 if (op->type == BOW) 3626 if (op->type == BOW)
3620 {
3621 who->current_weapon = op;
3622 change_abil (who, op);
3623 who->statusmsg (format ("You will now fire %s with %s.", op->race ? &op->race : "nothing", query_name (op))); 3627 who->statusmsg (format ("You will now fire %s with %s.", op->race ? &op->race : "nothing", query_name (op)));
3624 } 3628
3629 change_abil (who, op);
3625 } 3630 }
3626 else 3631 else
3627 { 3632 {
3633 who->change_skill (skop);
3634
3628 if (op->type == BOW) 3635 if (op->type == BOW)
3629 SET_FLAG (who, FLAG_READY_BOW); 3636 op->flag [FLAG_READY_BOW ] = true;
3630 else 3637 else
3631 SET_FLAG (who, FLAG_READY_RANGE); 3638 op->flag [FLAG_READY_RANGE] = true;
3632 } 3639 }
3633 3640
3634 break; 3641 break;
3635 3642
3636 case BUILDER: 3643 case BUILDER:
3637 if (who->type == PLAYER) 3644 if (player *pl = who->contr)
3638 { 3645 {
3639 //TODO: wtf does this do? shouldn't this be managed automatically (slots?)
3640 if (who->contr->ranged_ob && who->contr->ranged_ob->type == BUILDER)
3641 unapply_special (who, who->contr->ranged_ob, 0);
3642
3643 who->statusmsg (format ("You ready your %s.", query_name (op))); 3646 who->statusmsg (format ("You ready your %s.", query_name (op)));
3644 3647 //TODO: change_abil?
3645 who->contr->ranged_ob = op;
3646 } 3648 }
3647 break; 3649 break;
3648 3650
3649 default: 3651 default:
3650 who->statusmsg (format ("You apply %s.", query_name (op))); 3652 who->statusmsg (format ("You apply %s.", query_name (op)));
3651 } 3653 }
3652 3654
3653 SET_FLAG (op, FLAG_APPLIED); 3655 SET_FLAG (op, FLAG_APPLIED);
3654 3656
3655 if (tmp)
3656 who->insert (tmp); 3657 if (tmp) who->insert (tmp);
3657 3658
3658 who->update_stats (); 3659 who->update_stats ();
3659 3660
3660 /* We exclude spell casting objects. The fire code will set the 3661 /* We exclude spell casting objects. The fire code will set the
3661 * been applied flag when they are used - until that point, 3662 * been applied flag when they are used - until that point,

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines