{"action":"created","comment":{"url":"https://api.github.com/repos/DFHack/dfhack/pulls/comments/51367910","id":51367910,"diff_hunk":"@@ -0,0 +1,192 @@\n+-- Regularly writes extra info to gamelog.txt\n+local help = [[=begin\n+\n+modtools/extra-gamelog\n+======================\n+This script writes extra information to the gamelog.\n+This is useful for tools like :forums:`Soundsense <106497>`.\n+\n+=end]]\n+\n+msg = dfhack.gui.writeToGamelog\n+\n+function log_on_load(op)\n+    if op ~= SC_WORLD_LOADED then return end\n+\n+    -- Seasons fix for Soundsense\n+    local seasons = {\n+        [-1] = 'Nothing', -- worldgen\n+        'Spring',\n+        'Summer',\n+        'Autumn',\n+        'Winter'}\n+    msg(seasons[df.global.cur_season]..' has arrived on the calendar.')\n+\n+    -- Weather fix for Soundsense\n+    local raining = false\n+    local snowing = false\n+    for _, row in ipairs(df.global.current_weather) do\n+        for _, weather in ipairs(row) do\n+            raining = raining or weather == 1\n+            snowing = snowing or weather == 2\n+        end\n+    end\n+    if (not snowing and not raining) then msg(\"The weather has cleared.\")\n+    elseif raining then msg(\"It has started raining.\")\n+    elseif snowing then msg(\"A snow storm has come.\")\n+    end\n+\n+    -- Log site information for forts\n+    if df.world_site.find(df.global.ui.site_id) == nil then return end\n+    local site = df.world_site.find(df.global.ui.site_id)\n+    local fort_ent = df.global.ui.main.fortress_entity\n+    local civ_ent = df.historical_entity.find(df.global.ui.civ_id)\n+    local function fullname(item)\n+        return dfhack.TranslateName(item.name)..' ('..dfhack.TranslateName(item.name ,true)..')'\n+    end\n+    msg('Loaded '..df.global.world.cur_savegame.save_dir..', '..fullname(df.global.world.world_data)..\n+        ' at coordinates ('..site.pos.x..','..site.pos.y..')')\n+    msg('Loaded the fortress '..fullname(site)..\n+        (fort_ent and ', colonized by the group '..fullname(fort_ent) or '')..\n+        (civ_ent and ' of the civilization '..fullname(civ_ent)..'.' or '.'))\n+end\n+\n+\n+old_expedition_leader = nil\n+old_mayor = nil\n+function log_nobles()\n+    local expedition_leader = nil\n+    local mayor = nil\n+    local function check(unit)\n+        if not dfhack.units.isCitizen(unit) then return end\n+        for _, pos in ipairs(dfhack.units.getNoblePositions(unit) or {}) do\n+            if pos.position.name[0] == \"expedition leader\" then\n+                expedition_leader = unit\n+            elseif pos.position.name[0] == \"mayor\" then\n+                mayor = unit\n+            end\n+        end\n+    end\n+    for _, unit in ipairs(df.global.world.units.active) do\n+        check(unit)\n+    end\n+\n+    if old_mayor == nil and expedition_leader == nil and mayor ~= nil and old_expedition_leader ~= nil then\n+        msg(\"Expedition leader was replaced by mayor.\")\n+    end\n+\n+    if expedition_leader ~= old_expedition_leader then\n+        if expedition_leader == nil then\n+            msg(\"Expedition leader position is now vacant.\")\n+        else\n+            msg(dfhack.TranslateName(dfhack.units.getVisibleName(expedition_leader))..\" became expedition leader.\")\n+        end\n+    end\n+\n+    if mayor ~= old_mayor then\n+        if mayor == nil then\n+            msg(\"Mayor position is now vacant.\")\n+        else\n+            msg(dfhack.TranslateName(dfhack.units.getVisibleName(mayor))..\" became mayor.\")\n+        end\n+    end\n+    old_mayor = mayor\n+    old_expedition_leader = expedition_leader\n+end\n+\n+siege = false\n+function log_siege()\n+    local function cur_siege()\n+        for _, unit in ipairs(df.global.world.units.active) do\n+            if unit.flags1.active_invader then return true end\n+        end\n+        return false\n+    end\n+    local old_siege = siege\n+    siege = cur_siege()\n+    if siege ~= old_siege and siege then\n+        msg(\"A vile force of darkness has arrived!\")\n+    elseif siege ~= old_siege and not siege then\n+        msg(\"Siege was broken.\")\n+    end\n+end\n+\n+\n+local workshopTypes = {\n+    [0]=\"Carpenters Workshop\",\n+    \"Farmers Workshop\",\n+    \"Masons Workshop\",\n+    \"Craftsdwarfs Workshop\",\n+    \"Jewelers Workshop\",\n+    \"Metalsmiths Forge\",\n+    \"Magma Forge\",\n+    \"Bowyers Workshop\",\n+    \"Mechanics Workshop\",\n+    \"Siege Workshop\",\n+    \"Butchers Workshop\",\n+    \"Leatherworks Workshop\",\n+    \"Tanners Workshop\",\n+    \"Clothiers Workshop\",\n+    \"Fishery\",\n+    \"Still\",\n+    \"Loom\",\n+    \"Quern\",\n+    \"Kennels\",\n+    \"Kitchen\",\n+    \"Ashery\",\n+    \"Dyers Workshop\",\n+    \"Millstone\",\n+    \"Custom\",\n+    \"Tool\",\n+    }\n+\n+local furnaceTypes = {\n+    [0]=\"Wood Furnace\",\n+    \"Smelter\",\n+    \"Glass Furnace\",\n+    \"Kiln\",\n+    \"Magma Smelter\",\n+    \"Magma Glass Furnace\",\n+    \"Magma Kiln\",\n+    \"Custom Furnace\",\n+    }\n+\n+buildStates = {}\n+\n+function log_buildings()","path":"scripts/modtools/extra-gamelog.lua","position":156,"original_position":156,"commit_id":"9ac9ff15a24899dae0de9f36dd8135a1974fad09","original_commit_id":"9ac9ff15a24899dae0de9f36dd8135a1974fad09","user":{"login":"lethosor","id":3719547,"avatar_url":"https://avatars.githubusercontent.com/u/3719547?v=3","gravatar_id":"","url":"https://api.github.com/users/lethosor","html_url":"https://github.com/lethosor","followers_url":"https://api.github.com/users/lethosor/followers","following_url":"https://api.github.com/users/lethosor/following{/other_user}","gists_url":"https://api.github.com/users/lethosor/gists{/gist_id}","starred_url":"https://api.github.com/users/lethosor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lethosor/subscriptions","organizations_url":"https://api.github.com/users/lethosor/orgs","repos_url":"https://api.github.com/users/lethosor/repos","events_url":"https://api.github.com/users/lethosor/events{/privacy}","received_events_url":"https://api.github.com/users/lethosor/received_events","type":"User","site_admin":false},"body":"This stuff looks new and ought to be mentioned.","created_at":"2016-01-31T21:37:56Z","updated_at":"2016-01-31T21:37:56Z","html_url":"https://github.com/DFHack/dfhack/pull/754#discussion_r51367910","pull_request_url":"https://api.github.com/repos/DFHack/dfhack/pulls/754","_links":{"self":{"href":"https://api.github.com/repos/DFHack/dfhack/pulls/comments/51367910"},"html":{"href":"https://github.com/DFHack/dfhack/pull/754#discussion_r51367910"},"pull_request":{"href":"https://api.github.com/repos/DFHack/dfhack/pulls/754"}}},"pull_request":{"url":"https://api.github.com/repos/DFHack/dfhack/pulls/754","id":51055390,"html_url":"https://github.com/DFHack/dfhack/pull/754","diff_url":"https://github.com/DFHack/dfhack/pull/754.diff","patch_url":"https://github.com/DFHack/dfhack/pull/754.patch","issue_url":"https://api.github.com/repos/DFHack/dfhack/issues/754","number":754,"state":"open","locked":false,"title":"Merge gamelog scripts to modtools/extra-gamelog","user":{"login":"PeridexisErrant","id":5608912,"avatar_url":"https://avatars.githubusercontent.com/u/5608912?v=3","gravatar_id":"","url":"https://api.github.com/users/PeridexisErrant","html_url":"https://github.com/PeridexisErrant","followers_url":"https://api.github.com/users/PeridexisErrant/followers","following_url":"https://api.github.com/users/PeridexisErrant/following{/other_user}","gists_url":"https://api.github.com/users/PeridexisErrant/gists{/gist_id}","starred_url":"https://api.github.com/users/PeridexisErrant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PeridexisErrant/subscriptions","organizations_url":"https://api.github.com/users/PeridexisErrant/orgs","repos_url":"https://api.github.com/users/PeridexisErrant/repos","events_url":"https://api.github.com/users/PeridexisErrant/events{/privacy}","received_events_url":"https://api.github.com/users/PeridexisErrant/received_events","type":"User","site_admin":false},"body":"Combining `log-region` and `soundsense-season` with most of the actual `soundsense` script.  Keeping this in one place makes sense to me, and makes life easier for users of other tools such as Soundsense.","created_at":"2015-11-18T08:33:37Z","updated_at":"2016-01-31T21:37:56Z","closed_at":null,"merged_at":null,"merge_commit_sha":"35a71cc79b89f521efc38826b516ef2062fc2cce","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/DFHack/dfhack/pulls/754/commits","review_comments_url":"https://api.github.com/repos/DFHack/dfhack/pulls/754/comments","review_comment_url":"https://api.github.com/repos/DFHack/dfhack/pulls/comments{/number}","comments_url":"https://api.github.com/repos/DFHack/dfhack/issues/754/comments","statuses_url":"https://api.github.com/repos/DFHack/dfhack/statuses/9ac9ff15a24899dae0de9f36dd8135a1974fad09","head":{"label":"PeridexisErrant:better-gamelog","ref":"better-gamelog","sha":"9ac9ff15a24899dae0de9f36dd8135a1974fad09","user":{"login":"PeridexisErrant","id":5608912,"avatar_url":"https://avatars.githubusercontent.com/u/5608912?v=3","gravatar_id":"","url":"https://api.github.com/users/PeridexisErrant","html_url":"https://github.com/PeridexisErrant","followers_url":"https://api.github.com/users/PeridexisErrant/followers","following_url":"https://api.github.com/users/PeridexisErrant/following{/other_user}","gists_url":"https://api.github.com/users/PeridexisErrant/gists{/gist_id}","starred_url":"https://api.github.com/users/PeridexisErrant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PeridexisErrant/subscriptions","organizations_url":"https://api.github.com/users/PeridexisErrant/orgs","repos_url":"https://api.github.com/users/PeridexisErrant/repos","events_url":"https://api.github.com/users/PeridexisErrant/events{/privacy}","received_events_url":"https://api.github.com/users/PeridexisErrant/received_events","type":"User","site_admin":false},"repo":{"id":19444099,"name":"dfhack","full_name":"PeridexisErrant/dfhack","owner":{"login":"PeridexisErrant","id":5608912,"avatar_url":"https://avatars.githubusercontent.com/u/5608912?v=3","gravatar_id":"","url":"https://api.github.com/users/PeridexisErrant","html_url":"https://github.com/PeridexisErrant","followers_url":"https://api.github.com/users/PeridexisErrant/followers","following_url":"https://api.github.com/users/PeridexisErrant/following{/other_user}","gists_url":"https://api.github.com/users/PeridexisErrant/gists{/gist_id}","starred_url":"https://api.github.com/users/PeridexisErrant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PeridexisErrant/subscriptions","organizations_url":"https://api.github.com/users/PeridexisErrant/orgs","repos_url":"https://api.github.com/users/PeridexisErrant/repos","events_url":"https://api.github.com/users/PeridexisErrant/events{/privacy}","received_events_url":"https://api.github.com/users/PeridexisErrant/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/PeridexisErrant/dfhack","description":"Memory hacking library for Dwarf Fortress and a set of tools that use it","fork":true,"url":"https://api.github.com/repos/PeridexisErrant/dfhack","forks_url":"https://api.github.com/repos/PeridexisErrant/dfhack/forks","keys_url":"https://api.github.com/repos/PeridexisErrant/dfhack/keys{/key_id}","collaborators_url":"https://api.github.com/repos/PeridexisErrant/dfhack/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/PeridexisErrant/dfhack/teams","hooks_url":"https://api.github.com/repos/PeridexisErrant/dfhack/hooks","issue_events_url":"https://api.github.com/repos/PeridexisErrant/dfhack/issues/events{/number}","events_url":"https://api.github.com/repos/PeridexisErrant/dfhack/events","assignees_url":"https://api.github.com/repos/PeridexisErrant/dfhack/assignees{/user}","branches_url":"https://api.github.com/repos/PeridexisErrant/dfhack/branches{/branch}","tags_url":"https://api.github.com/repos/PeridexisErrant/dfhack/tags","blobs_url":"https://api.github.com/repos/PeridexisErrant/dfhack/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/PeridexisErrant/dfhack/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/PeridexisErrant/dfhack/git/refs{/sha}","trees_url":"https://api.github.com/repos/PeridexisErrant/dfhack/git/trees{/sha}","statuses_url":"https://api.github.com/repos/PeridexisErrant/dfhack/statuses/{sha}","languages_url":"https://api.github.com/repos/PeridexisErrant/dfhack/languages","stargazers_url":"https://api.github.com/repos/PeridexisErrant/dfhack/stargazers","contributors_url":"https://api.github.com/repos/PeridexisErrant/dfhack/contributors","subscribers_url":"https://api.github.com/repos/PeridexisErrant/dfhack/subscribers","subscription_url":"https://api.github.com/repos/PeridexisErrant/dfhack/subscription","commits_url":"https://api.github.com/repos/PeridexisErrant/dfhack/commits{/sha}","git_commits_url":"https://api.github.com/repos/PeridexisErrant/dfhack/git/commits{/sha}","comments_url":"https://api.github.com/repos/PeridexisErrant/dfhack/comments{/number}","issue_comment_url":"https://api.github.com/repos/PeridexisErrant/dfhack/issues/comments{/number}","contents_url":"https://api.github.com/repos/PeridexisErrant/dfhack/contents/{+path}","compare_url":"https://api.github.com/repos/PeridexisErrant/dfhack/compare/{base}...{head}","merges_url":"https://api.github.com/repos/PeridexisErrant/dfhack/merges","archive_url":"https://api.github.com/repos/PeridexisErrant/dfhack/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/PeridexisErrant/dfhack/downloads","issues_url":"https://api.github.com/repos/PeridexisErrant/dfhack/issues{/number}","pulls_url":"https://api.github.com/repos/PeridexisErrant/dfhack/pulls{/number}","milestones_url":"https://api.github.com/repos/PeridexisErrant/dfhack/milestones{/number}","notifications_url":"https://api.github.com/repos/PeridexisErrant/dfhack/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/PeridexisErrant/dfhack/labels{/name}","releases_url":"https://api.github.com/repos/PeridexisErrant/dfhack/releases{/id}","deployments_url":"https://api.github.com/repos/PeridexisErrant/dfhack/deployments","created_at":"2014-05-05T04:42:25Z","updated_at":"2015-11-01T02:59:57Z","pushed_at":"2015-12-04T12:07:45Z","git_url":"git://github.com/PeridexisErrant/dfhack.git","ssh_url":"git@github.com:PeridexisErrant/dfhack.git","clone_url":"https://github.com/PeridexisErrant/dfhack.git","svn_url":"https://github.com/PeridexisErrant/dfhack","homepage":"","size":20092,"stargazers_count":2,"watchers_count":2,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":2,"default_branch":"master"}},"base":{"label":"DFHack:develop","ref":"develop","sha":"67aed5618385bb023e0e0e4e43c3b9d74bd75012","user":{"login":"DFHack","id":5777323,"avatar_url":"https://avatars.githubusercontent.com/u/5777323?v=3","gravatar_id":"","url":"https://api.github.com/users/DFHack","html_url":"https://github.com/DFHack","followers_url":"https://api.github.com/users/DFHack/followers","following_url":"https://api.github.com/users/DFHack/following{/other_user}","gists_url":"https://api.github.com/users/DFHack/gists{/gist_id}","starred_url":"https://api.github.com/users/DFHack/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DFHack/subscriptions","organizations_url":"https://api.github.com/users/DFHack/orgs","repos_url":"https://api.github.com/users/DFHack/repos","events_url":"https://api.github.com/users/DFHack/events{/privacy}","received_events_url":"https://api.github.com/users/DFHack/received_events","type":"Organization","site_admin":false},"repo":{"id":517990,"name":"dfhack","full_name":"DFHack/dfhack","owner":{"login":"DFHack","id":5777323,"avatar_url":"https://avatars.githubusercontent.com/u/5777323?v=3","gravatar_id":"","url":"https://api.github.com/users/DFHack","html_url":"https://github.com/DFHack","followers_url":"https://api.github.com/users/DFHack/followers","following_url":"https://api.github.com/users/DFHack/following{/other_user}","gists_url":"https://api.github.com/users/DFHack/gists{/gist_id}","starred_url":"https://api.github.com/users/DFHack/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DFHack/subscriptions","organizations_url":"https://api.github.com/users/DFHack/orgs","repos_url":"https://api.github.com/users/DFHack/repos","events_url":"https://api.github.com/users/DFHack/events{/privacy}","received_events_url":"https://api.github.com/users/DFHack/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/DFHack/dfhack","description":"Memory hacking library for Dwarf Fortress and a set of tools that use it","fork":false,"url":"https://api.github.com/repos/DFHack/dfhack","forks_url":"https://api.github.com/repos/DFHack/dfhack/forks","keys_url":"https://api.github.com/repos/DFHack/dfhack/keys{/key_id}","collaborators_url":"https://api.github.com/repos/DFHack/dfhack/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/DFHack/dfhack/teams","hooks_url":"https://api.github.com/repos/DFHack/dfhack/hooks","issue_events_url":"https://api.github.com/repos/DFHack/dfhack/issues/events{/number}","events_url":"https://api.github.com/repos/DFHack/dfhack/events","assignees_url":"https://api.github.com/repos/DFHack/dfhack/assignees{/user}","branches_url":"https://api.github.com/repos/DFHack/dfhack/branches{/branch}","tags_url":"https://api.github.com/repos/DFHack/dfhack/tags","blobs_url":"https://api.github.com/repos/DFHack/dfhack/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/DFHack/dfhack/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/DFHack/dfhack/git/refs{/sha}","trees_url":"https://api.github.com/repos/DFHack/dfhack/git/trees{/sha}","statuses_url":"https://api.github.com/repos/DFHack/dfhack/statuses/{sha}","languages_url":"https://api.github.com/repos/DFHack/dfhack/languages","stargazers_url":"https://api.github.com/repos/DFHack/dfhack/stargazers","contributors_url":"https://api.github.com/repos/DFHack/dfhack/contributors","subscribers_url":"https://api.github.com/repos/DFHack/dfhack/subscribers","subscription_url":"https://api.github.com/repos/DFHack/dfhack/subscription","commits_url":"https://api.github.com/repos/DFHack/dfhack/commits{/sha}","git_commits_url":"https://api.github.com/repos/DFHack/dfhack/git/commits{/sha}","comments_url":"https://api.github.com/repos/DFHack/dfhack/comments{/number}","issue_comment_url":"https://api.github.com/repos/DFHack/dfhack/issues/comments{/number}","contents_url":"https://api.github.com/repos/DFHack/dfhack/contents/{+path}","compare_url":"https://api.github.com/repos/DFHack/dfhack/compare/{base}...{head}","merges_url":"https://api.github.com/repos/DFHack/dfhack/merges","archive_url":"https://api.github.com/repos/DFHack/dfhack/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/DFHack/dfhack/downloads","issues_url":"https://api.github.com/repos/DFHack/dfhack/issues{/number}","pulls_url":"https://api.github.com/repos/DFHack/dfhack/pulls{/number}","milestones_url":"https://api.github.com/repos/DFHack/dfhack/milestones{/number}","notifications_url":"https://api.github.com/repos/DFHack/dfhack/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/DFHack/dfhack/labels{/name}","releases_url":"https://api.github.com/repos/DFHack/dfhack/releases{/id}","deployments_url":"https://api.github.com/repos/DFHack/dfhack/deployments","created_at":"2010-02-14T21:09:49Z","updated_at":"2016-01-31T13:01:18Z","pushed_at":"2016-01-31T21:26:57Z","git_url":"git://github.com/DFHack/dfhack.git","ssh_url":"git@github.com:DFHack/dfhack.git","clone_url":"https://github.com/DFHack/dfhack.git","svn_url":"https://github.com/DFHack/dfhack","homepage":"","size":25906,"stargazers_count":477,"watchers_count":477,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":222,"mirror_url":null,"open_issues_count":75,"forks":222,"open_issues":75,"watchers":477,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/DFHack/dfhack/pulls/754"},"html":{"href":"https://github.com/DFHack/dfhack/pull/754"},"issue":{"href":"https://api.github.com/repos/DFHack/dfhack/issues/754"},"comments":{"href":"https://api.github.com/repos/DFHack/dfhack/issues/754/comments"},"review_comments":{"href":"https://api.github.com/repos/DFHack/dfhack/pulls/754/comments"},"review_comment":{"href":"https://api.github.com/repos/DFHack/dfhack/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/DFHack/dfhack/pulls/754/commits"},"statuses":{"href":"https://api.github.com/repos/DFHack/dfhack/statuses/9ac9ff15a24899dae0de9f36dd8135a1974fad09"}}}}