Skip to content

Commit

Permalink
chore: rename changeMounts to mountFromDelivery
Browse files Browse the repository at this point in the history
  • Loading branch information
eseidel committed Sep 24, 2023
1 parent 027339d commit db4655d
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 27 deletions.
6 changes: 3 additions & 3 deletions packages/cli/lib/behavior/advance.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'package:cli/behavior/behavior.dart';
import 'package:cli/behavior/buy_ship.dart';
import 'package:cli/behavior/central_command.dart';
import 'package:cli/behavior/change_mounts.dart';
import 'package:cli/behavior/deliver.dart';
import 'package:cli/behavior/explorer.dart';
import 'package:cli/behavior/miner.dart';
import 'package:cli/behavior/mount_from_delivery.dart';
import 'package:cli/behavior/surveyor.dart';
import 'package:cli/behavior/trader.dart';
import 'package:cli/cache/caches.dart';
Expand Down Expand Up @@ -51,8 +51,8 @@ Future<DateTime?> Function(
return advanceExplorer;
case Behavior.deliver:
return advanceDeliver;
case Behavior.changeMounts:
return advanceChangeMounts;
case Behavior.mountFromDelivery:
return advanceMountFromDelivery;
case Behavior.idle:
return _advanceIdle;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/lib/behavior/central_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ extension BehaviorCacheExtensions on BehaviorCache {
final claimed = MountSymbolSet();
for (final state in states) {
final behavior = state.behavior;
if (behavior != Behavior.changeMounts) {
if (behavior != Behavior.mountFromDelivery) {
continue;
}
final mountSymbol = state.mountToAdd;
Expand Down Expand Up @@ -190,7 +190,7 @@ class CentralCommand {
],
ShipRole.EXCAVATOR: [
// We'll always upgrade the ship as our best option.
Behavior.changeMounts,
Behavior.mountFromDelivery,
if (ship.canMine) Behavior.miner,
if (!ship.canMine && ship.hasSurveyor) Behavior.surveyor,
Behavior.idle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,21 @@ ShipMountSymbolEnum? _pickMountFromAvailable(
return needed.firstWhereOrNull((mount) => available[mount] > 0);
}

/// Returns ShipCargoItems for mounts in our cargo if any.
/// Used for getting rid of extra mounts at the end of a change-mounts job.
Iterable<ShipCargoItem> mountsInCargo(Ship ship) sync* {
for (final cargoItem in ship.cargo.inventory) {
final isMount = mountSymbolForTradeSymbol(cargoItem.tradeSymbol) != null;
if (isMount) {
yield cargoItem;
extension on Ship {
/// Returns ShipCargoItems for mounts in our cargo if any.
/// Used for getting rid of extra mounts at the end of a change-mounts job.
Iterable<ShipCargoItem> mountsInCargo() sync* {
for (final cargoItem in cargo.inventory) {
final isMount = mountSymbolForTradeSymbol(cargoItem.tradeSymbol) != null;
if (isMount) {
yield cargoItem;
}
}
}
}

/// Change mounts on a ship.
Future<DateTime?> advanceChangeMounts(
Future<DateTime?> advanceMountFromDelivery(
Api api,
Database db,
CentralCommand centralCommand,
Expand Down Expand Up @@ -125,7 +127,7 @@ Future<DateTime?> advanceChangeMounts(
);

// Give the delivery ship our extra mount if we have one.
final extraMounts = mountsInCargo(ship).toList();
final extraMounts = ship.mountsInCargo();
if (extraMounts.isNotEmpty) {
// This could send more items than deliveryShip has space for.
for (final cargoItem in extraMounts) {
Expand Down
18 changes: 9 additions & 9 deletions packages/cli/test/behavior/central_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,15 @@ void main() {
BehaviorState(ShipSymbol.fromString('X-A'), Behavior.explorer),
ShipSymbol.fromString('X-B'):
BehaviorState(ShipSymbol.fromString('X-B'), Behavior.trader),
ShipSymbol.fromString('X-C'):
BehaviorState(ShipSymbol.fromString('X-C'), Behavior.changeMounts)
..mountToAdd = ShipMountSymbolEnum.GAS_SIPHON_I,
ShipSymbol.fromString('X-D'):
BehaviorState(ShipSymbol.fromString('X-D'), Behavior.changeMounts)
..mountToAdd = ShipMountSymbolEnum.GAS_SIPHON_I,
ShipSymbol.fromString('X-E'):
BehaviorState(ShipSymbol.fromString('X-E'), Behavior.changeMounts)
..mountToAdd = ShipMountSymbolEnum.GAS_SIPHON_II,
ShipSymbol.fromString('X-C'): BehaviorState(
ShipSymbol.fromString('X-C'), Behavior.mountFromDelivery)
..mountToAdd = ShipMountSymbolEnum.GAS_SIPHON_I,
ShipSymbol.fromString('X-D'): BehaviorState(
ShipSymbol.fromString('X-D'), Behavior.mountFromDelivery)
..mountToAdd = ShipMountSymbolEnum.GAS_SIPHON_I,
ShipSymbol.fromString('X-E'): BehaviorState(
ShipSymbol.fromString('X-E'), Behavior.mountFromDelivery)
..mountToAdd = ShipMountSymbolEnum.GAS_SIPHON_II,
},
fs: MemoryFileSystem.test(),
);
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/test/behavior/change_mounts_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:cli/behavior/central_command.dart';
import 'package:cli/behavior/change_mounts.dart';
import 'package:cli/behavior/mount_from_delivery.dart';
import 'package:cli/cache/caches.dart';
import 'package:cli/logger.dart';
import 'package:cli/nav/route.dart';
Expand Down Expand Up @@ -115,12 +115,12 @@ void main() {
when(() => centralCommand.unclaimedMountsAt(symbol))
.thenReturn(MountSymbolSet.from([ShipMountSymbolEnum.SURVEYOR_II]));

final state = BehaviorState(shipSymbol, Behavior.changeMounts);
final state = BehaviorState(shipSymbol, Behavior.mountFromDelivery);

final logger = _MockLogger();
final waitUntil = await runWithLogger(
logger,
() => advanceChangeMounts(
() => advanceMountFromDelivery(
api,
db,
centralCommand,
Expand Down
2 changes: 1 addition & 1 deletion packages/types/lib/behavior.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ enum Behavior {
deliver,

/// Change mounts on this ship.
changeMounts,
mountFromDelivery,

/// Explore the universe.
explorer;
Expand Down

0 comments on commit db4655d

Please sign in to comment.