From 3f6875abb68b2ea1f643d23f47b89c2f72c12912 Mon Sep 17 00:00:00 2001 From: Colin McLeod Date: Tue, 6 Oct 2015 20:01:56 -0700 Subject: [PATCH] Add find lightest shield generator --- app/js/shipyard/factory-component-set.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/app/js/shipyard/factory-component-set.js b/app/js/shipyard/factory-component-set.js index a6b28509..334c92bc 100755 --- a/app/js/shipyard/factory-component-set.js +++ b/app/js/shipyard/factory-component-set.js @@ -117,7 +117,18 @@ angular.module('shipyard').factory('ComponentSet', ['lodash', function(_) { return th.class + th.rating; }; - ComponentSet.prototype.lightestPowerPlant = function(powerUsed) { + ComponentSet.prototype.lightestShieldGenerator = function(hullMass) { + var sg = null; + + _.forEach(this.internal.sg, function(s) { + if (sg == null || (s.mass < sg.mass && s.minmass <= hullMass && s.maxmass > hullMass)) { + sg = s; + } + }); + return sg.id; + }; + + ComponentSet.prototype.lightestPowerPlant = function(powerUsed, rating) { var pps = this.common[0]; var pp = null; @@ -126,7 +137,7 @@ angular.module('shipyard').factory('ComponentSet', ['lodash', function(_) { pp = pps[i]; } } - return pp.class + (pp.rating != 'D' ? 'A' : 'D'); // Use A rated if C,E + return pp.class + (pp.rating != 'D' || rating == 'A' ? 'A' : 'D'); // Use A rated if C,E }; return ComponentSet;