Skip to content
Permalink
Browse files

[RDY] Research fax options updating (#1484)

* Research fax options updating

* Update to better handle message content

* Updates from feedback

* Trainee doctors notify hospital
  • Loading branch information...
mugmuggy authored and TheCycoONE committed Apr 20, 2019
1 parent beb61e3 commit 635a71b784f4ccc2c9ccddfc50adcc0debf013d1
@@ -202,6 +202,7 @@ add_ignore("CorsixTH/Lua/humanoid_actions/multi_use_object.lua", "212")
add_ignore("CorsixTH/Lua/humanoid_actions/pickup.lua", "212")
add_ignore("CorsixTH/Lua/humanoid_actions/seek_reception.lua", "212")
add_ignore("CorsixTH/Lua/humanoid_actions/seek_reception.lua", "542")
add_ignore("CorsixTH/Lua/humanoid_actions/seek_room.lua", "212")
add_ignore("CorsixTH/Lua/humanoid_actions/staff_reception.lua", "113") -- ReceptionDesk does exist
add_ignore("CorsixTH/Lua/humanoid_actions/use_object.lua", "542")
add_ignore("CorsixTH/Lua/humanoid_actions/vaccinate.lua", "212")
@@ -28,7 +28,7 @@ local runDebugger = corsixth.require("run_debugger")
-- Increment each time a savegame break would occur
-- and add compatibility code in afterLoad functions

local SAVEGAME_VERSION = 133
local SAVEGAME_VERSION = 134

class "App"

@@ -166,6 +166,7 @@ function UIFax:choice(choice_number)
owner:goHome("over_priced", owner.disease.id)
end
elseif choice == "research" then
owner:unregisterCallbacks()
owner:setMood("idea", "activate")
owner:setNextAction(SeekRoomAction("research"))
end
@@ -144,8 +144,10 @@ function UIMessage:removeMessage(choice_number)
self.owner.message = nil
self.owner.message_callback = nil
end
self:onClose(false)
self.onClose = nil
if self.onClose then
self:onClose(false)
self.onClose = nil
end
self:close()
end
end
@@ -300,6 +300,7 @@ function Humanoid:Humanoid(...)

self.build_callbacks = {--[[set]]}
self.remove_callbacks = {--[[set]]}
self.staff_change_callbacks = {--[[set]]}
end

-- Save game compatibility
@@ -337,11 +338,15 @@ function Humanoid:afterLoad(old, new)
if old < 83 and new >= 83 and self.humanoid_class == "Chewbacca Patient" then
self.die_anims.extra_east = 1682
end
if old < 134 and new >= 134 then
self.staff_change_callbacks = {}
end

for _, action in pairs(self.action_queue) do
-- Sometimes actions not actual instances of HumanoidAction
HumanoidAction.afterLoad(action, old, new)
end

Entity.afterLoad(self, old, new)
end

@@ -819,6 +824,12 @@ function Humanoid:notifyNewRoom(room)
end
end

function Humanoid:notifyOfStaffChange(staff)
for callback, _ in pairs(self.staff_change_callbacks) do
callback(staff)
end
end

-- Registers a new remove callback for this humanoid.
--!param callback (function) The callback to call when a room has been removed.
function Humanoid:registerRoomRemoveCallback(callback)
@@ -841,6 +852,29 @@ function Humanoid:unregisterRoomRemoveCallback(callback)
end
end


-- Registers a new staff change callback for this humanoid.
--!param callback (function) The callback to call when a staff member has been hired or fired
function Humanoid:registerStaffChangeCallback(callback)
if self.staff_change_callbacks and not self.staff_change_callbacks[callback] then
self.staff_change_callbacks[callback] = true
else
self.world:gameLog("Warning: Trying to re-add staff callback (" .. tostring(callback) .. ") for humanoid (" .. tostring(self) .. ").")
end
end

-- Unregisters a staff change callback for this humanoid.
--!param callback (function) The callback to remove.
function Humanoid:unregisterStaffChangeCallback(callback)

if self.staff_change_callbacks and self.staff_change_callbacks[callback] then
self.staff_change_callbacks[callback] = nil
else
self.world:gameLog("Warning: Trying to remove nonexistant staff callback (" .. tostring(callback) .. ") from humanoid (" .. tostring(self) .. ").")
end
end


-- Function called when a humanoid is sent away from the hospital to prevent
-- further actions taken as a result of a callback
function Humanoid:unregisterCallbacks()
@@ -852,6 +886,10 @@ function Humanoid:unregisterCallbacks()
for cb, _ in pairs(self.remove_callbacks) do
self:unregisterRoomRemoveCallback(cb)
end
-- Remove callbacks for removed rooms
for cb, _ in pairs(self.staff_change_callbacks) do
self:unregisterStaffChangeCallback(cb)
end
-- Remove any message related to the humanoid.
if self.message_callback then
self:message_callback(true)
@@ -1078,20 +1078,42 @@ end
]]
function Patient:updateMessage(choice)
if self.message and self.message.choices then
local message_choice
local enabled = false
if choice == "research" then

for _, c in ipairs(self.message.choices) do
if c.choice == choice then
message_choice = choice
end
end

if choice == "research" and message_choice == choice then
-- enable only if research department is built and a room in the treatment chain is undiscovered
if self.hospital:hasRoomOfType("research") then
local req = self.hospital:checkDiseaseRequirements(self.disease.id)
if req then
for _, room_id in ipairs(req.rooms) do
local room = self.world.available_rooms[room_id]
if room and self.hospital.undiscovered_rooms[room] then
enabled = true
break
end
local req = self.hospital:checkDiseaseRequirements(self.disease.id)
if req then
local strings = _S.fax.disease_discovered_patient_choice
enabled = self.hospital:hasRoomOfType("research") and self.hospital:hasStaffOfCategory("Researcher")
local output_text = strings.can_not_cure
if #req.rooms == 1 then
local room_name, required_staff, staff_name = self.world:getRoomNameAndRequiredStaffName(req.rooms[1])
if req.staff[required_staff] or 0 > 0 then
output_text = strings.need_to_build_and_employ:format(room_name, staff_name)
else
output_text = strings.need_to_build:format(room_name)
end
elseif #req.rooms == 0 and next(req.staff) then
local staffclass_to_string = {
Nurse = _S.staff_title.nurse,
Doctor = _S.staff_title.doctor,
Surgeon = _S.staff_title.surgeon,
Psychiatrist = _S.staff_title.psychiatrist,
}
output_text = strings.need_to_employ:format(staffclass_to_string[next(req.staff)])
end
self.message[3].text = output_text
else
-- no requirements missing
enabled = false
end
else -- if choice == "guess_cure" then
-- TODO: implement
@@ -1129,7 +1151,6 @@ function Patient:removeVaccinationCandidateStatus()
end
end


function Patient:afterLoad(old, new)
if old < 68 then
if self.going_home then
@@ -159,6 +159,8 @@ function Doctor:updateSkill(consultant, trait, amount) -- luacheck: no unused ar
local is = trait:match"^is_(.*)"
if is == "surgeon" or is == "psychiatrist" or is == "researcher" then
self.world.ui.adviser:say(_A.information.promotion_to_specialist:format(_S.staff_title[is]))
-- patients might we waiting for a doctor with this skill, notify them
self.hospital:notifyOfStaffChange(self)
end
self:updateStaffTitle()
end
@@ -1695,6 +1695,7 @@ function Hospital:addStaff(staff)
self.staff[#self.staff + 1] = staff
-- Cost of hiring staff:
self:spendMoney(staff.profile.wage, _S.transactions.hire_staff .. ": " .. staff.profile.name)
self:notifyOfStaffChange(staff)
end

function Hospital:addPatient(patient)
@@ -1770,6 +1771,8 @@ end
--!param staff (Staff) Staff member to remove.
function Hospital:removeStaff(staff)
RemoveByValue(self.staff, staff)
-- update all messages for waiting patients
self:notifyOfStaffChange(staff)
end

--! Remove a patient from the hospital.
@@ -2366,3 +2369,11 @@ function Hospital:computePriceLevelImpact(patient, casebook)
self.world.ui.adviser:say(_A.warnings.fair_prices:format(casebook.disease.name))
end
end

--! Notify patients of a change to hospital staff members
--!param staff (Staff) Changed staff member subject of notification
function Hospital:notifyOfStaffChange(staff)
for _, patient in pairs(self.patients) do
patient:notifyOfStaffChange(staff)
end
end
Oops, something went wrong.

0 comments on commit 635a71b

Please sign in to comment.
You can’t perform that action at this time.