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.80 by root, Thu May 3 04:50:27 2007 UTC vs.
Revision 1.92 by root, Sat May 12 18:23:51 2007 UTC

232 depl = present_arch_in_ob (at, op); 232 depl = present_arch_in_ob (at, op);
233 233
234 if (depl) 234 if (depl)
235 { 235 {
236 for (i = 0; i < NUM_STATS; i++) 236 for (i = 0; i < NUM_STATS; i++)
237 if (get_attr_value (&depl->stats, i)) 237 if (depl->stats.stat (i))
238 new_draw_info (NDI_UNIQUE, 0, op, restore_msg[i]); 238 new_draw_info (NDI_UNIQUE, 0, op, restore_msg[i]);
239 239
240 depl->destroy (); 240 depl->destroy ();
241 op->update_stats (); 241 op->update_stats ();
242 } 242 }
374 force->stats.food *= 10; 374 force->stats.food *= 10;
375 for (i = 0; i < NROFATTACKS; i++) 375 for (i = 0; i < NROFATTACKS; i++)
376 if (force->resist[i] > 0) 376 if (force->resist[i] > 0)
377 force->resist[i] = -force->resist[i]; /* prot => vuln */ 377 force->resist[i] = -force->resist[i]; /* prot => vuln */
378 } 378 }
379
379 force->speed_left = -1; 380 force->speed_left = -1;
380 force = insert_ob_in_ob (force, op); 381 force = insert_ob_in_ob (force, op);
381 CLEAR_FLAG (tmp, FLAG_APPLIED); 382 CLEAR_FLAG (tmp, FLAG_APPLIED);
382 SET_FLAG (force, FLAG_APPLIED); 383 SET_FLAG (force, FLAG_APPLIED);
383 change_abil (op, force); 384 change_abil (op, force);
2358 case EXIT: 2359 case EXIT:
2359 if (op->type != PLAYER) 2360 if (op->type != PLAYER)
2360 return 0; 2361 return 0;
2361 2362
2362 if (!EXIT_PATH (tmp) || !is_legal_2ways_exit (op, tmp)) 2363 if (!EXIT_PATH (tmp) || !is_legal_2ways_exit (op, tmp))
2363 {
2364 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s is closed.", query_name (tmp)); 2364 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s is closed.", query_name (tmp));
2365 }
2366 else 2365 else
2367 { 2366 {
2368 /* Don't display messages for random maps. */ 2367 /* Don't display messages for random maps. */
2369 if (tmp->msg && strncmp (EXIT_PATH (tmp), "/!", 2)) 2368 if (tmp->msg && strncmp (EXIT_PATH (tmp), "/!", 2))
2370 new_draw_info (NDI_NAVY, 0, op, tmp->msg); 2369 new_draw_info (NDI_NAVY, 0, op, tmp->msg);
2371 2370
2372 op->enter_exit (tmp); 2371 op->enter_exit (tmp);
2373 } 2372 }
2373
2374 return 1; 2374 return 1;
2375 2375
2376 case SIGN: 2376 case SIGN:
2377 apply_sign (op, tmp, 0); 2377 apply_sign (op, tmp, 0);
2378 return 1; 2378 return 1;
2382 { 2382 {
2383 apply_book (op, tmp); 2383 apply_book (op, tmp);
2384 return 1; 2384 return 1;
2385 } 2385 }
2386 else 2386 else
2387 {
2388 return 0; 2387 return 0;
2389 }
2390 2388
2391 case SKILLSCROLL: 2389 case SKILLSCROLL:
2392 if (op->type == PLAYER) 2390 if (op->type == PLAYER)
2393 { 2391 {
2394 apply_skillscroll (op, tmp); 2392 apply_skillscroll (op, tmp);
2395 return 1; 2393 return 1;
2396 } 2394 }
2395 else
2397 return 0; 2396 return 0;
2398 2397
2399 case SPELLBOOK: 2398 case SPELLBOOK:
2400 if (op->type == PLAYER) 2399 if (op->type == PLAYER)
2401 { 2400 {
2402 apply_spellbook (op, tmp); 2401 apply_spellbook (op, tmp);
2403 return 1; 2402 return 1;
2404 } 2403 }
2404 else
2405 return 0; 2405 return 0;
2406 2406
2407 case SCROLL: 2407 case SCROLL:
2408 apply_scroll (op, tmp, 0); 2408 apply_scroll (op, tmp, 0);
2409 return 1; 2409 return 1;
2410 2410
2411 case POTION: 2411 case POTION:
2412 (void) apply_potion (op, tmp); 2412 apply_potion (op, tmp);
2413 return 1; 2413 return 1;
2414 2414
2415 /* Eneq(@csd.uu.se): Handle apply on containers. */ 2415 /* Eneq(@csd.uu.se): Handle apply on containers. */
2416 //TODO: remove, as it is unsed? 2416 //TODO: remove, as it is unsed?
2417 case CLOSE_CON: 2417 case CLOSE_CON:
2477 } 2477 }
2478 else 2478 else
2479 return 0; 2479 return 0;
2480 2480
2481 case WEAPON_IMPROVER: 2481 case WEAPON_IMPROVER:
2482 (void) check_improve_weapon (op, tmp); 2482 check_improve_weapon (op, tmp);
2483 return 1; 2483 return 1;
2484 2484
2485 case CLOCK: 2485 case CLOCK:
2486 if (op->type == PLAYER) 2486 if (op->type == PLAYER)
2487 { 2487 {
2495 play_sound_player_only (op->contr, SOUND_CLOCK, 0, 0); 2495 play_sound_player_only (op->contr, SOUND_CLOCK, 0, 0);
2496 new_draw_info (NDI_UNIQUE, 0, op, buf); 2496 new_draw_info (NDI_UNIQUE, 0, op, buf);
2497 return 1; 2497 return 1;
2498 } 2498 }
2499 else 2499 else
2500 {
2501 return 0; 2500 return 0;
2502 }
2503 2501
2504 case MENU: 2502 case MENU:
2505 if (op->type == PLAYER) 2503 if (op->type == PLAYER)
2506 { 2504 {
2507 shop_listing (tmp, op); 2505 shop_listing (tmp, op);
2508 return 1; 2506 return 1;
2509 } 2507 }
2510 else 2508 else
2511 {
2512 return 0; 2509 return 0;
2513 }
2514 2510
2515 case POWER_CRYSTAL: 2511 case POWER_CRYSTAL:
2516 apply_power_crystal (op, tmp); /* see egoitem.c */ 2512 apply_power_crystal (op, tmp); /* see egoitem.c */
2517 return 1; 2513 return 1;
2518 2514
2521 { 2517 {
2522 apply_lighter (op, tmp); 2518 apply_lighter (op, tmp);
2523 return 1; 2519 return 1;
2524 } 2520 }
2525 else 2521 else
2526 {
2527 return 0; 2522 return 0;
2528 }
2529 2523
2530 case ITEM_TRANSFORMER: 2524 case ITEM_TRANSFORMER:
2531 apply_item_transformer (op, tmp); 2525 apply_item_transformer (op, tmp);
2532 return 1; 2526 return 1;
2533 2527
2586/** 2580/**
2587 * player_apply_below attempts to apply the object 'below' the player. 2581 * player_apply_below attempts to apply the object 'below' the player.
2588 * If the player has an open container, we use that for below, otherwise 2582 * If the player has an open container, we use that for below, otherwise
2589 * we use the ground. 2583 * we use the ground.
2590 */ 2584 */
2591
2592void 2585void
2593player_apply_below (object *pl) 2586player_apply_below (object *pl)
2594{ 2587{
2595 int floors = 0; 2588 int floors = 0;
2596 2589
2633 * to keep the size of apply_special to a more managable size. 2626 * to keep the size of apply_special to a more managable size.
2634 */ 2627 */
2635static int 2628static int
2636unapply_special (object *who, object *op, int aflags) 2629unapply_special (object *who, object *op, int aflags)
2637{ 2630{
2638 if (INVOKE_OBJECT (BE_UNREADY, op, ARG_OBJECT (who), ARG_INT (aflags)) || INVOKE_OBJECT (UNREADY, who, ARG_OBJECT (op), ARG_INT (aflags))) 2631 if (INVOKE_OBJECT (BE_UNREADY, op, ARG_OBJECT (who), ARG_INT (aflags))
2632 || INVOKE_OBJECT (UNREADY, who, ARG_OBJECT (op), ARG_INT (aflags)))
2639 return RESULT_INT (0); 2633 return RESULT_INT (0);
2640 2634
2641 object *tmp2; 2635 object *tmp2;
2642 2636
2643 CLEAR_FLAG (op, FLAG_APPLIED); 2637 CLEAR_FLAG (op, FLAG_APPLIED);
2772 2766
2773 who->update_stats (); 2767 who->update_stats ();
2774 2768
2775 if (!(aflags & AP_NO_MERGE)) 2769 if (!(aflags & AP_NO_MERGE))
2776 { 2770 {
2777 object *tmp;
2778
2779 tmp = merge_ob (op, NULL); 2771 object *tmp = merge_ob (op, 0);
2780 2772
2781 if (who->contr) 2773 if (who->contr)
2782 { 2774 {
2783 if (tmp) 2775 if (tmp)
2784 { /* it was merged */ 2776 { /* it was merged */
2805 * loc is the index into the array we are looking for a match. 2797 * loc is the index into the array we are looking for a match.
2806 * don't return invisible objects unless they are skill objects 2798 * don't return invisible objects unless they are skill objects
2807 * invisible other objects that use 2799 * invisible other objects that use
2808 * up body locations can be used as restrictions. 2800 * up body locations can be used as restrictions.
2809 */ 2801 */
2810object * 2802static object *
2811get_item_from_body_location (object *start, int loc) 2803get_item_from_body_location (int loc, object *start)
2812{ 2804{
2813 object *tmp;
2814
2815 if (!start) 2805 if (start)
2816 return NULL;
2817
2818 for (tmp = start; tmp; tmp = tmp->below) 2806 for (object *tmp = start; tmp; tmp = tmp->below)
2819 if (QUERY_FLAG (tmp, FLAG_APPLIED) && tmp->body_info[loc] && (!tmp->invisible || tmp->type == SKILL)) 2807 if (QUERY_FLAG (tmp, FLAG_APPLIED) && tmp->slot[loc].info && (!tmp->invisible || tmp->type == SKILL))
2820 return tmp; 2808 return tmp;
2821 2809
2822 return NULL; 2810 return 0;
2823} 2811}
2824
2825
2826 2812
2827/** 2813/**
2828 * 'op' wants to apply an object, but can't because of other equipment. 2814 * 'op' wants to apply an object, but can't because of other equipment.
2829 * This should only be called when it is known 2815 * This should only be called when it is known
2830 * that there are objects to unapply. This makes pretty heavy 2816 * that there are objects to unapply. This makes pretty heavy
2836 * another function that does just that. 2822 * another function that does just that.
2837 */ 2823 */
2838int 2824int
2839unapply_for_ob (object *who, object *op, int aflags) 2825unapply_for_ob (object *who, object *op, int aflags)
2840{ 2826{
2841 int i; 2827 if (op->is_range ())
2842 object *tmp = NULL, *last;
2843
2844 /* If we are applying a shield or weapon, unapply any equipped shield
2845 * or weapons first - only allowed to use one weapon/shield at a time.
2846 */
2847 if (op->type == WEAPON || op->type == SHIELD)
2848 {
2849 for (tmp = who->inv; tmp; tmp = tmp->below) 2828 for (object *tmp = who->inv; tmp; tmp = tmp->below)
2850 {
2851 if (QUERY_FLAG (tmp, FLAG_APPLIED) && tmp->type == op->type) 2829 if (QUERY_FLAG (tmp, FLAG_APPLIED) && tmp->is_range ())
2852 {
2853 if ((aflags & AP_IGNORE_CURSE) || (aflags & AP_PRINT) || (!QUERY_FLAG (tmp, FLAG_CURSED) && !QUERY_FLAG (tmp, FLAG_DAMNED))) 2830 if ((aflags & AP_IGNORE_CURSE) || (aflags & AP_PRINT) || (!QUERY_FLAG (tmp, FLAG_CURSED) && !QUERY_FLAG (tmp, FLAG_DAMNED)))
2854 { 2831 {
2855 if (aflags & AP_PRINT) 2832 if (aflags & AP_PRINT)
2856 new_draw_info (NDI_UNIQUE, 0, who, query_name (tmp)); 2833 new_draw_info (NDI_UNIQUE, 0, who, query_name (tmp));
2857 else 2834 else
2858 unapply_special (who, tmp, aflags); 2835 unapply_special (who, tmp, aflags);
2859 } 2836 }
2860 else 2837 else
2861 { 2838 {
2862 /* In this case, we want to try and remove a cursed item. 2839 /* In this case, we want to try and remove a cursed item.
2863 * While we know it won't work, we want unapply_special to 2840 * While we know it won't work, we want unapply_special to
2864 * at least generate the message. 2841 * at least generate the message.
2865 */ 2842 */
2866 new_draw_info_format (NDI_UNIQUE, 0, who, "No matter how hard you try, you just can't\nremove %s.", query_name (tmp)); 2843 new_draw_info_format (NDI_UNIQUE, 0, who, "No matter how hard you try, you just can't remove the %s.", query_name (tmp));
2867 return 1; 2844 return 1;
2868 }
2869
2870 } 2845 }
2871 }
2872 }
2873 2846
2874 for (i = 0; i < NUM_BODY_LOCATIONS; i++) 2847 for (int i = 0; i < NUM_BODY_LOCATIONS; i++)
2875 { 2848 {
2876 /* this used up a slot that we need to free */ 2849 /* this used up a slot that we need to free */
2877 if (op->body_info[i]) 2850 if (op->slot[i].info)
2878 { 2851 {
2879 last = who->inv; 2852 object *last = who->inv;
2880 2853
2881 /* We do a while loop - may need to remove several items in order 2854 /* We do a while loop - may need to remove several items in order
2882 * to free up enough slots. 2855 * to free up enough slots.
2883 */ 2856 */
2884 while ((who->body_used[i] + op->body_info[i]) < 0) 2857 while ((who->slot[i].used + op->slot[i].info) < 0)
2885 { 2858 {
2886 tmp = get_item_from_body_location (last, i); 2859 object *tmp = get_item_from_body_location (i, last);
2860
2887 if (!tmp) 2861 if (!tmp)
2888 { 2862 {
2889#if 0 2863#if 0
2890 /* Not a bug - we'll get this if the player has cursed items 2864 /* Not a bug - we'll get this if the player has cursed items
2891 * equipped. 2865 * equipped.
2892 */ 2866 */
2893 LOG (llevError, "Can't find object using location %d (%s) on %s\n", i, body_locations[i].save_name, who->name); 2867 LOG (llevError, "Can't find object using location %d (%s) on %s\n", i, body_locations[i].save_name, who->name);
2894#endif 2868#endif
2895 return 1; 2869 return 1;
2896 } 2870 }
2871
2897 /* If we are just printing, we don't care about cursed status */ 2872 /* If we are just printing, we don't care about cursed status */
2898 if ((aflags & AP_IGNORE_CURSE) || (aflags & AP_PRINT) || (!(QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED)))) 2873 if ((aflags & AP_IGNORE_CURSE) || (aflags & AP_PRINT) || (!(QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED))))
2899 { 2874 {
2900 if (aflags & AP_PRINT) 2875 if (aflags & AP_PRINT)
2901 new_draw_info (NDI_UNIQUE, 0, who, query_name (tmp)); 2876 new_draw_info (NDI_UNIQUE, 0, who, query_name (tmp));
2909 * so it may not be critical (eg, putting on a ring and you have 2884 * so it may not be critical (eg, putting on a ring and you have
2910 * one cursed ring.) 2885 * one cursed ring.)
2911 */ 2886 */
2912 new_draw_info_format (NDI_UNIQUE, 0, who, "The %s just won't come off", query_name (tmp)); 2887 new_draw_info_format (NDI_UNIQUE, 0, who, "The %s just won't come off", query_name (tmp));
2913 } 2888 }
2889
2914 last = tmp->below; 2890 last = tmp->below;
2915 } 2891 }
2916 /* if we got here, this slot is freed up - otherwise, if it wasn't freed up, the 2892 /* if we got here, this slot is freed up - otherwise, if it wasn't freed up, the
2917 * return in the !tmp would have kicked in. 2893 * return in the !tmp would have kicked in.
2918 */ 2894 */
2919 } /* if op is using this body location */ 2895 } /* if op is using this body location */
2920 } /* for body lcoations */ 2896 } /* for body lcoations */
2897
2921 return 0; 2898 return 0;
2922} 2899}
2923 2900
2924/** 2901/**
2925 * Checks to see if 'who' can apply object 'op'. 2902 * Checks to see if 'who' can apply object 'op'.
2939 return RESULT_INT (0); 2916 return RESULT_INT (0);
2940 2917
2941 int retval = 0; 2918 int retval = 0;
2942 object *tmp = 0, *ws = 0; 2919 object *tmp = 0, *ws = 0;
2943 2920
2944 /* Players have 2 'arm's, so they could in theory equip 2 shields or
2945 * 2 weapons, but we don't want to let them do that. So if they are
2946 * trying to equip a weapon or shield, see if they already have one
2947 * in place and store that way.
2948 */
2949 if (op->type == WEAPON || op->type == BOW || op->type == SHIELD)
2950 {
2951 for (tmp = who->inv; tmp && !ws; tmp = tmp->below)
2952 {
2953 if (QUERY_FLAG (tmp, FLAG_APPLIED) && tmp->type == op->type)
2954 {
2955 retval = CAN_APPLY_UNAPPLY;
2956 ws = tmp;
2957 }
2958 }
2959 }
2960
2961 for (int i = 0; i < NUM_BODY_LOCATIONS; i++) 2921 for (int i = 0; i < NUM_BODY_LOCATIONS; i++)
2962 { 2922 {
2963 if (op->body_info[i]) 2923 if (op->slot[i].info)
2964 { 2924 {
2965 /* Item uses more slots than we have */ 2925 /* Item uses more slots than we have */
2966 if (abs (op->body_info[i]) > who->body_info[i]) 2926 if (abs (op->slot[i].info) > who->slot[i].info)
2967 { 2927 {
2968 /* Could return now for efficiency - rest of info below isn't 2928 /* Could return now for efficiency - rest of info below isn't
2969 * really needed. 2929 * really needed.
2970 */ 2930 */
2971 retval |= CAN_APPLY_NEVER; 2931 retval |= CAN_APPLY_NEVER;
2972 } 2932 }
2973 else if ((who->body_used[i] + op->body_info[i]) < 0) 2933 else if ((who->slot[i].used + op->slot[i].info) < 0)
2974 { 2934 {
2975 /* in this case, equipping this would use more free spots than 2935 /* in this case, equipping this would use more free spots than
2976 * we have. 2936 * we have.
2977 */ 2937 */
2978 2938
2979 /* if we have an applied weapon/shield, and unapply it would free 2939 /* if we have an applied weapon/shield, and unapply it would free
2980 * enough slots to equip the new item, then just set this can 2940 * enough slots to equip the new item, then just set "can
2981 * continue. We don't care about the logic below - if you have 2941 * apply unapply". We don't care about the logic below - if you have a
2982 * shield equipped and try to equip another shield, there is only 2942 * shield equipped and try to equip another shield, there is only
2983 * one choice. However, the check for the number of body locations 2943 * one choice. However, the check for the number of body locations
2984 * does take into the account cases where what is being applied 2944 * does take into the account cases where what is being applied
2985 * may be two handed for example. 2945 * may be two handed for example.
2986 */ 2946 */
2987 if (ws) 2947 if (ws)
2988 { 2948 if ((who->slot[i].used - ws->slot[i].info + op->slot[i].info) >= 0)
2989 if ((who->body_used[i] - ws->body_info[i] + op->body_info[i]) >= 0)
2990 { 2949 {
2991 retval |= CAN_APPLY_UNAPPLY; 2950 retval |= CAN_APPLY_UNAPPLY;
2992 continue; 2951 continue;
2993 } 2952 }
2994 }
2995 2953
2996 object *tmp1 = get_item_from_body_location (who->inv, i); 2954 object *tmp1 = get_item_from_body_location (i, who->inv);
2997 if (!tmp1) 2955 if (!tmp1)
2998 { 2956 {
2999#if 0 2957#if 0
3000 /* This is sort of an error, but happens a lot when old players 2958 /* This is sort of an error, but happens a lot when old players
3001 * join in with more stuff equipped than they are now allowed. 2959 * join in with more stuff equipped than they are now allowed.
3018 2976
3019 /* This object isn't using up all the slots, so there must 2977 /* This object isn't using up all the slots, so there must
3020 * be another. If so, and it the new item doesn't need all 2978 * be another. If so, and it the new item doesn't need all
3021 * the slots, the player then has a choice. 2979 * the slots, the player then has a choice.
3022 */ 2980 */
3023 if ((who->body_used[i] - tmp1->body_info[i] != who->body_info[i]) 2981 if ((who->slot[i].used - tmp1->slot[i].info != who->slot[i].info)
3024 && abs (op->body_info[i]) < who->body_info[i]) 2982 && abs (op->slot[i].info) < who->slot[i].info)
3025 retval |= CAN_APPLY_UNAPPLY_CHOICE; 2983 retval |= CAN_APPLY_UNAPPLY_CHOICE;
3026 2984
3027 /* Does unequippint 'tmp1' free up enough slots for this to be 2985 /* Does unequippint 'tmp1' free up enough slots for this to be
3028 * equipped? If not, there must be something else to unapply. 2986 * equipped? If not, there must be something else to unapply.
3029 */ 2987 */
3030 if (who->body_used[i] + op->body_info[i] < tmp1->body_info[i]) 2988 if (who->slot[i].used + op->slot[i].info < tmp1->slot[i].info)
3031 retval |= CAN_APPLY_UNAPPLY_MULT; 2989 retval |= CAN_APPLY_UNAPPLY_MULT;
3032 } 2990 }
3033 } /* if not enough free slots */ 2991 } /* if not enough free slots */
3034 } /* if this object uses location i */ 2992 } /* if this object uses location i */
3035 } /* for i -> num_body_locations loop */ 2993 } /* for i -> num_body_locations loop */
3109 if (basic_flag == AP_APPLY) 3067 if (basic_flag == AP_APPLY)
3110 return 0; 3068 return 0;
3111 3069
3112 if (!(aflags & AP_IGNORE_CURSE) && (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED))) 3070 if (!(aflags & AP_IGNORE_CURSE) && (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED)))
3113 { 3071 {
3114 new_draw_info_format (NDI_UNIQUE, 0, who, "No matter how hard you try, you just can't\nremove %s.", query_name (op)); 3072 new_draw_info_format (NDI_UNIQUE, 0, who, "No matter how hard you try, you just can't remove %s.", query_name (op));
3115 return 1; 3073 return 1;
3116 } 3074 }
3117 3075
3118 return unapply_special (who, op, aflags); 3076 return unapply_special (who, op, aflags);
3119 } 3077 }
3120 3078
3121 if (basic_flag == AP_UNAPPLY) 3079 if (basic_flag == AP_UNAPPLY)
3122 return 0; 3080 return 0;
3081
3082 // if the item is combat/ranged, wield the relevant slot first
3083 // to resolve conflicts.
3084 if (player *pl = who->contr)
3085 switch (op->type)
3086 {
3087 case WEAPON:
3088 who->change_weapon (pl->combat_ob);
3089 break;
3090
3091 case BOW:
3092 case ROD:
3093 case WAND:
3094 case HORN:
3095 case SKILL_TOOL:
3096 who->change_weapon (pl->ranged_ob);
3097 break;
3098
3099 case SKILL:
3100 if (IS_COMBAT_SKILL (op->subtype))
3101 who->change_weapon (pl->combat_ob);
3102 else if (IS_RANGED_SKILL (op->subtype))
3103 who->change_weapon (pl->ranged_ob);
3104 break;
3105 }
3123 3106
3124 /* Can't just apply this object. Lets see what not and what to do */ 3107 /* Can't just apply this object. Lets see what not and what to do */
3125 if (int i = can_apply_object (who, op)) 3108 if (int i = can_apply_object (who, op))
3126 { 3109 {
3127 if (i & CAN_APPLY_NEVER) 3110 if (i & CAN_APPLY_NEVER)
3148 new_draw_info (NDI_UNIQUE, 0, who, "You need to unapply some of the following item(s) or change your applymode:"); 3131 new_draw_info (NDI_UNIQUE, 0, who, "You need to unapply some of the following item(s) or change your applymode:");
3149 unapply_for_ob (who, op, AP_PRINT); 3132 unapply_for_ob (who, op, AP_PRINT);
3150 return 1; 3133 return 1;
3151 } 3134 }
3152 else if (who->contr->unapply == unapply_always || !(i & CAN_APPLY_UNAPPLY_CHOICE)) 3135 else if (who->contr->unapply == unapply_always || !(i & CAN_APPLY_UNAPPLY_CHOICE))
3153 {
3154 if (unapply_for_ob (who, op, aflags)) 3136 if (unapply_for_ob (who, op, aflags))
3155 return 1; 3137 return 1;
3156 }
3157 } 3138 }
3158 } 3139 }
3159 3140
3160 if (op->skill && op->type != SKILL && op->type != SKILL_TOOL) 3141 if (op->skill && op->type != SKILL && op->type != SKILL_TOOL)
3161 { 3142 {
3198 switch (op->type) 3179 switch (op->type)
3199 { 3180 {
3200 case WEAPON: 3181 case WEAPON:
3201 if (!check_weapon_power (who, op->last_eat)) 3182 if (!check_weapon_power (who, op->last_eat))
3202 { 3183 {
3203 new_draw_info (NDI_UNIQUE, 0, who, "That weapon is too powerful for you to use."); 3184 new_draw_info (NDI_UNIQUE, 0, who, "This weapon is too powerful for you to use.\n"
3204 new_draw_info (NDI_UNIQUE, 0, who, "It would consume your soul!."); 3185 "It would consume your soul!.");
3205 3186
3206 if (tmp) 3187 if (tmp)
3207 insert_ob_in_ob (tmp, who); 3188 insert_ob_in_ob (tmp, who);
3208 3189
3209 return 1; 3190 return 1;
3231 3212
3232 SET_FLAG (op, FLAG_APPLIED); 3213 SET_FLAG (op, FLAG_APPLIED);
3233 change_skill (who, skop, 1); 3214 change_skill (who, skop, 1);
3234 3215
3235 if (who->contr) 3216 if (who->contr)
3236 {
3237 who->contr->combat_ob = op; 3217 who->change_weapon (who->contr->combat_ob = op);
3238 who->current_weapon = op;
3239 }
3240 3218
3241 if (!QUERY_FLAG (who, FLAG_READY_WEAPON)) 3219 if (!QUERY_FLAG (who, FLAG_READY_WEAPON))
3242 SET_FLAG (who, FLAG_READY_WEAPON); 3220 SET_FLAG (who, FLAG_READY_WEAPON);
3243 3221
3244 new_draw_info_format (NDI_UNIQUE, 0, who, "You wield %s.", query_name (op)); 3222 new_draw_info_format (NDI_UNIQUE, 0, who, "You wield %s.", query_name (op));
3293 } 3271 }
3294 3272
3295 who->update_stats (); 3273 who->update_stats ();
3296 3274
3297 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED)) 3275 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED))
3298 {
3299 if (who->type == PLAYER) 3276 if (who->type == PLAYER)
3300 { 3277 {
3301 new_draw_info (NDI_UNIQUE, 0, who, "Oops, it feels deadly cold!"); 3278 new_draw_info (NDI_UNIQUE, 0, who, "Oops, it feels deadly cold!");
3302 SET_FLAG (tmp2, FLAG_KNOWN_CURSED); 3279 SET_FLAG (tmp2, FLAG_KNOWN_CURSED);
3303 } 3280 }
3304 }
3305 3281
3306 if (who->type == PLAYER) 3282 if (who->type == PLAYER)
3307 esrv_send_item (who, tmp2); 3283 esrv_send_item (who, tmp2);
3308 3284
3309 return 0; 3285 return 0;
3324 if (skill_flags [op->subtype] & SF_NEED_WEAPON) 3300 if (skill_flags [op->subtype] & SF_NEED_WEAPON)
3325 { 3301 {
3326 for (object *item = who->inv; item; item = item->below) 3302 for (object *item = who->inv; item; item = item->below)
3327 if (item->type == WEAPON && item->flag [FLAG_APPLIED]) 3303 if (item->type == WEAPON && item->flag [FLAG_APPLIED])
3328 { 3304 {
3329 pl->combat_ob = who->current_weapon = item; 3305 who->change_weapon (pl->combat_ob = item);
3330 goto found_weapon; 3306 goto found_weapon;
3331 } 3307 }
3332 3308
3333 new_draw_info (NDI_UNIQUE, 0, who, "You need to apply a melee weapon before readying this skill"); 3309 new_draw_info (NDI_UNIQUE, 0, who, "You need to apply a melee weapon before readying this skill");
3334 return 1; 3310 return 1;
3335 3311
3336 found_weapon:; 3312 found_weapon:;
3337 } 3313 }
3338 else 3314 else
3339 {
3340 pl->combat_ob = op; 3315 who->change_weapon (pl->combat_ob = op);
3341 op->current_weapon = 0;
3342 }
3343 } 3316 }
3344 else if (IS_RANGED_SKILL (op->subtype)) 3317 else if (IS_RANGED_SKILL (op->subtype))
3345 { 3318 {
3346 if (skill_flags [op->subtype] & SF_NEED_BOW) 3319 if (skill_flags [op->subtype] & SF_NEED_BOW)
3347 { 3320 {
3348 for (object *item = who->inv; item; item = item->below) 3321 for (object *item = who->inv; item; item = item->below)
3349 if (item->type == BOW && item->flag [FLAG_APPLIED]) 3322 if (item->type == BOW && item->flag [FLAG_APPLIED])
3350 { 3323 {
3351 pl->ranged_ob = who->current_weapon = item; 3324 who->change_weapon (pl->ranged_ob = item);
3352 goto found_bow; 3325 goto found_bow;
3353 } 3326 }
3354 3327
3355 new_draw_info (NDI_UNIQUE, 0, who, "You need to apply a missile weapon before readying this skill"); 3328 new_draw_info (NDI_UNIQUE, 0, who, "You need to apply a missile weapon before readying this skill");
3356 return 1; 3329 return 1;
3361 { 3334 {
3362 for (object *item = who->inv; item; item = item->below) 3335 for (object *item = who->inv; item; item = item->below)
3363 if (item->flag [FLAG_APPLIED] 3336 if (item->flag [FLAG_APPLIED]
3364 && (item->type == WAND || item->type == ROD || item->type == HORN)) 3337 && (item->type == WAND || item->type == ROD || item->type == HORN))
3365 { 3338 {
3366 pl->ranged_ob = who->current_weapon = item; 3339 who->change_weapon (pl->ranged_ob = item);
3367 goto found_item; 3340 goto found_item;
3368 } 3341 }
3369 3342
3370 new_draw_info (NDI_UNIQUE, 0, who, "You need to apply a magic item before readying this skill"); 3343 new_draw_info (NDI_UNIQUE, 0, who, "You need to apply a magic item before readying this skill");
3371 return 1; 3344 return 1;
3372 3345
3373 found_item:; 3346 found_item:;
3374 } 3347 }
3375 else 3348 else
3376 {
3377 pl->ranged_ob = op; 3349 who->change_weapon (pl->ranged_ob = op);
3378 op->current_weapon = 0;
3379 }
3380 } 3350 }
3381 3351
3382 if (!op->invisible) 3352 if (!op->invisible)
3383 { 3353 {
3384 new_draw_info_format (NDI_UNIQUE, 0, who, "You ready %s.", query_name (op)); 3354 new_draw_info_format (NDI_UNIQUE, 0, who, "You ready %s.", query_name (op));
3386 } 3356 }
3387 else 3357 else
3388 new_draw_info_format (NDI_UNIQUE, 0, who, "Readied skill: %s.", op->skill ? &op->skill : &op->name); 3358 new_draw_info_format (NDI_UNIQUE, 0, who, "Readied skill: %s.", op->skill ? &op->skill : &op->name);
3389 } 3359 }
3390 3360
3391 {
3392 SET_FLAG (op, FLAG_APPLIED); 3361 SET_FLAG (op, FLAG_APPLIED);
3393 change_abil (who, op); 3362 change_abil (who, op);
3394 who->chosen_skill = op; 3363 who->chosen_skill = op;
3395 SET_FLAG (who, FLAG_READY_SKILL); 3364 SET_FLAG (who, FLAG_READY_SKILL);
3396 break; 3365 break;
3397 3366
3398 case BOW: 3367 case BOW:
3399 if (!check_weapon_power (who, op->last_eat)) 3368 if (!check_weapon_power (who, op->last_eat))
3400 { 3369 {
3401 new_draw_info (NDI_UNIQUE, 0, who, "That item is too powerful for you to use."); 3370 new_draw_info (NDI_UNIQUE, 0, who, "That weapon is too powerful for you to use.");
3402 new_draw_info (NDI_UNIQUE, 0, who, "It would consume your soul!."); 3371 new_draw_info (NDI_UNIQUE, 0, who, "It would consume your soul!.");
3403 3372
3404 if (tmp) 3373 if (tmp)
3405 insert_ob_in_ob (tmp, who); 3374 insert_ob_in_ob (tmp, who);
3406 3375
3408 } 3377 }
3409 3378
3410 if (op->level && (strncmp (op->name, who->name, strlen (who->name)))) 3379 if (op->level && (strncmp (op->name, who->name, strlen (who->name))))
3411 { 3380 {
3412 new_draw_info (NDI_UNIQUE, 0, who, "The weapon does not recognize you as its owner."); 3381 new_draw_info (NDI_UNIQUE, 0, who, "The weapon does not recognize you as its owner.");
3413 if (tmp != NULL) 3382 if (tmp)
3414 insert_ob_in_ob (tmp, who); 3383 insert_ob_in_ob (tmp, who);
3415 3384
3416 return 1; 3385 return 1;
3417 } 3386 }
3418 3387
3691 * Handles player eating food that temporarily changes status (resistances, stats). 3660 * Handles player eating food that temporarily changes status (resistances, stats).
3692 * This used to call cast_change_attr(), but 3661 * This used to call cast_change_attr(), but
3693 * that doesn't work with the new spell code. Since we know what 3662 * that doesn't work with the new spell code. Since we know what
3694 * the food changes, just grab a force and use that instead. 3663 * the food changes, just grab a force and use that instead.
3695 */ 3664 */
3696
3697void 3665void
3698eat_special_food (object *who, object *food) 3666eat_special_food (object *who, object *food)
3699{ 3667{
3700 object *force; 3668 object *force;
3701 int i, did_one = 0; 3669 int i, did_one = 0;
3702 sint8 k;
3703 3670
3704 force = get_archetype (FORCE_NAME); 3671 force = get_archetype (FORCE_NAME);
3705 3672
3706 for (i = 0; i < NUM_STATS; i++) 3673 for (i = 0; i < NUM_STATS; i++)
3707 { 3674 if (sint8 k = food->stats.stat (i))
3708 k = get_attr_value (&food->stats, i);
3709 if (k)
3710 { 3675 {
3711 set_attr_value (&force->stats, i, k); 3676 force->stats.stat (i) = k;
3712 did_one = 1; 3677 did_one = 1;
3713 } 3678 }
3714 }
3715 3679
3716 /* check if we can protect the eater */ 3680 /* check if we can protect the eater */
3717 for (i = 0; i < NROFATTACKS; i++) 3681 for (i = 0; i < NROFATTACKS; i++)
3718 { 3682 {
3719 if (food->resist[i] > 0) 3683 if (food->resist[i] > 0)
3880 new_draw_info (NDI_UNIQUE, 0, op, "The magic recoils on you!"); 3844 new_draw_info (NDI_UNIQUE, 0, op, "The magic recoils on you!");
3881 blind_player (op, op, power); 3845 blind_player (op, op, power);
3882 } 3846 }
3883 else if (failure <= -80) 3847 else if (failure <= -80)
3884 { /* blast the immediate area */ 3848 { /* blast the immediate area */
3885 object *tmp;
3886
3887 tmp = get_archetype (LOOSE_MANA); 3849 object *tmp = get_archetype (LOOSE_MANA);
3888 cast_magic_storm (op, tmp, power); 3850 cast_magic_storm (op, tmp, power);
3889 new_draw_info (NDI_UNIQUE, 0, op, "You unlease uncontrolled mana!"); 3851 new_draw_info (NDI_UNIQUE, 0, op, "You unleash uncontrolled mana!");
3890 tmp->destroy (); 3852 tmp->destroy ();
3891 } 3853 }
3892 } 3854 }
3893} 3855}
3894 3856
3914 */ 3876 */
3915 int i, j; 3877 int i, j;
3916 3878
3917 for (i = 0; i < NUM_STATS; i++) 3879 for (i = 0; i < NUM_STATS; i++)
3918 { 3880 {
3919 sint8 stat = get_attr_value (stats, i);
3920 int race_bonus = get_attr_value (&(pl->arch->clone.stats), i); 3881 int race_bonus = pl->arch->clone.stats.stat (i);
3882 sint8 stat = stats->stat (i) + ns->stat (i);
3921 3883
3922 stat += get_attr_value (ns, i);
3923 if (stat > 20 + race_bonus) 3884 if (stat > 20 + race_bonus)
3924 { 3885 {
3925 excess_stat++; 3886 excess_stat++;
3926 stat = 20 + race_bonus; 3887 stat = 20 + race_bonus;
3927 } 3888 }
3928 set_attr_value (stats, i, stat); 3889
3890 stats->stat (i) = stat;
3929 } 3891 }
3930 3892
3931 for (j = 0; excess_stat > 0 && j < 100; j++) 3893 for (j = 0; excess_stat > 0 && j < 100; j++)
3932 { /* try 100 times to assign excess stats */ 3894 { /* try 100 times to assign excess stats */
3933 int i = rndm (0, 6); 3895 int i = rndm (0, 6);
3934 int stat = get_attr_value (stats, i);
3935 int race_bonus = get_attr_value (&(pl->arch->clone.stats), i);
3936 3896
3937 if (i == CHA) 3897 if (i == CHA)
3938 continue; /* exclude cha from this */ 3898 continue; /* exclude cha from this */
3899
3900 int stat = stats->stat (i);
3901 int race_bonus = pl->arch->clone.stats.stat (i);
3939 if (stat < 20 + race_bonus) 3902 if (stat < 20 + race_bonus)
3940 { 3903 {
3941 change_attr_value (stats, i, 1); 3904 change_attr_value (stats, i, 1);
3942 excess_stat--; 3905 excess_stat--;
3943 } 3906 }
3946 /* insert the randomitems from the change's treasurelist into 3909 /* insert the randomitems from the change's treasurelist into
3947 * the player ref: player.c 3910 * the player ref: player.c
3948 */ 3911 */
3949 if (change->randomitems != NULL) 3912 if (change->randomitems != NULL)
3950 give_initial_items (pl, change->randomitems); 3913 give_initial_items (pl, change->randomitems);
3951
3952 3914
3953 /* set up the face, for some races. */ 3915 /* set up the face, for some races. */
3954 3916
3955 /* first, look for the force object banning 3917 /* first, look for the force object banning
3956 * changing the face. Certain races never change face with class. 3918 * changing the face. Certain races never change face with class.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines