Debian Codegraph @

CorsixTH/Lua/entities/humanoid.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 --! An `Entity` which occupies a single tile and is capable of moving around the map.
22 class "Humanoid" (Entity)
23
24 ---@type Humanoid
25 local Humanoid = _G["Humanoid"]
26
27 local walk_animations = permanent"humanoid_walk_animations"({})
28 local door_animations = permanent"humanoid_door_animations"({})
29 local die_animations = permanent"humanoid_die_animations"({})
30 local falling_animations = permanent"humanoid_falling_animations"({})
31 local on_ground_animations = permanent"humanoid_on_ground_animations"({})
32 local get_up_animations = permanent"humanoid_get_up_animations"({})
33 local shake_fist_animations = permanent"humanoid_shake_fist_animations"({})
34 local pee_animations = permanent"humanoid_pee_animations"({})
35 local vomit_animations = permanent"humanoid_vomit_animations"({})
36 local tap_foot_animations = permanent"humanoid_tap_foot_animations"({})
37 local yawn_animations = permanent"humanoid_yawn_animations"({})
38 local check_watch_animations = permanent"humanoid_check_watch_animations"({})
39
40 local mood_icons = permanent"humanoid_mood_icons"({})
41
42 local function walk_anims(name, walkN, walkE, idleN, idleE, doorL, doorE, knockN, knockE, swingL, swingE)
43 walk_animations[name] = {
44 walk_east = walkE,
45 walk_north = walkN,
46 idle_east = idleE,
47 idle_north = idleN,
48 }
49 door_animations[name] = {
50 entering = doorE,
51 leaving = doorL,
52 entering_swing = swingE,
53 leaving_swing = swingL,
54 knock_north = knockN,
55 knock_east = knockE,
56 }
57 end
58
59 ---
60 -- @param name The name of the patient class these death animations are for.
61 -- @param fall The patient's fall animation.
62 -- @param rise The transparent getting up animation for heaven death patients who have been lying dead on the ground.
63 -- @param rise_hell The opaque getting up animation for hell death patients who have been lying dead on the ground.
64 -- @param wings The heaven death animation in which the patient's wings appear.
65 -- @param hands The heaven death animation which occurs after the wings animation when the patient puts their hands together.
66 -- @param fly The heaven death animation which makes patients fly upwards to heaven.
67 -- @param extra Dead untreated patients who don't transform before falling over use this animation afterwards to transform into a standard male/female.
68 ---
69 local function die_anims(name, fall, rise, rise_hell, wings, hands, fly, extra)
70 die_animations[name] = {
71 fall_east = fall,
72 rise_east = rise,
73 rise_hell_east = rise_hell,
74 wings_east = wings,
75 hands_east = hands,
76 fly_east = fly,
77 extra_east = extra,
78 }
79 end
80 local function falling_anim(name, fallingAnim)
81 falling_animations[name] = fallingAnim
82 end
83 local function on_ground_anim(name, on_groundAnim)
84 on_ground_animations[name] = on_groundAnim
85 end
86 local function get_up_anim(name, get_upAnim)
87 get_up_animations[name] = get_upAnim
88 end
89 local function shake_fist_anim(name, shake_fistAnim)
90 shake_fist_animations[name] = shake_fistAnim
91 end
92 local function vomit_anim(name, vomitAnim)
93 vomit_animations[name] = vomitAnim
94 end
95 local function yawn_anim(name, yawnAnim)
96 yawn_animations[name] = yawnAnim
97 end
98 local function tap_foot_anim(name, tap_footAnim)
99 tap_foot_animations[name] = tap_footAnim
100 end
101 local function check_watch_anim(name, check_watchAnim)
102 check_watch_animations[name] = check_watchAnim
103 end
104 local function pee_anim(name, peeAnim)
105 pee_animations[name] = peeAnim
106 end
107 local function moods(name, iconNo, prio, onHover)
108 mood_icons[name] = {icon = iconNo, priority = prio, on_hover = onHover}
109 end
110
111 --! Filter animations for patients and set the give marker positions.
112 local function assignPatientMarkers(anims, name, ...)
113 local anim_mgr = TheApp.animation_manager
114
115 for hum_type, anim in pairs(anims) do
116 if string.find(hum_type, "Patient") then
117 if name then anim = anim[name] end
118 anim_mgr:setPatientMarker(anim, ...)
119 end
120 end
121 end
122
123 --! Filter animations for staff and set the give marker positions.
124 local function assignStaffMarkers(anims, name, ...)
125 local anim_mgr = TheApp.animation_manager
126
127 for hum_type, anim in pairs(anims) do
128 if not string.find(hum_type, "Patient") then
129 if name then anim = anim[name] end
130 anim_mgr:setStaffMarker(anim, ...)
131 end
132 end
133 end
134
135
136 -- | Walk animations |
137 -- | Name |WalkN|WalkE|IdleN|IdleE|DoorL|DoorE|KnockN|KnockE|SwingL|SwingE| Notes
138 -----+---------------------------------------+-----+-----+-----+-----+-----+-----+------+------+-------+---------+
139 walk_anims("Standard Male Patient", 16, 18, 24, 26, 182, 184, 286, 288, 2040, 2042) -- 0-16, ABC
140 walk_anims("Gowned Male Patient", 406, 408, 414, 416) -- 0-10
141 walk_anims("Stripped Male Patient", 818, 820, 826, 828) -- 0-16
142 walk_anims("Stripped Male Patient 2", 818, 820, 826, 828) -- 0-16
143 walk_anims("Stripped Male Patient 3", 818, 820, 826, 828)
144 walk_anims("Alternate Male Patient", 2704, 2706, 2712, 2714, 2748, 2750, 2764, 2766) -- 0-10, ABC
145 walk_anims("Slack Male Patient", 1484, 1486, 1492, 1494, 1524, 1526, 2764, 1494) -- 0-14, ABC
146 walk_anims("Slack Female Patient", 0, 2, 8, 10, 258, 260, 294, 296, 2864, 2866) -- 0-16, ABC
147 walk_anims("Transparent Male Patient", 1064, 1066, 1072, 1074, 1104, 1106, 1120, 1074) -- 0-16, ABC
148 walk_anims("Standard Female Patient", 0, 2, 8, 10, 258, 260, 294, 296, 2864, 2866) -- 0-16, ABC
149 walk_anims("Gowned Female Patient", 2876, 2878, 2884, 2886) -- 0-8
150 walk_anims("Stripped Female Patient", 834, 836, 842, 844) -- 0-16
151 walk_anims("Stripped Female Patient 2", 834, 836, 842, 844) -- 0-16
152 walk_anims("Stripped Female Patient 3", 834, 836, 842, 844)
153 walk_anims("Transparent Female Patient",3012, 3014, 3020, 3022, 3052, 3054, 3068, 3070) -- 0-8, ABC
154 walk_anims("Chewbacca Patient", 858, 860, 866, 868, 3526, 3528, 4150, 4152)
155 walk_anims("Elvis Patient", 978, 980, 986, 988, 3634, 3636, 4868, 4870)
156 walk_anims("Invisible Patient", 1642, 1644, 1840, 1842, 1796, 1798, 4192, 4194)
157 walk_anims("Alien Male Patient", 3598, 3600, 3606, 3608, 182, 184, 286, 288, 3626, 3628) -- remember, no "normal"-doors animation
158 walk_anims("Alien Female Patient", 3598, 3600, 3606, 3608, 258, 260, 294, 296, 3626, 3628) -- identical to male; however death animations differ
159 walk_anims("Doctor", 32, 34, 40, 42, 670, 672, nil, nil, 4750, 4752)
160 walk_anims("Surgeon", 2288, 2290, 2296, 2298)
161 walk_anims("Nurse", 1206, 1208, 1650, 1652, 3264, 3266, nil, nil, 3272, 3274)
162 walk_anims("Handyman", 1858, 1860, 1866, 1868, 3286, 3288, nil, nil, 3518, 3520)
163 walk_anims("Receptionist", 3668, 3670, 3676, 3678) -- Could do with door animations
164 walk_anims("VIP", 266, 268, 274, 276)
165 walk_anims("Inspector", 266, 268, 274, 276)
166 walk_anims("Grim Reaper", 994, 996, 1002, 1004)
167
168
169 local kfp1, kfp2, kfp3, kfp4, kfp5, kfp6, kfp7, kfp8
170 kfp1, kfp2, kfp3, kfp4 = {-19, -15, "px"}, {-26, -17, "px"}, {-26, -15, "px"}, {-22, -13, "px"}
171 kfp5, kfp6, kfp7, kfp8 = {-19, -9, "px"}, {-13, -5, "px"}, {-8, -4, "px"}, {-5, 0, "px"}
172 local doorE_markers = { -- Anim 3288 in particular
173 kfp1, kfp2, kfp2, kfp2, kfp3, kfp4, kfp5, kfp6, kfp7, kfp8,
174 }
175
176 local kfp9, kfp10
177 kfp1, kfp2, kfp3, kfp4, kfp5 = {-7, 0, "px"}, {-14, 6, "px"}, {-12, 5, "px"}, {-11, 5, "px"}, {-7, 3, "px"}
178 kfp6, kfp7, kfp8, kfp9, kfp10 = {-4, 0, "px"}, {2, -1, "px"}, {10, -3, "px"}, {14, -7, "px"}, {20, -11, "px"}
179 local doorL_markers = { -- Anim 3286 in particular.
180 kfp1, kfp2, kfp2, kfp3, kfp4, kfp5, kfp6, kfp7, kfp7, kfp8, kfp9, kfp10,
181 }
182
183 assignPatientMarkers(door_animations, "entering", doorE_markers)
184 assignPatientMarkers(door_animations, "leaving", doorL_markers)
185 assignPatientMarkers(door_animations, "leaving_swing", {3, 4, "px"}, {32, -14, "px"})
186 assignPatientMarkers(door_animations, "entering_swing", {-32, -10, "px"}, {0, -2, "px"})
187
188 assignStaffMarkers(door_animations, "entering", doorE_markers)
189 assignStaffMarkers(door_animations, "leaving", doorL_markers)
190 assignStaffMarkers(door_animations, "leaving_swing", {3, 4, "px"}, {32, -14, "px"})
191 assignStaffMarkers(door_animations, "entering_swing", {-32, -10, "px"}, {0, -2, "px"})
192
193 -- | Die Animations |
194 -- | Name |FallE|RiseE|RiseE Hell|WingsE|HandsE|FlyE|ExtraE| Notes 2248
195 ----+--------------------------------+-----+-----+----------+-----+------+-----+------
196 die_anims("Standard Male Patient", 1682, 2434, 384, 2438, 2446, 2450) -- Always facing east or south
197 die_anims("Alternate Male Patient", 1682, 2434, 3404, 2438, 2446, 2450)
198 die_anims("Slack Male Patient", 1682, 2434, 384, 2438, 2446, 2450)
199 -- TODO: Where is slack male transformation? Uses alternate male for now.
200 die_anims("Transparent Male Patient", 4412, 2434, 384, 2438, 2446, 2450, 4416) -- Extra = Transformation
201 die_anims("Standard Female Patient", 3116, 3208, 580, 3212, 3216, 3220)
202 die_anims("Slack Female Patient", 4288, 3208, 580, 3212, 3216, 3220)
203 die_anims("Transparent Female Patient",4420, 3208, 580, 3212, 3216, 3220, 4428) -- Extra = Transformation
204 die_anims("Chewbacca Patient", 4182, 2434, 384, 2438, 2446, 2450, 1682) -- Only males die... (1222 is the Female)
205 die_anims("Elvis Patient", 974, 2434, 384, 2438, 2446, 2450, 4186) -- Extra = Transformation
206 die_anims("Invisible Patient", 4200, 2434, 384, 2438, 2446, 2450)
207 die_anims("Alien Male Patient", 4882, 2434, 384, 2438, 2446, 2450)
208 die_anims("Alien Female Patient", 4886, 3208, 580, 3212, 3216, 3220)
209
210 -- The next fours sets belong together, but are done like this so we can use them on their own
211 -- I also had difficulty in keeping them together, as the patient needs to be on the floor
212 -- for the duration of the earth quake before getting back up
213 -- Shaking of fist could perhaps be used when waiting too long
214
215 -- | Falling Animations |
216 -- | Name |Anim| Notes
217 ----+--------------------------------+-----+-----+-----+-----+------+------+
218 falling_anim("Standard Male Patient", 1682)
219 falling_anim("Standard Female Patient", 3116)
220
221 -- | On_ground Animations |
222 -- | Name |Anim| Notes
223 ----+--------------------------------+-----+-----+-----+-----+------+------+
224 on_ground_anim("Standard Male Patient", 1258)
225 on_ground_anim("Standard Female Patient", 1764)
226
227 -- | Get_up Animations |
228 -- | Name |Anim| Notes
229 ----+--------------------------------+-----+-----+-----+-----+------+------+
230 get_up_anim("Standard Male Patient", 384)
231 get_up_anim("Standard Female Patient", 580)
232
233 -- | Shake_fist Animations |
234 -- | Name |Anim| Notes
235 ----+--------------------------------+-----+-----+-----+-----+------+------+
236 shake_fist_anim("Standard Male Patient", 392) -- bloaty head patients lose head!
237
238 assignPatientMarkers(shake_fist_animations, nil, {0.0, 0.0})
239
240 -- | Vomit Animations |
241 -- | Name |Anim | Notes
242 ----+-----------------------------------+-----+
243 vomit_anim("Elvis Patient", 1034)
244 vomit_anim("Standard Female Patient", 3184)
245 vomit_anim("Standard Male Patient", 2056)
246 vomit_anim("Alternate Male Patient", 4476)
247 vomit_anim("Chewbacca Patient", 4138)
248 vomit_anim("Invisible Patient", 4204)
249 vomit_anim("Slack Male Patient", 4324)
250 vomit_anim("Transparent Female Patient", 4452)
251 vomit_anim("Transparent Male Patient", 4384)
252
253 assignPatientMarkers(vomit_animations, nil, {0.0, 0.0})
254
255 -- | Yawn Animations |
256 -- | Name |Anim | Notes
257 ----+-----------------------------------+-----+
258 yawn_anim("Standard Female Patient", 4864)
259 yawn_anim("Standard Male Patient", 368)
260 --yawn_anim("Alternate Male Patient", 2968) is this one the same as standard male?
261 -- whichever one is used for male, if he wears a hat it will lift when he yawns
262
263 assignPatientMarkers(yawn_animations, nil, {0.0, 0.0})
264
265 -- | Foot tapping Animations |
266 -- | Name |Anim | Notes
267 ----+-----------------------------------+-----+
268 tap_foot_anim("Standard Female Patient", 4464)
269 tap_foot_anim("Standard Male Patient", 2960)
270 tap_foot_anim("Alternate Male Patient", 360)
271
272 assignPatientMarkers(tap_foot_animations, nil, {0.0, 0.0})
273
274 -- | Check watch Animations |
275 -- | Name |Anim | Notes
276 ----+-----------------------------------+-----+
277 check_watch_anim("Standard Female Patient", 4468)
278 check_watch_anim("Standard Male Patient", 2964)
279 check_watch_anim("Alternate Male Patient", 364)
280 check_watch_anim("Slack Male Patient", 4060)
281
282 assignPatientMarkers(check_watch_animations, nil, {0.0, 0.0})
283
284 -- | pee Animations |
285 -- | Name |Anim | Notes
286 ----+-----------------------------------+-----+
287 pee_anim("Elvis Patient", 970)
288 pee_anim("Standard Female Patient", 4744)
289 pee_anim("Slack Female Patient", 4744)
290 pee_anim("Standard Male Patient", 2244)
291 pee_anim("Alternate Male Patient", 4472)
292 pee_anim("Slack Male Patient", 4328)
293 pee_anim("Chewbacca Patient", 4178)
294 pee_anim("Invisible Patient", 4208)
295 pee_anim("Transparent Female Patient", 4852)
296 pee_anim("Transparent Male Patient", 4848)
297
298 assignPatientMarkers(pee_animations, nil, {0.0, 0.0})
299
300 -- Some icons should only appear when the player hovers over the humanoid
301 -- Higher priority is more important.
302 -- | Available Moods |
303 -- | Name |Icon|Priority|On Hover| Notes
304 -----+-----------------+----+--------+-----------+
305 moods("reflexion", 4020, 5)
306 moods("cantfind", 4050, 3)
307 moods("idea1", 2464, 10)
308 moods("idea2", 2466, 11)
309 moods("idea3", 4044, 12)
310 moods("staff_wait", 4054, 20)
311 moods("tired", 3990, 30)
312 moods("pay_rise", 4576, 40)
313 moods("thirsty", 3986, 4)
314 moods("cold", 3994, 0, true) -- These have no priority since
315 moods("hot", 3988, 0, true) -- they will be shown when hovering
316 -- no matter what other priorities.
317 moods("queue", 4568, 70)
318 moods("poo", 3996, 5)
319 moods("sad_money", 4018, 55)
320 moods("patient_wait", 5006, 39)
321 moods("epidemy1", 4566, 55)
322 moods("epidemy2", 4570, 55)
323 moods("epidemy3", 4572, 55)
324 moods("epidemy4", 4574, 55)
325 moods("sad1", 3992, 39) -- unused?
326 moods("sad2", 4578, 40)
327 moods("dying1", 4000, 41)
328 moods("dying2", 4002, 42)
329 moods("dying3", 4004, 43)
330 moods("dying4", 4006, 44)
331 moods("dying5", 4008, 45)
332 moods("dead", 4046, 60)
333 moods("cured", 4048, 60)
334 moods("emergency", 3914, 50)
335 moods("exit", 4052, 60)
336
337
338 --!param ... Arguments for base class constructor.
339 function Humanoid:Humanoid(...)
340 self:Entity(...)
341 self.action_queue = {}
342 self.last_move_direction = "east"
343 self.attributes = {}
344 self.attributes["warmth"] = 0.29
345 self.attributes["happiness"] = 1
346 -- patients should be not be fully well when they come to your hospital and if it is staff there is no harm done!
347 self.attributes["health"] = math.random(80, 100) /100
348 self.active_moods = {}
349 self.should_knock_on_doors = false
350
351 self.speed = "normal"
352
353 self.build_callbacks = {--[[set]]}
354 self.remove_callbacks = {--[[set]]}
355 self.staff_change_callbacks = {--[[set]]}
356
357 self:setIfHoverMoodsVisible()
358 end
359
360 -- Save game compatibility
361 function Humanoid:afterLoad(old, new)
362 if old < 38 and new >= 38 then
363 -- should existing patients be updated and be getting really ill?
364 -- adds the new variables for health icons
365 self.attributes["health"] = math.random(60, 100) /100
366 end
367 -- make sure female slack patients have the correct animation
368 if old < 42 and new >= 42 then
369 if self:isType("Slack Female Patient") then
370 self.die_anims = die_animations["Slack Female Patient"]
371 end
372 end
373 if old < 77 and new >= 77 then
374 self.has_vomitted = 0
375 end
376 if old < 49 and new >= 49 then
377 self.has_fallen = 1
378 end
379 if old < 61 and new >= 61 then
380 -- callbacks changed
381 self.build_callbacks = {}
382 self.remove_callbacks = {}
383 if self.build_callback then
384 self.build_callbacks[self.build_callback] = true
385 self.build_callback = nil
386 end
387 if self.toilet_callback then
388 self.build_callbacks[self.toilet_callback] = true
389 self.toilet_callback = nil
390 end
391 end
392 if old < 83 and new >= 83 and self:isType("Chewbacca Patient") then
393 self.die_anims.extra_east = 1682
394 end
395 if old < 134 and new >= 134 then
396 self.staff_change_callbacks = {}
397 end
398 if old < 210 then
399 -- We renamed the old sad7 to sad2; and sad2 - sad6 to dying1 - dying5.
400 -- Make sure we adjust sad2 and sad7 to the new mood names
401 -- Other dying ones aren't an issue
402 if self:isMoodActive("sad2") then
403 self:setMood("sad2", "deactivate")
404 self:setMood("dying1", "activate")
405 end
406 if self:isMoodActive("sad7") then
407 self:setMood("sad7", "deactivate")
408 self:setMood("sad2", "activate")
409 end
410 end
411
412 for _, action in pairs(self.action_queue) do
413 -- Sometimes actions not actual instances of HumanoidAction
414 HumanoidAction.afterLoad(action, old, new)
415 end
416
417 Entity.afterLoad(self, old, new)
418 end
419
420 -- Function which is called when the user clicks on the `Humanoid`.
421 --!param ui (GameUI) The UI which the user in question is using.
422 --!param button (string) One of: "left", "middle", "right".
423 function Humanoid:onClick(ui, button)
424 if TheApp.config.debug then
425 self:dump()
426 end
427 end
428
429 function Humanoid:getRoom()
430 return self.in_room or Entity.getRoom(self)
431 end
432
433 function Humanoid:dump()
434 print("-----------------------------------")
435 print("Clicked on: ")
436 print(self:tostring())
437 print("-----------------------------------")
438 end
439
440 -- Called when the humanoid is about to be removed from the world.
441 function Humanoid:onDestroy()
442 local x, y = self.tile_x, self.tile_y
443 if x and y then
444 local notify_object = self.world:getObjectToNotifyOfOccupants(x, y)
445 if notify_object then
446 notify_object:onOccupantChange(-1)
447 end
448 end
449 -- Make absolutely sure there are no callbacks left on the humanoid.
450 self:unregisterCallbacks()
451 return Entity.onDestroy(self)
452 end
453
454 -- Set the `Hospital` which is responsible for treating or employing the
455 -- `Humanoid`. In single player games, this has little effect, but it is very
456 -- important in multiplayer games.
457 --!param hospital (Hospital) The `Hospital` which should be responsible
458 -- for the `Humanoid`.
459 function Humanoid:setHospital(hospital)
460 self.hospital = hospital
461 if not hospital.is_in_world then
462 self:despawn()
463 end
464 end
465
466 --! Despawn the humanoid.
467 function Humanoid:despawn()
468 local spawn_point = self.world.spawn_points[math.random(1, #self.world.spawn_points)]
469 self:setNextAction(SpawnAction("despawn", spawn_point):setMustHappen(true))
470 end
471
472 -- Function to activate/deactivate moods of a humanoid.
473 -- If mood_name is nil it is considered a refresh only.
474 function Humanoid:setMood(mood_name, activate)
475 if mood_name then
476 if activate and activate ~= "deactivate" then
477 if self.active_moods[mood_name] then
478 return -- No use doing anything if it already exists.
479 end
480 self.active_moods[mood_name] = mood_icons[mood_name]
481 else
482 if not self.active_moods[mood_name] then
483 return -- No use doing anything if the mood isn't there anyway.
484 end
485 self.active_moods[mood_name] = nil
486 end
487 end
488 local new_mood = nil
489 -- TODO: Make equal priorities cycle, or make all moods unique
490 for _, value in pairs(self.active_moods) do
491 if new_mood then -- There is a mood, check priorities.
492 if new_mood.priority < value.priority then
493 new_mood = value
494 end
495 else
496 if not value.on_hover then
497 new_mood = value
498 end
499 end
500 end
501 self:setMoodInfo(new_mood)
502 end
503
504 function Humanoid:setCallCompleted()
505 if self.on_call then
506 CallsDispatcher.onCheckpointCompleted(self.on_call)
507 end
508 end
509
510 -- Is the given mood in the list of active moods.
511 function Humanoid:isMoodActive(mood)
512 for i, _ in pairs(self.active_moods) do
513 if i == mood then
514 return true
515 end
516 end
517 return false
518 end
519
520 --! Set whether this humanoid should display its mood on hover.
521 function Humanoid:setIfHoverMoodsVisible()
522 self.hover_moods = true
523 end
524
525 function Humanoid.getIdleAnimation(humanoid_class)
526 return assert(walk_animations[humanoid_class], "Invalid humanoid class").idle_east
527 end
528
529 function Humanoid:getCurrentMood()
530 if self.mood_info then
531 return self.mood_info
532 end
533 end
534
535 --! Collect the objects in a square around the humanoid within the same room.
536 --!param size (int) Size of the square to be searched, as number of rows/columns
537 -- around the humanoid. Size 0 only searches the tile of the humanoid, size 1
538 -- adds the 8 tiles around the humanoid (one tile in all directions), and so on.
539 --!param object_spec (str or array str) Name(s) of objects to find.
540 --!return (array objs, or table str -> array objects) Found requested objects.
541 -- One array is returned if an object name was supplied, else a table with
542 -- object names to array of objects.
543 function Humanoid:findObjectsInSquare(size, object_spec)
544 -- Prepare for the search.
545 local objs_table = {}
546 if type(object_spec) == "string" then
547 -- Find one type of objects.
548 objs_table[object_spec] = {}
549 else
550 -- Find more types of objects.
551 for _, name in ipairs(object_spec) do objs_table[name] = {} end
552 end
553
554 local world_map = self.world.map
555 local th_map = world_map.th
556 local self_room_id = th_map:getRoomId(self.tile_x, self.tile_y)
557
558 -- Search the rectangle for as far as it is within the world.
559 local width, height = world_map.th:size()
560 local entity_map = self.world.entity_map
561
562 size = (size >= 0) and size or 0
563 for x = self.tile_x - size, self.tile_x + size do
564 if x >= 1 and x <= width then
565 for y = self.tile_y - size, self.tile_y + size do
566 if y >= 1 and y <= height and th_map:getRoomId(x, y) == self_room_id then
567 for _, obj in ipairs(entity_map:getObjectsAtCoordinate(x, y)) do
568 local entry = objs_table[obj.id]
569 if entry then entry[#entry + 1] = obj end
570 end
571 end
572 end
573 end
574 end
575
576 -- Return what was promised.
577 if type(object_spec) == "string" then
578 return objs_table[object_spec]
579 else
580 return objs_table
581 end
582 end
583
584 --! Start the next (always first) action in the queue.
585 function Humanoid:startAction()
586 local action = self.action_queue[1]
587
588 -- Handle an empty action queue in some way instead of crashing.
589 if not action then
590 self:_handleEmptyActionQueue() -- Inserts an action into the action queue.
591
592 action = self.action_queue[1]
593 assert(action)
594 end
595
596 -- Call the action start handler
597 TheApp.humanoid_actions[action.name](action, self)
598
599 -- If action has been marked as to be interrupted
600 if action == self.action_queue[1] and action.todo_interrupt and not action.uninterruptible then
601 -- Interrupt this action
602 local high_priority = action.todo_interrupt == "high"
603 action.todo_interrupt = nil
604 local on_interrupt = action.on_interrupt
605 if on_interrupt then
606 action.on_interrupt = nil
607 on_interrupt(action, self, high_priority)
608 end
609 end
610 end
611
612 function Humanoid:setNextAction(action, high_priority)
613 -- Aim: Cleanly finish the current action (along with any subsequent actions
614 -- which must happen), then replace all the remaining actions with the given
615 -- one.
616 local i = 1
617 local queue = self.action_queue
618 local interrupted = false
619
620 -- Skip over any actions which must happen
621 while queue[i] and queue[i].must_happen do
622 interrupted = true
623 i = i + 1
624 end
625
626 -- Remove actions which are no longer going to happen
627 local done_set = {}
628 for j = #queue, i, -1 do
629 local removed = queue[j]
630 queue[j] = nil
631 if not removed then
632 -- A bug (rare) that removed could be nil.
633 -- but as it's being removed anyway...it could be ignored
634 print("Warning: Action to be removed was nil")
635 else
636 if removed.on_remove then
637 removed.on_remove(removed, self)
638 end
639 if removed.until_leave_queue and not done_set[removed.until_leave_queue] then
640 removed.until_leave_queue:removeValue(self)
641 done_set[removed.until_leave_queue] = true
642 end
643 if removed.object and removed.object:isReservedFor(self) then
644 removed.object:removeReservedUser(self)
645 end
646 if removed.is_entering then
647 local dest_room = self.world:getRoom(removed.x, removed.y)
648 self:unexpectFromRoom(dest_room)
649 if dest_room and removed.reserve_on_resume and
650 removed.reserve_on_resume:isReservedFor(self) then
651 removed.reserve_on_resume:removeReservedUser(self)
652 dest_room:tryAdvanceQueue()
653 end
654 end
655 end
656 end
657
658 -- Add the new action to the queue
659 queue[i] = action
660
661 -- Interrupt the current action and queue other actions to be interrupted
662 -- when they start.
663 if interrupted then
664 local current_action = queue[1]
665 for j = 1, i - 1 do
666 queue[j].todo_interrupt = high_priority and "high" or true
667 end
668 -- Try to interrupt current action
669 if not current_action.uninterruptible then
670 local interrupt_handler = current_action.on_interrupt
671 if interrupt_handler then
672 current_action.on_interrupt = nil
673 interrupt_handler(current_action, self, high_priority or false)
674 end
675 end
676 else
677 -- Start the action if it has become the current action
678 self:startAction()
679 end
680 return self
681 end
682
683 function Humanoid:queueAction(action, pos)
684 if pos then
685 table.insert(self.action_queue, pos + 1, action)
686 if pos == 0 then
687 self:startAction()
688 end
689 else
690 self.action_queue[#self.action_queue + 1] = action
691 end
692 return self
693 end
694
695
696 function Humanoid:finishAction(action)
697 if action ~= nil then
698 assert(action == self.action_queue[1], "Can only finish current action")
699 end
700 -- Save the previous action just a while longer.
701 self.previous_action = self.action_queue[1]
702 table.remove(self.action_queue, 1)
703 self:startAction()
704 end
705
706 -- Check if the humanoid is running actions intended to leave the room, as indicated by the flag
707 function Humanoid:isLeaving()
708 return self.action_queue[1].is_leaving and true or false
709 end
710
711 -- Check if the humanoid is knocking on a door
712 function Humanoid:isKnockingDoor()
713 return class.is(self:getCurrentAction(), KnockDoorAction)
714 end
715
716 -- Check if the humanoid is entering room
717 function Humanoid:isEnteringRoom()
718 if self.user_of and self.user_of.object_type.id == "door" then
719 return true
720 end
721 return false
722 end
723
724 -- Check if there is "is_leaving" action in the action queue
725 function Humanoid:hasLeavingAction()
726 for _, action in ipairs(self.action_queue) do
727 if action.is_leaving then
728 return true
729 end
730 end
731 return false
732 end
733
734 -- Check if there is "use_screen is_leaving" action in the action queue
735 function Humanoid:hasDressingAndLeavingAction()
736 for _, action in ipairs(self.action_queue) do
737 if action.name == "use_screen" and action.is_leaving then
738 return true
739 end
740 end
741 return false
742 end
743
744 --! Handle an empty action queue in some way instead of crashing.
745 function Humanoid:_handleEmptyActionQueue()
746 -- if this is a patient that is going home, an empty
747 -- action queue is not a problem
748 if class.is(self, Patient) and self.going_home then
749 return
750 end
751
752 -- Log what just happened.
753 local message = "Warning: Empty action queue. For humanoid at coord x:"
754 .. self.tile_x .. " y:" .. self.tile_y .. ". Last action: " .. self.previous_action.name
755 if not TheApp.config.debug then
756 -- Notify the user about this in console even if debug mode is disabled.
757 -- Because gameLog() will be silent in console if debug mode is disabled.
758 print(message)
759 print("Automatic recovery has been attempted for empty queue.")
760 end
761 self.world:gameLog("")
762 self.world:gameLog(message)
763 self.world:gameLog(self:tostring())
764
765 -- First find out if this humanoid is in a room.
766 local room = self:getRoom()
767 if room then
768 room:makeHumanoidLeave(self)
769 end
770
771 -- Give the humanoid an action to avoid crashing.
772 if class.is(self, Staff) then
773 self:queueAction(MeanderAction())
774 elseif class.is(self, GrimReaper) then
775 self:queueAction(IdleAction())
776 elseif class.is(self, Patient) then
777 self:queueAction(SeekReceptionAction())
778 else
779 self:queueAction(SeekReceptionAction())
780 end
781
782 if TheApp.config.debug then
783 -- Open the dialog of the humanoid as feedback to the user.
784 local ui = self.world.ui
785 if class.is(self, Patient) then
786 ui:addWindow(UIPatient(ui, self))
787 elseif class.is(self, Staff) then
788 ui:addWindow(UIStaff(ui, self))
789 end
790
791 -- Ask user to choose kick off humanoid or do nothing
792 ui:addWindow(UIConfirmDialog(ui, true, _S.errors.dialog_empty_queue,
793 --[[persistable:humanoid_leave_hospital]] function()
794 self.world:gameLog("The humanoid was told to leave the hospital...")
795 if class.is(self, Staff) then
796 self:fire()
797 elseif class.is(self, Patient) then
798 -- Set these variables to increase the likelihood of the humanoid managing to get out of the hospital.
799 self.going_home = false
800 self.hospital = self.world:getLocalPlayerHospital()
801 self:goHome("kicked")
802 end
803 end,
804 nil -- Do nothing on cancel
805 ))
806 else
807 self.world:gameLog("Warning: Humanoid encountered an empty action queue. Recovery has been attempted.")
808 end
809 self.world:gameLog("")
810 self.world:dumpGameLog()
811 end
812
813 function Humanoid:setType(humanoid_class)
814 assert(walk_animations[humanoid_class], "Invalid humanoid class: " .. tostring(humanoid_class))
815 self.walk_anims = walk_animations[humanoid_class]
816 self.door_anims = door_animations[humanoid_class]
817 self.die_anims = die_animations[humanoid_class]
818 self.falling_anim = falling_animations[humanoid_class]
819 self.on_ground_anim = on_ground_animations[humanoid_class]
820 self.get_up_anim = get_up_animations[humanoid_class]
821 self.shake_fist_anim = shake_fist_animations[humanoid_class]
822 self.vomit_anim = vomit_animations[humanoid_class]
823 self.yawn_anim = yawn_animations[humanoid_class]
824 self.tap_foot_anim = tap_foot_animations[humanoid_class]
825 self.check_watch_anim = check_watch_animations[humanoid_class]
826 self.pee_anim = pee_animations[humanoid_class]
827 self.humanoid_class = humanoid_class
828 if #self.action_queue == 0 then
829 self:setNextAction(IdleAction())
830 end
831
832 self.th:setPartialFlag(self.permanent_flags or 0, false)
833 if humanoid_class == "Invisible Patient" then
834 -- Invisible patients do not have very many pixels to hit, box works better
835 self.permanent_flags = DrawFlags.BoundBoxHitTest
836 else
837 self.permanent_flags = nil
838 end
839 self.th:setPartialFlag(self.permanent_flags or 0)
840 end
841
842 function Humanoid:isType(humanoid_class)
843 return self.humanoid_class == humanoid_class
844 end
845
846 -- Helper function for the common case of instructing a `Humanoid` to walk to
847 -- a position on the map. Equivalent to calling `setNextAction` with a walk
848 -- action.
849 --!param tile_x (integer) The X-component of the Lua tile coordinates of the
850 -- tile to walk to.
851 --!param tile_y (integer) The Y-component of the Lua tile coordinates of the
852 -- tile to walk to.
853 --!param must_happen (boolean, nil) If true, then the walk action will not be
854 -- interrupted.
855 function Humanoid:walkTo(tile_x, tile_y, must_happen)
856 self:setNextAction(WalkAction(tile_x, tile_y)
857 :setMustHappen(not not must_happen))
858 end
859
860 -- Stub functions for handling fatigue. These are overridden by the staff subclass,
861 -- but also defined here, so we can just call it on any humanoid
862 function Humanoid:tire(amount)
863 end
864
865 function Humanoid:wake(amount)
866 end
867
868 function Humanoid:updateSpeed()
869 self.speed = "normal"
870 end
871
872 function Humanoid:handleRemovedObject(object)
873 local replacement_action
874 if class.is(self, Receptionist) then
875 replacement_action = MeanderAction()
876 elseif object.object_type.id == "bench" or object.object_type.id == "drinks_machine" then
877 replacement_action = IdleAction():setMustHappen(true)
878 end
879
880 for i, action in ipairs(self.action_queue) do
881 if (action.name == "use_object" or action.name == "staff_reception") and action.object == object then
882 if replacement_action then
883 self:queueAction(replacement_action, i)
884 end
885 if i == 1 then
886 local on_interrupt = action.on_interrupt
887 action.on_interrupt = nil
888 if on_interrupt then
889 on_interrupt(action, self, true)
890 end
891 else
892 table.remove(self.action_queue, i)
893 self.associated_desk = nil -- NB: for the other case, this is already handled in the on_interrupt function
894 end
895 -- Are we in a queue?
896 if self.action_queue[i + 1] and self.action_queue[i + 1].name == "queue" then
897 self.action_queue[i + 1]:onChangeQueuePosition(self)
898 end
899 break
900 end
901 end
902 end
903
904 -- Adjusts one of the `Humanoid`'s attributes.
905 --!param attribute (string) One of: "happiness", "thirst", "toilet_need", "warmth".
906 --!param amount (number) This amount is added to the existing value for the attribute,
907 -- and is then capped to be between 0 and 1.
908 function Humanoid:changeAttribute(attribute, amount)
909 -- Handle some happiness special cases
910 if attribute == "happiness" and self.humanoid_class then
911 local max_salary = self.world.map.level_config.payroll.MaxSalary
912 if class.is(self, Receptionist) then
913 -- A receptionist is never unhappy
914 self.attributes[attribute] = 1
915 return true
916 elseif self.profile and self.profile.wage >= max_salary then
917 -- A maximum salaried staff member is never unhappy
918 self.attributes[attribute] = 1
919 return true
920 end
921 end
922
923 if self.attributes[attribute] then
924 self.attributes[attribute] = self.attributes[attribute] + amount
925 if self.attributes[attribute] > 1 then
926 self.attributes[attribute] = 1
927 elseif self.attributes[attribute] < 0 then
928 self.attributes[attribute] = 0
929 end
930 end
931 end
932
933 -- Check if it is cold or hot around the humanoid and increase/decrease the
934 -- feeling of warmth accordingly. Returns whether the calling function should proceed.
935 function Humanoid:tickDay()
936 -- No use doing anything if we're going home/fired (or dead)
937 if self.going_home or self.going_to_die or self.dead then
938 return false
939 end
940
941 local temperature = self.world.map.th:getCellTemperature(self.tile_x, self.tile_y)
942 self.attributes.warmth = self:getAttribute("warmth") * 0.75 + temperature * 0.25
943
944 -- If it is too hot or too cold, start to decrease happiness and
945 -- show the corresponding icon. Otherwise we could get happier instead.
946 local min_comfort_temp = 0.22 -- 11 degrees Celsius.
947 local max_comfort_temp = 0.36 -- 18 degrees Celsius.
948 local decrease_factor = 0.10
949 local increase_happiness = 0.005
950 local warmth = self:getAttribute("warmth")
951
952 if warmth and self.hospital then
953 -- Cold: less than comfortable.
954 if warmth < min_comfort_temp then
955 self:changeAttribute("happiness", -decrease_factor * (min_comfort_temp - warmth))
956 self:setMood("cold", "activate")
957 -- Hot: More than comfortable.
958 elseif warmth > max_comfort_temp then
959 self:changeAttribute("happiness", -decrease_factor * (warmth - max_comfort_temp))
960 self:setMood("hot", "activate")
961 -- Ideal: Not too cold or too warm.
962 else
963 self:changeAttribute("happiness", increase_happiness)
964 self:setMood("cold", "deactivate")
965 self:setMood("hot", "deactivate")
966 end
967 end
968 return true
969 end
970
971 -- Helper function that finds out if there is an action queued to use the specified object
972 function Humanoid:goingToUseObject(object_type)
973 for _, action in ipairs(self.action_queue) do
974 if action.object and action.object.object_type.id == object_type then
975 return true
976 end
977 end
978 return false
979 end
980
981 -- Registers a new build callback for this humanoid.
982 --!param callback (function) The callback to call when a room has been built.
983 function Humanoid:registerRoomBuildCallback(callback)
984 if not self.build_callbacks[callback] then
985 self.build_callbacks[callback] = true
986 else
987 self.world:gameLog("Warning: Trying to re-add room build callback (" .. tostring(callback) .. ") for humanoid (" .. tostring(self) .. ").")
988 end
989 end
990
991 -- Unregisters a build callback for this humanoid.
992 --!param callback (function) The callback to remove.
993 function Humanoid:unregisterRoomBuildCallback(callback)
994 self.build_callbacks[callback] = nil
995 end
996
997 function Humanoid:notifyNewRoom(room)
998 for callback, _ in pairs(self.build_callbacks) do
999 callback(room)
1000 end
1001 end
1002
1003 function Humanoid:notifyOfStaffChange(staff)
1004 for callback, _ in pairs(self.staff_change_callbacks) do
1005 callback(staff)
1006 end
1007 end
1008
1009 -- Registers a new remove callback for this humanoid.
1010 --!param callback (function) The callback to call when a room has been removed.
1011 function Humanoid:registerRoomRemoveCallback(callback)
1012 if not self.remove_callbacks[callback] then
1013 self.world:registerRoomRemoveCallback(callback)
1014 self.remove_callbacks[callback] = true
1015 else
1016 self.world:gameLog("Warning: Trying to re-add room remove callback (" .. tostring(callback) .. ") for humanoid (" .. tostring(self) .. ").")
1017 end
1018 end
1019
1020 -- Unregisters a remove callback for this humanoid.
1021 --!param callback (function) The callback to remove.
1022 function Humanoid:unregisterRoomRemoveCallback(callback)
1023 if self.remove_callbacks[callback] then
1024 self.world:unregisterRoomRemoveCallback(callback)
1025 self.remove_callbacks[callback] = nil
1026 end
1027 end
1028
1029
1030 -- Registers a new staff change callback for this humanoid.
1031 --!param callback (function) The callback to call when a staff member has been hired or fired
1032 function Humanoid:registerStaffChangeCallback(callback)
1033 if self.staff_change_callbacks and not self.staff_change_callbacks[callback] then
1034 self.staff_change_callbacks[callback] = true
1035 else
1036 self.world:gameLog("Warning: Trying to re-add staff callback (" .. tostring(callback) .. ") for humanoid (" .. tostring(self) .. ").")
1037 end
1038 end
1039
1040 -- Unregisters a staff change callback for this humanoid.
1041 --!param callback (function) The callback to remove.
1042 function Humanoid:unregisterStaffChangeCallback(callback)
1043
1044 if self.staff_change_callbacks and self.staff_change_callbacks[callback] then
1045 self.staff_change_callbacks[callback] = nil
1046 else
1047 self.world:gameLog("Warning: Trying to remove nonexistent staff callback (" .. tostring(callback) .. ") from humanoid (" .. tostring(self) .. ").")
1048 end
1049 end
1050
1051
1052 -- Function called when a humanoid is sent away from the hospital to prevent
1053 -- further actions taken as a result of a callback
1054 function Humanoid:unregisterCallbacks()
1055 -- Remove callbacks for new rooms
1056 for cb, _ in pairs(self.build_callbacks) do
1057 self:unregisterRoomBuildCallback(cb)
1058 end
1059 -- Remove callbacks for removed rooms
1060 for cb, _ in pairs(self.remove_callbacks) do
1061 self:unregisterRoomRemoveCallback(cb)
1062 end
1063 -- Remove callbacks for removed rooms
1064 for cb, _ in pairs(self.staff_change_callbacks) do
1065 self:unregisterStaffChangeCallback(cb)
1066 end
1067 -- Remove any message related to the humanoid.
1068 if self.message_callback then
1069 self:message_callback(true)
1070 self.message_callback = nil
1071 end
1072 end
1073
1074 function Humanoid:getCurrentAction()
1075 if next(self.action_queue) == nil then
1076 error("Action queue was empty. This should never happen.\n" .. self:tostring())
1077 end
1078
1079 return self.action_queue[1]
1080 end
1081
1082 --[[ Return string representation
1083 ! Returns string representation of the humanoid like status and action queue
1084 !return (string)
1085 ]]
1086 function Humanoid:tostring()
1087 local name = self.profile and self.profile:getFullName() or nil
1088 local class = self.humanoid_class and self.humanoid_class or "N/A"
1089 local full_name = "humanoid"
1090 if (name) then
1091 full_name = full_name .. " (" .. name .. ")"
1092 end
1093
1094 local result = string.format("%s - class: %s", full_name, class)
1095
1096 result = result .. string.format("\nWarmth: %.3f Happiness: %.3f Fatigue: %.3f Thirst: %.3f Toilet_Need: %.3f Health: %.3f Service Quality: %.3f",
1097 self:getAttribute("warmth"),
1098 self:getAttribute("happiness"),
1099 self:getAttribute("fatigue"),
1100 self:getAttribute("thirst"),
1101 self:getAttribute("toilet_need"),
1102 self:getAttribute("health"),
1103 self.getServiceQuality and self:getServiceQuality() or 0)
1104
1105 result = result .. "\nActions: ["
1106 for i = 1, #self.action_queue do
1107 local action = self.action_queue[i]
1108 local action_string = action.name
1109 if action.room_type then
1110 action_string = action_string .. " - " .. action.room_type
1111 elseif action.object then
1112 action_string = action_string .. " - " .. action.object.object_type.id
1113 elseif action.name == "walk" then
1114 action_string = action_string .. " - going to " .. action.x .. ":" .. action.y
1115 elseif action.name == "queue" then
1116 local distance = action.current_bench_distance
1117 if distance == nil then
1118 distance = "nil"
1119 end
1120 local standing = "false"
1121 if action.isStanding and action:isStanding() then
1122 standing = "true"
1123 end
1124 action_string = action_string .. " - Bench distance: " .. distance .. " Standing: " .. standing
1125 end
1126 local flag = action.must_happen and " must_happen" or ""
1127 if flag ~= "" then
1128 action_string = action_string .. " " .. flag
1129 end
1130
1131 if i ~= 1 then
1132 result = result .. ", "
1133 end
1134 result = result .. action_string
1135 end
1136 result = result .. "]"
1137 return result
1138 end
1139
1140 --! Unexpects humanoid from a room, if validly entering this room
1141 --!param dest_room (Room) The room the humanoid maybe expected at
1142 function Humanoid:unexpectFromRoom(dest_room)
1143 -- Unexpect the patient from a possible destination room.
1144 if dest_room and dest_room.door.queue then
1145 -- 1st condition checks normal room routing
1146 -- 2nd checks patients going to toilets, doctors and nurses
1147 -- and redundantly checks patients routed between rooms
1148 if self.next_room_to_visit == dest_room or
1149 (dest_room ~= self.next_room_to_visit and (not self:getRoom() or class.is(self, Staff))) then
1150 dest_room.door.queue:unexpect(self)
1151 dest_room.door:updateDynamicInfo()
1152 end
1153 end
1154 end
1155
1156 -- Get attribute value
1157 --!param attribute (string)
1158 --!param default_value (float) Number to return if none found. If neither are present, 0 is returned
1159 --!return (float)
1160 function Humanoid:getAttribute(attribute, default_value)
1161 return self.attributes[attribute] or default_value or 0
1162 end
1163
1164 --! Checks whether a humanoid is within the specified area or is currently
1165 -- walking into it. To properly check whether a humanoid is entering an area,
1166 -- pass coordinates 1 tile outside the square where actually need to build.
1167 -- For example, if the intended wall of the room being built is outside the
1168 -- perimeter (x1, y1) (x2, y2), then need to pass (x1-1, y1-1) (x2+1, y2+1).
1169 -- Example input parameters: (50, 55, 60, 65).
1170 --!param x1 (int) north-west X position of target area.
1171 --!param x2 (int) south-east X position of target area.
1172 --!param y1 (int) north-west Y position of target area.
1173 --!param y2 (int) south-east Y position of target area.
1174 --!return (bool) true if obscuring given area.
1175 function Humanoid:isObscuringArea(x1, x2, y1, y2)
1176 if self.tile_x then
1177 if x1 <= self.tile_x and self.tile_x <= x2 and
1178 y1 <= self.tile_y and self.tile_y <= y2 then
1179 if (x1 == self.tile_x or x2 == self.tile_x) or
1180 (y1 == self.tile_y or y2 == self.tile_y) then
1181 -- Humanoid not in the rectangle, but might be walking into it
1182 local action = self:getCurrentAction()
1183 if action.name ~= "walk" then
1184 return false
1185 end
1186 if action.path_x then -- in a (rare) special case, path_x is nil (see action_walk_start)
1187 local next_x = action.path_x[action.path_index]
1188 local next_y = action.path_y[action.path_index]
1189 if x1 >= next_x or next_x >= x2 or y1 >= next_y or next_y >= y2 then
1190 return false
1191 end
1192 end
1193 end
1194 return true
1195 end
1196 end
1197 return false
1198 end