Skip to content

Instantly share code, notes, and snippets.

@Putnam3145
Last active September 24, 2015 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Putnam3145/d46ffdedb4d335b2ab5a to your computer and use it in GitHub Desktop.
Save Putnam3145/d46ffdedb4d335b2ab5a to your computer and use it in GitHub Desktop.
Outputs a few files containing generated raws.
local creatures = assert(io.open(dfhack.getDFPath()..'/generated_creatures.txt', 'w'))
local items = assert(io.open(dfhack.getDFPath()..'/generated_items.txt', 'w'))
local materials = assert(io.open(dfhack.getDFPath()..'/generated_materials.txt', 'w'))
local entities = assert(io.open(dfhack.getDFPath()..'/generated_entities.txt', 'w'))
local interactions = assert(io.open(dfhack.getDFPath()..'/generated_interactions.txt', 'w'))
local languages = assert(io.open(dfhack.getDFPath()..'/generated_languages.txt', 'w'))
if creatures then
for k,v in ipairs(df.global.world.raws.creatures.all) do
if v.flags.GENERATED then
creatures:write('[CREATURE:'..v.creature_id..']\n')
for kk,vv in ipairs(v.raws) do
creatures:write(' '..vv.value..'\n')
end
end
end
creatures:close()
end
if items then
for k,v in ipairs(df.global.world.raws.itemdefs.all) do
if v.base_flags[0] then --base_flags[0] is GENERATED, but apparently not actually in structures yet
items:write('[ITEM_SOMETHING:'..v.id..']\n') --the way this loop is precludes actually including proper item whosit.
for kk,vv in ipairs(v.raw_strings) do
items:write(' '..vv.value..'\n')
end
end
end
items:close()
end
if materials then
for k,v in ipairs(df.global.world.raws.inorganics) do
if v.flags.GENERATED then
materials:write('[INORGANIC:'..v.id..']\n')
for kk,vv in ipairs(v.str) do
materials:write(' '..vv.value..'\n')
end
end
end
materials:close()
end
if entities then
entities:write('THIS FILE IS INCOMPLETE! Only some of the more interesting stuff is included since the entity raws do not have an exact listing of their raw file in their data structures.\n\n')
for k,v in ipairs(df.global.world.raws.entities) do
if v.flags.GENERATED then
entities:write('[ENTITY:'..v.code..']\n')
--Fun fact: entities do not have a raw listing like other raw objects.
for kk,vv in pairs(v.creatures) do
entities:write(' [CREATURE:'..vv.value..']\n')
end
if v.translation:len()>0 then
entities:write(' [TRANSLATION:'..v.translation..']\n')
end
entities:write(' [ADVENTURE_TIER:'..v.adventure_tier..']\n')
entities:write(' [FRIENDLY_COLOR:'..v.friendly_color[0]..':'..v.friendly_color[1]..':'..v.friendly_color[2]..']\n')
entities:write(' [DEFAULT_SITE_TYPE:'..df.site_type[v.default_site_type]..']\n')
for kk,vv in pairs(v.likes_site) do
if vv==1 then
entities:write(' [LIKES_SITE:'..kk..']\n')
end
end
for kk,vv in pairs(v.tolerates_site) do
if vv==1 then
entities:write(' [TOLERATES_SITE:'..kk..']\n')
end
end
for kk,vv in pairs(v.equipment) do
if tostring(kk):find('_str') then
for kkk,vvv in pairs(vv) do --ahahaha
entities:write(' ['..kk:sub(1,-5):upper()..':'..vvv.value..']\n') --not bothering with rarity cause crap's pretty arcane, moreso than this
end
end
end
for kk,vv in pairs(v.ethic) do
entities:write(' [ETHIC:'..kk..':'..df.ethic_response[vv]..']\n')
end
for kk,vv in pairs(v.values) do
entities:write(' [VALUE:'..kk..':'..vv..']\n')
end
entities:write(' [HFID:'..v.source_hfid..']\n')
for kk,vv in pairs(v.flags) do
if vv then
entities:write(' ['..kk..']\n')
end
end
end
end
entities:close()
end
if interactions then
for k,v in ipairs(df.global.world.raws.interactions) do
if v.flags[0] then --flags[0] is GENERATED
interactions:write('[INTERACTION:'..v.name..']\n')
for kk,vv in ipairs(v.str) do
interactions:write(' '..vv.value..'\n')
end
end
end
interactions:close()
end
if languages then
for k,v in ipairs(df.global.world.raws.language.translations) do
if v.flags%2==1 then --translation.flags isn't a bitfield yet, so I gotta use some binary snazz to get to where I want
languages:write('[TRANSLATION:'..v.name..']\n')
for kk,vv in ipairs(v.str) do
languages:write(' '..vv.value..'\n')
end
end
end
languages:close()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment