From 69de209abaa55631ee22ac95536e5d55d23036a5 Mon Sep 17 00:00:00 2001 From: Kevin Chang Date: Thu, 30 Jul 2015 19:50:08 -0700 Subject: [PATCH] A-rated uses largest eligible shield slot; dirty hacks rewritten --- app/js/controllers/controller-outfit.js | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/app/js/controllers/controller-outfit.js b/app/js/controllers/controller-outfit.js index e2b6c142..558aa23b 100755 --- a/app/js/controllers/controller-outfit.js +++ b/app/js/controllers/controller-outfit.js @@ -175,28 +175,23 @@ angular.module('app').controller('OutfitController', ['$window', '$rootScope', ' }; /** - * Strip ship to A-class and A-class shield generator. + * Strip ship to A-class and biggest A-class shield generator with military bulkheads */ $scope.aRatedBuild = function() { - ship.buildWith(data.defaults); // Reset build to default -- lazy hack to find shield slot - var sgSlot = 0; - var sgId = 0; - ship.internal.forEach(function(slot) { - // TODO: equip biggest A-rated shield in highest slot instead - if (slot.c && (slot.c.grp == 'sg')) { - sgSlot = ship.internal.indexOf(slot); - // Dirty hack using char decrement to get to A rated shield from default E - sgId = slot.c.id.charAt(0) + String.fromCharCode(slot.c.id.charCodeAt(1) - 4); - } - }); for (var i = 0, l = ship.common.length - 1; i < l; i++) { // All except Fuel Tank var id = ship.common[i].maxClass + 'A'; ship.use(ship.common[i], id, Components.common(i, id)); } ship.hardpoints.forEach(function(slot) { ship.use(slot, null, null); }); ship.internal.forEach(function(slot) { ship.use(slot, null, null); }); - ship.use(ship.internal[sgSlot], sgId, Components.internal(sgId)); - ship.useBulkhead(0); + ship.internal.some(function(slot) { + if ('undefined' == typeof slot.eligible) { // Assuming largest slot can hold an eligible shield + var id = Components.findInternalId('Shield Generator', slot.maxClass, 'A'); + ship.use(slot, id, Components.internal(id)); + return true; + } + }); + ship.useBulkhead(2); updateState(Serializer.fromShip(ship)); };