summaryrefslogtreecommitdiffstats
path: root/crawl-ref
diff options
context:
space:
mode:
authorMatthew Cline <zelgadis@sourceforge.net>2009-11-02 00:18:27 -0800
committerMatthew Cline <zelgadis@sourceforge.net>2009-11-02 00:19:26 -0800
commita3673d5b42142d7f495a37f1e4f9569c6b176919 (patch)
treec9b2b92ad4b5f96a6c4dc1ba9ec48eccc58ec725 /crawl-ref
parent945b0cd6507cb5453e099e0cc245706f70c87d98 (diff)
downloadcrawl-ref-a3673d5b42142d7f495a37f1e4f9569c6b176919.tar.gz
crawl-ref-a3673d5b42142d7f495a37f1e4f9569c6b176919.zip
Ziggurats can now be added to the shopping list.
Diffstat (limited to 'crawl-ref')
-rw-r--r--crawl-ref/source/dat/clua/lm_toll.lua64
-rw-r--r--crawl-ref/source/l_you.cc37
-rw-r--r--crawl-ref/source/player.cc3
-rw-r--r--crawl-ref/source/shopping.cc91
4 files changed, 176 insertions, 19 deletions
diff --git a/crawl-ref/source/dat/clua/lm_toll.lua b/crawl-ref/source/dat/clua/lm_toll.lua
index 616ff7ed27..d74a1c7cf4 100644
--- a/crawl-ref/source/dat/clua/lm_toll.lua
+++ b/crawl-ref/source/dat/clua/lm_toll.lua
@@ -13,6 +13,7 @@ function TollStair:new(props)
if not props.amount or props.amount < 1 then
error("Bad toll amount: " .. props.amount)
end
+ toll.seen = 0
return toll
end
@@ -21,6 +22,54 @@ function TollStair:activate(marker)
dgn.register_listener(dgn.dgn_event_type("v_leave_level"),
marker, marker:pos())
+ dgn.register_listener(dgn.dgn_event_type("player_los"),
+ marker, marker:pos())
+end
+
+function TollStair:check_shopping_list(marker, first_time)
+ local name = self.props.overmap
+
+ if you.shopping_list_has(name, marker) then
+ return
+ end
+
+ local ask_name = name
+ if first_time then
+ ask_name = "" .. self.props.amount .. " gp " .. ask_name
+ end
+
+ if crawl.yesno("Add " .. ask_name .. " to shopping list? (y/N)",
+ true, "n")
+ then
+ local verb = self.props.shop_verb or "enter"
+
+ you.shopping_list_add(name, verb, self.props.amount, marker)
+
+ crawl.mpr("You can access your shopping list by pressing '$'")
+ end
+end
+
+function TollStair:event(marker, ev)
+ if ev:type() == dgn.dgn_event_type('player_los') then
+ local x, y = ev:pos()
+
+ -- Only prompt to add to shopping list the first time we are seen.
+ if self.seen == 1 then
+ return true
+ end
+
+ self.seen = 1
+
+ if self.props.amount <= you.gold() then
+ return true
+ end
+
+ self:check_shopping_list(marker, true)
+
+ return true
+ end
+
+ return self.super.event(self, marker, ev)
end
function TollStair:check_veto(marker, pname)
@@ -31,6 +80,7 @@ function TollStair:check_veto(marker, pname)
if gold < needed then
crawl.mpr("This portal charges " .. needed .. " gold for entry; " ..
"you have only " .. gold .. " gold.")
+ self:check_shopping_list(marker)
return "veto"
end
@@ -38,9 +88,16 @@ function TollStair:check_veto(marker, pname)
-- Ok, ask if the player wants to spend the $$$.
if not crawl.yesno("This portal charges " .. needed ..
" gold for entry. Pay?", true, "n") then
+ self:check_shopping_list(marker)
return "veto"
end
elseif pname == "veto_level_change" then
+ local name = self.props.overmap
+ if you.shopping_list_has(name, marker) then
+ crawl.mpr("Removing " .. name .. " from shopping list")
+ you.shopping_list_del(name, marker)
+ end
+
-- Gold gold gold! Forget that gold!
you.gold(you.gold() - needed)
@@ -78,8 +135,15 @@ function TollStair:feature_description_long(marker)
return desc .. "The portal charges " .. self.props.amount .. " for entry.\n"
end
+function TollStair:write(marker, th)
+ TollStair.super.write(self, marker, th)
+ file.marshall(th, self.seen)
+end
+
function TollStair:read(marker, th)
TollStair.super.read(self, marker, th)
+ self.seen = file.unmarshall_number(th)
+
setmetatable(self, TollStair)
return self
end
diff --git a/crawl-ref/source/l_you.cc b/crawl-ref/source/l_you.cc
index a316cc768d..836c82b508 100644
--- a/crawl-ref/source/l_you.cc
+++ b/crawl-ref/source/l_you.cc
@@ -11,9 +11,11 @@
#include "food.h"
#include "initfile.h"
#include "los.h"
+#include "mapmark.h"
#include "mon-util.h"
#include "jobs.h"
#include "ouch.h"
+#include "shopping.h"
#include "species.h"
#include "religion.h"
#include "skills2.h"
@@ -310,6 +312,38 @@ LUAFN(you_in_branch)
PLUARET(boolean, in_branch);
}
+LUAFN(_you_shopping_list_has)
+{
+ const char *thing = luaL_checkstring(ls, 1);
+ MAPMARKER(ls, 2, mark);
+
+ level_pos pos(level_id::current(), mark->pos);
+ bool has = shopping_list.is_on_list(thing, &pos);
+ PLUARET(boolean, has);
+}
+
+LUAFN(_you_shopping_list_add)
+{
+ const char *thing = luaL_checkstring(ls, 1);
+ const char *verb = luaL_checkstring(ls, 2);
+ const int cost = luaL_checkint(ls, 3);
+ MAPMARKER(ls, 4, mark);
+
+ level_pos pos(level_id::current(), mark->pos);
+ bool added = shopping_list.add_thing(thing, verb, cost, &pos);
+ PLUARET(boolean, added);
+}
+
+LUAFN(_you_shopping_list_del)
+{
+ const char *thing = luaL_checkstring(ls, 1);
+ MAPMARKER(ls, 2, mark);
+
+ level_pos pos(level_id::current(), mark->pos);
+ bool deleted = shopping_list.del_thing(thing, &pos);
+ PLUARET(boolean, deleted);
+}
+
static const struct luaL_reg you_dlib[] =
{
{ "hear_pos", you_can_hear_pos },
@@ -325,6 +359,9 @@ static const struct luaL_reg you_dlib[] =
{ "uniques", _you_uniques },
{ "die", _you_die },
{ "in_branch", you_in_branch },
+{ "shopping_list_has", _you_shopping_list_has },
+{ "shopping_list_add", _you_shopping_list_add },
+{ "shopping_list_del", _you_shopping_list_del },
{ NULL, NULL }
};
diff --git a/crawl-ref/source/player.cc b/crawl-ref/source/player.cc
index 1e1fa06931..7633583934 100644
--- a/crawl-ref/source/player.cc
+++ b/crawl-ref/source/player.cc
@@ -7624,7 +7624,8 @@ void player::set_gold(int amount)
if (amount != gold)
{
- shopping_list.gold_changed(gold, amount);
+ const int old_gold = gold;
gold = amount;
+ shopping_list.gold_changed(old_gold, gold);
}
}
diff --git a/crawl-ref/source/shopping.cc b/crawl-ref/source/shopping.cc
index 4a799415e3..f8fc73de53 100644
--- a/crawl-ref/source/shopping.cc
+++ b/crawl-ref/source/shopping.cc
@@ -2102,6 +2102,8 @@ static SavefileCallback _register_callback(_callback);
#define SHOPPING_LIST_KEY "shopping_list_key"
#define SHOPPING_THING_COST_KEY "cost_key"
#define SHOPPING_THING_ITEM_KEY "item_key"
+#define SHOPPING_THING_DESC_KEY "desc_key"
+#define SHOPPING_THING_VERB_KEY "verb_key"
#define SHOPPING_THING_POS_KEY "pos_key"
ShoppingList::ShoppingList()
@@ -2159,11 +2161,33 @@ bool ShoppingList::add_thing(const item_def &item, int cost,
bool ShoppingList::add_thing(std::string desc, std::string buy_verb, int cost,
level_pos* _pos)
{
- ASSERT(false); // Not implemented yet
+ ASSERT(!desc.empty());
+ ASSERT(!buy_verb.empty());
+ ASSERT(cost > 0);
SETUP_POS();
- return (false);
+ if (pos.id.level_type != LEVEL_DUNGEON)
+ {
+ mprf("The shopping list can only contain things in the dungeon.",
+ MSGCH_ERROR);
+ return (false);
+ }
+
+ if (find_thing(desc, pos) != -1)
+ {
+ mprf(MSGCH_ERROR, "%s is already on the shopping list.",
+ desc.c_str());
+ return (false);
+ }
+
+ SETUP_THING();
+ (*thing)[SHOPPING_THING_DESC_KEY] = desc;
+ (*thing)[SHOPPING_THING_VERB_KEY] = buy_verb;
+ list->push_back(*thing);
+ refresh();
+
+ return (true);
}
#undef SETUP_THING
@@ -2177,11 +2201,9 @@ bool ShoppingList::is_on_list(const item_def &item, level_pos* _pos) const
bool ShoppingList::is_on_list(std::string desc, level_pos* _pos) const
{
- ASSERT(false); // Not implemented yet
-
SETUP_POS();
- return (false);
+ return (find_thing(desc, pos) != -1);
}
bool ShoppingList::del_thing(const item_def &item, level_pos* _pos)
@@ -2205,11 +2227,21 @@ bool ShoppingList::del_thing(const item_def &item, level_pos* _pos)
bool ShoppingList::del_thing(std::string desc, level_pos* _pos)
{
- ASSERT(false); // Not implemented yet
-
SETUP_POS();
- return (false);
+ int idx = find_thing(desc, pos);
+
+ if (idx == -1)
+ {
+ mprf(MSGCH_ERROR, "%s isn't on shopping list, can't delete it.",
+ desc.c_str());
+ return (false);
+ }
+
+ list->erase(idx);
+ refresh();
+
+ return (true);
}
#undef SETUP_POS
@@ -2395,8 +2427,11 @@ void ShoppingList::gold_changed(int old_amount, int new_amount)
std::string desc;
- if (thing_is_item(thing))
- desc = "buy ";
+ if (thing.exists(SHOPPING_THING_VERB_KEY))
+ desc += thing[SHOPPING_THING_VERB_KEY].get_string();
+ else
+ desc = "buy";
+ desc += " ";
desc += describe_thing(thing, DESC_NOCAP_A);
@@ -2613,12 +2648,16 @@ int ShoppingList::find_thing(const item_def &item,
for (unsigned int i = 0; i < list->size(); i++)
{
const CrawlHashTable &thing = (*list)[i];
- const item_def &_item = get_thing_item(thing);
const level_pos _pos = thing_pos(thing);
if (pos != _pos)
continue;
+ if (!thing_is_item(thing))
+ continue;
+
+ const item_def &_item = get_thing_item(thing);
+
if (item_name_simple(item) == item_name_simple(_item))
return (i);
}
@@ -2629,7 +2668,21 @@ int ShoppingList::find_thing(const item_def &item,
int ShoppingList::find_thing(const std::string &desc,
const level_pos &pos) const
{
- ASSERT(false); // Not implemented yet
+ for (unsigned int i = 0; i < list->size(); i++)
+ {
+ const CrawlHashTable &thing = (*list)[i];
+ const level_pos _pos = thing_pos(thing);
+
+ if (pos != _pos)
+ continue;
+
+ if (thing_is_item(thing))
+ continue;
+
+ if (desc == name_thing(thing))
+ return (i);
+ }
+
return (-1);
}
@@ -2650,8 +2703,10 @@ const item_def& ShoppingList::get_thing_item(const CrawlHashTable& thing)
std::string ShoppingList::get_thing_desc(const CrawlHashTable& thing)
{
- ASSERT(false); // Not implemented yet
- return("");
+ ASSERT(thing.exists(SHOPPING_THING_DESC_KEY));
+
+ std::string desc = thing[SHOPPING_THING_DESC_KEY].get_string();
+ return (desc);
}
long ShoppingList::thing_cost(const CrawlHashTable& thing)
@@ -2672,13 +2727,13 @@ std::string ShoppingList::name_thing(const CrawlHashTable& thing,
if (thing_is_item(thing))
{
const item_def &item = get_thing_item(thing);
-
return item.name(descrip);
}
else
- ASSERT(false);
-
- return ("");
+ {
+ std::string desc = get_thing_desc(thing);
+ return apply_description(descrip, desc);
+ }
}
std::string ShoppingList::describe_thing(const CrawlHashTable& thing,