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.240 by root, Mon Apr 5 20:33:13 2010 UTC vs.
Revision 1.244 by root, Tue Apr 6 00:39:26 2010 UTC

2856 who->statusmsg (format ("I don't know how to apply the %s.", query_name (op))); 2856 who->statusmsg (format ("I don't know how to apply the %s.", query_name (op)));
2857 return 0; 2857 return 0;
2858 } 2858 }
2859} 2859}
2860 2860
2861/*
2862 * Same return value as apply() function.
2863 */
2864bool
2865player_apply (object *pl, object *op, int aflag)
2866{
2867 if (!op->env && (pl->move_type & MOVE_FLYING))
2868 {
2869 /* player is flying and applying object not in inventory */
2870 if (!QUERY_FLAG (pl, FLAG_WIZ) && !(op->move_type & MOVE_FLYING))
2871 {
2872 pl->failmsg ("But you are floating high above the ground! "
2873 "H<You have to stop levitating first, if you can, either by using your levitation skill, "
2874 "or waiting till the levitation effect wears off.>");
2875 return 0;
2876 }
2877 }
2878
2879 pl->contr->last_used = op;
2880
2881 return pl->apply (op, aflag);
2882}
2883
2884/** 2861/**
2885 * player_apply_below attempts to apply the object 'below' the player. 2862 * player_apply_below attempts to apply the object 'below' the player.
2886 * 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
2887 * we use the ground. 2864 * we use the ground.
2888 */ 2865 */
2897 * 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
2898 * 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
2899 * 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
2900 * not return a proper value. 2877 * not return a proper value.
2901 */ 2878 */
2902 //TODO: currently looks only at the topmost objetc, no longer at multiple floors 2879 //TODO: no longer at multiple floors
2903 // and also not on move_on floors. what was this for, anyways? 2880 // and also not on move_on floors. what was this for, anyways?
2904 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)
2905 { 2882 {
2906 next = tmp->below; 2883 next = tmp->below;
2907 2884
2885 if (tmp->type == SPELL_EFFECT || tmp->invisible)
2886 continue;
2887
2908 /* If it is visible, player can apply it. 2888 /* If it is visible, player can apply it.
2909 */ 2889 */
2910 if (!tmp->invisible)
2911 if (player_apply (pl, tmp, 0)) 2890 if (pl->apply (tmp))
2912 break; 2891 break;
2913
2914 break;
2915 } 2892 }
2916} 2893}
2917 2894
2918/** 2895/**
2919 * Unapplies specified item. 2896 * Unapplies specified item.
3259object::apply (object *ob, int aflags) 3236object::apply (object *ob, int aflags)
3260{ 3237{
3261 if (!ob) // simplifies a lot of callers 3238 if (!ob) // simplifies a lot of callers
3262 return true; 3239 return true;
3263 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
3264 bool want_apply = 3258 bool want_apply =
3265 aflags & AP_APPLY ? true 3259 aflags & AP_APPLY ? true
3266 : aflags & AP_UNAPPLY ? false 3260 : aflags & AP_UNAPPLY ? false
3267 : !ob->flag [FLAG_APPLIED]; // AP_TOGGLE 3261 : !ob->flag [FLAG_APPLIED]; // AP_TOGGLE
3268 3262
3316 // now handle slot exclusions 3310 // now handle slot exclusions
3317 if (slot) 3311 if (slot)
3318 { 3312 {
3319 // only one slot can be active 3313 // only one slot can be active
3320 if (want_apply) 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); 3321 apply (oslot, AP_UNAPPLY);
3322 }
3322 3323
3323 // clear item from slot if applied 3324 // clear item from slot if applied
3324 if (!want_apply && *slot == ob) 3325 if (!want_apply && current_weapon == ob)
3325 {
3326 *slot = 0;
3327
3328 if (current_weapon == ob)
3329 current_weapon = 0; 3326 current_weapon = 0;
3330 }
3331 } 3327 }
3332 } 3328 }
3333 3329
3334 if (ob->flag [FLAG_APPLIED] != want_apply) 3330 if (ob->flag [FLAG_APPLIED] != want_apply)
3335 manual_apply (this, ob, aflags); 3331 manual_apply (this, ob, aflags);
3336 3332
3337 if (ob->flag [FLAG_APPLIED] != want_apply) 3333 if (ob->flag [FLAG_APPLIED] != want_apply)
3338 return false; 3334 return false;
3339 3335
3340 if (slot) 3336 if (slot && want_apply)
3341 current_weapon = *slot = ob; 3337 current_weapon = *slot = ob;
3342 3338
3343 return true; 3339 return true;
3344} 3340}
3345 3341
3553 )); 3549 ));
3554 else 3550 else
3555 who->failmsg (format ( 3551 who->failmsg (format (
3556 "You feel as if you wanted to do something funny, but you can't remember what. " 3552 "You feel as if you wanted to do something funny, but you can't remember what. "
3557 "H<The %s skill cannot be readied or used, it is always active.>", 3553 "H<The %s skill cannot be readied or used, it is always active.>",
3558 &op->skill, &op->skill 3554 &op->skill
3559 )); 3555 ));
3560 3556
3561 if (tmp) who->insert (tmp); 3557 if (tmp) who->insert (tmp);
3558
3562 return 1; 3559 return 1;
3563 } 3560 }
3564 3561
3565 if (who->contr) 3562 if (who->contr)
3566 who->statusmsg (format ( 3563 if (op->invisible)
3567 op->invisible ? "You can now use the %s skill." : "You ready %s.", 3564 who->statusmsg (format ("You can now use the %s skill.", &op->skill));
3568 query_name (op),
3569 &op->skill
3570 )); 3565 else
3566 who->statusmsg (format ("You ready %s.", query_name (op)));
3571 } 3567 }
3572 3568
3573 SET_FLAG (who, FLAG_READY_SKILL); 3569 SET_FLAG (who, FLAG_READY_SKILL);
3574 SET_FLAG (op, FLAG_APPLIED); 3570 SET_FLAG (op, FLAG_APPLIED);
3575 change_abil (who, op); 3571 change_abil (who, op);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines