Skip to content

Commit

Permalink
chore: remove explicitBehavior dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
eseidel committed Sep 23, 2023
1 parent fa54ab5 commit cbde3e3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 41 deletions.
1 change: 0 additions & 1 deletion packages/cli/lib/behavior/advance.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ Future<DateTime?> advanceShipBehavior(
ship,
error.message,
error.timeout,
explicitBehavior: error.explicitBehavior,
);
}
return null;
Expand Down
16 changes: 3 additions & 13 deletions packages/cli/lib/behavior/behavior.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,27 @@ import 'package:types/types.dart';
@immutable
class JobException implements Exception {
/// Create a new job exception.
const JobException(
this.message,
this.timeout, {
this.explicitBehavior,
});
const JobException(this.message, this.timeout);

/// Why did the job error?
final String message;

/// How long should the calling behavior be disabled
final Duration timeout;

/// Was this exception thrown in a behavior other than the current one?
final Behavior? explicitBehavior;

@override
String toString() => 'JobException: $message, timeout: $timeout, '
'explicitBehavior: $explicitBehavior';
String toString() => 'JobException: $message, timeout: $timeout';

@override
bool operator ==(Object other) =>
other is JobException &&
message == other.message &&
timeout == other.timeout &&
explicitBehavior == other.explicitBehavior;
timeout == other.timeout;

@override
int get hashCode => Object.hash(
message,
timeout,
explicitBehavior,
);
}

Expand Down
33 changes: 6 additions & 27 deletions packages/cli/lib/behavior/central_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,6 @@ class CentralCommand {
/// Shorten the max age for explorer data.
Duration shortenMaxAgeForExplorerData() => _maxAgeForExplorerData ~/= 2;

// To tell a given explorer what to do.
// Figure out what squad they're in (are they watching a waypoint for us
// or are they exploring? and if so what jump gate network?)
// Then figure out what the next waypoint is for them to explore.
// If we don't have a cache of places to explore, collect a list
// of systems needing a visit.
// If there still aren't any places to explore, then we need to see if there
// is a place for them to watch.
// If there still isn't, then we print a warning and have them idle.

/// What template should we use for the given ship?
ShipTemplate? templateForShip(Ship ship) {
final genericMiner = ShipTemplate(
Expand Down Expand Up @@ -159,24 +149,18 @@ class CentralCommand {
return true;
}

// Consider having a config file like:
// https://gist.github.com/whyando/fed97534173437d8234be10ac03595e0
// instead of having this dynamic behavior function.
// At the top of the file because I change this so often.
// Consider a config file like:
// https://gist.github.com/whyando/fed97534173437d8234be10ac03595e0
// instead of having this dynamic behavior function.
/// What behavior should the given ship be doing?
Behavior behaviorFor(
Ship ship,
) {
Behavior behaviorFor(Ship ship) {
if (ship.isOutOfFuel) {
return Behavior.idle;
}

final shipCount = _shipCache.ships.length;

final behaviors = {
// TODO(eseidel): Evaluate based on expected value, not just order.
// Should mine until we have one ore-hound, then switch to survey-only?

ShipRole.COMMAND: [
// We should deliver first, but deliver can get stuck, so we'll
// try to buy a ship first.
Expand Down Expand Up @@ -226,15 +210,10 @@ class CentralCommand {
}

/// Disable the given behavior for [ship] for [duration].
void disableBehaviorForShip(
Ship ship,
String why,
Duration duration, {
Behavior? explicitBehavior,
}) {
void disableBehaviorForShip(Ship ship, String why, Duration duration) {
final shipSymbol = ship.shipSymbol;
final currentState = _behaviorCache.getBehavior(shipSymbol);
final behavior = explicitBehavior ?? currentState?.behavior;
final behavior = currentState?.behavior;
if (behavior == null) {
shipWarn(ship, '$shipSymbol has no behavior to disable.');
return;
Expand Down

0 comments on commit cbde3e3

Please sign in to comment.