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.97 by root, Tue May 15 19:07:15 2007 UTC vs.
Revision 1.118 by root, Thu Jul 26 00:27:08 2007 UTC

1/* 1/*
2 * CrossFire, A Multiplayer game 2 * This file is part of Crossfire TRT, the Roguelike Realtime MORPG.
3 * 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team 4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team
5 * Copyright (C) 2001 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * Crossfire TRT is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version. 11 * (at your option) any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
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, write to the Free Software 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * 20 *
22 * The authors can be reached via e-mail to <crossfire@schmorp.de> 21 * The authors can be reached via e-mail to <crossfire@schmorp.de>
23 */ 22 */
24 23
25#include <cmath> 24#include <cmath>
26 25
69 68
70 /* If the director has race set, only affect objects with a arch, 69 /* If the director has race set, only affect objects with a arch,
71 * name or race that matches. 70 * name or race that matches.
72 */ 71 */
73 if ((op->race) && 72 if ((op->race) &&
74 ((!(victim->arch && arch_flag && victim->arch->name) || op->race != victim->arch->name)) && 73 ((!(victim->arch && arch_flag && victim->arch->archname) || op->race != victim->arch->archname)) &&
75 ((!(victim->name && name_flag) || op->race != victim->name)) && 74 ((!(victim->name && name_flag) || op->race != victim->name)) &&
76 ((!(victim->race && race_flag) || op->race != victim->race))) 75 ((!(victim->race && race_flag) || op->race != victim->race)))
77 return 1; 76 return 1;
78 77
79 /* If the director has slaying set, only affect objects where none 78 /* If the director has slaying set, only affect objects where none
80 * of arch, name, or race match. 79 * of arch, name, or race match.
81 */ 80 */
82 if ((op->slaying) && (((victim->arch && arch_flag && victim->arch->name && op->slaying == victim->arch->name))) || 81 if ((op->slaying) && (((victim->arch && arch_flag && victim->arch->archname && op->slaying == victim->arch->archname))) ||
83 ((victim->name && name_flag && op->slaying == victim->name)) || 82 ((victim->name && name_flag && op->slaying == victim->name)) ||
84 ((victim->race && race_flag && op->slaying == victim->race))) 83 ((victim->race && race_flag && op->slaying == victim->race)))
85 return 1; 84 return 1;
86 85
87 return 0; 86 return 0;
158 157
159/** 158/**
160 * This checks whether the object has a "on_use_yield" field, and if so generated and drops 159 * This checks whether the object has a "on_use_yield" field, and if so generated and drops
161 * matching item. 160 * matching item.
162 **/ 161 **/
163static void 162void
164handle_apply_yield (object *tmp) 163handle_apply_yield (object *tmp)
165{ 164{
166 const char *yield; 165 const char *yield;
167 166
168 yield = get_ob_key_value (tmp, "on_use_yield"); 167 yield = get_ob_key_value (tmp, "on_use_yield");
425 return 0; 424 return 0;
426 425
427 op = op->below; 426 op = op->below;
428 while (op != NULL) 427 while (op != NULL)
429 { 428 {
430 if (strcmp (op->arch->name, item) == 0) 429 if (strcmp (op->arch->archname, item) == 0)
431 { 430 {
432 if (!QUERY_FLAG (op, FLAG_CURSED) && !QUERY_FLAG (op, FLAG_DAMNED) 431 if (!QUERY_FLAG (op, FLAG_CURSED) && !QUERY_FLAG (op, FLAG_DAMNED)
433 /* Loophole bug? -FD- */ && !QUERY_FLAG (op, FLAG_UNPAID)) 432 /* Loophole bug? -FD- */ && !QUERY_FLAG (op, FLAG_UNPAID))
434 { 433 {
435 if (op->nrof == 0) /* this is necessary for artifact sacrifices --FD-- */ 434 if (op->nrof == 0) /* this is necessary for artifact sacrifices --FD-- */
459 prev = op; 458 prev = op;
460 op = op->below; 459 op = op->below;
461 460
462 while (op != NULL) 461 while (op != NULL)
463 { 462 {
464 if (strcmp (op->arch->name, item) == 0) 463 if (strcmp (op->arch->archname, item) == 0)
465 { 464 {
466 if (op->nrof >= nrof) 465 if (op->nrof >= nrof)
467 { 466 {
468 decrease_ob_nr (op, nrof); 467 decrease_ob_nr (op, nrof);
469 return; 468 return;
576 op->update_stats (); 575 op->update_stats ();
577 return 1; 576 return 1;
578} 577}
579 578
580/* Types of improvements, hidden in the sp field. */ 579/* Types of improvements, hidden in the sp field. */
581#define IMPROVE_PREPARE 1 580#define IMPROVE_PREPARE 1
582#define IMPROVE_DAMAGE 2 581#define IMPROVE_DAMAGE 2
583#define IMPROVE_WEIGHT 3 582#define IMPROVE_WEIGHT 3
584#define IMPROVE_ENCHANT 4 583#define IMPROVE_ENCHANT 4
585#define IMPROVE_STR 5 584#define IMPROVE_STR 5
586#define IMPROVE_DEX 6 585#define IMPROVE_DEX 6
587#define IMPROVE_CON 7 586#define IMPROVE_CON 7
588#define IMPROVE_WIS 8 587#define IMPROVE_WIS 8
589#define IMPROVE_CHA 9 588#define IMPROVE_CHA 9
590#define IMPROVE_INT 10 589#define IMPROVE_INT 10
591#define IMPROVE_POW 11 590#define IMPROVE_POW 11
592
593 591
594/** 592/**
595 * This does the prepare weapon scroll. 593 * This does the prepare weapon scroll.
596 * Checks for sacrifice, and so on. 594 * Checks for sacrifice, and so on.
597 */ 595 */
598
599int 596int
600prepare_weapon (object *op, object *improver, object *weapon) 597prepare_weapon (object *op, object *improver, object *weapon)
601{ 598{
602 int sacrifice_count, i; 599 int sacrifice_count, i;
603 char buf[MAX_BUF]; 600 char buf[MAX_BUF];
605 if (weapon->level != 0) 602 if (weapon->level != 0)
606 { 603 {
607 new_draw_info (NDI_UNIQUE, 0, op, "Weapon already prepared."); 604 new_draw_info (NDI_UNIQUE, 0, op, "Weapon already prepared.");
608 return 0; 605 return 0;
609 } 606 }
607
610 for (i = 0; i < NROFATTACKS; i++) 608 for (i = 0; i < NROFATTACKS; i++)
611 if (weapon->resist[i]) 609 if (weapon->resist[i])
612 break; 610 break;
613 611
614 /* If we break out, i will be less than nrofattacks, preventing 612 /* If we break out, i will be less than nrofattacks, preventing
620 weapon->stats.ac) /* AC - only taifu's I think */ 618 weapon->stats.ac) /* AC - only taifu's I think */
621 { 619 {
622 new_draw_info (NDI_UNIQUE, 0, op, "Cannot prepare magic weapons."); 620 new_draw_info (NDI_UNIQUE, 0, op, "Cannot prepare magic weapons.");
623 return 0; 621 return 0;
624 } 622 }
623
625 sacrifice_count = check_sacrifice (op, improver); 624 sacrifice_count = check_sacrifice (op, improver);
626 if (sacrifice_count <= 0) 625 if (sacrifice_count <= 0)
627 return 0; 626 return 0;
627
628 weapon->level = isqrt (sacrifice_count); 628 weapon->level = isqrt (sacrifice_count);
629 new_draw_info (NDI_UNIQUE, 0, op, "Your sacrifice was accepted."); 629 new_draw_info (NDI_UNIQUE, 0, op, "Your sacrifice was accepted.");
630 eat_item (op, improver->slaying, sacrifice_count); 630 eat_item (op, improver->slaying, sacrifice_count);
631 631
632 new_draw_info_format (NDI_UNIQUE, 0, op, "Your *%s may be improved %d times.", &weapon->name, weapon->level); 632 new_draw_info_format (NDI_UNIQUE, 0, op, "Your *%s may be improved %d times.", &weapon->name, weapon->level);
855 { 855 {
856 base = base - (base * settings.armor_speed_improvement) / 100; 856 base = base - (base * settings.armor_speed_improvement) / 100;
857 pow++; 857 pow++;
858 } 858 }
859 859
860 ARMOUR_SPEED (armour) = (ARMOUR_SPEED (&armour->arch->clone) * base) / 100; 860 ARMOUR_SPEED (armour) = (ARMOUR_SPEED (armour->arch) * base) / 100;
861 } 861 }
862 else 862 else
863 ARMOUR_SPEED (armour) = (ARMOUR_SPEED (&armour->arch->clone) * (100 + armour->magic * settings.armor_speed_improvement)) / 100; 863 ARMOUR_SPEED (armour) = (ARMOUR_SPEED (armour->arch) * (100 + armour->magic * settings.armor_speed_improvement)) / 100;
864 864
865 if (!settings.armor_weight_linear) 865 if (!settings.armor_weight_linear)
866 { 866 {
867 int base = 100; 867 int base = 100;
868 int pow = 0; 868 int pow = 0;
871 { 871 {
872 base = base - (base * settings.armor_weight_reduction) / 100; 872 base = base - (base * settings.armor_weight_reduction) / 100;
873 pow++; 873 pow++;
874 } 874 }
875 875
876 armour->weight = (armour->arch->clone.weight * base) / 100; 876 armour->weight = (armour->arch->weight * base) / 100;
877 } 877 }
878 else 878 else
879 armour->weight = (armour->arch->clone.weight * (100 - armour->magic * settings.armor_weight_reduction)) / 100; 879 armour->weight = (armour->arch->weight * (100 - armour->magic * settings.armor_weight_reduction)) / 100;
880 880
881 if (armour->weight <= 0) 881 if (armour->weight <= 0)
882 { 882 {
883 LOG (llevInfo, "Warning: enchanted armours can have negative weight\n."); 883 LOG (llevInfo, "Warning: enchanted armours can have negative weight\n.");
884 armour->weight = 1; 884 armour->weight = 1;
885 } 885 }
886 886
887 armour->item_power = get_power_from_ench (armour->arch->clone.item_power + armour->magic); 887 armour->item_power = get_power_from_ench (armour->arch->item_power + armour->magic);
888 888
889 if (op->type == PLAYER) 889 if (op->type == PLAYER)
890 { 890 {
891 esrv_send_item (op, armour); 891 esrv_send_item (op, armour);
892 if (QUERY_FLAG (armour, FLAG_APPLIED)) 892 if (QUERY_FLAG (armour, FLAG_APPLIED))
944 944
945 price_in = cost * item->value; 945 price_in = cost * item->value;
946 } 946 }
947 else 947 else
948 { 948 {
949 if (item->type == PLAYER || CONV_FROM (converter) != item->arch->name || 949 if (item->type == PLAYER || CONV_FROM (converter) != item->arch->archname ||
950 (CONV_NEED (converter) && CONV_NEED (converter) > (uint16) item->nrof)) 950 (CONV_NEED (converter) && CONV_NEED (converter) > (uint16) item->nrof))
951 return 0; 951 return 0;
952 952
953 if (CONV_NEED (converter)) 953 if (CONV_NEED (converter))
954 { 954 {
1006 LOG (llevDebug, "converter output price higher than input: %s at %s (%d, %d) in value %d, out value %d for %s\n", 1006 LOG (llevDebug, "converter output price higher than input: %s at %s (%d, %d) in value %d, out value %d for %s\n",
1007 &converter->name, &converter->map->path, converter->x, converter->y, price_in, item->nrof * item->value, &item->name); 1007 &converter->name, &converter->map->path, converter->x, converter->y, price_in, item->nrof * item->value, &item->name);
1008 1008
1009 /** 1009 /**
1010 * elmex: we are going to let the game continue, as the mapcreator 1010 * elmex: we are going to let the game continue, as the mapcreator
1011 * propably had something in mind when doing this 1011 * probably had something in mind when doing this
1012 */ 1012 */
1013 } 1013 }
1014 insert_ob_in_map_at (item, converter->map, converter, 0, converter->x, converter->y); 1014 insert_ob_in_map_at (item, converter->map, converter, 0, converter->x, converter->y);
1015 return 1; 1015 return 1;
1016} 1016}
1245 */ 1245 */
1246static void 1246static void
1247apply_sign (object *op, object *sign, int autoapply) 1247apply_sign (object *op, object *sign, int autoapply)
1248{ 1248{
1249 readable_message_type *msgType; 1249 readable_message_type *msgType;
1250 char newbuf[HUGE_BUF];
1251 1250
1252 if (sign->msg == NULL) 1251 if (sign->msg == NULL)
1253 { 1252 {
1254 new_draw_info (NDI_UNIQUE, 0, op, "Nothing is written on it."); 1253 new_draw_info (NDI_UNIQUE, 0, op, "Nothing is written on it.");
1255 return; 1254 return;
1276 if (QUERY_FLAG (op, FLAG_BLIND) && !QUERY_FLAG (op, FLAG_WIZ) && !sign->move_on) 1275 if (QUERY_FLAG (op, FLAG_BLIND) && !QUERY_FLAG (op, FLAG_WIZ) && !sign->move_on)
1277 { 1276 {
1278 new_draw_info (NDI_UNIQUE, 0, op, "You are unable to read while blind."); 1277 new_draw_info (NDI_UNIQUE, 0, op, "You are unable to read while blind.");
1279 return; 1278 return;
1280 } 1279 }
1280
1281 if (op->contr)
1282 if (client *ns = op->contr->ns)
1283 {
1281 msgType = get_readable_message_type (sign); 1284 msgType = get_readable_message_type (sign);
1285
1286 if (ns->can_msg)
1287 ns->send_msg (NDI_NAVY, msgType->msgtype, &sign->msg);
1288 else
1289 {
1290 char newbuf[HUGE_BUF];
1282 snprintf (newbuf, sizeof (newbuf), "%hhu %s", autoapply ? 1 : 0, &sign->msg); 1291 snprintf (newbuf, sizeof (newbuf), "%u %s", autoapply ? 1 : 0, &sign->msg);
1283 draw_ext_info (NDI_UNIQUE | NDI_NAVY, 0, op, msgType->message_type, msgType->message_subtype, newbuf, &sign->msg); 1292 draw_ext_info (NDI_UNIQUE | NDI_NAVY, 0, op, msgType->message_type, msgType->message_subtype, newbuf, &sign->msg);
1293 }
1294 }
1284} 1295}
1285 1296
1286/** 1297/**
1287 * 'victim' moves onto 'trap' 1298 * 'victim' moves onto 'trap'
1288 * 'victim' leaves 'trap' 1299 * 'victim' leaves 'trap'
1311 * proper. This code was causing needless crashes. 1322 * proper. This code was causing needless crashes.
1312 */ 1323 */
1313 if (recursion_depth >= 500) 1324 if (recursion_depth >= 500)
1314 { 1325 {
1315 LOG (llevDebug, "WARNING: move_apply(): aborting recursion " 1326 LOG (llevDebug, "WARNING: move_apply(): aborting recursion "
1316 "[trap arch %s, name %s; victim arch %s, name %s]\n", &trap->arch->name, &trap->name, &victim->arch->name, &victim->name); 1327 "[trap arch %s, name %s; victim arch %s, name %s]\n", &trap->arch->archname, &trap->name, &victim->arch->archname, &victim->name);
1317 return; 1328 return;
1318 } 1329 }
1330
1319 recursion_depth++; 1331 recursion_depth++;
1320 if (trap->head) 1332 if (trap->head)
1321 trap = trap->head; 1333 trap = trap->head;
1322 1334
1323 if (INVOKE_OBJECT (MOVE_TRIGGER, trap, ARG_OBJECT (victim), ARG_OBJECT (originator))) 1335 if (INVOKE_OBJECT (MOVE_TRIGGER, trap, ARG_OBJECT (victim), ARG_OBJECT (originator)))
1421 1433
1422 if ((ab->move_type && trap->move_on) || ab->move_type == 0) 1434 if ((ab->move_type && trap->move_on) || ab->move_type == 0)
1423 { 1435 {
1424 if (!sound_was_played) 1436 if (!sound_was_played)
1425 { 1437 {
1426 play_sound_map (trap->map, trap->x, trap->y, SOUND_FALL_HOLE); 1438 trap->play_sound (sound_find ("fall_hole"));
1427 sound_was_played = 1; 1439 sound_was_played = 1;
1428 } 1440 }
1441
1429 new_draw_info (NDI_UNIQUE, 0, ab, "You fall into a trapdoor!"); 1442 new_draw_info (NDI_UNIQUE, 0, ab, "You fall into a trapdoor!");
1430 transfer_ob (ab, (int) EXIT_X (trap), (int) EXIT_Y (trap), 0, ab); 1443 transfer_ob (ab, (int) EXIT_X (trap), (int) EXIT_Y (trap), 0, ab);
1431 } 1444 }
1432 } 1445 }
1433 goto leave; 1446 goto leave;
1466 * Processing will happen if the head runs into the pit 1479 * Processing will happen if the head runs into the pit
1467 */ 1480 */
1468 if (victim->head) 1481 if (victim->head)
1469 goto leave; 1482 goto leave;
1470 1483
1471 play_sound_map (victim->map, victim->x, victim->y, SOUND_FALL_HOLE); 1484 victim->play_sound (sound_find ("fall_hole"));
1472 new_draw_info (NDI_UNIQUE, 0, victim, "You fall through the hole!\n"); 1485 new_draw_info (NDI_UNIQUE, 0, victim, "You fall through the hole!\n");
1473 transfer_ob (victim, EXIT_X (trap), EXIT_Y (trap), 1, victim); 1486 transfer_ob (victim, EXIT_X (trap), EXIT_Y (trap), 1, victim);
1474 goto leave; 1487 goto leave;
1475 1488
1476 case EXIT: 1489 case EXIT:
1518 } 1531 }
1519 goto leave; 1532 goto leave;
1520 1533
1521 default: 1534 default:
1522 LOG (llevDebug, "name %s, arch %s, type %d with fly/walk on/off not " 1535 LOG (llevDebug, "name %s, arch %s, type %d with fly/walk on/off not "
1523 "handled in move_apply()\n", &trap->name, &trap->arch->name, trap->type); 1536 "handled in move_apply()\n", &trap->name, &trap->arch->archname, trap->type);
1524 goto leave; 1537 goto leave;
1525 } 1538 }
1526 1539
1527leave: 1540leave:
1528 recursion_depth--; 1541 recursion_depth--;
1540 if (QUERY_FLAG (op, FLAG_BLIND) && !QUERY_FLAG (op, FLAG_WIZ)) 1553 if (QUERY_FLAG (op, FLAG_BLIND) && !QUERY_FLAG (op, FLAG_WIZ))
1541 { 1554 {
1542 new_draw_info (NDI_UNIQUE, 0, op, "You are unable to read while blind."); 1555 new_draw_info (NDI_UNIQUE, 0, op, "You are unable to read while blind.");
1543 return; 1556 return;
1544 } 1557 }
1558
1545 if (tmp->msg == NULL) 1559 if (!tmp->msg)
1546 { 1560 {
1547 new_draw_info_format (NDI_UNIQUE, 0, op, "You open the %s and find it empty.", &tmp->name); 1561 new_draw_info_format (NDI_UNIQUE, 0, op, "You open the %s and find it empty.", &tmp->name);
1548 return; 1562 return;
1549 } 1563 }
1550 1564
1551 /* need a literacy skill to read stuff! */ 1565 /* need a literacy skill to read stuff! */
1552 skill_ob = find_skill_by_name (op, tmp->skill); 1566 skill_ob = find_skill_by_name (op, tmp->skill);
1553 if (!skill_ob) 1567 if (!skill_ob)
1554 { 1568 {
1555 new_draw_info (NDI_UNIQUE, 0, op, "You are unable to decipher the strange symbols."); 1569 new_draw_info (NDI_UNIQUE, 0, op, "You are unable to decipher the strange symbols. H<You lack the skill to read this>");
1556 return; 1570 return;
1557 } 1571 }
1572
1558 lev_diff = tmp->level - (skill_ob->level + 5); 1573 lev_diff = tmp->level - (skill_ob->level + 5);
1559 if (!QUERY_FLAG (op, FLAG_WIZ) && lev_diff > 0) 1574 if (!QUERY_FLAG (op, FLAG_WIZ) && lev_diff > 0)
1560 { 1575 {
1561 if (lev_diff < 2) 1576 if (lev_diff < 2)
1562 new_draw_info (NDI_UNIQUE, 0, op, "This book is just barely beyond your comprehension."); 1577 new_draw_info (NDI_UNIQUE, 0, op, "This book is just barely beyond your comprehension.");
1573 return; 1588 return;
1574 } 1589 }
1575 1590
1576 readable_message_type *msgType = get_readable_message_type (tmp); 1591 readable_message_type *msgType = get_readable_message_type (tmp);
1577 1592
1593 if (player *pl = op->contr)
1594 if (client *ns = pl->ns)
1595 if (ns->can_msg)
1596 {
1597 dynbuf_text buf;
1598 buf << long_desc (tmp, op)
1599 << "\n\n"
1600 << tmp->msg
1601 << '\0';
1602 ns->send_msg (NDI_NAVY, msgType->msgtype, buf.linearise ());
1603 }
1604 else
1578 draw_ext_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, 1605 draw_ext_info_format (NDI_UNIQUE | NDI_NAVY, 0, op,
1579 msgType->message_type, msgType->message_subtype, 1606 msgType->message_type, msgType->message_subtype,
1580 "You open the %s and start reading.\n%s", (char *)"%s\n%s", 1607 "You open the %s and start reading.\n%s", (char *)"%s\n%s",
1581 long_desc (tmp, op), &tmp->msg); 1608 long_desc (tmp, op), &tmp->msg);
1582 1609
1583 /* gain xp from reading */ 1610 /* gain xp from reading */
1584 if (!QUERY_FLAG (tmp, FLAG_NO_SKILL_IDENT)) 1611 if (!QUERY_FLAG (tmp, FLAG_NO_SKILL_IDENT))
1585 { /* only if not read before */ 1612 { /* only if not read before */
1586 int exp_gain = calc_skill_exp (op, tmp, skill_ob); 1613 int exp_gain = calc_skill_exp (op, tmp, skill_ob);
1652 return; 1679 return;
1653 } 1680 }
1654 return; 1681 return;
1655 } 1682 }
1656 1683
1657 play_sound_player_only (op->contr, SOUND_LEARN_SPELL, 0, 0); 1684 op->contr->play_sound (sound_find ("learn_spell"));
1685
1658 tmp = spell->clone (); 1686 tmp = spell->clone ();
1659 insert_ob_in_ob (tmp, op); 1687 insert_ob_in_ob (tmp, op);
1660 1688
1661 if (special_prayer) 1689 if (special_prayer)
1662 SET_FLAG (tmp, FLAG_STARTEQUIP); 1690 SET_FLAG (tmp, FLAG_STARTEQUIP);
1707 1735
1708 /* artifact_spellbooks have 'slaying' field point to a spell name, 1736 /* artifact_spellbooks have 'slaying' field point to a spell name,
1709 * instead of having their spell stored in stats.sp. These are 1737 * instead of having their spell stored in stats.sp. These are
1710 * legacy spellbooks 1738 * legacy spellbooks
1711 */ 1739 */
1712
1713 if (tmp->slaying != NULL) 1740 if (tmp->slaying)
1714 { 1741 {
1715 spell = arch_to_object (find_archetype_by_object_name (tmp->slaying)); 1742 spell = arch_to_object (find_archetype_by_object_name (tmp->slaying));
1716 if (!spell) 1743 if (!spell)
1717 { 1744 {
1718 new_draw_info_format (NDI_UNIQUE, 0, op, "The book's formula for %s is incomplete", &tmp->slaying); 1745 new_draw_info_format (NDI_UNIQUE, 0, op, "The book's formula for %s is incomplete", &tmp->slaying);
1719 return; 1746 return;
1720 } 1747 }
1721 else 1748 else
1722 insert_ob_in_ob (spell, tmp); 1749 insert_ob_in_ob (spell, tmp);
1750
1723 tmp->slaying = NULL; 1751 tmp->slaying = 0;
1724 } 1752 }
1725 1753
1726 skop = find_skill_by_name (op, tmp->skill); 1754 skop = find_skill_by_name (op, tmp->skill);
1727 1755
1728 /* need a literacy skill to learn spells. Also, having a literacy level 1756 /* need a literacy skill to learn spells. Also, having a literacy level
1729 * lower than the spell will make learning the spell more difficult */ 1757 * lower than the spell will make learning the spell more difficult */
1730 if (!skop) 1758 if (!skop)
1731 { 1759 {
1732 new_draw_info (NDI_UNIQUE, 0, op, "You can't read! Your attempt fails."); 1760 new_draw_info (NDI_UNIQUE, 0, op, "You can't read! Your attempt fails. H<You lack the literacy skill.>");
1733 return; 1761 return;
1734 } 1762 }
1735 1763
1736 spell = tmp->inv; 1764 spell = tmp->inv;
1737 1765
1738 if (!spell) 1766 if (!spell)
1739 { 1767 {
1740 LOG (llevError, "apply_spellbook: Book %s has no spell in it!\n", &tmp->name); 1768 LOG (llevError, "apply_spellbook: Book %s has no spell in it!\n", &tmp->name);
1741 new_draw_info (NDI_UNIQUE, 0, op, "The spellbook symbols make no sense."); 1769 new_draw_info (NDI_UNIQUE, 0, op, "The spellbook symbols make no sense. This is a bug, please report!");
1742 return; 1770 return;
1743 } 1771 }
1744 1772
1745 if (skop->level < int (sqrtf (spell->level) * 1.5f)) 1773 if (skop->level < int (sqrtf (spell->level) * 1.5f))
1746 { 1774 {
1747 new_draw_info (NDI_UNIQUE, 0, op, "You are unable to decipher the strange symbols. [Your literacy level is too low]"); 1775 new_draw_info (NDI_UNIQUE, 0, op, "You are unable to decipher the strange symbols. H<Your literacy level is too low.>");
1748 return; 1776 return;
1749 } 1777 }
1750 1778
1751 new_draw_info_format (NDI_UNIQUE, 0, op, "The spellbook contains the %s level spell %s.", get_levelnumber (spell->level), &spell->name); 1779 new_draw_info_format (NDI_UNIQUE, 0, op, "The spellbook contains the %s level spell %s.", get_levelnumber (spell->level), &spell->name);
1752 1780
1765 * if the player doesn't know the spell, doesn't make a lot of sense that 1793 * if the player doesn't know the spell, doesn't make a lot of sense that
1766 * they would have a special prayer mark. 1794 * they would have a special prayer mark.
1767 */ 1795 */
1768 if (check_spell_known (op, spell->name)) 1796 if (check_spell_known (op, spell->name))
1769 { 1797 {
1770 new_draw_info (NDI_UNIQUE, 0, op, "You already know that spell.\n"); 1798 new_draw_info (NDI_UNIQUE, 0, op, "You already know that spell. H<It makes no sense to learn spells twice, and would only waste the spellbook.>\n");
1771 return; 1799 return;
1772 } 1800 }
1773 1801
1774 if (spell->skill) 1802 if (spell->skill)
1775 { 1803 {
1816 if (!QUERY_FLAG (tmp, FLAG_STARTEQUIP)) 1844 if (!QUERY_FLAG (tmp, FLAG_STARTEQUIP))
1817 change_exp (op, calc_skill_exp (op, tmp, skop), skop->skill, 0); 1845 change_exp (op, calc_skill_exp (op, tmp, skop), skop->skill, 0);
1818 } 1846 }
1819 else 1847 else
1820 { 1848 {
1821 play_sound_player_only (op->contr, SOUND_FUMBLE_SPELL, 0, 0); 1849 op->contr->play_sound (sound_find ("fumble_spell"));
1822 new_draw_info (NDI_UNIQUE, 0, op, "You fail to learn the spell.\n"); 1850 new_draw_info (NDI_UNIQUE, 0, op, "You fail to learn the spell. H<Wis (priests) or Int (wizards) governs the chance of learning a prayer or spell.>\n");
1823 } 1851 }
1824 1852
1825 decrease_ob (tmp); 1853 decrease_ob (tmp);
1826} 1854}
1827 1855
1839 return; 1867 return;
1840 } 1868 }
1841 1869
1842 if (!tmp->inv || tmp->inv->type != SPELL) 1870 if (!tmp->inv || tmp->inv->type != SPELL)
1843 { 1871 {
1844 new_draw_info (NDI_UNIQUE, 0, op, "The scroll just doesn't make sense!"); 1872 new_draw_info (NDI_UNIQUE, 0, op, "The scroll just doesn't make sense! H<...and never will make sense.>");
1845 return; 1873 return;
1846 } 1874 }
1847 1875
1848 if (op->type == PLAYER) 1876 if (op->type == PLAYER)
1849 { 1877 {
1855 */ 1883 */
1856 skop = find_skill_by_name (op, skill_names[SK_LITERACY]); 1884 skop = find_skill_by_name (op, skill_names[SK_LITERACY]);
1857 1885
1858 if (!skop) 1886 if (!skop)
1859 { 1887 {
1860 new_draw_info (NDI_UNIQUE, 0, op, "You are unable to decipher the strange symbols."); 1888 new_draw_info (NDI_UNIQUE, 0, op, "You are unable to decipher the strange symbols. H<You lack the literacy skill.>");
1861 return; 1889 return;
1862 } 1890 }
1863 1891
1864 if ((exp_gain = calc_skill_exp (op, tmp, skop))) 1892 if ((exp_gain = calc_skill_exp (op, tmp, skop)))
1865 change_exp (op, exp_gain, skop->skill, 0); 1893 change_exp (op, exp_gain, skop->skill, 0);
1867 1895
1868 if (!QUERY_FLAG (tmp, FLAG_IDENTIFIED)) 1896 if (!QUERY_FLAG (tmp, FLAG_IDENTIFIED))
1869 identify (tmp); 1897 identify (tmp);
1870 1898
1871 new_draw_info_format (NDI_BLACK, 0, op, "The scroll of %s turns to dust.", &tmp->inv->name); 1899 new_draw_info_format (NDI_BLACK, 0, op, "The scroll of %s turns to dust.", &tmp->inv->name);
1872
1873 1900
1874 cast_spell (op, tmp, dir, tmp->inv, NULL); 1901 cast_spell (op, tmp, dir, tmp->inv, NULL);
1875 decrease_ob (tmp); 1902 decrease_ob (tmp);
1876} 1903}
1877 1904
1881 * chest. 1908 * chest.
1882 */ 1909 */
1883static void 1910static void
1884apply_treasure (object *op, object *tmp) 1911apply_treasure (object *op, object *tmp)
1885{ 1912{
1886 object *treas;
1887
1888
1889 /* Nice side effect of new treasure creation method is that the treasure 1913 /* Nice side effect of new treasure creation method is that the treasure
1890 * for the chest is done when the chest is created, and put into the chest 1914 * for the chest is done when the chest is created, and put into the chest
1891 * inventory. So that when the chest burns up, the items still exist. Also 1915 * inventory. So that when the chest burns up, the items still exist. Also
1892 * prevents people fromt moving chests to more difficult maps to get better 1916 * prevents people fromt moving chests to more difficult maps to get better
1893 * treasure 1917 * treasure
1894 */ 1918 */
1895
1896 treas = tmp->inv; 1919 object *treas = tmp->inv;
1897 if (treas == NULL) 1920
1921 if (!treas)
1898 { 1922 {
1899 new_draw_info (NDI_UNIQUE, 0, op, "The chest was empty."); 1923 new_draw_info (NDI_UNIQUE, 0, op, "The chest was empty.");
1900 decrease_ob (tmp); 1924 decrease_ob (tmp);
1901 return; 1925 return;
1902 } 1926 }
1927
1903 while (tmp->inv) 1928 while (tmp->inv)
1904 { 1929 {
1905 treas = tmp->inv; 1930 treas = tmp->inv;
1906 1931
1907 treas->remove (); 1932 treas->remove ();
1989 /* special food hack -b.t. */ 2014 /* special food hack -b.t. */
1990 if (tmp->title || QUERY_FLAG (tmp, FLAG_CURSED)) 2015 if (tmp->title || QUERY_FLAG (tmp, FLAG_CURSED))
1991 eat_special_food (op, tmp); 2016 eat_special_food (op, tmp);
1992 } 2017 }
1993 } 2018 }
2019
1994 handle_apply_yield (tmp); 2020 handle_apply_yield (tmp);
1995 decrease_ob (tmp); 2021 decrease_ob (tmp);
1996} 2022}
1997 2023
1998/** 2024/**
2025 if (meal->type != FLESH || !is_dragon_pl (op)) 2051 if (meal->type != FLESH || !is_dragon_pl (op))
2026 return 0; 2052 return 0;
2027 2053
2028 /* now grab the 'dragon_skin'- and 'dragon_ability'-forces 2054 /* now grab the 'dragon_skin'- and 'dragon_ability'-forces
2029 from the player's inventory */ 2055 from the player's inventory */
2030 shstr_cmp dragon_ability_force ("dragon_ability_force");
2031 shstr_cmp dragon_skin_force ("dragon_skin_force");
2032
2033 for (tmp = op->inv; tmp; tmp = tmp->below) 2056 for (tmp = op->inv; tmp; tmp = tmp->below)
2034 if (tmp->type == FORCE) 2057 if (tmp->type == FORCE)
2035 if (tmp->arch->name == dragon_skin_force) 2058 if (tmp->arch->archname == shstr_dragon_skin_force)
2036 skin = tmp; 2059 skin = tmp;
2037 else if (tmp->arch->name == dragon_ability_force) 2060 else if (tmp->arch->archname == shstr_dragon_ability_force)
2038 abil = tmp; 2061 abil = tmp;
2039 2062
2040 /* if either skin or ability are missing, this is an old player 2063 /* if either skin or ability are missing, this is an old player
2041 which is not to be considered a dragon -> bail out */ 2064 which is not to be considered a dragon -> bail out */
2042 if (skin == NULL || abil == NULL) 2065 if (skin == NULL || abil == NULL)
2163static void 2186static void
2164apply_armour_improver (object *op, object *tmp) 2187apply_armour_improver (object *op, object *tmp)
2165{ 2188{
2166 object *armor; 2189 object *armor;
2167 2190
2168 if (!QUERY_FLAG (op, FLAG_WIZCAST) && (get_map_flags (op->map, NULL, op->x, op->y, NULL, NULL) & P_NO_MAGIC)) 2191 if (!QUERY_FLAG (op, FLAG_WIZCAST) && (get_map_flags (op->map, 0, op->x, op->y, 0, 0) & P_NO_MAGIC))
2169 { 2192 {
2170 new_draw_info (NDI_UNIQUE, 0, op, "Something blocks the magic of the scroll."); 2193 new_draw_info (NDI_UNIQUE, 0, op, "Something blocks the magic of the scroll. H<The area prevents magic effects.>");
2171 return; 2194 return;
2172 } 2195 }
2173 2196
2174 armor = find_marked_object (op); 2197 armor = find_marked_object (op);
2175 2198
2176 if (!armor) 2199 if (!armor)
2177 { 2200 {
2178 new_draw_info (NDI_UNIQUE, 0, op, "You need to mark an armor object."); 2201 new_draw_info (NDI_UNIQUE, 0, op, "You need to mark an armor object. Use the right mouse button popup or the mark command to do this.");
2179 return; 2202 return;
2180 } 2203 }
2181 2204
2182 if (armor->type != ARMOUR 2205 if (armor->type != ARMOUR
2183 && armor->type != CLOAK 2206 && armor->type != CLOAK
2194extern void 2217extern void
2195apply_poison (object *op, object *tmp) 2218apply_poison (object *op, object *tmp)
2196{ 2219{
2197 if (op->type == PLAYER) 2220 if (op->type == PLAYER)
2198 { 2221 {
2199 play_sound_player_only (op->contr, SOUND_DRINK_POISON, 0, 0); 2222 op->contr->play_sound (sound_find ("drink_poison"));
2200 new_draw_info (NDI_UNIQUE, 0, op, "Yech! That tasted poisonous!"); 2223 new_draw_info (NDI_UNIQUE, 0, op, "Yech! That tasted poisonous!");
2201 strcpy (op->contr->killer, "poisonous booze"); 2224 strcpy (op->contr->killer, "poisonous booze");
2202 } 2225 }
2226
2203 if (tmp->stats.hp > 0) 2227 if (tmp->stats.hp > 0)
2204 { 2228 {
2205 LOG (llevDebug, "Trying to poison player/monster for %d hp\n", tmp->stats.hp); 2229 LOG (llevDebug, "Trying to poison player/monster for %d hp\n", tmp->stats.hp);
2206 hit_player (op, tmp->stats.hp, tmp, AT_POISON, 1); 2230 hit_player (op, tmp->stats.hp, tmp, AT_POISON, 1);
2207 } 2231 }
2232
2208 op->stats.food -= op->stats.food / 4; 2233 op->stats.food -= op->stats.food / 4;
2209 handle_apply_yield (tmp); 2234 handle_apply_yield (tmp);
2210 decrease_ob (tmp); 2235 decrease_ob (tmp);
2211} 2236}
2212 2237
2322 2347
2323 if (QUERY_FLAG (tmp, FLAG_UNPAID) && !QUERY_FLAG (tmp, FLAG_APPLIED)) 2348 if (QUERY_FLAG (tmp, FLAG_UNPAID) && !QUERY_FLAG (tmp, FLAG_APPLIED))
2324 { 2349 {
2325 if (op->type == PLAYER) 2350 if (op->type == PLAYER)
2326 { 2351 {
2327 new_draw_info (NDI_UNIQUE, 0, op, "You should pay for it first."); 2352 new_draw_info (NDI_UNIQUE, 0, op, "You should pay for it first. H<You cannot use items marked as unpaid.>");
2328 return 1; 2353 return 1;
2329 } 2354 }
2330 else 2355 else
2331 return 0; /* monsters just skip unpaid items */ 2356 return 0; /* monsters just skip unpaid items */
2332 } 2357 }
2336 2361
2337 switch (tmp->type) 2362 switch (tmp->type)
2338 { 2363 {
2339 case CF_HANDLE: 2364 case CF_HANDLE:
2340 new_draw_info (NDI_UNIQUE, 0, op, "You turn the handle."); 2365 new_draw_info (NDI_UNIQUE, 0, op, "You turn the handle.");
2341 play_sound_map (op->map, op->x, op->y, SOUND_TURN_HANDLE); 2366 op->play_sound (sound_find ("turn_handle"));
2342 tmp->value = tmp->value ? 0 : 1; 2367 tmp->value = tmp->value ? 0 : 1;
2343 SET_ANIMATION (tmp, tmp->value); 2368 SET_ANIMATION (tmp, tmp->value);
2344 update_object (tmp, UP_OBJ_FACE); 2369 update_object (tmp, UP_OBJ_FACE);
2345 push_button (tmp); 2370 push_button (tmp);
2346 return 1; 2371 return 1;
2347 2372
2348 case TRIGGER: 2373 case TRIGGER:
2349 if (check_trigger (tmp, op)) 2374 if (check_trigger (tmp, op))
2350 { 2375 {
2351 new_draw_info (NDI_UNIQUE, 0, op, "You turn the handle."); 2376 new_draw_info (NDI_UNIQUE, 0, op, "You turn the handle.");
2352 play_sound_map (tmp->map, tmp->x, tmp->y, SOUND_TURN_HANDLE); 2377 op->play_sound (sound_find ("turn_handle"));
2353 } 2378 }
2354 else 2379 else
2355 new_draw_info (NDI_UNIQUE, 0, op, "The handle doesn't move."); 2380 new_draw_info (NDI_UNIQUE, 0, op, "The handle doesn't move.");
2356 2381
2357 return 1; 2382 return 1;
2490 2515
2491 get_tod (&tod); 2516 get_tod (&tod);
2492 sprintf (buf, "It is %d minute%s past %d o'clock %s", 2517 sprintf (buf, "It is %d minute%s past %d o'clock %s",
2493 tod.minute + 1, ((tod.minute + 1 < 2) ? "" : "s"), 2518 tod.minute + 1, ((tod.minute + 1 < 2) ? "" : "s"),
2494 ((tod.hour % 14 == 0) ? 14 : ((tod.hour) % 14)), ((tod.hour >= 14) ? "pm" : "am")); 2519 ((tod.hour % 14 == 0) ? 14 : ((tod.hour) % 14)), ((tod.hour >= 14) ? "pm" : "am"));
2495 play_sound_player_only (op->contr, SOUND_CLOCK, 0, 0); 2520 op->play_sound (sound_find ("sound_clock"));
2496 new_draw_info (NDI_UNIQUE, 0, op, buf); 2521 new_draw_info (NDI_UNIQUE, 0, op, buf);
2497 return 1; 2522 return 1;
2498 } 2523 }
2499 else 2524 else
2500 return 0; 2525 return 0;
2540int 2565int
2541player_apply (object *pl, object *op, int aflag, int quiet) 2566player_apply (object *pl, object *op, int aflag, int quiet)
2542{ 2567{
2543 int tmp; 2568 int tmp;
2544 2569
2545 if (op->env == NULL && (pl->move_type & MOVE_FLYING)) 2570 if (op->env && (pl->move_type & MOVE_FLYING))
2546 { 2571 {
2547 /* player is flying and applying object not in inventory */ 2572 /* player is flying and applying object not in inventory */
2548 if (!QUERY_FLAG (pl, FLAG_WIZ) && !(op->move_type & MOVE_FLYING)) 2573 if (!QUERY_FLAG (pl, FLAG_WIZ) && !(op->move_type & MOVE_FLYING))
2549 { 2574 {
2550 new_draw_info (NDI_UNIQUE, 0, pl, "But you are floating high " "above the ground!"); 2575 new_draw_info (NDI_UNIQUE, 0, pl, "But you are floating high above the ground! H<You have to stop levitating first, if you can.>");
2551 return 0; 2576 return 0;
2552 } 2577 }
2553 }
2554
2555 /* Check for PLAYER to avoid a DM to disappear in a puff of smoke if
2556 * applied.
2557 */
2558 if (op->type != PLAYER && QUERY_FLAG (op, FLAG_WAS_WIZ) && !QUERY_FLAG (pl, FLAG_WAS_WIZ))
2559 {
2560 play_sound_map (pl->map, pl->x, pl->y, SOUND_OB_EVAPORATE);
2561 new_draw_info (NDI_UNIQUE, 0, pl, "The object disappears in a puff " "of smoke!");
2562 new_draw_info (NDI_UNIQUE, 0, pl, "It must have been an illusion.");
2563 op->destroy ();
2564 return 1;
2565 } 2578 }
2566 2579
2567 pl->contr->last_used = op; 2580 pl->contr->last_used = op;
2568 2581
2569 tmp = manual_apply (pl, op, aflag); 2582 tmp = manual_apply (pl, op, aflag);
2572 if (tmp == 0) 2585 if (tmp == 0)
2573 new_draw_info_format (NDI_UNIQUE, 0, pl, "I don't know how to apply the %s.", query_name (op)); 2586 new_draw_info_format (NDI_UNIQUE, 0, pl, "I don't know how to apply the %s.", query_name (op));
2574 else if (tmp == 2) 2587 else if (tmp == 2)
2575 new_draw_info_format (NDI_UNIQUE, 0, pl, "You must get it first!\n"); 2588 new_draw_info_format (NDI_UNIQUE, 0, pl, "You must get it first!\n");
2576 } 2589 }
2590
2577 return tmp; 2591 return tmp;
2578} 2592}
2579 2593
2580/** 2594/**
2581 * player_apply_below attempts to apply the object 'below' the player. 2595 * player_apply_below attempts to apply the object 'below' the player.
2630{ 2644{
2631 if (INVOKE_OBJECT (BE_UNREADY, op, ARG_OBJECT (who), ARG_INT (aflags)) 2645 if (INVOKE_OBJECT (BE_UNREADY, op, ARG_OBJECT (who), ARG_INT (aflags))
2632 || INVOKE_OBJECT (UNREADY, who, ARG_OBJECT (op), ARG_INT (aflags))) 2646 || INVOKE_OBJECT (UNREADY, who, ARG_OBJECT (op), ARG_INT (aflags)))
2633 return RESULT_INT (0); 2647 return RESULT_INT (0);
2634 2648
2635 object *tmp2;
2636
2637 CLEAR_FLAG (op, FLAG_APPLIED); 2649 CLEAR_FLAG (op, FLAG_APPLIED);
2638
2639 if (player *pl = who->contr)
2640 {
2641 if (op == pl->ranged_ob) pl->ranged_ob = 0;
2642 if (op == pl->combat_ob) pl->combat_ob = 0;
2643 }
2644 2650
2645 switch (op->type) 2651 switch (op->type)
2646 { 2652 {
2647 case SKILL_TOOL: 2653 case SKILL_TOOL:
2648 // unapplying a skill tool should also unapply the skill it governs 2654 // unapplying a skill tool should also unapply the skill it governs
2657 2663
2658 change_abil (who, op); 2664 change_abil (who, op);
2659 break; 2665 break;
2660 2666
2661 case WEAPON: 2667 case WEAPON:
2668 if (player *pl = who->contr)
2669 if (op == pl->combat_ob)
2670 {
2671 pl->combat_ob = 0;
2672 who->change_weapon (pl->ranged_ob);
2673 }
2674
2662 new_draw_info_format (NDI_UNIQUE, 0, who, "You unwield %s.", query_name (op)); 2675 new_draw_info_format (NDI_UNIQUE, 0, who, "You unwield %s.", query_name (op));
2663 2676
2664 change_abil (who, op); 2677 change_abil (who, op);
2665 CLEAR_FLAG (who, FLAG_READY_WEAPON); 2678 CLEAR_FLAG (who, FLAG_READY_WEAPON);
2666 clear_skill (who);
2667 break; 2679 break;
2668 2680
2669 case SKILL: 2681 case SKILL:
2670 if (op != who->chosen_skill)
2671 LOG (llevError, "BUG: apply_special(): applied skill is not a chosen skill\n");
2672
2673 if (who->contr) 2682 if (who->contr)
2674 { 2683 {
2675 if (!op->invisible) 2684 if (!op->invisible)
2676 new_draw_info_format (NDI_UNIQUE, 0, who, "You stop using the %s.", query_name (op)); 2685 new_draw_info_format (NDI_UNIQUE, 0, who, "You stop using the %s.", query_name (op));
2677 else 2686 else
2678 new_draw_info_format (NDI_UNIQUE, 0, who, "You can no longer use the skill: %s.", &op->skill); 2687 new_draw_info_format (NDI_UNIQUE, 0, who, "You can no longer use the skill: %s.", &op->skill);
2679 } 2688 }
2680 2689
2681 change_abil (who, op); 2690 change_abil (who, op);
2682 who->chosen_skill = 0;
2683 CLEAR_FLAG (who, FLAG_READY_SKILL); 2691 CLEAR_FLAG (who, FLAG_READY_SKILL);
2684 break; 2692 break;
2685 2693
2686 case ARMOUR: 2694 case ARMOUR:
2687 case HELMET: 2695 case HELMET:
2696 new_draw_info_format (NDI_UNIQUE, 0, who, "You unwear %s.", query_name (op)); 2704 new_draw_info_format (NDI_UNIQUE, 0, who, "You unwear %s.", query_name (op));
2697 change_abil (who, op); 2705 change_abil (who, op);
2698 break; 2706 break;
2699 2707
2700 case LAMP: 2708 case LAMP:
2709 {
2701 new_draw_info_format (NDI_UNIQUE, 0, who, "You turn off your %s.", &op->name); 2710 new_draw_info_format (NDI_UNIQUE, 0, who, "You turn off your %s.", &op->name);
2711
2702 tmp2 = arch_to_object (op->other_arch); 2712 object *tmp2 = arch_to_object (op->other_arch);
2703 tmp2->x = op->x; 2713 tmp2->x = op->x;
2704 tmp2->y = op->y; 2714 tmp2->y = op->y;
2705 tmp2->map = op->map; 2715 tmp2->map = op->map;
2706 tmp2->below = op->below; 2716 tmp2->below = op->below;
2707 tmp2->above = op->above; 2717 tmp2->above = op->above;
2708 tmp2->stats.food = op->stats.food; 2718 tmp2->stats.food = op->stats.food;
2709 CLEAR_FLAG (tmp2, FLAG_APPLIED); 2719 CLEAR_FLAG (tmp2, FLAG_APPLIED);
2710 2720
2711 if (QUERY_FLAG (op, FLAG_INV_LOCKED)) 2721 if (QUERY_FLAG (op, FLAG_INV_LOCKED))
2712 SET_FLAG (tmp2, FLAG_INV_LOCKED); 2722 SET_FLAG (tmp2, FLAG_INV_LOCKED);
2713 2723
2714 if (who->contr) 2724 if (who->contr)
2715 esrv_del_item (who->contr, op->count); 2725 esrv_del_item (who->contr, op->count);
2716 2726
2717 op->destroy (); 2727 op->destroy ();
2718 insert_ob_in_ob (tmp2, who); 2728 insert_ob_in_ob (tmp2, who);
2719 who->update_stats (); 2729 who->update_stats ();
2720 2730
2721 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED)) 2731 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED))
2722 { 2732 {
2723 if (who->contr) 2733 if (who->contr)
2724 { 2734 {
2725 new_draw_info (NDI_UNIQUE, 0, who, "Oops, it feels deadly cold!"); 2735 new_draw_info (NDI_UNIQUE, 0, who, "Oops, it feels deadly cold!");
2726 SET_FLAG (tmp2, FLAG_KNOWN_CURSED); 2736 SET_FLAG (tmp2, FLAG_KNOWN_CURSED);
2727 } 2737 }
2728 } 2738 }
2729 2739
2730 if (who->contr) 2740 if (who->contr)
2731 esrv_send_item (who, tmp2); 2741 esrv_send_item (who, tmp2);
2742 }
2732 2743
2733 return 1; /* otherwise, an attempt to drop causes problems */ 2744 return 1; /* otherwise, an attempt to drop causes problems */
2734 2745
2735 case BOW: 2746 case BOW:
2736 case WAND: 2747 case WAND:
2737 case ROD: 2748 case ROD:
2738 case HORN: 2749 case HORN:
2739 clear_skill (who);
2740
2741 if (who->contr) 2750 if (player *pl = who->contr)
2751 {
2752 if (op == pl->ranged_ob)
2742 { 2753 {
2754 pl->ranged_ob = 0;
2755 who->change_weapon (pl->combat_ob);
2756 }
2757
2743 new_draw_info_format (NDI_UNIQUE, 0, who, "You unready %s.", query_name (op)); 2758 new_draw_info_format (NDI_UNIQUE, 0, who, "You unready %s.", query_name (op));
2744
2745 if (who->contr->ranged_ob == op)
2746 who->contr->ranged_ob = 0;
2747
2748 if (who->current_weapon == op)
2749 who->current_weapon = 0;
2750 } 2759 }
2751 else 2760 else
2752 { 2761 {
2762 who->change_skill (0);
2763
2753 if (op->type == BOW) 2764 if (op->type == BOW)
2754 CLEAR_FLAG (who, FLAG_READY_BOW); 2765 CLEAR_FLAG (who, FLAG_READY_BOW);
2755 else 2766 else
2756 CLEAR_FLAG (who, FLAG_READY_RANGE); 2767 CLEAR_FLAG (who, FLAG_READY_RANGE);
2757 } 2768 }
2758 2769
2759 break; 2770 break;
2760 2771
2761 case BUILDER: 2772 case BUILDER:
2762 if (who->contr) 2773 if (who->contr)
2763 {
2764 new_draw_info_format (NDI_UNIQUE, 0, who, "You unready %s.", query_name (op)); 2774 new_draw_info_format (NDI_UNIQUE, 0, who, "You unready %s.", query_name (op));
2765
2766 if (who->contr->ranged_ob == op)
2767 who->contr->ranged_ob = 0;
2768 }
2769 break; 2775 break;
2770 2776
2771 default: 2777 default:
2772 new_draw_info_format (NDI_UNIQUE, 0, who, "You unapply %s.", query_name (op)); 2778 new_draw_info_format (NDI_UNIQUE, 0, who, "You unapply %s.", query_name (op));
2773 break; 2779 break;
2829 * Returns 0 on success, returns 1 if there is some problem. 2835 * Returns 0 on success, returns 1 if there is some problem.
2830 * if aflags is AP_PRINT, we instead print out waht to unapply 2836 * if aflags is AP_PRINT, we instead print out waht to unapply
2831 * instead of doing it. This is a lot less code than having 2837 * instead of doing it. This is a lot less code than having
2832 * another function that does just that. 2838 * another function that does just that.
2833 */ 2839 */
2840
2841#define CANNOT_REMOVE_CURSED \
2842 "H<You cannot remove cursed or damned items, you first have to remove the curse. " \
2843 "Praying over an altar, scrolls of remove curse/damnation, " \
2844 "priests or even other players might help.>"
2845
2834int 2846int
2835unapply_for_ob (object *who, object *op, int aflags) 2847unapply_for_ob (object *who, object *op, int aflags)
2836{ 2848{
2837 if (op->is_range ()) 2849 if (op->is_range ())
2838 for (object *tmp = who->inv; tmp; tmp = tmp->below) 2850 for (object *tmp = who->inv; tmp; tmp = tmp->below)
2848 { 2860 {
2849 /* In this case, we want to try and remove a cursed item. 2861 /* In this case, we want to try and remove a cursed item.
2850 * While we know it won't work, we want unapply_special to 2862 * While we know it won't work, we want unapply_special to
2851 * at least generate the message. 2863 * at least generate the message.
2852 */ 2864 */
2853 new_draw_info_format (NDI_UNIQUE, 0, who, "No matter how hard you try, you just can't remove the %s.", query_name (tmp)); 2865 new_draw_info_format (NDI_UNIQUE, 0, who,
2866 "No matter how hard you try, you just can't remove the %s." CANNOT_REMOVE_CURSED,
2867 query_name (tmp));
2854 return 1; 2868 return 1;
2855 } 2869 }
2856 2870
2857 for (int i = 0; i < NUM_BODY_LOCATIONS; i++) 2871 for (int i = 0; i < NUM_BODY_LOCATIONS; i++)
2858 { 2872 {
2892 /* Cursed item that we can't unequip - tell the player. 2906 /* Cursed item that we can't unequip - tell the player.
2893 * Note this could be annoying if this is just one of a few, 2907 * Note this could be annoying if this is just one of a few,
2894 * so it may not be critical (eg, putting on a ring and you have 2908 * so it may not be critical (eg, putting on a ring and you have
2895 * one cursed ring.) 2909 * one cursed ring.)
2896 */ 2910 */
2897 new_draw_info_format (NDI_UNIQUE, 0, who, "The %s just won't come off", query_name (tmp)); 2911 new_draw_info_format (NDI_UNIQUE, 0, who, "The %s just won't come off." CANNOT_REMOVE_CURSED, query_name (tmp));
2898 } 2912 }
2899 2913
2900 last = tmp->below; 2914 last = tmp->below;
2901 } 2915 }
2902 /* if we got here, this slot is freed up - otherwise, if it wasn't freed up, the 2916 /* if we got here, this slot is freed up - otherwise, if it wasn't freed up, the
2968 /* This is sort of an error, but happens a lot when old players 2982 /* This is sort of an error, but happens a lot when old players
2969 * join in with more stuff equipped than they are now allowed. 2983 * join in with more stuff equipped than they are now allowed.
2970 */ 2984 */
2971 LOG (llevError, "Can't find object using location %d on %s\n", i, who->name); 2985 LOG (llevError, "Can't find object using location %d on %s\n", i, who->name);
2972#endif 2986#endif
2973 fprintf (stderr, "can apply never due to %d but %d - %d + %d\n",//D
2974 i, who->slot[i].used,ws ? ws->slot[i].info :-77,op->slot[i].info);//D
2975 retval |= CAN_APPLY_NEVER; 2987 retval |= CAN_APPLY_NEVER;
2976 } 2988 }
2977 else 2989 else
2978 { 2990 {
2979 /* need to unapply something. However, if this something 2991 /* need to unapply something. However, if this something
3051 * AP_UNAPPLY=always unapply). 3063 * AP_UNAPPLY=always unapply).
3052 * 3064 *
3053 * Optional flags: 3065 * Optional flags:
3054 * AP_NO_MERGE: don't merge an unapplied object with other objects 3066 * AP_NO_MERGE: don't merge an unapplied object with other objects
3055 * AP_IGNORE_CURSE: unapply cursed items 3067 * AP_IGNORE_CURSE: unapply cursed items
3068 * AP_NO_READY: do not ready skills when applying skill tools
3056 * 3069 *
3057 * Usage example: apply_special (who, op, AP_UNAPPLY | AP_IGNORE_CURSE) 3070 * Usage example: apply_special (who, op, AP_UNAPPLY | AP_IGNORE_CURSE)
3058 * 3071 *
3059 * apply_special() doesn't check for unpaid items. 3072 * apply_special() doesn't check for unpaid items.
3060 */ 3073 */
3074
3075#define LACK_ITEM_POWER \
3076 " H<You lack enough unused item power to use this weapon, see the skills command.>"
3077
3061int 3078int
3062apply_special (object *who, object *op, int aflags) 3079apply_special (object *who, object *op, int aflags)
3063{ 3080{
3064 int basic_flag = aflags & AP_BASIC_FLAGS; 3081 int basic_flag = aflags & AP_BASIC_FLAGS;
3065 object *tmp, *tmp2, *skop = NULL; 3082 object *tmp, *tmp2, *skop = NULL;
3080 if (basic_flag == AP_APPLY) 3097 if (basic_flag == AP_APPLY)
3081 return 0; 3098 return 0;
3082 3099
3083 if (!(aflags & AP_IGNORE_CURSE) && (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED))) 3100 if (!(aflags & AP_IGNORE_CURSE) && (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED)))
3084 { 3101 {
3085 new_draw_info_format (NDI_UNIQUE, 0, who, "No matter how hard you try, you just can't remove %s.", query_name (op)); 3102 new_draw_info_format (NDI_UNIQUE, 0, who,
3103 "No matter how hard you try, you just can't remove %s." CANNOT_REMOVE_CURSED,
3104 query_name (op));
3086 return 1; 3105 return 1;
3087 } 3106 }
3088 3107
3089 return unapply_special (who, op, aflags); 3108 return unapply_special (who, op, aflags);
3090 } 3109 }
3099 { 3118 {
3100 case slot_combat: who->change_weapon (pl->combat_ob); break; 3119 case slot_combat: who->change_weapon (pl->combat_ob); break;
3101 case slot_ranged: who->change_weapon (pl->ranged_ob); break; 3120 case slot_ranged: who->change_weapon (pl->ranged_ob); break;
3102 } 3121 }
3103 3122
3123 splay (op);
3124
3104 /* Can't just apply this object. Lets see what not and what to do */ 3125 /* Can't just apply this object. Lets see what not and what to do */
3105 if (int i = can_apply_object (who, op)) 3126 if (int i = can_apply_object (who, op))
3106 { 3127 {
3107 if (i & CAN_APPLY_NEVER) 3128 if (i & CAN_APPLY_NEVER)
3108 { 3129 {
3109 new_draw_info_format (NDI_UNIQUE, 0, who, "You don't have the body to use a %s\n", query_name (op)); 3130 new_draw_info_format (NDI_UNIQUE, 0, who,
3131 "You don't have the body to use a %s. H<You can never apply this item.>",
3132 query_name (op));
3110 return 1; 3133 return 1;
3111 } 3134 }
3112 else if (i & CAN_APPLY_RESTRICTION) 3135 else if (i & CAN_APPLY_RESTRICTION)
3113 { 3136 {
3114 new_draw_info_format (NDI_UNIQUE, 0, who, "You have a prohibition against using a %s\n", query_name (op)); 3137 new_draw_info_format (NDI_UNIQUE, 0, who,
3138 "You have a prohibition against using a %s. "
3139 "H<Your belief, profession or class prevents you from applying this item.>",
3140 query_name (op));
3115 return 1; 3141 return 1;
3116 } 3142 }
3117 3143
3118 if (who->type != PLAYER) 3144 if (who->type != PLAYER)
3119 { 3145 {
3146 } 3172 }
3147 else 3173 else
3148 /* While experience will be credited properly, we want to change the 3174 /* While experience will be credited properly, we want to change the
3149 * skill so that the dam and wc get updated 3175 * skill so that the dam and wc get updated
3150 */ 3176 */
3151 change_skill (who, skop, 0); 3177 who->change_skill (skop);
3152 } 3178 }
3153 3179
3154 if (who->type == PLAYER 3180 if (who->type == PLAYER
3155 && op->item_power 3181 && op->item_power
3156 && op->item_power + who->contr->item_power > settings.item_power_factor * who->level) 3182 && op->item_power + who->contr->item_power > settings.item_power_factor * who->level)
3157 { 3183 {
3158 new_draw_info (NDI_UNIQUE, 0, who, 3184 new_draw_info (NDI_UNIQUE, 0, who,
3159 "Equipping that combined with other items would consume your soul! " 3185 "Equipping that combined with other items would consume your soul!" LACK_ITEM_POWER);
3160 "[use the skills command to check your available item power]");
3161 return 1; 3186 return 1;
3162 } 3187 }
3163 3188
3164 /* Ok. We are now at the state where we can apply the new object. 3189 /* Ok. We are now at the state where we can apply the new object.
3165 * Note that we don't have the checks for can_use_... 3190 * Note that we don't have the checks for can_use_...
3176 switch (op->type) 3201 switch (op->type)
3177 { 3202 {
3178 case WEAPON: 3203 case WEAPON:
3179 if (!check_weapon_power (who, op->last_eat)) 3204 if (!check_weapon_power (who, op->last_eat))
3180 { 3205 {
3181 new_draw_info (NDI_UNIQUE, 0, who, "This weapon is too powerful for you to use.\n" 3206 new_draw_info (NDI_UNIQUE, 0, who, "This weapon is too powerful for you to use. "
3182 "It would consume your soul!."); 3207 "It would consume your soul!." LACK_ITEM_POWER);
3183 3208
3184 if (tmp) 3209 if (tmp)
3185 insert_ob_in_ob (tmp, who); 3210 insert_ob_in_ob (tmp, who);
3186 3211
3187 return 1; 3212 return 1;
3191 // i.e. "R" can use Ragnarok's sword. 3216 // i.e. "R" can use Ragnarok's sword.
3192 if (op->level && (strncmp (op->name, who->name, strlen (who->name)))) 3217 if (op->level && (strncmp (op->name, who->name, strlen (who->name))))
3193 { 3218 {
3194 /* if the weapon does not have the name as the character, can't use it. */ 3219 /* if the weapon does not have the name as the character, can't use it. */
3195 /* (Ragnarok's sword attempted to be used by Foo: won't work) */ 3220 /* (Ragnarok's sword attempted to be used by Foo: won't work) */
3196 new_draw_info (NDI_UNIQUE, 0, who, "The weapon does not recognize you as its owner."); 3221 new_draw_info (NDI_UNIQUE, 0, who,
3222 "The weapon does not recognize you as its owner. "
3223 "H<Its name indicates that it belongs to somebody else.>");
3197 3224
3198 if (tmp) 3225 if (tmp)
3199 insert_ob_in_ob (tmp, who); 3226 insert_ob_in_ob (tmp, who);
3200 3227
3201 return 1; 3228 return 1;
3206 new_draw_info_format (NDI_UNIQUE, 0, who, "The %s is broken, please report this to the dungeon master!", query_name (op));//TODO 3233 new_draw_info_format (NDI_UNIQUE, 0, who, "The %s is broken, please report this to the dungeon master!", query_name (op));//TODO
3207 return 1; 3234 return 1;
3208 } 3235 }
3209 3236
3210 SET_FLAG (op, FLAG_APPLIED); 3237 SET_FLAG (op, FLAG_APPLIED);
3211 change_skill (who, skop, 1); 3238 who->change_skill (skop);
3212 3239
3213 if (who->contr) 3240 if (who->contr)
3214 who->change_weapon (who->contr->combat_ob = op); 3241 who->change_weapon (who->contr->combat_ob = op);
3215 3242
3216 if (!QUERY_FLAG (who, FLAG_READY_WEAPON))
3217 SET_FLAG (who, FLAG_READY_WEAPON);
3218
3219 new_draw_info_format (NDI_UNIQUE, 0, who, "You wield %s.", query_name (op)); 3243 new_draw_info_format (NDI_UNIQUE, 0, who, "You wield %s.", query_name (op));
3220 3244
3245 SET_FLAG (who, FLAG_READY_WEAPON);
3221 change_abil (who, op); 3246 change_abil (who, op);
3222 break; 3247 break;
3223 3248
3224 case ARMOUR: 3249 case ARMOUR:
3225 case HELMET: 3250 case HELMET:
3237 break; 3262 break;
3238 3263
3239 case LAMP: 3264 case LAMP:
3240 if (op->stats.food < 1) 3265 if (op->stats.food < 1)
3241 { 3266 {
3242 new_draw_info_format (NDI_UNIQUE, 0, who, "Your %s is out of fuel!", &op->name); 3267 new_draw_info_format (NDI_UNIQUE, 0, who,
3268 "Your %s is out of fuel! "
3269 "H<Lamps and similar items need fuel. They cannot be refilled.>", &op->name);
3243 return 1; 3270 return 1;
3244 } 3271 }
3245 3272
3246 new_draw_info_format (NDI_UNIQUE, 0, who, "You turn on your %s.", &op->name); 3273 new_draw_info_format (NDI_UNIQUE, 0, who, "You turn on your %s.", &op->name);
3247 tmp2 = arch_to_object (op->other_arch); 3274 tmp2 = arch_to_object (op->other_arch);
3270 who->update_stats (); 3297 who->update_stats ();
3271 3298
3272 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED)) 3299 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED))
3273 if (who->type == PLAYER) 3300 if (who->type == PLAYER)
3274 { 3301 {
3275 new_draw_info (NDI_UNIQUE, 0, who, "Oops, it feels deadly cold!"); 3302 new_draw_info (NDI_UNIQUE, 0, who,
3303 "Oops, it feels deadly cold! "
3304 "H<Maybe it wasn't such a bright idea to apply this cursed/damned item.>");
3276 SET_FLAG (tmp2, FLAG_KNOWN_CURSED); 3305 SET_FLAG (tmp2, FLAG_KNOWN_CURSED);
3277 } 3306 }
3278 3307
3279 if (who->type == PLAYER) 3308 if (who->type == PLAYER)
3280 esrv_send_item (who, tmp2); 3309 esrv_send_item (who, tmp2);
3282 return 0; 3311 return 0;
3283 3312
3284 case SKILL_TOOL: 3313 case SKILL_TOOL:
3285 // applying a skill tool also readies the skill 3314 // applying a skill tool also readies the skill
3286 SET_FLAG (op, FLAG_APPLIED); 3315 SET_FLAG (op, FLAG_APPLIED);
3316
3317 if (!(aflags & AP_NO_READY))
3318 {
3287 skop = find_skill_by_name (who, op->skill); 3319 skop = find_skill_by_name (who, op->skill);
3288 if (!skop->flag [FLAG_APPLIED]) 3320 if (!skop->flag [FLAG_APPLIED])
3289 apply_special (who, skop, AP_APPLY); 3321 apply_special (who, skop, AP_APPLY);
3322 }
3290 break; 3323 break;
3291 3324
3292 case SKILL: 3325 case SKILL:
3293 if (who->chosen_skill)
3294 {
3295 LOG (llevError, "BUG: apply_special(): can't apply two skills\n");
3296 return 1;
3297 }
3298
3299 if (player *pl = who->contr) 3326 if (player *pl = who->contr)
3300 { 3327 {
3301 if (IS_COMBAT_SKILL (op->subtype)) 3328 if (IS_COMBAT_SKILL (op->subtype))
3302 { 3329 {
3303 if (skill_flags [op->subtype] & SF_NEED_WEAPON) 3330 if (skill_flags [op->subtype] & SF_NEED_WEAPON)
3304 { 3331 {
3305 for (object *item = who->inv; item; item = item->below) 3332 for (object *item = who->inv; item; item = item->below)
3306 if (item->type == WEAPON && item->flag [FLAG_APPLIED]) 3333 if (item->type == WEAPON && item->flag [FLAG_APPLIED])
3307 { 3334 {
3335 if (item->skill == op->skill)
3336 {
3308 who->change_weapon (pl->combat_ob = item); 3337 who->change_weapon (pl->combat_ob = item);
3309 goto found_weapon; 3338 goto found_weapon;
3339 }
3310 } 3340 }
3311 3341
3312 new_draw_info (NDI_UNIQUE, 0, who, "You need to apply a melee weapon before readying this skill"); 3342 new_draw_info_format (NDI_UNIQUE, 0, who,
3343 "You need to apply a '%s' melee weapon before readying this skill. "
3344 "H<Some skills need an item, in this case a melee weapon, to function.>",
3345 &op->skill);
3313 return 1; 3346 return 1;
3314 3347
3315 found_weapon:; 3348 found_weapon:;
3316 } 3349 }
3317 else 3350 else
3322 if (skill_flags [op->subtype] & SF_NEED_BOW) 3355 if (skill_flags [op->subtype] & SF_NEED_BOW)
3323 { 3356 {
3324 for (object *item = who->inv; item; item = item->below) 3357 for (object *item = who->inv; item; item = item->below)
3325 if (item->type == BOW && item->flag [FLAG_APPLIED]) 3358 if (item->type == BOW && item->flag [FLAG_APPLIED])
3326 { 3359 {
3360 //TODO: bows should/must all have skill missile weapon right now
3327 who->change_weapon (pl->ranged_ob = item); 3361 who->change_weapon (pl->ranged_ob = item);
3328 goto found_bow; 3362 goto found_bow;
3329 } 3363 }
3330 3364
3365 new_draw_info (NDI_UNIQUE, 0, who,
3331 new_draw_info (NDI_UNIQUE, 0, who, "You need to apply a missile weapon before readying this skill"); 3366 "You need to apply a missile weapon before readying this skill. "
3367 "H<Some skills need an item, in this case a missile weapon, to function.>");
3332 return 1; 3368 return 1;
3333 3369
3334 found_bow:; 3370 found_bow:;
3335 }
3336 else if (skill_flags [op->subtype] & SF_NEED_ITEM)
3337 {
3338 for (object *item = who->inv; item; item = item->below)
3339 if (item->flag [FLAG_APPLIED]
3340 && (item->type == WAND || item->type == ROD || item->type == HORN))
3341 {
3342 who->change_weapon (pl->ranged_ob = item);
3343 goto found_item;
3344 }
3345
3346 new_draw_info (NDI_UNIQUE, 0, who, "You need to apply a magic item before readying this skill");
3347 return 1;
3348
3349 found_item:;
3350 } 3371 }
3351 else 3372 else
3352 who->change_weapon (pl->ranged_ob = op); 3373 who->change_weapon (pl->ranged_ob = op);
3353 } 3374 }
3354 3375
3358 new_draw_info_format (NDI_UNIQUE, 0, who, "You can now use the skill: %s.", &op->skill); 3379 new_draw_info_format (NDI_UNIQUE, 0, who, "You can now use the skill: %s.", &op->skill);
3359 } 3380 }
3360 else 3381 else
3361 new_draw_info_format (NDI_UNIQUE, 0, who, "Readied skill: %s.", op->skill ? &op->skill : &op->name); 3382 new_draw_info_format (NDI_UNIQUE, 0, who, "Readied skill: %s.", op->skill ? &op->skill : &op->name);
3362 } 3383 }
3363 3384 else
3385 {
3364 SET_FLAG (op, FLAG_APPLIED); 3386 SET_FLAG (op, FLAG_APPLIED);
3365 change_abil (who, op); 3387 change_abil (who, op);
3366 who->chosen_skill = op; 3388 who->chosen_skill = op;
3367 SET_FLAG (who, FLAG_READY_SKILL); 3389 SET_FLAG (who, FLAG_READY_SKILL);
3390 }
3391
3368 break; 3392 break;
3369 3393
3370 case BOW: 3394 case BOW:
3371 if (!check_weapon_power (who, op->last_eat)) 3395 if (!check_weapon_power (who, op->last_eat))
3372 { 3396 {
3373 new_draw_info (NDI_UNIQUE, 0, who, "That weapon is too powerful for you to use."); 3397 new_draw_info (NDI_UNIQUE, 0, who,
3374 new_draw_info (NDI_UNIQUE, 0, who, "It would consume your soul!."); 3398 "That weapon is too powerful for you to use. It would consume your soul!" LACK_ITEM_POWER);
3375 3399
3376 if (tmp) 3400 if (tmp)
3377 insert_ob_in_ob (tmp, who); 3401 insert_ob_in_ob (tmp, who);
3378 3402
3379 return 1; 3403 return 1;
3380 } 3404 }
3381 3405
3382 if (op->level && (strncmp (op->name, who->name, strlen (who->name)))) 3406 if (op->level && (strncmp (op->name, who->name, strlen (who->name))))
3383 { 3407 {
3384 new_draw_info (NDI_UNIQUE, 0, who, "The weapon does not recognize you as its owner."); 3408 new_draw_info (NDI_UNIQUE, 0, who,
3409 "The weapon does not recognize you as its owner. "
3410 "H<Its name indicates that it belongs to somebody else.>");
3385 if (tmp) 3411 if (tmp)
3386 insert_ob_in_ob (tmp, who); 3412 insert_ob_in_ob (tmp, who);
3387 3413
3388 return 1; 3414 return 1;
3389 } 3415 }
3399 new_draw_info_format (NDI_UNIQUE, 0, who, "The %s is broken, please report this to the dungeon master!", query_name (op));//TODO 3425 new_draw_info_format (NDI_UNIQUE, 0, who, "The %s is broken, please report this to the dungeon master!", query_name (op));//TODO
3400 return 1; 3426 return 1;
3401 } 3427 }
3402 3428
3403 SET_FLAG (op, FLAG_APPLIED); 3429 SET_FLAG (op, FLAG_APPLIED);
3404 change_skill (who, skop, 0); 3430 who->change_skill (skop);
3405 3431
3406 if (who->contr) 3432 if (who->contr)
3407 { 3433 {
3408 who->contr->ranged_ob = op; 3434 who->contr->ranged_ob = op;
3409 3435
3428 break; 3454 break;
3429 3455
3430 case BUILDER: 3456 case BUILDER:
3431 if (who->type == PLAYER) 3457 if (who->type == PLAYER)
3432 { 3458 {
3459 //TODO: wtf does this do? shouldn't this be managed automatically (slots?)
3433 if (who->contr->ranged_ob && who->contr->ranged_ob->type == BUILDER) 3460 if (who->contr->ranged_ob && who->contr->ranged_ob->type == BUILDER)
3434 unapply_special (who, who->contr->ranged_ob, 0); 3461 unapply_special (who, who->contr->ranged_ob, 0);
3435 3462
3436 new_draw_info_format (NDI_UNIQUE, 0, who, "You ready your %s.", query_name (op)); 3463 new_draw_info_format (NDI_UNIQUE, 0, who, "You ready your %s.", query_name (op));
3437 3464
3456 */ 3483 */
3457 if (who->type == PLAYER && op->type != WAND && op->type != HORN && op->type != ROD) 3484 if (who->type == PLAYER && op->type != WAND && op->type != HORN && op->type != ROD)
3458 SET_FLAG (op, FLAG_BEEN_APPLIED); 3485 SET_FLAG (op, FLAG_BEEN_APPLIED);
3459 3486
3460 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED)) 3487 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED))
3461 {
3462 if (who->type == PLAYER) 3488 if (who->type == PLAYER)
3463 { 3489 {
3464 new_draw_info (NDI_UNIQUE, 0, who, "Oops, it feels deadly cold!"); 3490 new_draw_info (NDI_UNIQUE, 0, who,
3491 "Oops, it feels deadly cold! "
3492 "H<Maybe it wasn't such a bright idea to apply this cursed/damned item.>");
3465 SET_FLAG (op, FLAG_KNOWN_CURSED); 3493 SET_FLAG (op, FLAG_KNOWN_CURSED);
3466 } 3494 }
3467 }
3468 3495
3469 if (who->type == PLAYER) 3496 if (who->type == PLAYER)
3470 { 3497 {
3471 /* if multiple objects were applied, update both slots */ 3498 /* if multiple objects were applied, update both slots */
3472 if (tmp) 3499 if (tmp)
3481int 3508int
3482monster_apply_special (object *who, object *op, int aflags) 3509monster_apply_special (object *who, object *op, int aflags)
3483{ 3510{
3484 if (QUERY_FLAG (op, FLAG_UNPAID) && !QUERY_FLAG (op, FLAG_APPLIED)) 3511 if (QUERY_FLAG (op, FLAG_UNPAID) && !QUERY_FLAG (op, FLAG_APPLIED))
3485 return 1; 3512 return 1;
3513
3486 return apply_special (who, op, aflags); 3514 return apply_special (who, op, aflags);
3487} 3515}
3488 3516
3489/** 3517/**
3490 * Map was just loaded, handle op's initialisation. 3518 * Map was just loaded, handle op's initialisation.
3816 3844
3817 if (failure <= -1 && failure > -15) 3845 if (failure <= -1 && failure > -15)
3818 { /* wonder */ 3846 { /* wonder */
3819 object *tmp; 3847 object *tmp;
3820 3848
3821 new_draw_info (NDI_UNIQUE, 0, op, "Your spell warps!."); 3849 new_draw_info (NDI_UNIQUE, 0, op, "Your spell warps!");
3822 tmp = get_archetype (SPELL_WONDER); 3850 tmp = get_archetype (SPELL_WONDER);
3823 cast_wonder (op, op, 0, tmp); 3851 cast_wonder (op, op, 0, tmp);
3824 tmp->destroy (); 3852 tmp->destroy ();
3825 } 3853 }
3826 else if (failure <= -15 && failure > -35) 3854 else if (failure <= -15 && failure > -35)
3879 */ 3907 */
3880 int i, j; 3908 int i, j;
3881 3909
3882 for (i = 0; i < NUM_STATS; i++) 3910 for (i = 0; i < NUM_STATS; i++)
3883 { 3911 {
3884 int race_bonus = pl->arch->clone.stats.stat (i); 3912 int race_bonus = pl->arch->stats.stat (i);
3885 sint8 stat = stats->stat (i) + ns->stat (i); 3913 sint8 stat = stats->stat (i) + ns->stat (i);
3886 3914
3887 if (stat > 20 + race_bonus) 3915 if (stat > 20 + race_bonus)
3888 { 3916 {
3889 excess_stat++; 3917 excess_stat++;
3899 3927
3900 if (i == CHA) 3928 if (i == CHA)
3901 continue; /* exclude cha from this */ 3929 continue; /* exclude cha from this */
3902 3930
3903 int stat = stats->stat (i); 3931 int stat = stats->stat (i);
3904 int race_bonus = pl->arch->clone.stats.stat (i); 3932 int race_bonus = pl->arch->stats.stat (i);
3905 if (stat < 20 + race_bonus) 3933 if (stat < 20 + race_bonus)
3906 { 3934 {
3907 change_attr_value (stats, i, 1); 3935 change_attr_value (stats, i, 1);
3908 excess_stat--; 3936 excess_stat--;
3909 } 3937 }
3966 char got[MAX_BUF]; 3994 char got[MAX_BUF];
3967 int len; 3995 int len;
3968 3996
3969 if (!pl || !transformer) 3997 if (!pl || !transformer)
3970 return; 3998 return;
3999
3971 marked = find_marked_object (pl); 4000 marked = find_marked_object (pl);
4001
3972 if (!marked) 4002 if (!marked)
3973 { 4003 {
3974 new_draw_info_format (NDI_UNIQUE, 0, pl, "Use the %s with what item?", query_name (transformer)); 4004 new_draw_info_format (NDI_UNIQUE, 0, pl, "Use the %s with what item?", query_name (transformer));
3975 return; 4005 return;
3976 } 4006 }
4007
3977 if (!marked->slaying) 4008 if (!marked->slaying)
3978 { 4009 {
3979 new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't use the %s with your %s!", query_name (transformer), query_name (marked)); 4010 new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't use the %s with your %s!", query_name (transformer), query_name (marked));
3980 return; 4011 return;
3981 } 4012 }
4013
3982 /* check whether they are compatible or not */ 4014 /* check whether they are compatible or not */
3983 find = strstr (marked->slaying, transformer->arch->name); 4015 find = strstr (marked->slaying, transformer->arch->archname);
3984 if (!find || (*(find + strlen (transformer->arch->name)) != ':')) 4016 if (!find || (*(find + strlen (transformer->arch->archname)) != ':'))
3985 { 4017 {
3986 new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't use the %s with your %s!", query_name (transformer), query_name (marked)); 4018 new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't use the %s with your %s!", query_name (transformer), query_name (marked));
3987 return; 4019 return;
3988 } 4020 }
4021
3989 find += strlen (transformer->arch->name) + 1; 4022 find += strlen (transformer->arch->archname) + 1;
3990 /* Item can be used, now find how many and what it yields */ 4023 /* Item can be used, now find how many and what it yields */
3991 if (isdigit (*(find))) 4024 if (isdigit (*(find)))
3992 { 4025 {
3993 yield = atoi (find); 4026 yield = atoi (find);
3994 if (yield < 1) 4027 if (yield < 1)
4002 4035
4003 while (isdigit (*find)) 4036 while (isdigit (*find))
4004 find++; 4037 find++;
4005 while (*find == ' ') 4038 while (*find == ' ')
4006 find++; 4039 find++;
4040
4007 memset (got, 0, MAX_BUF); 4041 memset (got, 0, MAX_BUF);
4042
4008 if ((separator = strchr (find, ';')) != NULL) 4043 if ((separator = strchr (find, ';')) != NULL)
4009 {
4010 len = separator - find; 4044 len = separator - find;
4011 }
4012 else 4045 else
4013 {
4014 len = strlen (find); 4046 len = strlen (find);
4015 } 4047
4016 if (len > MAX_BUF - 1) 4048 if (len > MAX_BUF - 1)
4017 len = MAX_BUF - 1; 4049 len = MAX_BUF - 1;
4050
4018 strcpy (got, find); 4051 strcpy (got, find);
4019 got[len] = '\0'; 4052 got[len] = '\0';
4020 4053
4021 /* Now create new item, remove used ones when required. */ 4054 /* Now create new item, remove used ones when required. */
4022 new_item = get_archetype (got); 4055 new_item = get_archetype (got);
4030 new_draw_info_format (NDI_UNIQUE, 0, pl, "You %s the %s.", &transformer->slaying, query_base_name (marked, 0)); 4063 new_draw_info_format (NDI_UNIQUE, 0, pl, "You %s the %s.", &transformer->slaying, query_base_name (marked, 0));
4031 insert_ob_in_ob (new_item, pl); 4064 insert_ob_in_ob (new_item, pl);
4032 esrv_send_inventory (pl, pl); 4065 esrv_send_inventory (pl, pl);
4033 /* Eat up one item */ 4066 /* Eat up one item */
4034 decrease_ob_nr (marked, 1); 4067 decrease_ob_nr (marked, 1);
4068
4035 /* Eat one transformer if needed */ 4069 /* Eat one transformer if needed */
4036 if (transformer->stats.food) 4070 if (transformer->stats.food)
4037 if (--transformer->stats.food == 0) 4071 if (--transformer->stats.food == 0)
4038 decrease_ob_nr (transformer, 1); 4072 decrease_ob_nr (transformer, 1);
4039} 4073}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines