| 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 TH = require("TH") |
| 22 |
|
| 23 |
local object = {} |
| 24 |
object.id = "litter" |
| 25 |
object.thob = 62 -- previously unused |
| 26 |
object.name = _S.object.litter -- currently not shown anywhere |
| 27 |
object.tooltip = _S.tooltip.objects.litter -- currently not shown anywhere |
| 28 |
object.ticks = false |
| 29 |
object.class = "Litter" |
| 30 |
|
| 31 |
local litter_types = {} |
| 32 |
|
| 33 |
-- All types of "litter", i.e. small objects on the ground or walls. |
| 34 |
litter_types["pee"] = 2248 |
| 35 |
litter_types["dead_rat"] = 2242 |
| 36 |
litter_types["puke"] = 2060 |
| 37 |
litter_types["soda_can"] = 1894 |
| 38 |
litter_types["banana"] = 1896 |
| 39 |
litter_types["paper"] = 1898 |
| 40 |
litter_types["bottle"] = 1900 |
| 41 |
litter_types["soot_floor"] = 3416 |
| 42 |
litter_types["soot_wall"] = 3408 |
| 43 |
litter_types["soot_window"] = 3412 |
| 44 |
|
| 45 |
-- When randomising litter, only these should come up. |
| 46 |
litter_types[1] = 1894 |
| 47 |
litter_types[2] = 1896 |
| 48 |
litter_types[3] = 1898 |
| 49 |
litter_types[4] = 1900 |
| 50 |
|
| 51 |
class "Litter" (Entity) |
| 52 |
|
| 53 |
---@type Litter |
| 54 |
local Litter = _G["Litter"] |
| 55 |
|
| 56 |
function Litter:Litter(hospital, object_type, x, y) |
| 57 |
local th = TH.animation() |
| 58 |
self:Entity(th) |
| 59 |
self.ticks = object_type.ticks |
| 60 |
self.object_type = object_type |
| 61 |
self.hospital = hospital |
| 62 |
self.world = hospital.world |
| 63 |
self:setTile(x, y) |
| 64 |
end |
| 65 |
|
| 66 |
function Litter:setTile(x, y) |
| 67 |
Entity.setTile(self, x, y) |
| 68 |
if x then |
| 69 |
self.world:addObjectToTile(self, x, y) |
| 70 |
end |
| 71 |
end |
| 72 |
-- Litter is an Entity and not an Object so it does not inherit this method |
| 73 |
-- This is an (effective) hack, see issue 918 --cgj |
| 74 |
function Litter:getWalkableTiles() |
| 75 |
--emulate Object:getWalkableTiles() and return the tile (x,y) |
| 76 |
local tiles = {} |
| 77 |
tiles[0] = { self.tile_x, self.tile_y } |
| 78 |
return tiles |
| 79 |
end |
| 80 |
|
| 81 |
function Litter:setLitterType(anim_type, mirrorFlag) |
| 82 |
if anim_type then |
| 83 |
local anim = litter_types[anim_type] |
| 84 |
if anim then |
| 85 |
self:setAnimation(anim, mirrorFlag) |
| 86 |
else |
| 87 |
error("Unknown litter type") |
| 88 |
end |
| 89 |
if self:isCleanable() then |
| 90 |
self.hospital:addHandymanTask(self, "cleaning", 1, self.tile_x, self.tile_y) |
| 91 |
end |
| 92 |
end |
| 93 |
end |
| 94 |
|
| 95 |
--! Remove the litter from the world. |
| 96 |
function Litter:remove() |
| 97 |
assert(self:isCleanable() or TheApp.config.remove_destroyed_rooms) |
| 98 |
|
| 99 |
if self.tile_x then |
| 100 |
self.world:removeObjectFromTile(self, self.tile_x, self.tile_y) |
| 101 |
|
| 102 |
local taskIndex = self.hospital:getIndexOfTask(self.tile_x, self.tile_y, "cleaning", self) |
| 103 |
self.hospital:removeHandymanTask(taskIndex, "cleaning") |
| 104 |
else |
| 105 |
print("Warning: Removing litter that has already been removed.") |
| 106 |
end |
| 107 |
self.world:destroyEntity(self) |
| 108 |
end |
| 109 |
|
| 110 |
function Litter:getDrawingLayer() |
| 111 |
return DrawingLayers.Litter |
| 112 |
end |
| 113 |
|
| 114 |
function Litter:vomitInducing() |
| 115 |
local anim = self.animation_idx |
| 116 |
if anim == litter_types["puke"] or |
| 117 |
anim == litter_types["pee"] or |
| 118 |
anim == litter_types["dead_rat"] then |
| 119 |
return true |
| 120 |
end |
| 121 |
return false |
| 122 |
end |
| 123 |
|
| 124 |
function Litter:isCleanable() |
| 125 |
return self:vomitInducing() or self:anyLitter() |
| 126 |
end |
| 127 |
|
| 128 |
function Litter:anyLitter() |
| 129 |
local anim = self.animation_idx |
| 130 |
if anim == litter_types["soda_can"] or |
| 131 |
anim == litter_types["banana"] or |
| 132 |
anim == litter_types["paper"] or |
| 133 |
anim == litter_types["bottle"] then |
| 134 |
return true |
| 135 |
end |
| 136 |
return false |
| 137 |
end |
| 138 |
|
| 139 |
function Litter:afterLoad(old, new) |
| 140 |
if old < 52 then |
| 141 |
if self.tile_x then |
| 142 |
self.hospital:addHandymanTask(self, "cleaning", 1, self.tile_x, self.tile_y) |
| 143 |
else |
| 144 |
-- This object was not properly removed from the world. |
| 145 |
self.world:destroyEntity(self) |
| 146 |
end |
| 147 |
end |
| 148 |
if old < 54 then |
| 149 |
if not self:isCleanable() then |
| 150 |
local taskIndex = self.hospital:getIndexOfTask(self.tile_x, self.tile_y, "cleaning", self) |
| 151 |
self.hospital:removeHandymanTask(taskIndex, "cleaning") |
| 152 |
end |
| 153 |
end |
| 154 |
|
| 155 |
if old < 121 then |
| 156 |
self.ticks = object.ticks |
| 157 |
end |
| 158 |
|
| 159 |
if old < 151 then |
| 160 |
self.hospital = self.world:getHospital(self.tile_x, self.tile_y) |
| 161 |
end |
| 162 |
if old < 162 then |
| 163 |
-- Afterload 151 could cause nil hospital if the litter was outside it. |
| 164 |
-- For ease, remove affected litter |
| 165 |
if not self.hospital then |
| 166 |
self.hospital = TheApp.world:getLocalPlayerHospital() |
| 167 |
self:remove() |
| 168 |
end |
| 169 |
end |
| 170 |
Entity.afterLoad(self, old, new) |
| 171 |
end |
| 172 |
|
| 173 |
return object |