Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 232
Expand file tree
/
Copy pathextinguish.lua
More file actions
Latest commit
173 lines (161 loc) · 5.51 KB
/
Copy pathextinguish.lua
File metadata and controls
173 lines (161 loc) · 5.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
-- Puts out fires.
--@ module = true
localguidm=require('gui.dwarfmode')
localutils=require('utils')
localvalidArgs=utils.invert({
'all',
'help'
})
localargs=utils.processArgs({ ... }, validArgs)
ifargs.helpthen
print(dfhack.script_help())
return
end
functionextinguishTiletype(tiletype)
iftiletype==df.tiletype['Fire'] ortiletype==df.tiletype['Campfire'] then
returndf.tiletype['Ashes' ..math.random(1, 3)]
elseiftiletype==df.tiletype['BurningTreeTrunk'] then
returndf.tiletype['TreeDeadTrunkPillar']
elseiftiletype==df.tiletype['BurningTreeBranches'] then
returndf.tiletype['TreeDeadBranches']
elseiftiletype==df.tiletype['BurningTreeTwigs'] then
returndf.tiletype['TreeDeadTwigs']
elseiftiletype==df.tiletype['BurningTreeCapWall'] then
returndf.tiletype['TreeDeadCapPillar']
elseiftiletype==df.tiletype['BurningTreeCapRamp'] then
returndf.tiletype['TreeDeadCapRamp']
elseiftiletype==df.tiletype['BurningTreeCapFloor'] then
returndf.tiletype['TreeDeadCapFloor' ..math.random(1, 4)]
else
returntiletype
end
end
functionextinguishTile(x, y, z)
localtileBlock=dfhack.maps.getTileBlock(x, y, z)
tileBlock.tiletype[x%16][y%16] =extinguishTiletype(tileBlock.tiletype[x%16][y%16])
-- chosen as a 'standard' value; it'd be more ideal to calculate it with respect to the region,
-- season, undergound status, etc (but DF does this for us when updating temperatures)
tileBlock.temperature_1[x%16][y%16] =10050
tileBlock.temperature_2[x%16][y%16] =10050
tileBlock.flags.update_temperature=true
tileBlock.flags.update_liquid=true
tileBlock.flags.update_liquid_twice=true
end
functionextinguishContaminant(spatter)
-- reset temperature of any contaminants to prevent them from causing reignition
-- (just in case anyone decides to play around with molten gold or whatnot)
spatter.base.temperature.whole=10050
spatter.base.temperature.fraction=0
end
---@paramitemdf.item
functionextinguishItem(item)
ifitem.flags.on_firethen
item.flags.on_fire=false
item.temperature.whole=10050
item.temperature.fraction=0
item.flags.temps_computed=false
ifitem.contaminantsthen
for_, spatterinipairs(item.contaminants) do
extinguishContaminant(spatter)
end
end
end
end
functionextinguishUnit(unit)
localburning=false
for_, statusinipairs(unit.body.components.body_part_status) do
ifnotburningthen
ifstatus.on_firethen
burning=true
status.on_fire=false
end
else
status.on_fire=false
end
end
ifburningthen
fori=#unit.status2.body_part_temperature-1, 0, -1do
unit.status2.body_part_temperature:erase(i)
end
unit.flags2.calculated_nerves=false
unit.flags2.calculated_bodyparts=false
unit.flags2.calculated_insulation=false
unit.flags3.body_temp_in_range=false
unit.flags3.compute_health=true
unit.flags3.dangerous_terrain=false
for_, spatterinipairs(unit.body.spatters) do
extinguishContaminant(spatter)
end
end
end
functionextinguishAll()
localfires=df.global.world.event.fires
fori=#fires-1, 0, -1do
extinguishTile(pos2xyz(fires[i].pos))
fires:erase(i)
end
localcampfires=df.global.world.event.campfires
fori=#campfires-1, 0, -1do
extinguishTile(pos2xyz(campfires[i].pos))
campfires:erase(i)
end
for_, iteminipairs(df.global.world.items.other.IN_PLAY) do
extinguishItem(item)
end
for_, unitinipairs(df.global.world.units.active) do
extinguishUnit(unit)
end
end
functionextinguishLocation(x, y, z)
localpos=xyz2pos(x, y, z)
localfires=df.global.world.event.fires
fori=#fires-1, 0, -1do
ifsame_xyz(pos, fires[i].pos) then
extinguishTile(x, y, z)
fires:erase(i)
end
end
localcampfires=df.global.world.event.campfires
fori=#campfires-1, 0, -1do
ifsame_xyz(pos, campfires[i].pos) then
extinguishTile(x, y, z)
campfires:erase(i)
end
end
localunits=dfhack.units.getUnitsInBox(x, y, z, x, y, z)
for_, unitinipairs(units) do
extinguishUnit(unit)
end
for_, iteminipairs(df.global.world.items.other.IN_PLAY) do
ifsame_xyz(pos, xyz2pos(dfhack.items.getPosition(item))) then
extinguishItem(item)
end
end
end
ifdfhack_flags.modulethen
return
end
ifargs.allthen
extinguishAll()
else
localunit=dfhack.gui.getSelectedUnit(true)
localitem=dfhack.gui.getSelectedItem(true)
localbld=dfhack.gui.getSelectedBuilding(true)
ifunitthen
extinguishLocation(dfhack.units.getPosition(unit))
elseifitemthen
extinguishLocation(dfhack.items.getPosition(item))
elseifbldthen
fory=bld.y1, bld.y2do
forx=bld.x1, bld.x2do
extinguishLocation(x, y, bld.z)
end
end
else
localpos=guidm.getCursorPos()
ifnotposthen
qerror("Select a target, place the keyboard cursor, or specify --all to extinguish everything on the map.")
end
extinguishLocation(pos.x, pos.y, pos.z)
end
end