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 | */ |
173 | int |
173 | int |
174 | apply_potion (object *op, object *tmp) |
174 | apply_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 | |
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 = -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); |
… | |
… | |
1488 | if (victim->type == PLAYER && EXIT_PATH (trap)) |
1488 | if (victim->type == PLAYER && EXIT_PATH (trap)) |
1489 | { |
1489 | { |
1490 | /* Basically, don't show exits leading to random maps the |
1490 | /* Basically, don't show exits leading to random maps the |
1491 | * players output. |
1491 | * players output. |
1492 | */ |
1492 | */ |
1493 | if (trap->msg && !EXIT_PATH (trap).starts_with ("/!")) |
1493 | if (trap->msg && EXIT_PATH (trap) != shstr_random_map_exit) |
1494 | victim->statusmsg (trap->msg, NDI_NAVY); |
1494 | victim->statusmsg (trap->msg, NDI_NAVY); |
1495 | |
1495 | |
1496 | trap->play_sound (trap->sound); |
1496 | trap->play_sound (trap->sound); |
1497 | victim->enter_exit (trap); |
1497 | victim->enter_exit (trap); |
1498 | } |
1498 | } |
… | |
… | |
1576 | : lev_diff < 15 ? "This book is way beyond your comprehension." |
1576 | : lev_diff < 15 ? "This book is way beyond your comprehension." |
1577 | : "This book is totally beyond your comprehension."); |
1577 | : "This book is totally beyond your comprehension."); |
1578 | return; |
1578 | return; |
1579 | } |
1579 | } |
1580 | |
1580 | |
|
|
1581 | // we currently don't use the message types for anything. |
1581 | 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")); |
1582 | |
1585 | |
1583 | if (player *pl = op->contr) |
1586 | if (player *pl = op->contr) |
1584 | if (client *ns = pl->ns) |
1587 | if (client *ns = pl->ns) |
1585 | 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)); |
1586 | |
1589 | |
… | |
… | |
1766 | * instead of having their spell stored in stats.sp. These are |
1769 | * instead of having their spell stored in stats.sp. These are |
1767 | * legacy spellbooks |
1770 | * legacy spellbooks |
1768 | */ |
1771 | */ |
1769 | if (tmp->slaying) |
1772 | if (tmp->slaying) |
1770 | { |
1773 | { |
1771 | spell = arch_to_object (find_archetype_by_object_name (tmp->slaying)); |
1774 | spell = find_archetype_by_object_name (tmp->slaying)->instance (); |
|
|
1775 | |
1772 | if (!spell) |
1776 | if (!spell) |
1773 | { |
1777 | { |
1774 | op->failmsg (format ("The book's formula for %s is incomplete.", &tmp->slaying)); |
1778 | op->failmsg (format ("The book's formula for %s is incomplete.", &tmp->slaying)); |
1775 | return; |
1779 | return; |
1776 | } |
1780 | } |
… | |
… | |
1853 | * literacy rate very useful! -b.t. |
1857 | * literacy rate very useful! -b.t. |
1854 | */ |
1858 | */ |
1855 | if (QUERY_FLAG (op, FLAG_CONFUSED)) |
1859 | if (QUERY_FLAG (op, FLAG_CONFUSED)) |
1856 | { |
1860 | { |
1857 | op->failmsg ("In your confused state you flub the wording of the text!"); |
1861 | op->failmsg ("In your confused state you flub the wording of the text!"); |
1858 | scroll_failure (op, 0 - random_roll (0, spell->level, op, PREFER_LOW), MAX (spell->stats.sp, spell->stats.grace)); |
1862 | scroll_failure (op, 0 - random_roll (0, spell->level, op, PREFER_LOW), max (spell->stats.sp, spell->stats.grace)); |
1859 | } |
1863 | } |
1860 | else if (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || |
1864 | else if (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || |
1861 | (random_roll (0, 100, op, PREFER_LOW) - (5 * skop->level)) < learn_spell[spell->stats.grace ? op->stats.Wis : op->stats.Int]) |
1865 | (random_roll (0, 100, op, PREFER_LOW) - (5 * skop->level)) < learn_spell[spell->stats.grace ? op->stats.Wis : op->stats.Int]) |
1862 | { |
1866 | { |
1863 | op->statusmsg ("You succeed in learning the spell!", NDI_GREEN); |
1867 | op->statusmsg ("You succeed in learning the spell!", NDI_GREEN); |
… | |
… | |
1997 | int atnr_winner[NROFATTACKS]; /* winning candidates for resistance improvement */ |
2001 | int atnr_winner[NROFATTACKS]; /* winning candidates for resistance improvement */ |
1998 | int winners = 0; /* number of winners */ |
2002 | int winners = 0; /* number of winners */ |
1999 | int i; /* index */ |
2003 | int i; /* index */ |
2000 | |
2004 | |
2001 | /* let's make sure and doublecheck the parameters */ |
2005 | /* let's make sure and doublecheck the parameters */ |
2002 | if (meal->type != FLESH || !is_dragon_pl (op)) |
2006 | if (meal->type != FLESH || !op->is_dragon ()) |
2003 | return 0; |
2007 | return 0; |
2004 | |
2008 | |
2005 | /* now grab the 'dragon_skin'- and 'dragon_ability'-forces |
2009 | /* now grab the 'dragon_skin'- and 'dragon_ability'-forces |
2006 | from the player's inventory */ |
2010 | from the player's inventory */ |
2007 | for (tmp = op->inv; tmp; tmp = tmp->below) |
2011 | for (tmp = op->inv; tmp; tmp = tmp->below) |
… | |
… | |
2023 | op->stats.hp += meal->stats.food / 50; |
2027 | op->stats.hp += meal->stats.food / 50; |
2024 | |
2028 | |
2025 | if (op->stats.hp > op->stats.maxhp) |
2029 | if (op->stats.hp > op->stats.maxhp) |
2026 | op->stats.hp = op->stats.maxhp; |
2030 | op->stats.hp = op->stats.maxhp; |
2027 | |
2031 | |
2028 | op->stats.food = MIN (999, op->stats.food + meal->stats.food); |
2032 | op->stats.food = min (999, op->stats.food + meal->stats.food); |
2029 | |
2033 | |
2030 | /*LOG(llevDebug, "-> player: %d, flesh: %d\n", op->level, meal->level); */ |
2034 | /*LOG(llevDebug, "-> player: %d, flesh: %d\n", op->level, meal->level); */ |
2031 | |
2035 | |
2032 | /* on to the interesting part: chances for adding resistance */ |
2036 | /* on to the interesting part: chances for adding resistance */ |
2033 | for (i = 0; i < NROFATTACKS; i++) |
2037 | for (i = 0; i < NROFATTACKS; i++) |
… | |
… | |
2043 | |
2047 | |
2044 | /* monster bonus increases with level, because high-level |
2048 | /* monster bonus increases with level, because high-level |
2045 | flesh is too rare */ |
2049 | flesh is too rare */ |
2046 | mbonus = op->level * 20. / ((double) settings.max_level); |
2050 | mbonus = op->level * 20. / ((double) settings.max_level); |
2047 | |
2051 | |
2048 | chance = (((double) MIN (op->level + bonus, meal->level + bonus + mbonus)) * 100. / |
2052 | chance = (((double)min (op->level + bonus, meal->level + bonus + mbonus)) * 100. / |
2049 | ((double) settings.max_level)) - skin->resist[i]; |
2053 | ((double)settings.max_level)) - skin->resist[i]; |
2050 | |
2054 | |
2051 | if (chance >= 0.) |
2055 | if (chance >= 0.) |
2052 | chance += 1.; |
2056 | chance += 1.; |
2053 | else |
2057 | else |
2054 | chance = (chance < -12) ? 0. : 1. / pow (2., -chance); |
2058 | chance = (chance < -12) ? 0. : 1. / pow (2., -chance); |
2055 | |
2059 | |
2056 | /* chance is proportional to amount of resistance (max. 50) */ |
2060 | /* chance is proportional to amount of resistance (max. 50) */ |
2057 | chance *= ((double) (MIN (meal->resist[i], 50))) / 50.; |
2061 | chance *= ((double)(min (meal->resist[i], 50))) / 50.; |
2058 | |
2062 | |
2059 | /* doubled chance for resistance of ability-focus */ |
2063 | /* doubled chance for resistance of ability-focus */ |
2060 | if (i == abil->stats.exp) |
2064 | if (i == abil->stats.exp) |
2061 | chance = MIN (100., chance * 2.); |
2065 | chance = min (100., chance * 2.); |
2062 | |
2066 | |
2063 | /* now make the throw and save all winners (Don't insert luck bonus here!) */ |
2067 | /* now make the throw and save all winners (Don't insert luck bonus here!) */ |
2064 | if (rndm (10000) < (unsigned int) (chance * 100)) |
2068 | if (rndm (10000) < (unsigned int)(chance * 100)) |
2065 | { |
2069 | { |
2066 | atnr_winner[winners] = i; |
2070 | atnr_winner[winners] = i; |
2067 | winners++; |
2071 | winners++; |
2068 | } |
2072 | } |
2069 | |
2073 | |
… | |
… | |
2145 | if (op->type != PLAYER) |
2149 | if (op->type != PLAYER) |
2146 | op->stats.hp = op->stats.maxhp; |
2150 | op->stats.hp = op->stats.maxhp; |
2147 | else |
2151 | else |
2148 | { |
2152 | { |
2149 | /* check if this is a dragon (player), eating some flesh */ |
2153 | /* check if this is a dragon (player), eating some flesh */ |
2150 | if (tmp->type == FLESH && is_dragon_pl (op) && dragon_eat_flesh (op, tmp)) |
2154 | if (tmp->type == FLESH && op->is_dragon () && dragon_eat_flesh (op, tmp)) |
2151 | ; |
2155 | ; |
2152 | else |
2156 | else |
2153 | { |
2157 | { |
2154 | /* usual case - no dragon meal: */ |
2158 | /* usual case - no dragon meal: */ |
2155 | if (op->stats.food + tmp->stats.food > 999) |
2159 | if (op->stats.food + tmp->stats.food > 999) |
… | |
… | |
2170 | |
2174 | |
2171 | if (!QUERY_FLAG (tmp, FLAG_CURSED)) |
2175 | if (!QUERY_FLAG (tmp, FLAG_CURSED)) |
2172 | { |
2176 | { |
2173 | const char *buf; |
2177 | const char *buf; |
2174 | |
2178 | |
2175 | if (!is_dragon_pl (op)) |
2179 | if (!op->is_dragon ()) |
2176 | { |
2180 | { |
2177 | /* eating message for normal players */ |
2181 | /* eating message for normal players */ |
2178 | if (tmp->type == DRINK) |
2182 | if (tmp->type == DRINK) |
2179 | buf = format ("Ahhh...that %s tasted good.", &tmp->name); |
2183 | buf = format ("Ahhh...that %s tasted good.", &tmp->name); |
2180 | else |
2184 | else |
… | |
… | |
2268 | op->stats.food -= op->stats.food / 4; |
2272 | op->stats.food -= op->stats.food / 4; |
2269 | poison->destroy (); |
2273 | poison->destroy (); |
2270 | } |
2274 | } |
2271 | |
2275 | |
2272 | /** |
2276 | /** |
2273 | * This function return true if the exit is not a 2 ways one or it is 2 ways, valid exit. |
|
|
2274 | * A valid 2 way exit means: |
|
|
2275 | * -You can come back (there is another exit at the other side) |
|
|
2276 | * -You are |
|
|
2277 | * ° the owner of the exit |
|
|
2278 | * ° or in the same party as the owner |
|
|
2279 | * |
|
|
2280 | * Note: a owner in a 2 way exit is saved as the owner's name |
|
|
2281 | * in the field exit->name cause the field exit->owner doesn't |
|
|
2282 | * survive in the swapping (in fact the whole exit doesn't survive). |
|
|
2283 | */ |
|
|
2284 | int |
|
|
2285 | is_legal_2ways_exit (object *op, object *exit) |
|
|
2286 | { |
|
|
2287 | if (exit->stats.exp != 1) |
|
|
2288 | return 1; /*This is not a 2 way, so it is legal */ |
|
|
2289 | |
|
|
2290 | #if 0 //TODO |
|
|
2291 | if (!has_been_loaded (EXIT_PATH (exit)) && exit->race) |
|
|
2292 | return 0; /* This is a reset town portal */ |
|
|
2293 | #endif |
|
|
2294 | |
|
|
2295 | LOG (llevError | logBacktrace, "sync map load due to %s\n", exit->debug_desc ()); |
|
|
2296 | |
|
|
2297 | maptile *exitmap = maptile::find_sync (EXIT_PATH (exit), exit->map); |
|
|
2298 | |
|
|
2299 | if (exitmap) |
|
|
2300 | { |
|
|
2301 | exitmap->load_sync (); |
|
|
2302 | |
|
|
2303 | object *tmp = exitmap->at (EXIT_X (exit), EXIT_Y (exit)).bot; |
|
|
2304 | |
|
|
2305 | if (!tmp) |
|
|
2306 | return 0; |
|
|
2307 | |
|
|
2308 | for (; tmp; tmp = tmp->above) |
|
|
2309 | { |
|
|
2310 | if (tmp->type != EXIT) |
|
|
2311 | continue; /*Not an exit */ |
|
|
2312 | |
|
|
2313 | if (!EXIT_PATH (tmp)) |
|
|
2314 | continue; /*Not a valid exit */ |
|
|
2315 | |
|
|
2316 | if ((EXIT_X (tmp) != exit->x) || (EXIT_Y (tmp) != exit->y)) |
|
|
2317 | continue; /*Not in the same place */ |
|
|
2318 | |
|
|
2319 | if (exit->map->path != EXIT_PATH (tmp)) |
|
|
2320 | continue; /*Not in the same map */ |
|
|
2321 | |
|
|
2322 | /* From here we have found the exit is valid. However we do |
|
|
2323 | * here the check of the exit owner. It is important for the |
|
|
2324 | * town portals to prevent strangers from visiting your appartments |
|
|
2325 | */ |
|
|
2326 | if (!exit->race) |
|
|
2327 | return 1; /*No owner, free for all! */ |
|
|
2328 | |
|
|
2329 | object *exit_owner = 0; |
|
|
2330 | |
|
|
2331 | for_all_players (pp) |
|
|
2332 | { |
|
|
2333 | if (!pp->ob) |
|
|
2334 | continue; |
|
|
2335 | |
|
|
2336 | if (pp->ob->name != exit->race) |
|
|
2337 | continue; |
|
|
2338 | |
|
|
2339 | exit_owner = pp->ob; /*We found a player which correspond to the player name */ |
|
|
2340 | break; |
|
|
2341 | } |
|
|
2342 | |
|
|
2343 | if (!exit_owner) |
|
|
2344 | return 0; /* No more owner */ |
|
|
2345 | |
|
|
2346 | if (exit_owner->contr == op->contr) |
|
|
2347 | return 1; /*It is your exit */ |
|
|
2348 | |
|
|
2349 | if (exit_owner && /*There is a owner */ |
|
|
2350 | (op->contr) && /*A player tries to pass */ |
|
|
2351 | ((exit_owner->contr->party == NULL) || /*No pass if controller has no party */ |
|
|
2352 | (exit_owner->contr->party != op->contr->party))) /* Or not the same as op */ |
|
|
2353 | return 0; |
|
|
2354 | |
|
|
2355 | return 1; |
|
|
2356 | } |
|
|
2357 | } |
|
|
2358 | |
|
|
2359 | return 0; |
|
|
2360 | } |
|
|
2361 | |
|
|
2362 | /** |
|
|
2363 | * This function will try to apply a lighter and in case no lighter |
2277 | * This function will try to apply a lighter and in case no lighter |
2364 | * is specified it will try to find a lighter in the players inventory, |
2278 | * is specified it will try to find a lighter in the players inventory, |
2365 | * and inform him about this requirement. |
2279 | * and inform him about this requirement. |
2366 | * |
2280 | * |
2367 | * who - the player |
2281 | * who - the player |
… | |
… | |
2415 | /** |
2329 | /** |
2416 | * Designed primarily to light torches/lanterns/etc. |
2330 | * Designed primarily to light torches/lanterns/etc. |
2417 | * Also burns up burnable material too. First object in the inventory is |
2331 | * Also burns up burnable material too. First object in the inventory is |
2418 | * the selected object to "burn". -b.t. |
2332 | * the selected object to "burn". -b.t. |
2419 | */ |
2333 | */ |
2420 | void |
2334 | static void |
2421 | apply_lighter (object *who, object *lighter) |
2335 | apply_lighter (object *who, object *lighter) |
2422 | { |
2336 | { |
2423 | object *item; |
2337 | object *item; |
2424 | int is_player_env = 0; |
2338 | int is_player_env = 0; |
2425 | |
2339 | |
… | |
… | |
2452 | } |
2366 | } |
2453 | |
2367 | |
2454 | /** |
2368 | /** |
2455 | * This function generates a cursed effect for cursed lamps and torches. |
2369 | * This function generates a cursed effect for cursed lamps and torches. |
2456 | */ |
2370 | */ |
|
|
2371 | static void |
2457 | void player_apply_lamp_cursed_effect (object *who, object *op) |
2372 | player_apply_lamp_cursed_effect (object *who, object *op) |
2458 | { |
2373 | { |
2459 | if (op->level) |
2374 | if (op->level) |
2460 | { |
2375 | { |
2461 | who->failmsg (format ( |
2376 | who->failmsg (format ( |
2462 | "The %s was cursed, it explodes in a big fireball!", |
2377 | "The %s was cursed, it explodes in a big fireball!", |
… | |
… | |
2477 | * Apply for players and lamps |
2392 | * Apply for players and lamps |
2478 | * |
2393 | * |
2479 | * who - the player |
2394 | * who - the player |
2480 | * op - the lamp |
2395 | * op - the lamp |
2481 | */ |
2396 | */ |
|
|
2397 | static void |
2482 | void player_apply_lamp (object *who, object *op) |
2398 | player_apply_lamp (object *who, object *op) |
2483 | { |
2399 | { |
2484 | bool switch_on = op->glow_radius ? false : true; |
2400 | bool switch_on = op->glow_radius ? false : true; |
2485 | |
2401 | |
2486 | if (switch_on) |
2402 | if (switch_on) |
2487 | { |
2403 | { |
… | |
… | |
2617 | static void |
2533 | static void |
2618 | apply_item_transformer (object *pl, object *transformer) |
2534 | apply_item_transformer (object *pl, object *transformer) |
2619 | { |
2535 | { |
2620 | object *marked; |
2536 | object *marked; |
2621 | object *new_item; |
2537 | object *new_item; |
2622 | char *find; |
2538 | const char *find; |
2623 | char *separator; |
2539 | char *separator; |
2624 | int yield; |
2540 | int yield; |
2625 | char got[MAX_BUF]; |
2541 | char got[MAX_BUF]; |
2626 | int len; |
2542 | int len; |
2627 | |
2543 | |
… | |
… | |
2670 | while (*find == ' ') |
2586 | while (*find == ' ') |
2671 | find++; |
2587 | find++; |
2672 | |
2588 | |
2673 | memset (got, 0, MAX_BUF); |
2589 | memset (got, 0, MAX_BUF); |
2674 | |
2590 | |
2675 | if ((separator = strchr (find, ';')) != NULL) |
2591 | if ((separator = (char *) strchr (find, ';'))) |
2676 | len = separator - find; |
2592 | len = separator - find; |
2677 | else |
2593 | else |
2678 | len = strlen (find); |
2594 | len = strlen (find); |
2679 | |
2595 | |
2680 | if (len > MAX_BUF - 1) |
2596 | min_it (len, MAX_BUF - 1); |
2681 | len = MAX_BUF - 1; |
|
|
2682 | |
2597 | |
2683 | strcpy (got, find); |
2598 | strcpy (got, find); |
2684 | got[len] = '\0'; |
2599 | got[len] = '\0'; |
2685 | |
2600 | |
2686 | /* Now create new item, remove used ones when required. */ |
2601 | /* Now create new item, remove used ones when required. */ |
… | |
… | |
2765 | |
2680 | |
2766 | case EXIT: |
2681 | case EXIT: |
2767 | if (who->type != PLAYER) |
2682 | if (who->type != PLAYER) |
2768 | return 0; |
2683 | return 0; |
2769 | |
2684 | |
2770 | if (!EXIT_PATH (op) || !is_legal_2ways_exit (who, op)) |
2685 | if (!EXIT_PATH (op)) |
2771 | 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))); |
2686 | 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))); |
2772 | else |
2687 | else |
2773 | { |
2688 | { |
2774 | /* Don't display messages for random maps. */ |
2689 | /* Don't display messages for random maps. */ |
2775 | if (op->msg && !EXIT_PATH (op).starts_with ("/!")) |
2690 | if (op->msg && EXIT_PATH (op) != shstr_random_map_exit) |
2776 | who->statusmsg (op->msg, NDI_NAVY); |
2691 | who->statusmsg (op->msg, NDI_NAVY); |
2777 | |
2692 | |
2778 | who->enter_exit (op); |
2693 | who->enter_exit (op); |
2779 | } |
2694 | } |
2780 | |
2695 | |
… | |
… | |
3187 | #define CANNOT_REMOVE_CURSED \ |
3102 | #define CANNOT_REMOVE_CURSED \ |
3188 | "H<You cannot remove cursed or damned items, you first have to remove the curse. " \ |
3103 | "H<You cannot remove cursed or damned items, you first have to remove the curse. " \ |
3189 | "Praying over an altar, scrolls of remove curse/damnation, " \ |
3104 | "Praying over an altar, scrolls of remove curse/damnation, " \ |
3190 | "priests or even other players might help.>" |
3105 | "priests or even other players might help.>" |
3191 | |
3106 | |
3192 | int |
3107 | static int |
3193 | unapply_for_ob (object *who, object *op, int aflags) |
3108 | unapply_for_ob (object *who, object *op, int aflags) |
3194 | { |
3109 | { |
3195 | if (op->is_range ()) |
3110 | if (op->is_range ()) |
3196 | for (object *tmp = who->inv; tmp; tmp = tmp->below) |
3111 | for (object *tmp = who->inv; tmp; tmp = tmp->below) |
3197 | if (QUERY_FLAG (tmp, FLAG_APPLIED) && tmp->is_range ()) |
3112 | if (QUERY_FLAG (tmp, FLAG_APPLIED) && tmp->is_range ()) |
… | |
… | |
3597 | case SKILL: |
3512 | case SKILL: |
3598 | if (player *pl = who->contr) |
3513 | if (player *pl = who->contr) |
3599 | { |
3514 | { |
3600 | if (IS_COMBAT_SKILL (op->subtype)) |
3515 | if (IS_COMBAT_SKILL (op->subtype)) |
3601 | { |
3516 | { |
3602 | if (skill_flags [op->subtype] & SF_NEED_WEAPON) |
3517 | if (skill_flags [op->subtype] & SF_NEED_ITEM) |
3603 | { |
3518 | { |
3604 | for (object *item = who->inv; item; item = item->below) |
3519 | for (object *item = who->inv; item; item = item->below) |
3605 | if (item->type == WEAPON && item->flag [FLAG_APPLIED]) |
3520 | if (item->type == item->weapontype && item->flag [FLAG_APPLIED]) |
3606 | { |
3521 | { |
3607 | if (item->skill == op->skill) |
3522 | if (item->skill == op->skill) |
3608 | { |
3523 | { |
3609 | who->change_weapon (pl->combat_ob = item); |
3524 | who->change_weapon (pl->combat_ob = item); |
3610 | goto found_weapon; |
3525 | goto found_weapon; |
… | |
… | |
3623 | else |
3538 | else |
3624 | who->change_weapon (pl->combat_ob = op); |
3539 | who->change_weapon (pl->combat_ob = op); |
3625 | } |
3540 | } |
3626 | else if (IS_RANGED_SKILL (op->subtype)) |
3541 | else if (IS_RANGED_SKILL (op->subtype)) |
3627 | { |
3542 | { |
3628 | if (skill_flags [op->subtype] & SF_NEED_BOW) |
3543 | if (skill_flags [op->subtype] & SF_NEED_ITEM) |
3629 | { |
3544 | { |
3630 | for (object *item = who->inv; item; item = item->below) |
3545 | for (object *item = who->inv; item; item = item->below) |
3631 | if (item->type == BOW && item->flag [FLAG_APPLIED]) |
3546 | if (item->type == item->weapontype && item->flag [FLAG_APPLIED]) |
3632 | { |
3547 | { |
3633 | //TODO: bows should/must all have skill missile weapon right now |
3548 | //TODO: bows should/must all have skill missile weapon right now |
3634 | who->change_weapon (pl->ranged_ob = item); |
3549 | who->change_weapon (pl->ranged_ob = item); |
3635 | goto found_bow; |
3550 | goto found_bow; |
3636 | } |
3551 | } |
… | |
… | |
3763 | esrv_send_item (pl, op); |
3678 | esrv_send_item (pl, op); |
3764 | |
3679 | |
3765 | return 0; |
3680 | return 0; |
3766 | } |
3681 | } |
3767 | |
3682 | |
3768 | int |
|
|
3769 | monster_apply_special (object *who, object *op, int aflags) |
|
|
3770 | { |
|
|
3771 | if (QUERY_FLAG (op, FLAG_UNPAID) && !QUERY_FLAG (op, FLAG_APPLIED)) |
|
|
3772 | return 1; |
|
|
3773 | |
|
|
3774 | return apply_special (who, op, aflags); |
|
|
3775 | } |
|
|
3776 | |
|
|
3777 | /** |
3683 | /** |
3778 | * Map was just loaded, handle op's initialisation. |
3684 | * Map was just loaded, handle op's initialisation. |
3779 | * |
3685 | * |
3780 | * Generates shop floor's item, and treasures. |
3686 | * Generates shop floor's item, and treasures. |
3781 | */ |
3687 | */ |
… | |
… | |
3886 | * treasure again for this object |
3792 | * treasure again for this object |
3887 | */ |
3793 | */ |
3888 | invtmp->randomitems = NULL; |
3794 | invtmp->randomitems = NULL; |
3889 | } |
3795 | } |
3890 | } |
3796 | } |
|
|
3797 | |
3891 | /* This is really temporary - the code at the bottom will |
3798 | /* This is really temporary - the code at the bottom will |
3892 | * also set randomitems to null. The problem is there are bunches |
3799 | * also set randomitems to null. The problem is there are bunches |
3893 | * of maps/players already out there with items that have spells |
3800 | * of maps/players already out there with items that have spells |
3894 | * which haven't had the randomitems set to null yet. |
3801 | * which haven't had the randomitems set to null yet. |
3895 | * MSW 2004-05-13 |
3802 | * MSW 2004-05-13 |
… | |
… | |
3899 | * Ryo 2004-08-16 |
3806 | * Ryo 2004-08-16 |
3900 | */ |
3807 | */ |
3901 | if (tmp->type == WAND || tmp->type == ROD || tmp->type == SCROLL |
3808 | if (tmp->type == WAND || tmp->type == ROD || tmp->type == SCROLL |
3902 | || tmp->type == HORN || tmp->type == FIREWALL || tmp->type == POTION || tmp->type == ALTAR || tmp->type == SPELLBOOK) |
3809 | || tmp->type == HORN || tmp->type == FIREWALL || tmp->type == POTION || tmp->type == ALTAR || tmp->type == SPELLBOOK) |
3903 | tmp->randomitems = NULL; |
3810 | tmp->randomitems = NULL; |
3904 | |
|
|
3905 | } |
3811 | } |
3906 | |
3812 | |
3907 | if (QUERY_FLAG (tmp, FLAG_AUTO_APPLY)) |
3813 | if (QUERY_FLAG (tmp, FLAG_AUTO_APPLY)) |
3908 | auto_apply (tmp); |
3814 | auto_apply (tmp); |
3909 | else if ((tmp->type == TREASURE || (tmp->type == CONTAINER)) && tmp->has_random_items ()) |
3815 | else if ((tmp->type == TREASURE || (tmp->type == CONTAINER)) && tmp->has_random_items ()) |
… | |
… | |
3966 | /* bigger morsel of food = longer effect time */ |
3872 | /* bigger morsel of food = longer effect time */ |
3967 | int duration = TIME2TICK (food->stats.food); |
3873 | int duration = TIME2TICK (food->stats.food); |
3968 | |
3874 | |
3969 | if (force = who->force_find (key)) |
3875 | if (force = who->force_find (key)) |
3970 | { |
3876 | { |
3971 | if (duration > abs (force->speed_left / force->speed)) |
3877 | if (duration > fabs (force->speed_left / force->speed)) |
3972 | { |
3878 | { |
3973 | 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)); |
3879 | 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)); |
3974 | force->force_set_timer (duration); |
3880 | force->force_set_timer (duration); |
3975 | } |
3881 | } |
3976 | else |
3882 | else |