{"action":"created","comment":{"url":"https://api.github.com/repos/TooAngel/screeps/pulls/comments/95880042","pull_request_review_id":16447617,"id":95880042,"diff_hunk":"@@ -186,21 +186,168 @@ Room.prototype.checkRoleToSpawn = function(role, amount, targetId, targetRoom, l\n   this.memory.queue.push(creepMemory);\n };\n \n-Room.prototype.getPartConfig = function(energy, parts) {\n-  var sum = 0;\n-  var i = 0;\n-  var partConfig = [];\n-  while (sum < energy && partConfig.length < 50) {\n-    var part = parts[i % parts.length];\n-    if (sum + BODYPART_COST[part] <= energy) {\n-      partConfig.push(part);\n-      sum += BODYPART_COST[part];\n-      i += 1;\n-    } else {\n-      break;\n+/**\n+ * Room.prototype.checkParts use for check if a bodyPart can be add to total body.\n+ *\n+ * @param {Array} parts Array of body parts.\n+ * @param {Number} actualCost Cost of body before function call.\n+ * @param {Number} energy energy allow for spawn.\n+ */\n+\n+Room.prototype.checkParts = function(parts, actualCost, energy) {\n+  if (!parts) { return; }\n+  parts.forEach(\n+    function(p) {\n+      actualCost += BODYPART_COST[p];\n+      if (actualCost > energy) { return; }\n+    }\n+  );\n+  return actualCost;\n+};\n+\n+/**\n+ * Room.prototype.getSettings use for return creep spawn settings\n+ * adapted to room configuration\n+ *\n+ * @param {Collection} creep queue's creep spawn basic datas\n+ */\n+\n+Room.prototype.getSettings = function(creep) {\n+  let datas = {};\n+  let i = 0;\n+  let settings = roles[creep.role].settings;\n+  let parts = settings.parts || {};\n+  let energy = settings.energy || {};\n+\n+  let getKey = function(part, i) {\n+    let keys = Object.keys(part);\n+    let value = _.get(this, settings.param[i], 1);\n+    let previousKey = 0;\n+    _.forEach(keys, function(k) {\n+      if (part[k] && value < k & previousKey !== 0) {\n+        return previousKey;\n+      }\n+      previousKey = k;\n+    });\n+    return previousKey;\n+\n+  };\n+  let Settings = parts;\n+  if (energy) {\n+    _.forEach(energy, (e, name) => Settings[name] = e);\n+  }\n+  _.forEach(Settings, (element, settingName) => {\n+    let i = 0;\n+    let key;\n+    while (!_.isArray(element) && !_.isNumber(element) && i < settings.param.length) {\n+      key = getKey(element, i);\n+      element = element[key];\n+      i++;\n     }\n+\n+    datas[settingName] = element;\n+  });\n+  //console.log(JSON.stringify(datas));\n+  return datas;\n+};\n+\n+/**\n+ * Room.prototype.getPartsConfig use for generate adapted body\n+ *\n+ * @param {Collection} creep queue's creep spawn basic datas\n+ */\n+\n+Room.prototype.getPartConfig = function(creep) {\n+  if (config.debug.getPartsConfLogs) {\n+    console.log(this.name, '- - ->', creep.role);\n+  }\n+  let datas = this.getSettings(creep);\n+\n+  let layout = datas.layout;\n+  let amount = datas.amount;\n+  let minEnergyStored = datas.minEnergyStored;\n+  let maxEnergyUsed = datas.maxEnergyUsed;\n+  let prefixParts = datas.prefixParts;\n+  let sufixParts = datas.sufixParts;\n+\n+  let energyAvailable = this.energyAvailable;\n+  let parts = [];\n+  let cost = 0;\n+  if (config.debug.getPartsConfLogs) {\n+    console.log('prefix : ', prefixParts, '--layout : ', layout, '--minEnergy : ',\n+      minEnergyStored, '--maxEnergy : ', maxEnergyUsed);\n   }\n-  return partConfig;\n+\n+  let maxBodyLength = 50;\n+  if (prefixParts) { maxBodyLength -= prefixParts.length; }\n+  if (sufixParts) { maxBodyLength -= sufixParts.length; }\n+\n+  if (minEnergyStored && minEnergyStored > energyAvailable) { return; }\n+  if (maxEnergyUsed && maxEnergyUsed < energyAvailable) { energyAvailable = maxEnergyUsed; }\n+\n+  let prefixCost = this.checkParts(prefixParts, 0, energyAvailable);\n+  if (prefixCost) {\n+    cost = prefixCost;\n+    parts = prefixParts;\n+  }\n+\n+  if (amount) { // if size is defined\n+    let pushAll = function(element, index, array) {\n+      for (let i = 0; i < element; i++) {\n+        parts.push(layout[index]);\n+        cost += BODYPART_COST[layout[index]];\n+      }\n+    };\n+    amount.forEach(pushAll);\n+  } else {\n+    let halt = false;\n+    let i = 1;\n+    let j = 1;\n+    let layoutCost;\n+    let layoutParts;\n+    let part;\n+\n+    while (!halt && parts.length + j <= maxBodyLength) {\n+      layoutCost = 0;\n+      layoutParts = [];\n+      while (!halt && j <= layout.length && parts.length + j < maxBodyLength) {\n+        part = layout[j - 1];\n+        layoutCost += BODYPART_COST[part];\n+        if (cost + layoutCost <= energyAvailable) {\n+          layoutParts.push(part);\n+        } else {\n+          halt = true;\n+        }\n+        j++;\n+      }\n+\n+      if (!halt) {\n+        cost += layoutCost;\n+        parts = parts.concat(layoutParts);\n+        j = 1;\n+        i++;\n+      }\n+    }\n+  }\n+  if (sufixParts) {\n+    let newCost = this.checkParts(sufixParts, cost, energyAvailable);\n+    if (newCost) {\n+      cost = newCost;","path":"src/prototype_room_utils.js","position":163,"original_position":163,"commit_id":"1eb4e8b74abfaec2865fca944d55c7cb6b315c07","original_commit_id":"1eb4e8b74abfaec2865fca944d55c7cb6b315c07","user":{"login":"TooAngel","id":131156,"avatar_url":"https://avatars.githubusercontent.com/u/131156?v=3","gravatar_id":"","url":"https://api.github.com/users/TooAngel","html_url":"https://github.com/TooAngel","followers_url":"https://api.github.com/users/TooAngel/followers","following_url":"https://api.github.com/users/TooAngel/following{/other_user}","gists_url":"https://api.github.com/users/TooAngel/gists{/gist_id}","starred_url":"https://api.github.com/users/TooAngel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TooAngel/subscriptions","organizations_url":"https://api.github.com/users/TooAngel/orgs","repos_url":"https://api.github.com/users/TooAngel/repos","events_url":"https://api.github.com/users/TooAngel/events{/privacy}","received_events_url":"https://api.github.com/users/TooAngel/received_events","type":"User","site_admin":false},"body":"I'm not yet sure about the cost, or especially overwriting it here.","created_at":"2017-01-12T20:41:20Z","updated_at":"2017-01-12T20:43:23Z","html_url":"https://github.com/TooAngel/screeps/pull/54#discussion_r95880042","pull_request_url":"https://api.github.com/repos/TooAngel/screeps/pulls/54","_links":{"self":{"href":"https://api.github.com/repos/TooAngel/screeps/pulls/comments/95880042"},"html":{"href":"https://github.com/TooAngel/screeps/pull/54#discussion_r95880042"},"pull_request":{"href":"https://api.github.com/repos/TooAngel/screeps/pulls/54"}}},"pull_request":{"url":"https://api.github.com/repos/TooAngel/screeps/pulls/54","id":99615545,"html_url":"https://github.com/TooAngel/screeps/pull/54","diff_url":"https://github.com/TooAngel/screeps/pull/54.diff","patch_url":"https://github.com/TooAngel/screeps/pull/54.patch","issue_url":"https://api.github.com/repos/TooAngel/screeps/issues/54","number":54,"state":"open","locked":false,"title":"[WIP ]Getparts & energyCheks modifs","user":{"login":"Nevrdid","id":13476270,"avatar_url":"https://avatars.githubusercontent.com/u/13476270?v=3","gravatar_id":"","url":"https://api.github.com/users/Nevrdid","html_url":"https://github.com/Nevrdid","followers_url":"https://api.github.com/users/Nevrdid/followers","following_url":"https://api.github.com/users/Nevrdid/following{/other_user}","gists_url":"https://api.github.com/users/Nevrdid/gists{/gist_id}","starred_url":"https://api.github.com/users/Nevrdid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Nevrdid/subscriptions","organizations_url":"https://api.github.com/users/Nevrdid/orgs","repos_url":"https://api.github.com/users/Nevrdid/repos","events_url":"https://api.github.com/users/Nevrdid/events{/privacy}","received_events_url":"https://api.github.com/users/Nevrdid/received_events","type":"User","site_admin":false},"body":"TODO : \r\n\r\n1. finish role reserver.\r\n2. finish role carry.\r\n3. finish role repairer.\r\n4. check if harvester not bug.\r\n5. compact getPartsConf, getSettings and checkParts\r\n6. search better roles settings. ","created_at":"2016-12-29T03:40:01Z","updated_at":"2017-01-12T20:43:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":"15361cbd87a8c89c28c233e2a17f23c0303621a1","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/TooAngel/screeps/pulls/54/commits","review_comments_url":"https://api.github.com/repos/TooAngel/screeps/pulls/54/comments","review_comment_url":"https://api.github.com/repos/TooAngel/screeps/pulls/comments{/number}","comments_url":"https://api.github.com/repos/TooAngel/screeps/issues/54/comments","statuses_url":"https://api.github.com/repos/TooAngel/screeps/statuses/1eb4e8b74abfaec2865fca944d55c7cb6b315c07","head":{"label":"Nevrdid:getPartsConfig_changed","ref":"getPartsConfig_changed","sha":"1eb4e8b74abfaec2865fca944d55c7cb6b315c07","user":{"login":"Nevrdid","id":13476270,"avatar_url":"https://avatars.githubusercontent.com/u/13476270?v=3","gravatar_id":"","url":"https://api.github.com/users/Nevrdid","html_url":"https://github.com/Nevrdid","followers_url":"https://api.github.com/users/Nevrdid/followers","following_url":"https://api.github.com/users/Nevrdid/following{/other_user}","gists_url":"https://api.github.com/users/Nevrdid/gists{/gist_id}","starred_url":"https://api.github.com/users/Nevrdid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Nevrdid/subscriptions","organizations_url":"https://api.github.com/users/Nevrdid/orgs","repos_url":"https://api.github.com/users/Nevrdid/repos","events_url":"https://api.github.com/users/Nevrdid/events{/privacy}","received_events_url":"https://api.github.com/users/Nevrdid/received_events","type":"User","site_admin":false},"repo":{"id":77473896,"name":"screeps","full_name":"Nevrdid/screeps","owner":{"login":"Nevrdid","id":13476270,"avatar_url":"https://avatars.githubusercontent.com/u/13476270?v=3","gravatar_id":"","url":"https://api.github.com/users/Nevrdid","html_url":"https://github.com/Nevrdid","followers_url":"https://api.github.com/users/Nevrdid/followers","following_url":"https://api.github.com/users/Nevrdid/following{/other_user}","gists_url":"https://api.github.com/users/Nevrdid/gists{/gist_id}","starred_url":"https://api.github.com/users/Nevrdid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Nevrdid/subscriptions","organizations_url":"https://api.github.com/users/Nevrdid/orgs","repos_url":"https://api.github.com/users/Nevrdid/repos","events_url":"https://api.github.com/users/Nevrdid/events{/privacy}","received_events_url":"https://api.github.com/users/Nevrdid/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Nevrdid/screeps","description":"Bot for screeps","fork":true,"url":"https://api.github.com/repos/Nevrdid/screeps","forks_url":"https://api.github.com/repos/Nevrdid/screeps/forks","keys_url":"https://api.github.com/repos/Nevrdid/screeps/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Nevrdid/screeps/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Nevrdid/screeps/teams","hooks_url":"https://api.github.com/repos/Nevrdid/screeps/hooks","issue_events_url":"https://api.github.com/repos/Nevrdid/screeps/issues/events{/number}","events_url":"https://api.github.com/repos/Nevrdid/screeps/events","assignees_url":"https://api.github.com/repos/Nevrdid/screeps/assignees{/user}","branches_url":"https://api.github.com/repos/Nevrdid/screeps/branches{/branch}","tags_url":"https://api.github.com/repos/Nevrdid/screeps/tags","blobs_url":"https://api.github.com/repos/Nevrdid/screeps/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Nevrdid/screeps/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Nevrdid/screeps/git/refs{/sha}","trees_url":"https://api.github.com/repos/Nevrdid/screeps/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Nevrdid/screeps/statuses/{sha}","languages_url":"https://api.github.com/repos/Nevrdid/screeps/languages","stargazers_url":"https://api.github.com/repos/Nevrdid/screeps/stargazers","contributors_url":"https://api.github.com/repos/Nevrdid/screeps/contributors","subscribers_url":"https://api.github.com/repos/Nevrdid/screeps/subscribers","subscription_url":"https://api.github.com/repos/Nevrdid/screeps/subscription","commits_url":"https://api.github.com/repos/Nevrdid/screeps/commits{/sha}","git_commits_url":"https://api.github.com/repos/Nevrdid/screeps/git/commits{/sha}","comments_url":"https://api.github.com/repos/Nevrdid/screeps/comments{/number}","issue_comment_url":"https://api.github.com/repos/Nevrdid/screeps/issues/comments{/number}","contents_url":"https://api.github.com/repos/Nevrdid/screeps/contents/{+path}","compare_url":"https://api.github.com/repos/Nevrdid/screeps/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Nevrdid/screeps/merges","archive_url":"https://api.github.com/repos/Nevrdid/screeps/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Nevrdid/screeps/downloads","issues_url":"https://api.github.com/repos/Nevrdid/screeps/issues{/number}","pulls_url":"https://api.github.com/repos/Nevrdid/screeps/pulls{/number}","milestones_url":"https://api.github.com/repos/Nevrdid/screeps/milestones{/number}","notifications_url":"https://api.github.com/repos/Nevrdid/screeps/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Nevrdid/screeps/labels{/name}","releases_url":"https://api.github.com/repos/Nevrdid/screeps/releases{/id}","deployments_url":"https://api.github.com/repos/Nevrdid/screeps/deployments","created_at":"2016-12-27T18:06:44Z","updated_at":"2017-01-10T08:01:02Z","pushed_at":"2017-01-12T20:02:19Z","git_url":"git://github.com/Nevrdid/screeps.git","ssh_url":"git@github.com:Nevrdid/screeps.git","clone_url":"https://github.com/Nevrdid/screeps.git","svn_url":"https://github.com/Nevrdid/screeps","homepage":"https://screeps.com","size":1043,"stargazers_count":1,"watchers_count":1,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"TooAngel:master","ref":"master","sha":"b59f8cf0d63ecbf35843d74b85f73a9af4ab601e","user":{"login":"TooAngel","id":131156,"avatar_url":"https://avatars.githubusercontent.com/u/131156?v=3","gravatar_id":"","url":"https://api.github.com/users/TooAngel","html_url":"https://github.com/TooAngel","followers_url":"https://api.github.com/users/TooAngel/followers","following_url":"https://api.github.com/users/TooAngel/following{/other_user}","gists_url":"https://api.github.com/users/TooAngel/gists{/gist_id}","starred_url":"https://api.github.com/users/TooAngel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TooAngel/subscriptions","organizations_url":"https://api.github.com/users/TooAngel/orgs","repos_url":"https://api.github.com/users/TooAngel/repos","events_url":"https://api.github.com/users/TooAngel/events{/privacy}","received_events_url":"https://api.github.com/users/TooAngel/received_events","type":"User","site_admin":false},"repo":{"id":40529356,"name":"screeps","full_name":"TooAngel/screeps","owner":{"login":"TooAngel","id":131156,"avatar_url":"https://avatars.githubusercontent.com/u/131156?v=3","gravatar_id":"","url":"https://api.github.com/users/TooAngel","html_url":"https://github.com/TooAngel","followers_url":"https://api.github.com/users/TooAngel/followers","following_url":"https://api.github.com/users/TooAngel/following{/other_user}","gists_url":"https://api.github.com/users/TooAngel/gists{/gist_id}","starred_url":"https://api.github.com/users/TooAngel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TooAngel/subscriptions","organizations_url":"https://api.github.com/users/TooAngel/orgs","repos_url":"https://api.github.com/users/TooAngel/repos","events_url":"https://api.github.com/users/TooAngel/events{/privacy}","received_events_url":"https://api.github.com/users/TooAngel/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/TooAngel/screeps","description":"Bot for screeps","fork":false,"url":"https://api.github.com/repos/TooAngel/screeps","forks_url":"https://api.github.com/repos/TooAngel/screeps/forks","keys_url":"https://api.github.com/repos/TooAngel/screeps/keys{/key_id}","collaborators_url":"https://api.github.com/repos/TooAngel/screeps/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/TooAngel/screeps/teams","hooks_url":"https://api.github.com/repos/TooAngel/screeps/hooks","issue_events_url":"https://api.github.com/repos/TooAngel/screeps/issues/events{/number}","events_url":"https://api.github.com/repos/TooAngel/screeps/events","assignees_url":"https://api.github.com/repos/TooAngel/screeps/assignees{/user}","branches_url":"https://api.github.com/repos/TooAngel/screeps/branches{/branch}","tags_url":"https://api.github.com/repos/TooAngel/screeps/tags","blobs_url":"https://api.github.com/repos/TooAngel/screeps/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/TooAngel/screeps/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/TooAngel/screeps/git/refs{/sha}","trees_url":"https://api.github.com/repos/TooAngel/screeps/git/trees{/sha}","statuses_url":"https://api.github.com/repos/TooAngel/screeps/statuses/{sha}","languages_url":"https://api.github.com/repos/TooAngel/screeps/languages","stargazers_url":"https://api.github.com/repos/TooAngel/screeps/stargazers","contributors_url":"https://api.github.com/repos/TooAngel/screeps/contributors","subscribers_url":"https://api.github.com/repos/TooAngel/screeps/subscribers","subscription_url":"https://api.github.com/repos/TooAngel/screeps/subscription","commits_url":"https://api.github.com/repos/TooAngel/screeps/commits{/sha}","git_commits_url":"https://api.github.com/repos/TooAngel/screeps/git/commits{/sha}","comments_url":"https://api.github.com/repos/TooAngel/screeps/comments{/number}","issue_comment_url":"https://api.github.com/repos/TooAngel/screeps/issues/comments{/number}","contents_url":"https://api.github.com/repos/TooAngel/screeps/contents/{+path}","compare_url":"https://api.github.com/repos/TooAngel/screeps/compare/{base}...{head}","merges_url":"https://api.github.com/repos/TooAngel/screeps/merges","archive_url":"https://api.github.com/repos/TooAngel/screeps/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/TooAngel/screeps/downloads","issues_url":"https://api.github.com/repos/TooAngel/screeps/issues{/number}","pulls_url":"https://api.github.com/repos/TooAngel/screeps/pulls{/number}","milestones_url":"https://api.github.com/repos/TooAngel/screeps/milestones{/number}","notifications_url":"https://api.github.com/repos/TooAngel/screeps/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/TooAngel/screeps/labels{/name}","releases_url":"https://api.github.com/repos/TooAngel/screeps/releases{/id}","deployments_url":"https://api.github.com/repos/TooAngel/screeps/deployments","created_at":"2015-08-11T08:01:12Z","updated_at":"2017-01-11T12:37:20Z","pushed_at":"2017-01-12T20:02:20Z","git_url":"git://github.com/TooAngel/screeps.git","ssh_url":"git@github.com:TooAngel/screeps.git","clone_url":"https://github.com/TooAngel/screeps.git","svn_url":"https://github.com/TooAngel/screeps","homepage":"https://screeps.com","size":856,"stargazers_count":44,"watchers_count":44,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":18,"mirror_url":null,"open_issues_count":47,"forks":18,"open_issues":47,"watchers":44,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/TooAngel/screeps/pulls/54"},"html":{"href":"https://github.com/TooAngel/screeps/pull/54"},"issue":{"href":"https://api.github.com/repos/TooAngel/screeps/issues/54"},"comments":{"href":"https://api.github.com/repos/TooAngel/screeps/issues/54/comments"},"review_comments":{"href":"https://api.github.com/repos/TooAngel/screeps/pulls/54/comments"},"review_comment":{"href":"https://api.github.com/repos/TooAngel/screeps/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/TooAngel/screeps/pulls/54/commits"},"statuses":{"href":"https://api.github.com/repos/TooAngel/screeps/statuses/1eb4e8b74abfaec2865fca944d55c7cb6b315c07"}}}}
{"actor":{"display_login":"TooAngel"}}