Debian Codegraph @

CorsixTH/Lua/hospitals/player_hospital.lua

raw
1 --[[ Copyright (c) 2020 Albert "Alberth" Hofkamp
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 corsixth.require("announcer")
22
23 local AnnouncementPriority = _G["AnnouncementPriority"]
24
25 class "PlayerHospital" (Hospital)
26
27 ---@type PlayerHospital
28 local PlayerHospital = _G["PlayerHospital"]
29
30 local num_sitting_ratios = 15 -- Number of stored recent sitting ratio measurements.
31 local ratio_interval = 2 -- Measurement interval in days.
32
33 function PlayerHospital:PlayerHospital(world, avail_rooms, name)
34 self:Hospital(world, avail_rooms, name)
35
36 self.adviser_data = { -- Variables handling player advice.
37 temperature_advice = nil, -- Whether the player received advice about room temp.
38 reception_advice = nil, -- Whether advice was given about building the reception.
39 cured_died_message = nil, -- Whether the adviser reported about a cure or death.
40
41 sitting_ratios = {}, -- Measurements of recent sitting/standing ratios.
42 sitting_index = 1 -- Next entry in 'sitting_ratios' to update.
43 }
44
45 self.win_declined = false -- Has not yet declined the level win fax
46 self.announce_vip = 0 -- Number of spawned VIPs who need to be announced
47 end
48
49 --! Give advice to the player at the end of a day.
50 --! Note: For patient/staff warmth checks, advice is only on one or the other per month
51 function PlayerHospital:dailyAdviceChecks()
52 local current_date = self.world:date()
53 local day = current_date:dayOfMonth()
54
55 -- Hold any advice back until the game has somewhat started.
56 if current_date < Date(1, 5) then
57 return
58 end
59
60 -- Track sitting / standing ratio of patients.
61 if day % ratio_interval == 0 then
62 -- Compute the ratio of today.
63 local num_sitting, num_standing = self:countSittingStanding()
64 local ratio = (num_sitting + num_standing > 10)
65 and num_sitting / (num_sitting + num_standing) or nil
66
67 -- Store the measured ratio.
68 -- Once we hit num_sitting_ratios of index points, we wrap around
69 self.adviser_data.sitting_ratios[self.adviser_data.sitting_index] = ratio
70 self.adviser_data.sitting_index = (self.adviser_data.sitting_index >= num_sitting_ratios)
71 and 1 or self.adviser_data.sitting_index + 1
72 end
73
74 if day == 1 then
75 self:_adviseMoney()
76 end
77 if day == 3 then
78 self:_adviseStaffRoom()
79 end
80 -- Make players more aware of the need for radiators
81 if day == 5 and self:countRadiators() == 0 then
82 self:giveAdvice({_A.information.initial_general_advice.place_radiators})
83 end
84 if day == 8 then
85 self:_adviseToilets()
86 end
87 if day == 10 then
88 self:_warnForLongQueues()
89 end
90 if day == 12 then
91 self:_adviseBenches()
92 end
93 if day == 15 then
94 self:_adviseHeatingForPatients()
95 end
96 if day == 18 then
97 self:advisePlants(false)
98 end
99 if day == 20 then
100 self:_adviseHeatingForStaff()
101 end
102 if day == 24 then
103 self:_adviseDrinksMachines()
104 end
105
106 -- Reset advise flags at the end of the month.
107 if day == 28 then
108 self.adviser_data.temperature_advice = false
109 self.adviser_data.no_gp_office = false
110 self.adviser_data.no_doctor_no_gp_office = false
111 end
112 end
113
114 --! Private function to check if our financial situation needs advice.
115 --! This must occur after monthly maintenance and salary costs
116 --! or it may give invalid advice
117 function PlayerHospital:_adviseMoney()
118 local current_date = self.world:date()
119 local current_month = current_date:monthOfYear()
120 if not self.world.free_build_mode then
121 if self.balance < 2000 and self.balance >= -500 then
122 local cashlow_advice = {
123 _A.warnings.money_low, _A.warnings.money_very_low_take_loan,
124 _A.warnings.cash_low_consider_loan,
125 }
126 self:giveAdvice(cashlow_advice)
127
128 elseif self.balance < -2000 and current_month > 8 then
129 -- TODO: Ideally this should be linked to the lose criteria for balance.
130 self:giveAdvice({_A.warnings.bankruptcy_imminent})
131
132 elseif self.balance > 6000 and self.loan > 0 then
133 self:giveAdvice({_A.warnings.pay_back_loan})
134 end
135 end
136 end
137
138 --! Private function to warn about lack of a staff room.
139 function PlayerHospital:_adviseStaffRoom()
140 if self:countRoomOfType("staff_room", 1) > 0 then return end
141 local staffroom_advice = {
142 _A.warnings.build_staffroom, _A.warnings.need_staffroom,
143 _A.warnings.staff_overworked, _A.warnings.staff_tired,
144 }
145 self:giveAdvice(staffroom_advice)
146 end
147
148 --! Private function to warn about a lack of toilets.
149 function PlayerHospital:_adviseToilets()
150 if self:countRoomOfType("toilets", 1) > 0 then return end
151 local toilet_advice = {
152 _A.warnings.need_toilets, _A.warnings.build_toilets,
153 _A.warnings.build_toilet_now,
154 }
155 self:giveAdvice(toilet_advice)
156 end
157
158 --! Private function to check if patients have adequate seating
159 function PlayerHospital:_adviseBenches()
160 -- Compute average sitting ratio.
161 local sum_ratios = 0
162 local index = 1
163 while index <= num_sitting_ratios do
164 local ratio = self.adviser_data.sitting_ratios[index]
165 if ratio == nil then
166 sum_ratios = nil
167 break
168 else
169 sum_ratios = sum_ratios + ratio
170 end
171
172 index = index + 1
173 end
174
175 if sum_ratios ~= nil then -- Sufficient data available.
176 local ratio = sum_ratios / num_sitting_ratios
177 if ratio < 0.7 then -- At least 30% standing.
178 local bench_advice = {
179 _A.warnings.more_benches, _A.warnings.people_have_to_stand,
180 }
181 self:giveAdvice(bench_advice)
182
183 elseif ratio > 0.9 then
184 -- Praise having enough well placed seats about once a year.
185 local bench_advice = {
186 _A.praise.many_benches, _A.praise.plenty_of_benches,
187 _A.praise.few_have_to_stand,
188 }
189 self:giveAdvice(bench_advice, 1 / 12)
190 end
191 end
192 end
193
194 --! Private function to check warmth of the patients.
195 --! Only too hot or cold triggers advice
196 function PlayerHospital:_adviseHeatingForPatients()
197 if self.adviser_data.temperature_advice
198 or self.heating.heating_broke then return end
199 local warmth = self:getAveragePatientAttribute("warmth", 0.3)
200 if warmth < 0.22 then
201 local cold_advice = {
202 _A.information.initial_general_advice.increase_heating,
203 _A.warnings.patients_very_cold, _A.warnings.people_freezing,
204 }
205 self:giveAdvice(cold_advice)
206 self.adviser_data.temperature_advice = true
207
208 elseif warmth >= 0.36 then
209 local hot_advice = {
210 _A.information.initial_general_advice.decrease_heating,
211 _A.warnings.patients_too_hot, _A.warnings.patients_getting_hot,
212 }
213 self:giveAdvice(hot_advice)
214 self.adviser_data.temperature_advice = true
215 end
216 end
217
218 --! Private function to check warmth of the staff.
219 --! Only too hot or cold triggers advise
220 function PlayerHospital:_adviseHeatingForStaff()
221 if self.adviser_data.temperature_advice
222 or self.heating.heating_broke then return end
223 local warmth = self:getAverageStaffAttribute("warmth", 0.3)
224 if warmth < 0.22 then
225 self:giveAdvice({_A.warnings.staff_very_cold})
226 self.adviser_data.temperature_advice = true
227
228 elseif warmth >= 0.36 then
229 self:giveAdvice({_A.warnings.staff_too_hot})
230 self.adviser_data.temperature_advice = true
231 end
232 end
233
234 --! Private function to check if patients are getting thirsty
235 function PlayerHospital:_adviseDrinksMachines()
236 local current_date = self.world:date()
237 local thirst = self:getAveragePatientAttribute("thirst", 0)
238
239 -- Increase need after the first year.
240 local threshold = current_date:year() == 1 and 0.9 or 0.8
241 if thirst > threshold then
242 self:giveAdvice({_A.warnings.patients_very_thirsty})
243 elseif thirst > 0.6 then
244 local thirst_advice = {
245 _A.warnings.patients_thirsty, _A.warnings.patients_thirsty2,
246 }
247 self:giveAdvice(thirst_advice)
248 end
249 end
250
251 --! Private function to advise about long queues
252 --! Rooms requiring a doctor occasionally trigger the generic message
253 function PlayerHospital:_warnForLongQueues()
254 local chosen_room = self:getRandomBusyRoom()
255 if not chosen_room then return end
256 chosen_room = chosen_room.room_info
257 -- Required staff that is not nurse is doctor, researcher, surgeon or psych
258 if chosen_room.required_staff and not chosen_room.required_staff["Nurse"]
259 and math.random(1, 3) > 1 then
260 local warn_msgs = {
261 _A.warnings.queue_too_long_send_doctor:format(chosen_room.name),
262 _A.staff_advice.need_doctors
263 }
264 self:giveAdvice(warn_msgs)
265 else
266 self.world.ui.adviser:say(_A.warnings.queues_too_long)
267 end
268 end
269
270 --! Give advice to the user about maintenance of plants.
271 --!param placed (bool) If a plant was placed
272 function PlayerHospital:advisePlants(placed)
273 if self:countStaffOfCategory("Handyman", 1) > 0 then return end
274
275 local num_plants = self:countPlants()
276 if num_plants == 0 or (placed and num_plants > 1) then return end
277 self:giveAdvice({_A.staff_advice.need_handyman_plants})
278 end
279
280 --! Give advice to the player at the end of a month.
281 function PlayerHospital:monthlyAdviceChecks()
282 local today = self.world:date()
283 local current_month = today:monthOfYear()
284 local current_year = today:year()
285
286 if not self:hasReceptionDesk(true) then
287 self:checkReceptionAdvice(current_month, current_year)
288 -- No other checks should happen in this month
289 return
290 end
291 end
292
293 --! Make players aware of the need for a receptionist and desk.
294 --!param current_month (int) Month of the year.
295 --!param current_year (int) Current game year.
296 function PlayerHospital:checkReceptionAdvice(current_month, current_year)
297 if current_year > 1 then return end -- Playing too long.
298
299 local num_receptionists = self:countStaffOfCategory("Receptionist", 1)
300 if num_receptionists ~= 0 and current_month > 2 and not self.adviser_data.reception_advice then
301 self:giveAdvice({_A.warnings.no_desk_6})
302 self.adviser_data.reception_advice = true
303
304 elseif num_receptionists == 0 and current_month > 2 and self:countReceptionDesks() ~= 0 then
305 self:giveAdvice({_A.warnings.no_desk_7})
306
307 elseif current_month == 3 then
308 self:giveAdvice({_A.warnings.no_desk}, 1, true)
309
310 elseif current_month == 8 then
311 self:giveAdvice({_A.warnings.no_desk_1}, 1, true)
312
313 elseif current_month == 11 then
314 if self.visitors == 0 then
315 self:giveAdvice({_A.warnings.no_desk_2}, 1, true)
316 else
317 self:giveAdvice({_A.warnings.no_desk_3}, 1, true)
318 end
319 end
320 end
321
322 --! Give advice to the user about the need to buy the first reception desk.
323 function PlayerHospital:msgNeedFirstReceptionDesk()
324 if self.adviser_data.reception_advice then return end
325
326 if self:countReceptionDesks() == 0 then
327 self.world.ui.adviser:say(_A.warnings.no_desk_4)
328 self.adviser_data.reception_advice = true
329 end
330 end
331
332 --! Give advice to the user about having bought a reception desk.
333 function PlayerHospital:msgReceptionDesk()
334 local num_receptionists = self:countStaffOfCategory("Receptionist", 1)
335
336 if not self.world.ui.start_tutorial and num_receptionists == 0 then
337 self:giveAdvice({_A.room_requirements.reception_need_receptionist})
338 elseif num_receptionists > 0 and self:countReceptionDesks() == 1 and
339 not self.adviser_data.reception_advice and self.world:date():monthOfGame() > 3 then
340 self:giveAdvice({_A.warnings.no_desk_5})
341 self.adviser_data.reception_advice = true
342 end
343 end
344
345 --! Give advice about having more desks.
346 function PlayerHospital:msgMultiReceptionDesks()
347 local num_desks = #self:getReceptionDesks()
348 -- Compute total queue length at staffed receptions.
349 local queue_total = 0
350 for _, desk in ipairs(self:getReceptionDesks(true)) do
351 queue_total = queue_total + #desk.queue
352 end
353
354 local receptionists = self:countStaffOfCategory("Receptionist")
355 if (receptionists > 1 and num_desks > 0) or (receptionists > 0 and num_desks > 1) then
356 local queue_avg = math.floor(queue_total / num_desks)
357 if receptionists < num_desks and queue_avg > 5 then
358 self.world.ui.adviser:say(_A.warnings.reception_bottleneck)
359 elseif queue_avg > 4 then
360 self.world.ui.adviser:say(_A.warnings.queue_too_long_at_reception)
361 elseif receptionists > num_desks then
362 self.world.ui.adviser:say(_A.warnings.another_desk)
363 end
364 end
365 end
366
367 --! Show the 'Gates to hell' animation.
368 --!param entity (Entity) Gates to hell.
369 function PlayerHospital:showGatesToHell(entity)
370 local anim_func = --[[persistable:lava_hole_spawn_animation_end]]
371 function(anim_entity)
372 anim_entity:setAnimation(1602)
373 end
374
375 entity:playEntitySounds("LAVA00*.WAV", {0,1350,1150,950,750,350},
376 {0,1450,1250,1050,850,450}, 40)
377 entity:setTimer(TheApp.animation_manager:getAnimLength(2550), anim_func)
378 entity:setAnimation(2550)
379 end
380
381 --! Advises the player.
382 --!param msgs (array of string) Messages to select from.
383 --!param rnd_frac (optional float in range (0, 1]) Fraction of times that the
384 -- call actually says something.
385 --!param stay_up (bool) If true, let the adviser remain visible afterwards.
386 --!return (boolean) Whether a message was given to the user.
387 function PlayerHospital:giveAdvice(msgs, rnd_frac, stay_up)
388 local max_rnd = #msgs
389 if rnd_frac and rnd_frac > 0 and rnd_frac < 1 then
390 -- Scale by the fraction.
391 max_rnd = math.floor(max_rnd / rnd_frac)
392 end
393
394 local index = (max_rnd == 1) and 1 or math.random(1, max_rnd)
395 if index <= #msgs then
396 self.world.ui.adviser:say(msgs[index], stay_up)
397 return true
398 end
399 return false
400 end
401
402 --! Give the user possibly a message about a cured patient.
403 function PlayerHospital:msgCured()
404 self.world.ui:playSound("cheer.wav") -- This sound is always heard
405
406 local num_cured = math.floor(self.num_cured)
407 if num_cured == 1 then -- First cure is always reported.
408 self:giveAdvice({_A.information.first_cure})
409 elseif num_cured > 1 and not self.adviser_data.cured_died_message then
410 local cured_msgs = {
411 _A.level_progress.another_patient_cured:format(num_cured),
412 _A.praise.patients_cured:format(num_cured)
413 }
414 self.adviser_data.cured_died_message = self:giveAdvice(cured_msgs, 2/15)
415 end
416 end
417
418 --! Give the user possibly a message about a dead patient.
419 function PlayerHospital:msgKilled()
420 self.world.ui:playSound("boo.wav") -- this sound is always heard
421
422 if self.num_deaths < 1 then -- First death is always reported.
423 self:giveAdvice({_A.information.first_death})
424
425 elseif self.num_deaths > 1 and not self.adviser_data.cured_died_message then
426 local died_msgs = {
427 _A.warnings.many_killed:format(self.num_deaths),
428 _A.level_progress.another_patient_killed:format(self.num_deaths)
429 }
430 self.adviser_data.cured_died_message = self:giveAdvice(died_msgs, 6/10)
431 end
432 end
433
434 function PlayerHospital:adviseDiscoverDisease(disease)
435 -- Generate a message about the discovery
436 local message = {
437 {text = _S.fax.disease_discovered.discovered_name:format(disease.name)},
438 {text = disease.cause, offset = 12},
439 {text = disease.symptoms, offset = 12},
440 {text = disease.cure, offset = 12},
441 choices = {
442 {text = _S.fax.disease_discovered.close_text, choice = "close"},
443 },
444 }
445 self.world.ui.bottom_panel:queueMessage("disease", message, nil, 25*24, 1)
446
447 -- If the drug casebook is open, update it.
448 local window = self.world.ui:getWindow(UICasebook)
449 if window then
450 window:updateDiseaseList()
451 end
452 end
453
454 --! Select a relevant message to be displayed to the user
455 --!param broken_heat (0 or 1) Boiler output due to being broken.
456 function PlayerHospital:adviseBoilerBreakdown(broken_heat)
457 local ui = self.world.ui
458 if broken_heat == 0 then
459 ui.adviser:say(_A.boiler_issue.minimum_heat)
460 ui:playRandomAnnouncement({ "sorry002.wav", "sorry004.wav" })
461 else
462 ui.adviser:say(_A.boiler_issue.maximum_heat)
463 ui:playRandomAnnouncement({ "sorry003.wav", "sorry004.wav" })
464 end
465 end
466
467 --! Announces a machine needing repair
468 --!param room The room of the machine
469 function PlayerHospital:announceRepair(room)
470 local sound = room.room_info.handyman_call_sound
471 local earthquake = self.world.earthquake
472 self.world.ui:playAnnouncement("machwarn.wav", AnnouncementPriority.Critical)
473 -- If an earthquake is happening don't play the call sound to prevent spamming
474 if earthquake:isActive() and earthquake.warning_timer == 0 then return end
475 if self:countStaffOfCategory("Handyman", 1) == 0 then return end
476 if sound then self.world.ui:playAnnouncement(sound, AnnouncementPriority.Critical) end
477 end
478
479 function PlayerHospital:onSpawnVIP()
480 self.announce_vip = self.announce_vip + 1
481 end
482
483 --! Called at the end of each day.
484 function PlayerHospital:onEndDay()
485 if self:canAcceptPatients() then
486 -- Are we providing advice today?
487 self:dailyAdviceChecks()
488
489 -- If we haven't spawned our first patient yet for the player make it happen so
490 -- they don't wait too long
491 if self.num_visitors == 0 then
492 self.world:spawnPatient(self)
493 end
494 end
495
496 -- check if we still have to announce VIP visit
497 if self.announce_vip > 0 then
498 -- check if the VIP is in the building yet
499 for _, e in ipairs(self.world.entities) do
500 if class.is(e, Vip) and e.announced == false and
501 self:isInHospital(e.tile_x, e.tile_y) then
502 -- play VIP arrival sound and show tooltips
503 local ui = self.world.ui
504 -- there is also vip008 which announces a man from the ministry
505 ui:playRandomAnnouncement({ "vip001.wav", "vip002.wav", "vip003.wav",
506 "vip004.wav", "vip005.wav" }, AnnouncementPriority.High)
507 if self.num_vips < 1 then
508 ui.adviser:say(_A.information.initial_general_advice.first_VIP)
509 else
510 ui.adviser:say(_A.information.vip_arrived:format(e.name))
511 end
512 e.announced = true
513 self.announce_vip = self.announce_vip - 1
514 end
515 end
516 end
517
518 -- Look for work for staff who have nothing to do
519 for _, staff in ipairs(self.staff) do
520 -- Handymen currently have their own method to look for work
521 if not class.is(staff, Handyman) and staff:isIdle() then
522 self.world.dispatcher:answerCall(staff)
523 end
524 end
525
526 Hospital.onEndDay(self)
527 end
528
529 -- Called at the end of each day.
530 function PlayerHospital:onEndMonth()
531 -- Advise the player on the need for a staffed reception desk and cash flow.
532 self:monthlyAdviceChecks()
533
534 self.adviser_data.cured_died_message = nil -- Enable the message again.
535
536 -- Check if a player has won the level at months 3, 6 and 9. The annual report
537 -- window will perform this check at month 12 when it has been closed.
538 -- If the offer is declined then the next check is at month 6 and the annual report.
539 local check_months = {
540 [3] = not self.win_declined,
541 [6] = true,
542 [9] = not self.win_declined
543 }
544 if check_months[self.world.game_date:monthOfYear()] then self.world:checkIfGameWon() end
545
546 Hospital.onEndMonth(self)
547 end
548
549 --! Give visual warning that player doesn't have enough $ to build
550 -- Let the message remain until cancelled by the player as it is being displayed behind the town map
551 function PlayerHospital:adviseCannotAffordPlot()
552 self.world.ui.adviser:say(_A.warnings.cannot_afford_2, true, true)
553 end
554
555 --! Tell the player, through the advisor, about the impact of casebook prices
556 --!param judgment (string - under, over, fair) The judgment of the price,
557 -- from Hospital:computePriceLevelImpact
558 --!param name (string) The name of the casebook entry of the diagnosis or disease
559 function PlayerHospital:advisePriceLevelImpact(judgment, name)
560 local message
561 if judgment == "under" then
562 message = _A.warnings.low_prices:format(name)
563 elseif judgment == "over" then
564 message = _A.warnings.high_prices:format(name)
565 else
566 assert(judgment == "fair", "Price level impact judgements must be under, over or fair")
567 message = _A.warnings.fair_prices:format(name)
568 end
569 self.world.ui.adviser:say(message)
570 end
571
572 --! Makes the raise request for a staff member
573 --!param amount (num) the requested raise increase
574 --!param staff (table) the staff member
575 function PlayerHospital:makeRaiseRequest(amount, staff)
576 -- Show advice if it is the first time the player has experienced
577 -- a staff member requesting a raise.
578 -- Only show the help if the player is playing the campaign.
579 if not self.has_seen_pay_rise and tonumber(self.world.map.level_number) then
580 self.world.ui.adviser:say(_A.information.pay_rise)
581 self.has_seen_pay_rise = true
582 end
583 self.world.ui.bottom_panel:queueMessage("strike", amount, staff)
584 end
585
586 --! Announce to the player that a staff member is leaving the hospital
587 --!param staff (table) The staff member
588 function PlayerHospital:announceStaffLeave(staff)
589 self.world.ui:playRandomAnnouncement(staff.leave_sounds, staff.leave_priority)
590 end
591
592 --! Makes the fax requesting player action for the patient who needs a diagnosis room
593 --!param patient (table)
594 function PlayerHospital:makeNoTreatmentRoomFax(patient)
595 local strings = _S.fax.disease_discovered_patient_choice
596 -- Can this room be built right now? What is then missing?
597 local output_text = strings.can_not_cure
598 local req = self:checkDiseaseRequirements(patient.disease.id)
599 local research_enabled = false
600 if req then
601 research_enabled = (self:countRoomOfType("research", 1) > 0 and
602 self:countStaffOfCategory("Researcher", 1) > 0)
603 if #req.rooms == 1 then
604 local room_name, required_staff, staff_name = self.world:getRoomNameAndRequiredStaffName(req.rooms[1])
605 if req.staff[required_staff] or 0 > 0 then
606 output_text = strings.need_to_build_and_employ:format(room_name, staff_name)
607 else
608 output_text = strings.need_to_build:format(room_name)
609 end
610 elseif #req.rooms == 0 and next(req.staff) then
611 output_text = strings.need_to_employ:format(StaffProfile.translateStaffClass(next(req.staff)))
612 end
613 end
614
615 local message = {
616 {text = strings.disease_name:format(patient.disease.name)},
617 {text = " "},
618 {text = output_text},
619 {text = strings.what_to_do_question},
620 choices = {
621 {text = strings.choices.send_home, choice = "send_home"},
622 {text = strings.choices.wait, choice = "wait"},
623 {text = strings.choices.research, choice = "research", enabled = research_enabled},
624 },
625 }
626 -- Ok, send the message in all channels.
627 self.world.ui.bottom_panel:queueMessage("information", message, patient)
628 end
629
630 --! Makes the fax requesting player action for the patient who needs a diagnosis room
631 --!param patient (table)
632 function PlayerHospital:makeNoDiagnosisRoomFax(patient)
633 local guess_enabled = self.disease_casebook[patient.disease.id].discovered
634 local diag_failed = _S.fax.diagnosis_failed
635 local message = {
636 {text = diag_failed.situation},
637 {text = " "},
638 {text = diag_failed.what_to_do_question},
639 choices = {
640 {text = diag_failed.choices.send_home, choice = "send_home"},
641 {text = diag_failed.choices.take_chance, choice = "guess_cure", enabled = guess_enabled},
642 {text = diag_failed.choices.wait, choice = "wait"},
643 },
644 }
645 if guess_enabled then
646 table.insert(message, 3, {text = diag_failed.partial_diagnosis_percentage_name
647 :format(math.round(patient.diagnosis_progress * 100), patient.disease.name)})
648 end
649 self.world.ui.bottom_panel:queueMessage("information", message, patient)
650 end
651
652 --! Makes the fax at the start of an emergency
653 function PlayerHospital:makeEmergencyStartFax()
654 -- The last room in the list of treatment rooms is considered when checking for availability.
655 -- It works for all original diseases, but if we introduce new multiple room diseases it might break.
656 -- TODO: Make it work for all kinds of lists of treatment rooms.
657 -- TODO: Change to make use of Hospital:checkDiseaseRequirements
658 local no_rooms = #self.emergency.disease.treatment_rooms
659 local room_name, required_staff, staff_name = self.world
660 :getRoomNameAndRequiredStaffName(self.emergency.disease.treatment_rooms[no_rooms])
661
662 local staff_available = self:countStaffOfCategory(required_staff) > 0
663 -- Check so that all rooms in the list are available
664 if self:countRoomOfType(self.emergency.disease.treatment_rooms[no_rooms], 1) > 0 then
665 room_name = nil
666 end
667
668 local casebook = self.disease_casebook[self.emergency.disease.id]
669 local added_info = casebook.drug and
670 _S.fax.emergency.cure_possible_drug_name_efficiency
671 :format(self.emergency.disease.name, casebook.cure_effectiveness)
672 or _S.fax.emergency.cure_possible
673 if room_name then
674 if staff_available then
675 added_info = _S.fax.emergency.cure_not_possible_build:format(room_name) .. "."
676 else
677 added_info = _S.fax.emergency.cure_not_possible_build_and_employ:
678 format(room_name, staff_name) .. "."
679 end
680 elseif not staff_available then
681 added_info = _S.fax.emergency.cure_not_possible_employ:format(staff_name) .. "."
682 end
683
684 local one_or_many_victims_msg
685 if self.emergency.victims == 1 then
686 one_or_many_victims_msg = _S.fax.emergency.num_disease_singular
687 :format(self.emergency.disease.name)
688 else
689 one_or_many_victims_msg = _S.fax.emergency.num_disease
690 :format(self.emergency.victims, self.emergency.disease.name)
691 end
692 local message = {
693 {text = _S.fax.emergency.location:format(_S.fax.emergency.locations[math.random(1,9)])},
694 {text = one_or_many_victims_msg },
695 {text = added_info},
696 {text = self.world.free_build_mode and _S.fax.emergency.free_build or
697 _S.fax.emergency.bonus:format(self.emergency.bonus * self.emergency.victims)},
698 choices = {
699 {text = _S.fax.emergency.choices.accept, choice = "accept_emergency"},
700 {text = _S.fax.emergency.choices.refuse, choice = "refuse_emergency"},
701 },
702 }
703 -- Automatically refuse after 16 days
704 self.world.ui.bottom_panel:queueMessage("emergency", message, nil, Date.hoursPerDay() * 16, 2)
705 end
706
707 --! Makes the fax at the end of an emergency
708 function PlayerHospital:makeEmergencyEndFax(rescued_patients, total, max_bonus, earned)
709 local message = {
710 {text = _S.fax.emergency_result.saved_people:format(rescued_patients, total)},
711 {text = self.world.free_build_mode and "" or _S.fax.emergency_result.earned_money
712 :format(max_bonus, earned)},
713 choices = {
714 {text = _S.fax.emergency_result.close_text, choice = "close"},
715 },
716 }
717 self.world.ui.bottom_panel:queueMessage("report", message, nil, Date.hoursPerDay() * 25, 1)
718 end
719
720 --! Makes the fax which may spawn a VIP
721 function PlayerHospital:createVip()
722 local vipName = _S.vip_names[math.random(1,10)]
723 local message = {
724 {text = _S.fax.vip_visit_query.vip_name:format(vipName)},
725 choices = {
726 {text = _S.fax.vip_visit_query.choices.invite, choice = "accept_vip", additionalInfo = {name=vipName}},
727 {text = _S.fax.vip_visit_query.choices.refuse, choice = "refuse_vip", additionalInfo = {name=vipName}}
728 },
729 }
730 -- Automatically accept after 20 days
731 self.world.ui.bottom_panel:queueMessage("personality", message, nil, Date.hoursPerDay() * 20, 1)
732 end
733
734 --! Remove any message (fax) relating to this humanoid
735 --!param humanoid (table) The humanoid
736 function PlayerHospital:removeMessage(humanoid)
737 if humanoid.message then
738 self.world.ui.bottom_panel:deleteMessage(humanoid)
739 end
740 end
741
742 --! Called when the vip is out of the hospital grounds and ready to make their report
743 --!param vip_rating (int)
744 --!param name (string)
745 --!param cash_reward (int)
746 --!param vip_message (int)
747 function PlayerHospital:makeVipEndFax(vip_rating, name, cash_reward, vip_message)
748 local message
749 -- First of all there's a special message if we're in free build mode.
750 if self.world.free_build_mode then
751 message = {
752 {text = _S.fax.vip_visit_result.remarks.free_build[math.random(1, 3)]},
753 }
754 elseif vip_rating <= 7 then
755 message = {
756 {text = _S.fax.vip_visit_result.remarks[vip_message]},
757 {text = _S.fax.vip_visit_result.rep_boost},
758 {text = _S.fax.vip_visit_result.cash_grant:format(cash_reward)},
759 }
760 elseif vip_rating >= 8 and vip_rating < 11 then
761 -- Dont tell player about any rep change in this range
762 message = {
763 {text = _S.fax.vip_visit_result.remarks[vip_message]},
764 }
765 else
766 message = {
767 {text = _S.fax.vip_visit_result.remarks[vip_message]},
768 {text = _S.fax.vip_visit_result.rep_loss},
769 }
770 end
771 table.insert(message, 1, {text = _S.fax.vip_visit_result.vip_remarked_name:format(name)})
772 message["choices"] = {{text = _S.fax.vip_visit_result.close_text, choice = "close"}}
773
774 self.world.ui.bottom_panel:queueMessage("report", message, nil, Date.hoursPerDay() * 20, 1)
775 end
776
777 --! Play a sound file
778 function PlayerHospital:playSound(sound)
779 if self.world.app.config.play_sounds then
780 self.world.app.audio:playSound(sound)
781 end
782 end
783
784 --! The UI parts of earthquake ticks
785 --!param stage (string) Stage of the active earthquake. This must be one of the following,
786 -- "warning_start", "main_start", "end", "pause", "small_damage", "large damage", "sound"
787 function PlayerHospital:tickEarthquake(stage)
788 local ui = self.world.ui
789 local announcements = {
790 "quake001.wav", "quake002.wav", "quake003.wav", "quake004.wav",
791 }
792
793 -- Start of earthquakes
794 if stage == "warning_start" then
795 ui:beginShakeScreen(0.2)
796 ui:playRandomAnnouncement(announcements, AnnouncementPriority.Critical)
797 elseif stage == "main_start" then
798 ui:playRandomAnnouncement(announcements, AnnouncementPriority.Critical)
799
800 -- At the end of the warning or main earthquake, or on game pause, stop all screen movement
801 elseif stage == "end" or stage == "pause" then
802 ui:endShakeScreen()
803
804 -- All earthquakes start and end small (small earthquakes never become
805 -- larger), so when there has been less than 2 damage applied or only
806 -- 2 damage remaining to be applied, move the screen with less
807 -- intensity than otherwise.
808 elseif stage == "small_damage" then
809 ui:beginShakeScreen(0.5)
810 elseif stage == "large_damage" then
811 ui:beginShakeScreen(1)
812
813 elseif stage == "sound" then
814 -- Play the earthquake sound. It has different names depending on what the language contains.
815 if self.world.app.audio:soundExists("quake2.wav") then
816 ui:playSound("quake2.wav")
817 else
818 ui:playSound("quake.wav")
819 end
820 else
821 assert(false, "Unknown stage: " .. (stage or "nil"))
822 end
823 end
824
825 --! Give advice that a patient is waiting for the player to build a GP's office
826 -- Called when a patient has passed reception and is waiting for a room to be built.
827 -- Each piece of advice is only given once per month
828 function PlayerHospital:adviseNoGPOffice()
829 if self:countStaffOfCategory("Doctor", 1) > 0 then -- Doctor without a room
830 if not self.adviser_data.no_gp_office then
831 self.world.ui.adviser:say(_A.warnings.no_gp_office)
832 self.adviser_data.no_gp_office = true
833 end
834 else -- No room or doctor
835 if not self.adviser_data.no_doctor_no_gp_office then
836 self.world.ui.adviser:say(_A.warnings.no_doctor_no_gp_office)
837 self.adviser_data.no_doctor_no_gp_office = true
838 end
839 end
840 end
841
842 function PlayerHospital:afterLoad(old, new)
843 if old < 146 then
844 self.adviser_data = {
845 temperature_advise = nil,
846 sitting_ratios = {},
847 sitting_index = 1
848 }
849 end
850
851 if old < 147 then
852 -- Copy value of the previous name of the variable.
853 self.adviser_data.reception_advice = self.receptionist_msg
854 end
855 if old < 148 then
856 self.adviser_data.cured_died_message = nil
857 end
858 if old < 149 then
859 self.win_declined = false -- Has not yet declined the level win fax
860 end
861 if old < 159 then
862 self.adviser_data.reception_advice = self.adviser_data.reception_advice or self.receptionist_msg
863 end
864 if old < 211 then
865 -- Serious Radiation epidemics could exist in old saves and cause a crash
866 local serious_radiation = TheApp.diseases["serious_radiation"]
867 if self.epidemic and self.epidemic.disease == serious_radiation then
868 -- Tell the player somehow we ended the epidemic, EPI0008 is most fitting
869 self.world.ui:playAnnouncement("EPID008.wav", AnnouncementPriority.Critical)
870 self.world:gameLog("Notice: Removing active epidemic for Serious Radiation as it may crash the game due to a bug.")
871 end
872 self:cancelEpidemics(serious_radiation)
873 end
874
875 -- Refresh the cheat system every load
876 local old_active_cheats = self.hosp_cheats and self.hosp_cheats.active_cheats or {}
877 self.hosp_cheats = Cheats(self)
878 self.hosp_cheats.active_cheats = old_active_cheats
879
880 Hospital.afterLoad(self, old, new)
881 end