Debian Codegraph @

CorsixTH/Lua/rooms/general_diag.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 local room = {}
22 room.id = "general_diag"
23 room.vip_must_visit = false
24 room.level_config_id = 27
25 room.class = "GeneralDiagRoom"
26 room.name = _S.rooms_short.general_diag
27 room.long_name = _S.rooms_long.general_diag
28 room.tooltip = _S.tooltip.rooms.general_diag
29 room.objects_additional = { "extinguisher", "radiator", "plant", "bin" }
30 room.objects_needed = { screen = 1, crash_trolley = 1 }
31 room.build_preview_animation = 916
32 room.categories = {
33 diagnosis = 2,
34 }
35 room.minimum_size = 5
36 room.wall_type = "green"
37 room.floor_tile = 21
38 room.required_staff = {
39 Doctor = 1,
40 }
41 room.maximum_staff = room.required_staff
42 room.call_sound = "reqd021.wav"
43
44 class "GeneralDiagRoom" (Room)
45
46 ---@type GeneralDiagRoom
47 local GeneralDiagRoom = _G["GeneralDiagRoom"]
48
49 function GeneralDiagRoom:GeneralDiagRoom(...)
50 self:Room(...)
51 end
52
53 function GeneralDiagRoom:commandEnteringPatient(patient)
54 local screen, sx, sy = self.world:findObjectNear(patient, "screen")
55 -- Patient walks to screen
56 patient:walkTo(sx, sy)
57
58 local after_use_screen1 = --[[persistable:general_diag_screen_after_use1]] function()
59 local after_use_screen2 = --[[persistable:general_diag_screen_after_use2_next]] function() end
60 local staff = self:getStaffMember()
61 if staff then
62 local trolley, cx, cy = self.world:findObjectNear(patient, "crash_trolley")
63
64 -- Doctor walks to trolley
65 local ox, oy = trolley:getSecondaryUsageTile()
66 local staff_prepare = WalkAction(ox, oy)
67 :setMustHappen(true)
68 :disableTruncate()
69 :setUninterruptible(true)
70 staff:setNextAction(staff_prepare)
71
72 -- Doctor waits for patient near trolley
73 local staff_idle = IdleAction()
74 :setMustHappen(true)
75 :disableTruncate()
76 :setUninterruptible(true)
77 staff:queueAction(staff_idle)
78
79 -- Patient walks to trolley
80 local go_to_trolley = WalkAction(cx, cy)
81 :setMustHappen(true)
82 :disableTruncate()
83 patient:queueAction(go_to_trolley)
84
85 local after_use_trolley = --[[persistable:general_diag_trolley_after_use]] function()
86 -- Release doctor after procedure and finish his IdleAction() near trolley
87 staff:queueAction(MeanderAction())
88 staff:finishAction(staff_idle)
89 end
90
91 -- Patient uses trolley (trolly animation with patient and doctor)
92 local use_trolley = MultiUseObjectAction(trolley, staff)
93 :disableTruncate()
94 :setMustHappen(true)
95 :setProlongedUsage(false)
96 :setAfterUse(after_use_trolley)
97 patient:queueAction(use_trolley)
98
99 -- Patient walks back to screen
100 local go_to_screen2 = WalkAction(sx, sy)
101 :setIsLeaving(true)
102 :setMustHappen(true)
103 :disableTruncate()
104 patient:queueAction(go_to_screen2)
105
106 after_use_screen2 = --[[persistable:general_diag_screen_after_use2]] function()
107 if #patient.action_queue == 1 then
108 self:dealtWithPatient(patient)
109 end
110 end
111 else
112 -- Patient didn't get served
113 self:makeHumanoidLeave(patient)
114 patient:queueAction(SeekRoomAction(self.room_info.id))
115 end
116
117 -- Patient dresses back to their clothes
118 local dress_back = UseScreenAction(screen)
119 :setIsLeaving(true)
120 :setMustHappen(true)
121 :setAfterUse(after_use_screen2)
122 patient:queueAction(dress_back)
123 end
124
125 -- Patient undresses for procedure
126 local undress = UseScreenAction(screen):setAfterUse(after_use_screen1)
127 patient:queueAction(undress)
128
129 return Room.commandEnteringPatient(self, patient)
130 end
131
132 function GeneralDiagRoom:makeHumanoidLeave(humanoid)
133 self:makeHumanoidDressIfNecessaryAndThenLeave(humanoid)
134 end
135
136 function GeneralDiagRoom:shouldHavePatientReenter(patient)
137 return not patient:isLeaving()
138 end
139
140 return room