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.93 by root, Sat May 12 21:56:34 2007 UTC vs.
Revision 1.97 by root, Tue May 15 19:07:15 2007 UTC

2634 2634
2635 object *tmp2; 2635 object *tmp2;
2636 2636
2637 CLEAR_FLAG (op, FLAG_APPLIED); 2637 CLEAR_FLAG (op, FLAG_APPLIED);
2638 2638
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
2639 switch (op->type) 2645 switch (op->type)
2640 { 2646 {
2647 case SKILL_TOOL:
2648 // unapplying a skill tool should also unapply the skill it governs
2649 // but this is hard, as it shouldn't do so when the skill can
2650 // be used for other reasons
2651 for (object *tmp = who->inv; tmp; tmp = tmp->below)
2652 if (tmp->skill == op->skill
2653 && tmp->type == SKILL
2654 && tmp->flag [FLAG_APPLIED]
2655 && !tmp->flag [FLAG_CAN_USE_SKILL])
2656 unapply_special (who, tmp, 0);
2657
2658 change_abil (who, op);
2659 break;
2660
2641 case WEAPON: 2661 case WEAPON:
2642 new_draw_info_format (NDI_UNIQUE, 0, who, "You unwield %s.", query_name (op)); 2662 new_draw_info_format (NDI_UNIQUE, 0, who, "You unwield %s.", query_name (op));
2643 2663
2644 change_abil (who, op); 2664 change_abil (who, op);
2645 CLEAR_FLAG (who, FLAG_READY_WEAPON); 2665 CLEAR_FLAG (who, FLAG_READY_WEAPON);
2646
2647 if (who->contr)
2648 {
2649 if (who->contr->combat_ob == op)
2650 who->contr->combat_ob = 0;
2651
2652 if (who->current_weapon == op)
2653 who->current_weapon = 0;
2654 }
2655
2656 clear_skill (who); 2666 clear_skill (who);
2657 break; 2667 break;
2658 2668
2659 case SKILL: /* allows objects to impart skills */
2660 case SKILL_TOOL: 2669 case SKILL:
2661 if (op != who->chosen_skill) 2670 if (op != who->chosen_skill)
2662 LOG (llevError, "BUG: apply_special(): applied skill is not a chosen skill\n"); 2671 LOG (llevError, "BUG: apply_special(): applied skill is not a chosen skill\n");
2663 2672
2664 if (who->contr) 2673 if (who->contr)
2665 { 2674 {
2788/** 2797/**
2789 * Returns the object that is using location 'loc'. 2798 * Returns the object that is using location 'loc'.
2790 * Note that 'start' is the first object to start examing - we 2799 * Note that 'start' is the first object to start examing - we
2791 * then go through the below of this. In this way, you can do 2800 * then go through the below of this. In this way, you can do
2792 * something like: 2801 * something like:
2793 * tmp = get_item_from_body_location(who->inv, 1); 2802 * tmp = get_next_item_from_body_location(who->inv, 1);
2794 * if (tmp) tmp1 = get_item_from_body_location(tmp->below, 1); 2803 * if (tmp) tmp1 = get_next_item_from_body_location(tmp->below, 1);
2795 * to find the second object that may use this location, etc. 2804 * to find the second object that may use this location, etc.
2796 * Returns NULL if no match is found. 2805 * Returns NULL if no match is found.
2797 * loc is the index into the array we are looking for a match. 2806 * loc is the index into the array we are looking for a match.
2798 * don't return invisible objects unless they are skill objects 2807 * don't return invisible objects unless they are skill objects
2799 * invisible other objects that use 2808 * invisible other objects that use
2800 * up body locations can be used as restrictions. 2809 * up body locations can be used as restrictions.
2801 */ 2810 */
2802static object * 2811static object *
2803get_item_from_body_location (int loc, object *start) 2812get_next_item_from_body_location (int loc, object *start)
2804{ 2813{
2805 if (start)
2806 for (object *tmp = start; tmp; tmp = tmp->below) 2814 for (object *tmp = start; tmp; tmp = tmp->below)
2807 if (QUERY_FLAG (tmp, FLAG_APPLIED) && tmp->slot[loc].info && (!tmp->invisible || tmp->type == SKILL)) 2815 if (tmp->flag [FLAG_APPLIED]
2816 && tmp->slot[loc].info
2817 && (!tmp->invisible || tmp->type == SKILL))
2808 return tmp; 2818 return tmp;
2809 2819
2810 return 0; 2820 return 0;
2811} 2821}
2812 2822
2813/** 2823/**
2854 /* We do a while loop - may need to remove several items in order 2864 /* We do a while loop - may need to remove several items in order
2855 * to free up enough slots. 2865 * to free up enough slots.
2856 */ 2866 */
2857 while ((who->slot[i].used + op->slot[i].info) < 0) 2867 while ((who->slot[i].used + op->slot[i].info) < 0)
2858 { 2868 {
2859 object *tmp = get_item_from_body_location (i, last); 2869 object *tmp = get_next_item_from_body_location (i, last);
2860 2870
2861 if (!tmp) 2871 if (!tmp)
2862 { 2872 {
2863#if 0 2873#if 0
2864 /* Not a bug - we'll get this if the player has cursed items 2874 /* Not a bug - we'll get this if the player has cursed items
2902 * Checks to see if 'who' can apply object 'op'. 2912 * Checks to see if 'who' can apply object 'op'.
2903 * Returns 0 if apply can be done without anything special. 2913 * Returns 0 if apply can be done without anything special.
2904 * Otherwise returns a bitmask - potentially several of these may be 2914 * Otherwise returns a bitmask - potentially several of these may be
2905 * set, but largely depends on circumstance - in the future, processing 2915 * set, but largely depends on circumstance - in the future, processing
2906 * may be pruned once we know some status (eg, once CAN_APPLY_NEVER 2916 * may be pruned once we know some status (eg, once CAN_APPLY_NEVER
2907 * is set, do we really are what the other flags may be?) 2917 * is set, do we really care what the other flags may be?)
2908 * 2918 *
2909 * See include/define.h for detailed description of the meaning of 2919 * See include/define.h for detailed description of the meaning of
2910 * these return values. 2920 * these return values.
2911 */ 2921 */
2912int 2922int
2921 for (int i = 0; i < NUM_BODY_LOCATIONS; i++) 2931 for (int i = 0; i < NUM_BODY_LOCATIONS; i++)
2922 { 2932 {
2923 if (op->slot[i].info) 2933 if (op->slot[i].info)
2924 { 2934 {
2925 /* Item uses more slots than we have */ 2935 /* Item uses more slots than we have */
2926 if (abs (op->slot[i].info) > who->slot[i].info) 2936 if (who->slot[i].info + op->slot [i].info < 0)
2927 { 2937 {
2928 /* Could return now for efficiency - rest of info below isn't 2938 /* Could return now for efficiency - rest of info below isn't
2929 * really needed. 2939 * really needed.
2930 */ 2940 */
2931 retval |= CAN_APPLY_NEVER; 2941 retval |= CAN_APPLY_NEVER;
2932 } 2942 }
2933 else if ((who->slot[i].used + op->slot[i].info) < 0) 2943 else if (who->slot[i].used + op->slot[i].info < 0)
2934 { 2944 {
2935 /* in this case, equipping this would use more free spots than 2945 /* in this case, equipping this would use more free spots than
2936 * we have. 2946 * we have.
2937 */ 2947 */
2938 2948
2949 { 2959 {
2950 retval |= CAN_APPLY_UNAPPLY; 2960 retval |= CAN_APPLY_UNAPPLY;
2951 continue; 2961 continue;
2952 } 2962 }
2953 2963
2954 object *tmp1 = get_item_from_body_location (i, who->inv); 2964 object *tmp1 = get_next_item_from_body_location (i, who->inv);
2955 if (!tmp1) 2965 if (!tmp1)
2956 { 2966 {
2957#if 0 2967#if 0
2958 /* This is sort of an error, but happens a lot when old players 2968 /* This is sort of an error, but happens a lot when old players
2959 * join in with more stuff equipped than they are now allowed. 2969 * join in with more stuff equipped than they are now allowed.
2960 */ 2970 */
2961 LOG (llevError, "Can't find object using location %d on %s\n", i, who->name); 2971 LOG (llevError, "Can't find object using location %d on %s\n", i, who->name);
2962#endif 2972#endif
2973 fprintf (stderr, "can apply never due to %d but %d - %d + %d\n",//D
2974 i, who->slot[i].used,ws ? ws->slot[i].info :-77,op->slot[i].info);//D
2963 retval |= CAN_APPLY_NEVER; 2975 retval |= CAN_APPLY_NEVER;
2964 } 2976 }
2965 else 2977 else
2966 { 2978 {
2967 /* need to unapply something. However, if this something 2979 /* need to unapply something. However, if this something
2968 * is different than we had found before, it means they need 2980 * is different than we had found before, it means they need
2969 * to apply multiple objects 2981 * to apply multiple objects
2970 */ 2982 */
2971 retval |= CAN_APPLY_UNAPPLY; 2983 retval |= CAN_APPLY_UNAPPLY;
2984
2972 if (!tmp) 2985 if (!tmp)
2973 tmp = tmp1; 2986 tmp = tmp1;
2974 else if (tmp != tmp1) 2987 else if (tmp != tmp1)
2975 retval |= CAN_APPLY_UNAPPLY_MULT; 2988 retval |= CAN_APPLY_UNAPPLY_MULT;
2976 2989
3080 return 0; 3093 return 0;
3081 3094
3082 // if the item is combat/ranged, wield the relevant slot first 3095 // if the item is combat/ranged, wield the relevant slot first
3083 // to resolve conflicts. 3096 // to resolve conflicts.
3084 if (player *pl = who->contr) 3097 if (player *pl = who->contr)
3085 switch (op->type) 3098 switch (op->slottype ())
3086 { 3099 {
3087 case WEAPON:
3088 who->change_weapon (pl->combat_ob); 3100 case slot_combat: who->change_weapon (pl->combat_ob); break;
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); 3101 case slot_ranged: who->change_weapon (pl->ranged_ob); break;
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 } 3102 }
3106 3103
3107 /* Can't just apply this object. Lets see what not and what to do */ 3104 /* Can't just apply this object. Lets see what not and what to do */
3108 if (int i = can_apply_object (who, op)) 3105 if (int i = can_apply_object (who, op))
3109 { 3106 {
3282 if (who->type == PLAYER) 3279 if (who->type == PLAYER)
3283 esrv_send_item (who, tmp2); 3280 esrv_send_item (who, tmp2);
3284 3281
3285 return 0; 3282 return 0;
3286 3283
3287 /* this part is needed for skill-tools */ 3284 case SKILL_TOOL:
3285 // applying a skill tool also readies the skill
3286 SET_FLAG (op, FLAG_APPLIED);
3287 skop = find_skill_by_name (who, op->skill);
3288 if (!skop->flag [FLAG_APPLIED])
3289 apply_special (who, skop, AP_APPLY);
3290 break;
3291
3288 case SKILL: 3292 case SKILL:
3289 case SKILL_TOOL:
3290 if (who->chosen_skill) 3293 if (who->chosen_skill)
3291 { 3294 {
3292 LOG (llevError, "BUG: apply_special(): can't apply two skills\n"); 3295 LOG (llevError, "BUG: apply_special(): can't apply two skills\n");
3293 return 1; 3296 return 1;
3294 } 3297 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines