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.142 by root, Sun Apr 13 20:21:50 2008 UTC vs.
Revision 1.148 by root, Tue Apr 22 04:06:07 2008 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
217 217
218 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED)) 218 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED))
219 { 219 {
220 op->drain_stat (); 220 op->drain_stat ();
221 op->update_stats (); 221 op->update_stats ();
222 decrease_ob (tmp); 222 tmp->decrease ();
223 return 1; 223 return 1;
224 } 224 }
225 225
226 if (!(at = archetype::find (ARCH_DEPLETION))) 226 if (!(at = archetype::find (ARCH_DEPLETION)))
227 { 227 {
228 LOG (llevError, "Could not find archetype depletion\n"); 228 LOG (llevError, "Could not find archetype depletion\n");
229 return 0; 229 return 0;
230 } 230 }
231
231 depl = present_arch_in_ob (at, op); 232 depl = present_arch_in_ob (at, op);
232 233
233 if (depl) 234 if (depl)
234 { 235 {
235 for (i = 0; i < NUM_STATS; i++) 236 for (i = 0; i < NUM_STATS; i++)
240 op->update_stats (); 241 op->update_stats ();
241 } 242 }
242 else 243 else
243 op->statusmsg ("Your potion had no effect."); 244 op->statusmsg ("Your potion had no effect.");
244 245
245 decrease_ob (tmp); 246 tmp->decrease ();
246 return 1; 247 return 1;
247 } 248 }
248 249
249 /* improvement potion - only for players */ 250 /* improvement potion - only for players */
250 if (op->type == PLAYER && (tmp->attacktype & AT_GODPOWER)) 251 if (op->type == PLAYER && (tmp->attacktype & AT_GODPOWER))
318 } 319 }
319 else 320 else
320 op->statusmsg ("You are fortunate that you are so pathetic.", NDI_DK_ORANGE); 321 op->statusmsg ("You are fortunate that you are so pathetic.", NDI_DK_ORANGE);
321 } 322 }
322 323
323 decrease_ob (tmp); 324 tmp->decrease ();
324 return 1; 325 return 1;
325 } 326 }
326 327
327 328
328 /* A potion that casts a spell. Healing, restore spellpoint (power potion) 329 /* A potion that casts a spell. Healing, restore spellpoint (power potion)
347 insert_ob_in_map (fball, op->map, NULL, 0); 348 insert_ob_in_map (fball, op->map, NULL, 0);
348 } 349 }
349 else 350 else
350 cast_spell (op, tmp, op->facing, tmp->inv, NULL); 351 cast_spell (op, tmp, op->facing, tmp->inv, NULL);
351 352
352 decrease_ob (tmp); 353 tmp->decrease ();
353 354
354 /* if youre dead, no point in doing this... */ 355 /* if youre dead, no point in doing this... */
355 if (!QUERY_FLAG (op, FLAG_REMOVED)) 356 if (!QUERY_FLAG (op, FLAG_REMOVED))
356 op->update_stats (); 357 op->update_stats ();
357 358
388 force->speed_left = -1; 389 force->speed_left = -1;
389 force = insert_ob_in_ob (force, op); 390 force = insert_ob_in_ob (force, op);
390 CLEAR_FLAG (tmp, FLAG_APPLIED); 391 CLEAR_FLAG (tmp, FLAG_APPLIED);
391 SET_FLAG (force, FLAG_APPLIED); 392 SET_FLAG (force, FLAG_APPLIED);
392 change_abil (op, force); 393 change_abil (op, force);
393 decrease_ob (tmp); 394 tmp->decrease ();
394 return 1; 395 return 1;
395 } 396 }
396 397
397 /* Only thing left are the stat potions */ 398 /* Only thing left are the stat potions */
398 if (op->type == PLAYER) 399 if (op->type == PLAYER)
411 * stat will not be raised by them. fix_player just clears 412 * stat will not be raised by them. fix_player just clears
412 * up all the stats. 413 * up all the stats.
413 */ 414 */
414 CLEAR_FLAG (tmp, FLAG_APPLIED); 415 CLEAR_FLAG (tmp, FLAG_APPLIED);
415 op->update_stats (); 416 op->update_stats ();
416 decrease_ob (tmp); 417 tmp->decrease ();
417 return 1; 418 return 1;
418} 419}
419 420
420/**************************************************************************** 421/****************************************************************************
421 * Weapon improvement code follows 422 * Weapon improvement code follows
468 { 469 {
469 if (strcmp (op->arch->archname, item) == 0) 470 if (strcmp (op->arch->archname, item) == 0)
470 { 471 {
471 if (op->nrof >= nrof) 472 if (op->nrof >= nrof)
472 { 473 {
473 decrease_ob_nr (op, nrof); 474 op->decrease (nrof);
474 return; 475 return;
475 } 476 }
476 else 477 else
477 { 478 {
478 decrease_ob_nr (op, op->nrof); 479 op->decrease (nrof);
479 nrof -= op->nrof; 480 nrof -= op->nrof;
480 } 481 }
481 482
482 op = prev; 483 op = prev;
483 } 484 }
568static int 569static int
569improve_weapon_stat (object *op, object *improver, object *weapon, sint8 &stat, int sacrifice_count, const char *statname) 570improve_weapon_stat (object *op, object *improver, object *weapon, sint8 &stat, int sacrifice_count, const char *statname)
570{ 571{
571 stat += sacrifice_count; 572 stat += sacrifice_count;
572 weapon->last_eat++; 573 weapon->last_eat++;
573 decrease_ob (improver); 574 improver->decrease ();
574 575
575 /* So it updates the players stats and the window */ 576 /* So it updates the players stats and the window */
576 op->update_stats (); 577 op->update_stats ();
577 578
578 op->statusmsg (format ( 579 op->statusmsg (format (
646 647
647 sprintf (buf, "%s's %s", &op->name, &weapon->name); 648 sprintf (buf, "%s's %s", &op->name, &weapon->name);
648 weapon->name = weapon->name_pl = buf; 649 weapon->name = weapon->name_pl = buf;
649 weapon->nrof = 0; /* prevents preparing n weapons in the same 650 weapon->nrof = 0; /* prevents preparing n weapons in the same
650 slot at once! */ 651 slot at once! */
651 decrease_ob (improver); 652 improver->decrease ();
652 weapon->last_eat = 0; 653 weapon->last_eat = 0;
653 return 1; 654 return 1;
654} 655}
655 656
656 657
704 weapon->weight += 5000; /* 5 KG's */ 705 weapon->weight += 5000; /* 5 KG's */
705 op->statusmsg (format ("Damage has been increased by 5 to %d.", weapon->stats.dam)); 706 op->statusmsg (format ("Damage has been increased by 5 to %d.", weapon->stats.dam));
706 weapon->last_eat++; 707 weapon->last_eat++;
707 708
708 weapon->item_power++; 709 weapon->item_power++;
709 decrease_ob (improver); 710 improver->decrease ();
710 return 1; 711 return 1;
711 } 712 }
712 713
713 if (improver->stats.sp == IMPROVE_WEIGHT) 714 if (improver->stats.sp == IMPROVE_WEIGHT)
714 { 715 {
718 weapon->weight = 1; 719 weapon->weight = 1;
719 720
720 op->statusmsg (format ("Weapon weight reduced to %6.1fkg.", (float) weapon->weight / 1000.0)); 721 op->statusmsg (format ("Weapon weight reduced to %6.1fkg.", (float) weapon->weight / 1000.0));
721 weapon->last_eat++; 722 weapon->last_eat++;
722 weapon->item_power++; 723 weapon->item_power++;
723 decrease_ob (improver); 724 improver->decrease ();
724 return 1; 725 return 1;
725 } 726 }
726 if (improver->stats.sp == IMPROVE_ENCHANT) 727 if (improver->stats.sp == IMPROVE_ENCHANT)
727 { 728 {
728 weapon->magic++; 729 weapon->magic++;
729 weapon->last_eat++; 730 weapon->last_eat++;
730 op->statusmsg (format ("Weapon magic increased to %d.", weapon->magic)); 731 op->statusmsg (format ("Weapon magic increased to %d.", weapon->magic));
731 decrease_ob (improver); 732 improver->decrease ();
732 weapon->item_power++; 733 weapon->item_power++;
733 return 1; 734 return 1;
734 } 735 }
735 736
736 sacrifice_needed = weapon->stats.Str + weapon->stats.Int + weapon->stats.Dex + 737 sacrifice_needed = weapon->stats.Str + weapon->stats.Int + weapon->stats.Dex +
851 } 852 }
852 853
853 /* Split objects if needed. Can't insert tmp until the 854 /* Split objects if needed. Can't insert tmp until the
854 * end of this function - otherwise it will just re-merge. 855 * end of this function - otherwise it will just re-merge.
855 */ 856 */
856 if (armour->nrof > 1) 857 tmp = armour->nrof > 1 ? armour->split (armour->nrof - 1) : 0;
857 tmp = get_split_ob (armour, armour->nrof - 1);
858 else
859 tmp = NULL;
860 858
861 armour->magic++; 859 armour->magic++;
862 860
863 if (!settings.armor_speed_linear) 861 if (!settings.armor_speed_linear)
864 { 862 {
905 esrv_send_item (op, armour); 903 esrv_send_item (op, armour);
906 if (QUERY_FLAG (armour, FLAG_APPLIED)) 904 if (QUERY_FLAG (armour, FLAG_APPLIED))
907 op->update_stats (); 905 op->update_stats ();
908 } 906 }
909 907
910 decrease_ob (improver); 908 improver->decrease ();
911 909
912 if (tmp) 910 if (tmp)
913 { 911 {
914 insert_ob_in_ob (tmp, op); 912 insert_ob_in_ob (tmp, op);
915 esrv_send_item (op, tmp); 913 esrv_send_item (op, tmp);
955 953
956 converter->play_sound (sound_find ("shop_buy")); 954 converter->play_sound (sound_find ("shop_buy"));
957 955
958 sint64 cost = (nr * need + item->value - 1) / item->value; 956 sint64 cost = (nr * need + item->value - 1) / item->value;
959 957
960 decrease_ob_nr (item, cost); 958 item->decrease (cost);
961 959
962 price_in = cost * item->value; 960 price_in = cost * item->value;
963 } 961 }
964 else 962 else
965 { 963 {
971 converter->play_sound (sound_find ("convert_item")); 969 converter->play_sound (sound_find ("convert_item"));
972 970
973 if (need) 971 if (need)
974 { 972 {
975 nr = sint64 (item->nrof) / need; 973 nr = sint64 (item->nrof) / need;
976 decrease_ob_nr (item, nr * need); 974 item->decrease (nr * need);
977 price_in = nr * need * item->value; 975 price_in = nr * need * item->value;
978 } 976 }
979 else 977 else
980 { 978 {
981 price_in = item->value; 979 price_in = item->value;
1448 1446
1449 if (!trap->value) 1447 if (!trap->value)
1450 { 1448 {
1451 int tot; 1449 int tot;
1452 1450
1453 for (ab = trap->above, tot = 0; ab != NULL; ab = ab->above) 1451 for (ab = trap->above, tot = 0; ab; ab = ab->above)
1454 if ((ab->move_type && trap->move_on) || ab->move_type == 0) 1452 if ((ab->move_type && trap->move_on) || ab->move_type == 0)
1455 tot += (ab->nrof ? ab->nrof : 1) * ab->weight + ab->carrying; 1453 tot += ab->head_ ()->total_weight ();
1456 1454
1457 if (!(trap->value = (tot > trap->weight) ? 1 : 0)) 1455 if (!(trap->value = (tot > trap->weight) ? 1 : 0))
1458 goto leave; 1456 goto leave;
1459 1457
1460 SET_ANIMATION (trap, trap->value); 1458 SET_ANIMATION (trap, trap->value);
1664 op->play_sound (sound_find ("generic_fail")); 1662 op->play_sound (sound_find ("generic_fail"));
1665 op->failmsg (format ("You already possess the knowledge held within the %s.", query_name (tmp))); 1663 op->failmsg (format ("You already possess the knowledge held within the %s.", query_name (tmp)));
1666 break; 1664 break;
1667 1665
1668 case 1: 1666 case 1:
1669 decrease_ob (tmp); 1667 tmp->decrease ();
1670 op->play_sound (sound_find ("skill_learn")); 1668 op->play_sound (sound_find ("skill_learn"));
1671 op->statusmsg (format ("You succeed in learning %s", &tmp->skill)); 1669 op->statusmsg (format ("You succeed in learning %s", &tmp->skill));
1672 break; 1670 break;
1673 1671
1674 default: 1672 default:
1675 decrease_ob (tmp); 1673 tmp->decrease ();
1676 op->play_sound (sound_find ("generic_fail")); 1674 op->play_sound (sound_find ("generic_fail"));
1677 op->failmsg (format ("You fail to learn the knowledge of the %s.\n", query_name (tmp))); 1675 op->failmsg (format ("You fail to learn the knowledge of the %s.\n", query_name (tmp)));
1678 break; 1676 break;
1679 } 1677 }
1680} 1678}
1871 { 1869 {
1872 op->contr->play_sound (sound_find ("fumble_spell")); 1870 op->contr->play_sound (sound_find ("fumble_spell"));
1873 op->failmsg ("You fail to learn the spell. H<Wis (priests) or Int (wizards) governs the chance of learning a prayer or spell.>\n"); 1871 op->failmsg ("You fail to learn the spell. H<Wis (priests) or Int (wizards) governs the chance of learning a prayer or spell.>\n");
1874 } 1872 }
1875 1873
1876 decrease_ob (tmp); 1874 tmp->decrease ();
1877} 1875}
1878 1876
1879/** 1877/**
1880 * Handles applying a spell scroll. 1878 * Handles applying a spell scroll.
1881 */ 1879 */
1920 identify (tmp); 1918 identify (tmp);
1921 1919
1922 op->statusmsg (format ("The scroll of %s turns to dust.", &tmp->inv->name)); 1920 op->statusmsg (format ("The scroll of %s turns to dust.", &tmp->inv->name));
1923 1921
1924 cast_spell (op, tmp, dir, tmp->inv, NULL); 1922 cast_spell (op, tmp, dir, tmp->inv, NULL);
1925 decrease_ob (tmp); 1923 tmp->decrease ();
1926} 1924}
1927 1925
1928/** 1926/**
1929 * Applies a treasure object - by default, chest. op 1927 * Applies a treasure object - by default, chest. op
1930 * is the person doing the applying, tmp is the treasure 1928 * is the person doing the applying, tmp is the treasure
1942 object *treas = tmp->inv; 1940 object *treas = tmp->inv;
1943 1941
1944 if (!treas) 1942 if (!treas)
1945 { 1943 {
1946 op->statusmsg ("The chest was empty."); 1944 op->statusmsg ("The chest was empty.");
1947 decrease_ob (tmp); 1945 tmp->decrease ();
1948 return; 1946 return;
1949 } 1947 }
1950 1948
1951 while (tmp->inv) 1949 while (tmp->inv)
1952 { 1950 {
1968 if (op->destroyed () || tmp->destroyed ()) 1966 if (op->destroyed () || tmp->destroyed ())
1969 break; 1967 break;
1970 } 1968 }
1971 1969
1972 if (!tmp->destroyed () && !tmp->inv) 1970 if (!tmp->destroyed () && !tmp->inv)
1973 decrease_ob (tmp); 1971 tmp->decrease ();
1974} 1972}
1975 1973
1976/** 1974/**
1977 * op eats food. 1975 * op eats food.
1978 * If player, takes care of messages and dragon special food. 1976 * If player, takes care of messages and dragon special food.
2044 eat_special_food (op, tmp); 2042 eat_special_food (op, tmp);
2045 } 2043 }
2046 } 2044 }
2047 2045
2048 handle_apply_yield (tmp); 2046 handle_apply_yield (tmp);
2049 decrease_ob (tmp); 2047 tmp->decrease ();
2050} 2048}
2051 2049
2052/** 2050/**
2053 * A dragon is eating some flesh. If the flesh contains resistances, 2051 * A dragon is eating some flesh. If the flesh contains resistances,
2054 * there is a chance for the dragon's skin to get improved. 2052 * there is a chance for the dragon's skin to get improved.
2260 hit_player (op, tmp->stats.hp, tmp, AT_POISON, 1); 2258 hit_player (op, tmp->stats.hp, tmp, AT_POISON, 1);
2261 } 2259 }
2262 2260
2263 op->stats.food -= op->stats.food / 4; 2261 op->stats.food -= op->stats.food / 4;
2264 handle_apply_yield (tmp); 2262 handle_apply_yield (tmp);
2265 decrease_ob (tmp); 2263 tmp->decrease ();
2266} 2264}
2267 2265
2268/** 2266/**
2269 * This function return true if the exit is not a 2 ways one or it is 2 ways, valid exit. 2267 * This function return true if the exit is not a 2 ways one or it is 2 ways, valid exit.
2270 * A valid 2 way exit means: 2268 * A valid 2 way exit means:
2756 tmp2->stats.food = op->stats.food; 2754 tmp2->stats.food = op->stats.food;
2757 CLEAR_FLAG (tmp2, FLAG_APPLIED); 2755 CLEAR_FLAG (tmp2, FLAG_APPLIED);
2758 2756
2759 if (QUERY_FLAG (op, FLAG_INV_LOCKED)) 2757 if (QUERY_FLAG (op, FLAG_INV_LOCKED))
2760 SET_FLAG (tmp2, FLAG_INV_LOCKED); 2758 SET_FLAG (tmp2, FLAG_INV_LOCKED);
2761
2762 if (who->contr)
2763 esrv_del_item (who->contr, op->count);
2764 2759
2765 op->destroy (); 2760 op->destroy ();
2766 insert_ob_in_ob (tmp2, who); 2761 insert_ob_in_ob (tmp2, who);
2767 who->update_stats (); 2762 who->update_stats ();
2768 2763
3220 3215
3221 /* Ok. We are now at the state where we can apply the new object. 3216 /* Ok. We are now at the state where we can apply the new object.
3222 * Note that we don't have the checks for can_use_... 3217 * Note that we don't have the checks for can_use_...
3223 * below - that is already taken care of by can_apply_object. 3218 * below - that is already taken care of by can_apply_object.
3224 */ 3219 */
3225 if (op->nrof > 1) 3220 tmp = op->nrof > 1 ? op->split (op->nrof - 1) : 0;
3226 tmp = get_split_ob (op, op->nrof - 1);
3227 else
3228 tmp = 0;
3229 3221
3230 if (INVOKE_OBJECT (BE_READY, op, ARG_OBJECT (who)) || INVOKE_OBJECT (READY, who, ARG_OBJECT (op))) 3222 if (INVOKE_OBJECT (BE_READY, op, ARG_OBJECT (who)) || INVOKE_OBJECT (READY, who, ARG_OBJECT (op)))
3231 return RESULT_INT (0); 3223 return RESULT_INT (0);
3232 3224
3233 switch (op->type) 3225 switch (op->type)
3311 SET_FLAG (tmp2, FLAG_INV_LOCKED); 3303 SET_FLAG (tmp2, FLAG_INV_LOCKED);
3312 3304
3313 insert_ob_in_ob (tmp2, who); 3305 insert_ob_in_ob (tmp2, who);
3314 3306
3315 /* Remove the old lantern */ 3307 /* Remove the old lantern */
3316 if (who->type == PLAYER)
3317 esrv_del_item (who->contr, op->count);
3318
3319 op->destroy (); 3308 op->destroy ();
3320 3309
3321 /* insert the portion that was split off */ 3310 /* insert the portion that was split off */
3322 if (tmp) 3311 if (tmp)
3323 { 3312 {
4101 pl->statusmsg (format ("You %s the %s.", &transformer->slaying, query_base_name (marked, 0))); 4090 pl->statusmsg (format ("You %s the %s.", &transformer->slaying, query_base_name (marked, 0)));
4102 4091
4103 insert_ob_in_ob (new_item, pl); 4092 insert_ob_in_ob (new_item, pl);
4104 esrv_send_inventory (pl, pl); 4093 esrv_send_inventory (pl, pl);
4105 /* Eat up one item */ 4094 /* Eat up one item */
4106 decrease_ob_nr (marked, 1); 4095 marked->decrease ();
4107 4096
4108 /* Eat one transformer if needed */ 4097 /* Eat one transformer if needed */
4109 if (transformer->stats.food) 4098 if (transformer->stats.food)
4110 if (--transformer->stats.food == 0) 4099 if (--transformer->stats.food == 0)
4111 decrease_ob_nr (transformer, 1); 4100 transformer->decrease ();
4112} 4101}
4113 4102

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines