… | |
… | |
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 | |
405 | static bool |
406 | bool |
|
|
407 | check_item_power (object *who, int item_power) |
406 | check_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 | */ |
537 | int |
536 | static int |
538 | prepare_weapon (object *op, object *improver, object *weapon) |
537 | prepare_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 | */ |
600 | int |
599 | static int |
601 | improve_weapon (object *op, object *improver, object *weapon) |
600 | improve_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 | */ |
712 | int |
711 | static int |
713 | check_improve_weapon (object *op, object *tmp) |
712 | check_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 | */ |
769 | int |
768 | static int |
770 | improve_armour (object *op, object *improver, object *armour) |
769 | improve_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 | */ |
863 | int |
862 | int |
864 | convert_item (object *item, object *converter) |
863 | convert_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 | */ |
990 | int |
989 | static int |
991 | apply_container (object *op, object *sack) |
990 | apply_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 | |
… | |
… | |
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 = -fabs (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 | */ |
… | |
… | |
1405 | * 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. |
1406 | * 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 |
1407 | * 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 |
1408 | * action, we avoid hits here |
1407 | * action, we avoid hits here |
1409 | */ |
1408 | */ |
1410 | 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) |
1411 | hit_with_arrow (trap, victim); |
1411 | hit_with_arrow (trap, victim); |
1412 | break; |
1412 | break; |
1413 | |
1413 | |
1414 | case SPELL_EFFECT: |
1414 | case SPELL_EFFECT: |
1415 | apply_spell_effect (trap, victim); |
1415 | apply_spell_effect (trap, victim); |
… | |
… | |
1598 | esrv_update_item (UPD_FLAGS | UPD_NAME, pl, tmp); |
1598 | esrv_update_item (UPD_FLAGS | UPD_NAME, pl, tmp); |
1599 | } |
1599 | } |
1600 | |
1600 | |
1601 | change_exp (op, exp_gain, skill_ob->skill, 0); |
1601 | change_exp (op, exp_gain, skill_ob->skill, 0); |
1602 | 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 */ |
|
|
1603 | } |
|
|
1604 | } |
|
|
1605 | |
|
|
1606 | /** |
|
|
1607 | * op made some mistake with a scroll, this takes care of punishment. |
|
|
1608 | * scroll_failure()- hacked directly from spell_failure |
|
|
1609 | */ |
|
|
1610 | static void |
|
|
1611 | scroll_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 | } |
1603 | } |
1656 | } |
1604 | } |
1657 | } |
1605 | |
1658 | |
1606 | /** |
1659 | /** |
1607 | * Handles the applying of a skill scroll, calling learn_skill straight. |
1660 | * Handles the applying of a skill scroll, calling learn_skill straight. |
… | |
… | |
1800 | * literacy rate very useful! -b.t. |
1853 | * literacy rate very useful! -b.t. |
1801 | */ |
1854 | */ |
1802 | if (QUERY_FLAG (op, FLAG_CONFUSED)) |
1855 | if (QUERY_FLAG (op, FLAG_CONFUSED)) |
1803 | { |
1856 | { |
1804 | op->failmsg ("In your confused state you flub the wording of the text!"); |
1857 | op->failmsg ("In your confused state you flub the wording of the text!"); |
1805 | scroll_failure (op, 0 - random_roll (0, spell->level, op, PREFER_LOW), MAX (spell->stats.sp, spell->stats.grace)); |
1858 | scroll_failure (op, 0 - random_roll (0, spell->level, op, PREFER_LOW), max (spell->stats.sp, spell->stats.grace)); |
1806 | } |
1859 | } |
1807 | else if (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || |
1860 | else if (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || |
1808 | (random_roll (0, 100, op, PREFER_LOW) - (5 * skop->level)) < learn_spell[spell->stats.grace ? op->stats.Wis : op->stats.Int]) |
1861 | (random_roll (0, 100, op, PREFER_LOW) - (5 * skop->level)) < learn_spell[spell->stats.grace ? op->stats.Wis : op->stats.Int]) |
1809 | { |
1862 | { |
1810 | op->statusmsg ("You succeed in learning the spell!", NDI_GREEN); |
1863 | op->statusmsg ("You succeed in learning the spell!", NDI_GREEN); |
… | |
… | |
1916 | break; |
1969 | break; |
1917 | } |
1970 | } |
1918 | |
1971 | |
1919 | if (!tmp->destroyed () && !tmp->inv) |
1972 | if (!tmp->destroyed () && !tmp->inv) |
1920 | tmp->decrease (true); |
1973 | tmp->decrease (true); |
1921 | } |
|
|
1922 | |
|
|
1923 | /** |
|
|
1924 | * op eats food. |
|
|
1925 | * If player, takes care of messages and dragon special food. |
|
|
1926 | */ |
|
|
1927 | static void |
|
|
1928 | apply_food (object *op, object *tmp) |
|
|
1929 | { |
|
|
1930 | int capacity_remaining; |
|
|
1931 | |
|
|
1932 | if (op->type != PLAYER) |
|
|
1933 | op->stats.hp = op->stats.maxhp; |
|
|
1934 | else |
|
|
1935 | { |
|
|
1936 | /* check if this is a dragon (player), eating some flesh */ |
|
|
1937 | if (tmp->type == FLESH && is_dragon_pl (op) && dragon_eat_flesh (op, tmp)) |
|
|
1938 | ; |
|
|
1939 | else |
|
|
1940 | { |
|
|
1941 | /* usual case - no dragon meal: */ |
|
|
1942 | if (op->stats.food + tmp->stats.food > 999) |
|
|
1943 | { |
|
|
1944 | if (tmp->type == FOOD || tmp->type == FLESH) |
|
|
1945 | op->failmsg ("You feel full, but what a waste of food!"); |
|
|
1946 | else |
|
|
1947 | op->statusmsg ("Most of the drink goes down your face not your throat!"); |
|
|
1948 | } |
|
|
1949 | |
|
|
1950 | tmp->play_sound ( |
|
|
1951 | tmp->sound |
|
|
1952 | ? tmp->sound |
|
|
1953 | : tmp->type == DRINK |
|
|
1954 | ? sound_find ("eat_drink") |
|
|
1955 | : sound_find ("eat_food") |
|
|
1956 | ); |
|
|
1957 | |
|
|
1958 | if (!QUERY_FLAG (tmp, FLAG_CURSED)) |
|
|
1959 | { |
|
|
1960 | const char *buf; |
|
|
1961 | |
|
|
1962 | if (!is_dragon_pl (op)) |
|
|
1963 | { |
|
|
1964 | /* eating message for normal players */ |
|
|
1965 | if (tmp->type == DRINK) |
|
|
1966 | buf = format ("Ahhh...that %s tasted good.", &tmp->name); |
|
|
1967 | else |
|
|
1968 | buf = format ("The %s tasted %s", &tmp->name, tmp->type == FLESH ? "terrible!" : "good."); |
|
|
1969 | } |
|
|
1970 | else |
|
|
1971 | /* eating message for dragon players */ |
|
|
1972 | buf = format ("The %s tasted terrible!", &tmp->name); |
|
|
1973 | |
|
|
1974 | op->statusmsg (buf); |
|
|
1975 | |
|
|
1976 | capacity_remaining = 999 - op->stats.food; |
|
|
1977 | op->stats.food += tmp->stats.food; |
|
|
1978 | if (capacity_remaining < tmp->stats.food) |
|
|
1979 | op->stats.hp += capacity_remaining / 50; |
|
|
1980 | else |
|
|
1981 | op->stats.hp += tmp->stats.food / 50; |
|
|
1982 | |
|
|
1983 | if (op->stats.hp > op->stats.maxhp) |
|
|
1984 | op->stats.hp = op->stats.maxhp; |
|
|
1985 | if (op->stats.food > 999) |
|
|
1986 | op->stats.food = 999; |
|
|
1987 | } |
|
|
1988 | |
|
|
1989 | /* special food hack -b.t. */ |
|
|
1990 | if (tmp->title || QUERY_FLAG (tmp, FLAG_CURSED)) |
|
|
1991 | eat_special_food (op, tmp); |
|
|
1992 | } |
|
|
1993 | } |
|
|
1994 | |
|
|
1995 | handle_apply_yield (tmp); |
|
|
1996 | tmp->decrease (); |
|
|
1997 | } |
1974 | } |
1998 | |
1975 | |
1999 | /** |
1976 | /** |
2000 | * A dragon is eating some flesh. If the flesh contains resistances, |
1977 | * A dragon is eating some flesh. If the flesh contains resistances, |
2001 | * there is a chance for the dragon's skin to get improved. |
1978 | * there is a chance for the dragon's skin to get improved. |
… | |
… | |
2004 | * object *op the object (dragon player) eating the flesh |
1981 | * object *op the object (dragon player) eating the flesh |
2005 | * object *meal the flesh item, getting chewed in dragon's mouth |
1982 | * object *meal the flesh item, getting chewed in dragon's mouth |
2006 | * return: |
1983 | * return: |
2007 | * int 1 if eating successful, 0 if it doesn't work |
1984 | * int 1 if eating successful, 0 if it doesn't work |
2008 | */ |
1985 | */ |
2009 | int |
1986 | static int |
2010 | dragon_eat_flesh (object *op, object *meal) |
1987 | dragon_eat_flesh (object *op, object *meal) |
2011 | { |
1988 | { |
2012 | object *skin = NULL; /* pointer to dragon skin force */ |
1989 | object *skin = NULL; /* pointer to dragon skin force */ |
2013 | object *abil = NULL; /* pointer to dragon ability force */ |
1990 | object *abil = NULL; /* pointer to dragon ability force */ |
2014 | object *tmp = NULL; /* tmp. object */ |
1991 | object *tmp = NULL; /* tmp. object */ |
… | |
… | |
2046 | op->stats.hp += meal->stats.food / 50; |
2023 | op->stats.hp += meal->stats.food / 50; |
2047 | |
2024 | |
2048 | if (op->stats.hp > op->stats.maxhp) |
2025 | if (op->stats.hp > op->stats.maxhp) |
2049 | op->stats.hp = op->stats.maxhp; |
2026 | op->stats.hp = op->stats.maxhp; |
2050 | |
2027 | |
2051 | op->stats.food = MIN (999, op->stats.food + meal->stats.food); |
2028 | op->stats.food = min (999, op->stats.food + meal->stats.food); |
2052 | |
2029 | |
2053 | /*LOG(llevDebug, "-> player: %d, flesh: %d\n", op->level, meal->level); */ |
2030 | /*LOG(llevDebug, "-> player: %d, flesh: %d\n", op->level, meal->level); */ |
2054 | |
2031 | |
2055 | /* on to the interesting part: chances for adding resistance */ |
2032 | /* on to the interesting part: chances for adding resistance */ |
2056 | for (i = 0; i < NROFATTACKS; i++) |
2033 | for (i = 0; i < NROFATTACKS; i++) |
… | |
… | |
2066 | |
2043 | |
2067 | /* monster bonus increases with level, because high-level |
2044 | /* monster bonus increases with level, because high-level |
2068 | flesh is too rare */ |
2045 | flesh is too rare */ |
2069 | mbonus = op->level * 20. / ((double) settings.max_level); |
2046 | mbonus = op->level * 20. / ((double) settings.max_level); |
2070 | |
2047 | |
2071 | chance = (((double) MIN (op->level + bonus, meal->level + bonus + mbonus)) * 100. / |
2048 | chance = (((double)min (op->level + bonus, meal->level + bonus + mbonus)) * 100. / |
2072 | ((double) settings.max_level)) - skin->resist[i]; |
2049 | ((double)settings.max_level)) - skin->resist[i]; |
2073 | |
2050 | |
2074 | if (chance >= 0.) |
2051 | if (chance >= 0.) |
2075 | chance += 1.; |
2052 | chance += 1.; |
2076 | else |
2053 | else |
2077 | chance = (chance < -12) ? 0. : 1. / pow (2., -chance); |
2054 | chance = (chance < -12) ? 0. : 1. / pow (2., -chance); |
2078 | |
2055 | |
2079 | /* chance is proportional to amount of resistance (max. 50) */ |
2056 | /* chance is proportional to amount of resistance (max. 50) */ |
2080 | chance *= ((double) (MIN (meal->resist[i], 50))) / 50.; |
2057 | chance *= ((double)(min (meal->resist[i], 50))) / 50.; |
2081 | |
2058 | |
2082 | /* doubled chance for resistance of ability-focus */ |
2059 | /* doubled chance for resistance of ability-focus */ |
2083 | if (i == abil->stats.exp) |
2060 | if (i == abil->stats.exp) |
2084 | chance = MIN (100., chance * 2.); |
2061 | chance = min (100., chance * 2.); |
2085 | |
2062 | |
2086 | /* now make the throw and save all winners (Don't insert luck bonus here!) */ |
2063 | /* now make the throw and save all winners (Don't insert luck bonus here!) */ |
2087 | if (rndm (10000) < (unsigned int) (chance * 100)) |
2064 | if (rndm (10000) < (unsigned int)(chance * 100)) |
2088 | { |
2065 | { |
2089 | atnr_winner[winners] = i; |
2066 | atnr_winner[winners] = i; |
2090 | winners++; |
2067 | winners++; |
2091 | } |
2068 | } |
2092 | |
2069 | |
… | |
… | |
2155 | |
2132 | |
2156 | return 1; |
2133 | return 1; |
2157 | } |
2134 | } |
2158 | |
2135 | |
2159 | /** |
2136 | /** |
|
|
2137 | * op eats food. |
|
|
2138 | * If player, takes care of messages and dragon special food. |
|
|
2139 | */ |
|
|
2140 | static void |
|
|
2141 | apply_food (object *op, object *tmp) |
|
|
2142 | { |
|
|
2143 | int capacity_remaining; |
|
|
2144 | |
|
|
2145 | if (op->type != PLAYER) |
|
|
2146 | op->stats.hp = op->stats.maxhp; |
|
|
2147 | else |
|
|
2148 | { |
|
|
2149 | /* check if this is a dragon (player), eating some flesh */ |
|
|
2150 | if (tmp->type == FLESH && is_dragon_pl (op) && dragon_eat_flesh (op, tmp)) |
|
|
2151 | ; |
|
|
2152 | else |
|
|
2153 | { |
|
|
2154 | /* usual case - no dragon meal: */ |
|
|
2155 | if (op->stats.food + tmp->stats.food > 999) |
|
|
2156 | { |
|
|
2157 | if (tmp->type == FOOD || tmp->type == FLESH) |
|
|
2158 | op->failmsg ("You feel full, but what a waste of food!"); |
|
|
2159 | else |
|
|
2160 | op->statusmsg ("Most of the drink goes down your face not your throat!"); |
|
|
2161 | } |
|
|
2162 | |
|
|
2163 | tmp->play_sound ( |
|
|
2164 | tmp->sound |
|
|
2165 | ? tmp->sound |
|
|
2166 | : tmp->type == DRINK |
|
|
2167 | ? sound_find ("eat_drink") |
|
|
2168 | : sound_find ("eat_food") |
|
|
2169 | ); |
|
|
2170 | |
|
|
2171 | if (!QUERY_FLAG (tmp, FLAG_CURSED)) |
|
|
2172 | { |
|
|
2173 | const char *buf; |
|
|
2174 | |
|
|
2175 | if (!is_dragon_pl (op)) |
|
|
2176 | { |
|
|
2177 | /* eating message for normal players */ |
|
|
2178 | if (tmp->type == DRINK) |
|
|
2179 | buf = format ("Ahhh...that %s tasted good.", &tmp->name); |
|
|
2180 | else |
|
|
2181 | buf = format ("The %s tasted %s", &tmp->name, tmp->type == FLESH ? "terrible!" : "good."); |
|
|
2182 | } |
|
|
2183 | else |
|
|
2184 | /* eating message for dragon players */ |
|
|
2185 | buf = format ("The %s tasted terrible!", &tmp->name); |
|
|
2186 | |
|
|
2187 | op->statusmsg (buf); |
|
|
2188 | |
|
|
2189 | capacity_remaining = 999 - op->stats.food; |
|
|
2190 | op->stats.food += tmp->stats.food; |
|
|
2191 | if (capacity_remaining < tmp->stats.food) |
|
|
2192 | op->stats.hp += capacity_remaining / 50; |
|
|
2193 | else |
|
|
2194 | op->stats.hp += tmp->stats.food / 50; |
|
|
2195 | |
|
|
2196 | if (op->stats.hp > op->stats.maxhp) |
|
|
2197 | op->stats.hp = op->stats.maxhp; |
|
|
2198 | if (op->stats.food > 999) |
|
|
2199 | op->stats.food = 999; |
|
|
2200 | } |
|
|
2201 | |
|
|
2202 | /* special food hack -b.t. */ |
|
|
2203 | if (tmp->title || QUERY_FLAG (tmp, FLAG_CURSED)) |
|
|
2204 | eat_special_food (op, tmp); |
|
|
2205 | } |
|
|
2206 | } |
|
|
2207 | |
|
|
2208 | handle_apply_yield (tmp); |
|
|
2209 | tmp->decrease (); |
|
|
2210 | } |
|
|
2211 | |
|
|
2212 | /** |
2160 | * Handles applying an improve armor scroll. |
2213 | * Handles applying an improve armor scroll. |
2161 | * Does some sanity checks, then calls improve_armour. |
2214 | * Does some sanity checks, then calls improve_armour. |
2162 | */ |
2215 | */ |
2163 | static void |
2216 | static void |
2164 | apply_armour_improver (object *op, object *tmp) |
2217 | apply_armour_improver (object *op, object *tmp) |
… | |
… | |
2226 | * |
2279 | * |
2227 | * Note: a owner in a 2 way exit is saved as the owner's name |
2280 | * Note: a owner in a 2 way exit is saved as the owner's name |
2228 | * in the field exit->name cause the field exit->owner doesn't |
2281 | * in the field exit->name cause the field exit->owner doesn't |
2229 | * survive in the swapping (in fact the whole exit doesn't survive). |
2282 | * survive in the swapping (in fact the whole exit doesn't survive). |
2230 | */ |
2283 | */ |
2231 | int |
2284 | static int |
2232 | is_legal_2ways_exit (object *op, object *exit) |
2285 | is_legal_2ways_exit (object *op, object *exit) |
2233 | { |
2286 | { |
2234 | if (exit->stats.exp != 1) |
2287 | if (exit->stats.exp != 1) |
2235 | return 1; /*This is not a 2 way, so it is legal */ |
2288 | return 1; /*This is not a 2 way, so it is legal */ |
2236 | |
2289 | |
… | |
… | |
2362 | /** |
2415 | /** |
2363 | * Designed primarily to light torches/lanterns/etc. |
2416 | * Designed primarily to light torches/lanterns/etc. |
2364 | * Also burns up burnable material too. First object in the inventory is |
2417 | * Also burns up burnable material too. First object in the inventory is |
2365 | * the selected object to "burn". -b.t. |
2418 | * the selected object to "burn". -b.t. |
2366 | */ |
2419 | */ |
2367 | void |
2420 | static void |
2368 | apply_lighter (object *who, object *lighter) |
2421 | apply_lighter (object *who, object *lighter) |
2369 | { |
2422 | { |
2370 | object *item; |
2423 | object *item; |
2371 | int is_player_env = 0; |
2424 | int is_player_env = 0; |
2372 | |
2425 | |
… | |
… | |
2399 | } |
2452 | } |
2400 | |
2453 | |
2401 | /** |
2454 | /** |
2402 | * This function generates a cursed effect for cursed lamps and torches. |
2455 | * This function generates a cursed effect for cursed lamps and torches. |
2403 | */ |
2456 | */ |
|
|
2457 | static void |
2404 | void player_apply_lamp_cursed_effect (object *who, object *op) |
2458 | player_apply_lamp_cursed_effect (object *who, object *op) |
2405 | { |
2459 | { |
2406 | if (op->level) |
2460 | if (op->level) |
2407 | { |
2461 | { |
2408 | who->failmsg (format ( |
2462 | who->failmsg (format ( |
2409 | "The %s was cursed, it explodes in a big fireball!", |
2463 | "The %s was cursed, it explodes in a big fireball!", |
… | |
… | |
2424 | * Apply for players and lamps |
2478 | * Apply for players and lamps |
2425 | * |
2479 | * |
2426 | * who - the player |
2480 | * who - the player |
2427 | * op - the lamp |
2481 | * op - the lamp |
2428 | */ |
2482 | */ |
|
|
2483 | static void |
2429 | void player_apply_lamp (object *who, object *op) |
2484 | player_apply_lamp (object *who, object *op) |
2430 | { |
2485 | { |
2431 | bool switch_on = op->glow_radius ? false : true; |
2486 | bool switch_on = op->glow_radius ? false : true; |
2432 | |
2487 | |
2433 | if (switch_on) |
2488 | if (switch_on) |
2434 | { |
2489 | { |
… | |
… | |
2547 | if (op->other_arch) |
2602 | if (op->other_arch) |
2548 | get_animation_from_arch (op, switch_on ? op->other_arch : op->arch); |
2603 | get_animation_from_arch (op, switch_on ? op->other_arch : op->arch); |
2549 | |
2604 | |
2550 | if (object *pl = op->visible_to ()) |
2605 | if (object *pl = op->visible_to ()) |
2551 | esrv_update_item (UPD_ANIM | UPD_FACE | UPD_NAME, pl, op); |
2606 | esrv_update_item (UPD_ANIM | UPD_FACE | UPD_NAME, pl, op); |
|
|
2607 | } |
|
|
2608 | |
|
|
2609 | /** |
|
|
2610 | * This handles items of type 'transformer'. |
|
|
2611 | * Basically those items, used with a marked item, transform both items into something |
|
|
2612 | * else. |
|
|
2613 | * "Transformer" item has food decreased by 1, removed if 0 (0 at start means illimited).. |
|
|
2614 | * Change information is contained in the 'slaying' field of the marked item. |
|
|
2615 | * The format is as follow: transformer:[number ]yield[;transformer:...]. |
|
|
2616 | * This way an item can be transformed in many things, and/or many objects. |
|
|
2617 | * The 'slaying' field for transformer is used as verb for the action. |
|
|
2618 | */ |
|
|
2619 | static void |
|
|
2620 | apply_item_transformer (object *pl, object *transformer) |
|
|
2621 | { |
|
|
2622 | object *marked; |
|
|
2623 | object *new_item; |
|
|
2624 | char *find; |
|
|
2625 | char *separator; |
|
|
2626 | int yield; |
|
|
2627 | char got[MAX_BUF]; |
|
|
2628 | int len; |
|
|
2629 | |
|
|
2630 | if (!pl || !transformer) |
|
|
2631 | return; |
|
|
2632 | |
|
|
2633 | marked = find_marked_object (pl); |
|
|
2634 | |
|
|
2635 | if (!marked) |
|
|
2636 | { |
|
|
2637 | pl->failmsg (format ("Use the %s with what item?", query_name (transformer))); |
|
|
2638 | return; |
|
|
2639 | } |
|
|
2640 | |
|
|
2641 | if (!marked->slaying) |
|
|
2642 | { |
|
|
2643 | pl->failmsg (format ("You can't use the %s with your %s!", query_name (transformer), query_name (marked))); |
|
|
2644 | return; |
|
|
2645 | } |
|
|
2646 | |
|
|
2647 | /* check whether they are compatible or not */ |
|
|
2648 | find = strstr (&marked->slaying, transformer->arch->archname); |
|
|
2649 | if (!find || (*(find + strlen (transformer->arch->archname)) != ':')) |
|
|
2650 | { |
|
|
2651 | pl->failmsg (format ("You can't use the %s with your %s!", query_name (transformer), query_name (marked))); |
|
|
2652 | return; |
|
|
2653 | } |
|
|
2654 | |
|
|
2655 | find += strlen (transformer->arch->archname) + 1; |
|
|
2656 | /* Item can be used, now find how many and what it yields */ |
|
|
2657 | if (isdigit (*(find))) |
|
|
2658 | { |
|
|
2659 | yield = atoi (find); |
|
|
2660 | if (yield < 1) |
|
|
2661 | { |
|
|
2662 | LOG (llevDebug, "apply_item_transformer: item %s has slaying-yield %d.", query_base_name (marked, 0), yield); |
|
|
2663 | yield = 1; |
|
|
2664 | } |
|
|
2665 | } |
|
|
2666 | else |
|
|
2667 | yield = 1; |
|
|
2668 | |
|
|
2669 | while (isdigit (*find)) |
|
|
2670 | find++; |
|
|
2671 | |
|
|
2672 | while (*find == ' ') |
|
|
2673 | find++; |
|
|
2674 | |
|
|
2675 | memset (got, 0, MAX_BUF); |
|
|
2676 | |
|
|
2677 | if ((separator = strchr (find, ';')) != NULL) |
|
|
2678 | len = separator - find; |
|
|
2679 | else |
|
|
2680 | len = strlen (find); |
|
|
2681 | |
|
|
2682 | if (len > MAX_BUF - 1) |
|
|
2683 | len = MAX_BUF - 1; |
|
|
2684 | |
|
|
2685 | strcpy (got, find); |
|
|
2686 | got[len] = '\0'; |
|
|
2687 | |
|
|
2688 | /* Now create new item, remove used ones when required. */ |
|
|
2689 | new_item = get_archetype (got); |
|
|
2690 | if (!new_item) |
|
|
2691 | { |
|
|
2692 | pl->failmsg (format ("This %s is strange, better to not use it.", query_base_name (marked, 0))); |
|
|
2693 | return; |
|
|
2694 | } |
|
|
2695 | |
|
|
2696 | new_item->nrof = yield; |
|
|
2697 | |
|
|
2698 | pl->statusmsg (format ("You %s the %s.", &transformer->slaying, query_base_name (marked, 0))); |
|
|
2699 | |
|
|
2700 | pl->insert (new_item); |
|
|
2701 | /* Eat up one item */ |
|
|
2702 | marked->decrease (); |
|
|
2703 | |
|
|
2704 | /* Eat one transformer if needed */ |
|
|
2705 | if (transformer->stats.food) |
|
|
2706 | if (--transformer->stats.food == 0) |
|
|
2707 | transformer->decrease (); |
2552 | } |
2708 | } |
2553 | |
2709 | |
2554 | /** |
2710 | /** |
2555 | * Main apply handler. |
2711 | * Main apply handler. |
2556 | * |
2712 | * |
… | |
… | |
3033 | #define CANNOT_REMOVE_CURSED \ |
3189 | #define CANNOT_REMOVE_CURSED \ |
3034 | "H<You cannot remove cursed or damned items, you first have to remove the curse. " \ |
3190 | "H<You cannot remove cursed or damned items, you first have to remove the curse. " \ |
3035 | "Praying over an altar, scrolls of remove curse/damnation, " \ |
3191 | "Praying over an altar, scrolls of remove curse/damnation, " \ |
3036 | "priests or even other players might help.>" |
3192 | "priests or even other players might help.>" |
3037 | |
3193 | |
3038 | int |
3194 | static int |
3039 | unapply_for_ob (object *who, object *op, int aflags) |
3195 | unapply_for_ob (object *who, object *op, int aflags) |
3040 | { |
3196 | { |
3041 | if (op->is_range ()) |
3197 | if (op->is_range ()) |
3042 | for (object *tmp = who->inv; tmp; tmp = tmp->below) |
3198 | for (object *tmp = who->inv; tmp; tmp = tmp->below) |
3043 | if (QUERY_FLAG (tmp, FLAG_APPLIED) && tmp->is_range ()) |
3199 | if (QUERY_FLAG (tmp, FLAG_APPLIED) && tmp->is_range ()) |
… | |
… | |
3607 | |
3763 | |
3608 | if (object *pl = op->visible_to ()) |
3764 | if (object *pl = op->visible_to ()) |
3609 | esrv_send_item (pl, op); |
3765 | esrv_send_item (pl, op); |
3610 | |
3766 | |
3611 | return 0; |
3767 | return 0; |
3612 | } |
|
|
3613 | |
|
|
3614 | int |
|
|
3615 | monster_apply_special (object *who, object *op, int aflags) |
|
|
3616 | { |
|
|
3617 | if (QUERY_FLAG (op, FLAG_UNPAID) && !QUERY_FLAG (op, FLAG_APPLIED)) |
|
|
3618 | return 1; |
|
|
3619 | |
|
|
3620 | return apply_special (who, op, aflags); |
|
|
3621 | } |
3768 | } |
3622 | |
3769 | |
3623 | /** |
3770 | /** |
3624 | * Map was just loaded, handle op's initialisation. |
3771 | * Map was just loaded, handle op's initialisation. |
3625 | * |
3772 | * |
… | |
… | |
3896 | } |
4043 | } |
3897 | |
4044 | |
3898 | who->update_stats (); |
4045 | who->update_stats (); |
3899 | } |
4046 | } |
3900 | |
4047 | |
3901 | |
|
|
3902 | /** |
|
|
3903 | * op made some mistake with a scroll, this takes care of punishment. |
|
|
3904 | * scroll_failure()- hacked directly from spell_failure |
|
|
3905 | */ |
|
|
3906 | void |
|
|
3907 | scroll_failure (object *op, int failure, int power) |
|
|
3908 | { |
|
|
3909 | if (abs (failure / 4) > power) |
|
|
3910 | power = abs (failure / 4); /* set minimum effect */ |
|
|
3911 | |
|
|
3912 | if (failure <= -1 && failure > -15) |
|
|
3913 | { /* wonder */ |
|
|
3914 | object *tmp; |
|
|
3915 | |
|
|
3916 | op->failmsg ("Your spell warps!"); |
|
|
3917 | tmp = get_archetype (SPELL_WONDER); |
|
|
3918 | cast_wonder (op, op, 0, tmp); |
|
|
3919 | tmp->destroy (); |
|
|
3920 | } |
|
|
3921 | else if (failure <= -15 && failure > -35) |
|
|
3922 | { /* drain mana */ |
|
|
3923 | op->failmsg ("Your mana is drained!"); |
|
|
3924 | op->stats.sp -= random_roll (0, power - 1, op, PREFER_LOW); |
|
|
3925 | if (op->stats.sp < 0) |
|
|
3926 | op->stats.sp = 0; |
|
|
3927 | } |
|
|
3928 | else if (settings.spell_failure_effects == TRUE) |
|
|
3929 | { |
|
|
3930 | if (failure <= -35 && failure > -60) |
|
|
3931 | { /* confusion */ |
|
|
3932 | op->failmsg ("The magic recoils on you!"); |
|
|
3933 | confuse_player (op, op, power); |
|
|
3934 | } |
|
|
3935 | else if (failure <= -60 && failure > -70) |
|
|
3936 | { /* paralysis */ |
|
|
3937 | op->failmsg ("The magic recoils and paralyzes you!"); |
|
|
3938 | paralyze_player (op, op, power); |
|
|
3939 | } |
|
|
3940 | else if (failure <= -70 && failure > -80) |
|
|
3941 | { /* blind */ |
|
|
3942 | op->failmsg ("The magic recoils on you!"); |
|
|
3943 | blind_player (op, op, power); |
|
|
3944 | } |
|
|
3945 | else if (failure <= -80) |
|
|
3946 | { /* blast the immediate area */ |
|
|
3947 | object *tmp = get_archetype (LOOSE_MANA); |
|
|
3948 | cast_magic_storm (op, tmp, power); |
|
|
3949 | op->failmsg ("You unleash uncontrolled mana!"); |
|
|
3950 | tmp->destroy (); |
|
|
3951 | } |
|
|
3952 | } |
|
|
3953 | } |
|
|
3954 | |
|
|
3955 | void |
4048 | void |
3956 | apply_changes_to_player (object *pl, object *change) |
4049 | apply_changes_to_player (object *pl, object *change) |
3957 | { |
4050 | { |
3958 | int excess_stat = 0; /* if the stat goes over the maximum |
4051 | int excess_stat = 0; /* if the stat goes over the maximum |
3959 | for the race, put the excess stat some |
4052 | for the race, put the excess stat some |
… | |
… | |
4034 | break; |
4127 | break; |
4035 | } |
4128 | } |
4036 | } |
4129 | } |
4037 | } |
4130 | } |
4038 | |
4131 | |
4039 | /** |
|
|
4040 | * This handles items of type 'transformer'. |
|
|
4041 | * Basically those items, used with a marked item, transform both items into something |
|
|
4042 | * else. |
|
|
4043 | * "Transformer" item has food decreased by 1, removed if 0 (0 at start means illimited).. |
|
|
4044 | * Change information is contained in the 'slaying' field of the marked item. |
|
|
4045 | * The format is as follow: transformer:[number ]yield[;transformer:...]. |
|
|
4046 | * This way an item can be transformed in many things, and/or many objects. |
|
|
4047 | * The 'slaying' field for transformer is used as verb for the action. |
|
|
4048 | */ |
|
|
4049 | void |
|
|
4050 | apply_item_transformer (object *pl, object *transformer) |
|
|
4051 | { |
|
|
4052 | object *marked; |
|
|
4053 | object *new_item; |
|
|
4054 | char *find; |
|
|
4055 | char *separator; |
|
|
4056 | int yield; |
|
|
4057 | char got[MAX_BUF]; |
|
|
4058 | int len; |
|
|
4059 | |
|
|
4060 | if (!pl || !transformer) |
|
|
4061 | return; |
|
|
4062 | |
|
|
4063 | marked = find_marked_object (pl); |
|
|
4064 | |
|
|
4065 | if (!marked) |
|
|
4066 | { |
|
|
4067 | pl->failmsg (format ("Use the %s with what item?", query_name (transformer))); |
|
|
4068 | return; |
|
|
4069 | } |
|
|
4070 | |
|
|
4071 | if (!marked->slaying) |
|
|
4072 | { |
|
|
4073 | pl->failmsg (format ("You can't use the %s with your %s!", query_name (transformer), query_name (marked))); |
|
|
4074 | return; |
|
|
4075 | } |
|
|
4076 | |
|
|
4077 | /* check whether they are compatible or not */ |
|
|
4078 | find = strstr (&marked->slaying, transformer->arch->archname); |
|
|
4079 | if (!find || (*(find + strlen (transformer->arch->archname)) != ':')) |
|
|
4080 | { |
|
|
4081 | pl->failmsg (format ("You can't use the %s with your %s!", query_name (transformer), query_name (marked))); |
|
|
4082 | return; |
|
|
4083 | } |
|
|
4084 | |
|
|
4085 | find += strlen (transformer->arch->archname) + 1; |
|
|
4086 | /* Item can be used, now find how many and what it yields */ |
|
|
4087 | if (isdigit (*(find))) |
|
|
4088 | { |
|
|
4089 | yield = atoi (find); |
|
|
4090 | if (yield < 1) |
|
|
4091 | { |
|
|
4092 | LOG (llevDebug, "apply_item_transformer: item %s has slaying-yield %d.", query_base_name (marked, 0), yield); |
|
|
4093 | yield = 1; |
|
|
4094 | } |
|
|
4095 | } |
|
|
4096 | else |
|
|
4097 | yield = 1; |
|
|
4098 | |
|
|
4099 | while (isdigit (*find)) |
|
|
4100 | find++; |
|
|
4101 | |
|
|
4102 | while (*find == ' ') |
|
|
4103 | find++; |
|
|
4104 | |
|
|
4105 | memset (got, 0, MAX_BUF); |
|
|
4106 | |
|
|
4107 | if ((separator = strchr (find, ';')) != NULL) |
|
|
4108 | len = separator - find; |
|
|
4109 | else |
|
|
4110 | len = strlen (find); |
|
|
4111 | |
|
|
4112 | if (len > MAX_BUF - 1) |
|
|
4113 | len = MAX_BUF - 1; |
|
|
4114 | |
|
|
4115 | strcpy (got, find); |
|
|
4116 | got[len] = '\0'; |
|
|
4117 | |
|
|
4118 | /* Now create new item, remove used ones when required. */ |
|
|
4119 | new_item = get_archetype (got); |
|
|
4120 | if (!new_item) |
|
|
4121 | { |
|
|
4122 | pl->failmsg (format ("This %s is strange, better to not use it.", query_base_name (marked, 0))); |
|
|
4123 | return; |
|
|
4124 | } |
|
|
4125 | |
|
|
4126 | new_item->nrof = yield; |
|
|
4127 | |
|
|
4128 | pl->statusmsg (format ("You %s the %s.", &transformer->slaying, query_base_name (marked, 0))); |
|
|
4129 | |
|
|
4130 | pl->insert (new_item); |
|
|
4131 | /* Eat up one item */ |
|
|
4132 | marked->decrease (); |
|
|
4133 | |
|
|
4134 | /* Eat one transformer if needed */ |
|
|
4135 | if (transformer->stats.food) |
|
|
4136 | if (--transformer->stats.food == 0) |
|
|
4137 | transformer->decrease (); |
|
|
4138 | } |
|
|
4139 | |
|
|