Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions data/resources.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ return {
wood = {
name = "Wood",
weight = 2, -- carry-weight units per item
goldValue = 1,
color = {0.55, 0.35, 0.15}, -- placeholder render colour
harvestTime = 3.0, -- seconds to harvest one batch
yieldMin = 2, -- min items per harvest
Expand All @@ -16,6 +17,7 @@ return {
iron = {
name = "Iron",
weight = 5,
goldValue = 4,
color = {0.60, 0.60, 0.65},
harvestTime = 5.0,
yieldMin = 1,
Expand All @@ -27,6 +29,7 @@ return {
stone = {
name = "Stone",
weight = 4,
goldValue = 1,
color = {0.50, 0.50, 0.50},
harvestTime = 4.0,
yieldMin = 2,
Expand All @@ -38,6 +41,7 @@ return {
rope = {
name = "Rope",
weight = 1,
goldValue = 2,
color = {0.75, 0.70, 0.40},
harvestTime = 2.0,
yieldMin = 1,
Expand All @@ -49,6 +53,7 @@ return {
food = {
name = "Food",
weight = 1,
goldValue = 1,
color = {0.90, 0.30, 0.30},
harvestTime = 1.5,
yieldMin = 1,
Expand All @@ -60,11 +65,24 @@ return {
cloth = {
name = "Cloth",
weight = 1,
goldValue = 3,
color = {0.85, 0.85, 0.90},
harvestTime = 2.5,
yieldMin = 1,
yieldMax = 2,
sourceTiles = {"grass"},
biomes = {"plains"},
},

gold = {
name = "Gold",
weight = 0,
goldValue = 0,
color = {0.98, 0.82, 0.20},
harvestTime = 0,
yieldMin = 0,
yieldMax = 0,
sourceTiles = {},
biomes = {},
},
}
10 changes: 10 additions & 0 deletions src/inventory/inventory.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ function Inventory:add(resourceType, amount)
return actual
end

-- Add `amount` units even if it exceeds the normal carry capacity.
-- Used for special cases like casino payouts that should remain re-bettable.
function Inventory:forceAdd(resourceType, amount)
if amount <= 0 then return 0 end

self._items[resourceType] = (self._items[resourceType] or 0) + amount
self._weight = self._weight + amount * unitWeight(resourceType)
return amount
end

-- Remove `amount` units. Returns actual amount removed.
function Inventory:remove(resourceType, amount)
local have = self._items[resourceType] or 0
Expand Down
17 changes: 12 additions & 5 deletions src/inventory/supplydepot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,21 @@ end

-- Deposit all items from `inventory` into the depot.
function SupplyDepot:depositAll(inventory)
local items = inventory:clear()
local items = inventory:getItems()
local deposited = {}
for rtype, amt in pairs(items) do
self:add(rtype, amt)
if self.eventBus then
self.eventBus:publish("resource_deposited", rtype, amt)
if rtype ~= "gold" and amt > 0 then
local removed = inventory:remove(rtype, amt)
if removed > 0 then
self:add(rtype, removed)
deposited[rtype] = removed
if self.eventBus then
self.eventBus:publish("resource_deposited", rtype, removed)
end
end
end
end
return items
return deposited
end

-- Withdraw `amount` of `resourceType` into `inventory`. Returns actual withdrawn.
Expand Down
Loading
Loading