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.92 by root, Sat May 12 18:23:51 2007 UTC vs.
Revision 1.114 by root, Tue Jul 10 06:44:31 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;
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 */
855 { 853 {
856 base = base - (base * settings.armor_speed_improvement) / 100; 854 base = base - (base * settings.armor_speed_improvement) / 100;
857 pow++; 855 pow++;
858 } 856 }
859 857
860 ARMOUR_SPEED (armour) = (ARMOUR_SPEED (&armour->arch->clone) * base) / 100; 858 ARMOUR_SPEED (armour) = (ARMOUR_SPEED (armour->arch) * base) / 100;
861 } 859 }
862 else 860 else
863 ARMOUR_SPEED (armour) = (ARMOUR_SPEED (&armour->arch->clone) * (100 + armour->magic * settings.armor_speed_improvement)) / 100; 861 ARMOUR_SPEED (armour) = (ARMOUR_SPEED (armour->arch) * (100 + armour->magic * settings.armor_speed_improvement)) / 100;
864 862
865 if (!settings.armor_weight_linear) 863 if (!settings.armor_weight_linear)
866 { 864 {
867 int base = 100; 865 int base = 100;
868 int pow = 0; 866 int pow = 0;
871 { 869 {
872 base = base - (base * settings.armor_weight_reduction) / 100; 870 base = base - (base * settings.armor_weight_reduction) / 100;
873 pow++; 871 pow++;
874 } 872 }
875 873
876 armour->weight = (armour->arch->clone.weight * base) / 100; 874 armour->weight = (armour->arch->weight * base) / 100;
877 } 875 }
878 else 876 else
879 armour->weight = (armour->arch->clone.weight * (100 - armour->magic * settings.armor_weight_reduction)) / 100; 877 armour->weight = (armour->arch->weight * (100 - armour->magic * settings.armor_weight_reduction)) / 100;
880 878
881 if (armour->weight <= 0) 879 if (armour->weight <= 0)
882 { 880 {
883 LOG (llevInfo, "Warning: enchanted armours can have negative weight\n."); 881 LOG (llevInfo, "Warning: enchanted armours can have negative weight\n.");
884 armour->weight = 1; 882 armour->weight = 1;
885 } 883 }
886 884
887 armour->item_power = get_power_from_ench (armour->arch->clone.item_power + armour->magic); 885 armour->item_power = get_power_from_ench (armour->arch->item_power + armour->magic);
888 886
889 if (op->type == PLAYER) 887 if (op->type == PLAYER)
890 { 888 {
891 esrv_send_item (op, armour); 889 esrv_send_item (op, armour);
892 if (QUERY_FLAG (armour, FLAG_APPLIED)) 890 if (QUERY_FLAG (armour, FLAG_APPLIED))
944 942
945 price_in = cost * item->value; 943 price_in = cost * item->value;
946 } 944 }
947 else 945 else
948 { 946 {
949 if (item->type == PLAYER || CONV_FROM (converter) != item->arch->name || 947 if (item->type == PLAYER || CONV_FROM (converter) != item->arch->archname ||
950 (CONV_NEED (converter) && CONV_NEED (converter) > (uint16) item->nrof)) 948 (CONV_NEED (converter) && CONV_NEED (converter) > (uint16) item->nrof))
951 return 0; 949 return 0;
952 950
953 if (CONV_NEED (converter)) 951 if (CONV_NEED (converter))
954 { 952 {
1006 LOG (llevDebug, "converter output price higher than input: %s at %s (%d, %d) in value %d, out value %d for %s\n", 1004 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); 1005 &converter->name, &converter->map->path, converter->x, converter->y, price_in, item->nrof * item->value, &item->name);
1008 1006
1009 /** 1007 /**
1010 * elmex: we are going to let the game continue, as the mapcreator 1008 * elmex: we are going to let the game continue, as the mapcreator
1011 * propably had something in mind when doing this 1009 * probably had something in mind when doing this
1012 */ 1010 */
1013 } 1011 }
1014 insert_ob_in_map_at (item, converter->map, converter, 0, converter->x, converter->y); 1012 insert_ob_in_map_at (item, converter->map, converter, 0, converter->x, converter->y);
1015 return 1; 1013 return 1;
1016} 1014}
1245 */ 1243 */
1246static void 1244static void
1247apply_sign (object *op, object *sign, int autoapply) 1245apply_sign (object *op, object *sign, int autoapply)
1248{ 1246{
1249 readable_message_type *msgType; 1247 readable_message_type *msgType;
1250 char newbuf[HUGE_BUF];
1251 1248
1252 if (sign->msg == NULL) 1249 if (sign->msg == NULL)
1253 { 1250 {
1254 new_draw_info (NDI_UNIQUE, 0, op, "Nothing is written on it."); 1251 new_draw_info (NDI_UNIQUE, 0, op, "Nothing is written on it.");
1255 return; 1252 return;
1276 if (QUERY_FLAG (op, FLAG_BLIND) && !QUERY_FLAG (op, FLAG_WIZ) && !sign->move_on) 1273 if (QUERY_FLAG (op, FLAG_BLIND) && !QUERY_FLAG (op, FLAG_WIZ) && !sign->move_on)
1277 { 1274 {
1278 new_draw_info (NDI_UNIQUE, 0, op, "You are unable to read while blind."); 1275 new_draw_info (NDI_UNIQUE, 0, op, "You are unable to read while blind.");
1279 return; 1276 return;
1280 } 1277 }
1278
1279 if (op->contr)
1280 if (client *ns = op->contr->ns)
1281 {
1281 msgType = get_readable_message_type (sign); 1282 msgType = get_readable_message_type (sign);
1283
1284 if (ns->can_msg)
1285 ns->send_msg (NDI_NAVY, msgType->msgtype, &sign->msg);
1286 else
1287 {
1288 char newbuf[HUGE_BUF];
1282 snprintf (newbuf, sizeof (newbuf), "%hhu %s", autoapply ? 1 : 0, &sign->msg); 1289 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); 1290 draw_ext_info (NDI_UNIQUE | NDI_NAVY, 0, op, msgType->message_type, msgType->message_subtype, newbuf, &sign->msg);
1291 }
1292 }
1284} 1293}
1285 1294
1286/** 1295/**
1287 * 'victim' moves onto 'trap' 1296 * 'victim' moves onto 'trap'
1288 * 'victim' leaves 'trap' 1297 * 'victim' leaves 'trap'
1311 * proper. This code was causing needless crashes. 1320 * proper. This code was causing needless crashes.
1312 */ 1321 */
1313 if (recursion_depth >= 500) 1322 if (recursion_depth >= 500)
1314 { 1323 {
1315 LOG (llevDebug, "WARNING: move_apply(): aborting recursion " 1324 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); 1325 "[trap arch %s, name %s; victim arch %s, name %s]\n", &trap->arch->archname, &trap->name, &victim->arch->archname, &victim->name);
1317 return; 1326 return;
1318 } 1327 }
1328
1319 recursion_depth++; 1329 recursion_depth++;
1320 if (trap->head) 1330 if (trap->head)
1321 trap = trap->head; 1331 trap = trap->head;
1322 1332
1323 if (INVOKE_OBJECT (MOVE_TRIGGER, trap, ARG_OBJECT (victim), ARG_OBJECT (originator))) 1333 if (INVOKE_OBJECT (MOVE_TRIGGER, trap, ARG_OBJECT (victim), ARG_OBJECT (originator)))
1338 1348
1339 /* Just put in some sanity check. I think there is a bug in the 1349 /* Just put in some sanity check. I think there is a bug in the
1340 * above with some objects have zero speed, and thus the player 1350 * above with some objects have zero speed, and thus the player
1341 * getting permanently paralyzed. 1351 * getting permanently paralyzed.
1342 */ 1352 */
1343 if (victim->speed_left < -50.0) 1353 if (victim->speed_left < -50.f)
1344 victim->speed_left = -50.0; 1354 victim->speed_left = -50.f;
1345 /* LOG(llevDebug, "apply, playermove, player speed_left=%f\n", victim->speed_left); */ 1355 /* LOG(llevDebug, "apply, playermove, player speed_left=%f\n", victim->speed_left); */
1346 } 1356 }
1347 goto leave; 1357 goto leave;
1348 1358
1349 case SPINNER: 1359 case SPINNER:
1518 } 1528 }
1519 goto leave; 1529 goto leave;
1520 1530
1521 default: 1531 default:
1522 LOG (llevDebug, "name %s, arch %s, type %d with fly/walk on/off not " 1532 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); 1533 "handled in move_apply()\n", &trap->name, &trap->arch->archname, trap->type);
1524 goto leave; 1534 goto leave;
1525 } 1535 }
1526 1536
1527leave: 1537leave:
1528 recursion_depth--; 1538 recursion_depth--;
1540 if (QUERY_FLAG (op, FLAG_BLIND) && !QUERY_FLAG (op, FLAG_WIZ)) 1550 if (QUERY_FLAG (op, FLAG_BLIND) && !QUERY_FLAG (op, FLAG_WIZ))
1541 { 1551 {
1542 new_draw_info (NDI_UNIQUE, 0, op, "You are unable to read while blind."); 1552 new_draw_info (NDI_UNIQUE, 0, op, "You are unable to read while blind.");
1543 return; 1553 return;
1544 } 1554 }
1555
1545 if (tmp->msg == NULL) 1556 if (!tmp->msg)
1546 { 1557 {
1547 new_draw_info_format (NDI_UNIQUE, 0, op, "You open the %s and find it empty.", &tmp->name); 1558 new_draw_info_format (NDI_UNIQUE, 0, op, "You open the %s and find it empty.", &tmp->name);
1548 return; 1559 return;
1549 } 1560 }
1550 1561
1551 /* need a literacy skill to read stuff! */ 1562 /* need a literacy skill to read stuff! */
1552 skill_ob = find_skill_by_name (op, tmp->skill); 1563 skill_ob = find_skill_by_name (op, tmp->skill);
1553 if (!skill_ob) 1564 if (!skill_ob)
1554 { 1565 {
1555 new_draw_info (NDI_UNIQUE, 0, op, "You are unable to decipher the strange symbols."); 1566 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; 1567 return;
1557 } 1568 }
1569
1558 lev_diff = tmp->level - (skill_ob->level + 5); 1570 lev_diff = tmp->level - (skill_ob->level + 5);
1559 if (!QUERY_FLAG (op, FLAG_WIZ) && lev_diff > 0) 1571 if (!QUERY_FLAG (op, FLAG_WIZ) && lev_diff > 0)
1560 { 1572 {
1561 if (lev_diff < 2) 1573 if (lev_diff < 2)
1562 new_draw_info (NDI_UNIQUE, 0, op, "This book is just barely beyond your comprehension."); 1574 new_draw_info (NDI_UNIQUE, 0, op, "This book is just barely beyond your comprehension.");
1573 return; 1585 return;
1574 } 1586 }
1575 1587
1576 readable_message_type *msgType = get_readable_message_type (tmp); 1588 readable_message_type *msgType = get_readable_message_type (tmp);
1577 1589
1590 if (player *pl = op->contr)
1591 if (client *ns = pl->ns)
1592 if (ns->can_msg)
1593 {
1594 dynbuf_text buf;
1595 buf << long_desc (tmp, op)
1596 << "\n\n"
1597 << tmp->msg
1598 << '\0';
1599 ns->send_msg (NDI_NAVY, msgType->msgtype, buf.linearise ());
1600 }
1601 else
1578 draw_ext_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, 1602 draw_ext_info_format (NDI_UNIQUE | NDI_NAVY, 0, op,
1579 msgType->message_type, msgType->message_subtype, 1603 msgType->message_type, msgType->message_subtype,
1580 "You open the %s and start reading.\n%s", (char *)"%s\n%s", 1604 "You open the %s and start reading.\n%s", (char *)"%s\n%s",
1581 long_desc (tmp, op), &tmp->msg); 1605 long_desc (tmp, op), &tmp->msg);
1582 1606
1583 /* gain xp from reading */ 1607 /* gain xp from reading */
1584 if (!QUERY_FLAG (tmp, FLAG_NO_SKILL_IDENT)) 1608 if (!QUERY_FLAG (tmp, FLAG_NO_SKILL_IDENT))
1585 { /* only if not read before */ 1609 { /* only if not read before */
1586 int exp_gain = calc_skill_exp (op, tmp, skill_ob); 1610 int exp_gain = calc_skill_exp (op, tmp, skill_ob);
1707 1731
1708 /* artifact_spellbooks have 'slaying' field point to a spell name, 1732 /* artifact_spellbooks have 'slaying' field point to a spell name,
1709 * instead of having their spell stored in stats.sp. These are 1733 * instead of having their spell stored in stats.sp. These are
1710 * legacy spellbooks 1734 * legacy spellbooks
1711 */ 1735 */
1712
1713 if (tmp->slaying != NULL) 1736 if (tmp->slaying)
1714 { 1737 {
1715 spell = arch_to_object (find_archetype_by_object_name (tmp->slaying)); 1738 spell = arch_to_object (find_archetype_by_object_name (tmp->slaying));
1716 if (!spell) 1739 if (!spell)
1717 { 1740 {
1718 new_draw_info_format (NDI_UNIQUE, 0, op, "The book's formula for %s is incomplete", &tmp->slaying); 1741 new_draw_info_format (NDI_UNIQUE, 0, op, "The book's formula for %s is incomplete", &tmp->slaying);
1719 return; 1742 return;
1720 } 1743 }
1721 else 1744 else
1722 insert_ob_in_ob (spell, tmp); 1745 insert_ob_in_ob (spell, tmp);
1746
1723 tmp->slaying = NULL; 1747 tmp->slaying = 0;
1724 } 1748 }
1725 1749
1726 skop = find_skill_by_name (op, tmp->skill); 1750 skop = find_skill_by_name (op, tmp->skill);
1727 1751
1728 /* need a literacy skill to learn spells. Also, having a literacy level 1752 /* need a literacy skill to learn spells. Also, having a literacy level
1729 * lower than the spell will make learning the spell more difficult */ 1753 * lower than the spell will make learning the spell more difficult */
1730 if (!skop) 1754 if (!skop)
1731 { 1755 {
1732 new_draw_info (NDI_UNIQUE, 0, op, "You can't read! Your attempt fails."); 1756 new_draw_info (NDI_UNIQUE, 0, op, "You can't read! Your attempt fails. H<You lack the literacy skill.>");
1733 return; 1757 return;
1734 } 1758 }
1735 1759
1736 spell = tmp->inv; 1760 spell = tmp->inv;
1737 1761
1738 if (!spell) 1762 if (!spell)
1739 { 1763 {
1740 LOG (llevError, "apply_spellbook: Book %s has no spell in it!\n", &tmp->name); 1764 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."); 1765 new_draw_info (NDI_UNIQUE, 0, op, "The spellbook symbols make no sense. This is a bug, please report!");
1742 return; 1766 return;
1743 } 1767 }
1744 1768
1745 if (skop->level < int (sqrtf (spell->level) * 1.5f)) 1769 if (skop->level < int (sqrtf (spell->level) * 1.5f))
1746 { 1770 {
1747 new_draw_info (NDI_UNIQUE, 0, op, "You are unable to decipher the strange symbols. [Your literacy level is too low]"); 1771 new_draw_info (NDI_UNIQUE, 0, op, "You are unable to decipher the strange symbols. H<Your literacy level is too low.>");
1748 return; 1772 return;
1749 } 1773 }
1750 1774
1751 new_draw_info_format (NDI_UNIQUE, 0, op, "The spellbook contains the %s level spell %s.", get_levelnumber (spell->level), &spell->name); 1775 new_draw_info_format (NDI_UNIQUE, 0, op, "The spellbook contains the %s level spell %s.", get_levelnumber (spell->level), &spell->name);
1752 1776
1765 * if the player doesn't know the spell, doesn't make a lot of sense that 1789 * if the player doesn't know the spell, doesn't make a lot of sense that
1766 * they would have a special prayer mark. 1790 * they would have a special prayer mark.
1767 */ 1791 */
1768 if (check_spell_known (op, spell->name)) 1792 if (check_spell_known (op, spell->name))
1769 { 1793 {
1770 new_draw_info (NDI_UNIQUE, 0, op, "You already know that spell.\n"); 1794 new_draw_info (NDI_UNIQUE, 0, op, "You already know that spell. H<It makes no sense to leanr spells twice, and would only waste the spellbook.>\n");
1771 return; 1795 return;
1772 } 1796 }
1773 1797
1774 if (spell->skill) 1798 if (spell->skill)
1775 { 1799 {
1817 change_exp (op, calc_skill_exp (op, tmp, skop), skop->skill, 0); 1841 change_exp (op, calc_skill_exp (op, tmp, skop), skop->skill, 0);
1818 } 1842 }
1819 else 1843 else
1820 { 1844 {
1821 play_sound_player_only (op->contr, SOUND_FUMBLE_SPELL, 0, 0); 1845 play_sound_player_only (op->contr, SOUND_FUMBLE_SPELL, 0, 0);
1822 new_draw_info (NDI_UNIQUE, 0, op, "You fail to learn the spell.\n"); 1846 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 } 1847 }
1824 1848
1825 decrease_ob (tmp); 1849 decrease_ob (tmp);
1826} 1850}
1827 1851
1839 return; 1863 return;
1840 } 1864 }
1841 1865
1842 if (!tmp->inv || tmp->inv->type != SPELL) 1866 if (!tmp->inv || tmp->inv->type != SPELL)
1843 { 1867 {
1844 new_draw_info (NDI_UNIQUE, 0, op, "The scroll just doesn't make sense!"); 1868 new_draw_info (NDI_UNIQUE, 0, op, "The scroll just doesn't make sense! H<...and never will make sense.>");
1845 return; 1869 return;
1846 } 1870 }
1847 1871
1848 if (op->type == PLAYER) 1872 if (op->type == PLAYER)
1849 { 1873 {
1855 */ 1879 */
1856 skop = find_skill_by_name (op, skill_names[SK_LITERACY]); 1880 skop = find_skill_by_name (op, skill_names[SK_LITERACY]);
1857 1881
1858 if (!skop) 1882 if (!skop)
1859 { 1883 {
1860 new_draw_info (NDI_UNIQUE, 0, op, "You are unable to decipher the strange symbols."); 1884 new_draw_info (NDI_UNIQUE, 0, op, "You are unable to decipher the strange symbols. H<You lack the literacy skill.>");
1861 return; 1885 return;
1862 } 1886 }
1863 1887
1864 if ((exp_gain = calc_skill_exp (op, tmp, skop))) 1888 if ((exp_gain = calc_skill_exp (op, tmp, skop)))
1865 change_exp (op, exp_gain, skop->skill, 0); 1889 change_exp (op, exp_gain, skop->skill, 0);
1867 1891
1868 if (!QUERY_FLAG (tmp, FLAG_IDENTIFIED)) 1892 if (!QUERY_FLAG (tmp, FLAG_IDENTIFIED))
1869 identify (tmp); 1893 identify (tmp);
1870 1894
1871 new_draw_info_format (NDI_BLACK, 0, op, "The scroll of %s turns to dust.", &tmp->inv->name); 1895 new_draw_info_format (NDI_BLACK, 0, op, "The scroll of %s turns to dust.", &tmp->inv->name);
1872
1873 1896
1874 cast_spell (op, tmp, dir, tmp->inv, NULL); 1897 cast_spell (op, tmp, dir, tmp->inv, NULL);
1875 decrease_ob (tmp); 1898 decrease_ob (tmp);
1876} 1899}
1877 1900
1881 * chest. 1904 * chest.
1882 */ 1905 */
1883static void 1906static void
1884apply_treasure (object *op, object *tmp) 1907apply_treasure (object *op, object *tmp)
1885{ 1908{
1886 object *treas;
1887
1888
1889 /* Nice side effect of new treasure creation method is that the treasure 1909 /* 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 1910 * 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 1911 * 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 1912 * prevents people fromt moving chests to more difficult maps to get better
1893 * treasure 1913 * treasure
1894 */ 1914 */
1895
1896 treas = tmp->inv; 1915 object *treas = tmp->inv;
1897 if (treas == NULL) 1916
1917 if (!treas)
1898 { 1918 {
1899 new_draw_info (NDI_UNIQUE, 0, op, "The chest was empty."); 1919 new_draw_info (NDI_UNIQUE, 0, op, "The chest was empty.");
1900 decrease_ob (tmp); 1920 decrease_ob (tmp);
1901 return; 1921 return;
1902 } 1922 }
1923
1903 while (tmp->inv) 1924 while (tmp->inv)
1904 { 1925 {
1905 treas = tmp->inv; 1926 treas = tmp->inv;
1906 1927
1907 treas->remove (); 1928 treas->remove ();
1989 /* special food hack -b.t. */ 2010 /* special food hack -b.t. */
1990 if (tmp->title || QUERY_FLAG (tmp, FLAG_CURSED)) 2011 if (tmp->title || QUERY_FLAG (tmp, FLAG_CURSED))
1991 eat_special_food (op, tmp); 2012 eat_special_food (op, tmp);
1992 } 2013 }
1993 } 2014 }
2015
1994 handle_apply_yield (tmp); 2016 handle_apply_yield (tmp);
1995 decrease_ob (tmp); 2017 decrease_ob (tmp);
1996} 2018}
1997 2019
1998/** 2020/**
2025 if (meal->type != FLESH || !is_dragon_pl (op)) 2047 if (meal->type != FLESH || !is_dragon_pl (op))
2026 return 0; 2048 return 0;
2027 2049
2028 /* now grab the 'dragon_skin'- and 'dragon_ability'-forces 2050 /* now grab the 'dragon_skin'- and 'dragon_ability'-forces
2029 from the player's inventory */ 2051 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) 2052 for (tmp = op->inv; tmp; tmp = tmp->below)
2034 if (tmp->type == FORCE) 2053 if (tmp->type == FORCE)
2035 if (tmp->arch->name == dragon_skin_force) 2054 if (tmp->arch->archname == shstr_dragon_skin_force)
2036 skin = tmp; 2055 skin = tmp;
2037 else if (tmp->arch->name == dragon_ability_force) 2056 else if (tmp->arch->archname == shstr_dragon_ability_force)
2038 abil = tmp; 2057 abil = tmp;
2039 2058
2040 /* if either skin or ability are missing, this is an old player 2059 /* if either skin or ability are missing, this is an old player
2041 which is not to be considered a dragon -> bail out */ 2060 which is not to be considered a dragon -> bail out */
2042 if (skin == NULL || abil == NULL) 2061 if (skin == NULL || abil == NULL)
2163static void 2182static void
2164apply_armour_improver (object *op, object *tmp) 2183apply_armour_improver (object *op, object *tmp)
2165{ 2184{
2166 object *armor; 2185 object *armor;
2167 2186
2168 if (!QUERY_FLAG (op, FLAG_WIZCAST) && (get_map_flags (op->map, NULL, op->x, op->y, NULL, NULL) & P_NO_MAGIC)) 2187 if (!QUERY_FLAG (op, FLAG_WIZCAST) && (get_map_flags (op->map, 0, op->x, op->y, 0, 0) & P_NO_MAGIC))
2169 { 2188 {
2170 new_draw_info (NDI_UNIQUE, 0, op, "Something blocks the magic of the scroll."); 2189 new_draw_info (NDI_UNIQUE, 0, op, "Something blocks the magic of the scroll. H<The area prevents magic effects.>");
2171 return; 2190 return;
2172 } 2191 }
2173 2192
2174 armor = find_marked_object (op); 2193 armor = find_marked_object (op);
2175 2194
2176 if (!armor) 2195 if (!armor)
2177 { 2196 {
2178 new_draw_info (NDI_UNIQUE, 0, op, "You need to mark an armor object."); 2197 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; 2198 return;
2180 } 2199 }
2181 2200
2182 if (armor->type != ARMOUR 2201 if (armor->type != ARMOUR
2183 && armor->type != CLOAK 2202 && armor->type != CLOAK
2198 { 2217 {
2199 play_sound_player_only (op->contr, SOUND_DRINK_POISON, 0, 0); 2218 play_sound_player_only (op->contr, SOUND_DRINK_POISON, 0, 0);
2200 new_draw_info (NDI_UNIQUE, 0, op, "Yech! That tasted poisonous!"); 2219 new_draw_info (NDI_UNIQUE, 0, op, "Yech! That tasted poisonous!");
2201 strcpy (op->contr->killer, "poisonous booze"); 2220 strcpy (op->contr->killer, "poisonous booze");
2202 } 2221 }
2222
2203 if (tmp->stats.hp > 0) 2223 if (tmp->stats.hp > 0)
2204 { 2224 {
2205 LOG (llevDebug, "Trying to poison player/monster for %d hp\n", tmp->stats.hp); 2225 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); 2226 hit_player (op, tmp->stats.hp, tmp, AT_POISON, 1);
2207 } 2227 }
2228
2208 op->stats.food -= op->stats.food / 4; 2229 op->stats.food -= op->stats.food / 4;
2209 handle_apply_yield (tmp); 2230 handle_apply_yield (tmp);
2210 decrease_ob (tmp); 2231 decrease_ob (tmp);
2211} 2232}
2212 2233
2322 2343
2323 if (QUERY_FLAG (tmp, FLAG_UNPAID) && !QUERY_FLAG (tmp, FLAG_APPLIED)) 2344 if (QUERY_FLAG (tmp, FLAG_UNPAID) && !QUERY_FLAG (tmp, FLAG_APPLIED))
2324 { 2345 {
2325 if (op->type == PLAYER) 2346 if (op->type == PLAYER)
2326 { 2347 {
2327 new_draw_info (NDI_UNIQUE, 0, op, "You should pay for it first."); 2348 new_draw_info (NDI_UNIQUE, 0, op, "You should pay for it first. H<You cannot use items marked as unpaid.>");
2328 return 1; 2349 return 1;
2329 } 2350 }
2330 else 2351 else
2331 return 0; /* monsters just skip unpaid items */ 2352 return 0; /* monsters just skip unpaid items */
2332 } 2353 }
2540int 2561int
2541player_apply (object *pl, object *op, int aflag, int quiet) 2562player_apply (object *pl, object *op, int aflag, int quiet)
2542{ 2563{
2543 int tmp; 2564 int tmp;
2544 2565
2545 if (op->env == NULL && (pl->move_type & MOVE_FLYING)) 2566 if (op->env && (pl->move_type & MOVE_FLYING))
2546 { 2567 {
2547 /* player is flying and applying object not in inventory */ 2568 /* player is flying and applying object not in inventory */
2548 if (!QUERY_FLAG (pl, FLAG_WIZ) && !(op->move_type & MOVE_FLYING)) 2569 if (!QUERY_FLAG (pl, FLAG_WIZ) && !(op->move_type & MOVE_FLYING))
2549 { 2570 {
2550 new_draw_info (NDI_UNIQUE, 0, pl, "But you are floating high " "above the ground!"); 2571 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; 2572 return 0;
2552 } 2573 }
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 } 2574 }
2566 2575
2567 pl->contr->last_used = op; 2576 pl->contr->last_used = op;
2568 2577
2569 tmp = manual_apply (pl, op, aflag); 2578 tmp = manual_apply (pl, op, aflag);
2572 if (tmp == 0) 2581 if (tmp == 0)
2573 new_draw_info_format (NDI_UNIQUE, 0, pl, "I don't know how to apply the %s.", query_name (op)); 2582 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) 2583 else if (tmp == 2)
2575 new_draw_info_format (NDI_UNIQUE, 0, pl, "You must get it first!\n"); 2584 new_draw_info_format (NDI_UNIQUE, 0, pl, "You must get it first!\n");
2576 } 2585 }
2586
2577 return tmp; 2587 return tmp;
2578} 2588}
2579 2589
2580/** 2590/**
2581 * player_apply_below attempts to apply the object 'below' the player. 2591 * player_apply_below attempts to apply the object 'below' the player.
2630{ 2640{
2631 if (INVOKE_OBJECT (BE_UNREADY, op, ARG_OBJECT (who), ARG_INT (aflags)) 2641 if (INVOKE_OBJECT (BE_UNREADY, op, ARG_OBJECT (who), ARG_INT (aflags))
2632 || INVOKE_OBJECT (UNREADY, who, ARG_OBJECT (op), ARG_INT (aflags))) 2642 || INVOKE_OBJECT (UNREADY, who, ARG_OBJECT (op), ARG_INT (aflags)))
2633 return RESULT_INT (0); 2643 return RESULT_INT (0);
2634 2644
2635 object *tmp2;
2636
2637 CLEAR_FLAG (op, FLAG_APPLIED); 2645 CLEAR_FLAG (op, FLAG_APPLIED);
2638 2646
2639 switch (op->type) 2647 switch (op->type)
2640 { 2648 {
2649 case SKILL_TOOL:
2650 // unapplying a skill tool should also unapply the skill it governs
2651 // but this is hard, as it shouldn't do so when the skill can
2652 // be used for other reasons
2653 for (object *tmp = who->inv; tmp; tmp = tmp->below)
2654 if (tmp->skill == op->skill
2655 && tmp->type == SKILL
2656 && tmp->flag [FLAG_APPLIED]
2657 && !tmp->flag [FLAG_CAN_USE_SKILL])
2658 unapply_special (who, tmp, 0);
2659
2660 change_abil (who, op);
2661 break;
2662
2641 case WEAPON: 2663 case WEAPON:
2664 if (player *pl = who->contr)
2665 if (op == pl->combat_ob)
2666 {
2667 pl->combat_ob = 0;
2668 who->change_weapon (pl->ranged_ob);
2669 }
2670
2642 new_draw_info_format (NDI_UNIQUE, 0, who, "You unwield %s.", query_name (op)); 2671 new_draw_info_format (NDI_UNIQUE, 0, who, "You unwield %s.", query_name (op));
2643 2672
2644 change_abil (who, op); 2673 change_abil (who, op);
2645 CLEAR_FLAG (who, FLAG_READY_WEAPON); 2674 CLEAR_FLAG (who, FLAG_READY_WEAPON);
2646
2647 if (who->contr)
2648 {
2649 if (who->contr->combat_ob == op)
2650 who->contr->combat_ob = 0;
2651
2652 if (who->current_weapon == op)
2653 who->current_weapon = 0;
2654 }
2655
2656 clear_skill (who);
2657 break; 2675 break;
2658 2676
2659 case SKILL: /* allows objects to impart skills */
2660 case SKILL_TOOL: 2677 case SKILL:
2661 if (op != who->chosen_skill)
2662 LOG (llevError, "BUG: apply_special(): applied skill is not a chosen skill\n");
2663
2664 if (who->contr) 2678 if (who->contr)
2665 { 2679 {
2666 if (!op->invisible) 2680 if (!op->invisible)
2667 new_draw_info_format (NDI_UNIQUE, 0, who, "You stop using the %s.", query_name (op)); 2681 new_draw_info_format (NDI_UNIQUE, 0, who, "You stop using the %s.", query_name (op));
2668 else 2682 else
2669 new_draw_info_format (NDI_UNIQUE, 0, who, "You can no longer use the skill: %s.", &op->skill); 2683 new_draw_info_format (NDI_UNIQUE, 0, who, "You can no longer use the skill: %s.", &op->skill);
2670 } 2684 }
2671 2685
2672 change_abil (who, op); 2686 change_abil (who, op);
2673 who->chosen_skill = 0;
2674 CLEAR_FLAG (who, FLAG_READY_SKILL); 2687 CLEAR_FLAG (who, FLAG_READY_SKILL);
2675 break; 2688 break;
2676 2689
2677 case ARMOUR: 2690 case ARMOUR:
2678 case HELMET: 2691 case HELMET:
2687 new_draw_info_format (NDI_UNIQUE, 0, who, "You unwear %s.", query_name (op)); 2700 new_draw_info_format (NDI_UNIQUE, 0, who, "You unwear %s.", query_name (op));
2688 change_abil (who, op); 2701 change_abil (who, op);
2689 break; 2702 break;
2690 2703
2691 case LAMP: 2704 case LAMP:
2705 {
2692 new_draw_info_format (NDI_UNIQUE, 0, who, "You turn off your %s.", &op->name); 2706 new_draw_info_format (NDI_UNIQUE, 0, who, "You turn off your %s.", &op->name);
2707
2693 tmp2 = arch_to_object (op->other_arch); 2708 object *tmp2 = arch_to_object (op->other_arch);
2694 tmp2->x = op->x; 2709 tmp2->x = op->x;
2695 tmp2->y = op->y; 2710 tmp2->y = op->y;
2696 tmp2->map = op->map; 2711 tmp2->map = op->map;
2697 tmp2->below = op->below; 2712 tmp2->below = op->below;
2698 tmp2->above = op->above; 2713 tmp2->above = op->above;
2699 tmp2->stats.food = op->stats.food; 2714 tmp2->stats.food = op->stats.food;
2700 CLEAR_FLAG (tmp2, FLAG_APPLIED); 2715 CLEAR_FLAG (tmp2, FLAG_APPLIED);
2701 2716
2702 if (QUERY_FLAG (op, FLAG_INV_LOCKED)) 2717 if (QUERY_FLAG (op, FLAG_INV_LOCKED))
2703 SET_FLAG (tmp2, FLAG_INV_LOCKED); 2718 SET_FLAG (tmp2, FLAG_INV_LOCKED);
2704 2719
2705 if (who->contr) 2720 if (who->contr)
2706 esrv_del_item (who->contr, op->count); 2721 esrv_del_item (who->contr, op->count);
2707 2722
2708 op->destroy (); 2723 op->destroy ();
2709 insert_ob_in_ob (tmp2, who); 2724 insert_ob_in_ob (tmp2, who);
2710 who->update_stats (); 2725 who->update_stats ();
2711 2726
2712 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED)) 2727 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED))
2713 { 2728 {
2714 if (who->contr) 2729 if (who->contr)
2715 { 2730 {
2716 new_draw_info (NDI_UNIQUE, 0, who, "Oops, it feels deadly cold!"); 2731 new_draw_info (NDI_UNIQUE, 0, who, "Oops, it feels deadly cold!");
2717 SET_FLAG (tmp2, FLAG_KNOWN_CURSED); 2732 SET_FLAG (tmp2, FLAG_KNOWN_CURSED);
2718 } 2733 }
2719 } 2734 }
2720 2735
2721 if (who->contr) 2736 if (who->contr)
2722 esrv_send_item (who, tmp2); 2737 esrv_send_item (who, tmp2);
2738 }
2723 2739
2724 return 1; /* otherwise, an attempt to drop causes problems */ 2740 return 1; /* otherwise, an attempt to drop causes problems */
2725 2741
2726 case BOW: 2742 case BOW:
2727 case WAND: 2743 case WAND:
2728 case ROD: 2744 case ROD:
2729 case HORN: 2745 case HORN:
2730 clear_skill (who);
2731
2732 if (who->contr) 2746 if (player *pl = who->contr)
2747 {
2748 if (op == pl->ranged_ob)
2733 { 2749 {
2750 pl->ranged_ob = 0;
2751 who->change_weapon (pl->combat_ob);
2752 }
2753
2734 new_draw_info_format (NDI_UNIQUE, 0, who, "You unready %s.", query_name (op)); 2754 new_draw_info_format (NDI_UNIQUE, 0, who, "You unready %s.", query_name (op));
2735
2736 if (who->contr->ranged_ob == op)
2737 who->contr->ranged_ob = 0;
2738
2739 if (who->current_weapon == op)
2740 who->current_weapon = 0;
2741 } 2755 }
2742 else 2756 else
2743 { 2757 {
2758 who->change_skill (0);
2759
2744 if (op->type == BOW) 2760 if (op->type == BOW)
2745 CLEAR_FLAG (who, FLAG_READY_BOW); 2761 CLEAR_FLAG (who, FLAG_READY_BOW);
2746 else 2762 else
2747 CLEAR_FLAG (who, FLAG_READY_RANGE); 2763 CLEAR_FLAG (who, FLAG_READY_RANGE);
2748 } 2764 }
2749 2765
2750 break; 2766 break;
2751 2767
2752 case BUILDER: 2768 case BUILDER:
2753 if (who->contr) 2769 if (who->contr)
2754 {
2755 new_draw_info_format (NDI_UNIQUE, 0, who, "You unready %s.", query_name (op)); 2770 new_draw_info_format (NDI_UNIQUE, 0, who, "You unready %s.", query_name (op));
2756
2757 if (who->contr->ranged_ob == op)
2758 who->contr->ranged_ob = 0;
2759 }
2760 break; 2771 break;
2761 2772
2762 default: 2773 default:
2763 new_draw_info_format (NDI_UNIQUE, 0, who, "You unapply %s.", query_name (op)); 2774 new_draw_info_format (NDI_UNIQUE, 0, who, "You unapply %s.", query_name (op));
2764 break; 2775 break;
2788/** 2799/**
2789 * Returns the object that is using location 'loc'. 2800 * Returns the object that is using location 'loc'.
2790 * Note that 'start' is the first object to start examing - we 2801 * Note that 'start' is the first object to start examing - we
2791 * then go through the below of this. In this way, you can do 2802 * then go through the below of this. In this way, you can do
2792 * something like: 2803 * something like:
2793 * tmp = get_item_from_body_location(who->inv, 1); 2804 * tmp = get_next_item_from_body_location(who->inv, 1);
2794 * if (tmp) tmp1 = get_item_from_body_location(tmp->below, 1); 2805 * if (tmp) tmp1 = get_next_item_from_body_location(tmp->below, 1);
2795 * to find the second object that may use this location, etc. 2806 * to find the second object that may use this location, etc.
2796 * Returns NULL if no match is found. 2807 * Returns NULL if no match is found.
2797 * loc is the index into the array we are looking for a match. 2808 * loc is the index into the array we are looking for a match.
2798 * don't return invisible objects unless they are skill objects 2809 * don't return invisible objects unless they are skill objects
2799 * invisible other objects that use 2810 * invisible other objects that use
2800 * up body locations can be used as restrictions. 2811 * up body locations can be used as restrictions.
2801 */ 2812 */
2802static object * 2813static object *
2803get_item_from_body_location (int loc, object *start) 2814get_next_item_from_body_location (int loc, object *start)
2804{ 2815{
2805 if (start)
2806 for (object *tmp = start; tmp; tmp = tmp->below) 2816 for (object *tmp = start; tmp; tmp = tmp->below)
2807 if (QUERY_FLAG (tmp, FLAG_APPLIED) && tmp->slot[loc].info && (!tmp->invisible || tmp->type == SKILL)) 2817 if (tmp->flag [FLAG_APPLIED]
2818 && tmp->slot[loc].info
2819 && (!tmp->invisible || tmp->type == SKILL))
2808 return tmp; 2820 return tmp;
2809 2821
2810 return 0; 2822 return 0;
2811} 2823}
2812 2824
2813/** 2825/**
2819 * Returns 0 on success, returns 1 if there is some problem. 2831 * Returns 0 on success, returns 1 if there is some problem.
2820 * if aflags is AP_PRINT, we instead print out waht to unapply 2832 * if aflags is AP_PRINT, we instead print out waht to unapply
2821 * instead of doing it. This is a lot less code than having 2833 * instead of doing it. This is a lot less code than having
2822 * another function that does just that. 2834 * another function that does just that.
2823 */ 2835 */
2836
2837#define CANNOT_REMOVE_CURSED \
2838 "H<You cannot remove cursed or damned items, you first have to remove the curse. " \
2839 "Praying over an altar, scrolls of remove curse/damnation, " \
2840 "priests or even other players might help.>"
2841
2824int 2842int
2825unapply_for_ob (object *who, object *op, int aflags) 2843unapply_for_ob (object *who, object *op, int aflags)
2826{ 2844{
2827 if (op->is_range ()) 2845 if (op->is_range ())
2828 for (object *tmp = who->inv; tmp; tmp = tmp->below) 2846 for (object *tmp = who->inv; tmp; tmp = tmp->below)
2838 { 2856 {
2839 /* In this case, we want to try and remove a cursed item. 2857 /* In this case, we want to try and remove a cursed item.
2840 * While we know it won't work, we want unapply_special to 2858 * While we know it won't work, we want unapply_special to
2841 * at least generate the message. 2859 * at least generate the message.
2842 */ 2860 */
2843 new_draw_info_format (NDI_UNIQUE, 0, who, "No matter how hard you try, you just can't remove the %s.", query_name (tmp)); 2861 new_draw_info_format (NDI_UNIQUE, 0, who,
2862 "No matter how hard you try, you just can't remove the %s." CANNOT_REMOVE_CURSED,
2863 query_name (tmp));
2844 return 1; 2864 return 1;
2845 } 2865 }
2846 2866
2847 for (int i = 0; i < NUM_BODY_LOCATIONS; i++) 2867 for (int i = 0; i < NUM_BODY_LOCATIONS; i++)
2848 { 2868 {
2854 /* We do a while loop - may need to remove several items in order 2874 /* We do a while loop - may need to remove several items in order
2855 * to free up enough slots. 2875 * to free up enough slots.
2856 */ 2876 */
2857 while ((who->slot[i].used + op->slot[i].info) < 0) 2877 while ((who->slot[i].used + op->slot[i].info) < 0)
2858 { 2878 {
2859 object *tmp = get_item_from_body_location (i, last); 2879 object *tmp = get_next_item_from_body_location (i, last);
2860 2880
2861 if (!tmp) 2881 if (!tmp)
2862 { 2882 {
2863#if 0 2883#if 0
2864 /* Not a bug - we'll get this if the player has cursed items 2884 /* Not a bug - we'll get this if the player has cursed items
2882 /* Cursed item that we can't unequip - tell the player. 2902 /* Cursed item that we can't unequip - tell the player.
2883 * Note this could be annoying if this is just one of a few, 2903 * Note this could be annoying if this is just one of a few,
2884 * so it may not be critical (eg, putting on a ring and you have 2904 * so it may not be critical (eg, putting on a ring and you have
2885 * one cursed ring.) 2905 * one cursed ring.)
2886 */ 2906 */
2887 new_draw_info_format (NDI_UNIQUE, 0, who, "The %s just won't come off", query_name (tmp)); 2907 new_draw_info_format (NDI_UNIQUE, 0, who, "The %s just won't come off." CANNOT_REMOVE_CURSED, query_name (tmp));
2888 } 2908 }
2889 2909
2890 last = tmp->below; 2910 last = tmp->below;
2891 } 2911 }
2892 /* if we got here, this slot is freed up - otherwise, if it wasn't freed up, the 2912 /* if we got here, this slot is freed up - otherwise, if it wasn't freed up, the
2902 * Checks to see if 'who' can apply object 'op'. 2922 * Checks to see if 'who' can apply object 'op'.
2903 * Returns 0 if apply can be done without anything special. 2923 * Returns 0 if apply can be done without anything special.
2904 * Otherwise returns a bitmask - potentially several of these may be 2924 * Otherwise returns a bitmask - potentially several of these may be
2905 * set, but largely depends on circumstance - in the future, processing 2925 * set, but largely depends on circumstance - in the future, processing
2906 * may be pruned once we know some status (eg, once CAN_APPLY_NEVER 2926 * may be pruned once we know some status (eg, once CAN_APPLY_NEVER
2907 * is set, do we really are what the other flags may be?) 2927 * is set, do we really care what the other flags may be?)
2908 * 2928 *
2909 * See include/define.h for detailed description of the meaning of 2929 * See include/define.h for detailed description of the meaning of
2910 * these return values. 2930 * these return values.
2911 */ 2931 */
2912int 2932int
2921 for (int i = 0; i < NUM_BODY_LOCATIONS; i++) 2941 for (int i = 0; i < NUM_BODY_LOCATIONS; i++)
2922 { 2942 {
2923 if (op->slot[i].info) 2943 if (op->slot[i].info)
2924 { 2944 {
2925 /* Item uses more slots than we have */ 2945 /* Item uses more slots than we have */
2926 if (abs (op->slot[i].info) > who->slot[i].info) 2946 if (who->slot[i].info + op->slot [i].info < 0)
2927 { 2947 {
2928 /* Could return now for efficiency - rest of info below isn't 2948 /* Could return now for efficiency - rest of info below isn't
2929 * really needed. 2949 * really needed.
2930 */ 2950 */
2931 retval |= CAN_APPLY_NEVER; 2951 retval |= CAN_APPLY_NEVER;
2932 } 2952 }
2933 else if ((who->slot[i].used + op->slot[i].info) < 0) 2953 else if (who->slot[i].used + op->slot[i].info < 0)
2934 { 2954 {
2935 /* in this case, equipping this would use more free spots than 2955 /* in this case, equipping this would use more free spots than
2936 * we have. 2956 * we have.
2937 */ 2957 */
2938 2958
2949 { 2969 {
2950 retval |= CAN_APPLY_UNAPPLY; 2970 retval |= CAN_APPLY_UNAPPLY;
2951 continue; 2971 continue;
2952 } 2972 }
2953 2973
2954 object *tmp1 = get_item_from_body_location (i, who->inv); 2974 object *tmp1 = get_next_item_from_body_location (i, who->inv);
2955 if (!tmp1) 2975 if (!tmp1)
2956 { 2976 {
2957#if 0 2977#if 0
2958 /* This is sort of an error, but happens a lot when old players 2978 /* This is sort of an error, but happens a lot when old players
2959 * join in with more stuff equipped than they are now allowed. 2979 * join in with more stuff equipped than they are now allowed.
2967 /* need to unapply something. However, if this something 2987 /* need to unapply something. However, if this something
2968 * is different than we had found before, it means they need 2988 * is different than we had found before, it means they need
2969 * to apply multiple objects 2989 * to apply multiple objects
2970 */ 2990 */
2971 retval |= CAN_APPLY_UNAPPLY; 2991 retval |= CAN_APPLY_UNAPPLY;
2992
2972 if (!tmp) 2993 if (!tmp)
2973 tmp = tmp1; 2994 tmp = tmp1;
2974 else if (tmp != tmp1) 2995 else if (tmp != tmp1)
2975 retval |= CAN_APPLY_UNAPPLY_MULT; 2996 retval |= CAN_APPLY_UNAPPLY_MULT;
2976 2997
3038 * AP_UNAPPLY=always unapply). 3059 * AP_UNAPPLY=always unapply).
3039 * 3060 *
3040 * Optional flags: 3061 * Optional flags:
3041 * AP_NO_MERGE: don't merge an unapplied object with other objects 3062 * AP_NO_MERGE: don't merge an unapplied object with other objects
3042 * AP_IGNORE_CURSE: unapply cursed items 3063 * AP_IGNORE_CURSE: unapply cursed items
3064 * AP_NO_READY: do not ready skills when applying skill tools
3043 * 3065 *
3044 * Usage example: apply_special (who, op, AP_UNAPPLY | AP_IGNORE_CURSE) 3066 * Usage example: apply_special (who, op, AP_UNAPPLY | AP_IGNORE_CURSE)
3045 * 3067 *
3046 * apply_special() doesn't check for unpaid items. 3068 * apply_special() doesn't check for unpaid items.
3047 */ 3069 */
3070
3071#define LACK_ITEM_POWER \
3072 " H<You lack enough unused item power to use this weapon, see the skills command.>"
3073
3048int 3074int
3049apply_special (object *who, object *op, int aflags) 3075apply_special (object *who, object *op, int aflags)
3050{ 3076{
3051 int basic_flag = aflags & AP_BASIC_FLAGS; 3077 int basic_flag = aflags & AP_BASIC_FLAGS;
3052 object *tmp, *tmp2, *skop = NULL; 3078 object *tmp, *tmp2, *skop = NULL;
3067 if (basic_flag == AP_APPLY) 3093 if (basic_flag == AP_APPLY)
3068 return 0; 3094 return 0;
3069 3095
3070 if (!(aflags & AP_IGNORE_CURSE) && (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED))) 3096 if (!(aflags & AP_IGNORE_CURSE) && (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED)))
3071 { 3097 {
3072 new_draw_info_format (NDI_UNIQUE, 0, who, "No matter how hard you try, you just can't remove %s.", query_name (op)); 3098 new_draw_info_format (NDI_UNIQUE, 0, who,
3099 "No matter how hard you try, you just can't remove %s." CANNOT_REMOVE_CURSED,
3100 query_name (op));
3073 return 1; 3101 return 1;
3074 } 3102 }
3075 3103
3076 return unapply_special (who, op, aflags); 3104 return unapply_special (who, op, aflags);
3077 } 3105 }
3080 return 0; 3108 return 0;
3081 3109
3082 // if the item is combat/ranged, wield the relevant slot first 3110 // if the item is combat/ranged, wield the relevant slot first
3083 // to resolve conflicts. 3111 // to resolve conflicts.
3084 if (player *pl = who->contr) 3112 if (player *pl = who->contr)
3085 switch (op->type) 3113 switch (op->slottype ())
3086 { 3114 {
3087 case WEAPON:
3088 who->change_weapon (pl->combat_ob); 3115 case slot_combat: who->change_weapon (pl->combat_ob); break;
3089 break;
3090
3091 case BOW:
3092 case ROD:
3093 case WAND:
3094 case HORN:
3095 case SKILL_TOOL:
3096 who->change_weapon (pl->ranged_ob); 3116 case slot_ranged: who->change_weapon (pl->ranged_ob); break;
3097 break;
3098
3099 case SKILL:
3100 if (IS_COMBAT_SKILL (op->subtype))
3101 who->change_weapon (pl->combat_ob);
3102 else if (IS_RANGED_SKILL (op->subtype))
3103 who->change_weapon (pl->ranged_ob);
3104 break;
3105 } 3117 }
3118
3119 splay (op);
3106 3120
3107 /* Can't just apply this object. Lets see what not and what to do */ 3121 /* Can't just apply this object. Lets see what not and what to do */
3108 if (int i = can_apply_object (who, op)) 3122 if (int i = can_apply_object (who, op))
3109 { 3123 {
3110 if (i & CAN_APPLY_NEVER) 3124 if (i & CAN_APPLY_NEVER)
3111 { 3125 {
3112 new_draw_info_format (NDI_UNIQUE, 0, who, "You don't have the body to use a %s\n", query_name (op)); 3126 new_draw_info_format (NDI_UNIQUE, 0, who,
3127 "You don't have the body to use a %s. H<You can never apply this item.>",
3128 query_name (op));
3113 return 1; 3129 return 1;
3114 } 3130 }
3115 else if (i & CAN_APPLY_RESTRICTION) 3131 else if (i & CAN_APPLY_RESTRICTION)
3116 { 3132 {
3117 new_draw_info_format (NDI_UNIQUE, 0, who, "You have a prohibition against using a %s\n", query_name (op)); 3133 new_draw_info_format (NDI_UNIQUE, 0, who,
3134 "You have a prohibition against using a %s. "
3135 "H<Your belief, profession or class prevents you from applying this item.>",
3136 query_name (op));
3118 return 1; 3137 return 1;
3119 } 3138 }
3120 3139
3121 if (who->type != PLAYER) 3140 if (who->type != PLAYER)
3122 { 3141 {
3149 } 3168 }
3150 else 3169 else
3151 /* While experience will be credited properly, we want to change the 3170 /* While experience will be credited properly, we want to change the
3152 * skill so that the dam and wc get updated 3171 * skill so that the dam and wc get updated
3153 */ 3172 */
3154 change_skill (who, skop, 0); 3173 who->change_skill (skop);
3155 } 3174 }
3156 3175
3157 if (who->type == PLAYER 3176 if (who->type == PLAYER
3158 && op->item_power 3177 && op->item_power
3159 && op->item_power + who->contr->item_power > settings.item_power_factor * who->level) 3178 && op->item_power + who->contr->item_power > settings.item_power_factor * who->level)
3160 { 3179 {
3161 new_draw_info (NDI_UNIQUE, 0, who, 3180 new_draw_info (NDI_UNIQUE, 0, who,
3162 "Equipping that combined with other items would consume your soul! " 3181 "Equipping that combined with other items would consume your soul!" LACK_ITEM_POWER);
3163 "[use the skills command to check your available item power]");
3164 return 1; 3182 return 1;
3165 } 3183 }
3166 3184
3167 /* Ok. We are now at the state where we can apply the new object. 3185 /* Ok. We are now at the state where we can apply the new object.
3168 * Note that we don't have the checks for can_use_... 3186 * Note that we don't have the checks for can_use_...
3179 switch (op->type) 3197 switch (op->type)
3180 { 3198 {
3181 case WEAPON: 3199 case WEAPON:
3182 if (!check_weapon_power (who, op->last_eat)) 3200 if (!check_weapon_power (who, op->last_eat))
3183 { 3201 {
3184 new_draw_info (NDI_UNIQUE, 0, who, "This weapon is too powerful for you to use.\n" 3202 new_draw_info (NDI_UNIQUE, 0, who, "This weapon is too powerful for you to use. "
3185 "It would consume your soul!."); 3203 "It would consume your soul!." LACK_ITEM_POWER);
3186 3204
3187 if (tmp) 3205 if (tmp)
3188 insert_ob_in_ob (tmp, who); 3206 insert_ob_in_ob (tmp, who);
3189 3207
3190 return 1; 3208 return 1;
3194 // i.e. "R" can use Ragnarok's sword. 3212 // i.e. "R" can use Ragnarok's sword.
3195 if (op->level && (strncmp (op->name, who->name, strlen (who->name)))) 3213 if (op->level && (strncmp (op->name, who->name, strlen (who->name))))
3196 { 3214 {
3197 /* if the weapon does not have the name as the character, can't use it. */ 3215 /* if the weapon does not have the name as the character, can't use it. */
3198 /* (Ragnarok's sword attempted to be used by Foo: won't work) */ 3216 /* (Ragnarok's sword attempted to be used by Foo: won't work) */
3199 new_draw_info (NDI_UNIQUE, 0, who, "The weapon does not recognize you as its owner."); 3217 new_draw_info (NDI_UNIQUE, 0, who,
3218 "The weapon does not recognize you as its owner. "
3219 "H<Its name indicates that it belongs to somebody else.>");
3200 3220
3201 if (tmp) 3221 if (tmp)
3202 insert_ob_in_ob (tmp, who); 3222 insert_ob_in_ob (tmp, who);
3203 3223
3204 return 1; 3224 return 1;
3209 new_draw_info_format (NDI_UNIQUE, 0, who, "The %s is broken, please report this to the dungeon master!", query_name (op));//TODO 3229 new_draw_info_format (NDI_UNIQUE, 0, who, "The %s is broken, please report this to the dungeon master!", query_name (op));//TODO
3210 return 1; 3230 return 1;
3211 } 3231 }
3212 3232
3213 SET_FLAG (op, FLAG_APPLIED); 3233 SET_FLAG (op, FLAG_APPLIED);
3214 change_skill (who, skop, 1); 3234 who->change_skill (skop);
3215 3235
3216 if (who->contr) 3236 if (who->contr)
3217 who->change_weapon (who->contr->combat_ob = op); 3237 who->change_weapon (who->contr->combat_ob = op);
3218 3238
3219 if (!QUERY_FLAG (who, FLAG_READY_WEAPON))
3220 SET_FLAG (who, FLAG_READY_WEAPON);
3221
3222 new_draw_info_format (NDI_UNIQUE, 0, who, "You wield %s.", query_name (op)); 3239 new_draw_info_format (NDI_UNIQUE, 0, who, "You wield %s.", query_name (op));
3223 3240
3241 SET_FLAG (who, FLAG_READY_WEAPON);
3224 change_abil (who, op); 3242 change_abil (who, op);
3225 break; 3243 break;
3226 3244
3227 case ARMOUR: 3245 case ARMOUR:
3228 case HELMET: 3246 case HELMET:
3240 break; 3258 break;
3241 3259
3242 case LAMP: 3260 case LAMP:
3243 if (op->stats.food < 1) 3261 if (op->stats.food < 1)
3244 { 3262 {
3245 new_draw_info_format (NDI_UNIQUE, 0, who, "Your %s is out of fuel!", &op->name); 3263 new_draw_info_format (NDI_UNIQUE, 0, who,
3264 "Your %s is out of fuel! "
3265 "H<Lamps and similar items need fuel. They cannot be refilled.>", &op->name);
3246 return 1; 3266 return 1;
3247 } 3267 }
3248 3268
3249 new_draw_info_format (NDI_UNIQUE, 0, who, "You turn on your %s.", &op->name); 3269 new_draw_info_format (NDI_UNIQUE, 0, who, "You turn on your %s.", &op->name);
3250 tmp2 = arch_to_object (op->other_arch); 3270 tmp2 = arch_to_object (op->other_arch);
3273 who->update_stats (); 3293 who->update_stats ();
3274 3294
3275 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED)) 3295 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED))
3276 if (who->type == PLAYER) 3296 if (who->type == PLAYER)
3277 { 3297 {
3278 new_draw_info (NDI_UNIQUE, 0, who, "Oops, it feels deadly cold!"); 3298 new_draw_info (NDI_UNIQUE, 0, who,
3299 "Oops, it feels deadly cold! "
3300 "H<Maybe it wasn't such a bright idea to apply this cursed/damned item.>");
3279 SET_FLAG (tmp2, FLAG_KNOWN_CURSED); 3301 SET_FLAG (tmp2, FLAG_KNOWN_CURSED);
3280 } 3302 }
3281 3303
3282 if (who->type == PLAYER) 3304 if (who->type == PLAYER)
3283 esrv_send_item (who, tmp2); 3305 esrv_send_item (who, tmp2);
3284 3306
3285 return 0; 3307 return 0;
3286 3308
3287 /* this part is needed for skill-tools */ 3309 case SKILL_TOOL:
3310 // applying a skill tool also readies the skill
3311 SET_FLAG (op, FLAG_APPLIED);
3312
3313 if (!(aflags & AP_NO_READY))
3314 {
3315 skop = find_skill_by_name (who, op->skill);
3316 if (!skop->flag [FLAG_APPLIED])
3317 apply_special (who, skop, AP_APPLY);
3318 }
3319 break;
3320
3288 case SKILL: 3321 case SKILL:
3289 case SKILL_TOOL:
3290 if (who->chosen_skill)
3291 {
3292 LOG (llevError, "BUG: apply_special(): can't apply two skills\n");
3293 return 1;
3294 }
3295
3296 if (player *pl = who->contr) 3322 if (player *pl = who->contr)
3297 { 3323 {
3298 if (IS_COMBAT_SKILL (op->subtype)) 3324 if (IS_COMBAT_SKILL (op->subtype))
3299 { 3325 {
3300 if (skill_flags [op->subtype] & SF_NEED_WEAPON) 3326 if (skill_flags [op->subtype] & SF_NEED_WEAPON)
3301 { 3327 {
3302 for (object *item = who->inv; item; item = item->below) 3328 for (object *item = who->inv; item; item = item->below)
3303 if (item->type == WEAPON && item->flag [FLAG_APPLIED]) 3329 if (item->type == WEAPON && item->flag [FLAG_APPLIED])
3304 { 3330 {
3331 if (item->skill == op->skill)
3332 {
3305 who->change_weapon (pl->combat_ob = item); 3333 who->change_weapon (pl->combat_ob = item);
3306 goto found_weapon; 3334 goto found_weapon;
3335 }
3307 } 3336 }
3308 3337
3309 new_draw_info (NDI_UNIQUE, 0, who, "You need to apply a melee weapon before readying this skill"); 3338 new_draw_info_format (NDI_UNIQUE, 0, who,
3339 "You need to apply a '%s' melee weapon before readying this skill. "
3340 "H<Some skills need an item, in this case a melee weapon, to function.>",
3341 &op->skill);
3310 return 1; 3342 return 1;
3311 3343
3312 found_weapon:; 3344 found_weapon:;
3313 } 3345 }
3314 else 3346 else
3319 if (skill_flags [op->subtype] & SF_NEED_BOW) 3351 if (skill_flags [op->subtype] & SF_NEED_BOW)
3320 { 3352 {
3321 for (object *item = who->inv; item; item = item->below) 3353 for (object *item = who->inv; item; item = item->below)
3322 if (item->type == BOW && item->flag [FLAG_APPLIED]) 3354 if (item->type == BOW && item->flag [FLAG_APPLIED])
3323 { 3355 {
3356 //TODO: bows should/must all have skill missile weapon right now
3324 who->change_weapon (pl->ranged_ob = item); 3357 who->change_weapon (pl->ranged_ob = item);
3325 goto found_bow; 3358 goto found_bow;
3326 } 3359 }
3327 3360
3361 new_draw_info (NDI_UNIQUE, 0, who,
3328 new_draw_info (NDI_UNIQUE, 0, who, "You need to apply a missile weapon before readying this skill"); 3362 "You need to apply a missile weapon before readying this skill. "
3363 "H<Some skills need an item, in this case a missile weapon, to function.>");
3329 return 1; 3364 return 1;
3330 3365
3331 found_bow:; 3366 found_bow:;
3332 }
3333 else if (skill_flags [op->subtype] & SF_NEED_ITEM)
3334 {
3335 for (object *item = who->inv; item; item = item->below)
3336 if (item->flag [FLAG_APPLIED]
3337 && (item->type == WAND || item->type == ROD || item->type == HORN))
3338 {
3339 who->change_weapon (pl->ranged_ob = item);
3340 goto found_item;
3341 }
3342
3343 new_draw_info (NDI_UNIQUE, 0, who, "You need to apply a magic item before readying this skill");
3344 return 1;
3345
3346 found_item:;
3347 } 3367 }
3348 else 3368 else
3349 who->change_weapon (pl->ranged_ob = op); 3369 who->change_weapon (pl->ranged_ob = op);
3350 } 3370 }
3351 3371
3355 new_draw_info_format (NDI_UNIQUE, 0, who, "You can now use the skill: %s.", &op->skill); 3375 new_draw_info_format (NDI_UNIQUE, 0, who, "You can now use the skill: %s.", &op->skill);
3356 } 3376 }
3357 else 3377 else
3358 new_draw_info_format (NDI_UNIQUE, 0, who, "Readied skill: %s.", op->skill ? &op->skill : &op->name); 3378 new_draw_info_format (NDI_UNIQUE, 0, who, "Readied skill: %s.", op->skill ? &op->skill : &op->name);
3359 } 3379 }
3360 3380 else
3381 {
3361 SET_FLAG (op, FLAG_APPLIED); 3382 SET_FLAG (op, FLAG_APPLIED);
3362 change_abil (who, op); 3383 change_abil (who, op);
3363 who->chosen_skill = op; 3384 who->chosen_skill = op;
3364 SET_FLAG (who, FLAG_READY_SKILL); 3385 SET_FLAG (who, FLAG_READY_SKILL);
3386 }
3387
3365 break; 3388 break;
3366 3389
3367 case BOW: 3390 case BOW:
3368 if (!check_weapon_power (who, op->last_eat)) 3391 if (!check_weapon_power (who, op->last_eat))
3369 { 3392 {
3370 new_draw_info (NDI_UNIQUE, 0, who, "That weapon is too powerful for you to use."); 3393 new_draw_info (NDI_UNIQUE, 0, who,
3371 new_draw_info (NDI_UNIQUE, 0, who, "It would consume your soul!."); 3394 "That weapon is too powerful for you to use. It would consume your soul!" LACK_ITEM_POWER);
3372 3395
3373 if (tmp) 3396 if (tmp)
3374 insert_ob_in_ob (tmp, who); 3397 insert_ob_in_ob (tmp, who);
3375 3398
3376 return 1; 3399 return 1;
3377 } 3400 }
3378 3401
3379 if (op->level && (strncmp (op->name, who->name, strlen (who->name)))) 3402 if (op->level && (strncmp (op->name, who->name, strlen (who->name))))
3380 { 3403 {
3381 new_draw_info (NDI_UNIQUE, 0, who, "The weapon does not recognize you as its owner."); 3404 new_draw_info (NDI_UNIQUE, 0, who,
3405 "The weapon does not recognize you as its owner. "
3406 "H<Its name indicates that it belongs to somebody else.>");
3382 if (tmp) 3407 if (tmp)
3383 insert_ob_in_ob (tmp, who); 3408 insert_ob_in_ob (tmp, who);
3384 3409
3385 return 1; 3410 return 1;
3386 } 3411 }
3396 new_draw_info_format (NDI_UNIQUE, 0, who, "The %s is broken, please report this to the dungeon master!", query_name (op));//TODO 3421 new_draw_info_format (NDI_UNIQUE, 0, who, "The %s is broken, please report this to the dungeon master!", query_name (op));//TODO
3397 return 1; 3422 return 1;
3398 } 3423 }
3399 3424
3400 SET_FLAG (op, FLAG_APPLIED); 3425 SET_FLAG (op, FLAG_APPLIED);
3401 change_skill (who, skop, 0); 3426 who->change_skill (skop);
3402 3427
3403 if (who->contr) 3428 if (who->contr)
3404 { 3429 {
3405 who->contr->ranged_ob = op; 3430 who->contr->ranged_ob = op;
3406 3431
3425 break; 3450 break;
3426 3451
3427 case BUILDER: 3452 case BUILDER:
3428 if (who->type == PLAYER) 3453 if (who->type == PLAYER)
3429 { 3454 {
3455 //TODO: wtf does this do? shouldn't this be managed automatically (slots?)
3430 if (who->contr->ranged_ob && who->contr->ranged_ob->type == BUILDER) 3456 if (who->contr->ranged_ob && who->contr->ranged_ob->type == BUILDER)
3431 unapply_special (who, who->contr->ranged_ob, 0); 3457 unapply_special (who, who->contr->ranged_ob, 0);
3432 3458
3433 new_draw_info_format (NDI_UNIQUE, 0, who, "You ready your %s.", query_name (op)); 3459 new_draw_info_format (NDI_UNIQUE, 0, who, "You ready your %s.", query_name (op));
3434 3460
3453 */ 3479 */
3454 if (who->type == PLAYER && op->type != WAND && op->type != HORN && op->type != ROD) 3480 if (who->type == PLAYER && op->type != WAND && op->type != HORN && op->type != ROD)
3455 SET_FLAG (op, FLAG_BEEN_APPLIED); 3481 SET_FLAG (op, FLAG_BEEN_APPLIED);
3456 3482
3457 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED)) 3483 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED))
3458 {
3459 if (who->type == PLAYER) 3484 if (who->type == PLAYER)
3460 { 3485 {
3461 new_draw_info (NDI_UNIQUE, 0, who, "Oops, it feels deadly cold!"); 3486 new_draw_info (NDI_UNIQUE, 0, who,
3487 "Oops, it feels deadly cold! "
3488 "H<Maybe it wasn't such a bright idea to apply this cursed/damned item.>");
3462 SET_FLAG (op, FLAG_KNOWN_CURSED); 3489 SET_FLAG (op, FLAG_KNOWN_CURSED);
3463 } 3490 }
3464 }
3465 3491
3466 if (who->type == PLAYER) 3492 if (who->type == PLAYER)
3467 { 3493 {
3468 /* if multiple objects were applied, update both slots */ 3494 /* if multiple objects were applied, update both slots */
3469 if (tmp) 3495 if (tmp)
3478int 3504int
3479monster_apply_special (object *who, object *op, int aflags) 3505monster_apply_special (object *who, object *op, int aflags)
3480{ 3506{
3481 if (QUERY_FLAG (op, FLAG_UNPAID) && !QUERY_FLAG (op, FLAG_APPLIED)) 3507 if (QUERY_FLAG (op, FLAG_UNPAID) && !QUERY_FLAG (op, FLAG_APPLIED))
3482 return 1; 3508 return 1;
3509
3483 return apply_special (who, op, aflags); 3510 return apply_special (who, op, aflags);
3484} 3511}
3485 3512
3486/** 3513/**
3487 * Map was just loaded, handle op's initialisation. 3514 * Map was just loaded, handle op's initialisation.
3813 3840
3814 if (failure <= -1 && failure > -15) 3841 if (failure <= -1 && failure > -15)
3815 { /* wonder */ 3842 { /* wonder */
3816 object *tmp; 3843 object *tmp;
3817 3844
3818 new_draw_info (NDI_UNIQUE, 0, op, "Your spell warps!."); 3845 new_draw_info (NDI_UNIQUE, 0, op, "Your spell warps!");
3819 tmp = get_archetype (SPELL_WONDER); 3846 tmp = get_archetype (SPELL_WONDER);
3820 cast_wonder (op, op, 0, tmp); 3847 cast_wonder (op, op, 0, tmp);
3821 tmp->destroy (); 3848 tmp->destroy ();
3822 } 3849 }
3823 else if (failure <= -15 && failure > -35) 3850 else if (failure <= -15 && failure > -35)
3876 */ 3903 */
3877 int i, j; 3904 int i, j;
3878 3905
3879 for (i = 0; i < NUM_STATS; i++) 3906 for (i = 0; i < NUM_STATS; i++)
3880 { 3907 {
3881 int race_bonus = pl->arch->clone.stats.stat (i); 3908 int race_bonus = pl->arch->stats.stat (i);
3882 sint8 stat = stats->stat (i) + ns->stat (i); 3909 sint8 stat = stats->stat (i) + ns->stat (i);
3883 3910
3884 if (stat > 20 + race_bonus) 3911 if (stat > 20 + race_bonus)
3885 { 3912 {
3886 excess_stat++; 3913 excess_stat++;
3896 3923
3897 if (i == CHA) 3924 if (i == CHA)
3898 continue; /* exclude cha from this */ 3925 continue; /* exclude cha from this */
3899 3926
3900 int stat = stats->stat (i); 3927 int stat = stats->stat (i);
3901 int race_bonus = pl->arch->clone.stats.stat (i); 3928 int race_bonus = pl->arch->stats.stat (i);
3902 if (stat < 20 + race_bonus) 3929 if (stat < 20 + race_bonus)
3903 { 3930 {
3904 change_attr_value (stats, i, 1); 3931 change_attr_value (stats, i, 1);
3905 excess_stat--; 3932 excess_stat--;
3906 } 3933 }
3963 char got[MAX_BUF]; 3990 char got[MAX_BUF];
3964 int len; 3991 int len;
3965 3992
3966 if (!pl || !transformer) 3993 if (!pl || !transformer)
3967 return; 3994 return;
3995
3968 marked = find_marked_object (pl); 3996 marked = find_marked_object (pl);
3997
3969 if (!marked) 3998 if (!marked)
3970 { 3999 {
3971 new_draw_info_format (NDI_UNIQUE, 0, pl, "Use the %s with what item?", query_name (transformer)); 4000 new_draw_info_format (NDI_UNIQUE, 0, pl, "Use the %s with what item?", query_name (transformer));
3972 return; 4001 return;
3973 } 4002 }
4003
3974 if (!marked->slaying) 4004 if (!marked->slaying)
3975 { 4005 {
3976 new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't use the %s with your %s!", query_name (transformer), query_name (marked)); 4006 new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't use the %s with your %s!", query_name (transformer), query_name (marked));
3977 return; 4007 return;
3978 } 4008 }
4009
3979 /* check whether they are compatible or not */ 4010 /* check whether they are compatible or not */
3980 find = strstr (marked->slaying, transformer->arch->name); 4011 find = strstr (marked->slaying, transformer->arch->archname);
3981 if (!find || (*(find + strlen (transformer->arch->name)) != ':')) 4012 if (!find || (*(find + strlen (transformer->arch->archname)) != ':'))
3982 { 4013 {
3983 new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't use the %s with your %s!", query_name (transformer), query_name (marked)); 4014 new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't use the %s with your %s!", query_name (transformer), query_name (marked));
3984 return; 4015 return;
3985 } 4016 }
4017
3986 find += strlen (transformer->arch->name) + 1; 4018 find += strlen (transformer->arch->archname) + 1;
3987 /* Item can be used, now find how many and what it yields */ 4019 /* Item can be used, now find how many and what it yields */
3988 if (isdigit (*(find))) 4020 if (isdigit (*(find)))
3989 { 4021 {
3990 yield = atoi (find); 4022 yield = atoi (find);
3991 if (yield < 1) 4023 if (yield < 1)
3999 4031
4000 while (isdigit (*find)) 4032 while (isdigit (*find))
4001 find++; 4033 find++;
4002 while (*find == ' ') 4034 while (*find == ' ')
4003 find++; 4035 find++;
4036
4004 memset (got, 0, MAX_BUF); 4037 memset (got, 0, MAX_BUF);
4038
4005 if ((separator = strchr (find, ';')) != NULL) 4039 if ((separator = strchr (find, ';')) != NULL)
4006 {
4007 len = separator - find; 4040 len = separator - find;
4008 }
4009 else 4041 else
4010 {
4011 len = strlen (find); 4042 len = strlen (find);
4012 } 4043
4013 if (len > MAX_BUF - 1) 4044 if (len > MAX_BUF - 1)
4014 len = MAX_BUF - 1; 4045 len = MAX_BUF - 1;
4046
4015 strcpy (got, find); 4047 strcpy (got, find);
4016 got[len] = '\0'; 4048 got[len] = '\0';
4017 4049
4018 /* Now create new item, remove used ones when required. */ 4050 /* Now create new item, remove used ones when required. */
4019 new_item = get_archetype (got); 4051 new_item = get_archetype (got);
4027 new_draw_info_format (NDI_UNIQUE, 0, pl, "You %s the %s.", &transformer->slaying, query_base_name (marked, 0)); 4059 new_draw_info_format (NDI_UNIQUE, 0, pl, "You %s the %s.", &transformer->slaying, query_base_name (marked, 0));
4028 insert_ob_in_ob (new_item, pl); 4060 insert_ob_in_ob (new_item, pl);
4029 esrv_send_inventory (pl, pl); 4061 esrv_send_inventory (pl, pl);
4030 /* Eat up one item */ 4062 /* Eat up one item */
4031 decrease_ob_nr (marked, 1); 4063 decrease_ob_nr (marked, 1);
4064
4032 /* Eat one transformer if needed */ 4065 /* Eat one transformer if needed */
4033 if (transformer->stats.food) 4066 if (transformer->stats.food)
4034 if (--transformer->stats.food == 0) 4067 if (--transformer->stats.food == 0)
4035 decrease_ob_nr (transformer, 1); 4068 decrease_ob_nr (transformer, 1);
4036} 4069}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines