Add Acceleration Segment + Improved Thrust calculation
This commit is contained in:
parent
90085dd87a
commit
986cf8453e
9 changed files with 288 additions and 138 deletions
src/lib
|
@ -2,12 +2,13 @@ import {Thruster, THRUSTER_LIST, THRUSTER_TYPE_LIST} from "$lib/thruster.svelte"
|
|||
import {Grid} from "$lib/grid";
|
||||
import {INVENTORIES, Inventory} from "$lib/containers.svelte";
|
||||
import type {Fuel} from "$lib/fuel";
|
||||
import type {CargoMaterial} from "$lib/materials";
|
||||
|
||||
export class Ship {
|
||||
thrusters: Array<Thruster> = $state([]);
|
||||
inventories: Array<Inventory> = $state([]);
|
||||
grid: Grid = $state(Grid.Small);
|
||||
weight: number = $state(0);
|
||||
tons: number = $state(0);
|
||||
|
||||
constructor(grid: Grid = Grid.Small) {
|
||||
this.grid = grid;
|
||||
|
@ -22,7 +23,7 @@ export class Ship {
|
|||
return inventory.details.key;
|
||||
}),
|
||||
grid: this.grid,
|
||||
weight: this.weight,
|
||||
weight: this.tons,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,7 +50,7 @@ export class Ship {
|
|||
}
|
||||
|
||||
if (ship.weight !== undefined) {
|
||||
this.weight = ship.weight;
|
||||
this.tons = ship.weight;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -85,14 +86,6 @@ export class Ship {
|
|||
return thrust;
|
||||
}
|
||||
|
||||
getTotalMaxThrust(): number {
|
||||
let thrust = 0;
|
||||
this.thrusters.forEach((thruster) => {
|
||||
thrust += thruster.getMaxThrust(this.grid);
|
||||
});
|
||||
return thrust;
|
||||
}
|
||||
|
||||
getFuelTypes(): Array<Fuel> {
|
||||
let fuels: Array<Fuel> = [];
|
||||
this.thrusters.forEach((thruster) => {
|
||||
|
@ -102,4 +95,29 @@ export class Ship {
|
|||
})
|
||||
return fuels;
|
||||
}
|
||||
|
||||
getTotalWeightPossible(gravity: number, atmosphere: number): number {
|
||||
return this.getTotalThrust(atmosphere) / (gravity * 9.81)
|
||||
}
|
||||
|
||||
getVehicleWeightPossible(gravity: number, atmosphere: number, inventoryMultiplier: number, material: CargoMaterial): number {
|
||||
return this.getTotalWeightPossible(gravity, atmosphere) - this.getTotalVolume(inventoryMultiplier) * material.density;
|
||||
}
|
||||
|
||||
getVehicleWeight(): number {
|
||||
return (this.tons * 1000);
|
||||
}
|
||||
|
||||
getTotalWeight(inventoryMultiplier: number, material: CargoMaterial) {
|
||||
return this.getVehicleWeight() + this.getTotalVolume(inventoryMultiplier) * material.density;
|
||||
}
|
||||
|
||||
getAcceleration(atmosphere: number, inventoryMultiplier: number, material: CargoMaterial) {
|
||||
console.log(material)
|
||||
return this.getTotalThrust(atmosphere) / this.getTotalWeight(inventoryMultiplier, material)
|
||||
}
|
||||
|
||||
getMaxAcceleration(atmosphere: number) {
|
||||
return this.getTotalThrust(atmosphere) / this.getVehicleWeight();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue