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,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2001 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2001 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992 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. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the Affero GNU General Public License |
18 | * You should have received a copy of the Affero GNU General Public License |
19 | * and the GNU General Public License along with this program. If not, see |
19 | * and the GNU General Public License along with this program. If not, see |
20 | * <http://www.gnu.org/licenses/>. |
20 | * <http://www.gnu.org/licenses/>. |
21 | * |
21 | * |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | */ |
23 | */ |
24 | |
24 | |
25 | #include <cmath> |
25 | #include <cmath> |
26 | |
26 | |
… | |
… | |
30 | #include <skills.h> |
30 | #include <skills.h> |
31 | #include <tod.h> |
31 | #include <tod.h> |
32 | |
32 | |
33 | #include <sproto.h> |
33 | #include <sproto.h> |
34 | |
34 | |
35 | typedef bitset<NUM_TYPES> types_t; |
|
|
36 | |
|
|
37 | // these must be in the inventory before they can be applied |
35 | // these must be in the inventory before they can be applied |
38 | |
36 | |
39 | static const struct may_attempt_inv : types_t |
37 | static const struct apply_types_inv_only : typeset |
40 | { |
38 | { |
41 | may_attempt_inv () |
39 | apply_types_inv_only () |
42 | { |
40 | { |
43 | set (WEAPON); |
41 | set (WEAPON); |
44 | set (ARMOUR); |
42 | set (ARMOUR); |
45 | set (BOOTS); |
43 | set (BOOTS); |
46 | set (GLOVES); |
44 | set (GLOVES); |
… | |
… | |
59 | set (BOW); |
57 | set (BOW); |
60 | set (RANGED); |
58 | set (RANGED); |
61 | set (BUILDER); |
59 | set (BUILDER); |
62 | set (SKILL_TOOL); |
60 | set (SKILL_TOOL); |
63 | } |
61 | } |
64 | } may_attempt_inv; |
62 | } apply_types_inv_only; |
65 | |
63 | |
66 | // these only make sense for the player |
64 | // these only make sense for the player |
67 | |
65 | |
68 | static const struct may_attempt_player : types_t |
66 | static const struct apply_types_player_only : typeset |
69 | { |
67 | { |
70 | may_attempt_player () |
68 | apply_types_player_only () |
71 | { |
69 | { |
|
|
70 | set (TRANSPORT); |
72 | set (EXIT); |
71 | set (EXIT); |
|
|
72 | set (BOOK); |
|
|
73 | set (SIGN); |
73 | set (BOOK); |
74 | set (BOOK); |
74 | set (SKILLSCROLL); |
75 | set (SKILLSCROLL); |
75 | set (SPELLBOOK); |
76 | set (SPELLBOOK); |
|
|
77 | set (INSCRIBABLE); |
76 | set (TREASURE); |
78 | set (TREASURE); |
77 | set (SAVEBED); |
79 | set (SAVEBED); |
78 | set (ARMOUR_IMPROVER); |
80 | set (ARMOUR_IMPROVER); |
79 | set (WEAPON_IMPROVER); |
81 | set (WEAPON_IMPROVER); |
80 | set (CLOCK); |
82 | set (CLOCK); |
81 | set (MENU); |
83 | set (MENU); |
82 | set (LIGHTER); /* for lighting torches/lanterns/etc */ |
84 | set (LIGHTER); /* for lighting torches/lanterns/etc */ |
83 | set (INSCRIBABLE); |
|
|
84 | set (SIGN); |
|
|
85 | set (BOOK); |
|
|
86 | } |
85 | } |
87 | } may_attempt_player; |
86 | } apply_types_player_only; |
88 | |
87 | |
89 | // applying these _can_ be attempted, others cannot |
88 | // applying these _can_ be attempted, others cannot |
90 | // be applied at all. used by e.g. apply below. |
89 | // be applied at all. used by e.g. apply below. |
91 | |
90 | |
92 | static const struct may_attempt : types_t |
91 | static const struct apply_types : typeset |
93 | { |
92 | { |
94 | may_attempt () |
93 | apply_types () |
95 | : types_t ((types_t)may_attempt_player | (types_t)may_attempt_inv) |
94 | : typeset ((typeset)apply_types_player_only | (typeset)apply_types_inv_only) |
96 | { |
95 | { |
97 | set (T_HANDLE); |
96 | set (T_HANDLE); |
98 | set (TRIGGER); |
97 | set (TRIGGER); |
99 | set (SCROLL); |
98 | set (SCROLL); |
100 | set (POTION); |
99 | set (POTION); |
… | |
… | |
107 | set (FLESH); |
106 | set (FLESH); |
108 | set (POISON); |
107 | set (POISON); |
109 | set (POWER_CRYSTAL); |
108 | set (POWER_CRYSTAL); |
110 | set (ITEM_TRANSFORMER); |
109 | set (ITEM_TRANSFORMER); |
111 | } |
110 | } |
112 | } may_attempt; |
111 | } apply_types; |
113 | |
112 | |
114 | /**************************************************************************** |
113 | /**************************************************************************** |
115 | * Weapon improvement code follows |
114 | * Weapon improvement code follows |
116 | ****************************************************************************/ |
115 | ****************************************************************************/ |
117 | |
116 | |
… | |
… | |
141 | if (!item) |
140 | if (!item) |
142 | return 0; |
141 | return 0; |
143 | |
142 | |
144 | for (op = op->below; op; op = op->below) |
143 | for (op = op->below; op; op = op->below) |
145 | if (op->arch->archname == item) |
144 | if (op->arch->archname == item) |
146 | if (!QUERY_FLAG (op, FLAG_CURSED) && !QUERY_FLAG (op, FLAG_DAMNED) |
145 | if (!op->flag [FLAG_CURSED] && !op->flag [FLAG_DAMNED] |
147 | && /* Loophole bug? -FD- */ !QUERY_FLAG (op, FLAG_UNPAID)) |
146 | && /* Loophole bug? -FD- */ !op->flag [FLAG_UNPAID]) |
148 | count += op->number_of (); |
147 | count += op->number_of (); |
149 | |
148 | |
150 | return count; |
149 | return count; |
151 | } |
150 | } |
152 | |
151 | |
… | |
… | |
199 | if (improver->slaying) |
198 | if (improver->slaying) |
200 | { |
199 | { |
201 | count = check_item (op, improver->slaying); |
200 | count = check_item (op, improver->slaying); |
202 | if (count < 1) |
201 | if (count < 1) |
203 | { |
202 | { |
204 | op->failmsg (format ("The gods want more %ss", &improver->slaying)); |
203 | op->failmsgf ("The gods want more %ss", &improver->slaying); |
205 | return 0; |
204 | return 0; |
206 | } |
205 | } |
207 | } |
206 | } |
208 | else |
207 | else |
209 | count = 1; |
208 | count = 1; |
… | |
… | |
252 | */ |
251 | */ |
253 | static int |
252 | static int |
254 | prepare_weapon (object *op, object *improver, object *weapon) |
253 | prepare_weapon (object *op, object *improver, object *weapon) |
255 | { |
254 | { |
256 | int sacrifice_count, i; |
255 | int sacrifice_count, i; |
257 | char buf[MAX_BUF]; |
|
|
258 | |
256 | |
259 | if (weapon->level != 0) |
257 | if (weapon->level != 0) |
260 | { |
258 | { |
261 | op->failmsg ("Weapon is already prepared!"); |
259 | op->failmsg ("Weapon is already prepared!"); |
262 | return 0; |
260 | return 0; |
… | |
… | |
291 | "Your sacrifice was accepted." |
289 | "Your sacrifice was accepted." |
292 | "Your *%s may be improved %d times.", |
290 | "Your *%s may be improved %d times.", |
293 | &weapon->name, weapon->level |
291 | &weapon->name, weapon->level |
294 | )); |
292 | )); |
295 | |
293 | |
296 | sprintf (buf, "%s's %s", &op->name, &weapon->name); |
294 | weapon->name = weapon->name_pl = format ("%s's %s", &op->name, &weapon->name); |
297 | weapon->name = weapon->name_pl = buf; |
|
|
298 | weapon->nrof = 0; /* prevents preparing n weapons in the same |
295 | weapon->nrof = 0; /* prevents preparing n weapons in the same |
299 | slot at once! */ |
296 | slot at once! */ |
300 | improver->decrease (); |
297 | improver->decrease (); |
301 | weapon->last_eat = 0; |
298 | weapon->last_eat = 0; |
302 | return 1; |
299 | return 1; |
… | |
… | |
334 | { |
331 | { |
335 | op->failmsg ("This weapon cannot be improved any more."); |
332 | op->failmsg ("This weapon cannot be improved any more."); |
336 | return 0; |
333 | return 0; |
337 | } |
334 | } |
338 | |
335 | |
339 | if (QUERY_FLAG (weapon, FLAG_APPLIED) |
336 | if (weapon->flag [FLAG_APPLIED] |
340 | && !check_item_power (op, weapon->item_power + 1)) |
337 | && !check_item_power (op, weapon->item_power + 1)) |
341 | { |
338 | { |
342 | op->failmsg ("Improving the weapon will make it too " |
339 | op->failmsg ("Improving the weapon will make it too " |
343 | "powerful for you to use. Unready it if you " |
340 | "powerful for you to use. Unready it if you " |
344 | "really want to improve it."); |
341 | "really want to improve it."); |
… | |
… | |
394 | sacrifice_needed *= 2; |
391 | sacrifice_needed *= 2; |
395 | |
392 | |
396 | sacrifice_count = check_sacrifice (op, improver); |
393 | sacrifice_count = check_sacrifice (op, improver); |
397 | if (sacrifice_count < sacrifice_needed) |
394 | if (sacrifice_count < sacrifice_needed) |
398 | { |
395 | { |
399 | op->failmsg (format ("You need at least %d %s.", sacrifice_needed, &improver->slaying)); |
396 | op->failmsgf ("You need at least %d %s.", sacrifice_needed, &improver->slaying); |
400 | return 0; |
397 | return 0; |
401 | } |
398 | } |
402 | |
399 | |
403 | eat_item (op, improver->slaying, sacrifice_needed); |
400 | eat_item (op, improver->slaying, sacrifice_needed); |
404 | weapon->item_power++; |
401 | weapon->item_power++; |
… | |
… | |
426 | * then calls improve_weapon to do the dirty work. |
423 | * then calls improve_weapon to do the dirty work. |
427 | */ |
424 | */ |
428 | static int |
425 | static int |
429 | check_improve_weapon (object *op, object *tmp) |
426 | check_improve_weapon (object *op, object *tmp) |
430 | { |
427 | { |
431 | object *otmp; |
|
|
432 | |
|
|
433 | if (op->type != PLAYER) |
428 | if (op->type != PLAYER) |
434 | return 0; |
429 | return 0; |
435 | |
430 | |
436 | if (!QUERY_FLAG (op, FLAG_WIZCAST) && (get_map_flags (op->map, NULL, op->x, op->y, NULL, NULL) & P_NO_MAGIC)) |
431 | if (!op->flag [FLAG_WIZCAST] && (get_map_flags (op->map, NULL, op->x, op->y, NULL, NULL) & P_NO_MAGIC)) |
437 | { |
432 | { |
438 | op->failmsg ("Something blocks the magic of the scroll!"); |
433 | op->failmsg ("Something blocks the magic of the scroll!"); |
439 | return 0; |
434 | return 0; |
440 | } |
435 | } |
441 | |
436 | |
442 | otmp = find_marked_object (op); |
437 | object *otmp = op->mark (); |
443 | |
438 | |
444 | if (!otmp) |
439 | if (!otmp) |
445 | { |
440 | { |
446 | op->failmsg ("You need to mark a weapon object. H<Use the mark command or the mark option from the item popup menu.>"); |
441 | op->failmsg ("You need to mark a weapon object. H<Use the mark command or the mark option from the item popup menu.>"); |
447 | return 0; |
442 | return 0; |
448 | } |
443 | } |
449 | |
444 | |
450 | if (otmp->type != WEAPON && otmp->type != BOW) |
445 | if (otmp->type != WEAPON && otmp->type != BOW) |
451 | { |
446 | { |
452 | op->failmsg ("Marked item is not a weapon or bow!"); |
447 | op->failmsg ("Marked item is not a weapon or bow!"); |
|
|
448 | return 0; |
|
|
449 | } |
|
|
450 | |
|
|
451 | if (!op->apply (otmp, AP_UNAPPLY)) |
|
|
452 | { |
|
|
453 | op->failmsg ("You are unable to take off your weapon to improve it!"); |
453 | return 0; |
454 | return 0; |
454 | } |
455 | } |
455 | |
456 | |
456 | op->statusmsg ("Applied weapon builder."); |
457 | op->statusmsg ("Applied weapon builder."); |
457 | |
458 | |
… | |
… | |
483 | * changing of physical area right now. |
484 | * changing of physical area right now. |
484 | */ |
485 | */ |
485 | static int |
486 | static int |
486 | improve_armour (object *op, object *improver, object *armour) |
487 | improve_armour (object *op, object *improver, object *armour) |
487 | { |
488 | { |
488 | object *tmp; |
|
|
489 | |
|
|
490 | if (armour->magic >= settings.armor_max_enchant) |
489 | if (armour->magic >= settings.armor_max_enchant) |
491 | { |
490 | { |
492 | op->failmsg ("This armour can not be enchanted any further!"); |
491 | op->failmsg ("This armour can not be enchanted any further!"); |
493 | return 0; |
492 | return 0; |
494 | } |
493 | } |
… | |
… | |
505 | } |
504 | } |
506 | |
505 | |
507 | /* Split objects if needed. Can't insert tmp until the |
506 | /* Split objects if needed. Can't insert tmp until the |
508 | * end of this function - otherwise it will just re-merge. |
507 | * end of this function - otherwise it will just re-merge. |
509 | */ |
508 | */ |
510 | tmp = armour->nrof > 1 ? armour->split (armour->nrof - 1) : 0; |
509 | object *tmp = armour->nrof > 1 ? armour->split (armour->nrof - 1) : 0; |
511 | |
510 | |
512 | armour->magic++; |
511 | armour->magic++; |
513 | |
512 | |
514 | if (!settings.armor_speed_linear) |
513 | if (!settings.armor_speed_linear) |
515 | { |
514 | { |
… | |
… | |
553 | |
552 | |
554 | if (op->type == PLAYER) |
553 | if (op->type == PLAYER) |
555 | { |
554 | { |
556 | esrv_send_item (op, armour); |
555 | esrv_send_item (op, armour); |
557 | |
556 | |
558 | if (QUERY_FLAG (armour, FLAG_APPLIED)) |
557 | if (armour->flag [FLAG_APPLIED]) |
559 | op->update_stats (); |
558 | op->update_stats (); |
560 | } |
559 | } |
561 | |
560 | |
562 | improver->decrease (); |
561 | improver->decrease (); |
563 | |
562 | |
… | |
… | |
643 | for (ob = converter->inv->below, i = 1; ob; ob = ob->below, i++) |
642 | for (ob = converter->inv->below, i = 1; ob; ob = ob->below, i++) |
644 | if (rndm (0, i) == 0) |
643 | if (rndm (0, i) == 0) |
645 | ob_to_copy = ob; |
644 | ob_to_copy = ob; |
646 | |
645 | |
647 | item = ob_to_copy->deep_clone (); |
646 | item = ob_to_copy->deep_clone (); |
648 | CLEAR_FLAG (item, FLAG_IS_A_TEMPLATE); |
647 | item->clr_flag (FLAG_IS_A_TEMPLATE); |
649 | unflag_inv (item, FLAG_IS_A_TEMPLATE); |
648 | unflag_inv (item, FLAG_IS_A_TEMPLATE); |
650 | } |
649 | } |
651 | else |
650 | else |
652 | { |
651 | { |
653 | if (!conv_to) |
652 | if (!conv_to) |
… | |
… | |
666 | |
665 | |
667 | if (nr) |
666 | if (nr) |
668 | item->nrof *= nr; |
667 | item->nrof *= nr; |
669 | |
668 | |
670 | if (converter->flag [FLAG_PRECIOUS]) |
669 | if (converter->flag [FLAG_PRECIOUS]) |
671 | SET_FLAG (item, FLAG_UNPAID); |
670 | item->set_flag (FLAG_UNPAID); |
672 | |
671 | |
673 | if (converter->is_in_shop ()) |
672 | if (converter->is_in_shop ()) |
674 | { |
673 | { |
675 | // converters on shop floors don't work anymore, bug lets check for it |
674 | // converters on shop floors don't work anymore, bug lets check for it |
676 | // and report in case someone still does it. |
675 | // and report in case someone still does it. |
677 | LOG (llevDebug, "ITEMBUG: broken converter, converters on shop floor don't work: %s\n", |
676 | LOG (llevDebug, "ITEMBUG: broken converter, converters on shop floor don't work: %s\n", |
678 | converter->debug_desc ()); |
677 | converter->debug_desc ()); |
679 | SET_FLAG (item, FLAG_UNPAID); |
678 | item->set_flag (FLAG_UNPAID); |
680 | } |
679 | } |
681 | else if (price_in < sint64 (item->nrof) * item->value) |
680 | else if (price_in < sint64 (item->nrof) * item->value) |
682 | { |
681 | { |
683 | LOG (llevDebug, "converter output price higher than input: %s at %s (%d, %d) in value %d, out value %d for %s\n", |
682 | LOG (llevDebug, "converter output price higher than input: %s at %s (%d, %d) in value %d, out value %d for %s\n", |
684 | &converter->name, &converter->map->path, converter->x, converter->y, price_in, item->nrof * item->value, &item->name); |
683 | &converter->name, &converter->map->path, converter->x, converter->y, price_in, item->nrof * item->value, &item->name); |
… | |
… | |
688 | */ |
687 | */ |
689 | } |
688 | } |
690 | |
689 | |
691 | // elmex: only identify if we need to, for example so that generated money doesn't |
690 | // elmex: only identify if we need to, for example so that generated money doesn't |
692 | // get an 'identified' flag so easily. |
691 | // get an 'identified' flag so easily. |
693 | if (need_identify (item)) |
692 | if (item->need_identify ()) |
694 | identify (item); |
693 | identify (item); |
695 | |
694 | |
696 | insert_ob_in_map_at (item, converter->map, converter, 0, converter->x, converter->y); |
695 | item->insert_at (converter, 0, INS_NO_WALK_ON); |
|
|
696 | |
697 | return 1; |
697 | return 1; |
698 | } |
698 | } |
699 | |
699 | |
700 | /** |
700 | /** |
701 | * Handle apply on containers. |
701 | * Handle apply on containers. |
… | |
… | |
732 | op->close_container (); |
732 | op->close_container (); |
733 | return 1; |
733 | return 1; |
734 | } |
734 | } |
735 | else if (!sack->env) |
735 | else if (!sack->env) |
736 | { |
736 | { |
737 | // active, but not ours: some other player has opened it |
737 | // active on floor, but not ours: some other player has opened it |
|
|
738 | // normally this only happens to dms standing on the same space. |
|
|
739 | // but it doesn't hurt to handle it. |
738 | op->failmsg (format ("Somebody else is using the %s already.", query_name (sack))); |
740 | op->failmsgf ("Somebody else is using the %s already.", query_name (sack)); |
739 | return 1; |
741 | return 1; |
740 | } |
742 | } |
|
|
743 | } |
741 | |
744 | |
742 | // fall through to opening it (active in inv) |
745 | // it's locked? |
|
|
746 | if (sack->slaying) |
743 | } |
747 | { |
744 | else if (sack->env) |
748 | if (object *tmp = find_key (op, op, sack)) |
|
|
749 | { |
|
|
750 | op->statusmsg (format ("You unlock %s with %s.", query_name (sack), query_name (tmp))); |
|
|
751 | } |
|
|
752 | else |
|
|
753 | { |
|
|
754 | sack->flag [FLAG_APPLIED] = false; // might be applied in inv, let the user close it |
|
|
755 | esrv_update_item (UPD_FLAGS, op, sack); |
|
|
756 | op->statusmsg (format ("You don't have the key to unlock %s.", query_name (sack))); |
|
|
757 | return 1; |
|
|
758 | } |
|
|
759 | } |
|
|
760 | |
|
|
761 | if (sack->env && !sack->flag [FLAG_APPLIED]) |
745 | { |
762 | { |
746 | // it is in our env, so activate it, do not open yet |
763 | // it is in our env, so activate it, do not open yet |
747 | op->close_container (); |
764 | op->close_container (); |
748 | sack->flag [FLAG_APPLIED] = 1; |
765 | sack->flag [FLAG_APPLIED] = true; |
749 | esrv_update_item (UPD_FLAGS, op, sack); |
766 | esrv_update_item (UPD_FLAGS, op, sack); |
750 | op->statusmsg (format ("You ready %s.", query_name (sack))); |
767 | op->statusmsg (format ("You ready %s.", query_name (sack))); |
751 | return 1; |
|
|
752 | } |
|
|
753 | |
|
|
754 | // it's locked? |
|
|
755 | if (sack->slaying) |
|
|
756 | { |
768 | } |
757 | if (object *tmp = find_key (op, op, sack)) |
|
|
758 | op->statusmsg (format ("You unlock %s with %s.", query_name (sack), query_name (tmp))); |
|
|
759 | else |
769 | else |
760 | { |
|
|
761 | op->statusmsg (format ("You don't have the key to unlock %s.", query_name (sack))); |
|
|
762 | return 1; |
|
|
763 | } |
|
|
764 | } |
|
|
765 | |
|
|
766 | op->open_container (sack); |
770 | op->open_container (sack); |
767 | |
771 | |
768 | return 1; |
772 | return 1; |
769 | } |
773 | } |
770 | |
774 | |
771 | /** |
775 | /** |
… | |
… | |
819 | { |
823 | { |
820 | int rv = 0; |
824 | int rv = 0; |
821 | double opinion; |
825 | double opinion; |
822 | object *tmp, *next; |
826 | object *tmp, *next; |
823 | |
827 | |
824 | SET_FLAG (op, FLAG_NO_APPLY); /* prevent loops */ |
828 | op->set_flag (FLAG_NO_APPLY); /* prevent loops */ |
825 | |
829 | |
826 | bool has_unpaid = false; |
830 | bool has_unpaid = false; |
827 | |
831 | |
828 | // quite inefficient to do this here twice, but the api doesn't lend itself to |
832 | // quite inefficient to do this here twice, but the api doesn't lend itself to |
829 | // a quick and small change :( |
833 | // a quick and small change :( |
… | |
… | |
842 | */ |
846 | */ |
843 | for (tmp = op->inv; tmp; tmp = next) |
847 | for (tmp = op->inv; tmp; tmp = next) |
844 | { |
848 | { |
845 | next = tmp->below; |
849 | next = tmp->below; |
846 | |
850 | |
847 | if (QUERY_FLAG (tmp, FLAG_UNPAID)) |
851 | if (tmp->flag [FLAG_UNPAID]) |
848 | { |
852 | { |
849 | int i = find_free_spot (tmp, op->map, op->x, op->y, 1, 9); |
853 | int i = find_free_spot (tmp, op->map, op->x, op->y, 1, 9); |
850 | |
854 | |
851 | if (i >= 0) |
855 | if (i >= 0) |
852 | tmp->move (i); |
856 | tmp->move (i); |
853 | } |
857 | } |
854 | } |
858 | } |
855 | |
859 | |
856 | /* Don't teleport things like spell effects */ |
860 | /* Don't teleport things like spell effects */ |
857 | if (QUERY_FLAG (op, FLAG_NO_PICK)) |
861 | if (op->flag [FLAG_NO_PICK]) |
858 | return 0; |
862 | return 0; |
859 | |
863 | |
860 | /* unpaid objects, or non living objects, can't transfer by |
864 | /* unpaid objects, or non living objects, can't transfer by |
861 | * shop mats. Instead, put it on a nearby space. |
865 | * shop mats. Instead, put it on a nearby space. |
862 | */ |
866 | */ |
863 | if (QUERY_FLAG (op, FLAG_UNPAID) || !QUERY_FLAG (op, FLAG_ALIVE)) |
867 | if (op->flag [FLAG_UNPAID] || !op->flag [FLAG_ALIVE]) |
864 | { |
868 | { |
865 | /* Somebody dropped an unpaid item, just move to an adjacent place. */ |
869 | /* Somebody dropped an unpaid item, just move to an adjacent place. */ |
866 | int i = find_free_spot (op, op->map, op->x, op->y, 1, 9); |
870 | int i = find_free_spot (op, op->map, op->x, op->y, 1, 9); |
867 | |
871 | |
868 | if (i != -1) |
872 | if (i != -1) |
… | |
… | |
923 | op->y += freearr_y[i]; |
927 | op->y += freearr_y[i]; |
924 | rv = insert_ob_in_map (op, op->map, shop_mat, 0) == NULL; |
928 | rv = insert_ob_in_map (op, op->map, shop_mat, 0) == NULL; |
925 | } |
929 | } |
926 | } |
930 | } |
927 | |
931 | |
928 | CLEAR_FLAG (op, FLAG_NO_APPLY); |
932 | op->clr_flag (FLAG_NO_APPLY); |
929 | return rv; |
933 | return rv; |
930 | } |
934 | } |
931 | |
935 | |
932 | /** |
936 | /** |
933 | * Handles applying a sign. |
937 | * Handles applying a sign. |
… | |
… | |
961 | op->failmsg ("You cannot read it anymore."); |
965 | op->failmsg ("You cannot read it anymore."); |
962 | |
966 | |
963 | return; |
967 | return; |
964 | } |
968 | } |
965 | |
969 | |
966 | if (!QUERY_FLAG (op, FLAG_WIZPASS)) |
970 | if (!op->flag [FLAG_WIZPASS]) |
967 | sign->last_eat++; |
971 | sign->last_eat++; |
968 | } |
972 | } |
969 | |
973 | |
970 | /* Sign or magic mouth? Do we need to see it, or does it talk to us? |
974 | /* Sign or magic mouth? Do we need to see it, or does it talk to us? |
971 | * No way to know for sure. The presumption is basically that if |
975 | * No way to know for sure. The presumption is basically that if |
972 | * move_on is zero, it needs to be manually applied (doesn't talk |
976 | * move_on is zero, it needs to be manually applied (doesn't talk |
973 | * to us). |
977 | * to us). |
974 | */ |
978 | */ |
975 | if (QUERY_FLAG (op, FLAG_BLIND) && !QUERY_FLAG (op, FLAG_WIZ) && !sign->move_on) |
979 | if (op->flag [FLAG_BLIND] && !op->flag [FLAG_WIZ] && !sign->move_on) |
976 | { |
980 | { |
977 | op->failmsg ("You are unable to read while blind!"); |
981 | op->failmsg ("You are unable to read while blind!"); |
978 | return; |
982 | return; |
979 | } |
983 | } |
980 | |
984 | |
… | |
… | |
1059 | who->flag [FLAG_READY_WEAPON] = false; |
1063 | who->flag [FLAG_READY_WEAPON] = false; |
1060 | |
1064 | |
1061 | // unapplying a weapon or skill tool should also unapply the skill it governs |
1065 | // unapplying a weapon or skill tool should also unapply the skill it governs |
1062 | // but this is hard, as it shouldn't do so when the skill can |
1066 | // but this is hard, as it shouldn't do so when the skill can |
1063 | // be used for other reasons |
1067 | // be used for other reasons |
|
|
1068 | //TODO: really? |
1064 | if (who->chosen_skill) |
1069 | if (who->chosen_skill) |
1065 | if (!who->chosen_skill->flag [FLAG_CAN_USE_SKILL]) |
1070 | if (!who->chosen_skill->flag [FLAG_CAN_USE_SKILL]) |
1066 | unapply_special (who, op, 0); |
1071 | unapply_special (who, who->chosen_skill, 0); |
1067 | |
1072 | |
1068 | break; |
1073 | break; |
1069 | |
1074 | |
|
|
1075 | case RANGED: |
1070 | case BOW: |
1076 | case BOW: |
1071 | case WAND: |
1077 | case WAND: |
1072 | case ROD: |
1078 | case ROD: |
1073 | case HORN: |
1079 | case HORN: |
1074 | case RANGED: |
|
|
1075 | if (player *pl = who->contr) |
1080 | if (player *pl = who->contr) |
1076 | { |
1081 | { |
1077 | who->statusmsg (format ("You unready %s.", query_name (op))); |
1082 | who->statusmsg (format ("You unready %s.", query_name (op))); |
1078 | change_abil (who, op); |
1083 | change_abil (who, op); |
1079 | } |
1084 | } |
1080 | else |
1085 | else |
1081 | { |
1086 | { |
1082 | who->change_skill (0); |
|
|
1083 | |
|
|
1084 | if (op->type == BOW) |
1087 | if (op->type == BOW) |
1085 | op->flag [FLAG_READY_BOW ] = false; |
1088 | op->flag [FLAG_READY_BOW ] = false; |
1086 | else |
1089 | else |
1087 | op->flag [FLAG_READY_RANGE] = false; |
1090 | op->flag [FLAG_READY_RANGE] = false; |
1088 | } |
1091 | } |
… | |
… | |
1169 | static bool |
1172 | static bool |
1170 | unapply_for_ob (object *who, object *op, int aflags) |
1173 | unapply_for_ob (object *who, object *op, int aflags) |
1171 | { |
1174 | { |
1172 | if (op->is_range ()) |
1175 | if (op->is_range ()) |
1173 | for (object *tmp = who->inv; tmp; tmp = tmp->below) |
1176 | for (object *tmp = who->inv; tmp; tmp = tmp->below) |
1174 | if (QUERY_FLAG (tmp, FLAG_APPLIED) && tmp->is_range ()) |
1177 | if (tmp->flag [FLAG_APPLIED] && tmp->is_range ()) |
1175 | if ((aflags & AP_IGNORE_CURSE) || (aflags & AP_PRINT) || (!QUERY_FLAG (tmp, FLAG_CURSED) && !QUERY_FLAG (tmp, FLAG_DAMNED))) |
1178 | if ((aflags & AP_IGNORE_CURSE) || (aflags & AP_PRINT) || (!tmp->flag [FLAG_CURSED] && !tmp->flag [FLAG_DAMNED])) |
1176 | { |
1179 | { |
1177 | if (aflags & AP_PRINT) |
1180 | if (aflags & AP_PRINT) |
1178 | who->failmsg (query_name (tmp)); |
1181 | who->failmsg (query_name (tmp)); |
1179 | else |
1182 | else |
1180 | unapply_special (who, tmp, aflags); |
1183 | unapply_special (who, tmp, aflags); |
… | |
… | |
1183 | { |
1186 | { |
1184 | /* In this case, we want to try and remove a cursed item. |
1187 | /* In this case, we want to try and remove a cursed item. |
1185 | * While we know it won't work, we want unapply_special to |
1188 | * While we know it won't work, we want unapply_special to |
1186 | * at least generate the message. |
1189 | * at least generate the message. |
1187 | */ |
1190 | */ |
1188 | who->failmsg (format ("No matter how hard you try, you just can't remove the %s." CANNOT_REMOVE_CURSED, query_name (tmp))); |
1191 | who->failmsgf ("No matter how hard you try, you just can't remove the %s." CANNOT_REMOVE_CURSED, query_name (tmp)); |
1189 | return 1; |
1192 | return 1; |
1190 | } |
1193 | } |
1191 | |
1194 | |
1192 | for (int i = 0; i < NUM_BODY_LOCATIONS; i++) |
1195 | for (int i = 0; i < NUM_BODY_LOCATIONS; i++) |
1193 | { |
1196 | { |
… | |
… | |
1213 | #endif |
1216 | #endif |
1214 | return 1; |
1217 | return 1; |
1215 | } |
1218 | } |
1216 | |
1219 | |
1217 | /* If we are just printing, we don't care about cursed status */ |
1220 | /* If we are just printing, we don't care about cursed status */ |
1218 | if ((aflags & AP_IGNORE_CURSE) || (aflags & AP_PRINT) || (!(QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED)))) |
1221 | if ((aflags & AP_IGNORE_CURSE) || (aflags & AP_PRINT) || (!(tmp->flag [FLAG_CURSED] || tmp->flag [FLAG_DAMNED]))) |
1219 | { |
1222 | { |
1220 | if (aflags & AP_PRINT) |
1223 | if (aflags & AP_PRINT) |
1221 | who->failmsg (query_name (tmp)); |
1224 | who->failmsg (query_name (tmp)); |
1222 | else |
1225 | else |
1223 | unapply_special (who, tmp, aflags); |
1226 | unapply_special (who, tmp, aflags); |
… | |
… | |
1227 | /* Cursed item that we can't unequip - tell the player. |
1230 | /* Cursed item that we can't unequip - tell the player. |
1228 | * Note this could be annoying if this is just one of a few, |
1231 | * Note this could be annoying if this is just one of a few, |
1229 | * so it may not be critical (eg, putting on a ring and you have |
1232 | * so it may not be critical (eg, putting on a ring and you have |
1230 | * one cursed ring.) |
1233 | * one cursed ring.) |
1231 | */ |
1234 | */ |
1232 | who->failmsg (format ("The %s just won't come off." CANNOT_REMOVE_CURSED, query_name (tmp))); |
1235 | who->failmsgf ("The %s just won't come off." CANNOT_REMOVE_CURSED, query_name (tmp)); |
1233 | } |
1236 | } |
1234 | |
1237 | |
1235 | last = tmp->below; |
1238 | last = tmp->below; |
1236 | } |
1239 | } |
1237 | /* if we got here, this slot is freed up - otherwise, if it wasn't freed up, the |
1240 | /* if we got here, this slot is freed up - otherwise, if it wasn't freed up, the |
… | |
… | |
1335 | * the weapon/shield checks, and the range checks for monsters, |
1338 | * the weapon/shield checks, and the range checks for monsters, |
1336 | * because you can't control those just by body location - bows, shields, |
1339 | * because you can't control those just by body location - bows, shields, |
1337 | * and weapons all use the same slot. Similar for horn/rod/wand - they |
1340 | * and weapons all use the same slot. Similar for horn/rod/wand - they |
1338 | * all use the same location. |
1341 | * all use the same location. |
1339 | */ |
1342 | */ |
1340 | if (op->type == WEAPON && !QUERY_FLAG (who, FLAG_USE_WEAPON)) |
1343 | if (op->type == WEAPON && !who->flag [FLAG_USE_WEAPON]) |
1341 | retval |= CAN_APPLY_RESTRICTION; |
1344 | retval |= CAN_APPLY_RESTRICTION; |
1342 | |
1345 | |
1343 | if (op->type == SHIELD && !QUERY_FLAG (who, FLAG_USE_SHIELD)) |
1346 | if (op->type == SHIELD && !who->flag [FLAG_USE_SHIELD]) |
1344 | retval |= CAN_APPLY_RESTRICTION; |
1347 | retval |= CAN_APPLY_RESTRICTION; |
1345 | |
1348 | |
1346 | if (who->type != PLAYER) |
1349 | if (who->type != PLAYER) |
1347 | { |
1350 | { |
1348 | if ((op->type == WAND || op->type == HORN || op->type == ROD) && !QUERY_FLAG (who, FLAG_USE_RANGE)) |
1351 | if ((op->type == WAND || op->type == HORN || op->type == ROD) && !who->flag [FLAG_USE_RANGE]) |
1349 | retval |= CAN_APPLY_RESTRICTION; |
1352 | retval |= CAN_APPLY_RESTRICTION; |
1350 | |
1353 | |
1351 | if (op->type == BOW && !QUERY_FLAG (who, FLAG_USE_BOW)) |
1354 | if (op->type == BOW && !who->flag [FLAG_USE_BOW]) |
1352 | retval |= CAN_APPLY_RESTRICTION; |
1355 | retval |= CAN_APPLY_RESTRICTION; |
1353 | |
1356 | |
1354 | if (op->type == RING && !QUERY_FLAG (who, FLAG_USE_RING)) |
1357 | if (op->type == RING && !who->flag [FLAG_USE_RING]) |
1355 | retval |= CAN_APPLY_RESTRICTION; |
1358 | retval |= CAN_APPLY_RESTRICTION; |
1356 | |
1359 | |
1357 | if (op->type == BOW && !QUERY_FLAG (who, FLAG_USE_BOW)) |
1360 | if (op->type == BOW && !who->flag [FLAG_USE_BOW]) |
1358 | retval |= CAN_APPLY_RESTRICTION; |
1361 | retval |= CAN_APPLY_RESTRICTION; |
1359 | } |
1362 | } |
1360 | |
1363 | |
1361 | return retval; |
1364 | return retval; |
1362 | } |
1365 | } |
… | |
… | |
1390 | |
1393 | |
1391 | static bool |
1394 | static bool |
1392 | apply_special (object *who, object *op, int aflags) |
1395 | apply_special (object *who, object *op, int aflags) |
1393 | { |
1396 | { |
1394 | int basic_flag = aflags & AP_MODE; |
1397 | int basic_flag = aflags & AP_MODE; |
1395 | object *tmp, *tmp2, *skop = NULL; |
1398 | object *tmp, *skop = NULL; |
1396 | |
|
|
1397 | if (who == NULL) |
|
|
1398 | { |
|
|
1399 | LOG (llevError, "apply_special() from object without environment.\n"); |
|
|
1400 | return 1; |
|
|
1401 | } |
|
|
1402 | |
|
|
1403 | //TODO: remove these when apply_special is no longer exposed |
|
|
1404 | if (op->env != who) |
|
|
1405 | return 1; /* op is not in inventory */ |
|
|
1406 | |
1399 | |
1407 | /* trying to unequip op */ |
1400 | /* trying to unequip op */ |
1408 | if (QUERY_FLAG (op, FLAG_APPLIED)) |
1401 | if (op->flag [FLAG_APPLIED]) |
1409 | { |
1402 | { |
1410 | /* always apply, so no reason to unapply */ |
1403 | /* always apply, so no reason to unapply */ |
1411 | if (basic_flag == AP_APPLY) |
1404 | if (basic_flag == AP_APPLY) |
1412 | return 0; |
1405 | return 0; |
1413 | |
1406 | |
1414 | if (!(aflags & AP_IGNORE_CURSE) && (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED))) |
|
|
1415 | { |
|
|
1416 | who->failmsg (format ("No matter how hard you try, you just can't remove %s." CANNOT_REMOVE_CURSED, query_name (op))); |
|
|
1417 | return 1; |
|
|
1418 | } |
|
|
1419 | |
|
|
1420 | return unapply_special (who, op, aflags); |
1407 | return unapply_special (who, op, aflags); |
1421 | } |
1408 | } |
1422 | else if (basic_flag == AP_UNAPPLY) |
1409 | else if (basic_flag == AP_UNAPPLY) |
1423 | return 0; |
1410 | return 0; |
1424 | |
1411 | |
… | |
… | |
1427 | /* Can't just apply this object. Lets see what not and what to do */ |
1414 | /* Can't just apply this object. Lets see what not and what to do */ |
1428 | if (int i = can_apply_object (who, op)) |
1415 | if (int i = can_apply_object (who, op)) |
1429 | { |
1416 | { |
1430 | if (i & CAN_APPLY_NEVER) |
1417 | if (i & CAN_APPLY_NEVER) |
1431 | { |
1418 | { |
1432 | who->failmsg (format ("You don't have the body to use a %s. H<You can never apply this item.>", query_name (op))); |
1419 | who->failmsgf ("You don't have the body to use a %s. H<You can never apply this item.>", query_name (op)); |
1433 | return 1; |
1420 | return 1; |
1434 | } |
1421 | } |
1435 | else if (i & CAN_APPLY_RESTRICTION) |
1422 | else if (i & CAN_APPLY_RESTRICTION) |
1436 | { |
1423 | { |
1437 | who->failmsg (format ( |
1424 | who->failmsgf ( |
1438 | "You have a prohibition against using a %s. " |
1425 | "You have a prohibition against using a %s. " |
1439 | "H<Your belief, profession or class prevents you from applying this item.>", |
1426 | "H<Your belief, profession or class prevents you from applying this item.>", |
1440 | query_name (op) |
1427 | query_name (op) |
1441 | )); |
1428 | ); |
1442 | return 1; |
1429 | return 1; |
1443 | } |
1430 | } |
1444 | |
1431 | |
1445 | if (who->type != PLAYER) |
1432 | if (who->type != PLAYER) |
1446 | { |
1433 | { |
… | |
… | |
1467 | // try to ready attached skill first |
1454 | // try to ready attached skill first |
1468 | skop = find_skill_by_name (who, op->skill); |
1455 | skop = find_skill_by_name (who, op->skill); |
1469 | |
1456 | |
1470 | if (!skop) |
1457 | if (!skop) |
1471 | { |
1458 | { |
1472 | who->failmsg (format ("You need the %s skill to use this item!", &op->skill)); |
1459 | who->failmsgf ("You need the %s skill to use this item!", &op->skill); |
1473 | return 1; |
1460 | return 1; |
1474 | } |
1461 | } |
1475 | else if (!who->apply (skop, AP_APPLY | AP_NO_SLOT)) |
1462 | else if (!who->apply (skop, AP_APPLY | AP_NO_SLOT)) |
1476 | { |
1463 | { |
1477 | who->failmsg (format ("You can't use the required %s skill!", &op->skill)); |
1464 | who->failmsgf ("You can't use the required %s skill!", &op->skill); |
1478 | return 1; |
1465 | return 1; |
1479 | } |
1466 | } |
1480 | } |
1467 | } |
1481 | |
1468 | |
1482 | if (!check_item_power (who, op->item_power)) |
1469 | if (!check_item_power (who, op->item_power)) |
… | |
… | |
1514 | if (player *pl = who->contr) |
1501 | if (player *pl = who->contr) |
1515 | { |
1502 | { |
1516 | who->statusmsg (format ("You wield %s.", query_name (op))); |
1503 | who->statusmsg (format ("You wield %s.", query_name (op))); |
1517 | change_abil (who, op); |
1504 | change_abil (who, op); |
1518 | } |
1505 | } |
1519 | else |
|
|
1520 | who->change_skill (skop); |
|
|
1521 | |
1506 | |
1522 | op->flag [FLAG_READY_WEAPON] = true; |
1507 | op->flag [FLAG_READY_WEAPON] = true; |
1523 | break; |
1508 | break; |
1524 | |
1509 | |
1525 | case ARMOUR: |
1510 | case ARMOUR: |
… | |
… | |
1530 | case GIRDLE: |
1515 | case GIRDLE: |
1531 | case BRACERS: |
1516 | case BRACERS: |
1532 | case CLOAK: |
1517 | case CLOAK: |
1533 | case RING: |
1518 | case RING: |
1534 | case AMULET: |
1519 | case AMULET: |
1535 | SET_FLAG (op, FLAG_APPLIED); |
1520 | op->set_flag (FLAG_APPLIED); |
1536 | who->statusmsg (format ("You wear %s.", query_name (op))); |
1521 | who->statusmsg (format ("You wear %s.", query_name (op))); |
1537 | change_abil (who, op); |
1522 | change_abil (who, op); |
1538 | break; |
1523 | break; |
1539 | |
1524 | |
1540 | case SKILL_TOOL: |
1525 | case SKILL_TOOL: |
1541 | // applying a skill tool does not ready the skill |
1526 | // applying a skill tool does not ready the skill |
1542 | // if something needs the skill, it has to ready it itself |
1527 | // if something needs the skill, it has to ready it itself |
1543 | //TODO: unapplying should unapply the skill, though |
1528 | //TODO: unapplying should unapply the skill, though |
1544 | SET_FLAG (op, FLAG_APPLIED); |
1529 | op->set_flag (FLAG_APPLIED); |
1545 | break; |
1530 | break; |
1546 | |
1531 | |
1547 | case SKILL: |
1532 | case SKILL: |
1548 | if (!(aflags & AP_NO_SLOT)) |
|
|
1549 | { |
|
|
1550 | // skill is used on it's own, as opposed to being a chosen_skill |
|
|
1551 | |
|
|
1552 | if (skill_flags [op->subtype] & (SF_NEED_ITEM | SF_MANA)) |
|
|
1553 | { |
|
|
1554 | who->failmsg (format ( |
|
|
1555 | "You feel as if you wanted to do something funny, but you can't remember what. " |
|
|
1556 | "H<The %s skill needs something else to function, for example a tool, weapon, rod, or spell. " |
|
|
1557 | "It cannot be used on its own.>", |
|
|
1558 | &op->skill |
|
|
1559 | )); |
|
|
1560 | if (tmp) who->insert (tmp); |
|
|
1561 | return 1; |
|
|
1562 | } |
|
|
1563 | |
|
|
1564 | if (skill_flags [op->subtype] & SF_AUTARK |
|
|
1565 | || !(skill_flags [op->subtype] & (SF_COMBAT | SF_RANGED))) |
|
|
1566 | { |
|
|
1567 | if (skill_flags [op->subtype] & SF_USE) |
|
|
1568 | who->failmsg (format ( |
|
|
1569 | "You feel as if you wanted to do something funny, but you can't remember what. " |
|
|
1570 | "H<The %s skill cannot be readied, instead, try C<use_skill %s>.>", |
|
|
1571 | &op->skill, &op->skill |
|
|
1572 | )); |
|
|
1573 | else |
|
|
1574 | who->failmsg (format ( |
|
|
1575 | "You feel as if you wanted to do something funny, but you can't remember what. " |
|
|
1576 | "H<The %s skill cannot be readied or used, it is always active.>", |
|
|
1577 | &op->skill |
|
|
1578 | )); |
|
|
1579 | |
|
|
1580 | if (tmp) who->insert (tmp); |
|
|
1581 | |
|
|
1582 | return 1; |
|
|
1583 | } |
|
|
1584 | |
|
|
1585 | if (who->contr) |
1533 | if (who->contr) |
1586 | if (op->invisible) |
1534 | if (op->invisible) |
1587 | who->statusmsg (format ("You can now use the %s skill.", &op->skill)); |
1535 | who->statusmsg (format ("You can now use the %s skill.", &op->skill)); |
1588 | else |
1536 | else |
1589 | who->statusmsg (format ("You ready %s.", query_name (op))); |
1537 | who->statusmsg (format ("You ready %s.", query_name (op))); |
1590 | } |
|
|
1591 | |
1538 | |
1592 | SET_FLAG (who, FLAG_READY_SKILL); |
1539 | who->set_flag (FLAG_READY_SKILL); |
1593 | SET_FLAG (op, FLAG_APPLIED); |
1540 | op->set_flag (FLAG_APPLIED); |
1594 | change_abil (who, op); |
1541 | change_abil (who, op); |
1595 | break; |
1542 | break; |
1596 | |
1543 | |
1597 | case BOW: |
1544 | case BOW: |
1598 | if (op->level && (!op->name.starts_with (who->name) || op->name [who->name.length ()] != '\'')) |
1545 | if (op->level && (!op->name.starts_with (who->name) || op->name [who->name.length ()] != '\'')) |
… | |
… | |
1629 | |
1576 | |
1630 | /*FALLTHROUGH*/ |
1577 | /*FALLTHROUGH*/ |
1631 | case WAND: |
1578 | case WAND: |
1632 | case ROD: |
1579 | case ROD: |
1633 | case HORN: |
1580 | case HORN: |
1634 | /* check for skill, alter player status */ |
|
|
1635 | |
|
|
1636 | if (!skop) |
|
|
1637 | { |
|
|
1638 | who->failmsg (format ("The %s is broken, please report this to the dungeon master!", query_name (op)));//TODO |
|
|
1639 | if (tmp) who->insert (tmp); |
|
|
1640 | return 1; |
|
|
1641 | } |
|
|
1642 | |
|
|
1643 | op->flag [FLAG_APPLIED] = true; |
1581 | op->flag [FLAG_APPLIED] = true; |
1644 | |
1582 | |
1645 | if (player *pl = who->contr) |
1583 | if (player *pl = who->contr) |
1646 | { |
1584 | { |
1647 | who->statusmsg (format ("You ready %s.", query_name (op))); |
1585 | who->statusmsg (format ("You ready %s.", query_name (op))); |
… | |
… | |
1651 | |
1589 | |
1652 | change_abil (who, op); |
1590 | change_abil (who, op); |
1653 | } |
1591 | } |
1654 | else |
1592 | else |
1655 | { |
1593 | { |
1656 | who->change_skill (skop); |
|
|
1657 | |
|
|
1658 | if (op->type == BOW) |
1594 | if (op->type == BOW) |
1659 | op->flag [FLAG_READY_BOW ] = true; |
1595 | op->flag [FLAG_READY_BOW ] = true; |
1660 | else |
1596 | else |
1661 | op->flag [FLAG_READY_RANGE] = true; |
1597 | op->flag [FLAG_READY_RANGE] = true; |
1662 | } |
1598 | } |
… | |
… | |
1673 | |
1609 | |
1674 | default: |
1610 | default: |
1675 | who->statusmsg (format ("You apply %s.", query_name (op))); |
1611 | who->statusmsg (format ("You apply %s.", query_name (op))); |
1676 | } |
1612 | } |
1677 | |
1613 | |
1678 | SET_FLAG (op, FLAG_APPLIED); |
1614 | op->set_flag (FLAG_APPLIED); |
1679 | |
1615 | |
1680 | if (tmp) who->insert (tmp); |
1616 | if (tmp) who->insert (tmp); |
1681 | |
1617 | |
1682 | who->update_stats (); |
1618 | who->update_stats (); |
1683 | |
1619 | |
1684 | /* We exclude spell casting objects. The fire code will set the |
1620 | /* We exclude spell casting objects. The fire code will set the |
1685 | * been applied flag when they are used - until that point, |
1621 | * been applied flag when they are used - until that point, |
1686 | * you don't know anything about them. |
1622 | * you don't know anything about them. |
1687 | */ |
1623 | */ |
1688 | if (who->type == PLAYER && op->type != WAND && op->type != HORN && op->type != ROD) |
1624 | if (who->type == PLAYER && op->type != WAND && op->type != HORN && op->type != ROD) |
1689 | SET_FLAG (op, FLAG_BEEN_APPLIED); |
1625 | op->set_flag (FLAG_BEEN_APPLIED); |
1690 | |
1626 | |
1691 | if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED)) |
1627 | if (op->flag [FLAG_CURSED] || op->flag [FLAG_DAMNED]) |
1692 | if (who->type == PLAYER) |
1628 | if (who->type == PLAYER) |
1693 | { |
1629 | { |
1694 | who->failmsg ( |
1630 | who->failmsg ( |
1695 | "Oops, it feels deadly cold! " |
1631 | "Oops, it feels deadly cold! " |
1696 | "H<Maybe it wasn't such a bright idea to apply this cursed or damned item.>" |
1632 | "H<Maybe it wasn't such a bright idea to apply this cursed or damned item.>" |
1697 | ); |
1633 | ); |
1698 | SET_FLAG (op, FLAG_KNOWN_CURSED); |
1634 | op->set_flag (FLAG_KNOWN_CURSED); |
1699 | } |
1635 | } |
1700 | |
1636 | |
1701 | if (object *pl = op->visible_to ()) |
1637 | if (object *pl = op->visible_to ()) |
1702 | esrv_send_item (pl, op); |
1638 | esrv_send_item (pl, op); |
1703 | |
1639 | |
… | |
… | |
1776 | return 0; |
1712 | return 0; |
1777 | |
1713 | |
1778 | /* if the player has a marked item, identify that if it needs to be |
1714 | /* if the player has a marked item, identify that if it needs to be |
1779 | * identified. If it doesn't, then go through the player inventory. |
1715 | * identified. If it doesn't, then go through the player inventory. |
1780 | */ |
1716 | */ |
1781 | if (object *marked = find_marked_object (pl)) |
1717 | if (object *marked = pl->mark ()) |
1782 | if (!QUERY_FLAG (marked, FLAG_IDENTIFIED) && need_identify (marked)) |
1718 | if (!marked->flag [FLAG_IDENTIFIED] && marked->need_identify ()) |
1783 | { |
1719 | { |
1784 | if (operate_altar (altar, &money, pl)) |
1720 | if (operate_altar (altar, &money, pl)) |
1785 | { |
1721 | { |
1786 | identify (marked); |
1722 | identify (marked); |
1787 | |
1723 | |
… | |
… | |
1793 | } |
1729 | } |
1794 | } |
1730 | } |
1795 | |
1731 | |
1796 | for (object *id = pl->inv; id; id = id->below) |
1732 | for (object *id = pl->inv; id; id = id->below) |
1797 | { |
1733 | { |
1798 | if (!QUERY_FLAG (id, FLAG_IDENTIFIED) && !id->invisible && need_identify (id)) |
1734 | if (!id->flag [FLAG_IDENTIFIED] && !id->invisible && id->need_identify ()) |
1799 | { |
1735 | { |
1800 | if (operate_altar (altar, &money, pl)) |
1736 | if (operate_altar (altar, &money, pl)) |
1801 | { |
1737 | { |
1802 | identify (id); |
1738 | identify (id); |
1803 | |
1739 | |
… | |
… | |
1830 | * matching item. |
1766 | * matching item. |
1831 | **/ |
1767 | **/ |
1832 | void |
1768 | void |
1833 | handle_apply_yield (object *tmp) |
1769 | handle_apply_yield (object *tmp) |
1834 | { |
1770 | { |
1835 | if (shstr_tmp yield = tmp->kv (shstr_on_use_yield)) |
1771 | if (shstr_tmp yield = tmp->kv [shstr_on_use_yield]) |
1836 | archetype::get (yield)->insert_at (tmp, tmp, INS_BELOW_ORIGINATOR); |
1772 | archetype::get (yield)->insert_at (tmp, tmp, INS_BELOW_ORIGINATOR); |
1837 | } |
1773 | } |
1838 | |
1774 | |
1839 | /** |
1775 | /** |
1840 | * Handles applying a potion. |
1776 | * Handles applying a potion. |
… | |
… | |
1843 | apply_potion (object *op, object *tmp) |
1779 | apply_potion (object *op, object *tmp) |
1844 | { |
1780 | { |
1845 | int got_one = 0, i; |
1781 | int got_one = 0, i; |
1846 | object *force = 0; |
1782 | object *force = 0; |
1847 | |
1783 | |
1848 | object *floor = GET_MAP_OB (op->map, op->x, op->y); |
|
|
1849 | |
|
|
1850 | if (get_map_flags (op->map, NULL, op->x, op->y, NULL, NULL) & P_SAFE) |
1784 | if (get_map_flags (op->map, NULL, op->x, op->y, NULL, NULL) & P_SAFE) |
1851 | { |
1785 | { |
1852 | op->failmsg ("Gods prevent you from using this here, it's sacred ground!"); |
1786 | op->failmsg ("Gods prevent you from using this here, it's sacred ground!"); |
1853 | |
1787 | |
1854 | CLEAR_FLAG (tmp, FLAG_APPLIED); |
1788 | tmp->clr_flag (FLAG_APPLIED); |
1855 | return 0; |
1789 | return 0; |
1856 | } |
1790 | } |
1857 | |
1791 | |
1858 | if (op->type == PLAYER) |
1792 | if (op->type == PLAYER) |
1859 | if (!QUERY_FLAG (tmp, FLAG_IDENTIFIED)) |
1793 | if (!tmp->flag [FLAG_IDENTIFIED]) |
1860 | identify (tmp); |
1794 | identify (tmp); |
1861 | |
1795 | |
1862 | handle_apply_yield (tmp); |
1796 | handle_apply_yield (tmp); |
1863 | |
1797 | |
1864 | /* Potion of restoration - only for players */ |
1798 | /* Potion of restoration - only for players */ |
1865 | if (op->type == PLAYER && (tmp->attacktype & AT_DEPLETE)) |
1799 | if (op->type == PLAYER && (tmp->attacktype & AT_DEPLETE)) |
1866 | { |
1800 | { |
1867 | object *depl; |
1801 | object *depl; |
1868 | archetype *at; |
1802 | archetype *at; |
1869 | |
1803 | |
1870 | if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED)) |
1804 | if (tmp->flag [FLAG_CURSED] || tmp->flag [FLAG_DAMNED]) |
1871 | { |
1805 | { |
1872 | op->drain_stat (); |
1806 | op->drain_stat (); |
1873 | op->update_stats (); |
1807 | op->update_stats (); |
1874 | tmp->decrease (); |
1808 | tmp->decrease (); |
1875 | return 1; |
1809 | return 1; |
… | |
… | |
1902 | /* improvement potion - only for players */ |
1836 | /* improvement potion - only for players */ |
1903 | if (op->type == PLAYER && (tmp->attacktype & AT_GODPOWER)) |
1837 | if (op->type == PLAYER && (tmp->attacktype & AT_GODPOWER)) |
1904 | { |
1838 | { |
1905 | for (i = 1; i < min (11, op->level); i++) |
1839 | for (i = 1; i < min (11, op->level); i++) |
1906 | { |
1840 | { |
1907 | if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED)) |
1841 | if (tmp->flag [FLAG_CURSED] || tmp->flag [FLAG_DAMNED]) |
1908 | { |
1842 | { |
1909 | if (op->contr->levhp[i] != 1) |
1843 | if (op->contr->levhp[i] != 1) |
1910 | { |
1844 | { |
1911 | op->contr->levhp[i] = 1; |
1845 | op->contr->levhp[i] = 1; |
1912 | break; |
1846 | break; |
… | |
… | |
1948 | |
1882 | |
1949 | /* Just makes checking easier */ |
1883 | /* Just makes checking easier */ |
1950 | if (i < min (11, op->level)) |
1884 | if (i < min (11, op->level)) |
1951 | got_one = 1; |
1885 | got_one = 1; |
1952 | |
1886 | |
1953 | if (!QUERY_FLAG (tmp, FLAG_CURSED) && !QUERY_FLAG (tmp, FLAG_DAMNED)) |
1887 | if (!tmp->flag [FLAG_CURSED] && !tmp->flag [FLAG_DAMNED]) |
1954 | { |
1888 | { |
1955 | if (got_one) |
1889 | if (got_one) |
1956 | { |
1890 | { |
1957 | op->update_stats (); |
1891 | op->update_stats (); |
1958 | op->statusmsg ("The Gods smile upon you and remake you " |
1892 | op->statusmsg ("The Gods smile upon you and remake you " |
… | |
… | |
1983 | * there is no limit to the number of spells that potions can be cast, |
1917 | * there is no limit to the number of spells that potions can be cast, |
1984 | * but direction is problematic to try and imbue fireball potions for example. |
1918 | * but direction is problematic to try and imbue fireball potions for example. |
1985 | */ |
1919 | */ |
1986 | if (tmp->inv) |
1920 | if (tmp->inv) |
1987 | { |
1921 | { |
1988 | if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED)) |
1922 | if (tmp->flag [FLAG_CURSED] || tmp->flag [FLAG_DAMNED]) |
1989 | { |
1923 | { |
1990 | op->failmsg ("Yech! Your lungs are on fire!"); |
1924 | op->failmsg ("Yech! Your lungs are on fire!"); |
1991 | create_exploding_ball_at (op, op->level); |
1925 | create_exploding_ball_at (op, op->level); |
1992 | } |
1926 | } |
1993 | else |
1927 | else |
1994 | cast_spell (op, tmp, op->facing, tmp->inv, NULL); |
1928 | cast_spell (op, tmp, op->facing, tmp->inv, NULL); |
1995 | |
1929 | |
1996 | tmp->decrease (); |
1930 | tmp->decrease (); |
1997 | |
1931 | |
1998 | /* if youre dead, no point in doing this... */ |
1932 | /* if youre dead, no point in doing this... */ |
1999 | if (!QUERY_FLAG (op, FLAG_REMOVED)) |
1933 | if (!op->flag [FLAG_REMOVED]) |
2000 | op->update_stats (); |
1934 | op->update_stats (); |
2001 | |
1935 | |
2002 | return 1; |
1936 | return 1; |
2003 | } |
1937 | } |
2004 | |
1938 | |
… | |
… | |
2007 | for (i = 0; i < NROFATTACKS; i++) |
1941 | for (i = 0; i < NROFATTACKS; i++) |
2008 | { |
1942 | { |
2009 | if (tmp->resist[i]) |
1943 | if (tmp->resist[i]) |
2010 | { |
1944 | { |
2011 | if (!force) |
1945 | if (!force) |
2012 | force = get_archetype (FORCE_NAME); |
1946 | force = archetype::get (FORCE_NAME); |
2013 | |
1947 | |
2014 | memcpy (force->resist, tmp->resist, sizeof (tmp->resist)); |
1948 | memcpy (force->resist, tmp->resist, sizeof (tmp->resist)); |
2015 | force->type = POTION_EFFECT; |
1949 | force->type = POTION_EFFECT; |
2016 | break; /* Only need to find one protection since we copy entire batch */ |
1950 | break; /* Only need to find one protection since we copy entire batch */ |
2017 | } |
1951 | } |
… | |
… | |
2019 | |
1953 | |
2020 | /* This is a protection potion */ |
1954 | /* This is a protection potion */ |
2021 | if (force) |
1955 | if (force) |
2022 | { |
1956 | { |
2023 | /* cursed items last longer */ |
1957 | /* cursed items last longer */ |
2024 | if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED)) |
1958 | if (tmp->flag [FLAG_CURSED] || tmp->flag [FLAG_DAMNED]) |
2025 | { |
1959 | { |
2026 | force->stats.food *= 10; |
1960 | force->stats.food *= 10; |
2027 | for (i = 0; i < NROFATTACKS; i++) |
1961 | for (i = 0; i < NROFATTACKS; i++) |
2028 | if (force->resist[i] > 0) |
1962 | if (force->resist[i] > 0) |
2029 | force->resist[i] = -force->resist[i]; /* prot => vuln */ |
1963 | force->resist[i] = -force->resist[i]; /* prot => vuln */ |
2030 | } |
1964 | } |
2031 | |
1965 | |
2032 | force->speed_left = -1; |
1966 | force->speed_left = -1; |
2033 | force = insert_ob_in_ob (force, op); |
1967 | force = insert_ob_in_ob (force, op); |
2034 | CLEAR_FLAG (tmp, FLAG_APPLIED); |
1968 | tmp->clr_flag (FLAG_APPLIED); |
2035 | SET_FLAG (force, FLAG_APPLIED); |
1969 | force->set_flag (FLAG_APPLIED); |
2036 | change_abil (op, force); |
1970 | change_abil (op, force); |
2037 | tmp->decrease (); |
1971 | tmp->decrease (); |
2038 | return 1; |
1972 | return 1; |
2039 | } |
1973 | } |
2040 | |
1974 | |
2041 | /* Only thing left are the stat potions */ |
1975 | /* Only thing left are the stat potions */ |
2042 | if (op->type == PLAYER) |
1976 | if (op->type == PLAYER) |
2043 | { /* only for players */ |
1977 | { /* only for players */ |
2044 | if ((QUERY_FLAG (tmp, FLAG_CURSED) |
1978 | if ((tmp->flag [FLAG_CURSED] |
2045 | || QUERY_FLAG (tmp, FLAG_DAMNED)) |
1979 | || tmp->flag [FLAG_DAMNED]) |
2046 | && tmp->value != 0) |
1980 | && tmp->value != 0) |
2047 | CLEAR_FLAG (tmp, FLAG_APPLIED); |
1981 | tmp->clr_flag (FLAG_APPLIED); |
2048 | else |
1982 | else |
2049 | SET_FLAG (tmp, FLAG_APPLIED); |
1983 | tmp->set_flag (FLAG_APPLIED); |
2050 | |
1984 | |
2051 | if (!change_abil (op, tmp)) |
1985 | if (!change_abil (op, tmp)) |
2052 | op->statusmsg ("Nothing happened."); |
1986 | op->statusmsg ("Nothing happened."); |
2053 | } |
1987 | } |
2054 | |
1988 | |
2055 | /* CLEAR_FLAG is so that if the character has other potions |
1989 | /* CLEAR_FLAG is so that if the character has other potions |
2056 | * that were grouped with the one consumed, his |
1990 | * that were grouped with the one consumed, his |
2057 | * stat will not be raised by them. fix_player just clears |
1991 | * stat will not be raised by them. fix_player just clears |
2058 | * up all the stats. |
1992 | * up all the stats. |
2059 | */ |
1993 | */ |
2060 | CLEAR_FLAG (tmp, FLAG_APPLIED); |
1994 | tmp->clr_flag (FLAG_APPLIED); |
2061 | op->update_stats (); |
1995 | op->update_stats (); |
2062 | tmp->decrease (); |
1996 | tmp->decrease (); |
2063 | return 1; |
1997 | return 1; |
2064 | } |
1998 | } |
2065 | |
1999 | |
… | |
… | |
2075 | void |
2009 | void |
2076 | move_apply (object *trap, object *victim, object *originator) |
2010 | move_apply (object *trap, object *victim, object *originator) |
2077 | { |
2011 | { |
2078 | static int recursion_depth = 0; |
2012 | static int recursion_depth = 0; |
2079 | |
2013 | |
|
|
2014 | trap = trap->head_ (); |
|
|
2015 | |
2080 | /* Only exits affect DMs. */ |
2016 | /* Only exits affect DMs. */ |
2081 | if (QUERY_FLAG (victim, FLAG_WIZPASS) && trap->type != EXIT && trap->type != SIGN) |
2017 | if (victim->flag [FLAG_WIZPASS] && trap->type != EXIT && trap->type != SIGN) |
2082 | return; |
2018 | return; |
2083 | |
2019 | |
2084 | /* move_apply() is the most likely candidate for causing unwanted and |
2020 | /* move_apply() is the most likely candidate for causing unwanted and |
2085 | * possibly unlimited recursion. |
2021 | * possibly unlimited recursion. |
2086 | */ |
2022 | */ |
|
|
2023 | |
2087 | /* The following was changed because it was causing perfectly correct |
2024 | /* The following was changed because it was causing perfectly correct |
2088 | * maps to fail. 1) it's not an error to recurse: |
2025 | * maps to fail. 1) it's not an error to recurse: |
2089 | * rune detonates, summoning monster. monster lands on nearby rune. |
2026 | * rune detonates, summoning monster. monster lands on nearby rune. |
2090 | * nearby rune detonates. This sort of recursion is expected and |
2027 | * nearby rune detonates. This sort of recursion is expected and |
2091 | * proper. This code was causing needless crashes. |
2028 | * proper. This code was causing needless crashes. |
… | |
… | |
2096 | "[trap arch %s, name %s; victim arch %s, name %s]\n", &trap->arch->archname, &trap->name, &victim->arch->archname, &victim->name); |
2033 | "[trap arch %s, name %s; victim arch %s, name %s]\n", &trap->arch->archname, &trap->name, &victim->arch->archname, &victim->name); |
2097 | return; |
2034 | return; |
2098 | } |
2035 | } |
2099 | |
2036 | |
2100 | recursion_depth++; |
2037 | recursion_depth++; |
2101 | if (trap->head) |
|
|
2102 | trap = trap->head; |
|
|
2103 | |
2038 | |
2104 | if (!INVOKE_OBJECT (MOVE_TRIGGER, trap, ARG_OBJECT (victim), ARG_OBJECT (originator))) |
2039 | if (!INVOKE_OBJECT (MOVE_TRIGGER, trap, ARG_OBJECT (victim), ARG_OBJECT (originator))) |
2105 | switch (trap->type) |
2040 | switch (trap->type) |
2106 | { |
2041 | { |
2107 | case PLAYERMOVER: |
2042 | case PLAYERMOVER: |
… | |
… | |
2117 | |
2052 | |
2118 | /* Just put in some sanity check. I think there is a bug in the |
2053 | /* Just put in some sanity check. I think there is a bug in the |
2119 | * above with some objects have zero speed, and thus the player |
2054 | * above with some objects have zero speed, and thus the player |
2120 | * getting permanently paralyzed. |
2055 | * getting permanently paralyzed. |
2121 | */ |
2056 | */ |
2122 | if (victim->speed_left < -50.f) |
2057 | victim->speed_left = max (-50.f, victim->speed_left); |
2123 | victim->speed_left = -50.f; |
|
|
2124 | /* LOG(llevDebug, "apply, playermove, player speed_left=%f\n", victim->speed_left); */ |
2058 | /* LOG(llevDebug, "apply, playermove, player speed_left=%f\n", victim->speed_left); */ |
2125 | } |
2059 | } |
2126 | break; |
2060 | break; |
2127 | |
2061 | |
2128 | case SPINNER: |
2062 | case SPINNER: |
… | |
… | |
2160 | case ARROW: |
2094 | case ARROW: |
2161 | /* bad bug: monster throw a object, make a step forwards, step on object , |
2095 | /* bad bug: monster throw a object, make a step forwards, step on object , |
2162 | * trigger this here and get hit by own missile - and will be own enemy. |
2096 | * trigger this here and get hit by own missile - and will be own enemy. |
2163 | * Victim then is his own enemy and will start to kill herself (this is |
2097 | * Victim then is his own enemy and will start to kill herself (this is |
2164 | * removed) but we have not synced victim and his missile. To avoid senseless |
2098 | * removed) but we have not synced victim and his missile. To avoid senseless |
2165 | * action, we avoid hits here |
2099 | * action, we avoid hits here |
2166 | */ |
2100 | */ |
2167 | if ((QUERY_FLAG (victim, FLAG_ALIVE) && trap->has_active_speed ()) |
2101 | if ((victim->flag [FLAG_ALIVE] && trap->has_active_speed ()) |
2168 | && trap->owner != victim) |
2102 | && trap->owner != victim) |
2169 | hit_with_arrow (trap, victim); |
2103 | hit_with_arrow (trap, victim); |
2170 | break; |
2104 | break; |
2171 | |
2105 | |
2172 | case SPELL_EFFECT: |
2106 | case SPELL_EFFECT: |
… | |
… | |
2216 | } |
2150 | } |
2217 | |
2151 | |
2218 | case CONVERTER: |
2152 | case CONVERTER: |
2219 | if (convert_item (victim, trap) < 0) |
2153 | if (convert_item (victim, trap) < 0) |
2220 | { |
2154 | { |
2221 | originator->failmsg (format ("The %s seems to be broken!", query_name (trap))); |
2155 | originator->failmsgf ("The %s seems to be broken!", query_name (trap)); |
2222 | archetype::get (shstr_burnout)->insert_at (trap, trap); |
2156 | archetype::get (shstr_burnout)->insert_at (trap, trap); |
2223 | } |
2157 | } |
2224 | |
2158 | |
2225 | break; |
2159 | break; |
2226 | |
2160 | |
… | |
… | |
2280 | apply_container (victim, trap); |
2214 | apply_container (victim, trap); |
2281 | break; |
2215 | break; |
2282 | |
2216 | |
2283 | case RUNE: |
2217 | case RUNE: |
2284 | case TRAP: |
2218 | case TRAP: |
2285 | if (trap->level && QUERY_FLAG (victim, FLAG_ALIVE)) |
2219 | if (trap->level && victim->flag [FLAG_ALIVE]) |
2286 | spring_trap (trap, victim); |
2220 | spring_trap (trap, victim); |
2287 | break; |
2221 | break; |
2288 | |
2222 | |
2289 | default: |
2223 | default: |
2290 | LOG (llevDebug, "name %s, arch %s, type %d with fly/walk on/off not " |
2224 | LOG (llevDebug, "name %s, arch %s, type %d with fly/walk on/off not " |
… | |
… | |
2302 | apply_book (object *op, object *tmp) |
2236 | apply_book (object *op, object *tmp) |
2303 | { |
2237 | { |
2304 | int lev_diff; |
2238 | int lev_diff; |
2305 | object *skill_ob; |
2239 | object *skill_ob; |
2306 | |
2240 | |
2307 | if (QUERY_FLAG (op, FLAG_BLIND) && !QUERY_FLAG (op, FLAG_WIZ)) |
2241 | if (op->flag [FLAG_BLIND] && !op->flag [FLAG_WIZ]) |
2308 | { |
2242 | { |
2309 | op->failmsg ("You are unable to read while blind!"); |
2243 | op->failmsg ("You are unable to read while blind!"); |
2310 | return; |
2244 | return; |
2311 | } |
2245 | } |
2312 | |
2246 | |
2313 | if (!tmp->msg) |
2247 | if (!tmp->msg) |
2314 | { |
2248 | { |
2315 | op->failmsg (format ("The %s contains nothing but meaningless gibberish. H<There is nothing interesting to read here.>", &tmp->name)); |
2249 | op->failmsgf ("The %s contains nothing but meaningless gibberish. H<There is nothing interesting to read here.>", &tmp->name); |
2316 | return; |
2250 | return; |
2317 | } |
2251 | } |
2318 | |
2252 | |
2319 | /* need a literacy skill to read stuff! */ |
2253 | /* need a literacy skill to read stuff! */ |
2320 | skill_ob = find_skill_by_name (op, tmp->skill); |
2254 | skill_ob = find_skill_by_name (op, tmp->skill); |
2321 | if (!skill_ob) |
2255 | if (!skill_ob) |
2322 | { |
2256 | { |
2323 | op->failmsg (format ("You are unable to decipher the strange symbols. H<You lack the %s skill to read this.>", &tmp->skill)); |
2257 | op->failmsgf ("You are unable to decipher the strange symbols. H<You lack the %s skill to read this.>", &tmp->skill); |
2324 | return; |
2258 | return; |
2325 | } |
2259 | } |
2326 | |
2260 | |
2327 | lev_diff = tmp->level - (skill_ob->level + 5); |
2261 | lev_diff = tmp->level - (skill_ob->level + 5); |
2328 | if (!QUERY_FLAG (op, FLAG_WIZ) && lev_diff > 0) |
2262 | if (!op->flag [FLAG_WIZ] && lev_diff > 0) |
2329 | { |
2263 | { |
2330 | op->failmsg (lev_diff < 2 ? "This book is just barely beyond your comprehension." |
2264 | op->failmsg (lev_diff < 2 ? "This book is just barely beyond your comprehension." |
2331 | : lev_diff < 3 ? "This book is slightly beyond your comprehension." |
2265 | : lev_diff < 3 ? "This book is slightly beyond your comprehension." |
2332 | : lev_diff < 5 ? "This book is beyond your comprehension." |
2266 | : lev_diff < 5 ? "This book is beyond your comprehension." |
2333 | : lev_diff < 8 ? "This book is quite a bit beyond your comprehension." |
2267 | : lev_diff < 8 ? "This book is quite a bit beyond your comprehension." |
… | |
… | |
2344 | if (player *pl = op->contr) |
2278 | if (player *pl = op->contr) |
2345 | if (client *ns = pl->ns) |
2279 | if (client *ns = pl->ns) |
2346 | pl->infobox (MSG_CHANNEL ("book"), format ("T<%s>\n\n%s", (char *)long_desc (tmp, op), &tmp->msg)); |
2280 | pl->infobox (MSG_CHANNEL ("book"), format ("T<%s>\n\n%s", (char *)long_desc (tmp, op), &tmp->msg)); |
2347 | |
2281 | |
2348 | /* gain xp from reading */ |
2282 | /* gain xp from reading */ |
2349 | if (!QUERY_FLAG (tmp, FLAG_NO_SKILL_IDENT)) |
2283 | if (!tmp->flag [FLAG_NO_SKILL_IDENT]) |
2350 | { /* only if not read before */ |
2284 | { /* only if not read before */ |
2351 | int exp_gain = calc_skill_exp (op, tmp, skill_ob); |
2285 | int exp_gain = calc_skill_exp (op, tmp, skill_ob); |
2352 | |
2286 | |
2353 | if (!QUERY_FLAG (tmp, FLAG_IDENTIFIED)) |
2287 | if (!tmp->flag [FLAG_IDENTIFIED]) |
2354 | { |
2288 | { |
2355 | /*exp_gain *= 2; because they just identified it too */ |
2289 | /*exp_gain *= 2; because they just identified it too */ |
2356 | SET_FLAG (tmp, FLAG_IDENTIFIED); |
2290 | tmp->set_flag (FLAG_IDENTIFIED); |
2357 | |
2291 | |
2358 | if (object *pl = tmp->visible_to ()) |
2292 | if (object *pl = tmp->visible_to ()) |
2359 | esrv_update_item (UPD_FLAGS | UPD_NAME, pl, tmp); |
2293 | esrv_update_item (UPD_FLAGS | UPD_NAME, pl, tmp); |
2360 | } |
2294 | } |
2361 | |
2295 | |
2362 | change_exp (op, exp_gain, skill_ob->skill, 0); |
2296 | change_exp (op, exp_gain, skill_ob->skill, 0); |
2363 | SET_FLAG (tmp, FLAG_NO_SKILL_IDENT); /* so no more xp gained from this book */ |
2297 | tmp->set_flag (FLAG_NO_SKILL_IDENT); /* so no more xp gained from this book */ |
2364 | } |
2298 | } |
2365 | } |
2299 | } |
2366 | |
2300 | |
2367 | /** |
2301 | /** |
2368 | * op made some mistake with a scroll, this takes care of punishment. |
2302 | * op made some mistake with a scroll, this takes care of punishment. |
… | |
… | |
2377 | if (failure <= -1 && failure > -15) |
2311 | if (failure <= -1 && failure > -15) |
2378 | { /* wonder */ |
2312 | { /* wonder */ |
2379 | object *tmp; |
2313 | object *tmp; |
2380 | |
2314 | |
2381 | op->failmsg ("Your spell warps!"); |
2315 | op->failmsg ("Your spell warps!"); |
2382 | tmp = get_archetype (SPELL_WONDER); |
2316 | tmp = archetype::get (SPELL_WONDER); |
2383 | cast_wonder (op, op, 0, tmp); |
2317 | cast_wonder (op, op, 0, tmp); |
2384 | tmp->destroy (); |
2318 | tmp->destroy (); |
2385 | } |
2319 | } |
2386 | else if (failure <= -15 && failure > -35) |
2320 | else if (failure <= -15 && failure > -35) |
2387 | { /* drain mana */ |
2321 | { /* drain mana */ |
… | |
… | |
2407 | op->failmsg ("The magic recoils on you!"); |
2341 | op->failmsg ("The magic recoils on you!"); |
2408 | blind_player (op, op, power); |
2342 | blind_player (op, op, power); |
2409 | } |
2343 | } |
2410 | else if (failure <= -80) |
2344 | else if (failure <= -80) |
2411 | { /* blast the immediate area */ |
2345 | { /* blast the immediate area */ |
2412 | object *tmp = get_archetype (LOOSE_MANA); |
2346 | object *tmp = archetype::get (LOOSE_MANA); |
2413 | cast_magic_storm (op, tmp, power); |
2347 | cast_magic_storm (op, tmp, power); |
2414 | op->failmsg ("You unleash uncontrolled mana!"); |
2348 | op->failmsg ("You unleash uncontrolled mana!"); |
2415 | tmp->destroy (); |
2349 | tmp->destroy (); |
2416 | } |
2350 | } |
2417 | } |
2351 | } |
… | |
… | |
2426 | { |
2360 | { |
2427 | switch (learn_skill (op, tmp)) |
2361 | switch (learn_skill (op, tmp)) |
2428 | { |
2362 | { |
2429 | case 0: |
2363 | case 0: |
2430 | op->play_sound (sound_find ("generic_fail")); |
2364 | op->play_sound (sound_find ("generic_fail")); |
2431 | op->failmsg (format ("You already possess the knowledge held within the %s.", query_name (tmp))); |
2365 | op->failmsgf ("You already possess the knowledge held within the %s.", query_name (tmp)); |
2432 | break; |
2366 | break; |
2433 | |
2367 | |
2434 | case 1: |
2368 | case 1: |
2435 | tmp->decrease (); |
2369 | tmp->decrease (); |
2436 | op->play_sound (sound_find ("skill_learn")); |
2370 | op->play_sound (sound_find ("skill_learn")); |
… | |
… | |
2438 | break; |
2372 | break; |
2439 | |
2373 | |
2440 | default: |
2374 | default: |
2441 | tmp->decrease (); |
2375 | tmp->decrease (); |
2442 | op->play_sound (sound_find ("generic_fail")); |
2376 | op->play_sound (sound_find ("generic_fail")); |
2443 | op->failmsg (format ("You fail to learn the knowledge of the %s.\n", query_name (tmp))); |
2377 | op->failmsgf ("You fail to learn the knowledge of the %s.\n", query_name (tmp)); |
2444 | break; |
2378 | break; |
2445 | } |
2379 | } |
2446 | } |
2380 | } |
2447 | |
2381 | |
2448 | /** |
2382 | /** |
… | |
… | |
2461 | } |
2395 | } |
2462 | |
2396 | |
2463 | /* Upgrade special prayers to normal prayers */ |
2397 | /* Upgrade special prayers to normal prayers */ |
2464 | if ((tmp = check_spell_known (op, spell->name)) != NULL) |
2398 | if ((tmp = check_spell_known (op, spell->name)) != NULL) |
2465 | { |
2399 | { |
2466 | if (special_prayer && !QUERY_FLAG (tmp, FLAG_STARTEQUIP)) |
2400 | if (special_prayer && !tmp->flag [FLAG_STARTEQUIP]) |
2467 | { |
2401 | { |
2468 | LOG (llevError, "BUG: do_learn_spell(): spell already known, but not marked as startequip\n"); |
2402 | LOG (llevError, "BUG: do_learn_spell(): spell already known, but not marked as startequip\n"); |
2469 | return; |
2403 | return; |
2470 | } |
2404 | } |
2471 | return; |
2405 | return; |
… | |
… | |
2475 | |
2409 | |
2476 | tmp = spell->clone (); |
2410 | tmp = spell->clone (); |
2477 | insert_ob_in_ob (tmp, op); |
2411 | insert_ob_in_ob (tmp, op); |
2478 | |
2412 | |
2479 | if (special_prayer) |
2413 | if (special_prayer) |
2480 | SET_FLAG (tmp, FLAG_STARTEQUIP); |
2414 | tmp->set_flag (FLAG_STARTEQUIP); |
2481 | |
2415 | |
2482 | esrv_add_spells (op->contr, tmp); |
2416 | esrv_add_spells (op->contr, tmp); |
2483 | } |
2417 | } |
2484 | |
2418 | |
2485 | /** |
2419 | /** |
… | |
… | |
2499 | { |
2433 | { |
2500 | LOG (llevError, "BUG: do_forget_spell(): spell not known\n"); |
2434 | LOG (llevError, "BUG: do_forget_spell(): spell not known\n"); |
2501 | return; |
2435 | return; |
2502 | } |
2436 | } |
2503 | |
2437 | |
2504 | op->failmsg (format ("You lose knowledge of %s.", spell)); |
2438 | op->failmsgf ("You lose knowledge of %s.", spell); |
2505 | esrv_remove_spell (op->contr, spob); |
2439 | esrv_remove_spell (op->contr, spob); |
2506 | spob->destroy (); |
2440 | spob->destroy (); |
2507 | } |
2441 | } |
2508 | |
2442 | |
2509 | /** |
2443 | /** |
… | |
… | |
2514 | static void |
2448 | static void |
2515 | apply_spellbook (object *op, object *tmp) |
2449 | apply_spellbook (object *op, object *tmp) |
2516 | { |
2450 | { |
2517 | object *skop, *spell, *spell_skill; |
2451 | object *skop, *spell, *spell_skill; |
2518 | |
2452 | |
2519 | if (QUERY_FLAG (op, FLAG_BLIND) && !QUERY_FLAG (op, FLAG_WIZ)) |
2453 | if (op->flag [FLAG_BLIND] && !op->flag [FLAG_WIZ]) |
2520 | { |
2454 | { |
2521 | op->failmsg ("You are unable to read while blind."); |
2455 | op->failmsg ("You are unable to read while blind."); |
2522 | return; |
2456 | return; |
2523 | } |
2457 | } |
2524 | |
2458 | |
… | |
… | |
2530 | { |
2464 | { |
2531 | spell = find_archetype_by_object_name (tmp->slaying)->instance (); |
2465 | spell = find_archetype_by_object_name (tmp->slaying)->instance (); |
2532 | |
2466 | |
2533 | if (!spell) |
2467 | if (!spell) |
2534 | { |
2468 | { |
2535 | op->failmsg (format ("The book's formula for %s is incomplete.", &tmp->slaying)); |
2469 | op->failmsgf ("The book's formula for %s is incomplete.", &tmp->slaying); |
2536 | return; |
2470 | return; |
2537 | } |
2471 | } |
2538 | else |
2472 | else |
2539 | insert_ob_in_ob (spell, tmp); |
2473 | insert_ob_in_ob (spell, tmp); |
2540 | |
2474 | |
… | |
… | |
2545 | |
2479 | |
2546 | /* need a literacy skill to learn spells. Also, having a literacy level |
2480 | /* need a literacy skill to learn spells. Also, having a literacy level |
2547 | * lower than the spell will make learning the spell more difficult */ |
2481 | * lower than the spell will make learning the spell more difficult */ |
2548 | if (!skop) |
2482 | if (!skop) |
2549 | { |
2483 | { |
2550 | op->failmsg (format ("You can't read! Your attempt fails. H<You lack the %s skill.>", &tmp->skill)); |
2484 | op->failmsgf ("You can't read! Your attempt fails. H<You lack the %s skill.>", &tmp->skill); |
2551 | return; |
2485 | return; |
2552 | } |
2486 | } |
2553 | |
2487 | |
2554 | spell = tmp->inv; |
2488 | spell = tmp->inv; |
2555 | |
2489 | |
… | |
… | |
2561 | } |
2495 | } |
2562 | |
2496 | |
2563 | int learn_level = sqrtf (spell->level) * 1.5f; |
2497 | int learn_level = sqrtf (spell->level) * 1.5f; |
2564 | if (skop->level < learn_level) |
2498 | if (skop->level < learn_level) |
2565 | { |
2499 | { |
2566 | op->failmsg (format ("You are unable to decipher the strange symbols. H<Your %s level is too low, it must be at least %d.>", |
2500 | op->failmsgf ("You are unable to decipher the strange symbols. H<Your %s level is too low, it must be at least %d.>", |
2567 | &tmp->skill, learn_level)); |
2501 | &tmp->skill, learn_level); |
2568 | return; |
2502 | return; |
2569 | } |
2503 | } |
2570 | |
2504 | |
2571 | op->statusmsg (format ("The spellbook contains the %s level spell %s.", ordinal (spell->level), &spell->name)); |
2505 | op->statusmsg (format ("The spellbook contains the %s level spell %s.", ordinal (spell->level), &spell->name)); |
2572 | |
2506 | |
2573 | if (!QUERY_FLAG (tmp, FLAG_IDENTIFIED)) |
2507 | if (!tmp->flag [FLAG_IDENTIFIED]) |
2574 | identify (tmp); |
2508 | identify (tmp); |
2575 | |
2509 | |
2576 | /* I removed the check for special_prayer_mark here - it didn't make |
2510 | /* I removed the check for special_prayer_mark here - it didn't make |
2577 | * a lot of sense - special prayers are not found in spellbooks, and |
2511 | * a lot of sense - special prayers are not found in spellbooks, and |
2578 | * if the player doesn't know the spell, doesn't make a lot of sense that |
2512 | * if the player doesn't know the spell, doesn't make a lot of sense that |
… | |
… | |
2588 | { |
2522 | { |
2589 | spell_skill = find_skill_by_name (op, spell->skill); |
2523 | spell_skill = find_skill_by_name (op, spell->skill); |
2590 | |
2524 | |
2591 | if (!spell_skill) |
2525 | if (!spell_skill) |
2592 | { |
2526 | { |
2593 | op->failmsg (format ("You lack the %s skill to use this spell.", &spell->skill)); |
2527 | op->failmsgf ("You lack the %s skill to use this spell.", &spell->skill); |
2594 | return; |
2528 | return; |
2595 | } |
2529 | } |
2596 | |
2530 | |
2597 | if (spell_skill->level < spell->level) |
2531 | if (spell_skill->level < spell->level) |
2598 | { |
2532 | { |
2599 | op->failmsg (format ("You need to be level %d in %s to learn this spell.", spell->level, &spell->skill)); |
2533 | op->failmsgf ("You need to be level %d in %s to learn this spell.", spell->level, &spell->skill); |
2600 | return; |
2534 | return; |
2601 | } |
2535 | } |
2602 | } |
2536 | } |
2603 | |
2537 | |
2604 | /* Logic as follows |
2538 | /* Logic as follows |
… | |
… | |
2611 | * 3 -Automatically fail to learn if you read while confused |
2545 | * 3 -Automatically fail to learn if you read while confused |
2612 | * |
2546 | * |
2613 | * Overall, chances are the same but a player will find having a high |
2547 | * Overall, chances are the same but a player will find having a high |
2614 | * literacy rate very useful! -b.t. |
2548 | * literacy rate very useful! -b.t. |
2615 | */ |
2549 | */ |
2616 | if (QUERY_FLAG (op, FLAG_CONFUSED)) |
2550 | if (op->flag [FLAG_CONFUSED]) |
2617 | { |
2551 | { |
2618 | op->failmsg ("In your confused state you flub the wording of the text!"); |
2552 | op->failmsg ("In your confused state you flub the wording of the text!"); |
2619 | scroll_failure (op, 0 - random_roll (0, spell->level, op, PREFER_LOW), max (spell->stats.sp, spell->stats.grace)); |
2553 | scroll_failure (op, 0 - random_roll (0, spell->level, op, PREFER_LOW), max (spell->stats.sp, spell->stats.grace)); |
2620 | } |
2554 | } |
2621 | else if (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || |
2555 | else if (tmp->flag [FLAG_STARTEQUIP] || |
2622 | (random_roll (0, 100, op, PREFER_LOW) - (5 * skop->level)) < learn_spell[spell->stats.grace ? op->stats.Wis : op->stats.Int]) |
2556 | (random_roll (0, 100, op, PREFER_LOW) - (5 * skop->level)) < learn_spell[spell->stats.grace ? op->stats.Wis : op->stats.Int]) |
2623 | { |
2557 | { |
2624 | op->statusmsg ("You succeed in learning the spell!", NDI_GREEN); |
2558 | op->statusmsg ("You succeed in learning the spell!", NDI_GREEN); |
2625 | do_learn_spell (op, spell, 0); |
2559 | do_learn_spell (op, spell, 0); |
2626 | |
2560 | |
2627 | /* xp gain to literacy for spell learning */ |
2561 | /* xp gain to literacy for spell learning */ |
2628 | if (!QUERY_FLAG (tmp, FLAG_STARTEQUIP)) |
2562 | if (!tmp->flag [FLAG_STARTEQUIP]) |
2629 | change_exp (op, calc_skill_exp (op, tmp, skop), skop->skill, 0); |
2563 | change_exp (op, calc_skill_exp (op, tmp, skop), skop->skill, 0); |
2630 | } |
2564 | } |
2631 | else |
2565 | else |
2632 | { |
2566 | { |
2633 | op->contr->play_sound (sound_find ("fumble_spell")); |
2567 | op->contr->play_sound (sound_find ("fumble_spell")); |
… | |
… | |
2643 | void |
2577 | void |
2644 | apply_scroll (object *op, object *tmp, int dir) |
2578 | apply_scroll (object *op, object *tmp, int dir) |
2645 | { |
2579 | { |
2646 | object *skop; |
2580 | object *skop; |
2647 | |
2581 | |
2648 | if (QUERY_FLAG (op, FLAG_BLIND) && !QUERY_FLAG (op, FLAG_WIZ)) |
2582 | if (op->flag [FLAG_BLIND] && !op->flag [FLAG_WIZ]) |
2649 | { |
2583 | { |
2650 | op->failmsg ("You are unable to read while blind."); |
2584 | op->failmsg ("You are unable to read while blind."); |
2651 | return; |
2585 | return; |
2652 | } |
2586 | } |
2653 | |
2587 | |
… | |
… | |
2663 | int exp_gain = 0; |
2597 | int exp_gain = 0; |
2664 | |
2598 | |
2665 | /* hard code literacy - tmp->skill points to where the exp |
2599 | /* hard code literacy - tmp->skill points to where the exp |
2666 | * should go for anything killed by the spell. |
2600 | * should go for anything killed by the spell. |
2667 | */ |
2601 | */ |
2668 | skop = find_skill_by_name (op, skill_names[SK_LITERACY]); |
2602 | skop = find_skill_by_name (op, shstr_literacy); |
2669 | |
2603 | |
2670 | if (!skop) |
2604 | if (!skop) |
2671 | { |
2605 | { |
2672 | op->failmsg (format ("You are unable to decipher the strange symbols. H<You lack the %s skill.>", &skill_names[SK_LITERACY])); |
2606 | op->failmsgf ("You are unable to decipher the strange symbols. H<You lack the literacy skill.>"); |
2673 | return; |
2607 | return; |
2674 | } |
2608 | } |
2675 | |
2609 | |
2676 | if ((exp_gain = calc_skill_exp (op, tmp, skop))) |
2610 | if ((exp_gain = calc_skill_exp (op, tmp, skop))) |
2677 | change_exp (op, exp_gain, skop->skill, 0); |
2611 | change_exp (op, exp_gain, skop->skill, 0); |
2678 | } |
2612 | } |
2679 | |
2613 | |
2680 | if (!QUERY_FLAG (tmp, FLAG_IDENTIFIED)) |
2614 | if (!tmp->flag [FLAG_IDENTIFIED]) |
2681 | identify (tmp); |
2615 | identify (tmp); |
2682 | |
2616 | |
2683 | op->statusmsg (format ("The scroll of %s turns to dust.", &tmp->inv->name)); |
2617 | op->statusmsg (format ("The scroll of %s turns to dust.", &tmp->inv->name)); |
2684 | |
2618 | |
2685 | cast_spell (op, tmp, dir, tmp->inv, NULL); |
2619 | cast_spell (op, tmp, dir, tmp->inv, NULL); |
… | |
… | |
2716 | |
2650 | |
2717 | treas->x = op->x; |
2651 | treas->x = op->x; |
2718 | treas->y = op->y; |
2652 | treas->y = op->y; |
2719 | treas = insert_ob_in_map (treas, op->map, op, INS_BELOW_ORIGINATOR); |
2653 | treas = insert_ob_in_map (treas, op->map, op, INS_BELOW_ORIGINATOR); |
2720 | |
2654 | |
2721 | if (treas && (treas->type == RUNE || treas->type == TRAP) && treas->level && QUERY_FLAG (op, FLAG_ALIVE)) |
2655 | if (treas && (treas->type == RUNE || treas->type == TRAP) && treas->level && op->flag [FLAG_ALIVE]) |
2722 | spring_trap (treas, op); |
2656 | spring_trap (treas, op); |
2723 | |
2657 | |
2724 | /* If either player or container was destroyed, no need to do |
2658 | /* If either player or container was destroyed, no need to do |
2725 | * further processing. I think this should be enclused with |
2659 | * further processing. I think this should be enclused with |
2726 | * spring trap above, as I don't think there is otherwise |
2660 | * spring trap above, as I don't think there is otherwise |
… | |
… | |
2925 | : tmp->type == DRINK |
2859 | : tmp->type == DRINK |
2926 | ? sound_find ("eat_drink") |
2860 | ? sound_find ("eat_drink") |
2927 | : sound_find ("eat_food") |
2861 | : sound_find ("eat_food") |
2928 | ); |
2862 | ); |
2929 | |
2863 | |
2930 | if (!QUERY_FLAG (tmp, FLAG_CURSED)) |
2864 | if (!tmp->flag [FLAG_CURSED]) |
2931 | { |
2865 | { |
2932 | const char *buf; |
2866 | const char *buf; |
2933 | |
2867 | |
2934 | if (!op->is_dragon ()) |
2868 | if (!op->is_dragon ()) |
2935 | { |
2869 | { |
… | |
… | |
2955 | min_it (op->stats.hp, op->stats.maxhp); |
2889 | min_it (op->stats.hp, op->stats.maxhp); |
2956 | min_it (op->stats.food, MAX_FOOD); |
2890 | min_it (op->stats.food, MAX_FOOD); |
2957 | } |
2891 | } |
2958 | |
2892 | |
2959 | /* special food hack -b.t. */ |
2893 | /* special food hack -b.t. */ |
2960 | if (tmp->title || QUERY_FLAG (tmp, FLAG_CURSED)) |
2894 | if (tmp->title || tmp->flag [FLAG_CURSED]) |
2961 | eat_special_food (op, tmp); |
2895 | eat_special_food (op, tmp); |
2962 | } |
2896 | } |
2963 | } |
2897 | } |
2964 | |
2898 | |
2965 | handle_apply_yield (tmp); |
2899 | handle_apply_yield (tmp); |
… | |
… | |
2971 | * Does some sanity checks, then calls improve_armour. |
2905 | * Does some sanity checks, then calls improve_armour. |
2972 | */ |
2906 | */ |
2973 | static void |
2907 | static void |
2974 | apply_armour_improver (object *op, object *tmp) |
2908 | apply_armour_improver (object *op, object *tmp) |
2975 | { |
2909 | { |
2976 | object *armor; |
|
|
2977 | |
|
|
2978 | if (!QUERY_FLAG (op, FLAG_WIZCAST) && (get_map_flags (op->map, 0, op->x, op->y, 0, 0) & P_NO_MAGIC)) |
2910 | if (!op->flag [FLAG_WIZCAST] && (get_map_flags (op->map, 0, op->x, op->y, 0, 0) & P_NO_MAGIC)) |
2979 | { |
2911 | { |
2980 | op->failmsg ("Something blocks the magic of the scroll. H<This area prevents magic effects.>"); |
2912 | op->failmsg ("Something blocks the magic of the scroll. H<This area prevents magic effects.>"); |
2981 | return; |
2913 | return; |
2982 | } |
2914 | } |
2983 | |
2915 | |
2984 | armor = find_marked_object (op); |
2916 | object *armor = op->mark (); |
2985 | |
2917 | |
2986 | if (!armor) |
2918 | if (!armor) |
2987 | { |
2919 | { |
2988 | op->failmsg ("You need to mark an armor object. Use the right mouse button popup or the mark command to do this."); |
2920 | op->failmsg ("You need to mark an armor object. Use the right mouse button popup or the mark command to do this."); |
2989 | return; |
2921 | return; |
… | |
… | |
2992 | if (armor->type != ARMOUR |
2924 | if (armor->type != ARMOUR |
2993 | && armor->type != CLOAK |
2925 | && armor->type != CLOAK |
2994 | && armor->type != BOOTS && armor->type != GLOVES && armor->type != BRACERS && armor->type != SHIELD && armor->type != HELMET) |
2926 | && armor->type != BOOTS && armor->type != GLOVES && armor->type != BRACERS && armor->type != SHIELD && armor->type != HELMET) |
2995 | { |
2927 | { |
2996 | op->failmsg ("Your marked item is not armour!\n"); |
2928 | op->failmsg ("Your marked item is not armour!\n"); |
|
|
2929 | return; |
|
|
2930 | } |
|
|
2931 | |
|
|
2932 | if (!op->apply (armor, AP_UNAPPLY)) |
|
|
2933 | { |
|
|
2934 | op->failmsg ("You are unable to take off your armour to improve it!"); |
2997 | return; |
2935 | return; |
2998 | } |
2936 | } |
2999 | |
2937 | |
3000 | op->statusmsg ("Applying armour enchantment."); |
2938 | op->statusmsg ("Applying armour enchantment."); |
3001 | improve_armour (op, tmp, armor); |
2939 | improve_armour (op, tmp, armor); |
… | |
… | |
3049 | } |
2987 | } |
3050 | } |
2988 | } |
3051 | |
2989 | |
3052 | if (!lighter) |
2990 | if (!lighter) |
3053 | { |
2991 | { |
3054 | who->failmsg (format ( |
2992 | who->failmsgf ( |
3055 | "You can't light up the %s with your bare hands! " |
2993 | "You can't light up the %s with your bare hands! " |
3056 | "H<You need a lighter in your inventory, for example a flint and steel.>", |
2994 | "H<You need a lighter in your inventory, for example a flint and steel.>", |
3057 | &op->name)); |
2995 | &op->name |
|
|
2996 | ); |
3058 | return 0; |
2997 | return 0; |
3059 | } |
2998 | } |
3060 | } |
2999 | } |
3061 | |
3000 | |
3062 | // last_eat == 0 means the lighter is not being used up! |
3001 | // last_eat == 0 means the lighter is not being used up! |
… | |
… | |
3068 | who->insert (lighter); |
3007 | who->insert (lighter); |
3069 | } |
3008 | } |
3070 | else if (lighter->last_eat) |
3009 | else if (lighter->last_eat) |
3071 | { |
3010 | { |
3072 | /* no charges left in lighter */ |
3011 | /* no charges left in lighter */ |
3073 | who->failmsg (format ( |
3012 | who->failmsgf ( |
3074 | "You attempt to light the %s with a used up %s.", |
3013 | "You attempt to light the %s with a used up %s.", |
3075 | &op->name, &lighter->name)); |
3014 | &op->name, &lighter->name |
|
|
3015 | ); |
3076 | return 0; |
3016 | return 0; |
3077 | } |
3017 | } |
3078 | |
3018 | |
3079 | return lighter; |
3019 | return lighter; |
3080 | } |
3020 | } |
… | |
… | |
3085 | * the selected object to "burn". -b.t. |
3025 | * the selected object to "burn". -b.t. |
3086 | */ |
3026 | */ |
3087 | static void |
3027 | static void |
3088 | apply_lighter (object *who, object *lighter) |
3028 | apply_lighter (object *who, object *lighter) |
3089 | { |
3029 | { |
3090 | object *item; |
3030 | if (object *item = who->mark ()) |
3091 | int is_player_env = 0; |
|
|
3092 | |
|
|
3093 | item = find_marked_object (who); |
|
|
3094 | if (item) |
|
|
3095 | { |
3031 | { |
3096 | if (!auto_apply_lighter (who, item, lighter)) |
3032 | if (!auto_apply_lighter (who, item, lighter)) |
3097 | return; |
3033 | return; |
3098 | |
3034 | |
3099 | /* Perhaps we should split what we are trying to light on fire? |
3035 | /* Perhaps we should split what we are trying to light on fire? |
… | |
… | |
3106 | if (item->destroyed () |
3042 | if (item->destroyed () |
3107 | || ((item->type == LAMP || item->type == TORCH) |
3043 | || ((item->type == LAMP || item->type == TORCH) |
3108 | && item->glow_radius > 0)) |
3044 | && item->glow_radius > 0)) |
3109 | who->statusmsg (format ( |
3045 | who->statusmsg (format ( |
3110 | "You light the %s with the %s.", |
3046 | "You light the %s with the %s.", |
3111 | &item->name, &lighter->name)); |
3047 | &item->name, &lighter->name |
|
|
3048 | )); |
3112 | else |
3049 | else |
3113 | who->failmsg (format ( |
3050 | who->failmsgf ( |
3114 | "You attempt to light the %s with the %s and fail.", |
3051 | "You attempt to light the %s with the %s and fail.", |
3115 | &item->name, &lighter->name)); |
3052 | &item->name, &lighter->name |
|
|
3053 | ); |
3116 | } |
3054 | } |
3117 | else |
3055 | else |
3118 | who->failmsg ("You need to mark a lightable object."); |
3056 | who->failmsg ("You need to mark a lightable object."); |
3119 | } |
3057 | } |
3120 | |
3058 | |
… | |
… | |
3124 | static void |
3062 | static void |
3125 | player_apply_lamp_cursed_effect (object *who, object *op) |
3063 | player_apply_lamp_cursed_effect (object *who, object *op) |
3126 | { |
3064 | { |
3127 | if (op->level) |
3065 | if (op->level) |
3128 | { |
3066 | { |
3129 | who->failmsg (format ( |
3067 | who->failmsgf ( |
3130 | "The %s was cursed, it explodes in a big fireball!", |
3068 | "The %s was cursed, it explodes in a big fireball!", |
3131 | &op->name)); |
3069 | &op->name |
|
|
3070 | ); |
3132 | create_exploding_ball_at (who, op->level); |
3071 | create_exploding_ball_at (who, op->level); |
3133 | } |
3072 | } |
3134 | else |
3073 | else |
3135 | { |
3074 | { |
3136 | who->failmsg (format ( |
3075 | who->failmsgf ( |
3137 | "The %s was cursed, it crumbles to dust, at least it didn't explode.!", |
3076 | "The %s was cursed, it crumbles to dust, at least it didn't explode.!", |
3138 | &op->name)); |
3077 | &op->name |
|
|
3078 | ); |
3139 | } |
3079 | } |
3140 | |
3080 | |
3141 | op->destroy (); |
3081 | op->destroy (); |
3142 | } |
3082 | } |
3143 | |
3083 | |
… | |
… | |
3161 | return; |
3101 | return; |
3162 | |
3102 | |
3163 | if (op->stats.food < 1) |
3103 | if (op->stats.food < 1) |
3164 | { |
3104 | { |
3165 | if (op->type == LAMP) |
3105 | if (op->type == LAMP) |
3166 | who->failmsg (format ( |
3106 | who->failmsgf ( |
3167 | "The %s is out of fuel! " |
3107 | "The %s is out of fuel! " |
3168 | "H<Lamps and similar items need fuel. They cannot be refilled.>", |
3108 | "H<Lamps and similar items need fuel. They cannot be refilled.>", |
3169 | &op->name)); |
3109 | &op->name |
|
|
3110 | ); |
3170 | else |
3111 | else |
3171 | who->failmsg (format ( |
3112 | who->failmsgf ( |
3172 | "The %s is burnt out! " |
3113 | "The %s is burnt out! " |
3173 | "H<Torches and similar items burn out and become worthless.>", |
3114 | "H<Torches and similar items burn out and become worthless.>", |
3174 | &op->name)); |
3115 | &op->name |
|
|
3116 | ); |
3175 | return; |
3117 | return; |
3176 | } |
3118 | } |
3177 | |
3119 | |
3178 | if (op->flag [FLAG_CURSED]) |
3120 | if (op->flag [FLAG_CURSED]) |
3179 | { |
3121 | { |
… | |
… | |
3284 | * The 'slaying' field for transformer is used as verb for the action. |
3226 | * The 'slaying' field for transformer is used as verb for the action. |
3285 | */ |
3227 | */ |
3286 | static void |
3228 | static void |
3287 | apply_item_transformer (object *pl, object *transformer) |
3229 | apply_item_transformer (object *pl, object *transformer) |
3288 | { |
3230 | { |
3289 | object *marked; |
|
|
3290 | object *new_item; |
3231 | object *new_item; |
3291 | const char *find; |
3232 | const char *find; |
3292 | char *separator; |
3233 | char *separator; |
3293 | int yield; |
3234 | int yield; |
3294 | char got[MAX_BUF]; |
3235 | char got[MAX_BUF]; |
3295 | int len; |
3236 | int len; |
3296 | |
3237 | |
3297 | if (!pl || !transformer) |
3238 | if (!pl || !transformer) |
3298 | return; |
3239 | return; |
3299 | |
3240 | |
3300 | marked = find_marked_object (pl); |
3241 | object *marked = pl->mark (); |
3301 | |
3242 | |
3302 | if (!marked) |
3243 | if (!marked) |
3303 | { |
3244 | { |
3304 | pl->failmsg (format ("Use the %s with what item?", query_name (transformer))); |
3245 | pl->failmsgf ("Use the %s with what item?", query_name (transformer)); |
3305 | return; |
3246 | return; |
3306 | } |
3247 | } |
3307 | |
3248 | |
3308 | if (!marked->slaying) |
3249 | if (!marked->slaying) |
3309 | { |
3250 | { |
3310 | pl->failmsg (format ("You can't use the %s with your %s!", query_name (transformer), query_name (marked))); |
3251 | pl->failmsgf ("You can't use the %s with your %s!", query_name (transformer), query_name (marked)); |
3311 | return; |
3252 | return; |
3312 | } |
3253 | } |
3313 | |
3254 | |
3314 | /* check whether they are compatible or not */ |
3255 | /* check whether they are compatible or not */ |
3315 | find = strstr (&marked->slaying, transformer->arch->archname); |
3256 | find = strstr (&marked->slaying, transformer->arch->archname); |
3316 | if (!find || (*(find + strlen (transformer->arch->archname)) != ':')) |
3257 | if (!find || (*(find + strlen (transformer->arch->archname)) != ':')) |
3317 | { |
3258 | { |
3318 | pl->failmsg (format ("You can't use the %s with your %s!", query_name (transformer), query_name (marked))); |
3259 | pl->failmsgf ("You can't use the %s with your %s!", query_name (transformer), query_name (marked)); |
3319 | return; |
3260 | return; |
3320 | } |
3261 | } |
3321 | |
3262 | |
3322 | find += strlen (transformer->arch->archname) + 1; |
3263 | find += strlen (transformer->arch->archname) + 1; |
3323 | /* Item can be used, now find how many and what it yields */ |
3264 | /* Item can be used, now find how many and what it yields */ |
… | |
… | |
3350 | |
3291 | |
3351 | strcpy (got, find); |
3292 | strcpy (got, find); |
3352 | got[len] = '\0'; |
3293 | got[len] = '\0'; |
3353 | |
3294 | |
3354 | /* Now create new item, remove used ones when required. */ |
3295 | /* Now create new item, remove used ones when required. */ |
3355 | new_item = get_archetype (got); |
3296 | new_item = archetype::get (got); |
3356 | if (!new_item) |
3297 | if (!new_item) |
3357 | { |
3298 | { |
3358 | pl->failmsg (format ("This %s is strange, better to not use it.", query_base_name (marked, 0))); |
3299 | pl->failmsgf ("This %s is strange, better to not use it.", query_base_name (marked, 0)); |
3359 | return; |
3300 | return; |
3360 | } |
3301 | } |
3361 | |
3302 | |
3362 | new_item->nrof = yield; |
3303 | new_item->nrof = yield; |
3363 | |
3304 | |
… | |
… | |
3387 | * them in this function - they are passed to apply_special |
3328 | * them in this function - they are passed to apply_special |
3388 | */ |
3329 | */ |
3389 | static bool |
3330 | static bool |
3390 | manual_apply (object *who, object *op, int aflag) |
3331 | manual_apply (object *who, object *op, int aflag) |
3391 | { |
3332 | { |
3392 | op = op->head_ (); |
|
|
3393 | |
|
|
3394 | if (op->flag [FLAG_UNPAID] && !op->flag [FLAG_APPLIED]) |
|
|
3395 | { |
|
|
3396 | if (who->contr) |
|
|
3397 | { |
|
|
3398 | examine (who, op); |
|
|
3399 | //who->failmsg ("You should pay for it first! H<You cannot use items marked as unpaid.>");//TODO remove |
|
|
3400 | return 1; |
|
|
3401 | } |
|
|
3402 | else |
|
|
3403 | return 0; /* monsters just skip unpaid items */ |
|
|
3404 | } |
|
|
3405 | |
|
|
3406 | if (INVOKE_OBJECT (APPLY, op, ARG_OBJECT (who))) |
3333 | if (INVOKE_OBJECT (APPLY, op, ARG_OBJECT (who))) |
3407 | return RESULT_INT (0); |
3334 | return RESULT_INT (0); |
3408 | else if (may_attempt_inv [op->type]) |
3335 | else if (apply_types_inv_only [op->type]) |
3409 | { |
3336 | { |
3410 | // special item, using slot system, needs to be in inv |
3337 | // special item, using slot system, needs to be in inv |
3411 | if (op->env == who) |
3338 | if (op->env == who) |
3412 | return apply_special (who, op, aflag); |
3339 | return apply_special (who, op, aflag); |
3413 | |
3340 | |
3414 | who->failmsg (format ("You must get it first! H<You can only apply the %s if it is in your inventory.>\n", query_name (op))); |
3341 | who->failmsgf ("You must get it first! H<You can only apply the %s if it is in your inventory.>\n", query_name (op)); |
3415 | } |
3342 | } |
3416 | else if (!who->contr && may_attempt_player [op->type]) |
3343 | else if (!who->contr && apply_types_player_only [op->type]) |
3417 | return 0; // monsters shouldn't try to apply player-only stuff |
3344 | return 0; // monsters shouldn't try to apply player-only stuff |
3418 | else if (may_attempt [op->type]) |
3345 | else if (apply_types [op->type]) |
3419 | { |
3346 | { |
3420 | // ordinary stuff, may be on the floor |
3347 | // ordinary stuff, may be on the floor |
3421 | switch (op->type) |
3348 | switch (op->type) |
3422 | { |
3349 | { |
3423 | case T_HANDLE: |
3350 | case T_HANDLE: |
… | |
… | |
3440 | |
3367 | |
3441 | break; |
3368 | break; |
3442 | |
3369 | |
3443 | case EXIT: |
3370 | case EXIT: |
3444 | if (!EXIT_PATH (op)) |
3371 | if (!EXIT_PATH (op)) |
3445 | 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))); |
3372 | who->failmsgf ("The %s is closed. H<This exit doesn't lead anywhere at the moment, and this is unlikely to change.>", query_name (op)); |
3446 | else |
3373 | else |
3447 | { |
3374 | { |
3448 | /* Don't display messages for random maps. */ |
3375 | /* Don't display messages for random maps. */ |
3449 | if (op->msg && EXIT_PATH (op) != shstr_random_map_exit) |
3376 | if (op->msg && EXIT_PATH (op) != shstr_random_map_exit) |
3450 | who->statusmsg (op->msg, NDI_NAVY); |
3377 | who->statusmsg (op->msg, NDI_NAVY); |
… | |
… | |
3523 | check_improve_weapon (who, op); |
3450 | check_improve_weapon (who, op); |
3524 | break; |
3451 | break; |
3525 | |
3452 | |
3526 | case CLOCK: |
3453 | case CLOCK: |
3527 | { |
3454 | { |
3528 | char buf[MAX_BUF]; |
|
|
3529 | timeofday_t tod; |
3455 | timeofday_t tod; |
3530 | |
3456 | |
3531 | get_tod (&tod); |
3457 | get_tod (&tod); |
3532 | who->play_sound (sound_find ("sound_clock")); |
3458 | who->play_sound (sound_find ("sound_clock")); |
3533 | who->statusmsg (format ( |
3459 | who->statusmsg (format ( |
… | |
… | |
3557 | |
3483 | |
3558 | return 1; |
3484 | return 1; |
3559 | } |
3485 | } |
3560 | else |
3486 | else |
3561 | { |
3487 | { |
3562 | who->statusmsg (format ("I don't know how to apply the %s.", query_name (op))); |
3488 | who->statusmsg (format ("I don't know how to apply the %s. H<This object cannot be applied.>", query_name (op))); |
3563 | return 0; |
3489 | return 0; |
3564 | } |
3490 | } |
3565 | } |
3491 | } |
3566 | |
3492 | |
3567 | /** |
3493 | /** |
… | |
… | |
3578 | * item in the container. Otherwise, use the map. |
3504 | * item in the container. Otherwise, use the map. |
3579 | */ |
3505 | */ |
3580 | |
3506 | |
3581 | // first try to apply "applyables" |
3507 | // first try to apply "applyables" |
3582 | for (object *tmp = top; tmp; tmp = tmp->below) |
3508 | for (object *tmp = top; tmp; tmp = tmp->below) |
3583 | if (!tmp->invisible && may_attempt [tmp->type]) |
3509 | if (!tmp->invisible && apply_types [tmp->type]) |
3584 | { |
3510 | { |
3585 | // If it is visible, player can apply it. |
3511 | // If it is visible, player can apply it. |
3586 | pl->apply (tmp); |
3512 | pl->apply (tmp); |
3587 | return; |
3513 | return; |
3588 | } |
3514 | } |
… | |
… | |
3598 | switch (top->type) |
3524 | switch (top->type) |
3599 | { |
3525 | { |
3600 | // TODO: all this should move to examine |
3526 | // TODO: all this should move to examine |
3601 | case ALTAR: |
3527 | case ALTAR: |
3602 | case IDENTIFY_ALTAR: |
3528 | case IDENTIFY_ALTAR: |
|
|
3529 | case TRIGGER_ALTAR: |
3603 | case CONVERTER: |
3530 | case CONVERTER: |
|
|
3531 | //case TRIGGER_PEDESTAL: |
3604 | pl->failmsg (format ( |
3532 | pl->failmsgf ( |
3605 | "You see no obvious mechanism on the %s." |
3533 | "You see no obvious mechanism on the %s." |
3606 | "H<You have to drop one or more specific items here.>", |
3534 | "H<You have to drop one or more specific items here.>", |
3607 | query_short_name (top) |
3535 | query_short_name (top) |
3608 | )); |
3536 | ); |
3609 | break; |
3537 | break; |
3610 | |
3538 | |
3611 | case BUTTON: |
3539 | case BUTTON: |
|
|
3540 | case TRIGGER_BUTTON: |
3612 | pl->failmsg (format ( |
3541 | pl->failmsgf ( |
3613 | "The %s looks as if you could activate it with somehting heavy. " |
3542 | "The %s looks as if you could activate it with somehting heavy. " |
3614 | "H<You must put enough items here to activate it.>", |
3543 | "H<You must put enough items here to activate it.>", |
3615 | query_short_name (top) |
3544 | query_short_name (top) |
3616 | )); |
3545 | ); |
3617 | break; |
3546 | break; |
3618 | |
3547 | |
3619 | default: |
3548 | default: |
3620 | examine (pl, top); |
3549 | examine (pl, top); |
3621 | break; |
3550 | break; |
… | |
… | |
3626 | bool |
3555 | bool |
3627 | object::apply (object *ob, int aflags) |
3556 | object::apply (object *ob, int aflags) |
3628 | { |
3557 | { |
3629 | if (!ob) // simplifies a lot of callers |
3558 | if (!ob) // simplifies a lot of callers |
3630 | return true; |
3559 | return true; |
|
|
3560 | |
|
|
3561 | ob = ob->head_ (); |
|
|
3562 | |
|
|
3563 | if (ob->flag [FLAG_UNPAID] && !ob->flag [FLAG_APPLIED]) |
|
|
3564 | { |
|
|
3565 | if (contr) |
|
|
3566 | { |
|
|
3567 | examine (this, ob); |
|
|
3568 | //who->failmsg ("You should pay for it first! H<You cannot use items marked as unpaid.>");//TODO remove |
|
|
3569 | return 1; |
|
|
3570 | } |
|
|
3571 | else |
|
|
3572 | return 0; /* monsters just skip unpaid items */ |
|
|
3573 | } |
3631 | |
3574 | |
3632 | if (contr) |
3575 | if (contr) |
3633 | { |
3576 | { |
3634 | if (!ob->env && (move_type & MOVE_FLYING)) |
3577 | if (!ob->env && (move_type & MOVE_FLYING)) |
3635 | { |
3578 | { |
… | |
… | |
3649 | bool want_apply = |
3592 | bool want_apply = |
3650 | aflags & AP_APPLY ? true |
3593 | aflags & AP_APPLY ? true |
3651 | : aflags & AP_UNAPPLY ? false |
3594 | : aflags & AP_UNAPPLY ? false |
3652 | : !ob->flag [FLAG_APPLIED]; // AP_TOGGLE |
3595 | : !ob->flag [FLAG_APPLIED]; // AP_TOGGLE |
3653 | |
3596 | |
|
|
3597 | // cannot unapply cursed items |
|
|
3598 | if (!want_apply |
|
|
3599 | && (ob->flag [FLAG_CURSED] || ob->flag [FLAG_DAMNED]) |
|
|
3600 | && ob->flag [FLAG_APPLIED] |
|
|
3601 | && !(aflags & AP_IGNORE_CURSE)) |
|
|
3602 | { |
|
|
3603 | failmsgf ("No matter how hard you try, you just can't remove %s." CANNOT_REMOVE_CURSED, ob->query_name ()); |
|
|
3604 | return 0; |
|
|
3605 | } |
|
|
3606 | |
3654 | object_ptr *slot = 0; |
3607 | object_ptr *slot = 0; |
3655 | |
3608 | |
3656 | // detect the slot, if this is a player |
3609 | // detect the slot, if this is a player |
3657 | if (contr && !(aflags & AP_NO_SLOT)) |
3610 | if (contr && !(aflags & AP_NO_SLOT)) |
3658 | { |
3611 | { |
… | |
… | |
3663 | case WEAPON: |
3616 | case WEAPON: |
3664 | slot = &contr->combat_ob; |
3617 | slot = &contr->combat_ob; |
3665 | oslot = contr->ranged_ob; |
3618 | oslot = contr->ranged_ob; |
3666 | break; |
3619 | break; |
3667 | |
3620 | |
|
|
3621 | case RANGED: |
3668 | case BOW: |
3622 | case BOW: |
3669 | case RANGED: |
|
|
3670 | case SPELL: |
3623 | case SPELL: |
3671 | case WAND: |
3624 | case WAND: |
3672 | case ROD: |
3625 | case ROD: |
3673 | case HORN: |
3626 | case HORN: |
3674 | case BUILDER: |
3627 | case BUILDER: |
… | |
… | |
3676 | oslot = contr->combat_ob; |
3629 | oslot = contr->combat_ob; |
3677 | break; |
3630 | break; |
3678 | |
3631 | |
3679 | // oh, the humanity |
3632 | // oh, the humanity |
3680 | case SKILL: |
3633 | case SKILL: |
3681 | if (aflags & AP_NO_SLOT) |
3634 | // skill is used on it's own, as opposed to being a chosen_skill |
|
|
3635 | |
|
|
3636 | if (skill_flags [ob->subtype] & (SF_NEED_ITEM | SF_MANA)) |
3682 | break; |
3637 | { |
|
|
3638 | failmsgf ( |
|
|
3639 | "You feel as if you wanted to do something funny, but you can't remember what. " |
|
|
3640 | "H<The %s skill needs something else to function, for example a tool, weapon, rod, or spell. " |
|
|
3641 | "It cannot be used on its own.>", |
|
|
3642 | &ob->skill |
|
|
3643 | ); |
|
|
3644 | return 1; |
|
|
3645 | } |
|
|
3646 | |
|
|
3647 | if (skill_flags [ob->subtype] & SF_AUTARK |
|
|
3648 | || !(skill_flags [ob->subtype] & (SF_COMBAT | SF_RANGED))) |
|
|
3649 | { |
|
|
3650 | if (skill_flags [ob->subtype] & SF_USE) |
|
|
3651 | failmsgf ( |
|
|
3652 | "You feel as if you wanted to do something funny, but you can't remember what. " |
|
|
3653 | "H<The %s skill cannot be readied, instead, try C<use_skill %s>.>", |
|
|
3654 | &ob->skill, &ob->skill |
|
|
3655 | ); |
|
|
3656 | else |
|
|
3657 | failmsgf ( |
|
|
3658 | "You feel as if you wanted to do something funny, but you can't remember what. " |
|
|
3659 | "H<The %s skill cannot be readied or used, it is always active.>", |
|
|
3660 | &ob->skill |
|
|
3661 | ); |
|
|
3662 | |
|
|
3663 | return 1; |
|
|
3664 | } |
3683 | |
3665 | |
3684 | if (skill_flags [ob->subtype] & SF_NEED_ITEM) |
3666 | if (skill_flags [ob->subtype] & SF_NEED_ITEM) |
3685 | break; |
3667 | break; |
3686 | |
3668 | |
3687 | if (skill_flags [ob->subtype] & SF_COMBAT) |
3669 | if (skill_flags [ob->subtype] & SF_COMBAT) |
… | |
… | |
3704 | // only one slot can be active |
3686 | // only one slot can be active |
3705 | if (want_apply) |
3687 | if (want_apply) |
3706 | { |
3688 | { |
3707 | // clear slot unless we are in it already |
3689 | // clear slot unless we are in it already |
3708 | if (*slot != ob) |
3690 | if (*slot != ob) |
3709 | apply (*slot, AP_UNAPPLY); |
3691 | if (!apply (*slot, AP_UNAPPLY)) |
|
|
3692 | return false; |
3710 | |
3693 | |
3711 | // unapply other slot, because we want to become active |
3694 | // unapply other slot, because we want to become active |
3712 | apply (oslot, AP_UNAPPLY); |
3695 | if (!apply (oslot, AP_UNAPPLY)) |
|
|
3696 | return false; |
3713 | } |
3697 | } |
3714 | |
3698 | |
3715 | // clear item from slot if applied |
3699 | // clear item from slot if applied |
3716 | if (!want_apply && current_weapon == ob) |
3700 | if (!want_apply && current_weapon == ob) |
3717 | current_weapon = 0; |
3701 | current_weapon = 0; |
… | |
… | |
3736 | * Generates shop floor's item, and treasures. |
3720 | * Generates shop floor's item, and treasures. |
3737 | */ |
3721 | */ |
3738 | int |
3722 | int |
3739 | auto_apply (object *op) |
3723 | auto_apply (object *op) |
3740 | { |
3724 | { |
3741 | object *tmp = NULL, *tmp2; |
3725 | object *tmp = NULL; |
3742 | int i; |
3726 | int i; |
3743 | |
3727 | |
3744 | CLEAR_FLAG (op, FLAG_AUTO_APPLY); |
3728 | op->clr_flag (FLAG_AUTO_APPLY); |
3745 | |
3729 | |
3746 | switch (op->type) |
3730 | switch (op->type) |
3747 | { |
3731 | { |
3748 | case SHOP_FLOOR: |
3732 | case SHOP_FLOOR: |
3749 | if (!op->has_random_items ()) |
3733 | if (!op->has_random_items ()) |
… | |
… | |
3759 | == NULL && --i); |
3743 | == NULL && --i); |
3760 | |
3744 | |
3761 | if (tmp == NULL) |
3745 | if (tmp == NULL) |
3762 | return 0; |
3746 | return 0; |
3763 | |
3747 | |
3764 | if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED)) |
3748 | if (tmp->flag [FLAG_CURSED] || tmp->flag [FLAG_DAMNED]) |
3765 | { |
3749 | { |
3766 | tmp->destroy (); |
3750 | tmp->destroy (); |
3767 | tmp = NULL; |
3751 | tmp = NULL; |
3768 | } |
3752 | } |
3769 | } |
3753 | } |
3770 | while (!tmp); |
3754 | while (!tmp); |
3771 | |
3755 | |
3772 | tmp->x = op->x; |
3756 | tmp->x = op->x; |
3773 | tmp->y = op->y; |
3757 | tmp->y = op->y; |
3774 | SET_FLAG (tmp, FLAG_UNPAID); |
3758 | tmp->set_flag (FLAG_UNPAID); |
3775 | insert_ob_in_map (tmp, op->map, NULL, 0); |
3759 | insert_ob_in_map (tmp, op->map, NULL, 0); |
3776 | identify (tmp); |
3760 | identify (tmp); |
3777 | break; |
3761 | break; |
3778 | |
3762 | |
3779 | case TREASURE: |
3763 | case TREASURE: |
3780 | if (QUERY_FLAG (op, FLAG_IS_A_TEMPLATE)) |
3764 | if (op->flag [FLAG_IS_A_TEMPLATE]) |
3781 | return 0; |
3765 | return 0; |
3782 | |
3766 | |
3783 | while (op->stats.hp-- > 0) |
3767 | while (op->stats.hp-- > 0) |
3784 | create_treasure (op->randomitems, op, op->map ? GT_ENVIRONMENT : 0, |
3768 | create_treasure (op->randomitems, op, op->map ? GT_ENVIRONMENT : 0, |
3785 | op->stats.exp ? (int) op->stats.exp : op->map == NULL ? 14 : op->map->difficulty, 0); |
3769 | op->stats.exp ? (int) op->stats.exp : op->map == NULL ? 14 : op->map->difficulty, 0); |
… | |
… | |
3823 | |
3807 | |
3824 | for (invtmp = tmp->inv; invtmp; invtmp = invnext) |
3808 | for (invtmp = tmp->inv; invtmp; invtmp = invnext) |
3825 | { |
3809 | { |
3826 | invnext = invtmp->below; |
3810 | invnext = invtmp->below; |
3827 | |
3811 | |
3828 | if (QUERY_FLAG (invtmp, FLAG_AUTO_APPLY)) |
3812 | if (invtmp->flag [FLAG_AUTO_APPLY]) |
3829 | auto_apply (invtmp); |
3813 | auto_apply (invtmp); |
3830 | else if (invtmp->type == TREASURE && invtmp->has_random_items ()) |
3814 | else if (invtmp->type == TREASURE && invtmp->has_random_items ()) |
3831 | { |
3815 | { |
3832 | while (invtmp->stats.hp-- > 0) |
3816 | while (invtmp->stats.hp-- > 0) |
3833 | create_treasure (invtmp->randomitems, invtmp, 0, difficulty, 0); |
3817 | create_treasure (invtmp->randomitems, invtmp, 0, difficulty, 0); |
3834 | |
3818 | |
3835 | invtmp->randomitems = NULL; |
3819 | invtmp->randomitems = NULL; |
3836 | } |
3820 | } |
3837 | else if (invtmp && invtmp->arch |
3821 | else if (invtmp->arch |
3838 | && invtmp->type != TREASURE && invtmp->type != SPELL && invtmp->type != CLASS && invtmp->has_random_items ()) |
3822 | && invtmp->type != TREASURE && invtmp->type != SPELL && invtmp->type != CLASS |
|
|
3823 | && invtmp->has_random_items ()) |
3839 | { |
3824 | { |
3840 | create_treasure (invtmp->randomitems, invtmp, 0, difficulty, 0); |
3825 | create_treasure (invtmp->randomitems, invtmp, 0, difficulty, 0); |
3841 | /* Need to clear this so that we never try to create |
3826 | /* Need to clear this so that we never try to create |
3842 | * treasure again for this object |
3827 | * treasure again for this object |
3843 | */ |
3828 | */ |
… | |
… | |
3858 | if (tmp->type == WAND || tmp->type == ROD || tmp->type == SCROLL |
3843 | if (tmp->type == WAND || tmp->type == ROD || tmp->type == SCROLL |
3859 | || tmp->type == HORN || tmp->type == FIREWALL || tmp->type == POTION || tmp->type == ALTAR || tmp->type == SPELLBOOK) |
3844 | || tmp->type == HORN || tmp->type == FIREWALL || tmp->type == POTION || tmp->type == ALTAR || tmp->type == SPELLBOOK) |
3860 | tmp->randomitems = NULL; |
3845 | tmp->randomitems = NULL; |
3861 | } |
3846 | } |
3862 | |
3847 | |
3863 | if (QUERY_FLAG (tmp, FLAG_AUTO_APPLY)) |
3848 | if (tmp->flag [FLAG_AUTO_APPLY]) |
3864 | auto_apply (tmp); |
3849 | auto_apply (tmp); |
3865 | else if ((tmp->type == TREASURE || (tmp->type == CONTAINER)) && tmp->has_random_items ()) |
3850 | else if ((tmp->type == TREASURE || (tmp->type == CONTAINER)) && tmp->has_random_items ()) |
3866 | { |
3851 | { |
3867 | while ((tmp->stats.hp--) > 0) |
3852 | while ((tmp->stats.hp--) > 0) |
3868 | create_treasure (tmp->randomitems, tmp, 0, difficulty, 0); |
3853 | create_treasure (tmp->randomitems, tmp, 0, difficulty, 0); |
… | |
… | |
3870 | } |
3855 | } |
3871 | else if (tmp->type == TIMED_GATE) |
3856 | else if (tmp->type == TIMED_GATE) |
3872 | { |
3857 | { |
3873 | object *head = tmp->head != NULL ? tmp->head : tmp; |
3858 | object *head = tmp->head != NULL ? tmp->head : tmp; |
3874 | |
3859 | |
3875 | if (QUERY_FLAG (head, FLAG_IS_LINKED)) |
3860 | if (head->flag [FLAG_IS_LINKED]) |
3876 | tmp->set_speed (0); |
3861 | tmp->set_speed (0); |
3877 | } |
3862 | } |
3878 | /* This function can be called everytime a map is loaded, even when |
3863 | /* This function can be called everytime a map is loaded, even when |
3879 | * swapping back in. As such, we don't want to create the treasure |
3864 | * swapping back in. As such, we don't want to create the treasure |
3880 | * over and ove again, so after we generate the treasure, blank out |
3865 | * over and ove again, so after we generate the treasure, blank out |
… | |
… | |
3969 | } |
3954 | } |
3970 | |
3955 | |
3971 | /* check for hp, sp change */ |
3956 | /* check for hp, sp change */ |
3972 | if (food->stats.hp != 0) |
3957 | if (food->stats.hp != 0) |
3973 | { |
3958 | { |
3974 | if (QUERY_FLAG (food, FLAG_CURSED)) |
3959 | if (food->flag [FLAG_CURSED]) |
3975 | { |
3960 | { |
3976 | who->contr->killer = food; |
3961 | who->contr->killer = food; |
3977 | hit_player (who, food->stats.hp, food, AT_POISON, 1); |
3962 | hit_player (who, food->stats.hp, food, AT_POISON, 1); |
3978 | who->failmsg ("Eck!...that was poisonous!"); |
3963 | who->failmsg ("Eck!...that was poisonous!"); |
3979 | } |
3964 | } |
… | |
… | |
3988 | } |
3973 | } |
3989 | } |
3974 | } |
3990 | |
3975 | |
3991 | if (food->stats.sp != 0) |
3976 | if (food->stats.sp != 0) |
3992 | { |
3977 | { |
3993 | if (QUERY_FLAG (food, FLAG_CURSED)) |
3978 | if (food->flag [FLAG_CURSED]) |
3994 | { |
3979 | { |
3995 | who->failmsg ("You are drained of mana!"); |
3980 | who->failmsg ("You are drained of mana!"); |
3996 | who->stats.sp -= food->stats.sp; |
3981 | who->stats.sp -= food->stats.sp; |
3997 | if (who->stats.sp < 0) |
3982 | if (who->stats.sp < 0) |
3998 | who->stats.sp = 0; |
3983 | who->stats.sp = 0; |
… | |
… | |
4081 | pl->animation_id = change->animation_id; |
4066 | pl->animation_id = change->animation_id; |
4082 | pl->flag [FLAG_ANIMATE] = change->flag [FLAG_ANIMATE]; |
4067 | pl->flag [FLAG_ANIMATE] = change->flag [FLAG_ANIMATE]; |
4083 | } |
4068 | } |
4084 | |
4069 | |
4085 | /* check the special case of can't use weapons */ |
4070 | /* check the special case of can't use weapons */ |
4086 | /*if(QUERY_FLAG(change,FLAG_USE_WEAPON)) CLEAR_FLAG(pl,FLAG_USE_WEAPON); */ |
4071 | /*if(change->flag [FLAG_USE_WEAPON]) pl->clr_flag (FLAG_USE_WEAPON); */ |
4087 | if (change->name == shstr_monk) |
4072 | if (change->name == shstr_monk) |
4088 | CLEAR_FLAG (pl, FLAG_USE_WEAPON); |
4073 | pl->clr_flag (FLAG_USE_WEAPON); |
4089 | |
4074 | |
4090 | break; |
4075 | break; |
4091 | } |
4076 | } |
4092 | } |
4077 | } |
4093 | } |
4078 | } |