Skip to content

Commit

Permalink
Changelog.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
dimwit105 committed May 16, 2024
2 parents 0a19e50 + 2f664e7 commit f9a2aba
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 159 deletions.
2 changes: 2 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ Template for new versions:
## New Features

## Fixes
- `item`: don't match uncollected spider webs when you search for "silk"

## Misc Improvements
- `gui/gm-unit`: correctly display skill levels above Legendary+5
- `gui/unit-info-viewer`: now displays a unit's weight, relative to either dwarves, elephants or cats
- `gui/unit-info-viewer`: shows a unit's relative size to its race's average.

Expand Down
13 changes: 2 additions & 11 deletions docs/extinguish.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,14 @@ With this tool, you can put out fires affecting map tiles, plants, units, items,
and buildings.

Select a target in the UI or enable the keyboard cursor place it over the
target unit, building, or tile before running the script.
target tile before running the script.

If your FPS is unplayably low because of the generated smoke, see `clear-smoke`.

Usage
-----

``extinguish``
Put out the selected fire.
Put out the fire affecting the selected unit/item/map tile.
``extinguish --all``
Put out all fires on the map.
``extinguish --location [ <x> <y> <z> ]``
Put out the fire at the specified map coordinates. You can use the
`position` tool to find out what the coordinates under the cursor are.

Examples
--------

``extinguish --location [ 33 41 128 ]``
Put out the fire burning on the surface at position x=33, y=41, z=128.
3 changes: 3 additions & 0 deletions docs/item.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ Options
``--include-owned``
Include items owned by units (e.g., your dwarves or visitors)

``--ignore-webs``
Ignore undisturbed spider webs.

``-i``, ``--inside <burrow>``
Only include items inside the given burrow.

Expand Down
264 changes: 127 additions & 137 deletions extinguish.lua
Original file line number Diff line number Diff line change
@@ -1,183 +1,173 @@
-- Puts out fires.
-- author: Atomic Chicken
--@ module = true

local guidm = require('gui.dwarfmode')
local utils = require('utils')

local validArgs = utils.invert({
'all',
'location',
'help'
'all',
'help'
})
local args = utils.processArgs({...}, validArgs)
local args = utils.processArgs({ ... }, validArgs)

if args.help then
print(dfhack.script_help())
return
end

if args.all and args.location then
qerror('--all and --location cannot be specified together.')
print(dfhack.script_help())
return
end

function extinguishTiletype(tiletype)
if tiletype == df.tiletype['Fire'] or tiletype == df.tiletype['Campfire'] then
return df.tiletype['Ashes'..math.random(1,3)]
elseif tiletype == df.tiletype['BurningTreeTrunk'] then
return df.tiletype['TreeDeadTrunkPillar']
elseif tiletype == df.tiletype['BurningTreeBranches'] then
return df.tiletype['TreeDeadBranches']
elseif tiletype == df.tiletype['BurningTreeTwigs'] then
return df.tiletype['TreeDeadTwigs']
elseif tiletype == df.tiletype['BurningTreeCapWall'] then
return df.tiletype['TreeDeadCapPillar']
elseif tiletype == df.tiletype['BurningTreeCapRamp'] then
return df.tiletype['TreeDeadCapRamp']
elseif tiletype == df.tiletype['BurningTreeCapFloor'] then
return df.tiletype['TreeDeadCapFloor'..math.random(1,4)]
else
return tiletype
end
if tiletype == df.tiletype['Fire'] or tiletype == df.tiletype['Campfire'] then
return df.tiletype['Ashes' .. math.random(1, 3)]
elseif tiletype == df.tiletype['BurningTreeTrunk'] then
return df.tiletype['TreeDeadTrunkPillar']
elseif tiletype == df.tiletype['BurningTreeBranches'] then
return df.tiletype['TreeDeadBranches']
elseif tiletype == df.tiletype['BurningTreeTwigs'] then
return df.tiletype['TreeDeadTwigs']
elseif tiletype == df.tiletype['BurningTreeCapWall'] then
return df.tiletype['TreeDeadCapPillar']
elseif tiletype == df.tiletype['BurningTreeCapRamp'] then
return df.tiletype['TreeDeadCapRamp']
elseif tiletype == df.tiletype['BurningTreeCapFloor'] then
return df.tiletype['TreeDeadCapFloor' .. math.random(1, 4)]
else
return tiletype
end
end

function extinguishTile(x,y,z)
local tileBlock = dfhack.maps.getTileBlock(x,y,z)
tileBlock.tiletype[x%16][y%16] = extinguishTiletype(tileBlock.tiletype[x%16][y%16])
tileBlock.temperature_1[x%16][y%16] = 10050 -- 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_2[x%16][y%16] = 10050
tileBlock.flags.update_temperature = true
tileBlock.flags.update_liquid = true
tileBlock.flags.update_liquid_twice = true
function extinguishTile(x, y, z)
local tileBlock = 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

function extinguishContaminant(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.temperature.whole = 10050
spatter.temperature.fraction = 0
-- 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.temperature.whole = 10050
spatter.temperature.fraction = 0
end

---@param item df.item
function extinguishItem(item)
local item = item --as:df.item_actual
if item.flags.on_fire then
item.flags.on_fire = false
item.temperature.whole = 10050
item.temperature.fraction = 0
item.flags.temps_computed = false
if item.contaminants then
for _,spatter in ipairs(item.contaminants) do
extinguishContaminant(spatter)
end
if item.flags.on_fire then
item.flags.on_fire = false
item.temperature.whole = 10050
item.temperature.fraction = 0
item.flags.temps_computed = false
if item.contaminants then
for _, spatter in ipairs(item.contaminants) do
extinguishContaminant(spatter)
end
end
end
end
end

function extinguishUnit(unit)
-- based on full-heal.lua
local burning = false
for _, status in ipairs(unit.body.components.body_part_status) do
if not burning then
if status.on_fire then
burning = true
status.on_fire = false
end
else
status.on_fire = false
end
end
if burning then
for i = #unit.status2.body_part_temperature-1,0,-1 do
unit.status2.body_part_temperature:erase(i)
local burning = false
for _, status in ipairs(unit.body.components.body_part_status) do
if not burning then
if status.on_fire then
burning = true
status.on_fire = false
end
else
status.on_fire = false
end
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 _,spatter in ipairs(unit.body.spatters) do
extinguishContaminant(spatter)
if burning then
for i = #unit.status2.body_part_temperature - 1, 0, -1 do
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 _, spatter in ipairs(unit.body.spatters) do
extinguishContaminant(spatter)
end
end
end
end

function extinguishAll()
local fires = df.global.world.fires
for i = #fires-1,0,-1 do
extinguishTile(pos2xyz(fires[i].pos))
fires:erase(i)
end
local campfires = df.global.world.campfires
for i = #campfires-1,0,-1 do
extinguishTile(pos2xyz(campfires[i].pos))
campfires:erase(i)
end
for _,plant in ipairs(df.global.world.plants.all) do
plant.damage_flags.is_burning = false
end
for _,item in ipairs(df.global.world.items.other.IN_PLAY) do
extinguishItem(item)
end
for _,unit in ipairs(df.global.world.units.active) do
extinguishUnit(unit)
end
local fires = df.global.world.fires
for i = #fires - 1, 0, -1 do
extinguishTile(pos2xyz(fires[i].pos))
fires:erase(i)
end
local campfires = df.global.world.campfires
for i = #campfires - 1, 0, -1 do
extinguishTile(pos2xyz(campfires[i].pos))
campfires:erase(i)
end
for _, item in ipairs(df.global.world.items.other.IN_PLAY) do
extinguishItem(item)
end
for _, unit in ipairs(df.global.world.units.active) do
extinguishUnit(unit)
end
end

function extinguishLocation(x,y,z)
local pos = xyz2pos(x,y,z)
local fires = df.global.world.fires
for i = #fires-1,0,-1 do
if same_xyz(pos, fires[i].pos) then
extinguishTile(x,y,z)
fires:erase(i)
function extinguishLocation(x, y, z)
local pos = xyz2pos(x, y, z)
local fires = df.global.world.fires
for i = #fires - 1, 0, -1 do
if same_xyz(pos, fires[i].pos) then
extinguishTile(x, y, z)
fires:erase(i)
end
end
local campfires = df.global.world.campfires
for i = #campfires - 1, 0, -1 do
if same_xyz(pos, campfires[i].pos) then
extinguishTile(x, y, z)
campfires:erase(i)
end
end
end
local campfires = df.global.world.campfires
for i = #campfires-1,0,-1 do
if same_xyz(pos, campfires[i].pos) then
extinguishTile(x,y,z)
campfires:erase(i)
local units = dfhack.units.getUnitsInBox(x, y, z, x, y, z)
for _, unit in ipairs(units) do
extinguishUnit(unit)
end
end
local units = dfhack.units.getUnitsInBox(x,y,z,x,y,z)
for _,unit in ipairs(units) do
extinguishUnit(unit)
end
for _,item in ipairs(df.global.world.items.other.IN_PLAY) do
if same_xyz(pos, xyz2pos(dfhack.items.getPosition(item))) then
extinguishItem(item)
for _, item in ipairs(df.global.world.items.other.IN_PLAY) do
if same_xyz(pos, xyz2pos(dfhack.items.getPosition(item))) then
extinguishItem(item)
end
end
end
end

if not dfhack_flags.module then
if args.all then
if dfhack_flags.module then
return
end

if args.all then
extinguishAll()
elseif args.location then
if dfhack.maps.isValidTilePos(args.location[1],args.location[2],args.location[3]) then
extinguishLocation(tonumber(args.location[1]), tonumber(args.location[2]), tonumber(args.location[3]))
else
qerror("Invalid location coordinates!")
end
else
else
local unit = dfhack.gui.getSelectedUnit(true)
local item = dfhack.gui.getSelectedItem(true)
local bld = dfhack.gui.getSelectedBuilding(true)
if unit then
extinguishLocation(dfhack.units.getPosition(unit))
extinguishLocation(dfhack.units.getPosition(unit))
elseif item then
extinguishLocation(dfhack.items.getPosition(item))
extinguishLocation(dfhack.items.getPosition(item))
elseif bld then
for y=bld.y1,bld.y2 do
for x=bld.x1,bld.x2 do
extinguishLocation(x, y, bld.z)
for y = bld.y1, bld.y2 do
for x = bld.x1, bld.x2 do
extinguishLocation(x, y, bld.z)
end
end
end
else
local x,y,z = pos2xyz(df.global.cursor)
if not x then
qerror("Choose a target via the cursor or the --location argument, or specify --all to extinguish everything on the map.")
end
extinguishLocation(x,y,z)
local pos = guidm.getCursorPos()
if not pos then
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
end
12 changes: 3 additions & 9 deletions firestarter.lua
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
--Lights things on fire: items, locations, entire inventories even!
--[====[

firestarter
===========
Lights things on fire: items, locations, entire inventories even! Use while
viewing an item, unit inventory, or tile to start fires.
local guidm = require('gui.dwarfmode')

]====]
if dfhack.gui.getSelectedItem(true) then
dfhack.gui.getSelectedItem(true).flags.on_fire = true
elseif dfhack.gui.getSelectedUnit(true) then
for _, entry in ipairs(dfhack.gui.getSelectedUnit(true).inventory) do
entry.item.flags.on_fire = true
end
elseif df.global.cursor.x ~= -30000 then
local curpos = xyz2pos(pos2xyz(df.global.cursor))
elseif guidm.getCursorPos() then
df.global.world.fires:insert('#', {
new=df.fire,
timer=1000,
pos=curpos,
pos=guidm.getCursorPos(),
inner_temp_cur=60000,
outer_temp_cur=60000,
inner_temp_max=60000,
Expand Down
Loading

0 comments on commit f9a2aba

Please sign in to comment.