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.158 by root, Wed May 7 19:19:09 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
160 * matching item. 160 * matching item.
161 **/ 161 **/
162void 162void
163handle_apply_yield (object *tmp) 163handle_apply_yield (object *tmp)
164{ 164{
165 const char *yield; 165 if (shstr yield = tmp->kv (shstr_on_use_yield))
166 166 archetype::get (yield)->insert_at (tmp, tmp, INS_BELOW_ORIGINATOR);
167 yield = get_ob_key_value (tmp, "on_use_yield");
168 if (yield != NULL)
169 {
170 object *drop = get_archetype (yield);
171
172 if (tmp->env)
173 {
174 drop = insert_ob_in_ob (drop, tmp->env);
175 if (tmp->env->type == PLAYER)
176 esrv_send_item (tmp->env, drop);
177 }
178 else
179 {
180 drop->x = tmp->x;
181 drop->y = tmp->y;
182 insert_ob_in_map (drop, tmp->map, tmp, INS_BELOW_ORIGINATOR);
183 }
184 }
185} 167}
186 168
187/** 169/**
188 * Handles applying a potion. 170 * Handles applying a potion.
189 */ 171 */
217 199
218 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED)) 200 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED))
219 { 201 {
220 op->drain_stat (); 202 op->drain_stat ();
221 op->update_stats (); 203 op->update_stats ();
222 decrease_ob (tmp); 204 tmp->decrease ();
223 return 1; 205 return 1;
224 } 206 }
225 207
226 if (!(at = archetype::find (ARCH_DEPLETION))) 208 if (!(at = archetype::find (ARCH_DEPLETION)))
227 { 209 {
228 LOG (llevError, "Could not find archetype depletion\n"); 210 LOG (llevError, "Could not find archetype depletion\n");
229 return 0; 211 return 0;
230 } 212 }
213
231 depl = present_arch_in_ob (at, op); 214 depl = present_arch_in_ob (at, op);
232 215
233 if (depl) 216 if (depl)
234 { 217 {
235 for (i = 0; i < NUM_STATS; i++) 218 for (i = 0; i < NUM_STATS; i++)
240 op->update_stats (); 223 op->update_stats ();
241 } 224 }
242 else 225 else
243 op->statusmsg ("Your potion had no effect."); 226 op->statusmsg ("Your potion had no effect.");
244 227
245 decrease_ob (tmp); 228 tmp->decrease ();
246 return 1; 229 return 1;
247 } 230 }
248 231
249 /* improvement potion - only for players */ 232 /* improvement potion - only for players */
250 if (op->type == PLAYER && (tmp->attacktype & AT_GODPOWER)) 233 if (op->type == PLAYER && (tmp->attacktype & AT_GODPOWER))
318 } 301 }
319 else 302 else
320 op->statusmsg ("You are fortunate that you are so pathetic.", NDI_DK_ORANGE); 303 op->statusmsg ("You are fortunate that you are so pathetic.", NDI_DK_ORANGE);
321 } 304 }
322 305
323 decrease_ob (tmp); 306 tmp->decrease ();
324 return 1; 307 return 1;
325 } 308 }
326 309
327 310
328 /* A potion that casts a spell. Healing, restore spellpoint (power potion) 311 /* A potion that casts a spell. Healing, restore spellpoint (power potion)
347 insert_ob_in_map (fball, op->map, NULL, 0); 330 insert_ob_in_map (fball, op->map, NULL, 0);
348 } 331 }
349 else 332 else
350 cast_spell (op, tmp, op->facing, tmp->inv, NULL); 333 cast_spell (op, tmp, op->facing, tmp->inv, NULL);
351 334
352 decrease_ob (tmp); 335 tmp->decrease ();
353 336
354 /* if youre dead, no point in doing this... */ 337 /* if youre dead, no point in doing this... */
355 if (!QUERY_FLAG (op, FLAG_REMOVED)) 338 if (!QUERY_FLAG (op, FLAG_REMOVED))
356 op->update_stats (); 339 op->update_stats ();
357 340
388 force->speed_left = -1; 371 force->speed_left = -1;
389 force = insert_ob_in_ob (force, op); 372 force = insert_ob_in_ob (force, op);
390 CLEAR_FLAG (tmp, FLAG_APPLIED); 373 CLEAR_FLAG (tmp, FLAG_APPLIED);
391 SET_FLAG (force, FLAG_APPLIED); 374 SET_FLAG (force, FLAG_APPLIED);
392 change_abil (op, force); 375 change_abil (op, force);
393 decrease_ob (tmp); 376 tmp->decrease ();
394 return 1; 377 return 1;
395 } 378 }
396 379
397 /* Only thing left are the stat potions */ 380 /* Only thing left are the stat potions */
398 if (op->type == PLAYER) 381 if (op->type == PLAYER)
411 * stat will not be raised by them. fix_player just clears 394 * stat will not be raised by them. fix_player just clears
412 * up all the stats. 395 * up all the stats.
413 */ 396 */
414 CLEAR_FLAG (tmp, FLAG_APPLIED); 397 CLEAR_FLAG (tmp, FLAG_APPLIED);
415 op->update_stats (); 398 op->update_stats ();
416 decrease_ob (tmp); 399 tmp->decrease ();
417 return 1; 400 return 1;
418} 401}
419 402
420/**************************************************************************** 403/****************************************************************************
421 * Weapon improvement code follows 404 * Weapon improvement code follows
468 { 451 {
469 if (strcmp (op->arch->archname, item) == 0) 452 if (strcmp (op->arch->archname, item) == 0)
470 { 453 {
471 if (op->nrof >= nrof) 454 if (op->nrof >= nrof)
472 { 455 {
473 decrease_ob_nr (op, nrof); 456 op->decrease (nrof);
474 return; 457 return;
475 } 458 }
476 else 459 else
477 { 460 {
478 decrease_ob_nr (op, op->nrof); 461 op->decrease (nrof);
479 nrof -= op->nrof; 462 nrof -= op->nrof;
480 } 463 }
481 464
482 op = prev; 465 op = prev;
483 } 466 }
568static int 551static int
569improve_weapon_stat (object *op, object *improver, object *weapon, sint8 &stat, int sacrifice_count, const char *statname) 552improve_weapon_stat (object *op, object *improver, object *weapon, sint8 &stat, int sacrifice_count, const char *statname)
570{ 553{
571 stat += sacrifice_count; 554 stat += sacrifice_count;
572 weapon->last_eat++; 555 weapon->last_eat++;
573 decrease_ob (improver); 556 improver->decrease ();
574 557
575 /* So it updates the players stats and the window */ 558 /* So it updates the players stats and the window */
576 op->update_stats (); 559 op->update_stats ();
577 560
578 op->statusmsg (format ( 561 op->statusmsg (format (
646 629
647 sprintf (buf, "%s's %s", &op->name, &weapon->name); 630 sprintf (buf, "%s's %s", &op->name, &weapon->name);
648 weapon->name = weapon->name_pl = buf; 631 weapon->name = weapon->name_pl = buf;
649 weapon->nrof = 0; /* prevents preparing n weapons in the same 632 weapon->nrof = 0; /* prevents preparing n weapons in the same
650 slot at once! */ 633 slot at once! */
651 decrease_ob (improver); 634 improver->decrease ();
652 weapon->last_eat = 0; 635 weapon->last_eat = 0;
653 return 1; 636 return 1;
654} 637}
655
656 638
657/** 639/**
658 * Does the dirty job for 'improve weapon' scroll, prepare or add something. 640 * Does the dirty job for 'improve weapon' scroll, prepare or add something.
659 * This is the new improve weapon code. 641 * This is the new improve weapon code.
660 * Returns 0 if it was not able to work for some reason. 642 * Returns 0 if it was not able to work for some reason.
704 weapon->weight += 5000; /* 5 KG's */ 686 weapon->weight += 5000; /* 5 KG's */
705 op->statusmsg (format ("Damage has been increased by 5 to %d.", weapon->stats.dam)); 687 op->statusmsg (format ("Damage has been increased by 5 to %d.", weapon->stats.dam));
706 weapon->last_eat++; 688 weapon->last_eat++;
707 689
708 weapon->item_power++; 690 weapon->item_power++;
709 decrease_ob (improver); 691 improver->decrease ();
710 return 1; 692 return 1;
711 } 693 }
712 694
713 if (improver->stats.sp == IMPROVE_WEIGHT) 695 if (improver->stats.sp == IMPROVE_WEIGHT)
714 { 696 {
718 weapon->weight = 1; 700 weapon->weight = 1;
719 701
720 op->statusmsg (format ("Weapon weight reduced to %6.1fkg.", (float) weapon->weight / 1000.0)); 702 op->statusmsg (format ("Weapon weight reduced to %6.1fkg.", (float) weapon->weight / 1000.0));
721 weapon->last_eat++; 703 weapon->last_eat++;
722 weapon->item_power++; 704 weapon->item_power++;
723 decrease_ob (improver); 705 improver->decrease ();
724 return 1; 706 return 1;
725 } 707 }
726 if (improver->stats.sp == IMPROVE_ENCHANT) 708 if (improver->stats.sp == IMPROVE_ENCHANT)
727 { 709 {
728 weapon->magic++; 710 weapon->magic++;
729 weapon->last_eat++; 711 weapon->last_eat++;
730 op->statusmsg (format ("Weapon magic increased to %d.", weapon->magic)); 712 op->statusmsg (format ("Weapon magic increased to %d.", weapon->magic));
731 decrease_ob (improver); 713 improver->decrease ();
732 weapon->item_power++; 714 weapon->item_power++;
733 return 1; 715 return 1;
734 } 716 }
735 717
736 sacrifice_needed = weapon->stats.Str + weapon->stats.Int + weapon->stats.Dex + 718 sacrifice_needed = weapon->stats.Str + weapon->stats.Int + weapon->stats.Dex +
851 } 833 }
852 834
853 /* Split objects if needed. Can't insert tmp until the 835 /* Split objects if needed. Can't insert tmp until the
854 * end of this function - otherwise it will just re-merge. 836 * end of this function - otherwise it will just re-merge.
855 */ 837 */
856 if (armour->nrof > 1) 838 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 839
861 armour->magic++; 840 armour->magic++;
862 841
863 if (!settings.armor_speed_linear) 842 if (!settings.armor_speed_linear)
864 { 843 {
901 armour->item_power = get_power_from_ench (armour->arch->item_power + armour->magic); 880 armour->item_power = get_power_from_ench (armour->arch->item_power + armour->magic);
902 881
903 if (op->type == PLAYER) 882 if (op->type == PLAYER)
904 { 883 {
905 esrv_send_item (op, armour); 884 esrv_send_item (op, armour);
885
906 if (QUERY_FLAG (armour, FLAG_APPLIED)) 886 if (QUERY_FLAG (armour, FLAG_APPLIED))
907 op->update_stats (); 887 op->update_stats ();
908 } 888 }
909 889
910 decrease_ob (improver); 890 improver->decrease ();
911 891
912 if (tmp) 892 if (tmp)
913 { 893 op->insert (tmp);
914 insert_ob_in_ob (tmp, op);
915 esrv_send_item (op, tmp);
916 }
917 894
918 return 1; 895 return 1;
919} 896}
920 897
921/* 898/*
955 932
956 converter->play_sound (sound_find ("shop_buy")); 933 converter->play_sound (sound_find ("shop_buy"));
957 934
958 sint64 cost = (nr * need + item->value - 1) / item->value; 935 sint64 cost = (nr * need + item->value - 1) / item->value;
959 936
960 decrease_ob_nr (item, cost); 937 item->decrease (cost);
961 938
962 price_in = cost * item->value; 939 price_in = cost * item->value;
963 } 940 }
964 else 941 else
965 { 942 {
971 converter->play_sound (sound_find ("convert_item")); 948 converter->play_sound (sound_find ("convert_item"));
972 949
973 if (need) 950 if (need)
974 { 951 {
975 nr = sint64 (item->nrof) / need; 952 nr = sint64 (item->nrof) / need;
976 decrease_ob_nr (item, nr * need); 953 item->decrease (nr * need);
977 price_in = nr * need * item->value; 954 price_in = nr * need * item->value;
978 } 955 }
979 else 956 else
980 { 957 {
981 price_in = item->value; 958 price_in = item->value;
993 ob_to_copy = converter->inv; 970 ob_to_copy = converter->inv;
994 for (ob = converter->inv->below, i = 1; ob; ob = ob->below, i++) 971 for (ob = converter->inv->below, i = 1; ob; ob = ob->below, i++)
995 if (rndm (0, i) == 0) 972 if (rndm (0, i) == 0)
996 ob_to_copy = ob; 973 ob_to_copy = ob;
997 974
998 item = object_create_clone (ob_to_copy); 975 item = ob_to_copy->deep_clone ();
999 CLEAR_FLAG (item, FLAG_IS_A_TEMPLATE); 976 CLEAR_FLAG (item, FLAG_IS_A_TEMPLATE);
1000 unflag_inv (item, FLAG_IS_A_TEMPLATE); 977 unflag_inv (item, FLAG_IS_A_TEMPLATE);
1001 } 978 }
1002 else 979 else
1003 { 980 {
1448 1425
1449 if (!trap->value) 1426 if (!trap->value)
1450 { 1427 {
1451 int tot; 1428 int tot;
1452 1429
1453 for (ab = trap->above, tot = 0; ab != NULL; ab = ab->above) 1430 for (ab = trap->above, tot = 0; ab; ab = ab->above)
1454 if ((ab->move_type && trap->move_on) || ab->move_type == 0) 1431 if ((ab->move_type && trap->move_on) || ab->move_type == 0)
1455 tot += (ab->nrof ? ab->nrof : 1) * ab->weight + ab->carrying; 1432 tot += ab->head_ ()->total_weight ();
1456 1433
1457 if (!(trap->value = (tot > trap->weight) ? 1 : 0)) 1434 if (!(trap->value = (tot > trap->weight) ? 1 : 0))
1458 goto leave; 1435 goto leave;
1459 1436
1460 SET_ANIMATION (trap, trap->value); 1437 SET_ANIMATION (trap, trap->value);
1485 1462
1486 case CONVERTER: 1463 case CONVERTER:
1487 if (convert_item (victim, trap) < 0) 1464 if (convert_item (victim, trap) < 0)
1488 { 1465 {
1489 originator->failmsg (format ("The %s seems to be broken!", query_name (trap))); 1466 originator->failmsg (format ("The %s seems to be broken!", query_name (trap)));
1490 get_archetype ("burnout")->insert_at (trap, trap); 1467 archetype::get (shstr_burnout)->insert_at (trap, trap);
1491 } 1468 }
1492 1469
1493 goto leave; 1470 goto leave;
1494 1471
1495 case TRIGGER_BUTTON: 1472 case TRIGGER_BUTTON:
1637 if (!QUERY_FLAG (tmp, FLAG_IDENTIFIED)) 1614 if (!QUERY_FLAG (tmp, FLAG_IDENTIFIED))
1638 { 1615 {
1639 /*exp_gain *= 2; because they just identified it too */ 1616 /*exp_gain *= 2; because they just identified it too */
1640 SET_FLAG (tmp, FLAG_IDENTIFIED); 1617 SET_FLAG (tmp, FLAG_IDENTIFIED);
1641 1618
1642 /* If in a container, update how it looks */ 1619 if (object *pl = tmp->visible_to ())
1643 if (tmp->env)
1644 esrv_update_item (UPD_FLAGS | UPD_NAME, op, tmp); 1620 esrv_update_item (UPD_FLAGS | UPD_NAME, pl, tmp);
1645 else
1646 op->contr->ns->floorbox_update ();
1647 } 1621 }
1648 1622
1649 change_exp (op, exp_gain, skill_ob->skill, 0); 1623 change_exp (op, exp_gain, skill_ob->skill, 0);
1650 SET_FLAG (tmp, FLAG_NO_SKILL_IDENT); /* so no more xp gained from this book */ 1624 SET_FLAG (tmp, FLAG_NO_SKILL_IDENT); /* so no more xp gained from this book */
1651 } 1625 }
1664 op->play_sound (sound_find ("generic_fail")); 1638 op->play_sound (sound_find ("generic_fail"));
1665 op->failmsg (format ("You already possess the knowledge held within the %s.", query_name (tmp))); 1639 op->failmsg (format ("You already possess the knowledge held within the %s.", query_name (tmp)));
1666 break; 1640 break;
1667 1641
1668 case 1: 1642 case 1:
1669 decrease_ob (tmp); 1643 tmp->decrease ();
1670 op->play_sound (sound_find ("skill_learn")); 1644 op->play_sound (sound_find ("skill_learn"));
1671 op->statusmsg (format ("You succeed in learning %s", &tmp->skill)); 1645 op->statusmsg (format ("You succeed in learning %s", &tmp->skill));
1672 break; 1646 break;
1673 1647
1674 default: 1648 default:
1675 decrease_ob (tmp); 1649 tmp->decrease ();
1676 op->play_sound (sound_find ("generic_fail")); 1650 op->play_sound (sound_find ("generic_fail"));
1677 op->failmsg (format ("You fail to learn the knowledge of the %s.\n", query_name (tmp))); 1651 op->failmsg (format ("You fail to learn the knowledge of the %s.\n", query_name (tmp)));
1678 break; 1652 break;
1679 } 1653 }
1680} 1654}
1801 } 1775 }
1802 1776
1803 op->statusmsg (format ("The spellbook contains the %s level spell %s.", get_levelnumber (spell->level), &spell->name)); 1777 op->statusmsg (format ("The spellbook contains the %s level spell %s.", get_levelnumber (spell->level), &spell->name));
1804 1778
1805 if (!QUERY_FLAG (tmp, FLAG_IDENTIFIED)) 1779 if (!QUERY_FLAG (tmp, FLAG_IDENTIFIED))
1806 {
1807 identify (tmp); 1780 identify (tmp);
1808
1809 if (tmp->env)
1810 esrv_update_item (UPD_FLAGS | UPD_NAME, op, tmp);
1811 else
1812 op->contr->ns->floorbox_update ();
1813 }
1814 1781
1815 /* I removed the check for special_prayer_mark here - it didn't make 1782 /* I removed the check for special_prayer_mark here - it didn't make
1816 * a lot of sense - special prayers are not found in spellbooks, and 1783 * a lot of sense - special prayers are not found in spellbooks, and
1817 * if the player doesn't know the spell, doesn't make a lot of sense that 1784 * if the player doesn't know the spell, doesn't make a lot of sense that
1818 * they would have a special prayer mark. 1785 * they would have a special prayer mark.
1871 { 1838 {
1872 op->contr->play_sound (sound_find ("fumble_spell")); 1839 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"); 1840 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 } 1841 }
1875 1842
1876 decrease_ob (tmp); 1843 tmp->decrease ();
1877} 1844}
1878 1845
1879/** 1846/**
1880 * Handles applying a spell scroll. 1847 * Handles applying a spell scroll.
1881 */ 1848 */
1920 identify (tmp); 1887 identify (tmp);
1921 1888
1922 op->statusmsg (format ("The scroll of %s turns to dust.", &tmp->inv->name)); 1889 op->statusmsg (format ("The scroll of %s turns to dust.", &tmp->inv->name));
1923 1890
1924 cast_spell (op, tmp, dir, tmp->inv, NULL); 1891 cast_spell (op, tmp, dir, tmp->inv, NULL);
1925 decrease_ob (tmp); 1892 tmp->decrease ();
1926} 1893}
1927 1894
1928/** 1895/**
1929 * Applies a treasure object - by default, chest. op 1896 * Applies a treasure object - by default, chest. op
1930 * is the person doing the applying, tmp is the treasure 1897 * is the person doing the applying, tmp is the treasure
1942 object *treas = tmp->inv; 1909 object *treas = tmp->inv;
1943 1910
1944 if (!treas) 1911 if (!treas)
1945 { 1912 {
1946 op->statusmsg ("The chest was empty."); 1913 op->statusmsg ("The chest was empty.");
1947 decrease_ob (tmp); 1914 tmp->decrease ();
1948 return; 1915 return;
1949 } 1916 }
1950 1917
1951 while (tmp->inv) 1918 while (tmp->inv)
1952 { 1919 {
1968 if (op->destroyed () || tmp->destroyed ()) 1935 if (op->destroyed () || tmp->destroyed ())
1969 break; 1936 break;
1970 } 1937 }
1971 1938
1972 if (!tmp->destroyed () && !tmp->inv) 1939 if (!tmp->destroyed () && !tmp->inv)
1973 decrease_ob (tmp); 1940 tmp->decrease ();
1974} 1941}
1975 1942
1976/** 1943/**
1977 * op eats food. 1944 * op eats food.
1978 * If player, takes care of messages and dragon special food. 1945 * If player, takes care of messages and dragon special food.
2044 eat_special_food (op, tmp); 2011 eat_special_food (op, tmp);
2045 } 2012 }
2046 } 2013 }
2047 2014
2048 handle_apply_yield (tmp); 2015 handle_apply_yield (tmp);
2049 decrease_ob (tmp); 2016 tmp->decrease ();
2050} 2017}
2051 2018
2052/** 2019/**
2053 * A dragon is eating some flesh. If the flesh contains resistances, 2020 * A dragon is eating some flesh. If the flesh contains resistances,
2054 * there is a chance for the dragon's skin to get improved. 2021 * there is a chance for the dragon's skin to get improved.
2242 2209
2243 op->statusmsg ("Applying armour enchantment."); 2210 op->statusmsg ("Applying armour enchantment.");
2244 improve_armour (op, tmp, armor); 2211 improve_armour (op, tmp, armor);
2245} 2212}
2246 2213
2247extern void 2214void
2248apply_poison (object *op, object *tmp) 2215apply_poison (object *op, object *tmp)
2249{ 2216{
2217 // need to do it now when it is still on the map
2218 handle_apply_yield (tmp);
2219
2220 object *poison = tmp->split (1);
2221
2250 if (op->type == PLAYER) 2222 if (op->type == PLAYER)
2251 { 2223 {
2252 op->contr->play_sound (sound_find ("drink_poison")); 2224 op->contr->play_sound (sound_find ("drink_poison"));
2253 op->failmsg ("Yech! That tasted poisonous!"); 2225 op->failmsg ("Yech! That tasted poisonous!");
2254 strcpy (op->contr->killer, "poisonous booze"); 2226 op->contr->killer = poison;
2255 } 2227 }
2256 2228
2257 if (tmp->stats.hp > 0) 2229 if (poison->stats.hp > 0)
2258 { 2230 {
2259 LOG (llevDebug, "Trying to poison player/monster for %d hp\n", tmp->stats.hp); 2231 LOG (llevDebug, "Trying to poison player/monster for %d hp\n", poison->stats.hp);
2260 hit_player (op, tmp->stats.hp, tmp, AT_POISON, 1); 2232 hit_player (op, poison->stats.hp, tmp, AT_POISON, 1);
2261 } 2233 }
2262 2234
2263 op->stats.food -= op->stats.food / 4; 2235 op->stats.food -= op->stats.food / 4;
2264 handle_apply_yield (tmp); 2236 poison->destroy ();
2265 decrease_ob (tmp);
2266} 2237}
2267 2238
2268/** 2239/**
2269 * This function return true if the exit is not a 2 ways one or it is 2 ways, valid exit. 2240 * 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: 2241 * A valid 2 way exit means:
2372 * them in this function - they are passed to apply_special 2343 * them in this function - they are passed to apply_special
2373 */ 2344 */
2374int 2345int
2375manual_apply (object *op, object *tmp, int aflag) 2346manual_apply (object *op, object *tmp, int aflag)
2376{ 2347{
2377 if (tmp->head)
2378 tmp = tmp->head; 2348 tmp = tmp->head_ ();
2379 2349
2380 if (QUERY_FLAG (tmp, FLAG_UNPAID) && !QUERY_FLAG (tmp, FLAG_APPLIED)) 2350 if (QUERY_FLAG (tmp, FLAG_UNPAID) && !QUERY_FLAG (tmp, FLAG_APPLIED))
2381 { 2351 {
2382 if (op->type == PLAYER) 2352 if (op->type == PLAYER)
2383 { 2353 {
2591 default: 2561 default:
2592 return 0; 2562 return 0;
2593 } 2563 }
2594} 2564}
2595 2565
2596
2597/* quiet suppresses the "don't know how to apply" and "you must get it first" 2566/* quiet suppresses the "don't know how to apply" and "you must get it first"
2598 * messages as needed by player_apply_below(). But there can still be 2567 * messages as needed by player_apply_below(). But there can still be
2599 * "but you are floating high above the ground" messages. 2568 * "but you are floating high above the ground" messages.
2600 * 2569 *
2601 * Same return value as apply() function. 2570 * Same return value as apply() function.
2602 */ 2571 */
2603int 2572int
2604player_apply (object *pl, object *op, int aflag, int quiet) 2573player_apply (object *pl, object *op, int aflag, int quiet)
2605{ 2574{
2606 int tmp;
2607
2608 if (op->env && (pl->move_type & MOVE_FLYING)) 2575 if (!op->env && (pl->move_type & MOVE_FLYING))
2609 { 2576 {
2610 /* player is flying and applying object not in inventory */ 2577 /* player is flying and applying object not in inventory */
2611 if (!QUERY_FLAG (pl, FLAG_WIZ) && !(op->move_type & MOVE_FLYING)) 2578 if (!QUERY_FLAG (pl, FLAG_WIZ) && !(op->move_type & MOVE_FLYING))
2612 { 2579 {
2613 pl->failmsg ("But you are floating high above the ground! H<You have to stop levitating first, if you can.>"); 2580 pl->failmsg ("But you are floating high above the ground! "
2581 "H<You have to stop levitating first, if you can, either by using your levitation skill, "
2582 "or waiting till the levitation effect wears off.>");
2614 return 0; 2583 return 0;
2615 } 2584 }
2616 } 2585 }
2617 2586
2618 pl->contr->last_used = op; 2587 pl->contr->last_used = op;
2619 2588
2620 tmp = manual_apply (pl, op, aflag); 2589 int tmp = manual_apply (pl, op, aflag);
2590
2621 if (!quiet) 2591 if (!quiet)
2622 { 2592 {
2623 if (tmp == 0) 2593 if (tmp == 0)
2624 pl->statusmsg (format ("I don't know how to apply the %s.", query_name (op))); 2594 pl->statusmsg (format ("I don't know how to apply the %s.", query_name (op)));
2625 else if (tmp == 2) 2595 else if (tmp == 2)
2757 CLEAR_FLAG (tmp2, FLAG_APPLIED); 2727 CLEAR_FLAG (tmp2, FLAG_APPLIED);
2758 2728
2759 if (QUERY_FLAG (op, FLAG_INV_LOCKED)) 2729 if (QUERY_FLAG (op, FLAG_INV_LOCKED))
2760 SET_FLAG (tmp2, FLAG_INV_LOCKED); 2730 SET_FLAG (tmp2, FLAG_INV_LOCKED);
2761 2731
2732 op->destroy ();
2733 who->insert (tmp2);
2734 who->update_stats ();
2735
2762 if (who->contr) 2736 if (who->contr)
2763 esrv_del_item (who->contr, op->count);
2764
2765 op->destroy ();
2766 insert_ob_in_ob (tmp2, who);
2767 who->update_stats ();
2768
2769 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED))
2770 { 2737 {
2771 if (who->contr) 2738 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED))
2772 { 2739 {
2773 who->failmsg ("Oops, it feels deadly cold!"); 2740 who->failmsg ("Oops, it feels deadly cold!");
2774 SET_FLAG (tmp2, FLAG_KNOWN_CURSED); 2741 SET_FLAG (tmp2, FLAG_KNOWN_CURSED);
2775 } 2742 }
2776 } 2743 }
2777
2778 if (who->contr)
2779 esrv_send_item (who, tmp2);
2780 } 2744 }
2781 2745
2782 return 1; /* otherwise, an attempt to drop causes problems */ 2746 return 1; /* otherwise, an attempt to drop causes problems */
2783 2747
2784 case BOW: 2748 case BOW:
2815 default: 2779 default:
2816 who->statusmsg (format ("You unapply %s.", query_name (op))); 2780 who->statusmsg (format ("You unapply %s.", query_name (op)));
2817 break; 2781 break;
2818 } 2782 }
2819 2783
2784 if (aflags & AP_NO_MERGE || !merge_ob (op, 0))
2785 if (object *pl = op->visible_to ())
2786 esrv_send_item (pl, op);
2787
2820 who->update_stats (); 2788 who->update_stats ();
2821
2822 if (!(aflags & AP_NO_MERGE))
2823 {
2824 object *tmp = merge_ob (op, 0);
2825
2826 if (who->contr)
2827 {
2828 if (tmp)
2829 { /* it was merged */
2830 esrv_del_item (who->contr, op->count);
2831 op = tmp;
2832 }
2833
2834 esrv_send_item (who, op);
2835 }
2836 }
2837 2789
2838 return 0; 2790 return 0;
2839} 2791}
2840 2792
2841/** 2793/**
3220 3172
3221 /* Ok. We are now at the state where we can apply the new object. 3173 /* 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_... 3174 * Note that we don't have the checks for can_use_...
3223 * below - that is already taken care of by can_apply_object. 3175 * below - that is already taken care of by can_apply_object.
3224 */ 3176 */
3225 if (op->nrof > 1) 3177 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 3178
3230 if (INVOKE_OBJECT (BE_READY, op, ARG_OBJECT (who)) || INVOKE_OBJECT (READY, who, ARG_OBJECT (op))) 3179 if (INVOKE_OBJECT (BE_READY, op, ARG_OBJECT (who)) || INVOKE_OBJECT (READY, who, ARG_OBJECT (op)))
3231 return RESULT_INT (0); 3180 return RESULT_INT (0);
3232 3181
3233 switch (op->type) 3182 switch (op->type)
3234 { 3183 {
3235 case WEAPON: 3184 case WEAPON:
3236 if (!check_weapon_power (who, op->last_eat)) 3185 if (!check_weapon_power (who, op->last_eat))
3237 { 3186 {
3238 op->failmsg ("This weapon is too powerful for you to use. It would consume your soul!." LACK_ITEM_POWER); 3187 op->failmsg ("This weapon is too powerful for you to use. It would consume your soul!" LACK_ITEM_POWER);
3239 3188
3240 if (tmp) 3189 if (tmp)
3241 insert_ob_in_ob (tmp, who); 3190 insert_ob_in_ob (tmp, who);
3242 3191
3243 return 1; 3192 return 1;
3308 SET_FLAG (tmp2, FLAG_APPLIED); 3257 SET_FLAG (tmp2, FLAG_APPLIED);
3309 3258
3310 if (QUERY_FLAG (op, FLAG_INV_LOCKED)) 3259 if (QUERY_FLAG (op, FLAG_INV_LOCKED))
3311 SET_FLAG (tmp2, FLAG_INV_LOCKED); 3260 SET_FLAG (tmp2, FLAG_INV_LOCKED);
3312 3261
3313 insert_ob_in_ob (tmp2, who); 3262 who->insert (tmp2);
3314 3263
3315 /* Remove the old lantern */ 3264 /* Remove the old lantern */
3316 if (who->type == PLAYER)
3317 esrv_del_item (who->contr, op->count);
3318
3319 op->destroy (); 3265 op->destroy ();
3320 3266
3321 /* insert the portion that was split off */ 3267 /* insert the portion that was split off */
3322 if (tmp) 3268 if (tmp)
3323 { 3269 who->insert (tmp);
3324 insert_ob_in_ob (tmp, who);
3325 if (who->type == PLAYER)
3326 esrv_send_item (who, tmp);
3327 }
3328 3270
3329 who->update_stats (); 3271 who->update_stats ();
3330 3272
3331 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED)) 3273 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED))
3332 if (who->type == PLAYER) 3274 if (who->type == PLAYER)
3333 { 3275 {
3334 who->failmsg ("Oops, it feels deadly cold! H<Maybe it wasn't such a bright idea to apply this cursed/damned item.>"); 3276 who->failmsg ("Oops, it feels deadly cold! H<Maybe it wasn't such a bright idea to apply this cursed/damned item.>");
3335 SET_FLAG (tmp2, FLAG_KNOWN_CURSED); 3277 SET_FLAG (tmp2, FLAG_KNOWN_CURSED);
3336 } 3278 }
3337
3338 if (who->type == PLAYER)
3339 esrv_send_item (who, tmp2);
3340 3279
3341 return 0; 3280 return 0;
3342 3281
3343 case SKILL_TOOL: 3282 case SKILL_TOOL:
3344 // applying a skill tool also readies the skill 3283 // applying a skill tool also readies the skill
3504 } 3443 }
3505 3444
3506 SET_FLAG (op, FLAG_APPLIED); 3445 SET_FLAG (op, FLAG_APPLIED);
3507 3446
3508 if (tmp) 3447 if (tmp)
3509 tmp = insert_ob_in_ob (tmp, who); 3448 who->insert (tmp);
3510 3449
3511 who->update_stats (); 3450 who->update_stats ();
3512 3451
3513 /* We exclude spell casting objects. The fire code will set the 3452 /* We exclude spell casting objects. The fire code will set the
3514 * been applied flag when they are used - until that point, 3453 * been applied flag when they are used - until that point,
3525 "H<Maybe it wasn't such a bright idea to apply this cursed/damned item.>" 3464 "H<Maybe it wasn't such a bright idea to apply this cursed/damned item.>"
3526 ); 3465 );
3527 SET_FLAG (op, FLAG_KNOWN_CURSED); 3466 SET_FLAG (op, FLAG_KNOWN_CURSED);
3528 } 3467 }
3529 3468
3530 if (who->type == PLAYER) 3469 if (object *pl = op->visible_to ())
3531 {
3532 /* if multiple objects were applied, update both slots */
3533 if (tmp)
3534 esrv_send_item (who, tmp);
3535
3536 esrv_send_item (who, op); 3470 esrv_send_item (pl, op);
3537 }
3538 3471
3539 return 0; 3472 return 0;
3540} 3473}
3541 3474
3542int 3475int
3767 /* check for hp, sp change */ 3700 /* check for hp, sp change */
3768 if (food->stats.hp != 0) 3701 if (food->stats.hp != 0)
3769 { 3702 {
3770 if (QUERY_FLAG (food, FLAG_CURSED)) 3703 if (QUERY_FLAG (food, FLAG_CURSED))
3771 { 3704 {
3772 assign (who->contr->killer, food->name); 3705 who->contr->killer = food;
3773 hit_player (who, food->stats.hp, food, AT_POISON, 1); 3706 hit_player (who, food->stats.hp, food, AT_POISON, 1);
3774 who->failmsg ("Eck!...that was poisonous!"); 3707 who->failmsg ("Eck!...that was poisonous!");
3775 } 3708 }
3776 else 3709 else
3777 { 3710 {
3781 who->failmsg ("Eck!...that was poisonous!"); 3714 who->failmsg ("Eck!...that was poisonous!");
3782 3715
3783 who->stats.hp += food->stats.hp; 3716 who->stats.hp += food->stats.hp;
3784 } 3717 }
3785 } 3718 }
3719
3786 if (food->stats.sp != 0) 3720 if (food->stats.sp != 0)
3787 { 3721 {
3788 if (QUERY_FLAG (food, FLAG_CURSED)) 3722 if (QUERY_FLAG (food, FLAG_CURSED))
3789 { 3723 {
3790 who->failmsg ("You are drained of mana!"); 3724 who->failmsg ("You are drained of mana!");
3817 item = find_marked_object (who); 3751 item = find_marked_object (who);
3818 if (item) 3752 if (item)
3819 { 3753 {
3820 if (lighter->last_eat && lighter->stats.food) 3754 if (lighter->last_eat && lighter->stats.food)
3821 { /* lighter gets used up */ 3755 { /* lighter gets used up */
3822 /* Split multiple lighters if they're being used up. Otherwise *
3823 * one charge from each would be used up. --DAMN */
3824 if (lighter->nrof > 1)
3825 {
3826 object *oneLighter = lighter->clone (); 3756 object *oneLighter = lighter->split ();
3827
3828 lighter->nrof -= 1;
3829 oneLighter->nrof = 1;
3830 oneLighter->stats.food--; 3757 oneLighter->stats.food--;
3831 esrv_send_item (who, lighter); 3758 who->insert (oneLighter);
3832 oneLighter = insert_ob_in_ob (oneLighter, who);
3833 esrv_send_item (who, oneLighter);
3834 }
3835 else
3836 lighter->stats.food--;
3837 } 3759 }
3838 else if (lighter->last_eat) 3760 else if (lighter->last_eat)
3839 { 3761 {
3840 /* no charges left in lighter */ 3762 /* no charges left in lighter */
3841 who->failmsg (format ("You attempt to light the %s with a used up %s.", &item->name, &lighter->name)); 3763 who->failmsg (format ("You attempt to light the %s with a used up %s.", &item->name, &lighter->name));
3988 if (!strcmp (walk->name, "NOCLASSFACECHANGE")) 3910 if (!strcmp (walk->name, "NOCLASSFACECHANGE"))
3989 flag_change_face = 0; 3911 flag_change_face = 0;
3990 3912
3991 if (flag_change_face) 3913 if (flag_change_face)
3992 { 3914 {
3993 pl->animation_id = GET_ANIM_ID (change);
3994 pl->face = change->face; 3915 pl->face = change->face;
3995 3916 pl->animation_id = change->animation_id;
3996 if (QUERY_FLAG (change, FLAG_ANIMATE)) 3917 pl->flag [FLAG_ANIMATE] = change->flag [FLAG_ANIMATE];
3997 SET_FLAG (pl, FLAG_ANIMATE);
3998 else
3999 CLEAR_FLAG (pl, FLAG_ANIMATE);
4000 } 3918 }
4001 3919
4002 /* check the special case of can't use weapons */ 3920 /* check the special case of can't use weapons */
4003 /*if(QUERY_FLAG(change,FLAG_USE_WEAPON)) CLEAR_FLAG(pl,FLAG_USE_WEAPON); */ 3921 /*if(QUERY_FLAG(change,FLAG_USE_WEAPON)) CLEAR_FLAG(pl,FLAG_USE_WEAPON); */
4004 if (!strcmp (change->name, "monk")) 3922 if (!strcmp (change->name, "monk"))
4098 4016
4099 new_item->nrof = yield; 4017 new_item->nrof = yield;
4100 4018
4101 pl->statusmsg (format ("You %s the %s.", &transformer->slaying, query_base_name (marked, 0))); 4019 pl->statusmsg (format ("You %s the %s.", &transformer->slaying, query_base_name (marked, 0)));
4102 4020
4103 insert_ob_in_ob (new_item, pl); 4021 pl->insert (new_item);
4104 esrv_send_inventory (pl, pl);
4105 /* Eat up one item */ 4022 /* Eat up one item */
4106 decrease_ob_nr (marked, 1); 4023 marked->decrease ();
4107 4024
4108 /* Eat one transformer if needed */ 4025 /* Eat one transformer if needed */
4109 if (transformer->stats.food) 4026 if (transformer->stats.food)
4110 if (--transformer->stats.food == 0) 4027 if (--transformer->stats.food == 0)
4111 decrease_ob_nr (transformer, 1); 4028 transformer->decrease ();
4112} 4029}
4113 4030

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines