-
Notifications
You must be signed in to change notification settings - Fork 464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add graphics support for building-hacks #4380
base: develop
Are you sure you want to change the base?
Changes from all commits
534c3d8
f6d4488
939f038
b69fb11
3800286
1983589
48c69be
a59a3d3
d7da17a
39a9489
76b0799
8c45267
dbc9f54
91485c0
e5f7c5b
3d65ad1
01402b2
72c5c63
079bbd1
0c8e3ce
4935331
cf2f18b
13e49e9
5479ed1
5febcdc
22afaa7
9c9e81d
313469b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -5766,82 +5766,134 @@ The names of the functions are also available as the keys of the | |||||||||||
building-hacks | ||||||||||||
============== | ||||||||||||
|
||||||||||||
This plugin overwrites some methods in workshop df class so that mechanical workshops are possible. Although | ||||||||||||
plugin export a function it's recommended to use lua decorated function. | ||||||||||||
This plugin extends DF workshops to support custom powered buildings. | ||||||||||||
|
||||||||||||
.. note:: when using numeric ids for workshops be aware that those id can change between worlds | ||||||||||||
|
||||||||||||
.. contents:: | ||||||||||||
:local: | ||||||||||||
|
||||||||||||
Functions | ||||||||||||
--------- | ||||||||||||
|
||||||||||||
``registerBuilding(table)`` where table must contain name, as a workshop raw name, the rest are optional: | ||||||||||||
* ``setOwnableBuilding(workshop_type)`` | ||||||||||||
|
||||||||||||
Set workshop to be included in zones (such as bedroom or inn). | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why would you choose to include the workshop in zones? What does the choice affect? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It allows for interesting systems: one example i had (before big gui changes etc...) was a personal dwarven hobby workshop that would be built in owned rooms. That way you could query what dwarf owns what buildings (e.g. cabinet, bet, modded-hobby-workshop) and issue jobs that would consume resources, give nothing back, but still level skills. Intended to work as a "do this while dwarf is idle". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be a good idea to always allow the building to be ownable? If in zone, and zone owned, then building owned? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
|
||||||||||||
:workshop_type: custom workshop string id e.g. ``SOAPMAKER`` or numeric id | ||||||||||||
warmist marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
|
||||||||||||
* ``fixImpassible(workshop_type)`` | ||||||||||||
|
||||||||||||
Set workshop non walkable tiles to also block liquids (i.e. water and magma). | ||||||||||||
|
||||||||||||
:workshop_type: custom workshop string id e.g. ``SOAPMAKER`` or numeric id | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
|
||||||||||||
* ``setMachineInfo(workshop_type, needs_power, power_consumed, power_produced, connection_points)`` | ||||||||||||
warmist marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||
|
||||||||||||
Setup and enable machine-like functionality for the workshop. All workshops of this type will have | ||||||||||||
this as default power consumption/production. Note: due to implementation limitations | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
workshop only connects to other machines if the other machine is build later than this one. | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. must they be built after the custom workshop, or planned? is it ok if the other machine is planned before the custom workshop is planned, but then the workshop is built and finally the machine is built? |
||||||||||||
|
||||||||||||
:workshop_type: custom workshop string id e.g. ``SOAPMAKER`` or numeric id | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
:needs_power: only function if it has sufficient power | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
:power_consumed: building consumes this amount of power | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
:power_produced: output this amount of power | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
:connection_points: a table of ``{x=?,y=?}`` zero-based coordinates that can connect to other machines | ||||||||||||
|
||||||||||||
* ``setMachineInfoAuto(workshop_type, needs_power, power_consumed, power_produced, [gear_tiles])`` | ||||||||||||
|
||||||||||||
Same as ``setMachineInfo`` but fills out the ``connection_points`` table from raws placing connection | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
points on tiles which have the gear tile. ``gear_tiles`` is an optional array of two tiles that are | ||||||||||||
myk002 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||
counted as gears in the workshop ascii tile raws. The default gear tiles are ``42`` and ``15``. | ||||||||||||
|
||||||||||||
* ``setAnimationInfo(workshop_type, frames, frame_skip)`` | ||||||||||||
warmist marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||
|
||||||||||||
Animate workshop by replacing displayed tiles (or graphical tiles). There are two ways this works: | ||||||||||||
if ``frame_skip>=0`` then it shows each frame for ``frame_skip`` of frames or if ``frame_skip<0`` | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what does it mean if |
||||||||||||
Frames are synchronized to the machine this building is connected to. | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what if it is connected to multiple machines? |
||||||||||||
|
||||||||||||
:workshop_type: custom workshop string id e.g. ``SOAPMAKER`` or numeric id | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
:frames: table of frames. Each frame is sparse flat table with ids from ``0`` to ``31*31-1``. | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "sparse flat table" is ambiguous here. all other usage in these docs use "table" to mean "list". here, do you mean a sparse map with numeric keys? if an element is finally, is a 0-960 map of elements the best interface for a modder? would it be more natural to express regarding the tile metadata, I suggest using pens instead of a sequence of numbers. E.g. ensure_key(frames, frame_num, row)[col] = dfhack.pen.parse{
tile=dfhack.screen.findGraphicsTile('WARMIST_DRAGON_ENGINE', col, row),
ch=string.byte('['),
fg=COLOR_CYAN,
} How do |
||||||||||||
Each frame tile is table of integers from 4 to 8 members long. Tile members are as | ||||||||||||
follow: ``tile``, ``foreground color``, ``background color``, ``bright``, | ||||||||||||
``graphics tile``, ``overlay tile``, ``signpost tile``, ``item tile``. | ||||||||||||
First 4 are function same as ascii workshop definition. The latter 4 are graphics | ||||||||||||
layers. ``signpost tile`` is an optional row that sticks up over the workshop. | ||||||||||||
|
||||||||||||
:name: | ||||||||||||
custom workshop id e.g. ``SOAPMAKER`` | ||||||||||||
:frame_skip: How many ticks to display one frame. If set to negative number (or skipped) frames | ||||||||||||
are synchronized with machine animation. | ||||||||||||
|
||||||||||||
.. note:: this is the only mandatory field. | ||||||||||||
* ``setAnimationInfoAuto(workshop_type, make_graphics_too, [frame_length], [gear_tiles])`` | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
|
||||||||||||
:fix_impassible: | ||||||||||||
if true make impassable tiles impassable to liquids too | ||||||||||||
:consume: | ||||||||||||
how much machine power is needed to work. | ||||||||||||
Disables reactions if not supplied enough and ``needs_power==1`` | ||||||||||||
:produce: | ||||||||||||
how much machine power is produced. | ||||||||||||
:needs_power: | ||||||||||||
if produced in network < consumed stop working, default true | ||||||||||||
:gears: | ||||||||||||
a table or ``{x=?,y=?}`` of connection points for machines. | ||||||||||||
:action: | ||||||||||||
a table of number (how much ticks to skip) and a function which | ||||||||||||
gets called on shop update | ||||||||||||
:animate: | ||||||||||||
a table of frames which can be a table of: | ||||||||||||
Animate workshop as with function above but generate frames automatically. This works by finding | ||||||||||||
tiles which have gears and animating them with alternating gear tiles. | ||||||||||||
|
||||||||||||
a. tables of 4 numbers ``{tile,fore,back,bright}`` OR | ||||||||||||
b. empty table (tile not modified) OR | ||||||||||||
c. ``{x=<number> y=<number> + 4 numbers like in first case}``, | ||||||||||||
this generates full frame useful for animations that change little (1-2 tiles) | ||||||||||||
:workshop_type: custom workshop string id e.g. ``SOAPMAKER`` or numeric id | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
:make_graphics_too: replace same tiles in graphics mode with tiles from vanilla df mechanism | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. when would you want this set to false? |
||||||||||||
:frame_length: How many ticks to display one frame. If set to negative number (or skipped) frames | ||||||||||||
are synchronized with machine animation. | ||||||||||||
:gear_tiles: Optional array of 2 or 4 indexes. First two define ascii tiles and next two graphics tiles. | ||||||||||||
This overrides default gear tiles. | ||||||||||||
Comment on lines
+5835
to
+5836
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a map might be more instructive instead of a variable length list, e.g.: local bhacks = require('plugins.building-hacks')
bhacks.setAnimationInfoAuto('DRAGON_ENGINE', true, 4, {
gear_ch=42, -- looks for this in ascii
gear_ch_alt=15, -- replaces with this for animated frames
gear_tile=dfhack.screen.findGraphicsTile('WARMIST_DRAGON_ENGINE', 1, 0),
gear_tile_alt=dfhack.screen.findGraphicsTile('WARMIST_DRAGON_ENGINE', 4, 0),
})` |
||||||||||||
|
||||||||||||
:canBeRoomSubset: | ||||||||||||
a flag if this building can be counted in room. 1 means it can, 0 means it can't and -1 default building behaviour | ||||||||||||
:auto_gears: | ||||||||||||
a flag that automatically fills up gears and animations. It looks over the building definition for gear icons and maps them. | ||||||||||||
* ``setOnUpdate(workshop_type,interval,callback)`` | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
|
||||||||||||
Animate table also might contain: | ||||||||||||
Setup callback to be called every ``interval`` of ticks for each building of this type. Note: low interval | ||||||||||||
numbers and/or many workshops that use this might reduce DF performance. | ||||||||||||
Comment on lines
+5840
to
+5841
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you may want to explain the difference between frame ticks and world simulation ticks (and note which one this refers to). |
||||||||||||
|
||||||||||||
:frameLength: | ||||||||||||
how many ticks does one frame take OR | ||||||||||||
:isMechanical: | ||||||||||||
a bool that says to try to match to mechanical system (i.e. how gears are turning) | ||||||||||||
:workshop_type: custom workshop string id e.g. ``SOAPMAKER`` or numeric id | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
:interval: how many ticks to skip between event triggers | ||||||||||||
:callback: function to call. Function signature is ``func(workshop)`` where ``workshop`` is of type | ||||||||||||
``df.building_workshopst`` | ||||||||||||
|
||||||||||||
``getPower(building)`` returns two number - produced and consumed power if building can be modified and returns nothing otherwise | ||||||||||||
* ``getPower(building)`` | ||||||||||||
|
||||||||||||
``setPower(building,produced,consumed)`` sets current power production and consumption for a building. | ||||||||||||
Returns two number - produced and consumed power if building can be modified and returns nothing otherwise. | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
|
||||||||||||
:building: specific workshop that produces or consumes power | ||||||||||||
|
||||||||||||
* ``setPower(building, power_consumed, power_produced)`` | ||||||||||||
|
||||||||||||
Sets current power production and consumption for a specific workshop building. Can be used to make buildings that | ||||||||||||
dynamically change power consumption and production. | ||||||||||||
Comment on lines
+5856
to
+5857
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I note that the order of consumed and produced power is in the opposite order compared to |
||||||||||||
|
||||||||||||
:building: specific workshop that produces or consumes power | ||||||||||||
:power_consumed: set building to consume this amount of power | ||||||||||||
:power_produced: output this amount of power | ||||||||||||
|
||||||||||||
|
||||||||||||
Events | ||||||||||||
------ | ||||||||||||
|
||||||||||||
This module exports two events. However only one is documented here and is intended to be used directly. To use | ||||||||||||
``onUpdateAction`` instead call ``setOnUpdate`` function. | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why does onUpdateAction exist as a Lua event, then? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The plugin lua part still uses that event (i.e. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not convinced this is sufficient reasoning. Why do you need a lua event to communicate with your own Lua layer? Why can't you call the Lua functions directly? |
||||||||||||
|
||||||||||||
* ``onSetTriggerState(workshop,state)`` | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
|
||||||||||||
Notify when building is triggered from linked lever or trap. | ||||||||||||
|
||||||||||||
:workshop: object of type ``df.building_workshopst`` that is triggered. | ||||||||||||
:state: integer value of new state. | ||||||||||||
|
||||||||||||
Examples | ||||||||||||
-------- | ||||||||||||
|
||||||||||||
Simple mechanical workshop:: | ||||||||||||
|
||||||||||||
require('plugins.building-hacks').registerBuilding{name="BONE_GRINDER", | ||||||||||||
consume=15, | ||||||||||||
gears={x=0,y=0}, --connection point | ||||||||||||
animate={ | ||||||||||||
isMechanical=true, --animate the same conn. point as vanilla gear | ||||||||||||
frames={ | ||||||||||||
{{x=0,y=0,42,7,0,0}}, --first frame, 1 changed tile | ||||||||||||
{{x=0,y=0,15,7,0,0}} -- second frame, same | ||||||||||||
local bld=require('plugins.building-hacks') | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||
--work only powered, consume 15 power and one connection point at 0,0 | ||||||||||||
bld.setMachineInfo("BONE_GRINDER",true,15,0,{{x=0,y=0}}) | ||||||||||||
--set animation to switch between gear tiles at 0,0 | ||||||||||||
bld.setAnimationInfo("BONE_GRINDER",{ | ||||||||||||
{[0]={42,7,0,0}}, --first frame, 1 changed tile | ||||||||||||
{[0]={15,7,0,0}} -- second frame, same | ||||||||||||
} | ||||||||||||
} | ||||||||||||
) | ||||||||||||
|
||||||||||||
Or with auto_gears:: | ||||||||||||
|
||||||||||||
require('plugins.building-hacks').registerBuilding{name="BONE_GRINDER", | ||||||||||||
consume=15, | ||||||||||||
auto_gears=true | ||||||||||||
} | ||||||||||||
local bld=require('plugins.building-hacks') | ||||||||||||
bld.setMachineInfoAuto("BONE_GRINDER",true,15) | ||||||||||||
bld.setAnimationInfoAuto("BONE_GRINDER",true) | ||||||||||||
|
||||||||||||
buildingplan | ||||||||||||
============ | ||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.