• R/O
  • SSH
  • HTTPS

angband65: Commit


Commit MetaInfo

Revision138 (tree)
Zeit2009-05-09 22:33:36
Autorpaulblay

Log Message

This closes #16641 Some commands triggered by wrong keys.

Ändern Zusammenfassung

Diff

--- trunk/Angband65/src/cmd-obj.c (revision 137)
+++ trunk/Angband65/src/cmd-obj.c (revision 138)
@@ -298,6 +298,55 @@
298298 }
299299 #endif
300300
301+#if 0 /* Based on Vanilla version */
302+/* Cast a spell from a book */
303+static void obj_cast(object_type *o_ptr, int item)
304+{
305+ int spell;
306+ cptr verb = ((cp_ptr->spell_stat == 1) ? "cast" : "recite");
307+ UNREFERENCED_PARAMETER(item);
308+
309+ /* Track the object kind */
310+ object_kind_track(o_ptr->k_idx);
311+ handle_stuff();
312+
313+ /* Ask for a spell */
314+ spell = get_spell(o_ptr, verb, TRUE, FALSE);
315+ if (spell < 0)
316+ {
317+ cptr p = ((cp_ptr->spell_stat == 1) ? "spell" : "prayer");
318+
319+ if (spell == -2) msg_format("You don't know any %ss in that book.", p);
320+ return;
321+ }
322+
323+ /* Cast a spell */
324+ if (spell_cast(spell))
325+ p_ptr->energy_use = 100;
326+}
327+#endif
328+
329+/*
330+ * Cast a spell
331+ */
332+static void obj_cast(object_type *o_ptr, int item) /* do_cmd_cast_spell(void) */
333+{
334+ s16b spellno;
335+ UNREFERENCED_PARAMETER(o_ptr);
336+ UNREFERENCED_PARAMETER(item);
337+
338+ spellno = select_spell();
339+ if (spellno == -1) return ;
340+
341+ /* if exec_page returns FALSE, we don't have enough mana and aborted */
342+ if (exec_page(spellno))
343+ {
344+ /* Take a turn */
345+ p_ptr->energy_use = 100;
346+ }
347+}
348+
349+
301350 /*** Using items the traditional way ***/
302351
303352 /* Determine if the player can read scrolls. */
@@ -530,14 +579,14 @@
530579 { obj_browse, "browse",
531580 "Browse which book? ", "You have no books that you can read.",
532581 obj_can_browse, (USE_INVEN | USE_FLOOR | IS_HARMLESS), NULL },
533-/* TODO Do we need something here instead of obj_study and obj_cast ? */
534582 /* { obj_study, "study",
535583 "Study which book? ", "You have no books that you can read.",
536- obj_can_browse, (USE_INVEN | USE_FLOOR), obj_study_pre },
584+ obj_can_browse, (USE_INVEN | USE_FLOOR), obj_study_pre }, */
537585
586+/* TODO Do we need something here instead of obj_cast ? */
538587 { obj_cast, "cast",
539588 "Use which book? ", "You have no books that you can read.",
540- obj_can_browse, (USE_INVEN | USE_FLOOR), obj_cast_pre }, */
589+ obj_can_browse, (USE_INVEN | USE_FLOOR), obj_cast_pre },
541590
542591 /*** Item usage ***/
543592 { obj_use_staff, "use",
--- trunk/Angband65/src/externs.h (revision 137)
+++ trunk/Angband65/src/externs.h (revision 138)
@@ -324,6 +324,11 @@
324324 /* int spell_choose_new(const object_type *o_ptr); */
325325 bool spell_cast(int spell);
326326 /* void spell_learn(int spell); */
327+extern bool exec_page(s16b spellno);
328+extern bool exec_spell(s16b spellno);
329+extern s16b select_spell(void);
330+extern s16b select_spell_from_book(int item);
331+extern s16b select_spell_by_number(void);
327332
328333 int get_spell(const object_type *o_ptr, cptr prompt, bool known, bool browse);
329334 void do_cmd_browse_aux(const object_type *o_ptr);
--- trunk/Angband65/src/cmd5.c (revision 137)
+++ trunk/Angband65/src/cmd5.c (revision 138)
@@ -1146,8 +1146,217 @@
11461146 return ((s16b) o_ptr->tval == TV_BOOK);
11471147 }
11481148
1149+/* select a spell from book 'item'. return -1 if not successful */
1150+s16b select_spell_from_book(int item)
1151+{
1152+ object_type *o_ptr;
1153+ s16b count, i, j, k, spellno;
1154+ s16b index[MAX_SPELLS_PER_ITEM];
1155+ char buf;
11491156
1157+ /* Get the item */
1158+ o_ptr = &inventory[item];
1159+
1160+ count = 0;
1161+ for (i=0; i<MAX_SPELLS_PER_ITEM; i++)
1162+ {
1163+ if (has_spell(o_ptr, i)) index[count++]=i;
1164+ }
1165+
1166+ if (count==0)
1167+ {
1168+ msg_print("This book is empty.");
1169+ return -1;
1170+ }
1171+
1172+ object_kind_track(o_ptr->k_idx);
1173+ handle_stuff();
1174+
1175+ /* Save the screen */
1176+ (void)Term_save();
1177+
1178+ print_spells(index, count);
1179+
1180+ /* Clear the top line */
1181+ prt("", 0, 0);
1182+
1183+ buf = '\0';
1184+
1185+ /* Prompt user */
1186+ if (!get_com("Which spell (press @ for number)? ", &buf))
1187+ {
1188+ (void)Term_load();
1189+ return -1;
1190+ }
1191+ if (buf == '@')
1192+ {
1193+ char buf2[20];
1194+
1195+ buf2[0]='\0';
1196+ if (!get_string("Enter spell number: ", buf2, 3))
1197+ {
1198+ (void)Term_load();
1199+ return -1;
1200+ }
1201+ spellno=(s16b)atol(buf2);
1202+ if (spellno < 0)
1203+ {
1204+ (void)Term_load();
1205+ return -1;
1206+ }
1207+ for (j=0; j<INVEN_PACK; j++)
1208+ {
1209+ if (inventory[j].tval == TV_BOOK)
1210+ {
1211+ for (k = 0; k < z_info->s_max; k++)
1212+ {
1213+ if (has_spell(&inventory[j], spellno)) break;
1214+ }
1215+ if (k < z_info->s_max) break;
1216+ }
1217+ }
1218+ if (j == INVEN_PACK)
1219+ {
1220+ msg_print(NULL);
1221+ msg_print("That spell is not in in a book in your inventory.");
1222+ return -1;
1223+ }
1224+ }
1225+ else
1226+ {
1227+ spellno=(s16b)A2I(buf);
1228+ if ((spellno < 0) || (spellno >= count))
1229+ {
1230+ (void)Term_load();
1231+ return -1;
1232+ }
1233+ spellno=index[spellno];
1234+ }
1235+ (void)Term_load();
1236+ return (spellno);
1237+}
1238+
1239+s16b select_spell_by_number(void)
1240+{
1241+ char buf2[4];
1242+ s16b i, j, spellno;
1243+ cptr p;
1244+
1245+ buf2[0]='\0';
1246+
1247+ p = "Enter spell number (globally over all your books): ";
1248+ if (!get_string(p, buf2, 3)) return -1;
1249+ spellno = (s16b) atoi(buf2);
1250+
1251+ for (i = 0; i < INVEN_PACK; i++)
1252+ {
1253+ if (inventory[i].tval == TV_BOOK)
1254+ {
1255+ for (j=0; j<z_info->s_max; j++)
1256+ {
1257+ if (has_spell(&inventory[i], spellno)) break;
1258+ }
1259+ if (j < z_info->s_max) break;
1260+ }
1261+ }
1262+ if (i == INVEN_PACK)
1263+ {
1264+ msg_print(NULL);
1265+ msg_print("That spell is not in in a book in your inventory.");
1266+ return -1;
1267+ }
1268+ /* this is necessary to prevent messing up the screen */
1269+ prt(" ", 0, 0);
1270+ return spellno;
1271+}
1272+
11501273 /*
1274+ * Auxiliary function for "get_item()" -- test an index
1275+ */
1276+static bool get_item_okay(s16b i)
1277+{
1278+ /* Illegal items */
1279+ if ((i < 0) ||
1280+ (i > (INVEN_TOTAL - 1))) return (FALSE); /* TODO Handle objects on floor */
1281+
1282+ /* Verify the item */
1283+ return (item_tester_okay(&inventory[i]));
1284+}
1285+
1286+s16b count_items(int *first_item, bool equip, bool inven, bool floor)
1287+{
1288+ s16b i, result = 0;
1289+ UNREFERENCED_PARAMETER(floor); /* TODO Handle floor */
1290+
1291+ if (inven)
1292+ {
1293+ for (i=0; i<INVEN_PACK; i++)
1294+ {
1295+ if (get_item_okay(i))
1296+ {
1297+ result++;
1298+ (*first_item)=i;
1299+ }
1300+ }
1301+ }
1302+ if (equip)
1303+ {
1304+ for (i=INVEN_WIELD; i<INVEN_TOTAL; i++)
1305+ {
1306+ if (get_item_okay(i))
1307+ {
1308+ result++;
1309+ (*first_item)=i;
1310+ }
1311+ }
1312+ }
1313+/* if (floor)
1314+ {
1315+ for (i=INVEN_TOTAL; i<objects_on_floor(px, py); i++)
1316+ {
1317+ if (get_item_okay(i))
1318+ {
1319+ result++;
1320+ (*first_item)=i;
1321+ }
1322+ }
1323+ } */ /* TODO Handle floor */
1324+ return (result);
1325+}
1326+
1327+/* this function selects a spell, either by book or by number */
1328+s16b select_spell(void)
1329+{
1330+ s16b spellno, count;
1331+ int item;
1332+
1333+ /* Restrict choices to scrolls */
1334+ item_tester_tval = (byte)TV_BOOK;
1335+ item_tester_hook = NULL;
1336+ count = count_items(&item, FALSE, TRUE, TRUE);
1337+
1338+ /* Get an item (from inven or floor) */ /* TODO Handle floor */
1339+ if ( (count != 1) &&
1340+ !get_item(&item, "Cast spell from what? ", "You have nothing to read spells from.", USE_INVEN))
1341+ {
1342+ item_tester_tval = (byte)0;
1343+ if ( (item == -1) || (item == -2) ) return -1;
1344+ }
1345+ item_tester_tval = (byte)0;
1346+
1347+ /* item -3 means @ means cast spell by number, never mind the book */
1348+ if (item != -3)
1349+ {
1350+ spellno = select_spell_from_book(item);
1351+ }
1352+ else
1353+ {
1354+ spellno = select_spell_by_number();
1355+ }
1356+ return (spellno);
1357+}
1358+
1359+/*
11511360 * Peruse the spells/prayers in a Book
11521361 *
11531362 * Note that *all* spells in the book are listed
Show on old repository browser