df-structures
df-structures copied to clipboard
Site flags research
Reverse engineered a function that finds a site at a tile with certain conditions. Might be useful in determining some site flags. Lua code equivalent here:
function getTileSite(x, y, z, bool_1, bool_2)
--called after masterwork loss event (to find site id) with bool_1 = true and bool_2 = false
local feat_init = --get tile feature_init
local reg_x = world.map.region_x + x/48
local reg_y = world.map.region_y + y/48
local sites = world.world_data.sites
local site = nil
local prev_match = nil
for i = #sites-1, 0, -1 do --iterate sites backwards
site = sites[i]
if not site.flags[10] and (bool_2 or not site.flags[2]) and
reg_x >= site.global_min_x and reg_x <= site.global_max_x and
reg_y >= site.global_min_y and reg_y <= site.global_max_y and
(prev_match == nil or prev_match.flags[7] or (bool_1 == site.flags[7])) then
if feat_init then
if site.is_mountain_halls <= feat_init.end_depth and
site.is_fortress >= feat_init.start_depth then
prev_match = site
end
elseif site.is_mountain_halls <= df.layer_type.Cavern1 then
prev_match = site
end
end
end
return prev_match
end
It also reveals that site.is_mountain_halls and site.is_fortress are "layer_type" values (though the enum size doesn't match.) Function is located at 0x140D864A0 for Windows DF 0.47.05 64-bit.