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

Comparing deliantra/server/server/apply.C (file contents):
Revision 1.150 by root, Tue Apr 22 23:50:24 2008 UTC vs.
Revision 1.178 by root, Sun Dec 28 15:28:47 2008 UTC

53 * subtype 5: arch or race 53 * subtype 5: arch or race
54 * subtype 7: all three 54 * subtype 7: all three
55 */ 55 */
56 if (op->subtype) 56 if (op->subtype)
57 { 57 {
58 arch_flag = (op->subtype & 1); 58 arch_flag = op->subtype & 1;
59 name_flag = (op->subtype & 2); 59 name_flag = op->subtype & 2;
60 race_flag = (op->subtype & 4); 60 race_flag = op->subtype & 4;
61 } 61 }
62 else 62 else
63 { 63 {
64 arch_flag = 1; 64 arch_flag = 1;
65 name_flag = 1; 65 name_flag = 1;
113 { 113 {
114 if (operate_altar (altar, &money)) 114 if (operate_altar (altar, &money))
115 { 115 {
116 identify (marked); 116 identify (marked);
117 117
118 buf.printf ("You have %s.\n\n", long_desc (marked, pl)); 118 buf.printf ("You have %s.\r", long_desc (marked, pl));
119 if (marked->msg) 119 if (marked->msg)
120 buf << "The item has a story:\n\n" << marked->msg << "\n\n"; 120 buf << "The item has a story:\r" << marked->msg << "\n\n";
121 121
122 return !money; 122 return !money;
123 } 123 }
124 } 124 }
125 125
129 { 129 {
130 if (operate_altar (altar, &money)) 130 if (operate_altar (altar, &money))
131 { 131 {
132 identify (id); 132 identify (id);
133 133
134 buf.printf ("You have %s.\n\n", long_desc (id, pl)); 134 buf.printf ("You have %s.\r", long_desc (id, pl));
135 if (id->msg) 135 if (id->msg)
136 buf << "The item has a story:\n\n" << id->msg << "\n\n"; 136 buf << "The item has a story:\r" << id->msg << "\n\n";
137 137
138 /* If no more money, might as well quit now */ 138 /* If no more money, might as well quit now */
139 if (!money || !check_altar_sacrifice (altar, money)) 139 if (!money || !check_altar_sacrifice (altar, money))
140 break; 140 break;
141 } 141 }
160 * matching item. 160 * matching item.
161 **/ 161 **/
162void 162void
163handle_apply_yield (object *tmp) 163handle_apply_yield (object *tmp)
164{ 164{
165 const char *yield; 165 if (shstr yield = tmp->kv (shstr_on_use_yield))
166
167 yield = get_ob_key_value (tmp, "on_use_yield");
168
169 if (yield)
170 get_archetype (yield)->insert_at (tmp, tmp, INS_BELOW_ORIGINATOR); 166 archetype::get (yield)->insert_at (tmp, tmp, INS_BELOW_ORIGINATOR);
171} 167}
172 168
173/** 169/**
174 * Handles applying a potion. 170 * Handles applying a potion.
175 */ 171 */
612 weapon->stats.exp || /* speed */ 608 weapon->stats.exp || /* speed */
613 weapon->stats.ac) /* AC - only taifu's I think */ 609 weapon->stats.ac) /* AC - only taifu's I think */
614 { 610 {
615 op->failmsg ("You cannot prepare magic weapons. " 611 op->failmsg ("You cannot prepare magic weapons. "
616 "H<A weapon is considered magical if it changes regeneration, " 612 "H<A weapon is considered magical if it changes regeneration, "
617 "speed or ac.>"); 613 "speed or ac, or has other protections.>");
618 return 0; 614 return 0;
619 } 615 }
620 616
621 sacrifice_count = check_sacrifice (op, improver); 617 sacrifice_count = check_sacrifice (op, improver);
622 if (sacrifice_count <= 0) 618 if (sacrifice_count <= 0)
707 weapon->last_eat++; 703 weapon->last_eat++;
708 weapon->item_power++; 704 weapon->item_power++;
709 improver->decrease (); 705 improver->decrease ();
710 return 1; 706 return 1;
711 } 707 }
708
712 if (improver->stats.sp == IMPROVE_ENCHANT) 709 if (improver->stats.sp == IMPROVE_ENCHANT)
713 { 710 {
714 weapon->magic++; 711 weapon->magic++;
715 weapon->last_eat++; 712 weapon->last_eat++;
716 op->statusmsg (format ("Weapon magic increased to %d.", weapon->magic)); 713 op->statusmsg (format ("Weapon magic increased to %d.", weapon->magic));
771 op->failmsg ("Something blocks the magic of the scroll!"); 768 op->failmsg ("Something blocks the magic of the scroll!");
772 return 0; 769 return 0;
773 } 770 }
774 771
775 otmp = find_marked_object (op); 772 otmp = find_marked_object (op);
773
776 if (!otmp) 774 if (!otmp)
777 { 775 {
778 op->failmsg ("You need to mark a weapon object. H<Use the mark command or the mark option from the item popup menu.>"); 776 op->failmsg ("You need to mark a weapon object. H<Use the mark command or the mark option from the item popup menu.>");
779 return 0; 777 return 0;
780 } 778 }
974 ob_to_copy = converter->inv; 972 ob_to_copy = converter->inv;
975 for (ob = converter->inv->below, i = 1; ob; ob = ob->below, i++) 973 for (ob = converter->inv->below, i = 1; ob; ob = ob->below, i++)
976 if (rndm (0, i) == 0) 974 if (rndm (0, i) == 0)
977 ob_to_copy = ob; 975 ob_to_copy = ob;
978 976
979 item = object_create_clone (ob_to_copy); 977 item = ob_to_copy->deep_clone ();
980 CLEAR_FLAG (item, FLAG_IS_A_TEMPLATE); 978 CLEAR_FLAG (item, FLAG_IS_A_TEMPLATE);
981 unflag_inv (item, FLAG_IS_A_TEMPLATE); 979 unflag_inv (item, FLAG_IS_A_TEMPLATE);
982 } 980 }
983 else 981 else
984 { 982 {
997 item->nrof = give; 995 item->nrof = give;
998 996
999 if (nr) 997 if (nr)
1000 item->nrof *= nr; 998 item->nrof *= nr;
1001 999
1002 if (is_in_shop (converter)) 1000 if (converter->flag [FLAG_PRECIOUS])
1003 SET_FLAG (item, FLAG_UNPAID); 1001 SET_FLAG (item, FLAG_UNPAID);
1002
1003 if (is_in_shop (converter))
1004 {
1005 // converters on shop floors don't work anymore, bug lets check for it
1006 // and report in case someone still does it.
1007 LOG (llevDebug, "ITEMBUG: broken converter, converters on shop floor don't work: %s\n",
1008 converter->debug_desc ());
1009 SET_FLAG (item, FLAG_UNPAID);
1010 }
1004 else if (price_in < sint64 (item->nrof) * item->value) 1011 else if (price_in < sint64 (item->nrof) * item->value)
1005 { 1012 {
1006 LOG (llevDebug, "converter output price higher than input: %s at %s (%d, %d) in value %d, out value %d for %s\n", 1013 LOG (llevDebug, "converter output price higher than input: %s at %s (%d, %d) in value %d, out value %d for %s\n",
1007 &converter->name, &converter->map->path, converter->x, converter->y, price_in, item->nrof * item->value, &item->name); 1014 &converter->name, &converter->map->path, converter->x, converter->y, price_in, item->nrof * item->value, &item->name);
1008 /** 1015 /**
1009 * elmex: we are going to let the game continue, as the mapcreator 1016 * elmex: we are going to let the game continue, as the mapcreator
1010 * hopefully had something in mind when doing this. 1017 * hopefully had something in mind when doing this.
1011 */ 1018 */
1012 } 1019 }
1013 1020
1014 SET_FLAG (item, FLAG_IDENTIFIED); 1021 // elmex: only identify if we need to, for example so that generated money doesn't
1022 // get an 'identified' flag so easily.
1023 if (need_identify (item))
1024 identify (item);
1025
1015 insert_ob_in_map_at (item, converter->map, converter, 0, converter->x, converter->y); 1026 insert_ob_in_map_at (item, converter->map, converter, 0, converter->x, converter->y);
1016 return 1; 1027 return 1;
1017} 1028}
1018 1029
1019/** 1030/**
1151 { 1162 {
1152 has_unpaid = true; 1163 has_unpaid = true;
1153 break; 1164 break;
1154 } 1165 }
1155 1166
1156 if (op->type != PLAYER) 1167 if (!op->is_player ())
1157 { 1168 {
1158 /* Remove all the unpaid objects that may be carried here. 1169 /* Remove all the unpaid objects that may be carried here.
1159 * This could be pets or monsters that are somehow in 1170 * This could be pets or monsters that are somehow in
1160 * the shop. 1171 * the shop.
1161 */ 1172 */
1165 1176
1166 if (QUERY_FLAG (tmp, FLAG_UNPAID)) 1177 if (QUERY_FLAG (tmp, FLAG_UNPAID))
1167 { 1178 {
1168 int i = find_free_spot (tmp, op->map, op->x, op->y, 1, 9); 1179 int i = find_free_spot (tmp, op->map, op->x, op->y, 1, 9);
1169 1180
1181 if (i >= 0)
1170 tmp->remove (); 1182 tmp->move (i);
1171
1172 if (i == -1)
1173 i = 0;
1174
1175 tmp->map = op->map;
1176 tmp->x = op->x + freearr_x[i];
1177 tmp->y = op->y + freearr_y[i];
1178 insert_ob_in_map (tmp, op->map, op, 0);
1179 } 1183 }
1180 } 1184 }
1181 1185
1182 /* Don't teleport things like spell effects */ 1186 /* Don't teleport things like spell effects */
1183 if (QUERY_FLAG (op, FLAG_NO_PICK)) 1187 if (QUERY_FLAG (op, FLAG_NO_PICK))
1194 if (i != -1) 1198 if (i != -1)
1195 rv = transfer_ob (op, op->x + freearr_x[i], op->y + freearr_y[i], 0, shop_mat); 1199 rv = transfer_ob (op, op->x + freearr_x[i], op->y + freearr_y[i], 0, shop_mat);
1196 1200
1197 return 0; 1201 return 0;
1198 } 1202 }
1203
1199 /* Removed code that checked for multipart objects - it appears that 1204 /* Removed code that checked for multipart objects - it appears that
1200 * the teleport function should be able to handle this just fine. 1205 * the teleport function should be able to handle this just fine.
1201 */ 1206 */
1202 rv = teleport (shop_mat, SHOP_MAT, op); 1207 rv = teleport (shop_mat, SHOP_MAT, op);
1203 } 1208 }
1258 * Handles applying a sign. 1263 * Handles applying a sign.
1259 */ 1264 */
1260static void 1265static void
1261apply_sign (object *op, object *sign, int autoapply) 1266apply_sign (object *op, object *sign, int autoapply)
1262{ 1267{
1263 readable_message_type *msgType; 1268 if (sign->has_dialogue ())
1269 {
1270 op->statusmsg (format ("Maybe you should I<talk> to the %s instead?", &sign->name));
1271 return;
1272 }
1264 1273
1265 if (!sign->msg) 1274 if (!sign->msg)
1266 { 1275 {
1267 op->statusmsg ("Nothing is written on it."); 1276 op->contr->infobox (MSG_CHANNEL ("examine"),
1277 format ("T<%s>\n\n Nothing %sis written on it.",
1278 &sign->name,
1279 sign->name == sign->arch->name ? "" : "else "));
1268 return; 1280 return;
1269 } 1281 }
1270 1282
1271 if (sign->stats.food) 1283 if (sign->stats.food)
1272 { 1284 {
1273 if (sign->last_eat >= sign->stats.food) 1285 if (sign->last_eat >= sign->stats.food)
1274 { 1286 {
1275 if (!sign->move_on) 1287 if (!sign->move_on)
1276 op->statusmsg ("You cannot read it anymore."); 1288 op->failmsg ("You cannot read it anymore.");
1277 1289
1278 return; 1290 return;
1279 } 1291 }
1280 1292
1281 if (!QUERY_FLAG (op, FLAG_WIZPASS)) 1293 if (!QUERY_FLAG (op, FLAG_WIZPASS))
1299 if (sign->sound) 1311 if (sign->sound)
1300 ns->play_sound (sign->sound); 1312 ns->play_sound (sign->sound);
1301 else if (autoapply) 1313 else if (autoapply)
1302 ns->play_sound (sound_find ("msg_voice")); 1314 ns->play_sound (sound_find ("msg_voice"));
1303 1315
1304 if (ns->can_msg)
1305 op->contr->infobox (MSG_CHANNEL ("examine"), format ("T<%s>\n\n\n\n%s", &sign->name, &sign->msg)); 1316 op->contr->infobox (MSG_CHANNEL ("examine"), format ("T<%s>\n\n%s", &sign->name, &sign->msg));
1306 else
1307 {
1308 msgType = get_readable_message_type (sign);
1309 const char *somemsg = format ("%u %s", autoapply ? 1 : 0, &sign->msg);
1310 draw_ext_info (NDI_UNIQUE | NDI_NAVY, 0, op, msgType->message_type, msgType->message_subtype, somemsg, &sign->msg);
1311 }
1312 } 1317 }
1318}
1319
1320static void
1321move_apply_hole (object *trap, object *victim)
1322{
1323 /* Hole not open? */
1324 if (trap->stats.wc > 0)
1325 return;
1326
1327 /* Is this a multipart monster and not the head? If so, return.
1328 * Processing will happen if the head runs into the pit
1329 */
1330 if (victim->head)
1331 return;
1332
1333 // now find all possible locations and randomly pick one
1334 int dir = find_free_spot (victim, trap->map, EXIT_X (trap), EXIT_Y (trap), 0,
1335 trap->range >= 3 ? SIZEOFFREE3 + 1
1336 : trap->range >= 2 ? SIZEOFFREE2 + 1
1337 : trap->range >= 1 ? SIZEOFFREE1 + 1
1338 : SIZEOFFREE0 + 1);
1339
1340 if (dir < 0)
1341 return;
1342
1343 victim->play_sound (trap->sound ? trap->sound : sound_find ("fall_hole"));
1344 victim->statusmsg ("You fall through the hole!", NDI_RED);
1345
1346 transfer_ob (victim,
1347 EXIT_X (trap) + freearr_x[dir],
1348 EXIT_Y (trap) + freearr_y[dir],
1349 0, victim);
1313} 1350}
1314 1351
1315/** 1352/**
1316 * 'victim' moves onto 'trap' 1353 * 'victim' moves onto 'trap'
1317 * 'victim' leaves 'trap' 1354 * 'victim' leaves 'trap'
1466 1503
1467 case CONVERTER: 1504 case CONVERTER:
1468 if (convert_item (victim, trap) < 0) 1505 if (convert_item (victim, trap) < 0)
1469 { 1506 {
1470 originator->failmsg (format ("The %s seems to be broken!", query_name (trap))); 1507 originator->failmsg (format ("The %s seems to be broken!", query_name (trap)));
1471 get_archetype ("burnout")->insert_at (trap, trap); 1508 archetype::get (shstr_burnout)->insert_at (trap, trap);
1472 } 1509 }
1473 1510
1474 goto leave; 1511 goto leave;
1475 1512
1476 case TRIGGER_BUTTON: 1513 case TRIGGER_BUTTON:
1486 case CHECK_INV: 1523 case CHECK_INV:
1487 check_inv (victim, trap); 1524 check_inv (victim, trap);
1488 goto leave; 1525 goto leave;
1489 1526
1490 case HOLE: 1527 case HOLE:
1491 /* Hole not open? */ 1528 move_apply_hole (trap, victim);
1492 if (trap->stats.wc > 0)
1493 goto leave;
1494
1495 /* Is this a multipart monster and not the head? If so, return.
1496 * Processing will happen if the head runs into the pit
1497 */
1498 if (victim->head)
1499 goto leave;
1500
1501 victim->play_sound (trap->sound ? trap->sound : sound_find ("fall_hole"));
1502 victim->statusmsg ("You fall through the hole!", NDI_RED);
1503 transfer_ob (victim, EXIT_X (trap), EXIT_Y (trap), 1, victim);
1504 goto leave; 1529 goto leave;
1505 1530
1506 case EXIT: 1531 case EXIT:
1507 if (victim->type == PLAYER && EXIT_PATH (trap)) 1532 if (victim->type == PLAYER && EXIT_PATH (trap))
1508 { 1533 {
1600 1625
1601 readable_message_type *msgType = get_readable_message_type (tmp); 1626 readable_message_type *msgType = get_readable_message_type (tmp);
1602 1627
1603 if (player *pl = op->contr) 1628 if (player *pl = op->contr)
1604 if (client *ns = pl->ns) 1629 if (client *ns = pl->ns)
1605 if (ns->can_msg)
1606 pl->infobox (MSG_CHANNEL ("book"), format ("T<%s>\n\n\n\n%s", (char *)long_desc (tmp, op), &tmp->msg)); 1630 pl->infobox (MSG_CHANNEL ("book"), format ("T<%s>\n\n%s", (char *)long_desc (tmp, op), &tmp->msg));
1607 else
1608 draw_ext_info_format (NDI_UNIQUE | NDI_NAVY, 0, op,
1609 msgType->message_type, msgType->message_subtype,
1610 "You open the %s and start reading.\n%s", (char *)"%s\n%s",
1611 long_desc (tmp, op), &tmp->msg);
1612 1631
1613 /* gain xp from reading */ 1632 /* gain xp from reading */
1614 if (!QUERY_FLAG (tmp, FLAG_NO_SKILL_IDENT)) 1633 if (!QUERY_FLAG (tmp, FLAG_NO_SKILL_IDENT))
1615 { /* only if not read before */ 1634 { /* only if not read before */
1616 int exp_gain = calc_skill_exp (op, tmp, skill_ob); 1635 int exp_gain = calc_skill_exp (op, tmp, skill_ob);
1939 if (op->destroyed () || tmp->destroyed ()) 1958 if (op->destroyed () || tmp->destroyed ())
1940 break; 1959 break;
1941 } 1960 }
1942 1961
1943 if (!tmp->destroyed () && !tmp->inv) 1962 if (!tmp->destroyed () && !tmp->inv)
1944 tmp->decrease (); 1963 tmp->decrease (true);
1945} 1964}
1946 1965
1947/** 1966/**
1948 * op eats food. 1967 * op eats food.
1949 * If player, takes care of messages and dragon special food. 1968 * If player, takes care of messages and dragon special food.
2144 op->statusmsg (buf); 2163 op->statusmsg (buf);
2145 2164
2146 /* now choose a winner if we have any */ 2165 /* now choose a winner if we have any */
2147 i = -1; 2166 i = -1;
2148 if (winners > 0) 2167 if (winners > 0)
2149 i = atnr_winner[RANDOM () % winners]; 2168 i = atnr_winner [rndm (winners)];
2150 2169
2151 if (i >= 0 && i < NROFATTACKS && skin->resist[i] < 95) 2170 if (i >= 0 && i < NROFATTACKS && skin->resist[i] < 95)
2152 { 2171 {
2153 /* resistance increased! */ 2172 /* resistance increased! */
2154 skin->resist[i]++; 2173 skin->resist[i]++;
2213 2232
2214 op->statusmsg ("Applying armour enchantment."); 2233 op->statusmsg ("Applying armour enchantment.");
2215 improve_armour (op, tmp, armor); 2234 improve_armour (op, tmp, armor);
2216} 2235}
2217 2236
2218extern void 2237void
2219apply_poison (object *op, object *tmp) 2238apply_poison (object *op, object *tmp)
2220{ 2239{
2240 // need to do it now when it is still on the map
2241 handle_apply_yield (tmp);
2242
2243 object *poison = tmp->split (1);
2244
2221 if (op->type == PLAYER) 2245 if (op->type == PLAYER)
2222 { 2246 {
2223 op->contr->play_sound (sound_find ("drink_poison")); 2247 op->contr->play_sound (sound_find ("drink_poison"));
2224 op->failmsg ("Yech! That tasted poisonous!"); 2248 op->failmsg ("Yech! That tasted poisonous!");
2225 strcpy (op->contr->killer, "poisonous booze"); 2249 op->contr->killer = poison;
2226 } 2250 }
2227 2251
2228 if (tmp->stats.hp > 0) 2252 if (poison->stats.hp > 0)
2229 { 2253 {
2230 LOG (llevDebug, "Trying to poison player/monster for %d hp\n", tmp->stats.hp); 2254 LOG (llevDebug, "Trying to poison player/monster for %d hp\n", poison->stats.hp);
2231 hit_player (op, tmp->stats.hp, tmp, AT_POISON, 1); 2255 hit_player (op, poison->stats.hp, tmp, AT_POISON, 1);
2232 } 2256 }
2233 2257
2234 op->stats.food -= op->stats.food / 4; 2258 op->stats.food -= op->stats.food / 4;
2235 handle_apply_yield (tmp); 2259 poison->destroy ();
2236 tmp->decrease ();
2237} 2260}
2238 2261
2239/** 2262/**
2240 * This function return true if the exit is not a 2 ways one or it is 2 ways, valid exit. 2263 * This function return true if the exit is not a 2 ways one or it is 2 ways, valid exit.
2241 * A valid 2 way exit means: 2264 * A valid 2 way exit means:
2343 * them in this function - they are passed to apply_special 2366 * them in this function - they are passed to apply_special
2344 */ 2367 */
2345int 2368int
2346manual_apply (object *op, object *tmp, int aflag) 2369manual_apply (object *op, object *tmp, int aflag)
2347{ 2370{
2348 if (tmp->head)
2349 tmp = tmp->head; 2371 tmp = tmp->head_ ();
2350 2372
2351 if (QUERY_FLAG (tmp, FLAG_UNPAID) && !QUERY_FLAG (tmp, FLAG_APPLIED)) 2373 if (QUERY_FLAG (tmp, FLAG_UNPAID) && !QUERY_FLAG (tmp, FLAG_APPLIED))
2352 { 2374 {
2353 if (op->type == PLAYER) 2375 if (op->type == PLAYER)
2354 { 2376 {
2562 default: 2584 default:
2563 return 0; 2585 return 0;
2564 } 2586 }
2565} 2587}
2566 2588
2567
2568/* quiet suppresses the "don't know how to apply" and "you must get it first" 2589/* quiet suppresses the "don't know how to apply" and "you must get it first"
2569 * messages as needed by player_apply_below(). But there can still be 2590 * messages as needed by player_apply_below(). But there can still be
2570 * "but you are floating high above the ground" messages. 2591 * "but you are floating high above the ground" messages.
2571 * 2592 *
2572 * Same return value as apply() function. 2593 * Same return value as apply() function.
2573 */ 2594 */
2574int 2595int
2575player_apply (object *pl, object *op, int aflag, int quiet) 2596player_apply (object *pl, object *op, int aflag, int quiet)
2576{ 2597{
2577 int tmp;
2578
2579 if (op->env && (pl->move_type & MOVE_FLYING)) 2598 if (!op->env && (pl->move_type & MOVE_FLYING))
2580 { 2599 {
2581 /* player is flying and applying object not in inventory */ 2600 /* player is flying and applying object not in inventory */
2582 if (!QUERY_FLAG (pl, FLAG_WIZ) && !(op->move_type & MOVE_FLYING)) 2601 if (!QUERY_FLAG (pl, FLAG_WIZ) && !(op->move_type & MOVE_FLYING))
2583 { 2602 {
2584 pl->failmsg ("But you are floating high above the ground! H<You have to stop levitating first, if you can.>"); 2603 pl->failmsg ("But you are floating high above the ground! "
2604 "H<You have to stop levitating first, if you can, either by using your levitation skill, "
2605 "or waiting till the levitation effect wears off.>");
2585 return 0; 2606 return 0;
2586 } 2607 }
2587 } 2608 }
2588 2609
2589 pl->contr->last_used = op; 2610 pl->contr->last_used = op;
2590 2611
2591 tmp = manual_apply (pl, op, aflag); 2612 int tmp = manual_apply (pl, op, aflag);
2613
2592 if (!quiet) 2614 if (!quiet)
2593 { 2615 {
2594 if (tmp == 0) 2616 if (tmp == 0)
2595 pl->statusmsg (format ("I don't know how to apply the %s.", query_name (op))); 2617 pl->statusmsg (format ("I don't know how to apply the %s.", query_name (op)));
2596 else if (tmp == 2) 2618 else if (tmp == 2)
2631 * person moving on it, also activate. Added code to make it 2653 * person moving on it, also activate. Added code to make it
2632 * so that at least one of players movement types be that which 2654 * so that at least one of players movement types be that which
2633 * the item needs. 2655 * the item needs.
2634 */ 2656 */
2635 if (!tmp->invisible || (tmp->move_on & pl->move_type)) 2657 if (!tmp->invisible || (tmp->move_on & pl->move_type))
2636 {
2637 if (player_apply (pl, tmp, 0, 1) == 1) 2658 if (player_apply (pl, tmp, 0, 1) == 1)
2638 return; 2659 return;
2639 } 2660
2640 if (floors >= 2) 2661 if (floors >= 2)
2641 return; /* process at most two floor objects */ 2662 return; /* process at most two floor objects */
2642 } 2663 }
2643} 2664}
2644 2665
2688 break; 2709 break;
2689 2710
2690 case SKILL: 2711 case SKILL:
2691 if (who->contr) 2712 if (who->contr)
2692 { 2713 {
2714 if (IS_COMBAT_SKILL (op->subtype))
2715 who->change_weapon (who->contr->combat_ob = 0);
2716 else if (IS_RANGED_SKILL (op->subtype))
2717 who->change_weapon (who->contr->ranged_ob = 0);
2718
2693 if (!op->invisible) 2719 if (op->invisible)
2720 who->statusmsg (format ("You can no longer use the skill: %s.", &op->skill));
2721 else
2694 who->statusmsg (format ("You stop using the %s.", query_name (op))); 2722 who->statusmsg (format ("You stop using the %s.", query_name (op)));
2695 else
2696 who->statusmsg (format ("You can no longer use the skill: %s.", &op->skill));
2697 } 2723 }
2698 2724
2699 change_abil (who, op); 2725 change_abil (who, op);
2700 CLEAR_FLAG (who, FLAG_READY_SKILL); 2726 CLEAR_FLAG (who, FLAG_READY_SKILL);
2701 break; 2727 break;
2733 op->destroy (); 2759 op->destroy ();
2734 who->insert (tmp2); 2760 who->insert (tmp2);
2735 who->update_stats (); 2761 who->update_stats ();
2736 2762
2737 if (who->contr) 2763 if (who->contr)
2738 {
2739 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED)) 2764 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED))
2740 { 2765 {
2741 who->failmsg ("Oops, it feels deadly cold!"); 2766 who->failmsg ("Oops, it feels deadly cold!");
2742 SET_FLAG (tmp2, FLAG_KNOWN_CURSED); 2767 SET_FLAG (tmp2, FLAG_KNOWN_CURSED);
2743 } 2768 }
2744 }
2745 } 2769 }
2746 2770
2747 return 1; /* otherwise, an attempt to drop causes problems */ 2771 return 1; /* otherwise, an attempt to drop causes problems */
2748 2772
2749 case BOW: 2773 case BOW:
3092 return 1; 3116 return 1;
3093 } 3117 }
3094 3118
3095 return unapply_special (who, op, aflags); 3119 return unapply_special (who, op, aflags);
3096 } 3120 }
3097
3098 if (basic_flag == AP_UNAPPLY) 3121 else if (basic_flag == AP_UNAPPLY)
3099 return 0; 3122 return 0;
3100 3123
3101 // if the item is combat/ranged, wield the relevant slot first 3124 // if the item is combat/ranged, wield the relevant slot first
3102 // to resolve conflicts. 3125 // to resolve conflicts.
3103 if (player *pl = who->contr) 3126 if (player *pl = who->contr)
3183 switch (op->type) 3206 switch (op->type)
3184 { 3207 {
3185 case WEAPON: 3208 case WEAPON:
3186 if (!check_weapon_power (who, op->last_eat)) 3209 if (!check_weapon_power (who, op->last_eat))
3187 { 3210 {
3188 op->failmsg ("This weapon is too powerful for you to use. It would consume your soul!." LACK_ITEM_POWER); 3211 op->failmsg ("This weapon is too powerful for you to use. It would consume your soul!" LACK_ITEM_POWER);
3189 3212
3190 if (tmp) 3213 if (tmp)
3191 insert_ob_in_ob (tmp, who); 3214 insert_ob_in_ob (tmp, who);
3192 3215
3193 return 1; 3216 return 1;
3272 who->update_stats (); 3295 who->update_stats ();
3273 3296
3274 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED)) 3297 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED))
3275 if (who->type == PLAYER) 3298 if (who->type == PLAYER)
3276 { 3299 {
3277 who->failmsg ("Oops, it feels deadly cold! H<Maybe it wasn't such a bright idea to apply this cursed/damned item.>"); 3300 who->failmsg ("Oops, it feels deadly cold! H<Maybe it wasn't such a bright (hrhrhr) idea to apply this cursed or damned item.>");
3278 SET_FLAG (tmp2, FLAG_KNOWN_CURSED); 3301 SET_FLAG (tmp2, FLAG_KNOWN_CURSED);
3279 } 3302 }
3280 3303
3281 return 0; 3304 return 0;
3282 3305
3460 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED)) 3483 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED))
3461 if (who->type == PLAYER) 3484 if (who->type == PLAYER)
3462 { 3485 {
3463 who->failmsg ( 3486 who->failmsg (
3464 "Oops, it feels deadly cold! " 3487 "Oops, it feels deadly cold! "
3465 "H<Maybe it wasn't such a bright idea to apply this cursed/damned item.>" 3488 "H<Maybe it wasn't such a bright idea to apply this cursed or damned item.>"
3466 ); 3489 );
3467 SET_FLAG (op, FLAG_KNOWN_CURSED); 3490 SET_FLAG (op, FLAG_KNOWN_CURSED);
3468 } 3491 }
3469 3492
3470 if (object *pl = op->visible_to ()) 3493 if (object *pl = op->visible_to ())
3490int 3513int
3491auto_apply (object *op) 3514auto_apply (object *op)
3492{ 3515{
3493 object *tmp = NULL, *tmp2; 3516 object *tmp = NULL, *tmp2;
3494 int i; 3517 int i;
3518
3519 CLEAR_FLAG (op, FLAG_AUTO_APPLY);
3495 3520
3496 switch (op->type) 3521 switch (op->type)
3497 { 3522 {
3498 case SHOP_FLOOR: 3523 case SHOP_FLOOR:
3499 if (!op->has_random_items ()) 3524 if (!op->has_random_items ())
3501 3526
3502 do 3527 do
3503 { 3528 {
3504 i = 10; /* let's give it 10 tries */ 3529 i = 10; /* let's give it 10 tries */
3505 while ((tmp = generate_treasure (op->randomitems, 3530 while ((tmp = generate_treasure (op->randomitems,
3506 op->stats.exp ? (int) op->stats.exp : MAX (op->map->difficulty, 5))) == NULL && --i); 3531 op->stats.exp
3532 ? (int) op->stats.exp
3533 : max (op->map->difficulty, 5)))
3534 == NULL && --i);
3535
3507 if (tmp == NULL) 3536 if (tmp == NULL)
3508 return 0; 3537 return 0;
3538
3509 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED)) 3539 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED))
3510 { 3540 {
3511 tmp->destroy (); 3541 tmp->destroy ();
3512 tmp = NULL; 3542 tmp = NULL;
3513 } 3543 }
3516 3546
3517 tmp->x = op->x; 3547 tmp->x = op->x;
3518 tmp->y = op->y; 3548 tmp->y = op->y;
3519 SET_FLAG (tmp, FLAG_UNPAID); 3549 SET_FLAG (tmp, FLAG_UNPAID);
3520 insert_ob_in_map (tmp, op->map, NULL, 0); 3550 insert_ob_in_map (tmp, op->map, NULL, 0);
3521 CLEAR_FLAG (op, FLAG_AUTO_APPLY);
3522 identify (tmp); 3551 identify (tmp);
3523 break; 3552 break;
3524 3553
3525 case TREASURE: 3554 case TREASURE:
3526 if (QUERY_FLAG (op, FLAG_IS_A_TEMPLATE)) 3555 if (QUERY_FLAG (op, FLAG_IS_A_TEMPLATE))
3533 /* If we generated an object and put it in this object inventory, 3562 /* If we generated an object and put it in this object inventory,
3534 * move it to the parent object as the current object is about 3563 * move it to the parent object as the current object is about
3535 * to disappear. An example of this item is the random_* stuff 3564 * to disappear. An example of this item is the random_* stuff
3536 * that is put inside other objects. 3565 * that is put inside other objects.
3537 */ 3566 */
3538 for (tmp = op->inv; tmp; tmp = tmp2)
3539 {
3540 tmp2 = tmp->below;
3541 tmp->remove ();
3542
3543 if (op->env) 3567 if (op->env)
3544 insert_ob_in_ob (tmp, op->env); 3568 while (op->inv)
3545 else 3569 op->env->insert (op->inv);
3546 tmp->destroy ();
3547 }
3548 3570
3549 op->destroy (); 3571 op->destroy ();
3550 break; 3572 break;
3551 } 3573 }
3552 return tmp ? 1 : 0; 3574
3575 return !!tmp;
3553} 3576}
3554 3577
3555/** 3578/**
3556 * fix_auto_apply goes through the entire map every time a map 3579 * fix_auto_apply goes through the entire map every time a map
3557 * is loaded or swapped in and performs special actions for 3580 * is loaded or swapped in and performs special actions for
3571 3594
3572 if (tmp->inv) 3595 if (tmp->inv)
3573 { 3596 {
3574 object *invtmp, *invnext; 3597 object *invtmp, *invnext;
3575 3598
3576 for (invtmp = tmp->inv; invtmp != NULL; invtmp = invnext) 3599 for (invtmp = tmp->inv; invtmp; invtmp = invnext)
3577 { 3600 {
3578 invnext = invtmp->below; 3601 invnext = invtmp->below;
3579 3602
3580 if (QUERY_FLAG (invtmp, FLAG_AUTO_APPLY)) 3603 if (QUERY_FLAG (invtmp, FLAG_AUTO_APPLY))
3581 auto_apply (invtmp); 3604 auto_apply (invtmp);
3582 else if (invtmp->type == TREASURE && invtmp->has_random_items ()) 3605 else if (invtmp->type == TREASURE && invtmp->has_random_items ())
3583 { 3606 {
3584 while ((invtmp->stats.hp--) > 0) 3607 while (invtmp->stats.hp-- > 0)
3585 create_treasure (invtmp->randomitems, invtmp, 0, difficulty, 0); 3608 create_treasure (invtmp->randomitems, invtmp, 0, difficulty, 0);
3586 3609
3587 invtmp->randomitems = NULL; 3610 invtmp->randomitems = NULL;
3588 } 3611 }
3589 else if (invtmp && invtmp->arch 3612 else if (invtmp && invtmp->arch
3701 /* check for hp, sp change */ 3724 /* check for hp, sp change */
3702 if (food->stats.hp != 0) 3725 if (food->stats.hp != 0)
3703 { 3726 {
3704 if (QUERY_FLAG (food, FLAG_CURSED)) 3727 if (QUERY_FLAG (food, FLAG_CURSED))
3705 { 3728 {
3706 assign (who->contr->killer, food->name); 3729 who->contr->killer = food;
3707 hit_player (who, food->stats.hp, food, AT_POISON, 1); 3730 hit_player (who, food->stats.hp, food, AT_POISON, 1);
3708 who->failmsg ("Eck!...that was poisonous!"); 3731 who->failmsg ("Eck!...that was poisonous!");
3709 } 3732 }
3710 else 3733 else
3711 { 3734 {
3715 who->failmsg ("Eck!...that was poisonous!"); 3738 who->failmsg ("Eck!...that was poisonous!");
3716 3739
3717 who->stats.hp += food->stats.hp; 3740 who->stats.hp += food->stats.hp;
3718 } 3741 }
3719 } 3742 }
3743
3720 if (food->stats.sp != 0) 3744 if (food->stats.sp != 0)
3721 { 3745 {
3722 if (QUERY_FLAG (food, FLAG_CURSED)) 3746 if (QUERY_FLAG (food, FLAG_CURSED))
3723 { 3747 {
3724 who->failmsg ("You are drained of mana!"); 3748 who->failmsg ("You are drained of mana!");
3910 if (!strcmp (walk->name, "NOCLASSFACECHANGE")) 3934 if (!strcmp (walk->name, "NOCLASSFACECHANGE"))
3911 flag_change_face = 0; 3935 flag_change_face = 0;
3912 3936
3913 if (flag_change_face) 3937 if (flag_change_face)
3914 { 3938 {
3915 pl->animation_id = GET_ANIM_ID (change);
3916 pl->face = change->face; 3939 pl->face = change->face;
3917 3940 pl->animation_id = change->animation_id;
3918 if (QUERY_FLAG (change, FLAG_ANIMATE)) 3941 pl->flag [FLAG_ANIMATE] = change->flag [FLAG_ANIMATE];
3919 SET_FLAG (pl, FLAG_ANIMATE);
3920 else
3921 CLEAR_FLAG (pl, FLAG_ANIMATE);
3922 } 3942 }
3923 3943
3924 /* check the special case of can't use weapons */ 3944 /* check the special case of can't use weapons */
3925 /*if(QUERY_FLAG(change,FLAG_USE_WEAPON)) CLEAR_FLAG(pl,FLAG_USE_WEAPON); */ 3945 /*if(QUERY_FLAG(change,FLAG_USE_WEAPON)) CLEAR_FLAG(pl,FLAG_USE_WEAPON); */
3926 if (!strcmp (change->name, "monk")) 3946 if (!strcmp (change->name, "monk"))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines