Skip to content

Commit

Permalink
Merge pull request CorsixTH#2755 from FMMazur/fix-buy-object-limit
Browse files Browse the repository at this point in the history
Fix advice when exceeding maximum buy object limit
  • Loading branch information
lewri authored Jan 14, 2025
2 parents 5c5aa19 + 0f74089 commit b1457b1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
36 changes: 28 additions & 8 deletions CorsixTH/Lua/dialogs/furnish_corridor.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
--[[ Copyright (c) 2009 Peter "Corsix" Cawley
Copyright (c) 2024 Felipe "FMMazur" Mazur
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down Expand Up @@ -92,9 +93,14 @@ function UIFurnishCorridor:UIFurnishCorridor(ui, objects, edit_dialog)
local function item_callback(index, qty)
local is_negative_quantity = qty < 0
return --[[persistable:furnish_corridor_item_callback]] function(window)
if window:purchaseItem(index, qty) == 0 and not is_negative_quantity then
-- give visual warning that player doesn't have enough $ to buy
window.ui.adviser:say(_A.warnings.cannot_afford_2, false, true)
-- lewri: a persistence bug from the 'decrease' button converts integer to a
-- float, for now, sanitise it back to an integer
qty = math.floor(qty)
local quantity, error = window:purchaseItem(index, qty)

if quantity == nil and not is_negative_quantity then
-- give visual warning that player doesn't have enough $ to buy or can't buy more
window.ui.adviser:say(error, false, true)
window.ui:playSound("wrong2.wav")
elseif qty > 0 then
window.ui:playSound("AddItemJ.wav")
Expand Down Expand Up @@ -128,6 +134,11 @@ end
function UIFurnishCorridor:purchaseItem(index, quantity)
local o = self.objects[index]
local is_negative_quantity = quantity < 0

if (quantity > 0 and o.qty >= 99) then
return nil, _A.warnings.cannot_buy:format(o.object.name)
end

if self.ui.app.key_modifiers.ctrl then
quantity = quantity * 10
elseif self.ui.app.key_modifiers.shift then
Expand All @@ -139,11 +150,14 @@ function UIFurnishCorridor:purchaseItem(index, quantity)
elseif quantity > 99 then
quantity = 99
end
quantity = quantity - o.qty

local bought = quantity - o.qty
local hospital = self.ui.hospital
if hospital.balance >= self.total_price + quantity * hospital:getObjectBuildCost(o.object.id) or is_negative_quantity then
o.qty = o.qty + quantity
self.total_price = self.total_price + quantity * hospital:getObjectBuildCost(o.object.id)
local total_price = self.total_price + bought * hospital:getObjectBuildCost(o.object.id)

if hospital.balance >= total_price or is_negative_quantity then
o.qty = o.qty + bought
self.total_price = total_price
if o.object.id == "reception_desk" then
if o.qty > 0 then
self.ui:tutorialStep(1, 2, 3)
Expand All @@ -152,7 +166,7 @@ function UIFurnishCorridor:purchaseItem(index, quantity)
end
end
else
quantity = 0
return nil, _A.warnings.cannot_afford_2
end
return quantity
end
Expand Down Expand Up @@ -238,6 +252,12 @@ function UIFurnishCorridor:onMouseMove(x, y, dx, dy)
end

function UIFurnishCorridor:afterLoad(old, new)
-- If we saved with the window open, quantities might get converted to floats
-- This may be overkill
for _, obj in pairs(self.objects) do
obj.qty = math.floor(obj.qty)
end

Window.afterLoad(self, old, new)
self:registerKeyHandlers()
end
2 changes: 2 additions & 0 deletions CorsixTH/Lua/languages/brazilian_portuguese.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Copyright (c) 2012 Henrique Poyatos
Copyright (c) 2014 Leonardo Malaman (LeonardoGamer)
Copyright (c) 2017-2024 Altieres Lima da Silva
Copyright (c) 2020 Henrique Poyatos
Copyright (c) 2024 Felipe "FMMazur" Mazur
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down Expand Up @@ -242,6 +243,7 @@ adviser = {
no_desk_6 = "Você tem uma recepcionista, que tal se construir uma mesa de recepçäo para que possa trabalhar?",
no_desk_7 = "Você construiu a mesa da recepçäo, entäo que tal contratar um recepcionista? Você näo receberá nenhum paciente até que contrate uma.",
another_desk = "Você precisará construir outra mesa para essa nova recepcionista.",
cannot_buy = "Você näo pode comprar mais desse item!",
cannot_afford = "Você näo tem dinheiro suficiente no banco para contratar essa pessoa!", -- I can't see anything like this in the original strings
cannot_afford_2 = "Você näo tem dinheiro suficiente no banco para fazer essa compra!",
cannot_afford_machine = "Você precisa de pelo menos $%1% no banco para comprar um novo %2%!",
Expand Down
1 change: 1 addition & 0 deletions CorsixTH/Lua/languages/english.lua
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ adviser = {
no_desk_6 = "You have a receptionist, so how about building a reception desk for her to work from?",
no_desk_7 = "You've built the reception desk, so how about hiring a receptionist? You won't see any patients until you get this sorted out you know!",
another_desk = "You'll need to build another desk for that new receptionist.",
cannot_buy = "You can't buy more of that item!",
cannot_afford = "You don't have enough money in the bank to hire that person!", -- I can't see anything like this in the original strings
cannot_afford_2 = "You don't have enough money in the bank to make that purchase!",
cannot_afford_machine = "You need at least $%1% in the bank to afford a new %2%!",
Expand Down

0 comments on commit b1457b1

Please sign in to comment.