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.216 by root, Sun Nov 29 17:41:07 2009 UTC

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);
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);
1601 SET_FLAG (tmp, FLAG_NO_SKILL_IDENT); /* so no more xp gained from this book */ 1602 SET_FLAG (tmp, FLAG_NO_SKILL_IDENT); /* so no more xp gained from this book */
1602 } 1603 }
1603} 1604}
1604 1605
1605/** 1606/**
1607 * op made some mistake with a scroll, this takes care of punishment.
1608 * scroll_failure()- hacked directly from spell_failure
1609 */
1610static void
1611scroll_failure (object *op, int failure, int power)
1612{
1613 if (abs (failure / 4) > power)
1614 power = abs (failure / 4); /* set minimum effect */
1615
1616 if (failure <= -1 && failure > -15)
1617 { /* wonder */
1618 object *tmp;
1619
1620 op->failmsg ("Your spell warps!");
1621 tmp = get_archetype (SPELL_WONDER);
1622 cast_wonder (op, op, 0, tmp);
1623 tmp->destroy ();
1624 }
1625 else if (failure <= -15 && failure > -35)
1626 { /* drain mana */
1627 op->failmsg ("Your mana is drained!");
1628 op->stats.sp -= random_roll (0, power - 1, op, PREFER_LOW);
1629 if (op->stats.sp < 0)
1630 op->stats.sp = 0;
1631 }
1632 else if (settings.spell_failure_effects == TRUE)
1633 {
1634 if (failure <= -35 && failure > -60)
1635 { /* confusion */
1636 op->failmsg ("The magic recoils on you!");
1637 confuse_player (op, op, power);
1638 }
1639 else if (failure <= -60 && failure > -70)
1640 { /* paralysis */
1641 op->failmsg ("The magic recoils and paralyzes you!");
1642 paralyze_player (op, op, power);
1643 }
1644 else if (failure <= -70 && failure > -80)
1645 { /* blind */
1646 op->failmsg ("The magic recoils on you!");
1647 blind_player (op, op, power);
1648 }
1649 else if (failure <= -80)
1650 { /* blast the immediate area */
1651 object *tmp = get_archetype (LOOSE_MANA);
1652 cast_magic_storm (op, tmp, power);
1653 op->failmsg ("You unleash uncontrolled mana!");
1654 tmp->destroy ();
1655 }
1656 }
1657}
1658
1659/**
1606 * Handles the applying of a skill scroll, calling learn_skill straight. 1660 * Handles the applying of a skill scroll, calling learn_skill straight.
1607 * op is the person learning the skill, tmp is the skill scroll object 1661 * op is the person learning the skill, tmp is the skill scroll object
1608 */ 1662 */
1609static void 1663static void
1610apply_skillscroll (object *op, object *tmp) 1664apply_skillscroll (object *op, object *tmp)
1712 * instead of having their spell stored in stats.sp. These are 1766 * instead of having their spell stored in stats.sp. These are
1713 * legacy spellbooks 1767 * legacy spellbooks
1714 */ 1768 */
1715 if (tmp->slaying) 1769 if (tmp->slaying)
1716 { 1770 {
1717 spell = arch_to_object (find_archetype_by_object_name (tmp->slaying)); 1771 spell = find_archetype_by_object_name (tmp->slaying)->instance ();
1772
1718 if (!spell) 1773 if (!spell)
1719 { 1774 {
1720 op->failmsg (format ("The book's formula for %s is incomplete.", &tmp->slaying)); 1775 op->failmsg (format ("The book's formula for %s is incomplete.", &tmp->slaying));
1721 return; 1776 return;
1722 } 1777 }
1799 * literacy rate very useful! -b.t. 1854 * literacy rate very useful! -b.t.
1800 */ 1855 */
1801 if (QUERY_FLAG (op, FLAG_CONFUSED)) 1856 if (QUERY_FLAG (op, FLAG_CONFUSED))
1802 { 1857 {
1803 op->failmsg ("In your confused state you flub the wording of the text!"); 1858 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)); 1859 scroll_failure (op, 0 - random_roll (0, spell->level, op, PREFER_LOW), max (spell->stats.sp, spell->stats.grace));
1805 } 1860 }
1806 else if (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || 1861 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]) 1862 (random_roll (0, 100, op, PREFER_LOW) - (5 * skop->level)) < learn_spell[spell->stats.grace ? op->stats.Wis : op->stats.Int])
1808 { 1863 {
1809 op->statusmsg ("You succeed in learning the spell!", NDI_GREEN); 1864 op->statusmsg ("You succeed in learning the spell!", NDI_GREEN);
1915 break; 1970 break;
1916 } 1971 }
1917 1972
1918 if (!tmp->destroyed () && !tmp->inv) 1973 if (!tmp->destroyed () && !tmp->inv)
1919 tmp->decrease (true); 1974 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} 1975}
1997 1976
1998/** 1977/**
1999 * A dragon is eating some flesh. If the flesh contains resistances, 1978 * A dragon is eating some flesh. If the flesh contains resistances,
2000 * there is a chance for the dragon's skin to get improved. 1979 * there is a chance for the dragon's skin to get improved.
2003 * object *op the object (dragon player) eating the flesh 1982 * object *op the object (dragon player) eating the flesh
2004 * object *meal the flesh item, getting chewed in dragon's mouth 1983 * object *meal the flesh item, getting chewed in dragon's mouth
2005 * return: 1984 * return:
2006 * int 1 if eating successful, 0 if it doesn't work 1985 * int 1 if eating successful, 0 if it doesn't work
2007 */ 1986 */
2008int 1987static int
2009dragon_eat_flesh (object *op, object *meal) 1988dragon_eat_flesh (object *op, object *meal)
2010{ 1989{
2011 object *skin = NULL; /* pointer to dragon skin force */ 1990 object *skin = NULL; /* pointer to dragon skin force */
2012 object *abil = NULL; /* pointer to dragon ability force */ 1991 object *abil = NULL; /* pointer to dragon ability force */
2013 object *tmp = NULL; /* tmp. object */ 1992 object *tmp = NULL; /* tmp. object */
2045 op->stats.hp += meal->stats.food / 50; 2024 op->stats.hp += meal->stats.food / 50;
2046 2025
2047 if (op->stats.hp > op->stats.maxhp) 2026 if (op->stats.hp > op->stats.maxhp)
2048 op->stats.hp = op->stats.maxhp; 2027 op->stats.hp = op->stats.maxhp;
2049 2028
2050 op->stats.food = MIN (999, op->stats.food + meal->stats.food); 2029 op->stats.food = min (999, 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 && is_dragon_pl (op) && dragon_eat_flesh (op, tmp))
2152 ;
2153 else
2154 {
2155 /* usual case - no dragon meal: */
2156 if (op->stats.food + tmp->stats.food > 999)
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 (!is_dragon_pl (op))
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 = 999 - 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 if (op->stats.hp > op->stats.maxhp)
2198 op->stats.hp = op->stats.maxhp;
2199 if (op->stats.food > 999)
2200 op->stats.food = 999;
2201 }
2202
2203 /* special food hack -b.t. */
2204 if (tmp->title || QUERY_FLAG (tmp, FLAG_CURSED))
2205 eat_special_food (op, tmp);
2206 }
2207 }
2208
2209 handle_apply_yield (tmp);
2210 tmp->decrease ();
2211}
2212
2213/**
2159 * Handles applying an improve armor scroll. 2214 * Handles applying an improve armor scroll.
2160 * Does some sanity checks, then calls improve_armour. 2215 * Does some sanity checks, then calls improve_armour.
2161 */ 2216 */
2162static void 2217static void
2163apply_armour_improver (object *op, object *tmp) 2218apply_armour_improver (object *op, object *tmp)
2225 * 2280 *
2226 * Note: a owner in a 2 way exit is saved as the owner's name 2281 * 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 2282 * 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). 2283 * survive in the swapping (in fact the whole exit doesn't survive).
2229 */ 2284 */
2230int 2285static int
2231is_legal_2ways_exit (object *op, object *exit) 2286is_legal_2ways_exit (object *op, object *exit)
2232{ 2287{
2233 if (exit->stats.exp != 1) 2288 if (exit->stats.exp != 1)
2234 return 1; /*This is not a 2 way, so it is legal */ 2289 return 1; /*This is not a 2 way, so it is legal */
2235 2290
2361/** 2416/**
2362 * Designed primarily to light torches/lanterns/etc. 2417 * Designed primarily to light torches/lanterns/etc.
2363 * Also burns up burnable material too. First object in the inventory is 2418 * Also burns up burnable material too. First object in the inventory is
2364 * the selected object to "burn". -b.t. 2419 * the selected object to "burn". -b.t.
2365 */ 2420 */
2366void 2421static void
2367apply_lighter (object *who, object *lighter) 2422apply_lighter (object *who, object *lighter)
2368{ 2423{
2369 object *item; 2424 object *item;
2370 int is_player_env = 0; 2425 int is_player_env = 0;
2371 2426
2398} 2453}
2399 2454
2400/** 2455/**
2401 * This function generates a cursed effect for cursed lamps and torches. 2456 * This function generates a cursed effect for cursed lamps and torches.
2402 */ 2457 */
2458static void
2403void player_apply_lamp_cursed_effect (object *who, object *op) 2459player_apply_lamp_cursed_effect (object *who, object *op)
2404{ 2460{
2405 if (op->level) 2461 if (op->level)
2406 { 2462 {
2407 who->failmsg (format ( 2463 who->failmsg (format (
2408 "The %s was cursed, it explodes in a big fireball!", 2464 "The %s was cursed, it explodes in a big fireball!",
2423 * Apply for players and lamps 2479 * Apply for players and lamps
2424 * 2480 *
2425 * who - the player 2481 * who - the player
2426 * op - the lamp 2482 * op - the lamp
2427 */ 2483 */
2484static void
2428void player_apply_lamp (object *who, object *op) 2485player_apply_lamp (object *who, object *op)
2429{ 2486{
2430 bool switch_on = op->glow_radius ? false : true; 2487 bool switch_on = op->glow_radius ? false : true;
2431 2488
2432 if (switch_on) 2489 if (switch_on)
2433 { 2490 {
2546 if (op->other_arch) 2603 if (op->other_arch)
2547 get_animation_from_arch (op, switch_on ? op->other_arch : op->arch); 2604 get_animation_from_arch (op, switch_on ? op->other_arch : op->arch);
2548 2605
2549 if (object *pl = op->visible_to ()) 2606 if (object *pl = op->visible_to ())
2550 esrv_update_item (UPD_ANIM | UPD_FACE | UPD_NAME, pl, op); 2607 esrv_update_item (UPD_ANIM | UPD_FACE | UPD_NAME, pl, op);
2608}
2609
2610/**
2611 * This handles items of type 'transformer'.
2612 * Basically those items, used with a marked item, transform both items into something
2613 * else.
2614 * "Transformer" item has food decreased by 1, removed if 0 (0 at start means illimited)..
2615 * Change information is contained in the 'slaying' field of the marked item.
2616 * The format is as follow: transformer:[number ]yield[;transformer:...].
2617 * This way an item can be transformed in many things, and/or many objects.
2618 * The 'slaying' field for transformer is used as verb for the action.
2619 */
2620static void
2621apply_item_transformer (object *pl, object *transformer)
2622{
2623 object *marked;
2624 object *new_item;
2625 char *find;
2626 char *separator;
2627 int yield;
2628 char got[MAX_BUF];
2629 int len;
2630
2631 if (!pl || !transformer)
2632 return;
2633
2634 marked = find_marked_object (pl);
2635
2636 if (!marked)
2637 {
2638 pl->failmsg (format ("Use the %s with what item?", query_name (transformer)));
2639 return;
2640 }
2641
2642 if (!marked->slaying)
2643 {
2644 pl->failmsg (format ("You can't use the %s with your %s!", query_name (transformer), query_name (marked)));
2645 return;
2646 }
2647
2648 /* check whether they are compatible or not */
2649 find = strstr (&marked->slaying, transformer->arch->archname);
2650 if (!find || (*(find + strlen (transformer->arch->archname)) != ':'))
2651 {
2652 pl->failmsg (format ("You can't use the %s with your %s!", query_name (transformer), query_name (marked)));
2653 return;
2654 }
2655
2656 find += strlen (transformer->arch->archname) + 1;
2657 /* Item can be used, now find how many and what it yields */
2658 if (isdigit (*(find)))
2659 {
2660 yield = atoi (find);
2661 if (yield < 1)
2662 {
2663 LOG (llevDebug, "apply_item_transformer: item %s has slaying-yield %d.", query_base_name (marked, 0), yield);
2664 yield = 1;
2665 }
2666 }
2667 else
2668 yield = 1;
2669
2670 while (isdigit (*find))
2671 find++;
2672
2673 while (*find == ' ')
2674 find++;
2675
2676 memset (got, 0, MAX_BUF);
2677
2678 if ((separator = strchr (find, ';')) != NULL)
2679 len = separator - find;
2680 else
2681 len = strlen (find);
2682
2683 if (len > MAX_BUF - 1)
2684 len = MAX_BUF - 1;
2685
2686 strcpy (got, find);
2687 got[len] = '\0';
2688
2689 /* Now create new item, remove used ones when required. */
2690 new_item = get_archetype (got);
2691 if (!new_item)
2692 {
2693 pl->failmsg (format ("This %s is strange, better to not use it.", query_base_name (marked, 0)));
2694 return;
2695 }
2696
2697 new_item->nrof = yield;
2698
2699 pl->statusmsg (format ("You %s the %s.", &transformer->slaying, query_base_name (marked, 0)));
2700
2701 pl->insert (new_item);
2702 /* Eat up one item */
2703 marked->decrease ();
2704
2705 /* Eat one transformer if needed */
2706 if (transformer->stats.food)
2707 if (--transformer->stats.food == 0)
2708 transformer->decrease ();
2551} 2709}
2552 2710
2553/** 2711/**
2554 * Main apply handler. 2712 * Main apply handler.
2555 * 2713 *
2586 if (INVOKE_OBJECT (APPLY, op, ARG_OBJECT (who))) 2744 if (INVOKE_OBJECT (APPLY, op, ARG_OBJECT (who)))
2587 return RESULT_INT (0); 2745 return RESULT_INT (0);
2588 2746
2589 switch (op->type) 2747 switch (op->type)
2590 { 2748 {
2591 case CF_HANDLE: 2749 case T_HANDLE:
2592 who->play_sound (sound_find ("turn_handle")); 2750 who->play_sound (sound_find ("turn_handle"));
2593 who->statusmsg ("You turn the handle."); 2751 who->statusmsg ("You turn the handle.");
2594 op->value = op->value ? 0 : 1; 2752 op->value = op->value ? 0 : 1;
2595 SET_ANIMATION (op, op->value); 2753 SET_ANIMATION (op, op->value);
2596 update_object (op, UP_OBJ_FACE); 2754 update_object (op, UP_OBJ_FACE);
2844 * we don't use a corrupt pointer for the next object, so we get the 3002 * 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 3003 * 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 3004 * problem if player_apply() has a bug in that it uses the object but does
2847 * not return a proper value. 3005 * not return a proper value.
2848 */ 3006 */
2849 for (object *next, *tmp = pl->container ? pl->container->inv : pl->below; tmp; tmp = next) 3007 for (object *next, *tmp = pl->container_ () ? pl->container_ ()->inv : pl->below; tmp; tmp = next)
2850 { 3008 {
2851 next = tmp->below; 3009 next = tmp->below;
2852 3010
2853 if (QUERY_FLAG (tmp, FLAG_IS_FLOOR)) 3011 if (QUERY_FLAG (tmp, FLAG_IS_FLOOR))
2854 floors++; 3012 floors++;
3032#define CANNOT_REMOVE_CURSED \ 3190#define CANNOT_REMOVE_CURSED \
3033 "H<You cannot remove cursed or damned items, you first have to remove the curse. " \ 3191 "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, " \ 3192 "Praying over an altar, scrolls of remove curse/damnation, " \
3035 "priests or even other players might help.>" 3193 "priests or even other players might help.>"
3036 3194
3037int 3195static int
3038unapply_for_ob (object *who, object *op, int aflags) 3196unapply_for_ob (object *who, object *op, int aflags)
3039{ 3197{
3040 if (op->is_range ()) 3198 if (op->is_range ())
3041 for (object *tmp = who->inv; tmp; tmp = tmp->below) 3199 for (object *tmp = who->inv; tmp; tmp = tmp->below)
3042 if (QUERY_FLAG (tmp, FLAG_APPLIED) && tmp->is_range ()) 3200 if (QUERY_FLAG (tmp, FLAG_APPLIED) && tmp->is_range ())
3608 esrv_send_item (pl, op); 3766 esrv_send_item (pl, op);
3609 3767
3610 return 0; 3768 return 0;
3611} 3769}
3612 3770
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}
3621
3622/** 3771/**
3623 * Map was just loaded, handle op's initialisation. 3772 * Map was just loaded, handle op's initialisation.
3624 * 3773 *
3625 * Generates shop floor's item, and treasures. 3774 * Generates shop floor's item, and treasures.
3626 */ 3775 */
3731 * treasure again for this object 3880 * treasure again for this object
3732 */ 3881 */
3733 invtmp->randomitems = NULL; 3882 invtmp->randomitems = NULL;
3734 } 3883 }
3735 } 3884 }
3885
3736 /* This is really temporary - the code at the bottom will 3886 /* This is really temporary - the code at the bottom will
3737 * also set randomitems to null. The problem is there are bunches 3887 * also set randomitems to null. The problem is there are bunches
3738 * of maps/players already out there with items that have spells 3888 * of maps/players already out there with items that have spells
3739 * which haven't had the randomitems set to null yet. 3889 * which haven't had the randomitems set to null yet.
3740 * MSW 2004-05-13 3890 * MSW 2004-05-13
3744 * Ryo 2004-08-16 3894 * Ryo 2004-08-16
3745 */ 3895 */
3746 if (tmp->type == WAND || tmp->type == ROD || tmp->type == SCROLL 3896 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) 3897 || tmp->type == HORN || tmp->type == FIREWALL || tmp->type == POTION || tmp->type == ALTAR || tmp->type == SPELLBOOK)
3748 tmp->randomitems = NULL; 3898 tmp->randomitems = NULL;
3749
3750 } 3899 }
3751 3900
3752 if (QUERY_FLAG (tmp, FLAG_AUTO_APPLY)) 3901 if (QUERY_FLAG (tmp, FLAG_AUTO_APPLY))
3753 auto_apply (tmp); 3902 auto_apply (tmp);
3754 else if ((tmp->type == TREASURE || (tmp->type == CONTAINER)) && tmp->has_random_items ()) 3903 else if ((tmp->type == TREASURE || (tmp->type == CONTAINER)) && tmp->has_random_items ())
3811 /* bigger morsel of food = longer effect time */ 3960 /* bigger morsel of food = longer effect time */
3812 int duration = TIME2TICK (food->stats.food); 3961 int duration = TIME2TICK (food->stats.food);
3813 3962
3814 if (force = who->force_find (key)) 3963 if (force = who->force_find (key))
3815 { 3964 {
3816 if (duration > abs (force->speed_left / force->speed)) 3965 if (duration > fabs (force->speed_left / force->speed))
3817 { 3966 {
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)); 3967 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); 3968 force->force_set_timer (duration);
3820 } 3969 }
3821 else 3970 else
3893 /* place limit on max sp from food? */ 4042 /* place limit on max sp from food? */
3894 } 4043 }
3895 } 4044 }
3896 4045
3897 who->update_stats (); 4046 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} 4047}
3953 4048
3954void 4049void
3955apply_changes_to_player (object *pl, object *change) 4050apply_changes_to_player (object *pl, object *change)
3956{ 4051{
4033 break; 4128 break;
4034 } 4129 }
4035 } 4130 }
4036} 4131}
4037 4132
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