ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/skills.C
(Generate patch)

Comparing deliantra/server/server/skills.C (file contents):
Revision 1.35 by root, Sat May 19 00:31:08 2007 UTC vs.
Revision 1.41 by root, Mon Aug 20 19:13:10 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) 2003 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2003,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 <global.h> 24#include <global.h>
26#include <object.h> 25#include <object.h>
719/* do_skill_ident() - workhorse for skill_ident() -b.t. 718/* do_skill_ident() - workhorse for skill_ident() -b.t.
720 */ 719 */
721static int 720static int
722do_skill_ident (object *pl, int obj_class, object *skill) 721do_skill_ident (object *pl, int obj_class, object *skill)
723{ 722{
724 object *tmp;
725 int success = 0; 723 int success = 0;
726 724
727 for (tmp = pl->inv; tmp; tmp = tmp->below) 725 for (object *tmp = pl->inv; tmp; tmp = tmp->below)
728 success += do_skill_ident2 (tmp, pl, obj_class, skill); 726 success += do_skill_ident2 (tmp, pl, obj_class, skill);
729 /* check the ground */ 727 /* check the ground */
730 728
731 for (tmp = GET_MAP_OB (pl->map, pl->x, pl->y); tmp; tmp = tmp->above) 729 for (object *tmp = pl->ms ().bot; tmp; tmp = tmp->above)
732 success += do_skill_ident2 (tmp, pl, obj_class, skill); 730 success += do_skill_ident2 (tmp, pl, obj_class, skill);
733 731
734 return success; 732 return success;
735} 733}
736 734
744 742
745 new_draw_info (NDI_UNIQUE, 0, pl, "You look at the objects nearby..."); 743 new_draw_info (NDI_UNIQUE, 0, pl, "You look at the objects nearby...");
746 744
747 switch (skill->subtype) 745 switch (skill->subtype)
748 { 746 {
749 case SK_SMITHERY: 747 case SK_SMITHERY:
750 success += do_skill_ident (pl, WEAPON, skill) + do_skill_ident (pl, ARMOUR, skill) 748 success += do_skill_ident (pl, WEAPON, skill) + do_skill_ident (pl, ARMOUR, skill)
751 + do_skill_ident (pl, BRACERS, skill) + do_skill_ident (pl, CLOAK, skill) 749 + do_skill_ident (pl, BRACERS, skill) + do_skill_ident (pl, CLOAK, skill)
752 + do_skill_ident (pl, BOOTS, skill) + do_skill_ident (pl, SHIELD, skill) 750 + do_skill_ident (pl, BOOTS, skill) + do_skill_ident (pl, SHIELD, skill)
753 + do_skill_ident (pl, GIRDLE, skill) + do_skill_ident (pl, HELMET, skill) + do_skill_ident (pl, GLOVES, skill); 751 + do_skill_ident (pl, GIRDLE, skill) + do_skill_ident (pl, HELMET, skill) + do_skill_ident (pl, GLOVES, skill);
754 break; 752 break;
755 753
756 case SK_BOWYER: 754 case SK_BOWYER:
757 success += do_skill_ident (pl, BOW, skill) + do_skill_ident (pl, ARROW, skill); 755 success += do_skill_ident (pl, BOW, skill) + do_skill_ident (pl, ARROW, skill);
758 break; 756 break;
759 757
760 case SK_ALCHEMY: 758 case SK_ALCHEMY:
761 success += do_skill_ident (pl, POTION, skill) + do_skill_ident (pl, POISON, skill) 759 success += do_skill_ident (pl, POTION, skill) + do_skill_ident (pl, POISON, skill)
762 + do_skill_ident (pl, CONTAINER, skill) + do_skill_ident (pl, DRINK, skill) + do_skill_ident (pl, INORGANIC, skill); 760 + do_skill_ident (pl, CONTAINER, skill) + do_skill_ident (pl, DRINK, skill) + do_skill_ident (pl, INORGANIC, skill);
763 break; 761 break;
764 762
765 case SK_WOODSMAN: 763 case SK_WOODSMAN:
766 success += do_skill_ident (pl, FOOD, skill) + do_skill_ident (pl, DRINK, skill) + do_skill_ident (pl, FLESH, skill); 764 success += do_skill_ident (pl, FOOD, skill) + do_skill_ident (pl, DRINK, skill) + do_skill_ident (pl, FLESH, skill);
767 break; 765 break;
768 766
769 case SK_JEWELER: 767 case SK_JEWELER:
770 success += do_skill_ident (pl, GEM, skill) + do_skill_ident (pl, RING, skill) + do_skill_ident (pl, AMULET, skill); 768 success += do_skill_ident (pl, GEM, skill) + do_skill_ident (pl, RING, skill) + do_skill_ident (pl, AMULET, skill);
771 break; 769 break;
772 770
773 case SK_LITERACY: 771 case SK_LITERACY:
774 success += do_skill_ident (pl, SPELLBOOK, skill) + do_skill_ident (pl, SCROLL, skill) + do_skill_ident (pl, BOOK, skill); 772 success += do_skill_ident (pl, SPELLBOOK, skill) + do_skill_ident (pl, SCROLL, skill) + do_skill_ident (pl, BOOK, skill);
775 break; 773 break;
776 774
777 case SK_THAUMATURGY: 775 case SK_THAUMATURGY:
778 success += do_skill_ident (pl, WAND, skill) + do_skill_ident (pl, ROD, skill) + do_skill_ident (pl, HORN, skill); 776 success += do_skill_ident (pl, WAND, skill) + do_skill_ident (pl, ROD, skill) + do_skill_ident (pl, HORN, skill);
779 break; 777 break;
780 778
781 case SK_DET_CURSE: 779 case SK_DET_CURSE:
782 success = do_skill_detect_curse (pl, skill); 780 success = do_skill_detect_curse (pl, skill);
783 if (success) 781 if (success)
784 new_draw_info (NDI_UNIQUE, 0, pl, "...and discover cursed items!"); 782 new_draw_info (NDI_UNIQUE, 0, pl, "...and discover cursed items!");
785 break; 783 break;
786 784
787 case SK_DET_MAGIC: 785 case SK_DET_MAGIC:
788 success = do_skill_detect_magic (pl, skill); 786 success = do_skill_detect_magic (pl, skill);
789 if (success) 787 if (success)
790 new_draw_info (NDI_UNIQUE, 0, pl, "...and discover items imbued with mystic forces!"); 788 new_draw_info (NDI_UNIQUE, 0, pl, "...and discover items imbued with mystic forces!");
791 break; 789 break;
792 790
793 default: 791 default:
794 LOG (llevError, "Error: bad call to skill_ident()\n"); 792 LOG (llevError, "Error: bad call to skill_ident()\n");
795 return 0; 793 return 0;
796 break; 794 break;
797 } 795 }
796
798 if (!success) 797 if (!success)
799 {
800 new_draw_info (NDI_UNIQUE, 0, pl, "...and learn nothing more."); 798 new_draw_info (NDI_UNIQUE, 0, pl, "...and learn nothing more.");
801 } 799
802 return success; 800 return success;
803} 801}
804 802
805/* players using this skill can 'charm' a monster -- 803/* players using this skill can 'charm' a monster --
806 * into working for them. It can only be used on 804 * into working for them. It can only be used on
1122 success += calc_skill_exp (op, tmp, skill); 1120 success += calc_skill_exp (op, tmp, skill);
1123 } 1121 }
1124 } 1122 }
1125 } 1123 }
1126 } 1124 }
1125
1127 return success; 1126 return success;
1128} 1127}
1129
1130 1128
1131/* pray() - when this skill is called from do_skill(), it allows 1129/* pray() - when this skill is called from do_skill(), it allows
1132 * the player to regain lost grace points at a faster rate. -b.t. 1130 * the player to regain lost grace points at a faster rate. -b.t.
1133 * This always returns 0 - return value is used by calling function 1131 * This always returns 0 - return value is used by calling function
1134 * such that if it returns true, player gets exp in that skill. This 1132 * such that if it returns true, player gets exp in that skill. This
1135 * the effect here can be done on demand, we probably don't want to 1133 * the effect here can be done on demand, we probably don't want to
1136 * give infinite exp by returning true in any cases. 1134 * give infinite exp by returning true in any cases.
1137 */ 1135 */
1138
1139int 1136int
1140pray (object *pl, object *skill) 1137pray (object *pl, object *skill)
1141{ 1138{
1142 char buf[MAX_BUF]; 1139 char buf[MAX_BUF];
1143 object *tmp; 1140 object *tmp;
1168 if (pl->stats.grace < pl->stats.maxgrace) 1165 if (pl->stats.grace < pl->stats.maxgrace)
1169 { 1166 {
1170 pl->stats.grace++; 1167 pl->stats.grace++;
1171 pl->last_grace = -1; 1168 pl->last_grace = -1;
1172 } 1169 }
1170
1173 return 0; 1171 return 0;
1174} 1172}
1175 1173
1176/* This skill allows the player to regain a few sp or hp for a 1174/* This skill allows the player to regain a few sp or hp for a
1177 * brief period of concentration. No armour or weapons may be 1175 * brief period of concentration. No armour or weapons may be
1178 * wielded/applied for this to work. The amount of time needed 1176 * wielded/applied for this to work. The amount of time needed
1179 * to concentrate and the # of points regained is dependant on 1177 * to concentrate and the # of points regained is dependant on
1180 * the level of the user. - b.t. thomas@astro.psu.edu 1178 * the level of the user. - b.t. thomas@astro.psu.edu
1181 */ 1179 */
1182
1183void 1180void
1184meditate (object *pl, object *skill) 1181meditate (object *pl, object *skill)
1185{ 1182{
1186 object *tmp; 1183 object *tmp;
1187 1184
1230 pl->last_heal = -1; 1227 pl->last_heal = -1;
1231 } 1228 }
1232} 1229}
1233 1230
1234/* write_note() - this routine allows players to inscribe messages in 1231/* write_note() - this routine allows players to inscribe messages in
1235 * ordinary 'books' (anything that is type BOOK). b.t. 1232 * ordinary inscribable 'books' (anything that is not a SPELL). b.t.
1236 */ 1233 */
1237static int 1234static int
1238write_note (object *pl, object *item, const char *msg, object *skill) 1235write_note (object *pl, object *item, const char *msg, object *skill)
1239{ 1236{
1237
1238 if (strstr (msg, "\nendmsg"))
1239 {
1240 new_draw_info (NDI_UNIQUE, 0, pl, "Trying to cheat now are we?");
1241 return 0;
1242 }
1243
1244 int len = strlen (msg);
1245
1246 if (!is_utf8_string ((U8 *)msg, len))
1247 {
1248 new_draw_info_format (NDI_UNIQUE, 0, pl, "Your message is garbled (text must be UTF-8, client-bug)!");
1249 return 0;
1250 }
1251
1252 if (INVOKE_OBJECT (INSCRIBE_NOTE, item, ARG_PLAYER (pl->contr), ARG_STRING (msg), ARG_OBJECT (skill)))
1253 return RESULT_INT (0);
1254
1240 char buf[1024]; 1255 char buf[1024];
1241 object *newBook = NULL;
1242 1256
1243 /* a pair of sanity checks */ 1257 if (len < sizeof (buf) - 2)
1244 if (!item || item->type != BOOK)
1245 return 0;
1246
1247 if (!msg)
1248 {
1249 new_draw_info (NDI_UNIQUE, 0, pl, "No message to write!");
1250 new_draw_info_format (NDI_UNIQUE, 0, pl, "Usage: use_skill %s <message>", &skill->skill);
1251 return 0;
1252 } 1258 {
1259 snprintf (buf, sizeof (buf), "%s\n", msg);
1253 1260
1254 if (strcasestr_local (msg, "endmsg")) 1261 object *newbook = arch_to_object (item->other_arch);
1255 {
1256 new_draw_info (NDI_UNIQUE, 0, pl, "Trying to cheat now are we?");
1257 return 0;
1258 }
1259
1260 if (INVOKE_OBJECT (INSCRIBE_NOTE, item, ARG_PLAYER (pl->contr), ARG_STRING (msg), ARG_OBJECT (skill)))
1261 return strlen (msg);
1262
1263 buf[0] = 0;
1264 if (!book_overflow (item->msg, msg, sizeof (buf)))
1265 { /* add msg string to book */
1266 if (item->msg)
1267 strcpy (buf, item->msg);
1268
1269 strcat (buf, msg);
1270 strcat (buf, "\n"); /* new msg needs a LF */
1271 if (item->nrof > 1)
1272 {
1273 newBook = item->clone ();
1274 decrease_ob (item); 1262 decrease_ob (item);
1275 esrv_send_item (pl, item); 1263 esrv_send_item (pl, item);
1276 newBook->nrof = 1; 1264 newbook->nrof = 1;
1277 newBook->msg = buf; 1265 newbook->msg = buf;
1266 newbook->flag [FLAG_IDENTIFIED] = true;
1267
1268 if (item->subtype == 1) // mailscrolls
1269 {
1270 newbook->name = item->name;
1271 newbook->name_pl = item->name_pl;
1272 }
1273
1278 newBook = insert_ob_in_ob (newBook, pl); 1274 newbook = insert_ob_in_ob (newbook, pl);
1279 esrv_send_item (pl, newBook); 1275 esrv_send_item (pl, newbook);
1280 }
1281 else
1282 {
1283 item->msg = buf;
1284 /* This shouldn't be necessary - the object hasn't changed in any
1285 * visible way
1286 */
1287 /* esrv_send_item(pl, item); */
1288 }
1289 1276
1277 pl->contr->play_sound (sound_find ("inscribe_success"));
1290 new_draw_info_format (NDI_UNIQUE, 0, pl, "You write in the %s.", query_short_name (item)); 1278 new_draw_info_format (NDI_UNIQUE, 0, pl, "You write in the %s.", &item->name);
1291 return strlen (msg); 1279 return strlen (msg);
1292 } 1280 }
1293 else 1281 else
1294 new_draw_info_format (NDI_UNIQUE, 0, pl, "Your message won't fit in the %s!", query_short_name (item)); 1282 new_draw_info_format (NDI_UNIQUE, 0, pl, "Your message won't fit in the %s!", &item->name);
1295 1283
1296 return 0; 1284 return 0;
1297} 1285}
1298 1286
1299/* write_scroll() - this routine allows players to inscribe spell scrolls 1287/* write_scroll() - this routine allows players to inscribe spell scrolls
1300 * of spells which they know. Backfire effects are possible with the 1288 * of spells which they know. Backfire effects are possible with the
1301 * severity of the backlash correlated with the difficulty of the scroll 1289 * severity of the backlash correlated with the difficulty of the scroll
1302 * that is attempted. -b.t. thomas@astro.psu.edu 1290 * that is attempted. -b.t. thomas@astro.psu.edu
1303 */ 1291 */
1304
1305static int 1292static int
1306write_scroll (object *pl, object *scroll, object *skill) 1293write_scroll (object *pl, object *scroll, object *skill)
1307{ 1294{
1308 int success = 0, confused = 0; 1295 int success = 0, confused = 0;
1309 object *newscroll, *chosen_spell, *tmp;
1310
1311 /* this is a sanity check */
1312 if (scroll->type != SCROLL)
1313 {
1314 new_draw_info (NDI_UNIQUE, 0, pl, "A spell can only be inscribed into a scroll!");
1315 return 0;
1316 }
1317 1296
1318 /* Check if we are ready to attempt inscription */ 1297 /* Check if we are ready to attempt inscription */
1319 chosen_spell = pl->contr->ranged_ob; 1298 object *chosen_spell = pl->contr->ranged_ob;
1299
1320 if (!chosen_spell || chosen_spell->type != SPELL) 1300 if (!chosen_spell || chosen_spell->type != SPELL)
1321 { 1301 {
1322 new_draw_info (NDI_UNIQUE, 0, pl, "You need a spell readied in order to inscribe!"); 1302 new_draw_info (NDI_UNIQUE, 0, pl, "You need a spell readied in order to inscribe!");
1323 return 0; 1303 return 0;
1324 } 1304 }
1330 } 1310 }
1331 1311
1332 if (SP_level_spellpoint_cost (pl, chosen_spell, SPELL_MANA) > pl->stats.sp) 1312 if (SP_level_spellpoint_cost (pl, chosen_spell, SPELL_MANA) > pl->stats.sp)
1333 { 1313 {
1334 new_draw_info_format (NDI_UNIQUE, 0, pl, "You don't have enough mana to write a scroll of %s.", &chosen_spell->name); 1314 new_draw_info_format (NDI_UNIQUE, 0, pl, "You don't have enough mana to write a scroll of %s.", &chosen_spell->name);
1335 return 0;
1336 }
1337
1338 /* if there is a spell already on the scroll then player could easily
1339 * accidently read it while trying to write the new one. give player
1340 * a 50% chance to overwrite spell at their own level
1341 */
1342 if ((scroll->stats.sp || scroll->inv) && random_roll (0, scroll->level * 2, pl, PREFER_LOW) > skill->level)
1343 {
1344 new_draw_info_format (NDI_UNIQUE, 0, pl, "Oops! You accidently read it while trying to write on it.");
1345 manual_apply (pl, scroll, 0);
1346 return 0; 1315 return 0;
1347 } 1316 }
1348 1317
1349 /* ok, we are ready to try inscription */ 1318 /* ok, we are ready to try inscription */
1350 if (QUERY_FLAG (pl, FLAG_CONFUSED)) 1319 if (QUERY_FLAG (pl, FLAG_CONFUSED))
1354 pl->stats.grace -= SP_level_spellpoint_cost (pl, chosen_spell, SPELL_GRACE); 1323 pl->stats.grace -= SP_level_spellpoint_cost (pl, chosen_spell, SPELL_GRACE);
1355 pl->stats.sp -= SP_level_spellpoint_cost (pl, chosen_spell, SPELL_MANA); 1324 pl->stats.sp -= SP_level_spellpoint_cost (pl, chosen_spell, SPELL_MANA);
1356 1325
1357 if (random_roll (0, chosen_spell->level * 4 - 1, pl, PREFER_LOW) < skill->level) 1326 if (random_roll (0, chosen_spell->level * 4 - 1, pl, PREFER_LOW) < skill->level)
1358 { 1327 {
1359 if (scroll->nrof > 1) 1328 object *newscroll = arch_to_object (scroll->other_arch);
1360 {
1361 newscroll = scroll->clone ();
1362 decrease_ob (scroll); 1329 decrease_ob (scroll);
1363 newscroll->nrof = 1; 1330 newscroll->nrof = 1;
1364 } 1331
1365 else 1332 pl->contr->play_sound (sound_find ("inscribe_success"));
1366 newscroll = scroll;
1367 1333
1368 if (!confused) 1334 if (!confused)
1369 { 1335 {
1370 newscroll->level = MAX (skill->level, chosen_spell->level); 1336 newscroll->level = MAX (skill->level, chosen_spell->level);
1337 newscroll->flag [FLAG_IDENTIFIED] = true;
1371 new_draw_info (NDI_UNIQUE, 0, pl, "You succeed in writing a new scroll."); 1338 new_draw_info (NDI_UNIQUE, 0, pl, "You succeed in writing the spell.");
1372 } 1339 }
1373 else 1340 else
1374 { 1341 {
1375 chosen_spell = find_random_spell_in_ob (pl, NULL); 1342 chosen_spell = find_random_spell_in_ob (pl, NULL);
1376 if (!chosen_spell) 1343 if (!chosen_spell)
1378 1345
1379 newscroll->level = MAX (skill->level, chosen_spell->level); 1346 newscroll->level = MAX (skill->level, chosen_spell->level);
1380 new_draw_info (NDI_UNIQUE, 0, pl, "In your confused state, you write down some odd spell."); 1347 new_draw_info (NDI_UNIQUE, 0, pl, "In your confused state, you write down some odd spell.");
1381 } 1348 }
1382 1349
1383 if (newscroll->inv)
1384 newscroll->inv->destroy ();
1385
1386 tmp = chosen_spell->clone (); 1350 object *tmp = chosen_spell->clone ();
1387 insert_ob_in_ob (tmp, newscroll); 1351 insert_ob_in_ob (tmp, newscroll);
1388 1352
1389 /* Same code as from treasure.c - so they can better merge. 1353 /* Same code as from treasure.C - so they can better merge.
1390 * if players want to sell them, so be it. 1354 * if players want to sell them, so be it.
1391 */ 1355 */
1392 newscroll->value = newscroll->arch->clone.value * newscroll->inv->value * (newscroll->level + 50) / (newscroll->inv->level + 50); 1356 newscroll->value = newscroll->arch->value * newscroll->inv->value * (newscroll->level + 50) / (newscroll->inv->level + 50);
1393 newscroll->stats.exp = newscroll->value / 5; 1357 newscroll->stats.exp = newscroll->value / 5;
1394
1395 /* wait until finished manipulating the scroll before inserting it */
1396 if (newscroll == scroll)
1397 {
1398 /* Remove to correctly merge with other items which may exist in inventory */
1399 newscroll->remove ();
1400 esrv_del_item (pl->contr, newscroll->count);
1401 }
1402 1358
1403 newscroll = insert_ob_in_ob (newscroll, pl); 1359 newscroll = insert_ob_in_ob (newscroll, pl);
1404 esrv_send_item (pl, newscroll); 1360 esrv_send_item (pl, newscroll);
1361
1405 success = calc_skill_exp (pl, newscroll, skill); 1362 success = calc_skill_exp (pl, newscroll, skill);
1406 if (!confused) 1363 if (!confused)
1407 success *= 2; 1364 success *= 2;
1365
1408 success = success * skill->level; 1366 success = success * skill->level;
1409 return success; 1367 return success;
1410
1411 } 1368 }
1412 else 1369 else
1413 { /* Inscription has failed */ 1370 { /* Inscription has failed */
1371 pl->contr->play_sound (sound_find ("inscribe_fail"));
1414 1372
1415 if (chosen_spell->level > skill->level || confused) 1373 if (chosen_spell->level > skill->level || confused)
1416 { /*backfire! */ 1374 { /*backfire! */
1417 new_draw_info (NDI_UNIQUE, 0, pl, "Ouch! Your attempt to write a new scroll strains your mind!"); 1375 new_draw_info (NDI_UNIQUE, 0, pl, "Ouch! Your attempt to write a new scroll strains your mind!");
1376
1418 if (random_roll (0, 1, pl, PREFER_LOW) == 1) 1377 if (random_roll (0, 1, pl, PREFER_LOW) == 1)
1419 pl->drain_specific_stat (4); 1378 pl->drain_specific_stat (4);
1420 else 1379 else
1421 { 1380 {
1422 confuse_player (pl, pl, 99); 1381 confuse_player (pl, pl, 99);
1423 return (-30 * chosen_spell->level); 1382 return -30 * chosen_spell->level;
1424 } 1383 }
1425 } 1384 }
1426 else if (random_roll (0, pl->stats.Int - 1, pl, PREFER_HIGH) < 15) 1385 else if (random_roll (0, pl->stats.Int - 1, pl, PREFER_HIGH) < 15)
1427 { 1386 {
1428 new_draw_info (NDI_UNIQUE, 0, pl, "Your attempt to write a new scroll rattles your mind!"); 1387 new_draw_info (NDI_UNIQUE, 0, pl, "Your attempt to write a new scroll rattles your mind! H<Frankly spoken, you were too dumb and unlucky.>");
1429 confuse_player (pl, pl, 99); 1388 confuse_player (pl, pl, 99);
1430 } 1389 }
1431 else 1390 else
1432 new_draw_info (NDI_UNIQUE, 0, pl, "You fail to write a new scroll."); 1391 new_draw_info (NDI_UNIQUE, 0, pl, "You fail to write a new scroll. H<Try a lower-level spell, if possible at all.>");
1433 } 1392 }
1434 1393
1435 return 0; 1394 return 0;
1436} 1395}
1437 1396
1438/* write_on_item() - wrapper for write_note and write_scroll */ 1397/* write_on_item() - wrapper for write_note and write_scroll */
1439int 1398int
1440write_on_item (object *pl, const char *params, object *skill) 1399write_on_item (object *pl, const char *params, object *skill)
1441{ 1400{
1442 object *item;
1443 const char *string = params;
1444 int msgtype;
1445 archetype *skat; 1401 archetype *skat;
1446 1402
1447 if (pl->type != PLAYER) 1403 if (pl->type != PLAYER)
1448 return 0; 1404 return 0;
1449 1405
1450 if (!params) 1406 if (!params)
1451 {
1452 params = ""; 1407 params = "";
1453 string = params;
1454 }
1455 1408
1456 skat = get_archetype_by_type_subtype (SKILL, SK_LITERACY); 1409 skat = get_archetype_by_type_subtype (SKILL, SK_LITERACY);
1457 1410
1458 /* Need to be able to read before we can write! */ 1411 /* Need to be able to read before we can write! */
1459 if (!find_skill_by_name (pl, skat->clone.skill)) 1412 if (!find_skill_by_name (pl, skat->skill))
1460 { 1413 {
1461 new_draw_info (NDI_UNIQUE, 0, pl, "You must learn to read before you can write!"); 1414 new_draw_info (NDI_UNIQUE, 0, pl, "You must learn to read before you can write! H<You lack the literacy skill.>");
1462 return 0; 1415 return 0;
1463 } 1416 }
1464 1417
1465 /* if there is a message then it goes in a book and no message means 1418 object *item = find_marked_object (pl);
1466 * write active spell into the scroll
1467 */
1468 msgtype = (string[0] != '\0') ? BOOK : SCROLL;
1469 1419
1470 /* find an item of correct type to write on */ 1420 /* find an item of correct type to write on */
1471 if (!(item = find_marked_object (pl))) 1421 if (!item)
1422 {
1423 new_draw_info (NDI_UNIQUE, 0, pl, "You don't have any marked item to write on. H<Use the mark command or the popup menu to makr an item.>");
1424 return 0;
1472 { 1425 }
1473 new_draw_info (NDI_UNIQUE, 0, pl, "You don't have any marked item to write on."); 1426
1427 if (item->type != INSCRIBABLE)
1428 {
1429 new_draw_info_format (NDI_UNIQUE, 0, pl, "You cannot inscribe this! H<You can only inscribe empty scrolls and books.>");
1474 return 0; 1430 return 0;
1475 } 1431 }
1476 1432
1477 if (QUERY_FLAG (item, FLAG_UNPAID)) 1433 if (QUERY_FLAG (item, FLAG_UNPAID))
1478 { 1434 {
1479 new_draw_info (NDI_UNIQUE, 0, pl, "You had better pay for that before you write on it."); 1435 new_draw_info (NDI_UNIQUE, 0, pl, "You had better pay for that before you write on it.");
1480 return 0; 1436 return 0;
1481 } 1437 }
1482 if (msgtype != item->type) 1438
1439 if (item->other_arch->type == SCROLL)
1483 { 1440 {
1484 new_draw_info_format (NDI_UNIQUE, 0, pl, "You have no %s to write on", msgtype == BOOK ? "book" : "scroll"); 1441 if (*params)
1442 {
1443 // check readied scroll
1444 new_draw_info_format (NDI_UNIQUE, 0, pl,
1445 "When inscribing spells you need to ready a spell and do not specify a string argument.\n"
1446 "Usage: cast [spell name]; use_skill %s", &skill->skill);
1485 return 0; 1447 return 0;
1486 } 1448 }
1487 1449
1488 if (msgtype == SCROLL)
1489 return write_scroll (pl, item, skill); 1450 return write_scroll (pl, item, skill);
1490 else if (msgtype == BOOK) 1451 }
1452 else
1453 {
1454 if (!*params)
1455 {
1456 new_draw_info_format (NDI_UNIQUE, 0, pl,
1457 "When inscribing books you need to specify the words you want to inscribe as command argument.\n"
1458 "Usage: use_skill %s <message>", &skill->skill);
1459 return 0;
1460 }
1461
1491 return write_note (pl, item, string, skill); 1462 return write_note (pl, item, params, skill);
1463 }
1492 1464
1493 return 0; 1465 return 0;
1494} 1466}
1495 1467
1496/* find_throw_ob() - if we request an object, then 1468/* find_throw_ob() - if we request an object, then
1598 object *toss_item = orig->clone (); 1570 object *toss_item = orig->clone ();
1599 1571
1600 toss_item->type = THROWN_OBJ; 1572 toss_item->type = THROWN_OBJ;
1601 CLEAR_FLAG (toss_item, FLAG_CHANGING); 1573 CLEAR_FLAG (toss_item, FLAG_CHANGING);
1602 toss_item->stats.dam = 0; /* default damage */ 1574 toss_item->stats.dam = 0; /* default damage */
1603 insert_ob_in_ob (orig, toss_item); 1575 toss_item->insert (orig);
1576
1604 return toss_item; 1577 return toss_item;
1605} 1578}
1606 1579
1607/* do_throw() - op throws any object toss_item. This code 1580/* do_throw() - op throws any object toss_item. This code
1608 * was borrowed from fire_bow. 1581 * was borrowed from fire_bow.
1748 */ 1721 */
1749 throw_ob->inv->set_owner (op); 1722 throw_ob->inv->set_owner (op);
1750 throw_ob->direction = dir; 1723 throw_ob->direction = dir;
1751 1724
1752 /* the damage bonus from the force of the throw */ 1725 /* the damage bonus from the force of the throw */
1753 dam = (int) (str_factor * dam_bonus[eff_str]); 1726 dam = int (str_factor * dam_bonus[eff_str]);
1754 1727
1755 /* Now, lets adjust the properties of the thrown_ob. */ 1728 /* Now, lets adjust the properties of the thrown_ob. */
1756 1729
1757 /* how far to fly */ 1730 /* how far to fly */
1758 throw_ob->last_sp = (eff_str * 3) / 5; 1731 throw_ob->last_sp = (eff_str * 3) / 5;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines