| 1 |
--[[ Copyright (c) 2009 Manuel König |
| 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 = "scanner" |
| 23 |
room.vip_must_visit = false |
| 24 |
room.level_config_id = 13 |
| 25 |
room.class = "ScannerRoom" |
| 26 |
room.name = _S.rooms_short.scanner |
| 27 |
room.long_name = _S.rooms_long.scanner |
| 28 |
room.tooltip = _S.tooltip.rooms.scanner |
| 29 |
room.objects_additional = { "extinguisher", "radiator", "plant", "bin" } |
| 30 |
room.objects_needed = { scanner = 1, console = 1, screen = 1 } |
| 31 |
room.build_preview_animation = 920 |
| 32 |
room.categories = { |
| 33 |
diagnosis = 4, |
| 34 |
} |
| 35 |
room.minimum_size = 5 |
| 36 |
room.wall_type = "yellow" |
| 37 |
room.floor_tile = 19 |
| 38 |
room.required_staff = { |
| 39 |
Doctor = 1, |
| 40 |
} |
| 41 |
room.maximum_staff = room.required_staff |
| 42 |
room.call_sound = "reqd002.wav" |
| 43 |
-- Handyman is called to "diagnosis machine", all other diagnosis rooms have |
| 44 |
-- their own, more specific handyman call though |
| 45 |
--room.handyman_call_sound = "maint011.wav" |
| 46 |
|
| 47 |
class "ScannerRoom" (Room) |
| 48 |
|
| 49 |
---@type ScannerRoom |
| 50 |
local ScannerRoom = _G["ScannerRoom"] |
| 51 |
|
| 52 |
function ScannerRoom:ScannerRoom(...) |
| 53 |
self:Room(...) |
| 54 |
end |
| 55 |
|
| 56 |
function ScannerRoom:commandEnteringPatient(patient) |
| 57 |
local staff = self.staff_member |
| 58 |
local console, stf_x, stf_y = self.world:findObjectNear(staff, "console") |
| 59 |
local scanner, pat_x, pat_y = self.world:findObjectNear(patient, "scanner") |
| 60 |
local screen, sx, sy = self.world:findObjectNear(patient, "screen") |
| 61 |
local do_change = (patient:isType("Standard Male Patient")) or |
| 62 |
(patient:isType("Standard Female Patient")) |
| 63 |
|
| 64 |
local --[[persistable:scanner_shared_loop_callback]] function loop_callback() |
| 65 |
if staff:getCurrentAction().scanner_ready and patient:getCurrentAction().scanner_ready then |
| 66 |
staff:finishAction() |
| 67 |
patient:finishAction() |
| 68 |
end |
| 69 |
end |
| 70 |
|
| 71 |
staff:walkTo(stf_x, stf_y) |
| 72 |
local idle_action = IdleAction():setDirection(console.direction == "north" and "west" or "north") |
| 73 |
:setLoopCallback(loop_callback) |
| 74 |
idle_action.scanner_ready = true |
| 75 |
staff:queueAction(idle_action) |
| 76 |
|
| 77 |
staff:queueAction(UseObjectAction(console)) |
| 78 |
|
| 79 |
if do_change then |
| 80 |
patient:walkTo(sx, sy) |
| 81 |
patient:queueAction(UseScreenAction(screen)) |
| 82 |
patient:queueAction(WalkAction(pat_x, pat_y)) |
| 83 |
else |
| 84 |
patient:walkTo(pat_x, pat_y) |
| 85 |
end |
| 86 |
|
| 87 |
idle_action = IdleAction():setDirection(scanner.direction == "north" and "east" or "south") |
| 88 |
:setLoopCallback(loop_callback) |
| 89 |
idle_action.scanner_ready = true |
| 90 |
patient:queueAction(idle_action) |
| 91 |
|
| 92 |
local length = math.random(10, 20) * (2 - staff.profile.skill) |
| 93 |
local loop_callback_scan = --[[persistable:scanner_loop_callback]] function(action) |
| 94 |
if length <= 0 then |
| 95 |
action.prolonged_usage = false |
| 96 |
end |
| 97 |
length = length - 1 |
| 98 |
end |
| 99 |
|
| 100 |
local after_use_scan = --[[persistable:scanner_after_use]] function() |
| 101 |
if not self.staff_member or patient.going_home then |
| 102 |
-- If we aborted somehow, don't do anything here. |
| 103 |
-- The patient already has orders to change back if necessary and leave. |
| 104 |
-- makeHumanoidLeave() will make this function nil when it aborts the scanner's use. |
| 105 |
return |
| 106 |
end |
| 107 |
self.staff_member:setNextAction(MeanderAction()) |
| 108 |
self:dealtWithPatient(patient) |
| 109 |
end |
| 110 |
|
| 111 |
patient:queueAction(UseObjectAction(scanner):setLoopCallback(loop_callback_scan) |
| 112 |
:setAfterUse(after_use_scan)) |
| 113 |
return Room.commandEnteringPatient(self, patient) |
| 114 |
end |
| 115 |
|
| 116 |
function ScannerRoom:onHumanoidLeave(humanoid) |
| 117 |
if self.staff_member == humanoid then |
| 118 |
self.staff_member = nil |
| 119 |
end |
| 120 |
Room.onHumanoidLeave(self, humanoid) |
| 121 |
end |
| 122 |
|
| 123 |
function ScannerRoom:makeHumanoidLeave(humanoid) |
| 124 |
if humanoid:getCurrentAction().name == "use_object" and |
| 125 |
humanoid:getCurrentAction().object == self.world:findObjectNear(humanoid, "scanner") then |
| 126 |
humanoid:getCurrentAction().after_use = nil |
| 127 |
end |
| 128 |
|
| 129 |
self:makeHumanoidDressIfNecessaryAndThenLeave(humanoid) |
| 130 |
end |
| 131 |
|
| 132 |
function ScannerRoom:dealtWithPatient(patient) |
| 133 |
if string.find(patient.humanoid_class, "Stripped") then |
| 134 |
local screen, sx, sy = self.world:findObjectNear(patient, "screen") |
| 135 |
patient:setNextAction(WalkAction(sx, sy):setMustHappen(true):setIsLeaving(true) |
| 136 |
:disableTruncate()) |
| 137 |
|
| 138 |
local after_use_patient = --[[persistable:scanner_exit]] function() |
| 139 |
Room.dealtWithPatient(self, patient) |
| 140 |
end |
| 141 |
|
| 142 |
patient:queueAction(UseScreenAction(screen):setMustHappen(true):setIsLeaving(true) |
| 143 |
:setAfterUse(after_use_patient)) |
| 144 |
patient:queueAction(self:createLeaveAction()) |
| 145 |
else |
| 146 |
Room.dealtWithPatient(self, patient) |
| 147 |
end |
| 148 |
end |
| 149 |
|
| 150 |
function ScannerRoom:shouldHavePatientReenter(patient) |
| 151 |
return not patient:isLeaving() |
| 152 |
end |
| 153 |
|
| 154 |
return room |