-
Notifications
You must be signed in to change notification settings - Fork 354
/
scanner_room.lua
154 lines (130 loc) · 5.39 KB
/
scanner_room.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
--[[ Copyright (c) 2009 Manuel König
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. --]]
local room = {}
room.id = "scanner"
room.vip_must_visit = false
room.level_config_id = 13
room.class = "ScannerRoom"
room.name = _S.rooms_short.scanner
room.long_name = _S.rooms_long.scanner
room.tooltip = _S.tooltip.rooms.scanner
room.objects_additional = { "extinguisher", "radiator", "plant", "bin" }
room.objects_needed = { scanner = 1, console = 1, screen = 1 }
room.build_preview_animation = 920
room.categories = {
diagnosis = 4,
}
room.minimum_size = 5
room.wall_type = "yellow"
room.floor_tile = 19
room.required_staff = {
Doctor = 1,
}
room.maximum_staff = room.required_staff
room.call_sound = "reqd002.wav"
-- Handyman is called to "diagnosis machine", all other diagnosis rooms have
-- their own, more specific handyman call though
--room.handyman_call_sound = "maint011.wav"
class "ScannerRoom" (Room)
---@type ScannerRoom
local ScannerRoom = _G["ScannerRoom"]
function ScannerRoom:ScannerRoom(...)
self:Room(...)
end
function ScannerRoom:commandEnteringPatient(patient)
local staff = self.staff_member
local console, stf_x, stf_y = self.world:findObjectNear(staff, "console")
local scanner, pat_x, pat_y = self.world:findObjectNear(patient, "scanner")
local screen, sx, sy = self.world:findObjectNear(patient, "screen")
local do_change = (patient.humanoid_class == "Standard Male Patient") or
(patient.humanoid_class == "Standard Female Patient")
local --[[persistable:scanner_shared_loop_callback]] function loop_callback()
if staff:getCurrentAction().scanner_ready and patient:getCurrentAction().scanner_ready then
staff:finishAction()
patient:finishAction()
end
end
staff:walkTo(stf_x, stf_y)
local idle_action = IdleAction():setDirection(console.direction == "north" and "west" or "north")
:setLoopCallback(loop_callback)
idle_action.scanner_ready = true
staff:queueAction(idle_action)
staff:queueAction(UseObjectAction(console))
if do_change then
patient:walkTo(sx, sy)
patient:queueAction(UseScreenAction(screen))
patient:queueAction(WalkAction(pat_x, pat_y))
else
patient:walkTo(pat_x, pat_y)
end
idle_action = IdleAction():setDirection(scanner.direction == "north" and "east" or "south")
:setLoopCallback(loop_callback)
idle_action.scanner_ready = true
patient:queueAction(idle_action)
local length = math.random(10, 20) * (2 - staff.profile.skill)
local loop_callback_scan = --[[persistable:scanner_loop_callback]] function(action)
if length <= 0 then
action.prolonged_usage = false
end
length = length - 1
end
local after_use_scan = --[[persistable:scanner_after_use]] function()
if not self.staff_member or patient.going_home then
-- If we aborted somehow, don't do anything here.
-- The patient already has orders to change back if necessary and leave.
-- makeHumanoidLeave() will make this function nil when it aborts the scanner's use.
return
end
self.staff_member:setNextAction(MeanderAction())
self:dealtWithPatient(patient)
end
patient:queueAction(UseObjectAction(scanner):setLoopCallback(loop_callback_scan)
:setAfterUse(after_use_scan))
return Room.commandEnteringPatient(self, patient)
end
function ScannerRoom:onHumanoidLeave(humanoid)
if self.staff_member == humanoid then
self.staff_member = nil
end
Room.onHumanoidLeave(self, humanoid)
end
function ScannerRoom:makeHumanoidLeave(humanoid)
if humanoid:getCurrentAction().name == "use_object" and
humanoid:getCurrentAction().object == self.world:findObjectNear(humanoid, "scanner") then
humanoid:getCurrentAction().after_use = nil
end
self:makeHumanoidDressIfNecessaryAndThenLeave(humanoid)
end
function ScannerRoom:dealtWithPatient(patient)
if string.find(patient.humanoid_class, "Stripped") then
local screen, sx, sy = self.world:findObjectNear(patient, "screen")
patient:setNextAction(WalkAction(sx, sy):setMustHappen(true):setIsLeaving(true)
:disableTruncate())
local after_use_patient = --[[persistable:scanner_exit]] function()
Room.dealtWithPatient(self, patient)
end
patient:queueAction(UseScreenAction(screen):setMustHappen(true):setIsLeaving(true)
:setAfterUse(after_use_patient))
patient:queueAction(self:createLeaveAction())
else
Room.dealtWithPatient(self, patient)
end
end
function ScannerRoom:shouldHavePatientReenter(patient)
return not patient:isLeaving()
end
return room