{"action":"created","comment":{"url":"https://api.github.com/repos/DFHack/dfhack/pulls/comments/60234976","id":60234976,"diff_hunk":"@@ -0,0 +1,94 @@\n+-- Allow humans to make trade agreements\n+--[[=begin\n+\n+fix/merchants\n+=============\n+Adds the Guild Representative position to all Human civilizations,\n+allowing them to make trade agreements.  This was the default behaviour in\n+``0.28.181.40d`` and earlier.\n+\n+=end]]\n+checked = 0\n+fixed = 0\n+\n+function add_guild_rep(pos, ent)\n+    -- there was no guild rep - create it\n+    pos = df.entity_position:new()\n+    ent.positions.own:insert(0, pos)\n+\n+    pos.code = \"GUILD_REPRESENTATIVE\"\n+    pos.id = ent.positions.next_position_id + 1\n+    pos.flags.DO_NOT_CULL = true\n+    pos.flags.MENIAL_WORK_EXEMPTION = true\n+    pos.flags.SLEEP_PRETENSION = true\n+    pos.flags.PUNISHMENT_EXEMPTION = true\n+    pos.flags.ACCOUNT_EXEMPT = true\n+    pos.flags.DUTY_BOUND = true\n+    pos.flags.COLOR = true\n+    pos.flags.HAS_RESPONSIBILITIES = true\n+    pos.flags.IS_DIPLOMAT = true\n+    pos.flags.IS_LEADER = true\n+    -- not sure what these flags do, but the game sets them for a valid guild rep\n+    pos.flags.unk_12 = true\n+    pos.flags.unk_1a = true\n+    pos.flags.unk_1b = true\n+    pos.name[0] = \"Guild Representative\"\n+    pos.name[1] = \"Guild Representatives\"\n+    pos.precedence = 40\n+    pos.color[0] = 7\n+    pos.color[1] = 0\n+    pos.color[2] = 1\n+    return pos\n+end\n+\n+\n+for _,ent in pairs(df.global.world.entities.all) do\n+    if ent.type == 0 and ent.entity_raw.flags.MERCHANT_NOBILITY then\n+        checked = checked + 1\n+\n+        update = true\n+        -- see if we need to add a new position or modify an existing one\n+        for _,pos in pairs(ent.positions.own) do\n+            if pos.responsibilities.TRADE then\n+                -- a guild rep exists with the proper responsibilities - skip to the end\n+                update = false\n+                break\n+            end\n+            -- Guild Representative position already exists, but has the wrong options - modify it instead of creating a new one\n+            if pos.code == \"GUILD_REPRESENTATIVE\" then break end\n+            pos = nil\n+        end\n+        if update then\n+            -- either there's no guild rep, or there is one and it's got the wrong responsibilities\n+            if not pos then\n+                pos = add_guild_rep(pos, ent)\n+            end\n+            -- assign responsibilities\n+            pos.responsibilities.ESTABLISH_COLONY_TRADE_AGREEMENTS = true\n+        end\n+\n+        -- make sure the guild rep position, whether we created it or not, is set up for proper assignment\n+        assign = true\n+        for _,p in pairs(ent.positions.assignments) do\n+            if p.position_id == pos.id then -- it is - nothing more to do here\n+                assign = false\n+                break\n+            end\n+        end\n+        if assign then\n+            -- it isn't - set it up\n+            asn = df.entity_position_assignment:new()\n+            ent.positions.assignments:insert(0, asn)\n+\n+            asn.id = ent.positions.next_assignment_id + 1\n+            asn.position_id = pos.id\n+            --asn.flags:extend(32) -- make room for 32 flags","path":"scripts/fix/merchants.lua","position":85,"original_position":85,"commit_id":"e60d07bce9a90f2453f3579f81d19e79c2c6e072","original_commit_id":"e60d07bce9a90f2453f3579f81d19e79c2c6e072","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":"What's this?","created_at":"2016-04-19T13:55:29Z","updated_at":"2016-04-19T13:55:29Z","html_url":"https://github.com/DFHack/dfhack/pull/901#discussion_r60234976","pull_request_url":"https://api.github.com/repos/DFHack/dfhack/pulls/901","_links":{"self":{"href":"https://api.github.com/repos/DFHack/dfhack/pulls/comments/60234976"},"html":{"href":"https://github.com/DFHack/dfhack/pull/901#discussion_r60234976"},"pull_request":{"href":"https://api.github.com/repos/DFHack/dfhack/pulls/901"}}},"pull_request":{"url":"https://api.github.com/repos/DFHack/dfhack/pulls/901","id":67005577,"html_url":"https://github.com/DFHack/dfhack/pull/901","diff_url":"https://github.com/DFHack/dfhack/pull/901.diff","patch_url":"https://github.com/DFHack/dfhack/pull/901.patch","issue_url":"https://api.github.com/repos/DFHack/dfhack/issues/901","number":901,"state":"open","locked":false,"title":"Replace fixpositions plugin with scripts","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":"See issue #722 \r\n\r\nThe new scripts *seem* to work, but I'm still not confident in my ability to write working lua.  If someone could check that they seem ok and/or do some more playtesting, that would be great.","created_at":"2016-04-19T11:58:34Z","updated_at":"2016-04-19T13:55:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6e682722722369aea317580b1523b1cffada2f0d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/DFHack/dfhack/pulls/901/commits","review_comments_url":"https://api.github.com/repos/DFHack/dfhack/pulls/901/comments","review_comment_url":"https://api.github.com/repos/DFHack/dfhack/pulls/comments{/number}","comments_url":"https://api.github.com/repos/DFHack/dfhack/issues/901/comments","statuses_url":"https://api.github.com/repos/DFHack/dfhack/statuses/e60d07bce9a90f2453f3579f81d19e79c2c6e072","head":{"label":"PeridexisErrant:fixpositions","ref":"fixpositions","sha":"e60d07bce9a90f2453f3579f81d19e79c2c6e072","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":"2016-02-01T05:40:37Z","pushed_at":"2016-04-19T11:57:26Z","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":20780,"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":"50f28517722592ff1dbd7deaedd0288a35c24f62","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-04-19T03:39:05Z","pushed_at":"2016-04-19T13:45:45Z","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":25014,"stargazers_count":508,"watchers_count":508,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":222,"mirror_url":null,"open_issues_count":120,"forks":222,"open_issues":120,"watchers":508,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/DFHack/dfhack/pulls/901"},"html":{"href":"https://github.com/DFHack/dfhack/pull/901"},"issue":{"href":"https://api.github.com/repos/DFHack/dfhack/issues/901"},"comments":{"href":"https://api.github.com/repos/DFHack/dfhack/issues/901/comments"},"review_comments":{"href":"https://api.github.com/repos/DFHack/dfhack/pulls/901/comments"},"review_comment":{"href":"https://api.github.com/repos/DFHack/dfhack/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/DFHack/dfhack/pulls/901/commits"},"statuses":{"href":"https://api.github.com/repos/DFHack/dfhack/statuses/e60d07bce9a90f2453f3579f81d19e79c2c6e072"}}}}