Skip to content

Commit

Permalink
feat: start to makeShip work for COMMAND
Browse files Browse the repository at this point in the history
  • Loading branch information
eseidel committed Oct 14, 2023
1 parent b420921 commit 203e8b5
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 8 deletions.
3 changes: 3 additions & 0 deletions packages/cli/bin/ships_validate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ Future<void> command(FileSystem fs, ArgResults argResults) async {
type: shipType,
shipSymbol: ship.shipSymbol,
factionSymbol: FactionSymbols.fromJson(ship.registration.factionSymbol)!,
cooldown: ship.cooldown,
nav: ship.nav,
fuel: ship.fuel,
cargo: ship.cargo,
moduleSymbols: ship.modules.map((m) => m.symbol).toList(),
mountSymbols: ship.mounts.map((m) => m.symbol).toList(),
);
if (exampleShip == null) {
logger.info('Failed to make example ship for $shipType');
Expand Down
92 changes: 84 additions & 8 deletions packages/types/lib/ships.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@ class _FrameConfig {
required this.name,
required this.description,
required this.requirements,
required this.moduleSlots,
required this.mountingPoints,
});
final ShipFrameSymbolEnum frameSymbol;
final String name;
final String description;
final ShipRequirements requirements;
final int moduleSlots;
final int mountingPoints;
}

final _frameConfigs = [
Expand All @@ -35,6 +39,18 @@ final _frameConfigs = [
'A small, unmanned spacecraft used for exploration, reconnaissance, '
'and scientific research.',
requirements: ShipRequirements(crew: 0, power: 1),
moduleSlots: 0,
mountingPoints: 0,
),
_FrameConfig(
frameSymbol: ShipFrameSymbolEnum.FRIGATE,
name: 'Frame Frigate',
description:
'A medium-sized, multi-purpose spacecraft, often used for combat, '
'transport, or support operations.',
requirements: ShipRequirements(crew: 25, power: 8),
moduleSlots: 8,
mountingPoints: 5,
),
];

Expand Down Expand Up @@ -70,6 +86,15 @@ final _reactorConfigs = [
powerOutput: 3,
requirements: ShipRequirements(crew: 0),
),
_ReactorConfig(
reactorSymbol: ShipReactorSymbolEnum.FISSION_I,
name: 'Fission Reactor I',
description:
'A basic fission power reactor, used to generate electricity from '
'nuclear fission reactions.',
powerOutput: 31,
requirements: ShipRequirements(crew: 8),
),
];

_ReactorConfig? _reactorConfigForReactorSymbol(
Expand Down Expand Up @@ -106,6 +131,15 @@ final _engineConfigs = [
speed: 2,
requirements: ShipRequirements(crew: 0, power: 1),
),
_EngineConfig(
engineSymbol: ShipEngineSymbolEnum.ION_DRIVE_II,
name: 'Ion Drive II',
description: 'An advanced propulsion system that uses ionized particles to '
'generate high-speed, low-thrust acceleration, with improved '
'efficiency and performance.',
speed: 30,
requirements: ShipRequirements(crew: 8, power: 6),
),
];

_EngineConfig? _engineConfigForEngineSymbol(
Expand Down Expand Up @@ -187,8 +221,8 @@ class ShipConfig {
description: description,
condition: 100,
requirements: frameConfig?.requirements ?? ShipRequirements(crew: 0),
moduleSlots: 0,
mountingPoints: 0,
moduleSlots: frameConfig?.moduleSlots ?? 0,
mountingPoints: frameConfig?.mountingPoints ?? 0,
fuelCapacity: fuelCapacity,
);
}
Expand All @@ -210,13 +244,25 @@ class ShipConfig {
}

/// Get the initial ship crew for this config.
ShipCrew get crew => ShipCrew(
ShipCrew get crew {
if (shipTypeFromFrame(frameSymbol) == ShipType.PROBE) {
return ShipCrew(
current: 0,
required_: 0,
capacity: 0,
morale: 100,
wages: 0,
);
}
// Hack until we can compute this from modules/mounts.
return ShipCrew(
current: 59,
required_: 59,
capacity: 80,
morale: 100,
wages: 0,
);
}

/// Get the ship engine for this config.
ShipEngine get engine {
Expand Down Expand Up @@ -245,6 +291,15 @@ const _shipConfigs = [
cargoCapacity: 0,
fuelCapacity: 0,
),
ShipConfig(
type: ShipType.COMMAND_FRIGATE,
frameSymbol: ShipFrameSymbolEnum.FRIGATE,
role: ShipRole.COMMAND,
reactorSymbol: ShipReactorSymbolEnum.FISSION_I,
engineSymbol: ShipEngineSymbolEnum.ION_DRIVE_II,
cargoCapacity: 60,
fuelCapacity: 1200,
),
];

/// Get the ship template for a given ship type.
Expand Down Expand Up @@ -314,6 +369,26 @@ Ship? makeShipForTest({
);
}

/// Make an example ShipMount for a given mount symbol.
ShipMount makeMount(ShipMountSymbolEnum mountSymbol) {
return ShipMount(
symbol: mountSymbol,
name: mountSymbol.value,
description: mountSymbol.value,
requirements: ShipRequirements(crew: 0),
);
}

/// Make an example ShipModule for a given module symbol.
ShipModule makeModule(ShipModuleSymbolEnum moduleSymbol) {
return ShipModule(
symbol: moduleSymbol,
name: moduleSymbol.value,
description: moduleSymbol.value,
requirements: ShipRequirements(crew: 0),
);
}

/// Make Ship for comparison with an existing ship.
/// Uses the volatile parts of the existing ship, and the template for the
/// ship type to avoid needless differences.
Expand All @@ -324,6 +399,9 @@ Ship? makeShipForComparison({
required ShipNav nav,
required ShipFuel fuel,
required ShipCargo cargo,
required Cooldown cooldown,
required List<ShipModuleSymbolEnum> moduleSymbols,
required List<ShipMountSymbolEnum> mountSymbols,
}) {
final config = shipConfigForType(type);
if (config == null) return null;
Expand All @@ -335,17 +413,15 @@ Ship? makeShipForComparison({
name: shipSymbol.symbol,
role: config.role,
),
cooldown: Cooldown(
shipSymbol: shipSymbol.symbol,
remainingSeconds: 0,
totalSeconds: 0,
),
cooldown: cooldown,
nav: nav,
crew: config.crew,
frame: config.frame,
reactor: config.reactor,
engine: config.engine,
cargo: cargo,
fuel: fuel,
modules: moduleSymbols.map(makeModule).toList(),
mounts: mountSymbols.map(makeMount).toList(),
);
}

0 comments on commit 203e8b5

Please sign in to comment.