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.78 by root, Mon Apr 30 05:54:14 2007 UTC vs.
Revision 1.79 by root, Tue May 1 05:48:20 2007 UTC

1/* 1/*
2 * CrossFire, A Multiplayer game for X-windows 2 * CrossFire, A Multiplayer game
3 * 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team 4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
5 * Copyright (C) 2001 Mark Wedel & Crossfire Development Team 5 * Copyright (C) 2001 Mark Wedel & Crossfire Development Team
6 * Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (C) 1992 Frank Tore Johansen
7 * 7 *
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, 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>
26
25#include <global.h> 27#include <global.h>
26#include <living.h> 28#include <living.h>
27#include <spells.h> 29#include <spells.h>
28#include <skills.h> 30#include <skills.h>
29#include <tod.h> 31#include <tod.h>
30 32
31#include <sproto.h> 33#include <sproto.h>
32 34
33/* Want this regardless of rplay. */ 35/* Want this regardless of rplay. */
34#include <sounds.h> 36#include <sounds.h>
35
36/* need math lib for double-precision and pow() in dragon_eat_flesh() */
37#include <math.h>
38 37
39/** 38/**
40 * Check if op should abort moving victim because of it's race or slaying. 39 * Check if op should abort moving victim because of it's race or slaying.
41 * Returns 1 if it should abort, returns 0 if it should continue. 40 * Returns 1 if it should abort, returns 0 if it should continue.
42 */ 41 */
2296 } 2295 }
2297 2296
2298 return 0; 2297 return 0;
2299} 2298}
2300 2299
2301
2302/** 2300/**
2303 * Main apply handler. 2301 * Main apply handler.
2304 * 2302 *
2305 * Checks for unpaid items before applying. 2303 * Checks for unpaid items before applying.
2306 * 2304 *
2313 * being applied. 2311 * being applied.
2314 * 2312 *
2315 * aflag is special (always apply/unapply) flags. Nothing is done with 2313 * aflag is special (always apply/unapply) flags. Nothing is done with
2316 * them in this function - they are passed to apply_special 2314 * them in this function - they are passed to apply_special
2317 */ 2315 */
2318
2319int 2316int
2320manual_apply (object *op, object *tmp, int aflag) 2317manual_apply (object *op, object *tmp, int aflag)
2321{ 2318{
2322 if (tmp->head) 2319 if (tmp->head)
2323 tmp = tmp->head; 2320 tmp = tmp->head;
2453 case LAMP: 2450 case LAMP:
2454 case BUILDER: 2451 case BUILDER:
2455 case SKILL_TOOL: 2452 case SKILL_TOOL:
2456 if (tmp->env != op) 2453 if (tmp->env != op)
2457 return 2; /* not in inventory */ 2454 return 2; /* not in inventory */
2455
2458 (void) apply_special (op, tmp, aflag); 2456 apply_special (op, tmp, aflag);
2459 return 1; 2457 return 1;
2460 2458
2461 case DRINK: 2459 case DRINK:
2462 case FOOD: 2460 case FOOD:
2463 case FLESH: 2461 case FLESH:
2647 switch (op->type) 2645 switch (op->type)
2648 { 2646 {
2649 case WEAPON: 2647 case WEAPON:
2650 new_draw_info_format (NDI_UNIQUE, 0, who, "You unwield %s.", query_name (op)); 2648 new_draw_info_format (NDI_UNIQUE, 0, who, "You unwield %s.", query_name (op));
2651 2649
2652 (void) change_abil (who, op); 2650 change_abil (who, op);
2653 if (QUERY_FLAG (who, FLAG_READY_WEAPON))
2654 CLEAR_FLAG (who, FLAG_READY_WEAPON); 2651 CLEAR_FLAG (who, FLAG_READY_WEAPON);
2652
2653 if (who->contr)
2654 {
2655 if (who->contr->combat_ob == op)
2656 who->contr->combat_ob = 0;
2657
2658 if (who->current_weapon == op)
2659 who->current_weapon = 0;
2660 }
2661
2655 clear_skill (who); 2662 clear_skill (who);
2656 break; 2663 break;
2657 2664
2658 case SKILL: /* allows objects to impart skills */ 2665 case SKILL: /* allows objects to impart skills */
2659 case SKILL_TOOL: 2666 case SKILL_TOOL:
2660 if (op != who->chosen_skill) 2667 if (op != who->chosen_skill)
2661 LOG (llevError, "BUG: apply_special(): applied skill is not a chosen skill\n"); 2668 LOG (llevError, "BUG: apply_special(): applied skill is not a chosen skill\n");
2662 2669
2663 if (who->type == PLAYER) 2670 if (who->contr)
2664 {
2665 if (who->contr->ranged_ob == op)
2666 { 2671 {
2667 who->contr->ranged_skill = 0;
2668 who->contr->ranged_ob = 0;
2669 }
2670
2671 if (!op->invisible) 2672 if (!op->invisible)
2672 new_draw_info_format (NDI_UNIQUE, 0, who, "You stop using the %s.", query_name (op)); 2673 new_draw_info_format (NDI_UNIQUE, 0, who, "You stop using the %s.", query_name (op));
2673 else 2674 else
2674 new_draw_info_format (NDI_UNIQUE, 0, who, "You can no longer use the skill: %s.", &op->skill); 2675 new_draw_info_format (NDI_UNIQUE, 0, who, "You can no longer use the skill: %s.", &op->skill);
2675 } 2676 }
2688 case AMULET: 2689 case AMULET:
2689 case GIRDLE: 2690 case GIRDLE:
2690 case BRACERS: 2691 case BRACERS:
2691 case CLOAK: 2692 case CLOAK:
2692 new_draw_info_format (NDI_UNIQUE, 0, who, "You unwear %s.", query_name (op)); 2693 new_draw_info_format (NDI_UNIQUE, 0, who, "You unwear %s.", query_name (op));
2693 (void) change_abil (who, op); 2694 change_abil (who, op);
2694 break; 2695 break;
2696
2695 case LAMP: 2697 case LAMP:
2696 new_draw_info_format (NDI_UNIQUE, 0, who, "You turn off your %s.", &op->name); 2698 new_draw_info_format (NDI_UNIQUE, 0, who, "You turn off your %s.", &op->name);
2697 tmp2 = arch_to_object (op->other_arch); 2699 tmp2 = arch_to_object (op->other_arch);
2698 tmp2->x = op->x; 2700 tmp2->x = op->x;
2699 tmp2->y = op->y; 2701 tmp2->y = op->y;
2704 CLEAR_FLAG (tmp2, FLAG_APPLIED); 2706 CLEAR_FLAG (tmp2, FLAG_APPLIED);
2705 2707
2706 if (QUERY_FLAG (op, FLAG_INV_LOCKED)) 2708 if (QUERY_FLAG (op, FLAG_INV_LOCKED))
2707 SET_FLAG (tmp2, FLAG_INV_LOCKED); 2709 SET_FLAG (tmp2, FLAG_INV_LOCKED);
2708 2710
2709 if (who->type == PLAYER) 2711 if (who->contr)
2710 esrv_del_item (who->contr, op->count); 2712 esrv_del_item (who->contr, op->count);
2711 2713
2712 op->destroy (); 2714 op->destroy ();
2713 insert_ob_in_ob (tmp2, who); 2715 insert_ob_in_ob (tmp2, who);
2714 who->update_stats (); 2716 who->update_stats ();
2717
2715 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED)) 2718 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED))
2716 { 2719 {
2717 if (who->type == PLAYER) 2720 if (who->contr)
2718 { 2721 {
2719 new_draw_info (NDI_UNIQUE, 0, who, "Oops, it feels deadly cold!"); 2722 new_draw_info (NDI_UNIQUE, 0, who, "Oops, it feels deadly cold!");
2720 SET_FLAG (tmp2, FLAG_KNOWN_CURSED); 2723 SET_FLAG (tmp2, FLAG_KNOWN_CURSED);
2721 } 2724 }
2722 } 2725 }
2723 if (who->type == PLAYER) 2726
2727 if (who->contr)
2724 esrv_send_item (who, tmp2); 2728 esrv_send_item (who, tmp2);
2729
2725 return 1; /* otherwise, an attempt to drop causes problems */ 2730 return 1; /* otherwise, an attempt to drop causes problems */
2726 break;
2727 2731
2728 case BOW: 2732 case BOW:
2729 case WAND: 2733 case WAND:
2730 case ROD: 2734 case ROD:
2731 case HORN: 2735 case HORN:
2732 clear_skill (who); 2736 clear_skill (who);
2733 if (who->type == PLAYER) 2737
2738 if (who->contr)
2734 { 2739 {
2735 new_draw_info_format (NDI_UNIQUE, 0, who, "You unready %s.", query_name (op)); 2740 new_draw_info_format (NDI_UNIQUE, 0, who, "You unready %s.", query_name (op));
2736 2741
2737 who->contr->ranged_skill = 0; 2742 if (who->contr->ranged_ob == op)
2738 who->contr->ranged_ob = 0; 2743 who->contr->ranged_ob = 0;
2744
2745 if (who->current_weapon == op)
2746 who->current_weapon = 0;
2739 } 2747 }
2740 else 2748 else
2741 { 2749 {
2742 if (op->type == BOW) 2750 if (op->type == BOW)
2743 CLEAR_FLAG (who, FLAG_READY_BOW); 2751 CLEAR_FLAG (who, FLAG_READY_BOW);
2746 } 2754 }
2747 2755
2748 break; 2756 break;
2749 2757
2750 case BUILDER: 2758 case BUILDER:
2751 if (who->type == PLAYER) 2759 if (who->contr)
2752 { 2760 {
2753 new_draw_info_format (NDI_UNIQUE, 0, who, "You unready %s.", query_name (op)); 2761 new_draw_info_format (NDI_UNIQUE, 0, who, "You unready %s.", query_name (op));
2754 2762
2755 who->contr->ranged_skill = 0; 2763 if (who->contr->ranged_ob == op)
2756 who->contr->ranged_ob = 0; 2764 who->contr->ranged_ob = 0;
2757 } 2765 }
2758 break; 2766 break;
2759 2767
2760 default: 2768 default:
2761 new_draw_info_format (NDI_UNIQUE, 0, who, "You unapply %s.", query_name (op)); 2769 new_draw_info_format (NDI_UNIQUE, 0, who, "You unapply %s.", query_name (op));
2767 if (!(aflags & AP_NO_MERGE)) 2775 if (!(aflags & AP_NO_MERGE))
2768 { 2776 {
2769 object *tmp; 2777 object *tmp;
2770 2778
2771 tmp = merge_ob (op, NULL); 2779 tmp = merge_ob (op, NULL);
2772 if (who->type == PLAYER) 2780
2781 if (who->contr)
2773 { 2782 {
2774 if (tmp) 2783 if (tmp)
2775 { /* it was merged */ 2784 { /* it was merged */
2776 esrv_del_item (who->contr, op->count); 2785 esrv_del_item (who->contr, op->count);
2777 op = tmp; 2786 op = tmp;
2778 } 2787 }
2779 2788
2780 esrv_send_item (who, op); 2789 esrv_send_item (who, op);
2781 } 2790 }
2782 } 2791 }
2792
2783 return 0; 2793 return 0;
2784} 2794}
2785 2795
2786/** 2796/**
2787 * Returns the object that is using location 'loc'. 2797 * Returns the object that is using location 'loc'.
3190 case WEAPON: 3200 case WEAPON:
3191 if (!check_weapon_power (who, op->last_eat)) 3201 if (!check_weapon_power (who, op->last_eat))
3192 { 3202 {
3193 new_draw_info (NDI_UNIQUE, 0, who, "That weapon is too powerful for you to use."); 3203 new_draw_info (NDI_UNIQUE, 0, who, "That weapon is too powerful for you to use.");
3194 new_draw_info (NDI_UNIQUE, 0, who, "It would consume your soul!."); 3204 new_draw_info (NDI_UNIQUE, 0, who, "It would consume your soul!.");
3205
3195 if (tmp) 3206 if (tmp)
3196 insert_ob_in_ob (tmp, who); 3207 insert_ob_in_ob (tmp, who);
3208
3197 return 1; 3209 return 1;
3198 } 3210 }
3199 3211
3200 //TODO: this obviously fails for players using a shiorter prefix 3212 //TODO: this obviously fails for players using a shorter prefix
3201 // i.e. "R" can use Ragnarok's sword. 3213 // i.e. "R" can use Ragnarok's sword.
3202 if (op->level && (strncmp (op->name, who->name, strlen (who->name)))) 3214 if (op->level && (strncmp (op->name, who->name, strlen (who->name))))
3203 { 3215 {
3204 /* if the weapon does not have the name as the character, can't use it. */ 3216 /* if the weapon does not have the name as the character, can't use it. */
3205 /* (Ragnarok's sword attempted to be used by Foo: won't work) */ 3217 /* (Ragnarok's sword attempted to be used by Foo: won't work) */
3216 if (!skop) 3228 if (!skop)
3217 new_draw_info_format (NDI_UNIQUE, 0, who, "The %s is broken, please report this to the dungeon master!", query_name (op));//TODO 3229 new_draw_info_format (NDI_UNIQUE, 0, who, "The %s is broken, please report this to the dungeon master!", query_name (op));//TODO
3218 else//TODO 3230 else//TODO
3219 change_skill (who, skop, 1); 3231 change_skill (who, skop, 1);
3220 3232
3221 if (who->type == PLAYER) 3233 if (who->contr)
3222 who->contr->set_skill (skop, op); 3234 {
3235 who->contr->combat_ob = op;
3236 who->current_weapon = op;
3237 }
3223 3238
3224 if (!QUERY_FLAG (who, FLAG_READY_WEAPON)) 3239 if (!QUERY_FLAG (who, FLAG_READY_WEAPON))
3225 SET_FLAG (who, FLAG_READY_WEAPON); 3240 SET_FLAG (who, FLAG_READY_WEAPON);
3226 3241
3227 new_draw_info_format (NDI_UNIQUE, 0, who, "You wield %s.", query_name (op)); 3242 new_draw_info_format (NDI_UNIQUE, 0, who, "You wield %s.", query_name (op));
3298 { 3313 {
3299 LOG (llevError, "BUG: apply_special(): can't apply two skills\n"); 3314 LOG (llevError, "BUG: apply_special(): can't apply two skills\n");
3300 return 1; 3315 return 1;
3301 } 3316 }
3302 3317
3303 if (who->type == PLAYER) 3318 if (player *pl = who->contr)
3319 {
3320 if (IS_COMBAT_SKILL (op->subtype))
3304 { 3321 {
3305 who->contr->set_skill (op); 3322 if (skill_flags [op->subtype] && SF_NEED_WEAPON)
3323 {
3324 for (object *item = who->inv; item; item = item->below)
3325 if (item->type == WEAPON && item->flag [FLAG_APPLIED])
3326 {
3327 pl->combat_ob = who->current_weapon = item;
3328 goto found_weapon;
3329 }
3330
3331 new_draw_info (NDI_UNIQUE, 0, who, "You need to apply a melee weapon before readying this skill");
3332 return 1;
3333
3334 found_weapon:;
3335 }
3336 else
3337 who->contr->combat_ob = op;
3338 }
3339 else if (IS_RANGED_SKILL (op->subtype))
3340 {
3341 if (skill_flags [op->subtype] && SF_NEED_BOW)
3342 {
3343 for (object *item = who->inv; item; item = item->below)
3344 if (item->type == BOW && item->flag [FLAG_APPLIED])
3345 {
3346 pl->ranged_ob = who->current_weapon = item;
3347 goto found_bow;
3348 }
3349
3350 new_draw_info (NDI_UNIQUE, 0, who, "You need to apply a missile weapon before readying this skill");
3351 return 1;
3352
3353 found_bow:;
3354 }
3355 else if (skill_flags [op->subtype] && SF_NEED_ITEM)
3356 {
3357 for (object *item = who->inv; item; item = item->below)
3358 if (item->flag [FLAG_APPLIED]
3359 && (item->type == WAND || item->type == ROD || item->type == HORN))
3360 {
3361 pl->ranged_ob = who->current_weapon = item;
3362 goto found_item;
3363 }
3364
3365 new_draw_info (NDI_UNIQUE, 0, who, "You need to apply a magic item before readying this skill");
3366 return 1;
3367
3368 found_item:;
3369 }
3370 else
3371 pl->ranged_ob = op;
3372 }
3306 3373
3307 if (!op->invisible) 3374 if (!op->invisible)
3308 { 3375 {
3309 new_draw_info_format (NDI_UNIQUE, 0, who, "You ready %s.", query_name (op)); 3376 new_draw_info_format (NDI_UNIQUE, 0, who, "You ready %s.", query_name (op));
3310 new_draw_info_format (NDI_UNIQUE, 0, who, "You can now use the skill: %s.", &op->skill); 3377 new_draw_info_format (NDI_UNIQUE, 0, who, "You can now use the skill: %s.", &op->skill);
3311 } 3378 }
3312 else 3379 else
3313 new_draw_info_format (NDI_UNIQUE, 0, who, "Readied skill: %s.", op->skill ? &op->skill : &op->name); 3380 new_draw_info_format (NDI_UNIQUE, 0, who, "Readied skill: %s.", op->skill ? &op->skill : &op->name);
3314 } 3381 }
3315 3382
3316 if (who->type == PLAYER)
3317 who->contr->set_skill (op, 0);
3318
3319 SET_FLAG (op, FLAG_APPLIED); 3383 SET_FLAG (op, FLAG_APPLIED);
3320 change_abil (who, op); 3384 change_abil (who, op);
3321 who->chosen_skill = op; 3385 who->chosen_skill = op;
3322 SET_FLAG (who, FLAG_READY_SKILL); 3386 SET_FLAG (who, FLAG_READY_SKILL);
3323 break; 3387 break;
3353 if (!skop) 3417 if (!skop)
3354 new_draw_info_format (NDI_UNIQUE, 0, who, "The %s is broken, please report this to the dungeon master!", query_name (op));//TODO 3418 new_draw_info_format (NDI_UNIQUE, 0, who, "The %s is broken, please report this to the dungeon master!", query_name (op));//TODO
3355 else//TODO 3419 else//TODO
3356 change_skill (who, skop, 0); 3420 change_skill (who, skop, 0);
3357 3421
3358 if (who->type == PLAYER) 3422 if (who->contr)
3359 { 3423 {
3360 who->contr->set_skill (skop, op); 3424 who->contr->ranged_ob = op;
3361 3425
3362 new_draw_info_format (NDI_UNIQUE, 0, who, "You ready %s.", query_name (op)); 3426 new_draw_info_format (NDI_UNIQUE, 0, who, "You ready %s.", query_name (op));
3363 3427
3364 if (op->type == BOW) 3428 if (op->type == BOW)
3365 { 3429 {
3430 who->current_weapon = op;
3366 change_abil (who, op); 3431 change_abil (who, op);
3367 new_draw_info_format (NDI_UNIQUE, 0, who, 3432 new_draw_info_format (NDI_UNIQUE, 0, who,
3368 "You will now fire %s with %s.", op->race ? &op->race : "nothing", query_name (op)); 3433 "You will now fire %s with %s.", op->race ? &op->race : "nothing", query_name (op));
3369 } 3434 }
3370 } 3435 }
3384 if (who->contr->ranged_ob && who->contr->ranged_ob->type == BUILDER) 3449 if (who->contr->ranged_ob && who->contr->ranged_ob->type == BUILDER)
3385 unapply_special (who, who->contr->ranged_ob, 0); 3450 unapply_special (who, who->contr->ranged_ob, 0);
3386 3451
3387 new_draw_info_format (NDI_UNIQUE, 0, who, "You ready your %s.", query_name (op)); 3452 new_draw_info_format (NDI_UNIQUE, 0, who, "You ready your %s.", query_name (op));
3388 3453
3389 who->contr->ranged_skill = who;
3390 who->contr->ranged_ob = op; 3454 who->contr->ranged_ob = op;
3391 } 3455 }
3392 break; 3456 break;
3393 3457
3394 default: 3458 default:
3395 new_draw_info_format (NDI_UNIQUE, 0, who, "You apply %s.", query_name (op)); 3459 new_draw_info_format (NDI_UNIQUE, 0, who, "You apply %s.", query_name (op));
3396 } /* end of switch op->type */ 3460 } /* end of switch op->type */
3397 3461
3398 SET_FLAG (op, FLAG_APPLIED); 3462 SET_FLAG (op, FLAG_APPLIED);
3399 3463
3400 if (tmp != NULL) 3464 if (tmp)
3401 tmp = insert_ob_in_ob (tmp, who); 3465 tmp = insert_ob_in_ob (tmp, who);
3402 3466
3403 who->update_stats (); 3467 who->update_stats ();
3404 3468
3405 /* We exclude spell casting objects. The fire code will set the 3469 /* We exclude spell casting objects. The fire code will set the

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines