diff --git a/CorsixTH/Lua/dialogs/furnish_corridor.lua b/CorsixTH/Lua/dialogs/furnish_corridor.lua index 142945a94..5b28d1467 100644 --- a/CorsixTH/Lua/dialogs/furnish_corridor.lua +++ b/CorsixTH/Lua/dialogs/furnish_corridor.lua @@ -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 @@ -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") @@ -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 @@ -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) @@ -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 @@ -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 diff --git a/CorsixTH/Lua/languages/brazilian_portuguese.lua b/CorsixTH/Lua/languages/brazilian_portuguese.lua index d36e8cde7..8c4fda109 100644 --- a/CorsixTH/Lua/languages/brazilian_portuguese.lua +++ b/CorsixTH/Lua/languages/brazilian_portuguese.lua @@ -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 @@ -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%!", diff --git a/CorsixTH/Lua/languages/english.lua b/CorsixTH/Lua/languages/english.lua index 9cdc87d2a..754483577 100644 --- a/CorsixTH/Lua/languages/english.lua +++ b/CorsixTH/Lua/languages/english.lua @@ -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%!",