Debian Codegraph @

CorsixTH/Lua/rooms/cardiogram.lua

raw
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 = "cardiogram"
23 room.vip_must_visit = false
24 room.level_config_id = 12
25 room.class = "CardiogramRoom"
26 room.name = _S.rooms_short.cardiogram
27 room.long_name = _S.rooms_long.cardiogram
28 room.tooltip = _S.tooltip.rooms.cardiogram
29 room.objects_additional = { "extinguisher", "radiator", "plant", "bin" }
30 room.objects_needed = { cardio = 1, screen = 1 }
31 room.build_preview_animation = 918
32 room.categories = {
33 diagnosis = 3,
34 }
35 room.minimum_size = 4
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 = "reqd001.wav"
43 room.handyman_call_sound = "maint010.wav"
44
45 class "CardiogramRoom" (Room)
46
47 ---@type CardiogramRoom
48 local CardiogramRoom = _G["CardiogramRoom"]
49
50 function CardiogramRoom:CardiogramRoom(...)
51 self:Room(...)
52 end
53
54 function CardiogramRoom:commandEnteringPatient(patient)
55 local screen, sx, sy = self.world:findObjectNear(patient, "screen")
56 patient:walkTo(sx, sy)
57
58 local screen_after_use = --[[persistable:cardiogram_screen_after_use1]] function()
59 local staff = self.staff_member
60 local cardio, cx, cy = self.world:findObjectNear(patient, "cardio")
61 staff:walkTo(cardio:getSecondaryUsageTile())
62 local staff_idle = IdleAction()
63 staff:queueAction(staff_idle)
64 patient:walkTo(cx, cy)
65
66 local timer = 6
67 local phase = -2
68 local cardio_loop_callback = --[[persistable:cardiogram_cardio_loop_callback]] function(action)
69 if not action.on_interrupt then
70 action.prolonged_usage = false
71 patient.num_animation_ticks = 1
72 return
73 end
74 timer = timer - 1
75 if timer == 0 then
76 phase = phase + 1
77 if phase == 3 then
78 action.prolonged_usage = false
79 else
80 patient.num_animation_ticks = 3 - math.abs(phase)
81 end
82 timer = 6
83 else
84 action.secondary_anim = 1030
85 end
86 end
87
88 local cardio_after_use = --[[persistable:cardiogram_cardio_after_use]] function()
89 if #staff.action_queue == 1 then
90 staff:setNextAction(MeanderAction())
91 else
92 staff:finishAction(staff_idle)
93 end
94 end
95
96 patient:queueAction(MultiUseObjectAction(cardio, staff):setMustHappen(false)
97 :setProlongedUsage(true):setLoopCallback(cardio_loop_callback):setAfterUse(cardio_after_use))
98 patient:queueAction(WalkAction(sx, sy):setIsLeaving(true):setMustHappen(false):disableTruncate())
99
100 local leaving_after_use = --[[persistable:cardiogram_screen_after_use2]] function()
101 if #patient.action_queue == 1 then
102 self:dealtWithPatient(patient)
103 end
104 end
105 patient:queueAction(UseScreenAction(screen):setIsLeaving(true):setMustHappen(true):setAfterUse(leaving_after_use))
106 end
107
108 patient:queueAction(UseScreenAction(screen):setAfterUse(screen_after_use))
109 return Room.commandEnteringPatient(self, patient)
110 end
111
112 function CardiogramRoom:makeHumanoidLeave(humanoid)
113 self:makeHumanoidDressIfNecessaryAndThenLeave(humanoid)
114 end
115
116 function CardiogramRoom: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 CardiogramRoom:shouldHavePatientReenter(patient)
124 return not patient:isLeaving()
125 end
126
127 return room