mirror of
https://github.com/EDCD/coriolis.git
synced 2025-12-11 00:33:03 +00:00
Optimized statistics calculation in shipyard/Ship
This commit is contained in:
@@ -7,6 +7,7 @@ import LZString from 'lz-string';
|
|||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
import isEqual from 'lodash/lang';
|
import isEqual from 'lodash/lang';
|
||||||
import { Ships, Modifications } from 'coriolis-data/dist';
|
import { Ships, Modifications } from 'coriolis-data/dist';
|
||||||
|
import { chain } from 'lodash';
|
||||||
const zlib = require('zlib');
|
const zlib = require('zlib');
|
||||||
|
|
||||||
const UNIQUE_MODULES = ['psg', 'sg', 'bsg', 'rf', 'fs', 'fh', 'gfsb'];
|
const UNIQUE_MODULES = ['psg', 'sg', 'bsg', 'rf', 'fs', 'fh', 'gfsb'];
|
||||||
@@ -1181,38 +1182,35 @@ export default class Ship {
|
|||||||
|
|
||||||
unladenMass += this.bulkheads.m.getMass();
|
unladenMass += this.bulkheads.m.getMass();
|
||||||
|
|
||||||
for (let slotNum in this.standard) {
|
let slots = this.standard.concat(this.internal, this.hardpoints);
|
||||||
const slot = this.standard[slotNum];
|
// TODO: create class for slot and also add slot.get
|
||||||
if (slot.m) {
|
// handle unladen mass
|
||||||
unladenMass += slot.m.getMass();
|
unladenMass += chain(slots)
|
||||||
if (slot.m.grp === 'ft') {
|
.map(slot => slot.m ? slot.m.get('mass') : null)
|
||||||
fuelCapacity += slot.m.fuel;
|
.filter()
|
||||||
}
|
.reduce((sum, mass) => sum + mass)
|
||||||
}
|
.value();
|
||||||
}
|
|
||||||
|
|
||||||
for (let slotNum in this.internal) {
|
// handle fuel capacuty
|
||||||
const slot = this.internal[slotNum];
|
fuelCapacity += chain(slots)
|
||||||
if (slot.m) {
|
.map(slot => slot.m ? slot.m.get('fuel') : null)
|
||||||
unladenMass += slot.m.getMass();
|
.filter()
|
||||||
if (slot.m.grp === 'ft') {
|
.reduce((sum, fuel) => sum + fuel)
|
||||||
fuelCapacity += slot.m.fuel;
|
.value();
|
||||||
} else if (slot.m.grp === 'cr') {
|
|
||||||
cargoCapacity += slot.m.cargo;
|
|
||||||
} else if (slot.m.grp.slice(0,2) === 'pc') {
|
|
||||||
if (slot.m.passengers) {
|
|
||||||
passengerCapacity += slot.m.passengers;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let slotNum in this.hardpoints) {
|
// handle cargo capacity
|
||||||
const slot = this.hardpoints[slotNum];
|
cargoCapacity += chain(slots)
|
||||||
if (slot.m) {
|
.map(slot => slot.m ? slot.m.get('cargo') : null)
|
||||||
unladenMass += slot.m.getMass();
|
.filter()
|
||||||
}
|
.reduce((sum, cargo) => sum + cargo)
|
||||||
}
|
.value();
|
||||||
|
|
||||||
|
// handle passenger capacity
|
||||||
|
passengerCapacity += chain(slots)
|
||||||
|
.map(slot => slot.m ? slot.m.get('passengers') : null)
|
||||||
|
.filter()
|
||||||
|
.reduce((sum, passengers) => sum + passengers)
|
||||||
|
.value();
|
||||||
|
|
||||||
// Update global stats
|
// Update global stats
|
||||||
this.unladenMass = unladenMass;
|
this.unladenMass = unladenMass;
|
||||||
|
|||||||
Reference in New Issue
Block a user