Skip to content

Commit

Permalink
command ship also shuttles
Browse files Browse the repository at this point in the history
  • Loading branch information
staff0rd committed Mar 27, 2024
1 parent 7a54c78 commit d8f64ae
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
20 changes: 17 additions & 3 deletions src/features/actors/shuttle.ts
Expand Up @@ -14,18 +14,30 @@ export const shuttleActorFactory = (
miningLocation: IWaypoint,
ships: ShipEntity[],
sell: TradeSymbol[],
) =>
decisionMaker(shuttle, agent, act, async (ship: ShipEntity, agent: AgentEntity) => {
) => decisionMaker(shuttle, agent, act, shuttleLogicFactory(act, markets, miningLocation, ships, sell))

export const shuttleLogicFactory =
(
act: Awaited<ReturnType<typeof getActor>>,
markets: WaypointEntity[],
miningLocation: IWaypoint,
ships: ShipEntity[],
sell: TradeSymbol[],
) =>
async (ship: ShipEntity, agent: AgentEntity) => {
await act.refuelShip(ship)
await act.jettisonUnwanted(ship, sell)
const currentAction = ship.action?.type
if (!currentAction) {
await act.updateShipAction(ship, ShipActionType.FILL)
return
} else if (currentAction === ShipActionType.FILL) {
if (ship.cargo.units === ship.cargo.capacity) {
await act.updateShipAction(ship, ShipActionType.SELL)
return
} else if (ship.nav.waypointSymbol !== miningLocation.symbol) {
await act.navigateShip(ship, miningLocation, markets)
return
} else {
const capacity = ship.cargo.capacity - ship.cargo.units
const dronesAtMiningLocation = ships.filter(
Expand All @@ -40,12 +52,14 @@ export const shuttleActorFactory = (
} else if (currentAction === ShipActionType.SELL) {
if (ship.cargo.units === 0) {
await act.updateShipAction(ship, ShipActionType.FILL)
return
} else if (ship.cargo.inventory.find((p) => p.symbol === agent.contractGood.tradeSymbol)?.units) {
await act.deliverGoods(ship)
return
} else {
await act.sellGoods(markets, ship, [agent.contractGood.tradeSymbol as TradeSymbol])
return
}
} else throw new Error(`Unknown action: ${currentAction}`)
await act.wait(1000 * 10)
})
}
12 changes: 6 additions & 6 deletions src/features/status/startup.ts
Expand Up @@ -5,7 +5,7 @@ import { updateShips } from '../../db/updateShips'
import { invariant } from '../../invariant'
import { log } from '../../logging/configure-logging'
import { miningDroneActorFactory } from '../actors/mining-drone'
import { shuttleActorFactory } from '../actors/shuttle'
import { shuttleActorFactory, shuttleLogicFactory } from '../actors/shuttle'
import { ShipEntity } from '../ship/ship.entity'
import { getActor } from './actions/getActor'
import { getAgent } from './actions/getAgent'
Expand Down Expand Up @@ -39,8 +39,11 @@ export async function startup() {
},
} = await api.systems.getSystemWaypoints(commandShip.nav.systemSymbol, undefined, 20, 'ENGINEERED_ASTEROID')

const miningDronesToPurchase = 5
const miningDronesToPurchase = 15
const shuttlesToPurchase = 1
const keep: TradeSymbol[] = ['IRON_ORE', 'COPPER_ORE', 'ALUMINUM_ORE']

const shuttleLogic = shuttleLogicFactory(act, markets, engineeredAsteroid, ships, keep)

await decisionMaker(commandShip, agent, act, async (ship: ShipEntity) => {
if (!agent.contract || agent.contract.fulfilled) {
Expand All @@ -53,8 +56,6 @@ export async function startup() {
return
}

const keep: TradeSymbol[] = ['IRON_ORE', 'COPPER_ORE', 'ALUMINUM_ORE']

const miningDrones = ships.filter((s) => s.frame.symbol === 'FRAME_DRONE')
log.info('agent', `There are ${miningDrones.length} mining drones`)
// TODO: don't hardcode the price
Expand Down Expand Up @@ -84,8 +85,7 @@ export async function startup() {
})
}

log.info('ship', `${ship.label} has nothing to do, will idle 5 minutes`)
await act.wait(1000 * 60 * 5)
await shuttleLogic(commandShip, agent)
})
}

Expand Down

0 comments on commit d8f64ae

Please sign in to comment.