1 | /* |
1 | /* |
2 | * CrossFire, A Multiplayer game for X-windows |
2 | * CrossFire, A Multiplayer game |
3 | * |
3 | * |
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
5 | * Copyright (C) 2001 Mark Wedel & Crossfire Development Team |
5 | * Copyright (C) 2001 Mark Wedel & Crossfire Development Team |
6 | * Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (C) 1992 Frank Tore Johansen |
7 | * |
7 | * |
… | |
… | |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
21 | * |
21 | * |
22 | * The authors can be reached via e-mail to <crossfire@schmorp.de> |
22 | * The authors can be reached via e-mail to <crossfire@schmorp.de> |
23 | */ |
23 | */ |
24 | |
24 | |
|
|
25 | #include <cmath> |
|
|
26 | |
25 | #include <global.h> |
27 | #include <global.h> |
26 | #include <living.h> |
28 | #include <living.h> |
27 | #include <spells.h> |
29 | #include <spells.h> |
28 | #include <skills.h> |
30 | #include <skills.h> |
29 | #include <tod.h> |
31 | #include <tod.h> |
30 | |
32 | |
31 | #include <sproto.h> |
33 | #include <sproto.h> |
32 | |
34 | |
33 | /* Want this regardless of rplay. */ |
35 | /* Want this regardless of rplay. */ |
34 | #include <sounds.h> |
36 | #include <sounds.h> |
35 | |
|
|
36 | /* need math lib for double-precision and pow() in dragon_eat_flesh() */ |
|
|
37 | #include <math.h> |
|
|
38 | |
37 | |
39 | /** |
38 | /** |
40 | * Check if op should abort moving victim because of it's race or slaying. |
39 | * 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. |
40 | * Returns 1 if it should abort, returns 0 if it should continue. |
42 | */ |
41 | */ |
… | |
… | |
65 | { |
64 | { |
66 | arch_flag = 1; |
65 | arch_flag = 1; |
67 | name_flag = 1; |
66 | name_flag = 1; |
68 | race_flag = 1; |
67 | race_flag = 1; |
69 | } |
68 | } |
|
|
69 | |
70 | /* If the director has race set, only affect objects with a arch, |
70 | /* If the director has race set, only affect objects with a arch, |
71 | * name or race that matches. |
71 | * name or race that matches. |
72 | */ |
72 | */ |
73 | if ((op->race) && |
73 | if ((op->race) && |
74 | ((!(victim->arch && arch_flag && victim->arch->name) || strcmp (op->race, victim->arch->name))) && |
74 | ((!(victim->arch && arch_flag && victim->arch->name) || op->race != victim->arch->name)) && |
75 | ((!(victim->name && name_flag) || strcmp (op->race, victim->name))) && |
75 | ((!(victim->name && name_flag) || op->race != victim->name)) && |
76 | ((!(victim->race && race_flag) || strcmp (op->race, victim->race)))) |
76 | ((!(victim->race && race_flag) || op->race != victim->race))) |
77 | { |
|
|
78 | return 1; |
77 | return 1; |
79 | } |
78 | |
80 | /* If the director has slaying set, only affect objects where none |
79 | /* If the director has slaying set, only affect objects where none |
81 | * of arch, name, or race match. |
80 | * of arch, name, or race match. |
82 | */ |
81 | */ |
83 | if ((op->slaying) && (((victim->arch && arch_flag && victim->arch->name && !strcmp (op->slaying, victim->arch->name))) || |
82 | if ((op->slaying) && (((victim->arch && arch_flag && victim->arch->name && op->slaying == victim->arch->name))) || |
84 | ((victim->name && name_flag && !strcmp (op->slaying, victim->name))) || |
83 | ((victim->name && name_flag && op->slaying == victim->name)) || |
85 | ((victim->race && race_flag && !strcmp (op->slaying, victim->race))))) |
84 | ((victim->race && race_flag && op->slaying == victim->race))) |
86 | { |
|
|
87 | return 1; |
85 | return 1; |
88 | } |
86 | |
89 | return 0; |
87 | return 0; |
90 | } |
88 | } |
91 | |
89 | |
92 | /** |
90 | /** |
93 | * This handles a player dropping money on an altar to identify stuff. |
91 | * This handles a player dropping money on an altar to identify stuff. |
… | |
… | |
234 | depl = present_arch_in_ob (at, op); |
232 | depl = present_arch_in_ob (at, op); |
235 | |
233 | |
236 | if (depl) |
234 | if (depl) |
237 | { |
235 | { |
238 | for (i = 0; i < NUM_STATS; i++) |
236 | for (i = 0; i < NUM_STATS; i++) |
239 | if (get_attr_value (&depl->stats, i)) |
237 | if (depl->stats.stat (i)) |
240 | new_draw_info (NDI_UNIQUE, 0, op, restore_msg[i]); |
238 | new_draw_info (NDI_UNIQUE, 0, op, restore_msg[i]); |
241 | |
239 | |
242 | depl->destroy (); |
240 | depl->destroy (); |
243 | op->update_stats (); |
241 | op->update_stats (); |
244 | } |
242 | } |
… | |
… | |
376 | force->stats.food *= 10; |
374 | force->stats.food *= 10; |
377 | for (i = 0; i < NROFATTACKS; i++) |
375 | for (i = 0; i < NROFATTACKS; i++) |
378 | if (force->resist[i] > 0) |
376 | if (force->resist[i] > 0) |
379 | force->resist[i] = -force->resist[i]; /* prot => vuln */ |
377 | force->resist[i] = -force->resist[i]; /* prot => vuln */ |
380 | } |
378 | } |
|
|
379 | |
381 | force->speed_left = -1; |
380 | force->speed_left = -1; |
382 | force = insert_ob_in_ob (force, op); |
381 | force = insert_ob_in_ob (force, op); |
383 | CLEAR_FLAG (tmp, FLAG_APPLIED); |
382 | CLEAR_FLAG (tmp, FLAG_APPLIED); |
384 | SET_FLAG (force, FLAG_APPLIED); |
383 | SET_FLAG (force, FLAG_APPLIED); |
385 | change_abil (op, force); |
384 | change_abil (op, force); |
… | |
… | |
422 | int count = 0; |
421 | int count = 0; |
423 | |
422 | |
424 | |
423 | |
425 | if (item == NULL) |
424 | if (item == NULL) |
426 | return 0; |
425 | return 0; |
|
|
426 | |
427 | op = op->below; |
427 | op = op->below; |
428 | while (op != NULL) |
428 | while (op != NULL) |
429 | { |
429 | { |
430 | if (strcmp (op->arch->name, item) == 0) |
430 | if (strcmp (op->arch->name, item) == 0) |
431 | { |
431 | { |
… | |
… | |
436 | count++; |
436 | count++; |
437 | else |
437 | else |
438 | count += op->nrof; |
438 | count += op->nrof; |
439 | } |
439 | } |
440 | } |
440 | } |
|
|
441 | |
441 | op = op->below; |
442 | op = op->below; |
442 | } |
443 | } |
|
|
444 | |
443 | return count; |
445 | return count; |
444 | } |
446 | } |
445 | |
447 | |
446 | /** |
448 | /** |
447 | * This removes 'nrof' of what item->slaying says to remove. |
449 | * This removes 'nrof' of what item->slaying says to remove. |
… | |
… | |
763 | { |
765 | { |
764 | object *otmp; |
766 | object *otmp; |
765 | |
767 | |
766 | if (op->type != PLAYER) |
768 | if (op->type != PLAYER) |
767 | return 0; |
769 | return 0; |
|
|
770 | |
768 | 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)) |
769 | { |
772 | { |
770 | 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."); |
771 | return 0; |
774 | return 0; |
772 | } |
775 | } |
|
|
776 | |
773 | otmp = find_marked_object (op); |
777 | otmp = find_marked_object (op); |
774 | if (!otmp) |
778 | if (!otmp) |
775 | { |
779 | { |
776 | 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."); |
777 | return 0; |
781 | return 0; |
778 | } |
782 | } |
|
|
783 | |
779 | if (otmp->type != WEAPON && otmp->type != BOW) |
784 | if (otmp->type != WEAPON && otmp->type != BOW) |
780 | { |
785 | { |
781 | 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"); |
782 | return 0; |
787 | return 0; |
783 | } |
788 | } |
|
|
789 | |
784 | new_draw_info (NDI_UNIQUE, 0, op, "Applied weapon builder."); |
790 | new_draw_info (NDI_UNIQUE, 0, op, "Applied weapon builder."); |
785 | improve_weapon (op, tmp, otmp); |
791 | improve_weapon (op, tmp, otmp); |
786 | esrv_send_item (op, otmp); |
792 | esrv_send_item (op, otmp); |
787 | return 1; |
793 | return 1; |
788 | } |
794 | } |
… | |
… | |
1013 | * Handle apply on containers. |
1019 | * Handle apply on containers. |
1014 | * By Eneq(@csd.uu.se). |
1020 | * By Eneq(@csd.uu.se). |
1015 | * Moved to own function and added many features [Tero.Haatanen@lut.fi] |
1021 | * Moved to own function and added many features [Tero.Haatanen@lut.fi] |
1016 | * added the alchemical cauldron to the code -b.t. |
1022 | * added the alchemical cauldron to the code -b.t. |
1017 | */ |
1023 | */ |
1018 | |
|
|
1019 | int |
1024 | int |
1020 | apply_container (object *op, object *sack) |
1025 | apply_container (object *op, object *sack) |
1021 | { |
1026 | { |
1022 | char buf[MAX_BUF]; |
1027 | if (op->type != PLAYER || !op->contr->ns) |
1023 | object *tmp; |
|
|
1024 | |
|
|
1025 | if (op->type != PLAYER) |
|
|
1026 | return 0; /* This might change */ |
1028 | return 0; /* This might change */ |
1027 | |
1029 | |
1028 | if (sack == NULL || sack->type != CONTAINER) |
1030 | if (!sack || sack->type != CONTAINER) |
1029 | { |
1031 | { |
1030 | LOG (llevError, "apply_container: %s is not container!\n", sack ? &sack->name : "[nullobject]"); |
1032 | LOG (llevError, "apply_container: %s is not container!\n", sack ? &sack->name : "[nullobject]"); |
1031 | return 0; |
1033 | return 0; |
1032 | } |
1034 | } |
1033 | |
1035 | |
1034 | op->contr->last_used = 0; |
1036 | op->contr->last_used = 0; |
1035 | |
1037 | |
1036 | if (sack->env != op) |
1038 | if (sack->env && sack->env != op) |
|
|
1039 | { |
|
|
1040 | new_draw_info (NDI_UNIQUE, 0, op, "You must put it onto the floor or into your inventory first."); |
|
|
1041 | return 1; |
1037 | { |
1042 | } |
1038 | if (sack->other_arch == NULL || sack->env != NULL) |
1043 | |
|
|
1044 | // already applied == open on ground, or open in inv, or active in inv |
|
|
1045 | if (sack->flag [FLAG_APPLIED]) |
|
|
1046 | { |
|
|
1047 | if (op->container == sack) |
1039 | { |
1048 | { |
1040 | new_draw_info (NDI_UNIQUE, 0, op, "You must get it first."); |
1049 | // open on ground or inv, so close |
|
|
1050 | op->close_container (); |
1041 | return 1; |
1051 | return 1; |
1042 | } |
1052 | } |
1043 | |
1053 | else if (!sack->env) |
1044 | /* It's on the ground, the problems begin */ |
|
|
1045 | if (op->container != sack) |
|
|
1046 | { |
|
|
1047 | /* it's closed OR some player has opened it */ |
|
|
1048 | if (QUERY_FLAG (sack, FLAG_APPLIED)) |
|
|
1049 | { |
1054 | { |
1050 | for (tmp = GET_MAP_OB (sack->map, sack->x, sack->y); tmp && tmp->container != sack; tmp = tmp->above); |
1055 | // active, but not ours: some other player has opened it |
1051 | if (tmp) |
|
|
1052 | { |
|
|
1053 | /* some other player have opened it */ |
|
|
1054 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s is already occupied.", query_name (sack)); |
1056 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s is already occupied.", query_name (sack)); |
1055 | return 1; |
1057 | return 1; |
1056 | } |
|
|
1057 | } |
|
|
1058 | } |
|
|
1059 | if (QUERY_FLAG (sack, FLAG_APPLIED)) |
|
|
1060 | { |
1058 | } |
1061 | if (op->container == NULL) |
|
|
1062 | { |
|
|
1063 | tmp = arch_to_object (sack->other_arch); |
|
|
1064 | /* not good, but insert_ob_in_ob() is too smart */ |
|
|
1065 | CLEAR_FLAG (tmp, FLAG_REMOVED); |
|
|
1066 | tmp->x = tmp->y = 0; |
|
|
1067 | tmp->map = NULL; |
|
|
1068 | tmp->env = sack; |
|
|
1069 | if (sack->inv) |
|
|
1070 | sack->inv->above = tmp; |
|
|
1071 | tmp->below = sack->inv; |
|
|
1072 | tmp->above = NULL; |
|
|
1073 | sack->inv = tmp; |
|
|
1074 | sack->move_off = MOVE_ALL; /* trying force closing it */ |
|
|
1075 | } |
|
|
1076 | else |
|
|
1077 | { |
|
|
1078 | sack->move_off = 0; |
|
|
1079 | tmp = sack->inv; |
|
|
1080 | |
1059 | |
1081 | if (tmp && tmp->type == CLOSE_CON) |
1060 | // fall through to opening it (active in inv) |
1082 | tmp->destroy (); |
|
|
1083 | } |
|
|
1084 | } |
|
|
1085 | } |
|
|
1086 | |
|
|
1087 | if (QUERY_FLAG (sack, FLAG_APPLIED)) |
|
|
1088 | { |
1061 | } |
|
|
1062 | else if (sack->env) |
|
|
1063 | { |
|
|
1064 | // it is in our env, so activate it, do not open yet |
1089 | if (op->container) |
1065 | op->close_container (); |
1090 | { |
1066 | sack->flag [FLAG_APPLIED] = 1; |
1091 | if (op->container != sack) |
1067 | esrv_update_item (UPD_FLAGS, op, sack); |
1092 | { |
1068 | new_draw_info_format (NDI_UNIQUE, 0, op, "You ready %s.", query_name (sack)); |
1093 | tmp = op->container; |
1069 | return 1; |
1094 | apply_container (op, tmp); |
1070 | } |
1095 | sprintf (buf, "You close %s and open ", query_name (tmp)); |
1071 | |
1096 | op->container = sack; |
1072 | // it's locked? |
1097 | strcat (buf, query_name (sack)); |
1073 | if (sack->slaying) |
1098 | strcat (buf, "."); |
1074 | { |
1099 | } |
1075 | if (object *tmp = find_key (op, op, sack)) |
1100 | else |
1076 | new_draw_info_format (NDI_UNIQUE, 0, op, "You unlock %s with %s.", query_name (sack), query_name (tmp)); |
1101 | { |
|
|
1102 | CLEAR_FLAG (sack, FLAG_APPLIED); |
|
|
1103 | op->container = NULL; |
|
|
1104 | sprintf (buf, "You close %s.", query_name (sack)); |
|
|
1105 | } |
|
|
1106 | } |
|
|
1107 | else |
1077 | else |
1108 | { |
1078 | { |
1109 | CLEAR_FLAG (sack, FLAG_APPLIED); |
|
|
1110 | sprintf (buf, "You open %s.", query_name (sack)); |
|
|
1111 | SET_FLAG (sack, FLAG_APPLIED); |
|
|
1112 | op->container = sack; |
|
|
1113 | } |
|
|
1114 | } |
|
|
1115 | else |
|
|
1116 | { /* not applied */ |
|
|
1117 | if (sack->slaying) |
|
|
1118 | { /* it's locked */ |
|
|
1119 | tmp = find_key (op, op, sack); |
|
|
1120 | if (tmp) |
|
|
1121 | { |
|
|
1122 | sprintf (buf, "You unlock %s with %s.", query_name (sack), query_name (tmp)); |
|
|
1123 | SET_FLAG (sack, FLAG_APPLIED); |
|
|
1124 | |
|
|
1125 | if (sack->env == NULL) |
|
|
1126 | { /* if it's on ground,open it also */ |
|
|
1127 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
|
|
1128 | apply_container (op, sack); |
|
|
1129 | return 1; |
|
|
1130 | } |
|
|
1131 | } |
|
|
1132 | else |
|
|
1133 | sprintf (buf, "You don't have the key to unlock %s.", query_name (sack)); |
1079 | new_draw_info_format (NDI_UNIQUE, 0, op, "You don't have the key to unlock %s.", query_name (sack)); |
1134 | } |
|
|
1135 | else |
|
|
1136 | { |
|
|
1137 | sprintf (buf, "You readied %s.", query_name (sack)); |
|
|
1138 | SET_FLAG (sack, FLAG_APPLIED); |
|
|
1139 | |
|
|
1140 | if (sack->env == NULL) |
|
|
1141 | { /* if it's on ground,open it also */ |
|
|
1142 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
|
|
1143 | apply_container (op, sack); |
|
|
1144 | return 1; |
1080 | return 1; |
1145 | } |
1081 | } |
1146 | } |
|
|
1147 | } |
1082 | } |
1148 | |
1083 | |
1149 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
1084 | op->open_container (sack); |
1150 | |
|
|
1151 | if (op->contr) |
|
|
1152 | op->contr->ns->floorbox_update (); |
|
|
1153 | |
1085 | |
1154 | return 1; |
1086 | return 1; |
1155 | } |
1087 | } |
1156 | |
|
|
1157 | /** |
|
|
1158 | * Eneq(@csd.uu.se): Handle apply on containers. This is for containers |
|
|
1159 | * the player has in their inventory, eg, sacks, luggages, etc. |
|
|
1160 | * |
|
|
1161 | * Moved to own function and added many features [Tero.Haatanen@lut.fi] |
|
|
1162 | * This version is for client/server mode. |
|
|
1163 | * op is the player, sack is the container the player is opening or closing. |
|
|
1164 | * return 1 if an object is apllied somehow or another, 0 if error/no apply |
|
|
1165 | * |
|
|
1166 | * Reminder - there are three states for any container - closed (non applied), |
|
|
1167 | * applied (not open, but objects that match get tossed into it), and open |
|
|
1168 | * (applied flag set, and op->container points to the open container) |
|
|
1169 | */ |
|
|
1170 | |
|
|
1171 | int |
|
|
1172 | esrv_apply_container (object *op, object *sack) |
|
|
1173 | { |
|
|
1174 | object *tmp = op->container; |
|
|
1175 | |
|
|
1176 | if (op->type != PLAYER) |
|
|
1177 | return 0; /* This might change */ |
|
|
1178 | |
|
|
1179 | if (sack == NULL || sack->type != CONTAINER) |
|
|
1180 | { |
|
|
1181 | LOG (llevError, "esrv_apply_container: %s is not container!\n", sack ? &sack->name : "[nullobject]"); |
|
|
1182 | return 0; |
|
|
1183 | } |
|
|
1184 | |
|
|
1185 | /* If we have a currently open container, then it needs to be closed in all cases |
|
|
1186 | * if we are opening this one up. We then fall through if appropriate for |
|
|
1187 | * openening the new container. |
|
|
1188 | */ |
|
|
1189 | |
|
|
1190 | if (op->container && QUERY_FLAG (sack, FLAG_APPLIED)) |
|
|
1191 | { |
|
|
1192 | if (op->container->env != op) |
|
|
1193 | { /* if container is on the ground */ |
|
|
1194 | op->container->move_off = 0; |
|
|
1195 | } |
|
|
1196 | |
|
|
1197 | if (INVOKE_OBJECT (CLOSE, tmp, ARG_OBJECT (op))) |
|
|
1198 | return 1; |
|
|
1199 | |
|
|
1200 | new_draw_info_format (NDI_UNIQUE, 0, op, "You close %s.", query_name (op->container)); |
|
|
1201 | CLEAR_FLAG (op->container, FLAG_APPLIED); |
|
|
1202 | op->container = NULL; |
|
|
1203 | esrv_update_item (UPD_FLAGS, op, tmp); |
|
|
1204 | if (tmp == sack) |
|
|
1205 | return 1; |
|
|
1206 | } |
|
|
1207 | |
|
|
1208 | |
|
|
1209 | /* If the player is trying to open it (which he must be doing if we got here), |
|
|
1210 | * and it is locked, check to see if player has the equipment to open it. |
|
|
1211 | */ |
|
|
1212 | |
|
|
1213 | if (sack->slaying) |
|
|
1214 | { /* it's locked */ |
|
|
1215 | tmp = find_key (op, op, sack); |
|
|
1216 | if (tmp) |
|
|
1217 | { |
|
|
1218 | new_draw_info_format (NDI_UNIQUE, 0, op, "You unlock %s with %s.", query_name (sack), query_name (tmp)); |
|
|
1219 | } |
|
|
1220 | else |
|
|
1221 | { |
|
|
1222 | new_draw_info_format (NDI_UNIQUE, 0, op, "You don't have the key to unlock %s.", query_name (sack)); |
|
|
1223 | return 0; |
|
|
1224 | } |
|
|
1225 | } |
|
|
1226 | |
|
|
1227 | /* By the time we get here, we have made sure any other container has been closed and |
|
|
1228 | * if this is a locked container, the player they key to open it. |
|
|
1229 | */ |
|
|
1230 | |
|
|
1231 | /* There are really two cases - the sack is either on the ground, or the sack is |
|
|
1232 | * part of the players inventory. If on the ground, we assume that the player is |
|
|
1233 | * opening it, since if it was being closed, that would have been taken care of above. |
|
|
1234 | */ |
|
|
1235 | |
|
|
1236 | |
|
|
1237 | if (sack->env != op) |
|
|
1238 | { |
|
|
1239 | /* Hypothetical case - the player is trying to open a sack that belong to someone |
|
|
1240 | * else. This normally should not happen, but a misbehaving client/player could |
|
|
1241 | * try to do it, so lets handle it gracefully. |
|
|
1242 | */ |
|
|
1243 | if (sack->env) |
|
|
1244 | { |
|
|
1245 | new_draw_info_format (NDI_UNIQUE, 0, op, "You can't open %s", query_name (sack)); |
|
|
1246 | return 0; |
|
|
1247 | } |
|
|
1248 | /* set these so when the player walks off, we can unapply the sack */ |
|
|
1249 | sack->move_off = MOVE_ALL; /* trying force closing it */ |
|
|
1250 | |
|
|
1251 | CLEAR_FLAG (sack, FLAG_APPLIED); |
|
|
1252 | new_draw_info_format (NDI_UNIQUE, 0, op, "You open %s.", query_name (sack)); |
|
|
1253 | SET_FLAG (sack, FLAG_APPLIED); |
|
|
1254 | op->container = sack; |
|
|
1255 | esrv_update_item (UPD_FLAGS, op, sack); |
|
|
1256 | esrv_send_inventory (op, sack); |
|
|
1257 | |
|
|
1258 | } |
|
|
1259 | else |
|
|
1260 | { /* sack is in players inventory */ |
|
|
1261 | if (QUERY_FLAG (sack, FLAG_APPLIED)) |
|
|
1262 | { /* readied sack becoming open */ |
|
|
1263 | CLEAR_FLAG (sack, FLAG_APPLIED); |
|
|
1264 | new_draw_info_format (NDI_UNIQUE, 0, op, "You open %s.", query_name (sack)); |
|
|
1265 | SET_FLAG (sack, FLAG_APPLIED); |
|
|
1266 | op->container = sack; |
|
|
1267 | esrv_update_item (UPD_FLAGS, op, sack); |
|
|
1268 | esrv_send_inventory (op, sack); |
|
|
1269 | } |
|
|
1270 | else |
|
|
1271 | { |
|
|
1272 | CLEAR_FLAG (sack, FLAG_APPLIED); |
|
|
1273 | new_draw_info_format (NDI_UNIQUE, 0, op, "You readied %s.", query_name (sack)); |
|
|
1274 | SET_FLAG (sack, FLAG_APPLIED); |
|
|
1275 | esrv_update_item (UPD_FLAGS, op, sack); |
|
|
1276 | } |
|
|
1277 | } |
|
|
1278 | return 1; |
|
|
1279 | } |
|
|
1280 | |
|
|
1281 | |
1088 | |
1282 | /** |
1089 | /** |
1283 | * Handles dropping things on altar. |
1090 | * Handles dropping things on altar. |
1284 | * Returns true if sacrifice was accepted. |
1091 | * Returns true if sacrifice was accepted. |
1285 | */ |
1092 | */ |
… | |
… | |
1698 | |
1505 | |
1699 | apply_sign (victim, trap, 1); |
1506 | apply_sign (victim, trap, 1); |
1700 | goto leave; |
1507 | goto leave; |
1701 | |
1508 | |
1702 | case CONTAINER: |
1509 | case CONTAINER: |
1703 | if (victim->type == PLAYER) |
|
|
1704 | (void) esrv_apply_container (victim, trap); |
|
|
1705 | else |
|
|
1706 | (void) apply_container (victim, trap); |
1510 | apply_container (victim, trap); |
1707 | goto leave; |
1511 | goto leave; |
1708 | |
1512 | |
1709 | case RUNE: |
1513 | case RUNE: |
1710 | case TRAP: |
1514 | case TRAP: |
1711 | if (trap->level && QUERY_FLAG (victim, FLAG_ALIVE)) |
1515 | if (trap->level && QUERY_FLAG (victim, FLAG_ALIVE)) |
… | |
… | |
1771 | |
1575 | |
1772 | readable_message_type *msgType = get_readable_message_type (tmp); |
1576 | readable_message_type *msgType = get_readable_message_type (tmp); |
1773 | |
1577 | |
1774 | draw_ext_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, |
1578 | draw_ext_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, |
1775 | msgType->message_type, msgType->message_subtype, |
1579 | msgType->message_type, msgType->message_subtype, |
1776 | "You open the %s and start reading.\n%s", "%s\n%s", long_desc (tmp, op), &tmp->msg); |
1580 | "You open the %s and start reading.\n%s", (char *)"%s\n%s", |
|
|
1581 | long_desc (tmp, op), &tmp->msg); |
1777 | |
1582 | |
1778 | /* gain xp from reading */ |
1583 | /* gain xp from reading */ |
1779 | if (!QUERY_FLAG (tmp, FLAG_NO_SKILL_IDENT)) |
1584 | if (!QUERY_FLAG (tmp, FLAG_NO_SKILL_IDENT)) |
1780 | { /* only if not read before */ |
1585 | { /* only if not read before */ |
1781 | int exp_gain = calc_skill_exp (op, tmp, skill_ob); |
1586 | int exp_gain = calc_skill_exp (op, tmp, skill_ob); |
… | |
… | |
1937 | return; |
1742 | return; |
1938 | } |
1743 | } |
1939 | |
1744 | |
1940 | if (skop->level < int (sqrtf (spell->level) * 1.5f)) |
1745 | if (skop->level < int (sqrtf (spell->level) * 1.5f)) |
1941 | { |
1746 | { |
1942 | new_draw_info (NDI_UNIQUE, 0, op, "It is too hard to read at your level: You are unable to decipher the strange symbols."); |
1747 | new_draw_info (NDI_UNIQUE, 0, op, "You are unable to decipher the strange symbols. [Your literacy level is too low]"); |
1943 | return; |
1748 | return; |
1944 | } |
1749 | } |
1945 | |
1750 | |
1946 | new_draw_info_format (NDI_UNIQUE, 0, op, "The spellbook contains the %s level spell %s.", get_levelnumber (spell->level), &spell->name); |
1751 | new_draw_info_format (NDI_UNIQUE, 0, op, "The spellbook contains the %s level spell %s.", get_levelnumber (spell->level), &spell->name); |
1947 | |
1752 | |
… | |
… | |
1970 | { |
1775 | { |
1971 | spell_skill = find_skill_by_name (op, spell->skill); |
1776 | spell_skill = find_skill_by_name (op, spell->skill); |
1972 | |
1777 | |
1973 | if (!spell_skill) |
1778 | if (!spell_skill) |
1974 | { |
1779 | { |
1975 | new_draw_info_format (NDI_UNIQUE, 0, op, "You lack the skill %s to use this spell", &spell->skill); |
1780 | new_draw_info_format (NDI_UNIQUE, 0, op, "You lack the skill %s to use this spell.", &spell->skill); |
1976 | return; |
1781 | return; |
1977 | } |
1782 | } |
1978 | |
1783 | |
1979 | if (spell_skill->level < spell->level) |
1784 | if (spell_skill->level < spell->level) |
1980 | { |
1785 | { |
… | |
… | |
2014 | else |
1819 | else |
2015 | { |
1820 | { |
2016 | play_sound_player_only (op->contr, SOUND_FUMBLE_SPELL, 0, 0); |
1821 | play_sound_player_only (op->contr, SOUND_FUMBLE_SPELL, 0, 0); |
2017 | new_draw_info (NDI_UNIQUE, 0, op, "You fail to learn the spell.\n"); |
1822 | new_draw_info (NDI_UNIQUE, 0, op, "You fail to learn the spell.\n"); |
2018 | } |
1823 | } |
|
|
1824 | |
2019 | decrease_ob (tmp); |
1825 | decrease_ob (tmp); |
2020 | } |
1826 | } |
2021 | |
1827 | |
2022 | /** |
1828 | /** |
2023 | * Handles applying a spell scroll. |
1829 | * Handles applying a spell scroll. |
… | |
… | |
2278 | /* doubled chance for resistance of ability-focus */ |
2084 | /* doubled chance for resistance of ability-focus */ |
2279 | if (i == abil->stats.exp) |
2085 | if (i == abil->stats.exp) |
2280 | chance = MIN (100., chance * 2.); |
2086 | chance = MIN (100., chance * 2.); |
2281 | |
2087 | |
2282 | /* now make the throw and save all winners (Don't insert luck bonus here!) */ |
2088 | /* now make the throw and save all winners (Don't insert luck bonus here!) */ |
2283 | if (rndm (10000) < (int) (chance * 100)) |
2089 | if (rndm (10000) < (unsigned int) (chance * 100)) |
2284 | { |
2090 | { |
2285 | atnr_winner[winners] = i; |
2091 | atnr_winner[winners] = i; |
2286 | winners++; |
2092 | winners++; |
2287 | } |
2093 | } |
2288 | |
2094 | |
… | |
… | |
2447 | continue; /*Not a valid exit */ |
2253 | continue; /*Not a valid exit */ |
2448 | |
2254 | |
2449 | if ((EXIT_X (tmp) != exit->x) || (EXIT_Y (tmp) != exit->y)) |
2255 | if ((EXIT_X (tmp) != exit->x) || (EXIT_Y (tmp) != exit->y)) |
2450 | continue; /*Not in the same place */ |
2256 | continue; /*Not in the same place */ |
2451 | |
2257 | |
2452 | if (strcmp (exit->map->path, EXIT_PATH (tmp)) != 0) |
2258 | if (exit->map->path != EXIT_PATH (tmp)) |
2453 | continue; /*Not in the same map */ |
2259 | continue; /*Not in the same map */ |
2454 | |
2260 | |
2455 | /* From here we have found the exit is valid. However we do |
2261 | /* From here we have found the exit is valid. However we do |
2456 | * here the check of the exit owner. It is important for the |
2262 | * here the check of the exit owner. It is important for the |
2457 | * town portals to prevent strangers from visiting your appartments |
2263 | * town portals to prevent strangers from visiting your appartments |
… | |
… | |
2489 | } |
2295 | } |
2490 | } |
2296 | } |
2491 | |
2297 | |
2492 | return 0; |
2298 | return 0; |
2493 | } |
2299 | } |
2494 | |
|
|
2495 | |
2300 | |
2496 | /** |
2301 | /** |
2497 | * Main apply handler. |
2302 | * Main apply handler. |
2498 | * |
2303 | * |
2499 | * Checks for unpaid items before applying. |
2304 | * Checks for unpaid items before applying. |
… | |
… | |
2507 | * being applied. |
2312 | * being applied. |
2508 | * |
2313 | * |
2509 | * aflag is special (always apply/unapply) flags. Nothing is done with |
2314 | * aflag is special (always apply/unapply) flags. Nothing is done with |
2510 | * them in this function - they are passed to apply_special |
2315 | * them in this function - they are passed to apply_special |
2511 | */ |
2316 | */ |
2512 | |
|
|
2513 | int |
2317 | int |
2514 | manual_apply (object *op, object *tmp, int aflag) |
2318 | manual_apply (object *op, object *tmp, int aflag) |
2515 | { |
2319 | { |
2516 | if (tmp->head) |
2320 | if (tmp->head) |
2517 | tmp = tmp->head; |
2321 | tmp = tmp->head; |
… | |
… | |
2555 | case EXIT: |
2359 | case EXIT: |
2556 | if (op->type != PLAYER) |
2360 | if (op->type != PLAYER) |
2557 | return 0; |
2361 | return 0; |
2558 | |
2362 | |
2559 | if (!EXIT_PATH (tmp) || !is_legal_2ways_exit (op, tmp)) |
2363 | if (!EXIT_PATH (tmp) || !is_legal_2ways_exit (op, tmp)) |
2560 | { |
|
|
2561 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s is closed.", query_name (tmp)); |
2364 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s is closed.", query_name (tmp)); |
2562 | } |
|
|
2563 | else |
2365 | else |
2564 | { |
2366 | { |
2565 | /* Don't display messages for random maps. */ |
2367 | /* Don't display messages for random maps. */ |
2566 | if (tmp->msg && strncmp (EXIT_PATH (tmp), "/!", 2)) |
2368 | if (tmp->msg && strncmp (EXIT_PATH (tmp), "/!", 2)) |
2567 | new_draw_info (NDI_NAVY, 0, op, tmp->msg); |
2369 | new_draw_info (NDI_NAVY, 0, op, tmp->msg); |
2568 | |
2370 | |
2569 | op->enter_exit (tmp); |
2371 | op->enter_exit (tmp); |
2570 | } |
2372 | } |
|
|
2373 | |
2571 | return 1; |
2374 | return 1; |
2572 | |
2375 | |
2573 | case SIGN: |
2376 | case SIGN: |
2574 | apply_sign (op, tmp, 0); |
2377 | apply_sign (op, tmp, 0); |
2575 | return 1; |
2378 | return 1; |
… | |
… | |
2579 | { |
2382 | { |
2580 | apply_book (op, tmp); |
2383 | apply_book (op, tmp); |
2581 | return 1; |
2384 | return 1; |
2582 | } |
2385 | } |
2583 | else |
2386 | else |
2584 | { |
|
|
2585 | return 0; |
2387 | return 0; |
2586 | } |
|
|
2587 | |
2388 | |
2588 | case SKILLSCROLL: |
2389 | case SKILLSCROLL: |
2589 | if (op->type == PLAYER) |
2390 | if (op->type == PLAYER) |
2590 | { |
2391 | { |
2591 | apply_skillscroll (op, tmp); |
2392 | apply_skillscroll (op, tmp); |
2592 | return 1; |
2393 | return 1; |
2593 | } |
2394 | } |
|
|
2395 | else |
2594 | return 0; |
2396 | return 0; |
2595 | |
2397 | |
2596 | case SPELLBOOK: |
2398 | case SPELLBOOK: |
2597 | if (op->type == PLAYER) |
2399 | if (op->type == PLAYER) |
2598 | { |
2400 | { |
2599 | apply_spellbook (op, tmp); |
2401 | apply_spellbook (op, tmp); |
2600 | return 1; |
2402 | return 1; |
2601 | } |
2403 | } |
|
|
2404 | else |
2602 | return 0; |
2405 | return 0; |
2603 | |
2406 | |
2604 | case SCROLL: |
2407 | case SCROLL: |
2605 | apply_scroll (op, tmp, 0); |
2408 | apply_scroll (op, tmp, 0); |
2606 | return 1; |
2409 | return 1; |
2607 | |
2410 | |
2608 | case POTION: |
2411 | case POTION: |
2609 | (void) apply_potion (op, tmp); |
2412 | apply_potion (op, tmp); |
2610 | return 1; |
2413 | return 1; |
2611 | |
2414 | |
2612 | /* Eneq(@csd.uu.se): Handle apply on containers. */ |
2415 | /* Eneq(@csd.uu.se): Handle apply on containers. */ |
|
|
2416 | //TODO: remove, as it is unsed? |
2613 | case CLOSE_CON: |
2417 | case CLOSE_CON: |
2614 | if (op->type == PLAYER) |
|
|
2615 | (void) esrv_apply_container (op, tmp->env); |
|
|
2616 | else |
|
|
2617 | (void) apply_container (op, tmp->env); |
2418 | apply_container (op, tmp->env); |
2618 | return 1; |
2419 | return 1; |
2619 | |
2420 | |
2620 | case CONTAINER: |
2421 | case CONTAINER: |
2621 | if (op->type == PLAYER) |
|
|
2622 | (void) esrv_apply_container (op, tmp); |
|
|
2623 | else |
|
|
2624 | (void) apply_container (op, tmp); |
2422 | apply_container (op, tmp); |
2625 | return 1; |
2423 | return 1; |
2626 | |
2424 | |
2627 | case TREASURE: |
2425 | case TREASURE: |
2628 | if (op->type == PLAYER) |
2426 | if (op->type == PLAYER) |
2629 | { |
2427 | { |
2630 | apply_treasure (op, tmp); |
2428 | apply_treasure (op, tmp); |
2631 | return 1; |
2429 | return 1; |
2632 | } |
2430 | } |
2633 | else |
2431 | else |
2634 | { |
|
|
2635 | return 0; |
2432 | return 0; |
2636 | } |
|
|
2637 | |
2433 | |
2638 | case WEAPON: |
2434 | case WEAPON: |
2639 | case ARMOUR: |
2435 | case ARMOUR: |
2640 | case BOOTS: |
2436 | case BOOTS: |
2641 | case GLOVES: |
2437 | case GLOVES: |
… | |
… | |
2654 | case LAMP: |
2450 | case LAMP: |
2655 | case BUILDER: |
2451 | case BUILDER: |
2656 | case SKILL_TOOL: |
2452 | case SKILL_TOOL: |
2657 | if (tmp->env != op) |
2453 | if (tmp->env != op) |
2658 | return 2; /* not in inventory */ |
2454 | return 2; /* not in inventory */ |
|
|
2455 | |
2659 | (void) apply_special (op, tmp, aflag); |
2456 | apply_special (op, tmp, aflag); |
2660 | return 1; |
2457 | return 1; |
2661 | |
2458 | |
2662 | case DRINK: |
2459 | case DRINK: |
2663 | case FOOD: |
2460 | case FOOD: |
2664 | case FLESH: |
2461 | case FLESH: |
… | |
… | |
2680 | } |
2477 | } |
2681 | else |
2478 | else |
2682 | return 0; |
2479 | return 0; |
2683 | |
2480 | |
2684 | case WEAPON_IMPROVER: |
2481 | case WEAPON_IMPROVER: |
2685 | (void) check_improve_weapon (op, tmp); |
2482 | check_improve_weapon (op, tmp); |
2686 | return 1; |
2483 | return 1; |
2687 | |
2484 | |
2688 | case CLOCK: |
2485 | case CLOCK: |
2689 | if (op->type == PLAYER) |
2486 | if (op->type == PLAYER) |
2690 | { |
2487 | { |
… | |
… | |
2698 | play_sound_player_only (op->contr, SOUND_CLOCK, 0, 0); |
2495 | play_sound_player_only (op->contr, SOUND_CLOCK, 0, 0); |
2699 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
2496 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
2700 | return 1; |
2497 | return 1; |
2701 | } |
2498 | } |
2702 | else |
2499 | else |
2703 | { |
|
|
2704 | return 0; |
2500 | return 0; |
2705 | } |
|
|
2706 | |
2501 | |
2707 | case MENU: |
2502 | case MENU: |
2708 | if (op->type == PLAYER) |
2503 | if (op->type == PLAYER) |
2709 | { |
2504 | { |
2710 | shop_listing (op); |
2505 | shop_listing (tmp, op); |
2711 | return 1; |
2506 | return 1; |
2712 | } |
2507 | } |
2713 | else |
2508 | else |
2714 | { |
|
|
2715 | return 0; |
2509 | return 0; |
2716 | } |
|
|
2717 | |
2510 | |
2718 | case POWER_CRYSTAL: |
2511 | case POWER_CRYSTAL: |
2719 | apply_power_crystal (op, tmp); /* see egoitem.c */ |
2512 | apply_power_crystal (op, tmp); /* see egoitem.c */ |
2720 | return 1; |
2513 | return 1; |
2721 | |
2514 | |
… | |
… | |
2724 | { |
2517 | { |
2725 | apply_lighter (op, tmp); |
2518 | apply_lighter (op, tmp); |
2726 | return 1; |
2519 | return 1; |
2727 | } |
2520 | } |
2728 | else |
2521 | else |
2729 | { |
|
|
2730 | return 0; |
2522 | return 0; |
2731 | } |
|
|
2732 | |
2523 | |
2733 | case ITEM_TRANSFORMER: |
2524 | case ITEM_TRANSFORMER: |
2734 | apply_item_transformer (op, tmp); |
2525 | apply_item_transformer (op, tmp); |
2735 | return 1; |
2526 | return 1; |
2736 | |
2527 | |
… | |
… | |
2789 | /** |
2580 | /** |
2790 | * player_apply_below attempts to apply the object 'below' the player. |
2581 | * player_apply_below attempts to apply the object 'below' the player. |
2791 | * If the player has an open container, we use that for below, otherwise |
2582 | * If the player has an open container, we use that for below, otherwise |
2792 | * we use the ground. |
2583 | * we use the ground. |
2793 | */ |
2584 | */ |
2794 | |
|
|
2795 | void |
2585 | void |
2796 | player_apply_below (object *pl) |
2586 | player_apply_below (object *pl) |
2797 | { |
2587 | { |
2798 | object *tmp, *next; |
|
|
2799 | int floors; |
2588 | int floors = 0; |
2800 | |
2589 | |
2801 | /* If using a container, set the starting item to be the top |
2590 | /* If using a container, set the starting item to be the top |
2802 | * item in the container. Otherwise, use the map. |
2591 | * item in the container. Otherwise, use the map. |
2803 | */ |
|
|
2804 | tmp = (pl->container != NULL) ? pl->container->inv : pl->below; |
|
|
2805 | |
|
|
2806 | /* This is perhaps more complicated. However, I want to make sure that |
2592 | * This is perhaps more complicated. However, I want to make sure that |
2807 | * we don't use a corrupt pointer for the next object, so we get the |
2593 | * we don't use a corrupt pointer for the next object, so we get the |
2808 | * next object in the stack before applying. This is can only be a |
2594 | * next object in the stack before applying. This is can only be a |
2809 | * problem if player_apply() has a bug in that it uses the object but does |
2595 | * problem if player_apply() has a bug in that it uses the object but does |
2810 | * not return a proper value. |
2596 | * not return a proper value. |
2811 | */ |
2597 | */ |
2812 | for (floors = 0; tmp != NULL; tmp = next) |
2598 | for (object *next, *tmp = pl->container ? pl->container->inv : pl->below; tmp; tmp = next) |
2813 | { |
2599 | { |
2814 | next = tmp->below; |
2600 | next = tmp->below; |
|
|
2601 | |
2815 | if (QUERY_FLAG (tmp, FLAG_IS_FLOOR)) |
2602 | if (QUERY_FLAG (tmp, FLAG_IS_FLOOR)) |
2816 | floors++; |
2603 | floors++; |
2817 | else if (floors > 0) |
2604 | else if (floors > 0) |
2818 | return; /* process only floor objects after first floor object */ |
2605 | return; /* process only floor objects after first floor object */ |
2819 | |
2606 | |
… | |
… | |
2839 | * to keep the size of apply_special to a more managable size. |
2626 | * to keep the size of apply_special to a more managable size. |
2840 | */ |
2627 | */ |
2841 | static int |
2628 | static int |
2842 | unapply_special (object *who, object *op, int aflags) |
2629 | unapply_special (object *who, object *op, int aflags) |
2843 | { |
2630 | { |
2844 | if (INVOKE_OBJECT (BE_UNREADY, op, ARG_OBJECT (who), ARG_INT (aflags)) || INVOKE_OBJECT (UNREADY, who, ARG_OBJECT (op), ARG_INT (aflags))) |
2631 | if (INVOKE_OBJECT (BE_UNREADY, op, ARG_OBJECT (who), ARG_INT (aflags)) |
|
|
2632 | || INVOKE_OBJECT (UNREADY, who, ARG_OBJECT (op), ARG_INT (aflags))) |
2845 | return RESULT_INT (0); |
2633 | return RESULT_INT (0); |
2846 | |
2634 | |
2847 | object *tmp2; |
2635 | object *tmp2; |
2848 | |
2636 | |
2849 | CLEAR_FLAG (op, FLAG_APPLIED); |
2637 | CLEAR_FLAG (op, FLAG_APPLIED); |
|
|
2638 | |
2850 | switch (op->type) |
2639 | switch (op->type) |
2851 | { |
2640 | { |
2852 | case WEAPON: |
2641 | case WEAPON: |
2853 | new_draw_info_format (NDI_UNIQUE, 0, who, "You unwield %s.", query_name (op)); |
2642 | new_draw_info_format (NDI_UNIQUE, 0, who, "You unwield %s.", query_name (op)); |
2854 | |
2643 | |
2855 | (void) change_abil (who, op); |
2644 | change_abil (who, op); |
2856 | if (QUERY_FLAG (who, FLAG_READY_WEAPON)) |
|
|
2857 | CLEAR_FLAG (who, FLAG_READY_WEAPON); |
2645 | CLEAR_FLAG (who, FLAG_READY_WEAPON); |
|
|
2646 | |
|
|
2647 | if (who->contr) |
|
|
2648 | { |
|
|
2649 | if (who->contr->combat_ob == op) |
|
|
2650 | who->contr->combat_ob = 0; |
|
|
2651 | |
|
|
2652 | if (who->current_weapon == op) |
|
|
2653 | who->current_weapon = 0; |
|
|
2654 | } |
|
|
2655 | |
2858 | clear_skill (who); |
2656 | clear_skill (who); |
2859 | break; |
2657 | break; |
2860 | |
2658 | |
2861 | case SKILL: /* allows objects to impart skills */ |
2659 | case SKILL: /* allows objects to impart skills */ |
2862 | case SKILL_TOOL: |
2660 | case SKILL_TOOL: |
2863 | if (op != who->chosen_skill) |
2661 | if (op != who->chosen_skill) |
2864 | { |
|
|
2865 | LOG (llevError, "BUG: apply_special(): applied skill is not a chosen skill\n"); |
2662 | LOG (llevError, "BUG: apply_special(): applied skill is not a chosen skill\n"); |
|
|
2663 | |
|
|
2664 | if (who->contr) |
2866 | } |
2665 | { |
2867 | if (who->type == PLAYER) |
|
|
2868 | { |
|
|
2869 | if (who->contr->shoottype == range_skill) |
|
|
2870 | who->contr->shoottype = range_none; |
|
|
2871 | if (!op->invisible) |
2666 | if (!op->invisible) |
2872 | { |
|
|
2873 | new_draw_info_format (NDI_UNIQUE, 0, who, "You stop using the %s.", query_name (op)); |
2667 | new_draw_info_format (NDI_UNIQUE, 0, who, "You stop using the %s.", query_name (op)); |
2874 | } |
|
|
2875 | else |
2668 | else |
2876 | { |
|
|
2877 | new_draw_info_format (NDI_UNIQUE, 0, who, "You can no longer use the skill: %s.", &op->skill); |
2669 | new_draw_info_format (NDI_UNIQUE, 0, who, "You can no longer use the skill: %s.", &op->skill); |
2878 | } |
2670 | } |
2879 | } |
2671 | |
2880 | (void) change_abil (who, op); |
2672 | change_abil (who, op); |
2881 | who->chosen_skill = NULL; |
2673 | who->chosen_skill = 0; |
2882 | CLEAR_FLAG (who, FLAG_READY_SKILL); |
2674 | CLEAR_FLAG (who, FLAG_READY_SKILL); |
2883 | break; |
2675 | break; |
2884 | |
2676 | |
2885 | case ARMOUR: |
2677 | case ARMOUR: |
2886 | case HELMET: |
2678 | case HELMET: |
… | |
… | |
2891 | case AMULET: |
2683 | case AMULET: |
2892 | case GIRDLE: |
2684 | case GIRDLE: |
2893 | case BRACERS: |
2685 | case BRACERS: |
2894 | case CLOAK: |
2686 | case CLOAK: |
2895 | new_draw_info_format (NDI_UNIQUE, 0, who, "You unwear %s.", query_name (op)); |
2687 | new_draw_info_format (NDI_UNIQUE, 0, who, "You unwear %s.", query_name (op)); |
2896 | (void) change_abil (who, op); |
2688 | change_abil (who, op); |
2897 | break; |
2689 | break; |
|
|
2690 | |
2898 | case LAMP: |
2691 | case LAMP: |
2899 | new_draw_info_format (NDI_UNIQUE, 0, who, "You turn off your %s.", &op->name); |
2692 | new_draw_info_format (NDI_UNIQUE, 0, who, "You turn off your %s.", &op->name); |
2900 | tmp2 = arch_to_object (op->other_arch); |
2693 | tmp2 = arch_to_object (op->other_arch); |
2901 | tmp2->x = op->x; |
2694 | tmp2->x = op->x; |
2902 | tmp2->y = op->y; |
2695 | tmp2->y = op->y; |
… | |
… | |
2907 | CLEAR_FLAG (tmp2, FLAG_APPLIED); |
2700 | CLEAR_FLAG (tmp2, FLAG_APPLIED); |
2908 | |
2701 | |
2909 | if (QUERY_FLAG (op, FLAG_INV_LOCKED)) |
2702 | if (QUERY_FLAG (op, FLAG_INV_LOCKED)) |
2910 | SET_FLAG (tmp2, FLAG_INV_LOCKED); |
2703 | SET_FLAG (tmp2, FLAG_INV_LOCKED); |
2911 | |
2704 | |
2912 | if (who->type == PLAYER) |
2705 | if (who->contr) |
2913 | esrv_del_item (who->contr, op->count); |
2706 | esrv_del_item (who->contr, op->count); |
2914 | |
2707 | |
2915 | op->destroy (); |
2708 | op->destroy (); |
2916 | insert_ob_in_ob (tmp2, who); |
2709 | insert_ob_in_ob (tmp2, who); |
2917 | who->update_stats (); |
2710 | who->update_stats (); |
|
|
2711 | |
2918 | if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED)) |
2712 | if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED)) |
2919 | { |
2713 | { |
2920 | if (who->type == PLAYER) |
2714 | if (who->contr) |
2921 | { |
2715 | { |
2922 | new_draw_info (NDI_UNIQUE, 0, who, "Oops, it feels deadly cold!"); |
2716 | new_draw_info (NDI_UNIQUE, 0, who, "Oops, it feels deadly cold!"); |
2923 | SET_FLAG (tmp2, FLAG_KNOWN_CURSED); |
2717 | SET_FLAG (tmp2, FLAG_KNOWN_CURSED); |
2924 | } |
2718 | } |
2925 | } |
2719 | } |
2926 | if (who->type == PLAYER) |
2720 | |
|
|
2721 | if (who->contr) |
2927 | esrv_send_item (who, tmp2); |
2722 | esrv_send_item (who, tmp2); |
|
|
2723 | |
2928 | return 1; /* otherwise, an attempt to drop causes problems */ |
2724 | return 1; /* otherwise, an attempt to drop causes problems */ |
2929 | break; |
2725 | |
2930 | case BOW: |
2726 | case BOW: |
2931 | case WAND: |
2727 | case WAND: |
2932 | case ROD: |
2728 | case ROD: |
2933 | case HORN: |
2729 | case HORN: |
2934 | clear_skill (who); |
2730 | clear_skill (who); |
|
|
2731 | |
|
|
2732 | if (who->contr) |
|
|
2733 | { |
2935 | new_draw_info_format (NDI_UNIQUE, 0, who, "You unready %s.", query_name (op)); |
2734 | new_draw_info_format (NDI_UNIQUE, 0, who, "You unready %s.", query_name (op)); |
2936 | if (who->type == PLAYER) |
2735 | |
2937 | { |
2736 | if (who->contr->ranged_ob == op) |
2938 | who->contr->shoottype = range_none; |
2737 | who->contr->ranged_ob = 0; |
|
|
2738 | |
|
|
2739 | if (who->current_weapon == op) |
|
|
2740 | who->current_weapon = 0; |
2939 | } |
2741 | } |
2940 | else |
2742 | else |
2941 | { |
2743 | { |
2942 | if (op->type == BOW) |
2744 | if (op->type == BOW) |
2943 | CLEAR_FLAG (who, FLAG_READY_BOW); |
2745 | CLEAR_FLAG (who, FLAG_READY_BOW); |
2944 | else |
2746 | else |
2945 | CLEAR_FLAG (who, FLAG_READY_RANGE); |
2747 | CLEAR_FLAG (who, FLAG_READY_RANGE); |
2946 | } |
2748 | } |
|
|
2749 | |
2947 | break; |
2750 | break; |
2948 | |
2751 | |
2949 | case BUILDER: |
2752 | case BUILDER: |
|
|
2753 | if (who->contr) |
|
|
2754 | { |
2950 | new_draw_info_format (NDI_UNIQUE, 0, who, "You unready %s.", query_name (op)); |
2755 | new_draw_info_format (NDI_UNIQUE, 0, who, "You unready %s.", query_name (op)); |
2951 | who->contr->shoottype = range_none; |
2756 | |
2952 | who->contr->ranges[range_builder] = NULL; |
2757 | if (who->contr->ranged_ob == op) |
|
|
2758 | who->contr->ranged_ob = 0; |
|
|
2759 | } |
2953 | break; |
2760 | break; |
2954 | |
2761 | |
2955 | default: |
2762 | default: |
2956 | new_draw_info_format (NDI_UNIQUE, 0, who, "You unapply %s.", query_name (op)); |
2763 | new_draw_info_format (NDI_UNIQUE, 0, who, "You unapply %s.", query_name (op)); |
2957 | break; |
2764 | break; |
… | |
… | |
2959 | |
2766 | |
2960 | who->update_stats (); |
2767 | who->update_stats (); |
2961 | |
2768 | |
2962 | if (!(aflags & AP_NO_MERGE)) |
2769 | if (!(aflags & AP_NO_MERGE)) |
2963 | { |
2770 | { |
2964 | object *tmp; |
|
|
2965 | |
|
|
2966 | tmp = merge_ob (op, NULL); |
2771 | object *tmp = merge_ob (op, 0); |
2967 | if (who->type == PLAYER) |
2772 | |
|
|
2773 | if (who->contr) |
2968 | { |
2774 | { |
2969 | if (tmp) |
2775 | if (tmp) |
2970 | { /* it was merged */ |
2776 | { /* it was merged */ |
2971 | esrv_del_item (who->contr, op->count); |
2777 | esrv_del_item (who->contr, op->count); |
2972 | op = tmp; |
2778 | op = tmp; |
2973 | } |
2779 | } |
2974 | |
2780 | |
2975 | esrv_send_item (who, op); |
2781 | esrv_send_item (who, op); |
2976 | } |
2782 | } |
2977 | } |
2783 | } |
|
|
2784 | |
2978 | return 0; |
2785 | return 0; |
2979 | } |
2786 | } |
2980 | |
2787 | |
2981 | /** |
2788 | /** |
2982 | * Returns the object that is using location 'loc'. |
2789 | * Returns the object that is using location 'loc'. |
… | |
… | |
2990 | * loc is the index into the array we are looking for a match. |
2797 | * loc is the index into the array we are looking for a match. |
2991 | * don't return invisible objects unless they are skill objects |
2798 | * don't return invisible objects unless they are skill objects |
2992 | * invisible other objects that use |
2799 | * invisible other objects that use |
2993 | * up body locations can be used as restrictions. |
2800 | * up body locations can be used as restrictions. |
2994 | */ |
2801 | */ |
2995 | object * |
2802 | static object * |
2996 | get_item_from_body_location (object *start, int loc) |
2803 | get_item_from_body_location (int loc, object *start) |
2997 | { |
2804 | { |
2998 | object *tmp; |
|
|
2999 | |
|
|
3000 | if (!start) |
2805 | if (start) |
3001 | return NULL; |
|
|
3002 | |
|
|
3003 | for (tmp = start; tmp; tmp = tmp->below) |
2806 | for (object *tmp = start; tmp; tmp = tmp->below) |
3004 | if (QUERY_FLAG (tmp, FLAG_APPLIED) && tmp->body_info[loc] && (!tmp->invisible || tmp->type == SKILL)) |
2807 | if (QUERY_FLAG (tmp, FLAG_APPLIED) && tmp->slot[loc].info && (!tmp->invisible || tmp->type == SKILL)) |
3005 | return tmp; |
2808 | return tmp; |
3006 | |
2809 | |
3007 | return NULL; |
2810 | return 0; |
3008 | } |
2811 | } |
3009 | |
|
|
3010 | |
|
|
3011 | |
2812 | |
3012 | /** |
2813 | /** |
3013 | * 'op' wants to apply an object, but can't because of other equipment. |
2814 | * 'op' wants to apply an object, but can't because of other equipment. |
3014 | * This should only be called when it is known |
2815 | * This should only be called when it is known |
3015 | * that there are objects to unapply. This makes pretty heavy |
2816 | * that there are objects to unapply. This makes pretty heavy |
… | |
… | |
3021 | * another function that does just that. |
2822 | * another function that does just that. |
3022 | */ |
2823 | */ |
3023 | int |
2824 | int |
3024 | unapply_for_ob (object *who, object *op, int aflags) |
2825 | unapply_for_ob (object *who, object *op, int aflags) |
3025 | { |
2826 | { |
3026 | int i; |
2827 | if (op->is_range ()) |
3027 | object *tmp = NULL, *last; |
|
|
3028 | |
|
|
3029 | /* If we are applying a shield or weapon, unapply any equipped shield |
|
|
3030 | * or weapons first - only allowed to use one weapon/shield at a time. |
|
|
3031 | */ |
|
|
3032 | if (op->type == WEAPON || op->type == SHIELD) |
|
|
3033 | { |
|
|
3034 | for (tmp = who->inv; tmp; tmp = tmp->below) |
2828 | for (object *tmp = who->inv; tmp; tmp = tmp->below) |
3035 | { |
|
|
3036 | if (QUERY_FLAG (tmp, FLAG_APPLIED) && tmp->type == op->type) |
2829 | if (QUERY_FLAG (tmp, FLAG_APPLIED) && tmp->is_range ()) |
3037 | { |
|
|
3038 | if ((aflags & AP_IGNORE_CURSE) || (aflags & AP_PRINT) || (!QUERY_FLAG (tmp, FLAG_CURSED) && !QUERY_FLAG (tmp, FLAG_DAMNED))) |
2830 | if ((aflags & AP_IGNORE_CURSE) || (aflags & AP_PRINT) || (!QUERY_FLAG (tmp, FLAG_CURSED) && !QUERY_FLAG (tmp, FLAG_DAMNED))) |
3039 | { |
2831 | { |
3040 | if (aflags & AP_PRINT) |
2832 | if (aflags & AP_PRINT) |
3041 | new_draw_info (NDI_UNIQUE, 0, who, query_name (tmp)); |
2833 | new_draw_info (NDI_UNIQUE, 0, who, query_name (tmp)); |
3042 | else |
2834 | else |
3043 | unapply_special (who, tmp, aflags); |
2835 | unapply_special (who, tmp, aflags); |
3044 | } |
2836 | } |
3045 | else |
2837 | else |
3046 | { |
2838 | { |
3047 | /* In this case, we want to try and remove a cursed item. |
2839 | /* In this case, we want to try and remove a cursed item. |
3048 | * While we know it won't work, we want unapply_special to |
2840 | * While we know it won't work, we want unapply_special to |
3049 | * at least generate the message. |
2841 | * at least generate the message. |
3050 | */ |
2842 | */ |
3051 | new_draw_info_format (NDI_UNIQUE, 0, who, "No matter how hard you try, you just can't\nremove %s.", query_name (tmp)); |
2843 | new_draw_info_format (NDI_UNIQUE, 0, who, "No matter how hard you try, you just can't remove the %s.", query_name (tmp)); |
3052 | return 1; |
2844 | return 1; |
3053 | } |
|
|
3054 | |
|
|
3055 | } |
2845 | } |
3056 | } |
|
|
3057 | } |
|
|
3058 | |
2846 | |
3059 | for (i = 0; i < NUM_BODY_LOCATIONS; i++) |
2847 | for (int i = 0; i < NUM_BODY_LOCATIONS; i++) |
3060 | { |
2848 | { |
3061 | /* this used up a slot that we need to free */ |
2849 | /* this used up a slot that we need to free */ |
3062 | if (op->body_info[i]) |
2850 | if (op->slot[i].info) |
3063 | { |
2851 | { |
3064 | last = who->inv; |
2852 | object *last = who->inv; |
3065 | |
2853 | |
3066 | /* We do a while loop - may need to remove several items in order |
2854 | /* We do a while loop - may need to remove several items in order |
3067 | * to free up enough slots. |
2855 | * to free up enough slots. |
3068 | */ |
2856 | */ |
3069 | while ((who->body_used[i] + op->body_info[i]) < 0) |
2857 | while ((who->slot[i].used + op->slot[i].info) < 0) |
3070 | { |
2858 | { |
3071 | tmp = get_item_from_body_location (last, i); |
2859 | object *tmp = get_item_from_body_location (i, last); |
|
|
2860 | |
3072 | if (!tmp) |
2861 | if (!tmp) |
3073 | { |
2862 | { |
3074 | #if 0 |
2863 | #if 0 |
3075 | /* Not a bug - we'll get this if the player has cursed items |
2864 | /* Not a bug - we'll get this if the player has cursed items |
3076 | * equipped. |
2865 | * equipped. |
3077 | */ |
2866 | */ |
3078 | LOG (llevError, "Can't find object using location %d (%s) on %s\n", i, body_locations[i].save_name, who->name); |
2867 | LOG (llevError, "Can't find object using location %d (%s) on %s\n", i, body_locations[i].save_name, who->name); |
3079 | #endif |
2868 | #endif |
3080 | return 1; |
2869 | return 1; |
3081 | } |
2870 | } |
|
|
2871 | |
3082 | /* If we are just printing, we don't care about cursed status */ |
2872 | /* If we are just printing, we don't care about cursed status */ |
3083 | if ((aflags & AP_IGNORE_CURSE) || (aflags & AP_PRINT) || (!(QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED)))) |
2873 | if ((aflags & AP_IGNORE_CURSE) || (aflags & AP_PRINT) || (!(QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED)))) |
3084 | { |
2874 | { |
3085 | if (aflags & AP_PRINT) |
2875 | if (aflags & AP_PRINT) |
3086 | new_draw_info (NDI_UNIQUE, 0, who, query_name (tmp)); |
2876 | new_draw_info (NDI_UNIQUE, 0, who, query_name (tmp)); |
… | |
… | |
3094 | * so it may not be critical (eg, putting on a ring and you have |
2884 | * so it may not be critical (eg, putting on a ring and you have |
3095 | * one cursed ring.) |
2885 | * one cursed ring.) |
3096 | */ |
2886 | */ |
3097 | new_draw_info_format (NDI_UNIQUE, 0, who, "The %s just won't come off", query_name (tmp)); |
2887 | new_draw_info_format (NDI_UNIQUE, 0, who, "The %s just won't come off", query_name (tmp)); |
3098 | } |
2888 | } |
|
|
2889 | |
3099 | last = tmp->below; |
2890 | last = tmp->below; |
3100 | } |
2891 | } |
3101 | /* if we got here, this slot is freed up - otherwise, if it wasn't freed up, the |
2892 | /* if we got here, this slot is freed up - otherwise, if it wasn't freed up, the |
3102 | * return in the !tmp would have kicked in. |
2893 | * return in the !tmp would have kicked in. |
3103 | */ |
2894 | */ |
3104 | } /* if op is using this body location */ |
2895 | } /* if op is using this body location */ |
3105 | } /* for body lcoations */ |
2896 | } /* for body lcoations */ |
|
|
2897 | |
3106 | return 0; |
2898 | return 0; |
3107 | } |
2899 | } |
3108 | |
2900 | |
3109 | /** |
2901 | /** |
3110 | * Checks to see if 'who' can apply object 'op'. |
2902 | * Checks to see if 'who' can apply object 'op'. |
3111 | * Returns 0 if apply can be done without anything special. |
2903 | * Returns 0 if apply can be done without anything special. |
3112 | * Otherwise returns a bitmask - potentially several of these may be |
2904 | * Otherwise returns a bitmask - potentially several of these may be |
3113 | * set, but largely depends on circumstance - in the future, processing |
2905 | * set, but largely depends on circumstance - in the future, processing |
3114 | * may be pruned once we know some status (eg, once CAN_APPLY_NEVER |
2906 | * may be pruned once we know some status (eg, once CAN_APPLY_NEVER |
3115 | * is set, do we really are what the other flags may be?) |
2907 | * is set, do we really are what the other flags may be?) |
3116 | * |
2908 | * |
3117 | * See include/define.h for detailed description of the meaning of |
2909 | * See include/define.h for detailed description of the meaning of |
3118 | * these return values. |
2910 | * these return values. |
3119 | */ |
2911 | */ |
… | |
… | |
3121 | can_apply_object (object *who, object *op) |
2913 | can_apply_object (object *who, object *op) |
3122 | { |
2914 | { |
3123 | if (INVOKE_OBJECT (CAN_BE_APPLIED, op, ARG_OBJECT (who)) || INVOKE_OBJECT (CAN_APPLY, who, ARG_OBJECT (op))) |
2915 | if (INVOKE_OBJECT (CAN_BE_APPLIED, op, ARG_OBJECT (who)) || INVOKE_OBJECT (CAN_APPLY, who, ARG_OBJECT (op))) |
3124 | return RESULT_INT (0); |
2916 | return RESULT_INT (0); |
3125 | |
2917 | |
3126 | int i, retval = 0; |
2918 | int retval = 0; |
3127 | object *tmp = NULL, *ws = NULL; |
2919 | object *tmp = 0, *ws = 0; |
3128 | |
2920 | |
3129 | /* Players have 2 'arm's, so they could in theory equip 2 shields or |
2921 | for (int i = 0; i < NUM_BODY_LOCATIONS; i++) |
3130 | * 2 weapons, but we don't want to let them do that. So if they are |
|
|
3131 | * trying to equip a weapon or shield, see if they already have one |
|
|
3132 | * in place and store that way. |
|
|
3133 | */ |
|
|
3134 | if (op->type == WEAPON || op->type == SHIELD) |
|
|
3135 | { |
2922 | { |
3136 | for (tmp = who->inv; tmp && !ws; tmp = tmp->below) |
2923 | if (op->slot[i].info) |
3137 | { |
2924 | { |
3138 | if (QUERY_FLAG (tmp, FLAG_APPLIED) && tmp->type == op->type) |
2925 | /* Item uses more slots than we have */ |
|
|
2926 | if (abs (op->slot[i].info) > who->slot[i].info) |
3139 | { |
2927 | { |
3140 | retval = CAN_APPLY_UNAPPLY; |
|
|
3141 | ws = tmp; |
|
|
3142 | } |
|
|
3143 | } |
|
|
3144 | } |
|
|
3145 | |
|
|
3146 | |
|
|
3147 | for (i = 0; i < NUM_BODY_LOCATIONS; i++) |
|
|
3148 | { |
|
|
3149 | if (op->body_info[i]) |
|
|
3150 | { |
|
|
3151 | /* Item uses more slots than we have */ |
|
|
3152 | if (FABS (op->body_info[i]) > who->body_info[i]) |
|
|
3153 | { |
|
|
3154 | /* Could return now for efficiently - rest of info below isn' |
2928 | /* Could return now for efficiency - rest of info below isn't |
3155 | * really needed. |
2929 | * really needed. |
3156 | */ |
2930 | */ |
3157 | retval |= CAN_APPLY_NEVER; |
2931 | retval |= CAN_APPLY_NEVER; |
3158 | } |
2932 | } |
3159 | else if ((who->body_used[i] + op->body_info[i]) < 0) |
2933 | else if ((who->slot[i].used + op->slot[i].info) < 0) |
3160 | { |
2934 | { |
3161 | /* in this case, equipping this would use more free spots than |
2935 | /* in this case, equipping this would use more free spots than |
3162 | * we have. |
2936 | * we have. |
3163 | */ |
2937 | */ |
3164 | object *tmp1; |
|
|
3165 | |
|
|
3166 | |
2938 | |
3167 | /* if we have an applied weapon/shield, and unapply it would free |
2939 | /* if we have an applied weapon/shield, and unapply it would free |
3168 | * enough slots to equip the new item, then just set this can |
2940 | * enough slots to equip the new item, then just set "can |
3169 | * continue. We don't care about the logic below - if you have |
2941 | * apply unapply". We don't care about the logic below - if you have a |
3170 | * shield equipped and try to equip another shield, there is only |
2942 | * shield equipped and try to equip another shield, there is only |
3171 | * one choice. However, the check for the number of body locations |
2943 | * one choice. However, the check for the number of body locations |
3172 | * does take into the account cases where what is being applied |
2944 | * does take into the account cases where what is being applied |
3173 | * may be two handed for example. |
2945 | * may be two handed for example. |
3174 | */ |
2946 | */ |
3175 | if (ws) |
2947 | if (ws) |
3176 | { |
2948 | if ((who->slot[i].used - ws->slot[i].info + op->slot[i].info) >= 0) |
3177 | if ((who->body_used[i] - ws->body_info[i] + op->body_info[i]) >= 0) |
|
|
3178 | { |
2949 | { |
3179 | retval |= CAN_APPLY_UNAPPLY; |
2950 | retval |= CAN_APPLY_UNAPPLY; |
3180 | continue; |
2951 | continue; |
3181 | } |
2952 | } |
3182 | } |
|
|
3183 | |
2953 | |
3184 | tmp1 = get_item_from_body_location (who->inv, i); |
2954 | object *tmp1 = get_item_from_body_location (i, who->inv); |
3185 | if (!tmp1) |
2955 | if (!tmp1) |
3186 | { |
2956 | { |
3187 | #if 0 |
2957 | #if 0 |
3188 | /* This is sort of an error, but happens a lot when old players |
2958 | /* This is sort of an error, but happens a lot when old players |
3189 | * join in with more stuff equipped than they are now allowed. |
2959 | * join in with more stuff equipped than they are now allowed. |
… | |
… | |
3200 | */ |
2970 | */ |
3201 | retval |= CAN_APPLY_UNAPPLY; |
2971 | retval |= CAN_APPLY_UNAPPLY; |
3202 | if (!tmp) |
2972 | if (!tmp) |
3203 | tmp = tmp1; |
2973 | tmp = tmp1; |
3204 | else if (tmp != tmp1) |
2974 | else if (tmp != tmp1) |
3205 | { |
|
|
3206 | retval |= CAN_APPLY_UNAPPLY_MULT; |
2975 | retval |= CAN_APPLY_UNAPPLY_MULT; |
3207 | } |
2976 | |
3208 | /* This object isn't using up all the slots, so there must |
2977 | /* This object isn't using up all the slots, so there must |
3209 | * be another. If so, and it the new item doesn't need all |
2978 | * be another. If so, and it the new item doesn't need all |
3210 | * the slots, the player then has a choice. |
2979 | * the slots, the player then has a choice. |
3211 | */ |
2980 | */ |
3212 | if (((who->body_used[i] - tmp1->body_info[i]) != who->body_info[i]) && (FABS (op->body_info[i]) < who->body_info[i])) |
2981 | if ((who->slot[i].used - tmp1->slot[i].info != who->slot[i].info) |
|
|
2982 | && abs (op->slot[i].info) < who->slot[i].info) |
3213 | retval |= CAN_APPLY_UNAPPLY_CHOICE; |
2983 | retval |= CAN_APPLY_UNAPPLY_CHOICE; |
3214 | |
2984 | |
3215 | /* Does unequippint 'tmp1' free up enough slots for this to be |
2985 | /* Does unequippint 'tmp1' free up enough slots for this to be |
3216 | * equipped? If not, there must be something else to unapply. |
2986 | * equipped? If not, there must be something else to unapply. |
3217 | */ |
2987 | */ |
3218 | if ((who->body_used[i] + op->body_info[i] - tmp1->body_info[i]) < 0) |
2988 | if (who->slot[i].used + op->slot[i].info < tmp1->slot[i].info) |
3219 | retval |= CAN_APPLY_UNAPPLY_MULT; |
2989 | retval |= CAN_APPLY_UNAPPLY_MULT; |
3220 | |
|
|
3221 | } |
2990 | } |
3222 | } /* if not enough free slots */ |
2991 | } /* if not enough free slots */ |
3223 | } /* if this object uses location i */ |
2992 | } /* if this object uses location i */ |
3224 | } /* for i -> num_body_locations loop */ |
2993 | } /* for i -> num_body_locations loop */ |
3225 | |
2994 | |
… | |
… | |
3230 | * and weapons all use the same slot. Similar for horn/rod/wand - they |
2999 | * and weapons all use the same slot. Similar for horn/rod/wand - they |
3231 | * all use the same location. |
3000 | * all use the same location. |
3232 | */ |
3001 | */ |
3233 | if (op->type == WEAPON && !QUERY_FLAG (who, FLAG_USE_WEAPON)) |
3002 | if (op->type == WEAPON && !QUERY_FLAG (who, FLAG_USE_WEAPON)) |
3234 | retval |= CAN_APPLY_RESTRICTION; |
3003 | retval |= CAN_APPLY_RESTRICTION; |
|
|
3004 | |
3235 | if (op->type == SHIELD && !QUERY_FLAG (who, FLAG_USE_SHIELD)) |
3005 | if (op->type == SHIELD && !QUERY_FLAG (who, FLAG_USE_SHIELD)) |
3236 | retval |= CAN_APPLY_RESTRICTION; |
3006 | retval |= CAN_APPLY_RESTRICTION; |
3237 | |
3007 | |
3238 | |
|
|
3239 | if (who->type != PLAYER) |
3008 | if (who->type != PLAYER) |
3240 | { |
3009 | { |
3241 | if ((op->type == WAND || op->type == HORN || op->type == ROD) && !QUERY_FLAG (who, FLAG_USE_RANGE)) |
3010 | if ((op->type == WAND || op->type == HORN || op->type == ROD) && !QUERY_FLAG (who, FLAG_USE_RANGE)) |
3242 | retval |= CAN_APPLY_RESTRICTION; |
3011 | retval |= CAN_APPLY_RESTRICTION; |
|
|
3012 | |
3243 | if (op->type == BOW && !QUERY_FLAG (who, FLAG_USE_BOW)) |
3013 | if (op->type == BOW && !QUERY_FLAG (who, FLAG_USE_BOW)) |
3244 | retval |= CAN_APPLY_RESTRICTION; |
3014 | retval |= CAN_APPLY_RESTRICTION; |
|
|
3015 | |
3245 | if (op->type == RING && !QUERY_FLAG (who, FLAG_USE_RING)) |
3016 | if (op->type == RING && !QUERY_FLAG (who, FLAG_USE_RING)) |
3246 | retval |= CAN_APPLY_RESTRICTION; |
3017 | retval |= CAN_APPLY_RESTRICTION; |
|
|
3018 | |
3247 | if (op->type == BOW && !QUERY_FLAG (who, FLAG_USE_BOW)) |
3019 | if (op->type == BOW && !QUERY_FLAG (who, FLAG_USE_BOW)) |
3248 | retval |= CAN_APPLY_RESTRICTION; |
3020 | retval |= CAN_APPLY_RESTRICTION; |
3249 | } |
3021 | } |
|
|
3022 | |
3250 | return retval; |
3023 | return retval; |
3251 | } |
3024 | } |
3252 | |
|
|
3253 | |
|
|
3254 | |
3025 | |
3255 | /** |
3026 | /** |
3256 | * who is the object using the object. It can be a monster. |
3027 | * who is the object using the object. It can be a monster. |
3257 | * op is the object they are using. op is an equipment type item, |
3028 | * op is the object they are using. op is an equipment type item, |
3258 | * eg, one which you put on and keep on for a while, and not something |
3029 | * eg, one which you put on and keep on for a while, and not something |
… | |
… | |
3277 | int |
3048 | int |
3278 | apply_special (object *who, object *op, int aflags) |
3049 | apply_special (object *who, object *op, int aflags) |
3279 | { |
3050 | { |
3280 | int basic_flag = aflags & AP_BASIC_FLAGS; |
3051 | int basic_flag = aflags & AP_BASIC_FLAGS; |
3281 | object *tmp, *tmp2, *skop = NULL; |
3052 | object *tmp, *tmp2, *skop = NULL; |
3282 | int i; |
|
|
3283 | |
3053 | |
3284 | if (who == NULL) |
3054 | if (who == NULL) |
3285 | { |
3055 | { |
3286 | LOG (llevError, "apply_special() from object without environment.\n"); |
3056 | LOG (llevError, "apply_special() from object without environment.\n"); |
3287 | return 1; |
3057 | return 1; |
… | |
… | |
3297 | if (basic_flag == AP_APPLY) |
3067 | if (basic_flag == AP_APPLY) |
3298 | return 0; |
3068 | return 0; |
3299 | |
3069 | |
3300 | if (!(aflags & AP_IGNORE_CURSE) && (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED))) |
3070 | if (!(aflags & AP_IGNORE_CURSE) && (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED))) |
3301 | { |
3071 | { |
3302 | new_draw_info_format (NDI_UNIQUE, 0, who, "No matter how hard you try, you just can't\nremove %s.", query_name (op)); |
3072 | new_draw_info_format (NDI_UNIQUE, 0, who, "No matter how hard you try, you just can't remove %s.", query_name (op)); |
3303 | return 1; |
3073 | return 1; |
3304 | } |
3074 | } |
|
|
3075 | |
3305 | return unapply_special (who, op, aflags); |
3076 | return unapply_special (who, op, aflags); |
3306 | } |
3077 | } |
3307 | |
3078 | |
3308 | if (basic_flag == AP_UNAPPLY) |
3079 | if (basic_flag == AP_UNAPPLY) |
3309 | return 0; |
3080 | return 0; |
3310 | |
3081 | |
3311 | i = can_apply_object (who, op); |
3082 | // if the item is combat/ranged, wield the relevant slot first |
|
|
3083 | // to resolve conflicts. |
|
|
3084 | if (player *pl = who->contr) |
|
|
3085 | switch (op->type) |
|
|
3086 | { |
|
|
3087 | case WEAPON: |
|
|
3088 | who->change_weapon (pl->combat_ob); |
|
|
3089 | break; |
|
|
3090 | |
|
|
3091 | case BOW: |
|
|
3092 | case ROD: |
|
|
3093 | case WAND: |
|
|
3094 | case HORN: |
|
|
3095 | case SKILL_TOOL: |
|
|
3096 | who->change_weapon (pl->ranged_ob); |
|
|
3097 | break; |
|
|
3098 | |
|
|
3099 | case SKILL: |
|
|
3100 | if (IS_COMBAT_SKILL (op->subtype)) |
|
|
3101 | who->change_weapon (pl->combat_ob); |
|
|
3102 | else if (IS_RANGED_SKILL (op->subtype)) |
|
|
3103 | who->change_weapon (pl->ranged_ob); |
|
|
3104 | break; |
|
|
3105 | } |
3312 | |
3106 | |
3313 | /* Can't just apply this object. Lets see what not and what to do */ |
3107 | /* Can't just apply this object. Lets see what not and what to do */ |
3314 | if (i) |
3108 | if (int i = can_apply_object (who, op)) |
3315 | { |
3109 | { |
3316 | if (i & CAN_APPLY_NEVER) |
3110 | if (i & CAN_APPLY_NEVER) |
3317 | { |
3111 | { |
3318 | new_draw_info_format (NDI_UNIQUE, 0, who, "You don't have the body to use a %s\n", query_name (op)); |
3112 | new_draw_info_format (NDI_UNIQUE, 0, who, "You don't have the body to use a %s\n", query_name (op)); |
3319 | return 1; |
3113 | return 1; |
… | |
… | |
3321 | else if (i & CAN_APPLY_RESTRICTION) |
3115 | else if (i & CAN_APPLY_RESTRICTION) |
3322 | { |
3116 | { |
3323 | new_draw_info_format (NDI_UNIQUE, 0, who, "You have a prohibition against using a %s\n", query_name (op)); |
3117 | new_draw_info_format (NDI_UNIQUE, 0, who, "You have a prohibition against using a %s\n", query_name (op)); |
3324 | return 1; |
3118 | return 1; |
3325 | } |
3119 | } |
|
|
3120 | |
3326 | if (who->type != PLAYER) |
3121 | if (who->type != PLAYER) |
3327 | { |
3122 | { |
3328 | /* Some error, so don't try to equip something more */ |
3123 | /* Some error, so don't try to equip something more */ |
3329 | if (unapply_for_ob (who, op, aflags)) |
3124 | if (unapply_for_ob (who, op, aflags)) |
3330 | return 1; |
3125 | return 1; |
… | |
… | |
3336 | new_draw_info (NDI_UNIQUE, 0, who, "You need to unapply some of the following item(s) or change your applymode:"); |
3131 | new_draw_info (NDI_UNIQUE, 0, who, "You need to unapply some of the following item(s) or change your applymode:"); |
3337 | unapply_for_ob (who, op, AP_PRINT); |
3132 | unapply_for_ob (who, op, AP_PRINT); |
3338 | return 1; |
3133 | return 1; |
3339 | } |
3134 | } |
3340 | else if (who->contr->unapply == unapply_always || !(i & CAN_APPLY_UNAPPLY_CHOICE)) |
3135 | else if (who->contr->unapply == unapply_always || !(i & CAN_APPLY_UNAPPLY_CHOICE)) |
3341 | { |
|
|
3342 | i = unapply_for_ob (who, op, aflags); |
3136 | if (unapply_for_ob (who, op, aflags)) |
3343 | if (i) |
|
|
3344 | return 1; |
3137 | return 1; |
3345 | } |
|
|
3346 | } |
3138 | } |
3347 | } |
3139 | } |
3348 | |
3140 | |
3349 | if (op->skill && op->type != SKILL && op->type != SKILL_TOOL) |
3141 | if (op->skill && op->type != SKILL && op->type != SKILL_TOOL) |
3350 | { |
3142 | { |
3351 | skop = find_skill_by_name (who, op->skill); |
3143 | skop = find_skill_by_name (who, op->skill); |
|
|
3144 | |
3352 | if (!skop) |
3145 | if (!skop) |
3353 | { |
3146 | { |
3354 | new_draw_info_format (NDI_UNIQUE, 0, who, "You need the %s skill to use this item!", &op->skill); |
3147 | new_draw_info_format (NDI_UNIQUE, 0, who, "You need the %s skill to use this item!", &op->skill); |
3355 | return 1; |
3148 | return 1; |
3356 | } |
3149 | } |
3357 | else |
3150 | else |
3358 | { |
|
|
3359 | /* While experience will be credited properly, we want to change the |
3151 | /* While experience will be credited properly, we want to change the |
3360 | * skill so that the dam and wc get updated |
3152 | * skill so that the dam and wc get updated |
3361 | */ |
3153 | */ |
3362 | change_skill (who, skop, 0); |
3154 | change_skill (who, skop, 0); |
3363 | } |
|
|
3364 | } |
|
|
3365 | |
|
|
3366 | if (who->type == PLAYER && op->item_power && (op->item_power + who->contr->item_power) > (settings.item_power_factor * who->level)) |
|
|
3367 | { |
3155 | } |
3368 | new_draw_info (NDI_UNIQUE, 0, who, "Equipping that combined with other items would consume your soul!"); |
3156 | |
|
|
3157 | if (who->type == PLAYER |
|
|
3158 | && op->item_power |
|
|
3159 | && op->item_power + who->contr->item_power > settings.item_power_factor * who->level) |
|
|
3160 | { |
|
|
3161 | new_draw_info (NDI_UNIQUE, 0, who, |
|
|
3162 | "Equipping that combined with other items would consume your soul! " |
|
|
3163 | "[use the skills command to check your available item power]"); |
3369 | return 1; |
3164 | return 1; |
3370 | } |
3165 | } |
3371 | |
|
|
3372 | |
3166 | |
3373 | /* Ok. We are now at the state where we can apply the new object. |
3167 | /* Ok. We are now at the state where we can apply the new object. |
3374 | * Note that we don't have the checks for can_use_... |
3168 | * Note that we don't have the checks for can_use_... |
3375 | * below - that is already taken care of by can_apply_object. |
3169 | * below - that is already taken care of by can_apply_object. |
3376 | */ |
3170 | */ |
3377 | |
|
|
3378 | |
|
|
3379 | if (op->nrof > 1) |
3171 | if (op->nrof > 1) |
3380 | tmp = get_split_ob (op, op->nrof - 1); |
3172 | tmp = get_split_ob (op, op->nrof - 1); |
3381 | else |
3173 | else |
3382 | tmp = NULL; |
3174 | tmp = 0; |
3383 | |
3175 | |
3384 | if (INVOKE_OBJECT (BE_READY, op, ARG_OBJECT (who)) || INVOKE_OBJECT (READY, who, ARG_OBJECT (op))) |
3176 | if (INVOKE_OBJECT (BE_READY, op, ARG_OBJECT (who)) || INVOKE_OBJECT (READY, who, ARG_OBJECT (op))) |
3385 | return RESULT_INT (0); |
3177 | return RESULT_INT (0); |
3386 | |
3178 | |
3387 | switch (op->type) |
3179 | switch (op->type) |
3388 | { |
3180 | { |
3389 | case WEAPON: |
3181 | case WEAPON: |
3390 | if (!check_weapon_power (who, op->last_eat)) |
3182 | if (!check_weapon_power (who, op->last_eat)) |
3391 | { |
3183 | { |
3392 | new_draw_info (NDI_UNIQUE, 0, who, "That weapon is too powerful for you to use."); |
3184 | new_draw_info (NDI_UNIQUE, 0, who, "This weapon is too powerful for you to use.\n" |
3393 | new_draw_info (NDI_UNIQUE, 0, who, "It would consume your soul!."); |
3185 | "It would consume your soul!."); |
|
|
3186 | |
3394 | if (tmp != NULL) |
3187 | if (tmp) |
3395 | (void) insert_ob_in_ob (tmp, who); |
3188 | insert_ob_in_ob (tmp, who); |
|
|
3189 | |
3396 | return 1; |
3190 | return 1; |
3397 | } |
3191 | } |
3398 | |
3192 | |
3399 | //TODO: this obviously fails for players using a shiorter prefix |
3193 | //TODO: this obviously fails for players using a shorter prefix |
3400 | // i.e. "R" can use Ragnarok's swors. |
3194 | // i.e. "R" can use Ragnarok's sword. |
3401 | if (op->level && (strncmp (op->name, who->name, strlen (who->name)))) |
3195 | if (op->level && (strncmp (op->name, who->name, strlen (who->name)))) |
3402 | { |
3196 | { |
3403 | /* if the weapon does not have the name as the character, can't use it. */ |
3197 | /* if the weapon does not have the name as the character, can't use it. */ |
3404 | /* (Ragnarok's sword attempted to be used by Foo: won't work) */ |
3198 | /* (Ragnarok's sword attempted to be used by Foo: won't work) */ |
3405 | new_draw_info (NDI_UNIQUE, 0, who, "The weapon does not recognize you as its owner."); |
3199 | new_draw_info (NDI_UNIQUE, 0, who, "The weapon does not recognize you as its owner."); |
… | |
… | |
3408 | insert_ob_in_ob (tmp, who); |
3202 | insert_ob_in_ob (tmp, who); |
3409 | |
3203 | |
3410 | return 1; |
3204 | return 1; |
3411 | } |
3205 | } |
3412 | |
3206 | |
|
|
3207 | if (!skop) |
|
|
3208 | { |
|
|
3209 | new_draw_info_format (NDI_UNIQUE, 0, who, "The %s is broken, please report this to the dungeon master!", query_name (op));//TODO |
|
|
3210 | return 1; |
|
|
3211 | } |
|
|
3212 | |
3413 | SET_FLAG (op, FLAG_APPLIED); |
3213 | SET_FLAG (op, FLAG_APPLIED); |
3414 | |
|
|
3415 | if (skop) |
|
|
3416 | change_skill (who, skop, 1); |
3214 | change_skill (who, skop, 1); |
|
|
3215 | |
|
|
3216 | if (who->contr) |
|
|
3217 | who->change_weapon (who->contr->combat_ob = op); |
|
|
3218 | |
3417 | if (!QUERY_FLAG (who, FLAG_READY_WEAPON)) |
3219 | if (!QUERY_FLAG (who, FLAG_READY_WEAPON)) |
3418 | SET_FLAG (who, FLAG_READY_WEAPON); |
3220 | SET_FLAG (who, FLAG_READY_WEAPON); |
3419 | |
3221 | |
3420 | new_draw_info_format (NDI_UNIQUE, 0, who, "You wield %s.", query_name (op)); |
3222 | new_draw_info_format (NDI_UNIQUE, 0, who, "You wield %s.", query_name (op)); |
3421 | |
3223 | |
3422 | (void) change_abil (who, op); |
3224 | change_abil (who, op); |
3423 | break; |
3225 | break; |
3424 | |
3226 | |
3425 | case ARMOUR: |
3227 | case ARMOUR: |
3426 | case HELMET: |
3228 | case HELMET: |
3427 | case SHIELD: |
3229 | case SHIELD: |
… | |
… | |
3432 | case CLOAK: |
3234 | case CLOAK: |
3433 | case RING: |
3235 | case RING: |
3434 | case AMULET: |
3236 | case AMULET: |
3435 | SET_FLAG (op, FLAG_APPLIED); |
3237 | SET_FLAG (op, FLAG_APPLIED); |
3436 | new_draw_info_format (NDI_UNIQUE, 0, who, "You wear %s.", query_name (op)); |
3238 | new_draw_info_format (NDI_UNIQUE, 0, who, "You wear %s.", query_name (op)); |
3437 | (void) change_abil (who, op); |
3239 | change_abil (who, op); |
3438 | break; |
3240 | break; |
|
|
3241 | |
3439 | case LAMP: |
3242 | case LAMP: |
3440 | if (op->stats.food < 1) |
3243 | if (op->stats.food < 1) |
3441 | { |
3244 | { |
3442 | new_draw_info_format (NDI_UNIQUE, 0, who, "Your %s is out of" " fuel!", &op->name); |
3245 | new_draw_info_format (NDI_UNIQUE, 0, who, "Your %s is out of fuel!", &op->name); |
3443 | return 1; |
3246 | return 1; |
3444 | } |
3247 | } |
|
|
3248 | |
3445 | new_draw_info_format (NDI_UNIQUE, 0, who, "You turn on your %s.", &op->name); |
3249 | new_draw_info_format (NDI_UNIQUE, 0, who, "You turn on your %s.", &op->name); |
3446 | tmp2 = arch_to_object (op->other_arch); |
3250 | tmp2 = arch_to_object (op->other_arch); |
3447 | tmp2->stats.food = op->stats.food; |
3251 | tmp2->stats.food = op->stats.food; |
3448 | SET_FLAG (tmp2, FLAG_APPLIED); |
3252 | SET_FLAG (tmp2, FLAG_APPLIED); |
|
|
3253 | |
3449 | if (QUERY_FLAG (op, FLAG_INV_LOCKED)) |
3254 | if (QUERY_FLAG (op, FLAG_INV_LOCKED)) |
3450 | SET_FLAG (tmp2, FLAG_INV_LOCKED); |
3255 | SET_FLAG (tmp2, FLAG_INV_LOCKED); |
|
|
3256 | |
3451 | insert_ob_in_ob (tmp2, who); |
3257 | insert_ob_in_ob (tmp2, who); |
3452 | |
3258 | |
3453 | /* Remove the old lantern */ |
3259 | /* Remove the old lantern */ |
3454 | if (who->type == PLAYER) |
3260 | if (who->type == PLAYER) |
3455 | esrv_del_item (who->contr, op->count); |
3261 | esrv_del_item (who->contr, op->count); |
3456 | |
3262 | |
3457 | op->destroy (); |
3263 | op->destroy (); |
3458 | |
3264 | |
3459 | /* insert the portion that was split off */ |
3265 | /* insert the portion that was split off */ |
3460 | if (tmp != NULL) |
3266 | if (tmp) |
3461 | { |
3267 | { |
3462 | (void) insert_ob_in_ob (tmp, who); |
3268 | insert_ob_in_ob (tmp, who); |
3463 | if (who->type == PLAYER) |
3269 | if (who->type == PLAYER) |
3464 | esrv_send_item (who, tmp); |
3270 | esrv_send_item (who, tmp); |
3465 | } |
3271 | } |
|
|
3272 | |
3466 | who->update_stats (); |
3273 | who->update_stats (); |
|
|
3274 | |
3467 | if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED)) |
3275 | if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED)) |
3468 | { |
|
|
3469 | if (who->type == PLAYER) |
3276 | if (who->type == PLAYER) |
3470 | { |
3277 | { |
3471 | new_draw_info (NDI_UNIQUE, 0, who, "Oops, it feels deadly cold!"); |
3278 | new_draw_info (NDI_UNIQUE, 0, who, "Oops, it feels deadly cold!"); |
3472 | SET_FLAG (tmp2, FLAG_KNOWN_CURSED); |
3279 | SET_FLAG (tmp2, FLAG_KNOWN_CURSED); |
3473 | } |
3280 | } |
3474 | } |
3281 | |
3475 | if (who->type == PLAYER) |
3282 | if (who->type == PLAYER) |
3476 | esrv_send_item (who, tmp2); |
3283 | esrv_send_item (who, tmp2); |
|
|
3284 | |
3477 | return 0; |
3285 | return 0; |
3478 | break; |
|
|
3479 | |
3286 | |
3480 | /* this part is needed for skill-tools */ |
3287 | /* this part is needed for skill-tools */ |
3481 | case SKILL: |
3288 | case SKILL: |
3482 | case SKILL_TOOL: |
3289 | case SKILL_TOOL: |
3483 | if (who->chosen_skill) |
3290 | if (who->chosen_skill) |
3484 | { |
3291 | { |
3485 | LOG (llevError, "BUG: apply_special(): can't apply two skills\n"); |
3292 | LOG (llevError, "BUG: apply_special(): can't apply two skills\n"); |
3486 | return 1; |
3293 | return 1; |
3487 | } |
3294 | } |
3488 | if (who->type == PLAYER) |
3295 | |
|
|
3296 | if (player *pl = who->contr) |
|
|
3297 | { |
|
|
3298 | if (IS_COMBAT_SKILL (op->subtype)) |
3489 | { |
3299 | { |
3490 | who->contr->shoottype = range_skill; |
3300 | if (skill_flags [op->subtype] & SF_NEED_WEAPON) |
3491 | who->contr->ranges[range_skill] = op; |
3301 | { |
|
|
3302 | for (object *item = who->inv; item; item = item->below) |
|
|
3303 | if (item->type == WEAPON && item->flag [FLAG_APPLIED]) |
|
|
3304 | { |
|
|
3305 | who->change_weapon (pl->combat_ob = item); |
|
|
3306 | goto found_weapon; |
|
|
3307 | } |
|
|
3308 | |
|
|
3309 | new_draw_info (NDI_UNIQUE, 0, who, "You need to apply a melee weapon before readying this skill"); |
|
|
3310 | return 1; |
|
|
3311 | |
|
|
3312 | found_weapon:; |
|
|
3313 | } |
|
|
3314 | else |
|
|
3315 | who->change_weapon (pl->combat_ob = op); |
|
|
3316 | } |
|
|
3317 | else if (IS_RANGED_SKILL (op->subtype)) |
|
|
3318 | { |
|
|
3319 | if (skill_flags [op->subtype] & SF_NEED_BOW) |
|
|
3320 | { |
|
|
3321 | for (object *item = who->inv; item; item = item->below) |
|
|
3322 | if (item->type == BOW && item->flag [FLAG_APPLIED]) |
|
|
3323 | { |
|
|
3324 | who->change_weapon (pl->ranged_ob = item); |
|
|
3325 | goto found_bow; |
|
|
3326 | } |
|
|
3327 | |
|
|
3328 | new_draw_info (NDI_UNIQUE, 0, who, "You need to apply a missile weapon before readying this skill"); |
|
|
3329 | return 1; |
|
|
3330 | |
|
|
3331 | found_bow:; |
|
|
3332 | } |
|
|
3333 | else if (skill_flags [op->subtype] & SF_NEED_ITEM) |
|
|
3334 | { |
|
|
3335 | for (object *item = who->inv; item; item = item->below) |
|
|
3336 | if (item->flag [FLAG_APPLIED] |
|
|
3337 | && (item->type == WAND || item->type == ROD || item->type == HORN)) |
|
|
3338 | { |
|
|
3339 | who->change_weapon (pl->ranged_ob = item); |
|
|
3340 | goto found_item; |
|
|
3341 | } |
|
|
3342 | |
|
|
3343 | new_draw_info (NDI_UNIQUE, 0, who, "You need to apply a magic item before readying this skill"); |
|
|
3344 | return 1; |
|
|
3345 | |
|
|
3346 | found_item:; |
|
|
3347 | } |
|
|
3348 | else |
|
|
3349 | who->change_weapon (pl->ranged_ob = op); |
|
|
3350 | } |
|
|
3351 | |
3492 | if (!op->invisible) |
3352 | if (!op->invisible) |
3493 | { |
3353 | { |
3494 | new_draw_info_format (NDI_UNIQUE, 0, who, "You ready %s.", query_name (op)); |
3354 | new_draw_info_format (NDI_UNIQUE, 0, who, "You ready %s.", query_name (op)); |
3495 | new_draw_info_format (NDI_UNIQUE, 0, who, "You can now use the skill: %s.", &op->skill); |
3355 | new_draw_info_format (NDI_UNIQUE, 0, who, "You can now use the skill: %s.", &op->skill); |
3496 | } |
3356 | } |
3497 | else |
3357 | else |
3498 | { |
|
|
3499 | new_draw_info_format (NDI_UNIQUE, 0, who, "Readied skill: %s.", op->skill ? &op->skill : &op->name); |
3358 | new_draw_info_format (NDI_UNIQUE, 0, who, "Readied skill: %s.", op->skill ? &op->skill : &op->name); |
3500 | } |
3359 | } |
3501 | } |
3360 | |
3502 | SET_FLAG (op, FLAG_APPLIED); |
3361 | SET_FLAG (op, FLAG_APPLIED); |
3503 | (void) change_abil (who, op); |
3362 | change_abil (who, op); |
3504 | who->chosen_skill = op; |
3363 | who->chosen_skill = op; |
3505 | SET_FLAG (who, FLAG_READY_SKILL); |
3364 | SET_FLAG (who, FLAG_READY_SKILL); |
3506 | break; |
3365 | break; |
3507 | |
3366 | |
3508 | case BOW: |
3367 | case BOW: |
3509 | if (!check_weapon_power (who, op->last_eat)) |
3368 | if (!check_weapon_power (who, op->last_eat)) |
3510 | { |
3369 | { |
3511 | new_draw_info (NDI_UNIQUE, 0, who, "That item is too powerful for you to use."); |
3370 | new_draw_info (NDI_UNIQUE, 0, who, "That weapon is too powerful for you to use."); |
3512 | new_draw_info (NDI_UNIQUE, 0, who, "It would consume your soul!."); |
3371 | new_draw_info (NDI_UNIQUE, 0, who, "It would consume your soul!."); |
|
|
3372 | |
3513 | if (tmp != NULL) |
3373 | if (tmp) |
3514 | (void) insert_ob_in_ob (tmp, who); |
3374 | insert_ob_in_ob (tmp, who); |
|
|
3375 | |
3515 | return 1; |
3376 | return 1; |
3516 | } |
3377 | } |
|
|
3378 | |
3517 | if (op->level && (strncmp (op->name, who->name, strlen (who->name)))) |
3379 | if (op->level && (strncmp (op->name, who->name, strlen (who->name)))) |
3518 | { |
3380 | { |
3519 | new_draw_info (NDI_UNIQUE, 0, who, "The weapon does not recognize you as its owner."); |
3381 | new_draw_info (NDI_UNIQUE, 0, who, "The weapon does not recognize you as its owner."); |
3520 | if (tmp != NULL) |
3382 | if (tmp) |
3521 | (void) insert_ob_in_ob (tmp, who); |
3383 | insert_ob_in_ob (tmp, who); |
|
|
3384 | |
3522 | return 1; |
3385 | return 1; |
3523 | } |
3386 | } |
|
|
3387 | |
3524 | /*FALLTHROUGH*/ case WAND: |
3388 | /*FALLTHROUGH*/ |
|
|
3389 | case WAND: |
3525 | case ROD: |
3390 | case ROD: |
3526 | case HORN: |
3391 | case HORN: |
3527 | /* check for skill, alter player status */ |
3392 | /* check for skill, alter player status */ |
|
|
3393 | |
|
|
3394 | if (!skop) |
|
|
3395 | { |
|
|
3396 | new_draw_info_format (NDI_UNIQUE, 0, who, "The %s is broken, please report this to the dungeon master!", query_name (op));//TODO |
|
|
3397 | return 1; |
|
|
3398 | } |
|
|
3399 | |
3528 | SET_FLAG (op, FLAG_APPLIED); |
3400 | SET_FLAG (op, FLAG_APPLIED); |
3529 | if (skop) |
|
|
3530 | change_skill (who, skop, 0); |
3401 | change_skill (who, skop, 0); |
|
|
3402 | |
|
|
3403 | if (who->contr) |
|
|
3404 | { |
|
|
3405 | who->contr->ranged_ob = op; |
|
|
3406 | |
3531 | new_draw_info_format (NDI_UNIQUE, 0, who, "You ready %s.", query_name (op)); |
3407 | new_draw_info_format (NDI_UNIQUE, 0, who, "You ready %s.", query_name (op)); |
3532 | |
3408 | |
3533 | if (who->type == PLAYER) |
|
|
3534 | { |
|
|
3535 | if (op->type == BOW) |
3409 | if (op->type == BOW) |
3536 | { |
3410 | { |
|
|
3411 | who->current_weapon = op; |
3537 | (void) change_abil (who, op); |
3412 | change_abil (who, op); |
3538 | new_draw_info_format (NDI_UNIQUE, 0, who, |
3413 | new_draw_info_format (NDI_UNIQUE, 0, who, |
3539 | "You will now fire %s with %s.", op->race ? &op->race : "nothing", query_name (op)); |
3414 | "You will now fire %s with %s.", op->race ? &op->race : "nothing", query_name (op)); |
3540 | who->contr->shoottype = range_bow; |
|
|
3541 | } |
|
|
3542 | else |
|
|
3543 | { |
|
|
3544 | who->contr->shoottype = range_misc; |
|
|
3545 | } |
3415 | } |
3546 | } |
3416 | } |
3547 | else |
3417 | else |
3548 | { |
3418 | { |
3549 | if (op->type == BOW) |
3419 | if (op->type == BOW) |
3550 | SET_FLAG (who, FLAG_READY_BOW); |
3420 | SET_FLAG (who, FLAG_READY_BOW); |
3551 | else |
3421 | else |
3552 | SET_FLAG (who, FLAG_READY_RANGE); |
3422 | SET_FLAG (who, FLAG_READY_RANGE); |
3553 | } |
3423 | } |
|
|
3424 | |
3554 | break; |
3425 | break; |
3555 | |
3426 | |
3556 | case BUILDER: |
3427 | case BUILDER: |
3557 | if (who->contr->ranges[range_builder]) |
3428 | if (who->type == PLAYER) |
|
|
3429 | { |
|
|
3430 | if (who->contr->ranged_ob && who->contr->ranged_ob->type == BUILDER) |
3558 | unapply_special (who, who->contr->ranges[range_builder], 0); |
3431 | unapply_special (who, who->contr->ranged_ob, 0); |
3559 | who->contr->shoottype = range_builder; |
3432 | |
3560 | who->contr->ranges[range_builder] = op; |
|
|
3561 | new_draw_info_format (NDI_UNIQUE, 0, who, "You ready your %s.", query_name (op)); |
3433 | new_draw_info_format (NDI_UNIQUE, 0, who, "You ready your %s.", query_name (op)); |
|
|
3434 | |
|
|
3435 | who->contr->ranged_ob = op; |
|
|
3436 | } |
3562 | break; |
3437 | break; |
3563 | |
3438 | |
3564 | default: |
3439 | default: |
3565 | new_draw_info_format (NDI_UNIQUE, 0, who, "You apply %s.", query_name (op)); |
3440 | new_draw_info_format (NDI_UNIQUE, 0, who, "You apply %s.", query_name (op)); |
3566 | } /* end of switch op->type */ |
3441 | } /* end of switch op->type */ |
3567 | |
3442 | |
3568 | SET_FLAG (op, FLAG_APPLIED); |
3443 | SET_FLAG (op, FLAG_APPLIED); |
3569 | |
3444 | |
3570 | if (tmp != NULL) |
3445 | if (tmp) |
3571 | tmp = insert_ob_in_ob (tmp, who); |
3446 | tmp = insert_ob_in_ob (tmp, who); |
3572 | |
3447 | |
3573 | who->update_stats (); |
3448 | who->update_stats (); |
3574 | |
3449 | |
3575 | /* We exclude spell casting objects. The fire code will set the |
3450 | /* We exclude spell casting objects. The fire code will set the |
… | |
… | |
3585 | { |
3460 | { |
3586 | new_draw_info (NDI_UNIQUE, 0, who, "Oops, it feels deadly cold!"); |
3461 | new_draw_info (NDI_UNIQUE, 0, who, "Oops, it feels deadly cold!"); |
3587 | SET_FLAG (op, FLAG_KNOWN_CURSED); |
3462 | SET_FLAG (op, FLAG_KNOWN_CURSED); |
3588 | } |
3463 | } |
3589 | } |
3464 | } |
|
|
3465 | |
3590 | if (who->type == PLAYER) |
3466 | if (who->type == PLAYER) |
3591 | { |
3467 | { |
3592 | /* if multiple objects were applied, update both slots */ |
3468 | /* if multiple objects were applied, update both slots */ |
3593 | if (tmp) |
3469 | if (tmp) |
3594 | esrv_send_item (who, tmp); |
3470 | esrv_send_item (who, tmp); |
|
|
3471 | |
3595 | esrv_send_item (who, op); |
3472 | esrv_send_item (who, op); |
3596 | } |
3473 | } |
|
|
3474 | |
3597 | return 0; |
3475 | return 0; |
3598 | } |
3476 | } |
3599 | |
|
|
3600 | |
3477 | |
3601 | int |
3478 | int |
3602 | monster_apply_special (object *who, object *op, int aflags) |
3479 | monster_apply_special (object *who, object *op, int aflags) |
3603 | { |
3480 | { |
3604 | if (QUERY_FLAG (op, FLAG_UNPAID) && !QUERY_FLAG (op, FLAG_APPLIED)) |
3481 | if (QUERY_FLAG (op, FLAG_UNPAID) && !QUERY_FLAG (op, FLAG_APPLIED)) |
… | |
… | |
3648 | |
3525 | |
3649 | case TREASURE: |
3526 | case TREASURE: |
3650 | if (QUERY_FLAG (op, FLAG_IS_A_TEMPLATE)) |
3527 | if (QUERY_FLAG (op, FLAG_IS_A_TEMPLATE)) |
3651 | return 0; |
3528 | return 0; |
3652 | |
3529 | |
3653 | while ((op->stats.hp--) > 0) |
3530 | while (op->stats.hp-- > 0) |
3654 | create_treasure (op->randomitems, op, op->map ? GT_ENVIRONMENT : 0, |
3531 | create_treasure (op->randomitems, op, op->map ? GT_ENVIRONMENT : 0, |
3655 | op->stats.exp ? (int) op->stats.exp : op->map == NULL ? 14 : op->map->difficulty, 0); |
3532 | op->stats.exp ? (int) op->stats.exp : op->map == NULL ? 14 : op->map->difficulty, 0); |
3656 | |
3533 | |
3657 | /* If we generated an object and put it in this object inventory, |
3534 | /* If we generated an object and put it in this object inventory, |
3658 | * move it to the parent object as the current object is about |
3535 | * move it to the parent object as the current object is about |
… | |
… | |
3675 | } |
3552 | } |
3676 | return tmp ? 1 : 0; |
3553 | return tmp ? 1 : 0; |
3677 | } |
3554 | } |
3678 | |
3555 | |
3679 | /** |
3556 | /** |
3680 | * fix_auto_apply goes through the entire map (only the first time |
3557 | * fix_auto_apply goes through the entire map every time a map |
3681 | * when an original map is loaded) and performs special actions for |
3558 | * is loaded or swapped in and performs special actions for |
3682 | * certain objects (most initialization of chests and creation of |
3559 | * certain objects (most initialization of chests and creation of |
3683 | * treasures and stuff). Calls auto_apply if appropriate. |
3560 | * treasures and stuff). Calls auto_apply if appropriate. |
3684 | */ |
3561 | */ |
3685 | void |
3562 | void |
3686 | maptile::fix_auto_apply () |
3563 | maptile::fix_auto_apply () |
… | |
… | |
3764 | { |
3641 | { |
3765 | create_treasure (tmp->randomitems, tmp, GT_APPLY, difficulty, 0); |
3642 | create_treasure (tmp->randomitems, tmp, GT_APPLY, difficulty, 0); |
3766 | tmp->randomitems = NULL; |
3643 | tmp->randomitems = NULL; |
3767 | } |
3644 | } |
3768 | |
3645 | |
|
|
3646 | // close all containers |
|
|
3647 | else if (tmp->type == CONTAINER) |
|
|
3648 | tmp->flag [FLAG_APPLIED] = 0; |
|
|
3649 | |
3769 | tmp = above; |
3650 | tmp = above; |
3770 | } |
3651 | } |
3771 | |
3652 | |
3772 | for (mapspace *ms = spaces + size (); ms-- > spaces; ) |
3653 | for (mapspace *ms = spaces + size (); ms-- > spaces; ) |
3773 | for (object *tmp = ms->bot; tmp; tmp = tmp->above) |
3654 | for (object *tmp = ms->bot; tmp; tmp = tmp->above) |
… | |
… | |
3779 | * Handles player eating food that temporarily changes status (resistances, stats). |
3660 | * Handles player eating food that temporarily changes status (resistances, stats). |
3780 | * This used to call cast_change_attr(), but |
3661 | * This used to call cast_change_attr(), but |
3781 | * that doesn't work with the new spell code. Since we know what |
3662 | * that doesn't work with the new spell code. Since we know what |
3782 | * the food changes, just grab a force and use that instead. |
3663 | * the food changes, just grab a force and use that instead. |
3783 | */ |
3664 | */ |
3784 | |
|
|
3785 | void |
3665 | void |
3786 | eat_special_food (object *who, object *food) |
3666 | eat_special_food (object *who, object *food) |
3787 | { |
3667 | { |
3788 | object *force; |
3668 | object *force; |
3789 | int i, did_one = 0; |
3669 | int i, did_one = 0; |
3790 | sint8 k; |
|
|
3791 | |
3670 | |
3792 | force = get_archetype (FORCE_NAME); |
3671 | force = get_archetype (FORCE_NAME); |
3793 | |
3672 | |
3794 | for (i = 0; i < NUM_STATS; i++) |
3673 | for (i = 0; i < NUM_STATS; i++) |
3795 | { |
3674 | if (sint8 k = food->stats.stat (i)) |
3796 | k = get_attr_value (&food->stats, i); |
|
|
3797 | if (k) |
|
|
3798 | { |
3675 | { |
3799 | set_attr_value (&force->stats, i, k); |
3676 | force->stats.stat (i) = k; |
3800 | did_one = 1; |
3677 | did_one = 1; |
3801 | } |
3678 | } |
3802 | } |
|
|
3803 | |
3679 | |
3804 | /* check if we can protect the eater */ |
3680 | /* check if we can protect the eater */ |
3805 | for (i = 0; i < NROFATTACKS; i++) |
3681 | for (i = 0; i < NROFATTACKS; i++) |
3806 | { |
3682 | { |
3807 | if (food->resist[i] > 0) |
3683 | if (food->resist[i] > 0) |
… | |
… | |
3968 | new_draw_info (NDI_UNIQUE, 0, op, "The magic recoils on you!"); |
3844 | new_draw_info (NDI_UNIQUE, 0, op, "The magic recoils on you!"); |
3969 | blind_player (op, op, power); |
3845 | blind_player (op, op, power); |
3970 | } |
3846 | } |
3971 | else if (failure <= -80) |
3847 | else if (failure <= -80) |
3972 | { /* blast the immediate area */ |
3848 | { /* blast the immediate area */ |
3973 | object *tmp; |
|
|
3974 | |
|
|
3975 | tmp = get_archetype (LOOSE_MANA); |
3849 | object *tmp = get_archetype (LOOSE_MANA); |
3976 | cast_magic_storm (op, tmp, power); |
3850 | cast_magic_storm (op, tmp, power); |
3977 | new_draw_info (NDI_UNIQUE, 0, op, "You unlease uncontrolled mana!"); |
3851 | new_draw_info (NDI_UNIQUE, 0, op, "You unleash uncontrolled mana!"); |
3978 | tmp->destroy (); |
3852 | tmp->destroy (); |
3979 | } |
3853 | } |
3980 | } |
3854 | } |
3981 | } |
3855 | } |
3982 | |
3856 | |
… | |
… | |
4002 | */ |
3876 | */ |
4003 | int i, j; |
3877 | int i, j; |
4004 | |
3878 | |
4005 | for (i = 0; i < NUM_STATS; i++) |
3879 | for (i = 0; i < NUM_STATS; i++) |
4006 | { |
3880 | { |
4007 | sint8 stat = get_attr_value (stats, i); |
|
|
4008 | int race_bonus = get_attr_value (&(pl->arch->clone.stats), i); |
3881 | int race_bonus = pl->arch->clone.stats.stat (i); |
|
|
3882 | sint8 stat = stats->stat (i) + ns->stat (i); |
4009 | |
3883 | |
4010 | stat += get_attr_value (ns, i); |
|
|
4011 | if (stat > 20 + race_bonus) |
3884 | if (stat > 20 + race_bonus) |
4012 | { |
3885 | { |
4013 | excess_stat++; |
3886 | excess_stat++; |
4014 | stat = 20 + race_bonus; |
3887 | stat = 20 + race_bonus; |
4015 | } |
3888 | } |
4016 | set_attr_value (stats, i, stat); |
3889 | |
|
|
3890 | stats->stat (i) = stat; |
4017 | } |
3891 | } |
4018 | |
3892 | |
4019 | for (j = 0; excess_stat > 0 && j < 100; j++) |
3893 | for (j = 0; excess_stat > 0 && j < 100; j++) |
4020 | { /* try 100 times to assign excess stats */ |
3894 | { /* try 100 times to assign excess stats */ |
4021 | int i = rndm (0, 6); |
3895 | int i = rndm (0, 6); |
4022 | int stat = get_attr_value (stats, i); |
|
|
4023 | int race_bonus = get_attr_value (&(pl->arch->clone.stats), i); |
|
|
4024 | |
3896 | |
4025 | if (i == CHA) |
3897 | if (i == CHA) |
4026 | continue; /* exclude cha from this */ |
3898 | continue; /* exclude cha from this */ |
|
|
3899 | |
|
|
3900 | int stat = stats->stat (i); |
|
|
3901 | int race_bonus = pl->arch->clone.stats.stat (i); |
4027 | if (stat < 20 + race_bonus) |
3902 | if (stat < 20 + race_bonus) |
4028 | { |
3903 | { |
4029 | change_attr_value (stats, i, 1); |
3904 | change_attr_value (stats, i, 1); |
4030 | excess_stat--; |
3905 | excess_stat--; |
4031 | } |
3906 | } |
… | |
… | |
4034 | /* insert the randomitems from the change's treasurelist into |
3909 | /* insert the randomitems from the change's treasurelist into |
4035 | * the player ref: player.c |
3910 | * the player ref: player.c |
4036 | */ |
3911 | */ |
4037 | if (change->randomitems != NULL) |
3912 | if (change->randomitems != NULL) |
4038 | give_initial_items (pl, change->randomitems); |
3913 | give_initial_items (pl, change->randomitems); |
4039 | |
|
|
4040 | |
3914 | |
4041 | /* set up the face, for some races. */ |
3915 | /* set up the face, for some races. */ |
4042 | |
3916 | |
4043 | /* first, look for the force object banning |
3917 | /* first, look for the force object banning |
4044 | * changing the face. Certain races never change face with class. |
3918 | * changing the face. Certain races never change face with class. |