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 | */ |
… | |
… | |
233 | depl = present_arch_in_ob (at, op); |
232 | depl = present_arch_in_ob (at, op); |
234 | |
233 | |
235 | if (depl) |
234 | if (depl) |
236 | { |
235 | { |
237 | for (i = 0; i < NUM_STATS; i++) |
236 | for (i = 0; i < NUM_STATS; i++) |
238 | if (get_attr_value (&depl->stats, i)) |
237 | if (depl->stats.stat (i)) |
239 | new_draw_info (NDI_UNIQUE, 0, op, restore_msg[i]); |
238 | new_draw_info (NDI_UNIQUE, 0, op, restore_msg[i]); |
240 | |
239 | |
241 | depl->destroy (); |
240 | depl->destroy (); |
242 | op->update_stats (); |
241 | op->update_stats (); |
243 | } |
242 | } |
… | |
… | |
375 | force->stats.food *= 10; |
374 | force->stats.food *= 10; |
376 | for (i = 0; i < NROFATTACKS; i++) |
375 | for (i = 0; i < NROFATTACKS; i++) |
377 | if (force->resist[i] > 0) |
376 | if (force->resist[i] > 0) |
378 | force->resist[i] = -force->resist[i]; /* prot => vuln */ |
377 | force->resist[i] = -force->resist[i]; /* prot => vuln */ |
379 | } |
378 | } |
|
|
379 | |
380 | force->speed_left = -1; |
380 | force->speed_left = -1; |
381 | force = insert_ob_in_ob (force, op); |
381 | force = insert_ob_in_ob (force, op); |
382 | CLEAR_FLAG (tmp, FLAG_APPLIED); |
382 | CLEAR_FLAG (tmp, FLAG_APPLIED); |
383 | SET_FLAG (force, FLAG_APPLIED); |
383 | SET_FLAG (force, FLAG_APPLIED); |
384 | change_abil (op, force); |
384 | change_abil (op, force); |
… | |
… | |
765 | { |
765 | { |
766 | object *otmp; |
766 | object *otmp; |
767 | |
767 | |
768 | if (op->type != PLAYER) |
768 | if (op->type != PLAYER) |
769 | return 0; |
769 | return 0; |
|
|
770 | |
770 | if (!QUERY_FLAG (op, FLAG_WIZCAST) && (get_map_flags (op->map, NULL, op->x, op->y, NULL, NULL) & P_NO_MAGIC)) |
771 | if (!QUERY_FLAG (op, FLAG_WIZCAST) && (get_map_flags (op->map, NULL, op->x, op->y, NULL, NULL) & P_NO_MAGIC)) |
771 | { |
772 | { |
772 | new_draw_info (NDI_UNIQUE, 0, op, "Something blocks the magic of the scroll."); |
773 | new_draw_info (NDI_UNIQUE, 0, op, "Something blocks the magic of the scroll."); |
773 | return 0; |
774 | return 0; |
774 | } |
775 | } |
|
|
776 | |
775 | otmp = find_marked_object (op); |
777 | otmp = find_marked_object (op); |
776 | if (!otmp) |
778 | if (!otmp) |
777 | { |
779 | { |
778 | new_draw_info (NDI_UNIQUE, 0, op, "You need to mark a weapon object."); |
780 | new_draw_info (NDI_UNIQUE, 0, op, "You need to mark a weapon object."); |
779 | return 0; |
781 | return 0; |
780 | } |
782 | } |
|
|
783 | |
781 | if (otmp->type != WEAPON && otmp->type != BOW) |
784 | if (otmp->type != WEAPON && otmp->type != BOW) |
782 | { |
785 | { |
783 | new_draw_info (NDI_UNIQUE, 0, op, "Marked item is not a weapon or bow"); |
786 | new_draw_info (NDI_UNIQUE, 0, op, "Marked item is not a weapon or bow"); |
784 | return 0; |
787 | return 0; |
785 | } |
788 | } |
|
|
789 | |
786 | new_draw_info (NDI_UNIQUE, 0, op, "Applied weapon builder."); |
790 | new_draw_info (NDI_UNIQUE, 0, op, "Applied weapon builder."); |
787 | improve_weapon (op, tmp, otmp); |
791 | improve_weapon (op, tmp, otmp); |
788 | esrv_send_item (op, otmp); |
792 | esrv_send_item (op, otmp); |
789 | return 1; |
793 | return 1; |
790 | } |
794 | } |
… | |
… | |
1059 | { |
1063 | { |
1060 | // it is in our env, so activate it, do not open yet |
1064 | // it is in our env, so activate it, do not open yet |
1061 | op->close_container (); |
1065 | op->close_container (); |
1062 | sack->flag [FLAG_APPLIED] = 1; |
1066 | sack->flag [FLAG_APPLIED] = 1; |
1063 | esrv_update_item (UPD_FLAGS, op, sack); |
1067 | esrv_update_item (UPD_FLAGS, op, sack); |
|
|
1068 | new_draw_info_format (NDI_UNIQUE, 0, op, "You ready %s.", query_name (sack)); |
1064 | return 1; |
1069 | return 1; |
1065 | } |
1070 | } |
1066 | |
1071 | |
1067 | // it's locked? |
1072 | // it's locked? |
1068 | if (sack->slaying) |
1073 | if (sack->slaying) |
… | |
… | |
1333 | |
1338 | |
1334 | /* Just put in some sanity check. I think there is a bug in the |
1339 | /* Just put in some sanity check. I think there is a bug in the |
1335 | * above with some objects have zero speed, and thus the player |
1340 | * above with some objects have zero speed, and thus the player |
1336 | * getting permanently paralyzed. |
1341 | * getting permanently paralyzed. |
1337 | */ |
1342 | */ |
1338 | if (victim->speed_left < -50.0) |
1343 | if (victim->speed_left < -50.f) |
1339 | victim->speed_left = -50.0; |
1344 | victim->speed_left = -50.f; |
1340 | /* LOG(llevDebug, "apply, playermove, player speed_left=%f\n", victim->speed_left); */ |
1345 | /* LOG(llevDebug, "apply, playermove, player speed_left=%f\n", victim->speed_left); */ |
1341 | } |
1346 | } |
1342 | goto leave; |
1347 | goto leave; |
1343 | |
1348 | |
1344 | case SPINNER: |
1349 | case SPINNER: |
… | |
… | |
1570 | |
1575 | |
1571 | readable_message_type *msgType = get_readable_message_type (tmp); |
1576 | readable_message_type *msgType = get_readable_message_type (tmp); |
1572 | |
1577 | |
1573 | draw_ext_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, |
1578 | draw_ext_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, |
1574 | msgType->message_type, msgType->message_subtype, |
1579 | msgType->message_type, msgType->message_subtype, |
1575 | "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); |
1576 | |
1582 | |
1577 | /* gain xp from reading */ |
1583 | /* gain xp from reading */ |
1578 | if (!QUERY_FLAG (tmp, FLAG_NO_SKILL_IDENT)) |
1584 | if (!QUERY_FLAG (tmp, FLAG_NO_SKILL_IDENT)) |
1579 | { /* only if not read before */ |
1585 | { /* only if not read before */ |
1580 | int exp_gain = calc_skill_exp (op, tmp, skill_ob); |
1586 | int exp_gain = calc_skill_exp (op, tmp, skill_ob); |
… | |
… | |
1736 | return; |
1742 | return; |
1737 | } |
1743 | } |
1738 | |
1744 | |
1739 | if (skop->level < int (sqrtf (spell->level) * 1.5f)) |
1745 | if (skop->level < int (sqrtf (spell->level) * 1.5f)) |
1740 | { |
1746 | { |
1741 | 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]"); |
1742 | return; |
1748 | return; |
1743 | } |
1749 | } |
1744 | |
1750 | |
1745 | 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); |
1746 | |
1752 | |
… | |
… | |
1769 | { |
1775 | { |
1770 | spell_skill = find_skill_by_name (op, spell->skill); |
1776 | spell_skill = find_skill_by_name (op, spell->skill); |
1771 | |
1777 | |
1772 | if (!spell_skill) |
1778 | if (!spell_skill) |
1773 | { |
1779 | { |
1774 | 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); |
1775 | return; |
1781 | return; |
1776 | } |
1782 | } |
1777 | |
1783 | |
1778 | if (spell_skill->level < spell->level) |
1784 | if (spell_skill->level < spell->level) |
1779 | { |
1785 | { |
… | |
… | |
1813 | else |
1819 | else |
1814 | { |
1820 | { |
1815 | play_sound_player_only (op->contr, SOUND_FUMBLE_SPELL, 0, 0); |
1821 | play_sound_player_only (op->contr, SOUND_FUMBLE_SPELL, 0, 0); |
1816 | 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"); |
1817 | } |
1823 | } |
|
|
1824 | |
1818 | decrease_ob (tmp); |
1825 | decrease_ob (tmp); |
1819 | } |
1826 | } |
1820 | |
1827 | |
1821 | /** |
1828 | /** |
1822 | * Handles applying a spell scroll. |
1829 | * Handles applying a spell scroll. |
… | |
… | |
2077 | /* doubled chance for resistance of ability-focus */ |
2084 | /* doubled chance for resistance of ability-focus */ |
2078 | if (i == abil->stats.exp) |
2085 | if (i == abil->stats.exp) |
2079 | chance = MIN (100., chance * 2.); |
2086 | chance = MIN (100., chance * 2.); |
2080 | |
2087 | |
2081 | /* 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!) */ |
2082 | if (rndm (10000) < (int) (chance * 100)) |
2089 | if (rndm (10000) < (unsigned int) (chance * 100)) |
2083 | { |
2090 | { |
2084 | atnr_winner[winners] = i; |
2091 | atnr_winner[winners] = i; |
2085 | winners++; |
2092 | winners++; |
2086 | } |
2093 | } |
2087 | |
2094 | |
… | |
… | |
2289 | } |
2296 | } |
2290 | |
2297 | |
2291 | return 0; |
2298 | return 0; |
2292 | } |
2299 | } |
2293 | |
2300 | |
2294 | |
|
|
2295 | /** |
2301 | /** |
2296 | * Main apply handler. |
2302 | * Main apply handler. |
2297 | * |
2303 | * |
2298 | * Checks for unpaid items before applying. |
2304 | * Checks for unpaid items before applying. |
2299 | * |
2305 | * |
… | |
… | |
2306 | * being applied. |
2312 | * being applied. |
2307 | * |
2313 | * |
2308 | * aflag is special (always apply/unapply) flags. Nothing is done with |
2314 | * aflag is special (always apply/unapply) flags. Nothing is done with |
2309 | * them in this function - they are passed to apply_special |
2315 | * them in this function - they are passed to apply_special |
2310 | */ |
2316 | */ |
2311 | |
|
|
2312 | int |
2317 | int |
2313 | manual_apply (object *op, object *tmp, int aflag) |
2318 | manual_apply (object *op, object *tmp, int aflag) |
2314 | { |
2319 | { |
2315 | if (tmp->head) |
2320 | if (tmp->head) |
2316 | tmp = tmp->head; |
2321 | tmp = tmp->head; |
… | |
… | |
2354 | case EXIT: |
2359 | case EXIT: |
2355 | if (op->type != PLAYER) |
2360 | if (op->type != PLAYER) |
2356 | return 0; |
2361 | return 0; |
2357 | |
2362 | |
2358 | if (!EXIT_PATH (tmp) || !is_legal_2ways_exit (op, tmp)) |
2363 | if (!EXIT_PATH (tmp) || !is_legal_2ways_exit (op, tmp)) |
2359 | { |
|
|
2360 | 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)); |
2361 | } |
|
|
2362 | else |
2365 | else |
2363 | { |
2366 | { |
2364 | /* Don't display messages for random maps. */ |
2367 | /* Don't display messages for random maps. */ |
2365 | if (tmp->msg && strncmp (EXIT_PATH (tmp), "/!", 2)) |
2368 | if (tmp->msg && strncmp (EXIT_PATH (tmp), "/!", 2)) |
2366 | new_draw_info (NDI_NAVY, 0, op, tmp->msg); |
2369 | new_draw_info (NDI_NAVY, 0, op, tmp->msg); |
2367 | |
2370 | |
2368 | op->enter_exit (tmp); |
2371 | op->enter_exit (tmp); |
2369 | } |
2372 | } |
|
|
2373 | |
2370 | return 1; |
2374 | return 1; |
2371 | |
2375 | |
2372 | case SIGN: |
2376 | case SIGN: |
2373 | apply_sign (op, tmp, 0); |
2377 | apply_sign (op, tmp, 0); |
2374 | return 1; |
2378 | return 1; |
… | |
… | |
2378 | { |
2382 | { |
2379 | apply_book (op, tmp); |
2383 | apply_book (op, tmp); |
2380 | return 1; |
2384 | return 1; |
2381 | } |
2385 | } |
2382 | else |
2386 | else |
2383 | { |
|
|
2384 | return 0; |
2387 | return 0; |
2385 | } |
|
|
2386 | |
2388 | |
2387 | case SKILLSCROLL: |
2389 | case SKILLSCROLL: |
2388 | if (op->type == PLAYER) |
2390 | if (op->type == PLAYER) |
2389 | { |
2391 | { |
2390 | apply_skillscroll (op, tmp); |
2392 | apply_skillscroll (op, tmp); |
2391 | return 1; |
2393 | return 1; |
2392 | } |
2394 | } |
|
|
2395 | else |
2393 | return 0; |
2396 | return 0; |
2394 | |
2397 | |
2395 | case SPELLBOOK: |
2398 | case SPELLBOOK: |
2396 | if (op->type == PLAYER) |
2399 | if (op->type == PLAYER) |
2397 | { |
2400 | { |
2398 | apply_spellbook (op, tmp); |
2401 | apply_spellbook (op, tmp); |
2399 | return 1; |
2402 | return 1; |
2400 | } |
2403 | } |
|
|
2404 | else |
2401 | return 0; |
2405 | return 0; |
2402 | |
2406 | |
2403 | case SCROLL: |
2407 | case SCROLL: |
2404 | apply_scroll (op, tmp, 0); |
2408 | apply_scroll (op, tmp, 0); |
2405 | return 1; |
2409 | return 1; |
2406 | |
2410 | |
2407 | case POTION: |
2411 | case POTION: |
2408 | (void) apply_potion (op, tmp); |
2412 | apply_potion (op, tmp); |
2409 | return 1; |
2413 | return 1; |
2410 | |
2414 | |
2411 | /* Eneq(@csd.uu.se): Handle apply on containers. */ |
2415 | /* Eneq(@csd.uu.se): Handle apply on containers. */ |
2412 | //TODO: remove, as it is unsed? |
2416 | //TODO: remove, as it is unsed? |
2413 | case CLOSE_CON: |
2417 | case CLOSE_CON: |
… | |
… | |
2446 | case LAMP: |
2450 | case LAMP: |
2447 | case BUILDER: |
2451 | case BUILDER: |
2448 | case SKILL_TOOL: |
2452 | case SKILL_TOOL: |
2449 | if (tmp->env != op) |
2453 | if (tmp->env != op) |
2450 | return 2; /* not in inventory */ |
2454 | return 2; /* not in inventory */ |
|
|
2455 | |
2451 | (void) apply_special (op, tmp, aflag); |
2456 | apply_special (op, tmp, aflag); |
2452 | return 1; |
2457 | return 1; |
2453 | |
2458 | |
2454 | case DRINK: |
2459 | case DRINK: |
2455 | case FOOD: |
2460 | case FOOD: |
2456 | case FLESH: |
2461 | case FLESH: |
… | |
… | |
2472 | } |
2477 | } |
2473 | else |
2478 | else |
2474 | return 0; |
2479 | return 0; |
2475 | |
2480 | |
2476 | case WEAPON_IMPROVER: |
2481 | case WEAPON_IMPROVER: |
2477 | (void) check_improve_weapon (op, tmp); |
2482 | check_improve_weapon (op, tmp); |
2478 | return 1; |
2483 | return 1; |
2479 | |
2484 | |
2480 | case CLOCK: |
2485 | case CLOCK: |
2481 | if (op->type == PLAYER) |
2486 | if (op->type == PLAYER) |
2482 | { |
2487 | { |
… | |
… | |
2490 | play_sound_player_only (op->contr, SOUND_CLOCK, 0, 0); |
2495 | play_sound_player_only (op->contr, SOUND_CLOCK, 0, 0); |
2491 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
2496 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
2492 | return 1; |
2497 | return 1; |
2493 | } |
2498 | } |
2494 | else |
2499 | else |
2495 | { |
|
|
2496 | return 0; |
2500 | return 0; |
2497 | } |
|
|
2498 | |
2501 | |
2499 | case MENU: |
2502 | case MENU: |
2500 | if (op->type == PLAYER) |
2503 | if (op->type == PLAYER) |
2501 | { |
2504 | { |
2502 | shop_listing (op); |
2505 | shop_listing (tmp, op); |
2503 | return 1; |
2506 | return 1; |
2504 | } |
2507 | } |
2505 | else |
2508 | else |
2506 | { |
|
|
2507 | return 0; |
2509 | return 0; |
2508 | } |
|
|
2509 | |
2510 | |
2510 | case POWER_CRYSTAL: |
2511 | case POWER_CRYSTAL: |
2511 | apply_power_crystal (op, tmp); /* see egoitem.c */ |
2512 | apply_power_crystal (op, tmp); /* see egoitem.c */ |
2512 | return 1; |
2513 | return 1; |
2513 | |
2514 | |
… | |
… | |
2516 | { |
2517 | { |
2517 | apply_lighter (op, tmp); |
2518 | apply_lighter (op, tmp); |
2518 | return 1; |
2519 | return 1; |
2519 | } |
2520 | } |
2520 | else |
2521 | else |
2521 | { |
|
|
2522 | return 0; |
2522 | return 0; |
2523 | } |
|
|
2524 | |
2523 | |
2525 | case ITEM_TRANSFORMER: |
2524 | case ITEM_TRANSFORMER: |
2526 | apply_item_transformer (op, tmp); |
2525 | apply_item_transformer (op, tmp); |
2527 | return 1; |
2526 | return 1; |
2528 | |
2527 | |
… | |
… | |
2581 | /** |
2580 | /** |
2582 | * player_apply_below attempts to apply the object 'below' the player. |
2581 | * player_apply_below attempts to apply the object 'below' the player. |
2583 | * 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 |
2584 | * we use the ground. |
2583 | * we use the ground. |
2585 | */ |
2584 | */ |
2586 | |
|
|
2587 | void |
2585 | void |
2588 | player_apply_below (object *pl) |
2586 | player_apply_below (object *pl) |
2589 | { |
2587 | { |
2590 | int floors = 0; |
2588 | int floors = 0; |
2591 | |
2589 | |
… | |
… | |
2628 | * 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. |
2629 | */ |
2627 | */ |
2630 | static int |
2628 | static int |
2631 | unapply_special (object *who, object *op, int aflags) |
2629 | unapply_special (object *who, object *op, int aflags) |
2632 | { |
2630 | { |
2633 | 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))) |
2634 | return RESULT_INT (0); |
2633 | return RESULT_INT (0); |
2635 | |
2634 | |
2636 | object *tmp2; |
2635 | object *tmp2; |
2637 | |
2636 | |
2638 | CLEAR_FLAG (op, FLAG_APPLIED); |
2637 | CLEAR_FLAG (op, FLAG_APPLIED); |
|
|
2638 | |
|
|
2639 | if (player *pl = who->contr) |
|
|
2640 | { |
|
|
2641 | if (op == pl->ranged_ob) pl->ranged_ob = 0; |
|
|
2642 | if (op == pl->combat_ob) pl->combat_ob = 0; |
|
|
2643 | } |
|
|
2644 | |
2639 | switch (op->type) |
2645 | switch (op->type) |
2640 | { |
2646 | { |
|
|
2647 | case SKILL_TOOL: |
|
|
2648 | // unapplying a skill tool should also unapply the skill it governs |
|
|
2649 | // but this is hard, as it shouldn't do so when the skill can |
|
|
2650 | // be used for other reasons |
|
|
2651 | for (object *tmp = who->inv; tmp; tmp = tmp->below) |
|
|
2652 | if (tmp->skill == op->skill |
|
|
2653 | && tmp->type == SKILL |
|
|
2654 | && tmp->flag [FLAG_APPLIED] |
|
|
2655 | && !tmp->flag [FLAG_CAN_USE_SKILL]) |
|
|
2656 | unapply_special (who, tmp, 0); |
|
|
2657 | |
|
|
2658 | change_abil (who, op); |
|
|
2659 | break; |
|
|
2660 | |
2641 | case WEAPON: |
2661 | case WEAPON: |
2642 | new_draw_info_format (NDI_UNIQUE, 0, who, "You unwield %s.", query_name (op)); |
2662 | new_draw_info_format (NDI_UNIQUE, 0, who, "You unwield %s.", query_name (op)); |
2643 | |
2663 | |
2644 | (void) change_abil (who, op); |
2664 | change_abil (who, op); |
2645 | if (QUERY_FLAG (who, FLAG_READY_WEAPON)) |
|
|
2646 | CLEAR_FLAG (who, FLAG_READY_WEAPON); |
2665 | CLEAR_FLAG (who, FLAG_READY_WEAPON); |
2647 | clear_skill (who); |
2666 | clear_skill (who); |
2648 | break; |
2667 | break; |
2649 | |
2668 | |
2650 | case SKILL: /* allows objects to impart skills */ |
|
|
2651 | case SKILL_TOOL: |
2669 | case SKILL: |
2652 | if (op != who->chosen_skill) |
2670 | if (op != who->chosen_skill) |
2653 | { |
|
|
2654 | LOG (llevError, "BUG: apply_special(): applied skill is not a chosen skill\n"); |
2671 | LOG (llevError, "BUG: apply_special(): applied skill is not a chosen skill\n"); |
|
|
2672 | |
|
|
2673 | if (who->contr) |
2655 | } |
2674 | { |
2656 | if (who->type == PLAYER) |
|
|
2657 | { |
|
|
2658 | if (who->contr->shoottype == range_skill) |
|
|
2659 | who->contr->shoottype = range_none; |
|
|
2660 | if (!op->invisible) |
2675 | if (!op->invisible) |
2661 | { |
|
|
2662 | new_draw_info_format (NDI_UNIQUE, 0, who, "You stop using the %s.", query_name (op)); |
2676 | new_draw_info_format (NDI_UNIQUE, 0, who, "You stop using the %s.", query_name (op)); |
2663 | } |
|
|
2664 | else |
2677 | else |
2665 | { |
|
|
2666 | new_draw_info_format (NDI_UNIQUE, 0, who, "You can no longer use the skill: %s.", &op->skill); |
2678 | new_draw_info_format (NDI_UNIQUE, 0, who, "You can no longer use the skill: %s.", &op->skill); |
2667 | } |
2679 | } |
2668 | } |
2680 | |
2669 | (void) change_abil (who, op); |
2681 | change_abil (who, op); |
2670 | who->chosen_skill = NULL; |
2682 | who->chosen_skill = 0; |
2671 | CLEAR_FLAG (who, FLAG_READY_SKILL); |
2683 | CLEAR_FLAG (who, FLAG_READY_SKILL); |
2672 | break; |
2684 | break; |
2673 | |
2685 | |
2674 | case ARMOUR: |
2686 | case ARMOUR: |
2675 | case HELMET: |
2687 | case HELMET: |
… | |
… | |
2680 | case AMULET: |
2692 | case AMULET: |
2681 | case GIRDLE: |
2693 | case GIRDLE: |
2682 | case BRACERS: |
2694 | case BRACERS: |
2683 | case CLOAK: |
2695 | case CLOAK: |
2684 | new_draw_info_format (NDI_UNIQUE, 0, who, "You unwear %s.", query_name (op)); |
2696 | new_draw_info_format (NDI_UNIQUE, 0, who, "You unwear %s.", query_name (op)); |
2685 | (void) change_abil (who, op); |
2697 | change_abil (who, op); |
2686 | break; |
2698 | break; |
|
|
2699 | |
2687 | case LAMP: |
2700 | case LAMP: |
2688 | new_draw_info_format (NDI_UNIQUE, 0, who, "You turn off your %s.", &op->name); |
2701 | new_draw_info_format (NDI_UNIQUE, 0, who, "You turn off your %s.", &op->name); |
2689 | tmp2 = arch_to_object (op->other_arch); |
2702 | tmp2 = arch_to_object (op->other_arch); |
2690 | tmp2->x = op->x; |
2703 | tmp2->x = op->x; |
2691 | tmp2->y = op->y; |
2704 | tmp2->y = op->y; |
… | |
… | |
2696 | CLEAR_FLAG (tmp2, FLAG_APPLIED); |
2709 | CLEAR_FLAG (tmp2, FLAG_APPLIED); |
2697 | |
2710 | |
2698 | if (QUERY_FLAG (op, FLAG_INV_LOCKED)) |
2711 | if (QUERY_FLAG (op, FLAG_INV_LOCKED)) |
2699 | SET_FLAG (tmp2, FLAG_INV_LOCKED); |
2712 | SET_FLAG (tmp2, FLAG_INV_LOCKED); |
2700 | |
2713 | |
2701 | if (who->type == PLAYER) |
2714 | if (who->contr) |
2702 | esrv_del_item (who->contr, op->count); |
2715 | esrv_del_item (who->contr, op->count); |
2703 | |
2716 | |
2704 | op->destroy (); |
2717 | op->destroy (); |
2705 | insert_ob_in_ob (tmp2, who); |
2718 | insert_ob_in_ob (tmp2, who); |
2706 | who->update_stats (); |
2719 | who->update_stats (); |
|
|
2720 | |
2707 | if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED)) |
2721 | if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED)) |
2708 | { |
2722 | { |
2709 | if (who->type == PLAYER) |
2723 | if (who->contr) |
2710 | { |
2724 | { |
2711 | new_draw_info (NDI_UNIQUE, 0, who, "Oops, it feels deadly cold!"); |
2725 | new_draw_info (NDI_UNIQUE, 0, who, "Oops, it feels deadly cold!"); |
2712 | SET_FLAG (tmp2, FLAG_KNOWN_CURSED); |
2726 | SET_FLAG (tmp2, FLAG_KNOWN_CURSED); |
2713 | } |
2727 | } |
2714 | } |
2728 | } |
2715 | if (who->type == PLAYER) |
2729 | |
|
|
2730 | if (who->contr) |
2716 | esrv_send_item (who, tmp2); |
2731 | esrv_send_item (who, tmp2); |
|
|
2732 | |
2717 | return 1; /* otherwise, an attempt to drop causes problems */ |
2733 | return 1; /* otherwise, an attempt to drop causes problems */ |
2718 | break; |
2734 | |
2719 | case BOW: |
2735 | case BOW: |
2720 | case WAND: |
2736 | case WAND: |
2721 | case ROD: |
2737 | case ROD: |
2722 | case HORN: |
2738 | case HORN: |
2723 | clear_skill (who); |
2739 | clear_skill (who); |
|
|
2740 | |
|
|
2741 | if (who->contr) |
|
|
2742 | { |
2724 | new_draw_info_format (NDI_UNIQUE, 0, who, "You unready %s.", query_name (op)); |
2743 | new_draw_info_format (NDI_UNIQUE, 0, who, "You unready %s.", query_name (op)); |
2725 | if (who->type == PLAYER) |
2744 | |
2726 | { |
2745 | if (who->contr->ranged_ob == op) |
2727 | who->contr->shoottype = range_none; |
2746 | who->contr->ranged_ob = 0; |
|
|
2747 | |
|
|
2748 | if (who->current_weapon == op) |
|
|
2749 | who->current_weapon = 0; |
2728 | } |
2750 | } |
2729 | else |
2751 | else |
2730 | { |
2752 | { |
2731 | if (op->type == BOW) |
2753 | if (op->type == BOW) |
2732 | CLEAR_FLAG (who, FLAG_READY_BOW); |
2754 | CLEAR_FLAG (who, FLAG_READY_BOW); |
2733 | else |
2755 | else |
2734 | CLEAR_FLAG (who, FLAG_READY_RANGE); |
2756 | CLEAR_FLAG (who, FLAG_READY_RANGE); |
2735 | } |
2757 | } |
|
|
2758 | |
2736 | break; |
2759 | break; |
2737 | |
2760 | |
2738 | case BUILDER: |
2761 | case BUILDER: |
|
|
2762 | if (who->contr) |
|
|
2763 | { |
2739 | new_draw_info_format (NDI_UNIQUE, 0, who, "You unready %s.", query_name (op)); |
2764 | new_draw_info_format (NDI_UNIQUE, 0, who, "You unready %s.", query_name (op)); |
2740 | who->contr->shoottype = range_none; |
2765 | |
2741 | who->contr->ranges[range_builder] = NULL; |
2766 | if (who->contr->ranged_ob == op) |
|
|
2767 | who->contr->ranged_ob = 0; |
|
|
2768 | } |
2742 | break; |
2769 | break; |
2743 | |
2770 | |
2744 | default: |
2771 | default: |
2745 | new_draw_info_format (NDI_UNIQUE, 0, who, "You unapply %s.", query_name (op)); |
2772 | new_draw_info_format (NDI_UNIQUE, 0, who, "You unapply %s.", query_name (op)); |
2746 | break; |
2773 | break; |
… | |
… | |
2748 | |
2775 | |
2749 | who->update_stats (); |
2776 | who->update_stats (); |
2750 | |
2777 | |
2751 | if (!(aflags & AP_NO_MERGE)) |
2778 | if (!(aflags & AP_NO_MERGE)) |
2752 | { |
2779 | { |
2753 | object *tmp; |
|
|
2754 | |
|
|
2755 | tmp = merge_ob (op, NULL); |
2780 | object *tmp = merge_ob (op, 0); |
2756 | if (who->type == PLAYER) |
2781 | |
|
|
2782 | if (who->contr) |
2757 | { |
2783 | { |
2758 | if (tmp) |
2784 | if (tmp) |
2759 | { /* it was merged */ |
2785 | { /* it was merged */ |
2760 | esrv_del_item (who->contr, op->count); |
2786 | esrv_del_item (who->contr, op->count); |
2761 | op = tmp; |
2787 | op = tmp; |
2762 | } |
2788 | } |
2763 | |
2789 | |
2764 | esrv_send_item (who, op); |
2790 | esrv_send_item (who, op); |
2765 | } |
2791 | } |
2766 | } |
2792 | } |
|
|
2793 | |
2767 | return 0; |
2794 | return 0; |
2768 | } |
2795 | } |
2769 | |
2796 | |
2770 | /** |
2797 | /** |
2771 | * Returns the object that is using location 'loc'. |
2798 | * Returns the object that is using location 'loc'. |
2772 | * Note that 'start' is the first object to start examing - we |
2799 | * Note that 'start' is the first object to start examing - we |
2773 | * then go through the below of this. In this way, you can do |
2800 | * then go through the below of this. In this way, you can do |
2774 | * something like: |
2801 | * something like: |
2775 | * tmp = get_item_from_body_location(who->inv, 1); |
2802 | * tmp = get_next_item_from_body_location(who->inv, 1); |
2776 | * if (tmp) tmp1 = get_item_from_body_location(tmp->below, 1); |
2803 | * if (tmp) tmp1 = get_next_item_from_body_location(tmp->below, 1); |
2777 | * to find the second object that may use this location, etc. |
2804 | * to find the second object that may use this location, etc. |
2778 | * Returns NULL if no match is found. |
2805 | * Returns NULL if no match is found. |
2779 | * loc is the index into the array we are looking for a match. |
2806 | * loc is the index into the array we are looking for a match. |
2780 | * don't return invisible objects unless they are skill objects |
2807 | * don't return invisible objects unless they are skill objects |
2781 | * invisible other objects that use |
2808 | * invisible other objects that use |
2782 | * up body locations can be used as restrictions. |
2809 | * up body locations can be used as restrictions. |
2783 | */ |
2810 | */ |
2784 | object * |
2811 | static object * |
2785 | get_item_from_body_location (object *start, int loc) |
2812 | get_next_item_from_body_location (int loc, object *start) |
2786 | { |
2813 | { |
2787 | object *tmp; |
|
|
2788 | |
|
|
2789 | if (!start) |
|
|
2790 | return NULL; |
|
|
2791 | |
|
|
2792 | for (tmp = start; tmp; tmp = tmp->below) |
2814 | for (object *tmp = start; tmp; tmp = tmp->below) |
2793 | if (QUERY_FLAG (tmp, FLAG_APPLIED) && tmp->body_info[loc] && (!tmp->invisible || tmp->type == SKILL)) |
2815 | if (tmp->flag [FLAG_APPLIED] |
|
|
2816 | && tmp->slot[loc].info |
|
|
2817 | && (!tmp->invisible || tmp->type == SKILL)) |
2794 | return tmp; |
2818 | return tmp; |
2795 | |
2819 | |
2796 | return NULL; |
2820 | return 0; |
2797 | } |
2821 | } |
2798 | |
|
|
2799 | |
|
|
2800 | |
2822 | |
2801 | /** |
2823 | /** |
2802 | * 'op' wants to apply an object, but can't because of other equipment. |
2824 | * 'op' wants to apply an object, but can't because of other equipment. |
2803 | * This should only be called when it is known |
2825 | * This should only be called when it is known |
2804 | * that there are objects to unapply. This makes pretty heavy |
2826 | * that there are objects to unapply. This makes pretty heavy |
… | |
… | |
2810 | * another function that does just that. |
2832 | * another function that does just that. |
2811 | */ |
2833 | */ |
2812 | int |
2834 | int |
2813 | unapply_for_ob (object *who, object *op, int aflags) |
2835 | unapply_for_ob (object *who, object *op, int aflags) |
2814 | { |
2836 | { |
2815 | int i; |
2837 | if (op->is_range ()) |
2816 | object *tmp = NULL, *last; |
|
|
2817 | |
|
|
2818 | /* If we are applying a shield or weapon, unapply any equipped shield |
|
|
2819 | * or weapons first - only allowed to use one weapon/shield at a time. |
|
|
2820 | */ |
|
|
2821 | if (op->type == WEAPON || op->type == SHIELD) |
|
|
2822 | { |
|
|
2823 | for (tmp = who->inv; tmp; tmp = tmp->below) |
2838 | for (object *tmp = who->inv; tmp; tmp = tmp->below) |
2824 | { |
|
|
2825 | if (QUERY_FLAG (tmp, FLAG_APPLIED) && tmp->type == op->type) |
2839 | if (QUERY_FLAG (tmp, FLAG_APPLIED) && tmp->is_range ()) |
2826 | { |
|
|
2827 | if ((aflags & AP_IGNORE_CURSE) || (aflags & AP_PRINT) || (!QUERY_FLAG (tmp, FLAG_CURSED) && !QUERY_FLAG (tmp, FLAG_DAMNED))) |
2840 | if ((aflags & AP_IGNORE_CURSE) || (aflags & AP_PRINT) || (!QUERY_FLAG (tmp, FLAG_CURSED) && !QUERY_FLAG (tmp, FLAG_DAMNED))) |
2828 | { |
2841 | { |
2829 | if (aflags & AP_PRINT) |
2842 | if (aflags & AP_PRINT) |
2830 | new_draw_info (NDI_UNIQUE, 0, who, query_name (tmp)); |
2843 | new_draw_info (NDI_UNIQUE, 0, who, query_name (tmp)); |
2831 | else |
2844 | else |
2832 | unapply_special (who, tmp, aflags); |
2845 | unapply_special (who, tmp, aflags); |
2833 | } |
2846 | } |
2834 | else |
2847 | else |
2835 | { |
2848 | { |
2836 | /* In this case, we want to try and remove a cursed item. |
2849 | /* In this case, we want to try and remove a cursed item. |
2837 | * While we know it won't work, we want unapply_special to |
2850 | * While we know it won't work, we want unapply_special to |
2838 | * at least generate the message. |
2851 | * at least generate the message. |
2839 | */ |
2852 | */ |
2840 | new_draw_info_format (NDI_UNIQUE, 0, who, "No matter how hard you try, you just can't\nremove %s.", query_name (tmp)); |
2853 | new_draw_info_format (NDI_UNIQUE, 0, who, "No matter how hard you try, you just can't remove the %s.", query_name (tmp)); |
2841 | return 1; |
2854 | return 1; |
2842 | } |
|
|
2843 | |
|
|
2844 | } |
2855 | } |
2845 | } |
|
|
2846 | } |
|
|
2847 | |
2856 | |
2848 | for (i = 0; i < NUM_BODY_LOCATIONS; i++) |
2857 | for (int i = 0; i < NUM_BODY_LOCATIONS; i++) |
2849 | { |
2858 | { |
2850 | /* this used up a slot that we need to free */ |
2859 | /* this used up a slot that we need to free */ |
2851 | if (op->body_info[i]) |
2860 | if (op->slot[i].info) |
2852 | { |
2861 | { |
2853 | last = who->inv; |
2862 | object *last = who->inv; |
2854 | |
2863 | |
2855 | /* We do a while loop - may need to remove several items in order |
2864 | /* We do a while loop - may need to remove several items in order |
2856 | * to free up enough slots. |
2865 | * to free up enough slots. |
2857 | */ |
2866 | */ |
2858 | while ((who->body_used[i] + op->body_info[i]) < 0) |
2867 | while ((who->slot[i].used + op->slot[i].info) < 0) |
2859 | { |
2868 | { |
2860 | tmp = get_item_from_body_location (last, i); |
2869 | object *tmp = get_next_item_from_body_location (i, last); |
|
|
2870 | |
2861 | if (!tmp) |
2871 | if (!tmp) |
2862 | { |
2872 | { |
2863 | #if 0 |
2873 | #if 0 |
2864 | /* Not a bug - we'll get this if the player has cursed items |
2874 | /* Not a bug - we'll get this if the player has cursed items |
2865 | * equipped. |
2875 | * equipped. |
2866 | */ |
2876 | */ |
2867 | LOG (llevError, "Can't find object using location %d (%s) on %s\n", i, body_locations[i].save_name, who->name); |
2877 | LOG (llevError, "Can't find object using location %d (%s) on %s\n", i, body_locations[i].save_name, who->name); |
2868 | #endif |
2878 | #endif |
2869 | return 1; |
2879 | return 1; |
2870 | } |
2880 | } |
|
|
2881 | |
2871 | /* If we are just printing, we don't care about cursed status */ |
2882 | /* If we are just printing, we don't care about cursed status */ |
2872 | if ((aflags & AP_IGNORE_CURSE) || (aflags & AP_PRINT) || (!(QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED)))) |
2883 | if ((aflags & AP_IGNORE_CURSE) || (aflags & AP_PRINT) || (!(QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED)))) |
2873 | { |
2884 | { |
2874 | if (aflags & AP_PRINT) |
2885 | if (aflags & AP_PRINT) |
2875 | new_draw_info (NDI_UNIQUE, 0, who, query_name (tmp)); |
2886 | new_draw_info (NDI_UNIQUE, 0, who, query_name (tmp)); |
… | |
… | |
2883 | * so it may not be critical (eg, putting on a ring and you have |
2894 | * so it may not be critical (eg, putting on a ring and you have |
2884 | * one cursed ring.) |
2895 | * one cursed ring.) |
2885 | */ |
2896 | */ |
2886 | new_draw_info_format (NDI_UNIQUE, 0, who, "The %s just won't come off", query_name (tmp)); |
2897 | new_draw_info_format (NDI_UNIQUE, 0, who, "The %s just won't come off", query_name (tmp)); |
2887 | } |
2898 | } |
|
|
2899 | |
2888 | last = tmp->below; |
2900 | last = tmp->below; |
2889 | } |
2901 | } |
2890 | /* if we got here, this slot is freed up - otherwise, if it wasn't freed up, the |
2902 | /* if we got here, this slot is freed up - otherwise, if it wasn't freed up, the |
2891 | * return in the !tmp would have kicked in. |
2903 | * return in the !tmp would have kicked in. |
2892 | */ |
2904 | */ |
2893 | } /* if op is using this body location */ |
2905 | } /* if op is using this body location */ |
2894 | } /* for body lcoations */ |
2906 | } /* for body lcoations */ |
|
|
2907 | |
2895 | return 0; |
2908 | return 0; |
2896 | } |
2909 | } |
2897 | |
2910 | |
2898 | /** |
2911 | /** |
2899 | * Checks to see if 'who' can apply object 'op'. |
2912 | * Checks to see if 'who' can apply object 'op'. |
2900 | * Returns 0 if apply can be done without anything special. |
2913 | * Returns 0 if apply can be done without anything special. |
2901 | * Otherwise returns a bitmask - potentially several of these may be |
2914 | * Otherwise returns a bitmask - potentially several of these may be |
2902 | * set, but largely depends on circumstance - in the future, processing |
2915 | * set, but largely depends on circumstance - in the future, processing |
2903 | * may be pruned once we know some status (eg, once CAN_APPLY_NEVER |
2916 | * may be pruned once we know some status (eg, once CAN_APPLY_NEVER |
2904 | * is set, do we really are what the other flags may be?) |
2917 | * is set, do we really care what the other flags may be?) |
2905 | * |
2918 | * |
2906 | * See include/define.h for detailed description of the meaning of |
2919 | * See include/define.h for detailed description of the meaning of |
2907 | * these return values. |
2920 | * these return values. |
2908 | */ |
2921 | */ |
2909 | int |
2922 | int |
2910 | can_apply_object (object *who, object *op) |
2923 | can_apply_object (object *who, object *op) |
2911 | { |
2924 | { |
2912 | if (INVOKE_OBJECT (CAN_BE_APPLIED, op, ARG_OBJECT (who)) || INVOKE_OBJECT (CAN_APPLY, who, ARG_OBJECT (op))) |
2925 | if (INVOKE_OBJECT (CAN_BE_APPLIED, op, ARG_OBJECT (who)) || INVOKE_OBJECT (CAN_APPLY, who, ARG_OBJECT (op))) |
2913 | return RESULT_INT (0); |
2926 | return RESULT_INT (0); |
2914 | |
2927 | |
2915 | int i, retval = 0; |
2928 | int retval = 0; |
2916 | object *tmp = NULL, *ws = NULL; |
2929 | object *tmp = 0, *ws = 0; |
2917 | |
2930 | |
2918 | /* Players have 2 'arm's, so they could in theory equip 2 shields or |
2931 | for (int i = 0; i < NUM_BODY_LOCATIONS; i++) |
2919 | * 2 weapons, but we don't want to let them do that. So if they are |
|
|
2920 | * trying to equip a weapon or shield, see if they already have one |
|
|
2921 | * in place and store that way. |
|
|
2922 | */ |
|
|
2923 | if (op->type == WEAPON || op->type == SHIELD) |
|
|
2924 | { |
2932 | { |
2925 | for (tmp = who->inv; tmp && !ws; tmp = tmp->below) |
2933 | if (op->slot[i].info) |
2926 | { |
2934 | { |
2927 | if (QUERY_FLAG (tmp, FLAG_APPLIED) && tmp->type == op->type) |
2935 | /* Item uses more slots than we have */ |
|
|
2936 | if (who->slot[i].info + op->slot [i].info < 0) |
2928 | { |
2937 | { |
2929 | retval = CAN_APPLY_UNAPPLY; |
|
|
2930 | ws = tmp; |
|
|
2931 | } |
|
|
2932 | } |
|
|
2933 | } |
|
|
2934 | |
|
|
2935 | |
|
|
2936 | for (i = 0; i < NUM_BODY_LOCATIONS; i++) |
|
|
2937 | { |
|
|
2938 | if (op->body_info[i]) |
|
|
2939 | { |
|
|
2940 | /* Item uses more slots than we have */ |
|
|
2941 | if (FABS (op->body_info[i]) > who->body_info[i]) |
|
|
2942 | { |
|
|
2943 | /* Could return now for efficiently - rest of info below isn' |
2938 | /* Could return now for efficiency - rest of info below isn't |
2944 | * really needed. |
2939 | * really needed. |
2945 | */ |
2940 | */ |
2946 | retval |= CAN_APPLY_NEVER; |
2941 | retval |= CAN_APPLY_NEVER; |
2947 | } |
2942 | } |
2948 | else if ((who->body_used[i] + op->body_info[i]) < 0) |
2943 | else if (who->slot[i].used + op->slot[i].info < 0) |
2949 | { |
2944 | { |
2950 | /* in this case, equipping this would use more free spots than |
2945 | /* in this case, equipping this would use more free spots than |
2951 | * we have. |
2946 | * we have. |
2952 | */ |
2947 | */ |
2953 | object *tmp1; |
|
|
2954 | |
|
|
2955 | |
2948 | |
2956 | /* if we have an applied weapon/shield, and unapply it would free |
2949 | /* if we have an applied weapon/shield, and unapply it would free |
2957 | * enough slots to equip the new item, then just set this can |
2950 | * enough slots to equip the new item, then just set "can |
2958 | * continue. We don't care about the logic below - if you have |
2951 | * apply unapply". We don't care about the logic below - if you have a |
2959 | * shield equipped and try to equip another shield, there is only |
2952 | * shield equipped and try to equip another shield, there is only |
2960 | * one choice. However, the check for the number of body locations |
2953 | * one choice. However, the check for the number of body locations |
2961 | * does take into the account cases where what is being applied |
2954 | * does take into the account cases where what is being applied |
2962 | * may be two handed for example. |
2955 | * may be two handed for example. |
2963 | */ |
2956 | */ |
2964 | if (ws) |
2957 | if (ws) |
2965 | { |
2958 | if ((who->slot[i].used - ws->slot[i].info + op->slot[i].info) >= 0) |
2966 | if ((who->body_used[i] - ws->body_info[i] + op->body_info[i]) >= 0) |
|
|
2967 | { |
2959 | { |
2968 | retval |= CAN_APPLY_UNAPPLY; |
2960 | retval |= CAN_APPLY_UNAPPLY; |
2969 | continue; |
2961 | continue; |
2970 | } |
2962 | } |
2971 | } |
|
|
2972 | |
2963 | |
2973 | tmp1 = get_item_from_body_location (who->inv, i); |
2964 | object *tmp1 = get_next_item_from_body_location (i, who->inv); |
2974 | if (!tmp1) |
2965 | if (!tmp1) |
2975 | { |
2966 | { |
2976 | #if 0 |
2967 | #if 0 |
2977 | /* This is sort of an error, but happens a lot when old players |
2968 | /* This is sort of an error, but happens a lot when old players |
2978 | * join in with more stuff equipped than they are now allowed. |
2969 | * join in with more stuff equipped than they are now allowed. |
2979 | */ |
2970 | */ |
2980 | LOG (llevError, "Can't find object using location %d on %s\n", i, who->name); |
2971 | LOG (llevError, "Can't find object using location %d on %s\n", i, who->name); |
2981 | #endif |
2972 | #endif |
|
|
2973 | fprintf (stderr, "can apply never due to %d but %d - %d + %d\n",//D |
|
|
2974 | i, who->slot[i].used,ws ? ws->slot[i].info :-77,op->slot[i].info);//D |
2982 | retval |= CAN_APPLY_NEVER; |
2975 | retval |= CAN_APPLY_NEVER; |
2983 | } |
2976 | } |
2984 | else |
2977 | else |
2985 | { |
2978 | { |
2986 | /* need to unapply something. However, if this something |
2979 | /* need to unapply something. However, if this something |
2987 | * is different than we had found before, it means they need |
2980 | * is different than we had found before, it means they need |
2988 | * to apply multiple objects |
2981 | * to apply multiple objects |
2989 | */ |
2982 | */ |
2990 | retval |= CAN_APPLY_UNAPPLY; |
2983 | retval |= CAN_APPLY_UNAPPLY; |
|
|
2984 | |
2991 | if (!tmp) |
2985 | if (!tmp) |
2992 | tmp = tmp1; |
2986 | tmp = tmp1; |
2993 | else if (tmp != tmp1) |
2987 | else if (tmp != tmp1) |
2994 | { |
|
|
2995 | retval |= CAN_APPLY_UNAPPLY_MULT; |
2988 | retval |= CAN_APPLY_UNAPPLY_MULT; |
2996 | } |
2989 | |
2997 | /* This object isn't using up all the slots, so there must |
2990 | /* This object isn't using up all the slots, so there must |
2998 | * be another. If so, and it the new item doesn't need all |
2991 | * be another. If so, and it the new item doesn't need all |
2999 | * the slots, the player then has a choice. |
2992 | * the slots, the player then has a choice. |
3000 | */ |
2993 | */ |
3001 | if (((who->body_used[i] - tmp1->body_info[i]) != who->body_info[i]) && (FABS (op->body_info[i]) < who->body_info[i])) |
2994 | if ((who->slot[i].used - tmp1->slot[i].info != who->slot[i].info) |
|
|
2995 | && abs (op->slot[i].info) < who->slot[i].info) |
3002 | retval |= CAN_APPLY_UNAPPLY_CHOICE; |
2996 | retval |= CAN_APPLY_UNAPPLY_CHOICE; |
3003 | |
2997 | |
3004 | /* Does unequippint 'tmp1' free up enough slots for this to be |
2998 | /* Does unequippint 'tmp1' free up enough slots for this to be |
3005 | * equipped? If not, there must be something else to unapply. |
2999 | * equipped? If not, there must be something else to unapply. |
3006 | */ |
3000 | */ |
3007 | if ((who->body_used[i] + op->body_info[i] - tmp1->body_info[i]) < 0) |
3001 | if (who->slot[i].used + op->slot[i].info < tmp1->slot[i].info) |
3008 | retval |= CAN_APPLY_UNAPPLY_MULT; |
3002 | retval |= CAN_APPLY_UNAPPLY_MULT; |
3009 | |
|
|
3010 | } |
3003 | } |
3011 | } /* if not enough free slots */ |
3004 | } /* if not enough free slots */ |
3012 | } /* if this object uses location i */ |
3005 | } /* if this object uses location i */ |
3013 | } /* for i -> num_body_locations loop */ |
3006 | } /* for i -> num_body_locations loop */ |
3014 | |
3007 | |
… | |
… | |
3019 | * and weapons all use the same slot. Similar for horn/rod/wand - they |
3012 | * and weapons all use the same slot. Similar for horn/rod/wand - they |
3020 | * all use the same location. |
3013 | * all use the same location. |
3021 | */ |
3014 | */ |
3022 | if (op->type == WEAPON && !QUERY_FLAG (who, FLAG_USE_WEAPON)) |
3015 | if (op->type == WEAPON && !QUERY_FLAG (who, FLAG_USE_WEAPON)) |
3023 | retval |= CAN_APPLY_RESTRICTION; |
3016 | retval |= CAN_APPLY_RESTRICTION; |
|
|
3017 | |
3024 | if (op->type == SHIELD && !QUERY_FLAG (who, FLAG_USE_SHIELD)) |
3018 | if (op->type == SHIELD && !QUERY_FLAG (who, FLAG_USE_SHIELD)) |
3025 | retval |= CAN_APPLY_RESTRICTION; |
3019 | retval |= CAN_APPLY_RESTRICTION; |
3026 | |
3020 | |
3027 | |
|
|
3028 | if (who->type != PLAYER) |
3021 | if (who->type != PLAYER) |
3029 | { |
3022 | { |
3030 | if ((op->type == WAND || op->type == HORN || op->type == ROD) && !QUERY_FLAG (who, FLAG_USE_RANGE)) |
3023 | if ((op->type == WAND || op->type == HORN || op->type == ROD) && !QUERY_FLAG (who, FLAG_USE_RANGE)) |
3031 | retval |= CAN_APPLY_RESTRICTION; |
3024 | retval |= CAN_APPLY_RESTRICTION; |
|
|
3025 | |
3032 | if (op->type == BOW && !QUERY_FLAG (who, FLAG_USE_BOW)) |
3026 | if (op->type == BOW && !QUERY_FLAG (who, FLAG_USE_BOW)) |
3033 | retval |= CAN_APPLY_RESTRICTION; |
3027 | retval |= CAN_APPLY_RESTRICTION; |
|
|
3028 | |
3034 | if (op->type == RING && !QUERY_FLAG (who, FLAG_USE_RING)) |
3029 | if (op->type == RING && !QUERY_FLAG (who, FLAG_USE_RING)) |
3035 | retval |= CAN_APPLY_RESTRICTION; |
3030 | retval |= CAN_APPLY_RESTRICTION; |
|
|
3031 | |
3036 | if (op->type == BOW && !QUERY_FLAG (who, FLAG_USE_BOW)) |
3032 | if (op->type == BOW && !QUERY_FLAG (who, FLAG_USE_BOW)) |
3037 | retval |= CAN_APPLY_RESTRICTION; |
3033 | retval |= CAN_APPLY_RESTRICTION; |
3038 | } |
3034 | } |
|
|
3035 | |
3039 | return retval; |
3036 | return retval; |
3040 | } |
3037 | } |
3041 | |
|
|
3042 | |
|
|
3043 | |
3038 | |
3044 | /** |
3039 | /** |
3045 | * who is the object using the object. It can be a monster. |
3040 | * who is the object using the object. It can be a monster. |
3046 | * op is the object they are using. op is an equipment type item, |
3041 | * op is the object they are using. op is an equipment type item, |
3047 | * eg, one which you put on and keep on for a while, and not something |
3042 | * eg, one which you put on and keep on for a while, and not something |
… | |
… | |
3066 | int |
3061 | int |
3067 | apply_special (object *who, object *op, int aflags) |
3062 | apply_special (object *who, object *op, int aflags) |
3068 | { |
3063 | { |
3069 | int basic_flag = aflags & AP_BASIC_FLAGS; |
3064 | int basic_flag = aflags & AP_BASIC_FLAGS; |
3070 | object *tmp, *tmp2, *skop = NULL; |
3065 | object *tmp, *tmp2, *skop = NULL; |
3071 | int i; |
|
|
3072 | |
3066 | |
3073 | if (who == NULL) |
3067 | if (who == NULL) |
3074 | { |
3068 | { |
3075 | LOG (llevError, "apply_special() from object without environment.\n"); |
3069 | LOG (llevError, "apply_special() from object without environment.\n"); |
3076 | return 1; |
3070 | return 1; |
… | |
… | |
3086 | if (basic_flag == AP_APPLY) |
3080 | if (basic_flag == AP_APPLY) |
3087 | return 0; |
3081 | return 0; |
3088 | |
3082 | |
3089 | if (!(aflags & AP_IGNORE_CURSE) && (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED))) |
3083 | if (!(aflags & AP_IGNORE_CURSE) && (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED))) |
3090 | { |
3084 | { |
3091 | new_draw_info_format (NDI_UNIQUE, 0, who, "No matter how hard you try, you just can't\nremove %s.", query_name (op)); |
3085 | new_draw_info_format (NDI_UNIQUE, 0, who, "No matter how hard you try, you just can't remove %s.", query_name (op)); |
3092 | return 1; |
3086 | return 1; |
3093 | } |
3087 | } |
|
|
3088 | |
3094 | return unapply_special (who, op, aflags); |
3089 | return unapply_special (who, op, aflags); |
3095 | } |
3090 | } |
3096 | |
3091 | |
3097 | if (basic_flag == AP_UNAPPLY) |
3092 | if (basic_flag == AP_UNAPPLY) |
3098 | return 0; |
3093 | return 0; |
3099 | |
3094 | |
3100 | i = can_apply_object (who, op); |
3095 | // if the item is combat/ranged, wield the relevant slot first |
|
|
3096 | // to resolve conflicts. |
|
|
3097 | if (player *pl = who->contr) |
|
|
3098 | switch (op->slottype ()) |
|
|
3099 | { |
|
|
3100 | case slot_combat: who->change_weapon (pl->combat_ob); break; |
|
|
3101 | case slot_ranged: who->change_weapon (pl->ranged_ob); break; |
|
|
3102 | } |
3101 | |
3103 | |
3102 | /* Can't just apply this object. Lets see what not and what to do */ |
3104 | /* Can't just apply this object. Lets see what not and what to do */ |
3103 | if (i) |
3105 | if (int i = can_apply_object (who, op)) |
3104 | { |
3106 | { |
3105 | if (i & CAN_APPLY_NEVER) |
3107 | if (i & CAN_APPLY_NEVER) |
3106 | { |
3108 | { |
3107 | new_draw_info_format (NDI_UNIQUE, 0, who, "You don't have the body to use a %s\n", query_name (op)); |
3109 | new_draw_info_format (NDI_UNIQUE, 0, who, "You don't have the body to use a %s\n", query_name (op)); |
3108 | return 1; |
3110 | return 1; |
… | |
… | |
3110 | else if (i & CAN_APPLY_RESTRICTION) |
3112 | else if (i & CAN_APPLY_RESTRICTION) |
3111 | { |
3113 | { |
3112 | new_draw_info_format (NDI_UNIQUE, 0, who, "You have a prohibition against using a %s\n", query_name (op)); |
3114 | new_draw_info_format (NDI_UNIQUE, 0, who, "You have a prohibition against using a %s\n", query_name (op)); |
3113 | return 1; |
3115 | return 1; |
3114 | } |
3116 | } |
|
|
3117 | |
3115 | if (who->type != PLAYER) |
3118 | if (who->type != PLAYER) |
3116 | { |
3119 | { |
3117 | /* Some error, so don't try to equip something more */ |
3120 | /* Some error, so don't try to equip something more */ |
3118 | if (unapply_for_ob (who, op, aflags)) |
3121 | if (unapply_for_ob (who, op, aflags)) |
3119 | return 1; |
3122 | return 1; |
… | |
… | |
3125 | new_draw_info (NDI_UNIQUE, 0, who, "You need to unapply some of the following item(s) or change your applymode:"); |
3128 | new_draw_info (NDI_UNIQUE, 0, who, "You need to unapply some of the following item(s) or change your applymode:"); |
3126 | unapply_for_ob (who, op, AP_PRINT); |
3129 | unapply_for_ob (who, op, AP_PRINT); |
3127 | return 1; |
3130 | return 1; |
3128 | } |
3131 | } |
3129 | else if (who->contr->unapply == unapply_always || !(i & CAN_APPLY_UNAPPLY_CHOICE)) |
3132 | else if (who->contr->unapply == unapply_always || !(i & CAN_APPLY_UNAPPLY_CHOICE)) |
3130 | { |
|
|
3131 | i = unapply_for_ob (who, op, aflags); |
3133 | if (unapply_for_ob (who, op, aflags)) |
3132 | if (i) |
|
|
3133 | return 1; |
3134 | return 1; |
3134 | } |
|
|
3135 | } |
3135 | } |
3136 | } |
3136 | } |
3137 | |
3137 | |
3138 | if (op->skill && op->type != SKILL && op->type != SKILL_TOOL) |
3138 | if (op->skill && op->type != SKILL && op->type != SKILL_TOOL) |
3139 | { |
3139 | { |
3140 | skop = find_skill_by_name (who, op->skill); |
3140 | skop = find_skill_by_name (who, op->skill); |
|
|
3141 | |
3141 | if (!skop) |
3142 | if (!skop) |
3142 | { |
3143 | { |
3143 | new_draw_info_format (NDI_UNIQUE, 0, who, "You need the %s skill to use this item!", &op->skill); |
3144 | new_draw_info_format (NDI_UNIQUE, 0, who, "You need the %s skill to use this item!", &op->skill); |
3144 | return 1; |
3145 | return 1; |
3145 | } |
3146 | } |
3146 | else |
3147 | else |
3147 | { |
|
|
3148 | /* While experience will be credited properly, we want to change the |
3148 | /* While experience will be credited properly, we want to change the |
3149 | * skill so that the dam and wc get updated |
3149 | * skill so that the dam and wc get updated |
3150 | */ |
3150 | */ |
3151 | change_skill (who, skop, 0); |
3151 | change_skill (who, skop, 0); |
3152 | } |
|
|
3153 | } |
|
|
3154 | |
|
|
3155 | if (who->type == PLAYER && op->item_power && (op->item_power + who->contr->item_power) > (settings.item_power_factor * who->level)) |
|
|
3156 | { |
3152 | } |
3157 | new_draw_info (NDI_UNIQUE, 0, who, "Equipping that combined with other items would consume your soul!"); |
3153 | |
|
|
3154 | if (who->type == PLAYER |
|
|
3155 | && op->item_power |
|
|
3156 | && op->item_power + who->contr->item_power > settings.item_power_factor * who->level) |
|
|
3157 | { |
|
|
3158 | new_draw_info (NDI_UNIQUE, 0, who, |
|
|
3159 | "Equipping that combined with other items would consume your soul! " |
|
|
3160 | "[use the skills command to check your available item power]"); |
3158 | return 1; |
3161 | return 1; |
3159 | } |
3162 | } |
3160 | |
|
|
3161 | |
3163 | |
3162 | /* Ok. We are now at the state where we can apply the new object. |
3164 | /* Ok. We are now at the state where we can apply the new object. |
3163 | * Note that we don't have the checks for can_use_... |
3165 | * Note that we don't have the checks for can_use_... |
3164 | * below - that is already taken care of by can_apply_object. |
3166 | * below - that is already taken care of by can_apply_object. |
3165 | */ |
3167 | */ |
3166 | |
|
|
3167 | |
|
|
3168 | if (op->nrof > 1) |
3168 | if (op->nrof > 1) |
3169 | tmp = get_split_ob (op, op->nrof - 1); |
3169 | tmp = get_split_ob (op, op->nrof - 1); |
3170 | else |
3170 | else |
3171 | tmp = NULL; |
3171 | tmp = 0; |
3172 | |
3172 | |
3173 | if (INVOKE_OBJECT (BE_READY, op, ARG_OBJECT (who)) || INVOKE_OBJECT (READY, who, ARG_OBJECT (op))) |
3173 | if (INVOKE_OBJECT (BE_READY, op, ARG_OBJECT (who)) || INVOKE_OBJECT (READY, who, ARG_OBJECT (op))) |
3174 | return RESULT_INT (0); |
3174 | return RESULT_INT (0); |
3175 | |
3175 | |
3176 | switch (op->type) |
3176 | switch (op->type) |
3177 | { |
3177 | { |
3178 | case WEAPON: |
3178 | case WEAPON: |
3179 | if (!check_weapon_power (who, op->last_eat)) |
3179 | if (!check_weapon_power (who, op->last_eat)) |
3180 | { |
3180 | { |
3181 | new_draw_info (NDI_UNIQUE, 0, who, "That weapon is too powerful for you to use."); |
3181 | new_draw_info (NDI_UNIQUE, 0, who, "This weapon is too powerful for you to use.\n" |
3182 | new_draw_info (NDI_UNIQUE, 0, who, "It would consume your soul!."); |
3182 | "It would consume your soul!."); |
|
|
3183 | |
3183 | if (tmp != NULL) |
3184 | if (tmp) |
3184 | (void) insert_ob_in_ob (tmp, who); |
3185 | insert_ob_in_ob (tmp, who); |
|
|
3186 | |
3185 | return 1; |
3187 | return 1; |
3186 | } |
3188 | } |
3187 | |
3189 | |
3188 | //TODO: this obviously fails for players using a shiorter prefix |
3190 | //TODO: this obviously fails for players using a shorter prefix |
3189 | // i.e. "R" can use Ragnarok's swors. |
3191 | // i.e. "R" can use Ragnarok's sword. |
3190 | if (op->level && (strncmp (op->name, who->name, strlen (who->name)))) |
3192 | if (op->level && (strncmp (op->name, who->name, strlen (who->name)))) |
3191 | { |
3193 | { |
3192 | /* if the weapon does not have the name as the character, can't use it. */ |
3194 | /* if the weapon does not have the name as the character, can't use it. */ |
3193 | /* (Ragnarok's sword attempted to be used by Foo: won't work) */ |
3195 | /* (Ragnarok's sword attempted to be used by Foo: won't work) */ |
3194 | new_draw_info (NDI_UNIQUE, 0, who, "The weapon does not recognize you as its owner."); |
3196 | new_draw_info (NDI_UNIQUE, 0, who, "The weapon does not recognize you as its owner."); |
… | |
… | |
3197 | insert_ob_in_ob (tmp, who); |
3199 | insert_ob_in_ob (tmp, who); |
3198 | |
3200 | |
3199 | return 1; |
3201 | return 1; |
3200 | } |
3202 | } |
3201 | |
3203 | |
|
|
3204 | if (!skop) |
|
|
3205 | { |
|
|
3206 | new_draw_info_format (NDI_UNIQUE, 0, who, "The %s is broken, please report this to the dungeon master!", query_name (op));//TODO |
|
|
3207 | return 1; |
|
|
3208 | } |
|
|
3209 | |
3202 | SET_FLAG (op, FLAG_APPLIED); |
3210 | SET_FLAG (op, FLAG_APPLIED); |
3203 | |
|
|
3204 | if (skop) |
|
|
3205 | change_skill (who, skop, 1); |
3211 | change_skill (who, skop, 1); |
|
|
3212 | |
|
|
3213 | if (who->contr) |
|
|
3214 | who->change_weapon (who->contr->combat_ob = op); |
|
|
3215 | |
3206 | if (!QUERY_FLAG (who, FLAG_READY_WEAPON)) |
3216 | if (!QUERY_FLAG (who, FLAG_READY_WEAPON)) |
3207 | SET_FLAG (who, FLAG_READY_WEAPON); |
3217 | SET_FLAG (who, FLAG_READY_WEAPON); |
3208 | |
3218 | |
3209 | new_draw_info_format (NDI_UNIQUE, 0, who, "You wield %s.", query_name (op)); |
3219 | new_draw_info_format (NDI_UNIQUE, 0, who, "You wield %s.", query_name (op)); |
3210 | |
3220 | |
3211 | (void) change_abil (who, op); |
3221 | change_abil (who, op); |
3212 | break; |
3222 | break; |
3213 | |
3223 | |
3214 | case ARMOUR: |
3224 | case ARMOUR: |
3215 | case HELMET: |
3225 | case HELMET: |
3216 | case SHIELD: |
3226 | case SHIELD: |
… | |
… | |
3221 | case CLOAK: |
3231 | case CLOAK: |
3222 | case RING: |
3232 | case RING: |
3223 | case AMULET: |
3233 | case AMULET: |
3224 | SET_FLAG (op, FLAG_APPLIED); |
3234 | SET_FLAG (op, FLAG_APPLIED); |
3225 | new_draw_info_format (NDI_UNIQUE, 0, who, "You wear %s.", query_name (op)); |
3235 | new_draw_info_format (NDI_UNIQUE, 0, who, "You wear %s.", query_name (op)); |
3226 | (void) change_abil (who, op); |
3236 | change_abil (who, op); |
3227 | break; |
3237 | break; |
|
|
3238 | |
3228 | case LAMP: |
3239 | case LAMP: |
3229 | if (op->stats.food < 1) |
3240 | if (op->stats.food < 1) |
3230 | { |
3241 | { |
3231 | new_draw_info_format (NDI_UNIQUE, 0, who, "Your %s is out of" " fuel!", &op->name); |
3242 | new_draw_info_format (NDI_UNIQUE, 0, who, "Your %s is out of fuel!", &op->name); |
3232 | return 1; |
3243 | return 1; |
3233 | } |
3244 | } |
|
|
3245 | |
3234 | new_draw_info_format (NDI_UNIQUE, 0, who, "You turn on your %s.", &op->name); |
3246 | new_draw_info_format (NDI_UNIQUE, 0, who, "You turn on your %s.", &op->name); |
3235 | tmp2 = arch_to_object (op->other_arch); |
3247 | tmp2 = arch_to_object (op->other_arch); |
3236 | tmp2->stats.food = op->stats.food; |
3248 | tmp2->stats.food = op->stats.food; |
3237 | SET_FLAG (tmp2, FLAG_APPLIED); |
3249 | SET_FLAG (tmp2, FLAG_APPLIED); |
|
|
3250 | |
3238 | if (QUERY_FLAG (op, FLAG_INV_LOCKED)) |
3251 | if (QUERY_FLAG (op, FLAG_INV_LOCKED)) |
3239 | SET_FLAG (tmp2, FLAG_INV_LOCKED); |
3252 | SET_FLAG (tmp2, FLAG_INV_LOCKED); |
|
|
3253 | |
3240 | insert_ob_in_ob (tmp2, who); |
3254 | insert_ob_in_ob (tmp2, who); |
3241 | |
3255 | |
3242 | /* Remove the old lantern */ |
3256 | /* Remove the old lantern */ |
3243 | if (who->type == PLAYER) |
3257 | if (who->type == PLAYER) |
3244 | esrv_del_item (who->contr, op->count); |
3258 | esrv_del_item (who->contr, op->count); |
3245 | |
3259 | |
3246 | op->destroy (); |
3260 | op->destroy (); |
3247 | |
3261 | |
3248 | /* insert the portion that was split off */ |
3262 | /* insert the portion that was split off */ |
3249 | if (tmp != NULL) |
3263 | if (tmp) |
3250 | { |
3264 | { |
3251 | (void) insert_ob_in_ob (tmp, who); |
3265 | insert_ob_in_ob (tmp, who); |
3252 | if (who->type == PLAYER) |
3266 | if (who->type == PLAYER) |
3253 | esrv_send_item (who, tmp); |
3267 | esrv_send_item (who, tmp); |
3254 | } |
3268 | } |
|
|
3269 | |
3255 | who->update_stats (); |
3270 | who->update_stats (); |
|
|
3271 | |
3256 | if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED)) |
3272 | if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED)) |
3257 | { |
|
|
3258 | if (who->type == PLAYER) |
3273 | if (who->type == PLAYER) |
3259 | { |
3274 | { |
3260 | new_draw_info (NDI_UNIQUE, 0, who, "Oops, it feels deadly cold!"); |
3275 | new_draw_info (NDI_UNIQUE, 0, who, "Oops, it feels deadly cold!"); |
3261 | SET_FLAG (tmp2, FLAG_KNOWN_CURSED); |
3276 | SET_FLAG (tmp2, FLAG_KNOWN_CURSED); |
3262 | } |
3277 | } |
3263 | } |
3278 | |
3264 | if (who->type == PLAYER) |
3279 | if (who->type == PLAYER) |
3265 | esrv_send_item (who, tmp2); |
3280 | esrv_send_item (who, tmp2); |
|
|
3281 | |
3266 | return 0; |
3282 | return 0; |
|
|
3283 | |
|
|
3284 | case SKILL_TOOL: |
|
|
3285 | // applying a skill tool also readies the skill |
|
|
3286 | SET_FLAG (op, FLAG_APPLIED); |
|
|
3287 | skop = find_skill_by_name (who, op->skill); |
|
|
3288 | if (!skop->flag [FLAG_APPLIED]) |
|
|
3289 | apply_special (who, skop, AP_APPLY); |
3267 | break; |
3290 | break; |
3268 | |
3291 | |
3269 | /* this part is needed for skill-tools */ |
|
|
3270 | case SKILL: |
3292 | case SKILL: |
3271 | case SKILL_TOOL: |
|
|
3272 | if (who->chosen_skill) |
3293 | if (who->chosen_skill) |
3273 | { |
3294 | { |
3274 | LOG (llevError, "BUG: apply_special(): can't apply two skills\n"); |
3295 | LOG (llevError, "BUG: apply_special(): can't apply two skills\n"); |
3275 | return 1; |
3296 | return 1; |
3276 | } |
3297 | } |
3277 | if (who->type == PLAYER) |
3298 | |
|
|
3299 | if (player *pl = who->contr) |
|
|
3300 | { |
|
|
3301 | if (IS_COMBAT_SKILL (op->subtype)) |
3278 | { |
3302 | { |
3279 | who->contr->shoottype = range_skill; |
3303 | if (skill_flags [op->subtype] & SF_NEED_WEAPON) |
3280 | who->contr->ranges[range_skill] = op; |
3304 | { |
|
|
3305 | for (object *item = who->inv; item; item = item->below) |
|
|
3306 | if (item->type == WEAPON && item->flag [FLAG_APPLIED]) |
|
|
3307 | { |
|
|
3308 | who->change_weapon (pl->combat_ob = item); |
|
|
3309 | goto found_weapon; |
|
|
3310 | } |
|
|
3311 | |
|
|
3312 | new_draw_info (NDI_UNIQUE, 0, who, "You need to apply a melee weapon before readying this skill"); |
|
|
3313 | return 1; |
|
|
3314 | |
|
|
3315 | found_weapon:; |
|
|
3316 | } |
|
|
3317 | else |
|
|
3318 | who->change_weapon (pl->combat_ob = op); |
|
|
3319 | } |
|
|
3320 | else if (IS_RANGED_SKILL (op->subtype)) |
|
|
3321 | { |
|
|
3322 | if (skill_flags [op->subtype] & SF_NEED_BOW) |
|
|
3323 | { |
|
|
3324 | for (object *item = who->inv; item; item = item->below) |
|
|
3325 | if (item->type == BOW && item->flag [FLAG_APPLIED]) |
|
|
3326 | { |
|
|
3327 | who->change_weapon (pl->ranged_ob = item); |
|
|
3328 | goto found_bow; |
|
|
3329 | } |
|
|
3330 | |
|
|
3331 | new_draw_info (NDI_UNIQUE, 0, who, "You need to apply a missile weapon before readying this skill"); |
|
|
3332 | return 1; |
|
|
3333 | |
|
|
3334 | found_bow:; |
|
|
3335 | } |
|
|
3336 | else if (skill_flags [op->subtype] & SF_NEED_ITEM) |
|
|
3337 | { |
|
|
3338 | for (object *item = who->inv; item; item = item->below) |
|
|
3339 | if (item->flag [FLAG_APPLIED] |
|
|
3340 | && (item->type == WAND || item->type == ROD || item->type == HORN)) |
|
|
3341 | { |
|
|
3342 | who->change_weapon (pl->ranged_ob = item); |
|
|
3343 | goto found_item; |
|
|
3344 | } |
|
|
3345 | |
|
|
3346 | new_draw_info (NDI_UNIQUE, 0, who, "You need to apply a magic item before readying this skill"); |
|
|
3347 | return 1; |
|
|
3348 | |
|
|
3349 | found_item:; |
|
|
3350 | } |
|
|
3351 | else |
|
|
3352 | who->change_weapon (pl->ranged_ob = op); |
|
|
3353 | } |
|
|
3354 | |
3281 | if (!op->invisible) |
3355 | if (!op->invisible) |
3282 | { |
3356 | { |
3283 | new_draw_info_format (NDI_UNIQUE, 0, who, "You ready %s.", query_name (op)); |
3357 | new_draw_info_format (NDI_UNIQUE, 0, who, "You ready %s.", query_name (op)); |
3284 | new_draw_info_format (NDI_UNIQUE, 0, who, "You can now use the skill: %s.", &op->skill); |
3358 | new_draw_info_format (NDI_UNIQUE, 0, who, "You can now use the skill: %s.", &op->skill); |
3285 | } |
3359 | } |
3286 | else |
3360 | else |
3287 | { |
|
|
3288 | new_draw_info_format (NDI_UNIQUE, 0, who, "Readied skill: %s.", op->skill ? &op->skill : &op->name); |
3361 | new_draw_info_format (NDI_UNIQUE, 0, who, "Readied skill: %s.", op->skill ? &op->skill : &op->name); |
3289 | } |
3362 | } |
3290 | } |
3363 | |
3291 | SET_FLAG (op, FLAG_APPLIED); |
3364 | SET_FLAG (op, FLAG_APPLIED); |
3292 | (void) change_abil (who, op); |
3365 | change_abil (who, op); |
3293 | who->chosen_skill = op; |
3366 | who->chosen_skill = op; |
3294 | SET_FLAG (who, FLAG_READY_SKILL); |
3367 | SET_FLAG (who, FLAG_READY_SKILL); |
3295 | break; |
3368 | break; |
3296 | |
3369 | |
3297 | case BOW: |
3370 | case BOW: |
3298 | if (!check_weapon_power (who, op->last_eat)) |
3371 | if (!check_weapon_power (who, op->last_eat)) |
3299 | { |
3372 | { |
3300 | new_draw_info (NDI_UNIQUE, 0, who, "That item is too powerful for you to use."); |
3373 | new_draw_info (NDI_UNIQUE, 0, who, "That weapon is too powerful for you to use."); |
3301 | new_draw_info (NDI_UNIQUE, 0, who, "It would consume your soul!."); |
3374 | new_draw_info (NDI_UNIQUE, 0, who, "It would consume your soul!."); |
|
|
3375 | |
3302 | if (tmp != NULL) |
3376 | if (tmp) |
3303 | (void) insert_ob_in_ob (tmp, who); |
3377 | insert_ob_in_ob (tmp, who); |
|
|
3378 | |
3304 | return 1; |
3379 | return 1; |
3305 | } |
3380 | } |
|
|
3381 | |
3306 | if (op->level && (strncmp (op->name, who->name, strlen (who->name)))) |
3382 | if (op->level && (strncmp (op->name, who->name, strlen (who->name)))) |
3307 | { |
3383 | { |
3308 | new_draw_info (NDI_UNIQUE, 0, who, "The weapon does not recognize you as its owner."); |
3384 | new_draw_info (NDI_UNIQUE, 0, who, "The weapon does not recognize you as its owner."); |
3309 | if (tmp != NULL) |
3385 | if (tmp) |
3310 | (void) insert_ob_in_ob (tmp, who); |
3386 | insert_ob_in_ob (tmp, who); |
|
|
3387 | |
3311 | return 1; |
3388 | return 1; |
3312 | } |
3389 | } |
|
|
3390 | |
3313 | /*FALLTHROUGH*/ case WAND: |
3391 | /*FALLTHROUGH*/ |
|
|
3392 | case WAND: |
3314 | case ROD: |
3393 | case ROD: |
3315 | case HORN: |
3394 | case HORN: |
3316 | /* check for skill, alter player status */ |
3395 | /* check for skill, alter player status */ |
|
|
3396 | |
|
|
3397 | if (!skop) |
|
|
3398 | { |
|
|
3399 | new_draw_info_format (NDI_UNIQUE, 0, who, "The %s is broken, please report this to the dungeon master!", query_name (op));//TODO |
|
|
3400 | return 1; |
|
|
3401 | } |
|
|
3402 | |
3317 | SET_FLAG (op, FLAG_APPLIED); |
3403 | SET_FLAG (op, FLAG_APPLIED); |
3318 | if (skop) |
|
|
3319 | change_skill (who, skop, 0); |
3404 | change_skill (who, skop, 0); |
|
|
3405 | |
|
|
3406 | if (who->contr) |
|
|
3407 | { |
|
|
3408 | who->contr->ranged_ob = op; |
|
|
3409 | |
3320 | new_draw_info_format (NDI_UNIQUE, 0, who, "You ready %s.", query_name (op)); |
3410 | new_draw_info_format (NDI_UNIQUE, 0, who, "You ready %s.", query_name (op)); |
3321 | |
3411 | |
3322 | if (who->type == PLAYER) |
|
|
3323 | { |
|
|
3324 | if (op->type == BOW) |
3412 | if (op->type == BOW) |
3325 | { |
3413 | { |
|
|
3414 | who->current_weapon = op; |
3326 | (void) change_abil (who, op); |
3415 | change_abil (who, op); |
3327 | new_draw_info_format (NDI_UNIQUE, 0, who, |
3416 | new_draw_info_format (NDI_UNIQUE, 0, who, |
3328 | "You will now fire %s with %s.", op->race ? &op->race : "nothing", query_name (op)); |
3417 | "You will now fire %s with %s.", op->race ? &op->race : "nothing", query_name (op)); |
3329 | who->contr->shoottype = range_bow; |
|
|
3330 | } |
|
|
3331 | else |
|
|
3332 | { |
|
|
3333 | who->contr->shoottype = range_misc; |
|
|
3334 | } |
3418 | } |
3335 | } |
3419 | } |
3336 | else |
3420 | else |
3337 | { |
3421 | { |
3338 | if (op->type == BOW) |
3422 | if (op->type == BOW) |
3339 | SET_FLAG (who, FLAG_READY_BOW); |
3423 | SET_FLAG (who, FLAG_READY_BOW); |
3340 | else |
3424 | else |
3341 | SET_FLAG (who, FLAG_READY_RANGE); |
3425 | SET_FLAG (who, FLAG_READY_RANGE); |
3342 | } |
3426 | } |
|
|
3427 | |
3343 | break; |
3428 | break; |
3344 | |
3429 | |
3345 | case BUILDER: |
3430 | case BUILDER: |
3346 | if (who->contr->ranges[range_builder]) |
3431 | if (who->type == PLAYER) |
|
|
3432 | { |
|
|
3433 | if (who->contr->ranged_ob && who->contr->ranged_ob->type == BUILDER) |
3347 | unapply_special (who, who->contr->ranges[range_builder], 0); |
3434 | unapply_special (who, who->contr->ranged_ob, 0); |
3348 | who->contr->shoottype = range_builder; |
3435 | |
3349 | who->contr->ranges[range_builder] = op; |
|
|
3350 | new_draw_info_format (NDI_UNIQUE, 0, who, "You ready your %s.", query_name (op)); |
3436 | new_draw_info_format (NDI_UNIQUE, 0, who, "You ready your %s.", query_name (op)); |
|
|
3437 | |
|
|
3438 | who->contr->ranged_ob = op; |
|
|
3439 | } |
3351 | break; |
3440 | break; |
3352 | |
3441 | |
3353 | default: |
3442 | default: |
3354 | new_draw_info_format (NDI_UNIQUE, 0, who, "You apply %s.", query_name (op)); |
3443 | new_draw_info_format (NDI_UNIQUE, 0, who, "You apply %s.", query_name (op)); |
3355 | } /* end of switch op->type */ |
3444 | } /* end of switch op->type */ |
3356 | |
3445 | |
3357 | SET_FLAG (op, FLAG_APPLIED); |
3446 | SET_FLAG (op, FLAG_APPLIED); |
3358 | |
3447 | |
3359 | if (tmp != NULL) |
3448 | if (tmp) |
3360 | tmp = insert_ob_in_ob (tmp, who); |
3449 | tmp = insert_ob_in_ob (tmp, who); |
3361 | |
3450 | |
3362 | who->update_stats (); |
3451 | who->update_stats (); |
3363 | |
3452 | |
3364 | /* We exclude spell casting objects. The fire code will set the |
3453 | /* We exclude spell casting objects. The fire code will set the |
… | |
… | |
3374 | { |
3463 | { |
3375 | new_draw_info (NDI_UNIQUE, 0, who, "Oops, it feels deadly cold!"); |
3464 | new_draw_info (NDI_UNIQUE, 0, who, "Oops, it feels deadly cold!"); |
3376 | SET_FLAG (op, FLAG_KNOWN_CURSED); |
3465 | SET_FLAG (op, FLAG_KNOWN_CURSED); |
3377 | } |
3466 | } |
3378 | } |
3467 | } |
|
|
3468 | |
3379 | if (who->type == PLAYER) |
3469 | if (who->type == PLAYER) |
3380 | { |
3470 | { |
3381 | /* if multiple objects were applied, update both slots */ |
3471 | /* if multiple objects were applied, update both slots */ |
3382 | if (tmp) |
3472 | if (tmp) |
3383 | esrv_send_item (who, tmp); |
3473 | esrv_send_item (who, tmp); |
|
|
3474 | |
3384 | esrv_send_item (who, op); |
3475 | esrv_send_item (who, op); |
3385 | } |
3476 | } |
|
|
3477 | |
3386 | return 0; |
3478 | return 0; |
3387 | } |
3479 | } |
3388 | |
|
|
3389 | |
3480 | |
3390 | int |
3481 | int |
3391 | monster_apply_special (object *who, object *op, int aflags) |
3482 | monster_apply_special (object *who, object *op, int aflags) |
3392 | { |
3483 | { |
3393 | if (QUERY_FLAG (op, FLAG_UNPAID) && !QUERY_FLAG (op, FLAG_APPLIED)) |
3484 | if (QUERY_FLAG (op, FLAG_UNPAID) && !QUERY_FLAG (op, FLAG_APPLIED)) |
… | |
… | |
3552 | && tmp->type != PLAYER_CHANGER && tmp->type != CLASS && tmp->has_random_items ()) |
3643 | && tmp->type != PLAYER_CHANGER && tmp->type != CLASS && tmp->has_random_items ()) |
3553 | { |
3644 | { |
3554 | create_treasure (tmp->randomitems, tmp, GT_APPLY, difficulty, 0); |
3645 | create_treasure (tmp->randomitems, tmp, GT_APPLY, difficulty, 0); |
3555 | tmp->randomitems = NULL; |
3646 | tmp->randomitems = NULL; |
3556 | } |
3647 | } |
|
|
3648 | |
3557 | // close all containers |
3649 | // close all containers |
3558 | else if (tmp->type == CONTAINER) |
3650 | else if (tmp->type == CONTAINER) |
3559 | tmp->flag [FLAG_APPLIED] = 0; |
3651 | tmp->flag [FLAG_APPLIED] = 0; |
3560 | |
3652 | |
3561 | tmp = above; |
3653 | tmp = above; |
… | |
… | |
3571 | * Handles player eating food that temporarily changes status (resistances, stats). |
3663 | * Handles player eating food that temporarily changes status (resistances, stats). |
3572 | * This used to call cast_change_attr(), but |
3664 | * This used to call cast_change_attr(), but |
3573 | * that doesn't work with the new spell code. Since we know what |
3665 | * that doesn't work with the new spell code. Since we know what |
3574 | * the food changes, just grab a force and use that instead. |
3666 | * the food changes, just grab a force and use that instead. |
3575 | */ |
3667 | */ |
3576 | |
|
|
3577 | void |
3668 | void |
3578 | eat_special_food (object *who, object *food) |
3669 | eat_special_food (object *who, object *food) |
3579 | { |
3670 | { |
3580 | object *force; |
3671 | object *force; |
3581 | int i, did_one = 0; |
3672 | int i, did_one = 0; |
3582 | sint8 k; |
|
|
3583 | |
3673 | |
3584 | force = get_archetype (FORCE_NAME); |
3674 | force = get_archetype (FORCE_NAME); |
3585 | |
3675 | |
3586 | for (i = 0; i < NUM_STATS; i++) |
3676 | for (i = 0; i < NUM_STATS; i++) |
3587 | { |
3677 | if (sint8 k = food->stats.stat (i)) |
3588 | k = get_attr_value (&food->stats, i); |
|
|
3589 | if (k) |
|
|
3590 | { |
3678 | { |
3591 | set_attr_value (&force->stats, i, k); |
3679 | force->stats.stat (i) = k; |
3592 | did_one = 1; |
3680 | did_one = 1; |
3593 | } |
3681 | } |
3594 | } |
|
|
3595 | |
3682 | |
3596 | /* check if we can protect the eater */ |
3683 | /* check if we can protect the eater */ |
3597 | for (i = 0; i < NROFATTACKS; i++) |
3684 | for (i = 0; i < NROFATTACKS; i++) |
3598 | { |
3685 | { |
3599 | if (food->resist[i] > 0) |
3686 | if (food->resist[i] > 0) |
… | |
… | |
3760 | new_draw_info (NDI_UNIQUE, 0, op, "The magic recoils on you!"); |
3847 | new_draw_info (NDI_UNIQUE, 0, op, "The magic recoils on you!"); |
3761 | blind_player (op, op, power); |
3848 | blind_player (op, op, power); |
3762 | } |
3849 | } |
3763 | else if (failure <= -80) |
3850 | else if (failure <= -80) |
3764 | { /* blast the immediate area */ |
3851 | { /* blast the immediate area */ |
3765 | object *tmp; |
|
|
3766 | |
|
|
3767 | tmp = get_archetype (LOOSE_MANA); |
3852 | object *tmp = get_archetype (LOOSE_MANA); |
3768 | cast_magic_storm (op, tmp, power); |
3853 | cast_magic_storm (op, tmp, power); |
3769 | new_draw_info (NDI_UNIQUE, 0, op, "You unlease uncontrolled mana!"); |
3854 | new_draw_info (NDI_UNIQUE, 0, op, "You unleash uncontrolled mana!"); |
3770 | tmp->destroy (); |
3855 | tmp->destroy (); |
3771 | } |
3856 | } |
3772 | } |
3857 | } |
3773 | } |
3858 | } |
3774 | |
3859 | |
… | |
… | |
3794 | */ |
3879 | */ |
3795 | int i, j; |
3880 | int i, j; |
3796 | |
3881 | |
3797 | for (i = 0; i < NUM_STATS; i++) |
3882 | for (i = 0; i < NUM_STATS; i++) |
3798 | { |
3883 | { |
3799 | sint8 stat = get_attr_value (stats, i); |
|
|
3800 | int race_bonus = get_attr_value (&(pl->arch->clone.stats), i); |
3884 | int race_bonus = pl->arch->clone.stats.stat (i); |
|
|
3885 | sint8 stat = stats->stat (i) + ns->stat (i); |
3801 | |
3886 | |
3802 | stat += get_attr_value (ns, i); |
|
|
3803 | if (stat > 20 + race_bonus) |
3887 | if (stat > 20 + race_bonus) |
3804 | { |
3888 | { |
3805 | excess_stat++; |
3889 | excess_stat++; |
3806 | stat = 20 + race_bonus; |
3890 | stat = 20 + race_bonus; |
3807 | } |
3891 | } |
3808 | set_attr_value (stats, i, stat); |
3892 | |
|
|
3893 | stats->stat (i) = stat; |
3809 | } |
3894 | } |
3810 | |
3895 | |
3811 | for (j = 0; excess_stat > 0 && j < 100; j++) |
3896 | for (j = 0; excess_stat > 0 && j < 100; j++) |
3812 | { /* try 100 times to assign excess stats */ |
3897 | { /* try 100 times to assign excess stats */ |
3813 | int i = rndm (0, 6); |
3898 | int i = rndm (0, 6); |
3814 | int stat = get_attr_value (stats, i); |
|
|
3815 | int race_bonus = get_attr_value (&(pl->arch->clone.stats), i); |
|
|
3816 | |
3899 | |
3817 | if (i == CHA) |
3900 | if (i == CHA) |
3818 | continue; /* exclude cha from this */ |
3901 | continue; /* exclude cha from this */ |
|
|
3902 | |
|
|
3903 | int stat = stats->stat (i); |
|
|
3904 | int race_bonus = pl->arch->clone.stats.stat (i); |
3819 | if (stat < 20 + race_bonus) |
3905 | if (stat < 20 + race_bonus) |
3820 | { |
3906 | { |
3821 | change_attr_value (stats, i, 1); |
3907 | change_attr_value (stats, i, 1); |
3822 | excess_stat--; |
3908 | excess_stat--; |
3823 | } |
3909 | } |
… | |
… | |
3826 | /* insert the randomitems from the change's treasurelist into |
3912 | /* insert the randomitems from the change's treasurelist into |
3827 | * the player ref: player.c |
3913 | * the player ref: player.c |
3828 | */ |
3914 | */ |
3829 | if (change->randomitems != NULL) |
3915 | if (change->randomitems != NULL) |
3830 | give_initial_items (pl, change->randomitems); |
3916 | give_initial_items (pl, change->randomitems); |
3831 | |
|
|
3832 | |
3917 | |
3833 | /* set up the face, for some races. */ |
3918 | /* set up the face, for some races. */ |
3834 | |
3919 | |
3835 | /* first, look for the force object banning |
3920 | /* first, look for the force object banning |
3836 | * changing the face. Certain races never change face with class. |
3921 | * changing the face. Certain races never change face with class. |