Skip to content

Commit

Permalink
Refactor AgreesToPay
Browse files Browse the repository at this point in the history
  • Loading branch information
Matroftt authored Oct 1, 2024
1 parent 5b6204f commit f85c17e
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions CorsixTH/Lua/entities/humanoids/patient.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function Patient:Patient(...)
self.action_string = ""
self.cured = false
self.infected = false
self.pay_amount = 0
-- To distinguish between actually being dead and having a nil hospital
self.dead = false
-- Is the patient reserved for a particular nurse when being vaccinated
Expand All @@ -48,7 +49,6 @@ function Patient:Patient(...)
self.vaccination_candidate = false
-- Has the patient passed reception?
self.has_passed_reception = false

-- Is the patient trying to get to the toilet? ("yes", "no", or "no-toilets")
self.going_to_toilet = "no"

Expand All @@ -72,6 +72,10 @@ function Patient:onClick(ui, button)
ui:addWindow(UIPatient(ui, self))
end
end
elseif self.user_of then
-- The object we're using is made invisible, as the animation contains both
-- the humanoid and the object. Hence send the click onto the object.
self.user_of:onClick(ui, button)
elseif TheApp.config.debug_falling and button == "right" then
-- Attempt to push patient over
-- Currently debug-only, enable in config file for testing.
Expand All @@ -80,11 +84,8 @@ function Patient:onClick(ui, button)
and math.random(1, 2) == 2 then
self:falling(true)
end
elseif self.user_of then
-- The object we're using is made invisible, as the animation contains both
-- the humanoid and the object. Hence send the click onto the object.
self.user_of:onClick(ui, button)
end

Humanoid.onClick(self, ui, button)
end

Expand Down Expand Up @@ -274,7 +275,7 @@ end
function Patient:treatDisease()
local hospital = self.hospital

hospital:receiveMoneyForTreatment(self)
hospital:receiveMoneyForTreatment(self, self.pay_amount)

-- Remove visual effects of disease.
self.th:setPatientEffect(AnimationEffect.None)
Expand All @@ -295,12 +296,21 @@ function Patient:treatDisease()
end
end

--! Sets a pernament price of treatment for this patient instance,
--! so changing price in casebook wont affect any longer
function Patient:setTreatmentPrice(disease_id)
local hosp = self.hospital
local casebook = self.hospital.disease_casebook[disease_id]
self.pay_amount = hosp:getTreatmentPrice(disease_id)
end

--! Returns true if patient agrees to pay for the given treatment.
--!param disease_id (string): The id of the disease to test
function Patient:agreesToPay(disease_id)
local casebook = self.hospital.disease_casebook[disease_id]
local price_distortion = self:getPriceDistortion(casebook)
local is_over_priced = price_distortion > self.hospital.over_priced_threshold
self:setTreatmentPrice(disease_id)

return not (is_over_priced and math.random(1, 5) == 1)
end
Expand Down

0 comments on commit f85c17e

Please sign in to comment.