{"action":"created","comment":{"url":"https://api.github.com/repos/freeorion/freeorion/pulls/comments/214291557","pull_request_review_id":151316508,"id":214291557,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIxNDI5MTU1Nw==","diff_hunk":"@@ -0,0 +1,150 @@\n+#include \"CombatTargetting.h\"\n+\n+#include \"../universe/Condition.h\"\n+#include \"../universe/Enums.h\"\n+#include \"../universe/Planet.h\"\n+#include \"../universe/Fleet.h\"\n+#include \"../universe/Ship.h\"\n+#include \"../universe/ShipDesign.h\"\n+#include \"../universe/Fighter.h\"\n+#include \"../universe/ValueRef.h\"\n+\n+#include \"../util/Logger.h\"\n+#include \"../util/Random.h\"\n+\n+bool Targetting::isPreferredTarget(Targetting::TriggerConditions conditions,\n+                                   Targetting::Target target) {\n+    const Precision highest_weight = Targetting::findPrecision(conditions);\n+    for (long unsigned int i = 0; i < conditions.conditions.size(); i++) {\n+        const auto& condition = conditions.conditions[i];\n+        if (!condition) {\n+            DebugLogger() << \"No preferences. Target is perfect.\" ;\n+            return true;\n+        }\n+\n+        if (Targetting::isPreferredTarget(condition, target)) {\n+            const int upper = std::round(highest_weight * 1.5f); // HEURISTIC\n+            const int improbability = RandInt(0, upper);\n+            const int luck = conditions.weights[i];\n+            DebugLogger() << \"Prioritized locking attempt\" <<  [&improbability, &luck, &upper](){\n+                                                                   std::stringstream ss;\n+                                                                   ss << \"( \" << luck << \"/\" << upper << \" ?>? \" << improbability << \"/\" << upper << \")\";\n+                                                                   return ss.str();\n+                                                               }();\n+            if (luck > improbability) {\n+                DebugLogger() << \"Locked in target.\";\n+                return true;\n+            } else {\n+                DebugLogger() << \"Couldnt acquire lock.\" ;\n+            }\n+        }\n+    }\n+    return false;\n+}\n+\n+bool Targetting::isPreferredTarget(Targetting::TriggerCondition condition,\n+                                   Targetting::Target target) {","path":"combat/CombatTargetting.cpp","position":46,"original_position":46,"commit_id":"626a980b51231653a993b751b3b4fd812d55f871","original_commit_id":"626a980b51231653a993b751b3b4fd812d55f871","user":{"login":"geoffthemedio","id":11386908,"node_id":"MDQ6VXNlcjExMzg2OTA4","avatar_url":"https://avatars1.githubusercontent.com/u/11386908?v=4","gravatar_id":"","url":"https://api.github.com/users/geoffthemedio","html_url":"https://github.com/geoffthemedio","followers_url":"https://api.github.com/users/geoffthemedio/followers","following_url":"https://api.github.com/users/geoffthemedio/following{/other_user}","gists_url":"https://api.github.com/users/geoffthemedio/gists{/gist_id}","starred_url":"https://api.github.com/users/geoffthemedio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/geoffthemedio/subscriptions","organizations_url":"https://api.github.com/users/geoffthemedio/orgs","repos_url":"https://api.github.com/users/geoffthemedio/repos","events_url":"https://api.github.com/users/geoffthemedio/events{/privacy}","received_events_url":"https://api.github.com/users/geoffthemedio/received_events","type":"User","site_admin":false},"body":"`{` to newline","created_at":"2018-08-31T09:15:09Z","updated_at":"2018-08-31T09:15:09Z","html_url":"https://github.com/freeorion/freeorion/pull/2249#discussion_r214291557","pull_request_url":"https://api.github.com/repos/freeorion/freeorion/pulls/2249","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/freeorion/freeorion/pulls/comments/214291557"},"html":{"href":"https://github.com/freeorion/freeorion/pull/2249#discussion_r214291557"},"pull_request":{"href":"https://api.github.com/repos/freeorion/freeorion/pulls/2249"}}},"pull_request":{"url":"https://api.github.com/repos/freeorion/freeorion/pulls/2249","id":209333634,"node_id":"MDExOlB1bGxSZXF1ZXN0MjA5MzMzNjM0","html_url":"https://github.com/freeorion/freeorion/pull/2249","diff_url":"https://github.com/freeorion/freeorion/pull/2249.diff","patch_url":"https://github.com/freeorion/freeorion/pull/2249.patch","issue_url":"https://api.github.com/repos/freeorion/freeorion/issues/2249","number":2249,"state":"open","locked":false,"title":"Reroll wrong targets with preferred prey conditions","user":{"login":"agrrr3","id":3252041,"node_id":"MDQ6VXNlcjMyNTIwNDE=","avatar_url":"https://avatars3.githubusercontent.com/u/3252041?v=4","gravatar_id":"","url":"https://api.github.com/users/agrrr3","html_url":"https://github.com/agrrr3","followers_url":"https://api.github.com/users/agrrr3/followers","following_url":"https://api.github.com/users/agrrr3/following{/other_user}","gists_url":"https://api.github.com/users/agrrr3/gists{/gist_id}","starred_url":"https://api.github.com/users/agrrr3/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/agrrr3/subscriptions","organizations_url":"https://api.github.com/users/agrrr3/orgs","repos_url":"https://api.github.com/users/agrrr3/repos","events_url":"https://api.github.com/users/agrrr3/events{/privacy}","received_events_url":"https://api.github.com/users/agrrr3/received_events","type":"User","site_admin":false},"body":"This pull request implements target preferences for weapons and fighters by retrying a different enemy if a wrong enemy is in scope.\r\n\r\nTarget preferences and a precision are specified in the weapon and hangar parts. \r\nPreferences are specified as condition to match against the enemy vessel in scope.\r\n\r\nMultiple source can contribute weighted preference conditions. In the scope of this PR are detection ship parts (apply to all weapon systems), hangar parts (apply to the hangar's  boats) and short range weapon parts (apply to the part's weapon).\r\n\r\n[design discussion in forum](https://www.freeorion.org/forum/viewtopic.php?f=6&t=11048) \r\n\r\nContent setup:\r\nFlak (SR_WEAPON_0_1) - Precision 5 hunting space boats\r\nBombers (FT_HANGAR_3) - Precision 5 hunting space ship\r\nInterceptors (FT_HANGAR_1) - Precision 5 hunting space boats\r\nSpinal cannon (SR_SPINAL_ANTIMATTER) - Precision 5 hunting ships with a lot of structure\r\nEverything else - no preferences\r\n\r\nThe code functional but not in a good shape. It needs cleanup but also in order to get the implementation going i was stumbling against the parser library and automagic pointers.\r\n\r\nSo with your help i hope i can clean that up;\r\n- i wasnt able to split up the parser into subparsers, so i needed to add parameters _10 and _11\r\n- i had to many arguments in my function for rebinding it lazily(?), so i wrapped my values in a tuple - that made it a bit harder to debug and figure out types; i resorted to shared_ptr because i couldnt figure out how to do it with unique_ptr; could this leads to memory leaks?\r\n- (Answered) why are unique_ptr used as members in the ship design but extracted and returned as raw pointers? doesnt that defy the reason for using unique_ptr in the first place? \r\n- also i added the precision and preference condition simply at the end of the FOCS entry, that is probably not the best place\r\n- (TODO) composition of multiple sources (for the moment detection parts should also contribute)","created_at":"2018-08-18T22:41:17Z","updated_at":"2018-08-31T09:15:09Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6ef87363719f20dd5e64895e99e2decc0ef3c192","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":194101995,"node_id":"MDU6TGFiZWwxOTQxMDE5OTU=","url":"https://api.github.com/repos/freeorion/freeorion/labels/category:feature","name":"category:feature","color":"5319e7","default":false},{"id":344570077,"node_id":"MDU6TGFiZWwzNDQ1NzAwNzc=","url":"https://api.github.com/repos/freeorion/freeorion/labels/component:content%20scripting","name":"component:content scripting","color":"d93f0b","default":false},{"id":430445128,"node_id":"MDU6TGFiZWw0MzA0NDUxMjg=","url":"https://api.github.com/repos/freeorion/freeorion/labels/component:internal","name":"component:internal","color":"d93f0b","default":false}],"milestone":{"url":"https://api.github.com/repos/freeorion/freeorion/milestones/23","html_url":"https://github.com/freeorion/freeorion/milestone/23","labels_url":"https://api.github.com/repos/freeorion/freeorion/milestones/23/labels","id":2872605,"node_id":"MDk6TWlsZXN0b25lMjg3MjYwNQ==","number":23,"title":"post 0.4.8","description":"Bugs, features and pull requests that are not supposed to go into the 0.4.8 release and therefore should be postponed until afterwards.","creator":{"login":"Vezzra","id":10279417,"node_id":"MDQ6VXNlcjEwMjc5NDE3","avatar_url":"https://avatars2.githubusercontent.com/u/10279417?v=4","gravatar_id":"","url":"https://api.github.com/users/Vezzra","html_url":"https://github.com/Vezzra","followers_url":"https://api.github.com/users/Vezzra/followers","following_url":"https://api.github.com/users/Vezzra/following{/other_user}","gists_url":"https://api.github.com/users/Vezzra/gists{/gist_id}","starred_url":"https://api.github.com/users/Vezzra/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Vezzra/subscriptions","organizations_url":"https://api.github.com/users/Vezzra/orgs","repos_url":"https://api.github.com/users/Vezzra/repos","events_url":"https://api.github.com/users/Vezzra/events{/privacy}","received_events_url":"https://api.github.com/users/Vezzra/received_events","type":"User","site_admin":false},"open_issues":132,"closed_issues":28,"state":"open","created_at":"2017-10-29T13:18:34Z","updated_at":"2018-08-30T13:43:24Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/freeorion/freeorion/pulls/2249/commits","review_comments_url":"https://api.github.com/repos/freeorion/freeorion/pulls/2249/comments","review_comment_url":"https://api.github.com/repos/freeorion/freeorion/pulls/comments{/number}","comments_url":"https://api.github.com/repos/freeorion/freeorion/issues/2249/comments","statuses_url":"https://api.github.com/repos/freeorion/freeorion/statuses/626a980b51231653a993b751b3b4fd812d55f871","head":{"label":"agrrr3:RerollWrongTargets_WithPreferredPreyConditions","ref":"RerollWrongTargets_WithPreferredPreyConditions","sha":"626a980b51231653a993b751b3b4fd812d55f871","user":{"login":"agrrr3","id":3252041,"node_id":"MDQ6VXNlcjMyNTIwNDE=","avatar_url":"https://avatars3.githubusercontent.com/u/3252041?v=4","gravatar_id":"","url":"https://api.github.com/users/agrrr3","html_url":"https://github.com/agrrr3","followers_url":"https://api.github.com/users/agrrr3/followers","following_url":"https://api.github.com/users/agrrr3/following{/other_user}","gists_url":"https://api.github.com/users/agrrr3/gists{/gist_id}","starred_url":"https://api.github.com/users/agrrr3/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/agrrr3/subscriptions","organizations_url":"https://api.github.com/users/agrrr3/orgs","repos_url":"https://api.github.com/users/agrrr3/repos","events_url":"https://api.github.com/users/agrrr3/events{/privacy}","received_events_url":"https://api.github.com/users/agrrr3/received_events","type":"User","site_admin":false},"repo":{"id":65853125,"node_id":"MDEwOlJlcG9zaXRvcnk2NTg1MzEyNQ==","name":"freeorion","full_name":"agrrr3/freeorion","owner":{"login":"agrrr3","id":3252041,"node_id":"MDQ6VXNlcjMyNTIwNDE=","avatar_url":"https://avatars3.githubusercontent.com/u/3252041?v=4","gravatar_id":"","url":"https://api.github.com/users/agrrr3","html_url":"https://github.com/agrrr3","followers_url":"https://api.github.com/users/agrrr3/followers","following_url":"https://api.github.com/users/agrrr3/following{/other_user}","gists_url":"https://api.github.com/users/agrrr3/gists{/gist_id}","starred_url":"https://api.github.com/users/agrrr3/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/agrrr3/subscriptions","organizations_url":"https://api.github.com/users/agrrr3/orgs","repos_url":"https://api.github.com/users/agrrr3/repos","events_url":"https://api.github.com/users/agrrr3/events{/privacy}","received_events_url":"https://api.github.com/users/agrrr3/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/agrrr3/freeorion","description":"Source code repository of the FreeOrion project.","fork":true,"url":"https://api.github.com/repos/agrrr3/freeorion","forks_url":"https://api.github.com/repos/agrrr3/freeorion/forks","keys_url":"https://api.github.com/repos/agrrr3/freeorion/keys{/key_id}","collaborators_url":"https://api.github.com/repos/agrrr3/freeorion/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/agrrr3/freeorion/teams","hooks_url":"https://api.github.com/repos/agrrr3/freeorion/hooks","issue_events_url":"https://api.github.com/repos/agrrr3/freeorion/issues/events{/number}","events_url":"https://api.github.com/repos/agrrr3/freeorion/events","assignees_url":"https://api.github.com/repos/agrrr3/freeorion/assignees{/user}","branches_url":"https://api.github.com/repos/agrrr3/freeorion/branches{/branch}","tags_url":"https://api.github.com/repos/agrrr3/freeorion/tags","blobs_url":"https://api.github.com/repos/agrrr3/freeorion/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/agrrr3/freeorion/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/agrrr3/freeorion/git/refs{/sha}","trees_url":"https://api.github.com/repos/agrrr3/freeorion/git/trees{/sha}","statuses_url":"https://api.github.com/repos/agrrr3/freeorion/statuses/{sha}","languages_url":"https://api.github.com/repos/agrrr3/freeorion/languages","stargazers_url":"https://api.github.com/repos/agrrr3/freeorion/stargazers","contributors_url":"https://api.github.com/repos/agrrr3/freeorion/contributors","subscribers_url":"https://api.github.com/repos/agrrr3/freeorion/subscribers","subscription_url":"https://api.github.com/repos/agrrr3/freeorion/subscription","commits_url":"https://api.github.com/repos/agrrr3/freeorion/commits{/sha}","git_commits_url":"https://api.github.com/repos/agrrr3/freeorion/git/commits{/sha}","comments_url":"https://api.github.com/repos/agrrr3/freeorion/comments{/number}","issue_comment_url":"https://api.github.com/repos/agrrr3/freeorion/issues/comments{/number}","contents_url":"https://api.github.com/repos/agrrr3/freeorion/contents/{+path}","compare_url":"https://api.github.com/repos/agrrr3/freeorion/compare/{base}...{head}","merges_url":"https://api.github.com/repos/agrrr3/freeorion/merges","archive_url":"https://api.github.com/repos/agrrr3/freeorion/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/agrrr3/freeorion/downloads","issues_url":"https://api.github.com/repos/agrrr3/freeorion/issues{/number}","pulls_url":"https://api.github.com/repos/agrrr3/freeorion/pulls{/number}","milestones_url":"https://api.github.com/repos/agrrr3/freeorion/milestones{/number}","notifications_url":"https://api.github.com/repos/agrrr3/freeorion/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/agrrr3/freeorion/labels{/name}","releases_url":"https://api.github.com/repos/agrrr3/freeorion/releases{/id}","deployments_url":"https://api.github.com/repos/agrrr3/freeorion/deployments","created_at":"2016-08-16T20:56:32Z","updated_at":"2016-08-16T20:56:39Z","pushed_at":"2018-08-30T20:46:01Z","git_url":"git://github.com/agrrr3/freeorion.git","ssh_url":"git@github.com:agrrr3/freeorion.git","clone_url":"https://github.com/agrrr3/freeorion.git","svn_url":"https://github.com/agrrr3/freeorion","homepage":"http://www.freeorion.org/","size":550180,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"freeorion:master","ref":"master","sha":"bb76969fab231d9dbf0554e803f58792844de46f","user":{"login":"freeorion","id":1025550,"node_id":"MDEyOk9yZ2FuaXphdGlvbjEwMjU1NTA=","avatar_url":"https://avatars1.githubusercontent.com/u/1025550?v=4","gravatar_id":"","url":"https://api.github.com/users/freeorion","html_url":"https://github.com/freeorion","followers_url":"https://api.github.com/users/freeorion/followers","following_url":"https://api.github.com/users/freeorion/following{/other_user}","gists_url":"https://api.github.com/users/freeorion/gists{/gist_id}","starred_url":"https://api.github.com/users/freeorion/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/freeorion/subscriptions","organizations_url":"https://api.github.com/users/freeorion/orgs","repos_url":"https://api.github.com/users/freeorion/repos","events_url":"https://api.github.com/users/freeorion/events{/privacy}","received_events_url":"https://api.github.com/users/freeorion/received_events","type":"Organization","site_admin":false},"repo":{"id":33066062,"node_id":"MDEwOlJlcG9zaXRvcnkzMzA2NjA2Mg==","name":"freeorion","full_name":"freeorion/freeorion","owner":{"login":"freeorion","id":1025550,"node_id":"MDEyOk9yZ2FuaXphdGlvbjEwMjU1NTA=","avatar_url":"https://avatars1.githubusercontent.com/u/1025550?v=4","gravatar_id":"","url":"https://api.github.com/users/freeorion","html_url":"https://github.com/freeorion","followers_url":"https://api.github.com/users/freeorion/followers","following_url":"https://api.github.com/users/freeorion/following{/other_user}","gists_url":"https://api.github.com/users/freeorion/gists{/gist_id}","starred_url":"https://api.github.com/users/freeorion/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/freeorion/subscriptions","organizations_url":"https://api.github.com/users/freeorion/orgs","repos_url":"https://api.github.com/users/freeorion/repos","events_url":"https://api.github.com/users/freeorion/events{/privacy}","received_events_url":"https://api.github.com/users/freeorion/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/freeorion/freeorion","description":"Source code repository of the FreeOrion project.","fork":false,"url":"https://api.github.com/repos/freeorion/freeorion","forks_url":"https://api.github.com/repos/freeorion/freeorion/forks","keys_url":"https://api.github.com/repos/freeorion/freeorion/keys{/key_id}","collaborators_url":"https://api.github.com/repos/freeorion/freeorion/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/freeorion/freeorion/teams","hooks_url":"https://api.github.com/repos/freeorion/freeorion/hooks","issue_events_url":"https://api.github.com/repos/freeorion/freeorion/issues/events{/number}","events_url":"https://api.github.com/repos/freeorion/freeorion/events","assignees_url":"https://api.github.com/repos/freeorion/freeorion/assignees{/user}","branches_url":"https://api.github.com/repos/freeorion/freeorion/branches{/branch}","tags_url":"https://api.github.com/repos/freeorion/freeorion/tags","blobs_url":"https://api.github.com/repos/freeorion/freeorion/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/freeorion/freeorion/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/freeorion/freeorion/git/refs{/sha}","trees_url":"https://api.github.com/repos/freeorion/freeorion/git/trees{/sha}","statuses_url":"https://api.github.com/repos/freeorion/freeorion/statuses/{sha}","languages_url":"https://api.github.com/repos/freeorion/freeorion/languages","stargazers_url":"https://api.github.com/repos/freeorion/freeorion/stargazers","contributors_url":"https://api.github.com/repos/freeorion/freeorion/contributors","subscribers_url":"https://api.github.com/repos/freeorion/freeorion/subscribers","subscription_url":"https://api.github.com/repos/freeorion/freeorion/subscription","commits_url":"https://api.github.com/repos/freeorion/freeorion/commits{/sha}","git_commits_url":"https://api.github.com/repos/freeorion/freeorion/git/commits{/sha}","comments_url":"https://api.github.com/repos/freeorion/freeorion/comments{/number}","issue_comment_url":"https://api.github.com/repos/freeorion/freeorion/issues/comments{/number}","contents_url":"https://api.github.com/repos/freeorion/freeorion/contents/{+path}","compare_url":"https://api.github.com/repos/freeorion/freeorion/compare/{base}...{head}","merges_url":"https://api.github.com/repos/freeorion/freeorion/merges","archive_url":"https://api.github.com/repos/freeorion/freeorion/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/freeorion/freeorion/downloads","issues_url":"https://api.github.com/repos/freeorion/freeorion/issues{/number}","pulls_url":"https://api.github.com/repos/freeorion/freeorion/pulls{/number}","milestones_url":"https://api.github.com/repos/freeorion/freeorion/milestones{/number}","notifications_url":"https://api.github.com/repos/freeorion/freeorion/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/freeorion/freeorion/labels{/name}","releases_url":"https://api.github.com/repos/freeorion/freeorion/releases{/id}","deployments_url":"https://api.github.com/repos/freeorion/freeorion/deployments","created_at":"2015-03-29T08:22:20Z","updated_at":"2018-08-30T22:32:08Z","pushed_at":"2018-08-30T22:32:01Z","git_url":"git://github.com/freeorion/freeorion.git","ssh_url":"git@github.com:freeorion/freeorion.git","clone_url":"https://github.com/freeorion/freeorion.git","svn_url":"https://github.com/freeorion/freeorion","homepage":"http://www.freeorion.org/","size":550646,"stargazers_count":302,"watchers_count":302,"language":"C++","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":100,"mirror_url":null,"archived":false,"open_issues_count":207,"license":null,"forks":100,"open_issues":207,"watchers":302,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/freeorion/freeorion/pulls/2249"},"html":{"href":"https://github.com/freeorion/freeorion/pull/2249"},"issue":{"href":"https://api.github.com/repos/freeorion/freeorion/issues/2249"},"comments":{"href":"https://api.github.com/repos/freeorion/freeorion/issues/2249/comments"},"review_comments":{"href":"https://api.github.com/repos/freeorion/freeorion/pulls/2249/comments"},"review_comment":{"href":"https://api.github.com/repos/freeorion/freeorion/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/freeorion/freeorion/pulls/2249/commits"},"statuses":{"href":"https://api.github.com/repos/freeorion/freeorion/statuses/626a980b51231653a993b751b3b4fd812d55f871"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"geoffthemedio"}}