From 44c46c13ff21c16fcd1067b54621192e22cb2a4f Mon Sep 17 00:00:00 2001
From: Nathaniel Rook <nrook@google.com>
Date: Fri, 21 Mar 2014 18:52:41 -0700
Subject: [PATCH 1/8] Poke hole to allow dock_piety() calls from Lua.

Tested: dock_piety() works in dlua repl
---
 crawl-ref/source/l_you.cc | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/crawl-ref/source/l_you.cc b/crawl-ref/source/l_you.cc
index d43e6b5..9dec8d0 100644
--- a/crawl-ref/source/l_you.cc
+++ b/crawl-ref/source/l_you.cc
@@ -689,6 +689,14 @@ static int _you_piety(lua_State *ls)
     PLUARET(number, you.piety);
 }
 
+static int you_dock_piety(lua_State *ls)
+{
+    const int piety_loss = luaL_checkint(ls, 1);
+    const int penance = luaL_checkint(ls, 2);
+    dock_piety(piety_loss, penance);
+    return 0;
+}
+
 LUAFN(you_in_branch)
 {
     const char* name = luaL_checkstring(ls, 1);
@@ -805,6 +813,7 @@ static const struct luaL_reg you_dlib[] =
 { "uniques",            _you_uniques },
 { "die",                _you_die },
 { "piety",              _you_piety },
+{ "dock_piety",         you_dock_piety },
 { "in_branch",          you_in_branch },
 { "shopping_list_has",  _you_shopping_list_has },
 { "shopping_list_add",  _you_shopping_list_add },
-- 
1.9.1


From 7e5fc2533636e4402ddcc255b6e10fc0c033f862 Mon Sep 17 00:00:00 2001
From: Nathaniel Rook <nrook@google.com>
Date: Sat, 22 Mar 2014 11:16:12 -0700
Subject: [PATCH 2/8] Add general "toll" table for troves, to ease adding
 godless troves later

---
 crawl-ref/source/dat/des/portals/trove.des |  10 ++-
 crawl-ref/source/dat/dlua/lm_trove.lua     | 140 ++++++++++++++++++++---------
 2 files changed, 106 insertions(+), 44 deletions(-)

diff --git a/crawl-ref/source/dat/des/portals/trove.des b/crawl-ref/source/dat/des/portals/trove.des
index 57aa134..50936a2 100644
--- a/crawl-ref/source/dat/des/portals/trove.des
+++ b/crawl-ref/source/dat/des/portals/trove.des
@@ -153,12 +153,18 @@ function trove.get_trove_item(e, value, base_item)
   return item
 end
 
+function trove.get_trove_toll(e)
+    return {
+        item = trove.get_trove_item(e, 1000)
+    }
+end
+
 function trove.portal(e)
-    local item = trove.get_trove_item(e, 1000)
+    local toll = trove.get_trove_toll(e, 1000)
 
     local function stair ()
         return trove_marker  {
-            toll_item = item,
+            toll = toll,
             entity = "portal",
             toll_desc = "to enter a treasure trove",
             floor = "expired_portal",
diff --git a/crawl-ref/source/dat/dlua/lm_trove.lua b/crawl-ref/source/dat/dlua/lm_trove.lua
index 719c0a2..9f02879 100644
--- a/crawl-ref/source/dat/dlua/lm_trove.lua
+++ b/crawl-ref/source/dat/dlua/lm_trove.lua
@@ -27,11 +27,26 @@ function TroveMarker:new(props)
     error("Bad feature name: " .. feat)
   end
 
-  if not props.toll_item or props.toll_item == nil then
-    error("Need a toll item.")
+  if not props.toll or props.toll == nil then
+    error("Need a toll.")
+  end
+
+  if props.toll.item == nil then
+    error("Toll doesn't have any contents!")
+  end
+
+  init_item(props.toll.item)
+
+  tmarker.toll = props.toll
+
+  return tmarker
+end
+
+function init_item(item)
+  if item == nil then
+    return
   end
 
-  item = props.toll_item
   if item.quantity == nil then
     error("Item needs a quantity.")
   end
@@ -63,21 +78,32 @@ end
 
 function TroveMarker:fdesc_long (marker)
   local state
-  if self.props.toll_item.base_type == "miscellaneous" then
-    state = "\nThis portal requires the presence of " ..
-            self:item_name() .. " to function.\n"
+  local toll = get_toll(self.props)
+
+  if toll.item then
+    if toll.item.base_type == "miscellaneous" then
+      state = "\nThis portal requires the presence of " ..
+              self:item_name() .. " to function.\n"
+    else
+      state = "\nThis portal needs " ..
+              self:item_name() .. " to function.\n"
+    end
   else
-    state = "\nThis portal needs " ..
-            self:item_name() .. " to function.\n"
+    error("\nThis portal is very buggy.")
   end
   return state
 end
 
 function TroveMarker:overview_note (marker)
-  if self.props.toll_item.base_type == "miscellaneous" then
-    return "show " .. self:item_name(false)
+  local toll = get_toll(self.props)
+  if toll.item then
+    if toll.item.base_type == "miscellaneous" then
+      return "show " .. self:item_name(false)
+    else
+      return "give " .. self:item_name(false)
+    end
   else
-    return "give " .. self:item_name(false)
+    return "be buggy"
   end
 end
 
@@ -86,7 +112,7 @@ function TroveMarker:debug_portal (marker)
   if #dgn.items_at(_x, _y) ~= 0 then
     new_item = dgn.items_at(_x, _y)[1]
     if crawl.yesno("Switch Trove to " .. new_item.name() .. " instead?", true, "n") then
-      self.props.toll_item = trove.get_trove_item(nil, 0, new_item)
+      get_toll(self).item = trove.get_trove_item(nil, 0, new_item)
       crawl.mpr("Switched to a new item.")
     else
       crawl.mpr("Ignoring " .. new_item.name())
@@ -103,7 +129,7 @@ function TroveMarker:debug_portal (marker)
     self:search_for_item(marker, nil, dgn.items_at(_x, _y), true)
   end
 
-  local item = self.props.toll_item
+  local item = get_toll(self).item
   if item == nil then
     return "Failed to get item???"
   end
@@ -173,14 +199,26 @@ function TroveMarker:property(marker, pname)
 end
 
 function TroveMarker:describe(marker)
-  return "The portal requires " .. self.item:name() .. " for entry.\n"
+  local toll = get_toll(self)
+  if toll.item then
+    return "The portal requires " .. self.item_name() .. " for entry.\n"
+  else
+    return "This portal is very buggy."
+  end
 end
 
 function TroveMarker:read(marker, th)
   TroveMarker.super.read(self, marker, th)
   -- self.toll_item never used, but I'm not messing with this marshalling code.
   -- blackcustard May 26 2013.
-  self.toll_item = lmark.unmarshall_table(th)
+  toll = lmark.unmarshall_table(th)
+  if toll.base_type then
+    -- It's a toll_item!
+    -- TODO(nrook): Remove when > major version 34
+    self.toll = {item = toll}
+  else
+    self.toll = toll
+  end
 
   setmetatable(self, TroveMarker)
   return self
@@ -188,15 +226,14 @@ end
 
 function TroveMarker:write(marker, th)
   TroveMarker.super.write(self, marker, th)
-  self.toll_item = self.props.toll_item
-  lmark.marshall_table(th, self.toll_item)
+  lmark.marshall_table(th, self.toll)
 end
 
 -- We need to implement our own version of item_name because
 -- self.props.toll_item is not really an item. It is a table that contains
 -- all the important information about what the toll item should be.
 function TroveMarker:item_name(do_grammar)
-  local item = self.props.toll_item
+  local item = get_toll(self).item
   local s = ""
   if item.quantity > 1 then
     s = s .. item.quantity
@@ -289,16 +326,15 @@ function TroveMarker:item_name(do_grammar)
 end
 
 function TroveMarker:search_for_rune(marker, pname, dry_run)
-  if (self.props.toll_item.base_type ~= "miscellaneous"
-      or self.props.toll_item.sub_type ~= "rune of Zot") then
+  item = get_toll(self).item
+  if (item.base_type ~= "miscellaneous"
+      or item.sub_type ~= "rune of Zot") then
     return false
-  elseif you.have_rune(self.props.toll_item.plus1) then
-    if dry_run ~= nil then crawl.mpr("Accepting " ..
-                                     self.props.toll_item.ego_type .. ".") end
+  elseif you.have_rune(item.plus1) then
+    if dry_run ~= nil then crawl.mpr("Accepting " .. item.ego_type .. ".") end
     return true
   else
-    if dry_run ~= nil then crawl.mpr("No " ..
-                                     self.props.toll_item.ego_type .. ".") end
+    if dry_run ~= nil then crawl.mpr("No " .. item.ego_type .. ".") end
     return false
   end
 end
@@ -314,7 +350,7 @@ function TroveMarker:search_for_item(marker, pname, iter_table, dry_run)
 
   local acceptable_items = {}
 
-  local item = self.props.toll_item
+  local item = get_toll(self).item
 
   for it in iter.invent_iterator:new(iter_table) do
     local iplus1 = it.pluses()
@@ -403,7 +439,7 @@ function TroveMarker:item_with_lowest_pluses(marker, pname, dry_run, items)
   --crawl.mpr("Picking " .. titem.name() .. " to start with.")
   --crawl.mpr("This item p1: " .. titem_p1 .. ")
 
-  item = self.props.toll_item
+  item = get_toll(self).item
 
   for _, it in ipairs(items) do
     local this_p1 = it.pluses()
@@ -426,20 +462,22 @@ function TroveMarker:item_with_lowest_pluses(marker, pname, dry_run, items)
 end
 
 function TroveMarker:plural ()
-  if self.props.toll_item.quantity > 1 then
+  item = get_toll(self.props).item
+  if item.quantity > 1 then
     return "s"
   else
     return ""
   end
 end
 
-function TroveMarker:check_veto(marker, pname)
+function TroveMarker:check_item_veto(marker, pname)
   local quantity = false
   local plus = 0
 
+  local item = get_toll(self.props).item
   -- The message is slightly different for items that aren't actually taken by
   -- the trove (currently the horn of Geryon and the runes).
-  if self.props.toll_item.base_type == "miscellaneous" then
+  if item.base_type == "miscellaneous" then
     if not crawl.yesno("This trove requires the presence of "
                        .. self:item_name() .. " to function. Show it the item"
                        .. self:plural() .. "?", true, "n") then
@@ -455,12 +493,12 @@ function TroveMarker:check_veto(marker, pname)
     end
   end
 
-  if self.props.toll_item.sub_type == "rune of Zot" then
+  if item.sub_type == "rune of Zot" then
     -- Begin by checking for runes.
     if self:search_for_rune() then
       crawl.mpr("The portal draws power from the presence of the item"
                 .. self:plural() .. " and buzzes to life!")
-      self:note_payed("rune", false, self.props.toll_item.ego_type)
+      self:note_payed("rune", false, item.ego_type)
       return
     else
       crawl.mpr("You don't have " .. self:item_name() .. " with you.")
@@ -473,7 +511,7 @@ function TroveMarker:check_veto(marker, pname)
 
   if #acceptable_items == 0 then
     -- Give a different message for the horn of Geryon here, too.
-    if self.props.toll_item.base_type == "miscellaneous" then
+    if item.base_type == "miscellaneous" then
       crawl.mpr("You don't have " .. self:item_name() .. " with you.")
     else
       crawl.mpr("You don't have the item" .. self:plural() ..
@@ -488,14 +526,14 @@ function TroveMarker:check_veto(marker, pname)
   -- acceptable item, take the first in the list.
   local titem = nil
   if #acceptable_items == 1 or
-      (self.props.toll_item.plus1 == false) then
+      (item.plus1 == false) then
     titem = acceptable_items[1]
   else
     titem = self:item_with_lowest_pluses(marker, pname, false, acceptable_items)
   end
 
   -- Open the portal and maybe consume the item.
-  if self.props.toll_item.base_type == "miscellaneous" then
+  if item.base_type == "miscellaneous" then
     crawl.mpr("The portal draws power from the presence of the item" ..
               self:plural() .. " and buzzes to life!")
     self:note_payed(titem, false)
@@ -506,17 +544,34 @@ function TroveMarker:check_veto(marker, pname)
       crawl.mpr("You must unequip the item" .. self:plural() .. " first!")
       return "veto"
     end
-    -- NOTE: Not "self:note_payed(self.props.toll_item, true)". The player
-    -- might have paid a toll with a higher than necessary enchantment, and
-    -- we want to make note of that.
     self:note_payed(titem, true)
     crawl.mpr("The portal accepts the item" .. self:plural() ..
               " and buzzes to life!")
-    titem.dec_quantity(self.props.toll_item.quantity)
+    titem.dec_quantity(item.quantity)
   end
   return
 end
 
+function get_toll(obj)
+  -- TODO(nrook): Replace get_toll(self) with self.toll when major version > 34
+  -- Not sure this is necessary?
+  if obj.toll then
+    return obj.toll
+  else
+    return {item = obj.toll_item}
+  end
+end
+
+function TroveMarker:check_veto(marker, pname)
+  local toll = get_toll(self.props)
+  if toll.item then
+    return self:check_item_veto(marker, pname)
+  else
+    crawl.mpr("This trove is too buggy to enter!")
+    return "veto"
+  end
+end
+
 function TroveMarker:note_payed(toll_item, item_taken, rune_name)
   local toll_desc
   if self.props.toll_desc then
@@ -544,13 +599,14 @@ function TroveMarker:note_payed(toll_item, item_taken, rune_name)
   -- player gave us--is also wrong, because the quantity might be wrong! So we
   -- need to use a little of both.
 
-  local target_plus1 = self.props.toll_item.plus1
+  local requested_item = get_toll(self).item
+  local target_plus1 = requested_item.plus1
   local real_plus1 = toll_item.pluses()
-  self.props.toll_item.plus1 = real_plus1
+  requested_item.plus1 = real_plus1
 
   crawl.take_note(prefix .. self:item_name() .. " " .. toll_desc)
 
-  self.props.toll_item.plus1 = target_plus1
+  requested_item.plus1 = target_plus1
 end
 
 function trove_marker(pars)
-- 
1.9.1


From 8a92e25b493d10d45b91fa4bd3ac2fb452e0e187 Mon Sep 17 00:00:00 2001
From: Nathaniel Rook <nrook@google.com>
Date: Sat, 22 Mar 2014 12:47:14 -0700
Subject: [PATCH 3/8] Add troves that, when entered, steal your piety.

Tested:
  Works as expected on those with lots of piety, those with very low
  piety, those with no god.
---
 crawl-ref/source/dat/des/portals/trove.des |  6 ++++
 crawl-ref/source/dat/dlua/lm_trove.lua     | 45 ++++++++++++++++++++++++++----
 2 files changed, 46 insertions(+), 5 deletions(-)

diff --git a/crawl-ref/source/dat/des/portals/trove.des b/crawl-ref/source/dat/des/portals/trove.des
index 50936a2..cbb34eb 100644
--- a/crawl-ref/source/dat/des/portals/trove.des
+++ b/crawl-ref/source/dat/des/portals/trove.des
@@ -154,9 +154,15 @@ function trove.get_trove_item(e, value, base_item)
 end
 
 function trove.get_trove_toll(e)
+  if crawl.one_chance_in(20) then
+    return {
+        nopiety = true
+    }
+  else
     return {
         item = trove.get_trove_item(e, 1000)
     }
+  end
 end
 
 function trove.portal(e)
diff --git a/crawl-ref/source/dat/dlua/lm_trove.lua b/crawl-ref/source/dat/dlua/lm_trove.lua
index 9f02879..6773f10 100644
--- a/crawl-ref/source/dat/dlua/lm_trove.lua
+++ b/crawl-ref/source/dat/dlua/lm_trove.lua
@@ -31,7 +31,7 @@ function TroveMarker:new(props)
     error("Need a toll.")
   end
 
-  if props.toll.item == nil then
+  if props.toll.item == nil and props.toll.nopiety == nil then
     error("Toll doesn't have any contents!")
   end
 
@@ -82,15 +82,19 @@ function TroveMarker:fdesc_long (marker)
 
   if toll.item then
     if toll.item.base_type == "miscellaneous" then
-      state = "\nThis portal requires the presence of " ..
-              self:item_name() .. " to function.\n"
+      state = "This portal requires the presence of " ..
+              self:item_name() .. " to function."
     else
-      state = "\nThis portal needs " ..
-              self:item_name() .. " to function.\n"
+      state = "This portal needs " ..
+              self:item_name() .. " to function."
     end
+  elseif toll.nopiety then
+    state = "The gods themselves turn their backs on one who enters this " ..
+            "portal."
   else
     error("\nThis portal is very buggy.")
   end
+  state = "\n" .. state .. "\n"
   return state
 end
 
@@ -102,6 +106,8 @@ function TroveMarker:overview_note (marker)
     else
       return "give " .. self:item_name(false)
     end
+  elseif toll.nopiety then
+    return "lose all piety"
   else
     return "be buggy"
   end
@@ -202,6 +208,8 @@ function TroveMarker:describe(marker)
   local toll = get_toll(self)
   if toll.item then
     return "The portal requires " .. self.item_name() .. " for entry.\n"
+  elseif toll.nopiety then
+    return "Entrants to this portal lose all standing with their god.\n"
   else
     return "This portal is very buggy."
   end
@@ -234,6 +242,10 @@ end
 -- all the important information about what the toll item should be.
 function TroveMarker:item_name(do_grammar)
   local item = get_toll(self).item
+  if item == nil then
+    error("item_name called on a toll without an item")
+  end
+
   local s = ""
   if item.quantity > 1 then
     s = s .. item.quantity
@@ -463,6 +475,10 @@ end
 
 function TroveMarker:plural ()
   item = get_toll(self.props).item
+  if get_toll(self).item == nil then
+    error("Called plural() on toll without item")
+  end
+
   if item.quantity > 1 then
     return "s"
   else
@@ -566,12 +582,31 @@ function TroveMarker:check_veto(marker, pname)
   local toll = get_toll(self.props)
   if toll.item then
     return self:check_item_veto(marker, pname)
+  elseif toll.nopiety then
+    local yesno_message = (
+      "This portal professes the superiority of the material over the divine; "
+      .. "those who enter it will find they have lost all favor with their "
+      .. "chosen deity. Enter anyway?")
+    if crawl.yesno(yesno_message, true, "n") then
+      self:accept_nopiety()
+    else
+      return "veto"
+    end
   else
     crawl.mpr("This trove is too buggy to enter!")
     return "veto"
   end
 end
 
+function TroveMarker:accept_nopiety ()
+  if you.god() ~= "No God" then
+    local piety_loss = you.piety() - 15
+    if piety_loss > 0 then
+      you.dock_piety(piety_loss, 0)
+    end
+  end
+end
+
 function TroveMarker:note_payed(toll_item, item_taken, rune_name)
   local toll_desc
   if self.props.toll_desc then
-- 
1.9.1


From cbe44b67ed2c6bfce95aea8c75a8b12db9d158ff Mon Sep 17 00:00:00 2001
From: Nathaniel Rook <nrook@google.com>
Date: Sat, 22 Mar 2014 13:39:07 -0700
Subject: [PATCH 4/8] Modify debug_portal to support godless troves too.

---
 crawl-ref/source/dat/des/portals/trove.des | 17 ++++++++-----
 crawl-ref/source/dat/dlua/lm_trove.lua     | 41 ++++++++++++++++++++++--------
 2 files changed, 42 insertions(+), 16 deletions(-)

diff --git a/crawl-ref/source/dat/des/portals/trove.des b/crawl-ref/source/dat/des/portals/trove.des
index cbb34eb..0623706 100644
--- a/crawl-ref/source/dat/des/portals/trove.des
+++ b/crawl-ref/source/dat/des/portals/trove.des
@@ -155,16 +155,21 @@ end
 
 function trove.get_trove_toll(e)
   if crawl.one_chance_in(20) then
-    return {
-        nopiety = true
-    }
+    return trove.get_toll_nopiety()
   else
-    return {
-        item = trove.get_trove_item(e, 1000)
-    }
+    return trove.get_trove_toll_with_item(
+        trove.get_trove_item(e, 10000))
   end
 end
 
+function trove.get_trove_toll_with_item(item)
+  return { item = item }
+end
+
+function trove.get_toll_nopiety()
+  return { nopiety = true }
+end
+
 function trove.portal(e)
     local toll = trove.get_trove_toll(e, 1000)
 
diff --git a/crawl-ref/source/dat/dlua/lm_trove.lua b/crawl-ref/source/dat/dlua/lm_trove.lua
index 6773f10..ef2c05e 100644
--- a/crawl-ref/source/dat/dlua/lm_trove.lua
+++ b/crawl-ref/source/dat/dlua/lm_trove.lua
@@ -115,14 +115,35 @@ end
 
 function TroveMarker:debug_portal (marker)
   local _x, _y = marker:pos()
-  if #dgn.items_at(_x, _y) ~= 0 then
-    new_item = dgn.items_at(_x, _y)[1]
-    if crawl.yesno("Switch Trove to " .. new_item.name() .. " instead?", true, "n") then
-      get_toll(self).item = trove.get_trove_item(nil, 0, new_item)
-      crawl.mpr("Switched to a new item.")
-    else
-      crawl.mpr("Ignoring " .. new_item.name())
+  local toll = get_toll(self)
+  if crawl.yesno("Try making this Trove use an item (or a different item)?", true, "n") then
+    local _x, _y = marker:pos()
+    if #dgn.items_at(_x, _y) ~= 0 then
+      new_item = dgn.items_at(_x, _y)[1]
+      if crawl.yesno("Switch Trove to " .. new_item.name() .. " instead?",
+                     true, "n") then
+        self.toll = trove.get_trove_toll_with_item(
+            trove.get_trove_item(nil, 0, new_item))
+        init_item(self.toll.item)
+        self.props.toll = self.toll
+        crawl.mpr("Switched to a new item.")
+      else
+        crawl.mpr("Ignoring " .. new_item.name())
+      end
     end
+  elseif crawl.yesno("Make this portal take your piety?", true, "n") then
+    self.toll = trove.get_toll_nopiety()
+    self.props.toll = self.toll
+  else
+    self:debug_diag(marker)
+  end
+end
+
+function TroveMarker:debug_diag (marker)
+  local toll = get_toll(self)
+  if toll.nopiety then
+    crawl.mpr("It's a nopiety trove.")
+    return
   end
 
   if crawl.yesno("Run diagnostic on inventory?", true, "n") then
@@ -135,7 +156,7 @@ function TroveMarker:debug_portal (marker)
     self:search_for_item(marker, nil, dgn.items_at(_x, _y), true)
   end
 
-  local item = get_toll(self).item
+  local item = toll.item
   if item == nil then
     return "Failed to get item???"
   end
@@ -207,7 +228,7 @@ end
 function TroveMarker:describe(marker)
   local toll = get_toll(self)
   if toll.item then
-    return "The portal requires " .. self.item_name() .. " for entry.\n"
+    return "The portal requires " .. self:item_name() .. " for entry.\n"
   elseif toll.nopiety then
     return "Entrants to this portal lose all standing with their god.\n"
   else
@@ -243,7 +264,7 @@ end
 function TroveMarker:item_name(do_grammar)
   local item = get_toll(self).item
   if item == nil then
-    error("item_name called on a toll without an item")
+    error("item_name called on a toll without an item", 2)
   end
 
   local s = ""
-- 
1.9.1


From 793305ae181c7583009d47d8e4a6d16a91856697 Mon Sep 17 00:00:00 2001
From: Nathaniel Rook <nrook@google.com>
Date: Sat, 22 Mar 2014 18:18:12 -0700
Subject: [PATCH 5/8] Clarify lm_trove header to include piety cost.

---
 crawl-ref/source/dat/dlua/lm_trove.lua | 1 +
 1 file changed, 1 insertion(+)

diff --git a/crawl-ref/source/dat/dlua/lm_trove.lua b/crawl-ref/source/dat/dlua/lm_trove.lua
index ef2c05e..3a06835 100644
--- a/crawl-ref/source/dat/dlua/lm_trove.lua
+++ b/crawl-ref/source/dat/dlua/lm_trove.lua
@@ -11,6 +11,7 @@
 --  any potion
 --  any wand
 --  runes and the horn of Geryon
+--  your piety!
 ------------------------------------------------------------------------------
 
 require('dlua/lm_1way.lua')
-- 
1.9.1


From 891fbb25bfc882dbcdb3b394987b6e9395f312a1 Mon Sep 17 00:00:00 2001
From: Nathaniel Rook <nrook@google.com>
Date: Sat, 22 Mar 2014 18:24:31 -0700
Subject: [PATCH 6/8] Slightly modify nopiety trove messages.

---
 crawl-ref/source/dat/dlua/lm_trove.lua | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/crawl-ref/source/dat/dlua/lm_trove.lua b/crawl-ref/source/dat/dlua/lm_trove.lua
index 3a06835..44936cf 100644
--- a/crawl-ref/source/dat/dlua/lm_trove.lua
+++ b/crawl-ref/source/dat/dlua/lm_trove.lua
@@ -90,8 +90,10 @@ function TroveMarker:fdesc_long (marker)
               self:item_name() .. " to function."
     end
   elseif toll.nopiety then
-    state = "The gods themselves turn their backs on one who enters this " ..
-            "portal."
+    state = "The portal is engraved with runes symbolizing the primacy of the "
+            .. "material over the divine. Those who enter it may find riches, "
+            .. "but when they return, they will find that whatever gods they "
+            .. "held dear have forgotten them in their absence."
   else
     error("\nThis portal is very buggy.")
   end
@@ -606,7 +608,7 @@ function TroveMarker:check_veto(marker, pname)
     return self:check_item_veto(marker, pname)
   elseif toll.nopiety then
     local yesno_message = (
-      "This portal professes the superiority of the material over the divine; "
+      "This portal proclaims the superiority of the material over the divine; "
       .. "those who enter it will find they have lost all favor with their "
       .. "chosen deity. Enter anyway?")
     if crawl.yesno(yesno_message, true, "n") then
-- 
1.9.1


From 741dc91447763fa7d67e29f90f725c69428de0a8 Mon Sep 17 00:00:00 2001
From: Nathaniel Rook <nrook@google.com>
Date: Thu, 27 Mar 2014 18:59:26 -0700
Subject: [PATCH 7/8] Remove pointless comment about troves.

---
 crawl-ref/source/dat/dlua/lm_trove.lua | 1 -
 1 file changed, 1 deletion(-)

diff --git a/crawl-ref/source/dat/dlua/lm_trove.lua b/crawl-ref/source/dat/dlua/lm_trove.lua
index 44936cf..d6d6617 100644
--- a/crawl-ref/source/dat/dlua/lm_trove.lua
+++ b/crawl-ref/source/dat/dlua/lm_trove.lua
@@ -594,7 +594,6 @@ end
 
 function get_toll(obj)
   -- TODO(nrook): Replace get_toll(self) with self.toll when major version > 34
-  -- Not sure this is necessary?
   if obj.toll then
     return obj.toll
   else
-- 
1.9.1


From ae380402294dfd46b72401e40dba088a500655d5 Mon Sep 17 00:00:00 2001
From: Nathaniel Rook <nrook@google.com>
Date: Thu, 27 Mar 2014 21:43:27 -0700
Subject: [PATCH 8/8] Veto nopiety troves for demigods.

Also, clarify debug message if attempting to give an item to a debug
trove without any item on it.
---
 crawl-ref/source/dat/des/portals/trove.des | 2 +-
 crawl-ref/source/dat/dlua/lm_trove.lua     | 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/crawl-ref/source/dat/des/portals/trove.des b/crawl-ref/source/dat/des/portals/trove.des
index 0623706..e654d1c 100644
--- a/crawl-ref/source/dat/des/portals/trove.des
+++ b/crawl-ref/source/dat/des/portals/trove.des
@@ -154,7 +154,7 @@ function trove.get_trove_item(e, value, base_item)
 end
 
 function trove.get_trove_toll(e)
-  if crawl.one_chance_in(20) then
+  if crawl.one_chance_in(20) and (not (you.race() == "Demigod")) then
     return trove.get_toll_nopiety()
   else
     return trove.get_trove_toll_with_item(
diff --git a/crawl-ref/source/dat/dlua/lm_trove.lua b/crawl-ref/source/dat/dlua/lm_trove.lua
index d6d6617..16405c7 100644
--- a/crawl-ref/source/dat/dlua/lm_trove.lua
+++ b/crawl-ref/source/dat/dlua/lm_trove.lua
@@ -133,6 +133,9 @@ function TroveMarker:debug_portal (marker)
       else
         crawl.mpr("Ignoring " .. new_item.name())
       end
+    else
+      crawl.mpr("To change the item the trove wants, first drop it "
+                .. "on the trove tile.")
     end
   elseif crawl.yesno("Make this portal take your piety?", true, "n") then
     self.toll = trove.get_toll_nopiety()
-- 
1.9.1

