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.76 by root, Mon Apr 30 04:25:30 2007 UTC vs.
Revision 1.121 by root, Tue Jul 31 19:23:31 2007 UTC

1/* 1/*
2 * CrossFire, A Multiplayer game for X-windows 2 * This file is part of Crossfire TRT, the Roguelike Realtime MORPG.
3 * 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team 4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team
5 * Copyright (C) 2001 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * Crossfire TRT is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version. 11 * (at your 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 GNU General Public License 18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * 20 *
22 * The authors can be reached via e-mail to <crossfire@schmorp.de> 21 * The authors can be reached via e-mail to <crossfire@schmorp.de>
23 */ 22 */
23
24#include <cmath>
24 25
25#include <global.h> 26#include <global.h>
26#include <living.h> 27#include <living.h>
27#include <spells.h> 28#include <spells.h>
28#include <skills.h> 29#include <skills.h>
30 31
31#include <sproto.h> 32#include <sproto.h>
32 33
33/* Want this regardless of rplay. */ 34/* Want this regardless of rplay. */
34#include <sounds.h> 35#include <sounds.h>
35
36/* need math lib for double-precision and pow() in dragon_eat_flesh() */
37#include <math.h>
38 36
39/** 37/**
40 * Check if op should abort moving victim because of it's race or slaying. 38 * Check if op should abort moving victim because of it's race or slaying.
41 * Returns 1 if it should abort, returns 0 if it should continue. 39 * Returns 1 if it should abort, returns 0 if it should continue.
42 */ 40 */
70 68
71 /* If the director has race set, only affect objects with a arch, 69 /* If the director has race set, only affect objects with a arch,
72 * name or race that matches. 70 * name or race that matches.
73 */ 71 */
74 if ((op->race) && 72 if ((op->race) &&
75 ((!(victim->arch && arch_flag && victim->arch->name) || op->race != victim->arch->name)) && 73 ((!(victim->arch && arch_flag && victim->arch->archname) || op->race != victim->arch->archname)) &&
76 ((!(victim->name && name_flag) || op->race != victim->name)) && 74 ((!(victim->name && name_flag) || op->race != victim->name)) &&
77 ((!(victim->race && race_flag) || op->race != victim->race))) 75 ((!(victim->race && race_flag) || op->race != victim->race)))
78 return 1; 76 return 1;
79 77
80 /* If the director has slaying set, only affect objects where none 78 /* If the director has slaying set, only affect objects where none
81 * of arch, name, or race match. 79 * of arch, name, or race match.
82 */ 80 */
83 if ((op->slaying) && (((victim->arch && arch_flag && victim->arch->name && op->slaying == victim->arch->name))) || 81 if ((op->slaying) && (((victim->arch && arch_flag && victim->arch->archname && op->slaying == victim->arch->archname))) ||
84 ((victim->name && name_flag && op->slaying == victim->name)) || 82 ((victim->name && name_flag && op->slaying == victim->name)) ||
85 ((victim->race && race_flag && op->slaying == victim->race))) 83 ((victim->race && race_flag && op->slaying == victim->race)))
86 return 1; 84 return 1;
87 85
88 return 0; 86 return 0;
159 157
160/** 158/**
161 * This checks whether the object has a "on_use_yield" field, and if so generated and drops 159 * This checks whether the object has a "on_use_yield" field, and if so generated and drops
162 * matching item. 160 * matching item.
163 **/ 161 **/
164static void 162void
165handle_apply_yield (object *tmp) 163handle_apply_yield (object *tmp)
166{ 164{
167 const char *yield; 165 const char *yield;
168 166
169 yield = get_ob_key_value (tmp, "on_use_yield"); 167 yield = get_ob_key_value (tmp, "on_use_yield");
233 depl = present_arch_in_ob (at, op); 231 depl = present_arch_in_ob (at, op);
234 232
235 if (depl) 233 if (depl)
236 { 234 {
237 for (i = 0; i < NUM_STATS; i++) 235 for (i = 0; i < NUM_STATS; i++)
238 if (get_attr_value (&depl->stats, i)) 236 if (depl->stats.stat (i))
239 new_draw_info (NDI_UNIQUE, 0, op, restore_msg[i]); 237 new_draw_info (NDI_UNIQUE, 0, op, restore_msg[i]);
240 238
241 depl->destroy (); 239 depl->destroy ();
242 op->update_stats (); 240 op->update_stats ();
243 } 241 }
375 force->stats.food *= 10; 373 force->stats.food *= 10;
376 for (i = 0; i < NROFATTACKS; i++) 374 for (i = 0; i < NROFATTACKS; i++)
377 if (force->resist[i] > 0) 375 if (force->resist[i] > 0)
378 force->resist[i] = -force->resist[i]; /* prot => vuln */ 376 force->resist[i] = -force->resist[i]; /* prot => vuln */
379 } 377 }
378
380 force->speed_left = -1; 379 force->speed_left = -1;
381 force = insert_ob_in_ob (force, op); 380 force = insert_ob_in_ob (force, op);
382 CLEAR_FLAG (tmp, FLAG_APPLIED); 381 CLEAR_FLAG (tmp, FLAG_APPLIED);
383 SET_FLAG (force, FLAG_APPLIED); 382 SET_FLAG (force, FLAG_APPLIED);
384 change_abil (op, force); 383 change_abil (op, force);
425 return 0; 424 return 0;
426 425
427 op = op->below; 426 op = op->below;
428 while (op != NULL) 427 while (op != NULL)
429 { 428 {
430 if (strcmp (op->arch->name, item) == 0) 429 if (strcmp (op->arch->archname, item) == 0)
431 { 430 {
432 if (!QUERY_FLAG (op, FLAG_CURSED) && !QUERY_FLAG (op, FLAG_DAMNED) 431 if (!QUERY_FLAG (op, FLAG_CURSED) && !QUERY_FLAG (op, FLAG_DAMNED)
433 /* Loophole bug? -FD- */ && !QUERY_FLAG (op, FLAG_UNPAID)) 432 /* Loophole bug? -FD- */ && !QUERY_FLAG (op, FLAG_UNPAID))
434 { 433 {
435 if (op->nrof == 0) /* this is necessary for artifact sacrifices --FD-- */ 434 if (op->nrof == 0) /* this is necessary for artifact sacrifices --FD-- */
459 prev = op; 458 prev = op;
460 op = op->below; 459 op = op->below;
461 460
462 while (op != NULL) 461 while (op != NULL)
463 { 462 {
464 if (strcmp (op->arch->name, item) == 0) 463 if (strcmp (op->arch->archname, item) == 0)
465 { 464 {
466 if (op->nrof >= nrof) 465 if (op->nrof >= nrof)
467 { 466 {
468 decrease_ob_nr (op, nrof); 467 decrease_ob_nr (op, nrof);
469 return; 468 return;
576 op->update_stats (); 575 op->update_stats ();
577 return 1; 576 return 1;
578} 577}
579 578
580/* Types of improvements, hidden in the sp field. */ 579/* Types of improvements, hidden in the sp field. */
581#define IMPROVE_PREPARE 1 580#define IMPROVE_PREPARE 1
582#define IMPROVE_DAMAGE 2 581#define IMPROVE_DAMAGE 2
583#define IMPROVE_WEIGHT 3 582#define IMPROVE_WEIGHT 3
584#define IMPROVE_ENCHANT 4 583#define IMPROVE_ENCHANT 4
585#define IMPROVE_STR 5 584#define IMPROVE_STR 5
586#define IMPROVE_DEX 6 585#define IMPROVE_DEX 6
587#define IMPROVE_CON 7 586#define IMPROVE_CON 7
588#define IMPROVE_WIS 8 587#define IMPROVE_WIS 8
589#define IMPROVE_CHA 9 588#define IMPROVE_CHA 9
590#define IMPROVE_INT 10 589#define IMPROVE_INT 10
591#define IMPROVE_POW 11 590#define IMPROVE_POW 11
592
593 591
594/** 592/**
595 * This does the prepare weapon scroll. 593 * This does the prepare weapon scroll.
596 * Checks for sacrifice, and so on. 594 * Checks for sacrifice, and so on.
597 */ 595 */
598
599int 596int
600prepare_weapon (object *op, object *improver, object *weapon) 597prepare_weapon (object *op, object *improver, object *weapon)
601{ 598{
602 int sacrifice_count, i; 599 int sacrifice_count, i;
603 char buf[MAX_BUF]; 600 char buf[MAX_BUF];
605 if (weapon->level != 0) 602 if (weapon->level != 0)
606 { 603 {
607 new_draw_info (NDI_UNIQUE, 0, op, "Weapon already prepared."); 604 new_draw_info (NDI_UNIQUE, 0, op, "Weapon already prepared.");
608 return 0; 605 return 0;
609 } 606 }
607
610 for (i = 0; i < NROFATTACKS; i++) 608 for (i = 0; i < NROFATTACKS; i++)
611 if (weapon->resist[i]) 609 if (weapon->resist[i])
612 break; 610 break;
613 611
614 /* If we break out, i will be less than nrofattacks, preventing 612 /* If we break out, i will be less than nrofattacks, preventing
620 weapon->stats.ac) /* AC - only taifu's I think */ 618 weapon->stats.ac) /* AC - only taifu's I think */
621 { 619 {
622 new_draw_info (NDI_UNIQUE, 0, op, "Cannot prepare magic weapons."); 620 new_draw_info (NDI_UNIQUE, 0, op, "Cannot prepare magic weapons.");
623 return 0; 621 return 0;
624 } 622 }
623
625 sacrifice_count = check_sacrifice (op, improver); 624 sacrifice_count = check_sacrifice (op, improver);
626 if (sacrifice_count <= 0) 625 if (sacrifice_count <= 0)
627 return 0; 626 return 0;
627
628 weapon->level = isqrt (sacrifice_count); 628 weapon->level = isqrt (sacrifice_count);
629 new_draw_info (NDI_UNIQUE, 0, op, "Your sacrifice was accepted."); 629 new_draw_info (NDI_UNIQUE, 0, op, "Your sacrifice was accepted.");
630 eat_item (op, improver->slaying, sacrifice_count); 630 eat_item (op, improver->slaying, sacrifice_count);
631 631
632 new_draw_info_format (NDI_UNIQUE, 0, op, "Your *%s may be improved %d times.", &weapon->name, weapon->level); 632 new_draw_info_format (NDI_UNIQUE, 0, op, "Your *%s may be improved %d times.", &weapon->name, weapon->level);
765{ 765{
766 object *otmp; 766 object *otmp;
767 767
768 if (op->type != PLAYER) 768 if (op->type != PLAYER)
769 return 0; 769 return 0;
770
770 if (!QUERY_FLAG (op, FLAG_WIZCAST) && (get_map_flags (op->map, NULL, op->x, op->y, NULL, NULL) & P_NO_MAGIC)) 771 if (!QUERY_FLAG (op, FLAG_WIZCAST) && (get_map_flags (op->map, NULL, op->x, op->y, NULL, NULL) & P_NO_MAGIC))
771 { 772 {
772 new_draw_info (NDI_UNIQUE, 0, op, "Something blocks the magic of the scroll."); 773 new_draw_info (NDI_UNIQUE, 0, op, "Something blocks the magic of the scroll.");
773 return 0; 774 return 0;
774 } 775 }
776
775 otmp = find_marked_object (op); 777 otmp = find_marked_object (op);
776 if (!otmp) 778 if (!otmp)
777 { 779 {
778 new_draw_info (NDI_UNIQUE, 0, op, "You need to mark a weapon object."); 780 new_draw_info (NDI_UNIQUE, 0, op, "You need to mark a weapon object.");
779 return 0; 781 return 0;
780 } 782 }
783
781 if (otmp->type != WEAPON && otmp->type != BOW) 784 if (otmp->type != WEAPON && otmp->type != BOW)
782 { 785 {
783 new_draw_info (NDI_UNIQUE, 0, op, "Marked item is not a weapon or bow"); 786 new_draw_info (NDI_UNIQUE, 0, op, "Marked item is not a weapon or bow");
784 return 0; 787 return 0;
785 } 788 }
789
786 new_draw_info (NDI_UNIQUE, 0, op, "Applied weapon builder."); 790 new_draw_info (NDI_UNIQUE, 0, op, "Applied weapon builder.");
787 improve_weapon (op, tmp, otmp); 791 improve_weapon (op, tmp, otmp);
788 esrv_send_item (op, otmp); 792 esrv_send_item (op, otmp);
789 return 1; 793 return 1;
790} 794}
851 { 855 {
852 base = base - (base * settings.armor_speed_improvement) / 100; 856 base = base - (base * settings.armor_speed_improvement) / 100;
853 pow++; 857 pow++;
854 } 858 }
855 859
856 ARMOUR_SPEED (armour) = (ARMOUR_SPEED (&armour->arch->clone) * base) / 100; 860 ARMOUR_SPEED (armour) = (ARMOUR_SPEED (armour->arch) * base) / 100;
857 } 861 }
858 else 862 else
859 ARMOUR_SPEED (armour) = (ARMOUR_SPEED (&armour->arch->clone) * (100 + armour->magic * settings.armor_speed_improvement)) / 100; 863 ARMOUR_SPEED (armour) = (ARMOUR_SPEED (armour->arch) * (100 + armour->magic * settings.armor_speed_improvement)) / 100;
860 864
861 if (!settings.armor_weight_linear) 865 if (!settings.armor_weight_linear)
862 { 866 {
863 int base = 100; 867 int base = 100;
864 int pow = 0; 868 int pow = 0;
867 { 871 {
868 base = base - (base * settings.armor_weight_reduction) / 100; 872 base = base - (base * settings.armor_weight_reduction) / 100;
869 pow++; 873 pow++;
870 } 874 }
871 875
872 armour->weight = (armour->arch->clone.weight * base) / 100; 876 armour->weight = (armour->arch->weight * base) / 100;
873 } 877 }
874 else 878 else
875 armour->weight = (armour->arch->clone.weight * (100 - armour->magic * settings.armor_weight_reduction)) / 100; 879 armour->weight = (armour->arch->weight * (100 - armour->magic * settings.armor_weight_reduction)) / 100;
876 880
877 if (armour->weight <= 0) 881 if (armour->weight <= 0)
878 { 882 {
879 LOG (llevInfo, "Warning: enchanted armours can have negative weight\n."); 883 LOG (llevInfo, "Warning: enchanted armours can have negative weight\n.");
880 armour->weight = 1; 884 armour->weight = 1;
881 } 885 }
882 886
883 armour->item_power = get_power_from_ench (armour->arch->clone.item_power + armour->magic); 887 armour->item_power = get_power_from_ench (armour->arch->item_power + armour->magic);
884 888
885 if (op->type == PLAYER) 889 if (op->type == PLAYER)
886 { 890 {
887 esrv_send_item (op, armour); 891 esrv_send_item (op, armour);
888 if (QUERY_FLAG (armour, FLAG_APPLIED)) 892 if (QUERY_FLAG (armour, FLAG_APPLIED))
894 insert_ob_in_ob (tmp, op); 898 insert_ob_in_ob (tmp, op);
895 esrv_send_item (op, tmp); 899 esrv_send_item (op, tmp);
896 } 900 }
897 return 1; 901 return 1;
898} 902}
899
900 903
901/* 904/*
902 * convert_item() returns 1 if anything was converted, 0 if the item was not 905 * convert_item() returns 1 if anything was converted, 0 if the item was not
903 * what the converter wants, -1 if the converter is broken. 906 * what the converter wants, -1 if the converter is broken.
904 */ 907 */
920 923
921 /* We make some assumptions - we assume if it takes money as it type, 924 /* We make some assumptions - we assume if it takes money as it type,
922 * it wants some amount. We don't make change (ie, if something costs 925 * it wants some amount. We don't make change (ie, if something costs
923 * 3 gp and player drops a platinum, tough luck) 926 * 3 gp and player drops a platinum, tough luck)
924 */ 927 */
925 if (!strcmp (CONV_FROM (converter), "money")) 928 if (CONV_FROM (converter) == shstr_money)
926 { 929 {
927 int cost;
928
929 if (item->type != MONEY) 930 if (item->type != MONEY)
930 return 0; 931 return 0;
931 932
932 nr = (item->nrof * item->value) / CONV_NEED (converter); 933 nr = (item->nrof * item->value) / CONV_NEED (converter);
933 if (!nr) 934 if (!nr)
934 return 0; 935 return 0;
936
937 converter->play_sound (sound_find ("shop_buy"));
938
935 cost = nr * CONV_NEED (converter) / item->value; 939 int cost = nr * CONV_NEED (converter) / item->value;
936 /* take into account rounding errors */ 940 /* take into account rounding errors */
937 if (nr * CONV_NEED (converter) % item->value) 941 if (nr * CONV_NEED (converter) % item->value)
938 cost++; 942 cost++;
943
939 decrease_ob_nr (item, cost); 944 decrease_ob_nr (item, cost);
940 945
941 price_in = cost * item->value; 946 price_in = cost * item->value;
942 } 947 }
943 else 948 else
944 { 949 {
945 if (item->type == PLAYER || CONV_FROM (converter) != item->arch->name || 950 if (item->type == PLAYER || CONV_FROM (converter) != item->arch->archname ||
946 (CONV_NEED (converter) && CONV_NEED (converter) > (uint16) item->nrof)) 951 (CONV_NEED (converter) && CONV_NEED (converter) > (uint16) item->nrof))
947 return 0; 952 return 0;
953
954 converter->play_sound (sound_find ("convert_item"));
948 955
949 if (CONV_NEED (converter)) 956 if (CONV_NEED (converter))
950 { 957 {
951 nr = item->nrof / CONV_NEED (converter); 958 nr = item->nrof / CONV_NEED (converter);
952 decrease_ob_nr (item, nr * CONV_NEED (converter)); 959 decrease_ob_nr (item, nr * CONV_NEED (converter));
957 price_in = item->value; 964 price_in = item->value;
958 item->destroy (); 965 item->destroy ();
959 } 966 }
960 } 967 }
961 968
962 if (converter->inv != NULL) 969 if (converter->inv)
963 { 970 {
964 object *ob; 971 object *ob;
965 int i; 972 int i;
966 object *ob_to_copy; 973 object *ob_to_copy;
967 974
968 /* select random object from inventory to copy */ 975 /* select random object from inventory to copy */
969 ob_to_copy = converter->inv; 976 ob_to_copy = converter->inv;
970 for (ob = converter->inv->below, i = 1; ob != NULL; ob = ob->below, i++) 977 for (ob = converter->inv->below, i = 1; ob; ob = ob->below, i++)
971 {
972 if (rndm (0, i) == 0) 978 if (rndm (0, i) == 0)
973 {
974 ob_to_copy = ob; 979 ob_to_copy = ob;
975 } 980
976 }
977 item = object_create_clone (ob_to_copy); 981 item = object_create_clone (ob_to_copy);
978 CLEAR_FLAG (item, FLAG_IS_A_TEMPLATE); 982 CLEAR_FLAG (item, FLAG_IS_A_TEMPLATE);
979 unflag_inv (item, FLAG_IS_A_TEMPLATE); 983 unflag_inv (item, FLAG_IS_A_TEMPLATE);
980 } 984 }
981 else 985 else
991 fix_generated_item (item, converter, 0, 0, GT_MINIMAL); 995 fix_generated_item (item, converter, 0, 0, GT_MINIMAL);
992 } 996 }
993 997
994 if (CONV_NR (converter)) 998 if (CONV_NR (converter))
995 item->nrof = CONV_NR (converter); 999 item->nrof = CONV_NR (converter);
1000
996 if (nr) 1001 if (nr)
997 item->nrof *= nr; 1002 item->nrof *= nr;
1003
998 if (is_in_shop (converter)) 1004 if (is_in_shop (converter))
999 SET_FLAG (item, FLAG_UNPAID); 1005 SET_FLAG (item, FLAG_UNPAID);
1000 else if (price_in < item->nrof * item->value) 1006 else if (price_in < item->nrof * item->value)
1001 { 1007 {
1002 LOG (llevDebug, "converter output price higher than input: %s at %s (%d, %d) in value %d, out value %d for %s\n", 1008 LOG (llevDebug, "converter output price higher than input: %s at %s (%d, %d) in value %d, out value %d for %s\n",
1003 &converter->name, &converter->map->path, converter->x, converter->y, price_in, item->nrof * item->value, &item->name); 1009 &converter->name, &converter->map->path, converter->x, converter->y, price_in, item->nrof * item->value, &item->name);
1004
1005 /** 1010 /**
1006 * elmex: we are going to let the game continue, as the mapcreator 1011 * elmex: we are going to let the game continue, as the mapcreator
1007 * propably had something in mind when doing this 1012 * hopefully had something in mind when doing this.
1008 */ 1013 */
1009 } 1014 }
1015
1016 SET_FLAG (item, FLAG_IDENTIFIED);
1010 insert_ob_in_map_at (item, converter->map, converter, 0, converter->x, converter->y); 1017 insert_ob_in_map_at (item, converter->map, converter, 0, converter->x, converter->y);
1011 return 1; 1018 return 1;
1012} 1019}
1013 1020
1014/** 1021/**
1135 double opinion; 1142 double opinion;
1136 object *tmp, *next; 1143 object *tmp, *next;
1137 1144
1138 SET_FLAG (op, FLAG_NO_APPLY); /* prevent loops */ 1145 SET_FLAG (op, FLAG_NO_APPLY); /* prevent loops */
1139 1146
1147 bool has_unpaid = false;
1148
1149 // quite inefficient to do this here twice, but the api doesn'T lend itself to
1150 // a quick and small change :(
1151 for (object::depth_iterator item = op->begin (); item != op->end (); ++item)
1152 if (item->flag [FLAG_UNPAID])
1153 {
1154 has_unpaid = true;
1155 break;
1156 }
1157
1140 if (op->type != PLAYER) 1158 if (op->type != PLAYER)
1141 { 1159 {
1142 /* Remove all the unpaid objects that may be carried here. 1160 /* Remove all the unpaid objects that may be carried here.
1143 * This could be pets or monsters that are somehow in 1161 * This could be pets or monsters that are somehow in
1144 * the shop. 1162 * the shop.
1170 /* unpaid objects, or non living objects, can't transfer by 1188 /* unpaid objects, or non living objects, can't transfer by
1171 * shop mats. Instead, put it on a nearby space. 1189 * shop mats. Instead, put it on a nearby space.
1172 */ 1190 */
1173 if (QUERY_FLAG (op, FLAG_UNPAID) || !QUERY_FLAG (op, FLAG_ALIVE)) 1191 if (QUERY_FLAG (op, FLAG_UNPAID) || !QUERY_FLAG (op, FLAG_ALIVE))
1174 { 1192 {
1175
1176 /* Somebody dropped an unpaid item, just move to an adjacent place. */ 1193 /* Somebody dropped an unpaid item, just move to an adjacent place. */
1177 int i = find_free_spot (op, op->map, op->x, op->y, 1, 9); 1194 int i = find_free_spot (op, op->map, op->x, op->y, 1, 9);
1178 1195
1179 if (i != -1) 1196 if (i != -1)
1180 rv = transfer_ob (op, op->x + freearr_x[i], op->y + freearr_y[i], 0, shop_mat); 1197 rv = transfer_ob (op, op->x + freearr_x[i], op->y + freearr_y[i], 0, shop_mat);
1188 } 1205 }
1189 else if (can_pay (op) && get_payment (op)) 1206 else if (can_pay (op) && get_payment (op))
1190 { 1207 {
1191 /* this is only used for players */ 1208 /* this is only used for players */
1192 rv = teleport (shop_mat, SHOP_MAT, op); 1209 rv = teleport (shop_mat, SHOP_MAT, op);
1210
1211 if (has_unpaid)
1212 op->contr->play_sound (sound_find ("shop_buy"));
1213 else if (is_in_shop (op))
1214 op->contr->play_sound (sound_find ("shop_enter"));
1215 else
1216 op->contr->play_sound (sound_find ("shop_leave"));
1193 1217
1194 if (shop_mat->msg) 1218 if (shop_mat->msg)
1195 new_draw_info (NDI_UNIQUE, 0, op, shop_mat->msg); 1219 new_draw_info (NDI_UNIQUE, 0, op, shop_mat->msg);
1196 /* This check below is a bit simplistic - generally it should be correct, 1220 /* This check below is a bit simplistic - generally it should be correct,
1197 * but there is never a guarantee that the bottom space on the map is 1221 * but there is never a guarantee that the bottom space on the map is
1212 } 1236 }
1213 } 1237 }
1214 else 1238 else
1215 { 1239 {
1216 /* if we get here, a player tried to leave a shop but was not able 1240 /* if we get here, a player tried to leave a shop but was not able
1217 * to afford the items he has. We try to move the player so that 1241 * to afford the items he has. We try to move the player so that
1218 * they are not on the mat anymore 1242 * they are not on the mat anymore
1219 */ 1243 */
1220 int i = find_free_spot (op, op->map, op->x, op->y, 1, 9); 1244 int i = find_free_spot (op, op->map, op->x, op->y, 1, 9);
1221 1245
1222 if (i == -1) 1246 if (i == -1)
1223 {
1224 LOG (llevError, "Internal shop-mat problem.\n"); 1247 LOG (llevError, "Internal shop-mat problem.\n");
1225 }
1226 else 1248 else
1227 { 1249 {
1228 op->remove (); 1250 op->remove ();
1229 op->x += freearr_x[i]; 1251 op->x += freearr_x[i];
1230 op->y += freearr_y[i]; 1252 op->y += freearr_y[i];
1241 */ 1263 */
1242static void 1264static void
1243apply_sign (object *op, object *sign, int autoapply) 1265apply_sign (object *op, object *sign, int autoapply)
1244{ 1266{
1245 readable_message_type *msgType; 1267 readable_message_type *msgType;
1246 char newbuf[HUGE_BUF];
1247 1268
1248 if (sign->msg == NULL) 1269 if (sign->msg == NULL)
1249 { 1270 {
1250 new_draw_info (NDI_UNIQUE, 0, op, "Nothing is written on it."); 1271 new_draw_info (NDI_UNIQUE, 0, op, "Nothing is written on it.");
1251 return; 1272 return;
1255 { 1276 {
1256 if (sign->last_eat >= sign->stats.food) 1277 if (sign->last_eat >= sign->stats.food)
1257 { 1278 {
1258 if (!sign->move_on) 1279 if (!sign->move_on)
1259 new_draw_info (NDI_UNIQUE, 0, op, "You cannot read it anymore."); 1280 new_draw_info (NDI_UNIQUE, 0, op, "You cannot read it anymore.");
1281
1260 return; 1282 return;
1261 } 1283 }
1262 1284
1263 if (!QUERY_FLAG (op, FLAG_WIZPASS)) 1285 if (!QUERY_FLAG (op, FLAG_WIZPASS))
1264 sign->last_eat++; 1286 sign->last_eat++;
1272 if (QUERY_FLAG (op, FLAG_BLIND) && !QUERY_FLAG (op, FLAG_WIZ) && !sign->move_on) 1294 if (QUERY_FLAG (op, FLAG_BLIND) && !QUERY_FLAG (op, FLAG_WIZ) && !sign->move_on)
1273 { 1295 {
1274 new_draw_info (NDI_UNIQUE, 0, op, "You are unable to read while blind."); 1296 new_draw_info (NDI_UNIQUE, 0, op, "You are unable to read while blind.");
1275 return; 1297 return;
1276 } 1298 }
1299
1300 if (op->contr)
1301 if (client *ns = op->contr->ns)
1302 {
1303 ns->play_sound (sign->sound);
1277 msgType = get_readable_message_type (sign); 1304 msgType = get_readable_message_type (sign);
1305
1306 if (ns->can_msg)
1307 ns->send_msg (NDI_NAVY, msgType->msgtype, &sign->msg);
1308 else
1309 {
1310 char newbuf[HUGE_BUF];
1278 snprintf (newbuf, sizeof (newbuf), "%hhu %s", autoapply ? 1 : 0, &sign->msg); 1311 snprintf (newbuf, sizeof (newbuf), "%u %s", autoapply ? 1 : 0, &sign->msg);
1279 draw_ext_info (NDI_UNIQUE | NDI_NAVY, 0, op, msgType->message_type, msgType->message_subtype, newbuf, &sign->msg); 1312 draw_ext_info (NDI_UNIQUE | NDI_NAVY, 0, op, msgType->message_type, msgType->message_subtype, newbuf, &sign->msg);
1313 }
1314 }
1280} 1315}
1281 1316
1282/** 1317/**
1283 * 'victim' moves onto 'trap' 1318 * 'victim' moves onto 'trap'
1284 * 'victim' leaves 'trap' 1319 * 'victim' leaves 'trap'
1307 * proper. This code was causing needless crashes. 1342 * proper. This code was causing needless crashes.
1308 */ 1343 */
1309 if (recursion_depth >= 500) 1344 if (recursion_depth >= 500)
1310 { 1345 {
1311 LOG (llevDebug, "WARNING: move_apply(): aborting recursion " 1346 LOG (llevDebug, "WARNING: move_apply(): aborting recursion "
1312 "[trap arch %s, name %s; victim arch %s, name %s]\n", &trap->arch->name, &trap->name, &victim->arch->name, &victim->name); 1347 "[trap arch %s, name %s; victim arch %s, name %s]\n", &trap->arch->archname, &trap->name, &victim->arch->archname, &victim->name);
1313 return; 1348 return;
1314 } 1349 }
1350
1315 recursion_depth++; 1351 recursion_depth++;
1316 if (trap->head) 1352 if (trap->head)
1317 trap = trap->head; 1353 trap = trap->head;
1318 1354
1319 if (INVOKE_OBJECT (MOVE_TRIGGER, trap, ARG_OBJECT (victim), ARG_OBJECT (originator))) 1355 if (INVOKE_OBJECT (MOVE_TRIGGER, trap, ARG_OBJECT (victim), ARG_OBJECT (originator)))
1334 1370
1335 /* Just put in some sanity check. I think there is a bug in the 1371 /* Just put in some sanity check. I think there is a bug in the
1336 * above with some objects have zero speed, and thus the player 1372 * above with some objects have zero speed, and thus the player
1337 * getting permanently paralyzed. 1373 * getting permanently paralyzed.
1338 */ 1374 */
1339 if (victim->speed_left < -50.0) 1375 if (victim->speed_left < -50.f)
1340 victim->speed_left = -50.0; 1376 victim->speed_left = -50.f;
1341 /* LOG(llevDebug, "apply, playermove, player speed_left=%f\n", victim->speed_left); */ 1377 /* LOG(llevDebug, "apply, playermove, player speed_left=%f\n", victim->speed_left); */
1342 } 1378 }
1343 goto leave; 1379 goto leave;
1344 1380
1345 case SPINNER: 1381 case SPINNER:
1417 1453
1418 if ((ab->move_type && trap->move_on) || ab->move_type == 0) 1454 if ((ab->move_type && trap->move_on) || ab->move_type == 0)
1419 { 1455 {
1420 if (!sound_was_played) 1456 if (!sound_was_played)
1421 { 1457 {
1422 play_sound_map (trap->map, trap->x, trap->y, SOUND_FALL_HOLE); 1458 trap->play_sound (sound_find ("fall_hole"));
1423 sound_was_played = 1; 1459 sound_was_played = 1;
1424 } 1460 }
1461
1425 new_draw_info (NDI_UNIQUE, 0, ab, "You fall into a trapdoor!"); 1462 new_draw_info (NDI_UNIQUE, 0, ab, "You fall into a trapdoor!");
1426 transfer_ob (ab, (int) EXIT_X (trap), (int) EXIT_Y (trap), 0, ab); 1463 transfer_ob (ab, (int) EXIT_X (trap), (int) EXIT_Y (trap), 0, ab);
1427 } 1464 }
1428 } 1465 }
1429 goto leave; 1466 goto leave;
1430 } 1467 }
1431 1468
1432
1433 case CONVERTER: 1469 case CONVERTER:
1434 if (convert_item (victim, trap) < 0) 1470 if (convert_item (victim, trap) < 0)
1435 { 1471 {
1436 new_draw_info_format (NDI_UNIQUE, 0, originator, "The %s seems to be broken!", query_name (trap)); 1472 new_draw_info_format (NDI_UNIQUE, 0, originator, "The %s seems to be broken!", query_name (trap));
1437 get_archetype ("burnout")->insert_at (trap, trap); 1473 get_archetype ("burnout")->insert_at (trap, trap);
1462 * Processing will happen if the head runs into the pit 1498 * Processing will happen if the head runs into the pit
1463 */ 1499 */
1464 if (victim->head) 1500 if (victim->head)
1465 goto leave; 1501 goto leave;
1466 1502
1467 play_sound_map (victim->map, victim->x, victim->y, SOUND_FALL_HOLE); 1503 victim->play_sound (sound_find ("fall_hole"));
1468 new_draw_info (NDI_UNIQUE, 0, victim, "You fall through the hole!\n"); 1504 new_draw_info (NDI_UNIQUE, 0, victim, "You fall through the hole!\n");
1469 transfer_ob (victim, EXIT_X (trap), EXIT_Y (trap), 1, victim); 1505 transfer_ob (victim, EXIT_X (trap), EXIT_Y (trap), 1, victim);
1470 goto leave; 1506 goto leave;
1471 1507
1472 case EXIT: 1508 case EXIT:
1514 } 1550 }
1515 goto leave; 1551 goto leave;
1516 1552
1517 default: 1553 default:
1518 LOG (llevDebug, "name %s, arch %s, type %d with fly/walk on/off not " 1554 LOG (llevDebug, "name %s, arch %s, type %d with fly/walk on/off not "
1519 "handled in move_apply()\n", &trap->name, &trap->arch->name, trap->type); 1555 "handled in move_apply()\n", &trap->name, &trap->arch->archname, trap->type);
1520 goto leave; 1556 goto leave;
1521 } 1557 }
1522 1558
1523leave: 1559leave:
1524 recursion_depth--; 1560 recursion_depth--;
1536 if (QUERY_FLAG (op, FLAG_BLIND) && !QUERY_FLAG (op, FLAG_WIZ)) 1572 if (QUERY_FLAG (op, FLAG_BLIND) && !QUERY_FLAG (op, FLAG_WIZ))
1537 { 1573 {
1538 new_draw_info (NDI_UNIQUE, 0, op, "You are unable to read while blind."); 1574 new_draw_info (NDI_UNIQUE, 0, op, "You are unable to read while blind.");
1539 return; 1575 return;
1540 } 1576 }
1577
1541 if (tmp->msg == NULL) 1578 if (!tmp->msg)
1542 { 1579 {
1543 new_draw_info_format (NDI_UNIQUE, 0, op, "You open the %s and find it empty.", &tmp->name); 1580 new_draw_info_format (NDI_UNIQUE, 0, op, "You open the %s and find it empty.", &tmp->name);
1544 return; 1581 return;
1545 } 1582 }
1546 1583
1547 /* need a literacy skill to read stuff! */ 1584 /* need a literacy skill to read stuff! */
1548 skill_ob = find_skill_by_name (op, tmp->skill); 1585 skill_ob = find_skill_by_name (op, tmp->skill);
1549 if (!skill_ob) 1586 if (!skill_ob)
1550 { 1587 {
1551 new_draw_info (NDI_UNIQUE, 0, op, "You are unable to decipher the strange symbols."); 1588 new_draw_info (NDI_UNIQUE, 0, op, "You are unable to decipher the strange symbols. H<You lack the skill to read this>");
1552 return; 1589 return;
1553 } 1590 }
1591
1554 lev_diff = tmp->level - (skill_ob->level + 5); 1592 lev_diff = tmp->level - (skill_ob->level + 5);
1555 if (!QUERY_FLAG (op, FLAG_WIZ) && lev_diff > 0) 1593 if (!QUERY_FLAG (op, FLAG_WIZ) && lev_diff > 0)
1556 { 1594 {
1557 if (lev_diff < 2) 1595 if (lev_diff < 2)
1558 new_draw_info (NDI_UNIQUE, 0, op, "This book is just barely beyond your comprehension."); 1596 new_draw_info (NDI_UNIQUE, 0, op, "This book is just barely beyond your comprehension.");
1569 return; 1607 return;
1570 } 1608 }
1571 1609
1572 readable_message_type *msgType = get_readable_message_type (tmp); 1610 readable_message_type *msgType = get_readable_message_type (tmp);
1573 1611
1612 if (player *pl = op->contr)
1613 if (client *ns = pl->ns)
1614 if (ns->can_msg)
1615 {
1616 dynbuf_text buf;
1617 buf << long_desc (tmp, op)
1618 << "\n\n"
1619 << tmp->msg
1620 << '\0';
1621 ns->send_msg (NDI_NAVY, msgType->msgtype, buf.linearise ());
1622 }
1623 else
1574 draw_ext_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, 1624 draw_ext_info_format (NDI_UNIQUE | NDI_NAVY, 0, op,
1575 msgType->message_type, msgType->message_subtype, 1625 msgType->message_type, msgType->message_subtype,
1576 "You open the %s and start reading.\n%s", (char *)"%s\n%s", 1626 "You open the %s and start reading.\n%s", (char *)"%s\n%s",
1577 long_desc (tmp, op), &tmp->msg); 1627 long_desc (tmp, op), &tmp->msg);
1578 1628
1579 /* gain xp from reading */ 1629 /* gain xp from reading */
1580 if (!QUERY_FLAG (tmp, FLAG_NO_SKILL_IDENT)) 1630 if (!QUERY_FLAG (tmp, FLAG_NO_SKILL_IDENT))
1581 { /* only if not read before */ 1631 { /* only if not read before */
1582 int exp_gain = calc_skill_exp (op, tmp, skill_ob); 1632 int exp_gain = calc_skill_exp (op, tmp, skill_ob);
1648 return; 1698 return;
1649 } 1699 }
1650 return; 1700 return;
1651 } 1701 }
1652 1702
1653 play_sound_player_only (op->contr, SOUND_LEARN_SPELL, 0, 0); 1703 op->contr->play_sound (sound_find ("learn_spell"));
1704
1654 tmp = spell->clone (); 1705 tmp = spell->clone ();
1655 insert_ob_in_ob (tmp, op); 1706 insert_ob_in_ob (tmp, op);
1656 1707
1657 if (special_prayer) 1708 if (special_prayer)
1658 SET_FLAG (tmp, FLAG_STARTEQUIP); 1709 SET_FLAG (tmp, FLAG_STARTEQUIP);
1703 1754
1704 /* artifact_spellbooks have 'slaying' field point to a spell name, 1755 /* artifact_spellbooks have 'slaying' field point to a spell name,
1705 * instead of having their spell stored in stats.sp. These are 1756 * instead of having their spell stored in stats.sp. These are
1706 * legacy spellbooks 1757 * legacy spellbooks
1707 */ 1758 */
1708
1709 if (tmp->slaying != NULL) 1759 if (tmp->slaying)
1710 { 1760 {
1711 spell = arch_to_object (find_archetype_by_object_name (tmp->slaying)); 1761 spell = arch_to_object (find_archetype_by_object_name (tmp->slaying));
1712 if (!spell) 1762 if (!spell)
1713 { 1763 {
1714 new_draw_info_format (NDI_UNIQUE, 0, op, "The book's formula for %s is incomplete", &tmp->slaying); 1764 new_draw_info_format (NDI_UNIQUE, 0, op, "The book's formula for %s is incomplete", &tmp->slaying);
1715 return; 1765 return;
1716 } 1766 }
1717 else 1767 else
1718 insert_ob_in_ob (spell, tmp); 1768 insert_ob_in_ob (spell, tmp);
1769
1719 tmp->slaying = NULL; 1770 tmp->slaying = 0;
1720 } 1771 }
1721 1772
1722 skop = find_skill_by_name (op, tmp->skill); 1773 skop = find_skill_by_name (op, tmp->skill);
1723 1774
1724 /* need a literacy skill to learn spells. Also, having a literacy level 1775 /* need a literacy skill to learn spells. Also, having a literacy level
1725 * lower than the spell will make learning the spell more difficult */ 1776 * lower than the spell will make learning the spell more difficult */
1726 if (!skop) 1777 if (!skop)
1727 { 1778 {
1728 new_draw_info (NDI_UNIQUE, 0, op, "You can't read! Your attempt fails."); 1779 new_draw_info (NDI_UNIQUE, 0, op, "You can't read! Your attempt fails. H<You lack the literacy skill.>");
1729 return; 1780 return;
1730 } 1781 }
1731 1782
1732 spell = tmp->inv; 1783 spell = tmp->inv;
1733 1784
1734 if (!spell) 1785 if (!spell)
1735 { 1786 {
1736 LOG (llevError, "apply_spellbook: Book %s has no spell in it!\n", &tmp->name); 1787 LOG (llevError, "apply_spellbook: Book %s has no spell in it!\n", &tmp->name);
1737 new_draw_info (NDI_UNIQUE, 0, op, "The spellbook symbols make no sense."); 1788 new_draw_info (NDI_UNIQUE, 0, op, "The spellbook symbols make no sense. This is a bug, please report!");
1738 return; 1789 return;
1739 } 1790 }
1740 1791
1741 if (skop->level < int (sqrtf (spell->level) * 1.5f)) 1792 if (skop->level < int (sqrtf (spell->level) * 1.5f))
1742 { 1793 {
1743 new_draw_info (NDI_UNIQUE, 0, op, "You are unable to decipher the strange symbols. [Your literacy level is too low]"); 1794 new_draw_info (NDI_UNIQUE, 0, op, "You are unable to decipher the strange symbols. H<Your literacy level is too low.>");
1744 return; 1795 return;
1745 } 1796 }
1746 1797
1747 new_draw_info_format (NDI_UNIQUE, 0, op, "The spellbook contains the %s level spell %s.", get_levelnumber (spell->level), &spell->name); 1798 new_draw_info_format (NDI_UNIQUE, 0, op, "The spellbook contains the %s level spell %s.", get_levelnumber (spell->level), &spell->name);
1748 1799
1761 * if the player doesn't know the spell, doesn't make a lot of sense that 1812 * if the player doesn't know the spell, doesn't make a lot of sense that
1762 * they would have a special prayer mark. 1813 * they would have a special prayer mark.
1763 */ 1814 */
1764 if (check_spell_known (op, spell->name)) 1815 if (check_spell_known (op, spell->name))
1765 { 1816 {
1766 new_draw_info (NDI_UNIQUE, 0, op, "You already know that spell.\n"); 1817 new_draw_info (NDI_UNIQUE, 0, op, "You already know that spell. H<It makes no sense to learn spells twice, and would only waste the spellbook.>\n");
1767 return; 1818 return;
1768 } 1819 }
1769 1820
1770 if (spell->skill) 1821 if (spell->skill)
1771 { 1822 {
1812 if (!QUERY_FLAG (tmp, FLAG_STARTEQUIP)) 1863 if (!QUERY_FLAG (tmp, FLAG_STARTEQUIP))
1813 change_exp (op, calc_skill_exp (op, tmp, skop), skop->skill, 0); 1864 change_exp (op, calc_skill_exp (op, tmp, skop), skop->skill, 0);
1814 } 1865 }
1815 else 1866 else
1816 { 1867 {
1817 play_sound_player_only (op->contr, SOUND_FUMBLE_SPELL, 0, 0); 1868 op->contr->play_sound (sound_find ("fumble_spell"));
1818 new_draw_info (NDI_UNIQUE, 0, op, "You fail to learn the spell.\n"); 1869 new_draw_info (NDI_UNIQUE, 0, op, "You fail to learn the spell. H<Wis (priests) or Int (wizards) governs the chance of learning a prayer or spell.>\n");
1819 } 1870 }
1820 1871
1821 decrease_ob (tmp); 1872 decrease_ob (tmp);
1822} 1873}
1823 1874
1835 return; 1886 return;
1836 } 1887 }
1837 1888
1838 if (!tmp->inv || tmp->inv->type != SPELL) 1889 if (!tmp->inv || tmp->inv->type != SPELL)
1839 { 1890 {
1840 new_draw_info (NDI_UNIQUE, 0, op, "The scroll just doesn't make sense!"); 1891 new_draw_info (NDI_UNIQUE, 0, op, "The scroll just doesn't make sense! H<...and never will make sense.>");
1841 return; 1892 return;
1842 } 1893 }
1843 1894
1844 if (op->type == PLAYER) 1895 if (op->type == PLAYER)
1845 { 1896 {
1851 */ 1902 */
1852 skop = find_skill_by_name (op, skill_names[SK_LITERACY]); 1903 skop = find_skill_by_name (op, skill_names[SK_LITERACY]);
1853 1904
1854 if (!skop) 1905 if (!skop)
1855 { 1906 {
1856 new_draw_info (NDI_UNIQUE, 0, op, "You are unable to decipher the strange symbols."); 1907 new_draw_info (NDI_UNIQUE, 0, op, "You are unable to decipher the strange symbols. H<You lack the literacy skill.>");
1857 return; 1908 return;
1858 } 1909 }
1859 1910
1860 if ((exp_gain = calc_skill_exp (op, tmp, skop))) 1911 if ((exp_gain = calc_skill_exp (op, tmp, skop)))
1861 change_exp (op, exp_gain, skop->skill, 0); 1912 change_exp (op, exp_gain, skop->skill, 0);
1863 1914
1864 if (!QUERY_FLAG (tmp, FLAG_IDENTIFIED)) 1915 if (!QUERY_FLAG (tmp, FLAG_IDENTIFIED))
1865 identify (tmp); 1916 identify (tmp);
1866 1917
1867 new_draw_info_format (NDI_BLACK, 0, op, "The scroll of %s turns to dust.", &tmp->inv->name); 1918 new_draw_info_format (NDI_BLACK, 0, op, "The scroll of %s turns to dust.", &tmp->inv->name);
1868
1869 1919
1870 cast_spell (op, tmp, dir, tmp->inv, NULL); 1920 cast_spell (op, tmp, dir, tmp->inv, NULL);
1871 decrease_ob (tmp); 1921 decrease_ob (tmp);
1872} 1922}
1873 1923
1877 * chest. 1927 * chest.
1878 */ 1928 */
1879static void 1929static void
1880apply_treasure (object *op, object *tmp) 1930apply_treasure (object *op, object *tmp)
1881{ 1931{
1882 object *treas;
1883
1884
1885 /* Nice side effect of new treasure creation method is that the treasure 1932 /* Nice side effect of new treasure creation method is that the treasure
1886 * for the chest is done when the chest is created, and put into the chest 1933 * for the chest is done when the chest is created, and put into the chest
1887 * inventory. So that when the chest burns up, the items still exist. Also 1934 * inventory. So that when the chest burns up, the items still exist. Also
1888 * prevents people fromt moving chests to more difficult maps to get better 1935 * prevents people fromt moving chests to more difficult maps to get better
1889 * treasure 1936 * treasure
1890 */ 1937 */
1891
1892 treas = tmp->inv; 1938 object *treas = tmp->inv;
1893 if (treas == NULL) 1939
1940 if (!treas)
1894 { 1941 {
1895 new_draw_info (NDI_UNIQUE, 0, op, "The chest was empty."); 1942 new_draw_info (NDI_UNIQUE, 0, op, "The chest was empty.");
1896 decrease_ob (tmp); 1943 decrease_ob (tmp);
1897 return; 1944 return;
1898 } 1945 }
1946
1899 while (tmp->inv) 1947 while (tmp->inv)
1900 { 1948 {
1901 treas = tmp->inv; 1949 treas = tmp->inv;
1902 1950
1903 treas->remove (); 1951 treas->remove ();
1985 /* special food hack -b.t. */ 2033 /* special food hack -b.t. */
1986 if (tmp->title || QUERY_FLAG (tmp, FLAG_CURSED)) 2034 if (tmp->title || QUERY_FLAG (tmp, FLAG_CURSED))
1987 eat_special_food (op, tmp); 2035 eat_special_food (op, tmp);
1988 } 2036 }
1989 } 2037 }
2038
1990 handle_apply_yield (tmp); 2039 handle_apply_yield (tmp);
1991 decrease_ob (tmp); 2040 decrease_ob (tmp);
1992} 2041}
1993 2042
1994/** 2043/**
2021 if (meal->type != FLESH || !is_dragon_pl (op)) 2070 if (meal->type != FLESH || !is_dragon_pl (op))
2022 return 0; 2071 return 0;
2023 2072
2024 /* now grab the 'dragon_skin'- and 'dragon_ability'-forces 2073 /* now grab the 'dragon_skin'- and 'dragon_ability'-forces
2025 from the player's inventory */ 2074 from the player's inventory */
2026 shstr_cmp dragon_ability_force ("dragon_ability_force");
2027 shstr_cmp dragon_skin_force ("dragon_skin_force");
2028
2029 for (tmp = op->inv; tmp; tmp = tmp->below) 2075 for (tmp = op->inv; tmp; tmp = tmp->below)
2030 if (tmp->type == FORCE) 2076 if (tmp->type == FORCE)
2031 if (tmp->arch->name == dragon_skin_force) 2077 if (tmp->arch->archname == shstr_dragon_skin_force)
2032 skin = tmp; 2078 skin = tmp;
2033 else if (tmp->arch->name == dragon_ability_force) 2079 else if (tmp->arch->archname == shstr_dragon_ability_force)
2034 abil = tmp; 2080 abil = tmp;
2035 2081
2036 /* if either skin or ability are missing, this is an old player 2082 /* if either skin or ability are missing, this is an old player
2037 which is not to be considered a dragon -> bail out */ 2083 which is not to be considered a dragon -> bail out */
2038 if (skin == NULL || abil == NULL) 2084 if (skin == NULL || abil == NULL)
2159static void 2205static void
2160apply_armour_improver (object *op, object *tmp) 2206apply_armour_improver (object *op, object *tmp)
2161{ 2207{
2162 object *armor; 2208 object *armor;
2163 2209
2164 if (!QUERY_FLAG (op, FLAG_WIZCAST) && (get_map_flags (op->map, NULL, op->x, op->y, NULL, NULL) & P_NO_MAGIC)) 2210 if (!QUERY_FLAG (op, FLAG_WIZCAST) && (get_map_flags (op->map, 0, op->x, op->y, 0, 0) & P_NO_MAGIC))
2165 { 2211 {
2166 new_draw_info (NDI_UNIQUE, 0, op, "Something blocks the magic of the scroll."); 2212 new_draw_info (NDI_UNIQUE, 0, op, "Something blocks the magic of the scroll. H<The area prevents magic effects.>");
2167 return; 2213 return;
2168 } 2214 }
2169 2215
2170 armor = find_marked_object (op); 2216 armor = find_marked_object (op);
2171 2217
2172 if (!armor) 2218 if (!armor)
2173 { 2219 {
2174 new_draw_info (NDI_UNIQUE, 0, op, "You need to mark an armor object."); 2220 new_draw_info (NDI_UNIQUE, 0, op, "You need to mark an armor object. Use the right mouse button popup or the mark command to do this.");
2175 return; 2221 return;
2176 } 2222 }
2177 2223
2178 if (armor->type != ARMOUR 2224 if (armor->type != ARMOUR
2179 && armor->type != CLOAK 2225 && armor->type != CLOAK
2190extern void 2236extern void
2191apply_poison (object *op, object *tmp) 2237apply_poison (object *op, object *tmp)
2192{ 2238{
2193 if (op->type == PLAYER) 2239 if (op->type == PLAYER)
2194 { 2240 {
2195 play_sound_player_only (op->contr, SOUND_DRINK_POISON, 0, 0); 2241 op->contr->play_sound (sound_find ("drink_poison"));
2196 new_draw_info (NDI_UNIQUE, 0, op, "Yech! That tasted poisonous!"); 2242 new_draw_info (NDI_UNIQUE, 0, op, "Yech! That tasted poisonous!");
2197 strcpy (op->contr->killer, "poisonous booze"); 2243 strcpy (op->contr->killer, "poisonous booze");
2198 } 2244 }
2245
2199 if (tmp->stats.hp > 0) 2246 if (tmp->stats.hp > 0)
2200 { 2247 {
2201 LOG (llevDebug, "Trying to poison player/monster for %d hp\n", tmp->stats.hp); 2248 LOG (llevDebug, "Trying to poison player/monster for %d hp\n", tmp->stats.hp);
2202 hit_player (op, tmp->stats.hp, tmp, AT_POISON, 1); 2249 hit_player (op, tmp->stats.hp, tmp, AT_POISON, 1);
2203 } 2250 }
2251
2204 op->stats.food -= op->stats.food / 4; 2252 op->stats.food -= op->stats.food / 4;
2205 handle_apply_yield (tmp); 2253 handle_apply_yield (tmp);
2206 decrease_ob (tmp); 2254 decrease_ob (tmp);
2207} 2255}
2208 2256
2291 } 2339 }
2292 } 2340 }
2293 2341
2294 return 0; 2342 return 0;
2295} 2343}
2296
2297 2344
2298/** 2345/**
2299 * Main apply handler. 2346 * Main apply handler.
2300 * 2347 *
2301 * Checks for unpaid items before applying. 2348 * Checks for unpaid items before applying.
2309 * being applied. 2356 * being applied.
2310 * 2357 *
2311 * aflag is special (always apply/unapply) flags. Nothing is done with 2358 * aflag is special (always apply/unapply) flags. Nothing is done with
2312 * them in this function - they are passed to apply_special 2359 * them in this function - they are passed to apply_special
2313 */ 2360 */
2314
2315int 2361int
2316manual_apply (object *op, object *tmp, int aflag) 2362manual_apply (object *op, object *tmp, int aflag)
2317{ 2363{
2318 if (tmp->head) 2364 if (tmp->head)
2319 tmp = tmp->head; 2365 tmp = tmp->head;
2320 2366
2321 if (QUERY_FLAG (tmp, FLAG_UNPAID) && !QUERY_FLAG (tmp, FLAG_APPLIED)) 2367 if (QUERY_FLAG (tmp, FLAG_UNPAID) && !QUERY_FLAG (tmp, FLAG_APPLIED))
2322 { 2368 {
2323 if (op->type == PLAYER) 2369 if (op->type == PLAYER)
2324 { 2370 {
2325 new_draw_info (NDI_UNIQUE, 0, op, "You should pay for it first."); 2371 new_draw_info (NDI_UNIQUE, 0, op, "You should pay for it first. H<You cannot use items marked as unpaid.>");
2326 return 1; 2372 return 1;
2327 } 2373 }
2328 else 2374 else
2329 return 0; /* monsters just skip unpaid items */ 2375 return 0; /* monsters just skip unpaid items */
2330 } 2376 }
2334 2380
2335 switch (tmp->type) 2381 switch (tmp->type)
2336 { 2382 {
2337 case CF_HANDLE: 2383 case CF_HANDLE:
2338 new_draw_info (NDI_UNIQUE, 0, op, "You turn the handle."); 2384 new_draw_info (NDI_UNIQUE, 0, op, "You turn the handle.");
2339 play_sound_map (op->map, op->x, op->y, SOUND_TURN_HANDLE); 2385 op->play_sound (sound_find ("turn_handle"));
2340 tmp->value = tmp->value ? 0 : 1; 2386 tmp->value = tmp->value ? 0 : 1;
2341 SET_ANIMATION (tmp, tmp->value); 2387 SET_ANIMATION (tmp, tmp->value);
2342 update_object (tmp, UP_OBJ_FACE); 2388 update_object (tmp, UP_OBJ_FACE);
2343 push_button (tmp); 2389 push_button (tmp);
2344 return 1; 2390 return 1;
2345 2391
2346 case TRIGGER: 2392 case TRIGGER:
2347 if (check_trigger (tmp, op)) 2393 if (check_trigger (tmp, op))
2348 { 2394 {
2349 new_draw_info (NDI_UNIQUE, 0, op, "You turn the handle."); 2395 new_draw_info (NDI_UNIQUE, 0, op, "You turn the handle.");
2350 play_sound_map (tmp->map, tmp->x, tmp->y, SOUND_TURN_HANDLE); 2396 op->play_sound (sound_find ("turn_handle"));
2351 } 2397 }
2352 else 2398 else
2353 new_draw_info (NDI_UNIQUE, 0, op, "The handle doesn't move."); 2399 new_draw_info (NDI_UNIQUE, 0, op, "The handle doesn't move.");
2354 2400
2355 return 1; 2401 return 1;
2357 case EXIT: 2403 case EXIT:
2358 if (op->type != PLAYER) 2404 if (op->type != PLAYER)
2359 return 0; 2405 return 0;
2360 2406
2361 if (!EXIT_PATH (tmp) || !is_legal_2ways_exit (op, tmp)) 2407 if (!EXIT_PATH (tmp) || !is_legal_2ways_exit (op, tmp))
2362 {
2363 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s is closed.", query_name (tmp)); 2408 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s is closed.", query_name (tmp));
2364 }
2365 else 2409 else
2366 { 2410 {
2367 /* Don't display messages for random maps. */ 2411 /* Don't display messages for random maps. */
2368 if (tmp->msg && strncmp (EXIT_PATH (tmp), "/!", 2)) 2412 if (tmp->msg && strncmp (EXIT_PATH (tmp), "/!", 2))
2369 new_draw_info (NDI_NAVY, 0, op, tmp->msg); 2413 new_draw_info (NDI_NAVY, 0, op, tmp->msg);
2370 2414
2371 op->enter_exit (tmp); 2415 op->enter_exit (tmp);
2372 } 2416 }
2417
2373 return 1; 2418 return 1;
2374 2419
2375 case SIGN: 2420 case SIGN:
2376 apply_sign (op, tmp, 0); 2421 apply_sign (op, tmp, 0);
2377 return 1; 2422 return 1;
2381 { 2426 {
2382 apply_book (op, tmp); 2427 apply_book (op, tmp);
2383 return 1; 2428 return 1;
2384 } 2429 }
2385 else 2430 else
2386 {
2387 return 0; 2431 return 0;
2388 }
2389 2432
2390 case SKILLSCROLL: 2433 case SKILLSCROLL:
2391 if (op->type == PLAYER) 2434 if (op->type == PLAYER)
2392 { 2435 {
2393 apply_skillscroll (op, tmp); 2436 apply_skillscroll (op, tmp);
2394 return 1; 2437 return 1;
2395 } 2438 }
2439 else
2396 return 0; 2440 return 0;
2397 2441
2398 case SPELLBOOK: 2442 case SPELLBOOK:
2399 if (op->type == PLAYER) 2443 if (op->type == PLAYER)
2400 { 2444 {
2401 apply_spellbook (op, tmp); 2445 apply_spellbook (op, tmp);
2402 return 1; 2446 return 1;
2403 } 2447 }
2448 else
2404 return 0; 2449 return 0;
2405 2450
2406 case SCROLL: 2451 case SCROLL:
2407 apply_scroll (op, tmp, 0); 2452 apply_scroll (op, tmp, 0);
2408 return 1; 2453 return 1;
2409 2454
2410 case POTION: 2455 case POTION:
2411 (void) apply_potion (op, tmp); 2456 apply_potion (op, tmp);
2412 return 1; 2457 return 1;
2413 2458
2414 /* Eneq(@csd.uu.se): Handle apply on containers. */ 2459 /* Eneq(@csd.uu.se): Handle apply on containers. */
2415 //TODO: remove, as it is unsed? 2460 //TODO: remove, as it is unsed?
2416 case CLOSE_CON: 2461 case CLOSE_CON:
2449 case LAMP: 2494 case LAMP:
2450 case BUILDER: 2495 case BUILDER:
2451 case SKILL_TOOL: 2496 case SKILL_TOOL:
2452 if (tmp->env != op) 2497 if (tmp->env != op)
2453 return 2; /* not in inventory */ 2498 return 2; /* not in inventory */
2499
2454 (void) apply_special (op, tmp, aflag); 2500 apply_special (op, tmp, aflag);
2455 return 1; 2501 return 1;
2456 2502
2457 case DRINK: 2503 case DRINK:
2458 case FOOD: 2504 case FOOD:
2459 case FLESH: 2505 case FLESH:
2475 } 2521 }
2476 else 2522 else
2477 return 0; 2523 return 0;
2478 2524
2479 case WEAPON_IMPROVER: 2525 case WEAPON_IMPROVER:
2480 (void) check_improve_weapon (op, tmp); 2526 check_improve_weapon (op, tmp);
2481 return 1; 2527 return 1;
2482 2528
2483 case CLOCK: 2529 case CLOCK:
2484 if (op->type == PLAYER) 2530 if (op->type == PLAYER)
2485 { 2531 {
2488 2534
2489 get_tod (&tod); 2535 get_tod (&tod);
2490 sprintf (buf, "It is %d minute%s past %d o'clock %s", 2536 sprintf (buf, "It is %d minute%s past %d o'clock %s",
2491 tod.minute + 1, ((tod.minute + 1 < 2) ? "" : "s"), 2537 tod.minute + 1, ((tod.minute + 1 < 2) ? "" : "s"),
2492 ((tod.hour % 14 == 0) ? 14 : ((tod.hour) % 14)), ((tod.hour >= 14) ? "pm" : "am")); 2538 ((tod.hour % 14 == 0) ? 14 : ((tod.hour) % 14)), ((tod.hour >= 14) ? "pm" : "am"));
2493 play_sound_player_only (op->contr, SOUND_CLOCK, 0, 0); 2539 op->play_sound (sound_find ("sound_clock"));
2494 new_draw_info (NDI_UNIQUE, 0, op, buf); 2540 new_draw_info (NDI_UNIQUE, 0, op, buf);
2495 return 1; 2541 return 1;
2496 } 2542 }
2497 else 2543 else
2498 {
2499 return 0; 2544 return 0;
2500 }
2501 2545
2502 case MENU: 2546 case MENU:
2503 if (op->type == PLAYER) 2547 if (op->type == PLAYER)
2504 { 2548 {
2505 shop_listing (tmp, op); 2549 shop_listing (tmp, op);
2506 return 1; 2550 return 1;
2507 } 2551 }
2508 else 2552 else
2509 {
2510 return 0; 2553 return 0;
2511 }
2512 2554
2513 case POWER_CRYSTAL: 2555 case POWER_CRYSTAL:
2514 apply_power_crystal (op, tmp); /* see egoitem.c */ 2556 apply_power_crystal (op, tmp); /* see egoitem.c */
2515 return 1; 2557 return 1;
2516 2558
2519 { 2561 {
2520 apply_lighter (op, tmp); 2562 apply_lighter (op, tmp);
2521 return 1; 2563 return 1;
2522 } 2564 }
2523 else 2565 else
2524 {
2525 return 0; 2566 return 0;
2526 }
2527 2567
2528 case ITEM_TRANSFORMER: 2568 case ITEM_TRANSFORMER:
2529 apply_item_transformer (op, tmp); 2569 apply_item_transformer (op, tmp);
2530 return 1; 2570 return 1;
2531 2571
2544int 2584int
2545player_apply (object *pl, object *op, int aflag, int quiet) 2585player_apply (object *pl, object *op, int aflag, int quiet)
2546{ 2586{
2547 int tmp; 2587 int tmp;
2548 2588
2549 if (op->env == NULL && (pl->move_type & MOVE_FLYING)) 2589 if (op->env && (pl->move_type & MOVE_FLYING))
2550 { 2590 {
2551 /* player is flying and applying object not in inventory */ 2591 /* player is flying and applying object not in inventory */
2552 if (!QUERY_FLAG (pl, FLAG_WIZ) && !(op->move_type & MOVE_FLYING)) 2592 if (!QUERY_FLAG (pl, FLAG_WIZ) && !(op->move_type & MOVE_FLYING))
2553 { 2593 {
2554 new_draw_info (NDI_UNIQUE, 0, pl, "But you are floating high " "above the ground!"); 2594 new_draw_info (NDI_UNIQUE, 0, pl, "But you are floating high above the ground! H<You have to stop levitating first, if you can.>");
2555 return 0; 2595 return 0;
2556 } 2596 }
2557 }
2558
2559 /* Check for PLAYER to avoid a DM to disappear in a puff of smoke if
2560 * applied.
2561 */
2562 if (op->type != PLAYER && QUERY_FLAG (op, FLAG_WAS_WIZ) && !QUERY_FLAG (pl, FLAG_WAS_WIZ))
2563 {
2564 play_sound_map (pl->map, pl->x, pl->y, SOUND_OB_EVAPORATE);
2565 new_draw_info (NDI_UNIQUE, 0, pl, "The object disappears in a puff " "of smoke!");
2566 new_draw_info (NDI_UNIQUE, 0, pl, "It must have been an illusion.");
2567 op->destroy ();
2568 return 1;
2569 } 2597 }
2570 2598
2571 pl->contr->last_used = op; 2599 pl->contr->last_used = op;
2572 2600
2573 tmp = manual_apply (pl, op, aflag); 2601 tmp = manual_apply (pl, op, aflag);
2576 if (tmp == 0) 2604 if (tmp == 0)
2577 new_draw_info_format (NDI_UNIQUE, 0, pl, "I don't know how to apply the %s.", query_name (op)); 2605 new_draw_info_format (NDI_UNIQUE, 0, pl, "I don't know how to apply the %s.", query_name (op));
2578 else if (tmp == 2) 2606 else if (tmp == 2)
2579 new_draw_info_format (NDI_UNIQUE, 0, pl, "You must get it first!\n"); 2607 new_draw_info_format (NDI_UNIQUE, 0, pl, "You must get it first!\n");
2580 } 2608 }
2609
2581 return tmp; 2610 return tmp;
2582} 2611}
2583 2612
2584/** 2613/**
2585 * player_apply_below attempts to apply the object 'below' the player. 2614 * player_apply_below attempts to apply the object 'below' the player.
2586 * If the player has an open container, we use that for below, otherwise 2615 * If the player has an open container, we use that for below, otherwise
2587 * we use the ground. 2616 * we use the ground.
2588 */ 2617 */
2589
2590void 2618void
2591player_apply_below (object *pl) 2619player_apply_below (object *pl)
2592{ 2620{
2593 int floors = 0; 2621 int floors = 0;
2594 2622
2631 * to keep the size of apply_special to a more managable size. 2659 * to keep the size of apply_special to a more managable size.
2632 */ 2660 */
2633static int 2661static int
2634unapply_special (object *who, object *op, int aflags) 2662unapply_special (object *who, object *op, int aflags)
2635{ 2663{
2636 if (INVOKE_OBJECT (BE_UNREADY, op, ARG_OBJECT (who), ARG_INT (aflags)) || INVOKE_OBJECT (UNREADY, who, ARG_OBJECT (op), ARG_INT (aflags))) 2664 if (INVOKE_OBJECT (BE_UNREADY, op, ARG_OBJECT (who), ARG_INT (aflags))
2665 || INVOKE_OBJECT (UNREADY, who, ARG_OBJECT (op), ARG_INT (aflags)))
2637 return RESULT_INT (0); 2666 return RESULT_INT (0);
2638 2667
2639 object *tmp2;
2640
2641 CLEAR_FLAG (op, FLAG_APPLIED); 2668 CLEAR_FLAG (op, FLAG_APPLIED);
2642 2669
2643 switch (op->type) 2670 switch (op->type)
2644 { 2671 {
2672 case SKILL_TOOL:
2673 // unapplying a skill tool should also unapply the skill it governs
2674 // but this is hard, as it shouldn't do so when the skill can
2675 // be used for other reasons
2676 for (object *tmp = who->inv; tmp; tmp = tmp->below)
2677 if (tmp->skill == op->skill
2678 && tmp->type == SKILL
2679 && tmp->flag [FLAG_APPLIED]
2680 && !tmp->flag [FLAG_CAN_USE_SKILL])
2681 unapply_special (who, tmp, 0);
2682
2683 change_abil (who, op);
2684 break;
2685
2645 case WEAPON: 2686 case WEAPON:
2687 if (player *pl = who->contr)
2688 if (op == pl->combat_ob)
2689 {
2690 pl->combat_ob = 0;
2691 who->change_weapon (pl->ranged_ob);
2692 }
2693
2646 new_draw_info_format (NDI_UNIQUE, 0, who, "You unwield %s.", query_name (op)); 2694 new_draw_info_format (NDI_UNIQUE, 0, who, "You unwield %s.", query_name (op));
2647 2695
2648 (void) change_abil (who, op); 2696 change_abil (who, op);
2649 if (QUERY_FLAG (who, FLAG_READY_WEAPON))
2650 CLEAR_FLAG (who, FLAG_READY_WEAPON); 2697 CLEAR_FLAG (who, FLAG_READY_WEAPON);
2651 clear_skill (who);
2652 break; 2698 break;
2653 2699
2654 case SKILL: /* allows objects to impart skills */
2655 case SKILL_TOOL: 2700 case SKILL:
2656 if (op != who->chosen_skill) 2701 if (who->contr)
2657 LOG (llevError, "BUG: apply_special(): applied skill is not a chosen skill\n");
2658
2659 if (who->type == PLAYER)
2660 {
2661 if (who->contr->ranged_ob == op)
2662 { 2702 {
2663 who->contr->ranged_skill = 0;
2664 who->contr->ranged_ob = 0;
2665 }
2666
2667 if (!op->invisible) 2703 if (!op->invisible)
2668 new_draw_info_format (NDI_UNIQUE, 0, who, "You stop using the %s.", query_name (op)); 2704 new_draw_info_format (NDI_UNIQUE, 0, who, "You stop using the %s.", query_name (op));
2669 else 2705 else
2670 new_draw_info_format (NDI_UNIQUE, 0, who, "You can no longer use the skill: %s.", &op->skill); 2706 new_draw_info_format (NDI_UNIQUE, 0, who, "You can no longer use the skill: %s.", &op->skill);
2671 } 2707 }
2672 2708
2673 change_abil (who, op); 2709 change_abil (who, op);
2674 who->chosen_skill = 0;
2675 CLEAR_FLAG (who, FLAG_READY_SKILL); 2710 CLEAR_FLAG (who, FLAG_READY_SKILL);
2676 break; 2711 break;
2677 2712
2678 case ARMOUR: 2713 case ARMOUR:
2679 case HELMET: 2714 case HELMET:
2684 case AMULET: 2719 case AMULET:
2685 case GIRDLE: 2720 case GIRDLE:
2686 case BRACERS: 2721 case BRACERS:
2687 case CLOAK: 2722 case CLOAK:
2688 new_draw_info_format (NDI_UNIQUE, 0, who, "You unwear %s.", query_name (op)); 2723 new_draw_info_format (NDI_UNIQUE, 0, who, "You unwear %s.", query_name (op));
2689 (void) change_abil (who, op); 2724 change_abil (who, op);
2690 break; 2725 break;
2726
2691 case LAMP: 2727 case LAMP:
2728 {
2692 new_draw_info_format (NDI_UNIQUE, 0, who, "You turn off your %s.", &op->name); 2729 new_draw_info_format (NDI_UNIQUE, 0, who, "You turn off your %s.", &op->name);
2730
2693 tmp2 = arch_to_object (op->other_arch); 2731 object *tmp2 = arch_to_object (op->other_arch);
2694 tmp2->x = op->x; 2732 tmp2->x = op->x;
2695 tmp2->y = op->y; 2733 tmp2->y = op->y;
2696 tmp2->map = op->map; 2734 tmp2->map = op->map;
2697 tmp2->below = op->below; 2735 tmp2->below = op->below;
2698 tmp2->above = op->above; 2736 tmp2->above = op->above;
2699 tmp2->stats.food = op->stats.food; 2737 tmp2->stats.food = op->stats.food;
2700 CLEAR_FLAG (tmp2, FLAG_APPLIED); 2738 CLEAR_FLAG (tmp2, FLAG_APPLIED);
2701 2739
2702 if (QUERY_FLAG (op, FLAG_INV_LOCKED)) 2740 if (QUERY_FLAG (op, FLAG_INV_LOCKED))
2703 SET_FLAG (tmp2, FLAG_INV_LOCKED); 2741 SET_FLAG (tmp2, FLAG_INV_LOCKED);
2704 2742
2705 if (who->type == PLAYER) 2743 if (who->contr)
2706 esrv_del_item (who->contr, op->count); 2744 esrv_del_item (who->contr, op->count);
2707 2745
2708 op->destroy (); 2746 op->destroy ();
2709 insert_ob_in_ob (tmp2, who); 2747 insert_ob_in_ob (tmp2, who);
2710 who->update_stats (); 2748 who->update_stats ();
2749
2711 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED)) 2750 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED))
2712 { 2751 {
2713 if (who->type == PLAYER) 2752 if (who->contr)
2714 { 2753 {
2715 new_draw_info (NDI_UNIQUE, 0, who, "Oops, it feels deadly cold!"); 2754 new_draw_info (NDI_UNIQUE, 0, who, "Oops, it feels deadly cold!");
2716 SET_FLAG (tmp2, FLAG_KNOWN_CURSED); 2755 SET_FLAG (tmp2, FLAG_KNOWN_CURSED);
2717 } 2756 }
2718 } 2757 }
2719 if (who->type == PLAYER) 2758
2759 if (who->contr)
2720 esrv_send_item (who, tmp2); 2760 esrv_send_item (who, tmp2);
2761 }
2762
2721 return 1; /* otherwise, an attempt to drop causes problems */ 2763 return 1; /* otherwise, an attempt to drop causes problems */
2722 break;
2723 2764
2724 case BOW: 2765 case BOW:
2725 case WAND: 2766 case WAND:
2726 case ROD: 2767 case ROD:
2727 case HORN: 2768 case HORN:
2728 clear_skill (who); 2769 if (player *pl = who->contr)
2729 if (who->type == PLAYER) 2770 {
2771 if (op == pl->ranged_ob)
2730 { 2772 {
2773 pl->ranged_ob = 0;
2774 who->change_weapon (pl->combat_ob);
2775 }
2776
2731 new_draw_info_format (NDI_UNIQUE, 0, who, "You unready %s.", query_name (op)); 2777 new_draw_info_format (NDI_UNIQUE, 0, who, "You unready %s.", query_name (op));
2732
2733 who->contr->ranged_skill = 0;
2734 who->contr->ranged_ob = 0;
2735 } 2778 }
2736 else 2779 else
2737 { 2780 {
2781 who->change_skill (0);
2782
2738 if (op->type == BOW) 2783 if (op->type == BOW)
2739 CLEAR_FLAG (who, FLAG_READY_BOW); 2784 CLEAR_FLAG (who, FLAG_READY_BOW);
2740 else 2785 else
2741 CLEAR_FLAG (who, FLAG_READY_RANGE); 2786 CLEAR_FLAG (who, FLAG_READY_RANGE);
2742 } 2787 }
2743 2788
2744 break; 2789 break;
2745 2790
2746 case BUILDER: 2791 case BUILDER:
2747 if (who->type == PLAYER) 2792 if (who->contr)
2748 {
2749 new_draw_info_format (NDI_UNIQUE, 0, who, "You unready %s.", query_name (op)); 2793 new_draw_info_format (NDI_UNIQUE, 0, who, "You unready %s.", query_name (op));
2750
2751 who->contr->ranged_skill = 0;
2752 who->contr->ranged_ob = 0;
2753 }
2754 break; 2794 break;
2755 2795
2756 default: 2796 default:
2757 new_draw_info_format (NDI_UNIQUE, 0, who, "You unapply %s.", query_name (op)); 2797 new_draw_info_format (NDI_UNIQUE, 0, who, "You unapply %s.", query_name (op));
2758 break; 2798 break;
2760 2800
2761 who->update_stats (); 2801 who->update_stats ();
2762 2802
2763 if (!(aflags & AP_NO_MERGE)) 2803 if (!(aflags & AP_NO_MERGE))
2764 { 2804 {
2765 object *tmp;
2766
2767 tmp = merge_ob (op, NULL); 2805 object *tmp = merge_ob (op, 0);
2768 if (who->type == PLAYER) 2806
2807 if (who->contr)
2769 { 2808 {
2770 if (tmp) 2809 if (tmp)
2771 { /* it was merged */ 2810 { /* it was merged */
2772 esrv_del_item (who->contr, op->count); 2811 esrv_del_item (who->contr, op->count);
2773 op = tmp; 2812 op = tmp;
2774 } 2813 }
2775 2814
2776 esrv_send_item (who, op); 2815 esrv_send_item (who, op);
2777 } 2816 }
2778 } 2817 }
2818
2779 return 0; 2819 return 0;
2780} 2820}
2781 2821
2782/** 2822/**
2783 * Returns the object that is using location 'loc'. 2823 * Returns the object that is using location 'loc'.
2784 * Note that 'start' is the first object to start examing - we 2824 * Note that 'start' is the first object to start examing - we
2785 * then go through the below of this. In this way, you can do 2825 * then go through the below of this. In this way, you can do
2786 * something like: 2826 * something like:
2787 * tmp = get_item_from_body_location(who->inv, 1); 2827 * tmp = get_next_item_from_body_location(who->inv, 1);
2788 * if (tmp) tmp1 = get_item_from_body_location(tmp->below, 1); 2828 * if (tmp) tmp1 = get_next_item_from_body_location(tmp->below, 1);
2789 * to find the second object that may use this location, etc. 2829 * to find the second object that may use this location, etc.
2790 * Returns NULL if no match is found. 2830 * Returns NULL if no match is found.
2791 * loc is the index into the array we are looking for a match. 2831 * loc is the index into the array we are looking for a match.
2792 * don't return invisible objects unless they are skill objects 2832 * don't return invisible objects unless they are skill objects
2793 * invisible other objects that use 2833 * invisible other objects that use
2794 * up body locations can be used as restrictions. 2834 * up body locations can be used as restrictions.
2795 */ 2835 */
2796object * 2836static object *
2797get_item_from_body_location (object *start, int loc) 2837get_next_item_from_body_location (int loc, object *start)
2798{ 2838{
2799 object *tmp;
2800
2801 if (!start)
2802 return NULL;
2803
2804 for (tmp = start; tmp; tmp = tmp->below) 2839 for (object *tmp = start; tmp; tmp = tmp->below)
2805 if (QUERY_FLAG (tmp, FLAG_APPLIED) && tmp->body_info[loc] && (!tmp->invisible || tmp->type == SKILL)) 2840 if (tmp->flag [FLAG_APPLIED]
2841 && tmp->slot[loc].info
2842 && (!tmp->invisible || tmp->type == SKILL))
2806 return tmp; 2843 return tmp;
2807 2844
2808 return NULL; 2845 return 0;
2809} 2846}
2810
2811
2812 2847
2813/** 2848/**
2814 * 'op' wants to apply an object, but can't because of other equipment. 2849 * 'op' wants to apply an object, but can't because of other equipment.
2815 * This should only be called when it is known 2850 * This should only be called when it is known
2816 * that there are objects to unapply. This makes pretty heavy 2851 * that there are objects to unapply. This makes pretty heavy
2819 * Returns 0 on success, returns 1 if there is some problem. 2854 * Returns 0 on success, returns 1 if there is some problem.
2820 * if aflags is AP_PRINT, we instead print out waht to unapply 2855 * if aflags is AP_PRINT, we instead print out waht to unapply
2821 * instead of doing it. This is a lot less code than having 2856 * instead of doing it. This is a lot less code than having
2822 * another function that does just that. 2857 * another function that does just that.
2823 */ 2858 */
2859
2860#define CANNOT_REMOVE_CURSED \
2861 "H<You cannot remove cursed or damned items, you first have to remove the curse. " \
2862 "Praying over an altar, scrolls of remove curse/damnation, " \
2863 "priests or even other players might help.>"
2864
2824int 2865int
2825unapply_for_ob (object *who, object *op, int aflags) 2866unapply_for_ob (object *who, object *op, int aflags)
2826{ 2867{
2827 int i; 2868 if (op->is_range ())
2828 object *tmp = NULL, *last;
2829
2830 /* If we are applying a shield or weapon, unapply any equipped shield
2831 * or weapons first - only allowed to use one weapon/shield at a time.
2832 */
2833 if (op->type == WEAPON || op->type == SHIELD)
2834 {
2835 for (tmp = who->inv; tmp; tmp = tmp->below) 2869 for (object *tmp = who->inv; tmp; tmp = tmp->below)
2836 {
2837 if (QUERY_FLAG (tmp, FLAG_APPLIED) && tmp->type == op->type) 2870 if (QUERY_FLAG (tmp, FLAG_APPLIED) && tmp->is_range ())
2838 {
2839 if ((aflags & AP_IGNORE_CURSE) || (aflags & AP_PRINT) || (!QUERY_FLAG (tmp, FLAG_CURSED) && !QUERY_FLAG (tmp, FLAG_DAMNED))) 2871 if ((aflags & AP_IGNORE_CURSE) || (aflags & AP_PRINT) || (!QUERY_FLAG (tmp, FLAG_CURSED) && !QUERY_FLAG (tmp, FLAG_DAMNED)))
2840 { 2872 {
2841 if (aflags & AP_PRINT) 2873 if (aflags & AP_PRINT)
2842 new_draw_info (NDI_UNIQUE, 0, who, query_name (tmp)); 2874 new_draw_info (NDI_UNIQUE, 0, who, query_name (tmp));
2843 else 2875 else
2844 unapply_special (who, tmp, aflags); 2876 unapply_special (who, tmp, aflags);
2845 } 2877 }
2846 else 2878 else
2847 { 2879 {
2848 /* In this case, we want to try and remove a cursed item. 2880 /* In this case, we want to try and remove a cursed item.
2849 * While we know it won't work, we want unapply_special to 2881 * While we know it won't work, we want unapply_special to
2850 * at least generate the message. 2882 * at least generate the message.
2851 */ 2883 */
2852 new_draw_info_format (NDI_UNIQUE, 0, who, "No matter how hard you try, you just can't\nremove %s.", query_name (tmp)); 2884 new_draw_info_format (NDI_UNIQUE, 0, who,
2885 "No matter how hard you try, you just can't remove the %s." CANNOT_REMOVE_CURSED,
2886 query_name (tmp));
2853 return 1; 2887 return 1;
2854 }
2855
2856 } 2888 }
2857 }
2858 }
2859 2889
2860 for (i = 0; i < NUM_BODY_LOCATIONS; i++) 2890 for (int i = 0; i < NUM_BODY_LOCATIONS; i++)
2861 { 2891 {
2862 /* this used up a slot that we need to free */ 2892 /* this used up a slot that we need to free */
2863 if (op->body_info[i]) 2893 if (op->slot[i].info)
2864 { 2894 {
2865 last = who->inv; 2895 object *last = who->inv;
2866 2896
2867 /* We do a while loop - may need to remove several items in order 2897 /* We do a while loop - may need to remove several items in order
2868 * to free up enough slots. 2898 * to free up enough slots.
2869 */ 2899 */
2870 while ((who->body_used[i] + op->body_info[i]) < 0) 2900 while ((who->slot[i].used + op->slot[i].info) < 0)
2871 { 2901 {
2872 tmp = get_item_from_body_location (last, i); 2902 object *tmp = get_next_item_from_body_location (i, last);
2903
2873 if (!tmp) 2904 if (!tmp)
2874 { 2905 {
2875#if 0 2906#if 0
2876 /* Not a bug - we'll get this if the player has cursed items 2907 /* Not a bug - we'll get this if the player has cursed items
2877 * equipped. 2908 * equipped.
2878 */ 2909 */
2879 LOG (llevError, "Can't find object using location %d (%s) on %s\n", i, body_locations[i].save_name, who->name); 2910 LOG (llevError, "Can't find object using location %d (%s) on %s\n", i, body_locations[i].save_name, who->name);
2880#endif 2911#endif
2881 return 1; 2912 return 1;
2882 } 2913 }
2914
2883 /* If we are just printing, we don't care about cursed status */ 2915 /* If we are just printing, we don't care about cursed status */
2884 if ((aflags & AP_IGNORE_CURSE) || (aflags & AP_PRINT) || (!(QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED)))) 2916 if ((aflags & AP_IGNORE_CURSE) || (aflags & AP_PRINT) || (!(QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED))))
2885 { 2917 {
2886 if (aflags & AP_PRINT) 2918 if (aflags & AP_PRINT)
2887 new_draw_info (NDI_UNIQUE, 0, who, query_name (tmp)); 2919 new_draw_info (NDI_UNIQUE, 0, who, query_name (tmp));
2893 /* Cursed item that we can't unequip - tell the player. 2925 /* Cursed item that we can't unequip - tell the player.
2894 * Note this could be annoying if this is just one of a few, 2926 * Note this could be annoying if this is just one of a few,
2895 * so it may not be critical (eg, putting on a ring and you have 2927 * so it may not be critical (eg, putting on a ring and you have
2896 * one cursed ring.) 2928 * one cursed ring.)
2897 */ 2929 */
2898 new_draw_info_format (NDI_UNIQUE, 0, who, "The %s just won't come off", query_name (tmp)); 2930 new_draw_info_format (NDI_UNIQUE, 0, who, "The %s just won't come off." CANNOT_REMOVE_CURSED, query_name (tmp));
2899 } 2931 }
2932
2900 last = tmp->below; 2933 last = tmp->below;
2901 } 2934 }
2902 /* if we got here, this slot is freed up - otherwise, if it wasn't freed up, the 2935 /* if we got here, this slot is freed up - otherwise, if it wasn't freed up, the
2903 * return in the !tmp would have kicked in. 2936 * return in the !tmp would have kicked in.
2904 */ 2937 */
2905 } /* if op is using this body location */ 2938 } /* if op is using this body location */
2906 } /* for body lcoations */ 2939 } /* for body lcoations */
2940
2907 return 0; 2941 return 0;
2908} 2942}
2909 2943
2910/** 2944/**
2911 * Checks to see if 'who' can apply object 'op'. 2945 * Checks to see if 'who' can apply object 'op'.
2912 * Returns 0 if apply can be done without anything special. 2946 * Returns 0 if apply can be done without anything special.
2913 * Otherwise returns a bitmask - potentially several of these may be 2947 * Otherwise returns a bitmask - potentially several of these may be
2914 * set, but largely depends on circumstance - in the future, processing 2948 * set, but largely depends on circumstance - in the future, processing
2915 * may be pruned once we know some status (eg, once CAN_APPLY_NEVER 2949 * may be pruned once we know some status (eg, once CAN_APPLY_NEVER
2916 * is set, do we really are what the other flags may be?) 2950 * is set, do we really care what the other flags may be?)
2917 * 2951 *
2918 * See include/define.h for detailed description of the meaning of 2952 * See include/define.h for detailed description of the meaning of
2919 * these return values. 2953 * these return values.
2920 */ 2954 */
2921int 2955int
2922can_apply_object (object *who, object *op) 2956can_apply_object (object *who, object *op)
2923{ 2957{
2924 if (INVOKE_OBJECT (CAN_BE_APPLIED, op, ARG_OBJECT (who)) || INVOKE_OBJECT (CAN_APPLY, who, ARG_OBJECT (op))) 2958 if (INVOKE_OBJECT (CAN_BE_APPLIED, op, ARG_OBJECT (who)) || INVOKE_OBJECT (CAN_APPLY, who, ARG_OBJECT (op)))
2925 return RESULT_INT (0); 2959 return RESULT_INT (0);
2926 2960
2927 int i, retval = 0; 2961 int retval = 0;
2928 object *tmp = NULL, *ws = NULL; 2962 object *tmp = 0, *ws = 0;
2929 2963
2930 /* Players have 2 'arm's, so they could in theory equip 2 shields or 2964 for (int i = 0; i < NUM_BODY_LOCATIONS; i++)
2931 * 2 weapons, but we don't want to let them do that. So if they are
2932 * trying to equip a weapon or shield, see if they already have one
2933 * in place and store that way.
2934 */
2935 if (op->type == WEAPON || op->type == SHIELD)
2936 { 2965 {
2937 for (tmp = who->inv; tmp && !ws; tmp = tmp->below) 2966 if (op->slot[i].info)
2938 { 2967 {
2939 if (QUERY_FLAG (tmp, FLAG_APPLIED) && tmp->type == op->type) 2968 /* Item uses more slots than we have */
2969 if (who->slot[i].info + op->slot [i].info < 0)
2940 { 2970 {
2941 retval = CAN_APPLY_UNAPPLY;
2942 ws = tmp;
2943 }
2944 }
2945 }
2946
2947 for (i = 0; i < NUM_BODY_LOCATIONS; i++)
2948 {
2949 if (op->body_info[i])
2950 {
2951 /* Item uses more slots than we have */
2952 if (FABS (op->body_info[i]) > who->body_info[i])
2953 {
2954 /* Could return now for efficiently - rest of info below isn' 2971 /* Could return now for efficiency - rest of info below isn't
2955 * really needed. 2972 * really needed.
2956 */ 2973 */
2957 retval |= CAN_APPLY_NEVER; 2974 retval |= CAN_APPLY_NEVER;
2958 } 2975 }
2959 else if ((who->body_used[i] + op->body_info[i]) < 0) 2976 else if (who->slot[i].used + op->slot[i].info < 0)
2960 { 2977 {
2961 /* in this case, equipping this would use more free spots than 2978 /* in this case, equipping this would use more free spots than
2962 * we have. 2979 * we have.
2963 */ 2980 */
2964 object *tmp1;
2965
2966 2981
2967 /* if we have an applied weapon/shield, and unapply it would free 2982 /* if we have an applied weapon/shield, and unapply it would free
2968 * enough slots to equip the new item, then just set this can 2983 * enough slots to equip the new item, then just set "can
2969 * continue. We don't care about the logic below - if you have 2984 * apply unapply". We don't care about the logic below - if you have a
2970 * shield equipped and try to equip another shield, there is only 2985 * shield equipped and try to equip another shield, there is only
2971 * one choice. However, the check for the number of body locations 2986 * one choice. However, the check for the number of body locations
2972 * does take into the account cases where what is being applied 2987 * does take into the account cases where what is being applied
2973 * may be two handed for example. 2988 * may be two handed for example.
2974 */ 2989 */
2975 if (ws) 2990 if (ws)
2976 { 2991 if ((who->slot[i].used - ws->slot[i].info + op->slot[i].info) >= 0)
2977 if ((who->body_used[i] - ws->body_info[i] + op->body_info[i]) >= 0)
2978 { 2992 {
2979 retval |= CAN_APPLY_UNAPPLY; 2993 retval |= CAN_APPLY_UNAPPLY;
2980 continue; 2994 continue;
2981 } 2995 }
2982 }
2983 2996
2984 tmp1 = get_item_from_body_location (who->inv, i); 2997 object *tmp1 = get_next_item_from_body_location (i, who->inv);
2985 if (!tmp1) 2998 if (!tmp1)
2986 { 2999 {
2987#if 0 3000#if 0
2988 /* This is sort of an error, but happens a lot when old players 3001 /* This is sort of an error, but happens a lot when old players
2989 * join in with more stuff equipped than they are now allowed. 3002 * join in with more stuff equipped than they are now allowed.
2997 /* need to unapply something. However, if this something 3010 /* need to unapply something. However, if this something
2998 * is different than we had found before, it means they need 3011 * is different than we had found before, it means they need
2999 * to apply multiple objects 3012 * to apply multiple objects
3000 */ 3013 */
3001 retval |= CAN_APPLY_UNAPPLY; 3014 retval |= CAN_APPLY_UNAPPLY;
3015
3002 if (!tmp) 3016 if (!tmp)
3003 tmp = tmp1; 3017 tmp = tmp1;
3004 else if (tmp != tmp1) 3018 else if (tmp != tmp1)
3005 {
3006 retval |= CAN_APPLY_UNAPPLY_MULT; 3019 retval |= CAN_APPLY_UNAPPLY_MULT;
3007 } 3020
3008 /* This object isn't using up all the slots, so there must 3021 /* This object isn't using up all the slots, so there must
3009 * be another. If so, and it the new item doesn't need all 3022 * be another. If so, and it the new item doesn't need all
3010 * the slots, the player then has a choice. 3023 * the slots, the player then has a choice.
3011 */ 3024 */
3012 if (((who->body_used[i] - tmp1->body_info[i]) != who->body_info[i]) && (FABS (op->body_info[i]) < who->body_info[i])) 3025 if ((who->slot[i].used - tmp1->slot[i].info != who->slot[i].info)
3026 && abs (op->slot[i].info) < who->slot[i].info)
3013 retval |= CAN_APPLY_UNAPPLY_CHOICE; 3027 retval |= CAN_APPLY_UNAPPLY_CHOICE;
3014 3028
3015 /* Does unequippint 'tmp1' free up enough slots for this to be 3029 /* Does unequippint 'tmp1' free up enough slots for this to be
3016 * equipped? If not, there must be something else to unapply. 3030 * equipped? If not, there must be something else to unapply.
3017 */ 3031 */
3018 if ((who->body_used[i] + op->body_info[i] - tmp1->body_info[i]) < 0) 3032 if (who->slot[i].used + op->slot[i].info < tmp1->slot[i].info)
3019 retval |= CAN_APPLY_UNAPPLY_MULT; 3033 retval |= CAN_APPLY_UNAPPLY_MULT;
3020
3021 } 3034 }
3022 } /* if not enough free slots */ 3035 } /* if not enough free slots */
3023 } /* if this object uses location i */ 3036 } /* if this object uses location i */
3024 } /* for i -> num_body_locations loop */ 3037 } /* for i -> num_body_locations loop */
3025 3038
3038 3051
3039 if (who->type != PLAYER) 3052 if (who->type != PLAYER)
3040 { 3053 {
3041 if ((op->type == WAND || op->type == HORN || op->type == ROD) && !QUERY_FLAG (who, FLAG_USE_RANGE)) 3054 if ((op->type == WAND || op->type == HORN || op->type == ROD) && !QUERY_FLAG (who, FLAG_USE_RANGE))
3042 retval |= CAN_APPLY_RESTRICTION; 3055 retval |= CAN_APPLY_RESTRICTION;
3056
3043 if (op->type == BOW && !QUERY_FLAG (who, FLAG_USE_BOW)) 3057 if (op->type == BOW && !QUERY_FLAG (who, FLAG_USE_BOW))
3044 retval |= CAN_APPLY_RESTRICTION; 3058 retval |= CAN_APPLY_RESTRICTION;
3059
3045 if (op->type == RING && !QUERY_FLAG (who, FLAG_USE_RING)) 3060 if (op->type == RING && !QUERY_FLAG (who, FLAG_USE_RING))
3046 retval |= CAN_APPLY_RESTRICTION; 3061 retval |= CAN_APPLY_RESTRICTION;
3062
3047 if (op->type == BOW && !QUERY_FLAG (who, FLAG_USE_BOW)) 3063 if (op->type == BOW && !QUERY_FLAG (who, FLAG_USE_BOW))
3048 retval |= CAN_APPLY_RESTRICTION; 3064 retval |= CAN_APPLY_RESTRICTION;
3049 } 3065 }
3050 3066
3051 return retval; 3067 return retval;
3066 * AP_UNAPPLY=always unapply). 3082 * AP_UNAPPLY=always unapply).
3067 * 3083 *
3068 * Optional flags: 3084 * Optional flags:
3069 * AP_NO_MERGE: don't merge an unapplied object with other objects 3085 * AP_NO_MERGE: don't merge an unapplied object with other objects
3070 * AP_IGNORE_CURSE: unapply cursed items 3086 * AP_IGNORE_CURSE: unapply cursed items
3087 * AP_NO_READY: do not ready skills when applying skill tools
3071 * 3088 *
3072 * Usage example: apply_special (who, op, AP_UNAPPLY | AP_IGNORE_CURSE) 3089 * Usage example: apply_special (who, op, AP_UNAPPLY | AP_IGNORE_CURSE)
3073 * 3090 *
3074 * apply_special() doesn't check for unpaid items. 3091 * apply_special() doesn't check for unpaid items.
3075 */ 3092 */
3093
3094#define LACK_ITEM_POWER \
3095 " H<You lack enough unused item power to use this weapon, see the skills command.>"
3096
3076int 3097int
3077apply_special (object *who, object *op, int aflags) 3098apply_special (object *who, object *op, int aflags)
3078{ 3099{
3079 int basic_flag = aflags & AP_BASIC_FLAGS; 3100 int basic_flag = aflags & AP_BASIC_FLAGS;
3080 object *tmp, *tmp2, *skop = NULL; 3101 object *tmp, *tmp2, *skop = NULL;
3081 int i;
3082 3102
3083 if (who == NULL) 3103 if (who == NULL)
3084 { 3104 {
3085 LOG (llevError, "apply_special() from object without environment.\n"); 3105 LOG (llevError, "apply_special() from object without environment.\n");
3086 return 1; 3106 return 1;
3096 if (basic_flag == AP_APPLY) 3116 if (basic_flag == AP_APPLY)
3097 return 0; 3117 return 0;
3098 3118
3099 if (!(aflags & AP_IGNORE_CURSE) && (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED))) 3119 if (!(aflags & AP_IGNORE_CURSE) && (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED)))
3100 { 3120 {
3101 new_draw_info_format (NDI_UNIQUE, 0, who, "No matter how hard you try, you just can't\nremove %s.", query_name (op)); 3121 new_draw_info_format (NDI_UNIQUE, 0, who,
3122 "No matter how hard you try, you just can't remove %s." CANNOT_REMOVE_CURSED,
3123 query_name (op));
3102 return 1; 3124 return 1;
3103 } 3125 }
3126
3104 return unapply_special (who, op, aflags); 3127 return unapply_special (who, op, aflags);
3105 } 3128 }
3106 3129
3107 if (basic_flag == AP_UNAPPLY) 3130 if (basic_flag == AP_UNAPPLY)
3108 return 0; 3131 return 0;
3109 3132
3110 i = can_apply_object (who, op); 3133 // if the item is combat/ranged, wield the relevant slot first
3134 // to resolve conflicts.
3135 if (player *pl = who->contr)
3136 switch (op->slottype ())
3137 {
3138 case slot_combat: who->change_weapon (pl->combat_ob); break;
3139 case slot_ranged: who->change_weapon (pl->ranged_ob); break;
3140 }
3141
3142 splay (op);
3111 3143
3112 /* Can't just apply this object. Lets see what not and what to do */ 3144 /* Can't just apply this object. Lets see what not and what to do */
3113 if (i) 3145 if (int i = can_apply_object (who, op))
3114 { 3146 {
3115 if (i & CAN_APPLY_NEVER) 3147 if (i & CAN_APPLY_NEVER)
3116 { 3148 {
3117 new_draw_info_format (NDI_UNIQUE, 0, who, "You don't have the body to use a %s\n", query_name (op)); 3149 new_draw_info_format (NDI_UNIQUE, 0, who,
3150 "You don't have the body to use a %s. H<You can never apply this item.>",
3151 query_name (op));
3118 return 1; 3152 return 1;
3119 } 3153 }
3120 else if (i & CAN_APPLY_RESTRICTION) 3154 else if (i & CAN_APPLY_RESTRICTION)
3121 { 3155 {
3122 new_draw_info_format (NDI_UNIQUE, 0, who, "You have a prohibition against using a %s\n", query_name (op)); 3156 new_draw_info_format (NDI_UNIQUE, 0, who,
3157 "You have a prohibition against using a %s. "
3158 "H<Your belief, profession or class prevents you from applying this item.>",
3159 query_name (op));
3123 return 1; 3160 return 1;
3124 } 3161 }
3162
3125 if (who->type != PLAYER) 3163 if (who->type != PLAYER)
3126 { 3164 {
3127 /* Some error, so don't try to equip something more */ 3165 /* Some error, so don't try to equip something more */
3128 if (unapply_for_ob (who, op, aflags)) 3166 if (unapply_for_ob (who, op, aflags))
3129 return 1; 3167 return 1;
3135 new_draw_info (NDI_UNIQUE, 0, who, "You need to unapply some of the following item(s) or change your applymode:"); 3173 new_draw_info (NDI_UNIQUE, 0, who, "You need to unapply some of the following item(s) or change your applymode:");
3136 unapply_for_ob (who, op, AP_PRINT); 3174 unapply_for_ob (who, op, AP_PRINT);
3137 return 1; 3175 return 1;
3138 } 3176 }
3139 else if (who->contr->unapply == unapply_always || !(i & CAN_APPLY_UNAPPLY_CHOICE)) 3177 else if (who->contr->unapply == unapply_always || !(i & CAN_APPLY_UNAPPLY_CHOICE))
3140 {
3141 i = unapply_for_ob (who, op, aflags); 3178 if (unapply_for_ob (who, op, aflags))
3142 if (i)
3143 return 1; 3179 return 1;
3144 }
3145 } 3180 }
3146 } 3181 }
3147 3182
3148 if (op->skill && op->type != SKILL && op->type != SKILL_TOOL) 3183 if (op->skill && op->type != SKILL && op->type != SKILL_TOOL)
3149 { 3184 {
3150 skop = find_skill_by_name (who, op->skill); 3185 skop = find_skill_by_name (who, op->skill);
3186
3151 if (!skop) 3187 if (!skop)
3152 { 3188 {
3153 new_draw_info_format (NDI_UNIQUE, 0, who, "You need the %s skill to use this item!", &op->skill); 3189 new_draw_info_format (NDI_UNIQUE, 0, who, "You need the %s skill to use this item!", &op->skill);
3154 return 1; 3190 return 1;
3155 } 3191 }
3156 else 3192 else
3157 /* While experience will be credited properly, we want to change the 3193 /* While experience will be credited properly, we want to change the
3158 * skill so that the dam and wc get updated 3194 * skill so that the dam and wc get updated
3159 */ 3195 */
3160 change_skill (who, skop, 0); 3196 who->change_skill (skop);
3161 } 3197 }
3162 3198
3199 if (who->type == PLAYER
3200 && op->item_power
3163 if (who->type == PLAYER && op->item_power && (op->item_power + who->contr->item_power) > (settings.item_power_factor * who->level)) 3201 && op->item_power + who->contr->item_power > settings.item_power_factor * who->level)
3164 { 3202 {
3165 new_draw_info (NDI_UNIQUE, 0, who, 3203 new_draw_info (NDI_UNIQUE, 0, who,
3166 "Equipping that combined with other items would consume your soul! " 3204 "Equipping that combined with other items would consume your soul!" LACK_ITEM_POWER);
3167 "[use the skills command to check your available item power]");
3168 return 1; 3205 return 1;
3169 } 3206 }
3170
3171 3207
3172 /* Ok. We are now at the state where we can apply the new object. 3208 /* Ok. We are now at the state where we can apply the new object.
3173 * Note that we don't have the checks for can_use_... 3209 * Note that we don't have the checks for can_use_...
3174 * below - that is already taken care of by can_apply_object. 3210 * below - that is already taken care of by can_apply_object.
3175 */ 3211 */
3176
3177 if (op->nrof > 1) 3212 if (op->nrof > 1)
3178 tmp = get_split_ob (op, op->nrof - 1); 3213 tmp = get_split_ob (op, op->nrof - 1);
3179 else 3214 else
3180 tmp = NULL; 3215 tmp = 0;
3181 3216
3182 if (INVOKE_OBJECT (BE_READY, op, ARG_OBJECT (who)) || INVOKE_OBJECT (READY, who, ARG_OBJECT (op))) 3217 if (INVOKE_OBJECT (BE_READY, op, ARG_OBJECT (who)) || INVOKE_OBJECT (READY, who, ARG_OBJECT (op)))
3183 return RESULT_INT (0); 3218 return RESULT_INT (0);
3184 3219
3185 switch (op->type) 3220 switch (op->type)
3186 { 3221 {
3187 case WEAPON: 3222 case WEAPON:
3188 if (!check_weapon_power (who, op->last_eat)) 3223 if (!check_weapon_power (who, op->last_eat))
3189 { 3224 {
3190 new_draw_info (NDI_UNIQUE, 0, who, "That weapon is too powerful for you to use."); 3225 new_draw_info (NDI_UNIQUE, 0, who, "This weapon is too powerful for you to use. "
3191 new_draw_info (NDI_UNIQUE, 0, who, "It would consume your soul!."); 3226 "It would consume your soul!." LACK_ITEM_POWER);
3227
3192 if (tmp != NULL) 3228 if (tmp)
3193 (void) insert_ob_in_ob (tmp, who); 3229 insert_ob_in_ob (tmp, who);
3230
3194 return 1; 3231 return 1;
3195 } 3232 }
3196 3233
3197 //TODO: this obviously fails for players using a shiorter prefix 3234 //TODO: this obviously fails for players using a shorter prefix
3198 // i.e. "R" can use Ragnarok's swors. 3235 // i.e. "R" can use Ragnarok's sword.
3199 if (op->level && (strncmp (op->name, who->name, strlen (who->name)))) 3236 if (op->level && (strncmp (op->name, who->name, strlen (who->name))))
3200 { 3237 {
3201 /* if the weapon does not have the name as the character, can't use it. */ 3238 /* if the weapon does not have the name as the character, can't use it. */
3202 /* (Ragnarok's sword attempted to be used by Foo: won't work) */ 3239 /* (Ragnarok's sword attempted to be used by Foo: won't work) */
3203 new_draw_info (NDI_UNIQUE, 0, who, "The weapon does not recognize you as its owner."); 3240 new_draw_info (NDI_UNIQUE, 0, who,
3241 "The weapon does not recognize you as its owner. "
3242 "H<Its name indicates that it belongs to somebody else.>");
3204 3243
3205 if (tmp) 3244 if (tmp)
3206 insert_ob_in_ob (tmp, who); 3245 insert_ob_in_ob (tmp, who);
3207 3246
3208 return 1; 3247 return 1;
3209 } 3248 }
3210 3249
3250 if (!skop)
3251 {
3252 new_draw_info_format (NDI_UNIQUE, 0, who, "The %s is broken, please report this to the dungeon master!", query_name (op));//TODO
3253 return 1;
3254 }
3255
3211 SET_FLAG (op, FLAG_APPLIED); 3256 SET_FLAG (op, FLAG_APPLIED);
3212
3213 if (skop)
3214 change_skill (who, skop, 1); 3257 who->change_skill (skop);
3215 3258
3216 if (!QUERY_FLAG (who, FLAG_READY_WEAPON)) 3259 if (who->contr)
3217 SET_FLAG (who, FLAG_READY_WEAPON); 3260 who->change_weapon (who->contr->combat_ob = op);
3218 3261
3219 new_draw_info_format (NDI_UNIQUE, 0, who, "You wield %s.", query_name (op)); 3262 new_draw_info_format (NDI_UNIQUE, 0, who, "You wield %s.", query_name (op));
3220 3263
3264 SET_FLAG (who, FLAG_READY_WEAPON);
3221 change_abil (who, op); 3265 change_abil (who, op);
3222 break; 3266 break;
3223 3267
3224 case ARMOUR: 3268 case ARMOUR:
3225 case HELMET: 3269 case HELMET:
3237 break; 3281 break;
3238 3282
3239 case LAMP: 3283 case LAMP:
3240 if (op->stats.food < 1) 3284 if (op->stats.food < 1)
3241 { 3285 {
3242 new_draw_info_format (NDI_UNIQUE, 0, who, "Your %s is out of" " fuel!", &op->name); 3286 new_draw_info_format (NDI_UNIQUE, 0, who,
3287 "Your %s is out of fuel! "
3288 "H<Lamps and similar items need fuel. They cannot be refilled.>", &op->name);
3243 return 1; 3289 return 1;
3244 } 3290 }
3245 3291
3246 new_draw_info_format (NDI_UNIQUE, 0, who, "You turn on your %s.", &op->name); 3292 new_draw_info_format (NDI_UNIQUE, 0, who, "You turn on your %s.", &op->name);
3247 tmp2 = arch_to_object (op->other_arch); 3293 tmp2 = arch_to_object (op->other_arch);
3268 } 3314 }
3269 3315
3270 who->update_stats (); 3316 who->update_stats ();
3271 3317
3272 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED)) 3318 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED))
3273 {
3274 if (who->type == PLAYER) 3319 if (who->type == PLAYER)
3275 { 3320 {
3276 new_draw_info (NDI_UNIQUE, 0, who, "Oops, it feels deadly cold!"); 3321 new_draw_info (NDI_UNIQUE, 0, who,
3322 "Oops, it feels deadly cold! "
3323 "H<Maybe it wasn't such a bright idea to apply this cursed/damned item.>");
3277 SET_FLAG (tmp2, FLAG_KNOWN_CURSED); 3324 SET_FLAG (tmp2, FLAG_KNOWN_CURSED);
3278 } 3325 }
3279 }
3280 3326
3281 if (who->type == PLAYER) 3327 if (who->type == PLAYER)
3282 esrv_send_item (who, tmp2); 3328 esrv_send_item (who, tmp2);
3283 3329
3284 return 0; 3330 return 0;
3285 3331
3286 /* this part is needed for skill-tools */ 3332 case SKILL_TOOL:
3333 // applying a skill tool also readies the skill
3334 SET_FLAG (op, FLAG_APPLIED);
3335
3336 if (!(aflags & AP_NO_READY))
3337 {
3338 skop = find_skill_by_name (who, op->skill);
3339 if (!skop->flag [FLAG_APPLIED])
3340 apply_special (who, skop, AP_APPLY);
3341 }
3342 break;
3343
3287 case SKILL: 3344 case SKILL:
3288 case SKILL_TOOL: 3345 if (player *pl = who->contr)
3289 if (who->chosen_skill)
3290 {
3291 LOG (llevError, "BUG: apply_special(): can't apply two skills\n");
3292 return 1;
3293 } 3346 {
3294 3347 if (IS_COMBAT_SKILL (op->subtype))
3295 if (who->type == PLAYER)
3296 { 3348 {
3297 who->contr->ranged_skill = who; 3349 if (skill_flags [op->subtype] & SF_NEED_WEAPON)
3298 who->contr->ranged_ob = op; 3350 {
3351 for (object *item = who->inv; item; item = item->below)
3352 if (item->type == WEAPON && item->flag [FLAG_APPLIED])
3353 {
3354 if (item->skill == op->skill)
3355 {
3356 who->change_weapon (pl->combat_ob = item);
3357 goto found_weapon;
3358 }
3359 }
3360
3361 new_draw_info_format (NDI_UNIQUE, 0, who,
3362 "You need to apply a '%s' melee weapon before readying this skill. "
3363 "H<Some skills need an item, in this case a melee weapon, to function.>",
3364 &op->skill);
3365 return 1;
3366
3367 found_weapon:;
3368 }
3369 else
3370 who->change_weapon (pl->combat_ob = op);
3371 }
3372 else if (IS_RANGED_SKILL (op->subtype))
3373 {
3374 if (skill_flags [op->subtype] & SF_NEED_BOW)
3375 {
3376 for (object *item = who->inv; item; item = item->below)
3377 if (item->type == BOW && item->flag [FLAG_APPLIED])
3378 {
3379 //TODO: bows should/must all have skill missile weapon right now
3380 who->change_weapon (pl->ranged_ob = item);
3381 goto found_bow;
3382 }
3383
3384 new_draw_info (NDI_UNIQUE, 0, who,
3385 "You need to apply a missile weapon before readying this skill. "
3386 "H<Some skills need an item, in this case a missile weapon, to function.>");
3387 return 1;
3388
3389 found_bow:;
3390 }
3391 else
3392 who->change_weapon (pl->ranged_ob = op);
3393 }
3299 3394
3300 if (!op->invisible) 3395 if (!op->invisible)
3301 { 3396 {
3302 new_draw_info_format (NDI_UNIQUE, 0, who, "You ready %s.", query_name (op)); 3397 new_draw_info_format (NDI_UNIQUE, 0, who, "You ready %s.", query_name (op));
3303 new_draw_info_format (NDI_UNIQUE, 0, who, "You can now use the skill: %s.", &op->skill); 3398 new_draw_info_format (NDI_UNIQUE, 0, who, "You can now use the skill: %s.", &op->skill);
3304 } 3399 }
3305 else 3400 else
3306 new_draw_info_format (NDI_UNIQUE, 0, who, "Readied skill: %s.", op->skill ? &op->skill : &op->name); 3401 new_draw_info_format (NDI_UNIQUE, 0, who, "Readied skill: %s.", op->skill ? &op->skill : &op->name);
3307 } 3402 }
3308 3403 else
3404 {
3309 SET_FLAG (op, FLAG_APPLIED); 3405 SET_FLAG (op, FLAG_APPLIED);
3310 change_abil (who, op); 3406 change_abil (who, op);
3311 who->chosen_skill = op; 3407 who->chosen_skill = op;
3312 SET_FLAG (who, FLAG_READY_SKILL); 3408 SET_FLAG (who, FLAG_READY_SKILL);
3409 }
3410
3313 break; 3411 break;
3314 3412
3315 case BOW: 3413 case BOW:
3316 if (!check_weapon_power (who, op->last_eat)) 3414 if (!check_weapon_power (who, op->last_eat))
3317 { 3415 {
3318 new_draw_info (NDI_UNIQUE, 0, who, "That item is too powerful for you to use."); 3416 new_draw_info (NDI_UNIQUE, 0, who,
3319 new_draw_info (NDI_UNIQUE, 0, who, "It would consume your soul!."); 3417 "That weapon is too powerful for you to use. It would consume your soul!" LACK_ITEM_POWER);
3320 3418
3321 if (tmp) 3419 if (tmp)
3322 insert_ob_in_ob (tmp, who); 3420 insert_ob_in_ob (tmp, who);
3323 3421
3324 return 1; 3422 return 1;
3325 } 3423 }
3326 3424
3327 if (op->level && (strncmp (op->name, who->name, strlen (who->name)))) 3425 if (op->level && (strncmp (op->name, who->name, strlen (who->name))))
3328 { 3426 {
3329 new_draw_info (NDI_UNIQUE, 0, who, "The weapon does not recognize you as its owner."); 3427 new_draw_info (NDI_UNIQUE, 0, who,
3428 "The weapon does not recognize you as its owner. "
3429 "H<Its name indicates that it belongs to somebody else.>");
3330 if (tmp != NULL) 3430 if (tmp)
3331 insert_ob_in_ob (tmp, who); 3431 insert_ob_in_ob (tmp, who);
3332 3432
3333 return 1; 3433 return 1;
3334 } 3434 }
3335 3435
3336 /*FALLTHROUGH*/ 3436 /*FALLTHROUGH*/
3337 case WAND: 3437 case WAND:
3338 case ROD: 3438 case ROD:
3339 case HORN: 3439 case HORN:
3340 /* check for skill, alter player status */ 3440 /* check for skill, alter player status */
3441
3442 if (!skop)
3443 {
3444 new_draw_info_format (NDI_UNIQUE, 0, who, "The %s is broken, please report this to the dungeon master!", query_name (op));//TODO
3445 return 1;
3446 }
3447
3341 SET_FLAG (op, FLAG_APPLIED); 3448 SET_FLAG (op, FLAG_APPLIED);
3342 if (skop)
3343 change_skill (who, skop, 0); 3449 who->change_skill (skop);
3344 3450
3345 if (who->type == PLAYER) 3451 if (who->contr)
3346 { 3452 {
3453 who->contr->ranged_ob = op;
3454
3347 new_draw_info_format (NDI_UNIQUE, 0, who, "You ready %s.", query_name (op)); 3455 new_draw_info_format (NDI_UNIQUE, 0, who, "You ready %s.", query_name (op));
3348 3456
3349 if (op->type == BOW) 3457 if (op->type == BOW)
3350 { 3458 {
3459 who->current_weapon = op;
3351 change_abil (who, op); 3460 change_abil (who, op);
3352 new_draw_info_format (NDI_UNIQUE, 0, who, 3461 new_draw_info_format (NDI_UNIQUE, 0, who,
3353 "You will now fire %s with %s.", op->race ? &op->race : "nothing", query_name (op)); 3462 "You will now fire %s with %s.", op->race ? &op->race : "nothing", query_name (op));
3354 } 3463 }
3355
3356 who->contr->ranged_skill = find_skill_by_name (who, op->skill);//TODO
3357 who->contr->ranged_ob = op;
3358 } 3464 }
3359 else 3465 else
3360 { 3466 {
3361 if (op->type == BOW) 3467 if (op->type == BOW)
3362 SET_FLAG (who, FLAG_READY_BOW); 3468 SET_FLAG (who, FLAG_READY_BOW);
3367 break; 3473 break;
3368 3474
3369 case BUILDER: 3475 case BUILDER:
3370 if (who->type == PLAYER) 3476 if (who->type == PLAYER)
3371 { 3477 {
3478 //TODO: wtf does this do? shouldn't this be managed automatically (slots?)
3372 if (who->contr->ranged_ob && who->contr->ranged_ob->type == BUILDER) 3479 if (who->contr->ranged_ob && who->contr->ranged_ob->type == BUILDER)
3373 unapply_special (who, who->contr->ranged_ob, 0); 3480 unapply_special (who, who->contr->ranged_ob, 0);
3374 3481
3375 new_draw_info_format (NDI_UNIQUE, 0, who, "You ready your %s.", query_name (op)); 3482 new_draw_info_format (NDI_UNIQUE, 0, who, "You ready your %s.", query_name (op));
3376 3483
3377 who->contr->ranged_skill = who;
3378 who->contr->ranged_ob = op; 3484 who->contr->ranged_ob = op;
3379 } 3485 }
3380 break; 3486 break;
3381 3487
3382 default: 3488 default:
3383 new_draw_info_format (NDI_UNIQUE, 0, who, "You apply %s.", query_name (op)); 3489 new_draw_info_format (NDI_UNIQUE, 0, who, "You apply %s.", query_name (op));
3384 } /* end of switch op->type */ 3490 } /* end of switch op->type */
3385 3491
3386 SET_FLAG (op, FLAG_APPLIED); 3492 SET_FLAG (op, FLAG_APPLIED);
3387 3493
3388 if (tmp != NULL) 3494 if (tmp)
3389 tmp = insert_ob_in_ob (tmp, who); 3495 tmp = insert_ob_in_ob (tmp, who);
3390 3496
3391 who->update_stats (); 3497 who->update_stats ();
3392 3498
3393 /* We exclude spell casting objects. The fire code will set the 3499 /* We exclude spell casting objects. The fire code will set the
3396 */ 3502 */
3397 if (who->type == PLAYER && op->type != WAND && op->type != HORN && op->type != ROD) 3503 if (who->type == PLAYER && op->type != WAND && op->type != HORN && op->type != ROD)
3398 SET_FLAG (op, FLAG_BEEN_APPLIED); 3504 SET_FLAG (op, FLAG_BEEN_APPLIED);
3399 3505
3400 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED)) 3506 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED))
3401 {
3402 if (who->type == PLAYER) 3507 if (who->type == PLAYER)
3403 { 3508 {
3404 new_draw_info (NDI_UNIQUE, 0, who, "Oops, it feels deadly cold!"); 3509 new_draw_info (NDI_UNIQUE, 0, who,
3510 "Oops, it feels deadly cold! "
3511 "H<Maybe it wasn't such a bright idea to apply this cursed/damned item.>");
3405 SET_FLAG (op, FLAG_KNOWN_CURSED); 3512 SET_FLAG (op, FLAG_KNOWN_CURSED);
3406 } 3513 }
3407 }
3408 3514
3409 if (who->type == PLAYER) 3515 if (who->type == PLAYER)
3410 { 3516 {
3411 /* if multiple objects were applied, update both slots */ 3517 /* if multiple objects were applied, update both slots */
3412 if (tmp) 3518 if (tmp)
3421int 3527int
3422monster_apply_special (object *who, object *op, int aflags) 3528monster_apply_special (object *who, object *op, int aflags)
3423{ 3529{
3424 if (QUERY_FLAG (op, FLAG_UNPAID) && !QUERY_FLAG (op, FLAG_APPLIED)) 3530 if (QUERY_FLAG (op, FLAG_UNPAID) && !QUERY_FLAG (op, FLAG_APPLIED))
3425 return 1; 3531 return 1;
3532
3426 return apply_special (who, op, aflags); 3533 return apply_special (who, op, aflags);
3427} 3534}
3428 3535
3429/** 3536/**
3430 * Map was just loaded, handle op's initialisation. 3537 * Map was just loaded, handle op's initialisation.
3583 && tmp->type != PLAYER_CHANGER && tmp->type != CLASS && tmp->has_random_items ()) 3690 && tmp->type != PLAYER_CHANGER && tmp->type != CLASS && tmp->has_random_items ())
3584 { 3691 {
3585 create_treasure (tmp->randomitems, tmp, GT_APPLY, difficulty, 0); 3692 create_treasure (tmp->randomitems, tmp, GT_APPLY, difficulty, 0);
3586 tmp->randomitems = NULL; 3693 tmp->randomitems = NULL;
3587 } 3694 }
3695
3588 // close all containers 3696 // close all containers
3589 else if (tmp->type == CONTAINER) 3697 else if (tmp->type == CONTAINER)
3590 tmp->flag [FLAG_APPLIED] = 0; 3698 tmp->flag [FLAG_APPLIED] = 0;
3591 3699
3592 tmp = above; 3700 tmp = above;
3602 * Handles player eating food that temporarily changes status (resistances, stats). 3710 * Handles player eating food that temporarily changes status (resistances, stats).
3603 * This used to call cast_change_attr(), but 3711 * This used to call cast_change_attr(), but
3604 * that doesn't work with the new spell code. Since we know what 3712 * that doesn't work with the new spell code. Since we know what
3605 * the food changes, just grab a force and use that instead. 3713 * the food changes, just grab a force and use that instead.
3606 */ 3714 */
3607
3608void 3715void
3609eat_special_food (object *who, object *food) 3716eat_special_food (object *who, object *food)
3610{ 3717{
3611 object *force; 3718 object *force;
3612 int i, did_one = 0; 3719 int i, did_one = 0;
3613 sint8 k;
3614 3720
3615 force = get_archetype (FORCE_NAME); 3721 force = get_archetype (FORCE_NAME);
3616 3722
3617 for (i = 0; i < NUM_STATS; i++) 3723 for (i = 0; i < NUM_STATS; i++)
3618 { 3724 if (sint8 k = food->stats.stat (i))
3619 k = get_attr_value (&food->stats, i);
3620 if (k)
3621 { 3725 {
3622 set_attr_value (&force->stats, i, k); 3726 force->stats.stat (i) = k;
3623 did_one = 1; 3727 did_one = 1;
3624 } 3728 }
3625 }
3626 3729
3627 /* check if we can protect the eater */ 3730 /* check if we can protect the eater */
3628 for (i = 0; i < NROFATTACKS; i++) 3731 for (i = 0; i < NROFATTACKS; i++)
3629 { 3732 {
3630 if (food->resist[i] > 0) 3733 if (food->resist[i] > 0)
3760 3863
3761 if (failure <= -1 && failure > -15) 3864 if (failure <= -1 && failure > -15)
3762 { /* wonder */ 3865 { /* wonder */
3763 object *tmp; 3866 object *tmp;
3764 3867
3765 new_draw_info (NDI_UNIQUE, 0, op, "Your spell warps!."); 3868 new_draw_info (NDI_UNIQUE, 0, op, "Your spell warps!");
3766 tmp = get_archetype (SPELL_WONDER); 3869 tmp = get_archetype (SPELL_WONDER);
3767 cast_wonder (op, op, 0, tmp); 3870 cast_wonder (op, op, 0, tmp);
3768 tmp->destroy (); 3871 tmp->destroy ();
3769 } 3872 }
3770 else if (failure <= -15 && failure > -35) 3873 else if (failure <= -15 && failure > -35)
3791 new_draw_info (NDI_UNIQUE, 0, op, "The magic recoils on you!"); 3894 new_draw_info (NDI_UNIQUE, 0, op, "The magic recoils on you!");
3792 blind_player (op, op, power); 3895 blind_player (op, op, power);
3793 } 3896 }
3794 else if (failure <= -80) 3897 else if (failure <= -80)
3795 { /* blast the immediate area */ 3898 { /* blast the immediate area */
3796 object *tmp;
3797
3798 tmp = get_archetype (LOOSE_MANA); 3899 object *tmp = get_archetype (LOOSE_MANA);
3799 cast_magic_storm (op, tmp, power); 3900 cast_magic_storm (op, tmp, power);
3800 new_draw_info (NDI_UNIQUE, 0, op, "You unlease uncontrolled mana!"); 3901 new_draw_info (NDI_UNIQUE, 0, op, "You unleash uncontrolled mana!");
3801 tmp->destroy (); 3902 tmp->destroy ();
3802 } 3903 }
3803 } 3904 }
3804} 3905}
3805 3906
3825 */ 3926 */
3826 int i, j; 3927 int i, j;
3827 3928
3828 for (i = 0; i < NUM_STATS; i++) 3929 for (i = 0; i < NUM_STATS; i++)
3829 { 3930 {
3830 sint8 stat = get_attr_value (stats, i); 3931 int race_bonus = pl->arch->stats.stat (i);
3831 int race_bonus = get_attr_value (&(pl->arch->clone.stats), i); 3932 sint8 stat = stats->stat (i) + ns->stat (i);
3832 3933
3833 stat += get_attr_value (ns, i);
3834 if (stat > 20 + race_bonus) 3934 if (stat > 20 + race_bonus)
3835 { 3935 {
3836 excess_stat++; 3936 excess_stat++;
3837 stat = 20 + race_bonus; 3937 stat = 20 + race_bonus;
3838 } 3938 }
3839 set_attr_value (stats, i, stat); 3939
3940 stats->stat (i) = stat;
3840 } 3941 }
3841 3942
3842 for (j = 0; excess_stat > 0 && j < 100; j++) 3943 for (j = 0; excess_stat > 0 && j < 100; j++)
3843 { /* try 100 times to assign excess stats */ 3944 { /* try 100 times to assign excess stats */
3844 int i = rndm (0, 6); 3945 int i = rndm (0, 6);
3845 int stat = get_attr_value (stats, i);
3846 int race_bonus = get_attr_value (&(pl->arch->clone.stats), i);
3847 3946
3848 if (i == CHA) 3947 if (i == CHA)
3849 continue; /* exclude cha from this */ 3948 continue; /* exclude cha from this */
3949
3950 int stat = stats->stat (i);
3951 int race_bonus = pl->arch->stats.stat (i);
3850 if (stat < 20 + race_bonus) 3952 if (stat < 20 + race_bonus)
3851 { 3953 {
3852 change_attr_value (stats, i, 1); 3954 change_attr_value (stats, i, 1);
3853 excess_stat--; 3955 excess_stat--;
3854 } 3956 }
3857 /* insert the randomitems from the change's treasurelist into 3959 /* insert the randomitems from the change's treasurelist into
3858 * the player ref: player.c 3960 * the player ref: player.c
3859 */ 3961 */
3860 if (change->randomitems != NULL) 3962 if (change->randomitems != NULL)
3861 give_initial_items (pl, change->randomitems); 3963 give_initial_items (pl, change->randomitems);
3862
3863 3964
3864 /* set up the face, for some races. */ 3965 /* set up the face, for some races. */
3865 3966
3866 /* first, look for the force object banning 3967 /* first, look for the force object banning
3867 * changing the face. Certain races never change face with class. 3968 * changing the face. Certain races never change face with class.
3912 char got[MAX_BUF]; 4013 char got[MAX_BUF];
3913 int len; 4014 int len;
3914 4015
3915 if (!pl || !transformer) 4016 if (!pl || !transformer)
3916 return; 4017 return;
4018
3917 marked = find_marked_object (pl); 4019 marked = find_marked_object (pl);
4020
3918 if (!marked) 4021 if (!marked)
3919 { 4022 {
3920 new_draw_info_format (NDI_UNIQUE, 0, pl, "Use the %s with what item?", query_name (transformer)); 4023 new_draw_info_format (NDI_UNIQUE, 0, pl, "Use the %s with what item?", query_name (transformer));
3921 return; 4024 return;
3922 } 4025 }
4026
3923 if (!marked->slaying) 4027 if (!marked->slaying)
3924 { 4028 {
3925 new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't use the %s with your %s!", query_name (transformer), query_name (marked)); 4029 new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't use the %s with your %s!", query_name (transformer), query_name (marked));
3926 return; 4030 return;
3927 } 4031 }
4032
3928 /* check whether they are compatible or not */ 4033 /* check whether they are compatible or not */
3929 find = strstr (marked->slaying, transformer->arch->name); 4034 find = strstr (marked->slaying, transformer->arch->archname);
3930 if (!find || (*(find + strlen (transformer->arch->name)) != ':')) 4035 if (!find || (*(find + strlen (transformer->arch->archname)) != ':'))
3931 { 4036 {
3932 new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't use the %s with your %s!", query_name (transformer), query_name (marked)); 4037 new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't use the %s with your %s!", query_name (transformer), query_name (marked));
3933 return; 4038 return;
3934 } 4039 }
4040
3935 find += strlen (transformer->arch->name) + 1; 4041 find += strlen (transformer->arch->archname) + 1;
3936 /* Item can be used, now find how many and what it yields */ 4042 /* Item can be used, now find how many and what it yields */
3937 if (isdigit (*(find))) 4043 if (isdigit (*(find)))
3938 { 4044 {
3939 yield = atoi (find); 4045 yield = atoi (find);
3940 if (yield < 1) 4046 if (yield < 1)
3948 4054
3949 while (isdigit (*find)) 4055 while (isdigit (*find))
3950 find++; 4056 find++;
3951 while (*find == ' ') 4057 while (*find == ' ')
3952 find++; 4058 find++;
4059
3953 memset (got, 0, MAX_BUF); 4060 memset (got, 0, MAX_BUF);
4061
3954 if ((separator = strchr (find, ';')) != NULL) 4062 if ((separator = strchr (find, ';')) != NULL)
3955 {
3956 len = separator - find; 4063 len = separator - find;
3957 }
3958 else 4064 else
3959 {
3960 len = strlen (find); 4065 len = strlen (find);
3961 } 4066
3962 if (len > MAX_BUF - 1) 4067 if (len > MAX_BUF - 1)
3963 len = MAX_BUF - 1; 4068 len = MAX_BUF - 1;
4069
3964 strcpy (got, find); 4070 strcpy (got, find);
3965 got[len] = '\0'; 4071 got[len] = '\0';
3966 4072
3967 /* Now create new item, remove used ones when required. */ 4073 /* Now create new item, remove used ones when required. */
3968 new_item = get_archetype (got); 4074 new_item = get_archetype (got);
3976 new_draw_info_format (NDI_UNIQUE, 0, pl, "You %s the %s.", &transformer->slaying, query_base_name (marked, 0)); 4082 new_draw_info_format (NDI_UNIQUE, 0, pl, "You %s the %s.", &transformer->slaying, query_base_name (marked, 0));
3977 insert_ob_in_ob (new_item, pl); 4083 insert_ob_in_ob (new_item, pl);
3978 esrv_send_inventory (pl, pl); 4084 esrv_send_inventory (pl, pl);
3979 /* Eat up one item */ 4085 /* Eat up one item */
3980 decrease_ob_nr (marked, 1); 4086 decrease_ob_nr (marked, 1);
4087
3981 /* Eat one transformer if needed */ 4088 /* Eat one transformer if needed */
3982 if (transformer->stats.food) 4089 if (transformer->stats.food)
3983 if (--transformer->stats.food == 0) 4090 if (--transformer->stats.food == 0)
3984 decrease_ob_nr (transformer, 1); 4091 decrease_ob_nr (transformer, 1);
3985} 4092}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines