summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/effects.cc
diff options
context:
space:
mode:
authordshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2009-09-21 08:23:35 +0000
committerdshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2009-09-21 08:23:35 +0000
commita36fd3f9f0e5bde3dd9d74e1742cfbd2f045c635 (patch)
tree162c04f1bb86a4f1bde64d55c69c81ee65b38680 /crawl-ref/source/effects.cc
parent02c7a7e290da364ed194a72ccc42240afe19e344 (diff)
downloadcrawl-ref-a36fd3f9f0e5bde3dd9d74e1742cfbd2f045c635.tar.gz
crawl-ref-a36fd3f9f0e5bde3dd9d74e1742cfbd2f045c635.zip
Allow vaults to request use of the acquirement code with "acquire <item_class>" or "acquire:<god> <item_class>" in item specs (due).
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@10765 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/effects.cc')
-rw-r--r--crawl-ref/source/effects.cc199
1 files changed, 103 insertions, 96 deletions
diff --git a/crawl-ref/source/effects.cc b/crawl-ref/source/effects.cc
index 9576d5b95e..83a048b643 100644
--- a/crawl-ref/source/effects.cc
+++ b/crawl-ref/source/effects.cc
@@ -1774,87 +1774,21 @@ static bool _do_book_acquirement(item_def &book, int agent)
return (true);
}
-bool acquirement(object_class_type class_wanted, int agent,
- bool quiet, int* item_index)
+static int _failed_acquirement(bool quiet)
{
- ASSERT(!crawl_state.arena);
-
- int thing_created = NON_ITEM;
-
- if (item_index == NULL)
- item_index = &thing_created;
-
- *item_index = NON_ITEM;
-
- while (class_wanted == OBJ_RANDOM)
- {
- ASSERT(!quiet);
- mesclr();
- mpr("[a] Weapon [b] Armour [c] Jewellery [d] Book");
- mpr("[e] Staff [f] Wand [g] Miscellaneous [h] Food [i] Gold");
- mpr("What kind of item would you like to acquire? ", MSGCH_PROMPT);
-
- const int keyin = tolower( get_ch() );
- switch (keyin)
- {
- case 'a': case ')': class_wanted = OBJ_WEAPONS; break;
- case 'b': case '[': case ']': class_wanted = OBJ_ARMOUR; break;
- case 'c': case '=': case '"': class_wanted = OBJ_JEWELLERY; break;
- case 'd': case '+': case ':': class_wanted = OBJ_BOOKS; break;
- case 'e': case '\\': case '|': class_wanted = OBJ_STAVES; break;
- case 'f': case '/': class_wanted = OBJ_WANDS; break;
- case 'g': case '}': case '{': class_wanted = OBJ_MISCELLANY; break;
- case 'h': case '%': class_wanted = OBJ_FOOD; break;
- case 'i': case '$': class_wanted = OBJ_GOLD; break;
- default:
- // Lets wizards escape out of accidently choosing acquirement.
- if (agent == AQ_WIZMODE)
- {
- canned_msg(MSG_OK);
- return (false);
- }
-
-#if defined(USE_UNIX_SIGNALS) && defined(SIGHUP_SAVE) && defined(USE_CURSES)
- // If we've gotten a HUP signal then the player will be unable
- // to make a selection.
- if (crawl_state.seen_hups)
- {
- mpr("Acquirement interrupted by HUP signal.", MSGCH_ERROR);
- you.turn_is_over = false;
- return (false);
- }
-#endif
- break;
- }
- }
-
- if (grid_destroys_items(grd(you.pos())))
- {
- // How sad (and stupid).
- if (!silenced(you.pos()) && !quiet)
- mprf(MSGCH_SOUND, grid_item_destruction_message(grd(you.pos())));
-
- if (agent > GOD_NO_GOD && agent < NUM_GODS)
- {
- if (agent == GOD_XOM)
- simple_god_message(" snickers.", GOD_XOM);
- else
- {
- ASSERT(!"God gave gift item while player was on grid which "
- "destroys items.");
- mprf(MSGCH_ERROR, "%s gave a god gift while you were on "
- "terrain which destroys items.",
- god_name((god_type) agent).c_str());
- }
- }
-
- *item_index = NON_ITEM;
+ if (!quiet)
+ mpr("The demon of the infinite void smiles upon you.");
+ return (NON_ITEM);
+}
- // Well, the item may have fallen in the drink, but the intent is
- // that acquirement happened. -- bwr
- return (true);
- }
+int acquirement_create_item(object_class_type class_wanted,
+ int agent,
+ bool quiet,
+ const coord_def &pos)
+{
+ ASSERT(class_wanted != OBJ_RANDOM);
+ int thing_created = NON_ITEM;
int quant = 1;
for (int item_tries = 0; item_tries < 40; item_tries++)
{
@@ -2008,12 +1942,7 @@ bool acquirement(object_class_type class_wanted, int agent,
}
if (thing_created == NON_ITEM)
- {
- if (!quiet)
- mpr("The demon of the infinite void smiles upon you.");
- *item_index = NON_ITEM;
- return (false);
- }
+ return _failed_acquirement(quiet);
// Easier to read this way.
item_def& thing(mitm[thing_created]);
@@ -2036,11 +1965,8 @@ bool acquirement(object_class_type class_wanted, int agent,
{
if (!_do_book_acquirement(thing, agent))
{
- if (!quiet)
- mpr("The demon of the infinite void smiles upon you.");
- *item_index = NON_ITEM;
destroy_item(thing, true);
- return (false);
+ return _failed_acquirement(quiet);
}
mark_had_book(thing);
}
@@ -2164,21 +2090,102 @@ bool acquirement(object_class_type class_wanted, int agent,
if (agent > GOD_NO_GOD && agent < NUM_GODS && agent == you.religion)
thing.inscription = "god gift";
- move_item_to_grid( &thing_created, you.pos() );
+ move_item_to_grid( &thing_created, pos );
// This should never actually be NON_ITEM because of the way
// move_item_to_grid works (doesn't create a new item ever),
// but we're checking it anyways. -- bwr
- if (thing_created != NON_ITEM)
+ if (thing_created != NON_ITEM && !quiet)
+ canned_msg(MSG_SOMETHING_APPEARS);
+
+ return (thing_created);
+}
+
+bool acquirement(object_class_type class_wanted, int agent,
+ bool quiet, int* item_index)
+{
+ ASSERT(!crawl_state.arena);
+
+ int thing_created = NON_ITEM;
+
+ if (item_index == NULL)
+ item_index = &thing_created;
+
+ *item_index = NON_ITEM;
+
+ while (class_wanted == OBJ_RANDOM)
{
- if (!quiet)
- canned_msg(MSG_SOMETHING_APPEARS);
+ ASSERT(!quiet);
+ mesclr();
+ mpr("[a] Weapon [b] Armour [c] Jewellery [d] Book");
+ mpr("[e] Staff [f] Wand [g] Miscellaneous [h] Food [i] Gold");
+ mpr("What kind of item would you like to acquire? ", MSGCH_PROMPT);
+
+ const int keyin = tolower( get_ch() );
+ switch (keyin)
+ {
+ case 'a': case ')': class_wanted = OBJ_WEAPONS; break;
+ case 'b': case '[': case ']': class_wanted = OBJ_ARMOUR; break;
+ case 'c': case '=': case '"': class_wanted = OBJ_JEWELLERY; break;
+ case 'd': case '+': case ':': class_wanted = OBJ_BOOKS; break;
+ case 'e': case '\\': case '|': class_wanted = OBJ_STAVES; break;
+ case 'f': case '/': class_wanted = OBJ_WANDS; break;
+ case 'g': case '}': case '{': class_wanted = OBJ_MISCELLANY; break;
+ case 'h': case '%': class_wanted = OBJ_FOOD; break;
+ case 'i': case '$': class_wanted = OBJ_GOLD; break;
+ default:
+ // Lets wizards escape out of accidently choosing acquirement.
+ if (agent == AQ_WIZMODE)
+ {
+ canned_msg(MSG_OK);
+ return (false);
+ }
+
+#if defined(USE_UNIX_SIGNALS) && defined(SIGHUP_SAVE) && defined(USE_CURSES)
+ // If we've gotten a HUP signal then the player will be unable
+ // to make a selection.
+ if (crawl_state.seen_hups)
+ {
+ mpr("Acquirement interrupted by HUP signal.", MSGCH_ERROR);
+ you.turn_is_over = false;
+ return (false);
+ }
+#endif
+ break;
+ }
}
- *item_index = thing_created;
- // Well, the item may have fallen in the drink, but the intent is
- // that acquirement happened. -- bwr
- return (true);
+ if (grid_destroys_items(grd(you.pos())))
+ {
+ // How sad (and stupid).
+ if (!silenced(you.pos()) && !quiet)
+ mprf(MSGCH_SOUND, grid_item_destruction_message(grd(you.pos())));
+
+ if (agent > GOD_NO_GOD && agent < NUM_GODS)
+ {
+ if (agent == GOD_XOM)
+ simple_god_message(" snickers.", GOD_XOM);
+ else
+ {
+ ASSERT(!"God gave gift item while player was on grid which "
+ "destroys items.");
+ mprf(MSGCH_ERROR, "%s gave a god gift while you were on "
+ "terrain which destroys items.",
+ god_name((god_type) agent).c_str());
+ }
+ }
+
+ *item_index = NON_ITEM;
+
+ // Well, the item may have fallen in the drink, but the intent is
+ // that acquirement happened. -- bwr
+ return (true);
+ }
+
+ *item_index =
+ acquirement_create_item(class_wanted, agent, quiet, you.pos());
+
+ return (*item_index != NON_ITEM);
}
bool recharge_wand(int item_slot)