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.68 by root, Sat Feb 10 01:52:29 2007 UTC vs.
Revision 1.105 by root, Fri May 18 12:50:42 2007 UTC

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.
1861 if (!QUERY_FLAG (tmp, FLAG_IDENTIFIED)) 1868 if (!QUERY_FLAG (tmp, FLAG_IDENTIFIED))
1862 identify (tmp); 1869 identify (tmp);
1863 1870
1864 new_draw_info_format (NDI_BLACK, 0, op, "The scroll of %s turns to dust.", &tmp->inv->name); 1871 new_draw_info_format (NDI_BLACK, 0, op, "The scroll of %s turns to dust.", &tmp->inv->name);
1865 1872
1866
1867 cast_spell (op, tmp, dir, tmp->inv, NULL); 1873 cast_spell (op, tmp, dir, tmp->inv, NULL);
1868 decrease_ob (tmp); 1874 decrease_ob (tmp);
1869} 1875}
1870 1876
1871/** 1877/**
1874 * chest. 1880 * chest.
1875 */ 1881 */
1876static void 1882static void
1877apply_treasure (object *op, object *tmp) 1883apply_treasure (object *op, object *tmp)
1878{ 1884{
1879 object *treas;
1880
1881
1882 /* Nice side effect of new treasure creation method is that the treasure 1885 /* Nice side effect of new treasure creation method is that the treasure
1883 * for the chest is done when the chest is created, and put into the chest 1886 * for the chest is done when the chest is created, and put into the chest
1884 * inventory. So that when the chest burns up, the items still exist. Also 1887 * inventory. So that when the chest burns up, the items still exist. Also
1885 * prevents people fromt moving chests to more difficult maps to get better 1888 * prevents people fromt moving chests to more difficult maps to get better
1886 * treasure 1889 * treasure
1887 */ 1890 */
1888
1889 treas = tmp->inv; 1891 object *treas = tmp->inv;
1890 if (treas == NULL) 1892
1893 if (!treas)
1891 { 1894 {
1892 new_draw_info (NDI_UNIQUE, 0, op, "The chest was empty."); 1895 new_draw_info (NDI_UNIQUE, 0, op, "The chest was empty.");
1893 decrease_ob (tmp); 1896 decrease_ob (tmp);
1894 return; 1897 return;
1895 } 1898 }
1899
1896 while (tmp->inv) 1900 while (tmp->inv)
1897 { 1901 {
1898 treas = tmp->inv; 1902 treas = tmp->inv;
1899 1903
1900 treas->remove (); 1904 treas->remove ();
2077 /* doubled chance for resistance of ability-focus */ 2081 /* doubled chance for resistance of ability-focus */
2078 if (i == abil->stats.exp) 2082 if (i == abil->stats.exp)
2079 chance = MIN (100., chance * 2.); 2083 chance = MIN (100., chance * 2.);
2080 2084
2081 /* now make the throw and save all winners (Don't insert luck bonus here!) */ 2085 /* now make the throw and save all winners (Don't insert luck bonus here!) */
2082 if (rndm (10000) < (int) (chance * 100)) 2086 if (rndm (10000) < (unsigned int) (chance * 100))
2083 { 2087 {
2084 atnr_winner[winners] = i; 2088 atnr_winner[winners] = i;
2085 winners++; 2089 winners++;
2086 } 2090 }
2087 2091
2289 } 2293 }
2290 2294
2291 return 0; 2295 return 0;
2292} 2296}
2293 2297
2294
2295/** 2298/**
2296 * Main apply handler. 2299 * Main apply handler.
2297 * 2300 *
2298 * Checks for unpaid items before applying. 2301 * Checks for unpaid items before applying.
2299 * 2302 *
2306 * being applied. 2309 * being applied.
2307 * 2310 *
2308 * aflag is special (always apply/unapply) flags. Nothing is done with 2311 * aflag is special (always apply/unapply) flags. Nothing is done with
2309 * them in this function - they are passed to apply_special 2312 * them in this function - they are passed to apply_special
2310 */ 2313 */
2311
2312int 2314int
2313manual_apply (object *op, object *tmp, int aflag) 2315manual_apply (object *op, object *tmp, int aflag)
2314{ 2316{
2315 if (tmp->head) 2317 if (tmp->head)
2316 tmp = tmp->head; 2318 tmp = tmp->head;
2354 case EXIT: 2356 case EXIT:
2355 if (op->type != PLAYER) 2357 if (op->type != PLAYER)
2356 return 0; 2358 return 0;
2357 2359
2358 if (!EXIT_PATH (tmp) || !is_legal_2ways_exit (op, tmp)) 2360 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)); 2361 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s is closed.", query_name (tmp));
2361 }
2362 else 2362 else
2363 { 2363 {
2364 /* Don't display messages for random maps. */ 2364 /* Don't display messages for random maps. */
2365 if (tmp->msg && strncmp (EXIT_PATH (tmp), "/!", 2)) 2365 if (tmp->msg && strncmp (EXIT_PATH (tmp), "/!", 2))
2366 new_draw_info (NDI_NAVY, 0, op, tmp->msg); 2366 new_draw_info (NDI_NAVY, 0, op, tmp->msg);
2367 2367
2368 op->enter_exit (tmp); 2368 op->enter_exit (tmp);
2369 } 2369 }
2370
2370 return 1; 2371 return 1;
2371 2372
2372 case SIGN: 2373 case SIGN:
2373 apply_sign (op, tmp, 0); 2374 apply_sign (op, tmp, 0);
2374 return 1; 2375 return 1;
2378 { 2379 {
2379 apply_book (op, tmp); 2380 apply_book (op, tmp);
2380 return 1; 2381 return 1;
2381 } 2382 }
2382 else 2383 else
2383 {
2384 return 0; 2384 return 0;
2385 }
2386 2385
2387 case SKILLSCROLL: 2386 case SKILLSCROLL:
2388 if (op->type == PLAYER) 2387 if (op->type == PLAYER)
2389 { 2388 {
2390 apply_skillscroll (op, tmp); 2389 apply_skillscroll (op, tmp);
2391 return 1; 2390 return 1;
2392 } 2391 }
2392 else
2393 return 0; 2393 return 0;
2394 2394
2395 case SPELLBOOK: 2395 case SPELLBOOK:
2396 if (op->type == PLAYER) 2396 if (op->type == PLAYER)
2397 { 2397 {
2398 apply_spellbook (op, tmp); 2398 apply_spellbook (op, tmp);
2399 return 1; 2399 return 1;
2400 } 2400 }
2401 else
2401 return 0; 2402 return 0;
2402 2403
2403 case SCROLL: 2404 case SCROLL:
2404 apply_scroll (op, tmp, 0); 2405 apply_scroll (op, tmp, 0);
2405 return 1; 2406 return 1;
2406 2407
2407 case POTION: 2408 case POTION:
2408 (void) apply_potion (op, tmp); 2409 apply_potion (op, tmp);
2409 return 1; 2410 return 1;
2410 2411
2411 /* Eneq(@csd.uu.se): Handle apply on containers. */ 2412 /* Eneq(@csd.uu.se): Handle apply on containers. */
2412 //TODO: remove, as it is unsed? 2413 //TODO: remove, as it is unsed?
2413 case CLOSE_CON: 2414 case CLOSE_CON:
2446 case LAMP: 2447 case LAMP:
2447 case BUILDER: 2448 case BUILDER:
2448 case SKILL_TOOL: 2449 case SKILL_TOOL:
2449 if (tmp->env != op) 2450 if (tmp->env != op)
2450 return 2; /* not in inventory */ 2451 return 2; /* not in inventory */
2452
2451 (void) apply_special (op, tmp, aflag); 2453 apply_special (op, tmp, aflag);
2452 return 1; 2454 return 1;
2453 2455
2454 case DRINK: 2456 case DRINK:
2455 case FOOD: 2457 case FOOD:
2456 case FLESH: 2458 case FLESH:
2472 } 2474 }
2473 else 2475 else
2474 return 0; 2476 return 0;
2475 2477
2476 case WEAPON_IMPROVER: 2478 case WEAPON_IMPROVER:
2477 (void) check_improve_weapon (op, tmp); 2479 check_improve_weapon (op, tmp);
2478 return 1; 2480 return 1;
2479 2481
2480 case CLOCK: 2482 case CLOCK:
2481 if (op->type == PLAYER) 2483 if (op->type == PLAYER)
2482 { 2484 {
2490 play_sound_player_only (op->contr, SOUND_CLOCK, 0, 0); 2492 play_sound_player_only (op->contr, SOUND_CLOCK, 0, 0);
2491 new_draw_info (NDI_UNIQUE, 0, op, buf); 2493 new_draw_info (NDI_UNIQUE, 0, op, buf);
2492 return 1; 2494 return 1;
2493 } 2495 }
2494 else 2496 else
2495 {
2496 return 0; 2497 return 0;
2497 }
2498 2498
2499 case MENU: 2499 case MENU:
2500 if (op->type == PLAYER) 2500 if (op->type == PLAYER)
2501 { 2501 {
2502 shop_listing (op); 2502 shop_listing (tmp, op);
2503 return 1; 2503 return 1;
2504 } 2504 }
2505 else 2505 else
2506 {
2507 return 0; 2506 return 0;
2508 }
2509 2507
2510 case POWER_CRYSTAL: 2508 case POWER_CRYSTAL:
2511 apply_power_crystal (op, tmp); /* see egoitem.c */ 2509 apply_power_crystal (op, tmp); /* see egoitem.c */
2512 return 1; 2510 return 1;
2513 2511
2516 { 2514 {
2517 apply_lighter (op, tmp); 2515 apply_lighter (op, tmp);
2518 return 1; 2516 return 1;
2519 } 2517 }
2520 else 2518 else
2521 {
2522 return 0; 2519 return 0;
2523 }
2524 2520
2525 case ITEM_TRANSFORMER: 2521 case ITEM_TRANSFORMER:
2526 apply_item_transformer (op, tmp); 2522 apply_item_transformer (op, tmp);
2527 return 1; 2523 return 1;
2528 2524
2551 new_draw_info (NDI_UNIQUE, 0, pl, "But you are floating high " "above the ground!"); 2547 new_draw_info (NDI_UNIQUE, 0, pl, "But you are floating high " "above the ground!");
2552 return 0; 2548 return 0;
2553 } 2549 }
2554 } 2550 }
2555 2551
2556 /* Check for PLAYER to avoid a DM to disappear in a puff of smoke if
2557 * applied.
2558 */
2559 if (op->type != PLAYER && QUERY_FLAG (op, FLAG_WAS_WIZ) && !QUERY_FLAG (pl, FLAG_WAS_WIZ))
2560 {
2561 play_sound_map (pl->map, pl->x, pl->y, SOUND_OB_EVAPORATE);
2562 new_draw_info (NDI_UNIQUE, 0, pl, "The object disappears in a puff " "of smoke!");
2563 new_draw_info (NDI_UNIQUE, 0, pl, "It must have been an illusion.");
2564 op->destroy ();
2565 return 1;
2566 }
2567
2568 pl->contr->last_used = op; 2552 pl->contr->last_used = op;
2569 2553
2570 tmp = manual_apply (pl, op, aflag); 2554 tmp = manual_apply (pl, op, aflag);
2571 if (!quiet) 2555 if (!quiet)
2572 { 2556 {
2581/** 2565/**
2582 * player_apply_below attempts to apply the object 'below' the player. 2566 * 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 2567 * If the player has an open container, we use that for below, otherwise
2584 * we use the ground. 2568 * we use the ground.
2585 */ 2569 */
2586
2587void 2570void
2588player_apply_below (object *pl) 2571player_apply_below (object *pl)
2589{ 2572{
2590 int floors = 0; 2573 int floors = 0;
2591 2574
2628 * to keep the size of apply_special to a more managable size. 2611 * to keep the size of apply_special to a more managable size.
2629 */ 2612 */
2630static int 2613static int
2631unapply_special (object *who, object *op, int aflags) 2614unapply_special (object *who, object *op, int aflags)
2632{ 2615{
2633 if (INVOKE_OBJECT (BE_UNREADY, op, ARG_OBJECT (who), ARG_INT (aflags)) || INVOKE_OBJECT (UNREADY, who, ARG_OBJECT (op), ARG_INT (aflags))) 2616 if (INVOKE_OBJECT (BE_UNREADY, op, ARG_OBJECT (who), ARG_INT (aflags))
2617 || INVOKE_OBJECT (UNREADY, who, ARG_OBJECT (op), ARG_INT (aflags)))
2634 return RESULT_INT (0); 2618 return RESULT_INT (0);
2635 2619
2636 object *tmp2;
2637
2638 CLEAR_FLAG (op, FLAG_APPLIED); 2620 CLEAR_FLAG (op, FLAG_APPLIED);
2621
2639 switch (op->type) 2622 switch (op->type)
2640 { 2623 {
2624 case SKILL_TOOL:
2625 // unapplying a skill tool should also unapply the skill it governs
2626 // but this is hard, as it shouldn't do so when the skill can
2627 // be used for other reasons
2628 for (object *tmp = who->inv; tmp; tmp = tmp->below)
2629 if (tmp->skill == op->skill
2630 && tmp->type == SKILL
2631 && tmp->flag [FLAG_APPLIED]
2632 && !tmp->flag [FLAG_CAN_USE_SKILL])
2633 unapply_special (who, tmp, 0);
2634
2635 change_abil (who, op);
2636 break;
2637
2641 case WEAPON: 2638 case WEAPON:
2639 if (player *pl = who->contr)
2640 if (op == pl->combat_ob)
2641 {
2642 pl->combat_ob = 0;
2643 who->change_weapon (pl->ranged_ob);
2644 }
2645
2642 new_draw_info_format (NDI_UNIQUE, 0, who, "You unwield %s.", query_name (op)); 2646 new_draw_info_format (NDI_UNIQUE, 0, who, "You unwield %s.", query_name (op));
2643 2647
2644 (void) change_abil (who, op); 2648 change_abil (who, op);
2645 if (QUERY_FLAG (who, FLAG_READY_WEAPON))
2646 CLEAR_FLAG (who, FLAG_READY_WEAPON); 2649 CLEAR_FLAG (who, FLAG_READY_WEAPON);
2647 clear_skill (who);
2648 break; 2650 break;
2649 2651
2650 case SKILL: /* allows objects to impart skills */
2651 case SKILL_TOOL: 2652 case SKILL:
2652 if (op != who->chosen_skill) 2653 if (who->contr)
2653 { 2654 {
2654 LOG (llevError, "BUG: apply_special(): applied skill is not a chosen skill\n"); 2655 if (!op->invisible)
2656 new_draw_info_format (NDI_UNIQUE, 0, who, "You stop using the %s.", query_name (op));
2657 else
2658 new_draw_info_format (NDI_UNIQUE, 0, who, "You can no longer use the skill: %s.", &op->skill);
2655 } 2659 }
2656 if (who->type == PLAYER) 2660
2657 {
2658 if (who->contr->shoottype == range_skill)
2659 who->contr->shoottype = range_none;
2660 if (!op->invisible)
2661 {
2662 new_draw_info_format (NDI_UNIQUE, 0, who, "You stop using the %s.", query_name (op));
2663 }
2664 else
2665 {
2666 new_draw_info_format (NDI_UNIQUE, 0, who, "You can no longer use the skill: %s.", &op->skill);
2667 }
2668 }
2669 (void) change_abil (who, op); 2661 change_abil (who, op);
2670 who->chosen_skill = NULL;
2671 CLEAR_FLAG (who, FLAG_READY_SKILL); 2662 CLEAR_FLAG (who, FLAG_READY_SKILL);
2672 break; 2663 break;
2673 2664
2674 case ARMOUR: 2665 case ARMOUR:
2675 case HELMET: 2666 case HELMET:
2680 case AMULET: 2671 case AMULET:
2681 case GIRDLE: 2672 case GIRDLE:
2682 case BRACERS: 2673 case BRACERS:
2683 case CLOAK: 2674 case CLOAK:
2684 new_draw_info_format (NDI_UNIQUE, 0, who, "You unwear %s.", query_name (op)); 2675 new_draw_info_format (NDI_UNIQUE, 0, who, "You unwear %s.", query_name (op));
2685 (void) change_abil (who, op); 2676 change_abil (who, op);
2686 break; 2677 break;
2678
2687 case LAMP: 2679 case LAMP:
2680 {
2688 new_draw_info_format (NDI_UNIQUE, 0, who, "You turn off your %s.", &op->name); 2681 new_draw_info_format (NDI_UNIQUE, 0, who, "You turn off your %s.", &op->name);
2682
2689 tmp2 = arch_to_object (op->other_arch); 2683 object *tmp2 = arch_to_object (op->other_arch);
2690 tmp2->x = op->x; 2684 tmp2->x = op->x;
2691 tmp2->y = op->y; 2685 tmp2->y = op->y;
2692 tmp2->map = op->map; 2686 tmp2->map = op->map;
2693 tmp2->below = op->below; 2687 tmp2->below = op->below;
2694 tmp2->above = op->above; 2688 tmp2->above = op->above;
2695 tmp2->stats.food = op->stats.food; 2689 tmp2->stats.food = op->stats.food;
2696 CLEAR_FLAG (tmp2, FLAG_APPLIED); 2690 CLEAR_FLAG (tmp2, FLAG_APPLIED);
2697 2691
2698 if (QUERY_FLAG (op, FLAG_INV_LOCKED)) 2692 if (QUERY_FLAG (op, FLAG_INV_LOCKED))
2699 SET_FLAG (tmp2, FLAG_INV_LOCKED); 2693 SET_FLAG (tmp2, FLAG_INV_LOCKED);
2700 2694
2701 if (who->type == PLAYER) 2695 if (who->contr)
2702 esrv_del_item (who->contr, op->count); 2696 esrv_del_item (who->contr, op->count);
2703 2697
2704 op->destroy (); 2698 op->destroy ();
2705 insert_ob_in_ob (tmp2, who); 2699 insert_ob_in_ob (tmp2, who);
2706 who->update_stats (); 2700 who->update_stats ();
2701
2707 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED)) 2702 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED))
2708 { 2703 {
2709 if (who->type == PLAYER) 2704 if (who->contr)
2710 { 2705 {
2711 new_draw_info (NDI_UNIQUE, 0, who, "Oops, it feels deadly cold!"); 2706 new_draw_info (NDI_UNIQUE, 0, who, "Oops, it feels deadly cold!");
2712 SET_FLAG (tmp2, FLAG_KNOWN_CURSED); 2707 SET_FLAG (tmp2, FLAG_KNOWN_CURSED);
2713 } 2708 }
2714 } 2709 }
2715 if (who->type == PLAYER) 2710
2711 if (who->contr)
2716 esrv_send_item (who, tmp2); 2712 esrv_send_item (who, tmp2);
2713 }
2714
2717 return 1; /* otherwise, an attempt to drop causes problems */ 2715 return 1; /* otherwise, an attempt to drop causes problems */
2718 break; 2716
2719 case BOW: 2717 case BOW:
2720 case WAND: 2718 case WAND:
2721 case ROD: 2719 case ROD:
2722 case HORN: 2720 case HORN:
2723 clear_skill (who); 2721 if (player *pl = who->contr)
2724 new_draw_info_format (NDI_UNIQUE, 0, who, "You unready %s.", query_name (op));
2725 if (who->type == PLAYER)
2726 { 2722 {
2727 who->contr->shoottype = range_none; 2723 if (op == pl->ranged_ob)
2724 {
2725 pl->ranged_ob = 0;
2726 who->change_weapon (pl->combat_ob);
2727 }
2728
2729 new_draw_info_format (NDI_UNIQUE, 0, who, "You unready %s.", query_name (op));
2728 } 2730 }
2729 else 2731 else
2730 { 2732 {
2733 who->change_skill (0);
2734
2731 if (op->type == BOW) 2735 if (op->type == BOW)
2732 CLEAR_FLAG (who, FLAG_READY_BOW); 2736 CLEAR_FLAG (who, FLAG_READY_BOW);
2733 else 2737 else
2734 CLEAR_FLAG (who, FLAG_READY_RANGE); 2738 CLEAR_FLAG (who, FLAG_READY_RANGE);
2735 } 2739 }
2740
2736 break; 2741 break;
2737 2742
2738 case BUILDER: 2743 case BUILDER:
2744 if (who->contr)
2739 new_draw_info_format (NDI_UNIQUE, 0, who, "You unready %s.", query_name (op)); 2745 new_draw_info_format (NDI_UNIQUE, 0, who, "You unready %s.", query_name (op));
2740 who->contr->shoottype = range_none;
2741 who->contr->ranges[range_builder] = NULL;
2742 break; 2746 break;
2743 2747
2744 default: 2748 default:
2745 new_draw_info_format (NDI_UNIQUE, 0, who, "You unapply %s.", query_name (op)); 2749 new_draw_info_format (NDI_UNIQUE, 0, who, "You unapply %s.", query_name (op));
2746 break; 2750 break;
2748 2752
2749 who->update_stats (); 2753 who->update_stats ();
2750 2754
2751 if (!(aflags & AP_NO_MERGE)) 2755 if (!(aflags & AP_NO_MERGE))
2752 { 2756 {
2753 object *tmp;
2754
2755 tmp = merge_ob (op, NULL); 2757 object *tmp = merge_ob (op, 0);
2756 if (who->type == PLAYER) 2758
2759 if (who->contr)
2757 { 2760 {
2758 if (tmp) 2761 if (tmp)
2759 { /* it was merged */ 2762 { /* it was merged */
2760 esrv_del_item (who->contr, op->count); 2763 esrv_del_item (who->contr, op->count);
2761 op = tmp; 2764 op = tmp;
2762 } 2765 }
2763 2766
2764 esrv_send_item (who, op); 2767 esrv_send_item (who, op);
2765 } 2768 }
2766 } 2769 }
2770
2767 return 0; 2771 return 0;
2768} 2772}
2769 2773
2770/** 2774/**
2771 * Returns the object that is using location 'loc'. 2775 * Returns the object that is using location 'loc'.
2772 * Note that 'start' is the first object to start examing - we 2776 * 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 2777 * then go through the below of this. In this way, you can do
2774 * something like: 2778 * something like:
2775 * tmp = get_item_from_body_location(who->inv, 1); 2779 * tmp = get_next_item_from_body_location(who->inv, 1);
2776 * if (tmp) tmp1 = get_item_from_body_location(tmp->below, 1); 2780 * if (tmp) tmp1 = get_next_item_from_body_location(tmp->below, 1);
2777 * to find the second object that may use this location, etc. 2781 * to find the second object that may use this location, etc.
2778 * Returns NULL if no match is found. 2782 * Returns NULL if no match is found.
2779 * loc is the index into the array we are looking for a match. 2783 * loc is the index into the array we are looking for a match.
2780 * don't return invisible objects unless they are skill objects 2784 * don't return invisible objects unless they are skill objects
2781 * invisible other objects that use 2785 * invisible other objects that use
2782 * up body locations can be used as restrictions. 2786 * up body locations can be used as restrictions.
2783 */ 2787 */
2784object * 2788static object *
2785get_item_from_body_location (object *start, int loc) 2789get_next_item_from_body_location (int loc, object *start)
2786{ 2790{
2787 object *tmp;
2788
2789 if (!start)
2790 return NULL;
2791
2792 for (tmp = start; tmp; tmp = tmp->below) 2791 for (object *tmp = start; tmp; tmp = tmp->below)
2793 if (QUERY_FLAG (tmp, FLAG_APPLIED) && tmp->body_info[loc] && (!tmp->invisible || tmp->type == SKILL)) 2792 if (tmp->flag [FLAG_APPLIED]
2793 && tmp->slot[loc].info
2794 && (!tmp->invisible || tmp->type == SKILL))
2794 return tmp; 2795 return tmp;
2795 2796
2796 return NULL; 2797 return 0;
2797} 2798}
2798
2799
2800 2799
2801/** 2800/**
2802 * 'op' wants to apply an object, but can't because of other equipment. 2801 * 'op' wants to apply an object, but can't because of other equipment.
2803 * This should only be called when it is known 2802 * This should only be called when it is known
2804 * that there are objects to unapply. This makes pretty heavy 2803 * that there are objects to unapply. This makes pretty heavy
2810 * another function that does just that. 2809 * another function that does just that.
2811 */ 2810 */
2812int 2811int
2813unapply_for_ob (object *who, object *op, int aflags) 2812unapply_for_ob (object *who, object *op, int aflags)
2814{ 2813{
2815 int i; 2814 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) 2815 for (object *tmp = who->inv; tmp; tmp = tmp->below)
2824 {
2825 if (QUERY_FLAG (tmp, FLAG_APPLIED) && tmp->type == op->type) 2816 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))) 2817 if ((aflags & AP_IGNORE_CURSE) || (aflags & AP_PRINT) || (!QUERY_FLAG (tmp, FLAG_CURSED) && !QUERY_FLAG (tmp, FLAG_DAMNED)))
2828 { 2818 {
2829 if (aflags & AP_PRINT) 2819 if (aflags & AP_PRINT)
2830 new_draw_info (NDI_UNIQUE, 0, who, query_name (tmp)); 2820 new_draw_info (NDI_UNIQUE, 0, who, query_name (tmp));
2831 else 2821 else
2832 unapply_special (who, tmp, aflags); 2822 unapply_special (who, tmp, aflags);
2833 } 2823 }
2834 else 2824 else
2835 { 2825 {
2836 /* In this case, we want to try and remove a cursed item. 2826 /* 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 2827 * While we know it won't work, we want unapply_special to
2838 * at least generate the message. 2828 * at least generate the message.
2839 */ 2829 */
2840 new_draw_info_format (NDI_UNIQUE, 0, who, "No matter how hard you try, you just can't\nremove %s.", query_name (tmp)); 2830 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; 2831 return 1;
2842 }
2843
2844 } 2832 }
2845 }
2846 }
2847 2833
2848 for (i = 0; i < NUM_BODY_LOCATIONS; i++) 2834 for (int i = 0; i < NUM_BODY_LOCATIONS; i++)
2849 { 2835 {
2850 /* this used up a slot that we need to free */ 2836 /* this used up a slot that we need to free */
2851 if (op->body_info[i]) 2837 if (op->slot[i].info)
2852 { 2838 {
2853 last = who->inv; 2839 object *last = who->inv;
2854 2840
2855 /* We do a while loop - may need to remove several items in order 2841 /* We do a while loop - may need to remove several items in order
2856 * to free up enough slots. 2842 * to free up enough slots.
2857 */ 2843 */
2858 while ((who->body_used[i] + op->body_info[i]) < 0) 2844 while ((who->slot[i].used + op->slot[i].info) < 0)
2859 { 2845 {
2860 tmp = get_item_from_body_location (last, i); 2846 object *tmp = get_next_item_from_body_location (i, last);
2847
2861 if (!tmp) 2848 if (!tmp)
2862 { 2849 {
2863#if 0 2850#if 0
2864 /* Not a bug - we'll get this if the player has cursed items 2851 /* Not a bug - we'll get this if the player has cursed items
2865 * equipped. 2852 * equipped.
2866 */ 2853 */
2867 LOG (llevError, "Can't find object using location %d (%s) on %s\n", i, body_locations[i].save_name, who->name); 2854 LOG (llevError, "Can't find object using location %d (%s) on %s\n", i, body_locations[i].save_name, who->name);
2868#endif 2855#endif
2869 return 1; 2856 return 1;
2870 } 2857 }
2858
2871 /* If we are just printing, we don't care about cursed status */ 2859 /* 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)))) 2860 if ((aflags & AP_IGNORE_CURSE) || (aflags & AP_PRINT) || (!(QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED))))
2873 { 2861 {
2874 if (aflags & AP_PRINT) 2862 if (aflags & AP_PRINT)
2875 new_draw_info (NDI_UNIQUE, 0, who, query_name (tmp)); 2863 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 2871 * so it may not be critical (eg, putting on a ring and you have
2884 * one cursed ring.) 2872 * one cursed ring.)
2885 */ 2873 */
2886 new_draw_info_format (NDI_UNIQUE, 0, who, "The %s just won't come off", query_name (tmp)); 2874 new_draw_info_format (NDI_UNIQUE, 0, who, "The %s just won't come off", query_name (tmp));
2887 } 2875 }
2876
2888 last = tmp->below; 2877 last = tmp->below;
2889 } 2878 }
2890 /* if we got here, this slot is freed up - otherwise, if it wasn't freed up, the 2879 /* 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. 2880 * return in the !tmp would have kicked in.
2892 */ 2881 */
2893 } /* if op is using this body location */ 2882 } /* if op is using this body location */
2894 } /* for body lcoations */ 2883 } /* for body lcoations */
2884
2895 return 0; 2885 return 0;
2896} 2886}
2897 2887
2898/** 2888/**
2899 * Checks to see if 'who' can apply object 'op'. 2889 * Checks to see if 'who' can apply object 'op'.
2900 * Returns 0 if apply can be done without anything special. 2890 * Returns 0 if apply can be done without anything special.
2901 * Otherwise returns a bitmask - potentially several of these may be 2891 * Otherwise returns a bitmask - potentially several of these may be
2902 * set, but largely depends on circumstance - in the future, processing 2892 * set, but largely depends on circumstance - in the future, processing
2903 * may be pruned once we know some status (eg, once CAN_APPLY_NEVER 2893 * 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?) 2894 * is set, do we really care what the other flags may be?)
2905 * 2895 *
2906 * See include/define.h for detailed description of the meaning of 2896 * See include/define.h for detailed description of the meaning of
2907 * these return values. 2897 * these return values.
2908 */ 2898 */
2909int 2899int
2910can_apply_object (object *who, object *op) 2900can_apply_object (object *who, object *op)
2911{ 2901{
2912 if (INVOKE_OBJECT (CAN_BE_APPLIED, op, ARG_OBJECT (who)) || INVOKE_OBJECT (CAN_APPLY, who, ARG_OBJECT (op))) 2902 if (INVOKE_OBJECT (CAN_BE_APPLIED, op, ARG_OBJECT (who)) || INVOKE_OBJECT (CAN_APPLY, who, ARG_OBJECT (op)))
2913 return RESULT_INT (0); 2903 return RESULT_INT (0);
2914 2904
2915 int i, retval = 0; 2905 int retval = 0;
2916 object *tmp = NULL, *ws = NULL; 2906 object *tmp = 0, *ws = 0;
2917 2907
2918 /* Players have 2 'arm's, so they could in theory equip 2 shields or 2908 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 { 2909 {
2925 for (tmp = who->inv; tmp && !ws; tmp = tmp->below) 2910 if (op->slot[i].info)
2926 { 2911 {
2927 if (QUERY_FLAG (tmp, FLAG_APPLIED) && tmp->type == op->type) 2912 /* Item uses more slots than we have */
2913 if (who->slot[i].info + op->slot [i].info < 0)
2928 { 2914 {
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' 2915 /* Could return now for efficiency - rest of info below isn't
2944 * really needed. 2916 * really needed.
2945 */ 2917 */
2946 retval |= CAN_APPLY_NEVER; 2918 retval |= CAN_APPLY_NEVER;
2947 } 2919 }
2948 else if ((who->body_used[i] + op->body_info[i]) < 0) 2920 else if (who->slot[i].used + op->slot[i].info < 0)
2949 { 2921 {
2950 /* in this case, equipping this would use more free spots than 2922 /* in this case, equipping this would use more free spots than
2951 * we have. 2923 * we have.
2952 */ 2924 */
2953 object *tmp1;
2954
2955 2925
2956 /* if we have an applied weapon/shield, and unapply it would free 2926 /* 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 2927 * enough slots to equip the new item, then just set "can
2958 * continue. We don't care about the logic below - if you have 2928 * 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 2929 * shield equipped and try to equip another shield, there is only
2960 * one choice. However, the check for the number of body locations 2930 * one choice. However, the check for the number of body locations
2961 * does take into the account cases where what is being applied 2931 * does take into the account cases where what is being applied
2962 * may be two handed for example. 2932 * may be two handed for example.
2963 */ 2933 */
2964 if (ws) 2934 if (ws)
2965 { 2935 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 { 2936 {
2968 retval |= CAN_APPLY_UNAPPLY; 2937 retval |= CAN_APPLY_UNAPPLY;
2969 continue; 2938 continue;
2970 } 2939 }
2971 }
2972 2940
2973 tmp1 = get_item_from_body_location (who->inv, i); 2941 object *tmp1 = get_next_item_from_body_location (i, who->inv);
2974 if (!tmp1) 2942 if (!tmp1)
2975 { 2943 {
2976#if 0 2944#if 0
2977 /* This is sort of an error, but happens a lot when old players 2945 /* 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. 2946 * join in with more stuff equipped than they are now allowed.
2986 /* need to unapply something. However, if this something 2954 /* need to unapply something. However, if this something
2987 * is different than we had found before, it means they need 2955 * is different than we had found before, it means they need
2988 * to apply multiple objects 2956 * to apply multiple objects
2989 */ 2957 */
2990 retval |= CAN_APPLY_UNAPPLY; 2958 retval |= CAN_APPLY_UNAPPLY;
2959
2991 if (!tmp) 2960 if (!tmp)
2992 tmp = tmp1; 2961 tmp = tmp1;
2993 else if (tmp != tmp1) 2962 else if (tmp != tmp1)
2994 {
2995 retval |= CAN_APPLY_UNAPPLY_MULT; 2963 retval |= CAN_APPLY_UNAPPLY_MULT;
2996 } 2964
2997 /* This object isn't using up all the slots, so there must 2965 /* 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 2966 * be another. If so, and it the new item doesn't need all
2999 * the slots, the player then has a choice. 2967 * the slots, the player then has a choice.
3000 */ 2968 */
3001 if (((who->body_used[i] - tmp1->body_info[i]) != who->body_info[i]) && (FABS (op->body_info[i]) < who->body_info[i])) 2969 if ((who->slot[i].used - tmp1->slot[i].info != who->slot[i].info)
2970 && abs (op->slot[i].info) < who->slot[i].info)
3002 retval |= CAN_APPLY_UNAPPLY_CHOICE; 2971 retval |= CAN_APPLY_UNAPPLY_CHOICE;
3003 2972
3004 /* Does unequippint 'tmp1' free up enough slots for this to be 2973 /* Does unequippint 'tmp1' free up enough slots for this to be
3005 * equipped? If not, there must be something else to unapply. 2974 * equipped? If not, there must be something else to unapply.
3006 */ 2975 */
3007 if ((who->body_used[i] + op->body_info[i] - tmp1->body_info[i]) < 0) 2976 if (who->slot[i].used + op->slot[i].info < tmp1->slot[i].info)
3008 retval |= CAN_APPLY_UNAPPLY_MULT; 2977 retval |= CAN_APPLY_UNAPPLY_MULT;
3009
3010 } 2978 }
3011 } /* if not enough free slots */ 2979 } /* if not enough free slots */
3012 } /* if this object uses location i */ 2980 } /* if this object uses location i */
3013 } /* for i -> num_body_locations loop */ 2981 } /* for i -> num_body_locations loop */
3014 2982
3019 * and weapons all use the same slot. Similar for horn/rod/wand - they 2987 * and weapons all use the same slot. Similar for horn/rod/wand - they
3020 * all use the same location. 2988 * all use the same location.
3021 */ 2989 */
3022 if (op->type == WEAPON && !QUERY_FLAG (who, FLAG_USE_WEAPON)) 2990 if (op->type == WEAPON && !QUERY_FLAG (who, FLAG_USE_WEAPON))
3023 retval |= CAN_APPLY_RESTRICTION; 2991 retval |= CAN_APPLY_RESTRICTION;
2992
3024 if (op->type == SHIELD && !QUERY_FLAG (who, FLAG_USE_SHIELD)) 2993 if (op->type == SHIELD && !QUERY_FLAG (who, FLAG_USE_SHIELD))
3025 retval |= CAN_APPLY_RESTRICTION; 2994 retval |= CAN_APPLY_RESTRICTION;
3026 2995
3027
3028 if (who->type != PLAYER) 2996 if (who->type != PLAYER)
3029 { 2997 {
3030 if ((op->type == WAND || op->type == HORN || op->type == ROD) && !QUERY_FLAG (who, FLAG_USE_RANGE)) 2998 if ((op->type == WAND || op->type == HORN || op->type == ROD) && !QUERY_FLAG (who, FLAG_USE_RANGE))
3031 retval |= CAN_APPLY_RESTRICTION; 2999 retval |= CAN_APPLY_RESTRICTION;
3000
3032 if (op->type == BOW && !QUERY_FLAG (who, FLAG_USE_BOW)) 3001 if (op->type == BOW && !QUERY_FLAG (who, FLAG_USE_BOW))
3033 retval |= CAN_APPLY_RESTRICTION; 3002 retval |= CAN_APPLY_RESTRICTION;
3003
3034 if (op->type == RING && !QUERY_FLAG (who, FLAG_USE_RING)) 3004 if (op->type == RING && !QUERY_FLAG (who, FLAG_USE_RING))
3035 retval |= CAN_APPLY_RESTRICTION; 3005 retval |= CAN_APPLY_RESTRICTION;
3006
3036 if (op->type == BOW && !QUERY_FLAG (who, FLAG_USE_BOW)) 3007 if (op->type == BOW && !QUERY_FLAG (who, FLAG_USE_BOW))
3037 retval |= CAN_APPLY_RESTRICTION; 3008 retval |= CAN_APPLY_RESTRICTION;
3038 } 3009 }
3010
3039 return retval; 3011 return retval;
3040} 3012}
3041
3042
3043 3013
3044/** 3014/**
3045 * who is the object using the object. It can be a monster. 3015 * 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, 3016 * 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 3017 * eg, one which you put on and keep on for a while, and not something
3056 * AP_UNAPPLY=always unapply). 3026 * AP_UNAPPLY=always unapply).
3057 * 3027 *
3058 * Optional flags: 3028 * Optional flags:
3059 * AP_NO_MERGE: don't merge an unapplied object with other objects 3029 * AP_NO_MERGE: don't merge an unapplied object with other objects
3060 * AP_IGNORE_CURSE: unapply cursed items 3030 * AP_IGNORE_CURSE: unapply cursed items
3031 * AP_NO_READY: do not ready skills when applying skill tools
3061 * 3032 *
3062 * Usage example: apply_special (who, op, AP_UNAPPLY | AP_IGNORE_CURSE) 3033 * Usage example: apply_special (who, op, AP_UNAPPLY | AP_IGNORE_CURSE)
3063 * 3034 *
3064 * apply_special() doesn't check for unpaid items. 3035 * apply_special() doesn't check for unpaid items.
3065 */ 3036 */
3066int 3037int
3067apply_special (object *who, object *op, int aflags) 3038apply_special (object *who, object *op, int aflags)
3068{ 3039{
3069 int basic_flag = aflags & AP_BASIC_FLAGS; 3040 int basic_flag = aflags & AP_BASIC_FLAGS;
3070 object *tmp, *tmp2, *skop = NULL; 3041 object *tmp, *tmp2, *skop = NULL;
3071 int i;
3072 3042
3073 if (who == NULL) 3043 if (who == NULL)
3074 { 3044 {
3075 LOG (llevError, "apply_special() from object without environment.\n"); 3045 LOG (llevError, "apply_special() from object without environment.\n");
3076 return 1; 3046 return 1;
3086 if (basic_flag == AP_APPLY) 3056 if (basic_flag == AP_APPLY)
3087 return 0; 3057 return 0;
3088 3058
3089 if (!(aflags & AP_IGNORE_CURSE) && (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED))) 3059 if (!(aflags & AP_IGNORE_CURSE) && (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED)))
3090 { 3060 {
3091 new_draw_info_format (NDI_UNIQUE, 0, who, "No matter how hard you try, you just can't\nremove %s.", query_name (op)); 3061 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; 3062 return 1;
3093 } 3063 }
3064
3094 return unapply_special (who, op, aflags); 3065 return unapply_special (who, op, aflags);
3095 } 3066 }
3096 3067
3097 if (basic_flag == AP_UNAPPLY) 3068 if (basic_flag == AP_UNAPPLY)
3098 return 0; 3069 return 0;
3099 3070
3100 i = can_apply_object (who, op); 3071 // if the item is combat/ranged, wield the relevant slot first
3072 // to resolve conflicts.
3073 if (player *pl = who->contr)
3074 switch (op->slottype ())
3075 {
3076 case slot_combat: who->change_weapon (pl->combat_ob); break;
3077 case slot_ranged: who->change_weapon (pl->ranged_ob); break;
3078 }
3079
3080 splay (op);
3101 3081
3102 /* Can't just apply this object. Lets see what not and what to do */ 3082 /* Can't just apply this object. Lets see what not and what to do */
3103 if (i) 3083 if (int i = can_apply_object (who, op))
3104 { 3084 {
3105 if (i & CAN_APPLY_NEVER) 3085 if (i & CAN_APPLY_NEVER)
3106 { 3086 {
3107 new_draw_info_format (NDI_UNIQUE, 0, who, "You don't have the body to use a %s\n", query_name (op)); 3087 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; 3088 return 1;
3110 else if (i & CAN_APPLY_RESTRICTION) 3090 else if (i & CAN_APPLY_RESTRICTION)
3111 { 3091 {
3112 new_draw_info_format (NDI_UNIQUE, 0, who, "You have a prohibition against using a %s\n", query_name (op)); 3092 new_draw_info_format (NDI_UNIQUE, 0, who, "You have a prohibition against using a %s\n", query_name (op));
3113 return 1; 3093 return 1;
3114 } 3094 }
3095
3115 if (who->type != PLAYER) 3096 if (who->type != PLAYER)
3116 { 3097 {
3117 /* Some error, so don't try to equip something more */ 3098 /* Some error, so don't try to equip something more */
3118 if (unapply_for_ob (who, op, aflags)) 3099 if (unapply_for_ob (who, op, aflags))
3119 return 1; 3100 return 1;
3125 new_draw_info (NDI_UNIQUE, 0, who, "You need to unapply some of the following item(s) or change your applymode:"); 3106 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); 3107 unapply_for_ob (who, op, AP_PRINT);
3127 return 1; 3108 return 1;
3128 } 3109 }
3129 else if (who->contr->unapply == unapply_always || !(i & CAN_APPLY_UNAPPLY_CHOICE)) 3110 else if (who->contr->unapply == unapply_always || !(i & CAN_APPLY_UNAPPLY_CHOICE))
3130 {
3131 i = unapply_for_ob (who, op, aflags); 3111 if (unapply_for_ob (who, op, aflags))
3132 if (i)
3133 return 1; 3112 return 1;
3134 }
3135 } 3113 }
3136 } 3114 }
3137 3115
3138 if (op->skill && op->type != SKILL && op->type != SKILL_TOOL) 3116 if (op->skill && op->type != SKILL && op->type != SKILL_TOOL)
3139 { 3117 {
3140 skop = find_skill_by_name (who, op->skill); 3118 skop = find_skill_by_name (who, op->skill);
3119
3141 if (!skop) 3120 if (!skop)
3142 { 3121 {
3143 new_draw_info_format (NDI_UNIQUE, 0, who, "You need the %s skill to use this item!", &op->skill); 3122 new_draw_info_format (NDI_UNIQUE, 0, who, "You need the %s skill to use this item!", &op->skill);
3144 return 1; 3123 return 1;
3145 } 3124 }
3146 else 3125 else
3147 {
3148 /* While experience will be credited properly, we want to change the 3126 /* While experience will be credited properly, we want to change the
3149 * skill so that the dam and wc get updated 3127 * skill so that the dam and wc get updated
3150 */ 3128 */
3151 change_skill (who, skop, 0); 3129 who->change_skill (skop);
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 { 3130 }
3157 new_draw_info (NDI_UNIQUE, 0, who, "Equipping that combined with other items would consume your soul!"); 3131
3132 if (who->type == PLAYER
3133 && op->item_power
3134 && op->item_power + who->contr->item_power > settings.item_power_factor * who->level)
3135 {
3136 new_draw_info (NDI_UNIQUE, 0, who,
3137 "Equipping that combined with other items would consume your soul! "
3138 "[use the skills command to check your available item power]");
3158 return 1; 3139 return 1;
3159 } 3140 }
3160
3161 3141
3162 /* Ok. We are now at the state where we can apply the new object. 3142 /* 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_... 3143 * Note that we don't have the checks for can_use_...
3164 * below - that is already taken care of by can_apply_object. 3144 * below - that is already taken care of by can_apply_object.
3165 */ 3145 */
3166
3167
3168 if (op->nrof > 1) 3146 if (op->nrof > 1)
3169 tmp = get_split_ob (op, op->nrof - 1); 3147 tmp = get_split_ob (op, op->nrof - 1);
3170 else 3148 else
3171 tmp = NULL; 3149 tmp = 0;
3172 3150
3173 if (INVOKE_OBJECT (BE_READY, op, ARG_OBJECT (who)) || INVOKE_OBJECT (READY, who, ARG_OBJECT (op))) 3151 if (INVOKE_OBJECT (BE_READY, op, ARG_OBJECT (who)) || INVOKE_OBJECT (READY, who, ARG_OBJECT (op)))
3174 return RESULT_INT (0); 3152 return RESULT_INT (0);
3175 3153
3176 switch (op->type) 3154 switch (op->type)
3177 { 3155 {
3178 case WEAPON: 3156 case WEAPON:
3179 if (!check_weapon_power (who, op->last_eat)) 3157 if (!check_weapon_power (who, op->last_eat))
3180 { 3158 {
3181 new_draw_info (NDI_UNIQUE, 0, who, "That weapon is too powerful for you to use."); 3159 new_draw_info (NDI_UNIQUE, 0, who, "This weapon is too powerful for you to use. "
3182 new_draw_info (NDI_UNIQUE, 0, who, "It would consume your soul!."); 3160 "It would consume your soul!.");
3161
3183 if (tmp != NULL) 3162 if (tmp)
3184 (void) insert_ob_in_ob (tmp, who); 3163 insert_ob_in_ob (tmp, who);
3164
3185 return 1; 3165 return 1;
3186 } 3166 }
3187 3167
3188 //TODO: this obviously fails for players using a shiorter prefix 3168 //TODO: this obviously fails for players using a shorter prefix
3189 // i.e. "R" can use Ragnarok's swors. 3169 // i.e. "R" can use Ragnarok's sword.
3190 if (op->level && (strncmp (op->name, who->name, strlen (who->name)))) 3170 if (op->level && (strncmp (op->name, who->name, strlen (who->name))))
3191 { 3171 {
3192 /* if the weapon does not have the name as the character, can't use it. */ 3172 /* 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) */ 3173 /* (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."); 3174 new_draw_info (NDI_UNIQUE, 0, who, "The weapon does not recognize you as its owner.");
3197 insert_ob_in_ob (tmp, who); 3177 insert_ob_in_ob (tmp, who);
3198 3178
3199 return 1; 3179 return 1;
3200 } 3180 }
3201 3181
3182 if (!skop)
3183 {
3184 new_draw_info_format (NDI_UNIQUE, 0, who, "The %s is broken, please report this to the dungeon master!", query_name (op));//TODO
3185 return 1;
3186 }
3187
3202 SET_FLAG (op, FLAG_APPLIED); 3188 SET_FLAG (op, FLAG_APPLIED);
3203
3204 if (skop)
3205 change_skill (who, skop, 1); 3189 who->change_skill (skop);
3206 if (!QUERY_FLAG (who, FLAG_READY_WEAPON)) 3190
3207 SET_FLAG (who, FLAG_READY_WEAPON); 3191 if (who->contr)
3192 who->change_weapon (who->contr->combat_ob = op);
3208 3193
3209 new_draw_info_format (NDI_UNIQUE, 0, who, "You wield %s.", query_name (op)); 3194 new_draw_info_format (NDI_UNIQUE, 0, who, "You wield %s.", query_name (op));
3210 3195
3196 SET_FLAG (who, FLAG_READY_WEAPON);
3211 (void) change_abil (who, op); 3197 change_abil (who, op);
3212 break; 3198 break;
3213 3199
3214 case ARMOUR: 3200 case ARMOUR:
3215 case HELMET: 3201 case HELMET:
3216 case SHIELD: 3202 case SHIELD:
3221 case CLOAK: 3207 case CLOAK:
3222 case RING: 3208 case RING:
3223 case AMULET: 3209 case AMULET:
3224 SET_FLAG (op, FLAG_APPLIED); 3210 SET_FLAG (op, FLAG_APPLIED);
3225 new_draw_info_format (NDI_UNIQUE, 0, who, "You wear %s.", query_name (op)); 3211 new_draw_info_format (NDI_UNIQUE, 0, who, "You wear %s.", query_name (op));
3226 (void) change_abil (who, op); 3212 change_abil (who, op);
3227 break; 3213 break;
3214
3228 case LAMP: 3215 case LAMP:
3229 if (op->stats.food < 1) 3216 if (op->stats.food < 1)
3230 { 3217 {
3231 new_draw_info_format (NDI_UNIQUE, 0, who, "Your %s is out of" " fuel!", &op->name); 3218 new_draw_info_format (NDI_UNIQUE, 0, who, "Your %s is out of fuel!", &op->name);
3232 return 1; 3219 return 1;
3233 } 3220 }
3221
3234 new_draw_info_format (NDI_UNIQUE, 0, who, "You turn on your %s.", &op->name); 3222 new_draw_info_format (NDI_UNIQUE, 0, who, "You turn on your %s.", &op->name);
3235 tmp2 = arch_to_object (op->other_arch); 3223 tmp2 = arch_to_object (op->other_arch);
3236 tmp2->stats.food = op->stats.food; 3224 tmp2->stats.food = op->stats.food;
3237 SET_FLAG (tmp2, FLAG_APPLIED); 3225 SET_FLAG (tmp2, FLAG_APPLIED);
3226
3238 if (QUERY_FLAG (op, FLAG_INV_LOCKED)) 3227 if (QUERY_FLAG (op, FLAG_INV_LOCKED))
3239 SET_FLAG (tmp2, FLAG_INV_LOCKED); 3228 SET_FLAG (tmp2, FLAG_INV_LOCKED);
3229
3240 insert_ob_in_ob (tmp2, who); 3230 insert_ob_in_ob (tmp2, who);
3241 3231
3242 /* Remove the old lantern */ 3232 /* Remove the old lantern */
3243 if (who->type == PLAYER) 3233 if (who->type == PLAYER)
3244 esrv_del_item (who->contr, op->count); 3234 esrv_del_item (who->contr, op->count);
3245 3235
3246 op->destroy (); 3236 op->destroy ();
3247 3237
3248 /* insert the portion that was split off */ 3238 /* insert the portion that was split off */
3249 if (tmp != NULL) 3239 if (tmp)
3250 { 3240 {
3251 (void) insert_ob_in_ob (tmp, who); 3241 insert_ob_in_ob (tmp, who);
3252 if (who->type == PLAYER) 3242 if (who->type == PLAYER)
3253 esrv_send_item (who, tmp); 3243 esrv_send_item (who, tmp);
3254 } 3244 }
3245
3255 who->update_stats (); 3246 who->update_stats ();
3247
3256 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED)) 3248 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED))
3257 {
3258 if (who->type == PLAYER) 3249 if (who->type == PLAYER)
3259 { 3250 {
3260 new_draw_info (NDI_UNIQUE, 0, who, "Oops, it feels deadly cold!"); 3251 new_draw_info (NDI_UNIQUE, 0, who, "Oops, it feels deadly cold!");
3261 SET_FLAG (tmp2, FLAG_KNOWN_CURSED); 3252 SET_FLAG (tmp2, FLAG_KNOWN_CURSED);
3262 } 3253 }
3263 } 3254
3264 if (who->type == PLAYER) 3255 if (who->type == PLAYER)
3265 esrv_send_item (who, tmp2); 3256 esrv_send_item (who, tmp2);
3257
3266 return 0; 3258 return 0;
3259
3260 case SKILL_TOOL:
3261 // applying a skill tool also readies the skill
3262 SET_FLAG (op, FLAG_APPLIED);
3263
3264 if (!(aflags & AP_NO_READY))
3265 {
3266 skop = find_skill_by_name (who, op->skill);
3267 if (!skop->flag [FLAG_APPLIED])
3268 apply_special (who, skop, AP_APPLY);
3269 }
3267 break; 3270 break;
3268 3271
3269 /* this part is needed for skill-tools */
3270 case SKILL: 3272 case SKILL:
3271 case SKILL_TOOL: 3273 if (player *pl = who->contr)
3272 if (who->chosen_skill)
3273 { 3274 {
3274 LOG (llevError, "BUG: apply_special(): can't apply two skills\n"); 3275 if (IS_COMBAT_SKILL (op->subtype))
3275 return 1;
3276 }
3277 if (who->type == PLAYER)
3278 { 3276 {
3279 who->contr->shoottype = range_skill; 3277 if (skill_flags [op->subtype] & SF_NEED_WEAPON)
3280 who->contr->ranges[range_skill] = op; 3278 {
3279 for (object *item = who->inv; item; item = item->below)
3280 if (item->type == WEAPON && item->flag [FLAG_APPLIED])
3281 {
3282 if (item->skill == op->skill)
3283 {
3284 who->change_weapon (pl->combat_ob = item);
3285 goto found_weapon;
3286 }
3287 }
3288
3289 new_draw_info_format (NDI_UNIQUE, 0, who, "You need to apply a '%s' melee weapon before readying this skill", &op->skill);
3290 return 1;
3291
3292 found_weapon:;
3293 }
3294 else
3295 who->change_weapon (pl->combat_ob = op);
3296 }
3297 else if (IS_RANGED_SKILL (op->subtype))
3298 {
3299 if (skill_flags [op->subtype] & SF_NEED_BOW)
3300 {
3301 for (object *item = who->inv; item; item = item->below)
3302 if (item->type == BOW && item->flag [FLAG_APPLIED])
3303 {
3304 //TODO: bows should/must all have skill missile weapon right now
3305 who->change_weapon (pl->ranged_ob = item);
3306 goto found_bow;
3307 }
3308
3309 new_draw_info (NDI_UNIQUE, 0, who, "You need to apply a missile weapon before readying this skill");
3310 return 1;
3311
3312 found_bow:;
3313 }
3314 else
3315 who->change_weapon (pl->ranged_ob = op);
3316 }
3317
3281 if (!op->invisible) 3318 if (!op->invisible)
3282 { 3319 {
3283 new_draw_info_format (NDI_UNIQUE, 0, who, "You ready %s.", query_name (op)); 3320 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); 3321 new_draw_info_format (NDI_UNIQUE, 0, who, "You can now use the skill: %s.", &op->skill);
3285 } 3322 }
3286 else 3323 else
3287 {
3288 new_draw_info_format (NDI_UNIQUE, 0, who, "Readied skill: %s.", op->skill ? &op->skill : &op->name); 3324 new_draw_info_format (NDI_UNIQUE, 0, who, "Readied skill: %s.", op->skill ? &op->skill : &op->name);
3289 }
3290 } 3325 }
3326 else
3327 {
3291 SET_FLAG (op, FLAG_APPLIED); 3328 SET_FLAG (op, FLAG_APPLIED);
3292 (void) change_abil (who, op); 3329 change_abil (who, op);
3293 who->chosen_skill = op; 3330 who->chosen_skill = op;
3294 SET_FLAG (who, FLAG_READY_SKILL); 3331 SET_FLAG (who, FLAG_READY_SKILL);
3332 }
3333
3295 break; 3334 break;
3296 3335
3297 case BOW: 3336 case BOW:
3298 if (!check_weapon_power (who, op->last_eat)) 3337 if (!check_weapon_power (who, op->last_eat))
3299 { 3338 {
3300 new_draw_info (NDI_UNIQUE, 0, who, "That item is too powerful for you to use."); 3339 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!."); 3340 new_draw_info (NDI_UNIQUE, 0, who, "It would consume your soul!.");
3341
3302 if (tmp != NULL) 3342 if (tmp)
3303 (void) insert_ob_in_ob (tmp, who); 3343 insert_ob_in_ob (tmp, who);
3344
3304 return 1; 3345 return 1;
3305 } 3346 }
3347
3306 if (op->level && (strncmp (op->name, who->name, strlen (who->name)))) 3348 if (op->level && (strncmp (op->name, who->name, strlen (who->name))))
3307 { 3349 {
3308 new_draw_info (NDI_UNIQUE, 0, who, "The weapon does not recognize you as its owner."); 3350 new_draw_info (NDI_UNIQUE, 0, who, "The weapon does not recognize you as its owner.");
3309 if (tmp != NULL) 3351 if (tmp)
3310 (void) insert_ob_in_ob (tmp, who); 3352 insert_ob_in_ob (tmp, who);
3353
3311 return 1; 3354 return 1;
3312 } 3355 }
3356
3313 /*FALLTHROUGH*/ case WAND: 3357 /*FALLTHROUGH*/
3358 case WAND:
3314 case ROD: 3359 case ROD:
3315 case HORN: 3360 case HORN:
3316 /* check for skill, alter player status */ 3361 /* check for skill, alter player status */
3362
3363 if (!skop)
3364 {
3365 new_draw_info_format (NDI_UNIQUE, 0, who, "The %s is broken, please report this to the dungeon master!", query_name (op));//TODO
3366 return 1;
3367 }
3368
3317 SET_FLAG (op, FLAG_APPLIED); 3369 SET_FLAG (op, FLAG_APPLIED);
3318 if (skop)
3319 change_skill (who, skop, 0); 3370 who->change_skill (skop);
3320 new_draw_info_format (NDI_UNIQUE, 0, who, "You ready %s.", query_name (op));
3321 3371
3322 if (who->type == PLAYER) 3372 if (who->contr)
3323 { 3373 {
3374 who->contr->ranged_ob = op;
3375
3376 new_draw_info_format (NDI_UNIQUE, 0, who, "You ready %s.", query_name (op));
3377
3324 if (op->type == BOW) 3378 if (op->type == BOW)
3325 { 3379 {
3380 who->current_weapon = op;
3326 (void) change_abil (who, op); 3381 change_abil (who, op);
3327 new_draw_info_format (NDI_UNIQUE, 0, who, 3382 new_draw_info_format (NDI_UNIQUE, 0, who,
3328 "You will now fire %s with %s.", op->race ? &op->race : "nothing", query_name (op)); 3383 "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 } 3384 }
3335 } 3385 }
3336 else 3386 else
3337 { 3387 {
3338 if (op->type == BOW) 3388 if (op->type == BOW)
3339 SET_FLAG (who, FLAG_READY_BOW); 3389 SET_FLAG (who, FLAG_READY_BOW);
3340 else 3390 else
3341 SET_FLAG (who, FLAG_READY_RANGE); 3391 SET_FLAG (who, FLAG_READY_RANGE);
3342 } 3392 }
3393
3343 break; 3394 break;
3344 3395
3345 case BUILDER: 3396 case BUILDER:
3346 if (who->contr->ranges[range_builder]) 3397 if (who->type == PLAYER)
3398 {
3399 //TODO: wtf does this do? shouldn't this be managed automatically (slots?)
3400 if (who->contr->ranged_ob && who->contr->ranged_ob->type == BUILDER)
3347 unapply_special (who, who->contr->ranges[range_builder], 0); 3401 unapply_special (who, who->contr->ranged_ob, 0);
3348 who->contr->shoottype = range_builder; 3402
3349 who->contr->ranges[range_builder] = op;
3350 new_draw_info_format (NDI_UNIQUE, 0, who, "You ready your %s.", query_name (op)); 3403 new_draw_info_format (NDI_UNIQUE, 0, who, "You ready your %s.", query_name (op));
3404
3405 who->contr->ranged_ob = op;
3406 }
3351 break; 3407 break;
3352 3408
3353 default: 3409 default:
3354 new_draw_info_format (NDI_UNIQUE, 0, who, "You apply %s.", query_name (op)); 3410 new_draw_info_format (NDI_UNIQUE, 0, who, "You apply %s.", query_name (op));
3355 } /* end of switch op->type */ 3411 } /* end of switch op->type */
3356 3412
3357 SET_FLAG (op, FLAG_APPLIED); 3413 SET_FLAG (op, FLAG_APPLIED);
3358 3414
3359 if (tmp != NULL) 3415 if (tmp)
3360 tmp = insert_ob_in_ob (tmp, who); 3416 tmp = insert_ob_in_ob (tmp, who);
3361 3417
3362 who->update_stats (); 3418 who->update_stats ();
3363 3419
3364 /* We exclude spell casting objects. The fire code will set the 3420 /* We exclude spell casting objects. The fire code will set the
3374 { 3430 {
3375 new_draw_info (NDI_UNIQUE, 0, who, "Oops, it feels deadly cold!"); 3431 new_draw_info (NDI_UNIQUE, 0, who, "Oops, it feels deadly cold!");
3376 SET_FLAG (op, FLAG_KNOWN_CURSED); 3432 SET_FLAG (op, FLAG_KNOWN_CURSED);
3377 } 3433 }
3378 } 3434 }
3435
3379 if (who->type == PLAYER) 3436 if (who->type == PLAYER)
3380 { 3437 {
3381 /* if multiple objects were applied, update both slots */ 3438 /* if multiple objects were applied, update both slots */
3382 if (tmp) 3439 if (tmp)
3383 esrv_send_item (who, tmp); 3440 esrv_send_item (who, tmp);
3441
3384 esrv_send_item (who, op); 3442 esrv_send_item (who, op);
3385 } 3443 }
3444
3386 return 0; 3445 return 0;
3387} 3446}
3388
3389 3447
3390int 3448int
3391monster_apply_special (object *who, object *op, int aflags) 3449monster_apply_special (object *who, object *op, int aflags)
3392{ 3450{
3393 if (QUERY_FLAG (op, FLAG_UNPAID) && !QUERY_FLAG (op, FLAG_APPLIED)) 3451 if (QUERY_FLAG (op, FLAG_UNPAID) && !QUERY_FLAG (op, FLAG_APPLIED))
3552 && tmp->type != PLAYER_CHANGER && tmp->type != CLASS && tmp->has_random_items ()) 3610 && tmp->type != PLAYER_CHANGER && tmp->type != CLASS && tmp->has_random_items ())
3553 { 3611 {
3554 create_treasure (tmp->randomitems, tmp, GT_APPLY, difficulty, 0); 3612 create_treasure (tmp->randomitems, tmp, GT_APPLY, difficulty, 0);
3555 tmp->randomitems = NULL; 3613 tmp->randomitems = NULL;
3556 } 3614 }
3615
3557 // close all containers 3616 // close all containers
3558 else if (tmp->type == CONTAINER) 3617 else if (tmp->type == CONTAINER)
3559 tmp->flag [FLAG_APPLIED] = 0; 3618 tmp->flag [FLAG_APPLIED] = 0;
3560 3619
3561 tmp = above; 3620 tmp = above;
3571 * Handles player eating food that temporarily changes status (resistances, stats). 3630 * Handles player eating food that temporarily changes status (resistances, stats).
3572 * This used to call cast_change_attr(), but 3631 * This used to call cast_change_attr(), but
3573 * that doesn't work with the new spell code. Since we know what 3632 * 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. 3633 * the food changes, just grab a force and use that instead.
3575 */ 3634 */
3576
3577void 3635void
3578eat_special_food (object *who, object *food) 3636eat_special_food (object *who, object *food)
3579{ 3637{
3580 object *force; 3638 object *force;
3581 int i, did_one = 0; 3639 int i, did_one = 0;
3582 sint8 k;
3583 3640
3584 force = get_archetype (FORCE_NAME); 3641 force = get_archetype (FORCE_NAME);
3585 3642
3586 for (i = 0; i < NUM_STATS; i++) 3643 for (i = 0; i < NUM_STATS; i++)
3587 { 3644 if (sint8 k = food->stats.stat (i))
3588 k = get_attr_value (&food->stats, i);
3589 if (k)
3590 { 3645 {
3591 set_attr_value (&force->stats, i, k); 3646 force->stats.stat (i) = k;
3592 did_one = 1; 3647 did_one = 1;
3593 } 3648 }
3594 }
3595 3649
3596 /* check if we can protect the eater */ 3650 /* check if we can protect the eater */
3597 for (i = 0; i < NROFATTACKS; i++) 3651 for (i = 0; i < NROFATTACKS; i++)
3598 { 3652 {
3599 if (food->resist[i] > 0) 3653 if (food->resist[i] > 0)
3760 new_draw_info (NDI_UNIQUE, 0, op, "The magic recoils on you!"); 3814 new_draw_info (NDI_UNIQUE, 0, op, "The magic recoils on you!");
3761 blind_player (op, op, power); 3815 blind_player (op, op, power);
3762 } 3816 }
3763 else if (failure <= -80) 3817 else if (failure <= -80)
3764 { /* blast the immediate area */ 3818 { /* blast the immediate area */
3765 object *tmp;
3766
3767 tmp = get_archetype (LOOSE_MANA); 3819 object *tmp = get_archetype (LOOSE_MANA);
3768 cast_magic_storm (op, tmp, power); 3820 cast_magic_storm (op, tmp, power);
3769 new_draw_info (NDI_UNIQUE, 0, op, "You unlease uncontrolled mana!"); 3821 new_draw_info (NDI_UNIQUE, 0, op, "You unleash uncontrolled mana!");
3770 tmp->destroy (); 3822 tmp->destroy ();
3771 } 3823 }
3772 } 3824 }
3773} 3825}
3774 3826
3794 */ 3846 */
3795 int i, j; 3847 int i, j;
3796 3848
3797 for (i = 0; i < NUM_STATS; i++) 3849 for (i = 0; i < NUM_STATS; i++)
3798 { 3850 {
3799 sint8 stat = get_attr_value (stats, i);
3800 int race_bonus = get_attr_value (&(pl->arch->clone.stats), i); 3851 int race_bonus = pl->arch->clone.stats.stat (i);
3852 sint8 stat = stats->stat (i) + ns->stat (i);
3801 3853
3802 stat += get_attr_value (ns, i);
3803 if (stat > 20 + race_bonus) 3854 if (stat > 20 + race_bonus)
3804 { 3855 {
3805 excess_stat++; 3856 excess_stat++;
3806 stat = 20 + race_bonus; 3857 stat = 20 + race_bonus;
3807 } 3858 }
3808 set_attr_value (stats, i, stat); 3859
3860 stats->stat (i) = stat;
3809 } 3861 }
3810 3862
3811 for (j = 0; excess_stat > 0 && j < 100; j++) 3863 for (j = 0; excess_stat > 0 && j < 100; j++)
3812 { /* try 100 times to assign excess stats */ 3864 { /* try 100 times to assign excess stats */
3813 int i = rndm (0, 6); 3865 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 3866
3817 if (i == CHA) 3867 if (i == CHA)
3818 continue; /* exclude cha from this */ 3868 continue; /* exclude cha from this */
3869
3870 int stat = stats->stat (i);
3871 int race_bonus = pl->arch->clone.stats.stat (i);
3819 if (stat < 20 + race_bonus) 3872 if (stat < 20 + race_bonus)
3820 { 3873 {
3821 change_attr_value (stats, i, 1); 3874 change_attr_value (stats, i, 1);
3822 excess_stat--; 3875 excess_stat--;
3823 } 3876 }
3826 /* insert the randomitems from the change's treasurelist into 3879 /* insert the randomitems from the change's treasurelist into
3827 * the player ref: player.c 3880 * the player ref: player.c
3828 */ 3881 */
3829 if (change->randomitems != NULL) 3882 if (change->randomitems != NULL)
3830 give_initial_items (pl, change->randomitems); 3883 give_initial_items (pl, change->randomitems);
3831
3832 3884
3833 /* set up the face, for some races. */ 3885 /* set up the face, for some races. */
3834 3886
3835 /* first, look for the force object banning 3887 /* first, look for the force object banning
3836 * changing the face. Certain races never change face with class. 3888 * changing the face. Certain races never change face with class.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines