Calculate speed based on Thrusters. Closes #16

This commit is contained in:
Colin McLeod
2015-09-17 00:59:09 -07:00
parent fc2f76c31c
commit 726a08b05b
7 changed files with 45 additions and 22 deletions

View File

@@ -100,11 +100,11 @@ angular.module('app').controller('OutfitController', ['$window', '$rootScope', '
$scope.speedSeries = { $scope.speedSeries = {
xMin: 0, xMin: 0,
xMax: ship.cargoCapacity, xMax: ship.cargoCapacity,
yMax: 500, yMax: calcSpeed(ship.unladenMass, ship.speed, $scope.th.c, ship.pipSpeed)['4 Pips'],
yMin: 0, yMin: 0,
series: ['speed', 'boost'], series: ['4 Pips', '2 Pips', '0 Pips'],
func: function(cargo) { // X Axis is Cargo func: function(cargo) { // X Axis is Cargo
return calcSpeed(ship.unladenMass + $scope.fuel + cargo, ship.speed, ship.boost, $scope.th.c); return calcSpeed(ship.unladenMass + $scope.fuel + cargo, ship.speed, $scope.th.c, ship.pipSpeed);
} }
}; };
$scope.speedChart = { $scope.speedChart = {
@@ -360,6 +360,7 @@ angular.module('app').controller('OutfitController', ['$window', '$rootScope', '
$scope.speedSeries.xMax = $scope.trSeries.xMax = $scope.jrSeries.xMax = ship.cargoCapacity; $scope.speedSeries.xMax = $scope.trSeries.xMax = $scope.jrSeries.xMax = ship.cargoCapacity;
$scope.jrSeries.yMax = ship.unladenRange; $scope.jrSeries.yMax = ship.unladenRange;
$scope.trSeries.yMax = ship.unladenTotalRange; $scope.trSeries.yMax = ship.unladenTotalRange;
$scope.speedSeries.yMax = calcSpeed(ship.unladenMass, ship.speed, $scope.th.c, ship.pipSpeed)['4 Pips'];
updateRetrofitCosts(); updateRetrofitCosts();
win.triggerHandler('pwrchange'); win.triggerHandler('pwrchange');
} }

View File

@@ -1,4 +1,4 @@
angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength', 'calcJumpRange', 'calcTotalRange', 'lodash', 'ArmourMultiplier', function(Components, calcShieldStrength, calcJumpRange, calcTotalRange, _, ArmourMultiplier) { angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength', 'calcJumpRange', 'calcTotalRange', 'calcSpeed', 'lodash', 'ArmourMultiplier', function(Components, calcShieldStrength, calcJumpRange, calcTotalRange, calcSpeed, _, ArmourMultiplier) {
/** /**
* Returns the power usage type of a slot and it's particular component * Returns the power usage type of a slot and it's particular component
@@ -159,6 +159,7 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
this.updatePower(); this.updatePower();
this.updateJumpStats(); this.updateJumpStats();
this.updateShieldStrength(); this.updateShieldStrength();
this.updateTopSpeed();
} }
}; };
@@ -375,6 +376,7 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
if (powerChange) { if (powerChange) {
this.updatePower(); this.updatePower();
} }
this.updateTopSpeed();
this.updateJumpStats(); this.updateJumpStats();
this.updateShieldStrength(); this.updateShieldStrength();
} }
@@ -395,6 +397,10 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
this.powerDeployed = prevDeployed; this.powerDeployed = prevDeployed;
}; };
Ship.prototype.updateTopSpeed = function() {
this.topSpeed = calcSpeed(this.unladenMass + this.fuelCapacity, this.speed, this.common[1].c, this.pipSpeed)['4 Pips'];
};
Ship.prototype.updateShieldStrength = function() { Ship.prototype.updateShieldStrength = function() {
var sgSlot = this.findInternalByGroup('sg'); // Find Shield Generator slot Index if any var sgSlot = this.findInternalByGroup('sg'); // Find Shield Generator slot Index if any
this.shieldStrength = sgSlot && sgSlot.enabled ? calcShieldStrength(this.hullMass, this.baseShieldStrength, sgSlot.c, this.shieldMultiplier) : 0; this.shieldStrength = sgSlot && sgSlot.enabled ? calcShieldStrength(this.hullMass, this.baseShieldStrength, sgSlot.c, this.shieldMultiplier) : 0;

View File

@@ -204,7 +204,6 @@ angular.module('shipyard', ['ngLodash'])
/** /**
* Calculate the a ships shield strength based on mass, shield generator and shield boosters used. * Calculate the a ships shield strength based on mass, shield generator and shield boosters used.
* *
* @private
* @param {number} mass Current mass of the ship * @param {number} mass Current mass of the ship
* @param {number} shields Base Shield strength MJ for ship * @param {number} shields Base Shield strength MJ for ship
* @param {object} sg The shield generator used * @param {object} sg The shield generator used
@@ -230,18 +229,20 @@ angular.module('shipyard', ['ngLodash'])
} }
}) })
/** /**
* Calculate the a ships speed based on mass, and thrusters. Currently Innacurate / Incomplete :( * Calculate the a ships speed based on mass, and thrusters.
* *
* @private
* @param {number} mass Current mass of the ship * @param {number} mass Current mass of the ship
* @param {number} baseSpeed Base speed m/s for ship * @param {number} baseSpeed Base speed m/s for ship
* @param {number} baseBoost Base boost m/s for ship * @param {object} thrusters The Thrusters used
* @param {object} thrusters The shield generator used * @param {number} pipSpeed Speed pip multiplier
* @return {object} Approximate speed and boost speed in m/s * @return {object} Approximate speed by pips
*/ */
.value('calcSpeed', function(mass, baseSpeed, baseBoost) { //, thrusters) { .value('calcSpeed', function(mass, baseSpeed, thrusters, pipSpeed) {
//var speed = baseSpeed * (1 + ((thrusters.optmass / mass) * 0.1 ) ); // TODO: find thruser coefficient(s) var speed = baseSpeed * ((1 - thrusters.M) + (thrusters.M * Math.pow(3 - (2 * Math.max(0.5, mass / thrusters.optmass)), thrusters.P)));
//var boost = baseBoost * (1 + ((thrusters.optmass / mass) * 0.1 ) );
return { boost: baseSpeed, speed: baseBoost }; return {
'0 Pips': speed * (1 - (pipSpeed * 4)),
'2 Pips': speed * (1 - (pipSpeed * 2)),
'4 Pips': speed
};
}); });

View File

@@ -63,7 +63,7 @@
<td class="cap" ng-bind="['','small','medium','large','capital'][ship.class] | translate"></td> <td class="cap" ng-bind="['','small','medium','large','capital'][ship.class] | translate"></td>
<td>{{ship.agility}}/10</td> <td>{{ship.agility}}/10</td>
<td> <td>
<span ng-if="th.c.maxmass >= ship.ladenMass">{{fRound(ship.speed)}} <u translate>m/s</u></span> <span ng-if="th.c.maxmass >= ship.ladenMass">{{fCrd(ship.topSpeed)}} <u translate>m/s</u></span>
<span class="warning" ng-if="th.c.maxmass < ship.ladenMass">0 <svg class="icon"><use xlink:href="#warning"></use></svg></span> <span class="warning" ng-if="th.c.maxmass < ship.ladenMass">0 <svg class="icon"><use xlink:href="#warning"></use></svg></span>
</td> </td>
<td> <td>
@@ -348,22 +348,21 @@
</div> </div>
</div> </div>
<div class="group half"> <div class="group third">
<h1 translate="jump range"></h1> <h1 translate="jump range"></h1>
<div line-chart config="jrChart" series="jrSeries"></div> <div line-chart config="jrChart" series="jrSeries"></div>
</div> </div>
<div class="group half"> <div class="group third">
<h1 translate="total range"></h1> <h1 translate="total range"></h1>
<div line-chart config="trChart" series="trSeries"></div> <div line-chart config="trChart" series="trSeries"></div>
</div> </div>
<!-- TODO: Add back in once calcSpeed is dynamic and accurate
<div class="group third"> <div class="group third">
<h1 translate="speed"></h1> <h1 translate="speed"></h1>
<div line-chart config="speedChart" series="speedSeries"></div> <div line-chart config="speedChart" series="speedSeries"></div>
</div> </div>
-->
<div class="group half"> <div class="group half">
<div slider max="ship.fuelCapacity" unit="'T'" on-change="::fuelChange(val)" style="position:relative; margin: 0 auto;"> <div slider max="ship.fuelCapacity" unit="'T'" on-change="::fuelChange(val)" style="position:relative; margin: 0 auto;">

View File

@@ -187,7 +187,7 @@
"class": 3, "class": 3,
"hullCost": 141889932, "hullCost": 141889932,
"speed": 180, "speed": 180,
"boost": 240, "boost": 244,
"boostEnergy": 29, "boostEnergy": 29,
"agility": 2, "agility": 2,
"baseShieldStrength": 350, "baseShieldStrength": 350,

View File

@@ -253,13 +253,15 @@
"class": 3, "class": 3,
"hullCost": 141889932, "hullCost": 141889932,
"speed": 180, "speed": 180,
"boost": 240, "topSpeed": 186.5,
"boost": 244,
"boostEnergy": 29, "boostEnergy": 29,
"agility": 2, "agility": 2,
"baseShieldStrength": 350, "baseShieldStrength": 350,
"baseArmour": 945, "baseArmour": 945,
"hullMass": 400, "hullMass": 400,
"masslock": 23, "masslock": 23,
"pipSpeed": 0.14,
"shipCostMultiplier": 1, "shipCostMultiplier": 1,
"componentCostMultiplier": 1, "componentCostMultiplier": 1,
"fuelCapacity": 32, "fuelCapacity": 32,

View File

@@ -1,6 +1,20 @@
describe('Database', function() { describe('Database', function() {
var shipProperties = ['name', 'manufacturer', 'class', 'hullCost', 'speed', 'boost', 'agility', 'baseShieldStrength', 'baseArmour', 'hullMass', 'masslock']; var shipProperties = [
'name',
'manufacturer',
'class',
'hullCost',
'speed',
'boost',
'boostEnergy',
'agility',
'baseShieldStrength',
'baseArmour',
'hullMass',
'masslock',
'pipSpeed'
];
it('has ships and components', function() { it('has ships and components', function() {
expect(DB.ships).toBeDefined() expect(DB.ships).toBeDefined()