| 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 |
local room = {} |
| 22 |
room.id = "psych" |
| 23 |
room.vip_must_visit = false |
| 24 |
room.level_config_id = 8 |
| 25 |
room.class = "PsychRoom" |
| 26 |
room.name = _S.rooms_short.psychiatric |
| 27 |
room.long_name = _S.rooms_long.psychiatric |
| 28 |
room.tooltip = _S.tooltip.rooms.psychiatry |
| 29 |
room.objects_additional = { "extinguisher", "radiator", "plant", "bin", "bookcase", "skeleton" } |
| 30 |
room.objects_needed = { screen = 1, couch = 1, comfortable_chair = 1 } |
| 31 |
room.build_preview_animation = 924 |
| 32 |
room.categories = { |
| 33 |
treatment = 1, |
| 34 |
diagnosis = 8, |
| 35 |
} |
| 36 |
room.minimum_size = 5 |
| 37 |
room.wall_type = "white" |
| 38 |
room.floor_tile = 18 |
| 39 |
room.required_staff = { |
| 40 |
Psychiatrist = 1, |
| 41 |
} |
| 42 |
room.maximum_staff = room.required_staff |
| 43 |
room.call_sound = "reqd003.wav" |
| 44 |
|
| 45 |
class "PsychRoom" (Room) |
| 46 |
|
| 47 |
---@type PsychRoom |
| 48 |
local PsychRoom = _G["PsychRoom"] |
| 49 |
|
| 50 |
function PsychRoom:PsychRoom(...) |
| 51 |
self:Room(...) |
| 52 |
end |
| 53 |
|
| 54 |
function PsychRoom:roomFinished() |
| 55 |
if self.hospital:countStaffOfCategory("Psychiatrist", 1) == 0 then |
| 56 |
self.hospital:giveAdvice({_A.room_requirements.psychiatry_need_psychiatrist}) |
| 57 |
end |
| 58 |
return Room.roomFinished(self) |
| 59 |
end |
| 60 |
|
| 61 |
function PsychRoom:commandEnteringStaff(staff) |
| 62 |
self.staff_member = staff |
| 63 |
local obj, ox, oy = self.world:findFreeObjectNearToUse(staff, "bookcase", "near") |
| 64 |
if not obj then |
| 65 |
staff:setNextAction(MeanderAction()) |
| 66 |
else |
| 67 |
staff:walkTo(ox, oy) |
| 68 |
staff:queueAction(UseObjectAction(obj)) |
| 69 |
local num_meanders = math.random(2, 8) |
| 70 |
local loop_callback_meanders = --[[persistable:psych_meander_loop_callback]] function() |
| 71 |
num_meanders = num_meanders - 1 |
| 72 |
if num_meanders == 0 then |
| 73 |
self:commandEnteringStaff(staff) |
| 74 |
end |
| 75 |
end |
| 76 |
staff:queueAction(MeanderAction():setLoopCallback(loop_callback_meanders)) |
| 77 |
end |
| 78 |
return Room.commandEnteringStaff(self, staff, true) |
| 79 |
end |
| 80 |
|
| 81 |
function PsychRoom:commandEnteringPatient(patient) |
| 82 |
local staff = self.staff_member |
| 83 |
|
| 84 |
local obj, ox, oy = self.world:findObjectNear(patient, "couch") |
| 85 |
patient:walkTo(ox, oy) |
| 86 |
patient:queueAction(UseObjectAction(obj)) |
| 87 |
|
| 88 |
local duration = math.random(16, 72) |
| 89 |
local bookcase, bx, by |
| 90 |
local --[[persistable:psych_loop_callback]] function loop_callback() |
| 91 |
if bookcase == nil then |
| 92 |
bookcase, bx, by = self.world:findObjectNear(staff, "bookcase") |
| 93 |
end |
| 94 |
if patient and patient.user_of and patient.user_of.object_type.id == "couch" then |
| 95 |
duration = duration - 1 |
| 96 |
end |
| 97 |
if duration == 0 then |
| 98 |
if patient.diagnosed and patient.disease.id == "king_complex" then |
| 99 |
-- Diagnosed patients (Elvis) need to change clothes |
| 100 |
local after_use_screen = --[[persistable:psych_screen_after_use]] function() |
| 101 |
if self:getStaffMember() then |
| 102 |
self:getStaffMember():setNextAction(MeanderAction()) |
| 103 |
end |
| 104 |
self:dealtWithPatient(patient) |
| 105 |
end |
| 106 |
|
| 107 |
obj, ox, oy = self.world:findObjectNear(patient, "screen") |
| 108 |
patient:walkTo(ox, oy) |
| 109 |
patient:queueAction(UseScreenAction(obj):setAfterUse(after_use_screen)) |
| 110 |
else |
| 111 |
if self:getStaffMember() then |
| 112 |
self:getStaffMember():setNextAction(MeanderAction()) |
| 113 |
end |
| 114 |
self:dealtWithPatient(patient) |
| 115 |
end |
| 116 |
return |
| 117 |
else |
| 118 |
if patient:getRoom() ~= self and self:getStaffMember() then |
| 119 |
self:getStaffMember():setNextAction(MeanderAction()) |
| 120 |
return |
| 121 |
end |
| 122 |
end |
| 123 |
if bookcase and (duration % 10) == 0 and math.random(1, 2) == 1 then |
| 124 |
staff:walkTo(bx, by) |
| 125 |
staff:queueAction(UseObjectAction(bookcase)) |
| 126 |
staff:queueAction(WalkAction(ox, oy)) |
| 127 |
staff:queueAction(UseObjectAction(obj):setLoopCallback(loop_callback)) |
| 128 |
duration = math.max(8, duration - 72) |
| 129 |
end |
| 130 |
end |
| 131 |
obj, ox, oy = self.world:findObjectNear(staff, "comfortable_chair") |
| 132 |
staff:walkTo(ox, oy) |
| 133 |
staff:queueAction(UseObjectAction(obj):setLoopCallback(loop_callback)) |
| 134 |
|
| 135 |
return Room.commandEnteringPatient(self, patient) |
| 136 |
end |
| 137 |
|
| 138 |
|
| 139 |
return room |