diff --git a/scripts/exportlegends.lua b/scripts/exportlegends.lua index 6f5bc84a0..25ee48de6 100644 --- a/scripts/exportlegends.lua +++ b/scripts/exportlegends.lua @@ -72,9 +72,8 @@ function export_more_legends_xml() local day = julian_day % 28 + 1 local year_str = string.format('%0'..math.max(5, string.len(''..df.global.cur_year))..'d', df.global.cur_year) local date_str = year_str..string.format('-%02d-%02d', month, day) - + io.output(tostring(df.global.world.cur_savegame.save_dir).."-"..date_str.."-legends_plus.xml") - --io.output(tostring(df.global.world.cur_savegame.save_dir).."-legends_plus.xml") io.write ("".."\n") io.write ("".."\n") @@ -111,7 +110,7 @@ function export_more_legends_xml() for siteK, siteV in ipairs(df.global.world.world_data.sites) do if (#siteV.buildings > 0) then io.write ("\t".."".."\n") - for k,v in pairs(siteV) do + for k,v in pairs(siteV) do if (k == "id") then io.write ("\t\t".."<"..k..">"..tostring(v).."".."\n") elseif (k == "buildings") then @@ -127,8 +126,7 @@ function export_more_legends_xml() io.write ("\t\t\t".."".."\n") end io.write ("\t\t".."".."\n") - end - + end end io.write ("\t".."".."\n") end @@ -160,10 +158,9 @@ function export_more_legends_xml() io.write ("\t\t"..""..artifactV.item.subtype.name.."".."\n") end end - if (table.containskey(artifactV.item,"description")) then - io.write ("\t\t"..""..artifactV.item.description:lower().."".."\n") - end - + if (table.containskey(artifactV.item,"description")) then + io.write ("\t\t"..""..artifactV.item.description:lower().."".."\n") + end if (artifactV.item:getMaterial() ~= -1 and artifactV.item:getMaterialIndex() ~= -1) then io.write ("\t\t"..""..dfhack.matinfo.toString(dfhack.matinfo.decode(artifactV.item:getMaterial(), artifactV.item:getMaterialIndex())).."".."\n") end @@ -171,8 +168,7 @@ function export_more_legends_xml() end io.write ("".."\n") - io.write ("".."\n") - io.write ("".."\n") + io.write ("".."\n".."".."\n") io.write ("".."\n") for entityPopK, entityPopV in ipairs(df.global.world.entity_populations) do @@ -193,13 +189,13 @@ function export_more_legends_xml() io.write ("\t\t"..""..entityV.id.."".."\n") io.write ("\t\t"..""..(df.global.world.raws.creatures.all[entityV.race].creature_id):lower().."".."\n") io.write ("\t\t"..""..(df.historical_entity_type[entityV.type]):lower().."".."\n") - if (df.historical_entity_type[entityV.type]):lower() == "religion" then -- Get worshipped figure - if (entityV.unknown1b ~= nil and entityV.unknown1b.worship ~= nill and + if (df.historical_entity_type[entityV.type]):lower() == "religion" then -- Get worshipped figure + if (entityV.unknown1b ~= nil and entityV.unknown1b.worship ~= nill and #entityV.unknown1b.worship == 1) then io.write ("\t\t"..""..entityV.unknown1b.worship[0].."".."\n") else print(entityV.unknown1b, entityV.unknown1b.worship, #entityV.unknown1b.worship) - end + end end for id, link in pairs(entityV.entity_links) do io.write ("\t\t".."".."\n") @@ -221,7 +217,7 @@ function export_more_legends_xml() io.write ("".."\n") for ID, event in ipairs(df.global.world.history.events) do - if event:getType() == df.history_event_type.ADD_HF_ENTITY_LINK + if event:getType() == df.history_event_type.ADD_HF_ENTITY_LINK or event:getType() == df.history_event_type.ADD_HF_SITE_LINK or event:getType() == df.history_event_type.ADD_HF_HF_LINK or event:getType() == df.history_event_type.ADD_HF_ENTITY_LINK @@ -263,12 +259,12 @@ function export_more_legends_xml() io.write ("\t".."".."\n") io.write ("\t\t"..""..event.id.."".."\n") io.write ("\t\t"..""..tostring(df.history_event_type[event:getType()]):lower().."".."\n") - for k,v in pairs(event) do - if k == "year" or k == "seconds" or k == "flags" or k == "id" + for k,v in pairs(event) do + if k == "year" or k == "seconds" or k == "flags" or k == "id" or (k == "region" and event:getType() ~= df.history_event_type.HF_DOES_INTERACTION) or k == "region_pos" or k == "layer" or k == "feature_layer" or k == "subregion" or k == "anon_1" or k == "anon_2" or k == "flags2" or k == "unk1" then - + elseif event:getType() == df.history_event_type.ADD_HF_ENTITY_LINK and k == "link_type" then io.write ("\t\t".."<"..k..">"..df.histfig_entity_link_type[v]:lower().."".."\n") elseif event:getType() == df.history_event_type.ADD_HF_ENTITY_LINK and k == "position_id" then @@ -278,11 +274,11 @@ function export_more_legends_xml() if entityPositionsV.id == v then io.write ("\t\t"..""..tostring(entityPositionsV.name[0]):lower().."".."\n") break - end + end end else io.write ("\t\t".."-1".."\n") - end + end elseif event:getType() == df.history_event_type.CREATE_ENTITY_POSITION and k == "position" then local entity = findEntity(event.site_civ) if (entity ~= nil and v > -1) then @@ -290,11 +286,11 @@ function export_more_legends_xml() if entityPositionsV.id == v then io.write ("\t\t"..""..tostring(entityPositionsV.name[0]):lower().."".."\n") break - end + end end else io.write ("\t\t".."-1".."\n") - end + end elseif event:getType() == df.history_event_type.REMOVE_HF_ENTITY_LINK and k == "link_type" then io.write ("\t\t".."<"..k..">"..df.histfig_entity_link_type[v]:lower().."".."\n") elseif event:getType() == df.history_event_type.REMOVE_HF_ENTITY_LINK and k == "position_id" then @@ -304,25 +300,25 @@ function export_more_legends_xml() if entityPositionsV.id == v then io.write ("\t\t"..""..tostring(entityPositionsV.name[0]):lower().."".."\n") break - end + end end else io.write ("\t\t".."-1".."\n") - end + end elseif event:getType() == df.history_event_type.ADD_HF_HF_LINK and k == "type" then io.write ("\t\t"..""..df.histfig_hf_link_type[v]:lower().."".."\n") elseif event:getType() == df.history_event_type.ADD_HF_SITE_LINK and k == "type" then io.write ("\t\t"..""..df.histfig_site_link_type[v]:lower().."".."\n") elseif event:getType() == df.history_event_type.REMOVE_HF_SITE_LINK and k == "type" then io.write ("\t\t"..""..df.histfig_site_link_type[v]:lower().."".."\n") - elseif (event:getType() == df.history_event_type.ITEM_STOLEN or + elseif (event:getType() == df.history_event_type.ITEM_STOLEN or event:getType() == df.history_event_type.MASTERPIECE_CREATED_ITEM or - event:getType() == df.history_event_type.MASTERPIECE_CREATED_ITEM_IMPROVEMENT + event:getType() == df.history_event_type.MASTERPIECE_CREATED_ITEM_IMPROVEMENT ) and k == "item_type" then io.write ("\t\t"..""..df.item_type[v]:lower().."".."\n") - elseif (event:getType() == df.history_event_type.ITEM_STOLEN or + elseif (event:getType() == df.history_event_type.ITEM_STOLEN or event:getType() == df.history_event_type.MASTERPIECE_CREATED_ITEM or - event:getType() == df.history_event_type.MASTERPIECE_CREATED_ITEM_IMPROVEMENT + event:getType() == df.history_event_type.MASTERPIECE_CREATED_ITEM_IMPROVEMENT ) and k == "item_subtype" then --if event.item_type > -1 and v > -1 then io.write ("\t\t".."<"..k..">"..getItemSubTypeName(event.item_type,v).."".."\n") @@ -337,7 +333,7 @@ function export_more_legends_xml() end end elseif (event:getType() == df.history_event_type.MASTERPIECE_CREATED_ITEM or - event:getType() == df.history_event_type.MASTERPIECE_CREATED_ITEM_IMPROVEMENT + event:getType() == df.history_event_type.MASTERPIECE_CREATED_ITEM_IMPROVEMENT ) and k == "mat_type" then if (v > -1) then if (dfhack.matinfo.decode(event.mat_type, event.mat_index) == nil) then @@ -356,37 +352,36 @@ function export_more_legends_xml() io.write ("\t\t"..""..dfhack.matinfo.toString(dfhack.matinfo.decode(event.imp_mat_type, event.imp_mat_index)).."".."\n") end end - + elseif event:getType() == df.history_event_type.ITEM_STOLEN and k == "matindex" then --skip elseif event:getType() == df.history_event_type.ITEM_STOLEN and k == "item" and v == -1 then --skip - elseif (event:getType() == df.history_event_type.MASTERPIECE_CREATED_ITEM or + elseif (event:getType() == df.history_event_type.MASTERPIECE_CREATED_ITEM or event:getType() == df.history_event_type.MASTERPIECE_CREATED_ITEM_IMPROVEMENT ) and k == "mat_index" then --skip elseif event:getType() == df.history_event_type.MASTERPIECE_CREATED_ITEM_IMPROVEMENT and k == "imp_mat_index" then --skip - elseif (event:getType() == df.history_event_type.WAR_PEACE_ACCEPTED or - event:getType() == df.history_event_type.WAR_PEACE_REJECTED or - event:getType() == df.history_event_type.TOPICAGREEMENT_CONCLUDED or - event:getType() == df.history_event_type.TOPICAGREEMENT_REJECTED or - event:getType() == df.history_event_type.TOPICAGREEMENT_MADE + elseif (event:getType() == df.history_event_type.WAR_PEACE_ACCEPTED or + event:getType() == df.history_event_type.WAR_PEACE_REJECTED or + event:getType() == df.history_event_type.TOPICAGREEMENT_CONCLUDED or + event:getType() == df.history_event_type.TOPICAGREEMENT_REJECTED or + event:getType() == df.history_event_type.TOPICAGREEMENT_MADE ) and k == "topic" then io.write ("\t\t"..""..tostring(df.meeting_topic[v]):lower().."".."\n") elseif event:getType() == df.history_event_type.MASTERPIECE_CREATED_ITEM_IMPROVEMENT and k == "improvement_type" then io.write ("\t\t"..""..df.improvement_type[v]:lower().."".."\n") elseif ((event:getType() == df.history_event_type.HIST_FIGURE_REACH_SUMMIT and k == "figures") or - (event:getType() == df.history_event_type.HIST_FIGURE_NEW_PET and k == "group") + (event:getType() == df.history_event_type.HIST_FIGURE_NEW_PET and k == "group") or (event:getType() == df.history_event_type.BODY_ABUSED and k == "bodies")) then - for detailK,detailV in pairs(v) do + for detailK,detailV in pairs(v) do io.write ("\t\t".."<"..k..">"..detailV.."".."\n") end elseif event:getType() == df.history_event_type.HIST_FIGURE_NEW_PET and k == "pets" then for detailK,detailV in pairs(v) do io.write ("\t\t".."<"..k..">"..(df.global.world.raws.creatures.all[detailV].creature_id):lower().."".."\n") end - elseif event:getType() == df.history_event_type.BODY_ABUSED and (k == "props") then io.write ("\t\t".."<"..k.."_item_type"..">"..tostring(df.item_type[event.props.item.item_type]):lower().."".."\n") io.write ("\t\t".."<"..k.."_item_subtype"..">"..getItemSubTypeName(event.props.item.item_type,event.props.item.item_subtype).."".."\n") @@ -397,7 +392,7 @@ function export_more_legends_xml() else io.write ("\t\t"..""..dfhack.matinfo.toString(dfhack.matinfo.decode(event.props.item.mat_type, event.props.item.mat_index)).."".."\n") end - end + end --io.write ("\t\t".."<"..k.."_item_mat_type"..">"..tostring(event.props.item.mat_type).."".."\n") --io.write ("\t\t".."<"..k.."_item_mat_index"..">"..tostring(event.props.item.mat_index).."".."\n") io.write ("\t\t".."<"..k.."_pile_type"..">"..tostring(event.props.pile_type).."".."\n") @@ -421,19 +416,18 @@ function export_more_legends_xml() elseif k == "race" then if v > -1 then io.write ("\t\t"..""..(df.global.world.raws.creatures.all[v].creature_id):lower().."".."\n") - end + end elseif k == "caste" then if v > -1 then io.write ("\t\t"..""..(df.global.world.raws.creatures.all[event.race].caste[v].caste_id):lower().."".."\n") - end + end elseif k == "interaction" and event:getType() == df.history_event_type.HF_DOES_INTERACTION then - io.write ("\t\t"..""..df.global.world.raws.interactions[v].str[3].value.."".."\n") - io.write ("\t\t"..""..df.global.world.raws.interactions[v].str[4].value.."".."\n") + io.write ("\t\t"..""..df.global.world.raws.interactions[v].str[3].value.."".."\n") + io.write ("\t\t"..""..df.global.world.raws.interactions[v].str[4].value.."".."\n") elseif k == "interaction" and event:getType() == df.history_event_type.HF_LEARNS_SECRET then - io.write ("\t\t"..""..df.global.world.raws.interactions[v].str[2].value.."".."\n") + io.write ("\t\t"..""..df.global.world.raws.interactions[v].str[2].value.."".."\n") elseif event:getType() == df.history_event_type.HIST_FIGURE_DIED and k == "weapon" then - for detailK,detailV in pairs(v) do - + for detailK,detailV in pairs(v) do if (detailK == "item") then if detailV > -1 then io.write ("\t\t".."<"..detailK..">"..detailV.."".."\n") @@ -444,11 +438,11 @@ function export_more_legends_xml() if (refv:getType() == 1) then io.write ("\t\t"..""..refv.artifact_id.."".."\n") break - end + end end end end - + end elseif (detailK == "item_type") then if event.weapon.item > -1 then @@ -474,7 +468,7 @@ function export_more_legends_xml() if (refv:getType() == 1) then io.write ("\t\t"..""..refv.artifact_id.."".."\n") break - end + end end end end @@ -492,9 +486,9 @@ function export_more_legends_xml() io.write ("\t\t"..""..dfhack.matinfo.toString(dfhack.matinfo.decode(event.weapon.shooter_mattype, event.weapon.shooter_matindex)).."".."\n") end elseif (detailK == "shooter_matindex") then - + --skip elseif detailK == "slayer_race" or detailK == "slayer_caste" then - + --skip else io.write ("\t\t".."<"..detailK..">"..detailV.."".."\n") end @@ -506,7 +500,6 @@ function export_more_legends_xml() else io.write ("\t\t".."<"..k..">"..tostring(v).."".."\n") end - end io.write ("\t".."".."\n") end @@ -576,11 +569,11 @@ if dfhack.gui.getCurFocus() == "legends" then export_legends_info() export_site_maps() wait_for_legends_vs() - elseif args[1] == "info" then + elseif args[1] == "info" then export_legends_info() - elseif args[1] == "maps" then + elseif args[1] == "maps" then wait_for_legends_vs() - elseif args[1] == "sites" then + elseif args[1] == "sites" then export_site_maps() else dfhack.printerr('Valid arguments are "all", "info", "maps" or "sites"') end