mirror of
https://github.com/EDCD/coriolis.git
synced 2025-12-09 22:55:35 +00:00
Detailed suface scanner power management special case
This commit is contained in:
@@ -75,7 +75,7 @@ angular.module('app').directive('powerBands', ['$window', function($window) {
|
|||||||
|
|
||||||
for (var b = 0, l = bands.length; b < l; b++) {
|
for (var b = 0, l = bands.length; b < l; b++) {
|
||||||
if (bands[b].retSelected) {
|
if (bands[b].retSelected) {
|
||||||
retractedSum += bands[b].retracted;
|
retractedSum += bands[b].retracted + bands[b].retOnly;
|
||||||
retBandsSelected = true;
|
retBandsSelected = true;
|
||||||
}
|
}
|
||||||
if (bands[b].depSelected) {
|
if (bands[b].depSelected) {
|
||||||
@@ -89,8 +89,8 @@ angular.module('app').directive('powerBands', ['$window', function($window) {
|
|||||||
|
|
||||||
retracted.selectAll('rect').data(bands).enter().append('rect')
|
retracted.selectAll('rect').data(bands).enter().append('rect')
|
||||||
.attr('height', barHeight)
|
.attr('height', barHeight)
|
||||||
.attr('width', function(d) { return Math.max(wattScale(d.retracted) - 1, 0); })
|
.attr('width', function(d) { return Math.max(wattScale(d.retracted + d.retOnly) - 1, 0); })
|
||||||
.attr('x', function(d) { return wattScale(d.retractedSum) - wattScale(d.retracted); })
|
.attr('x', function(d) { return wattScale(d.retractedSum) - wattScale(d.retracted + d.retOnly); })
|
||||||
.attr('y', 1)
|
.attr('y', 1)
|
||||||
.on('click', function(d) {
|
.on('click', function(d) {
|
||||||
d.retSelected = !d.retSelected;
|
d.retSelected = !d.retSelected;
|
||||||
@@ -99,7 +99,7 @@ angular.module('app').directive('powerBands', ['$window', function($window) {
|
|||||||
.attr('class', function(d) { return getClass(d.retSelected, d.retractedSum, available); });
|
.attr('class', function(d) { return getClass(d.retSelected, d.retractedSum, available); });
|
||||||
|
|
||||||
retracted.selectAll('text').data(bands).enter().append('text')
|
retracted.selectAll('text').data(bands).enter().append('text')
|
||||||
.attr('x', function(d) { return wattScale(d.retractedSum) - (wattScale(d.retracted) / 2); })
|
.attr('x', function(d) { return wattScale(d.retractedSum) - (wattScale(d.retracted + d.retOnly) / 2); })
|
||||||
.attr('y', 15)
|
.attr('y', 15)
|
||||||
.style('text-anchor', 'middle')
|
.style('text-anchor', 'middle')
|
||||||
.attr('class', 'primary-bg')
|
.attr('class', 'primary-bg')
|
||||||
@@ -107,7 +107,7 @@ angular.module('app').directive('powerBands', ['$window', function($window) {
|
|||||||
d.retSelected = !d.retSelected;
|
d.retSelected = !d.retSelected;
|
||||||
render();
|
render();
|
||||||
})
|
})
|
||||||
.text(function(d, i) { return bandText(d.retracted, i); });
|
.text(function(d, i) { return bandText(d.retracted + d.retOnly, i); });
|
||||||
|
|
||||||
deployed.selectAll('rect').data(bands).enter().append('rect')
|
deployed.selectAll('rect').data(bands).enter().append('rect')
|
||||||
.attr('height', barHeight)
|
.attr('height', barHeight)
|
||||||
|
|||||||
@@ -1,5 +1,23 @@
|
|||||||
angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength', 'calcJumpRange', 'lodash', function(Components, calcShieldStrength, calcJumpRange, _) {
|
angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength', 'calcJumpRange', 'lodash', function(Components, calcShieldStrength, calcJumpRange, _) {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the power usage type of a slot and it's particular component
|
||||||
|
* @param {object} slot The Slot
|
||||||
|
* @param {object} component The component in the slot
|
||||||
|
* @return {string} The key for the power usage type
|
||||||
|
*/
|
||||||
|
function powerUsageType(slot, component) {
|
||||||
|
if (component) {
|
||||||
|
if (component.retractedOnly) {
|
||||||
|
return 'retOnly';
|
||||||
|
}
|
||||||
|
if (component.passive) {
|
||||||
|
return 'retracted';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return slot.cat != 1 ? 'retracted' : 'deployed';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ship model used to track all ship components and properties.
|
* Ship model used to track all ship components and properties.
|
||||||
*
|
*
|
||||||
@@ -37,11 +55,11 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
|||||||
this.powerList.unshift(this.common[0]); // Add Power Plant
|
this.powerList.unshift(this.common[0]); // Add Power Plant
|
||||||
|
|
||||||
this.priorityBands = [
|
this.priorityBands = [
|
||||||
{ deployed: 0, retracted: 0 },
|
{ deployed: 0, retracted: 0, retOnly: 0 },
|
||||||
{ deployed: 0, retracted: 0 },
|
{ deployed: 0, retracted: 0, retOnly: 0 },
|
||||||
{ deployed: 0, retracted: 0 },
|
{ deployed: 0, retracted: 0, retOnly: 0 },
|
||||||
{ deployed: 0, retracted: 0 },
|
{ deployed: 0, retracted: 0, retOnly: 0 },
|
||||||
{ deployed: 0, retracted: 0 }
|
{ deployed: 0, retracted: 0, retOnly: 0 }
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,6 +93,7 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
|||||||
for (i = 0, l = this.priorityBands.length; i < l; i++) {
|
for (i = 0, l = this.priorityBands.length; i < l; i++) {
|
||||||
this.priorityBands[i].deployed = 0;
|
this.priorityBands[i].deployed = 0;
|
||||||
this.priorityBands[i].retracted = 0;
|
this.priorityBands[i].retracted = 0;
|
||||||
|
this.priorityBands[i].retOnly = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.cargoScoop.enabled) {
|
if (this.cargoScoop.enabled) {
|
||||||
@@ -82,6 +101,7 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < cl; i++) {
|
for (i = 0; i < cl; i++) {
|
||||||
|
common[i].cat = 0;
|
||||||
common[i].enabled = enabled ? enabled[i + 1] * 1 : true;
|
common[i].enabled = enabled ? enabled[i + 1] * 1 : true;
|
||||||
common[i].priority = priorities ? priorities[i + 1] * 1 : 0;
|
common[i].priority = priorities ? priorities[i + 1] * 1 : 0;
|
||||||
common[i].type = 'SYS';
|
common[i].type = 'SYS';
|
||||||
@@ -94,6 +114,7 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
|||||||
cl++; // Increase accounts for Cargo Scoop
|
cl++; // Increase accounts for Cargo Scoop
|
||||||
|
|
||||||
for (i = 0, l = hps.length; i < l; i++) {
|
for (i = 0, l = hps.length; i < l; i++) {
|
||||||
|
hps[i].cat = 1;
|
||||||
hps[i].enabled = enabled ? enabled[cl + i] * 1 : true;
|
hps[i].enabled = enabled ? enabled[cl + i] * 1 : true;
|
||||||
hps[i].priority = priorities ? priorities[cl + i] * 1 : 0;
|
hps[i].priority = priorities ? priorities[cl + i] * 1 : 0;
|
||||||
hps[i].type = hps[i].maxClass ? 'WEP' : 'SYS';
|
hps[i].type = hps[i].maxClass ? 'WEP' : 'SYS';
|
||||||
@@ -107,6 +128,7 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
|||||||
cl += hps.length; // Increase accounts for hardpoints
|
cl += hps.length; // Increase accounts for hardpoints
|
||||||
|
|
||||||
for (i = 0, l = internal.length; i < l; i++) {
|
for (i = 0, l = internal.length; i < l; i++) {
|
||||||
|
internal[i].cat = 2;
|
||||||
internal[i].enabled = enabled ? enabled[cl + i] * 1 : true;
|
internal[i].enabled = enabled ? enabled[cl + i] * 1 : true;
|
||||||
internal[i].priority = priorities ? priorities[cl + i] * 1 : 0;
|
internal[i].priority = priorities ? priorities[cl + i] * 1 : 0;
|
||||||
internal[i].type = 'SYS';
|
internal[i].type = 'SYS';
|
||||||
@@ -141,18 +163,14 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
|||||||
*/
|
*/
|
||||||
Ship.prototype.use = function(slot, id, component, preventUpdate) {
|
Ship.prototype.use = function(slot, id, component, preventUpdate) {
|
||||||
if (slot.id != id) { // Selecting a different component
|
if (slot.id != id) { // Selecting a different component
|
||||||
var slotIndex = preventUpdate ? -1 : this.internal.indexOf(slot);
|
|
||||||
// Slot is an internal slot, is not being emptied, and the selected component group/type must be of unique
|
// Slot is an internal slot, is not being emptied, and the selected component group/type must be of unique
|
||||||
if (slotIndex != -1 && component && _.includes(['sg', 'rf', 'fs'], component.grp)) {
|
if (slot.cat != 2 && component && _.includes(['sg', 'rf', 'fs'], component.grp)) {
|
||||||
// Find another internal slot that already has this type/group installed
|
// Find another internal slot that already has this type/group installed
|
||||||
var similarSlotIndex = this.findInternalByGroup(component.grp);
|
var similarSlot = this.findInternalByGroup(component.grp);
|
||||||
// If another slot has an installed component with of the same type
|
// If another slot has an installed component with of the same type
|
||||||
if (similarSlotIndex != -1 && similarSlotIndex != slotIndex) {
|
if (similarSlot && similarSlot !== slot) {
|
||||||
// Empty the slot
|
|
||||||
var similarSlot = this.internal[similarSlotIndex];
|
|
||||||
this.updateStats(similarSlot, null, similarSlot.c, true); // Update stats but don't trigger a global update
|
this.updateStats(similarSlot, null, similarSlot.c, true); // Update stats but don't trigger a global update
|
||||||
similarSlot.id = null;
|
similarSlot.id = similarSlot.c = null; // Empty the slot
|
||||||
similarSlot.c = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var oldComponent = slot.c;
|
var oldComponent = slot.c;
|
||||||
@@ -181,9 +199,13 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
|||||||
* @return {number} The index of the slot in ship.internal
|
* @return {number} The index of the slot in ship.internal
|
||||||
*/
|
*/
|
||||||
Ship.prototype.findInternalByGroup = function(group) {
|
Ship.prototype.findInternalByGroup = function(group) {
|
||||||
return _.findIndex(this.internal, function(slot) {
|
var index = _.findIndex(this.internal, function(slot) {
|
||||||
return slot.c && slot.c.grp == group;
|
return slot.c && slot.c.grp == group;
|
||||||
});
|
});
|
||||||
|
if (index !== -1) {
|
||||||
|
return this.internal[index];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -198,7 +220,7 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
|||||||
slot.priority = newPriority;
|
slot.priority = newPriority;
|
||||||
|
|
||||||
if (slot.enabled) { // Only update power if the slot is enabled
|
if (slot.enabled) { // Only update power if the slot is enabled
|
||||||
var usage = (slot.c.passive || this.hardpoints.indexOf(slot) == -1) ? 'retracted' : 'deployed';
|
var usage = powerUsageType(slot, slot.c);
|
||||||
this.priorityBands[oldPriority][usage] -= slot.c.power;
|
this.priorityBands[oldPriority][usage] -= slot.c.power;
|
||||||
this.priorityBands[newPriority][usage] += slot.c.power;
|
this.priorityBands[newPriority][usage] += slot.c.power;
|
||||||
this.updatePower();
|
this.updatePower();
|
||||||
@@ -217,8 +239,7 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
|||||||
|
|
||||||
Ship.prototype.setSlotEnabled = function(slot, enabled) {
|
Ship.prototype.setSlotEnabled = function(slot, enabled) {
|
||||||
if (slot.enabled != enabled && slot.c) { // Enabled state is changing
|
if (slot.enabled != enabled && slot.c) { // Enabled state is changing
|
||||||
var usage = (slot.c.passive || this.hardpoints.indexOf(slot) == -1) ? 'retracted' : 'deployed';
|
this.priorityBands[slot.priority][powerUsageType(slot, slot.c)] += enabled ? slot.c.power : -slot.c.power;
|
||||||
this.priorityBands[slot.priority][usage] += enabled ? slot.c.power : -slot.c.power;
|
|
||||||
this.updatePower();
|
this.updatePower();
|
||||||
}
|
}
|
||||||
slot.enabled = enabled;
|
slot.enabled = enabled;
|
||||||
@@ -229,9 +250,10 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
|||||||
return 0; // No Status (Not possible)
|
return 0; // No Status (Not possible)
|
||||||
} else if (!slot.enabled) {
|
} else if (!slot.enabled) {
|
||||||
return 1; // Disabled
|
return 1; // Disabled
|
||||||
} else if (deployed) {
|
} else if (deployed && !slot.c.retractedOnly) { // Certain component (e.g. Detaild Surface scanner) are power only while retracted
|
||||||
return this.priorityBands[slot.priority].deployedSum > this.powerAvailable ? 2 : 3; // Offline : Online
|
return this.priorityBands[slot.priority].deployedSum > this.powerAvailable ? 2 : 3; // Offline : Online
|
||||||
} else if (this.hardpoints.indexOf(slot) != -1 && !slot.c.passive) { // Active hardpoints have no retracted status
|
// Active hardpoints have no retracted status
|
||||||
|
} else if ((deployed && slot.c.retractedOnly) || (slot.cat === 1 && !slot.c.passive)) {
|
||||||
return 0; // No Status (Not possible)
|
return 0; // No Status (Not possible)
|
||||||
}
|
}
|
||||||
return this.priorityBands[slot.priority].retractedSum > this.powerAvailable ? 2 : 3; // Offline : Online
|
return this.priorityBands[slot.priority].retractedSum > this.powerAvailable ? 2 : 3; // Offline : Online
|
||||||
@@ -241,7 +263,6 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
|||||||
* Updates the ship's cumulative and aggregated stats based on the component change.
|
* Updates the ship's cumulative and aggregated stats based on the component change.
|
||||||
*/
|
*/
|
||||||
Ship.prototype.updateStats = function(slot, n, old, preventUpdate) {
|
Ship.prototype.updateStats = function(slot, n, old, preventUpdate) {
|
||||||
var isHardPoint = this.hardpoints.indexOf(slot) != -1;
|
|
||||||
var powerChange = slot == this.common[0];
|
var powerChange = slot == this.common[0];
|
||||||
|
|
||||||
if (old) { // Old component now being removed
|
if (old) { // Old component now being removed
|
||||||
@@ -265,7 +286,7 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (old.power && slot.enabled) {
|
if (old.power && slot.enabled) {
|
||||||
this.priorityBands[slot.priority][(isHardPoint && !old.passive) ? 'deployed' : 'retracted'] -= old.power;
|
this.priorityBands[slot.priority][powerUsageType(slot, old)] -= old.power;
|
||||||
powerChange = true;
|
powerChange = true;
|
||||||
}
|
}
|
||||||
this.unladenMass -= old.mass || 0;
|
this.unladenMass -= old.mass || 0;
|
||||||
@@ -295,7 +316,7 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (n.power && slot.enabled) {
|
if (n.power && slot.enabled) {
|
||||||
this.priorityBands[slot.priority][(isHardPoint && !n.passive) ? 'deployed' : 'retracted'] += n.power;
|
this.priorityBands[slot.priority][powerUsageType(slot, n)] += n.power;
|
||||||
powerChange = true;
|
powerChange = true;
|
||||||
}
|
}
|
||||||
this.unladenMass += n.mass || 0;
|
this.unladenMass += n.mass || 0;
|
||||||
@@ -319,7 +340,7 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
|||||||
|
|
||||||
for (var i = 0, l = bands.length; i < l; i++) {
|
for (var i = 0, l = bands.length; i < l; i++) {
|
||||||
var band = bands[i];
|
var band = bands[i];
|
||||||
prevRetracted = band.retractedSum = prevRetracted + band.retracted;
|
prevRetracted = band.retractedSum = prevRetracted + band.retracted + band.retOnly;
|
||||||
prevDeployed = band.deployedSum = prevDeployed + band.deployed + band.retracted;
|
prevDeployed = band.deployedSum = prevDeployed + band.deployed + band.retracted;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -329,8 +350,8 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
|||||||
};
|
};
|
||||||
|
|
||||||
Ship.prototype.updateShieldStrength = function() {
|
Ship.prototype.updateShieldStrength = function() {
|
||||||
var sgSI = this.findInternalByGroup('sg'); // Find Shield Generator slot Index if any
|
var sgSlot = this.findInternalByGroup('sg'); // Find Shield Generator slot Index if any
|
||||||
this.shieldStrength = sgSI != -1 ? calcShieldStrength(this.mass, this.shields, this.internal[sgSI].c, this.shieldMultiplier) : 0;
|
this.shieldStrength = sgSlot ? calcShieldStrength(this.mass, this.shields, sgSlot.c, this.shieldMultiplier) : 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -38,6 +38,7 @@
|
|||||||
"grp": "sc",
|
"grp": "sc",
|
||||||
"name": "Detailed Surface Scanner",
|
"name": "Detailed Surface Scanner",
|
||||||
"class": 1,
|
"class": 1,
|
||||||
|
"retractedOnly": 1,
|
||||||
"rating": "C",
|
"rating": "C",
|
||||||
"cost": 250000,
|
"cost": 250000,
|
||||||
"mass": 1.3,
|
"mass": 1.3,
|
||||||
|
|||||||
Reference in New Issue
Block a user