Debian Codegraph @

CorsixTH/Lua/rooms/electrolysis.lua

raw
1 --[[ Copyright (c) 2009 Edvin "Lego3" Linge
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 = "electrolysis"
23 room.vip_must_visit = false
24 room.level_config_id = 23
25 room.class = "ElectrolysisRoom"
26 room.name = _S.rooms_short.electrolysis
27 room.long_name = _S.rooms_long.electrolysis
28 room.tooltip = _S.tooltip.rooms.electrolysis
29 room.objects_additional = { "extinguisher", "radiator", "plant", "bin" }
30 room.objects_needed = { electrolyser = 1, console = 1 }
31 room.build_preview_animation = 930
32 room.categories = {
33 clinics = 5,
34 }
35 room.minimum_size = 5
36 room.wall_type = "blue"
37 room.floor_tile = 17
38 room.required_staff = {
39 Doctor = 1,
40 }
41 room.maximum_staff = room.required_staff
42 room.call_sound = "reqd019.wav"
43 room.handyman_call_sound = "maint008.wav"
44
45 class "ElectrolysisRoom" (Room)
46
47 ---@type ElectrolysisRoom
48 local ElectrolysisRoom = _G["ElectrolysisRoom"]
49
50 function ElectrolysisRoom:ElectrolysisRoom(...)
51 self:Room(...)
52 end
53
54 function ElectrolysisRoom:commandEnteringPatient(patient)
55 local staff = self.staff_member
56 local electrolyser, pat_x, pat_y = self.world:findObjectNear(patient, "electrolyser")
57 local console, stf_x, stf_y = self.world:findObjectNear(staff, "console")
58
59 local --[[persistable:electrolysis_shared_loop_callback]] function loop_callback()
60 -- If the other humanoid has already started to idle we move on
61 if staff:getCurrentAction().name == "idle" and patient:getCurrentAction().name == "idle" then
62 -- Skilled doctors require less electrocutions
63 local num_electrocutions = math.random(1, 5) * (2 - staff.profile.skill)
64 -- We need to change to another type before starting, to be able
65 -- to have different animations depending on gender.
66 if math.random(0, 1) == 1 then
67 patient:setType("Standard Male Patient") -- Other attributes already set
68 else
69 patient:setType("Standard Female Patient")
70 patient:setLayer(0, math.random(1, 4) * 2)
71 patient:setLayer(1, math.random(0, 3) * 2)
72 patient:setLayer(2, 0)
73 end
74
75 local loop_callback_electrolysis = --[[persistable:electrolysis_loop_callback]] function(action)
76 num_electrocutions = num_electrocutions - 1
77 if num_electrocutions <= 0 then
78 -- Tired doctors can continue electrocuting for a bit too long...
79 -- Fatigue 0.00 - normal number of electrocutions
80 -- Fatigue 0.45 - normal number of electrocutions
81 -- Fatigue 0.80 - expect 1 extra electrocution
82 -- Fatigue 1.00 - expect 9 extra electrocutions
83 if math.random() <= 0.1 + 2 * (1 - staff:getAttribute("fatigue")) then
84 action.prolonged_usage = false
85 end
86 end
87 end
88
89 local after_electrolysis = --[[persistable:electrolysis_after_use]] function()
90 self:dealtWithPatient(patient)
91 staff:setNextAction(MeanderAction())
92 end
93
94 patient:setNextAction(UseObjectAction(electrolyser):setLoopCallback(loop_callback_electrolysis)
95 :setAfterUse(after_electrolysis))
96
97 staff:setNextAction(UseObjectAction(console))
98 end
99 end
100 -- As soon as one starts to idle the callback is called to see if the other one is already idling.
101 patient:walkTo(pat_x, pat_y)
102 patient:queueAction(IdleAction():setDirection(electrolyser.direction == "north" and "east" or "south")
103 :setLoopCallback(loop_callback))
104
105 staff:walkTo(stf_x, stf_y)
106 staff:queueAction(IdleAction():setDirection(console.direction == "north" and "east" or "south")
107 :setLoopCallback(loop_callback))
108
109 return Room.commandEnteringPatient(self, patient)
110 end
111
112 return room