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