Home Reference Source
public class | source

Ship

Ship Model - Encapsulates and models in-game ship behavior

Constructor Summary

Public Constructor
public

constructor(id: String, properties: Object, slots: Object)

Member Summary

Public Members
public

[p]: *

public

armour: *

public

availCS: *

public

bulkheads: {"incCost": boolean, "maxClass": number}

public
public

cargoHatch: {"m": *, "type": string}

public
public
public
public
public
public
public

id: *

public
public
public
public

m: {"incCost": boolean, "type": string, "discountedCost": *, "m": *}

public
public
public
public
public
public

pitches: *

public
public
public
public
public
public

rolls: *

public
public

shield: *

public
public
public
public
public

speeds: *

public
public
public

topRoll: *

public
public

topYaw: *

public
public
public
public
public
public
public
public
public
public
public
public
public
public
public
public
public
public
public
public
public
public

yaws: *

Method Summary

Public Methods
public

applyDiscounts(shipDiscount: Number, moduleDiscount: Number): this

Recalculate all item costs and total based on discounts.

public

buildFrom(serializedString: String): this

Updates an existing ship instance's slots with modules determined by the code.

public

buildWith(comps: Object, priorities: array, enabled: Array, mods: Array, blueprints: Array): this

Builds/Updates the ship instance with the ModuleUtils[comps] passed in.

public

calcLadenRange(massDelta: Number, fuel: Number, fsd: Object): Number

Calculate the hypothetical laden jump range based on a potential change in mass, fuel, or FSD

public

Calculate the lowest possible mass for this ship.

public

calcPitch(eng: Number, fuel: Number, cargo: Number, boost: boolean): Number

Calculate the pitch for a given configuration

public

calcRoll(eng: Number, fuel: Number, cargo: Number, boost: boolean): Number

Calculate the roll for a given configuration

public

calcShieldStrengthWith(sg: Object, multiplierDelta: Number): Number

Calculate the hypothetical shield strength for the ship using the specified parameters

public

calcSpeed(eng: Number, fuel: Number, cargo: Number, boost: boolean): Number

Calculate the speed for a given configuration

public

calcSpeedsWith(fuel: Number, cargo: Number): array

Calculate the hypothetical top speeds at cargo and fuel tonnage

public

calcUnladenRange(massDelta: Number, fuel: Number, fsd: Object): Number

Calculate the hypothetical unladen jump range based on a potential change in mass, fuel, or FSD

public

calcYaw(eng: Number, fuel: Number, cargo: Number, boost: boolean): Number

Calculate the yaw for a given configuration

public

canBoost(cargo: Number, fuel: Number): [type]

Can the ship boost

public

canThrust(cargo: Number, fuel: Number): [type]

Can the ship thrust/move

public

Clear all modification values for a module

public

Clear blueprint for a module

public

Clear special for a module

public

Populate the modifications array with modification values from the code

public

decodeModificationsStruct(buffer: String, modArr: Array, blueprintArr: Array)

Populate the modifications array with modification values from the code.

public

diminishingReturns(val: Number, drll: Number, drul: Number): this

Calculate diminishing returns value, where values below a given limit are returned as-is, and values between the lower and upper limit of the diminishing returns are given at half value.

public

emptyHardpoints(): this

Empties all hardpoints and utility slots

public

emptyInternal(): this

Empties all Internal slots

public

emptyUtility(): this

Empties all Utility slots

public

emptyWeapons(): this

Empties all hardpoints

public

Find an internal slot that has an installed modul of the specific group.

public

Find the shield generator for this ship

public

Get the set of available modules for this ship

public

Serializes the hardpoints and utility modules to a string

public

Serializes the internal modules to a string

public

Serializes the modifications to a string

public

Get the serialized module active/inactive settings

public

Get the serialized module priority settings

public

getSlotStatus(slot: Object, deployed: boolean): Number

Returns the a slots power status: 0 - No status [Blank] 1 - Disabled (Switched off) 2 - Offline (Insufficient power available) 3 - Online

public

Serializes the standard modules to a string

public

optimizeMass(m: Object): this

Optimize for the lower mass build that can still boost and power the ship without power management.

public

Update armour and hull resistances

public

recalculateDps(): this

Calculate damage per second and related items for weapons

public

recalculateEps(): this

Calculate energy per second for weapons

public

recalculateHps(): this

Calculate heat per second for weapons

public

recalculateMass(): this

Eecalculate mass

public

Update shield

public

Update shield cells

public

setCostIncluded(item: Object, included: boolean): this

Include/Exclude a item/slot in cost calculations

public

setModification(m: Object, name: Object, value: Number, sentfromui: bool)

Set a modification value and update ship stats

public

Set blueprint for a module

public

Set special for a module

public

setSlotEnabled(slot: Object, enabled: boolean): this

Set slot active/inactive

public

setSlotPriority(slot: Object, newPriority: Number): boolean

Will change the priority of the specified slot if the new priority is valid

public

Serializes the ship to a string

public

updateJumpStats(): this

Jump Range and total range calculations

public

Update the modifications string.

public

updateMovement(): this

Update movement values

public

Update the serialized power active/inactive string

public

Update power calculations when amount generated changes

public

Update the serialized power priorites string

public

updatePowerUsed(): this

Update power calculations when amount consumed changes

public

updateStats(slot: Object, n: Object, old: Object, preventUpdate: boolean): this

Updates the ship's cumulative and aggregated stats based on the module change.

public

upgradeInternals(internals: array, offset: int, priorities: array, enableds: array, modifications: array, blueprints: array, version: int)

Upgrade information about internals with version changes

public

use(slot: Object, mdef: Object, preventUpdate: boolean): this

Update a slot with a the modul if the id is different from the current id for this slot.

public

useBulkhead(index: Number, preventUpdate: boolean): this

Mount the specified bulkhead type (index)

public

Use the lightest standard ModuleUtils unless otherwise specified

public

useStandard(rating: String): this

Set all standard slots to use the speficied rating and class based on the slot's max class

public

useUtility(group: String, rating: String, name: String, clobber: boolean): this

Fill all utility slots with the specified module

public

useWeapon(group: [type], mount: [type], missile: [type], clobber: boolean): this

[useWeapon description]

Public Constructors

public constructor(id: String, properties: Object, slots: Object) source

Params:

NameTypeAttributeDescription
id String

Unique ship Id / Key

properties Object

Basic ship properties such as name, manufacturer, mass, etc

slots Object

Collection of slot groups (standard/standard, internal, hardpoints) with their max class size.

Public Members

public [p]: * source

public armour: * source

public availCS: * source

public bulkheads: {"incCost": boolean, "maxClass": number} source

public cargoCapacity: number source

public cargoHatch: {"m": *, "type": string} source

public costList: * source

public fuelCapacity: number source

public fullTankRange: * source

public hullExplRes: number source

public hullKinRes: number source

public hullThermRes: number source

public id: * source

public ladenFastestRange: * source

public ladenMass: number source

public ladenRange: * source

public m: {"incCost": boolean, "type": string, "discountedCost": *, "m": *} source

public maxJumpCount: * source

public moduleCostMultiplier: number source

public modulearmour: * source

public moduleprotection: * source

public passengerCapacity: number source

public pitches: * source

public powerAvailable: * source

public powerDeployed: * source

public powerList: * source

public powerRetracted: * source

public priorityBands: undefined[] source

public rolls: * source

public serialized: {} source

public shield: * source

public shieldCells: number source

public shieldExplRes: number source

public shieldKinRes: number source

public shieldThermRes: number source

public speeds: * source

public topBoost: * source

public topPitch: * source

public topRoll: * source

public topSpeed: * source

public topYaw: * source

public totalAbsDpe: number source

public totalAbsDps: number source

public totalAbsSDps: number source

public totalCost: * source

public totalDpe: number source

public totalDps: number source

public totalEps: number source

public totalExplDpe: number source

public totalExplDps: number source

public totalExplSDps: number source

public totalHps: number source

public totalKinDpe: number source

public totalKinDps: number source

public totalKinSDps: number source

public totalSDps: number source

public totalThermDpe: number source

public totalThermDps: number source

public totalThermSDps: number source

public unladenFastestRange: * source

public unladenMass: * source

public unladenRange: * source

public yaws: * source

Public Methods

public applyDiscounts(shipDiscount: Number, moduleDiscount: Number): this source

Recalculate all item costs and total based on discounts.

Params:

NameTypeAttributeDescription
shipDiscount Number

Ship cost discount (e.g. 0.1 === 10% discount)

moduleDiscount Number

Module cost discount (e.g. 0.75 === 25% discount)

Return:

this

The current ship instance for chaining

public buildFrom(serializedString: String): this source

Updates an existing ship instance's slots with modules determined by the code.

Params:

NameTypeAttributeDescription
serializedString String

The string to deserialize

Return:

this

The current ship instance for chaining

public buildWith(comps: Object, priorities: array, enabled: Array, mods: Array, blueprints: Array): this source

Builds/Updates the ship instance with the ModuleUtils[comps] passed in.

Params:

NameTypeAttributeDescription
comps Object

Collection of ModuleUtils used to build the ship

priorities array

Slot priorities

enabled Array

Slot active/inactive

mods Array

Modifications

blueprints Array

Blueprints for modifications

Return:

this

The current ship instance for chaining

public calcLadenRange(massDelta: Number, fuel: Number, fsd: Object): Number source

Calculate the hypothetical laden jump range based on a potential change in mass, fuel, or FSD

Params:

NameTypeAttributeDescription
massDelta Number

Optional - Change in laden mass (mass + cargo + fuel)

fuel Number

Optional - Available fuel (defaults to max fuel based on FSD)

fsd Object

Optional - Frame Shift Drive (or use mounted FSD)

Return:

Number

Jump range in Light Years

public calcLowestPossibleMass(m: Object): number source

Calculate the lowest possible mass for this ship.

Params:

NameTypeAttributeDescription
m Object

Module override set (standard type => Module)

Return:

number

The lowest possible mass for this ship

public calcPitch(eng: Number, fuel: Number, cargo: Number, boost: boolean): Number source

Calculate the pitch for a given configuration

Params:

NameTypeAttributeDescription
eng Number

Number of pips in ENG

fuel Number

Amount of fuel carried

cargo Number

Amount of cargo carried

boost boolean

true if boost is applied

Return:

Number

Pitch

public calcRoll(eng: Number, fuel: Number, cargo: Number, boost: boolean): Number source

Calculate the roll for a given configuration

Params:

NameTypeAttributeDescription
eng Number

Number of pips in ENG

fuel Number

Amount of fuel carried

cargo Number

Amount of cargo carried

boost boolean

true if boost is applied

Return:

Number

Roll

public calcShieldStrengthWith(sg: Object, multiplierDelta: Number): Number source

Calculate the hypothetical shield strength for the ship using the specified parameters

Params:

NameTypeAttributeDescription
sg Object

[optional] Shield Generator to use

multiplierDelta Number

[optional] Change to shield multiplier (+0.2, - 0.12, etc)

Return:

Number

Shield strength in MJ

public calcSpeed(eng: Number, fuel: Number, cargo: Number, boost: boolean): Number source

Calculate the speed for a given configuration

Params:

NameTypeAttributeDescription
eng Number

Number of pips in ENG

fuel Number

Amount of fuel carried

cargo Number

Amount of cargo carried

boost boolean

true if boost is applied

Return:

Number

Speed

public calcSpeedsWith(fuel: Number, cargo: Number): array source

Calculate the hypothetical top speeds at cargo and fuel tonnage

Params:

NameTypeAttributeDescription
fuel Number

Fuel available in tons

cargo Number

Cargo in tons

Return:

array

Speed at pip settings

public calcUnladenRange(massDelta: Number, fuel: Number, fsd: Object): Number source

Calculate the hypothetical unladen jump range based on a potential change in mass, fuel, or FSD

Params:

NameTypeAttributeDescription
massDelta Number

Optional - Change in ship mass

fuel Number

Optional - Available fuel (defaults to lesser of fuel capacity or max fuel based on FSD)

fsd Object

Optional - Frame Shift Drive (or use mounted FSD)

Return:

Number

Jump range in Light Years

public calcYaw(eng: Number, fuel: Number, cargo: Number, boost: boolean): Number source

Calculate the yaw for a given configuration

Params:

NameTypeAttributeDescription
eng Number

Number of pips in ENG

fuel Number

Amount of fuel carried

cargo Number

Amount of cargo carried

boost boolean

true if boost is applied

Return:

Number

Yaw

public canBoost(cargo: Number, fuel: Number): [type] source

Can the ship boost

Params:

NameTypeAttributeDescription
cargo Number

Amount of cargo in the ship

fuel Number

Amount of fuel in the ship

Return:

[type]

True if boost capable

public canThrust(cargo: Number, fuel: Number): [type] source

Can the ship thrust/move

Params:

NameTypeAttributeDescription
cargo Number

Amount of cargo in the ship

fuel Number

Amount of fuel in the ship

Return:

[type]

True if thrusters operational

public clearModifications(m: Number) source

Clear all modification values for a module

Params:

NameTypeAttributeDescription
m Number

The module for which to clear the modifications

public clearModuleBlueprint(m: Object) source

Clear blueprint for a module

Params:

NameTypeAttributeDescription
m Object

The module for which to clear the blueprint

public clearModuleSpecial(m: Object) source

Clear special for a module

Params:

NameTypeAttributeDescription
m Object

The module for which to clear the blueprint

public decodeModificationsString(code: String, arr: Array) source

Populate the modifications array with modification values from the code

Params:

NameTypeAttributeDescription
code String

Serialized modification code

arr Array

Modification array

public decodeModificationsStruct(buffer: String, modArr: Array, blueprintArr: Array) source

Populate the modifications array with modification values from the code. See updateModificationsString() for details of the structure.

Params:

NameTypeAttributeDescription
buffer String

Buffer holding modification info

modArr Array

Modification array

blueprintArr Array

Blueprint array

public diminishingReturns(val: Number, drll: Number, drul: Number): this source

Calculate diminishing returns value, where values below a given limit are returned as-is, and values between the lower and upper limit of the diminishing returns are given at half value. Commonly used for resistances.

Params:

NameTypeAttributeDescription
val Number

The value

drll Number

The lower limit for diminishing returns

drul Number

The upper limit for diminishing returns

Return:

this

The ship instance (for chaining operations)

public emptyHardpoints(): this source

Empties all hardpoints and utility slots

Return:

this

The current ship instance for chaining

public emptyInternal(): this source

Empties all Internal slots

Return:

this

The current ship instance for chaining

public emptyUtility(): this source

Empties all Utility slots

Return:

this

The current ship instance for chaining

public emptyWeapons(): this source

Empties all hardpoints

Return:

this

The current ship instance for chaining

public findInternalByGroup(group: String): Number source

Find an internal slot that has an installed modul of the specific group.

Params:

NameTypeAttributeDescription
group String

Module group/type

Return:

Number

The index of the slot in ship.internal

public findShieldGenerator(): object source

Find the shield generator for this ship

Return:

object

The shield generator module for this ship

public getAvailableModules(): ModuleSet source

Get the set of available modules for this ship

Return:

ModuleSet

Available module set

public getHardpointsString(): String source

Serializes the hardpoints and utility modules to a string

Return:

String

Serialized hardpoints and utility modules 'code'

public getInternalString(): String source

Serializes the internal modules to a string

Return:

String

Serialized internal modules 'code'

public getModificationsString(): String source

Serializes the modifications to a string

Return:

String

Serialized modifications 'code'

public getPowerEnabledString(): String source

Get the serialized module active/inactive settings

Return:

String

Serialized active/inactive settings

public getPowerPrioritiesString(): String source

Get the serialized module priority settings

Return:

String

Serialized priority settings

public getSlotStatus(slot: Object, deployed: boolean): Number source

Returns the a slots power status: 0 - No status [Blank] 1 - Disabled (Switched off) 2 - Offline (Insufficient power available) 3 - Online

Params:

NameTypeAttributeDescription
slot Object

Slot model

deployed boolean

True - power used when hardpoints are deployed

Return:

Number

status index

public getStandardString(): String source

Serializes the standard modules to a string

Return:

String

Serialized standard modules 'code'

public optimizeMass(m: Object): this source

Optimize for the lower mass build that can still boost and power the ship without power management.

Params:

NameTypeAttributeDescription
m Object

Standard Module overrides

Return:

this

The current ship instance for chaining

public recalculateArmour(): this source

Update armour and hull resistances

Return:

this

The ship instance (for chaining operations)

public recalculateDps(): this source

Calculate damage per second and related items for weapons

Return:

this

The ship instance (for chaining operations)

public recalculateEps(): this source

Calculate energy per second for weapons

Return:

this

The ship instance (for chaining operations)

public recalculateHps(): this source

Calculate heat per second for weapons

Return:

this

The ship instance (for chaining operations)

public recalculateMass(): this source

Eecalculate mass

Return:

this

The ship instance (for chaining operations)

public recalculateShield(): this source

Update shield

Return:

this

The ship instance (for chaining operations)

public recalculateShieldCells(): this source

Update shield cells

Return:

this

The ship instance (for chaining operations)

public setCostIncluded(item: Object, included: boolean): this source

Include/Exclude a item/slot in cost calculations

Params:

NameTypeAttributeDescription
item Object

Slot or item

included boolean

Cost included

Return:

this

The current ship instance for chaining

public setModification(m: Object, name: Object, value: Number, sentfromui: bool) source

Set a modification value and update ship stats

Params:

NameTypeAttributeDescription
m Object

The module to change

name Object

The name of the modification to change

value Number

The new value of the modification. The value of the modification is scaled to provide two decimal places of precision in an integer. For example 1.23% is stored as 123

sentfromui bool

True if this update was sent from the UI

public setModuleBlueprint(m: Object, bp: Object) source

Set blueprint for a module

Params:

NameTypeAttributeDescription
m Object

The module for which to set the blueprint

bp Object

The blueprint

public setModuleSpecial(m: Object, special: Object) source

Set special for a module

Params:

NameTypeAttributeDescription
m Object

The module for which to set the blueprint

special Object

The special

public setSlotEnabled(slot: Object, enabled: boolean): this source

Set slot active/inactive

Params:

NameTypeAttributeDescription
slot Object

Slot model

enabled boolean

True - active

Return:

this

The current ship instance for chaining

public setSlotPriority(slot: Object, newPriority: Number): boolean source

Will change the priority of the specified slot if the new priority is valid

Params:

NameTypeAttributeDescription
slot Object

The slot to be updated

newPriority Number

The new priority to be set

Return:

boolean

Returns true if the priority was changed (within range)

public toString(): String source

Serializes the ship to a string

Return:

String

Serialized ship 'code'

public updateJumpStats(): this source

Jump Range and total range calculations

Return:

this

The ship instance (for chaining operations)

public updateModificationsString(): this source

Update the modifications string. This is a binary structure. It starts with a byte that identifies a slot, with bulkheads being ID 0 and moving through standard modules, hardpoints, and finally internal modules. It then contains one or more modifications, with each modification being a one-byte modification ID and at two-byte modification value. Modification IDs are based on the array in Modifications.modifications. The list of modifications is terminated by a modification ID of -1. The structure then repeats for the next module, and the next, and is terminated by a slot ID of -1.

Return:

this

The ship instance (for chaining operations)

public updateMovement(): this source

Update movement values

Return:

this

The ship instance (for chaining operations)

public updatePowerEnabledString(): this source

Update the serialized power active/inactive string

Return:

this

The ship instance (for chaining operations)

public updatePowerGenerated(): this source

Update power calculations when amount generated changes

Return:

this

The ship instance (for chaining operations)

public updatePowerPrioritesString(): this source

Update the serialized power priorites string

Return:

this

The ship instance (for chaining operations)

public updatePowerUsed(): this source

Update power calculations when amount consumed changes

Return:

this

The ship instance (for chaining operations)

public updateStats(slot: Object, n: Object, old: Object, preventUpdate: boolean): this source

Updates the ship's cumulative and aggregated stats based on the module change.

Params:

NameTypeAttributeDescription
slot Object

The slot being updated

n Object

The new module (may be null)

old Object

The old module (may be null)

preventUpdate boolean

If true the global ship state will not be updated

Return:

this

The ship instance (for chaining operations)

public upgradeInternals(internals: array, offset: int, priorities: array, enableds: array, modifications: array, blueprints: array, version: int) source

Upgrade information about internals with version changes

Params:

NameTypeAttributeDescription
internals array

the internals from the ship code

offset int

the offset of the internals information in the priorities etc. arrays

priorities array

the existing priorities arrray

enableds array

the existing enableds arrray

modifications array

the existing modifications arrray

blueprints array

the existing blueprints arrray

version int

the version of the information

public use(slot: Object, mdef: Object, preventUpdate: boolean): this source

Update a slot with a the modul if the id is different from the current id for this slot. Has logic handling ModuleUtils that you may only have 1 of (Shield Generator or Refinery).

Params:

NameTypeAttributeDescription
slot Object

The modul slot

mdef Object

Properties for the selected modul

preventUpdate boolean

If true, do not update aggregated stats

Return:

this

The ship instance (for chaining operations)

public useBulkhead(index: Number, preventUpdate: boolean): this source

Mount the specified bulkhead type (index)

Params:

NameTypeAttributeDescription
index Number

Bulkhead index [0-4]

preventUpdate boolean

Prevent summary update

Return:

this

The ship instance (for chaining operations)

public useLightestStandard(m: Object): this source

Use the lightest standard ModuleUtils unless otherwise specified

Params:

NameTypeAttributeDescription
m Object

Module override set (standard type => module ID)

Return:

this

The ship instance (for chaining operations)

public useStandard(rating: String): this source

Set all standard slots to use the speficied rating and class based on the slot's max class

Params:

NameTypeAttributeDescription
rating String

Module Rating (A-E)

Return:

this

The ship instance (for chaining operations)

public useUtility(group: String, rating: String, name: String, clobber: boolean): this source

Fill all utility slots with the specified module

Params:

NameTypeAttributeDescription
group String

Group name

rating String

Rating [A-I]

name String

Module name

clobber boolean

Overwrite non-empty slots

Return:

this

The ship instance (for chaining operations)

public useWeapon(group: [type], mount: [type], missile: [type], clobber: boolean): this source

[useWeapon description]

Params:

NameTypeAttributeDescription
group [type]

[description]

mount [type]

[description]

missile [type]

[description]

clobber boolean

Overwrite non-empty slots

Return:

this

The ship instance (for chaining operations)