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.92 by root, Sat May 12 18:23:51 2007 UTC vs.
Revision 1.100 by root, Thu May 17 14:14:55 2007 UTC

1338 1338
1339 /* Just put in some sanity check. I think there is a bug in the 1339 /* Just put in some sanity check. I think there is a bug in the
1340 * above with some objects have zero speed, and thus the player 1340 * above with some objects have zero speed, and thus the player
1341 * getting permanently paralyzed. 1341 * getting permanently paralyzed.
1342 */ 1342 */
1343 if (victim->speed_left < -50.0) 1343 if (victim->speed_left < -50.f)
1344 victim->speed_left = -50.0; 1344 victim->speed_left = -50.f;
1345 /* LOG(llevDebug, "apply, playermove, player speed_left=%f\n", victim->speed_left); */ 1345 /* LOG(llevDebug, "apply, playermove, player speed_left=%f\n", victim->speed_left); */
1346 } 1346 }
1347 goto leave; 1347 goto leave;
1348 1348
1349 case SPINNER: 1349 case SPINNER:
1868 if (!QUERY_FLAG (tmp, FLAG_IDENTIFIED)) 1868 if (!QUERY_FLAG (tmp, FLAG_IDENTIFIED))
1869 identify (tmp); 1869 identify (tmp);
1870 1870
1871 new_draw_info_format (NDI_BLACK, 0, op, "The scroll of %s turns to dust.", &tmp->inv->name); 1871 new_draw_info_format (NDI_BLACK, 0, op, "The scroll of %s turns to dust.", &tmp->inv->name);
1872 1872
1873
1874 cast_spell (op, tmp, dir, tmp->inv, NULL); 1873 cast_spell (op, tmp, dir, tmp->inv, NULL);
1875 decrease_ob (tmp); 1874 decrease_ob (tmp);
1876} 1875}
1877 1876
1878/** 1877/**
1881 * chest. 1880 * chest.
1882 */ 1881 */
1883static void 1882static void
1884apply_treasure (object *op, object *tmp) 1883apply_treasure (object *op, object *tmp)
1885{ 1884{
1886 object *treas;
1887
1888
1889 /* Nice side effect of new treasure creation method is that the treasure 1885 /* Nice side effect of new treasure creation method is that the treasure
1890 * for the chest is done when the chest is created, and put into the chest 1886 * for the chest is done when the chest is created, and put into the chest
1891 * inventory. So that when the chest burns up, the items still exist. Also 1887 * inventory. So that when the chest burns up, the items still exist. Also
1892 * prevents people fromt moving chests to more difficult maps to get better 1888 * prevents people fromt moving chests to more difficult maps to get better
1893 * treasure 1889 * treasure
1894 */ 1890 */
1895
1896 treas = tmp->inv; 1891 object *treas = tmp->inv;
1897 if (treas == NULL) 1892
1893 if (!treas)
1898 { 1894 {
1899 new_draw_info (NDI_UNIQUE, 0, op, "The chest was empty."); 1895 new_draw_info (NDI_UNIQUE, 0, op, "The chest was empty.");
1900 decrease_ob (tmp); 1896 decrease_ob (tmp);
1901 return; 1897 return;
1902 } 1898 }
1899
1903 while (tmp->inv) 1900 while (tmp->inv)
1904 { 1901 {
1905 treas = tmp->inv; 1902 treas = tmp->inv;
1906 1903
1907 treas->remove (); 1904 treas->remove ();
2550 new_draw_info (NDI_UNIQUE, 0, pl, "But you are floating high " "above the ground!"); 2547 new_draw_info (NDI_UNIQUE, 0, pl, "But you are floating high " "above the ground!");
2551 return 0; 2548 return 0;
2552 } 2549 }
2553 } 2550 }
2554 2551
2555 /* Check for PLAYER to avoid a DM to disappear in a puff of smoke if
2556 * applied.
2557 */
2558 if (op->type != PLAYER && QUERY_FLAG (op, FLAG_WAS_WIZ) && !QUERY_FLAG (pl, FLAG_WAS_WIZ))
2559 {
2560 play_sound_map (pl->map, pl->x, pl->y, SOUND_OB_EVAPORATE);
2561 new_draw_info (NDI_UNIQUE, 0, pl, "The object disappears in a puff " "of smoke!");
2562 new_draw_info (NDI_UNIQUE, 0, pl, "It must have been an illusion.");
2563 op->destroy ();
2564 return 1;
2565 }
2566
2567 pl->contr->last_used = op; 2552 pl->contr->last_used = op;
2568 2553
2569 tmp = manual_apply (pl, op, aflag); 2554 tmp = manual_apply (pl, op, aflag);
2570 if (!quiet) 2555 if (!quiet)
2571 { 2556 {
2634 2619
2635 object *tmp2; 2620 object *tmp2;
2636 2621
2637 CLEAR_FLAG (op, FLAG_APPLIED); 2622 CLEAR_FLAG (op, FLAG_APPLIED);
2638 2623
2624 if (player *pl = who->contr)
2625 {
2626 if (op == pl->ranged_ob) pl->ranged_ob = 0;
2627 if (op == pl->combat_ob) pl->combat_ob = 0;
2628 }
2629
2639 switch (op->type) 2630 switch (op->type)
2640 { 2631 {
2632 case SKILL_TOOL:
2633 // unapplying a skill tool should also unapply the skill it governs
2634 // but this is hard, as it shouldn't do so when the skill can
2635 // be used for other reasons
2636 for (object *tmp = who->inv; tmp; tmp = tmp->below)
2637 if (tmp->skill == op->skill
2638 && tmp->type == SKILL
2639 && tmp->flag [FLAG_APPLIED]
2640 && !tmp->flag [FLAG_CAN_USE_SKILL])
2641 unapply_special (who, tmp, 0);
2642
2643 change_abil (who, op);
2644 break;
2645
2641 case WEAPON: 2646 case WEAPON:
2642 new_draw_info_format (NDI_UNIQUE, 0, who, "You unwield %s.", query_name (op)); 2647 new_draw_info_format (NDI_UNIQUE, 0, who, "You unwield %s.", query_name (op));
2643 2648
2644 change_abil (who, op); 2649 change_abil (who, op);
2645 CLEAR_FLAG (who, FLAG_READY_WEAPON); 2650 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); 2651 clear_skill (who);
2657 break; 2652 break;
2658 2653
2659 case SKILL: /* allows objects to impart skills */
2660 case SKILL_TOOL: 2654 case SKILL:
2661 if (op != who->chosen_skill) 2655 if (op != who->chosen_skill)
2662 LOG (llevError, "BUG: apply_special(): applied skill is not a chosen skill\n"); 2656 LOG (llevError, "BUG: apply_special(): applied skill is not a chosen skill\n");
2663 2657
2664 if (who->contr) 2658 if (who->contr)
2665 { 2659 {
2788/** 2782/**
2789 * Returns the object that is using location 'loc'. 2783 * Returns the object that is using location 'loc'.
2790 * Note that 'start' is the first object to start examing - we 2784 * 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 2785 * then go through the below of this. In this way, you can do
2792 * something like: 2786 * something like:
2793 * tmp = get_item_from_body_location(who->inv, 1); 2787 * tmp = get_next_item_from_body_location(who->inv, 1);
2794 * if (tmp) tmp1 = get_item_from_body_location(tmp->below, 1); 2788 * if (tmp) tmp1 = get_next_item_from_body_location(tmp->below, 1);
2795 * to find the second object that may use this location, etc. 2789 * to find the second object that may use this location, etc.
2796 * Returns NULL if no match is found. 2790 * Returns NULL if no match is found.
2797 * loc is the index into the array we are looking for a match. 2791 * loc is the index into the array we are looking for a match.
2798 * don't return invisible objects unless they are skill objects 2792 * don't return invisible objects unless they are skill objects
2799 * invisible other objects that use 2793 * invisible other objects that use
2800 * up body locations can be used as restrictions. 2794 * up body locations can be used as restrictions.
2801 */ 2795 */
2802static object * 2796static object *
2803get_item_from_body_location (int loc, object *start) 2797get_next_item_from_body_location (int loc, object *start)
2804{ 2798{
2805 if (start)
2806 for (object *tmp = start; tmp; tmp = tmp->below) 2799 for (object *tmp = start; tmp; tmp = tmp->below)
2807 if (QUERY_FLAG (tmp, FLAG_APPLIED) && tmp->slot[loc].info && (!tmp->invisible || tmp->type == SKILL)) 2800 if (tmp->flag [FLAG_APPLIED]
2801 && tmp->slot[loc].info
2802 && (!tmp->invisible || tmp->type == SKILL))
2808 return tmp; 2803 return tmp;
2809 2804
2810 return 0; 2805 return 0;
2811} 2806}
2812 2807
2813/** 2808/**
2854 /* We do a while loop - may need to remove several items in order 2849 /* We do a while loop - may need to remove several items in order
2855 * to free up enough slots. 2850 * to free up enough slots.
2856 */ 2851 */
2857 while ((who->slot[i].used + op->slot[i].info) < 0) 2852 while ((who->slot[i].used + op->slot[i].info) < 0)
2858 { 2853 {
2859 object *tmp = get_item_from_body_location (i, last); 2854 object *tmp = get_next_item_from_body_location (i, last);
2860 2855
2861 if (!tmp) 2856 if (!tmp)
2862 { 2857 {
2863#if 0 2858#if 0
2864 /* Not a bug - we'll get this if the player has cursed items 2859 /* Not a bug - we'll get this if the player has cursed items
2902 * Checks to see if 'who' can apply object 'op'. 2897 * Checks to see if 'who' can apply object 'op'.
2903 * Returns 0 if apply can be done without anything special. 2898 * Returns 0 if apply can be done without anything special.
2904 * Otherwise returns a bitmask - potentially several of these may be 2899 * Otherwise returns a bitmask - potentially several of these may be
2905 * set, but largely depends on circumstance - in the future, processing 2900 * set, but largely depends on circumstance - in the future, processing
2906 * may be pruned once we know some status (eg, once CAN_APPLY_NEVER 2901 * 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?) 2902 * is set, do we really care what the other flags may be?)
2908 * 2903 *
2909 * See include/define.h for detailed description of the meaning of 2904 * See include/define.h for detailed description of the meaning of
2910 * these return values. 2905 * these return values.
2911 */ 2906 */
2912int 2907int
2921 for (int i = 0; i < NUM_BODY_LOCATIONS; i++) 2916 for (int i = 0; i < NUM_BODY_LOCATIONS; i++)
2922 { 2917 {
2923 if (op->slot[i].info) 2918 if (op->slot[i].info)
2924 { 2919 {
2925 /* Item uses more slots than we have */ 2920 /* Item uses more slots than we have */
2926 if (abs (op->slot[i].info) > who->slot[i].info) 2921 if (who->slot[i].info + op->slot [i].info < 0)
2927 { 2922 {
2928 /* Could return now for efficiency - rest of info below isn't 2923 /* Could return now for efficiency - rest of info below isn't
2929 * really needed. 2924 * really needed.
2930 */ 2925 */
2931 retval |= CAN_APPLY_NEVER; 2926 retval |= CAN_APPLY_NEVER;
2932 } 2927 }
2933 else if ((who->slot[i].used + op->slot[i].info) < 0) 2928 else if (who->slot[i].used + op->slot[i].info < 0)
2934 { 2929 {
2935 /* in this case, equipping this would use more free spots than 2930 /* in this case, equipping this would use more free spots than
2936 * we have. 2931 * we have.
2937 */ 2932 */
2938 2933
2949 { 2944 {
2950 retval |= CAN_APPLY_UNAPPLY; 2945 retval |= CAN_APPLY_UNAPPLY;
2951 continue; 2946 continue;
2952 } 2947 }
2953 2948
2954 object *tmp1 = get_item_from_body_location (i, who->inv); 2949 object *tmp1 = get_next_item_from_body_location (i, who->inv);
2955 if (!tmp1) 2950 if (!tmp1)
2956 { 2951 {
2957#if 0 2952#if 0
2958 /* This is sort of an error, but happens a lot when old players 2953 /* 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. 2954 * join in with more stuff equipped than they are now allowed.
2960 */ 2955 */
2961 LOG (llevError, "Can't find object using location %d on %s\n", i, who->name); 2956 LOG (llevError, "Can't find object using location %d on %s\n", i, who->name);
2962#endif 2957#endif
2958 fprintf (stderr, "can apply never due to %d but %d - %d + %d\n",//D
2959 i, who->slot[i].used,ws ? ws->slot[i].info :-77,op->slot[i].info);//D
2963 retval |= CAN_APPLY_NEVER; 2960 retval |= CAN_APPLY_NEVER;
2964 } 2961 }
2965 else 2962 else
2966 { 2963 {
2967 /* need to unapply something. However, if this something 2964 /* need to unapply something. However, if this something
2968 * is different than we had found before, it means they need 2965 * is different than we had found before, it means they need
2969 * to apply multiple objects 2966 * to apply multiple objects
2970 */ 2967 */
2971 retval |= CAN_APPLY_UNAPPLY; 2968 retval |= CAN_APPLY_UNAPPLY;
2969
2972 if (!tmp) 2970 if (!tmp)
2973 tmp = tmp1; 2971 tmp = tmp1;
2974 else if (tmp != tmp1) 2972 else if (tmp != tmp1)
2975 retval |= CAN_APPLY_UNAPPLY_MULT; 2973 retval |= CAN_APPLY_UNAPPLY_MULT;
2976 2974
3080 return 0; 3078 return 0;
3081 3079
3082 // if the item is combat/ranged, wield the relevant slot first 3080 // if the item is combat/ranged, wield the relevant slot first
3083 // to resolve conflicts. 3081 // to resolve conflicts.
3084 if (player *pl = who->contr) 3082 if (player *pl = who->contr)
3085 switch (op->type) 3083 switch (op->slottype ())
3086 { 3084 {
3087 case WEAPON:
3088 who->change_weapon (pl->combat_ob); 3085 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); 3086 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 } 3087 }
3106 3088
3107 /* Can't just apply this object. Lets see what not and what to do */ 3089 /* Can't just apply this object. Lets see what not and what to do */
3108 if (int i = can_apply_object (who, op)) 3090 if (int i = can_apply_object (who, op))
3109 { 3091 {
3282 if (who->type == PLAYER) 3264 if (who->type == PLAYER)
3283 esrv_send_item (who, tmp2); 3265 esrv_send_item (who, tmp2);
3284 3266
3285 return 0; 3267 return 0;
3286 3268
3287 /* this part is needed for skill-tools */ 3269 case SKILL_TOOL:
3270 // applying a skill tool also readies the skill
3271 SET_FLAG (op, FLAG_APPLIED);
3272 skop = find_skill_by_name (who, op->skill);
3273 if (!skop->flag [FLAG_APPLIED])
3274 apply_special (who, skop, AP_APPLY);
3275 break;
3276
3288 case SKILL: 3277 case SKILL:
3289 case SKILL_TOOL:
3290 if (who->chosen_skill) 3278 if (who->chosen_skill)
3291 { 3279 {
3292 LOG (llevError, "BUG: apply_special(): can't apply two skills\n"); 3280 LOG (llevError, "BUG: apply_special(): can't apply two skills\n");
3293 return 1; 3281 return 1;
3294 } 3282 }
3327 3315
3328 new_draw_info (NDI_UNIQUE, 0, who, "You need to apply a missile weapon before readying this skill"); 3316 new_draw_info (NDI_UNIQUE, 0, who, "You need to apply a missile weapon before readying this skill");
3329 return 1; 3317 return 1;
3330 3318
3331 found_bow:; 3319 found_bow:;
3332 }
3333 else if (skill_flags [op->subtype] & SF_NEED_ITEM)
3334 {
3335 for (object *item = who->inv; item; item = item->below)
3336 if (item->flag [FLAG_APPLIED]
3337 && (item->type == WAND || item->type == ROD || item->type == HORN))
3338 {
3339 who->change_weapon (pl->ranged_ob = item);
3340 goto found_item;
3341 }
3342
3343 new_draw_info (NDI_UNIQUE, 0, who, "You need to apply a magic item before readying this skill");
3344 return 1;
3345
3346 found_item:;
3347 } 3320 }
3348 else 3321 else
3349 who->change_weapon (pl->ranged_ob = op); 3322 who->change_weapon (pl->ranged_ob = op);
3350 } 3323 }
3351 3324

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines