… | |
… | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the GNU General Public License |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | * |
20 | * |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
22 | */ |
23 | |
23 | |
24 | #include <cmath> |
24 | #include <cmath> |
25 | |
25 | |
… | |
… | |
2342 | |
2342 | |
2343 | return 0; |
2343 | return 0; |
2344 | } |
2344 | } |
2345 | |
2345 | |
2346 | /** |
2346 | /** |
|
|
2347 | * This function will try to apply a lighter and in case no lighter |
|
|
2348 | * is specified it will try to find a lighter in the players inventory, |
|
|
2349 | * and inform him about this requirement. |
|
|
2350 | * |
|
|
2351 | * who - the player |
|
|
2352 | * op - the item we want to light |
|
|
2353 | * ligher - the lighter or 0 if a lighter has yet to be found |
|
|
2354 | */ |
|
|
2355 | object *auto_apply_lighter (object *who, object *op, object *lighter) |
|
|
2356 | { |
|
|
2357 | if (lighter == 0) |
|
|
2358 | { |
|
|
2359 | for (object *tmp = who->inv; tmp; tmp = tmp->below) |
|
|
2360 | { |
|
|
2361 | if (tmp->type == LIGHTER) |
|
|
2362 | { |
|
|
2363 | lighter = tmp; |
|
|
2364 | break; |
|
|
2365 | } |
|
|
2366 | } |
|
|
2367 | |
|
|
2368 | if (!lighter) |
|
|
2369 | { |
|
|
2370 | who->failmsg (format ( |
|
|
2371 | "You can't light up the %s with your bare hands! " |
|
|
2372 | "H<You need a lighter in your inventory, for example a flint and steel.>", |
|
|
2373 | &op->name)); |
|
|
2374 | return 0; |
|
|
2375 | } |
|
|
2376 | } |
|
|
2377 | |
|
|
2378 | // last_eat == 0 means the lighter is not being used up! |
|
|
2379 | if (lighter->last_eat && lighter->stats.food) |
|
|
2380 | { |
|
|
2381 | /* lighter gets used up */ |
|
|
2382 | lighter = lighter->split (); |
|
|
2383 | lighter->stats.food--; |
|
|
2384 | who->insert (lighter); |
|
|
2385 | } |
|
|
2386 | else if (lighter->last_eat) |
|
|
2387 | { |
|
|
2388 | /* no charges left in lighter */ |
|
|
2389 | who->failmsg (format ( |
|
|
2390 | "You attempt to light the %s with a used up %s.", |
|
|
2391 | &op->name, &lighter->name)); |
|
|
2392 | return 0; |
|
|
2393 | } |
|
|
2394 | |
|
|
2395 | return lighter; |
|
|
2396 | } |
|
|
2397 | |
|
|
2398 | /** |
|
|
2399 | * Designed primarily to light torches/lanterns/etc. |
|
|
2400 | * Also burns up burnable material too. First object in the inventory is |
|
|
2401 | * the selected object to "burn". -b.t. |
|
|
2402 | */ |
|
|
2403 | void |
|
|
2404 | apply_lighter (object *who, object *lighter) |
|
|
2405 | { |
|
|
2406 | object *item; |
|
|
2407 | int is_player_env = 0; |
|
|
2408 | |
|
|
2409 | item = find_marked_object (who); |
|
|
2410 | if (item) |
|
|
2411 | { |
|
|
2412 | if (!auto_apply_lighter (who, 0, lighter)) |
|
|
2413 | return; |
|
|
2414 | |
|
|
2415 | /* Perhaps we should split what we are trying to light on fire? |
|
|
2416 | * I can't see many times when you would want to light multiple |
|
|
2417 | * objects at once. |
|
|
2418 | */ |
|
|
2419 | |
|
|
2420 | save_throw_object (item, AT_FIRE, who); |
|
|
2421 | |
|
|
2422 | if (item->destroyed () |
|
|
2423 | || ((item->type == LAMP || item->type == TORCH) |
|
|
2424 | && item->glow_radius > 0)) |
|
|
2425 | who->statusmsg (format ( |
|
|
2426 | "You light the %s with the %s.", |
|
|
2427 | &item->name, &lighter->name)); |
|
|
2428 | else |
|
|
2429 | who->failmsg (format ( |
|
|
2430 | "You attempt to light the %s with the %s and fail.", |
|
|
2431 | &item->name, &lighter->name)); |
|
|
2432 | } |
|
|
2433 | else |
|
|
2434 | who->failmsg ("You need to mark a lightable object."); |
|
|
2435 | } |
|
|
2436 | |
|
|
2437 | /** |
|
|
2438 | * Apply for players and lamps |
|
|
2439 | * |
|
|
2440 | * who - the player |
|
|
2441 | * op - the lamp |
|
|
2442 | */ |
|
|
2443 | void player_apply_lamp (object *who, object *op) |
|
|
2444 | { |
|
|
2445 | bool switch_on = op->glow_radius ? false : true; |
|
|
2446 | |
|
|
2447 | if (switch_on) |
|
|
2448 | { |
|
|
2449 | object *lighter = 0; |
|
|
2450 | |
|
|
2451 | if (op->flag [FLAG_IS_LIGHTABLE] |
|
|
2452 | && !(lighter = auto_apply_lighter (who, op, 0))) |
|
|
2453 | return; |
|
|
2454 | |
|
|
2455 | if (op->stats.food < 1) |
|
|
2456 | { |
|
|
2457 | if (op->type == LAMP) |
|
|
2458 | who->failmsg (format ( |
|
|
2459 | "The %s is out of fuel! " |
|
|
2460 | "H<Lamps and similar items need fuel. They cannot be refilled.>", |
|
|
2461 | &op->name)); |
|
|
2462 | else |
|
|
2463 | who->failmsg (format ( |
|
|
2464 | "The %s is burnt out! " |
|
|
2465 | "H<Torches and similar items burn out and become worthless.>", |
|
|
2466 | &op->name)); |
|
|
2467 | return; |
|
|
2468 | } |
|
|
2469 | |
|
|
2470 | if (lighter) |
|
|
2471 | who->statusmsg (format ( |
|
|
2472 | "You light up the %s with the %s.", &op->name, &lighter->name)); |
|
|
2473 | else |
|
|
2474 | who->statusmsg (format ("You light up the %s.", &op->name)); |
|
|
2475 | } |
|
|
2476 | else |
|
|
2477 | { |
|
|
2478 | if (op->type == TORCH) |
|
|
2479 | { |
|
|
2480 | if (!op->flag [FLAG_IS_LIGHTABLE]) |
|
|
2481 | { |
|
|
2482 | who->statusmsg (format ( |
|
|
2483 | "You put out the %s. " |
|
|
2484 | "H<The %s can't be used anymore, as it can't be lighted up again.>", |
|
|
2485 | &op->name, &op->name)); |
|
|
2486 | } |
|
|
2487 | else |
|
|
2488 | who->statusmsg (format ( |
|
|
2489 | "You put out the %s." |
|
|
2490 | "H<Torches wear out if you put them out.>", |
|
|
2491 | &op->name)); |
|
|
2492 | } |
|
|
2493 | else |
|
|
2494 | who->statusmsg (format ("You turn off the %s.", &op->name)); |
|
|
2495 | } |
|
|
2496 | |
|
|
2497 | apply_lamp (op, switch_on); |
|
|
2498 | } |
|
|
2499 | |
|
|
2500 | void lamp_get_animation_from_arch (object *op, arch_ptr a) |
|
|
2501 | { |
|
|
2502 | op->animation_id = a->animation_id; |
|
|
2503 | op->flag [FLAG_IS_TURNABLE] = a->flag [FLAG_IS_TURNABLE]; |
|
|
2504 | op->flag [FLAG_ANIMATE] = a->flag [FLAG_ANIMATE]; |
|
|
2505 | op->anim_speed = a->anim_speed; |
|
|
2506 | op->last_anim = 0; |
|
|
2507 | op->state = 0; |
|
|
2508 | op->face = a->face; |
|
|
2509 | |
|
|
2510 | if (NUM_ANIMATIONS(op) > 1) |
|
|
2511 | { |
|
|
2512 | SET_ANIMATION(op, 0); |
|
|
2513 | animate_object (op, op->direction); |
|
|
2514 | } |
|
|
2515 | else |
|
|
2516 | update_object (op, UP_OBJ_FACE); |
|
|
2517 | } |
|
|
2518 | |
|
|
2519 | /** |
|
|
2520 | * Apply for LAMPs and TORCHes. |
|
|
2521 | * |
|
|
2522 | * op - the lamp |
|
|
2523 | * switch_on - a flag which says whether the lamp should be switched on or off |
|
|
2524 | */ |
|
|
2525 | void apply_lamp (object *op, bool switch_on) |
|
|
2526 | { |
|
|
2527 | op->set_glow_radius (switch_on ? op->range : 0); |
|
|
2528 | op->set_speed (switch_on ? op->arch->speed : 0); |
|
|
2529 | |
|
|
2530 | // torches wear out if you put them out |
|
|
2531 | if (op->type == TORCH && !switch_on) |
|
|
2532 | { |
|
|
2533 | if (op->flag [FLAG_IS_LIGHTABLE]) |
|
|
2534 | { |
|
|
2535 | op->stats.food -= (double) op->arch->stats.food / 15; |
|
|
2536 | if (op->stats.food < 0) |
|
|
2537 | op->stats.food = 0; |
|
|
2538 | } |
|
|
2539 | else |
|
|
2540 | op->stats.food = 0; |
|
|
2541 | } |
|
|
2542 | |
|
|
2543 | // lamps and torched get worthless when used up |
|
|
2544 | if (op->stats.food <= 0) |
|
|
2545 | op->value = 0; |
|
|
2546 | |
|
|
2547 | // FIXME: This is a hack to make the more sane torches and lamps |
|
|
2548 | // still animated ;-/ |
|
|
2549 | if (op->other_arch) |
|
|
2550 | lamp_get_animation_from_arch (op, switch_on ? op->other_arch : op->arch); |
|
|
2551 | |
|
|
2552 | if (object *pl = op->visible_to ()) |
|
|
2553 | esrv_update_item (UPD_ANIM | UPD_FACE | UPD_NAME, pl, op); |
|
|
2554 | } |
|
|
2555 | |
|
|
2556 | /** |
2347 | * Main apply handler. |
2557 | * Main apply handler. |
2348 | * |
2558 | * |
2349 | * Checks for unpaid items before applying. |
2559 | * Checks for unpaid items before applying. |
2350 | * |
2560 | * |
2351 | * Return value: |
2561 | * Return value: |
2352 | * 0: player or monster can't apply objects of that type |
2562 | * 0: player or monster can't apply objects of that type |
2353 | * 1: has been applied, or there was an error applying the object |
2563 | * 1: has been applied, or there was an error applying the object |
2354 | * 2: objects of that type can't be applied if not in inventory |
2564 | * 2: objects of that type can't be applied if not in inventory |
2355 | * |
2565 | * |
2356 | * op is the object that is causing object to be applied, tmp is the object |
2566 | * who is the object that is causing object to be applied, op is the object |
2357 | * being applied. |
2567 | * being applied. |
2358 | * |
2568 | * |
2359 | * aflag is special (always apply/unapply) flags. Nothing is done with |
2569 | * aflag is special (always apply/unapply) flags. Nothing is done with |
2360 | * them in this function - they are passed to apply_special |
2570 | * them in this function - they are passed to apply_special |
2361 | */ |
2571 | */ |
2362 | int |
2572 | int |
2363 | manual_apply (object *op, object *tmp, int aflag) |
2573 | manual_apply (object *who, object *op, int aflag) |
2364 | { |
2574 | { |
2365 | tmp = tmp->head_ (); |
2575 | op = op->head_ (); |
2366 | |
2576 | |
2367 | if (QUERY_FLAG (tmp, FLAG_UNPAID) && !QUERY_FLAG (tmp, FLAG_APPLIED)) |
2577 | if (QUERY_FLAG (op, FLAG_UNPAID) && !QUERY_FLAG (op, FLAG_APPLIED)) |
2368 | { |
2578 | { |
2369 | if (op->type == PLAYER) |
2579 | if (who->type == PLAYER) |
2370 | { |
2580 | { |
2371 | op->failmsg ("You should pay for it first! H<You cannot use items marked as unpaid.>"); |
2581 | who->failmsg ("You should pay for it first! H<You cannot use items marked as unpaid.>"); |
2372 | return 1; |
2582 | return 1; |
2373 | } |
2583 | } |
2374 | else |
2584 | else |
2375 | return 0; /* monsters just skip unpaid items */ |
2585 | return 0; /* monsters just skip unpaid items */ |
2376 | } |
2586 | } |
2377 | |
2587 | |
2378 | if (INVOKE_OBJECT (APPLY, tmp, ARG_OBJECT (op))) |
2588 | if (INVOKE_OBJECT (APPLY, op, ARG_OBJECT (who))) |
2379 | return RESULT_INT (0); |
2589 | return RESULT_INT (0); |
2380 | |
2590 | |
2381 | switch (tmp->type) |
2591 | switch (op->type) |
2382 | { |
2592 | { |
2383 | case CF_HANDLE: |
2593 | case CF_HANDLE: |
2384 | op->play_sound (sound_find ("turn_handle")); |
2594 | who->play_sound (sound_find ("turn_handle")); |
2385 | op->statusmsg ("You turn the handle."); |
2595 | who->statusmsg ("You turn the handle."); |
2386 | tmp->value = tmp->value ? 0 : 1; |
2596 | op->value = op->value ? 0 : 1; |
2387 | SET_ANIMATION (tmp, tmp->value); |
2597 | SET_ANIMATION (op, op->value); |
2388 | update_object (tmp, UP_OBJ_FACE); |
2598 | update_object (op, UP_OBJ_FACE); |
2389 | push_button (tmp, op); |
2599 | push_button (op, who); |
2390 | return 1; |
2600 | return 1; |
2391 | |
2601 | |
2392 | case TRIGGER: |
2602 | case TRIGGER: |
2393 | if (check_trigger (tmp, op)) |
2603 | if (check_trigger (op, who)) |
2394 | { |
2604 | { |
2395 | op->statusmsg ("You turn the handle."); |
2605 | who->statusmsg ("You turn the handle."); |
2396 | op->play_sound (sound_find ("turn_handle")); |
2606 | who->play_sound (sound_find ("turn_handle")); |
2397 | } |
2607 | } |
2398 | else |
2608 | else |
2399 | op->failmsg ("The handle doesn't move."); |
2609 | who->failmsg ("The handle doesn't move."); |
2400 | |
2610 | |
2401 | return 1; |
2611 | return 1; |
2402 | |
2612 | |
2403 | case EXIT: |
2613 | case EXIT: |
2404 | if (op->type != PLAYER) |
2614 | if (who->type != PLAYER) |
2405 | return 0; |
2615 | return 0; |
2406 | |
2616 | |
2407 | if (!EXIT_PATH (tmp) || !is_legal_2ways_exit (op, tmp)) |
2617 | if (!EXIT_PATH (op) || !is_legal_2ways_exit (who, op)) |
2408 | op->failmsg (format ("The %s is closed.", query_name (tmp))); |
2618 | who->failmsg (format ("The %s is closed.", query_name (op))); |
2409 | else |
2619 | else |
2410 | { |
2620 | { |
2411 | /* Don't display messages for random maps. */ |
2621 | /* Don't display messages for random maps. */ |
2412 | if (tmp->msg && !EXIT_PATH (tmp).starts_with ("/!")) |
2622 | if (op->msg && !EXIT_PATH (op).starts_with ("/!")) |
2413 | op->statusmsg (tmp->msg, NDI_NAVY); |
2623 | who->statusmsg (op->msg, NDI_NAVY); |
2414 | |
2624 | |
2415 | op->enter_exit (tmp); |
2625 | who->enter_exit (op); |
2416 | } |
2626 | } |
2417 | |
2627 | |
2418 | return 1; |
2628 | return 1; |
2419 | |
2629 | |
2420 | case INSCRIBABLE: |
2630 | case INSCRIBABLE: |
2421 | op->statusmsg (tmp->msg); |
2631 | who->statusmsg (op->msg); |
2422 | // maybe show a spell menu to chose from or something like that |
2632 | // maybe show a spell menu to chose from or something like that |
2423 | return 1; |
2633 | return 1; |
2424 | |
2634 | |
2425 | case SIGN: |
2635 | case SIGN: |
2426 | apply_sign (op, tmp, 0); |
2636 | apply_sign (who, op, 0); |
2427 | return 1; |
2637 | return 1; |
2428 | |
2638 | |
2429 | case BOOK: |
2639 | case BOOK: |
2430 | if (op->type == PLAYER) |
2640 | if (who->type == PLAYER) |
2431 | { |
2641 | { |
2432 | apply_book (op, tmp); |
2642 | apply_book (who, op); |
2433 | return 1; |
2643 | return 1; |
2434 | } |
2644 | } |
2435 | else |
2645 | else |
2436 | return 0; |
2646 | return 0; |
2437 | |
2647 | |
2438 | case SKILLSCROLL: |
2648 | case SKILLSCROLL: |
2439 | if (op->type == PLAYER) |
2649 | if (who->type == PLAYER) |
2440 | { |
2650 | { |
2441 | apply_skillscroll (op, tmp); |
2651 | apply_skillscroll (who, op); |
2442 | return 1; |
2652 | return 1; |
2443 | } |
2653 | } |
2444 | else |
2654 | else |
2445 | return 0; |
2655 | return 0; |
2446 | |
2656 | |
2447 | case SPELLBOOK: |
2657 | case SPELLBOOK: |
2448 | if (op->type == PLAYER) |
2658 | if (who->type == PLAYER) |
2449 | { |
2659 | { |
2450 | apply_spellbook (op, tmp); |
2660 | apply_spellbook (who, op); |
2451 | return 1; |
2661 | return 1; |
2452 | } |
2662 | } |
2453 | else |
2663 | else |
2454 | return 0; |
2664 | return 0; |
2455 | |
2665 | |
2456 | case SCROLL: |
2666 | case SCROLL: |
2457 | apply_scroll (op, tmp, 0); |
2667 | apply_scroll (who, op, 0); |
2458 | return 1; |
2668 | return 1; |
2459 | |
2669 | |
2460 | case POTION: |
2670 | case POTION: |
2461 | apply_potion (op, tmp); |
2671 | apply_potion (who, op); |
2462 | return 1; |
2672 | return 1; |
2463 | |
2673 | |
2464 | /* Eneq(@csd.uu.se): Handle apply on containers. */ |
2674 | /* Eneq(@csd.uu.se): Handle apply on containers. */ |
2465 | //TODO: remove, as it is unsed? |
2675 | //TODO: remove, as it is unsed? |
2466 | case CLOSE_CON: |
2676 | case CLOSE_CON: |
2467 | apply_container (op, tmp->env); |
2677 | apply_container (who, op->env); |
2468 | return 1; |
2678 | return 1; |
2469 | |
2679 | |
2470 | case CONTAINER: |
2680 | case CONTAINER: |
2471 | apply_container (op, tmp); |
2681 | apply_container (who, op); |
2472 | return 1; |
2682 | return 1; |
2473 | |
2683 | |
2474 | case TREASURE: |
2684 | case TREASURE: |
2475 | if (op->type == PLAYER) |
2685 | if (who->type == PLAYER) |
2476 | { |
2686 | { |
2477 | apply_treasure (op, tmp); |
2687 | apply_treasure (who, op); |
2478 | return 1; |
2688 | return 1; |
2479 | } |
2689 | } |
2480 | else |
2690 | else |
2481 | return 0; |
2691 | return 0; |
|
|
2692 | |
|
|
2693 | case LAMP: |
|
|
2694 | case TORCH: |
|
|
2695 | player_apply_lamp (who, op); |
|
|
2696 | return 1; |
2482 | |
2697 | |
2483 | case WEAPON: |
2698 | case WEAPON: |
2484 | case ARMOUR: |
2699 | case ARMOUR: |
2485 | case BOOTS: |
2700 | case BOOTS: |
2486 | case GLOVES: |
2701 | case GLOVES: |
… | |
… | |
2494 | case WAND: |
2709 | case WAND: |
2495 | case ROD: |
2710 | case ROD: |
2496 | case HORN: |
2711 | case HORN: |
2497 | case SKILL: |
2712 | case SKILL: |
2498 | case BOW: |
2713 | case BOW: |
2499 | case LAMP: |
|
|
2500 | case BUILDER: |
2714 | case BUILDER: |
2501 | case SKILL_TOOL: |
2715 | case SKILL_TOOL: |
2502 | if (tmp->env != op) |
2716 | if (op->env != who) |
2503 | return 2; /* not in inventory */ |
2717 | return 2; /* not in inventory */ |
2504 | |
2718 | |
2505 | apply_special (op, tmp, aflag); |
2719 | apply_special (who, op, aflag); |
2506 | return 1; |
2720 | return 1; |
2507 | |
2721 | |
2508 | case DRINK: |
2722 | case DRINK: |
2509 | case FOOD: |
2723 | case FOOD: |
2510 | case FLESH: |
2724 | case FLESH: |
2511 | apply_food (op, tmp); |
2725 | apply_food (who, op); |
2512 | return 1; |
2726 | return 1; |
2513 | |
2727 | |
2514 | case POISON: |
2728 | case POISON: |
2515 | apply_poison (op, tmp); |
2729 | apply_poison (who, op); |
2516 | return 1; |
2730 | return 1; |
2517 | |
2731 | |
2518 | case SAVEBED: |
2732 | case SAVEBED: |
2519 | return 1; |
2733 | return 1; |
2520 | |
2734 | |
2521 | case ARMOUR_IMPROVER: |
2735 | case ARMOUR_IMPROVER: |
2522 | if (op->type == PLAYER) |
2736 | if (who->type == PLAYER) |
2523 | { |
2737 | { |
2524 | apply_armour_improver (op, tmp); |
2738 | apply_armour_improver (who, op); |
2525 | return 1; |
2739 | return 1; |
2526 | } |
2740 | } |
2527 | else |
2741 | else |
2528 | return 0; |
2742 | return 0; |
2529 | |
2743 | |
2530 | case WEAPON_IMPROVER: |
2744 | case WEAPON_IMPROVER: |
2531 | check_improve_weapon (op, tmp); |
2745 | check_improve_weapon (who, op); |
2532 | return 1; |
2746 | return 1; |
2533 | |
2747 | |
2534 | case CLOCK: |
2748 | case CLOCK: |
2535 | if (op->type == PLAYER) |
2749 | if (who->type == PLAYER) |
2536 | { |
2750 | { |
2537 | char buf[MAX_BUF]; |
2751 | char buf[MAX_BUF]; |
2538 | timeofday_t tod; |
2752 | timeofday_t tod; |
2539 | |
2753 | |
2540 | get_tod (&tod); |
2754 | get_tod (&tod); |
2541 | op->play_sound (sound_find ("sound_clock")); |
2755 | who->play_sound (sound_find ("sound_clock")); |
2542 | op->statusmsg (format ( |
2756 | who->statusmsg (format ( |
2543 | "It is %d minute%s past %d o'clock %s", |
2757 | "It is %d minute%s past %d o'clock %s", |
2544 | tod.minute + 1, ((tod.minute + 1 < 2) ? "" : "s"), |
2758 | tod.minute + 1, ((tod.minute + 1 < 2) ? "" : "s"), |
2545 | ((tod.hour % 14 == 0) ? 14 : ((tod.hour) % 14)), ((tod.hour >= 14) ? "pm" : "am") |
2759 | ((tod.hour % 14 == 0) ? 14 : ((tod.hour) % 14)), ((tod.hour >= 14) ? "pm" : "am") |
2546 | )); |
2760 | )); |
2547 | return 1; |
2761 | return 1; |
2548 | } |
2762 | } |
2549 | else |
2763 | else |
2550 | return 0; |
2764 | return 0; |
2551 | |
2765 | |
2552 | case MENU: |
2766 | case MENU: |
2553 | if (op->type == PLAYER) |
2767 | if (who->type == PLAYER) |
2554 | { |
2768 | { |
2555 | shop_listing (tmp, op); |
2769 | shop_listing (op, who); |
2556 | return 1; |
2770 | return 1; |
2557 | } |
2771 | } |
2558 | else |
2772 | else |
2559 | return 0; |
2773 | return 0; |
2560 | |
2774 | |
2561 | case POWER_CRYSTAL: |
2775 | case POWER_CRYSTAL: |
2562 | apply_power_crystal (op, tmp); /* see egoitem.c */ |
2776 | apply_power_crystal (who, op); /* see egoitem.c */ |
2563 | return 1; |
2777 | return 1; |
2564 | |
2778 | |
2565 | case LIGHTER: /* for lighting torches/lanterns/etc */ |
2779 | case LIGHTER: /* for lighting torches/lanterns/etc */ |
2566 | if (op->type == PLAYER) |
2780 | if (who->type == PLAYER) |
2567 | { |
2781 | { |
2568 | apply_lighter (op, tmp); |
2782 | apply_lighter (who, op); |
2569 | return 1; |
2783 | return 1; |
2570 | } |
2784 | } |
2571 | else |
2785 | else |
2572 | return 0; |
2786 | return 0; |
2573 | |
2787 | |
2574 | case ITEM_TRANSFORMER: |
2788 | case ITEM_TRANSFORMER: |
2575 | apply_item_transformer (op, tmp); |
2789 | apply_item_transformer (who, op); |
2576 | return 1; |
2790 | return 1; |
2577 | |
2791 | |
2578 | default: |
2792 | default: |
2579 | return 0; |
2793 | return 0; |
2580 | } |
2794 | } |
… | |
… | |
2731 | case BRACERS: |
2945 | case BRACERS: |
2732 | case CLOAK: |
2946 | case CLOAK: |
2733 | who->statusmsg (format ("You unwear %s.", query_name (op))); |
2947 | who->statusmsg (format ("You unwear %s.", query_name (op))); |
2734 | change_abil (who, op); |
2948 | change_abil (who, op); |
2735 | break; |
2949 | break; |
2736 | |
|
|
2737 | case LAMP: |
|
|
2738 | { |
|
|
2739 | who->statusmsg (format ("You turn off your %s.", &op->name)); |
|
|
2740 | |
|
|
2741 | object *tmp2 = arch_to_object (op->other_arch); |
|
|
2742 | tmp2->x = op->x; |
|
|
2743 | tmp2->y = op->y; |
|
|
2744 | tmp2->map = op->map; |
|
|
2745 | tmp2->below = op->below; |
|
|
2746 | tmp2->above = op->above; |
|
|
2747 | tmp2->stats.food = op->stats.food; |
|
|
2748 | CLEAR_FLAG (tmp2, FLAG_APPLIED); |
|
|
2749 | |
|
|
2750 | if (QUERY_FLAG (op, FLAG_INV_LOCKED)) |
|
|
2751 | SET_FLAG (tmp2, FLAG_INV_LOCKED); |
|
|
2752 | |
|
|
2753 | op->destroy (); |
|
|
2754 | who->insert (tmp2); |
|
|
2755 | who->update_stats (); |
|
|
2756 | |
|
|
2757 | if (who->contr) |
|
|
2758 | if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED)) |
|
|
2759 | { |
|
|
2760 | who->failmsg ("Oops, it feels deadly cold!"); |
|
|
2761 | SET_FLAG (tmp2, FLAG_KNOWN_CURSED); |
|
|
2762 | } |
|
|
2763 | } |
|
|
2764 | |
|
|
2765 | return 1; /* otherwise, an attempt to drop causes problems */ |
|
|
2766 | |
2950 | |
2767 | case BOW: |
2951 | case BOW: |
2768 | case WAND: |
2952 | case WAND: |
2769 | case ROD: |
2953 | case ROD: |
2770 | case HORN: |
2954 | case HORN: |
… | |
… | |
3254 | case AMULET: |
3438 | case AMULET: |
3255 | SET_FLAG (op, FLAG_APPLIED); |
3439 | SET_FLAG (op, FLAG_APPLIED); |
3256 | who->statusmsg (format ("You wear %s.", query_name (op))); |
3440 | who->statusmsg (format ("You wear %s.", query_name (op))); |
3257 | change_abil (who, op); |
3441 | change_abil (who, op); |
3258 | break; |
3442 | break; |
3259 | |
|
|
3260 | case LAMP: |
|
|
3261 | if (op->stats.food < 1) |
|
|
3262 | { |
|
|
3263 | who->failmsg (format ( |
|
|
3264 | "Your %s is out of fuel! " |
|
|
3265 | "H<Lamps and similar items need fuel. They cannot be refilled.>", |
|
|
3266 | &op->name |
|
|
3267 | )); |
|
|
3268 | return 1; |
|
|
3269 | } |
|
|
3270 | |
|
|
3271 | who->statusmsg (format ("You turn on your %s.", &op->name)); |
|
|
3272 | |
|
|
3273 | tmp2 = arch_to_object (op->other_arch); |
|
|
3274 | tmp2->stats.food = op->stats.food; |
|
|
3275 | SET_FLAG (tmp2, FLAG_APPLIED); |
|
|
3276 | |
|
|
3277 | if (QUERY_FLAG (op, FLAG_INV_LOCKED)) |
|
|
3278 | SET_FLAG (tmp2, FLAG_INV_LOCKED); |
|
|
3279 | |
|
|
3280 | who->insert (tmp2); |
|
|
3281 | |
|
|
3282 | /* Remove the old lantern */ |
|
|
3283 | op->destroy (); |
|
|
3284 | |
|
|
3285 | /* insert the portion that was split off */ |
|
|
3286 | if (tmp) |
|
|
3287 | who->insert (tmp); |
|
|
3288 | |
|
|
3289 | who->update_stats (); |
|
|
3290 | |
|
|
3291 | if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED)) |
|
|
3292 | if (who->type == PLAYER) |
|
|
3293 | { |
|
|
3294 | who->failmsg ("Oops, it feels deadly cold! H<Maybe it wasn't such a bright (hrhrhr) idea to apply this cursed or damned item.>"); |
|
|
3295 | SET_FLAG (tmp2, FLAG_KNOWN_CURSED); |
|
|
3296 | } |
|
|
3297 | |
|
|
3298 | return 0; |
|
|
3299 | |
3443 | |
3300 | case SKILL_TOOL: |
3444 | case SKILL_TOOL: |
3301 | // applying a skill tool also readies the skill |
3445 | // applying a skill tool also readies the skill |
3302 | SET_FLAG (op, FLAG_APPLIED); |
3446 | SET_FLAG (op, FLAG_APPLIED); |
3303 | |
3447 | |
… | |
… | |
3753 | } |
3897 | } |
3754 | |
3898 | |
3755 | who->update_stats (); |
3899 | who->update_stats (); |
3756 | } |
3900 | } |
3757 | |
3901 | |
3758 | /** |
|
|
3759 | * Designed primarily to light torches/lanterns/etc. |
|
|
3760 | * Also burns up burnable material too. First object in the inventory is |
|
|
3761 | * the selected object to "burn". -b.t. |
|
|
3762 | */ |
|
|
3763 | void |
|
|
3764 | apply_lighter (object *who, object *lighter) |
|
|
3765 | { |
|
|
3766 | object *item; |
|
|
3767 | int is_player_env = 0; |
|
|
3768 | |
|
|
3769 | item = find_marked_object (who); |
|
|
3770 | if (item) |
|
|
3771 | { |
|
|
3772 | if (lighter->last_eat && lighter->stats.food) |
|
|
3773 | { /* lighter gets used up */ |
|
|
3774 | object *oneLighter = lighter->split (); |
|
|
3775 | oneLighter->stats.food--; |
|
|
3776 | who->insert (oneLighter); |
|
|
3777 | } |
|
|
3778 | else if (lighter->last_eat) |
|
|
3779 | { |
|
|
3780 | /* no charges left in lighter */ |
|
|
3781 | who->failmsg (format ("You attempt to light the %s with a used up %s.", &item->name, &lighter->name)); |
|
|
3782 | return; |
|
|
3783 | } |
|
|
3784 | |
|
|
3785 | /* Perhaps we should split what we are trying to light on fire? |
|
|
3786 | * I can't see many times when you would want to light multiple |
|
|
3787 | * objects at once. |
|
|
3788 | */ |
|
|
3789 | |
|
|
3790 | if (who == item->in_player ()) |
|
|
3791 | is_player_env = 1; |
|
|
3792 | |
|
|
3793 | save_throw_object (item, AT_FIRE, who); |
|
|
3794 | |
|
|
3795 | if (item->destroyed ()) |
|
|
3796 | { |
|
|
3797 | who->statusmsg (format ("You light the %s with the %s.", &item->name, &lighter->name)); |
|
|
3798 | /* Need to update the player so that the players glow radius |
|
|
3799 | * gets changed. |
|
|
3800 | */ |
|
|
3801 | if (is_player_env) |
|
|
3802 | who->update_stats (); |
|
|
3803 | } |
|
|
3804 | else |
|
|
3805 | who->failmsg (format ("You attempt to light the %s with the %s and fail.", &item->name, &lighter->name)); |
|
|
3806 | } |
|
|
3807 | else |
|
|
3808 | who->failmsg ("You need to mark a lightable object."); |
|
|
3809 | } |
|
|
3810 | |
3902 | |
3811 | /** |
3903 | /** |
3812 | * op made some mistake with a scroll, this takes care of punishment. |
3904 | * op made some mistake with a scroll, this takes care of punishment. |
3813 | * scroll_failure()- hacked directly from spell_failure |
3905 | * scroll_failure()- hacked directly from spell_failure |
3814 | */ |
3906 | */ |