ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/apply.C
(Generate patch)

Comparing deliantra/server/server/apply.C (file contents):
Revision 1.247 by root, Tue Apr 6 03:59:19 2010 UTC vs.
Revision 1.257 by root, Thu Apr 15 00:36:51 2010 UTC

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
35typedef 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
39static const struct may_attempt_inv : types_t 37static 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
68static const struct may_attempt_player : types_t 66static const struct apply_types_player_only : typeset
69{ 67{
70 may_attempt_player () 68 apply_types_player_only ()
71 { 69 {
72 set (EXIT); 70 set (EXIT);
73 set (BOOK); 71 set (BOOK);
72 set (SIGN);
73 set (BOOK);
74 set (SKILLSCROLL); 74 set (SKILLSCROLL);
75 set (SPELLBOOK); 75 set (SPELLBOOK);
76 set (INSCRIBABLE);
76 set (TREASURE); 77 set (TREASURE);
77 set (SAVEBED); 78 set (SAVEBED);
78 set (ARMOUR_IMPROVER); 79 set (ARMOUR_IMPROVER);
79 set (WEAPON_IMPROVER); 80 set (WEAPON_IMPROVER);
80 set (CLOCK); 81 set (CLOCK);
81 set (MENU); 82 set (MENU);
82 set (LIGHTER); /* for lighting torches/lanterns/etc */ 83 set (LIGHTER); /* for lighting torches/lanterns/etc */
83 set (INSCRIBABLE);
84 set (SIGN);
85 set (BOOK);
86 } 84 }
87} may_attempt_player; 85} apply_types_player_only;
88 86
89// applying these _can_ be attempted, others cannot 87// applying these _can_ be attempted, others cannot
90// be applied at all. used by e.g. apply below. 88// be applied at all. used by e.g. apply below.
91 89
92static const struct may_attempt : types_t 90static const struct apply_types : typeset
93{ 91{
94 may_attempt () 92 apply_types ()
95 : types_t ((types_t)may_attempt_player | (types_t)may_attempt_inv) 93 : typeset ((typeset)apply_types_player_only | (typeset)apply_types_inv_only)
96 { 94 {
97 set (T_HANDLE); 95 set (T_HANDLE);
98 set (TRIGGER); 96 set (TRIGGER);
99 set (SCROLL); 97 set (SCROLL);
100 set (POTION); 98 set (POTION);
107 set (FLESH); 105 set (FLESH);
108 set (POISON); 106 set (POISON);
109 set (POWER_CRYSTAL); 107 set (POWER_CRYSTAL);
110 set (ITEM_TRANSFORMER); 108 set (ITEM_TRANSFORMER);
111 } 109 }
112} may_attempt; 110} apply_types;
113 111
114/**************************************************************************** 112/****************************************************************************
115 * Weapon improvement code follows 113 * Weapon improvement code follows
116 ****************************************************************************/ 114 ****************************************************************************/
117 115
141 if (!item) 139 if (!item)
142 return 0; 140 return 0;
143 141
144 for (op = op->below; op; op = op->below) 142 for (op = op->below; op; op = op->below)
145 if (op->arch->archname == item) 143 if (op->arch->archname == item)
146 if (!QUERY_FLAG (op, FLAG_CURSED) && !QUERY_FLAG (op, FLAG_DAMNED) 144 if (!op->flag [FLAG_CURSED] && !op->flag [FLAG_DAMNED]
147 && /* Loophole bug? -FD- */ !QUERY_FLAG (op, FLAG_UNPAID)) 145 && /* Loophole bug? -FD- */ !op->flag [FLAG_UNPAID])
148 count += op->number_of (); 146 count += op->number_of ();
149 147
150 return count; 148 return count;
151} 149}
152 150
199 if (improver->slaying) 197 if (improver->slaying)
200 { 198 {
201 count = check_item (op, improver->slaying); 199 count = check_item (op, improver->slaying);
202 if (count < 1) 200 if (count < 1)
203 { 201 {
204 op->failmsg (format ("The gods want more %ss", &improver->slaying)); 202 op->failmsgf ("The gods want more %ss", &improver->slaying);
205 return 0; 203 return 0;
206 } 204 }
207 } 205 }
208 else 206 else
209 count = 1; 207 count = 1;
334 { 332 {
335 op->failmsg ("This weapon cannot be improved any more."); 333 op->failmsg ("This weapon cannot be improved any more.");
336 return 0; 334 return 0;
337 } 335 }
338 336
339 if (QUERY_FLAG (weapon, FLAG_APPLIED) 337 if (weapon->flag [FLAG_APPLIED]
340 && !check_item_power (op, weapon->item_power + 1)) 338 && !check_item_power (op, weapon->item_power + 1))
341 { 339 {
342 op->failmsg ("Improving the weapon will make it too " 340 op->failmsg ("Improving the weapon will make it too "
343 "powerful for you to use. Unready it if you " 341 "powerful for you to use. Unready it if you "
344 "really want to improve it."); 342 "really want to improve it.");
394 sacrifice_needed *= 2; 392 sacrifice_needed *= 2;
395 393
396 sacrifice_count = check_sacrifice (op, improver); 394 sacrifice_count = check_sacrifice (op, improver);
397 if (sacrifice_count < sacrifice_needed) 395 if (sacrifice_count < sacrifice_needed)
398 { 396 {
399 op->failmsg (format ("You need at least %d %s.", sacrifice_needed, &improver->slaying)); 397 op->failmsgf ("You need at least %d %s.", sacrifice_needed, &improver->slaying);
400 return 0; 398 return 0;
401 } 399 }
402 400
403 eat_item (op, improver->slaying, sacrifice_needed); 401 eat_item (op, improver->slaying, sacrifice_needed);
404 weapon->item_power++; 402 weapon->item_power++;
426 * then calls improve_weapon to do the dirty work. 424 * then calls improve_weapon to do the dirty work.
427 */ 425 */
428static int 426static int
429check_improve_weapon (object *op, object *tmp) 427check_improve_weapon (object *op, object *tmp)
430{ 428{
431 object *otmp;
432
433 if (op->type != PLAYER) 429 if (op->type != PLAYER)
434 return 0; 430 return 0;
435 431
436 if (!QUERY_FLAG (op, FLAG_WIZCAST) && (get_map_flags (op->map, NULL, op->x, op->y, NULL, NULL) & P_NO_MAGIC)) 432 if (!op->flag [FLAG_WIZCAST] && (get_map_flags (op->map, NULL, op->x, op->y, NULL, NULL) & P_NO_MAGIC))
437 { 433 {
438 op->failmsg ("Something blocks the magic of the scroll!"); 434 op->failmsg ("Something blocks the magic of the scroll!");
439 return 0; 435 return 0;
440 } 436 }
441 437
442 otmp = find_marked_object (op); 438 object *otmp = op->mark ();
443 439
444 if (!otmp) 440 if (!otmp)
445 { 441 {
446 op->failmsg ("You need to mark a weapon object. H<Use the mark command or the mark option from the item popup menu.>"); 442 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; 443 return 0;
448 } 444 }
449 445
450 if (otmp->type != WEAPON && otmp->type != BOW) 446 if (otmp->type != WEAPON && otmp->type != BOW)
451 { 447 {
452 op->failmsg ("Marked item is not a weapon or bow!"); 448 op->failmsg ("Marked item is not a weapon or bow!");
449 return 0;
450 }
451
452 if (!op->apply (otmp, AP_UNAPPLY))
453 {
454 op->failmsg ("You are unable to take off your weapon to improve it!");
453 return 0; 455 return 0;
454 } 456 }
455 457
456 op->statusmsg ("Applied weapon builder."); 458 op->statusmsg ("Applied weapon builder.");
457 459
483 * changing of physical area right now. 485 * changing of physical area right now.
484 */ 486 */
485static int 487static int
486improve_armour (object *op, object *improver, object *armour) 488improve_armour (object *op, object *improver, object *armour)
487{ 489{
488 object *tmp;
489
490 if (armour->magic >= settings.armor_max_enchant) 490 if (armour->magic >= settings.armor_max_enchant)
491 { 491 {
492 op->failmsg ("This armour can not be enchanted any further!"); 492 op->failmsg ("This armour can not be enchanted any further!");
493 return 0; 493 return 0;
494 } 494 }
505 } 505 }
506 506
507 /* Split objects if needed. Can't insert tmp until the 507 /* Split objects if needed. Can't insert tmp until the
508 * end of this function - otherwise it will just re-merge. 508 * end of this function - otherwise it will just re-merge.
509 */ 509 */
510 tmp = armour->nrof > 1 ? armour->split (armour->nrof - 1) : 0; 510 object *tmp = armour->nrof > 1 ? armour->split (armour->nrof - 1) : 0;
511 511
512 armour->magic++; 512 armour->magic++;
513 513
514 if (!settings.armor_speed_linear) 514 if (!settings.armor_speed_linear)
515 { 515 {
553 553
554 if (op->type == PLAYER) 554 if (op->type == PLAYER)
555 { 555 {
556 esrv_send_item (op, armour); 556 esrv_send_item (op, armour);
557 557
558 if (QUERY_FLAG (armour, FLAG_APPLIED)) 558 if (armour->flag [FLAG_APPLIED])
559 op->update_stats (); 559 op->update_stats ();
560 } 560 }
561 561
562 improver->decrease (); 562 improver->decrease ();
563 563
643 for (ob = converter->inv->below, i = 1; ob; ob = ob->below, i++) 643 for (ob = converter->inv->below, i = 1; ob; ob = ob->below, i++)
644 if (rndm (0, i) == 0) 644 if (rndm (0, i) == 0)
645 ob_to_copy = ob; 645 ob_to_copy = ob;
646 646
647 item = ob_to_copy->deep_clone (); 647 item = ob_to_copy->deep_clone ();
648 CLEAR_FLAG (item, FLAG_IS_A_TEMPLATE); 648 item->clr_flag (FLAG_IS_A_TEMPLATE);
649 unflag_inv (item, FLAG_IS_A_TEMPLATE); 649 unflag_inv (item, FLAG_IS_A_TEMPLATE);
650 } 650 }
651 else 651 else
652 { 652 {
653 if (!conv_to) 653 if (!conv_to)
666 666
667 if (nr) 667 if (nr)
668 item->nrof *= nr; 668 item->nrof *= nr;
669 669
670 if (converter->flag [FLAG_PRECIOUS]) 670 if (converter->flag [FLAG_PRECIOUS])
671 SET_FLAG (item, FLAG_UNPAID); 671 item->set_flag (FLAG_UNPAID);
672 672
673 if (converter->is_in_shop ()) 673 if (converter->is_in_shop ())
674 { 674 {
675 // converters on shop floors don't work anymore, bug lets check for it 675 // converters on shop floors don't work anymore, bug lets check for it
676 // and report in case someone still does it. 676 // and report in case someone still does it.
677 LOG (llevDebug, "ITEMBUG: broken converter, converters on shop floor don't work: %s\n", 677 LOG (llevDebug, "ITEMBUG: broken converter, converters on shop floor don't work: %s\n",
678 converter->debug_desc ()); 678 converter->debug_desc ());
679 SET_FLAG (item, FLAG_UNPAID); 679 item->set_flag (FLAG_UNPAID);
680 } 680 }
681 else if (price_in < sint64 (item->nrof) * item->value) 681 else if (price_in < sint64 (item->nrof) * item->value)
682 { 682 {
683 LOG (llevDebug, "converter output price higher than input: %s at %s (%d, %d) in value %d, out value %d for %s\n", 683 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); 684 &converter->name, &converter->map->path, converter->x, converter->y, price_in, item->nrof * item->value, &item->name);
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, but not ours: some other player has opened it
738 op->failmsg (format ("Somebody else is using the %s already.", query_name (sack))); 738 op->failmsgf ("Somebody else is using the %s already.", query_name (sack));
739 return 1; 739 return 1;
740 } 740 }
741 741
742 // fall through to opening it (active in inv) 742 // fall through to opening it (active in inv)
743 } 743 }
819{ 819{
820 int rv = 0; 820 int rv = 0;
821 double opinion; 821 double opinion;
822 object *tmp, *next; 822 object *tmp, *next;
823 823
824 SET_FLAG (op, FLAG_NO_APPLY); /* prevent loops */ 824 op->set_flag (FLAG_NO_APPLY); /* prevent loops */
825 825
826 bool has_unpaid = false; 826 bool has_unpaid = false;
827 827
828 // quite inefficient to do this here twice, but the api doesn't lend itself to 828 // quite inefficient to do this here twice, but the api doesn't lend itself to
829 // a quick and small change :( 829 // a quick and small change :(
842 */ 842 */
843 for (tmp = op->inv; tmp; tmp = next) 843 for (tmp = op->inv; tmp; tmp = next)
844 { 844 {
845 next = tmp->below; 845 next = tmp->below;
846 846
847 if (QUERY_FLAG (tmp, FLAG_UNPAID)) 847 if (tmp->flag [FLAG_UNPAID])
848 { 848 {
849 int i = find_free_spot (tmp, op->map, op->x, op->y, 1, 9); 849 int i = find_free_spot (tmp, op->map, op->x, op->y, 1, 9);
850 850
851 if (i >= 0) 851 if (i >= 0)
852 tmp->move (i); 852 tmp->move (i);
853 } 853 }
854 } 854 }
855 855
856 /* Don't teleport things like spell effects */ 856 /* Don't teleport things like spell effects */
857 if (QUERY_FLAG (op, FLAG_NO_PICK)) 857 if (op->flag [FLAG_NO_PICK])
858 return 0; 858 return 0;
859 859
860 /* unpaid objects, or non living objects, can't transfer by 860 /* unpaid objects, or non living objects, can't transfer by
861 * shop mats. Instead, put it on a nearby space. 861 * shop mats. Instead, put it on a nearby space.
862 */ 862 */
863 if (QUERY_FLAG (op, FLAG_UNPAID) || !QUERY_FLAG (op, FLAG_ALIVE)) 863 if (op->flag [FLAG_UNPAID] || !op->flag [FLAG_ALIVE])
864 { 864 {
865 /* Somebody dropped an unpaid item, just move to an adjacent place. */ 865 /* 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); 866 int i = find_free_spot (op, op->map, op->x, op->y, 1, 9);
867 867
868 if (i != -1) 868 if (i != -1)
923 op->y += freearr_y[i]; 923 op->y += freearr_y[i];
924 rv = insert_ob_in_map (op, op->map, shop_mat, 0) == NULL; 924 rv = insert_ob_in_map (op, op->map, shop_mat, 0) == NULL;
925 } 925 }
926 } 926 }
927 927
928 CLEAR_FLAG (op, FLAG_NO_APPLY); 928 op->clr_flag (FLAG_NO_APPLY);
929 return rv; 929 return rv;
930} 930}
931 931
932/** 932/**
933 * Handles applying a sign. 933 * Handles applying a sign.
961 op->failmsg ("You cannot read it anymore."); 961 op->failmsg ("You cannot read it anymore.");
962 962
963 return; 963 return;
964 } 964 }
965 965
966 if (!QUERY_FLAG (op, FLAG_WIZPASS)) 966 if (!op->flag [FLAG_WIZPASS])
967 sign->last_eat++; 967 sign->last_eat++;
968 } 968 }
969 969
970 /* Sign or magic mouth? Do we need to see it, or does it talk to us? 970 /* 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 971 * 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 972 * move_on is zero, it needs to be manually applied (doesn't talk
973 * to us). 973 * to us).
974 */ 974 */
975 if (QUERY_FLAG (op, FLAG_BLIND) && !QUERY_FLAG (op, FLAG_WIZ) && !sign->move_on) 975 if (op->flag [FLAG_BLIND] && !op->flag [FLAG_WIZ] && !sign->move_on)
976 { 976 {
977 op->failmsg ("You are unable to read while blind!"); 977 op->failmsg ("You are unable to read while blind!");
978 return; 978 return;
979 } 979 }
980 980
1077 who->statusmsg (format ("You unready %s.", query_name (op))); 1077 who->statusmsg (format ("You unready %s.", query_name (op)));
1078 change_abil (who, op); 1078 change_abil (who, op);
1079 } 1079 }
1080 else 1080 else
1081 { 1081 {
1082 who->change_skill (0);
1083
1084 if (op->type == BOW) 1082 if (op->type == BOW)
1085 op->flag [FLAG_READY_BOW ] = false; 1083 op->flag [FLAG_READY_BOW ] = false;
1086 else 1084 else
1087 op->flag [FLAG_READY_RANGE] = false; 1085 op->flag [FLAG_READY_RANGE] = false;
1088 } 1086 }
1169static bool 1167static bool
1170unapply_for_ob (object *who, object *op, int aflags) 1168unapply_for_ob (object *who, object *op, int aflags)
1171{ 1169{
1172 if (op->is_range ()) 1170 if (op->is_range ())
1173 for (object *tmp = who->inv; tmp; tmp = tmp->below) 1171 for (object *tmp = who->inv; tmp; tmp = tmp->below)
1174 if (QUERY_FLAG (tmp, FLAG_APPLIED) && tmp->is_range ()) 1172 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))) 1173 if ((aflags & AP_IGNORE_CURSE) || (aflags & AP_PRINT) || (!tmp->flag [FLAG_CURSED] && !tmp->flag [FLAG_DAMNED]))
1176 { 1174 {
1177 if (aflags & AP_PRINT) 1175 if (aflags & AP_PRINT)
1178 who->failmsg (query_name (tmp)); 1176 who->failmsg (query_name (tmp));
1179 else 1177 else
1180 unapply_special (who, tmp, aflags); 1178 unapply_special (who, tmp, aflags);
1183 { 1181 {
1184 /* In this case, we want to try and remove a cursed item. 1182 /* 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 1183 * While we know it won't work, we want unapply_special to
1186 * at least generate the message. 1184 * at least generate the message.
1187 */ 1185 */
1188 who->failmsg (format ("No matter how hard you try, you just can't remove the %s." CANNOT_REMOVE_CURSED, query_name (tmp))); 1186 who->failmsgf ("No matter how hard you try, you just can't remove the %s." CANNOT_REMOVE_CURSED, query_name (tmp));
1189 return 1; 1187 return 1;
1190 } 1188 }
1191 1189
1192 for (int i = 0; i < NUM_BODY_LOCATIONS; i++) 1190 for (int i = 0; i < NUM_BODY_LOCATIONS; i++)
1193 { 1191 {
1213#endif 1211#endif
1214 return 1; 1212 return 1;
1215 } 1213 }
1216 1214
1217 /* If we are just printing, we don't care about cursed status */ 1215 /* 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)))) 1216 if ((aflags & AP_IGNORE_CURSE) || (aflags & AP_PRINT) || (!(tmp->flag [FLAG_CURSED] || tmp->flag [FLAG_DAMNED])))
1219 { 1217 {
1220 if (aflags & AP_PRINT) 1218 if (aflags & AP_PRINT)
1221 who->failmsg (query_name (tmp)); 1219 who->failmsg (query_name (tmp));
1222 else 1220 else
1223 unapply_special (who, tmp, aflags); 1221 unapply_special (who, tmp, aflags);
1227 /* Cursed item that we can't unequip - tell the player. 1225 /* Cursed item that we can't unequip - tell the player.
1228 * Note this could be annoying if this is just one of a few, 1226 * 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 1227 * so it may not be critical (eg, putting on a ring and you have
1230 * one cursed ring.) 1228 * one cursed ring.)
1231 */ 1229 */
1232 who->failmsg (format ("The %s just won't come off." CANNOT_REMOVE_CURSED, query_name (tmp))); 1230 who->failmsgf ("The %s just won't come off." CANNOT_REMOVE_CURSED, query_name (tmp));
1233 } 1231 }
1234 1232
1235 last = tmp->below; 1233 last = tmp->below;
1236 } 1234 }
1237 /* if we got here, this slot is freed up - otherwise, if it wasn't freed up, the 1235 /* 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, 1333 * the weapon/shield checks, and the range checks for monsters,
1336 * because you can't control those just by body location - bows, shields, 1334 * 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 1335 * and weapons all use the same slot. Similar for horn/rod/wand - they
1338 * all use the same location. 1336 * all use the same location.
1339 */ 1337 */
1340 if (op->type == WEAPON && !QUERY_FLAG (who, FLAG_USE_WEAPON)) 1338 if (op->type == WEAPON && !who->flag [FLAG_USE_WEAPON])
1341 retval |= CAN_APPLY_RESTRICTION; 1339 retval |= CAN_APPLY_RESTRICTION;
1342 1340
1343 if (op->type == SHIELD && !QUERY_FLAG (who, FLAG_USE_SHIELD)) 1341 if (op->type == SHIELD && !who->flag [FLAG_USE_SHIELD])
1344 retval |= CAN_APPLY_RESTRICTION; 1342 retval |= CAN_APPLY_RESTRICTION;
1345 1343
1346 if (who->type != PLAYER) 1344 if (who->type != PLAYER)
1347 { 1345 {
1348 if ((op->type == WAND || op->type == HORN || op->type == ROD) && !QUERY_FLAG (who, FLAG_USE_RANGE)) 1346 if ((op->type == WAND || op->type == HORN || op->type == ROD) && !who->flag [FLAG_USE_RANGE])
1349 retval |= CAN_APPLY_RESTRICTION; 1347 retval |= CAN_APPLY_RESTRICTION;
1350 1348
1351 if (op->type == BOW && !QUERY_FLAG (who, FLAG_USE_BOW)) 1349 if (op->type == BOW && !who->flag [FLAG_USE_BOW])
1352 retval |= CAN_APPLY_RESTRICTION; 1350 retval |= CAN_APPLY_RESTRICTION;
1353 1351
1354 if (op->type == RING && !QUERY_FLAG (who, FLAG_USE_RING)) 1352 if (op->type == RING && !who->flag [FLAG_USE_RING])
1355 retval |= CAN_APPLY_RESTRICTION; 1353 retval |= CAN_APPLY_RESTRICTION;
1356 1354
1357 if (op->type == BOW && !QUERY_FLAG (who, FLAG_USE_BOW)) 1355 if (op->type == BOW && !who->flag [FLAG_USE_BOW])
1358 retval |= CAN_APPLY_RESTRICTION; 1356 retval |= CAN_APPLY_RESTRICTION;
1359 } 1357 }
1360 1358
1361 return retval; 1359 return retval;
1362} 1360}
1403 //TODO: remove these when apply_special is no longer exposed 1401 //TODO: remove these when apply_special is no longer exposed
1404 if (op->env != who) 1402 if (op->env != who)
1405 return 1; /* op is not in inventory */ 1403 return 1; /* op is not in inventory */
1406 1404
1407 /* trying to unequip op */ 1405 /* trying to unequip op */
1408 if (QUERY_FLAG (op, FLAG_APPLIED)) 1406 if (op->flag [FLAG_APPLIED])
1409 { 1407 {
1410 /* always apply, so no reason to unapply */ 1408 /* always apply, so no reason to unapply */
1411 if (basic_flag == AP_APPLY) 1409 if (basic_flag == AP_APPLY)
1412 return 0; 1410 return 0;
1413 1411
1414 if (!(aflags & AP_IGNORE_CURSE) && (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED))) 1412 if (!(aflags & AP_IGNORE_CURSE) && (op->flag [FLAG_CURSED] || op->flag [FLAG_DAMNED]))
1415 { 1413 {
1416 who->failmsg (format ("No matter how hard you try, you just can't remove %s." CANNOT_REMOVE_CURSED, query_name (op))); 1414 who->failmsgf ("No matter how hard you try, you just can't remove %s." CANNOT_REMOVE_CURSED, query_name (op));
1417 return 1; 1415 return 1;
1418 } 1416 }
1419 1417
1420 return unapply_special (who, op, aflags); 1418 return unapply_special (who, op, aflags);
1421 } 1419 }
1427 /* Can't just apply this object. Lets see what not and what to do */ 1425 /* Can't just apply this object. Lets see what not and what to do */
1428 if (int i = can_apply_object (who, op)) 1426 if (int i = can_apply_object (who, op))
1429 { 1427 {
1430 if (i & CAN_APPLY_NEVER) 1428 if (i & CAN_APPLY_NEVER)
1431 { 1429 {
1432 who->failmsg (format ("You don't have the body to use a %s. H<You can never apply this item.>", query_name (op))); 1430 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; 1431 return 1;
1434 } 1432 }
1435 else if (i & CAN_APPLY_RESTRICTION) 1433 else if (i & CAN_APPLY_RESTRICTION)
1436 { 1434 {
1437 who->failmsg (format ( 1435 who->failmsgf (
1438 "You have a prohibition against using a %s. " 1436 "You have a prohibition against using a %s. "
1439 "H<Your belief, profession or class prevents you from applying this item.>", 1437 "H<Your belief, profession or class prevents you from applying this item.>",
1440 query_name (op) 1438 query_name (op)
1441 )); 1439 );
1442 return 1; 1440 return 1;
1443 } 1441 }
1444 1442
1445 if (who->type != PLAYER) 1443 if (who->type != PLAYER)
1446 { 1444 {
1467 // try to ready attached skill first 1465 // try to ready attached skill first
1468 skop = find_skill_by_name (who, op->skill); 1466 skop = find_skill_by_name (who, op->skill);
1469 1467
1470 if (!skop) 1468 if (!skop)
1471 { 1469 {
1472 who->failmsg (format ("You need the %s skill to use this item!", &op->skill)); 1470 who->failmsgf ("You need the %s skill to use this item!", &op->skill);
1473 return 1; 1471 return 1;
1474 } 1472 }
1475 else if (!who->apply (skop, AP_APPLY | AP_NO_SLOT)) 1473 else if (!who->apply (skop, AP_APPLY | AP_NO_SLOT))
1476 { 1474 {
1477 who->failmsg (format ("You can't use the required %s skill!", &op->skill)); 1475 who->failmsgf ("You can't use the required %s skill!", &op->skill);
1478 return 1; 1476 return 1;
1479 } 1477 }
1480 } 1478 }
1481 1479
1482 if (!check_item_power (who, op->item_power)) 1480 if (!check_item_power (who, op->item_power))
1514 if (player *pl = who->contr) 1512 if (player *pl = who->contr)
1515 { 1513 {
1516 who->statusmsg (format ("You wield %s.", query_name (op))); 1514 who->statusmsg (format ("You wield %s.", query_name (op)));
1517 change_abil (who, op); 1515 change_abil (who, op);
1518 } 1516 }
1519 else
1520 who->change_skill (skop);
1521 1517
1522 op->flag [FLAG_READY_WEAPON] = true; 1518 op->flag [FLAG_READY_WEAPON] = true;
1523 break; 1519 break;
1524 1520
1525 case ARMOUR: 1521 case ARMOUR:
1530 case GIRDLE: 1526 case GIRDLE:
1531 case BRACERS: 1527 case BRACERS:
1532 case CLOAK: 1528 case CLOAK:
1533 case RING: 1529 case RING:
1534 case AMULET: 1530 case AMULET:
1535 SET_FLAG (op, FLAG_APPLIED); 1531 op->set_flag (FLAG_APPLIED);
1536 who->statusmsg (format ("You wear %s.", query_name (op))); 1532 who->statusmsg (format ("You wear %s.", query_name (op)));
1537 change_abil (who, op); 1533 change_abil (who, op);
1538 break; 1534 break;
1539 1535
1540 case SKILL_TOOL: 1536 case SKILL_TOOL:
1541 // applying a skill tool does not ready the skill 1537 // applying a skill tool does not ready the skill
1542 // if something needs the skill, it has to ready it itself 1538 // if something needs the skill, it has to ready it itself
1543 //TODO: unapplying should unapply the skill, though 1539 //TODO: unapplying should unapply the skill, though
1544 SET_FLAG (op, FLAG_APPLIED); 1540 op->set_flag (FLAG_APPLIED);
1545 break; 1541 break;
1546 1542
1547 case SKILL: 1543 case SKILL:
1548 if (!(aflags & AP_NO_SLOT)) 1544 if (!(aflags & AP_NO_SLOT))
1549 { 1545 {
1550 // skill is used on it's own, as opposed to being a chosen_skill 1546 // skill is used on it's own, as opposed to being a chosen_skill
1551 1547
1552 if (skill_flags [op->subtype] & (SF_NEED_ITEM | SF_MANA)) 1548 if (skill_flags [op->subtype] & (SF_NEED_ITEM | SF_MANA))
1553 { 1549 {
1554 who->failmsg (format ( 1550 who->failmsgf (
1555 "You feel as if you wanted to do something funny, but you can't remember what. " 1551 "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. " 1552 "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.>", 1553 "It cannot be used on its own.>",
1558 &op->skill 1554 &op->skill
1559 )); 1555 );
1560 if (tmp) who->insert (tmp); 1556 if (tmp) who->insert (tmp);
1561 return 1; 1557 return 1;
1562 } 1558 }
1563 1559
1564 if (skill_flags [op->subtype] & SF_AUTARK 1560 if (skill_flags [op->subtype] & SF_AUTARK
1565 || !(skill_flags [op->subtype] & (SF_COMBAT | SF_RANGED))) 1561 || !(skill_flags [op->subtype] & (SF_COMBAT | SF_RANGED)))
1566 { 1562 {
1567 if (skill_flags [op->subtype] & SF_USE) 1563 if (skill_flags [op->subtype] & SF_USE)
1568 who->failmsg (format ( 1564 who->failmsgf (
1569 "You feel as if you wanted to do something funny, but you can't remember what. " 1565 "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>.>", 1566 "H<The %s skill cannot be readied, instead, try C<use_skill %s>.>",
1571 &op->skill, &op->skill 1567 &op->skill, &op->skill
1572 )); 1568 );
1573 else 1569 else
1574 who->failmsg (format ( 1570 who->failmsgf (
1575 "You feel as if you wanted to do something funny, but you can't remember what. " 1571 "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.>", 1572 "H<The %s skill cannot be readied or used, it is always active.>",
1577 &op->skill 1573 &op->skill
1578 )); 1574 );
1579 1575
1580 if (tmp) who->insert (tmp); 1576 if (tmp) who->insert (tmp);
1581 1577
1582 return 1; 1578 return 1;
1583 } 1579 }
1587 who->statusmsg (format ("You can now use the %s skill.", &op->skill)); 1583 who->statusmsg (format ("You can now use the %s skill.", &op->skill));
1588 else 1584 else
1589 who->statusmsg (format ("You ready %s.", query_name (op))); 1585 who->statusmsg (format ("You ready %s.", query_name (op)));
1590 } 1586 }
1591 1587
1592 SET_FLAG (who, FLAG_READY_SKILL); 1588 who->set_flag (FLAG_READY_SKILL);
1593 SET_FLAG (op, FLAG_APPLIED); 1589 op->set_flag (FLAG_APPLIED);
1594 change_abil (who, op); 1590 change_abil (who, op);
1595 break; 1591 break;
1596 1592
1597 case BOW: 1593 case BOW:
1598 if (op->level && (!op->name.starts_with (who->name) || op->name [who->name.length ()] != '\'')) 1594 if (op->level && (!op->name.starts_with (who->name) || op->name [who->name.length ()] != '\''))
1629 1625
1630 /*FALLTHROUGH*/ 1626 /*FALLTHROUGH*/
1631 case WAND: 1627 case WAND:
1632 case ROD: 1628 case ROD:
1633 case HORN: 1629 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; 1630 op->flag [FLAG_APPLIED] = true;
1644 1631
1645 if (player *pl = who->contr) 1632 if (player *pl = who->contr)
1646 { 1633 {
1647 who->statusmsg (format ("You ready %s.", query_name (op))); 1634 who->statusmsg (format ("You ready %s.", query_name (op)));
1651 1638
1652 change_abil (who, op); 1639 change_abil (who, op);
1653 } 1640 }
1654 else 1641 else
1655 { 1642 {
1656 who->change_skill (skop);
1657
1658 if (op->type == BOW) 1643 if (op->type == BOW)
1659 op->flag [FLAG_READY_BOW ] = true; 1644 op->flag [FLAG_READY_BOW ] = true;
1660 else 1645 else
1661 op->flag [FLAG_READY_RANGE] = true; 1646 op->flag [FLAG_READY_RANGE] = true;
1662 } 1647 }
1673 1658
1674 default: 1659 default:
1675 who->statusmsg (format ("You apply %s.", query_name (op))); 1660 who->statusmsg (format ("You apply %s.", query_name (op)));
1676 } 1661 }
1677 1662
1678 SET_FLAG (op, FLAG_APPLIED); 1663 op->set_flag (FLAG_APPLIED);
1679 1664
1680 if (tmp) who->insert (tmp); 1665 if (tmp) who->insert (tmp);
1681 1666
1682 who->update_stats (); 1667 who->update_stats ();
1683 1668
1684 /* We exclude spell casting objects. The fire code will set the 1669 /* We exclude spell casting objects. The fire code will set the
1685 * been applied flag when they are used - until that point, 1670 * been applied flag when they are used - until that point,
1686 * you don't know anything about them. 1671 * you don't know anything about them.
1687 */ 1672 */
1688 if (who->type == PLAYER && op->type != WAND && op->type != HORN && op->type != ROD) 1673 if (who->type == PLAYER && op->type != WAND && op->type != HORN && op->type != ROD)
1689 SET_FLAG (op, FLAG_BEEN_APPLIED); 1674 op->set_flag (FLAG_BEEN_APPLIED);
1690 1675
1691 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED)) 1676 if (op->flag [FLAG_CURSED] || op->flag [FLAG_DAMNED])
1692 if (who->type == PLAYER) 1677 if (who->type == PLAYER)
1693 { 1678 {
1694 who->failmsg ( 1679 who->failmsg (
1695 "Oops, it feels deadly cold! " 1680 "Oops, it feels deadly cold! "
1696 "H<Maybe it wasn't such a bright idea to apply this cursed or damned item.>" 1681 "H<Maybe it wasn't such a bright idea to apply this cursed or damned item.>"
1697 ); 1682 );
1698 SET_FLAG (op, FLAG_KNOWN_CURSED); 1683 op->set_flag (FLAG_KNOWN_CURSED);
1699 } 1684 }
1700 1685
1701 if (object *pl = op->visible_to ()) 1686 if (object *pl = op->visible_to ())
1702 esrv_send_item (pl, op); 1687 esrv_send_item (pl, op);
1703 1688
1776 return 0; 1761 return 0;
1777 1762
1778 /* if the player has a marked item, identify that if it needs to be 1763 /* 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. 1764 * identified. If it doesn't, then go through the player inventory.
1780 */ 1765 */
1781 if (object *marked = find_marked_object (pl)) 1766 if (object *marked = pl->mark ())
1782 if (!QUERY_FLAG (marked, FLAG_IDENTIFIED) && need_identify (marked)) 1767 if (!marked->flag [FLAG_IDENTIFIED] && need_identify (marked))
1783 { 1768 {
1784 if (operate_altar (altar, &money, pl)) 1769 if (operate_altar (altar, &money, pl))
1785 { 1770 {
1786 identify (marked); 1771 identify (marked);
1787 1772
1793 } 1778 }
1794 } 1779 }
1795 1780
1796 for (object *id = pl->inv; id; id = id->below) 1781 for (object *id = pl->inv; id; id = id->below)
1797 { 1782 {
1798 if (!QUERY_FLAG (id, FLAG_IDENTIFIED) && !id->invisible && need_identify (id)) 1783 if (!id->flag [FLAG_IDENTIFIED] && !id->invisible && need_identify (id))
1799 { 1784 {
1800 if (operate_altar (altar, &money, pl)) 1785 if (operate_altar (altar, &money, pl))
1801 { 1786 {
1802 identify (id); 1787 identify (id);
1803 1788
1849 1834
1850 if (get_map_flags (op->map, NULL, op->x, op->y, NULL, NULL) & P_SAFE) 1835 if (get_map_flags (op->map, NULL, op->x, op->y, NULL, NULL) & P_SAFE)
1851 { 1836 {
1852 op->failmsg ("Gods prevent you from using this here, it's sacred ground!"); 1837 op->failmsg ("Gods prevent you from using this here, it's sacred ground!");
1853 1838
1854 CLEAR_FLAG (tmp, FLAG_APPLIED); 1839 tmp->clr_flag (FLAG_APPLIED);
1855 return 0; 1840 return 0;
1856 } 1841 }
1857 1842
1858 if (op->type == PLAYER) 1843 if (op->type == PLAYER)
1859 if (!QUERY_FLAG (tmp, FLAG_IDENTIFIED)) 1844 if (!tmp->flag [FLAG_IDENTIFIED])
1860 identify (tmp); 1845 identify (tmp);
1861 1846
1862 handle_apply_yield (tmp); 1847 handle_apply_yield (tmp);
1863 1848
1864 /* Potion of restoration - only for players */ 1849 /* Potion of restoration - only for players */
1865 if (op->type == PLAYER && (tmp->attacktype & AT_DEPLETE)) 1850 if (op->type == PLAYER && (tmp->attacktype & AT_DEPLETE))
1866 { 1851 {
1867 object *depl; 1852 object *depl;
1868 archetype *at; 1853 archetype *at;
1869 1854
1870 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED)) 1855 if (tmp->flag [FLAG_CURSED] || tmp->flag [FLAG_DAMNED])
1871 { 1856 {
1872 op->drain_stat (); 1857 op->drain_stat ();
1873 op->update_stats (); 1858 op->update_stats ();
1874 tmp->decrease (); 1859 tmp->decrease ();
1875 return 1; 1860 return 1;
1902 /* improvement potion - only for players */ 1887 /* improvement potion - only for players */
1903 if (op->type == PLAYER && (tmp->attacktype & AT_GODPOWER)) 1888 if (op->type == PLAYER && (tmp->attacktype & AT_GODPOWER))
1904 { 1889 {
1905 for (i = 1; i < min (11, op->level); i++) 1890 for (i = 1; i < min (11, op->level); i++)
1906 { 1891 {
1907 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED)) 1892 if (tmp->flag [FLAG_CURSED] || tmp->flag [FLAG_DAMNED])
1908 { 1893 {
1909 if (op->contr->levhp[i] != 1) 1894 if (op->contr->levhp[i] != 1)
1910 { 1895 {
1911 op->contr->levhp[i] = 1; 1896 op->contr->levhp[i] = 1;
1912 break; 1897 break;
1948 1933
1949 /* Just makes checking easier */ 1934 /* Just makes checking easier */
1950 if (i < min (11, op->level)) 1935 if (i < min (11, op->level))
1951 got_one = 1; 1936 got_one = 1;
1952 1937
1953 if (!QUERY_FLAG (tmp, FLAG_CURSED) && !QUERY_FLAG (tmp, FLAG_DAMNED)) 1938 if (!tmp->flag [FLAG_CURSED] && !tmp->flag [FLAG_DAMNED])
1954 { 1939 {
1955 if (got_one) 1940 if (got_one)
1956 { 1941 {
1957 op->update_stats (); 1942 op->update_stats ();
1958 op->statusmsg ("The Gods smile upon you and remake you " 1943 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, 1968 * 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. 1969 * but direction is problematic to try and imbue fireball potions for example.
1985 */ 1970 */
1986 if (tmp->inv) 1971 if (tmp->inv)
1987 { 1972 {
1988 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED)) 1973 if (tmp->flag [FLAG_CURSED] || tmp->flag [FLAG_DAMNED])
1989 { 1974 {
1990 op->failmsg ("Yech! Your lungs are on fire!"); 1975 op->failmsg ("Yech! Your lungs are on fire!");
1991 create_exploding_ball_at (op, op->level); 1976 create_exploding_ball_at (op, op->level);
1992 } 1977 }
1993 else 1978 else
1994 cast_spell (op, tmp, op->facing, tmp->inv, NULL); 1979 cast_spell (op, tmp, op->facing, tmp->inv, NULL);
1995 1980
1996 tmp->decrease (); 1981 tmp->decrease ();
1997 1982
1998 /* if youre dead, no point in doing this... */ 1983 /* if youre dead, no point in doing this... */
1999 if (!QUERY_FLAG (op, FLAG_REMOVED)) 1984 if (!op->flag [FLAG_REMOVED])
2000 op->update_stats (); 1985 op->update_stats ();
2001 1986
2002 return 1; 1987 return 1;
2003 } 1988 }
2004 1989
2019 2004
2020 /* This is a protection potion */ 2005 /* This is a protection potion */
2021 if (force) 2006 if (force)
2022 { 2007 {
2023 /* cursed items last longer */ 2008 /* cursed items last longer */
2024 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED)) 2009 if (tmp->flag [FLAG_CURSED] || tmp->flag [FLAG_DAMNED])
2025 { 2010 {
2026 force->stats.food *= 10; 2011 force->stats.food *= 10;
2027 for (i = 0; i < NROFATTACKS; i++) 2012 for (i = 0; i < NROFATTACKS; i++)
2028 if (force->resist[i] > 0) 2013 if (force->resist[i] > 0)
2029 force->resist[i] = -force->resist[i]; /* prot => vuln */ 2014 force->resist[i] = -force->resist[i]; /* prot => vuln */
2030 } 2015 }
2031 2016
2032 force->speed_left = -1; 2017 force->speed_left = -1;
2033 force = insert_ob_in_ob (force, op); 2018 force = insert_ob_in_ob (force, op);
2034 CLEAR_FLAG (tmp, FLAG_APPLIED); 2019 tmp->clr_flag (FLAG_APPLIED);
2035 SET_FLAG (force, FLAG_APPLIED); 2020 force->set_flag (FLAG_APPLIED);
2036 change_abil (op, force); 2021 change_abil (op, force);
2037 tmp->decrease (); 2022 tmp->decrease ();
2038 return 1; 2023 return 1;
2039 } 2024 }
2040 2025
2041 /* Only thing left are the stat potions */ 2026 /* Only thing left are the stat potions */
2042 if (op->type == PLAYER) 2027 if (op->type == PLAYER)
2043 { /* only for players */ 2028 { /* only for players */
2044 if ((QUERY_FLAG (tmp, FLAG_CURSED) 2029 if ((tmp->flag [FLAG_CURSED]
2045 || QUERY_FLAG (tmp, FLAG_DAMNED)) 2030 || tmp->flag [FLAG_DAMNED])
2046 && tmp->value != 0) 2031 && tmp->value != 0)
2047 CLEAR_FLAG (tmp, FLAG_APPLIED); 2032 tmp->clr_flag (FLAG_APPLIED);
2048 else 2033 else
2049 SET_FLAG (tmp, FLAG_APPLIED); 2034 tmp->set_flag (FLAG_APPLIED);
2050 2035
2051 if (!change_abil (op, tmp)) 2036 if (!change_abil (op, tmp))
2052 op->statusmsg ("Nothing happened."); 2037 op->statusmsg ("Nothing happened.");
2053 } 2038 }
2054 2039
2055 /* CLEAR_FLAG is so that if the character has other potions 2040 /* CLEAR_FLAG is so that if the character has other potions
2056 * that were grouped with the one consumed, his 2041 * that were grouped with the one consumed, his
2057 * stat will not be raised by them. fix_player just clears 2042 * stat will not be raised by them. fix_player just clears
2058 * up all the stats. 2043 * up all the stats.
2059 */ 2044 */
2060 CLEAR_FLAG (tmp, FLAG_APPLIED); 2045 tmp->clr_flag (FLAG_APPLIED);
2061 op->update_stats (); 2046 op->update_stats ();
2062 tmp->decrease (); 2047 tmp->decrease ();
2063 return 1; 2048 return 1;
2064} 2049}
2065 2050
2076move_apply (object *trap, object *victim, object *originator) 2061move_apply (object *trap, object *victim, object *originator)
2077{ 2062{
2078 static int recursion_depth = 0; 2063 static int recursion_depth = 0;
2079 2064
2080 /* Only exits affect DMs. */ 2065 /* Only exits affect DMs. */
2081 if (QUERY_FLAG (victim, FLAG_WIZPASS) && trap->type != EXIT && trap->type != SIGN) 2066 if (victim->flag [FLAG_WIZPASS] && trap->type != EXIT && trap->type != SIGN)
2082 return; 2067 return;
2083 2068
2084 /* move_apply() is the most likely candidate for causing unwanted and 2069 /* move_apply() is the most likely candidate for causing unwanted and
2085 * possibly unlimited recursion. 2070 * possibly unlimited recursion.
2086 */ 2071 */
2162 * trigger this here and get hit by own missile - and will be own enemy. 2147 * 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 2148 * 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 2149 * removed) but we have not synced victim and his missile. To avoid senseless
2165 * action, we avoid hits here 2150 * action, we avoid hits here
2166 */ 2151 */
2167 if ((QUERY_FLAG (victim, FLAG_ALIVE) && trap->has_active_speed ()) 2152 if ((victim->flag [FLAG_ALIVE] && trap->has_active_speed ())
2168 && trap->owner != victim) 2153 && trap->owner != victim)
2169 hit_with_arrow (trap, victim); 2154 hit_with_arrow (trap, victim);
2170 break; 2155 break;
2171 2156
2172 case SPELL_EFFECT: 2157 case SPELL_EFFECT:
2216 } 2201 }
2217 2202
2218 case CONVERTER: 2203 case CONVERTER:
2219 if (convert_item (victim, trap) < 0) 2204 if (convert_item (victim, trap) < 0)
2220 { 2205 {
2221 originator->failmsg (format ("The %s seems to be broken!", query_name (trap))); 2206 originator->failmsgf ("The %s seems to be broken!", query_name (trap));
2222 archetype::get (shstr_burnout)->insert_at (trap, trap); 2207 archetype::get (shstr_burnout)->insert_at (trap, trap);
2223 } 2208 }
2224 2209
2225 break; 2210 break;
2226 2211
2280 apply_container (victim, trap); 2265 apply_container (victim, trap);
2281 break; 2266 break;
2282 2267
2283 case RUNE: 2268 case RUNE:
2284 case TRAP: 2269 case TRAP:
2285 if (trap->level && QUERY_FLAG (victim, FLAG_ALIVE)) 2270 if (trap->level && victim->flag [FLAG_ALIVE])
2286 spring_trap (trap, victim); 2271 spring_trap (trap, victim);
2287 break; 2272 break;
2288 2273
2289 default: 2274 default:
2290 LOG (llevDebug, "name %s, arch %s, type %d with fly/walk on/off not " 2275 LOG (llevDebug, "name %s, arch %s, type %d with fly/walk on/off not "
2302apply_book (object *op, object *tmp) 2287apply_book (object *op, object *tmp)
2303{ 2288{
2304 int lev_diff; 2289 int lev_diff;
2305 object *skill_ob; 2290 object *skill_ob;
2306 2291
2307 if (QUERY_FLAG (op, FLAG_BLIND) && !QUERY_FLAG (op, FLAG_WIZ)) 2292 if (op->flag [FLAG_BLIND] && !op->flag [FLAG_WIZ])
2308 { 2293 {
2309 op->failmsg ("You are unable to read while blind!"); 2294 op->failmsg ("You are unable to read while blind!");
2310 return; 2295 return;
2311 } 2296 }
2312 2297
2313 if (!tmp->msg) 2298 if (!tmp->msg)
2314 { 2299 {
2315 op->failmsg (format ("The %s contains nothing but meaningless gibberish. H<There is nothing interesting to read here.>", &tmp->name)); 2300 op->failmsgf ("The %s contains nothing but meaningless gibberish. H<There is nothing interesting to read here.>", &tmp->name);
2316 return; 2301 return;
2317 } 2302 }
2318 2303
2319 /* need a literacy skill to read stuff! */ 2304 /* need a literacy skill to read stuff! */
2320 skill_ob = find_skill_by_name (op, tmp->skill); 2305 skill_ob = find_skill_by_name (op, tmp->skill);
2321 if (!skill_ob) 2306 if (!skill_ob)
2322 { 2307 {
2323 op->failmsg (format ("You are unable to decipher the strange symbols. H<You lack the %s skill to read this.>", &tmp->skill)); 2308 op->failmsgf ("You are unable to decipher the strange symbols. H<You lack the %s skill to read this.>", &tmp->skill);
2324 return; 2309 return;
2325 } 2310 }
2326 2311
2327 lev_diff = tmp->level - (skill_ob->level + 5); 2312 lev_diff = tmp->level - (skill_ob->level + 5);
2328 if (!QUERY_FLAG (op, FLAG_WIZ) && lev_diff > 0) 2313 if (!op->flag [FLAG_WIZ] && lev_diff > 0)
2329 { 2314 {
2330 op->failmsg (lev_diff < 2 ? "This book is just barely beyond your comprehension." 2315 op->failmsg (lev_diff < 2 ? "This book is just barely beyond your comprehension."
2331 : lev_diff < 3 ? "This book is slightly beyond your comprehension." 2316 : lev_diff < 3 ? "This book is slightly beyond your comprehension."
2332 : lev_diff < 5 ? "This book is beyond your comprehension." 2317 : lev_diff < 5 ? "This book is beyond your comprehension."
2333 : lev_diff < 8 ? "This book is quite a bit beyond your comprehension." 2318 : lev_diff < 8 ? "This book is quite a bit beyond your comprehension."
2344 if (player *pl = op->contr) 2329 if (player *pl = op->contr)
2345 if (client *ns = pl->ns) 2330 if (client *ns = pl->ns)
2346 pl->infobox (MSG_CHANNEL ("book"), format ("T<%s>\n\n%s", (char *)long_desc (tmp, op), &tmp->msg)); 2331 pl->infobox (MSG_CHANNEL ("book"), format ("T<%s>\n\n%s", (char *)long_desc (tmp, op), &tmp->msg));
2347 2332
2348 /* gain xp from reading */ 2333 /* gain xp from reading */
2349 if (!QUERY_FLAG (tmp, FLAG_NO_SKILL_IDENT)) 2334 if (!tmp->flag [FLAG_NO_SKILL_IDENT])
2350 { /* only if not read before */ 2335 { /* only if not read before */
2351 int exp_gain = calc_skill_exp (op, tmp, skill_ob); 2336 int exp_gain = calc_skill_exp (op, tmp, skill_ob);
2352 2337
2353 if (!QUERY_FLAG (tmp, FLAG_IDENTIFIED)) 2338 if (!tmp->flag [FLAG_IDENTIFIED])
2354 { 2339 {
2355 /*exp_gain *= 2; because they just identified it too */ 2340 /*exp_gain *= 2; because they just identified it too */
2356 SET_FLAG (tmp, FLAG_IDENTIFIED); 2341 tmp->set_flag (FLAG_IDENTIFIED);
2357 2342
2358 if (object *pl = tmp->visible_to ()) 2343 if (object *pl = tmp->visible_to ())
2359 esrv_update_item (UPD_FLAGS | UPD_NAME, pl, tmp); 2344 esrv_update_item (UPD_FLAGS | UPD_NAME, pl, tmp);
2360 } 2345 }
2361 2346
2362 change_exp (op, exp_gain, skill_ob->skill, 0); 2347 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 */ 2348 tmp->set_flag (FLAG_NO_SKILL_IDENT); /* so no more xp gained from this book */
2364 } 2349 }
2365} 2350}
2366 2351
2367/** 2352/**
2368 * op made some mistake with a scroll, this takes care of punishment. 2353 * op made some mistake with a scroll, this takes care of punishment.
2426{ 2411{
2427 switch (learn_skill (op, tmp)) 2412 switch (learn_skill (op, tmp))
2428 { 2413 {
2429 case 0: 2414 case 0:
2430 op->play_sound (sound_find ("generic_fail")); 2415 op->play_sound (sound_find ("generic_fail"));
2431 op->failmsg (format ("You already possess the knowledge held within the %s.", query_name (tmp))); 2416 op->failmsgf ("You already possess the knowledge held within the %s.", query_name (tmp));
2432 break; 2417 break;
2433 2418
2434 case 1: 2419 case 1:
2435 tmp->decrease (); 2420 tmp->decrease ();
2436 op->play_sound (sound_find ("skill_learn")); 2421 op->play_sound (sound_find ("skill_learn"));
2438 break; 2423 break;
2439 2424
2440 default: 2425 default:
2441 tmp->decrease (); 2426 tmp->decrease ();
2442 op->play_sound (sound_find ("generic_fail")); 2427 op->play_sound (sound_find ("generic_fail"));
2443 op->failmsg (format ("You fail to learn the knowledge of the %s.\n", query_name (tmp))); 2428 op->failmsgf ("You fail to learn the knowledge of the %s.\n", query_name (tmp));
2444 break; 2429 break;
2445 } 2430 }
2446} 2431}
2447 2432
2448/** 2433/**
2461 } 2446 }
2462 2447
2463 /* Upgrade special prayers to normal prayers */ 2448 /* Upgrade special prayers to normal prayers */
2464 if ((tmp = check_spell_known (op, spell->name)) != NULL) 2449 if ((tmp = check_spell_known (op, spell->name)) != NULL)
2465 { 2450 {
2466 if (special_prayer && !QUERY_FLAG (tmp, FLAG_STARTEQUIP)) 2451 if (special_prayer && !tmp->flag [FLAG_STARTEQUIP])
2467 { 2452 {
2468 LOG (llevError, "BUG: do_learn_spell(): spell already known, but not marked as startequip\n"); 2453 LOG (llevError, "BUG: do_learn_spell(): spell already known, but not marked as startequip\n");
2469 return; 2454 return;
2470 } 2455 }
2471 return; 2456 return;
2475 2460
2476 tmp = spell->clone (); 2461 tmp = spell->clone ();
2477 insert_ob_in_ob (tmp, op); 2462 insert_ob_in_ob (tmp, op);
2478 2463
2479 if (special_prayer) 2464 if (special_prayer)
2480 SET_FLAG (tmp, FLAG_STARTEQUIP); 2465 tmp->set_flag (FLAG_STARTEQUIP);
2481 2466
2482 esrv_add_spells (op->contr, tmp); 2467 esrv_add_spells (op->contr, tmp);
2483} 2468}
2484 2469
2485/** 2470/**
2499 { 2484 {
2500 LOG (llevError, "BUG: do_forget_spell(): spell not known\n"); 2485 LOG (llevError, "BUG: do_forget_spell(): spell not known\n");
2501 return; 2486 return;
2502 } 2487 }
2503 2488
2504 op->failmsg (format ("You lose knowledge of %s.", spell)); 2489 op->failmsgf ("You lose knowledge of %s.", spell);
2505 esrv_remove_spell (op->contr, spob); 2490 esrv_remove_spell (op->contr, spob);
2506 spob->destroy (); 2491 spob->destroy ();
2507} 2492}
2508 2493
2509/** 2494/**
2514static void 2499static void
2515apply_spellbook (object *op, object *tmp) 2500apply_spellbook (object *op, object *tmp)
2516{ 2501{
2517 object *skop, *spell, *spell_skill; 2502 object *skop, *spell, *spell_skill;
2518 2503
2519 if (QUERY_FLAG (op, FLAG_BLIND) && !QUERY_FLAG (op, FLAG_WIZ)) 2504 if (op->flag [FLAG_BLIND] && !op->flag [FLAG_WIZ])
2520 { 2505 {
2521 op->failmsg ("You are unable to read while blind."); 2506 op->failmsg ("You are unable to read while blind.");
2522 return; 2507 return;
2523 } 2508 }
2524 2509
2530 { 2515 {
2531 spell = find_archetype_by_object_name (tmp->slaying)->instance (); 2516 spell = find_archetype_by_object_name (tmp->slaying)->instance ();
2532 2517
2533 if (!spell) 2518 if (!spell)
2534 { 2519 {
2535 op->failmsg (format ("The book's formula for %s is incomplete.", &tmp->slaying)); 2520 op->failmsgf ("The book's formula for %s is incomplete.", &tmp->slaying);
2536 return; 2521 return;
2537 } 2522 }
2538 else 2523 else
2539 insert_ob_in_ob (spell, tmp); 2524 insert_ob_in_ob (spell, tmp);
2540 2525
2545 2530
2546 /* need a literacy skill to learn spells. Also, having a literacy level 2531 /* need a literacy skill to learn spells. Also, having a literacy level
2547 * lower than the spell will make learning the spell more difficult */ 2532 * lower than the spell will make learning the spell more difficult */
2548 if (!skop) 2533 if (!skop)
2549 { 2534 {
2550 op->failmsg (format ("You can't read! Your attempt fails. H<You lack the %s skill.>", &tmp->skill)); 2535 op->failmsgf ("You can't read! Your attempt fails. H<You lack the %s skill.>", &tmp->skill);
2551 return; 2536 return;
2552 } 2537 }
2553 2538
2554 spell = tmp->inv; 2539 spell = tmp->inv;
2555 2540
2561 } 2546 }
2562 2547
2563 int learn_level = sqrtf (spell->level) * 1.5f; 2548 int learn_level = sqrtf (spell->level) * 1.5f;
2564 if (skop->level < learn_level) 2549 if (skop->level < learn_level)
2565 { 2550 {
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.>", 2551 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)); 2552 &tmp->skill, learn_level);
2568 return; 2553 return;
2569 } 2554 }
2570 2555
2571 op->statusmsg (format ("The spellbook contains the %s level spell %s.", ordinal (spell->level), &spell->name)); 2556 op->statusmsg (format ("The spellbook contains the %s level spell %s.", ordinal (spell->level), &spell->name));
2572 2557
2573 if (!QUERY_FLAG (tmp, FLAG_IDENTIFIED)) 2558 if (!tmp->flag [FLAG_IDENTIFIED])
2574 identify (tmp); 2559 identify (tmp);
2575 2560
2576 /* I removed the check for special_prayer_mark here - it didn't make 2561 /* 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 2562 * 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 2563 * if the player doesn't know the spell, doesn't make a lot of sense that
2588 { 2573 {
2589 spell_skill = find_skill_by_name (op, spell->skill); 2574 spell_skill = find_skill_by_name (op, spell->skill);
2590 2575
2591 if (!spell_skill) 2576 if (!spell_skill)
2592 { 2577 {
2593 op->failmsg (format ("You lack the %s skill to use this spell.", &spell->skill)); 2578 op->failmsgf ("You lack the %s skill to use this spell.", &spell->skill);
2594 return; 2579 return;
2595 } 2580 }
2596 2581
2597 if (spell_skill->level < spell->level) 2582 if (spell_skill->level < spell->level)
2598 { 2583 {
2599 op->failmsg (format ("You need to be level %d in %s to learn this spell.", spell->level, &spell->skill)); 2584 op->failmsgf ("You need to be level %d in %s to learn this spell.", spell->level, &spell->skill);
2600 return; 2585 return;
2601 } 2586 }
2602 } 2587 }
2603 2588
2604 /* Logic as follows 2589 /* Logic as follows
2611 * 3 -Automatically fail to learn if you read while confused 2596 * 3 -Automatically fail to learn if you read while confused
2612 * 2597 *
2613 * Overall, chances are the same but a player will find having a high 2598 * Overall, chances are the same but a player will find having a high
2614 * literacy rate very useful! -b.t. 2599 * literacy rate very useful! -b.t.
2615 */ 2600 */
2616 if (QUERY_FLAG (op, FLAG_CONFUSED)) 2601 if (op->flag [FLAG_CONFUSED])
2617 { 2602 {
2618 op->failmsg ("In your confused state you flub the wording of the text!"); 2603 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)); 2604 scroll_failure (op, 0 - random_roll (0, spell->level, op, PREFER_LOW), max (spell->stats.sp, spell->stats.grace));
2620 } 2605 }
2621 else if (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || 2606 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]) 2607 (random_roll (0, 100, op, PREFER_LOW) - (5 * skop->level)) < learn_spell[spell->stats.grace ? op->stats.Wis : op->stats.Int])
2623 { 2608 {
2624 op->statusmsg ("You succeed in learning the spell!", NDI_GREEN); 2609 op->statusmsg ("You succeed in learning the spell!", NDI_GREEN);
2625 do_learn_spell (op, spell, 0); 2610 do_learn_spell (op, spell, 0);
2626 2611
2627 /* xp gain to literacy for spell learning */ 2612 /* xp gain to literacy for spell learning */
2628 if (!QUERY_FLAG (tmp, FLAG_STARTEQUIP)) 2613 if (!tmp->flag [FLAG_STARTEQUIP])
2629 change_exp (op, calc_skill_exp (op, tmp, skop), skop->skill, 0); 2614 change_exp (op, calc_skill_exp (op, tmp, skop), skop->skill, 0);
2630 } 2615 }
2631 else 2616 else
2632 { 2617 {
2633 op->contr->play_sound (sound_find ("fumble_spell")); 2618 op->contr->play_sound (sound_find ("fumble_spell"));
2643void 2628void
2644apply_scroll (object *op, object *tmp, int dir) 2629apply_scroll (object *op, object *tmp, int dir)
2645{ 2630{
2646 object *skop; 2631 object *skop;
2647 2632
2648 if (QUERY_FLAG (op, FLAG_BLIND) && !QUERY_FLAG (op, FLAG_WIZ)) 2633 if (op->flag [FLAG_BLIND] && !op->flag [FLAG_WIZ])
2649 { 2634 {
2650 op->failmsg ("You are unable to read while blind."); 2635 op->failmsg ("You are unable to read while blind.");
2651 return; 2636 return;
2652 } 2637 }
2653 2638
2663 int exp_gain = 0; 2648 int exp_gain = 0;
2664 2649
2665 /* hard code literacy - tmp->skill points to where the exp 2650 /* hard code literacy - tmp->skill points to where the exp
2666 * should go for anything killed by the spell. 2651 * should go for anything killed by the spell.
2667 */ 2652 */
2668 skop = find_skill_by_name (op, skill_names[SK_LITERACY]); 2653 skop = find_skill_by_name (op, shstr_literacy);
2669 2654
2670 if (!skop) 2655 if (!skop)
2671 { 2656 {
2672 op->failmsg (format ("You are unable to decipher the strange symbols. H<You lack the %s skill.>", &skill_names[SK_LITERACY])); 2657 op->failmsgf ("You are unable to decipher the strange symbols. H<You lack the literacy skill.>");
2673 return; 2658 return;
2674 } 2659 }
2675 2660
2676 if ((exp_gain = calc_skill_exp (op, tmp, skop))) 2661 if ((exp_gain = calc_skill_exp (op, tmp, skop)))
2677 change_exp (op, exp_gain, skop->skill, 0); 2662 change_exp (op, exp_gain, skop->skill, 0);
2678 } 2663 }
2679 2664
2680 if (!QUERY_FLAG (tmp, FLAG_IDENTIFIED)) 2665 if (!tmp->flag [FLAG_IDENTIFIED])
2681 identify (tmp); 2666 identify (tmp);
2682 2667
2683 op->statusmsg (format ("The scroll of %s turns to dust.", &tmp->inv->name)); 2668 op->statusmsg (format ("The scroll of %s turns to dust.", &tmp->inv->name));
2684 2669
2685 cast_spell (op, tmp, dir, tmp->inv, NULL); 2670 cast_spell (op, tmp, dir, tmp->inv, NULL);
2716 2701
2717 treas->x = op->x; 2702 treas->x = op->x;
2718 treas->y = op->y; 2703 treas->y = op->y;
2719 treas = insert_ob_in_map (treas, op->map, op, INS_BELOW_ORIGINATOR); 2704 treas = insert_ob_in_map (treas, op->map, op, INS_BELOW_ORIGINATOR);
2720 2705
2721 if (treas && (treas->type == RUNE || treas->type == TRAP) && treas->level && QUERY_FLAG (op, FLAG_ALIVE)) 2706 if (treas && (treas->type == RUNE || treas->type == TRAP) && treas->level && op->flag [FLAG_ALIVE])
2722 spring_trap (treas, op); 2707 spring_trap (treas, op);
2723 2708
2724 /* If either player or container was destroyed, no need to do 2709 /* If either player or container was destroyed, no need to do
2725 * further processing. I think this should be enclused with 2710 * further processing. I think this should be enclused with
2726 * spring trap above, as I don't think there is otherwise 2711 * spring trap above, as I don't think there is otherwise
2925 : tmp->type == DRINK 2910 : tmp->type == DRINK
2926 ? sound_find ("eat_drink") 2911 ? sound_find ("eat_drink")
2927 : sound_find ("eat_food") 2912 : sound_find ("eat_food")
2928 ); 2913 );
2929 2914
2930 if (!QUERY_FLAG (tmp, FLAG_CURSED)) 2915 if (!tmp->flag [FLAG_CURSED])
2931 { 2916 {
2932 const char *buf; 2917 const char *buf;
2933 2918
2934 if (!op->is_dragon ()) 2919 if (!op->is_dragon ())
2935 { 2920 {
2955 min_it (op->stats.hp, op->stats.maxhp); 2940 min_it (op->stats.hp, op->stats.maxhp);
2956 min_it (op->stats.food, MAX_FOOD); 2941 min_it (op->stats.food, MAX_FOOD);
2957 } 2942 }
2958 2943
2959 /* special food hack -b.t. */ 2944 /* special food hack -b.t. */
2960 if (tmp->title || QUERY_FLAG (tmp, FLAG_CURSED)) 2945 if (tmp->title || tmp->flag [FLAG_CURSED])
2961 eat_special_food (op, tmp); 2946 eat_special_food (op, tmp);
2962 } 2947 }
2963 } 2948 }
2964 2949
2965 handle_apply_yield (tmp); 2950 handle_apply_yield (tmp);
2971 * Does some sanity checks, then calls improve_armour. 2956 * Does some sanity checks, then calls improve_armour.
2972 */ 2957 */
2973static void 2958static void
2974apply_armour_improver (object *op, object *tmp) 2959apply_armour_improver (object *op, object *tmp)
2975{ 2960{
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)) 2961 if (!op->flag [FLAG_WIZCAST] && (get_map_flags (op->map, 0, op->x, op->y, 0, 0) & P_NO_MAGIC))
2979 { 2962 {
2980 op->failmsg ("Something blocks the magic of the scroll. H<This area prevents magic effects.>"); 2963 op->failmsg ("Something blocks the magic of the scroll. H<This area prevents magic effects.>");
2981 return; 2964 return;
2982 } 2965 }
2983 2966
2984 armor = find_marked_object (op); 2967 object *armor = op->mark ();
2985 2968
2986 if (!armor) 2969 if (!armor)
2987 { 2970 {
2988 op->failmsg ("You need to mark an armor object. Use the right mouse button popup or the mark command to do this."); 2971 op->failmsg ("You need to mark an armor object. Use the right mouse button popup or the mark command to do this.");
2989 return; 2972 return;
2992 if (armor->type != ARMOUR 2975 if (armor->type != ARMOUR
2993 && armor->type != CLOAK 2976 && armor->type != CLOAK
2994 && armor->type != BOOTS && armor->type != GLOVES && armor->type != BRACERS && armor->type != SHIELD && armor->type != HELMET) 2977 && armor->type != BOOTS && armor->type != GLOVES && armor->type != BRACERS && armor->type != SHIELD && armor->type != HELMET)
2995 { 2978 {
2996 op->failmsg ("Your marked item is not armour!\n"); 2979 op->failmsg ("Your marked item is not armour!\n");
2980 return;
2981 }
2982
2983 if (!op->apply (armor, AP_UNAPPLY))
2984 {
2985 op->failmsg ("You are unable to take off your armour to improve it!");
2997 return; 2986 return;
2998 } 2987 }
2999 2988
3000 op->statusmsg ("Applying armour enchantment."); 2989 op->statusmsg ("Applying armour enchantment.");
3001 improve_armour (op, tmp, armor); 2990 improve_armour (op, tmp, armor);
3049 } 3038 }
3050 } 3039 }
3051 3040
3052 if (!lighter) 3041 if (!lighter)
3053 { 3042 {
3054 who->failmsg (format ( 3043 who->failmsgf (
3055 "You can't light up the %s with your bare hands! " 3044 "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.>", 3045 "H<You need a lighter in your inventory, for example a flint and steel.>",
3057 &op->name)); 3046 &op->name
3047 );
3058 return 0; 3048 return 0;
3059 } 3049 }
3060 } 3050 }
3061 3051
3062 // last_eat == 0 means the lighter is not being used up! 3052 // last_eat == 0 means the lighter is not being used up!
3068 who->insert (lighter); 3058 who->insert (lighter);
3069 } 3059 }
3070 else if (lighter->last_eat) 3060 else if (lighter->last_eat)
3071 { 3061 {
3072 /* no charges left in lighter */ 3062 /* no charges left in lighter */
3073 who->failmsg (format ( 3063 who->failmsgf (
3074 "You attempt to light the %s with a used up %s.", 3064 "You attempt to light the %s with a used up %s.",
3075 &op->name, &lighter->name)); 3065 &op->name, &lighter->name
3066 );
3076 return 0; 3067 return 0;
3077 } 3068 }
3078 3069
3079 return lighter; 3070 return lighter;
3080} 3071}
3085 * the selected object to "burn". -b.t. 3076 * the selected object to "burn". -b.t.
3086 */ 3077 */
3087static void 3078static void
3088apply_lighter (object *who, object *lighter) 3079apply_lighter (object *who, object *lighter)
3089{ 3080{
3090 object *item;
3091 int is_player_env = 0; 3081 int is_player_env = 0;
3092 3082
3093 item = find_marked_object (who); 3083 if (object *item = who->mark ())
3094 if (item)
3095 { 3084 {
3096 if (!auto_apply_lighter (who, item, lighter)) 3085 if (!auto_apply_lighter (who, item, lighter))
3097 return; 3086 return;
3098 3087
3099 /* Perhaps we should split what we are trying to light on fire? 3088 /* Perhaps we should split what we are trying to light on fire?
3106 if (item->destroyed () 3095 if (item->destroyed ()
3107 || ((item->type == LAMP || item->type == TORCH) 3096 || ((item->type == LAMP || item->type == TORCH)
3108 && item->glow_radius > 0)) 3097 && item->glow_radius > 0))
3109 who->statusmsg (format ( 3098 who->statusmsg (format (
3110 "You light the %s with the %s.", 3099 "You light the %s with the %s.",
3111 &item->name, &lighter->name)); 3100 &item->name, &lighter->name
3101 ));
3112 else 3102 else
3113 who->failmsg (format ( 3103 who->failmsgf (
3114 "You attempt to light the %s with the %s and fail.", 3104 "You attempt to light the %s with the %s and fail.",
3115 &item->name, &lighter->name)); 3105 &item->name, &lighter->name
3106 );
3116 } 3107 }
3117 else 3108 else
3118 who->failmsg ("You need to mark a lightable object."); 3109 who->failmsg ("You need to mark a lightable object.");
3119} 3110}
3120 3111
3124static void 3115static void
3125player_apply_lamp_cursed_effect (object *who, object *op) 3116player_apply_lamp_cursed_effect (object *who, object *op)
3126{ 3117{
3127 if (op->level) 3118 if (op->level)
3128 { 3119 {
3129 who->failmsg (format ( 3120 who->failmsgf (
3130 "The %s was cursed, it explodes in a big fireball!", 3121 "The %s was cursed, it explodes in a big fireball!",
3131 &op->name)); 3122 &op->name
3123 );
3132 create_exploding_ball_at (who, op->level); 3124 create_exploding_ball_at (who, op->level);
3133 } 3125 }
3134 else 3126 else
3135 { 3127 {
3136 who->failmsg (format ( 3128 who->failmsgf (
3137 "The %s was cursed, it crumbles to dust, at least it didn't explode.!", 3129 "The %s was cursed, it crumbles to dust, at least it didn't explode.!",
3138 &op->name)); 3130 &op->name
3131 );
3139 } 3132 }
3140 3133
3141 op->destroy (); 3134 op->destroy ();
3142} 3135}
3143 3136
3161 return; 3154 return;
3162 3155
3163 if (op->stats.food < 1) 3156 if (op->stats.food < 1)
3164 { 3157 {
3165 if (op->type == LAMP) 3158 if (op->type == LAMP)
3166 who->failmsg (format ( 3159 who->failmsgf (
3167 "The %s is out of fuel! " 3160 "The %s is out of fuel! "
3168 "H<Lamps and similar items need fuel. They cannot be refilled.>", 3161 "H<Lamps and similar items need fuel. They cannot be refilled.>",
3169 &op->name)); 3162 &op->name
3163 );
3170 else 3164 else
3171 who->failmsg (format ( 3165 who->failmsgf (
3172 "The %s is burnt out! " 3166 "The %s is burnt out! "
3173 "H<Torches and similar items burn out and become worthless.>", 3167 "H<Torches and similar items burn out and become worthless.>",
3174 &op->name)); 3168 &op->name
3169 );
3175 return; 3170 return;
3176 } 3171 }
3177 3172
3178 if (op->flag [FLAG_CURSED]) 3173 if (op->flag [FLAG_CURSED])
3179 { 3174 {
3284 * The 'slaying' field for transformer is used as verb for the action. 3279 * The 'slaying' field for transformer is used as verb for the action.
3285 */ 3280 */
3286static void 3281static void
3287apply_item_transformer (object *pl, object *transformer) 3282apply_item_transformer (object *pl, object *transformer)
3288{ 3283{
3289 object *marked;
3290 object *new_item; 3284 object *new_item;
3291 const char *find; 3285 const char *find;
3292 char *separator; 3286 char *separator;
3293 int yield; 3287 int yield;
3294 char got[MAX_BUF]; 3288 char got[MAX_BUF];
3295 int len; 3289 int len;
3296 3290
3297 if (!pl || !transformer) 3291 if (!pl || !transformer)
3298 return; 3292 return;
3299 3293
3300 marked = find_marked_object (pl); 3294 object *marked = pl->mark ();
3301 3295
3302 if (!marked) 3296 if (!marked)
3303 { 3297 {
3304 pl->failmsg (format ("Use the %s with what item?", query_name (transformer))); 3298 pl->failmsgf ("Use the %s with what item?", query_name (transformer));
3305 return; 3299 return;
3306 } 3300 }
3307 3301
3308 if (!marked->slaying) 3302 if (!marked->slaying)
3309 { 3303 {
3310 pl->failmsg (format ("You can't use the %s with your %s!", query_name (transformer), query_name (marked))); 3304 pl->failmsgf ("You can't use the %s with your %s!", query_name (transformer), query_name (marked));
3311 return; 3305 return;
3312 } 3306 }
3313 3307
3314 /* check whether they are compatible or not */ 3308 /* check whether they are compatible or not */
3315 find = strstr (&marked->slaying, transformer->arch->archname); 3309 find = strstr (&marked->slaying, transformer->arch->archname);
3316 if (!find || (*(find + strlen (transformer->arch->archname)) != ':')) 3310 if (!find || (*(find + strlen (transformer->arch->archname)) != ':'))
3317 { 3311 {
3318 pl->failmsg (format ("You can't use the %s with your %s!", query_name (transformer), query_name (marked))); 3312 pl->failmsgf ("You can't use the %s with your %s!", query_name (transformer), query_name (marked));
3319 return; 3313 return;
3320 } 3314 }
3321 3315
3322 find += strlen (transformer->arch->archname) + 1; 3316 find += strlen (transformer->arch->archname) + 1;
3323 /* Item can be used, now find how many and what it yields */ 3317 /* Item can be used, now find how many and what it yields */
3353 3347
3354 /* Now create new item, remove used ones when required. */ 3348 /* Now create new item, remove used ones when required. */
3355 new_item = get_archetype (got); 3349 new_item = get_archetype (got);
3356 if (!new_item) 3350 if (!new_item)
3357 { 3351 {
3358 pl->failmsg (format ("This %s is strange, better to not use it.", query_base_name (marked, 0))); 3352 pl->failmsgf ("This %s is strange, better to not use it.", query_base_name (marked, 0));
3359 return; 3353 return;
3360 } 3354 }
3361 3355
3362 new_item->nrof = yield; 3356 new_item->nrof = yield;
3363 3357
3403 return 0; /* monsters just skip unpaid items */ 3397 return 0; /* monsters just skip unpaid items */
3404 } 3398 }
3405 3399
3406 if (INVOKE_OBJECT (APPLY, op, ARG_OBJECT (who))) 3400 if (INVOKE_OBJECT (APPLY, op, ARG_OBJECT (who)))
3407 return RESULT_INT (0); 3401 return RESULT_INT (0);
3408 else if (may_attempt_inv [op->type]) 3402 else if (apply_types_inv_only [op->type])
3409 { 3403 {
3410 // special item, using slot system, needs to be in inv 3404 // special item, using slot system, needs to be in inv
3411 if (op->env == who) 3405 if (op->env == who)
3412 return apply_special (who, op, aflag); 3406 return apply_special (who, op, aflag);
3413 3407
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))); 3408 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 } 3409 }
3416 else if (!who->contr && may_attempt_player [op->type]) 3410 else if (!who->contr && apply_types_player_only [op->type])
3417 return 0; // monsters shouldn't try to apply player-only stuff 3411 return 0; // monsters shouldn't try to apply player-only stuff
3418 else if (may_attempt [op->type]) 3412 else if (apply_types [op->type])
3419 { 3413 {
3420 // ordinary stuff, may be on the floor 3414 // ordinary stuff, may be on the floor
3421 switch (op->type) 3415 switch (op->type)
3422 { 3416 {
3423 case T_HANDLE: 3417 case T_HANDLE:
3440 3434
3441 break; 3435 break;
3442 3436
3443 case EXIT: 3437 case EXIT:
3444 if (!EXIT_PATH (op)) 3438 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))); 3439 who->failmsgf ("The %s is closed. H<And will stay closed, until somebody fires up the map editor and adds it.>", query_name (op));
3446 else 3440 else
3447 { 3441 {
3448 /* Don't display messages for random maps. */ 3442 /* Don't display messages for random maps. */
3449 if (op->msg && EXIT_PATH (op) != shstr_random_map_exit) 3443 if (op->msg && EXIT_PATH (op) != shstr_random_map_exit)
3450 who->statusmsg (op->msg, NDI_NAVY); 3444 who->statusmsg (op->msg, NDI_NAVY);
3578 * item in the container. Otherwise, use the map. 3572 * item in the container. Otherwise, use the map.
3579 */ 3573 */
3580 3574
3581 // first try to apply "applyables" 3575 // first try to apply "applyables"
3582 for (object *tmp = top; tmp; tmp = tmp->below) 3576 for (object *tmp = top; tmp; tmp = tmp->below)
3583 if (!tmp->invisible && may_attempt [tmp->type]) 3577 if (!tmp->invisible && apply_types [tmp->type])
3584 { 3578 {
3585 // If it is visible, player can apply it. 3579 // If it is visible, player can apply it.
3586 pl->apply (tmp); 3580 pl->apply (tmp);
3587 return; 3581 return;
3588 } 3582 }
3601 case ALTAR: 3595 case ALTAR:
3602 case IDENTIFY_ALTAR: 3596 case IDENTIFY_ALTAR:
3603 case TRIGGER_ALTAR: 3597 case TRIGGER_ALTAR:
3604 case CONVERTER: 3598 case CONVERTER:
3605 //case TRIGGER_PEDESTAL: 3599 //case TRIGGER_PEDESTAL:
3606 pl->failmsg (format ( 3600 pl->failmsgf (
3607 "You see no obvious mechanism on the %s." 3601 "You see no obvious mechanism on the %s."
3608 "H<You have to drop one or more specific items here.>", 3602 "H<You have to drop one or more specific items here.>",
3609 query_short_name (top) 3603 query_short_name (top)
3610 )); 3604 );
3611 break; 3605 break;
3612 3606
3613 case BUTTON: 3607 case BUTTON:
3614 case TRIGGER_BUTTON: 3608 case TRIGGER_BUTTON:
3615 pl->failmsg (format ( 3609 pl->failmsgf (
3616 "The %s looks as if you could activate it with somehting heavy. " 3610 "The %s looks as if you could activate it with somehting heavy. "
3617 "H<You must put enough items here to activate it.>", 3611 "H<You must put enough items here to activate it.>",
3618 query_short_name (top) 3612 query_short_name (top)
3619 )); 3613 );
3620 break; 3614 break;
3621 3615
3622 default: 3616 default:
3623 examine (pl, top); 3617 examine (pl, top);
3624 break; 3618 break;
3742auto_apply (object *op) 3736auto_apply (object *op)
3743{ 3737{
3744 object *tmp = NULL, *tmp2; 3738 object *tmp = NULL, *tmp2;
3745 int i; 3739 int i;
3746 3740
3747 CLEAR_FLAG (op, FLAG_AUTO_APPLY); 3741 op->clr_flag (FLAG_AUTO_APPLY);
3748 3742
3749 switch (op->type) 3743 switch (op->type)
3750 { 3744 {
3751 case SHOP_FLOOR: 3745 case SHOP_FLOOR:
3752 if (!op->has_random_items ()) 3746 if (!op->has_random_items ())
3762 == NULL && --i); 3756 == NULL && --i);
3763 3757
3764 if (tmp == NULL) 3758 if (tmp == NULL)
3765 return 0; 3759 return 0;
3766 3760
3767 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED)) 3761 if (tmp->flag [FLAG_CURSED] || tmp->flag [FLAG_DAMNED])
3768 { 3762 {
3769 tmp->destroy (); 3763 tmp->destroy ();
3770 tmp = NULL; 3764 tmp = NULL;
3771 } 3765 }
3772 } 3766 }
3773 while (!tmp); 3767 while (!tmp);
3774 3768
3775 tmp->x = op->x; 3769 tmp->x = op->x;
3776 tmp->y = op->y; 3770 tmp->y = op->y;
3777 SET_FLAG (tmp, FLAG_UNPAID); 3771 tmp->set_flag (FLAG_UNPAID);
3778 insert_ob_in_map (tmp, op->map, NULL, 0); 3772 insert_ob_in_map (tmp, op->map, NULL, 0);
3779 identify (tmp); 3773 identify (tmp);
3780 break; 3774 break;
3781 3775
3782 case TREASURE: 3776 case TREASURE:
3783 if (QUERY_FLAG (op, FLAG_IS_A_TEMPLATE)) 3777 if (op->flag [FLAG_IS_A_TEMPLATE])
3784 return 0; 3778 return 0;
3785 3779
3786 while (op->stats.hp-- > 0) 3780 while (op->stats.hp-- > 0)
3787 create_treasure (op->randomitems, op, op->map ? GT_ENVIRONMENT : 0, 3781 create_treasure (op->randomitems, op, op->map ? GT_ENVIRONMENT : 0,
3788 op->stats.exp ? (int) op->stats.exp : op->map == NULL ? 14 : op->map->difficulty, 0); 3782 op->stats.exp ? (int) op->stats.exp : op->map == NULL ? 14 : op->map->difficulty, 0);
3826 3820
3827 for (invtmp = tmp->inv; invtmp; invtmp = invnext) 3821 for (invtmp = tmp->inv; invtmp; invtmp = invnext)
3828 { 3822 {
3829 invnext = invtmp->below; 3823 invnext = invtmp->below;
3830 3824
3831 if (QUERY_FLAG (invtmp, FLAG_AUTO_APPLY)) 3825 if (invtmp->flag [FLAG_AUTO_APPLY])
3832 auto_apply (invtmp); 3826 auto_apply (invtmp);
3833 else if (invtmp->type == TREASURE && invtmp->has_random_items ()) 3827 else if (invtmp->type == TREASURE && invtmp->has_random_items ())
3834 { 3828 {
3835 while (invtmp->stats.hp-- > 0) 3829 while (invtmp->stats.hp-- > 0)
3836 create_treasure (invtmp->randomitems, invtmp, 0, difficulty, 0); 3830 create_treasure (invtmp->randomitems, invtmp, 0, difficulty, 0);
3861 if (tmp->type == WAND || tmp->type == ROD || tmp->type == SCROLL 3855 if (tmp->type == WAND || tmp->type == ROD || tmp->type == SCROLL
3862 || tmp->type == HORN || tmp->type == FIREWALL || tmp->type == POTION || tmp->type == ALTAR || tmp->type == SPELLBOOK) 3856 || tmp->type == HORN || tmp->type == FIREWALL || tmp->type == POTION || tmp->type == ALTAR || tmp->type == SPELLBOOK)
3863 tmp->randomitems = NULL; 3857 tmp->randomitems = NULL;
3864 } 3858 }
3865 3859
3866 if (QUERY_FLAG (tmp, FLAG_AUTO_APPLY)) 3860 if (tmp->flag [FLAG_AUTO_APPLY])
3867 auto_apply (tmp); 3861 auto_apply (tmp);
3868 else if ((tmp->type == TREASURE || (tmp->type == CONTAINER)) && tmp->has_random_items ()) 3862 else if ((tmp->type == TREASURE || (tmp->type == CONTAINER)) && tmp->has_random_items ())
3869 { 3863 {
3870 while ((tmp->stats.hp--) > 0) 3864 while ((tmp->stats.hp--) > 0)
3871 create_treasure (tmp->randomitems, tmp, 0, difficulty, 0); 3865 create_treasure (tmp->randomitems, tmp, 0, difficulty, 0);
3873 } 3867 }
3874 else if (tmp->type == TIMED_GATE) 3868 else if (tmp->type == TIMED_GATE)
3875 { 3869 {
3876 object *head = tmp->head != NULL ? tmp->head : tmp; 3870 object *head = tmp->head != NULL ? tmp->head : tmp;
3877 3871
3878 if (QUERY_FLAG (head, FLAG_IS_LINKED)) 3872 if (head->flag [FLAG_IS_LINKED])
3879 tmp->set_speed (0); 3873 tmp->set_speed (0);
3880 } 3874 }
3881 /* This function can be called everytime a map is loaded, even when 3875 /* This function can be called everytime a map is loaded, even when
3882 * swapping back in. As such, we don't want to create the treasure 3876 * swapping back in. As such, we don't want to create the treasure
3883 * over and ove again, so after we generate the treasure, blank out 3877 * over and ove again, so after we generate the treasure, blank out
3972 } 3966 }
3973 3967
3974 /* check for hp, sp change */ 3968 /* check for hp, sp change */
3975 if (food->stats.hp != 0) 3969 if (food->stats.hp != 0)
3976 { 3970 {
3977 if (QUERY_FLAG (food, FLAG_CURSED)) 3971 if (food->flag [FLAG_CURSED])
3978 { 3972 {
3979 who->contr->killer = food; 3973 who->contr->killer = food;
3980 hit_player (who, food->stats.hp, food, AT_POISON, 1); 3974 hit_player (who, food->stats.hp, food, AT_POISON, 1);
3981 who->failmsg ("Eck!...that was poisonous!"); 3975 who->failmsg ("Eck!...that was poisonous!");
3982 } 3976 }
3991 } 3985 }
3992 } 3986 }
3993 3987
3994 if (food->stats.sp != 0) 3988 if (food->stats.sp != 0)
3995 { 3989 {
3996 if (QUERY_FLAG (food, FLAG_CURSED)) 3990 if (food->flag [FLAG_CURSED])
3997 { 3991 {
3998 who->failmsg ("You are drained of mana!"); 3992 who->failmsg ("You are drained of mana!");
3999 who->stats.sp -= food->stats.sp; 3993 who->stats.sp -= food->stats.sp;
4000 if (who->stats.sp < 0) 3994 if (who->stats.sp < 0)
4001 who->stats.sp = 0; 3995 who->stats.sp = 0;
4084 pl->animation_id = change->animation_id; 4078 pl->animation_id = change->animation_id;
4085 pl->flag [FLAG_ANIMATE] = change->flag [FLAG_ANIMATE]; 4079 pl->flag [FLAG_ANIMATE] = change->flag [FLAG_ANIMATE];
4086 } 4080 }
4087 4081
4088 /* check the special case of can't use weapons */ 4082 /* check the special case of can't use weapons */
4089 /*if(QUERY_FLAG(change,FLAG_USE_WEAPON)) CLEAR_FLAG(pl,FLAG_USE_WEAPON); */ 4083 /*if(change->flag [FLAG_USE_WEAPON]) pl->clr_flag (FLAG_USE_WEAPON); */
4090 if (change->name == shstr_monk) 4084 if (change->name == shstr_monk)
4091 CLEAR_FLAG (pl, FLAG_USE_WEAPON); 4085 pl->clr_flag (FLAG_USE_WEAPON);
4092 4086
4093 break; 4087 break;
4094 } 4088 }
4095 } 4089 }
4096} 4090}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines