Debian Codegraph @

CorsixTH/Lua/entities/humanoids/patient.lua

raw
1 --[[ Copyright (c) 2009 Peter "Corsix" Cawley
2
3 Permission is hereby granted, free of charge, to any person obtaining a copy of
4 this software and associated documentation files (the "Software"), to deal in
5 the Software without restriction, including without limitation the rights to
6 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7 of the Software, and to permit persons to whom the Software is furnished to do
8 so, subject to the following conditions:
9
10 The above copyright notice and this permission notice shall be included in all
11 copies or substantial portions of the Software.
12
13 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 SOFTWARE. --]]
20
21 --! A `Humanoid` who is in the hospital for diagnosis and/or treatment.
22 class "Patient" (Humanoid)
23
24 ---@type Patient
25 local Patient = _G["Patient"]
26
27 function Patient:Patient(...)
28 self:Humanoid(...)
29 self.hover_cursor = TheApp.gfx:loadMainCursor("patient")
30 self.should_knock_on_doors = true
31 self.treatment_history = {}
32 self.going_home = false -- If set, the patient is going home.
33 self.litter_countdown = nil -- If set, number of tiles to walk before attempting to drop litter.
34 self.has_fallen = 1
35 self.has_vomitted = 0
36 self.action_string = ""
37 self.cured = false
38 self.infected = false
39 self.pay_amount = 0
40 -- To distinguish between actually being dead and having a nil hospital
41 self.dead = false
42 -- Indicates that the patient is being marked for death. The patient may be busy,
43 -- But as soon as the patient is unoccupied he will start the dying scenario based
44 -- on this flag, except the cases when he is cured or sent home while being busy.
45 self.set_to_die = false
46 -- Indicates that the patient on the dying scenario
47 -- Cure should not happen at this state. Patient can't be sent home
48 self.going_to_die = false
49 -- Is the patient reserved for a particular nurse when being vaccinated
50 self.reserved_for = false
51 self.vaccinated = false
52 -- Has the patient been sent to the wrong room and needs redirecting
53 self.needs_redirecting = false
54 -- Indicates is currently some infected patient trying to infect this patient
55 -- Prevents the situation when several infectors trying to infect the same victim
56 self.under_infection_attempt = false
57 -- Is the patient about to be vaccinated?
58 self.vaccination_candidate = false
59 -- Has the patient passed reception?
60 self.has_passed_reception = false
61 -- Diagnostics progress to diagnose the patient.
62 -- Usually this value is in the range from 0 to ~2.5
63 self.diagnosis_progress = 0
64
65 -- Is the patient trying to get to the toilet? ("yes", "no", or "no-toilets")
66 self.going_to_toilet = "no"
67
68 -- Health history in entries 1..SIZE (may not all exist at first). The "last"
69 -- entry indicates last written entry, "(last+1) % SIZE" is the oldest entry.
70 -- The "size" entry holds the length of the array (that is, SIZE).
71 -- Variable gets automatically initialized on first day.
72 self.health_history = nil
73 end
74
75 function Patient:onClick(ui, button)
76 if button == "left" then
77 if self.message_callback then
78 self:message_callback()
79 else
80
81 local function isValidEpidemicTarget(epidemic)
82 return epidemic and epidemic.coverup_selected and
83 (epidemic.vaccination_mode_active or
84 (self.infected and (not self.marked_for_vaccination)))
85 end
86
87 local hospital = self.hospital or self.world:getLocalPlayerHospital()
88 local epidemic = hospital and hospital.epidemic
89 if isValidEpidemicTarget(epidemic) then
90 if not epidemic.timer.closed then
91 epidemic:markForVaccination(self)
92 end
93 else
94 ui:addWindow(UIPatient(ui, self))
95 end
96 end
97 elseif self.user_of then
98 -- The object we're using is made invisible, as the animation contains both
99 -- the humanoid and the object. Hence send the click onto the object.
100 self.user_of:onClick(ui, button)
101 elseif button == "right" then
102 -- Attempt to push patient over
103 if not self.world:isPaused() and not (self.cured or self.going_to_die or self.dead or self.going_home)
104 and math.random(1, 2) == 2 then
105 self:falling(true)
106 end
107 end
108 Humanoid.onClick(self, ui, button)
109 end
110
111 function Patient:setDisease(disease)
112 self.disease = disease
113 disease.initPatient(self)
114 self.th:setPatientEffect(disease.effect or AnimationEffect.None)
115 self.diagnosed = false
116 self.diagnosis_progress = 0
117 self.cure_rooms_visited = 0
118 -- Copy list of diagnosis rooms
119 -- (patient may visit these for diagnosis, if they exist in the hospital).
120 self.available_diagnosis_rooms = {}
121 for i, room in ipairs(self.disease.diagnosis_rooms) do
122 self.available_diagnosis_rooms[i] = room
123 end
124 -- 25% of the patients pay via insurance
125 if math.random(1,4) == 1 then
126 -- randomly select one of three insurance companies
127 self.insurance_company = math.random(1,3)
128 end
129 -- Randomise thirst and the need to visit the loo soon.
130 -- Alien patients do not have the needed animations for these things, so exclude them
131 if not self.disease.only_emergency then
132 self.attributes["thirst"] = math.random()*0.2
133 self.attributes["toilet_need"] = math.random()*0.2
134 end
135 self:updateDynamicInfo()
136 end
137
138 function Patient:changeDisease(new_disease)
139 assert(not self.diagnosed, "Cannot change the disease of a diagnosed patient")
140 -- These assertions should hold until handling of visual diseases is implemented.
141 assert(self.disease.contagious, "Cannot change the disease of a patient who has a non-contagious disease")
142 assert(new_disease.contagious, "Cannot change a disease to a non-contagious disease")
143
144 local visited_rooms = {}
145
146 -- Add all diagnosis room for the old disease.
147 for _, room in ipairs(self.disease.diagnosis_rooms) do
148 visited_rooms[room] = true
149 end
150
151 -- Disable the rooms not yet visited by the patient.
152 for _, room in ipairs(self.available_diagnosis_rooms) do
153 visited_rooms[room] = false
154 end
155
156 -- 'visited_rooms' is now diagnosis rooms that the patient has visited for the old disease.
157
158 -- Compute unvisited rooms for the new disease.
159 self.available_diagnosis_rooms = {}
160 for _, room in ipairs(new_disease.diagnosis_rooms) do
161 if not visited_rooms[room] then
162 self.available_diagnosis_rooms[#self.available_diagnosis_rooms + 1] = room
163 end
164 end
165
166 self.disease = new_disease -- Finally, make the patient carry the new disease.
167 end
168
169 --! Mark patient as being diagnosed.
170 function Patient:setDiagnosed()
171 self.diagnosed = true
172 self.treatment_history[#self.treatment_history + 1] = self.disease.name
173
174 local window = self.world.ui:getWindow(UIPatient)
175 if window and window.patient == self then
176 window:updateInformation()
177 end
178
179 self:updateDynamicInfo()
180 end
181
182 --! Modifies the diagnosis progress of a patient.
183 -- incrementValue can be either positive or negative.
184 function Patient:modifyDiagnosisProgress(incrementValue)
185 self.diagnosis_progress = math.min(self.hospital.policies["stop_procedure"],
186 self.diagnosis_progress + incrementValue)
187 self.diagnosis_progress = math.max(0.000, self.diagnosis_progress)
188 local window = self.world.ui:getWindow(UIPatient)
189 if window and window.patient == self then
190 window:updateInformation()
191 end
192 self:updateDynamicInfo()
193 end
194
195 --! Updates the patients diagnostic progress based on the doctors skill
196 -- called when they are done using a diagnosis room
197 function Patient:completeDiagnosticStep(room)
198 -- Base: depending on difficulty of disease as set in sam file
199 -- tiredness reduces the chance of diagnosis if staff member is above 50% tired
200 local multiplier = 1
201
202 local expertise = self.world.map.level_config.expertise
203 local diagnosis_difficulty = expertise[self.disease.expertise_id].MaxDiagDiff / 1000
204 local diagnosis_base = 0.4 * (1 - diagnosis_difficulty)
205 local diagnosis_bonus = 0.4
206
207 -- Did the staff member manage to leave the room before the patient had
208 -- a chance to get diagnosed? Then use a default middle value.
209 if room.staff_member then
210 local fatigue = room.staff_member:getAttribute("fatigue")
211
212 -- Bonus: based on skill and attn to detail (with some randomness).
213 -- additional bonus if the staff member is highly skilled / consultant
214 -- tiredness reduces the chance of diagnosis if staff member is above 50% tired
215 if room.staff_member.profile.skill >= 0.9 then
216 multiplier = math.random(1, 5) * (1 - (fatigue -0.5))
217 else
218 multiplier = 1 * (1 - (fatigue -0.5))
219 end
220 local divisor = math.random(1, 3)
221 local attn_detail = room.staff_member.profile.attention_to_detail / divisor
222 local skill = room.staff_member.profile.skill / divisor
223 diagnosis_bonus = (attn_detail + 0.4) * skill
224 end
225 self:modifyDiagnosisProgress(diagnosis_base + (diagnosis_bonus * multiplier))
226 end
227
228 --! Sets the hospital for the patient - additionally removing them from a
229 -- hospital if they already belong to one. For player hospitals, patients who
230 -- are not debug or emergency patients are made to seek a reception desk.
231 --!param hospital (Hospital): hospital to assign to patient
232 function Patient:setHospital(hospital)
233 if self.hospital then
234 self.hospital:removePatient(self)
235 end
236 Humanoid.setHospital(self, hospital)
237 if hospital.is_in_world and not self.is_debug and not self.is_emergency then
238 self:setNextAction(SeekReceptionAction())
239 end
240 hospital:addPatient(self)
241 end
242
243 --! Decide the ID of the disease or treatment that the patient is paying for.
244 --!return (string or nil) Id of the disease or treatment, or nil if the Id could
245 --! not be decided.
246 function Patient:getTreatmentDiseaseId()
247 if self.diagnosed then
248 return self.disease.id
249 else
250 local room_info = self:getRoom()
251 if not room_info then
252 print("Warning: Trying to receive money for treated patient who is "..
253 "not in a room")
254 return nil
255 end
256 room_info = room_info.room_info
257 return "diag_" .. room_info.id
258 end
259 end
260
261 --! Estimate the subjective perceived distortion between the price level the
262 --! patient might expect considering the reputation and the cure effectiveness
263 --! of a given treatment and the staff internal state.
264 --!param casebook (table): casebook entry for the treatment.
265 --!return (float) [-1, 1]. The smaller the value is, the more the patient
266 --! considers the bill to be under-priced. The bigger the value is, the more
267 --! the patient patient considers the bill to be over-priced.
268 function Patient:getPriceDistortion(casebook)
269 -- weights
270 local happiness_weight = 0.1
271 local reputation_weight = 0.6
272 local effectiveness_weight = 0.3
273
274 -- map the different variables to [0-1] and merge them
275 local reputation = casebook.reputation or self.hospital.reputation
276 local effectiveness = casebook.cure_effectiveness
277
278 local weighted_happiness = happiness_weight * self:getAttribute("happiness")
279 local weighted_reputation = reputation_weight * (reputation / 1000)
280 local weighted_effectiveness = effectiveness_weight * (effectiveness / 100)
281
282 local expected_price_level = weighted_happiness + weighted_reputation + weighted_effectiveness
283
284 -- map to [0-1]
285 local price_level = ((casebook.price - 0.5) / 3) * 2
286
287 return price_level - expected_price_level
288 end
289
290 --! Handle attempting to treat this patient
291 --!
292 --! If the treatment is effective the patient will be sent home, otherwise they
293 --! will die. The patient may or may not agree to pay for the treatment
294 --! depending on whether they consider the price reasonable.
295 function Patient:treatDisease()
296 local hospital = self.hospital
297
298 hospital:receiveMoneyForTreatment(self)
299
300 -- Remove visual effects of disease.
301 self.th:setPatientEffect(AnimationEffect.None)
302
303 -- Either the patient is no longer sick, or he/she dies.
304 if self:isTreatmentEffective() then
305 self:cure()
306 self.treatment_history[#self.treatment_history + 1] = _S.dynamic_info.patient.actions.cured
307 self:goHome("cured")
308 else
309 self:die()
310 end
311
312 hospital:updatePercentages()
313 hospital:paySupplierForDrug(self.disease.id)
314 if self.is_emergency then
315 hospital:checkEmergencyOver()
316 end
317 end
318
319 --! Returns true if patient agrees to pay for the given treatment.
320 --!param disease_id (string): The id of the disease to test
321 function Patient:agreesToPay(disease_id)
322 local hosp = self.hospital
323 local casebook = hosp.disease_casebook[disease_id]
324 local agrees_to_pay = true
325 local price_multiplier = casebook.price
326 local is_over_priced = price_multiplier > 1.0
327 if is_over_priced then
328 local overprice_size = price_multiplier - 1.0
329 -- payment chance modificator was chosen experimentally to match the chance in the original game.
330 local payment_chance_modificator = 4
331 local payment_chance = math.exp(-1 * payment_chance_modificator * overprice_size)
332 agrees_to_pay = math.random() <= payment_chance
333 end
334 if agrees_to_pay then
335 -- save the price the patient agrees to
336 self.pay_amount = hosp:getTreatmentPrice(disease_id)
337 end
338 return agrees_to_pay
339 end
340
341 --! Either the patient is cured, or he/she dies.
342 --!return (boolean) True if cured, false if died.
343 function Patient:isTreatmentEffective()
344 local cure_chance = self.hospital.disease_casebook[self.disease.id].cure_effectiveness
345 cure_chance = cure_chance * self.diagnosis_progress
346
347 -- Service quality has a factor on cure chance
348 local room = self:getRoom()
349 local min_impact = 20
350 local service_base = math.max(100 - cure_chance, min_impact)
351
352 local scale = 0.2 -- Quality scaled to +-10%
353 local service_factor = (room:getStaffServiceQuality() - 0.5) * scale
354 cure_chance = cure_chance + (service_base * service_factor)
355
356 return (cure_chance >= math.random(1,100))
357 end
358
359 function Patient:hasMoreDiagnosisRoomsAvailable()
360 return #self.available_diagnosis_rooms ~= 0
361 end
362
363 --! Change patient internal state to "cured".
364 function Patient:cure()
365 self.cured = true
366 self.infected = false
367 self.attributes["health"] = 1
368 end
369
370 --! Patient died, process the event.
371 function Patient:die()
372 self.set_to_die = false
373 if self.cured then return end
374
375 -- It may happen that this patient was just cured and then the room blew up.
376 self.hospital:humanoidDeath(self)
377
378 self:setMood("dying5", "deactivate")
379 self:setMood("dead", "activate")
380
381 -- Remove any messages and/or callbacks related to the patient.
382 self:unregisterCallbacks()
383
384 self.going_to_die = true
385 if self:getRoom() then
386 self:queueAction(MeanderAction():setCount(1))
387 else
388 self:setNextAction(MeanderAction():setCount(1))
389 end
390 self:queueAction(DieAction())
391 self:setDynamicInfoText(_S.dynamic_info.patient.actions.dying)
392 end
393
394 -- Actions we can interrupt when at a fully empty tile.
395 local good_actions = {walk=true, idle=true, seek_room=true, queue=true}
396
397 --! Test whether the current tile of the patient is useful for inserting an
398 -- action that needs a fully empty tile in the hospital.
399 --!param cur_action Current action of the patient.
400 --!return Whether the tile can be used for inserting an action.
401 function Patient:atFullyEmptyTile(cur_action)
402 if not good_actions[cur_action.name] then return false end
403 if self.going_home or self.going_to_die then return false end
404
405 local th = self.world.map.th
406 local cell_flags = th:getCellFlags(self.tile_x, self.tile_y)
407 if not cell_flags.buildable or not cell_flags.hospital then return false end
408
409 local parcel = cell_flags.parcelId
410 return parcel ~= 0 and th:getPlotOwner(parcel) == self.hospital:getPlayerIndex()
411 end
412
413 --! Falling animations for when there is an earth quake or the player is being very mean
414 --!param player_init (bool) if true, player triggered the fall
415 function Patient:falling(player_init)
416 local current = self:getCurrentAction()
417 current.keep_reserved = true
418 if self.falling_anim and self:atFullyEmptyTile(current) and self.has_fallen == 1 then
419 self.has_fallen = 2
420 self:queueAction(FallingAction(), 1)
421 self:queueAction(OnGroundAction(), 2)
422 self:queueAction(GetUpAction(), 3)
423 -- show the patient is annoyed, if possible
424 if math.random(1, 5) == 3 and self.shake_fist_anim then
425 self:queueAction(ShakeFistAction(), 4)
426 self:interruptAndRequeueAction(current, 5)
427 else
428 self:interruptAndRequeueAction(current, 4)
429 end
430 if player_init then self:fallingAnnounce() end
431 self:changeAttribute("happiness", -0.05) -- falling makes you very unhappy
432 end
433 end
434
435 function Patient:fallingAnnounce()
436 local msg = {
437 (_A.warnings.falling_1),
438 (_A.warnings.falling_2),
439 (_A.warnings.falling_3),
440 (_A.warnings.falling_4),
441 (_A.warnings.falling_5),
442 (_A.warnings.falling_6),
443 }
444 self.hospital:giveAdvice(msg)
445 end
446
447 function Patient:vomit()
448 local current = self:getCurrentAction()
449 --Only vomit under these conditions. Maybe I should add a vomit for patients in queues too?
450 if self:atFullyEmptyTile(current) and self.has_vomitted == 0 then
451 self:queueAction(VomitAction(), 1)
452 self:interruptAndRequeueAction(current, 2)
453 self.has_vomitted = self.has_vomitted + 1
454 self:changeAttribute("happiness", -0.02) -- being sick makes you unhappy
455 else
456 return
457 end
458 end
459
460 function Patient:pee()
461 local current = self:getCurrentAction()
462 --Only pee under these conditions. As with vomit, should they also pee if in a queue?
463 if self:atFullyEmptyTile(current) then
464 self:queueAction(PeeAction(), 1)
465 self:interruptAndRequeueAction(current, 2)
466 self:setMood("poo", "deactivate")
467 self:changeAttribute("happiness", -0.02) -- not being able to find a loo and doing it in the corridor will make you sad too
468 if not self.hospital.did_it_on_floor then
469 self.hospital.did_it_on_floor = true
470 self.hospital:giveAdvice({_A.warnings.people_did_it_on_the_floor})
471 end
472 else
473 return
474 end
475 end
476
477 function Patient:checkWatch()
478 local action = self:getCurrentAction()
479 if self.check_watch_anim and (action.name == "idle" or action.name == "seek_room") and not action.is_leaving then
480 self:queueAction(CheckWatchAction(), 0)
481 end
482 end
483
484 function Patient:yawn()
485 local action = self:getCurrentAction()
486 if self.yawn_anim and (action.name == "idle" or action.name == "seek_room") and not action.is_leaving then
487 self:queueAction(YawnAction(), 0)
488 end
489 end
490
491 function Patient:tapFoot()
492 local action = self:getCurrentAction()
493 if self.tap_foot_anim and (action.name == "idle" or action.name == "seek_room") and not action.is_leaving then
494 self:queueAction(TapFootAction(), 0)
495 end
496 end
497
498 --! Make the patient leave the hospital. This function also handles some
499 --! statistics (number of cured/kicked out patients, etc.)
500 --! The mood icon is updated accordingly. Reputation is impacted accordingly.
501 --!param reason (string): the reason why the patient is sent home, which could be:
502 --! -"cured": When the patient is cured.
503 --! -"kicked": When the patient is kicked anyway, either manually,
504 --! either when no treatment can be found for her/him, etc.
505 --! -"over_priced": When the patient decided to leave because he/she believes
506 --! the last treatment is over-priced.
507 --param disease_id (string): When the reason is "over_priced" this is the
508 --! id of the disease/diagnosis that the patient considered over_priced
509 function Patient:goHome(reason, disease_id)
510 local hosp = self.hospital
511 if self.going_home then
512 -- The patient should be going home already! Anything related to the hospital
513 -- will not be updated correctly, but we still want to try to get the patient to go home.
514 TheApp.world:gameLog("Warning: goHome called when the patient is already going home")
515 self:despawn()
516 return
517 end
518 if reason == "cured" then
519 self:setMood("cured", "activate")
520 self:changeAttribute("happiness", 0.8)
521 hosp:updateCuredCounts(self)
522 self:setDynamicInfoText(_S.dynamic_info.patient.actions.cured)
523
524 elseif reason == "kicked" then
525 self:setMood("exit", "activate")
526 hosp:updateNotCuredCounts(self, reason)
527
528 elseif reason == "over_priced" then
529 self:setMood("sad_money", "activate")
530 self:changeAttribute("happiness", -0.5)
531
532 local treatment_name = self.hospital.disease_casebook[disease_id].disease.name
533 self.hospital:giveAdvice({_A.warnings.patient_not_paying:format(treatment_name)})
534 hosp:updateNotCuredCounts(self, reason)
535 self:clearDynamicInfo()
536 self:setDynamicInfo('text', {"", _S.dynamic_info.patient.actions.prices_too_high})
537
538 elseif reason == "evacuated" then
539 self:clearDynamicInfo()
540 self:setDynamicInfo('text', {"", _S.dynamic_info.patient.actions.epidemic_sent_home})
541 self:setMood("exit","activate")
542
543 else
544 TheApp.world:gameLog("Error: unknown reason " .. reason .. "!")
545 end
546
547 hosp:updatePercentages()
548
549 -- Debug patients must be removed from the debug list so they can despawn properly
550 if self.is_debug then
551 hosp:removeDebugPatient(self)
552 end
553
554 -- Remove any messages and/or callbacks related to the patient.
555 self:unregisterCallbacks()
556
557 self.going_home = true
558 self.waiting = nil
559
560 -- Remove any vaccination calls from patient
561 if not self.vaccinated then
562 self.world.dispatcher:dropFromQueue(self)
563 end
564
565 -- allow timer to end early and after going_home is set
566 if self.is_emergency then
567 hosp:checkEmergencyOver()
568 end
569
570 local room = self:getRoom()
571 if room then
572 room:makeHumanoidLeave(self)
573 end
574 Humanoid.despawn(self)
575 end
576
577 -- Despawns the patient and removes them from the hospital
578 function Patient:despawn()
579 self.hospital:removePatient(self)
580 Humanoid.despawn(self)
581 end
582
583 -- Checks if the room the patient is in is the final treatment room for their disease
584 -- NB: Check diagnosed status as some illnesses use Psych for diagnosis and treatment
585 function Patient:_checkIfCureRoom(room)
586 local num_rooms = #self.disease.treatment_rooms
587 return (room and self.disease.treatment_rooms[num_rooms] == room.room_info.id
588 and self.diagnosed)
589 end
590
591 function Patient:setToDying()
592 -- Check that the patient is in a later state of dying
593 if self.going_to_die or self.dead then return end
594
595 self.set_to_die = true
596 end
597
598 function Patient:tick()
599 Humanoid.tick(self)
600
601 if self.set_to_die and
602 not self:getRoom() and
603 not self:getCurrentAction().is_leaving and
604 not self:isKnockingDoor() and
605 not self:isEnteringRoom() then
606 self:die()
607 end
608 end
609
610 -- Different events happen while a patient is waiting, based on the total number of remaining days.
611 local waiting_events = {
612 [0] = "go_home",
613 [10] = "tap_foot",
614 [20] = "yawn",
615 [30] = "check_watch"
616 }
617
618 --! Handle processing of a patient waiting for something (like a room or player action)
619 function Patient:_dailyWaitChecks()
620 self.waiting = self.waiting - 1
621 local wait_event = waiting_events[self.waiting]
622 if not wait_event then return end
623 if wait_event == "go_home" then
624 self:goHome("kicked")
625 if self.diagnosed then
626 -- No treatment rooms
627 self:setDynamicInfoText(_S.dynamic_info.patient.actions.no_treatment_available)
628 else
629 -- No diagnosis rooms
630 self:setDynamicInfoText(_S.dynamic_info.patient.actions.no_diagnoses_available)
631 end
632 elseif wait_event == "tap_foot" then
633 self:tapFoot()
634 elseif wait_event == "yawn" then
635 self:yawn()
636 elseif wait_event == "check_watch" then
637 self:checkWatch()
638 end
639 end
640
641 -- Define different thresholds for deteriorating health and their mood changes.
642 -- First value is the mood to deactivate, the second to activate (as applicable).
643 local health_treshold_rangemap = {
644 {upper = 0.06, value = {"dying4", "dying5"}}, -- Not looking good
645 {upper = 0.10, value = {"dying3", "dying4"}}, -- Fading fast
646 {upper = 0.14, value = {"dying2", "dying3"}}, -- Starts to take a turn for the worse
647 {upper = 0.18, value = {"dying1", "dying2"}}, -- Wishes they went to that other hospital
648 {upper = 0.22, value = {false, "dying1"}}, -- Getting rather unwell now
649 {value = false}
650 }
651
652 --! Handle processing of a patient's current health state and perform necessary actions
653 --!return health (number) A patient's current health value, from 0 to 1.
654 function Patient:_dailyHealthChecks()
655 -- If a Patient has been in the hospital for over 6 months and is still not well, they
656 -- will become sad and will either get fed up and leave or stay in the hope that you
657 -- will cure them before they die.
658 -- Note: This behaviour intentionally differs from Theme Hospital where being close to
659 -- death does not impact happiness.
660
661 local health = self:getAttribute("health")
662
663 -- Special handling for a patient almost passed.
664 local almost_dead_value, dying_value = 0.01, 0.0
665 if health < almost_dead_value then
666 if health == dying_value then
667 self:setToDying() -- Patient is going to die.
668 -- If patient is busy, they will die when they leave the room, will be cured,
669 -- or is leaving the hospital. Regardless we do not need to do anything else.
670 else
671 -- Is there time to say a prayer (will be dying tomorrow)
672 self.attributes["health"] = dying_value
673 end
674 return health
675 end
676
677 local dying_moods = rangeMapLookup(health, health_treshold_rangemap, true)
678 -- Above 0.22 on health, lookup returns an index we can exit early on
679 if type(dying_moods) == "number" then
680 return health
681 end
682
683 local old_dying_mood, new_dying_mood = dying_moods[1], dying_moods[2]
684 if not old_dying_mood then
685 if new_dying_mood then
686 -- Patient has entered the road of deterioration.
687 self:setMood(new_dying_mood, "activate")
688 self:changeAttribute("happiness", -0.0002) -- waiting too long will make you sad
689 -- There is a 1/3 chance that the patient will get fed up and leave.
690 -- This is potentially run 10 ((0.22-0.18)/0.004) times, hence the 1/30 chance.
691 -- If patient is already in the cure room, let the treatment happen.
692 if not self:_checkIfCureRoom(self:getRoom()) and math.random(1,30) == 1 then
693 self:setDynamicInfoText(_S.dynamic_info.patient.actions.fed_up)
694 self:setMood("dying1", "deactivate")
695 self:goHome("kicked")
696 end
697 end
698 return health
699 end
700
701 -- All other stages of deterioration simply cycle through the stages of dying mood.
702 self:setMood(old_dying_mood, "deactivate")
703 self:setMood(new_dying_mood, "activate")
704
705 return health
706 end
707
708 --! Generate or refresh the patient's health chart
709 function Patient:_dailyHealthHistoryRefresh()
710 if not self.health_history then
711 -- First day, initialize health history.
712 self.health_history = {}
713 self.health_history[1] = self:getAttribute("health")
714 self.health_history["last"] = 1
715 self.health_history["size"] = 20
716 else
717 -- Update the health history, wrapping around the array.
718 local last = self.health_history["last"] + 1
719 if last > self.health_history["size"] then last = 1 end
720 self.health_history[last] = self:getAttribute("health")
721 self.health_history["last"] = last
722 end
723 end
724
725 --! Process a patient's exposure to vomit and calculate their level of nausea
726 function Patient:_calculateNausea(num_nearby_vomit)
727 --Nausea level is based on health then proximity to vomit is used as a multiplier.
728 --Only a patient with a health value of less than 0.8 can be the initial vomiter, however :)
729 local initialVomitMult = 0.002 --The initial chance of vomiting.
730 local proximityVomitMult = 1.5 --The multiplier used when in proximity to vomit.
731 local nausea = (1.0 - self:getAttribute("health")) * initialVomitMult
732
733 -- As we don't yet have rats, ratholes and dead rats the chances of vomitting are slim
734 -- as a temp fix for this I have added 0.5 to the < nausea equation,
735 -- this may want adjusting or removing when the other factors are in the game MarkL
736 if self:getAttribute("health") <= 0.8 or num_nearby_vomit > 0 or self:getAttribute("happiness") < 0.6 then
737 return nausea * ((num_nearby_vomit + 1) * proximityVomitMult)
738 end
739 end
740
741 --! Process a patient's current state of toilet need, and action accordingly.
742 function Patient:_dailyBowelChecks()
743 if self.disease.more_loo_use then
744 self:changeAttribute("toilet_need", 0.018 * math.random() + 0.008)
745 else
746 self:changeAttribute("toilet_need", 0.006 * math.random() + 0.002)
747 end
748 -- Maybe it's time to visit the loo?
749 if self:getAttribute("toilet_need") > 0.75 and self.pee_anim and
750 not self:getRoom() and not self:getCurrentAction().is_leaving and
751 not self:getCurrentAction().is_entering then
752 self:handleToiletNeed()
753 end
754 end
755
756 --! Process a patient's sudden need for the toilet.
757 --! We will either do it on the floor (40% chance, daily), or seek out a toilet.
758 function Patient:handleToiletNeed()
759 if math.random(1, 10) < 5 then
760 self:pee()
761 self:changeAttribute("toilet_need", -(0.5 + math.random()*0.15))
762 self.going_to_toilet = "no"
763 else
764 -- If waiting for user response, do not send to toilets, as this messes
765 -- things up.
766 if self.going_to_toilet == "no" and not self.waiting then
767 self:setMood("poo", "activate")
768 -- Check if any room exists.
769 if not self.world:findRoomNear(self, "toilets") then
770 self.going_to_toilet = "no-toilets" -- Gets reset when a new toilet is built (then, patient will try again).
771 -- Otherwise we can queue the action, but only if not in any rooms right now.
772 elseif not self:getRoom() and not self:getCurrentAction().is_leaving and not self:getCurrentAction().pee then
773 self:setNextAction(SeekToiletsAction():setMustHappen(true))
774 self.going_to_toilet = "yes"
775 end
776 end
777 end
778 end
779
780 --! Process specific objects near the patient and their effect on happiness factors.
781 --!return (number) Quanitity of vomit inducing litter
782 function Patient:_dailyObjectHappinessEffects()
783 -- It is nice to see plants, but dead plants make you unhappy.
784 local plant = getRandomEntryFromArray(self:findObjectsInSquare(2, "plant"))
785 if plant then
786 self:changeAttribute("happiness", -0.0003 + (plant:isPleasingFactor() * 0.0001))
787 end
788
789 -- It always makes you happy to see you are in safe place.
790 local extinguisher = getRandomEntryFromArray(self:findObjectsInSquare(2, "extinguisher"))
791 if extinguisher then self:changeAttribute("happiness", 0.0002) end
792
793 -- sitting makes you happy whilst standing and walking does not
794 if self:goingToUseObject("bench") then
795 self:changeAttribute("happiness", 0.00002)
796 else
797 self:changeAttribute("happiness", -0.00002)
798 end
799
800 local num_vomit_inducing = 0
801 for _, litter in ipairs(self:findObjectsInSquare(2, "litter")) do
802 -- Count vomit inducing litter.
803 if litter:vomitInducing() then num_vomit_inducing = num_vomit_inducing + 1 end
804
805 -- Seeing litter will make you unhappy. If it is pee or puke it is worse
806 if litter:anyLitter() then
807 self:changeAttribute("happiness", -0.0002)
808 else
809 self:changeAttribute("happiness", -0.0004)
810 end
811 end
812 return num_vomit_inducing
813 end
814
815 --! Take the necessary steps to let a patient to get a soda.
816 --!param machine (object) The drinks machine to target
817 --!param lx (int) X usage coordinate of the drinks machine
818 --!param ly (int) Y usage coordinate of the drinks machine
819 function Patient:_constructGetSodaAction(machine, lx, ly)
820 -- Callback function when the machine has been used
821 local --[[persistable:patient_drinks_machine_after_use]] function after_use()
822 self:changeAttribute("thirst", -(0.7 + math.random()*0.3))
823 self:changeAttribute("toilet_need", 0.05 + math.random()*0.05)
824 self:setMood("thirsty", "deactivate")
825 -- The patient might be kicked while buying a drink
826 if not self.going_home then
827 self.hospital:sellSodaToPatient(self)
828 end
829 -- The patient might also throw the can on the floor, bad patient!
830 if math.random() < 0.6 then
831 -- It will be dropped between 1 and 12 tiles away (litter bin catches 8 radius).
832 self.litter_countdown = math.random(1, 12)
833 end
834 end
835
836 -- If we are queueing, let the queue handle the situation.
837 for _, current_action in ipairs(self.action_queue) do
838 if current_action.name == "queue" then
839 local callbacks = current_action.queue.callbacks[self]
840 if callbacks then
841 callbacks:onGetSoda(self, machine, lx, ly, after_use)
842 return
843 end
844 end
845 end
846
847 -- Or, if walking or idling insert the needed actions in
848 -- the beginning of the queue
849 local current = self:getCurrentAction()
850 if current.name == "walk" or current.name == "idle" or current.name == "seek_room" then
851 -- Go to the machine, use it, and then continue with
852 -- whatever he/she was doing.
853 current.keep_reserved = true
854 self:queueAction(WalkAction(lx, ly):setMustHappen(true):disableTruncate(), 1)
855 self:queueAction(UseObjectAction(machine):setAfterUse(after_use):setMustHappen(true), 2)
856 machine:addReservedUser(self)
857 -- Insert the old action again, a little differently depending on
858 -- what the previous action was.
859 self:interruptAndRequeueAction(current, 3, true)
860 end
861 end
862
863 --! Handle a pateint who is very thirsty. They'll start getting unhappy and wanting to
864 --! look for a drink.
865 function Patient:_handleExcessThirst()
866 self:changeAttribute("happiness", -0.002)
867 self:setMood("thirsty", "activate")
868 -- If there's already an action to buy a drink in the action queue, or
869 -- if we're going to the loo, do nothing
870 if self:goingToUseObject("drinks_machine") or self.going_to_toilet ~= "no" then
871 return
872 end
873 -- Don't check for a drinks machine too often
874 if self.timeout and self.timeout > 0 then
875 self.timeout = self.timeout - 1
876 return
877 end
878 -- The only allowed situations to grab a soda is when queueing
879 -- or idling/walking in the corridors
880 -- Also make sure the walk action when leaving a room has a chance to finish.
881 if self:getRoom() or self:getCurrentAction().is_entering or
882 self:getCurrentAction().is_leaving or self.going_home then
883 return
884 end
885
886 local machine, lx, ly = self.world:findObjectNear(self, "drinks_machine", 8, true)
887
888 -- If no machine can be found, resume previous action and wait a
889 -- while before trying again. To get a little randomness into the picture
890 -- it's not certain we go for it right now.
891 if not machine or not lx or not ly or math.random(1,10) < 3 then
892 self.timeout = math.random(2,4)
893 return
894 end
895
896 -- Go get a drink.
897 self:_constructGetSodaAction(machine, lx, ly)
898 end
899
900 --! If the patient is sitting on a bench or standing and queued, it may be a situation
901 --! where he/she is not in the queue anymore, but should be. If this is the case for
902 --! more than 2 ticks, go to reception.
903 function Patient:_checkPatientIsStillQueueingForARoom()
904 if #self.action_queue > 1 and (self:getCurrentAction().name == "use_object" or
905 self:getCurrentAction().name == "idle") and
906 self.action_queue[2].name == "queue" then
907 local found = false
908 for _, humanoid in ipairs(self.action_queue[2].queue) do
909 if humanoid == self then
910 found = true
911 break
912 end
913 end
914
915 if not found then
916 if not self.noqueue_ticks then
917 self.noqueue_ticks = 1
918 elseif self.noqueue_ticks > 2 then
919 self.world:gameLog("A patient has a queue action, but is not in the corresponding queue")
920 self:setNextAction(SeekReceptionAction())
921 else
922 self.noqueue_ticks = self.noqueue_ticks + 1
923 end
924 else
925 self.noqueue_ticks = 0
926 end
927 end
928 end
929
930 -- This function handles changing of the different attributes of the patient.
931 -- For example if thirst gets over a certain level (now: 0.7), the patient
932 -- tries to find a drinks machine nearby.
933 function Patient:tickDay()
934 -- First of all it may happen that this patient is tired of waiting and goes home.
935 if self.waiting then
936 self:_dailyWaitChecks()
937 if self.has_vomitted and self.has_vomitted > 0 then
938 self.has_vomitted = 0
939 end
940 end
941
942 -- if patients are getting unhappy, then maybe we should see this!
943 if self:getAttribute("happiness") < 0.3 then
944 self:setMood("sad2", "activate")
945 else
946 self:setMood("sad2", "deactivate")
947 end
948
949 -- Avoid an empty action queue error if the player clicks a patient to fall
950 -- at the same time as the day changes. There is now a between "neutral" stage.
951 if self.has_fallen == 3 then
952 self.has_fallen = 1
953 elseif self.has_fallen == 2 then
954 self.has_fallen = 3
955 end
956
957 -- Now call the parent function - it checks
958 -- if we're outside the hospital or on our way home.
959 if not Humanoid.tickDay(self) then
960 return
961 end
962
963 -- If we've hit zero health today, we should no longer continue performing daily actions.
964 if self:_dailyHealthChecks() == 0.0 then return end
965
966 -- Update health history.
967 self:_dailyHealthHistoryRefresh()
968
969 -- Perform Happiness and nausea calculations from nearby objects when not interacting
970 -- with a room.
971 if not self:getRoom() and not self:getCurrentAction().is_entering and
972 not self:getCurrentAction().is_leaving then
973 local num_nearby_vomit = self:_dailyObjectHappinessEffects()
974 -- We only want to calculate vomit chance on patients who have the relevant animation
975 -- and aren't an emergency.
976 if self.vomit_anim and not self.is_emergency then
977 local nausea_level = self:_calculateNausea(num_nearby_vomit)
978 if nausea_level and math.random() < nausea_level + 0.5 then
979 self:vomit()
980 end
981 end
982 end
983
984 -- Each day both thirst and toilet_need changes, and health decreases.
985 self:changeAttribute("health", - 0.004)
986 if not self.is_emergency then
987 self:changeAttribute("thirst", self:getAttribute("warmth") * 0.02 + 0.004 * math.random() + 0.004)
988 self:_dailyBowelChecks()
989
990 -- If thirsty enough a soda would be nice
991 if self:getAttribute("thirst") > 0.7 then
992 self:_handleExcessThirst()
993 end
994 end
995
996 -- See if a patient should yawn today.
997 -- Don't attempt if the patient is already waiting with a yawn event
998 local will_yawn = self.waiting and waiting_events[self.waiting] == "yawn"
999 if self.disease.yawn and not will_yawn and math.random(1, 10) == 5 then
1000 self:yawn()
1001 end
1002
1003 self:_checkPatientIsStillQueueingForARoom()
1004 end
1005
1006 function Patient:notifyNewRoom(room)
1007 Humanoid.notifyNewRoom(self, room)
1008 if self.going_to_toilet == "no-toilets" and room.room_info.id == "toilets" then
1009 self.going_to_toilet = "no" -- Patient can try again going to the loo.
1010 end
1011 end
1012
1013 -- Called each time the patient moves to a new tile.
1014 function Patient:setTile(x, y)
1015 if not self.litter_countdown then
1016 -- If arrived at the first tile of the hospital, give patient some litter.
1017 if x and self.world.map.th:getCellFlags(x, y).buildable then
1018 -- Small hospitals are around 40-50 tiles.
1019 self.litter_countdown = math.random(20, 100)
1020 end
1021
1022 elseif self.hospital and not self.going_to_die and not self.going_home then
1023 self.litter_countdown = self.litter_countdown - 1
1024
1025 -- Is the patient about to drop some litter?
1026 if self.litter_countdown == 0 then
1027 if x and not self:getRoom() and not self.world:getObjects(x, y) and
1028 self.world.map.th:getCellFlags(x, y).buildable and
1029 self.hospital:isInHospital(x, y) and
1030 (not self.world:findObjectNear(self, "bin", 8) or math.random() < 0.05) then
1031 -- Drop some litter!
1032 local trash = math.random(1, 4)
1033 local litter = self.world:newObject("litter", x, y)
1034 litter:setLitterType(trash, math.random(0, 1))
1035 if not self.hospital.hospital_littered then
1036 self.hospital.hospital_littered = true
1037
1038 -- A callout is only needed if there are no handymen employed
1039 if self.hospital:countStaffOfCategory("Handyman", 1) == 0 then
1040 self.hospital:giveAdvice({_A.staff_advice.need_handyman_litter})
1041 end
1042 end
1043 end
1044
1045 -- Always give new litter to drop.
1046 self.litter_countdown = math.random(30, 150)
1047 end
1048 end
1049
1050 Humanoid.setTile(self, x, y)
1051 end
1052
1053 -- As of now each time a bench is placed the world notifies all patients
1054 -- in the vicinity through this function.
1055 function Patient:notifyNewObject(id)
1056 -- If currently queueing it would be nice to be able to sit down.
1057 assert(id == "bench", "Can only handle benches at the moment")
1058 -- Look for a queue action and tell this patient to look for a bench
1059 -- if currently standing up.
1060 for _, action in ipairs(self.action_queue) do
1061 if action.name == "queue" then
1062 local callbacks = action.queue.callbacks[self]
1063 if callbacks then
1064 assert(action.done_init, "Queue action was not yet initialized")
1065 if action:isStanding() then
1066 callbacks:onChangeQueuePosition(self)
1067 break
1068 end
1069 end
1070 end
1071 end
1072 end
1073
1074 function Patient:addToTreatmentHistory(room)
1075 local should_add = true
1076 -- Do not add facility rooms such as toilets to the treatment history.
1077 for i, _ in pairs(room.categories) do
1078 if i == "facilities" then
1079 should_add = false
1080 break
1081 end
1082 end
1083 if should_add then
1084 self.treatment_history[#self.treatment_history + 1] = room.name
1085 end
1086 end
1087
1088 --! Sets the dynamic text currently in use by the patient
1089 --!param action_string (string) What text to say in dynamic text
1090 function Patient:setDynamicInfoText(action_string)
1091 self.action_string = action_string
1092 self:updateDynamicInfo()
1093 end
1094
1095 --! Updates a patient's dynamic info
1096 --! Can be called direct to refresh only
1097 function Patient:updateDynamicInfo()
1098 local action_string = self.action_string or ""
1099 local info = ""
1100 if self.going_home or self.going_to_die then
1101 self:setDynamicInfo('progress', nil)
1102 elseif self.diagnosed then
1103 if self.diagnosis_progress < 1.0 then
1104 -- The cure was guessed
1105 info = _S.dynamic_info.patient.guessed_diagnosis:format(self.disease.name)
1106 else
1107 if self.is_emergency then
1108 info = _S.dynamic_info.patient.emergency:format(self.disease.name)
1109 else
1110 info = _S.dynamic_info.patient.diagnosed:format(self.disease.name)
1111 end
1112 end
1113 self:setDynamicInfo('progress', nil)
1114 else
1115 info = _S.dynamic_info.patient.diagnosis_progress
1116 -- TODO: If the policy is changed this info will not be changed until the next
1117 -- diagnosis facility has been visited.
1118 local divider = 1
1119 if self.hospital then
1120 divider = self.hospital.policies["stop_procedure"]
1121 end
1122 if self.diagnosis_progress then
1123 self:setDynamicInfo('progress', math.min(1.0, self.diagnosis_progress / divider))
1124 end
1125 end
1126 -- Set the centre line of dynamic info based on contagiousness, if appropriate
1127 local epidemic = self.hospital and self.hospital.epidemic
1128 if epidemic and self.infected and epidemic.coverup_selected then
1129 if self.vaccinated then
1130 self:setDynamicInfo('text',
1131 {action_string, _S.dynamic_info.patient.actions.epidemic_vaccinated, info})
1132 else
1133 self:setDynamicInfo('text',
1134 {action_string, _S.dynamic_info.patient.actions.epidemic_contagious, info})
1135 end
1136 else
1137 self:setDynamicInfo('text', {action_string, "", info})
1138 end
1139 end
1140
1141 --[[ Update availability of a choice in message owned by this patient, if any
1142 !param choice (string) The choice that needs updating (currently "research" or "guess_cure").
1143 ]]
1144 function Patient:updateMessage(choice)
1145 if self.message and self.message.choices then
1146 local message_choice
1147 local enabled = false
1148
1149 for _, c in ipairs(self.message.choices) do
1150 if c.choice == choice then
1151 message_choice = choice
1152 end
1153 end
1154
1155 if choice == "research" and message_choice == choice then
1156 -- enable only if research department is built and a room in the treatment chain is undiscovered
1157 local req = self.hospital:checkDiseaseRequirements(self.disease.id)
1158 if req then
1159 enabled = (self.hospital:countRoomOfType("research", 1) > 0 and
1160 self.hospital:countStaffOfCategory("Researcher", 1) > 0)
1161
1162 local strings = _S.fax.disease_discovered_patient_choice
1163 local output_text = strings.can_not_cure
1164 if #req.rooms == 1 then
1165 local room_name, required_staff, staff_name = self.world:getRoomNameAndRequiredStaffName(req.rooms[1])
1166 if req.staff[required_staff] or 0 > 0 then
1167 output_text = strings.need_to_build_and_employ:format(room_name, staff_name)
1168 else
1169 output_text = strings.need_to_build:format(room_name)
1170 end
1171 elseif #req.rooms == 0 and next(req.staff) then
1172 output_text = strings.need_to_employ:format(StaffProfile.translateStaffClass(next(req.staff)))
1173 end
1174 self.message[3].text = output_text
1175 else
1176 -- no requirements missing
1177 enabled = false
1178 end
1179 -- TODO: implement choice == "guess_cure"
1180 end
1181
1182 for _, c in ipairs(self.message.choices) do
1183 if c.choice == choice then
1184 c.enabled = enabled
1185 end
1186 end
1187
1188 -- Update the fax window if it is open.
1189 local window = self.world.ui:getWindow(UIFax)
1190 if window then
1191 window:updateChoices()
1192 end
1193
1194 end
1195 end
1196
1197 --[[ Show patient infected status ]]
1198 function Patient:setInfectedStatus()
1199 self:removeAnyEpidemicStatus()
1200 self:setMood("epidemy4","activate")
1201 self.vaccination_candidate = false
1202 end
1203
1204 --[[ Show patient as ready for vaccination status ]]
1205 function Patient:setToReadyForVaccinationStatus()
1206 self:removeAnyEpidemicStatus()
1207 self:setMood("epidemy2","activate")
1208 self.marked_for_vaccination = true
1209 end
1210
1211 --[[ Show patient selected vaccination candidate status ]]
1212 function Patient:giveVaccinationCandidateStatus()
1213 self:removeAnyEpidemicStatus()
1214 self:setMood("epidemy3","activate")
1215 self.vaccination_candidate = true
1216 end
1217
1218 --[[ Remove the vaccination candidate icon and status from the patient ]]
1219 function Patient:removeVaccinationCandidateStatus()
1220 if not self.vaccinated then
1221 self:removeAnyEpidemicStatus()
1222 self:setMood("epidemy2","activate")
1223 self.vaccination_candidate = false
1224 end
1225 end
1226
1227 --[[ Show vaccinated status for vaccinated patient ]]
1228 function Patient:setVaccinatedStatus()
1229 self:removeAnyEpidemicStatus()
1230 self:setMood("epidemy1","activate")
1231 self.marked_for_vaccination = false
1232 self.vaccinated = true
1233 end
1234
1235 --[[ Clear all epidemic status ]]
1236 function Patient:removeAnyEpidemicStatus()
1237 self:setMood("epidemy1","deactivate") -- vaccinated (step 4)
1238 self:setMood("epidemy2","deactivate") -- marked (step 2)
1239 self:setMood("epidemy3","deactivate") -- chosen by nurse (step 3)
1240 self:setMood("epidemy4","deactivate") -- infected (step 1)
1241 end
1242
1243 function Patient:afterLoad(old, new)
1244 if old < 68 then
1245 if self.going_home then
1246 self.waiting = nil
1247 end
1248 end
1249 if old < 87 then
1250 if self.die_anims == nil then
1251 self.die_anims = {}
1252 end
1253
1254 -- New humanoid animation: rise_hell_east:
1255 if self:isMalePatient() then
1256 if not self:isType("Alternate Male Patient") then
1257 self.die_anims.rise_hell_east = 384
1258 else
1259 self.die_anims.rise_hell_east = 3404
1260 end
1261 else
1262 self.die_anims.rise_hell_east = 580
1263 end
1264 end
1265 if old < 108 then
1266 if self.going_to_toilet then
1267 -- Not easily decidable what the patient is doing here,
1268 -- removing a toilet while it's used is unlikely to happen.
1269 if self.world:findRoomNear(self, "toilets") then
1270 self.going_to_toilet = "yes"
1271 else
1272 self.going_to_toilet = "no-toilets"
1273 end
1274 else
1275 self.going_to_toilet = "no"
1276 end
1277 end
1278 if old < 158 then
1279 -- Always overwrite patient effect from old saves since it is
1280 -- loaded from a dummy field which used to have another meaning.
1281 if self.disease and not self.cured then
1282 self.th:setPatientEffect(self.disease.effect or AnimationEffect.None)
1283 else
1284 self.th:setPatientEffect(AnimationEffect.None)
1285 end
1286 end
1287 -- fix walks into room - regression in #2086
1288 if old < 177 then
1289 for i, action in ipairs(self.action_queue) do
1290 if action.name == "walk" and action.is_entering then
1291 action.saved_must_happen = false
1292 -- if its not the currently executing action
1293 -- we should set must_happen to false
1294 if i > 1 then
1295 action.must_happen = false
1296 end
1297 end
1298 end
1299 end
1300 if old < 190 then
1301 if self:isType("Standard Female Patient") then
1302 self.on_ground_anim = 1764
1303 end
1304 end
1305 if old < 211 then
1306 self.under_infection_attempt = self.attempted_to_infect
1307 self.attempted_to_infect = nil
1308 end
1309
1310 if old < 213 then
1311 self.mood_marker = 1
1312 end
1313
1314 self:updateDynamicInfo()
1315 Humanoid.afterLoad(self, old, new)
1316 end
1317
1318 function Patient:isMalePatient()
1319 if string.find(self.humanoid_class, "Female") then return false
1320 elseif string.find(self.humanoid_class, "Male") then return true
1321 else
1322 local male_patient_classes = {
1323 ["Chewbacca Patient"] = true,
1324 ["Elvis Patient"] = true,
1325 ["Invisible Patient"] = true
1326 }
1327 return male_patient_classes[self.humanoid_class] ~= nil
1328 end
1329 end
1330
1331 --[[ Interrupt a patients current action and resumes it after
1332 !param current_action (string) Action being interrupted
1333 !param queue_pos (int) Position to insert resumed action in queue
1334 !param meander_before_resume (bool) Indicator to insert an additional action before resuming.
1335 ]]
1336 function Patient:interruptAndRequeueAction(current_action, queue_pos, meander_before_resume)
1337 -- Rebuild the current action.
1338 local requeue_action
1339 if current_action.name == "idle" then
1340 requeue_action = IdleAction():setMustHappen(current_action.must_happen)
1341 requeue_action:setDirection(current_action.direction)
1342
1343 -- Go away a little before continuing with that important action.
1344 if meander_before_resume then
1345 self:queueAction(MeanderAction():setCount(1), queue_pos)
1346 end
1347 elseif current_action.name == "walk" then
1348 requeue_action = WalkAction(current_action.x, current_action.y)
1349 requeue_action:setMustHappen(current_action.must_happen)
1350 if current_action.saved_must_happen ~= nil then
1351 requeue_action.must_happen = current_action.saved_must_happen
1352 end
1353 -- need to copy the reserve_on_resume, otherwise the new queued action will not
1354 -- unreserve on interrupt
1355 requeue_action.reserve_on_resume = current_action.reserve_on_resume
1356 requeue_action:setIsEntering(current_action.is_entering)
1357 else
1358 -- We were seeking a room, start that action from the beginning
1359 -- i.e. do not set the must_happen flag.
1360 requeue_action = SeekRoomAction(current_action.room_type)
1361 if current_action.treatment_room then requeue_action:enableTreatmentRoom() end
1362 if current_action.diagnosis_room then
1363 requeue_action:setDiagnosisRoom(current_action.diagnosis_room)
1364 end
1365 requeue_action.message_sent = true
1366 end
1367 self:queueAction(requeue_action, queue_pos)
1368
1369 -- now interrupt
1370 if current_action.on_interrupt then
1371 current_action.on_interrupt(current_action, self)
1372 else
1373 self:finishAction()
1374 end
1375 end
1376
1377 -- Dummy callback for savegame compatibility
1378 local callbackNewRoom = --[[persistable:patient_toilet_build_callback]] function() end