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.201 by root, Mon Oct 12 14:00:58 2009 UTC vs.
Revision 1.233 by root, Fri Apr 2 03:41:24 2010 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,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2001 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify it under 8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * the terms of the Affero GNU General Public License as published by the 9 * the terms of the Affero GNU General Public License as published by the
10 * Free Software Foundation, either version 3 of the License, or (at your 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version. 11 * option) any later version.
172 */ 172 */
173int 173int
174apply_potion (object *op, object *tmp) 174apply_potion (object *op, object *tmp)
175{ 175{
176 int got_one = 0, i; 176 int got_one = 0, i;
177 object *force = 0, *floor = 0; 177 object *force = 0;
178 178
179 floor = GET_MAP_OB (op->map, op->x, op->y); 179 object *floor = GET_MAP_OB (op->map, op->x, op->y);
180 180
181 if (get_map_flags (op->map, NULL, op->x, op->y, NULL, NULL) & P_SAFE) 181 if (get_map_flags (op->map, NULL, op->x, op->y, NULL, NULL) & P_SAFE)
182 { 182 {
183 op->failmsg ("Gods prevent you from using this here, it's sacred ground!"); 183 op->failmsg ("Gods prevent you from using this here, it's sacred ground!");
184 184
204 op->update_stats (); 204 op->update_stats ();
205 tmp->decrease (); 205 tmp->decrease ();
206 return 1; 206 return 1;
207 } 207 }
208 208
209 if (!(at = archetype::find (ARCH_DEPLETION))) 209 if (!(at = archetype::find (shstr_depletion)))
210 { 210 {
211 LOG (llevError, "Could not find archetype depletion\n"); 211 LOG (llevError, "Could not find archetype depletion\n");
212 return 0; 212 return 0;
213 } 213 }
214 214
231 } 231 }
232 232
233 /* improvement potion - only for players */ 233 /* improvement potion - only for players */
234 if (op->type == PLAYER && (tmp->attacktype & AT_GODPOWER)) 234 if (op->type == PLAYER && (tmp->attacktype & AT_GODPOWER))
235 { 235 {
236 for (i = 1; i < MIN (11, op->level); i++) 236 for (i = 1; i < min (11, op->level); i++)
237 { 237 {
238 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED)) 238 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED))
239 { 239 {
240 if (op->contr->levhp[i] != 1) 240 if (op->contr->levhp[i] != 1)
241 { 241 {
276 } 276 }
277 } 277 }
278 } 278 }
279 279
280 /* Just makes checking easier */ 280 /* Just makes checking easier */
281 if (i < MIN (11, op->level)) 281 if (i < min (11, op->level))
282 got_one = 1; 282 got_one = 1;
283 283
284 if (!QUERY_FLAG (tmp, FLAG_CURSED) && !QUERY_FLAG (tmp, FLAG_DAMNED)) 284 if (!QUERY_FLAG (tmp, FLAG_CURSED) && !QUERY_FLAG (tmp, FLAG_DAMNED))
285 { 285 {
286 if (got_one) 286 if (got_one)
400 400
401/** 401/**
402 * This function just checks whether who can handle equipping an item 402 * This function just checks whether who can handle equipping an item
403 * with item_power. 403 * with item_power.
404 */ 404 */
405 405static bool
406bool
407check_item_power (object *who, int item_power) 406check_item_power (object *who, int item_power)
408{ 407{
409 if (who->type == PLAYER 408 if (who->type == PLAYER
410 && item_power 409 && item_power
411 && item_power + who->contr->item_power > settings.item_power_factor * who->level) 410 && item_power + who->contr->item_power > settings.item_power_factor * who->level)
532 531
533/** 532/**
534 * This does the prepare weapon scroll. 533 * This does the prepare weapon scroll.
535 * Checks for sacrifice, and so on. 534 * Checks for sacrifice, and so on.
536 */ 535 */
537int 536static int
538prepare_weapon (object *op, object *improver, object *weapon) 537prepare_weapon (object *op, object *improver, object *weapon)
539{ 538{
540 int sacrifice_count, i; 539 int sacrifice_count, i;
541 char buf[MAX_BUF]; 540 char buf[MAX_BUF];
542 541
595 * 594 *
596 * We are hiding extra information about the weapon in the level and 595 * We are hiding extra information about the weapon in the level and
597 * last_eat numbers for an object. Hopefully this won't break anything ?? 596 * last_eat numbers for an object. Hopefully this won't break anything ??
598 * level == max improve last_eat == current improve 597 * level == max improve last_eat == current improve
599 */ 598 */
600int 599static int
601improve_weapon (object *op, object *improver, object *weapon) 600improve_weapon (object *op, object *improver, object *weapon)
602{ 601{
603 int sacrifice_count, sacrifice_needed = 0; 602 int sacrifice_count, sacrifice_needed = 0;
604 603
605 if (improver->stats.sp == IMPROVE_PREPARE) 604 if (improver->stats.sp == IMPROVE_PREPARE)
707/** 706/**
708 * Handles the applying of improve/prepare/enchant weapon scroll. 707 * Handles the applying of improve/prepare/enchant weapon scroll.
709 * Checks a few things (not on a non-magic square, marked weapon, ...), 708 * Checks a few things (not on a non-magic square, marked weapon, ...),
710 * then calls improve_weapon to do the dirty work. 709 * then calls improve_weapon to do the dirty work.
711 */ 710 */
712int 711static int
713check_improve_weapon (object *op, object *tmp) 712check_improve_weapon (object *op, object *tmp)
714{ 713{
715 object *otmp; 714 object *otmp;
716 715
717 if (op->type != PLAYER) 716 if (op->type != PLAYER)
764 * the armour value of the piece of equipment exceed either 763 * the armour value of the piece of equipment exceed either
765 * the users level or 90) 764 * the users level or 90)
766 * Modified by MSW for partial resistance. Only support 765 * Modified by MSW for partial resistance. Only support
767 * changing of physical area right now. 766 * changing of physical area right now.
768 */ 767 */
769int 768static int
770improve_armour (object *op, object *improver, object *armour) 769improve_armour (object *op, object *improver, object *armour)
771{ 770{
772 object *tmp; 771 object *tmp;
773 772
774 if (armour->magic >= settings.armor_max_enchant) 773 if (armour->magic >= settings.armor_max_enchant)
861 * what the converter wants, this will not do anything. 860 * what the converter wants, this will not do anything.
862 */ 861 */
863int 862int
864convert_item (object *item, object *converter) 863convert_item (object *item, object *converter)
865{ 864{
866 sint64 nr, price_in; 865 sint64 nr = 0, price_in;
867 866
868 if (item->flag [FLAG_UNPAID]) 867 if (item->flag [FLAG_UNPAID])
869 return 0; 868 return 0;
870 869
871 shstr conv_from = converter->slaying; 870 shstr conv_from = converter->slaying;
872 archetype *conv_to = converter->other_arch; 871 archetype *conv_to = converter->other_arch;
873 sint64 need = converter->stats.food; 872 sint64 need = converter->stats.food;
874 sint64 give = converter->stats.sp; 873 sint64 give = converter->stats.sp;
875 874
985 * Handle apply on containers. 984 * Handle apply on containers.
986 * By Eneq(@csd.uu.se). 985 * By Eneq(@csd.uu.se).
987 * Moved to own function and added many features [Tero.Haatanen@lut.fi] 986 * Moved to own function and added many features [Tero.Haatanen@lut.fi]
988 * added the alchemical cauldron to the code -b.t. 987 * added the alchemical cauldron to the code -b.t.
989 */ 988 */
990int 989static int
991apply_container (object *op, object *sack) 990apply_container (object *op, object *sack)
992{ 991{
993 if (op->type != PLAYER || !op->contr->ns) 992 if (op->type != PLAYER || !op->contr->ns)
994 return 0; /* This might change */ 993 return 0; /* This might change */
995 994
1008 } 1007 }
1009 1008
1010 // already applied == open on ground, or open in inv, or active in inv 1009 // already applied == open on ground, or open in inv, or active in inv
1011 if (sack->flag [FLAG_APPLIED]) 1010 if (sack->flag [FLAG_APPLIED])
1012 { 1011 {
1013 if (op->container == sack) 1012 if (op->container_ () == sack)
1014 { 1013 {
1015 // open on ground or inv, so close 1014 // open on ground or inv, so close
1016 op->close_container (); 1015 op->close_container ();
1017 return 1; 1016 return 1;
1018 } 1017 }
1325 return; 1324 return;
1326 1325
1327 /* move_apply() is the most likely candidate for causing unwanted and 1326 /* move_apply() is the most likely candidate for causing unwanted and
1328 * possibly unlimited recursion. 1327 * possibly unlimited recursion.
1329 */ 1328 */
1330 /* The following was changed because it was causing perfeclty correct 1329 /* The following was changed because it was causing perfectly correct
1331 * maps to fail. 1) it's not an error to recurse: 1330 * maps to fail. 1) it's not an error to recurse:
1332 * rune detonates, summoning monster. monster lands on nearby rune. 1331 * rune detonates, summoning monster. monster lands on nearby rune.
1333 * nearby rune detonates. This sort of recursion is expected and 1332 * nearby rune detonates. This sort of recursion is expected and
1334 * proper. This code was causing needless crashes. 1333 * proper. This code was causing needless crashes.
1335 */ 1334 */
1354 trap->stats.maxsp = 2; 1353 trap->stats.maxsp = 2;
1355 1354
1356 /* Is this correct? From the docs, it doesn't look like it 1355 /* Is this correct? From the docs, it doesn't look like it
1357 * should be divided by trap->speed 1356 * should be divided by trap->speed
1358 */ 1357 */
1359 victim->speed_left = -FABS (trap->stats.maxsp * victim->speed / trap->speed); 1358 victim->speed_left = -trap->stats.maxsp * victim->speed / trap->speed;
1360 1359
1361 /* Just put in some sanity check. I think there is a bug in the 1360 /* Just put in some sanity check. I think there is a bug in the
1362 * above with some objects have zero speed, and thus the player 1361 * above with some objects have zero speed, and thus the player
1363 * getting permanently paralyzed. 1362 * getting permanently paralyzed.
1364 */ 1363 */
1384 } 1383 }
1385 break; 1384 break;
1386 1385
1387 case BUTTON: 1386 case BUTTON:
1388 case PEDESTAL: 1387 case PEDESTAL:
1388 case T_MATCH:
1389 update_button (trap, originator); 1389 update_button (trap, originator);
1390 break; 1390 break;
1391 1391
1392 case ALTAR: 1392 case ALTAR:
1393 /* sacrifice victim on trap */ 1393 /* sacrifice victim on trap */
1404 * trigger this here and get hit by own missile - and will be own enemy. 1404 * trigger this here and get hit by own missile - and will be own enemy.
1405 * Victim then is his own enemy and will start to kill herself (this is 1405 * Victim then is his own enemy and will start to kill herself (this is
1406 * removed) but we have not synced victim and his missile. To avoid senseless 1406 * removed) but we have not synced victim and his missile. To avoid senseless
1407 * action, we avoid hits here 1407 * action, we avoid hits here
1408 */ 1408 */
1409 if ((QUERY_FLAG (victim, FLAG_ALIVE) && trap->speed) && trap->owner != victim) 1409 if ((QUERY_FLAG (victim, FLAG_ALIVE) && trap->has_active_speed ())
1410 && trap->owner != victim)
1410 hit_with_arrow (trap, victim); 1411 hit_with_arrow (trap, victim);
1411 break; 1412 break;
1412 1413
1413 case SPELL_EFFECT: 1414 case SPELL_EFFECT:
1414 apply_spell_effect (trap, victim); 1415 apply_spell_effect (trap, victim);
1487 if (victim->type == PLAYER && EXIT_PATH (trap)) 1488 if (victim->type == PLAYER && EXIT_PATH (trap))
1488 { 1489 {
1489 /* Basically, don't show exits leading to random maps the 1490 /* Basically, don't show exits leading to random maps the
1490 * players output. 1491 * players output.
1491 */ 1492 */
1492 if (trap->msg && !EXIT_PATH (trap).starts_with ("/!")) 1493 if (trap->msg && EXIT_PATH (trap) != shstr_random_map_exit)
1493 victim->statusmsg (trap->msg, NDI_NAVY); 1494 victim->statusmsg (trap->msg, NDI_NAVY);
1494 1495
1495 trap->play_sound (trap->sound); 1496 trap->play_sound (trap->sound);
1496 victim->enter_exit (trap); 1497 victim->enter_exit (trap);
1497 } 1498 }
1551 return; 1552 return;
1552 } 1553 }
1553 1554
1554 if (!tmp->msg) 1555 if (!tmp->msg)
1555 { 1556 {
1556 op->failmsg (format ("You open the %s and find it empty.", &tmp->name)); 1557 op->failmsg (format ("The %s contains nothing but meaningless gibberish. H<There is nothing interesting to read here.>", &tmp->name));
1557 return; 1558 return;
1558 } 1559 }
1559 1560
1560 /* need a literacy skill to read stuff! */ 1561 /* need a literacy skill to read stuff! */
1561 skill_ob = find_skill_by_name (op, tmp->skill); 1562 skill_ob = find_skill_by_name (op, tmp->skill);
1575 : lev_diff < 15 ? "This book is way beyond your comprehension." 1576 : lev_diff < 15 ? "This book is way beyond your comprehension."
1576 : "This book is totally beyond your comprehension."); 1577 : "This book is totally beyond your comprehension.");
1577 return; 1578 return;
1578 } 1579 }
1579 1580
1581 // we currently don't use the message types for anything.
1580 readable_message_type *msgType = get_readable_message_type (tmp); 1582 // readable_message_type *msgType = get_readable_message_type (tmp);
1583
1584 tmp->play_sound (tmp->sound ? tmp->sound : sound_find ("apply_book"));
1581 1585
1582 if (player *pl = op->contr) 1586 if (player *pl = op->contr)
1583 if (client *ns = pl->ns) 1587 if (client *ns = pl->ns)
1584 pl->infobox (MSG_CHANNEL ("book"), format ("T<%s>\n\n%s", (char *)long_desc (tmp, op), &tmp->msg)); 1588 pl->infobox (MSG_CHANNEL ("book"), format ("T<%s>\n\n%s", (char *)long_desc (tmp, op), &tmp->msg));
1585 1589
1597 esrv_update_item (UPD_FLAGS | UPD_NAME, pl, tmp); 1601 esrv_update_item (UPD_FLAGS | UPD_NAME, pl, tmp);
1598 } 1602 }
1599 1603
1600 change_exp (op, exp_gain, skill_ob->skill, 0); 1604 change_exp (op, exp_gain, skill_ob->skill, 0);
1601 SET_FLAG (tmp, FLAG_NO_SKILL_IDENT); /* so no more xp gained from this book */ 1605 SET_FLAG (tmp, FLAG_NO_SKILL_IDENT); /* so no more xp gained from this book */
1606 }
1607}
1608
1609/**
1610 * op made some mistake with a scroll, this takes care of punishment.
1611 * scroll_failure()- hacked directly from spell_failure
1612 */
1613static void
1614scroll_failure (object *op, int failure, int power)
1615{
1616 if (abs (failure / 4) > power)
1617 power = abs (failure / 4); /* set minimum effect */
1618
1619 if (failure <= -1 && failure > -15)
1620 { /* wonder */
1621 object *tmp;
1622
1623 op->failmsg ("Your spell warps!");
1624 tmp = get_archetype (SPELL_WONDER);
1625 cast_wonder (op, op, 0, tmp);
1626 tmp->destroy ();
1627 }
1628 else if (failure <= -15 && failure > -35)
1629 { /* drain mana */
1630 op->failmsg ("Your mana is drained!");
1631 op->stats.sp -= random_roll (0, power - 1, op, PREFER_LOW);
1632 if (op->stats.sp < 0)
1633 op->stats.sp = 0;
1634 }
1635 else if (settings.spell_failure_effects == TRUE)
1636 {
1637 if (failure <= -35 && failure > -60)
1638 { /* confusion */
1639 op->failmsg ("The magic recoils on you!");
1640 confuse_player (op, op, power);
1641 }
1642 else if (failure <= -60 && failure > -70)
1643 { /* paralysis */
1644 op->failmsg ("The magic recoils and paralyzes you!");
1645 paralyze_player (op, op, power);
1646 }
1647 else if (failure <= -70 && failure > -80)
1648 { /* blind */
1649 op->failmsg ("The magic recoils on you!");
1650 blind_player (op, op, power);
1651 }
1652 else if (failure <= -80)
1653 { /* blast the immediate area */
1654 object *tmp = get_archetype (LOOSE_MANA);
1655 cast_magic_storm (op, tmp, power);
1656 op->failmsg ("You unleash uncontrolled mana!");
1657 tmp->destroy ();
1658 }
1602 } 1659 }
1603} 1660}
1604 1661
1605/** 1662/**
1606 * Handles the applying of a skill scroll, calling learn_skill straight. 1663 * Handles the applying of a skill scroll, calling learn_skill straight.
1685 LOG (llevError, "BUG: do_forget_spell(): spell not known\n"); 1742 LOG (llevError, "BUG: do_forget_spell(): spell not known\n");
1686 return; 1743 return;
1687 } 1744 }
1688 1745
1689 op->failmsg (format ("You lose knowledge of %s.", spell)); 1746 op->failmsg (format ("You lose knowledge of %s.", spell));
1690 player_unready_range_ob (op->contr, spob);
1691 esrv_remove_spell (op->contr, spob); 1747 esrv_remove_spell (op->contr, spob);
1692 spob->destroy (); 1748 spob->destroy ();
1693} 1749}
1694 1750
1695/** 1751/**
1712 * instead of having their spell stored in stats.sp. These are 1768 * instead of having their spell stored in stats.sp. These are
1713 * legacy spellbooks 1769 * legacy spellbooks
1714 */ 1770 */
1715 if (tmp->slaying) 1771 if (tmp->slaying)
1716 { 1772 {
1717 spell = arch_to_object (find_archetype_by_object_name (tmp->slaying)); 1773 spell = find_archetype_by_object_name (tmp->slaying)->instance ();
1774
1718 if (!spell) 1775 if (!spell)
1719 { 1776 {
1720 op->failmsg (format ("The book's formula for %s is incomplete.", &tmp->slaying)); 1777 op->failmsg (format ("The book's formula for %s is incomplete.", &tmp->slaying));
1721 return; 1778 return;
1722 } 1779 }
1799 * literacy rate very useful! -b.t. 1856 * literacy rate very useful! -b.t.
1800 */ 1857 */
1801 if (QUERY_FLAG (op, FLAG_CONFUSED)) 1858 if (QUERY_FLAG (op, FLAG_CONFUSED))
1802 { 1859 {
1803 op->failmsg ("In your confused state you flub the wording of the text!"); 1860 op->failmsg ("In your confused state you flub the wording of the text!");
1804 scroll_failure (op, 0 - random_roll (0, spell->level, op, PREFER_LOW), MAX (spell->stats.sp, spell->stats.grace)); 1861 scroll_failure (op, 0 - random_roll (0, spell->level, op, PREFER_LOW), max (spell->stats.sp, spell->stats.grace));
1805 } 1862 }
1806 else if (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || 1863 else if (QUERY_FLAG (tmp, FLAG_STARTEQUIP) ||
1807 (random_roll (0, 100, op, PREFER_LOW) - (5 * skop->level)) < learn_spell[spell->stats.grace ? op->stats.Wis : op->stats.Int]) 1864 (random_roll (0, 100, op, PREFER_LOW) - (5 * skop->level)) < learn_spell[spell->stats.grace ? op->stats.Wis : op->stats.Int])
1808 { 1865 {
1809 op->statusmsg ("You succeed in learning the spell!", NDI_GREEN); 1866 op->statusmsg ("You succeed in learning the spell!", NDI_GREEN);
1915 break; 1972 break;
1916 } 1973 }
1917 1974
1918 if (!tmp->destroyed () && !tmp->inv) 1975 if (!tmp->destroyed () && !tmp->inv)
1919 tmp->decrease (true); 1976 tmp->decrease (true);
1920}
1921
1922/**
1923 * op eats food.
1924 * If player, takes care of messages and dragon special food.
1925 */
1926static void
1927apply_food (object *op, object *tmp)
1928{
1929 int capacity_remaining;
1930
1931 if (op->type != PLAYER)
1932 op->stats.hp = op->stats.maxhp;
1933 else
1934 {
1935 /* check if this is a dragon (player), eating some flesh */
1936 if (tmp->type == FLESH && is_dragon_pl (op) && dragon_eat_flesh (op, tmp))
1937 ;
1938 else
1939 {
1940 /* usual case - no dragon meal: */
1941 if (op->stats.food + tmp->stats.food > 999)
1942 {
1943 if (tmp->type == FOOD || tmp->type == FLESH)
1944 op->failmsg ("You feel full, but what a waste of food!");
1945 else
1946 op->statusmsg ("Most of the drink goes down your face not your throat!");
1947 }
1948
1949 tmp->play_sound (
1950 tmp->sound
1951 ? tmp->sound
1952 : tmp->type == DRINK
1953 ? sound_find ("eat_drink")
1954 : sound_find ("eat_food")
1955 );
1956
1957 if (!QUERY_FLAG (tmp, FLAG_CURSED))
1958 {
1959 const char *buf;
1960
1961 if (!is_dragon_pl (op))
1962 {
1963 /* eating message for normal players */
1964 if (tmp->type == DRINK)
1965 buf = format ("Ahhh...that %s tasted good.", &tmp->name);
1966 else
1967 buf = format ("The %s tasted %s", &tmp->name, tmp->type == FLESH ? "terrible!" : "good.");
1968 }
1969 else
1970 /* eating message for dragon players */
1971 buf = format ("The %s tasted terrible!", &tmp->name);
1972
1973 op->statusmsg (buf);
1974
1975 capacity_remaining = 999 - op->stats.food;
1976 op->stats.food += tmp->stats.food;
1977 if (capacity_remaining < tmp->stats.food)
1978 op->stats.hp += capacity_remaining / 50;
1979 else
1980 op->stats.hp += tmp->stats.food / 50;
1981
1982 if (op->stats.hp > op->stats.maxhp)
1983 op->stats.hp = op->stats.maxhp;
1984 if (op->stats.food > 999)
1985 op->stats.food = 999;
1986 }
1987
1988 /* special food hack -b.t. */
1989 if (tmp->title || QUERY_FLAG (tmp, FLAG_CURSED))
1990 eat_special_food (op, tmp);
1991 }
1992 }
1993
1994 handle_apply_yield (tmp);
1995 tmp->decrease ();
1996} 1977}
1997 1978
1998/** 1979/**
1999 * A dragon is eating some flesh. If the flesh contains resistances, 1980 * A dragon is eating some flesh. If the flesh contains resistances,
2000 * there is a chance for the dragon's skin to get improved. 1981 * there is a chance for the dragon's skin to get improved.
2003 * object *op the object (dragon player) eating the flesh 1984 * object *op the object (dragon player) eating the flesh
2004 * object *meal the flesh item, getting chewed in dragon's mouth 1985 * object *meal the flesh item, getting chewed in dragon's mouth
2005 * return: 1986 * return:
2006 * int 1 if eating successful, 0 if it doesn't work 1987 * int 1 if eating successful, 0 if it doesn't work
2007 */ 1988 */
2008int 1989static int
2009dragon_eat_flesh (object *op, object *meal) 1990dragon_eat_flesh (object *op, object *meal)
2010{ 1991{
2011 object *skin = NULL; /* pointer to dragon skin force */ 1992 object *skin = NULL; /* pointer to dragon skin force */
2012 object *abil = NULL; /* pointer to dragon ability force */ 1993 object *abil = NULL; /* pointer to dragon ability force */
2013 object *tmp = NULL; /* tmp. object */ 1994 object *tmp = NULL; /* tmp. object */
2019 int atnr_winner[NROFATTACKS]; /* winning candidates for resistance improvement */ 2000 int atnr_winner[NROFATTACKS]; /* winning candidates for resistance improvement */
2020 int winners = 0; /* number of winners */ 2001 int winners = 0; /* number of winners */
2021 int i; /* index */ 2002 int i; /* index */
2022 2003
2023 /* let's make sure and doublecheck the parameters */ 2004 /* let's make sure and doublecheck the parameters */
2024 if (meal->type != FLESH || !is_dragon_pl (op)) 2005 if (meal->type != FLESH || !op->is_dragon ())
2025 return 0; 2006 return 0;
2026 2007
2027 /* now grab the 'dragon_skin'- and 'dragon_ability'-forces 2008 /* now grab the 'dragon_skin'- and 'dragon_ability'-forces
2028 from the player's inventory */ 2009 from the player's inventory */
2029 for (tmp = op->inv; tmp; tmp = tmp->below) 2010 for (tmp = op->inv; tmp; tmp = tmp->below)
2037 which is not to be considered a dragon -> bail out */ 2018 which is not to be considered a dragon -> bail out */
2038 if (skin == NULL || abil == NULL) 2019 if (skin == NULL || abil == NULL)
2039 return 0; 2020 return 0;
2040 2021
2041 /* now start by filling stomache and health, according to food-value */ 2022 /* now start by filling stomache and health, according to food-value */
2042 if ((999 - op->stats.food) < meal->stats.food) 2023 if ((MAX_FOOD - op->stats.food) < meal->stats.food)
2043 op->stats.hp += (999 - op->stats.food) / 50; 2024 op->stats.hp += (MAX_FOOD - op->stats.food) / 50;
2044 else 2025 else
2045 op->stats.hp += meal->stats.food / 50; 2026 op->stats.hp += meal->stats.food / 50;
2046 2027
2047 if (op->stats.hp > op->stats.maxhp) 2028 min_it (op->stats.hp, op->stats.maxhp);
2048 op->stats.hp = op->stats.maxhp;
2049
2050 op->stats.food = MIN (999, op->stats.food + meal->stats.food); 2029 op->stats.food = min (MAX_FOOD, op->stats.food + meal->stats.food);
2051 2030
2052 /*LOG(llevDebug, "-> player: %d, flesh: %d\n", op->level, meal->level); */ 2031 /*LOG(llevDebug, "-> player: %d, flesh: %d\n", op->level, meal->level); */
2053 2032
2054 /* on to the interesting part: chances for adding resistance */ 2033 /* on to the interesting part: chances for adding resistance */
2055 for (i = 0; i < NROFATTACKS; i++) 2034 for (i = 0; i < NROFATTACKS; i++)
2065 2044
2066 /* monster bonus increases with level, because high-level 2045 /* monster bonus increases with level, because high-level
2067 flesh is too rare */ 2046 flesh is too rare */
2068 mbonus = op->level * 20. / ((double) settings.max_level); 2047 mbonus = op->level * 20. / ((double) settings.max_level);
2069 2048
2070 chance = (((double) MIN (op->level + bonus, meal->level + bonus + mbonus)) * 100. / 2049 chance = (((double)min (op->level + bonus, meal->level + bonus + mbonus)) * 100. /
2071 ((double) settings.max_level)) - skin->resist[i]; 2050 ((double)settings.max_level)) - skin->resist[i];
2072 2051
2073 if (chance >= 0.) 2052 if (chance >= 0.)
2074 chance += 1.; 2053 chance += 1.;
2075 else 2054 else
2076 chance = (chance < -12) ? 0. : 1. / pow (2., -chance); 2055 chance = (chance < -12) ? 0. : 1. / pow (2., -chance);
2077 2056
2078 /* chance is proportional to amount of resistance (max. 50) */ 2057 /* chance is proportional to amount of resistance (max. 50) */
2079 chance *= ((double) (MIN (meal->resist[i], 50))) / 50.; 2058 chance *= ((double)(min (meal->resist[i], 50))) / 50.;
2080 2059
2081 /* doubled chance for resistance of ability-focus */ 2060 /* doubled chance for resistance of ability-focus */
2082 if (i == abil->stats.exp) 2061 if (i == abil->stats.exp)
2083 chance = MIN (100., chance * 2.); 2062 chance = min (100., chance * 2.);
2084 2063
2085 /* now make the throw and save all winners (Don't insert luck bonus here!) */ 2064 /* now make the throw and save all winners (Don't insert luck bonus here!) */
2086 if (rndm (10000) < (unsigned int) (chance * 100)) 2065 if (rndm (10000) < (unsigned int)(chance * 100))
2087 { 2066 {
2088 atnr_winner[winners] = i; 2067 atnr_winner[winners] = i;
2089 winners++; 2068 winners++;
2090 } 2069 }
2091 2070
2154 2133
2155 return 1; 2134 return 1;
2156} 2135}
2157 2136
2158/** 2137/**
2138 * op eats food.
2139 * If player, takes care of messages and dragon special food.
2140 */
2141static void
2142apply_food (object *op, object *tmp)
2143{
2144 int capacity_remaining;
2145
2146 if (op->type != PLAYER)
2147 op->stats.hp = op->stats.maxhp;
2148 else
2149 {
2150 /* check if this is a dragon (player), eating some flesh */
2151 if (tmp->type == FLESH && op->is_dragon () && dragon_eat_flesh (op, tmp))
2152 ;
2153 else
2154 {
2155 /* usual case - no dragon meal: */
2156 if (op->stats.food + tmp->stats.food > MAX_FOOD)
2157 {
2158 if (tmp->type == FOOD || tmp->type == FLESH)
2159 op->failmsg ("You feel full, but what a waste of food!");
2160 else
2161 op->statusmsg ("Most of the drink goes down your face not your throat!");
2162 }
2163
2164 tmp->play_sound (
2165 tmp->sound
2166 ? tmp->sound
2167 : tmp->type == DRINK
2168 ? sound_find ("eat_drink")
2169 : sound_find ("eat_food")
2170 );
2171
2172 if (!QUERY_FLAG (tmp, FLAG_CURSED))
2173 {
2174 const char *buf;
2175
2176 if (!op->is_dragon ())
2177 {
2178 /* eating message for normal players */
2179 if (tmp->type == DRINK)
2180 buf = format ("Ahhh...that %s tasted good.", &tmp->name);
2181 else
2182 buf = format ("The %s tasted %s", &tmp->name, tmp->type == FLESH ? "terrible!" : "good.");
2183 }
2184 else
2185 /* eating message for dragon players */
2186 buf = format ("The %s tasted terrible!", &tmp->name);
2187
2188 op->statusmsg (buf);
2189
2190 capacity_remaining = MAX_FOOD - op->stats.food;
2191 op->stats.food += tmp->stats.food;
2192 if (capacity_remaining < tmp->stats.food)
2193 op->stats.hp += capacity_remaining / 50;
2194 else
2195 op->stats.hp += tmp->stats.food / 50;
2196
2197 min_it (op->stats.hp, op->stats.maxhp);
2198 min_it (op->stats.food, MAX_FOOD);
2199 }
2200
2201 /* special food hack -b.t. */
2202 if (tmp->title || QUERY_FLAG (tmp, FLAG_CURSED))
2203 eat_special_food (op, tmp);
2204 }
2205 }
2206
2207 handle_apply_yield (tmp);
2208 tmp->decrease ();
2209}
2210
2211/**
2159 * Handles applying an improve armor scroll. 2212 * Handles applying an improve armor scroll.
2160 * Does some sanity checks, then calls improve_armour. 2213 * Does some sanity checks, then calls improve_armour.
2161 */ 2214 */
2162static void 2215static void
2163apply_armour_improver (object *op, object *tmp) 2216apply_armour_improver (object *op, object *tmp)
2211 hit_player (op, poison->stats.hp, tmp, AT_POISON, 1); 2264 hit_player (op, poison->stats.hp, tmp, AT_POISON, 1);
2212 } 2265 }
2213 2266
2214 op->stats.food -= op->stats.food / 4; 2267 op->stats.food -= op->stats.food / 4;
2215 poison->destroy (); 2268 poison->destroy ();
2216}
2217
2218/**
2219 * This function return true if the exit is not a 2 ways one or it is 2 ways, valid exit.
2220 * A valid 2 way exit means:
2221 * -You can come back (there is another exit at the other side)
2222 * -You are
2223 * ° the owner of the exit
2224 * ° or in the same party as the owner
2225 *
2226 * Note: a owner in a 2 way exit is saved as the owner's name
2227 * in the field exit->name cause the field exit->owner doesn't
2228 * survive in the swapping (in fact the whole exit doesn't survive).
2229 */
2230int
2231is_legal_2ways_exit (object *op, object *exit)
2232{
2233 if (exit->stats.exp != 1)
2234 return 1; /*This is not a 2 way, so it is legal */
2235
2236#if 0 //TODO
2237 if (!has_been_loaded (EXIT_PATH (exit)) && exit->race)
2238 return 0; /* This is a reset town portal */
2239#endif
2240
2241 LOG (llevError | logBacktrace, "sync map load due to %s\n", exit->debug_desc ());
2242
2243 maptile *exitmap = maptile::find_sync (EXIT_PATH (exit), exit->map);
2244
2245 if (exitmap)
2246 {
2247 exitmap->load_sync ();
2248
2249 object *tmp = exitmap->at (EXIT_X (exit), EXIT_Y (exit)).bot;
2250
2251 if (!tmp)
2252 return 0;
2253
2254 for (; tmp; tmp = tmp->above)
2255 {
2256 if (tmp->type != EXIT)
2257 continue; /*Not an exit */
2258
2259 if (!EXIT_PATH (tmp))
2260 continue; /*Not a valid exit */
2261
2262 if ((EXIT_X (tmp) != exit->x) || (EXIT_Y (tmp) != exit->y))
2263 continue; /*Not in the same place */
2264
2265 if (exit->map->path != EXIT_PATH (tmp))
2266 continue; /*Not in the same map */
2267
2268 /* From here we have found the exit is valid. However we do
2269 * here the check of the exit owner. It is important for the
2270 * town portals to prevent strangers from visiting your appartments
2271 */
2272 if (!exit->race)
2273 return 1; /*No owner, free for all! */
2274
2275 object *exit_owner = 0;
2276
2277 for_all_players (pp)
2278 {
2279 if (!pp->ob)
2280 continue;
2281
2282 if (pp->ob->name != exit->race)
2283 continue;
2284
2285 exit_owner = pp->ob; /*We found a player which correspond to the player name */
2286 break;
2287 }
2288
2289 if (!exit_owner)
2290 return 0; /* No more owner */
2291
2292 if (exit_owner->contr == op->contr)
2293 return 1; /*It is your exit */
2294
2295 if (exit_owner && /*There is a owner */
2296 (op->contr) && /*A player tries to pass */
2297 ((exit_owner->contr->party == NULL) || /*No pass if controller has no party */
2298 (exit_owner->contr->party != op->contr->party))) /* Or not the same as op */
2299 return 0;
2300
2301 return 1;
2302 }
2303 }
2304
2305 return 0;
2306} 2269}
2307 2270
2308/** 2271/**
2309 * This function will try to apply a lighter and in case no lighter 2272 * This function will try to apply a lighter and in case no lighter
2310 * is specified it will try to find a lighter in the players inventory, 2273 * is specified it will try to find a lighter in the players inventory,
2361/** 2324/**
2362 * Designed primarily to light torches/lanterns/etc. 2325 * Designed primarily to light torches/lanterns/etc.
2363 * Also burns up burnable material too. First object in the inventory is 2326 * Also burns up burnable material too. First object in the inventory is
2364 * the selected object to "burn". -b.t. 2327 * the selected object to "burn". -b.t.
2365 */ 2328 */
2366void 2329static void
2367apply_lighter (object *who, object *lighter) 2330apply_lighter (object *who, object *lighter)
2368{ 2331{
2369 object *item; 2332 object *item;
2370 int is_player_env = 0; 2333 int is_player_env = 0;
2371 2334
2398} 2361}
2399 2362
2400/** 2363/**
2401 * This function generates a cursed effect for cursed lamps and torches. 2364 * This function generates a cursed effect for cursed lamps and torches.
2402 */ 2365 */
2366static void
2403void player_apply_lamp_cursed_effect (object *who, object *op) 2367player_apply_lamp_cursed_effect (object *who, object *op)
2404{ 2368{
2405 if (op->level) 2369 if (op->level)
2406 { 2370 {
2407 who->failmsg (format ( 2371 who->failmsg (format (
2408 "The %s was cursed, it explodes in a big fireball!", 2372 "The %s was cursed, it explodes in a big fireball!",
2423 * Apply for players and lamps 2387 * Apply for players and lamps
2424 * 2388 *
2425 * who - the player 2389 * who - the player
2426 * op - the lamp 2390 * op - the lamp
2427 */ 2391 */
2392static void
2428void player_apply_lamp (object *who, object *op) 2393player_apply_lamp (object *who, object *op)
2429{ 2394{
2430 bool switch_on = op->glow_radius ? false : true; 2395 bool switch_on = op->glow_radius ? false : true;
2431 2396
2432 if (switch_on) 2397 if (switch_on)
2433 { 2398 {
2546 if (op->other_arch) 2511 if (op->other_arch)
2547 get_animation_from_arch (op, switch_on ? op->other_arch : op->arch); 2512 get_animation_from_arch (op, switch_on ? op->other_arch : op->arch);
2548 2513
2549 if (object *pl = op->visible_to ()) 2514 if (object *pl = op->visible_to ())
2550 esrv_update_item (UPD_ANIM | UPD_FACE | UPD_NAME, pl, op); 2515 esrv_update_item (UPD_ANIM | UPD_FACE | UPD_NAME, pl, op);
2516}
2517
2518/**
2519 * This handles items of type 'transformer'.
2520 * Basically those items, used with a marked item, transform both items into something
2521 * else.
2522 * "Transformer" item has food decreased by 1, removed if 0 (0 at start means illimited)..
2523 * Change information is contained in the 'slaying' field of the marked item.
2524 * The format is as follow: transformer:[number ]yield[;transformer:...].
2525 * This way an item can be transformed in many things, and/or many objects.
2526 * The 'slaying' field for transformer is used as verb for the action.
2527 */
2528static void
2529apply_item_transformer (object *pl, object *transformer)
2530{
2531 object *marked;
2532 object *new_item;
2533 const char *find;
2534 char *separator;
2535 int yield;
2536 char got[MAX_BUF];
2537 int len;
2538
2539 if (!pl || !transformer)
2540 return;
2541
2542 marked = find_marked_object (pl);
2543
2544 if (!marked)
2545 {
2546 pl->failmsg (format ("Use the %s with what item?", query_name (transformer)));
2547 return;
2548 }
2549
2550 if (!marked->slaying)
2551 {
2552 pl->failmsg (format ("You can't use the %s with your %s!", query_name (transformer), query_name (marked)));
2553 return;
2554 }
2555
2556 /* check whether they are compatible or not */
2557 find = strstr (&marked->slaying, transformer->arch->archname);
2558 if (!find || (*(find + strlen (transformer->arch->archname)) != ':'))
2559 {
2560 pl->failmsg (format ("You can't use the %s with your %s!", query_name (transformer), query_name (marked)));
2561 return;
2562 }
2563
2564 find += strlen (transformer->arch->archname) + 1;
2565 /* Item can be used, now find how many and what it yields */
2566 if (isdigit (*(find)))
2567 {
2568 yield = atoi (find);
2569 if (yield < 1)
2570 {
2571 LOG (llevDebug, "apply_item_transformer: item %s has slaying-yield %d.", query_base_name (marked, 0), yield);
2572 yield = 1;
2573 }
2574 }
2575 else
2576 yield = 1;
2577
2578 while (isdigit (*find))
2579 find++;
2580
2581 while (*find == ' ')
2582 find++;
2583
2584 memset (got, 0, MAX_BUF);
2585
2586 if ((separator = (char *) strchr (find, ';')))
2587 len = separator - find;
2588 else
2589 len = strlen (find);
2590
2591 min_it (len, MAX_BUF - 1);
2592
2593 strcpy (got, find);
2594 got[len] = '\0';
2595
2596 /* Now create new item, remove used ones when required. */
2597 new_item = get_archetype (got);
2598 if (!new_item)
2599 {
2600 pl->failmsg (format ("This %s is strange, better to not use it.", query_base_name (marked, 0)));
2601 return;
2602 }
2603
2604 new_item->nrof = yield;
2605
2606 pl->statusmsg (format ("You %s the %s.", &transformer->slaying, query_base_name (marked, 0)));
2607
2608 pl->insert (new_item);
2609 /* Eat up one item */
2610 marked->decrease ();
2611
2612 /* Eat one transformer if needed */
2613 if (transformer->stats.food)
2614 if (--transformer->stats.food == 0)
2615 transformer->decrease ();
2551} 2616}
2552 2617
2553/** 2618/**
2554 * Main apply handler. 2619 * Main apply handler.
2555 * 2620 *
2586 if (INVOKE_OBJECT (APPLY, op, ARG_OBJECT (who))) 2651 if (INVOKE_OBJECT (APPLY, op, ARG_OBJECT (who)))
2587 return RESULT_INT (0); 2652 return RESULT_INT (0);
2588 2653
2589 switch (op->type) 2654 switch (op->type)
2590 { 2655 {
2591 case CF_HANDLE: 2656 case T_HANDLE:
2592 who->play_sound (sound_find ("turn_handle")); 2657 who->play_sound (sound_find ("turn_handle"));
2593 who->statusmsg ("You turn the handle."); 2658 who->statusmsg ("You turn the handle.");
2594 op->value = op->value ? 0 : 1; 2659 op->value = op->value ? 0 : 1;
2595 SET_ANIMATION (op, op->value); 2660 SET_ANIMATION (op, op->value);
2596 update_object (op, UP_OBJ_FACE); 2661 update_object (op, UP_OBJ_FACE);
2610 2675
2611 case EXIT: 2676 case EXIT:
2612 if (who->type != PLAYER) 2677 if (who->type != PLAYER)
2613 return 0; 2678 return 0;
2614 2679
2615 if (!EXIT_PATH (op) || !is_legal_2ways_exit (who, op)) 2680 if (!EXIT_PATH (op))
2616 who->failmsg (format ("The %s is closed. H<And will stay closed, until somebody fires up the map editor and adds it.>", query_name (op))); 2681 who->failmsg (format ("The %s is closed. H<And will stay closed, until somebody fires up the map editor and adds it.>", query_name (op)));
2617 else 2682 else
2618 { 2683 {
2619 /* Don't display messages for random maps. */ 2684 /* Don't display messages for random maps. */
2620 if (op->msg && !EXIT_PATH (op).starts_with ("/!")) 2685 if (op->msg && EXIT_PATH (op) != shstr_random_map_exit)
2621 who->statusmsg (op->msg, NDI_NAVY); 2686 who->statusmsg (op->msg, NDI_NAVY);
2622 2687
2623 who->enter_exit (op); 2688 who->enter_exit (op);
2624 } 2689 }
2625 2690
2706 case CLOAK: 2771 case CLOAK:
2707 case WAND: 2772 case WAND:
2708 case ROD: 2773 case ROD:
2709 case HORN: 2774 case HORN:
2710 case SKILL: 2775 case SKILL:
2776 case SPELL:
2711 case BOW: 2777 case BOW:
2778 case RANGED:
2712 case BUILDER: 2779 case BUILDER:
2713 case SKILL_TOOL: 2780 case SKILL_TOOL:
2714 if (op->env != who) 2781 if (op->env != who)
2715 return 2; /* not in inventory */ 2782 return 2; /* not in inventory */
2716 2783
2844 * we don't use a corrupt pointer for the next object, so we get the 2911 * we don't use a corrupt pointer for the next object, so we get the
2845 * next object in the stack before applying. This is can only be a 2912 * next object in the stack before applying. This is can only be a
2846 * problem if player_apply() has a bug in that it uses the object but does 2913 * problem if player_apply() has a bug in that it uses the object but does
2847 * not return a proper value. 2914 * not return a proper value.
2848 */ 2915 */
2849 for (object *next, *tmp = pl->container ? pl->container->inv : pl->below; tmp; tmp = next) 2916 for (object *next, *tmp = pl->container_ () ? pl->container_ ()->inv : pl->below; tmp; tmp = next)
2850 { 2917 {
2851 next = tmp->below; 2918 next = tmp->below;
2852 2919
2853 if (QUERY_FLAG (tmp, FLAG_IS_FLOOR)) 2920 if (QUERY_FLAG (tmp, FLAG_IS_FLOOR))
2854 floors++; 2921 floors++;
2880{ 2947{
2881 if (INVOKE_OBJECT (BE_UNREADY, op, ARG_OBJECT (who), ARG_INT (aflags)) 2948 if (INVOKE_OBJECT (BE_UNREADY, op, ARG_OBJECT (who), ARG_INT (aflags))
2882 || INVOKE_OBJECT (UNREADY, who, ARG_OBJECT (op), ARG_INT (aflags))) 2949 || INVOKE_OBJECT (UNREADY, who, ARG_OBJECT (op), ARG_INT (aflags)))
2883 return RESULT_INT (0); 2950 return RESULT_INT (0);
2884 2951
2885 CLEAR_FLAG (op, FLAG_APPLIED); 2952 if (who->current_weapon == op)
2953 who->current_weapon = 0;
2954
2955 op->flag [FLAG_APPLIED] = false;
2886 2956
2887 switch (op->type) 2957 switch (op->type)
2888 { 2958 {
2889 case SKILL_TOOL: 2959 case SKILL:
2960 if (player *pl = who->contr)
2961 if (op->invisible)
2962 pl->statusmsg (format ("You can no longer use the skill: %s.", &op->skill));
2963 else
2964 pl->statusmsg (format ("You stop using the %s.", query_name (op)));
2965
2966 change_abil (who, op);
2967 who->flag [FLAG_READY_SKILL] = false;
2968 break;
2969
2970 case WEAPON:
2971 who->statusmsg (format ("You unwield %s.", query_name (op)));
2972 change_abil (who, op);
2973 who->flag [FLAG_READY_WEAPON] = false;
2974
2890 // unapplying a skill tool should also unapply the skill it governs 2975 // unapplying a weapon or skill tool should also unapply the skill it governs
2891 // but this is hard, as it shouldn't do so when the skill can 2976 // but this is hard, as it shouldn't do so when the skill can
2892 // be used for other reasons 2977 // be used for other reasons
2893 for (object *tmp = who->inv; tmp; tmp = tmp->below) 2978 if (who->chosen_skill)
2894 if (tmp->skill == op->skill 2979 if (!who->chosen_skill->flag [FLAG_CAN_USE_SKILL])
2895 && tmp->type == SKILL
2896 && tmp->flag [FLAG_APPLIED]
2897 && !tmp->flag [FLAG_CAN_USE_SKILL])
2898 unapply_special (who, tmp, 0); 2980 unapply_special (who, op, 0);
2899 2981
2900 change_abil (who, op);
2901 break; 2982 break;
2902 2983
2984 case BOW:
2903 case WEAPON: 2985 case WAND:
2986 case ROD:
2987 case HORN:
2988 case RANGED:
2904 if (player *pl = who->contr) 2989 if (player *pl = who->contr)
2905 if (op == pl->combat_ob)
2906 {
2907 pl->combat_ob = 0;
2908 who->change_weapon (pl->ranged_ob);
2909 }
2910
2911 who->statusmsg (format ("You unwield %s.", query_name (op)));
2912
2913 change_abil (who, op);
2914 CLEAR_FLAG (who, FLAG_READY_WEAPON);
2915 break;
2916
2917 case SKILL:
2918 if (who->contr)
2919 { 2990 {
2920 if (IS_COMBAT_SKILL (op->subtype)) 2991 who->statusmsg (format ("You unready %s.", query_name (op)));
2921 who->change_weapon (who->contr->combat_ob = 0); 2992 change_abil (who, op);
2922 else if (IS_RANGED_SKILL (op->subtype)) 2993 }
2923 who->change_weapon (who->contr->ranged_ob = 0); 2994 else
2995 {
2996 who->change_skill (0);
2924 2997
2925 if (op->invisible) 2998 if (op->type == BOW)
2926 who->statusmsg (format ("You can no longer use the skill: %s.", &op->skill)); 2999 op->flag [FLAG_READY_BOW ] = false;
2927 else 3000 else
2928 who->statusmsg (format ("You stop using the %s.", query_name (op))); 3001 op->flag [FLAG_READY_RANGE] = false;
2929 } 3002 }
2930 3003
2931 change_abil (who, op);
2932 CLEAR_FLAG (who, FLAG_READY_SKILL);
2933 break; 3004 break;
2934 3005
2935 case ARMOUR: 3006 case ARMOUR:
2936 case HELMET: 3007 case HELMET:
2937 case SHIELD: 3008 case SHIELD:
2944 case CLOAK: 3015 case CLOAK:
2945 who->statusmsg (format ("You unwear %s.", query_name (op))); 3016 who->statusmsg (format ("You unwear %s.", query_name (op)));
2946 change_abil (who, op); 3017 change_abil (who, op);
2947 break; 3018 break;
2948 3019
3020 case SPELL:
2949 case BOW: 3021 case BUILDER:
2950 case WAND:
2951 case ROD:
2952 case HORN:
2953 if (player *pl = who->contr)
2954 {
2955 if (op == pl->ranged_ob)
2956 {
2957 pl->ranged_ob = 0;
2958 who->change_weapon (pl->combat_ob);
2959 }
2960
2961 who->statusmsg (format ("You unready %s.", query_name (op))); 3022 who->statusmsg (format ("You unready %s.", query_name (op)));
2962 }
2963 else
2964 {
2965 who->change_skill (0);
2966
2967 if (op->type == BOW)
2968 CLEAR_FLAG (who, FLAG_READY_BOW);
2969 else
2970 CLEAR_FLAG (who, FLAG_READY_RANGE);
2971 }
2972
2973 break; 3023 break;
2974 3024
2975 case BUILDER: 3025 //case SKILL_TOOL://TODO
2976 if (who->contr)
2977 who->statusmsg (format ("You unready %s.", query_name (op)));
2978 break;
2979
2980 default: 3026 default:
2981 who->statusmsg (format ("You unapply %s.", query_name (op))); 3027 who->statusmsg (format ("You unapply %s.", query_name (op)));
2982 break; 3028 break;
2983 } 3029 }
2984 3030
3032#define CANNOT_REMOVE_CURSED \ 3078#define CANNOT_REMOVE_CURSED \
3033 "H<You cannot remove cursed or damned items, you first have to remove the curse. " \ 3079 "H<You cannot remove cursed or damned items, you first have to remove the curse. " \
3034 "Praying over an altar, scrolls of remove curse/damnation, " \ 3080 "Praying over an altar, scrolls of remove curse/damnation, " \
3035 "priests or even other players might help.>" 3081 "priests or even other players might help.>"
3036 3082
3037int 3083static int
3038unapply_for_ob (object *who, object *op, int aflags) 3084unapply_for_ob (object *who, object *op, int aflags)
3039{ 3085{
3040 if (op->is_range ()) 3086 if (op->is_range ())
3041 for (object *tmp = who->inv; tmp; tmp = tmp->below) 3087 for (object *tmp = who->inv; tmp; tmp = tmp->below)
3042 if (QUERY_FLAG (tmp, FLAG_APPLIED) && tmp->is_range ()) 3088 if (QUERY_FLAG (tmp, FLAG_APPLIED) && tmp->is_range ())
3233 if (op->type == BOW && !QUERY_FLAG (who, FLAG_USE_BOW)) 3279 if (op->type == BOW && !QUERY_FLAG (who, FLAG_USE_BOW))
3234 retval |= CAN_APPLY_RESTRICTION; 3280 retval |= CAN_APPLY_RESTRICTION;
3235 } 3281 }
3236 3282
3237 return retval; 3283 return retval;
3284}
3285
3286// saner interface, returns successful status
3287bool
3288object::apply (object *ob, int aflags)
3289{
3290 bool want_apply = aflags & AP_APPLY;
3291
3292 if (ob->flag [FLAG_APPLIED] == want_apply)
3293 return true;
3294
3295 manual_apply (this, ob, aflags);
3296
3297 return ob->flag [FLAG_APPLIED] == want_apply;
3238} 3298}
3239 3299
3240/** 3300/**
3241 * who is the object using the object. It can be a monster. 3301 * who is the object using the object. It can be a monster.
3242 * op is the object they are using. op is an equipment type item, 3302 * op is the object they are using. op is an equipment type item,
3295 return unapply_special (who, op, aflags); 3355 return unapply_special (who, op, aflags);
3296 } 3356 }
3297 else if (basic_flag == AP_UNAPPLY) 3357 else if (basic_flag == AP_UNAPPLY)
3298 return 0; 3358 return 0;
3299 3359
3300 // if the item is combat/ranged, wield the relevant slot first
3301 // to resolve conflicts.
3302 if (player *pl = who->contr)
3303 switch (op->slottype ())
3304 {
3305 case slot_combat: who->change_weapon (pl->combat_ob); break;
3306 case slot_ranged: who->change_weapon (pl->ranged_ob); break;
3307 }
3308
3309 splay (op); 3360 splay (op);
3310 3361
3311 /* Can't just apply this object. Lets see what not and what to do */ 3362 /* Can't just apply this object. Lets see what not and what to do */
3312 if (int i = can_apply_object (who, op)) 3363 if (int i = can_apply_object (who, op))
3313 { 3364 {
3346 } 3397 }
3347 } 3398 }
3348 3399
3349 if (op->skill && op->type != SKILL && op->type != SKILL_TOOL) 3400 if (op->skill && op->type != SKILL && op->type != SKILL_TOOL)
3350 { 3401 {
3402 // try to ready attached skill first
3351 skop = find_skill_by_name (who, op->skill); 3403 skop = find_skill_by_name (who, op->skill);
3352 3404
3353 if (!skop) 3405 if (!skop)
3354 { 3406 {
3355 who->failmsg (format ("You need the %s skill to use this item!", &op->skill)); 3407 who->failmsg (format ("You need the %s skill to use this item!", &op->skill));
3356 return 1; 3408 return 1;
3357 } 3409 }
3358 else 3410 else if (!who->apply (skop, AP_APPLY | AP_HAVE_WEAPON))
3359 /* While experience will be credited properly, we want to change the
3360 * skill so that the dam and wc get updated
3361 */ 3411 {
3362 who->change_skill (skop); 3412 who->failmsg (format ("You can't use the required %s skill!", &op->skill));
3413 return 1;
3414 }
3363 } 3415 }
3364 3416
3365 if (!check_item_power (who, op->item_power)) 3417 if (!check_item_power (who, op->item_power))
3366 { 3418 {
3367 who->failmsg ("Equipping that combined with other items would consume your soul!" LACK_ITEM_POWER); 3419 who->failmsg ("Equipping that combined with other items would consume your soul!" LACK_ITEM_POWER);
3370 3422
3371 /* Ok. We are now at the state where we can apply the new object. 3423 /* Ok. We are now at the state where we can apply the new object.
3372 * Note that we don't have the checks for can_use_... 3424 * Note that we don't have the checks for can_use_...
3373 * below - that is already taken care of by can_apply_object. 3425 * below - that is already taken care of by can_apply_object.
3374 */ 3426 */
3427
3428 // split away all the other items from the stack, so only one item is left
3375 tmp = op->nrof > 1 ? op->split (op->nrof - 1) : 0; 3429 tmp = op->nrof > 1 ? op->split (op->nrof - 1) : 0;
3376 3430
3377 if (INVOKE_OBJECT (BE_READY, op, ARG_OBJECT (who)) || INVOKE_OBJECT (READY, who, ARG_OBJECT (op))) 3431 if (INVOKE_OBJECT (BE_READY, op, ARG_OBJECT (who)) || INVOKE_OBJECT (READY, who, ARG_OBJECT (op)))
3378 return RESULT_INT (0); 3432 return RESULT_INT (0);
3379 3433
3380 switch (op->type) 3434 switch (op->type)
3381 { 3435 {
3382 case WEAPON: 3436 case WEAPON:
3383 //TODO: this obviously fails for players using a shorter prefix 3437 if (op->level && (!op->name.starts_with (who->name) || op->name [who->name.length ()] != '\''))
3384 // i.e. "R" can use Ragnarok's sword.
3385 if (op->level && !op->name.starts_with (who->name))
3386 { 3438 {
3387 /* if the weapon does not have the name as the character, can't use it. */ 3439 /* if the weapon does not have the name as the character, can't use it. */
3388 /* (Ragnarok's sword attempted to be used by Foo: won't work) */ 3440 /* (Ragnarok's sword attempted to be used by Foo: won't work) */
3389 who->failmsg ("The weapon does not recognize you as its owner. H<Its name indicates that it belongs to somebody else.>"); 3441 who->failmsg ("The weapon does not recognize you as its owner. "
3390 3442 "H<Its name indicates that it belongs to somebody else.>");
3391 if (tmp) 3443 if (tmp) who->insert (tmp);
3392 insert_ob_in_ob (tmp, who);
3393
3394 return 1; 3444 return 1;
3395 } 3445 }
3396 3446
3397 if (!skop) 3447 op->flag [FLAG_APPLIED] = true;
3448
3449 if (player *pl = who->contr)
3398 { 3450 {
3399 who->failmsg (format ("The %s is broken, please report this to the dungeon master!", query_name (op)));//TODO 3451 who->current_weapon = pl->combat_ob = op;
3400 return 1; 3452 who->statusmsg (format ("You wield %s.", query_name (op)));
3453 change_abil (who, op);
3401 } 3454 }
3402 3455 else
3403 SET_FLAG (op, FLAG_APPLIED);
3404 who->change_skill (skop); 3456 who->change_skill (skop);
3405 3457
3406 if (who->contr) 3458 op->flag [FLAG_READY_WEAPON] = true;
3407 who->change_weapon (who->contr->combat_ob = op);
3408
3409 who->statusmsg (format ("You wield %s.", query_name (op)));
3410
3411 SET_FLAG (who, FLAG_READY_WEAPON);
3412 change_abil (who, op);
3413 break; 3459 break;
3414 3460
3415 case ARMOUR: 3461 case ARMOUR:
3416 case HELMET: 3462 case HELMET:
3417 case SHIELD: 3463 case SHIELD:
3426 who->statusmsg (format ("You wear %s.", query_name (op))); 3472 who->statusmsg (format ("You wear %s.", query_name (op)));
3427 change_abil (who, op); 3473 change_abil (who, op);
3428 break; 3474 break;
3429 3475
3430 case SKILL_TOOL: 3476 case SKILL_TOOL:
3431 // applying a skill tool also readies the skill 3477 // applying a skill tool does not ready the skill
3478 // if something needs the skill, it has to ready it itself
3479 //TODO: unapplying should unapply the skill, though
3432 SET_FLAG (op, FLAG_APPLIED); 3480 SET_FLAG (op, FLAG_APPLIED);
3481 break;
3433 3482
3434 if (!(aflags & AP_NO_READY)) 3483 case SKILL:
3484 if (skill_flags [op->subtype] & SF_NEED_ITEM && !(aflags & AP_HAVE_WEAPON))
3435 { 3485 {
3436 skop = find_skill_by_name (who, op->skill); 3486 who->failmsg (format (
3437 if (!skop->flag [FLAG_APPLIED]) 3487 "You feel as if you wanted to do something funny, but you can't remember what. "
3438 apply_special (who, skop, AP_APPLY); 3488 "H<The skill %s needs an item to function, it cannot be used on its own.>",
3489 &op->skill
3490 ));
3491 if (tmp) who->insert (tmp);
3492 return 1;
3439 } 3493 }
3440 break;
3441 3494
3442 case SKILL:
3443 if (player *pl = who->contr) 3495 if (player *pl = who->contr)
3444 { 3496 {
3445 if (IS_COMBAT_SKILL (op->subtype))
3446 {
3447 if (skill_flags [op->subtype] & SF_NEED_WEAPON) 3497 if (skill_flags [op->subtype] & SF_COMBAT)
3448 {
3449 for (object *item = who->inv; item; item = item->below)
3450 if (item->type == WEAPON && item->flag [FLAG_APPLIED])
3451 {
3452 if (item->skill == op->skill)
3453 {
3454 who->change_weapon (pl->combat_ob = item);
3455 goto found_weapon;
3456 }
3457 }
3458
3459 who->failmsg (format (
3460 "You need to apply a '%s' melee weapon before readying this skill. "
3461 "H<Some skills need an item, in this case a melee weapon, to function.>",
3462 &op->skill
3463 ));
3464 return 1;
3465
3466 found_weapon:;
3467 }
3468 else
3469 who->change_weapon (pl->combat_ob = op); 3498 who->current_weapon = pl->combat_ob = op;
3470 } 3499
3471 else if (IS_RANGED_SKILL (op->subtype))
3472 {
3473 if (skill_flags [op->subtype] & SF_NEED_BOW) 3500 if (skill_flags [op->subtype] & SF_RANGED)
3474 {
3475 for (object *item = who->inv; item; item = item->below)
3476 if (item->type == BOW && item->flag [FLAG_APPLIED])
3477 {
3478 //TODO: bows should/must all have skill missile weapon right now
3479 who->change_weapon (pl->ranged_ob = item);
3480 goto found_bow;
3481 }
3482
3483 who->failmsg (
3484 "You need to apply a missile weapon before readying this skill. "
3485 "H<Some skills need an item, in this case a missile weapon, to function.>"
3486 );
3487 return 1;
3488
3489 found_bow:;
3490 }
3491 else
3492 who->change_weapon (pl->ranged_ob = op); 3501 who->current_weapon = pl->ranged_ob = op;
3493 }
3494 3502
3495 if (!op->invisible) 3503 if (op->invisible)
3496 { 3504 who->statusmsg (format ("Readied skill: %s.", op->skill ? &op->skill : &op->name));
3497 who->statusmsg (format (
3498 "You ready %s."
3499 "You can now use the skill: %s.",
3500 query_name (op),
3501 &op->skill
3502 ));
3503 }
3504 else 3505 else
3505 who->statusmsg (format ("Readied skill: %s.", op->skill ? &op->skill : &op->name)); 3506 who->statusmsg (format (
3507 "You ready %s."
3508 "You can now use the skill: %s.",
3509 query_name (op),
3510 &op->skill
3511 ));
3506 } 3512 }
3507 else 3513
3508 {
3509 SET_FLAG (op, FLAG_APPLIED);
3510 change_abil (who, op);
3511 who->chosen_skill = op;
3512 SET_FLAG (who, FLAG_READY_SKILL); 3514 SET_FLAG (who, FLAG_READY_SKILL);
3513 } 3515 SET_FLAG (op, FLAG_APPLIED);
3514 3516 change_abil (who, op);
3515 break; 3517 break;
3516 3518
3517 case BOW: 3519 case BOW:
3518 if (op->level && !op->name.starts_with (who->name)) 3520 if (op->level && (!op->name.starts_with (who->name) || op->name [who->name.length ()] != '\''))
3519 { 3521 {
3520 who->failmsg ("The weapon does not recognize you as its owner. " 3522 who->failmsg ("The weapon does not recognize you as its owner. "
3521 "H<Its name indicates that it belongs to somebody else.>"); 3523 "H<Its name indicates that it belongs to somebody else.>");
3522 if (tmp) 3524 if (tmp) who->insert (tmp);
3523 insert_ob_in_ob (tmp, who);
3524
3525 return 1; 3525 return 1;
3526 } 3526 }
3527
3528 if (player *pl = who->contr)
3529 {
3530 op->flag [FLAG_APPLIED] = true;
3531 who->current_weapon = pl->ranged_ob = op;
3532 who->statusmsg (format ("You wield the %s.", query_name (op)));
3533 change_abil (who, op);
3534 }
3535 break;
3536
3537 case RANGED:
3538 if (player *pl = who->contr)
3539 {
3540 op->flag [FLAG_APPLIED] = true;
3541 who->current_weapon = pl->ranged_ob = op;
3542 who->statusmsg (format ("You applied the %s.", query_name (op)));
3543 }
3544 break;
3545
3546 case SPELL:
3547 if (player *pl = who->contr)
3548 {
3549 op->flag [FLAG_APPLIED] = true;
3550 who->current_weapon = pl->ranged_ob = op;
3551 who->statusmsg (format ("You ready the spell %s.", query_name (op)));
3552 }
3553 break;
3527 3554
3528 /*FALLTHROUGH*/ 3555 /*FALLTHROUGH*/
3529 case WAND: 3556 case WAND:
3530 case ROD: 3557 case ROD:
3531 case HORN: 3558 case HORN:
3532 /* check for skill, alter player status */ 3559 /* check for skill, alter player status */
3533 3560
3534 if (!skop) 3561 if (!skop)
3535 { 3562 {
3536 who->failmsg (format ("The %s is broken, please report this to the dungeon master!", query_name (op)));//TODO 3563 who->failmsg (format ("The %s is broken, please report this to the dungeon master!", query_name (op)));//TODO
3564 if (tmp) who->insert (tmp);
3537 return 1; 3565 return 1;
3538 } 3566 }
3539 3567
3540 SET_FLAG (op, FLAG_APPLIED); 3568 op->flag [FLAG_APPLIED] = true;
3541 who->change_skill (skop);
3542 3569
3543 if (who->contr) 3570 if (player *pl = who->contr)
3544 { 3571 {
3545 who->contr->ranged_ob = op;
3546
3547 who->statusmsg (format ("You ready %s.", query_name (op))); 3572 who->statusmsg (format ("You ready %s.", query_name (op)));
3573 who->current_weapon = pl->ranged_ob = op;
3548 3574
3549 if (op->type == BOW) 3575 if (op->type == BOW)
3550 {
3551 who->current_weapon = op;
3552 change_abil (who, op);
3553 who->statusmsg (format ("You will now fire %s with %s.", op->race ? &op->race : "nothing", query_name (op))); 3576 who->statusmsg (format ("You will now fire %s with %s.", op->race ? &op->race : "nothing", query_name (op)));
3554 } 3577
3578 change_abil (who, op);
3555 } 3579 }
3556 else 3580 else
3557 { 3581 {
3582 who->change_skill (skop);
3583
3558 if (op->type == BOW) 3584 if (op->type == BOW)
3559 SET_FLAG (who, FLAG_READY_BOW); 3585 op->flag [FLAG_READY_BOW ] = true;
3560 else 3586 else
3561 SET_FLAG (who, FLAG_READY_RANGE); 3587 op->flag [FLAG_READY_RANGE] = true;
3562 } 3588 }
3563 3589
3564 break; 3590 break;
3565 3591
3566 case BUILDER: 3592 case BUILDER:
3567 if (who->type == PLAYER) 3593 if (player *pl = who->contr)
3568 { 3594 {
3569 //TODO: wtf does this do? shouldn't this be managed automatically (slots?) 3595 who->current_weapon = pl->ranged_ob = op;
3570 if (who->contr->ranged_ob && who->contr->ranged_ob->type == BUILDER)
3571 unapply_special (who, who->contr->ranged_ob, 0);
3572
3573 who->statusmsg (format ("You ready your %s.", query_name (op))); 3596 who->statusmsg (format ("You ready your %s.", query_name (op)));
3574 3597 //TODO: change_abil?
3575 who->contr->ranged_ob = op;
3576 } 3598 }
3577 break; 3599 break;
3578 3600
3579 default: 3601 default:
3580 who->statusmsg (format ("You apply %s.", query_name (op))); 3602 who->statusmsg (format ("You apply %s.", query_name (op)));
3581 } 3603 }
3582 3604
3583 SET_FLAG (op, FLAG_APPLIED); 3605 SET_FLAG (op, FLAG_APPLIED);
3584 3606
3585 if (tmp)
3586 who->insert (tmp); 3607 if (tmp) who->insert (tmp);
3587 3608
3588 who->update_stats (); 3609 who->update_stats ();
3589 3610
3590 /* We exclude spell casting objects. The fire code will set the 3611 /* We exclude spell casting objects. The fire code will set the
3591 * been applied flag when they are used - until that point, 3612 * been applied flag when they are used - until that point,
3606 3627
3607 if (object *pl = op->visible_to ()) 3628 if (object *pl = op->visible_to ())
3608 esrv_send_item (pl, op); 3629 esrv_send_item (pl, op);
3609 3630
3610 return 0; 3631 return 0;
3611}
3612
3613int
3614monster_apply_special (object *who, object *op, int aflags)
3615{
3616 if (QUERY_FLAG (op, FLAG_UNPAID) && !QUERY_FLAG (op, FLAG_APPLIED))
3617 return 1;
3618
3619 return apply_special (who, op, aflags);
3620} 3632}
3621 3633
3622/** 3634/**
3623 * Map was just loaded, handle op's initialisation. 3635 * Map was just loaded, handle op's initialisation.
3624 * 3636 *
3731 * treasure again for this object 3743 * treasure again for this object
3732 */ 3744 */
3733 invtmp->randomitems = NULL; 3745 invtmp->randomitems = NULL;
3734 } 3746 }
3735 } 3747 }
3748
3736 /* This is really temporary - the code at the bottom will 3749 /* This is really temporary - the code at the bottom will
3737 * also set randomitems to null. The problem is there are bunches 3750 * also set randomitems to null. The problem is there are bunches
3738 * of maps/players already out there with items that have spells 3751 * of maps/players already out there with items that have spells
3739 * which haven't had the randomitems set to null yet. 3752 * which haven't had the randomitems set to null yet.
3740 * MSW 2004-05-13 3753 * MSW 2004-05-13
3744 * Ryo 2004-08-16 3757 * Ryo 2004-08-16
3745 */ 3758 */
3746 if (tmp->type == WAND || tmp->type == ROD || tmp->type == SCROLL 3759 if (tmp->type == WAND || tmp->type == ROD || tmp->type == SCROLL
3747 || tmp->type == HORN || tmp->type == FIREWALL || tmp->type == POTION || tmp->type == ALTAR || tmp->type == SPELLBOOK) 3760 || tmp->type == HORN || tmp->type == FIREWALL || tmp->type == POTION || tmp->type == ALTAR || tmp->type == SPELLBOOK)
3748 tmp->randomitems = NULL; 3761 tmp->randomitems = NULL;
3749
3750 } 3762 }
3751 3763
3752 if (QUERY_FLAG (tmp, FLAG_AUTO_APPLY)) 3764 if (QUERY_FLAG (tmp, FLAG_AUTO_APPLY))
3753 auto_apply (tmp); 3765 auto_apply (tmp);
3754 else if ((tmp->type == TREASURE || (tmp->type == CONTAINER)) && tmp->has_random_items ()) 3766 else if ((tmp->type == TREASURE || (tmp->type == CONTAINER)) && tmp->has_random_items ())
3811 /* bigger morsel of food = longer effect time */ 3823 /* bigger morsel of food = longer effect time */
3812 int duration = TIME2TICK (food->stats.food); 3824 int duration = TIME2TICK (food->stats.food);
3813 3825
3814 if (force = who->force_find (key)) 3826 if (force = who->force_find (key))
3815 { 3827 {
3816 if (duration > abs (force->speed_left / force->speed)) 3828 if (duration > fabs (force->speed_left / force->speed))
3817 { 3829 {
3818 new_draw_info_format (NDI_UNIQUE, 0, who, "More magical force spreads through you. H<The effect will last for about %.10g more seconds.>", TICK2TIME (duration)); 3830 new_draw_info_format (NDI_UNIQUE, 0, who, "More magical force spreads through you. H<The effect will last for about %.10g more seconds.>", TICK2TIME (duration));
3819 force->force_set_timer (duration); 3831 force->force_set_timer (duration);
3820 } 3832 }
3821 else 3833 else
3893 /* place limit on max sp from food? */ 3905 /* place limit on max sp from food? */
3894 } 3906 }
3895 } 3907 }
3896 3908
3897 who->update_stats (); 3909 who->update_stats ();
3898}
3899
3900
3901/**
3902 * op made some mistake with a scroll, this takes care of punishment.
3903 * scroll_failure()- hacked directly from spell_failure
3904 */
3905void
3906scroll_failure (object *op, int failure, int power)
3907{
3908 if (abs (failure / 4) > power)
3909 power = abs (failure / 4); /* set minimum effect */
3910
3911 if (failure <= -1 && failure > -15)
3912 { /* wonder */
3913 object *tmp;
3914
3915 op->failmsg ("Your spell warps!");
3916 tmp = get_archetype (SPELL_WONDER);
3917 cast_wonder (op, op, 0, tmp);
3918 tmp->destroy ();
3919 }
3920 else if (failure <= -15 && failure > -35)
3921 { /* drain mana */
3922 op->failmsg ("Your mana is drained!");
3923 op->stats.sp -= random_roll (0, power - 1, op, PREFER_LOW);
3924 if (op->stats.sp < 0)
3925 op->stats.sp = 0;
3926 }
3927 else if (settings.spell_failure_effects == TRUE)
3928 {
3929 if (failure <= -35 && failure > -60)
3930 { /* confusion */
3931 op->failmsg ("The magic recoils on you!");
3932 confuse_player (op, op, power);
3933 }
3934 else if (failure <= -60 && failure > -70)
3935 { /* paralysis */
3936 op->failmsg ("The magic recoils and paralyzes you!");
3937 paralyze_player (op, op, power);
3938 }
3939 else if (failure <= -70 && failure > -80)
3940 { /* blind */
3941 op->failmsg ("The magic recoils on you!");
3942 blind_player (op, op, power);
3943 }
3944 else if (failure <= -80)
3945 { /* blast the immediate area */
3946 object *tmp = get_archetype (LOOSE_MANA);
3947 cast_magic_storm (op, tmp, power);
3948 op->failmsg ("You unleash uncontrolled mana!");
3949 tmp->destroy ();
3950 }
3951 }
3952} 3910}
3953 3911
3954void 3912void
3955apply_changes_to_player (object *pl, object *change) 3913apply_changes_to_player (object *pl, object *change)
3956{ 3914{
4033 break; 3991 break;
4034 } 3992 }
4035 } 3993 }
4036} 3994}
4037 3995
4038/**
4039 * This handles items of type 'transformer'.
4040 * Basically those items, used with a marked item, transform both items into something
4041 * else.
4042 * "Transformer" item has food decreased by 1, removed if 0 (0 at start means illimited)..
4043 * Change information is contained in the 'slaying' field of the marked item.
4044 * The format is as follow: transformer:[number ]yield[;transformer:...].
4045 * This way an item can be transformed in many things, and/or many objects.
4046 * The 'slaying' field for transformer is used as verb for the action.
4047 */
4048void
4049apply_item_transformer (object *pl, object *transformer)
4050{
4051 object *marked;
4052 object *new_item;
4053 char *find;
4054 char *separator;
4055 int yield;
4056 char got[MAX_BUF];
4057 int len;
4058
4059 if (!pl || !transformer)
4060 return;
4061
4062 marked = find_marked_object (pl);
4063
4064 if (!marked)
4065 {
4066 pl->failmsg (format ("Use the %s with what item?", query_name (transformer)));
4067 return;
4068 }
4069
4070 if (!marked->slaying)
4071 {
4072 pl->failmsg (format ("You can't use the %s with your %s!", query_name (transformer), query_name (marked)));
4073 return;
4074 }
4075
4076 /* check whether they are compatible or not */
4077 find = strstr (&marked->slaying, transformer->arch->archname);
4078 if (!find || (*(find + strlen (transformer->arch->archname)) != ':'))
4079 {
4080 pl->failmsg (format ("You can't use the %s with your %s!", query_name (transformer), query_name (marked)));
4081 return;
4082 }
4083
4084 find += strlen (transformer->arch->archname) + 1;
4085 /* Item can be used, now find how many and what it yields */
4086 if (isdigit (*(find)))
4087 {
4088 yield = atoi (find);
4089 if (yield < 1)
4090 {
4091 LOG (llevDebug, "apply_item_transformer: item %s has slaying-yield %d.", query_base_name (marked, 0), yield);
4092 yield = 1;
4093 }
4094 }
4095 else
4096 yield = 1;
4097
4098 while (isdigit (*find))
4099 find++;
4100
4101 while (*find == ' ')
4102 find++;
4103
4104 memset (got, 0, MAX_BUF);
4105
4106 if ((separator = strchr (find, ';')) != NULL)
4107 len = separator - find;
4108 else
4109 len = strlen (find);
4110
4111 if (len > MAX_BUF - 1)
4112 len = MAX_BUF - 1;
4113
4114 strcpy (got, find);
4115 got[len] = '\0';
4116
4117 /* Now create new item, remove used ones when required. */
4118 new_item = get_archetype (got);
4119 if (!new_item)
4120 {
4121 pl->failmsg (format ("This %s is strange, better to not use it.", query_base_name (marked, 0)));
4122 return;
4123 }
4124
4125 new_item->nrof = yield;
4126
4127 pl->statusmsg (format ("You %s the %s.", &transformer->slaying, query_base_name (marked, 0)));
4128
4129 pl->insert (new_item);
4130 /* Eat up one item */
4131 marked->decrease ();
4132
4133 /* Eat one transformer if needed */
4134 if (transformer->stats.food)
4135 if (--transformer->stats.food == 0)
4136 transformer->decrease ();
4137}
4138

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines