'use strict'; /* * POST /backbone/:id/ship {fromTownId, cargo}: send resources from one of your POPs to a landing site your alliance holds, to * feed its stockpile. A normal transport (same links, 500 per link, 12 tiles/h) whose target is the site's tile; on arrival it is * added to the stockpile if the sender's alliance still holds the site, otherwise it rides home. */ const { GameError } = require('../errors'); const { settle } = require('../state'); const { ownedTown } = require('./build'); const { launchTransport } = require('./sendTransport'); const { holderContext } = require('./backboneBuild'); const ctxOf = require('../military/ctx'); module.exports = function backboneShip(ctx0, { userId, siteId, fromTownId, cargo }) { const ctx = ctxOf(ctx0); const { db, now } = ctx; const { site } = holderContext(db, userId, siteId, now); const from = ownedTown(db, userId, fromTownId); if (from.worldId !== site.world_id) throw new GameError('not_found', { what: 'town' }); settle(db, from, now); const mv = launchTransport(ctx, from, { x: site.x, y: site.y }, cargo || {}, { siteId: site.id }); return { movementId: mv.id, type: 'transport', siteId: site.id, fromTownId: from.id, toTownId: null, to: { x: site.x, y: site.y }, cargo: mv.cargo, departAt: mv.departAt, arriveAt: mv.arriveAt }; };