@shipload/sdk 2.0.0-rc11 → 2.0.0-rc13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/shipload.js CHANGED
@@ -2140,6 +2140,11 @@ const SHIP_CARGO_NOT_LOADED = 'Cannot unload cargo that is not loaded.';
2140
2140
  const WAREHOUSE_NOT_FOUND = 'Cannot find warehouse for given id.';
2141
2141
  const WAREHOUSE_ALREADY_AT_LOCATION = 'Warehouse already exists at this location.';
2142
2142
  const WAREHOUSE_CAPACITY_EXCEEDED = 'Warehouse capacity would be exceeded.';
2143
+ const ENTITY_CAPACITY_EXCEEDED = 'Entity cargo capacity would be exceeded.';
2144
+ const RECIPE_INPUTS_INSUFFICIENT = 'Insufficient inputs for recipe.';
2145
+ const RECIPE_INPUTS_INVALID = 'Input cargo does not match recipe requirements.';
2146
+ const RECIPE_INPUTS_EXCESS = 'Provided inputs exceed recipe requirements.';
2147
+ const RECIPE_INPUTS_MIXED = 'All stacks for a recipe input must be the same resource.';
2143
2148
 
2144
2149
  const PRECISION$1 = 10000;
2145
2150
  const CRAFT_ENERGY_DIVISOR = 150000;
@@ -2163,7 +2168,8 @@ exports.TaskType = void 0;
2163
2168
  TaskType[TaskType["WARP"] = 6] = "WARP";
2164
2169
  TaskType[TaskType["CRAFT"] = 7] = "CRAFT";
2165
2170
  TaskType[TaskType["DEPLOY"] = 8] = "DEPLOY";
2166
- TaskType[TaskType["DEPLOY_SHIP"] = 9] = "DEPLOY_SHIP";
2171
+ TaskType[TaskType["WRAP"] = 9] = "WRAP";
2172
+ TaskType[TaskType["UNWRAP"] = 10] = "UNWRAP";
2167
2173
  })(exports.TaskType || (exports.TaskType = {}));
2168
2174
  exports.LocationType = void 0;
2169
2175
  (function (LocationType) {
@@ -2264,7 +2270,7 @@ const DEPTH_THRESHOLD_T4 = 30000;
2264
2270
  const DEPTH_THRESHOLD_T5 = 55000;
2265
2271
  const LOCATION_MIN_DEPTH = 500;
2266
2272
  const LOCATION_MAX_DEPTH = 65535;
2267
- const YIELD_THRESHOLD = Math.floor(0.003 * 0xffffffff);
2273
+ const YIELD_THRESHOLD = Math.floor(0.001 * 0xffffffff);
2268
2274
  const PLANET_SUBTYPE_GAS_GIANT = 0;
2269
2275
  const PLANET_SUBTYPE_ROCKY = 1;
2270
2276
  const PLANET_SUBTYPE_TERRESTRIAL = 2;
@@ -2382,12 +2388,6 @@ function getEligibleResources(locationType, subtype, stratum) {
2382
2388
  return stratum >= threshold;
2383
2389
  });
2384
2390
  }
2385
- function depthScaleFactor(stratum) {
2386
- if (stratum <= 1)
2387
- return 1.0;
2388
- const logScale = Math.log(stratum) / Math.log(65535);
2389
- return 1.0 + logScale * 2.0;
2390
- }
2391
2391
 
2392
2392
  function deriveLocationSize(loc) {
2393
2393
  if (loc.type.toNumber() === exports.LocationType.EMPTY)
@@ -4576,10 +4576,14 @@ function isGatherableLocation(locationType) {
4576
4576
  }
4577
4577
  function getLocationTypeName(type) {
4578
4578
  switch (type) {
4579
- case exports.LocationType.EMPTY: return 'Empty';
4580
- case exports.LocationType.PLANET: return 'Planet';
4581
- case exports.LocationType.ASTEROID: return 'Asteroid';
4582
- case exports.LocationType.NEBULA: return 'Nebula';
4579
+ case exports.LocationType.EMPTY:
4580
+ return 'Empty';
4581
+ case exports.LocationType.PLANET:
4582
+ return 'Planet';
4583
+ case exports.LocationType.ASTEROID:
4584
+ return 'Asteroid';
4585
+ case exports.LocationType.NEBULA:
4586
+ return 'Nebula';
4583
4587
  }
4584
4588
  }
4585
4589
  function uint16(hash, offset) {
@@ -4909,1930 +4913,48 @@ var itemsData = [
4909
4913
  }
4910
4914
  ];
4911
4915
 
4912
- const items = itemsData.map((g) => exports.Item.from({
4913
- id: g.id,
4914
- name: g.name,
4915
- description: g.description,
4916
- mass: g.mass,
4917
- category: g.category,
4918
- tier: g.tier,
4919
- color: g.color,
4920
- }));
4921
- const itemIds = items.map((i) => i.id);
4922
- function getItem(itemId) {
4923
- const id = antelope.UInt16.from(itemId);
4924
- const item = items.find((i) => i.id.equals(id));
4925
- if (!item) {
4926
- throw new Error(`Item with id ${id} not found`);
4927
- }
4928
- return item;
4929
- }
4930
- function getItems() {
4931
- return items;
4932
- }
4933
-
4934
- function calc_orbital_altitude(mass) {
4935
- if (mass <= BASE_ORBITAL_MASS) {
4936
- return MIN_ORBITAL_ALTITUDE;
4937
- }
4938
- const ratio = mass / BASE_ORBITAL_MASS;
4939
- const capRatio = 10.0;
4940
- let scale = Math.log(ratio) / Math.log(capRatio);
4941
- scale = Math.min(scale, 1.0);
4942
- return MIN_ORBITAL_ALTITUDE + Math.floor((MAX_ORBITAL_ALTITUDE - MIN_ORBITAL_ALTITUDE) * scale);
4943
- }
4944
- function distanceBetweenCoordinates(origin, destination) {
4945
- return distanceBetweenPoints(origin.x, origin.y, destination.x, destination.y);
4946
- }
4947
- function distanceBetweenPoints(x1, y1, x2, y2) {
4948
- const x = Math.pow(x1 - x2, 2);
4949
- const y = Math.pow(y1 - y2, 2);
4950
- return antelope.UInt64.from(Math.sqrt(x + y) * PRECISION$1);
4951
- }
4952
- function lerp(origin, destination, time) {
4953
- return {
4954
- x: (1 - time) * Number(origin.x) + time * Number(destination.x),
4955
- y: (1 - time) * Number(origin.y) + time * Number(destination.y),
4956
- };
4957
- }
4958
- function rotation(origin, destination) {
4959
- return Math.atan2(destination.y - origin.y, destination.x - origin.x) * (180 / Math.PI) + 90;
4960
- }
4961
- function findNearbyPlanets(seed, origin, maxDistance = 20 * PRECISION$1) {
4962
- const nearbySystems = [];
4963
- const max = antelope.UInt64.from(maxDistance / PRECISION$1);
4964
- const xMin = antelope.Int64.from(origin.x).subtracting(max);
4965
- const xMax = antelope.Int64.from(origin.x).adding(max);
4966
- const yMin = antelope.Int64.from(origin.y).subtracting(max);
4967
- const yMax = antelope.Int64.from(origin.y).adding(max);
4968
- for (let x = Number(xMin); x <= Number(xMax); x++) {
4969
- for (let y = Number(yMin); y <= Number(yMax); y++) {
4970
- const samePlace = x === Number(origin.x) && y === Number(origin.y);
4971
- if (!samePlace) {
4972
- const distance = distanceBetweenPoints(origin.x, origin.y, x, y);
4973
- if (Number(distance) <= Number(maxDistance)) {
4974
- const system = hasSystem(seed, { x, y });
4975
- if (system) {
4976
- nearbySystems.push({ origin, destination: { x, y }, distance });
4977
- }
4978
- }
4979
- }
4980
- }
4981
- }
4982
- return nearbySystems;
4983
- }
4984
- function calc_rechargetime(capacity, energy, recharge) {
4985
- const cap = antelope.UInt32.from(capacity);
4986
- const eng = antelope.UInt32.from(energy);
4987
- if (eng.gte(cap))
4988
- return antelope.UInt32.zero;
4989
- return cap.subtracting(eng).dividing(recharge);
4990
- }
4991
- function calc_ship_rechargetime(ship) {
4992
- if (!ship.generator)
4993
- return antelope.UInt32.from(0);
4994
- return calc_rechargetime(ship.generator.capacity, ship.energy ?? antelope.UInt16.from(0), ship.generator.recharge);
4995
- }
4996
- function calc_flighttime(distance, acceleration) {
4997
- return antelope.UInt32.from(2 * Math.sqrt(Number(distance) / acceleration));
4998
- }
4999
- function calc_loader_flighttime(ship, mass, altitude) {
5000
- const z = altitude ?? ship.coordinates.z?.toNumber() ?? calc_orbital_altitude(Number(mass));
5001
- return calc_flighttime(z, calc_loader_acceleration(ship, mass));
5002
- }
5003
- function calc_loader_acceleration(ship, mass) {
5004
- const thrust = ship.loaders ? Number(ship.loaders.thrust) : 0;
5005
- const loaderMass = ship.loaders ? Number(ship.loaders.mass) : 0;
5006
- return calc_acceleration(thrust, Number(mass) + loaderMass);
5007
- }
5008
- function calc_ship_flighttime(ship, mass, distance) {
5009
- const acceleration = calc_ship_acceleration(ship, mass);
5010
- return calc_flighttime(distance, acceleration);
5011
- }
5012
- function calc_ship_acceleration(ship, mass) {
5013
- const thrust = ship.engines ? Number(ship.engines.thrust) : 0;
5014
- return calc_acceleration(thrust, Number(mass));
5015
- }
5016
- function calc_acceleration(thrust, mass) {
5017
- return (thrust / mass) * PRECISION$1;
5018
- }
5019
- function calc_ship_mass(ship, cargos) {
5020
- const mass = antelope.UInt64.from(0);
5021
- mass.add(ship.hullmass);
5022
- if (ship.loaders && ship.loaders.quantity.gt(antelope.UInt32.zero)) {
5023
- mass.add(ship.loaders.mass.multiplying(ship.loaders.quantity));
5024
- }
5025
- for (const cargo of cargos) {
5026
- mass.add(getItem(cargo.item_id).mass.multiplying(cargo.quantity));
5027
- }
5028
- return mass;
5029
- }
5030
- function calc_energyusage(distance, drain) {
5031
- return antelope.UInt64.from(distance).dividing(PRECISION$1).multiplying(drain);
5032
- }
5033
- function calculateTransferTime(ship, cargos, quantities) {
5034
- let mass = antelope.UInt64.from(0);
5035
- for (const cargo of cargos) {
5036
- const qty = quantities?.get(Number(cargo.item_id)) ?? 0;
5037
- if (qty > 0) {
5038
- const good_mass = getItem(cargo.item_id).mass;
5039
- const cargo_mass = good_mass.multiplying(qty);
5040
- mass = antelope.UInt64.from(mass).adding(cargo_mass);
5041
- }
5042
- }
5043
- if (mass.equals(antelope.UInt64.zero)) {
5044
- return antelope.UInt32.from(0);
5045
- }
5046
- if (!ship.loaders)
5047
- return antelope.UInt32.from(0);
5048
- mass = antelope.UInt64.from(mass).adding(ship.loaders.mass);
5049
- const transfer_time = calc_loader_flighttime(ship, mass);
5050
- return transfer_time.dividing(ship.loaders.quantity);
5051
- }
5052
- function calculateRefuelingTime(ship) {
5053
- return calc_ship_rechargetime(ship);
5054
- }
5055
- function calculateFlightTime(ship, cargos, distance) {
5056
- const mass = calc_ship_mass(ship, cargos);
5057
- return calc_ship_flighttime(ship, mass, distance);
5058
- }
5059
- function calculateLoadTimeBreakdown(ship, cargos, loadQuantities, unloadQuantities) {
5060
- let mass_unload = antelope.UInt64.from(0);
5061
- let mass_load = antelope.UInt64.from(0);
5062
- for (const cargo of cargos) {
5063
- const goodId = Number(cargo.item_id);
5064
- const loadQty = loadQuantities?.get(goodId) ?? 0;
5065
- const unloadQty = unloadQuantities?.get(goodId) ?? 0;
5066
- if (loadQty > 0 || unloadQty > 0) {
5067
- const good = getItem(cargo.item_id);
5068
- if (loadQty > 0) {
5069
- const cargo_mass = good.mass.multiplying(loadQty);
5070
- mass_load = antelope.UInt64.from(mass_load).adding(cargo_mass);
5071
- }
5072
- if (unloadQty > 0) {
5073
- const cargo_mass = good.mass.multiplying(unloadQty);
5074
- mass_unload = antelope.UInt64.from(mass_unload).adding(cargo_mass);
5075
- }
5076
- }
5077
- }
5078
- let unloadTime = 0;
5079
- let loadTime = 0;
5080
- if (mass_unload.gt(antelope.UInt64.zero) && ship.loaders) {
5081
- const totalMass = antelope.UInt64.from(mass_unload).adding(ship.loaders.mass);
5082
- unloadTime = Number(calc_loader_flighttime(ship, totalMass));
5083
- }
5084
- if (mass_load.gt(antelope.UInt64.zero) && ship.loaders) {
5085
- const totalMass = antelope.UInt64.from(mass_load).adding(ship.loaders.mass);
5086
- loadTime = Number(calc_loader_flighttime(ship, totalMass));
5087
- }
5088
- const numLoaders = ship.loaders ? Number(ship.loaders.quantity) : 0;
5089
- const totalTime = numLoaders > 0 ? (unloadTime + loadTime) / numLoaders : 0;
5090
- const unloadTimePerLoader = numLoaders > 0 ? unloadTime / numLoaders : 0;
5091
- const loadTimePerLoader = numLoaders > 0 ? loadTime / numLoaders : 0;
5092
- return {
5093
- unloadTime: unloadTimePerLoader,
5094
- loadTime: loadTimePerLoader,
5095
- totalTime,
5096
- unloadMass: Number(mass_unload),
5097
- loadMass: Number(mass_load),
5098
- };
4916
+ const ITEM_ENGINE_T1 = 10100;
4917
+ const ITEM_GENERATOR_T1 = 10101;
4918
+ const ITEM_GATHERER_T1 = 10102;
4919
+ const ITEM_LOADER_T1 = 10103;
4920
+ const ITEM_MANUFACTURING_T1 = 10104;
4921
+ const ITEM_STORAGE_T1 = 10105;
4922
+ const ITEM_HAULER_T1 = 10106;
4923
+ const MODULE_ANY = 0;
4924
+ const MODULE_ENGINE = 1;
4925
+ const MODULE_GENERATOR = 2;
4926
+ const MODULE_GATHERER = 3;
4927
+ const MODULE_LOADER = 4;
4928
+ const MODULE_WARP = 5;
4929
+ const MODULE_CRAFTER = 6;
4930
+ const MODULE_LAUNCHER = 7;
4931
+ const MODULE_STORAGE = 8;
4932
+ const MODULE_HAULER = 9;
4933
+ function moduleAccepts(slotType, moduleType) {
4934
+ return slotType === MODULE_ANY || slotType === moduleType;
5099
4935
  }
5100
- function estimateTravelTime(ship, travelMass, distance, options = {}) {
5101
- const { needsRecharge = false, loadMass, unloadMass } = options;
5102
- const flightTime = calc_ship_flighttime(ship, antelope.UInt64.from(travelMass), antelope.UInt64.from(distance));
5103
- const rechargeTime = needsRecharge ? calc_ship_rechargetime(ship) : antelope.UInt32.zero;
5104
- let loadTime = antelope.UInt32.zero;
5105
- let unloadTime = antelope.UInt32.zero;
5106
- if (loadMass &&
5107
- antelope.UInt32.from(loadMass).gt(antelope.UInt32.zero) &&
5108
- ship.loaders &&
5109
- ship.loaders.quantity.gt(antelope.UInt32.zero)) {
5110
- const totalMass = antelope.UInt64.from(loadMass).adding(ship.loaders.mass);
5111
- loadTime = calc_loader_flighttime(ship, totalMass).dividing(ship.loaders.quantity);
5112
- }
5113
- if (unloadMass &&
5114
- antelope.UInt32.from(unloadMass).gt(antelope.UInt32.zero) &&
5115
- ship.loaders &&
5116
- ship.loaders.quantity.gt(antelope.UInt32.zero)) {
5117
- const totalMass = antelope.UInt64.from(unloadMass).adding(ship.loaders.mass);
5118
- unloadTime = calc_loader_flighttime(ship, totalMass).dividing(ship.loaders.quantity);
4936
+ function getModuleCapabilityType(itemId) {
4937
+ switch (itemId) {
4938
+ case ITEM_ENGINE_T1:
4939
+ return MODULE_ENGINE;
4940
+ case ITEM_GENERATOR_T1:
4941
+ return MODULE_GENERATOR;
4942
+ case ITEM_GATHERER_T1:
4943
+ return MODULE_GATHERER;
4944
+ case ITEM_LOADER_T1:
4945
+ return MODULE_LOADER;
4946
+ case ITEM_MANUFACTURING_T1:
4947
+ return MODULE_CRAFTER;
4948
+ case ITEM_STORAGE_T1:
4949
+ return MODULE_STORAGE;
4950
+ case ITEM_HAULER_T1:
4951
+ return MODULE_HAULER;
4952
+ default:
4953
+ return 0xff;
5119
4954
  }
5120
- return {
5121
- flightTime,
5122
- rechargeTime,
5123
- loadTime,
5124
- unloadTime,
5125
- total: flightTime.adding(rechargeTime).adding(loadTime).adding(unloadTime),
5126
- };
5127
- }
5128
- function estimateDealTravelTime(ship, shipMass, distance, loadMass) {
5129
- const needsRecharge = !hasEnergyForDistance$1(ship, distance);
5130
- const estimate = estimateTravelTime(ship, shipMass, distance, {
5131
- needsRecharge,
5132
- loadMass,
5133
- });
5134
- return estimate.total;
5135
4955
  }
5136
- function hasEnergyForDistance$1(ship, distance) {
5137
- if (!ship.engines)
5138
- return false;
5139
- const energyNeeded = antelope.UInt64.from(distance).dividing(PRECISION$1).multiplying(ship.engines.drain);
5140
- return antelope.UInt64.from(ship.energy ?? 0).gte(energyNeeded);
5141
- }
5142
- function getFlightOrigin(entity, flightTaskIndex) {
5143
- if (!entity.schedule)
5144
- return entity.coordinates;
5145
- let origin = entity.coordinates;
5146
- for (let i = 0; i < flightTaskIndex && i < entity.schedule.tasks.length; i++) {
5147
- const task = entity.schedule.tasks[i];
5148
- if (task.type.equals(exports.TaskType.TRAVEL) && task.coordinates) {
5149
- origin = task.coordinates;
5150
- }
5151
- }
5152
- return origin;
5153
- }
5154
- function getDestinationLocation(entity) {
5155
- if (!entity.schedule)
5156
- return undefined;
5157
- for (let i = entity.schedule.tasks.length - 1; i >= 0; i--) {
5158
- const task = entity.schedule.tasks[i];
5159
- if (task.type.equals(exports.TaskType.TRAVEL) && task.coordinates) {
5160
- return task.coordinates;
5161
- }
5162
- }
5163
- return undefined;
5164
- }
5165
- function getPositionAt(entity, taskIndex, taskProgress) {
5166
- if (!entity.schedule || entity.schedule.tasks.length === 0 || taskIndex < 0) {
5167
- return entity.coordinates;
5168
- }
5169
- const task = entity.schedule.tasks[taskIndex];
5170
- if (!task.type.equals(exports.TaskType.TRAVEL) || !task.coordinates) {
5171
- return getFlightOrigin(entity, taskIndex);
5172
- }
5173
- const origin = getFlightOrigin(entity, taskIndex);
5174
- const destination = task.coordinates;
5175
- const interpolated = lerp(origin, destination, taskProgress);
5176
- return {
5177
- x: Math.round(interpolated.x),
5178
- y: Math.round(interpolated.y),
5179
- };
5180
- }
5181
- function calc_transfer_duration(source, dest, cargoMass) {
5182
- if (cargoMass === 0) {
5183
- return 0;
5184
- }
5185
- let totalThrust = 0;
5186
- let totalLoaderMass = 0;
5187
- let totalQuantity = 0;
5188
- if (source.loaders) {
5189
- const thrust = typeof source.loaders.thrust === 'number'
5190
- ? source.loaders.thrust
5191
- : source.loaders.thrust.toNumber();
5192
- const mass = typeof source.loaders.mass === 'number'
5193
- ? source.loaders.mass
5194
- : source.loaders.mass.toNumber();
5195
- const qty = typeof source.loaders.quantity === 'number'
5196
- ? source.loaders.quantity
5197
- : source.loaders.quantity.toNumber();
5198
- totalThrust += thrust * qty;
5199
- totalLoaderMass += mass * qty;
5200
- totalQuantity += qty;
5201
- }
5202
- if (dest.loaders) {
5203
- const thrust = typeof dest.loaders.thrust === 'number'
5204
- ? dest.loaders.thrust
5205
- : dest.loaders.thrust.toNumber();
5206
- const mass = typeof dest.loaders.mass === 'number' ? dest.loaders.mass : dest.loaders.mass.toNumber();
5207
- const qty = typeof dest.loaders.quantity === 'number'
5208
- ? dest.loaders.quantity
5209
- : dest.loaders.quantity.toNumber();
5210
- totalThrust += thrust * qty;
5211
- totalLoaderMass += mass * qty;
5212
- totalQuantity += qty;
5213
- }
5214
- if (totalThrust === 0 || totalQuantity === 0) {
5215
- return 0;
5216
- }
5217
- const sourceZ = typeof source.location.z === 'number'
5218
- ? source.location.z
5219
- : source.location.z?.toNumber() ?? 0;
5220
- const destZ = typeof dest.location.z === 'number' ? dest.location.z : dest.location.z?.toNumber() ?? 0;
5221
- const distance = Math.abs(sourceZ - destZ);
5222
- const totalMass = cargoMass + totalLoaderMass;
5223
- const acceleration = calc_acceleration(totalThrust, totalMass);
5224
- const flightTime = 2 * Math.sqrt(distance / acceleration);
5225
- return Math.floor(flightTime / totalQuantity);
5226
- }
5227
-
5228
- function capsHasMovement(caps) {
5229
- return caps.engines !== undefined && caps.generator !== undefined;
5230
- }
5231
- function capsHasStorage(caps) {
5232
- return caps.capacity !== undefined;
5233
- }
5234
- function capsHasLoaders(caps) {
5235
- return caps.loaders !== undefined;
5236
- }
5237
- function capsHasGatherer(caps) {
5238
- return caps.gatherer !== undefined;
5239
- }
5240
- function capsHasMass(caps) {
5241
- return caps.hullmass !== undefined;
5242
- }
5243
-
5244
- function calcCargoItemMass(item) {
5245
- const itemDef = getItem(item.item_id);
5246
- let mass = antelope.UInt64.from(itemDef.mass).multiplying(item.quantity);
5247
- for (const mod of item.modules) {
5248
- if (mod.installed) {
5249
- const modDef = getItem(mod.installed.item_id);
5250
- mass = mass.adding(modDef.mass);
5251
- }
5252
- }
5253
- return mass;
5254
- }
5255
- function calcCargoMass(entity) {
5256
- let mass = antelope.UInt64.from(0);
5257
- for (const item of entity.cargo) {
5258
- mass = mass.adding(calcCargoItemMass(item));
5259
- }
5260
- return mass;
5261
- }
5262
- function availableCapacity$1(entity) {
5263
- const cargoMass = calcCargoMass(entity);
5264
- return entity.capacity.gt(cargoMass)
5265
- ? antelope.UInt64.from(entity.capacity).subtracting(cargoMass)
5266
- : antelope.UInt64.from(0);
5267
- }
5268
- function availableCapacityFromMass(capacity, cargoMass) {
5269
- const cap = antelope.UInt64.from(capacity);
5270
- const mass = antelope.UInt64.from(cargoMass);
5271
- return cap.gt(mass) ? cap.subtracting(mass) : antelope.UInt64.from(0);
5272
- }
5273
- function hasSpace$1(entity, goodMass, quantity) {
5274
- const additional = goodMass.multiplying(quantity);
5275
- return availableCapacity$1(entity).gte(additional);
5276
- }
5277
- function hasSpaceForMass(capacity, currentMass, additionalMass) {
5278
- return antelope.UInt64.from(currentMass).adding(additionalMass).lte(capacity);
5279
- }
5280
- function isFull$1(entity) {
5281
- return antelope.UInt64.from(entity.cargomass).gte(entity.capacity);
5282
- }
5283
- function isFullFromMass(capacity, cargoMass) {
5284
- return antelope.UInt64.from(cargoMass).gte(capacity);
5285
- }
5286
-
5287
- function hasSchedule$1(entity) {
5288
- return !!entity.schedule && entity.schedule.tasks.length > 0;
5289
- }
5290
- function isIdle(entity) {
5291
- return !hasSchedule$1(entity);
5292
- }
5293
- function getTasks(entity) {
5294
- return entity.schedule?.tasks || [];
5295
- }
5296
- function scheduleDuration(entity) {
5297
- if (!entity.schedule)
5298
- return 0;
5299
- return entity.schedule.tasks.reduce((sum, task) => sum + task.duration.toNumber(), 0);
5300
- }
5301
- function scheduleElapsed(entity, now) {
5302
- if (!entity.schedule)
5303
- return 0;
5304
- const started = entity.schedule.started.toDate();
5305
- const elapsed = Math.floor((now.getTime() - started.getTime()) / 1000);
5306
- return Math.max(0, elapsed);
5307
- }
5308
- function scheduleRemaining(entity, now) {
5309
- if (!entity.schedule)
5310
- return 0;
5311
- const duration = scheduleDuration(entity);
5312
- const elapsed = scheduleElapsed(entity, now);
5313
- return Math.max(0, duration - elapsed);
5314
- }
5315
- function scheduleComplete(entity, now) {
5316
- return hasSchedule$1(entity) && scheduleRemaining(entity, now) === 0;
5317
- }
5318
- function currentTaskIndex(entity, now) {
5319
- if (!entity.schedule || entity.schedule.tasks.length === 0)
5320
- return -1;
5321
- const elapsed = scheduleElapsed(entity, now);
5322
- let timeAccum = 0;
5323
- for (let i = 0; i < entity.schedule.tasks.length; i++) {
5324
- const taskDuration = entity.schedule.tasks[i].duration.toNumber();
5325
- if (elapsed < timeAccum + taskDuration) {
5326
- return i;
5327
- }
5328
- timeAccum += taskDuration;
5329
- }
5330
- return entity.schedule.tasks.length - 1;
5331
- }
5332
- function currentTask(entity, now) {
5333
- const index = currentTaskIndex(entity, now);
5334
- if (index < 0 || !entity.schedule)
5335
- return undefined;
5336
- return entity.schedule.tasks[index];
5337
- }
5338
- function currentTaskType(entity, now) {
5339
- const task = currentTask(entity, now);
5340
- if (!task)
5341
- return undefined;
5342
- return task.type.toNumber();
5343
- }
5344
- function getTaskStartTime(entity, index) {
5345
- if (!entity.schedule || index < 0 || index >= entity.schedule.tasks.length)
5346
- return 0;
5347
- let timeAccum = 0;
5348
- for (let i = 0; i < index; i++) {
5349
- timeAccum += entity.schedule.tasks[i].duration.toNumber();
5350
- }
5351
- return timeAccum;
5352
- }
5353
- function getTaskElapsed(entity, index, now) {
5354
- if (!entity.schedule || index < 0 || index >= entity.schedule.tasks.length)
5355
- return 0;
5356
- const elapsed = scheduleElapsed(entity, now);
5357
- const taskStart = getTaskStartTime(entity, index);
5358
- const taskDuration = entity.schedule.tasks[index].duration.toNumber();
5359
- if (elapsed <= taskStart)
5360
- return 0;
5361
- const elapsedInTask = elapsed - taskStart;
5362
- return Math.min(elapsedInTask, taskDuration);
5363
- }
5364
- function getTaskRemaining(entity, index, now) {
5365
- if (!entity.schedule || index < 0 || index >= entity.schedule.tasks.length)
5366
- return 0;
5367
- const taskDuration = entity.schedule.tasks[index].duration.toNumber();
5368
- const taskElapsed = getTaskElapsed(entity, index, now);
5369
- return Math.max(0, taskDuration - taskElapsed);
5370
- }
5371
- function isTaskComplete(entity, index, now) {
5372
- if (!entity.schedule || index < 0 || index >= entity.schedule.tasks.length)
5373
- return false;
5374
- const taskDuration = entity.schedule.tasks[index].duration.toNumber();
5375
- const taskElapsed = getTaskElapsed(entity, index, now);
5376
- return taskElapsed >= taskDuration;
5377
- }
5378
- function isTaskInProgress(entity, index, now) {
5379
- if (!entity.schedule || index < 0 || index >= entity.schedule.tasks.length)
5380
- return false;
5381
- const taskElapsed = getTaskElapsed(entity, index, now);
5382
- const taskDuration = entity.schedule.tasks[index].duration.toNumber();
5383
- return taskElapsed > 0 && taskElapsed < taskDuration;
5384
- }
5385
- function currentTaskProgress(entity, now) {
5386
- const task = currentTask(entity, now);
5387
- if (!task)
5388
- return 0;
5389
- const index = currentTaskIndex(entity, now);
5390
- const elapsed = getTaskElapsed(entity, index, now);
5391
- const duration = task.duration.toNumber();
5392
- if (duration === 0)
5393
- return 1;
5394
- return Math.min(1, elapsed / duration);
5395
- }
5396
- function scheduleProgress(entity, now) {
5397
- const duration = scheduleDuration(entity);
5398
- if (duration === 0)
5399
- return hasSchedule$1(entity) ? 1 : 0;
5400
- const elapsed = scheduleElapsed(entity, now);
5401
- return Math.min(1, elapsed / duration);
5402
- }
5403
- function isTaskType(entity, taskType, now) {
5404
- return currentTaskType(entity, now) === taskType;
5405
- }
5406
- function isInFlight(entity, now) {
5407
- return isTaskType(entity, exports.TaskType.TRAVEL, now);
5408
- }
5409
- function isRecharging(entity, now) {
5410
- return isTaskType(entity, exports.TaskType.RECHARGE, now);
5411
- }
5412
- function isLoading(entity, now) {
5413
- return isTaskType(entity, exports.TaskType.LOAD, now);
5414
- }
5415
- function isUnloading(entity, now) {
5416
- return isTaskType(entity, exports.TaskType.UNLOAD, now);
5417
- }
5418
- function isGathering(entity, now) {
5419
- return isTaskType(entity, exports.TaskType.GATHER, now);
5420
- }
5421
-
5422
- var schedule = /*#__PURE__*/Object.freeze({
5423
- __proto__: null,
5424
- hasSchedule: hasSchedule$1,
5425
- isIdle: isIdle,
5426
- getTasks: getTasks,
5427
- scheduleDuration: scheduleDuration,
5428
- scheduleElapsed: scheduleElapsed,
5429
- scheduleRemaining: scheduleRemaining,
5430
- scheduleComplete: scheduleComplete,
5431
- currentTaskIndex: currentTaskIndex,
5432
- currentTask: currentTask,
5433
- currentTaskType: currentTaskType,
5434
- getTaskStartTime: getTaskStartTime,
5435
- getTaskElapsed: getTaskElapsed,
5436
- getTaskRemaining: getTaskRemaining,
5437
- isTaskComplete: isTaskComplete,
5438
- isTaskInProgress: isTaskInProgress,
5439
- currentTaskProgress: currentTaskProgress,
5440
- scheduleProgress: scheduleProgress,
5441
- isTaskType: isTaskType,
5442
- isInFlight: isInFlight,
5443
- isRecharging: isRecharging,
5444
- isLoading: isLoading,
5445
- isUnloading: isUnloading,
5446
- isGathering: isGathering
5447
- });
5448
-
5449
- function getHullMass(entity) {
5450
- return antelope.UInt32.from(entity.hullmass ?? 0);
5451
- }
5452
- function createProjectedEntity(entity) {
5453
- const cargoMass = calcCargoMass(entity);
5454
- const shipMass = getHullMass(entity);
5455
- const loaders = entity.loaders;
5456
- const engines = entity.engines;
5457
- const generator = entity.generator;
5458
- const hauler = entity.hauler;
5459
- const capacity = entity.capacity;
5460
- const projected = {
5461
- location: Coordinates.from(entity.coordinates),
5462
- energy: antelope.UInt16.from(entity.energy ?? 0),
5463
- cargoMass,
5464
- shipMass,
5465
- capacity: capacity ? antelope.UInt64.from(capacity) : undefined,
5466
- engines,
5467
- generator,
5468
- hauler,
5469
- loaders,
5470
- get totalMass() {
5471
- let mass = antelope.UInt64.from(this.shipMass).adding(this.cargoMass);
5472
- if (this.loaders) {
5473
- mass = mass.adding(this.loaders.mass.multiplying(this.loaders.quantity));
5474
- }
5475
- return mass;
5476
- },
5477
- hasMovement() {
5478
- return capsHasMovement(this.capabilities());
5479
- },
5480
- hasStorage() {
5481
- return capsHasStorage(this.capabilities());
5482
- },
5483
- hasLoaders() {
5484
- return capsHasLoaders(this.capabilities());
5485
- },
5486
- capabilities() {
5487
- return {
5488
- hullmass: this.shipMass,
5489
- capacity: this.capacity ? antelope.UInt32.from(this.capacity) : undefined,
5490
- engines: this.engines,
5491
- generator: this.generator,
5492
- loaders: this.loaders,
5493
- };
5494
- },
5495
- state() {
5496
- return {
5497
- owner: entity.owner ?? antelope.Name.from(''),
5498
- location: Types.coordinates.from(this.location),
5499
- energy: this.energy,
5500
- cargomass: antelope.UInt32.from(this.cargoMass),
5501
- cargo: entity.cargo,
5502
- };
5503
- },
5504
- };
5505
- return projected;
5506
- }
5507
- function applyRechargeTask(projected, _task, options) {
5508
- if (!projected.generator)
5509
- return;
5510
- if (options.complete) {
5511
- projected.energy = antelope.UInt16.from(projected.generator.capacity);
5512
- }
5513
- else if (options.progress !== undefined) {
5514
- const capacity = Number(projected.generator.capacity);
5515
- const currentEnergy = Number(projected.energy);
5516
- const rechargeAmount = (capacity - currentEnergy) * options.progress;
5517
- projected.energy = antelope.UInt16.from(Math.min(capacity, currentEnergy + rechargeAmount));
5518
- }
5519
- }
5520
- function applyFlightTask(projected, task, options) {
5521
- if (!task.coordinates || !projected.engines)
5522
- return;
5523
- const origin = projected.location;
5524
- const destination = Coordinates.from(task.coordinates);
5525
- const distance = distanceBetweenCoordinates(origin, task.coordinates);
5526
- const energyUsage = distance.dividing(PRECISION$1).multiplying(projected.engines.drain);
5527
- if (options.complete) {
5528
- projected.energy = projected.energy.gt(energyUsage)
5529
- ? antelope.UInt16.from(projected.energy.subtracting(energyUsage))
5530
- : antelope.UInt16.from(0);
5531
- projected.location = destination;
5532
- }
5533
- else if (options.progress !== undefined) {
5534
- const interpolated = lerp(origin, destination, options.progress);
5535
- projected.location = Coordinates.from({
5536
- x: Math.round(interpolated.x),
5537
- y: Math.round(interpolated.y),
5538
- });
5539
- const partialEnergy = antelope.UInt64.from(Math.floor(Number(energyUsage) * options.progress));
5540
- projected.energy = projected.energy.gt(partialEnergy)
5541
- ? antelope.UInt16.from(projected.energy.subtracting(partialEnergy))
5542
- : antelope.UInt16.from(0);
5543
- }
5544
- }
5545
- function applyLoadTask(projected, task) {
5546
- for (const item of task.cargo) {
5547
- projected.cargoMass = projected.cargoMass.adding(calcCargoItemMass(item));
5548
- }
5549
- }
5550
- function applyUnloadTask(projected, task) {
5551
- for (const item of task.cargo) {
5552
- const cargoMass = calcCargoItemMass(item);
5553
- projected.cargoMass = projected.cargoMass.gt(cargoMass)
5554
- ? projected.cargoMass.subtracting(cargoMass)
5555
- : antelope.UInt64.from(0);
5556
- }
5557
- }
5558
- function applyEnergyCost(projected, task) {
5559
- if (!task.energy_cost)
5560
- return;
5561
- const energyCost = antelope.UInt16.from(task.energy_cost);
5562
- projected.energy = projected.energy.gt(energyCost)
5563
- ? antelope.UInt16.from(projected.energy.subtracting(energyCost))
5564
- : antelope.UInt16.from(0);
5565
- }
5566
- function applyGatherTask(projected, task, options) {
5567
- if (!options.complete)
5568
- return;
5569
- applyEnergyCost(projected, task);
5570
- for (const item of task.cargo) {
5571
- projected.cargoMass = projected.cargoMass.adding(calcCargoItemMass(item));
5572
- }
5573
- }
5574
- function applyCraftTask(projected, task) {
5575
- applyEnergyCost(projected, task);
5576
- if (task.cargo.length > 0) {
5577
- for (let i = 0; i < task.cargo.length - 1; i++) {
5578
- const inputMass = calcCargoItemMass(task.cargo[i]);
5579
- projected.cargoMass = projected.cargoMass.gt(inputMass)
5580
- ? projected.cargoMass.subtracting(inputMass)
5581
- : antelope.UInt64.from(0);
5582
- }
5583
- const output = task.cargo[task.cargo.length - 1];
5584
- projected.cargoMass = projected.cargoMass.adding(calcCargoItemMass(output));
5585
- }
5586
- }
5587
- function applyDeployTask(projected, task) {
5588
- applyEnergyCost(projected, task);
5589
- if (task.cargo.length > 0) {
5590
- const mass = calcCargoItemMass(task.cargo[0]);
5591
- projected.cargoMass = projected.cargoMass.gt(mass)
5592
- ? projected.cargoMass.subtracting(mass)
5593
- : antelope.UInt64.from(0);
5594
- }
5595
- }
5596
- function projectEntity(entity) {
5597
- const projected = createProjectedEntity(entity);
5598
- if (!entity.schedule) {
5599
- return projected;
5600
- }
5601
- for (const task of entity.schedule.tasks) {
5602
- switch (task.type.toNumber()) {
5603
- case exports.TaskType.RECHARGE:
5604
- applyRechargeTask(projected, task, { complete: true });
5605
- break;
5606
- case exports.TaskType.TRAVEL:
5607
- applyFlightTask(projected, task, { complete: true });
5608
- break;
5609
- case exports.TaskType.LOAD:
5610
- applyLoadTask(projected, task);
5611
- break;
5612
- case exports.TaskType.UNLOAD:
5613
- applyUnloadTask(projected, task);
5614
- break;
5615
- case exports.TaskType.GATHER:
5616
- applyGatherTask(projected, task, { complete: true });
5617
- break;
5618
- case exports.TaskType.CRAFT:
5619
- applyCraftTask(projected, task);
5620
- break;
5621
- case exports.TaskType.DEPLOY:
5622
- case exports.TaskType.DEPLOY_SHIP:
5623
- applyDeployTask(projected, task);
5624
- break;
5625
- }
5626
- }
5627
- return projected;
5628
- }
5629
- function projectEntityAt(entity, now) {
5630
- const projected = createProjectedEntity(entity);
5631
- if (!entity.schedule || entity.schedule.tasks.length === 0) {
5632
- return projected;
5633
- }
5634
- for (let i = 0; i < entity.schedule.tasks.length; i++) {
5635
- const task = entity.schedule.tasks[i];
5636
- const taskComplete = isTaskComplete(entity, i, now);
5637
- const taskInProgress = isTaskInProgress(entity, i, now);
5638
- if (!taskComplete && !taskInProgress) {
5639
- break;
5640
- }
5641
- const progress = taskInProgress
5642
- ? getTaskElapsed(entity, i, now) / task.duration.toNumber()
5643
- : undefined;
5644
- switch (task.type.toNumber()) {
5645
- case exports.TaskType.RECHARGE:
5646
- applyRechargeTask(projected, task, { complete: taskComplete, progress });
5647
- break;
5648
- case exports.TaskType.TRAVEL:
5649
- applyFlightTask(projected, task, { complete: taskComplete, progress });
5650
- break;
5651
- case exports.TaskType.LOAD:
5652
- if (taskComplete) {
5653
- applyLoadTask(projected, task);
5654
- }
5655
- break;
5656
- case exports.TaskType.UNLOAD:
5657
- if (taskComplete) {
5658
- applyUnloadTask(projected, task);
5659
- }
5660
- break;
5661
- case exports.TaskType.GATHER:
5662
- if (taskComplete) {
5663
- applyGatherTask(projected, task, { complete: true });
5664
- }
5665
- break;
5666
- case exports.TaskType.CRAFT:
5667
- if (taskComplete) {
5668
- applyCraftTask(projected, task);
5669
- }
5670
- break;
5671
- case exports.TaskType.DEPLOY:
5672
- case exports.TaskType.DEPLOY_SHIP:
5673
- if (taskComplete) {
5674
- applyDeployTask(projected, task);
5675
- }
5676
- break;
5677
- }
5678
- }
5679
- return projected;
5680
- }
5681
-
5682
- class Location {
5683
- constructor(coordinates) {
5684
- this.coordinates = Coordinates.from(coordinates);
5685
- }
5686
- static from(coordinates) {
5687
- return new Location(Coordinates.from(coordinates));
5688
- }
5689
- hasSystemAt(gameSeed) {
5690
- const seed = antelope.Checksum256.from(gameSeed);
5691
- if (this._hasSystem === undefined || !this._gameSeed?.equals(seed)) {
5692
- this._gameSeed = seed;
5693
- this._hasSystem = hasSystem(seed, this.coordinates);
5694
- }
5695
- return this._hasSystem;
5696
- }
5697
- getLocationTypeAt(gameSeed) {
5698
- return getLocationType(gameSeed, this.coordinates);
5699
- }
5700
- isGatherableAt(gameSeed) {
5701
- return isGatherableLocation(this.getLocationTypeAt(gameSeed));
5702
- }
5703
- findNearby(gameSeed, maxDistance = 20) {
5704
- return findNearbyPlanets(antelope.Checksum256.from(gameSeed), this.coordinates, maxDistance);
5705
- }
5706
- equals(other) {
5707
- const otherCoords = other instanceof Location ? other.coordinates : Coordinates.from(other);
5708
- return this.coordinates.equals(otherCoords);
5709
- }
5710
- get epoch() {
5711
- return this._epoch;
5712
- }
5713
- clearCache() {
5714
- this._epoch = undefined;
5715
- }
5716
- }
5717
- function toLocation(coords) {
5718
- if (coords instanceof Location) {
5719
- return coords;
5720
- }
5721
- return Location.from(coords);
5722
- }
5723
-
5724
- class ScheduleAccessor {
5725
- constructor(entity) {
5726
- this.entity = entity;
5727
- }
5728
- get hasSchedule() {
5729
- return hasSchedule$1(this.entity);
5730
- }
5731
- get isIdle() {
5732
- return isIdle(this.entity);
5733
- }
5734
- get tasks() {
5735
- return getTasks(this.entity);
5736
- }
5737
- duration() {
5738
- return scheduleDuration(this.entity);
5739
- }
5740
- elapsed(now) {
5741
- return scheduleElapsed(this.entity, now);
5742
- }
5743
- remaining(now) {
5744
- return scheduleRemaining(this.entity, now);
5745
- }
5746
- complete(now) {
5747
- return scheduleComplete(this.entity, now);
5748
- }
5749
- currentTaskIndex(now) {
5750
- return currentTaskIndex(this.entity, now);
5751
- }
5752
- currentTask(now) {
5753
- return currentTask(this.entity, now);
5754
- }
5755
- currentTaskType(now) {
5756
- return currentTaskType(this.entity, now);
5757
- }
5758
- taskStartTime(index) {
5759
- return getTaskStartTime(this.entity, index);
5760
- }
5761
- taskElapsed(index, now) {
5762
- return getTaskElapsed(this.entity, index, now);
5763
- }
5764
- taskRemaining(index, now) {
5765
- return getTaskRemaining(this.entity, index, now);
5766
- }
5767
- taskComplete(index, now) {
5768
- return isTaskComplete(this.entity, index, now);
5769
- }
5770
- taskInProgress(index, now) {
5771
- return isTaskInProgress(this.entity, index, now);
5772
- }
5773
- currentTaskProgress(now) {
5774
- return currentTaskProgress(this.entity, now);
5775
- }
5776
- progress(now) {
5777
- return scheduleProgress(this.entity, now);
5778
- }
5779
- }
5780
- function createScheduleAccessor(entity) {
5781
- return new ScheduleAccessor(entity);
5782
- }
5783
-
5784
- class EntityInventory extends Types.cargo_item {
5785
- get item() {
5786
- if (!this._item) {
5787
- this._item = getItem(this.item_id);
5788
- }
5789
- return this._item;
5790
- }
5791
- get good() {
5792
- return this.item;
5793
- }
5794
- get name() {
5795
- return this.item.name;
5796
- }
5797
- get unitMass() {
5798
- return this.item.mass;
5799
- }
5800
- get totalMass() {
5801
- return antelope.UInt64.from(this.unitMass).multiplying(this.quantity);
5802
- }
5803
- get hasCargo() {
5804
- return antelope.UInt32.from(this.quantity).gt(antelope.UInt32.from(0));
5805
- }
5806
- get isEmpty() {
5807
- return antelope.UInt32.from(this.quantity).equals(antelope.UInt32.from(0));
5808
- }
5809
- }
5810
-
5811
- class InventoryAccessor {
5812
- constructor(entity) {
5813
- this.entity = entity;
5814
- }
5815
- get items() {
5816
- if (!this._items) {
5817
- this._items = this.entity.cargo.map((item) => new EntityInventory(item));
5818
- }
5819
- return this._items;
5820
- }
5821
- get totalMass() {
5822
- return this.items.reduce((sum, c) => sum.adding(c.totalMass), antelope.UInt64.from(0));
5823
- }
5824
- forItem(goodId) {
5825
- return this.items.find((c) => c.item_id.equals(goodId));
5826
- }
5827
- get sellable() {
5828
- return this.items.filter((c) => c.hasCargo);
5829
- }
5830
- get hasSellable() {
5831
- return this.items.some((c) => c.hasCargo);
5832
- }
5833
- get sellableCount() {
5834
- return this.items.filter((c) => c.hasCargo).length;
5835
- }
5836
- }
5837
- function createInventoryAccessor(entity) {
5838
- return new InventoryAccessor(entity);
5839
- }
5840
-
5841
- function maxTravelDistance(entity) {
5842
- return antelope.UInt32.from(entity.generator.capacity)
5843
- .dividing(entity.engines.drain)
5844
- .multiplying(PRECISION$1);
5845
- }
5846
- function calcEnergyUsage(entity, distance) {
5847
- return distance.dividing(PRECISION$1).multiplying(entity.engines.drain);
5848
- }
5849
- function hasEnergyForDistance(entity, distance) {
5850
- const usage = calcEnergyUsage(entity, distance);
5851
- return antelope.UInt64.from(entity.energy).gte(usage);
5852
- }
5853
- function energyPercent(entity) {
5854
- return (Number(entity.energy) / Number(entity.generator.capacity)) * 100;
5855
- }
5856
- function needsRecharge(entity) {
5857
- return antelope.UInt64.from(entity.energy).lt(entity.generator.capacity);
5858
- }
5859
-
5860
- class Ship extends Types.entity_info {
5861
- get name() {
5862
- return this.entity_name;
5863
- }
5864
- get inv() {
5865
- return (this._inv ?? (this._inv = new InventoryAccessor(this)));
5866
- }
5867
- get inventory() {
5868
- return this.inv.items;
5869
- }
5870
- get sched() {
5871
- return (this._sched ?? (this._sched = new ScheduleAccessor(this)));
5872
- }
5873
- get maxDistance() {
5874
- if (!this.generator || !this.engines)
5875
- return antelope.UInt32.from(0);
5876
- return maxTravelDistance(this);
5877
- }
5878
- get isIdle() {
5879
- return this.is_idle;
5880
- }
5881
- getFlightOrigin(flightTaskIndex) {
5882
- return Coordinates.from(getFlightOrigin(this, flightTaskIndex));
5883
- }
5884
- destinationLocation() {
5885
- const dest = getDestinationLocation(this);
5886
- return dest ? Coordinates.from(dest) : undefined;
5887
- }
5888
- positionAt(now) {
5889
- const taskIndex = this.sched.currentTaskIndex(now);
5890
- const progress = this.sched.currentTaskProgress(now);
5891
- return Coordinates.from(getPositionAt(this, taskIndex, progress));
5892
- }
5893
- isInFlight(now) {
5894
- return isInFlight(this, now);
5895
- }
5896
- isRecharging(now) {
5897
- return isRecharging(this, now);
5898
- }
5899
- isLoading(now) {
5900
- return isLoading(this, now);
5901
- }
5902
- isUnloading(now) {
5903
- return isUnloading(this, now);
5904
- }
5905
- isGathering(now) {
5906
- return isGathering(this, now);
5907
- }
5908
- get hasEngines() {
5909
- return this.engines !== undefined;
5910
- }
5911
- get hasGenerator() {
5912
- return this.generator !== undefined;
5913
- }
5914
- get hasGatherer() {
5915
- return this.gatherer !== undefined;
5916
- }
5917
- get hasWarp() {
5918
- return this.warp !== undefined;
5919
- }
5920
- project() {
5921
- return projectEntity(this);
5922
- }
5923
- projectAt(now) {
5924
- return projectEntityAt(this, now);
5925
- }
5926
- get location() {
5927
- return Location.from(this.coordinates);
5928
- }
5929
- get totalCargoMass() {
5930
- return this.inv.totalMass;
5931
- }
5932
- get totalMass() {
5933
- let mass = antelope.UInt64.from(this.hullmass ?? 0).adding(this.totalCargoMass);
5934
- if (this.loaders) {
5935
- mass = mass.adding(antelope.UInt64.from(this.loaders.mass).multiplying(this.loaders.quantity));
5936
- }
5937
- return mass;
5938
- }
5939
- get maxCapacity() {
5940
- return antelope.UInt64.from(this.capacity);
5941
- }
5942
- hasSpace(goodMass, quantity) {
5943
- return this.totalMass.adding(goodMass.multiplying(quantity)).lte(this.maxCapacity);
5944
- }
5945
- get availableCapacity() {
5946
- return this.totalMass.gte(this.maxCapacity)
5947
- ? antelope.UInt64.from(0)
5948
- : this.maxCapacity.subtracting(this.totalMass);
5949
- }
5950
- getCargoForItem(goodId) {
5951
- return this.inv.forItem(goodId);
5952
- }
5953
- get sellableCargo() {
5954
- return this.inv.sellable;
5955
- }
5956
- get hasSellableCargo() {
5957
- return this.inv.hasSellable;
5958
- }
5959
- get sellableGoodsCount() {
5960
- return this.inv.sellableCount;
5961
- }
5962
- get isFull() {
5963
- return this.totalMass.gte(this.maxCapacity);
5964
- }
5965
- get energyPercent() {
5966
- if (!this.generator || this.energy === undefined)
5967
- return 0;
5968
- return energyPercent(this);
5969
- }
5970
- get needsRecharge() {
5971
- if (!this.generator || this.energy === undefined)
5972
- return false;
5973
- return needsRecharge(this);
5974
- }
5975
- hasEnergyFor(distance) {
5976
- if (!this.engines || !this.generator || this.energy === undefined)
5977
- return false;
5978
- return hasEnergyForDistance(this, distance);
5979
- }
5980
- }
5981
-
5982
- class Warehouse extends Types.entity_info {
5983
- get name() {
5984
- return this.entity_name;
5985
- }
5986
- get inv() {
5987
- return (this._inv ?? (this._inv = new InventoryAccessor(this)));
5988
- }
5989
- get inventory() {
5990
- return this.inv.items;
5991
- }
5992
- get sched() {
5993
- return (this._sched ?? (this._sched = new ScheduleAccessor(this)));
5994
- }
5995
- get isIdle() {
5996
- return this.is_idle;
5997
- }
5998
- isLoading(now) {
5999
- return isLoading(this, now);
6000
- }
6001
- isUnloading(now) {
6002
- return isUnloading(this, now);
6003
- }
6004
- get location() {
6005
- return Location.from(this.coordinates);
6006
- }
6007
- get totalCargoMass() {
6008
- return this.inv.totalMass;
6009
- }
6010
- get maxCapacity() {
6011
- return antelope.UInt64.from(this.capacity);
6012
- }
6013
- get availableCapacity() {
6014
- const cargo = this.totalCargoMass;
6015
- return cargo.gte(this.maxCapacity) ? antelope.UInt64.from(0) : this.maxCapacity.subtracting(cargo);
6016
- }
6017
- hasSpace(goodMass, quantity) {
6018
- return this.totalCargoMass.adding(goodMass.multiplying(quantity)).lte(this.maxCapacity);
6019
- }
6020
- get isFull() {
6021
- return this.totalCargoMass.gte(this.maxCapacity);
6022
- }
6023
- getCargoForItem(goodId) {
6024
- return this.inv.forItem(goodId);
6025
- }
6026
- get orbitalAltitude() {
6027
- return this.coordinates.z?.toNumber() || 0;
6028
- }
6029
- get totalMass() {
6030
- const hull = this.hullmass ? antelope.UInt64.from(this.hullmass) : antelope.UInt64.from(0);
6031
- return hull.adding(this.totalCargoMass);
6032
- }
6033
- }
6034
-
6035
- class Container extends Types.entity_info {
6036
- get name() {
6037
- return this.entity_name;
6038
- }
6039
- get sched() {
6040
- return (this._sched ?? (this._sched = new ScheduleAccessor(this)));
6041
- }
6042
- get isIdle() {
6043
- return this.is_idle;
6044
- }
6045
- isLoading(now) {
6046
- return isLoading(this, now);
6047
- }
6048
- isUnloading(now) {
6049
- return isUnloading(this, now);
6050
- }
6051
- get location() {
6052
- return Location.from(this.coordinates);
6053
- }
6054
- get totalMass() {
6055
- return antelope.UInt64.from(this.hullmass ?? 0).adding(this.cargomass);
6056
- }
6057
- get maxCapacity() {
6058
- return antelope.UInt64.from(this.capacity);
6059
- }
6060
- get availableCapacity() {
6061
- const cargo = antelope.UInt64.from(this.cargomass);
6062
- return cargo.gte(this.maxCapacity) ? antelope.UInt64.from(0) : this.maxCapacity.subtracting(cargo);
6063
- }
6064
- hasSpace(additionalMass) {
6065
- return antelope.UInt64.from(this.cargomass).adding(additionalMass).lte(this.maxCapacity);
6066
- }
6067
- get isFull() {
6068
- return antelope.UInt64.from(this.cargomass).gte(this.maxCapacity);
6069
- }
6070
- get orbitalAltitude() {
6071
- return this.coordinates.z?.toNumber() || 0;
6072
- }
6073
- }
6074
- function computeContainerCapabilities(stats) {
6075
- const density = stats['density'] ?? 500;
6076
- const strength = stats['strength'] ?? 500;
6077
- const ductility = stats['ductility'] ?? 500;
6078
- const purity = stats['purity'] ?? 500;
6079
- const hullmass = 25000 + 75 * density;
6080
- const statSum = strength + ductility + purity;
6081
- const exponent = statSum / 2997;
6082
- const capacity = Math.floor(1000000 * Math.pow(10, exponent));
6083
- return { hullmass, capacity };
6084
- }
6085
- function computeContainerT2Capabilities(stats) {
6086
- const strength = stats['strength'] ?? 0;
6087
- const density = stats['density'] ?? 0;
6088
- const ductility = stats['ductility'] ?? 0;
6089
- const purity = stats['purity'] ?? 0;
6090
- const hullmass = 20000 + 50 * density;
6091
- const statSum = strength + ductility + purity;
6092
- const exponent = statSum / 2500;
6093
- const capacity = Math.floor(1500000 * Math.pow(10, exponent));
6094
- return { hullmass, capacity };
6095
- }
6096
-
6097
- class EntitiesManager extends BaseManager {
6098
- async getEntity(type, id) {
6099
- const result = await this.server.readonly('getentity', {
6100
- entity_type: antelope.Name.from(type),
6101
- entity_id: id,
6102
- });
6103
- const entityInfo = result;
6104
- return this.wrapEntity(entityInfo);
6105
- }
6106
- async getEntities(owner, type) {
6107
- const ownerName = this.resolveOwner(owner);
6108
- const result = await this.server.readonly('getentities', {
6109
- owner: ownerName,
6110
- entity_type: type ? antelope.Name.from(type) : null,
6111
- });
6112
- const entities = result;
6113
- return entities.map((entity) => this.wrapEntity(entity));
6114
- }
6115
- async getSummaries(owner, type) {
6116
- const ownerName = this.resolveOwner(owner);
6117
- const result = await this.server.readonly('getsummaries', {
6118
- owner: ownerName,
6119
- entity_type: type ? antelope.Name.from(type) : null,
6120
- });
6121
- return result;
6122
- }
6123
- async getShip(id) {
6124
- return (await this.getEntity('ship', id));
6125
- }
6126
- async getWarehouse(id) {
6127
- return (await this.getEntity('warehouse', id));
6128
- }
6129
- async getContainer(id) {
6130
- return (await this.getEntity('container', id));
6131
- }
6132
- async getShips(owner) {
6133
- return (await this.getEntities(owner, 'ship'));
6134
- }
6135
- async getWarehouses(owner) {
6136
- return (await this.getEntities(owner, 'warehouse'));
6137
- }
6138
- async getContainers(owner) {
6139
- return (await this.getEntities(owner, 'container'));
6140
- }
6141
- async getShipSummaries(owner) {
6142
- return this.getSummaries(owner, 'ship');
6143
- }
6144
- async getWarehouseSummaries(owner) {
6145
- return this.getSummaries(owner, 'warehouse');
6146
- }
6147
- async getContainerSummaries(owner) {
6148
- return this.getSummaries(owner, 'container');
6149
- }
6150
- wrapEntity(entity) {
6151
- if (entity.type.equals('ship')) {
6152
- return new Ship(entity);
6153
- }
6154
- else if (entity.type.equals('warehouse')) {
6155
- return new Warehouse(entity);
6156
- }
6157
- else {
6158
- return new Container(entity);
6159
- }
6160
- }
6161
- resolveOwner(owner) {
6162
- if (typeof owner === 'object' && owner !== null && 'owner' in owner) {
6163
- return owner.owner;
6164
- }
6165
- return antelope.Name.from(owner);
6166
- }
6167
- }
6168
-
6169
- class Player extends Types.player_row {
6170
- static fromState(state) {
6171
- const playerRow = Types.player_row.from({
6172
- owner: antelope.Name.from(state.owner),
6173
- });
6174
- return new Player(playerRow);
6175
- }
6176
- }
6177
-
6178
- class PlayersManager extends BaseManager {
6179
- async getPlayer(account) {
6180
- const playerRow = await this.server.table('player').get(antelope.Name.from(account));
6181
- if (!playerRow) {
6182
- return undefined;
6183
- }
6184
- return new Player(playerRow);
6185
- }
6186
- }
6187
-
6188
- class LocationsManager extends BaseManager {
6189
- async hasSystem(location) {
6190
- const game = await this.getGame();
6191
- return hasSystem(game.config.seed, location);
6192
- }
6193
- async findNearbyPlanets(origin, maxDistance = 20) {
6194
- const game = await this.getGame();
6195
- return findNearbyPlanets(game.config.seed, origin, maxDistance);
6196
- }
6197
- async getLocationEntity(id) {
6198
- const row = await this.server.table('location').get(antelope.UInt64.from(id));
6199
- return row ?? undefined;
6200
- }
6201
- async getLocationEntityAt(coords) {
6202
- const id = coordsToLocationId(coords);
6203
- return this.getLocationEntity(id);
6204
- }
6205
- async getAllLocationEntities() {
6206
- return this.server.table('location').all();
6207
- }
6208
- }
6209
-
6210
- class EpochsManager extends BaseManager {
6211
- async getCurrentHeight() {
6212
- const game = await this.getGame();
6213
- return getCurrentEpoch(game);
6214
- }
6215
- async getCurrent() {
6216
- const game = await this.getGame();
6217
- const epoch = await this.getCurrentHeight();
6218
- return getEpochInfo(game, epoch);
6219
- }
6220
- async getByHeight(height) {
6221
- const game = await this.getGame();
6222
- return getEpochInfo(game, antelope.UInt64.from(height));
6223
- }
6224
- async getTimeRemaining() {
6225
- const epochInfo = await this.getCurrent();
6226
- const now = Date.now();
6227
- const endTime = epochInfo.end.getTime();
6228
- return Math.max(0, endTime - now);
6229
- }
6230
- async getProgress() {
6231
- const epochInfo = await this.getCurrent();
6232
- const now = Date.now();
6233
- const startTime = epochInfo.start.getTime();
6234
- const endTime = epochInfo.end.getTime();
6235
- const duration = endTime - startTime;
6236
- const elapsed = now - startTime;
6237
- if (elapsed <= 0)
6238
- return 0;
6239
- if (elapsed >= duration)
6240
- return 1;
6241
- return elapsed / duration;
6242
- }
6243
- async fitsInCurrentEpoch(durationMs) {
6244
- const remaining = await this.getTimeRemaining();
6245
- return durationMs <= remaining;
6246
- }
6247
- }
6248
-
6249
- class ActionsManager extends BaseManager {
6250
- travel(shipId, destination, recharge = true) {
6251
- const x = antelope.Int64.from(destination.x);
6252
- const y = antelope.Int64.from(destination.y);
6253
- return this.server.action('travel', {
6254
- entity_type: EntityType.SHIP,
6255
- id: antelope.UInt64.from(shipId),
6256
- x,
6257
- y,
6258
- recharge,
6259
- });
6260
- }
6261
- grouptravel(entities, destination, recharge = true) {
6262
- const entityRefs = entities.map((e) => Types.entity_ref.from({
6263
- entity_type: e.entityType,
6264
- entity_id: antelope.UInt64.from(e.entityId),
6265
- }));
6266
- const x = antelope.Int64.from(destination.x);
6267
- const y = antelope.Int64.from(destination.y);
6268
- return this.server.action('grouptravel', {
6269
- entities: entityRefs,
6270
- x,
6271
- y,
6272
- recharge,
6273
- });
6274
- }
6275
- resolve(entityId, entityType = EntityType.SHIP) {
6276
- return this.server.action('resolve', {
6277
- entity_type: entityType,
6278
- id: antelope.UInt64.from(entityId),
6279
- });
6280
- }
6281
- cancel(entityId, count, entityType = EntityType.SHIP) {
6282
- return this.server.action('cancel', {
6283
- entity_type: entityType,
6284
- id: antelope.UInt64.from(entityId),
6285
- count: antelope.UInt64.from(count),
6286
- });
6287
- }
6288
- recharge(shipId) {
6289
- return this.server.action('recharge', {
6290
- entity_type: EntityType.SHIP,
6291
- id: antelope.UInt64.from(shipId),
6292
- });
6293
- }
6294
- transfer(sourceType, sourceId, destType, destId, goodId, quantity) {
6295
- return this.server.action('transfer', {
6296
- source_type: sourceType,
6297
- source_id: antelope.UInt64.from(sourceId),
6298
- dest_type: destType,
6299
- dest_id: antelope.UInt64.from(destId),
6300
- item_id: antelope.UInt16.from(goodId),
6301
- quantity: antelope.UInt32.from(quantity),
6302
- });
6303
- }
6304
- foundCompany(account, name) {
6305
- return this.platform.action('foundcompany', {
6306
- account: antelope.Name.from(account),
6307
- name,
6308
- });
6309
- }
6310
- join(account) {
6311
- return this.server.action('join', {
6312
- account: antelope.Name.from(account),
6313
- });
6314
- }
6315
- gather(shipId, stratum, quantity) {
6316
- return this.server.action('gather', {
6317
- entity_type: EntityType.SHIP,
6318
- id: antelope.UInt64.from(shipId),
6319
- stratum: antelope.UInt16.from(stratum),
6320
- quantity: antelope.UInt32.from(quantity),
6321
- });
6322
- }
6323
- warp(shipId, destination) {
6324
- const x = antelope.Int64.from(destination.x);
6325
- const y = antelope.Int64.from(destination.y);
6326
- return this.server.action('warp', {
6327
- entity_type: EntityType.SHIP,
6328
- id: antelope.UInt64.from(shipId),
6329
- x,
6330
- y,
6331
- });
6332
- }
6333
- craft(entityType, entityId, recipeId, quantity, inputs) {
6334
- const cargoInputs = inputs.map((i) => Types.cargo_item.from(i));
6335
- return this.server.action('craft', {
6336
- entity_type: entityType,
6337
- id: antelope.UInt64.from(entityId),
6338
- recipe_id: antelope.UInt16.from(recipeId),
6339
- quantity: antelope.UInt32.from(quantity),
6340
- inputs: cargoInputs,
6341
- });
6342
- }
6343
- blend(entityType, entityId, inputs) {
6344
- const cargoInputs = inputs.map((i) => Types.cargo_item.from(i));
6345
- return this.server.action('blend', {
6346
- entity_type: entityType,
6347
- id: antelope.UInt64.from(entityId),
6348
- inputs: cargoInputs,
6349
- });
6350
- }
6351
- deploy(entityType, entityId, packedItemId, seed, entityName) {
6352
- return this.server.action('deploy', {
6353
- entity_type: entityType,
6354
- id: antelope.UInt64.from(entityId),
6355
- packed_item_id: antelope.UInt16.from(packedItemId),
6356
- seed: antelope.UInt64.from(seed),
6357
- entity_name: entityName,
6358
- });
6359
- }
6360
- addmodule(entityType, entityId, moduleIndex, moduleCargoId, targetCargoId = antelope.UInt64.from(0)) {
6361
- return this.server.action('addmodule', {
6362
- entity_type: entityType,
6363
- entity_id: antelope.UInt64.from(entityId),
6364
- module_index: moduleIndex,
6365
- module_cargo_id: antelope.UInt64.from(moduleCargoId),
6366
- target_cargo_id: antelope.UInt64.from(targetCargoId),
6367
- });
6368
- }
6369
- rmmodule(entityType, entityId, moduleIndex, targetCargoId = antelope.UInt64.from(0)) {
6370
- return this.server.action('rmmodule', {
6371
- entity_type: entityType,
6372
- entity_id: antelope.UInt64.from(entityId),
6373
- module_index: moduleIndex,
6374
- target_cargo_id: antelope.UInt64.from(targetCargoId),
6375
- });
6376
- }
6377
- joinGame(account, companyName) {
6378
- return [this.foundCompany(account, companyName), this.join(account)];
6379
- }
6380
- }
6381
-
6382
- class GameContext {
6383
- constructor(client, server, platform) {
6384
- this.client = client;
6385
- this.server = server;
6386
- this.platform = platform;
6387
- }
6388
- get entities() {
6389
- if (!this._entities) {
6390
- this._entities = new EntitiesManager(this);
6391
- }
6392
- return this._entities;
6393
- }
6394
- get players() {
6395
- if (!this._players) {
6396
- this._players = new PlayersManager(this);
6397
- }
6398
- return this._players;
6399
- }
6400
- get locations() {
6401
- if (!this._locations) {
6402
- this._locations = new LocationsManager(this);
6403
- }
6404
- return this._locations;
6405
- }
6406
- get epochs() {
6407
- if (!this._epochs) {
6408
- this._epochs = new EpochsManager(this);
6409
- }
6410
- return this._epochs;
6411
- }
6412
- get actions() {
6413
- if (!this._actions) {
6414
- this._actions = new ActionsManager(this);
6415
- }
6416
- return this._actions;
6417
- }
6418
- async getGame(reload = false) {
6419
- if (!reload && this._gameCache) {
6420
- return this._gameCache;
6421
- }
6422
- const game = await this.platform.table('games').get();
6423
- if (!game) {
6424
- throw new Error('Game not initialized');
6425
- }
6426
- this._gameCache = game;
6427
- return game;
6428
- }
6429
- async getState(reload = false) {
6430
- if (!reload && this._stateCache) {
6431
- return this._stateCache;
6432
- }
6433
- const state = await this.server.table('state').get();
6434
- if (!state) {
6435
- throw new Error('Game state not initialized');
6436
- }
6437
- const game = this._gameCache;
6438
- this._stateCache = GameState.from(state, game);
6439
- return this._stateCache;
6440
- }
6441
- get cachedGame() {
6442
- return this._gameCache;
6443
- }
6444
- get cachedState() {
6445
- return this._stateCache;
6446
- }
6447
- }
6448
-
6449
- class Shipload {
6450
- constructor(chain, constructorOptions) {
6451
- const { client, platformContract, serverContract } = constructorOptions || {};
6452
- const apiClient = client || new antelope.APIClient({ url: chain.url });
6453
- const platform$1 = platformContract
6454
- ? platformContract
6455
- : new Contract$1({ client: apiClient });
6456
- const server$1 = serverContract
6457
- ? serverContract
6458
- : new Contract({ client: apiClient });
6459
- this._context = new GameContext(apiClient, server$1, platform$1);
6460
- }
6461
- static async load(chain, shiploadOptions) {
6462
- let platform$1 = new Contract$1({
6463
- client: new antelope.APIClient({ url: chain.url }),
6464
- });
6465
- if (shiploadOptions?.platformContractName) {
6466
- const client = shiploadOptions.client || new antelope.APIClient({ url: chain.url });
6467
- const contractKit = new ContractKit__default["default"]({ client });
6468
- platform$1 = await contractKit.load(shiploadOptions.platformContractName);
6469
- }
6470
- let server$1 = new Contract({
6471
- client: new antelope.APIClient({ url: chain.url }),
6472
- });
6473
- if (shiploadOptions?.serverContractName) {
6474
- const client = shiploadOptions.client || new antelope.APIClient({ url: chain.url });
6475
- const contractKit = new ContractKit__default["default"]({ client });
6476
- server$1 = await contractKit.load(shiploadOptions.serverContractName);
6477
- }
6478
- return new Shipload(chain, {
6479
- ...shiploadOptions,
6480
- platformContract: platform$1,
6481
- serverContract: server$1,
6482
- });
6483
- }
6484
- get client() {
6485
- return this._context.client;
6486
- }
6487
- get server() {
6488
- return this._context.server;
6489
- }
6490
- get platform() {
6491
- return this._context.platform;
6492
- }
6493
- get entities() {
6494
- return this._context.entities;
6495
- }
6496
- get players() {
6497
- return this._context.players;
6498
- }
6499
- get locations() {
6500
- return this._context.locations;
6501
- }
6502
- get epochs() {
6503
- return this._context.epochs;
6504
- }
6505
- get actions() {
6506
- return this._context.actions;
6507
- }
6508
- async getGame(reload = false) {
6509
- return this._context.getGame(reload);
6510
- }
6511
- async getState(reload = false) {
6512
- return this._context.getState(reload);
6513
- }
6514
- }
6515
-
6516
- function makeShip(state) {
6517
- const info = {
6518
- type: antelope.Name.from('ship'),
6519
- id: antelope.UInt64.from(state.id),
6520
- owner: antelope.Name.from(state.owner),
6521
- entity_name: state.name,
6522
- coordinates: Types.coordinates.from(state.coordinates),
6523
- cargomass: antelope.UInt32.from(0),
6524
- cargo: state.cargo || [],
6525
- is_idle: !state.schedule,
6526
- current_task_elapsed: antelope.UInt32.from(0),
6527
- current_task_remaining: antelope.UInt32.from(0),
6528
- pending_tasks: [],
6529
- };
6530
- if (state.hullmass !== undefined)
6531
- info.hullmass = antelope.UInt32.from(state.hullmass);
6532
- if (state.capacity !== undefined)
6533
- info.capacity = antelope.UInt32.from(state.capacity);
6534
- if (state.energy !== undefined)
6535
- info.energy = antelope.UInt16.from(state.energy);
6536
- if (state.engines)
6537
- info.engines = state.engines;
6538
- if (state.generator)
6539
- info.generator = state.generator;
6540
- if (state.loaders)
6541
- info.loaders = state.loaders;
6542
- if (state.schedule)
6543
- info.schedule = state.schedule;
6544
- const entityInfo = Types.entity_info.from(info);
6545
- return new Ship(entityInfo);
6546
- }
6547
- function makeWarehouse(state) {
6548
- const info = {
6549
- type: antelope.Name.from('warehouse'),
6550
- id: antelope.UInt64.from(state.id),
6551
- owner: antelope.Name.from(state.owner),
6552
- entity_name: state.name,
6553
- coordinates: Types.coordinates.from(state.coordinates),
6554
- capacity: antelope.UInt32.from(state.capacity),
6555
- cargomass: antelope.UInt32.from(0),
6556
- cargo: state.cargo || [],
6557
- is_idle: !state.schedule,
6558
- current_task_elapsed: antelope.UInt32.from(0),
6559
- current_task_remaining: antelope.UInt32.from(0),
6560
- pending_tasks: [],
6561
- };
6562
- if (state.hullmass !== undefined)
6563
- info.hullmass = antelope.UInt32.from(state.hullmass);
6564
- if (state.loaders)
6565
- info.loaders = state.loaders;
6566
- if (state.schedule)
6567
- info.schedule = state.schedule;
6568
- const entityInfo = Types.entity_info.from(info);
6569
- return new Warehouse(entityInfo);
6570
- }
6571
- function makeContainer(state) {
6572
- const entityInfo = Types.entity_info.from({
6573
- type: antelope.Name.from('container'),
6574
- id: antelope.UInt64.from(state.id),
6575
- owner: antelope.Name.from(state.owner),
6576
- entity_name: state.name,
6577
- coordinates: Types.coordinates.from(state.coordinates),
6578
- hullmass: antelope.UInt32.from(state.hullmass),
6579
- capacity: antelope.UInt32.from(state.capacity),
6580
- cargomass: antelope.UInt32.from(state.cargomass || 0),
6581
- cargo: [],
6582
- is_idle: !state.schedule,
6583
- current_task_elapsed: antelope.UInt32.from(0),
6584
- current_task_remaining: antelope.UInt32.from(0),
6585
- pending_tasks: [],
6586
- schedule: state.schedule,
6587
- });
6588
- return new Container(entityInfo);
6589
- }
6590
-
6591
- function deriveStratum(epochSeed, coords, stratum, locationType, subtype, _maxDepth) {
6592
- const seed = antelope.Checksum256.from(epochSeed);
6593
- const c = Coordinates.from(coords);
6594
- const input = `stratum-${c.x}-${c.y}-${stratum}`;
6595
- const hashResult = hash512(seed, input);
6596
- const bytes = hashResult.array;
6597
- const rawReserve = ((bytes[0] << 24) | (bytes[1] << 16) | (bytes[2] << 8) | bytes[3]) >>> 0;
6598
- let reserve = 0;
6599
- if (rawReserve <= YIELD_THRESHOLD) {
6600
- const baseReserve = (rawReserve % 333) + 1;
6601
- const scale = depthScaleFactor(stratum);
6602
- reserve = Math.floor(baseReserve * scale);
6603
- }
6604
- if (reserve === 0)
6605
- return { itemId: 0, seed: 0n, richness: 0, reserve: 0 };
6606
- const eligible = getEligibleResources(locationType, subtype, stratum);
6607
- if (eligible.length === 0)
6608
- return { itemId: 0, seed: 0n, richness: 0, reserve: 0 };
6609
- const resourceRoll = ((bytes[4] << 24) | (bytes[5] << 16) | (bytes[6] << 8) | bytes[7]) >>> 0;
6610
- let totalWeight = 0;
6611
- for (const id of eligible) {
6612
- totalWeight += getResourceWeight(id, stratum);
6613
- }
6614
- let selectedItemId = eligible[0];
6615
- if (totalWeight > 0) {
6616
- const roll = resourceRoll % totalWeight;
6617
- let cumulative = 0;
6618
- for (const id of eligible) {
6619
- cumulative += getResourceWeight(id, stratum);
6620
- if (roll < cumulative) {
6621
- selectedItemId = id;
6622
- break;
6623
- }
6624
- }
6625
- }
6626
- const seedBigInt = (BigInt(bytes[8]) << 56n) |
6627
- (BigInt(bytes[9]) << 48n) |
6628
- (BigInt(bytes[10]) << 40n) |
6629
- (BigInt(bytes[11]) << 32n) |
6630
- (BigInt(bytes[12]) << 24n) |
6631
- (BigInt(bytes[13]) << 16n) |
6632
- (BigInt(bytes[14]) << 8n) |
6633
- BigInt(bytes[15]);
6634
- const rawRichness = (bytes[16] << 8) | bytes[17];
6635
- const normalized = rawRichness / 65535;
6636
- const baseRichness = Math.floor(normalized * normalized * 999) + 1;
6637
- let depthBonus = 0;
6638
- if (stratum > 1) {
6639
- depthBonus = (50 * Math.log(stratum)) / Math.log(65535);
6640
- }
6641
- const richness = Math.min(Math.floor(baseRichness + depthBonus), 1000);
6642
- return { itemId: selectedItemId, seed: seedBigInt, richness, reserve };
6643
- }
6644
- function deriveResourceStats(seed) {
6645
- const seedBytes = new Uint8Array(8);
6646
- for (let i = 0; i < 8; i++) {
6647
- seedBytes[i] = Number(seed & 0xffn);
6648
- seed >>= 8n;
6649
- }
6650
- const hashResult = antelope.Checksum256.hash(antelope.Bytes.from(seedBytes));
6651
- const hashBytes = hashResult.array;
6652
- const extractU32 = (offset) => (hashBytes[offset] * 0x1000000 +
6653
- (hashBytes[offset + 1] << 16) +
6654
- (hashBytes[offset + 2] << 8) +
6655
- hashBytes[offset + 3]) >>> 0;
6656
- const weibull = (raw) => {
6657
- const u = raw / 4294967296;
6658
- let x = 0.27 * Math.sqrt(-Math.log(1 - u));
6659
- if (x > 1)
6660
- x = 1;
6661
- let val = Math.floor(x * 999) + 1;
6662
- if (val > 999)
6663
- val = 999;
6664
- return val;
6665
- };
6666
- return {
6667
- stat1: weibull(extractU32(0)),
6668
- stat2: weibull(extractU32(4)),
6669
- stat3: weibull(extractU32(8)),
6670
- };
6671
- }
6672
-
6673
- const METAL_STATS = [
6674
- {
6675
- key: 'strength',
6676
- label: 'Strength',
6677
- abbreviation: 'STR',
6678
- purpose: 'Raw structural/mechanical force',
6679
- },
6680
- {
6681
- key: 'tolerance',
6682
- label: 'Tolerance',
6683
- abbreviation: 'TOL',
6684
- purpose: 'Ability to withstand heat, pressure, and stress extremes',
6685
- },
6686
- {
6687
- key: 'density',
6688
- label: 'Density',
6689
- abbreviation: 'DEN',
6690
- purpose: 'Mass per unit',
6691
- inverted: true,
6692
- },
6693
- ];
6694
- const PRECIOUS_STATS = [
6695
- {
6696
- key: 'conductivity',
6697
- label: 'Conductivity',
6698
- abbreviation: 'CON',
6699
- purpose: 'Efficiency of energy/signal transfer',
6700
- },
6701
- {
6702
- key: 'ductility',
6703
- label: 'Ductility',
6704
- abbreviation: 'DUC',
6705
- purpose: 'Ability to be worked into fine, precise shapes',
6706
- },
6707
- {
6708
- key: 'reflectivity',
6709
- label: 'Reflectivity',
6710
- abbreviation: 'REF',
6711
- purpose: 'Surface quality for heat management and precision optics',
6712
- },
6713
- ];
6714
- const GAS_STATS = [
6715
- {
6716
- key: 'volatility',
6717
- label: 'Volatility',
6718
- abbreviation: 'VOL',
6719
- purpose: 'Energy release potential for propulsion and force',
6720
- },
6721
- {
6722
- key: 'reactivity',
6723
- label: 'Reactivity',
6724
- abbreviation: 'REA',
6725
- purpose: 'Chemical interaction speed for processing and penetration',
6726
- },
6727
- {
6728
- key: 'thermal',
6729
- label: 'Thermal',
6730
- abbreviation: 'THM',
6731
- purpose: 'Heat capacity for thermal management',
6732
- },
6733
- ];
6734
- const MINERAL_STATS = [
6735
- {
6736
- key: 'resonance',
6737
- label: 'Resonance',
6738
- abbreviation: 'RES',
6739
- purpose: 'Energy field interaction — storage, focusing, projection',
6740
- },
6741
- {
6742
- key: 'hardness',
6743
- label: 'Hardness',
6744
- abbreviation: 'HRD',
6745
- purpose: 'Resistance to wear — cutting surfaces, penetration',
6746
- },
6747
- {
6748
- key: 'clarity',
6749
- label: 'Clarity',
6750
- abbreviation: 'CLR',
6751
- purpose: 'Crystalline perfection — precision optics',
6752
- },
6753
- ];
6754
- const ORGANIC_STATS = [
6755
- {
6756
- key: 'plasticity',
6757
- label: 'Plasticity',
6758
- abbreviation: 'PLA',
6759
- purpose: 'Ease of reshaping — speeds processing',
6760
- },
6761
- {
6762
- key: 'insulation',
6763
- label: 'Insulation',
6764
- abbreviation: 'INS',
6765
- purpose: 'Energy containment — reduces energy loss',
6766
- },
6767
- {
6768
- key: 'purity',
6769
- label: 'Purity',
6770
- abbreviation: 'PUR',
6771
- purpose: 'Biological cleanliness — better composites and lubricants',
6772
- },
6773
- ];
6774
- const STAT_MAP = {
6775
- metal: METAL_STATS,
6776
- precious: PRECIOUS_STATS,
6777
- gas: GAS_STATS,
6778
- mineral: MINERAL_STATS,
6779
- organic: ORGANIC_STATS,
6780
- };
6781
- function getStatDefinitions(category) {
6782
- return STAT_MAP[category];
6783
- }
6784
- function getStatName(category, index) {
6785
- return STAT_MAP[category][index];
6786
- }
6787
- function resolveStats(category, stats) {
6788
- return {
6789
- definitions: STAT_MAP[category],
6790
- values: [stats.stat1, stats.stat2, stats.stat3],
6791
- };
6792
- }
6793
-
6794
- const ITEM_ENGINE_T1 = 10100;
6795
- const ITEM_GENERATOR_T1 = 10101;
6796
- const ITEM_GATHERER_T1 = 10102;
6797
- const ITEM_LOADER_T1 = 10103;
6798
- const ITEM_MANUFACTURING_T1 = 10104;
6799
- const ITEM_STORAGE_T1 = 10105;
6800
- const ITEM_HAULER_T1 = 10106;
6801
- const MODULE_ANY = 0;
6802
- const MODULE_ENGINE = 1;
6803
- const MODULE_GENERATOR = 2;
6804
- const MODULE_GATHERER = 3;
6805
- const MODULE_LOADER = 4;
6806
- const MODULE_WARP = 5;
6807
- const MODULE_CRAFTER = 6;
6808
- const MODULE_LAUNCHER = 7;
6809
- const MODULE_STORAGE = 8;
6810
- const MODULE_HAULER = 9;
6811
- function moduleAccepts(slotType, moduleType) {
6812
- return slotType === MODULE_ANY || slotType === moduleType;
6813
- }
6814
- function getModuleCapabilityType(itemId) {
6815
- switch (itemId) {
6816
- case ITEM_ENGINE_T1:
6817
- return MODULE_ENGINE;
6818
- case ITEM_GENERATOR_T1:
6819
- return MODULE_GENERATOR;
6820
- case ITEM_GATHERER_T1:
6821
- return MODULE_GATHERER;
6822
- case ITEM_LOADER_T1:
6823
- return MODULE_LOADER;
6824
- case ITEM_MANUFACTURING_T1:
6825
- return MODULE_CRAFTER;
6826
- case ITEM_STORAGE_T1:
6827
- return MODULE_STORAGE;
6828
- case ITEM_HAULER_T1:
6829
- return MODULE_HAULER;
6830
- default:
6831
- return 0xff;
6832
- }
6833
- }
6834
- function isModuleItem(itemId) {
6835
- return getModuleCapabilityType(itemId) !== 0xff;
4956
+ function isModuleItem(itemId) {
4957
+ return getModuleCapabilityType(itemId) !== 0xff;
6836
4958
  }
6837
4959
 
6838
4960
  const ITEM_MATTER_CONDUIT = 10005;
@@ -7249,211 +5371,2320 @@ const moduleRecipes = [
7249
5371
  function getModuleRecipe(id) {
7250
5372
  return moduleRecipes.find((r) => r.id === id);
7251
5373
  }
7252
- function getModuleRecipeByItemId(itemId) {
7253
- return moduleRecipes.find((r) => r.itemId === itemId);
5374
+ function getModuleRecipeByItemId(itemId) {
5375
+ return moduleRecipes.find((r) => r.itemId === itemId);
5376
+ }
5377
+ function getComponentById(id) {
5378
+ return components.find((c) => c.id === id);
5379
+ }
5380
+ function getEntityRecipe(id) {
5381
+ return entityRecipes.find((r) => r.id === id);
5382
+ }
5383
+ function getEntityRecipeByItemId(itemId) {
5384
+ return entityRecipes.find((r) => r.packedItemId === itemId);
5385
+ }
5386
+ function getEntitySlotLayout(packedItemId) {
5387
+ const recipe = getEntityRecipeByItemId(packedItemId);
5388
+ return recipe?.moduleSlots ?? [];
5389
+ }
5390
+ function getAllCraftableItems() {
5391
+ const items = [];
5392
+ for (const comp of components) {
5393
+ items.push({
5394
+ type: 'component',
5395
+ id: comp.id,
5396
+ name: comp.name,
5397
+ description: comp.description,
5398
+ color: comp.color,
5399
+ });
5400
+ }
5401
+ for (const entity of entityRecipes) {
5402
+ items.push({
5403
+ type: 'entity',
5404
+ id: entity.id,
5405
+ name: entity.name,
5406
+ description: entity.description,
5407
+ color: entity.color,
5408
+ });
5409
+ }
5410
+ for (const mod of moduleRecipes) {
5411
+ items.push({
5412
+ type: 'module',
5413
+ id: mod.id,
5414
+ name: mod.name,
5415
+ description: mod.description,
5416
+ color: mod.color,
5417
+ });
5418
+ }
5419
+ return items;
5420
+ }
5421
+ function getComponentsForCategory(category) {
5422
+ return components.filter((c) => c.recipe.some((r) => r.category === category));
5423
+ }
5424
+ function getComponentsForStat(statKey) {
5425
+ return components.filter((c) => c.stats.some((s) => s.key === statKey));
5426
+ }
5427
+
5428
+ const METAL_STATS = [
5429
+ {
5430
+ key: 'strength',
5431
+ label: 'Strength',
5432
+ abbreviation: 'STR',
5433
+ purpose: 'Raw structural/mechanical force',
5434
+ },
5435
+ {
5436
+ key: 'tolerance',
5437
+ label: 'Tolerance',
5438
+ abbreviation: 'TOL',
5439
+ purpose: 'Ability to withstand heat, pressure, and stress extremes',
5440
+ },
5441
+ {
5442
+ key: 'density',
5443
+ label: 'Density',
5444
+ abbreviation: 'DEN',
5445
+ purpose: 'Mass per unit',
5446
+ inverted: true,
5447
+ },
5448
+ ];
5449
+ const PRECIOUS_STATS = [
5450
+ {
5451
+ key: 'conductivity',
5452
+ label: 'Conductivity',
5453
+ abbreviation: 'CON',
5454
+ purpose: 'Efficiency of energy/signal transfer',
5455
+ },
5456
+ {
5457
+ key: 'ductility',
5458
+ label: 'Ductility',
5459
+ abbreviation: 'DUC',
5460
+ purpose: 'Ability to be worked into fine, precise shapes',
5461
+ },
5462
+ {
5463
+ key: 'reflectivity',
5464
+ label: 'Reflectivity',
5465
+ abbreviation: 'REF',
5466
+ purpose: 'Surface quality for heat management and precision optics',
5467
+ },
5468
+ ];
5469
+ const GAS_STATS = [
5470
+ {
5471
+ key: 'volatility',
5472
+ label: 'Volatility',
5473
+ abbreviation: 'VOL',
5474
+ purpose: 'Energy release potential for propulsion and force',
5475
+ },
5476
+ {
5477
+ key: 'reactivity',
5478
+ label: 'Reactivity',
5479
+ abbreviation: 'REA',
5480
+ purpose: 'Chemical interaction speed for processing and penetration',
5481
+ },
5482
+ {
5483
+ key: 'thermal',
5484
+ label: 'Thermal',
5485
+ abbreviation: 'THM',
5486
+ purpose: 'Heat capacity for thermal management',
5487
+ },
5488
+ ];
5489
+ const MINERAL_STATS = [
5490
+ {
5491
+ key: 'resonance',
5492
+ label: 'Resonance',
5493
+ abbreviation: 'RES',
5494
+ purpose: 'Energy field interaction — storage, focusing, projection',
5495
+ },
5496
+ {
5497
+ key: 'hardness',
5498
+ label: 'Hardness',
5499
+ abbreviation: 'HRD',
5500
+ purpose: 'Resistance to wear — cutting surfaces, penetration',
5501
+ },
5502
+ {
5503
+ key: 'clarity',
5504
+ label: 'Clarity',
5505
+ abbreviation: 'CLR',
5506
+ purpose: 'Crystalline perfection — precision optics',
5507
+ },
5508
+ ];
5509
+ const ORGANIC_STATS = [
5510
+ {
5511
+ key: 'plasticity',
5512
+ label: 'Plasticity',
5513
+ abbreviation: 'PLA',
5514
+ purpose: 'Ease of reshaping — speeds processing',
5515
+ },
5516
+ {
5517
+ key: 'insulation',
5518
+ label: 'Insulation',
5519
+ abbreviation: 'INS',
5520
+ purpose: 'Energy containment — reduces energy loss',
5521
+ },
5522
+ {
5523
+ key: 'purity',
5524
+ label: 'Purity',
5525
+ abbreviation: 'PUR',
5526
+ purpose: 'Biological cleanliness — better composites and lubricants',
5527
+ },
5528
+ ];
5529
+ const STAT_MAP = {
5530
+ metal: METAL_STATS,
5531
+ precious: PRECIOUS_STATS,
5532
+ gas: GAS_STATS,
5533
+ mineral: MINERAL_STATS,
5534
+ organic: ORGANIC_STATS,
5535
+ };
5536
+ function getStatDefinitions(category) {
5537
+ return STAT_MAP[category];
5538
+ }
5539
+ function getStatName(category, index) {
5540
+ return STAT_MAP[category][index];
5541
+ }
5542
+ function resolveStats(category, stats) {
5543
+ return {
5544
+ definitions: STAT_MAP[category],
5545
+ values: [stats.stat1, stats.stat2, stats.stat3],
5546
+ };
5547
+ }
5548
+
5549
+ const RESERVE_TIERS = {
5550
+ small: { min: 15, max: 60 },
5551
+ medium: { min: 100, max: 200 },
5552
+ large: { min: 400, max: 700 },
5553
+ massive: { min: 1000, max: 2500 },
5554
+ motherlode: { min: 4000, max: 10000 },
5555
+ };
5556
+ const SHALLOW_THRESHOLDS = {
5557
+ small: 0.8,
5558
+ medium: 0.991946,
5559
+ large: 0.999946,
5560
+ massive: 0.999996,
5561
+ };
5562
+ const DEEP_THRESHOLDS = {
5563
+ small: 0.5,
5564
+ medium: 0.95892,
5565
+ large: 0.99892,
5566
+ massive: 0.99992,
5567
+ };
5568
+ const TIER_ROLL_MAX = 0x10000;
5569
+ function lerp$1(a, b, t) {
5570
+ return a + (b - a) * t;
5571
+ }
5572
+ function rollTier(tierRoll, stratum) {
5573
+ const d = Math.min(stratum, 65535) / 65535;
5574
+ const smallMax = lerp$1(SHALLOW_THRESHOLDS.small, DEEP_THRESHOLDS.small, d) * TIER_ROLL_MAX;
5575
+ const mediumMax = lerp$1(SHALLOW_THRESHOLDS.medium, DEEP_THRESHOLDS.medium, d) * TIER_ROLL_MAX;
5576
+ const largeMax = lerp$1(SHALLOW_THRESHOLDS.large, DEEP_THRESHOLDS.large, d) * TIER_ROLL_MAX;
5577
+ const massiveMax = lerp$1(SHALLOW_THRESHOLDS.massive, DEEP_THRESHOLDS.massive, d) * TIER_ROLL_MAX;
5578
+ if (tierRoll < smallMax)
5579
+ return 'small';
5580
+ if (tierRoll < mediumMax)
5581
+ return 'medium';
5582
+ if (tierRoll < largeMax)
5583
+ return 'large';
5584
+ if (tierRoll < massiveMax)
5585
+ return 'massive';
5586
+ return 'motherlode';
5587
+ }
5588
+ function rollWithinTier(withinRoll, range) {
5589
+ const u = withinRoll / 65535;
5590
+ const skewed = u * u;
5591
+ return Math.floor(range.min + skewed * (range.max - range.min));
5592
+ }
5593
+
5594
+ function deriveStratum(epochSeed, coords, stratum, locationType, subtype, _maxDepth) {
5595
+ const seed = antelope.Checksum256.from(epochSeed);
5596
+ const c = Coordinates.from(coords);
5597
+ const input = `stratum-${c.x}-${c.y}-${stratum}`;
5598
+ const hashResult = hash512(seed, input);
5599
+ const bytes = hashResult.array;
5600
+ const rawReserve = ((bytes[0] << 24) | (bytes[1] << 16) | (bytes[2] << 8) | bytes[3]) >>> 0;
5601
+ let reserve = 0;
5602
+ if (rawReserve <= YIELD_THRESHOLD) {
5603
+ const tierRoll = ((bytes[18] << 8) | bytes[19]) >>> 0;
5604
+ const withinRoll = ((bytes[20] << 8) | bytes[21]) >>> 0;
5605
+ const tier = rollTier(tierRoll, stratum);
5606
+ reserve = rollWithinTier(withinRoll, RESERVE_TIERS[tier]);
5607
+ }
5608
+ if (reserve === 0)
5609
+ return { itemId: 0, seed: 0n, richness: 0, reserve: 0 };
5610
+ const eligible = getEligibleResources(locationType, subtype, stratum);
5611
+ if (eligible.length === 0)
5612
+ return { itemId: 0, seed: 0n, richness: 0, reserve: 0 };
5613
+ const resourceRoll = ((bytes[4] << 24) | (bytes[5] << 16) | (bytes[6] << 8) | bytes[7]) >>> 0;
5614
+ let totalWeight = 0;
5615
+ for (const id of eligible) {
5616
+ totalWeight += getResourceWeight(id, stratum);
5617
+ }
5618
+ let selectedItemId = eligible[0];
5619
+ if (totalWeight > 0) {
5620
+ const roll = resourceRoll % totalWeight;
5621
+ let cumulative = 0;
5622
+ for (const id of eligible) {
5623
+ cumulative += getResourceWeight(id, stratum);
5624
+ if (roll < cumulative) {
5625
+ selectedItemId = id;
5626
+ break;
5627
+ }
5628
+ }
5629
+ }
5630
+ const seedBigInt = (BigInt(bytes[8]) << 56n) |
5631
+ (BigInt(bytes[9]) << 48n) |
5632
+ (BigInt(bytes[10]) << 40n) |
5633
+ (BigInt(bytes[11]) << 32n) |
5634
+ (BigInt(bytes[12]) << 24n) |
5635
+ (BigInt(bytes[13]) << 16n) |
5636
+ (BigInt(bytes[14]) << 8n) |
5637
+ BigInt(bytes[15]);
5638
+ const rawRichness = (bytes[16] << 8) | bytes[17];
5639
+ const normalized = rawRichness / 65535;
5640
+ const baseRichness = Math.floor(normalized * normalized * 999) + 1;
5641
+ let depthBonus = 0;
5642
+ if (stratum > 1) {
5643
+ depthBonus = (50 * Math.log(stratum)) / Math.log(65535);
5644
+ }
5645
+ const richness = Math.min(Math.floor(baseRichness + depthBonus), 1000);
5646
+ return { itemId: selectedItemId, seed: seedBigInt, richness, reserve };
5647
+ }
5648
+ function deriveResourceStats(seed) {
5649
+ const seedBytes = new Uint8Array(8);
5650
+ for (let i = 0; i < 8; i++) {
5651
+ seedBytes[i] = Number(seed & 0xffn);
5652
+ seed >>= 8n;
5653
+ }
5654
+ const hashResult = antelope.Checksum256.hash(antelope.Bytes.from(seedBytes));
5655
+ const hashBytes = hashResult.array;
5656
+ const extractU32 = (offset) => (hashBytes[offset] * 0x1000000 +
5657
+ (hashBytes[offset + 1] << 16) +
5658
+ (hashBytes[offset + 2] << 8) +
5659
+ hashBytes[offset + 3]) >>>
5660
+ 0;
5661
+ const weibull = (raw) => {
5662
+ const u = raw / 4294967296;
5663
+ let x = 0.24 * Math.sqrt(-Math.log(1 - u));
5664
+ if (x > 1)
5665
+ x = 1;
5666
+ let val = Math.floor(x * 999) + 1;
5667
+ if (val > 999)
5668
+ val = 999;
5669
+ return val;
5670
+ };
5671
+ return {
5672
+ stat1: weibull(extractU32(0)),
5673
+ stat2: weibull(extractU32(4)),
5674
+ stat3: weibull(extractU32(8)),
5675
+ };
5676
+ }
5677
+
5678
+ function encodeStats(values) {
5679
+ let seed = 0n;
5680
+ for (let i = 0; i < values.length && i < 6; i++) {
5681
+ seed |= BigInt(values[i] & 0x3ff) << BigInt(i * 10);
5682
+ }
5683
+ return seed;
5684
+ }
5685
+ function decodeStat(seed, index) {
5686
+ return Number((seed >> BigInt(index * 10)) & 0x3ffn);
5687
+ }
5688
+ function decodeStats(seed, count) {
5689
+ const stats = [];
5690
+ for (let i = 0; i < count; i++) {
5691
+ stats.push(decodeStat(seed, i));
5692
+ }
5693
+ return stats;
5694
+ }
5695
+ function mapStatsToKeys(seed, statDefs) {
5696
+ const values = decodeStats(seed, statDefs.length);
5697
+ const result = {};
5698
+ for (let i = 0; i < statDefs.length; i++) {
5699
+ result[statDefs[i].key] = values[i];
5700
+ }
5701
+ return result;
5702
+ }
5703
+ function decodeCraftedItemStats(itemId, seed) {
5704
+ const comp = getComponentById(itemId);
5705
+ if (comp)
5706
+ return mapStatsToKeys(seed, comp.stats);
5707
+ const entityRecipe = entityRecipes.find((r) => r.packedItemId === itemId);
5708
+ if (entityRecipe)
5709
+ return mapStatsToKeys(seed, entityRecipe.stats);
5710
+ const moduleRecipe = moduleRecipes.find((r) => r.itemId === itemId);
5711
+ if (moduleRecipe)
5712
+ return mapStatsToKeys(seed, moduleRecipe.stats);
5713
+ return {};
5714
+ }
5715
+ function blendStacks(stacks, statKey) {
5716
+ let totalQty = 0;
5717
+ let weightedSum = 0;
5718
+ for (const stack of stacks) {
5719
+ const val = stack.stats[statKey] ?? 0;
5720
+ weightedSum += val * stack.quantity;
5721
+ totalQty += stack.quantity;
5722
+ }
5723
+ if (totalQty === 0)
5724
+ return 0;
5725
+ return Math.floor(weightedSum / totalQty);
5726
+ }
5727
+ function computeComponentStats(componentId, categoryStacks) {
5728
+ const comp = getComponentById(componentId);
5729
+ if (!comp)
5730
+ return [];
5731
+ return comp.stats.map((statDef) => {
5732
+ const matching = categoryStacks.find((cs) => cs.category === statDef.source);
5733
+ const value = matching ? blendStacks(matching.stacks, statDef.key) : 0;
5734
+ return { key: statDef.key, value: Math.max(1, Math.min(999, value)) };
5735
+ });
5736
+ }
5737
+ function blendComponentStacks(stacks) {
5738
+ if (stacks.length === 0)
5739
+ return {};
5740
+ const allKeys = new Set();
5741
+ for (const s of stacks) {
5742
+ for (const k of Object.keys(s.stats))
5743
+ allKeys.add(k);
5744
+ }
5745
+ const result = {};
5746
+ for (const key of allKeys) {
5747
+ result[key] = blendStacks(stacks.map((s) => ({ quantity: s.quantity, stats: s.stats })), key);
5748
+ }
5749
+ return result;
5750
+ }
5751
+ function computeEntityStats(entityRecipeId, componentStacks) {
5752
+ const recipe = getEntityRecipe(entityRecipeId) ?? getModuleRecipe(entityRecipeId);
5753
+ if (!recipe)
5754
+ return [];
5755
+ const blendedByComponent = {};
5756
+ for (const [compId, stacks] of Object.entries(componentStacks)) {
5757
+ blendedByComponent[Number(compId)] = blendComponentStacks(stacks);
5758
+ }
5759
+ return recipe.stats.map((stat) => {
5760
+ const blended = blendedByComponent[stat.sourceComponentId] ?? {};
5761
+ const value = blended[stat.sourceStatKey] ?? 0;
5762
+ return { key: stat.key, value: Math.max(1, Math.min(999, value)) };
5763
+ });
5764
+ }
5765
+ function decodeStackStats(itemId, seed) {
5766
+ if (itemId >= 10000) {
5767
+ return decodeCraftedItemStats(itemId, BigInt(seed.toString()));
5768
+ }
5769
+ const raw = deriveResourceStats(BigInt(seed.toString()));
5770
+ return { stat1: raw.stat1, stat2: raw.stat2, stat3: raw.stat3 };
5771
+ }
5772
+ const categoryItemMass = {
5773
+ metal: 30000,
5774
+ precious: 40000,
5775
+ gas: 15000,
5776
+ mineral: 22000,
5777
+ organic: 15000,
5778
+ };
5779
+ function computeInputMass(itemId, itemType) {
5780
+ if (itemType === 'component') {
5781
+ const comp = getComponentById(itemId);
5782
+ if (!comp)
5783
+ return 0;
5784
+ return comp.recipe.reduce((sum, input) => {
5785
+ const mass = input.category ? categoryItemMass[input.category] ?? 0 : 0;
5786
+ return sum + mass * input.quantity;
5787
+ }, 0);
5788
+ }
5789
+ if (itemType === 'module') {
5790
+ const mod = getModuleRecipe(itemId);
5791
+ if (!mod)
5792
+ return 0;
5793
+ return mod.recipe.reduce((sum, input) => {
5794
+ const comp = input.itemId ? getComponentById(input.itemId) : undefined;
5795
+ return sum + (comp?.mass ?? 0) * input.quantity;
5796
+ }, 0);
5797
+ }
5798
+ if (itemType === 'entity') {
5799
+ const ent = getEntityRecipe(itemId);
5800
+ if (!ent)
5801
+ return 0;
5802
+ return ent.recipe.reduce((sum, input) => {
5803
+ const comp = input.itemId ? getComponentById(input.itemId) : undefined;
5804
+ return sum + (comp?.mass ?? 0) * input.quantity;
5805
+ }, 0);
5806
+ }
5807
+ return 0;
5808
+ }
5809
+ function blendCrossGroup(sources) {
5810
+ let weightedSum = 0;
5811
+ let totalWeight = 0;
5812
+ for (const src of sources) {
5813
+ weightedSum += src.value * src.weight;
5814
+ totalWeight += src.weight;
5815
+ }
5816
+ if (totalWeight === 0)
5817
+ return 1;
5818
+ const result = Math.floor(weightedSum / totalWeight);
5819
+ return Math.max(1, Math.min(999, result));
5820
+ }
5821
+ function blendCargoStacks(itemId, stacks) {
5822
+ const decoded = stacks.map((s) => ({
5823
+ quantity: s.quantity,
5824
+ stats: decodeStackStats(itemId, s.seed),
5825
+ }));
5826
+ const allKeys = Object.keys(decoded[0]?.stats ?? {});
5827
+ const blended = allKeys.map((key) => Math.max(1, Math.min(999, blendStacks(decoded, key))));
5828
+ return antelope.UInt64.from(encodeStats(blended));
5829
+ }
5830
+ function decodeRawStackToCategoryStats(seed, category) {
5831
+ const raw = deriveResourceStats(seed);
5832
+ const defs = getStatDefinitions(category);
5833
+ const result = {};
5834
+ if (defs[0])
5835
+ result[defs[0].key] = raw.stat1;
5836
+ if (defs[1])
5837
+ result[defs[1].key] = raw.stat2;
5838
+ if (defs[2])
5839
+ result[defs[2].key] = raw.stat3;
5840
+ return result;
5841
+ }
5842
+ function computeCraftedOutputSeed(outputItemId, slotInputs) {
5843
+ var _a;
5844
+ const component = getComponentById(outputItemId);
5845
+ if (component) {
5846
+ const categoryStacks = [];
5847
+ for (const slot of slotInputs) {
5848
+ if (!slot.category)
5849
+ continue;
5850
+ const slotIsComponent = getComponentById(slot.itemId) !== undefined;
5851
+ const stacks = slot.stacks.map((s) => ({
5852
+ quantity: s.quantity,
5853
+ stats: slotIsComponent
5854
+ ? decodeCraftedItemStats(slot.itemId, s.seed)
5855
+ : decodeRawStackToCategoryStats(s.seed, slot.category),
5856
+ }));
5857
+ categoryStacks.push({ category: slot.category, stacks });
5858
+ }
5859
+ const stats = computeComponentStats(outputItemId, categoryStacks);
5860
+ const ordered = component.stats.map((statDef) => {
5861
+ const found = stats.find((s) => s.key === statDef.key);
5862
+ return found ? found.value : 0;
5863
+ });
5864
+ return antelope.UInt64.from(encodeStats(ordered));
5865
+ }
5866
+ const entityRecipe = getEntityRecipeByItemId(outputItemId);
5867
+ if (entityRecipe) {
5868
+ const componentStacks = {};
5869
+ for (const slot of slotInputs) {
5870
+ if (slot.category !== undefined) {
5871
+ throw new Error(`entity recipe ${entityRecipe.id} expects component inputs but slot itemId=${slot.itemId} has category=${slot.category}`);
5872
+ }
5873
+ const list = (componentStacks[_a = slot.itemId] ?? (componentStacks[_a] = []));
5874
+ for (const s of slot.stacks) {
5875
+ list.push({
5876
+ quantity: s.quantity,
5877
+ stats: decodeCraftedItemStats(slot.itemId, s.seed),
5878
+ });
5879
+ }
5880
+ }
5881
+ const stats = computeEntityStats(entityRecipe.id, componentStacks);
5882
+ const ordered = entityRecipe.stats.map((statDef) => {
5883
+ const found = stats.find((s) => s.key === statDef.key);
5884
+ return found ? found.value : 0;
5885
+ });
5886
+ return antelope.UInt64.from(encodeStats(ordered));
5887
+ }
5888
+ throw new Error(`computeCraftedOutputSeed: no recipe found for outputItemId=${outputItemId}`);
5889
+ }
5890
+
5891
+ const itemsById = new Map();
5892
+ const synthesizedCache = new Map();
5893
+ for (const g of itemsData) {
5894
+ const item = exports.Item.from({
5895
+ id: g.id,
5896
+ name: g.name,
5897
+ description: g.description,
5898
+ mass: g.mass,
5899
+ category: g.category,
5900
+ tier: g.tier,
5901
+ color: g.color,
5902
+ });
5903
+ itemsById.set(item.id.toNumber(), item);
5904
+ }
5905
+ const itemIds = Array.from(itemsById.values(), (i) => i.id);
5906
+ function synthesizeItem(id, source) {
5907
+ return exports.Item.from({
5908
+ id,
5909
+ name: source.name,
5910
+ description: source.description,
5911
+ mass: source.mass,
5912
+ category: 'metal',
5913
+ tier: 't1',
5914
+ color: source.color,
5915
+ });
5916
+ }
5917
+ function synthesizeFromRecipes(id) {
5918
+ const component = getComponentById(id);
5919
+ if (component)
5920
+ return synthesizeItem(id, component);
5921
+ const entityRecipe = getEntityRecipeByItemId(id);
5922
+ if (entityRecipe) {
5923
+ return synthesizeItem(id, {
5924
+ ...entityRecipe,
5925
+ mass: computeInputMass(entityRecipe.id, 'entity'),
5926
+ });
5927
+ }
5928
+ const moduleRecipe = getModuleRecipeByItemId(id);
5929
+ if (moduleRecipe) {
5930
+ return synthesizeItem(id, {
5931
+ ...moduleRecipe,
5932
+ mass: computeInputMass(moduleRecipe.id, 'module'),
5933
+ });
5934
+ }
5935
+ return undefined;
5936
+ }
5937
+ function getItem(itemId) {
5938
+ const id = antelope.UInt16.from(itemId).toNumber();
5939
+ const existing = itemsById.get(id) ?? synthesizedCache.get(id);
5940
+ if (existing)
5941
+ return existing;
5942
+ const synthesized = synthesizeFromRecipes(id);
5943
+ if (synthesized) {
5944
+ synthesizedCache.set(id, synthesized);
5945
+ return synthesized;
5946
+ }
5947
+ throw new Error(`Item with id ${id} not found`);
5948
+ }
5949
+ function getItems() {
5950
+ return Array.from(itemsById.values());
5951
+ }
5952
+
5953
+ function calc_orbital_altitude(mass) {
5954
+ if (mass <= BASE_ORBITAL_MASS) {
5955
+ return MIN_ORBITAL_ALTITUDE;
5956
+ }
5957
+ const ratio = mass / BASE_ORBITAL_MASS;
5958
+ const capRatio = 10.0;
5959
+ let scale = Math.log(ratio) / Math.log(capRatio);
5960
+ scale = Math.min(scale, 1.0);
5961
+ return MIN_ORBITAL_ALTITUDE + Math.floor((MAX_ORBITAL_ALTITUDE - MIN_ORBITAL_ALTITUDE) * scale);
5962
+ }
5963
+ function distanceBetweenCoordinates(origin, destination) {
5964
+ return distanceBetweenPoints(origin.x, origin.y, destination.x, destination.y);
5965
+ }
5966
+ function distanceBetweenPoints(x1, y1, x2, y2) {
5967
+ const x = Math.pow(x1 - x2, 2);
5968
+ const y = Math.pow(y1 - y2, 2);
5969
+ return antelope.UInt64.from(Math.sqrt(x + y) * PRECISION$1);
5970
+ }
5971
+ function lerp(origin, destination, time) {
5972
+ return {
5973
+ x: (1 - time) * Number(origin.x) + time * Number(destination.x),
5974
+ y: (1 - time) * Number(origin.y) + time * Number(destination.y),
5975
+ };
5976
+ }
5977
+ function rotation(origin, destination) {
5978
+ return Math.atan2(destination.y - origin.y, destination.x - origin.x) * (180 / Math.PI) + 90;
5979
+ }
5980
+ function findNearbyPlanets(seed, origin, maxDistance = 20 * PRECISION$1) {
5981
+ const nearbySystems = [];
5982
+ const max = antelope.UInt64.from(maxDistance / PRECISION$1);
5983
+ const xMin = antelope.Int64.from(origin.x).subtracting(max);
5984
+ const xMax = antelope.Int64.from(origin.x).adding(max);
5985
+ const yMin = antelope.Int64.from(origin.y).subtracting(max);
5986
+ const yMax = antelope.Int64.from(origin.y).adding(max);
5987
+ for (let x = Number(xMin); x <= Number(xMax); x++) {
5988
+ for (let y = Number(yMin); y <= Number(yMax); y++) {
5989
+ const samePlace = x === Number(origin.x) && y === Number(origin.y);
5990
+ if (!samePlace) {
5991
+ const distance = distanceBetweenPoints(origin.x, origin.y, x, y);
5992
+ if (Number(distance) <= Number(maxDistance)) {
5993
+ const system = hasSystem(seed, { x, y });
5994
+ if (system) {
5995
+ nearbySystems.push({ origin, destination: { x, y }, distance });
5996
+ }
5997
+ }
5998
+ }
5999
+ }
6000
+ }
6001
+ return nearbySystems;
6002
+ }
6003
+ function calc_rechargetime(capacity, energy, recharge) {
6004
+ const cap = antelope.UInt32.from(capacity);
6005
+ const eng = antelope.UInt32.from(energy);
6006
+ if (eng.gte(cap))
6007
+ return antelope.UInt32.zero;
6008
+ return cap.subtracting(eng).dividing(recharge);
6009
+ }
6010
+ function calc_ship_rechargetime(ship) {
6011
+ if (!ship.generator)
6012
+ return antelope.UInt32.from(0);
6013
+ return calc_rechargetime(ship.generator.capacity, ship.energy ?? antelope.UInt16.from(0), ship.generator.recharge);
6014
+ }
6015
+ function calc_flighttime(distance, acceleration) {
6016
+ return antelope.UInt32.from(2 * Math.sqrt(Number(distance) / acceleration));
6017
+ }
6018
+ function calc_loader_flighttime(ship, mass, altitude) {
6019
+ const z = altitude ?? ship.coordinates.z?.toNumber() ?? calc_orbital_altitude(Number(mass));
6020
+ return calc_flighttime(z, calc_loader_acceleration(ship, mass));
6021
+ }
6022
+ function calc_loader_acceleration(ship, mass) {
6023
+ const thrust = ship.loaders ? Number(ship.loaders.thrust) : 0;
6024
+ const loaderMass = ship.loaders ? Number(ship.loaders.mass) : 0;
6025
+ return calc_acceleration(thrust, Number(mass) + loaderMass);
6026
+ }
6027
+ function calc_ship_flighttime(ship, mass, distance) {
6028
+ const acceleration = calc_ship_acceleration(ship, mass);
6029
+ return calc_flighttime(distance, acceleration);
6030
+ }
6031
+ function calc_ship_acceleration(ship, mass) {
6032
+ const thrust = ship.engines ? Number(ship.engines.thrust) : 0;
6033
+ return calc_acceleration(thrust, Number(mass));
6034
+ }
6035
+ function calc_acceleration(thrust, mass) {
6036
+ return (thrust / mass) * PRECISION$1;
6037
+ }
6038
+ function calc_ship_mass(ship, cargos) {
6039
+ const mass = antelope.UInt64.from(0);
6040
+ mass.add(ship.hullmass);
6041
+ if (ship.loaders && ship.loaders.quantity.gt(antelope.UInt32.zero)) {
6042
+ mass.add(ship.loaders.mass.multiplying(ship.loaders.quantity));
6043
+ }
6044
+ for (const cargo of cargos) {
6045
+ mass.add(getItem(cargo.item_id).mass.multiplying(cargo.quantity));
6046
+ }
6047
+ return mass;
6048
+ }
6049
+ function calc_energyusage(distance, drain) {
6050
+ return antelope.UInt64.from(distance).dividing(PRECISION$1).multiplying(drain);
6051
+ }
6052
+ function calculateTransferTime(ship, cargos, quantities) {
6053
+ let mass = antelope.UInt64.from(0);
6054
+ for (const cargo of cargos) {
6055
+ const qty = quantities?.get(Number(cargo.item_id)) ?? 0;
6056
+ if (qty > 0) {
6057
+ const good_mass = getItem(cargo.item_id).mass;
6058
+ const cargo_mass = good_mass.multiplying(qty);
6059
+ mass = antelope.UInt64.from(mass).adding(cargo_mass);
6060
+ }
6061
+ }
6062
+ if (mass.equals(antelope.UInt64.zero)) {
6063
+ return antelope.UInt32.from(0);
6064
+ }
6065
+ if (!ship.loaders)
6066
+ return antelope.UInt32.from(0);
6067
+ mass = antelope.UInt64.from(mass).adding(ship.loaders.mass);
6068
+ const transfer_time = calc_loader_flighttime(ship, mass);
6069
+ return transfer_time.dividing(ship.loaders.quantity);
6070
+ }
6071
+ function calculateRefuelingTime(ship) {
6072
+ return calc_ship_rechargetime(ship);
6073
+ }
6074
+ function calculateFlightTime(ship, cargos, distance) {
6075
+ const mass = calc_ship_mass(ship, cargos);
6076
+ return calc_ship_flighttime(ship, mass, distance);
6077
+ }
6078
+ function calculateLoadTimeBreakdown(ship, cargos, loadQuantities, unloadQuantities) {
6079
+ let mass_unload = antelope.UInt64.from(0);
6080
+ let mass_load = antelope.UInt64.from(0);
6081
+ for (const cargo of cargos) {
6082
+ const goodId = Number(cargo.item_id);
6083
+ const loadQty = loadQuantities?.get(goodId) ?? 0;
6084
+ const unloadQty = unloadQuantities?.get(goodId) ?? 0;
6085
+ if (loadQty > 0 || unloadQty > 0) {
6086
+ const good = getItem(cargo.item_id);
6087
+ if (loadQty > 0) {
6088
+ const cargo_mass = good.mass.multiplying(loadQty);
6089
+ mass_load = antelope.UInt64.from(mass_load).adding(cargo_mass);
6090
+ }
6091
+ if (unloadQty > 0) {
6092
+ const cargo_mass = good.mass.multiplying(unloadQty);
6093
+ mass_unload = antelope.UInt64.from(mass_unload).adding(cargo_mass);
6094
+ }
6095
+ }
6096
+ }
6097
+ let unloadTime = 0;
6098
+ let loadTime = 0;
6099
+ if (mass_unload.gt(antelope.UInt64.zero) && ship.loaders) {
6100
+ const totalMass = antelope.UInt64.from(mass_unload).adding(ship.loaders.mass);
6101
+ unloadTime = Number(calc_loader_flighttime(ship, totalMass));
6102
+ }
6103
+ if (mass_load.gt(antelope.UInt64.zero) && ship.loaders) {
6104
+ const totalMass = antelope.UInt64.from(mass_load).adding(ship.loaders.mass);
6105
+ loadTime = Number(calc_loader_flighttime(ship, totalMass));
6106
+ }
6107
+ const numLoaders = ship.loaders ? Number(ship.loaders.quantity) : 0;
6108
+ const totalTime = numLoaders > 0 ? (unloadTime + loadTime) / numLoaders : 0;
6109
+ const unloadTimePerLoader = numLoaders > 0 ? unloadTime / numLoaders : 0;
6110
+ const loadTimePerLoader = numLoaders > 0 ? loadTime / numLoaders : 0;
6111
+ return {
6112
+ unloadTime: unloadTimePerLoader,
6113
+ loadTime: loadTimePerLoader,
6114
+ totalTime,
6115
+ unloadMass: Number(mass_unload),
6116
+ loadMass: Number(mass_load),
6117
+ };
6118
+ }
6119
+ function estimateTravelTime(ship, travelMass, distance, options = {}) {
6120
+ const { needsRecharge = false, loadMass, unloadMass } = options;
6121
+ const flightTime = calc_ship_flighttime(ship, antelope.UInt64.from(travelMass), antelope.UInt64.from(distance));
6122
+ const rechargeTime = needsRecharge ? calc_ship_rechargetime(ship) : antelope.UInt32.zero;
6123
+ let loadTime = antelope.UInt32.zero;
6124
+ let unloadTime = antelope.UInt32.zero;
6125
+ if (loadMass &&
6126
+ antelope.UInt32.from(loadMass).gt(antelope.UInt32.zero) &&
6127
+ ship.loaders &&
6128
+ ship.loaders.quantity.gt(antelope.UInt32.zero)) {
6129
+ const totalMass = antelope.UInt64.from(loadMass).adding(ship.loaders.mass);
6130
+ loadTime = calc_loader_flighttime(ship, totalMass).dividing(ship.loaders.quantity);
6131
+ }
6132
+ if (unloadMass &&
6133
+ antelope.UInt32.from(unloadMass).gt(antelope.UInt32.zero) &&
6134
+ ship.loaders &&
6135
+ ship.loaders.quantity.gt(antelope.UInt32.zero)) {
6136
+ const totalMass = antelope.UInt64.from(unloadMass).adding(ship.loaders.mass);
6137
+ unloadTime = calc_loader_flighttime(ship, totalMass).dividing(ship.loaders.quantity);
6138
+ }
6139
+ return {
6140
+ flightTime,
6141
+ rechargeTime,
6142
+ loadTime,
6143
+ unloadTime,
6144
+ total: flightTime.adding(rechargeTime).adding(loadTime).adding(unloadTime),
6145
+ };
6146
+ }
6147
+ function estimateDealTravelTime(ship, shipMass, distance, loadMass) {
6148
+ const needsRecharge = !hasEnergyForDistance$1(ship, distance);
6149
+ const estimate = estimateTravelTime(ship, shipMass, distance, {
6150
+ needsRecharge,
6151
+ loadMass,
6152
+ });
6153
+ return estimate.total;
6154
+ }
6155
+ function hasEnergyForDistance$1(ship, distance) {
6156
+ if (!ship.engines)
6157
+ return false;
6158
+ const energyNeeded = antelope.UInt64.from(distance).dividing(PRECISION$1).multiplying(ship.engines.drain);
6159
+ return antelope.UInt64.from(ship.energy ?? 0).gte(energyNeeded);
6160
+ }
6161
+ function getFlightOrigin(entity, flightTaskIndex) {
6162
+ if (!entity.schedule)
6163
+ return entity.coordinates;
6164
+ let origin = entity.coordinates;
6165
+ for (let i = 0; i < flightTaskIndex && i < entity.schedule.tasks.length; i++) {
6166
+ const task = entity.schedule.tasks[i];
6167
+ if (task.type.equals(exports.TaskType.TRAVEL) && task.coordinates) {
6168
+ origin = task.coordinates;
6169
+ }
6170
+ }
6171
+ return origin;
6172
+ }
6173
+ function getDestinationLocation(entity) {
6174
+ if (!entity.schedule)
6175
+ return undefined;
6176
+ for (let i = entity.schedule.tasks.length - 1; i >= 0; i--) {
6177
+ const task = entity.schedule.tasks[i];
6178
+ if (task.type.equals(exports.TaskType.TRAVEL) && task.coordinates) {
6179
+ return task.coordinates;
6180
+ }
6181
+ }
6182
+ return undefined;
6183
+ }
6184
+ function getPositionAt(entity, taskIndex, taskProgress) {
6185
+ if (!entity.schedule || entity.schedule.tasks.length === 0 || taskIndex < 0) {
6186
+ return entity.coordinates;
6187
+ }
6188
+ const task = entity.schedule.tasks[taskIndex];
6189
+ if (!task.type.equals(exports.TaskType.TRAVEL) || !task.coordinates) {
6190
+ return getFlightOrigin(entity, taskIndex);
6191
+ }
6192
+ const origin = getFlightOrigin(entity, taskIndex);
6193
+ const destination = task.coordinates;
6194
+ const interpolated = lerp(origin, destination, taskProgress);
6195
+ return {
6196
+ x: Math.round(interpolated.x),
6197
+ y: Math.round(interpolated.y),
6198
+ };
6199
+ }
6200
+ function calc_transfer_duration(source, dest, cargoMass) {
6201
+ if (cargoMass === 0) {
6202
+ return 0;
6203
+ }
6204
+ let totalThrust = 0;
6205
+ let totalLoaderMass = 0;
6206
+ let totalQuantity = 0;
6207
+ if (source.loaders) {
6208
+ const thrust = typeof source.loaders.thrust === 'number'
6209
+ ? source.loaders.thrust
6210
+ : source.loaders.thrust.toNumber();
6211
+ const mass = typeof source.loaders.mass === 'number'
6212
+ ? source.loaders.mass
6213
+ : source.loaders.mass.toNumber();
6214
+ const qty = typeof source.loaders.quantity === 'number'
6215
+ ? source.loaders.quantity
6216
+ : source.loaders.quantity.toNumber();
6217
+ totalThrust += thrust * qty;
6218
+ totalLoaderMass += mass * qty;
6219
+ totalQuantity += qty;
6220
+ }
6221
+ if (dest.loaders) {
6222
+ const thrust = typeof dest.loaders.thrust === 'number'
6223
+ ? dest.loaders.thrust
6224
+ : dest.loaders.thrust.toNumber();
6225
+ const mass = typeof dest.loaders.mass === 'number' ? dest.loaders.mass : dest.loaders.mass.toNumber();
6226
+ const qty = typeof dest.loaders.quantity === 'number'
6227
+ ? dest.loaders.quantity
6228
+ : dest.loaders.quantity.toNumber();
6229
+ totalThrust += thrust * qty;
6230
+ totalLoaderMass += mass * qty;
6231
+ totalQuantity += qty;
6232
+ }
6233
+ if (totalThrust === 0 || totalQuantity === 0) {
6234
+ return 0;
6235
+ }
6236
+ const sourceZ = typeof source.location.z === 'number'
6237
+ ? source.location.z
6238
+ : source.location.z?.toNumber() ?? 0;
6239
+ const destZ = typeof dest.location.z === 'number' ? dest.location.z : dest.location.z?.toNumber() ?? 0;
6240
+ const distance = Math.abs(sourceZ - destZ);
6241
+ const totalMass = cargoMass + totalLoaderMass;
6242
+ const acceleration = calc_acceleration(totalThrust, totalMass);
6243
+ const flightTime = 2 * Math.sqrt(distance / acceleration);
6244
+ return Math.floor(flightTime / totalQuantity);
6245
+ }
6246
+
6247
+ function capsHasMovement(caps) {
6248
+ return caps.engines !== undefined && caps.generator !== undefined;
6249
+ }
6250
+ function capsHasStorage(caps) {
6251
+ return caps.capacity !== undefined;
6252
+ }
6253
+ function capsHasLoaders(caps) {
6254
+ return caps.loaders !== undefined;
6255
+ }
6256
+ function capsHasGatherer(caps) {
6257
+ return caps.gatherer !== undefined;
6258
+ }
6259
+ function capsHasMass(caps) {
6260
+ return caps.hullmass !== undefined;
6261
+ }
6262
+
6263
+ function calcCargoItemMass(item) {
6264
+ const itemDef = getItem(item.item_id);
6265
+ let mass = antelope.UInt64.from(itemDef.mass).multiplying(item.quantity);
6266
+ for (const mod of item.modules) {
6267
+ if (mod.installed) {
6268
+ const modDef = getItem(mod.installed.item_id);
6269
+ mass = mass.adding(modDef.mass);
6270
+ }
6271
+ }
6272
+ return mass;
6273
+ }
6274
+ function calcCargoMass(entity) {
6275
+ let mass = antelope.UInt64.from(0);
6276
+ for (const item of entity.cargo) {
6277
+ mass = mass.adding(calcCargoItemMass(item));
6278
+ }
6279
+ return mass;
6280
+ }
6281
+ function calcStacksMass(stacks) {
6282
+ let mass = antelope.UInt64.from(0);
6283
+ for (const s of stacks) {
6284
+ mass = mass.adding(calcCargoItemMass(s));
6285
+ }
6286
+ return mass;
6287
+ }
6288
+ function availableCapacity$1(entity) {
6289
+ const cargoMass = calcCargoMass(entity);
6290
+ return entity.capacity.gt(cargoMass)
6291
+ ? antelope.UInt64.from(entity.capacity).subtracting(cargoMass)
6292
+ : antelope.UInt64.from(0);
6293
+ }
6294
+ function availableCapacityFromMass(capacity, cargoMass) {
6295
+ const cap = antelope.UInt64.from(capacity);
6296
+ const mass = antelope.UInt64.from(cargoMass);
6297
+ return cap.gt(mass) ? cap.subtracting(mass) : antelope.UInt64.from(0);
6298
+ }
6299
+ function hasSpace$1(entity, goodMass, quantity) {
6300
+ const additional = goodMass.multiplying(quantity);
6301
+ return availableCapacity$1(entity).gte(additional);
6302
+ }
6303
+ function hasSpaceForMass(capacity, currentMass, additionalMass) {
6304
+ return antelope.UInt64.from(currentMass).adding(additionalMass).lte(capacity);
6305
+ }
6306
+ function isFull$1(entity) {
6307
+ return antelope.UInt64.from(entity.cargomass).gte(entity.capacity);
6308
+ }
6309
+ function isFullFromMass(capacity, cargoMass) {
6310
+ return antelope.UInt64.from(cargoMass).gte(capacity);
6311
+ }
6312
+ function cargoItemToStack(item) {
6313
+ return {
6314
+ item_id: antelope.UInt16.from(item.item_id),
6315
+ quantity: antelope.UInt32.from(item.quantity),
6316
+ seed: item.seed,
6317
+ modules: item.modules ?? [],
6318
+ };
6319
+ }
6320
+ function stackToCargoItem(stack) {
6321
+ return Types.cargo_item.from({
6322
+ item_id: stack.item_id,
6323
+ quantity: stack.quantity,
6324
+ seed: stack.seed,
6325
+ modules: stack.modules,
6326
+ });
6327
+ }
6328
+ function seedEquals(a, b) {
6329
+ if (!a && !b)
6330
+ return true;
6331
+ if (!a || !b)
6332
+ return false;
6333
+ return a.equals(b);
6334
+ }
6335
+ function stackIdentityEqual(a, b) {
6336
+ return a.item_id.equals(b.item_id) && seedEquals(a.seed, b.seed);
6337
+ }
6338
+ function stackKey(s) {
6339
+ const seedVal = s.seed ? s.seed.toString() : '0';
6340
+ return `${s.item_id.toNumber()}:${seedVal}`;
6341
+ }
6342
+ function stacksEqual(a, b) {
6343
+ return stackIdentityEqual(a, b) && a.quantity.equals(b.quantity);
6344
+ }
6345
+ function mergeStacks(stacks, add) {
6346
+ const idx = stacks.findIndex((s) => stackIdentityEqual(s, add));
6347
+ if (idx === -1) {
6348
+ return [...stacks, { ...add }];
6349
+ }
6350
+ const result = stacks.slice();
6351
+ result[idx] = {
6352
+ ...result[idx],
6353
+ quantity: antelope.UInt32.from(result[idx].quantity.adding(add.quantity)),
6354
+ };
6355
+ return result;
6356
+ }
6357
+ function removeFromStacks(stacks, remove) {
6358
+ const idx = stacks.findIndex((s) => stackIdentityEqual(s, remove));
6359
+ if (idx === -1) {
6360
+ throw new Error(INSUFFICIENT_ITEM_QUANTITY);
6361
+ }
6362
+ const target = stacks[idx];
6363
+ if (target.quantity.lt(remove.quantity)) {
6364
+ throw new Error(INSUFFICIENT_ITEM_QUANTITY);
6365
+ }
6366
+ const remaining = antelope.UInt32.from(target.quantity.subtracting(remove.quantity));
6367
+ if (remaining.equals(antelope.UInt32.from(0))) {
6368
+ return [...stacks.slice(0, idx), ...stacks.slice(idx + 1)];
6369
+ }
6370
+ const result = stacks.slice();
6371
+ result[idx] = { ...target, quantity: remaining };
6372
+ return result;
6373
+ }
6374
+
6375
+ function hasSchedule$1(entity) {
6376
+ return !!entity.schedule && entity.schedule.tasks.length > 0;
6377
+ }
6378
+ function isIdle(entity) {
6379
+ return !hasSchedule$1(entity);
6380
+ }
6381
+ function getTasks(entity) {
6382
+ return entity.schedule?.tasks || [];
6383
+ }
6384
+ function scheduleDuration(entity) {
6385
+ if (!entity.schedule)
6386
+ return 0;
6387
+ return entity.schedule.tasks.reduce((sum, task) => sum + task.duration.toNumber(), 0);
6388
+ }
6389
+ function scheduleElapsed(entity, now) {
6390
+ if (!entity.schedule)
6391
+ return 0;
6392
+ const started = entity.schedule.started.toDate();
6393
+ const elapsed = Math.floor((now.getTime() - started.getTime()) / 1000);
6394
+ return Math.max(0, elapsed);
6395
+ }
6396
+ function scheduleRemaining(entity, now) {
6397
+ if (!entity.schedule)
6398
+ return 0;
6399
+ const duration = scheduleDuration(entity);
6400
+ const elapsed = scheduleElapsed(entity, now);
6401
+ return Math.max(0, duration - elapsed);
6402
+ }
6403
+ function scheduleComplete(entity, now) {
6404
+ return hasSchedule$1(entity) && scheduleRemaining(entity, now) === 0;
6405
+ }
6406
+ function currentTaskIndex(entity, now) {
6407
+ if (!entity.schedule || entity.schedule.tasks.length === 0)
6408
+ return -1;
6409
+ const elapsed = scheduleElapsed(entity, now);
6410
+ let timeAccum = 0;
6411
+ for (let i = 0; i < entity.schedule.tasks.length; i++) {
6412
+ const taskDuration = entity.schedule.tasks[i].duration.toNumber();
6413
+ if (elapsed < timeAccum + taskDuration) {
6414
+ return i;
6415
+ }
6416
+ timeAccum += taskDuration;
6417
+ }
6418
+ return entity.schedule.tasks.length - 1;
6419
+ }
6420
+ function currentTask(entity, now) {
6421
+ const index = currentTaskIndex(entity, now);
6422
+ if (index < 0 || !entity.schedule)
6423
+ return undefined;
6424
+ return entity.schedule.tasks[index];
6425
+ }
6426
+ function currentTaskType(entity, now) {
6427
+ const task = currentTask(entity, now);
6428
+ if (!task)
6429
+ return undefined;
6430
+ return task.type.toNumber();
6431
+ }
6432
+ function getTaskStartTime(entity, index) {
6433
+ if (!entity.schedule || index < 0 || index >= entity.schedule.tasks.length)
6434
+ return 0;
6435
+ let timeAccum = 0;
6436
+ for (let i = 0; i < index; i++) {
6437
+ timeAccum += entity.schedule.tasks[i].duration.toNumber();
6438
+ }
6439
+ return timeAccum;
6440
+ }
6441
+ function getTaskElapsed(entity, index, now) {
6442
+ if (!entity.schedule || index < 0 || index >= entity.schedule.tasks.length)
6443
+ return 0;
6444
+ const elapsed = scheduleElapsed(entity, now);
6445
+ const taskStart = getTaskStartTime(entity, index);
6446
+ const taskDuration = entity.schedule.tasks[index].duration.toNumber();
6447
+ if (elapsed <= taskStart)
6448
+ return 0;
6449
+ const elapsedInTask = elapsed - taskStart;
6450
+ return Math.min(elapsedInTask, taskDuration);
6451
+ }
6452
+ function getTaskRemaining(entity, index, now) {
6453
+ if (!entity.schedule || index < 0 || index >= entity.schedule.tasks.length)
6454
+ return 0;
6455
+ const taskDuration = entity.schedule.tasks[index].duration.toNumber();
6456
+ const taskElapsed = getTaskElapsed(entity, index, now);
6457
+ return Math.max(0, taskDuration - taskElapsed);
6458
+ }
6459
+ function isTaskComplete(entity, index, now) {
6460
+ if (!entity.schedule || index < 0 || index >= entity.schedule.tasks.length)
6461
+ return false;
6462
+ const taskDuration = entity.schedule.tasks[index].duration.toNumber();
6463
+ const taskElapsed = getTaskElapsed(entity, index, now);
6464
+ return taskElapsed >= taskDuration;
6465
+ }
6466
+ function isTaskInProgress(entity, index, now) {
6467
+ if (!entity.schedule || index < 0 || index >= entity.schedule.tasks.length)
6468
+ return false;
6469
+ const taskElapsed = getTaskElapsed(entity, index, now);
6470
+ const taskDuration = entity.schedule.tasks[index].duration.toNumber();
6471
+ return taskElapsed > 0 && taskElapsed < taskDuration;
6472
+ }
6473
+ function currentTaskProgress(entity, now) {
6474
+ const task = currentTask(entity, now);
6475
+ if (!task)
6476
+ return 0;
6477
+ const index = currentTaskIndex(entity, now);
6478
+ const elapsed = getTaskElapsed(entity, index, now);
6479
+ const duration = task.duration.toNumber();
6480
+ if (duration === 0)
6481
+ return 1;
6482
+ return Math.min(1, elapsed / duration);
6483
+ }
6484
+ function scheduleProgress(entity, now) {
6485
+ const duration = scheduleDuration(entity);
6486
+ if (duration === 0)
6487
+ return hasSchedule$1(entity) ? 1 : 0;
6488
+ const elapsed = scheduleElapsed(entity, now);
6489
+ return Math.min(1, elapsed / duration);
6490
+ }
6491
+ function isTaskType(entity, taskType, now) {
6492
+ return currentTaskType(entity, now) === taskType;
6493
+ }
6494
+ function isInFlight(entity, now) {
6495
+ return isTaskType(entity, exports.TaskType.TRAVEL, now);
6496
+ }
6497
+ function isRecharging(entity, now) {
6498
+ return isTaskType(entity, exports.TaskType.RECHARGE, now);
6499
+ }
6500
+ function isLoading(entity, now) {
6501
+ return isTaskType(entity, exports.TaskType.LOAD, now);
6502
+ }
6503
+ function isUnloading(entity, now) {
6504
+ return isTaskType(entity, exports.TaskType.UNLOAD, now);
6505
+ }
6506
+ function isGathering(entity, now) {
6507
+ return isTaskType(entity, exports.TaskType.GATHER, now);
6508
+ }
6509
+
6510
+ var schedule = /*#__PURE__*/Object.freeze({
6511
+ __proto__: null,
6512
+ hasSchedule: hasSchedule$1,
6513
+ isIdle: isIdle,
6514
+ getTasks: getTasks,
6515
+ scheduleDuration: scheduleDuration,
6516
+ scheduleElapsed: scheduleElapsed,
6517
+ scheduleRemaining: scheduleRemaining,
6518
+ scheduleComplete: scheduleComplete,
6519
+ currentTaskIndex: currentTaskIndex,
6520
+ currentTask: currentTask,
6521
+ currentTaskType: currentTaskType,
6522
+ getTaskStartTime: getTaskStartTime,
6523
+ getTaskElapsed: getTaskElapsed,
6524
+ getTaskRemaining: getTaskRemaining,
6525
+ isTaskComplete: isTaskComplete,
6526
+ isTaskInProgress: isTaskInProgress,
6527
+ currentTaskProgress: currentTaskProgress,
6528
+ scheduleProgress: scheduleProgress,
6529
+ isTaskType: isTaskType,
6530
+ isInFlight: isInFlight,
6531
+ isRecharging: isRecharging,
6532
+ isLoading: isLoading,
6533
+ isUnloading: isUnloading,
6534
+ isGathering: isGathering
6535
+ });
6536
+
6537
+ function getHullMass(entity) {
6538
+ return antelope.UInt32.from(entity.hullmass ?? 0);
6539
+ }
6540
+ function createProjectedEntity(entity) {
6541
+ const shipMass = getHullMass(entity);
6542
+ const loaders = entity.loaders;
6543
+ const engines = entity.engines;
6544
+ const generator = entity.generator;
6545
+ const hauler = entity.hauler;
6546
+ const capacity = entity.capacity;
6547
+ const cargo = entity.cargo.map(cargoItemToStack);
6548
+ const projected = {
6549
+ location: Coordinates.from(entity.coordinates),
6550
+ energy: antelope.UInt16.from(entity.energy ?? 0),
6551
+ cargo,
6552
+ shipMass,
6553
+ capacity: capacity ? antelope.UInt64.from(capacity) : undefined,
6554
+ engines,
6555
+ generator,
6556
+ hauler,
6557
+ loaders,
6558
+ get cargoMass() {
6559
+ return calcStacksMass(this.cargo);
6560
+ },
6561
+ get totalMass() {
6562
+ let mass = antelope.UInt64.from(this.shipMass).adding(this.cargoMass);
6563
+ if (this.loaders) {
6564
+ mass = mass.adding(this.loaders.mass.multiplying(this.loaders.quantity));
6565
+ }
6566
+ return mass;
6567
+ },
6568
+ hasMovement() {
6569
+ return capsHasMovement(this.capabilities());
6570
+ },
6571
+ hasStorage() {
6572
+ return capsHasStorage(this.capabilities());
6573
+ },
6574
+ hasLoaders() {
6575
+ return capsHasLoaders(this.capabilities());
6576
+ },
6577
+ capabilities() {
6578
+ return {
6579
+ hullmass: this.shipMass,
6580
+ capacity: this.capacity ? antelope.UInt32.from(this.capacity) : undefined,
6581
+ engines: this.engines,
6582
+ generator: this.generator,
6583
+ loaders: this.loaders,
6584
+ };
6585
+ },
6586
+ state() {
6587
+ return {
6588
+ owner: entity.owner ?? antelope.Name.from(''),
6589
+ location: Types.coordinates.from(this.location),
6590
+ energy: this.energy,
6591
+ cargomass: antelope.UInt32.from(this.cargoMass),
6592
+ cargo: this.cargo.map(stackToCargoItem),
6593
+ };
6594
+ },
6595
+ };
6596
+ return projected;
6597
+ }
6598
+ function applyRechargeTask(projected, _task, options) {
6599
+ if (!projected.generator)
6600
+ return;
6601
+ if (options.complete) {
6602
+ projected.energy = antelope.UInt16.from(projected.generator.capacity);
6603
+ }
6604
+ else if (options.progress !== undefined) {
6605
+ const capacity = Number(projected.generator.capacity);
6606
+ const currentEnergy = Number(projected.energy);
6607
+ const rechargeAmount = (capacity - currentEnergy) * options.progress;
6608
+ projected.energy = antelope.UInt16.from(Math.min(capacity, currentEnergy + rechargeAmount));
6609
+ }
6610
+ }
6611
+ function applyFlightTask(projected, task, options) {
6612
+ if (!task.coordinates || !projected.engines)
6613
+ return;
6614
+ const origin = projected.location;
6615
+ const destination = Coordinates.from(task.coordinates);
6616
+ const distance = distanceBetweenCoordinates(origin, task.coordinates);
6617
+ const energyUsage = distance.dividing(PRECISION$1).multiplying(projected.engines.drain);
6618
+ if (options.complete) {
6619
+ projected.energy = projected.energy.gt(energyUsage)
6620
+ ? antelope.UInt16.from(projected.energy.subtracting(energyUsage))
6621
+ : antelope.UInt16.from(0);
6622
+ projected.location = destination;
6623
+ }
6624
+ else if (options.progress !== undefined) {
6625
+ const interpolated = lerp(origin, destination, options.progress);
6626
+ projected.location = Coordinates.from({
6627
+ x: Math.round(interpolated.x),
6628
+ y: Math.round(interpolated.y),
6629
+ });
6630
+ const partialEnergy = antelope.UInt64.from(Math.floor(Number(energyUsage) * options.progress));
6631
+ projected.energy = projected.energy.gt(partialEnergy)
6632
+ ? antelope.UInt16.from(projected.energy.subtracting(partialEnergy))
6633
+ : antelope.UInt16.from(0);
6634
+ }
6635
+ }
6636
+ function addCargoItem(projected, item) {
6637
+ projected.cargo = mergeStacks(projected.cargo, cargoItemToStack(item));
6638
+ }
6639
+ function removeCargoItem(projected, item) {
6640
+ projected.cargo = removeFromStacks(projected.cargo, cargoItemToStack(item));
6641
+ }
6642
+ function applyAddCargoTask(projected, task) {
6643
+ for (const item of task.cargo) {
6644
+ addCargoItem(projected, item);
6645
+ }
6646
+ }
6647
+ function applyRemoveCargoTask(projected, task) {
6648
+ for (const item of task.cargo) {
6649
+ removeCargoItem(projected, item);
6650
+ }
6651
+ }
6652
+ function applyEnergyCost(projected, task) {
6653
+ if (!task.energy_cost)
6654
+ return;
6655
+ const energyCost = antelope.UInt16.from(task.energy_cost);
6656
+ projected.energy = projected.energy.gt(energyCost)
6657
+ ? antelope.UInt16.from(projected.energy.subtracting(energyCost))
6658
+ : antelope.UInt16.from(0);
6659
+ }
6660
+ function applyGatherTask(projected, task, options) {
6661
+ if (!options.complete)
6662
+ return;
6663
+ applyEnergyCost(projected, task);
6664
+ applyAddCargoTask(projected, task);
6665
+ }
6666
+ function applyCraftTask(projected, task) {
6667
+ applyEnergyCost(projected, task);
6668
+ if (task.cargo.length === 0)
6669
+ return;
6670
+ for (let i = 0; i < task.cargo.length - 1; i++) {
6671
+ removeCargoItem(projected, task.cargo[i]);
6672
+ }
6673
+ addCargoItem(projected, task.cargo[task.cargo.length - 1]);
6674
+ }
6675
+ function applyDeployTask(projected, task) {
6676
+ applyEnergyCost(projected, task);
6677
+ if (task.cargo.length > 0) {
6678
+ removeCargoItem(projected, task.cargo[0]);
6679
+ }
6680
+ }
6681
+ function applyTask(projected, task) {
6682
+ switch (task.type.toNumber()) {
6683
+ case exports.TaskType.RECHARGE:
6684
+ applyRechargeTask(projected, task, { complete: true });
6685
+ break;
6686
+ case exports.TaskType.TRAVEL:
6687
+ applyFlightTask(projected, task, { complete: true });
6688
+ break;
6689
+ case exports.TaskType.LOAD:
6690
+ case exports.TaskType.UNWRAP:
6691
+ applyAddCargoTask(projected, task);
6692
+ break;
6693
+ case exports.TaskType.UNLOAD:
6694
+ case exports.TaskType.WRAP:
6695
+ applyRemoveCargoTask(projected, task);
6696
+ break;
6697
+ case exports.TaskType.GATHER:
6698
+ applyGatherTask(projected, task, { complete: true });
6699
+ break;
6700
+ case exports.TaskType.CRAFT:
6701
+ applyCraftTask(projected, task);
6702
+ break;
6703
+ case exports.TaskType.DEPLOY:
6704
+ applyDeployTask(projected, task);
6705
+ break;
6706
+ }
6707
+ }
6708
+ function projectEntity(entity, options) {
6709
+ const projected = createProjectedEntity(entity);
6710
+ if (!entity.schedule || entity.schedule.tasks.length === 0)
6711
+ return projected;
6712
+ const tasks = entity.schedule.tasks;
6713
+ const taskCount = options?.upToTaskIndex !== undefined
6714
+ ? Math.max(0, Math.min(options.upToTaskIndex, tasks.length))
6715
+ : tasks.length;
6716
+ for (let i = 0; i < taskCount; i++) {
6717
+ applyTask(projected, tasks[i]);
6718
+ }
6719
+ return projected;
6720
+ }
6721
+ function validateSchedule(entity) {
6722
+ if (!entity.schedule || entity.schedule.tasks.length === 0)
6723
+ return;
6724
+ const projected = createProjectedEntity(entity);
6725
+ for (const task of entity.schedule.tasks) {
6726
+ applyTask(projected, task);
6727
+ if (projected.capacity && projected.cargoMass.gt(projected.capacity)) {
6728
+ throw new Error(ENTITY_CAPACITY_EXCEEDED);
6729
+ }
6730
+ }
6731
+ }
6732
+ function projectEntityAt(entity, now) {
6733
+ const projected = createProjectedEntity(entity);
6734
+ if (!entity.schedule || entity.schedule.tasks.length === 0) {
6735
+ return projected;
6736
+ }
6737
+ for (let i = 0; i < entity.schedule.tasks.length; i++) {
6738
+ const task = entity.schedule.tasks[i];
6739
+ const taskComplete = isTaskComplete(entity, i, now);
6740
+ const taskInProgress = isTaskInProgress(entity, i, now);
6741
+ if (!taskComplete && !taskInProgress) {
6742
+ break;
6743
+ }
6744
+ const progress = taskInProgress
6745
+ ? getTaskElapsed(entity, i, now) / task.duration.toNumber()
6746
+ : undefined;
6747
+ switch (task.type.toNumber()) {
6748
+ case exports.TaskType.RECHARGE:
6749
+ applyRechargeTask(projected, task, { complete: taskComplete, progress });
6750
+ break;
6751
+ case exports.TaskType.TRAVEL:
6752
+ applyFlightTask(projected, task, { complete: taskComplete, progress });
6753
+ break;
6754
+ case exports.TaskType.LOAD:
6755
+ case exports.TaskType.UNWRAP:
6756
+ if (taskComplete)
6757
+ applyAddCargoTask(projected, task);
6758
+ break;
6759
+ case exports.TaskType.UNLOAD:
6760
+ case exports.TaskType.WRAP:
6761
+ if (taskComplete)
6762
+ applyRemoveCargoTask(projected, task);
6763
+ break;
6764
+ case exports.TaskType.GATHER:
6765
+ if (taskComplete)
6766
+ applyGatherTask(projected, task, { complete: true });
6767
+ break;
6768
+ case exports.TaskType.CRAFT:
6769
+ if (taskComplete)
6770
+ applyCraftTask(projected, task);
6771
+ break;
6772
+ case exports.TaskType.DEPLOY:
6773
+ if (taskComplete)
6774
+ applyDeployTask(projected, task);
6775
+ break;
6776
+ }
6777
+ }
6778
+ return projected;
6779
+ }
6780
+
6781
+ class Location {
6782
+ constructor(coordinates) {
6783
+ this.coordinates = Coordinates.from(coordinates);
6784
+ }
6785
+ static from(coordinates) {
6786
+ return new Location(Coordinates.from(coordinates));
6787
+ }
6788
+ hasSystemAt(gameSeed) {
6789
+ const seed = antelope.Checksum256.from(gameSeed);
6790
+ if (this._hasSystem === undefined || !this._gameSeed?.equals(seed)) {
6791
+ this._gameSeed = seed;
6792
+ this._hasSystem = hasSystem(seed, this.coordinates);
6793
+ }
6794
+ return this._hasSystem;
6795
+ }
6796
+ getLocationTypeAt(gameSeed) {
6797
+ return getLocationType(gameSeed, this.coordinates);
6798
+ }
6799
+ isGatherableAt(gameSeed) {
6800
+ return isGatherableLocation(this.getLocationTypeAt(gameSeed));
6801
+ }
6802
+ findNearby(gameSeed, maxDistance = 20) {
6803
+ return findNearbyPlanets(antelope.Checksum256.from(gameSeed), this.coordinates, maxDistance);
6804
+ }
6805
+ equals(other) {
6806
+ const otherCoords = other instanceof Location ? other.coordinates : Coordinates.from(other);
6807
+ return this.coordinates.equals(otherCoords);
6808
+ }
6809
+ get epoch() {
6810
+ return this._epoch;
6811
+ }
6812
+ clearCache() {
6813
+ this._epoch = undefined;
6814
+ }
6815
+ }
6816
+ function toLocation(coords) {
6817
+ if (coords instanceof Location) {
6818
+ return coords;
6819
+ }
6820
+ return Location.from(coords);
6821
+ }
6822
+
6823
+ class ScheduleAccessor {
6824
+ constructor(entity) {
6825
+ this.entity = entity;
6826
+ }
6827
+ get hasSchedule() {
6828
+ return hasSchedule$1(this.entity);
6829
+ }
6830
+ get isIdle() {
6831
+ return isIdle(this.entity);
6832
+ }
6833
+ get tasks() {
6834
+ return getTasks(this.entity);
6835
+ }
6836
+ duration() {
6837
+ return scheduleDuration(this.entity);
6838
+ }
6839
+ elapsed(now) {
6840
+ return scheduleElapsed(this.entity, now);
6841
+ }
6842
+ remaining(now) {
6843
+ return scheduleRemaining(this.entity, now);
6844
+ }
6845
+ complete(now) {
6846
+ return scheduleComplete(this.entity, now);
6847
+ }
6848
+ currentTaskIndex(now) {
6849
+ return currentTaskIndex(this.entity, now);
6850
+ }
6851
+ currentTask(now) {
6852
+ return currentTask(this.entity, now);
6853
+ }
6854
+ currentTaskType(now) {
6855
+ return currentTaskType(this.entity, now);
6856
+ }
6857
+ taskStartTime(index) {
6858
+ return getTaskStartTime(this.entity, index);
6859
+ }
6860
+ taskElapsed(index, now) {
6861
+ return getTaskElapsed(this.entity, index, now);
6862
+ }
6863
+ taskRemaining(index, now) {
6864
+ return getTaskRemaining(this.entity, index, now);
6865
+ }
6866
+ taskComplete(index, now) {
6867
+ return isTaskComplete(this.entity, index, now);
6868
+ }
6869
+ taskInProgress(index, now) {
6870
+ return isTaskInProgress(this.entity, index, now);
6871
+ }
6872
+ currentTaskProgress(now) {
6873
+ return currentTaskProgress(this.entity, now);
6874
+ }
6875
+ progress(now) {
6876
+ return scheduleProgress(this.entity, now);
6877
+ }
6878
+ }
6879
+ function createScheduleAccessor(entity) {
6880
+ return new ScheduleAccessor(entity);
6881
+ }
6882
+
6883
+ class EntityInventory extends Types.cargo_item {
6884
+ get item() {
6885
+ if (!this._item) {
6886
+ this._item = getItem(this.item_id);
6887
+ }
6888
+ return this._item;
6889
+ }
6890
+ get good() {
6891
+ return this.item;
6892
+ }
6893
+ get name() {
6894
+ return this.item.name;
6895
+ }
6896
+ get unitMass() {
6897
+ return this.item.mass;
6898
+ }
6899
+ get totalMass() {
6900
+ return antelope.UInt64.from(this.unitMass).multiplying(this.quantity);
6901
+ }
6902
+ get hasCargo() {
6903
+ return antelope.UInt32.from(this.quantity).gt(antelope.UInt32.from(0));
6904
+ }
6905
+ get isEmpty() {
6906
+ return antelope.UInt32.from(this.quantity).equals(antelope.UInt32.from(0));
6907
+ }
6908
+ }
6909
+
6910
+ class InventoryAccessor {
6911
+ constructor(entity) {
6912
+ this.entity = entity;
6913
+ }
6914
+ get items() {
6915
+ if (!this._items) {
6916
+ this._items = this.entity.cargo.map((item) => new EntityInventory(item));
6917
+ }
6918
+ return this._items;
6919
+ }
6920
+ get totalMass() {
6921
+ return this.items.reduce((sum, c) => sum.adding(c.totalMass), antelope.UInt64.from(0));
6922
+ }
6923
+ forItem(goodId) {
6924
+ return this.items.find((c) => c.item_id.equals(goodId));
6925
+ }
6926
+ get sellable() {
6927
+ return this.items.filter((c) => c.hasCargo);
6928
+ }
6929
+ get hasSellable() {
6930
+ return this.items.some((c) => c.hasCargo);
6931
+ }
6932
+ get sellableCount() {
6933
+ return this.items.filter((c) => c.hasCargo).length;
6934
+ }
6935
+ }
6936
+ function createInventoryAccessor(entity) {
6937
+ return new InventoryAccessor(entity);
6938
+ }
6939
+
6940
+ function maxTravelDistance(entity) {
6941
+ return antelope.UInt32.from(entity.generator.capacity)
6942
+ .dividing(entity.engines.drain)
6943
+ .multiplying(PRECISION$1);
6944
+ }
6945
+ function calcEnergyUsage(entity, distance) {
6946
+ return distance.dividing(PRECISION$1).multiplying(entity.engines.drain);
6947
+ }
6948
+ function hasEnergyForDistance(entity, distance) {
6949
+ const usage = calcEnergyUsage(entity, distance);
6950
+ return antelope.UInt64.from(entity.energy).gte(usage);
6951
+ }
6952
+ function energyPercent(entity) {
6953
+ return (Number(entity.energy) / Number(entity.generator.capacity)) * 100;
6954
+ }
6955
+ function needsRecharge(entity) {
6956
+ return antelope.UInt64.from(entity.energy).lt(entity.generator.capacity);
6957
+ }
6958
+
6959
+ class Ship extends Types.entity_info {
6960
+ get name() {
6961
+ return this.entity_name;
6962
+ }
6963
+ get inv() {
6964
+ return (this._inv ?? (this._inv = new InventoryAccessor(this)));
6965
+ }
6966
+ get inventory() {
6967
+ return this.inv.items;
6968
+ }
6969
+ get sched() {
6970
+ return (this._sched ?? (this._sched = new ScheduleAccessor(this)));
6971
+ }
6972
+ get maxDistance() {
6973
+ if (!this.generator || !this.engines)
6974
+ return antelope.UInt32.from(0);
6975
+ return maxTravelDistance(this);
6976
+ }
6977
+ get isIdle() {
6978
+ return this.is_idle;
6979
+ }
6980
+ getFlightOrigin(flightTaskIndex) {
6981
+ return Coordinates.from(getFlightOrigin(this, flightTaskIndex));
6982
+ }
6983
+ destinationLocation() {
6984
+ const dest = getDestinationLocation(this);
6985
+ return dest ? Coordinates.from(dest) : undefined;
6986
+ }
6987
+ positionAt(now) {
6988
+ const taskIndex = this.sched.currentTaskIndex(now);
6989
+ const progress = this.sched.currentTaskProgress(now);
6990
+ return Coordinates.from(getPositionAt(this, taskIndex, progress));
6991
+ }
6992
+ isInFlight(now) {
6993
+ return isInFlight(this, now);
6994
+ }
6995
+ isRecharging(now) {
6996
+ return isRecharging(this, now);
6997
+ }
6998
+ isLoading(now) {
6999
+ return isLoading(this, now);
7000
+ }
7001
+ isUnloading(now) {
7002
+ return isUnloading(this, now);
7003
+ }
7004
+ isGathering(now) {
7005
+ return isGathering(this, now);
7006
+ }
7007
+ get hasEngines() {
7008
+ return this.engines !== undefined;
7009
+ }
7010
+ get hasGenerator() {
7011
+ return this.generator !== undefined;
7012
+ }
7013
+ get hasGatherer() {
7014
+ return this.gatherer !== undefined;
7015
+ }
7016
+ get hasWarp() {
7017
+ return this.warp !== undefined;
7018
+ }
7019
+ project() {
7020
+ return projectEntity(this);
7021
+ }
7022
+ projectAt(now) {
7023
+ return projectEntityAt(this, now);
7024
+ }
7025
+ get location() {
7026
+ return Location.from(this.coordinates);
7027
+ }
7028
+ get totalCargoMass() {
7029
+ return this.inv.totalMass;
7030
+ }
7031
+ get totalMass() {
7032
+ let mass = antelope.UInt64.from(this.hullmass ?? 0).adding(this.totalCargoMass);
7033
+ if (this.loaders) {
7034
+ mass = mass.adding(antelope.UInt64.from(this.loaders.mass).multiplying(this.loaders.quantity));
7035
+ }
7036
+ return mass;
7037
+ }
7038
+ get maxCapacity() {
7039
+ return antelope.UInt64.from(this.capacity);
7040
+ }
7041
+ hasSpace(goodMass, quantity) {
7042
+ return this.totalMass.adding(goodMass.multiplying(quantity)).lte(this.maxCapacity);
7043
+ }
7044
+ get availableCapacity() {
7045
+ return this.totalMass.gte(this.maxCapacity)
7046
+ ? antelope.UInt64.from(0)
7047
+ : this.maxCapacity.subtracting(this.totalMass);
7048
+ }
7049
+ getCargoForItem(goodId) {
7050
+ return this.inv.forItem(goodId);
7051
+ }
7052
+ get sellableCargo() {
7053
+ return this.inv.sellable;
7054
+ }
7055
+ get hasSellableCargo() {
7056
+ return this.inv.hasSellable;
7057
+ }
7058
+ get sellableGoodsCount() {
7059
+ return this.inv.sellableCount;
7060
+ }
7061
+ get isFull() {
7062
+ return this.totalMass.gte(this.maxCapacity);
7063
+ }
7064
+ get energyPercent() {
7065
+ if (!this.generator || this.energy === undefined)
7066
+ return 0;
7067
+ return energyPercent(this);
7068
+ }
7069
+ get needsRecharge() {
7070
+ if (!this.generator || this.energy === undefined)
7071
+ return false;
7072
+ return needsRecharge(this);
7073
+ }
7074
+ hasEnergyFor(distance) {
7075
+ if (!this.engines || !this.generator || this.energy === undefined)
7076
+ return false;
7077
+ return hasEnergyForDistance(this, distance);
7078
+ }
7079
+ }
7080
+
7081
+ class Warehouse extends Types.entity_info {
7082
+ get name() {
7083
+ return this.entity_name;
7084
+ }
7085
+ get inv() {
7086
+ return (this._inv ?? (this._inv = new InventoryAccessor(this)));
7087
+ }
7088
+ get inventory() {
7089
+ return this.inv.items;
7090
+ }
7091
+ get sched() {
7092
+ return (this._sched ?? (this._sched = new ScheduleAccessor(this)));
7093
+ }
7094
+ get isIdle() {
7095
+ return this.is_idle;
7096
+ }
7097
+ isLoading(now) {
7098
+ return isLoading(this, now);
7099
+ }
7100
+ isUnloading(now) {
7101
+ return isUnloading(this, now);
7102
+ }
7103
+ get location() {
7104
+ return Location.from(this.coordinates);
7105
+ }
7106
+ get totalCargoMass() {
7107
+ return this.inv.totalMass;
7108
+ }
7109
+ get maxCapacity() {
7110
+ return antelope.UInt64.from(this.capacity);
7111
+ }
7112
+ get availableCapacity() {
7113
+ const cargo = this.totalCargoMass;
7114
+ return cargo.gte(this.maxCapacity) ? antelope.UInt64.from(0) : this.maxCapacity.subtracting(cargo);
7115
+ }
7116
+ hasSpace(goodMass, quantity) {
7117
+ return this.totalCargoMass.adding(goodMass.multiplying(quantity)).lte(this.maxCapacity);
7118
+ }
7119
+ get isFull() {
7120
+ return this.totalCargoMass.gte(this.maxCapacity);
7121
+ }
7122
+ getCargoForItem(goodId) {
7123
+ return this.inv.forItem(goodId);
7124
+ }
7125
+ get orbitalAltitude() {
7126
+ return this.coordinates.z?.toNumber() || 0;
7127
+ }
7128
+ get totalMass() {
7129
+ const hull = this.hullmass ? antelope.UInt64.from(this.hullmass) : antelope.UInt64.from(0);
7130
+ return hull.adding(this.totalCargoMass);
7131
+ }
7254
7132
  }
7255
- function getComponentById(id) {
7256
- return components.find((c) => c.id === id);
7133
+
7134
+ class Container extends Types.entity_info {
7135
+ get name() {
7136
+ return this.entity_name;
7137
+ }
7138
+ get sched() {
7139
+ return (this._sched ?? (this._sched = new ScheduleAccessor(this)));
7140
+ }
7141
+ get isIdle() {
7142
+ return this.is_idle;
7143
+ }
7144
+ isLoading(now) {
7145
+ return isLoading(this, now);
7146
+ }
7147
+ isUnloading(now) {
7148
+ return isUnloading(this, now);
7149
+ }
7150
+ get location() {
7151
+ return Location.from(this.coordinates);
7152
+ }
7153
+ get totalMass() {
7154
+ return antelope.UInt64.from(this.hullmass ?? 0).adding(this.cargomass);
7155
+ }
7156
+ get maxCapacity() {
7157
+ return antelope.UInt64.from(this.capacity);
7158
+ }
7159
+ get availableCapacity() {
7160
+ const cargo = antelope.UInt64.from(this.cargomass);
7161
+ return cargo.gte(this.maxCapacity) ? antelope.UInt64.from(0) : this.maxCapacity.subtracting(cargo);
7162
+ }
7163
+ hasSpace(additionalMass) {
7164
+ return antelope.UInt64.from(this.cargomass).adding(additionalMass).lte(this.maxCapacity);
7165
+ }
7166
+ get isFull() {
7167
+ return antelope.UInt64.from(this.cargomass).gte(this.maxCapacity);
7168
+ }
7169
+ get orbitalAltitude() {
7170
+ return this.coordinates.z?.toNumber() || 0;
7171
+ }
7257
7172
  }
7258
- function getEntityRecipe(id) {
7259
- return entityRecipes.find((r) => r.id === id);
7173
+ function computeContainerCapabilities(stats) {
7174
+ const density = stats['density'] ?? 500;
7175
+ const strength = stats['strength'] ?? 500;
7176
+ const ductility = stats['ductility'] ?? 500;
7177
+ const purity = stats['purity'] ?? 500;
7178
+ const hullmass = 25000 + 75 * density;
7179
+ const statSum = strength + ductility + purity;
7180
+ const exponent = statSum / 2997;
7181
+ const capacity = Math.floor(1000000 * Math.pow(10, exponent));
7182
+ return { hullmass, capacity };
7260
7183
  }
7261
- function getEntityRecipeByItemId(itemId) {
7262
- return entityRecipes.find((r) => r.packedItemId === itemId);
7184
+ function computeContainerT2Capabilities(stats) {
7185
+ const strength = stats['strength'] ?? 0;
7186
+ const density = stats['density'] ?? 0;
7187
+ const ductility = stats['ductility'] ?? 0;
7188
+ const purity = stats['purity'] ?? 0;
7189
+ const hullmass = 20000 + 50 * density;
7190
+ const statSum = strength + ductility + purity;
7191
+ const exponent = statSum / 2500;
7192
+ const capacity = Math.floor(1500000 * Math.pow(10, exponent));
7193
+ return { hullmass, capacity };
7263
7194
  }
7264
- function getEntitySlotLayout(packedItemId) {
7265
- const recipe = getEntityRecipeByItemId(packedItemId);
7266
- return recipe?.moduleSlots ?? [];
7195
+
7196
+ class EntitiesManager extends BaseManager {
7197
+ async getEntity(type, id) {
7198
+ const result = await this.server.readonly('getentity', {
7199
+ entity_type: antelope.Name.from(type),
7200
+ entity_id: id,
7201
+ });
7202
+ const entityInfo = result;
7203
+ return this.wrapEntity(entityInfo);
7204
+ }
7205
+ async getEntities(owner, type) {
7206
+ const ownerName = this.resolveOwner(owner);
7207
+ const result = await this.server.readonly('getentities', {
7208
+ owner: ownerName,
7209
+ entity_type: type ? antelope.Name.from(type) : null,
7210
+ });
7211
+ const entities = result;
7212
+ return entities.map((entity) => this.wrapEntity(entity));
7213
+ }
7214
+ async getSummaries(owner, type) {
7215
+ const ownerName = this.resolveOwner(owner);
7216
+ const result = await this.server.readonly('getsummaries', {
7217
+ owner: ownerName,
7218
+ entity_type: type ? antelope.Name.from(type) : null,
7219
+ });
7220
+ return result;
7221
+ }
7222
+ async getShip(id) {
7223
+ return (await this.getEntity('ship', id));
7224
+ }
7225
+ async getWarehouse(id) {
7226
+ return (await this.getEntity('warehouse', id));
7227
+ }
7228
+ async getContainer(id) {
7229
+ return (await this.getEntity('container', id));
7230
+ }
7231
+ async getShips(owner) {
7232
+ return (await this.getEntities(owner, 'ship'));
7233
+ }
7234
+ async getWarehouses(owner) {
7235
+ return (await this.getEntities(owner, 'warehouse'));
7236
+ }
7237
+ async getContainers(owner) {
7238
+ return (await this.getEntities(owner, 'container'));
7239
+ }
7240
+ async getShipSummaries(owner) {
7241
+ return this.getSummaries(owner, 'ship');
7242
+ }
7243
+ async getWarehouseSummaries(owner) {
7244
+ return this.getSummaries(owner, 'warehouse');
7245
+ }
7246
+ async getContainerSummaries(owner) {
7247
+ return this.getSummaries(owner, 'container');
7248
+ }
7249
+ wrapEntity(entity) {
7250
+ if (entity.type.equals('ship')) {
7251
+ return new Ship(entity);
7252
+ }
7253
+ else if (entity.type.equals('warehouse')) {
7254
+ return new Warehouse(entity);
7255
+ }
7256
+ else {
7257
+ return new Container(entity);
7258
+ }
7259
+ }
7260
+ resolveOwner(owner) {
7261
+ if (typeof owner === 'object' && owner !== null && 'owner' in owner) {
7262
+ return owner.owner;
7263
+ }
7264
+ return antelope.Name.from(owner);
7265
+ }
7266
+ }
7267
+
7268
+ class Player extends Types.player_row {
7269
+ static fromState(state) {
7270
+ const playerRow = Types.player_row.from({
7271
+ owner: antelope.Name.from(state.owner),
7272
+ });
7273
+ return new Player(playerRow);
7274
+ }
7275
+ }
7276
+
7277
+ class PlayersManager extends BaseManager {
7278
+ async getPlayer(account) {
7279
+ const playerRow = await this.server.table('player').get(antelope.Name.from(account));
7280
+ if (!playerRow) {
7281
+ return undefined;
7282
+ }
7283
+ return new Player(playerRow);
7284
+ }
7285
+ }
7286
+
7287
+ class LocationsManager extends BaseManager {
7288
+ async hasSystem(location) {
7289
+ const game = await this.getGame();
7290
+ return hasSystem(game.config.seed, location);
7291
+ }
7292
+ async findNearbyPlanets(origin, maxDistance = 20) {
7293
+ const game = await this.getGame();
7294
+ return findNearbyPlanets(game.config.seed, origin, maxDistance);
7295
+ }
7296
+ async getLocationEntity(id) {
7297
+ const row = await this.server.table('location').get(antelope.UInt64.from(id));
7298
+ return row ?? undefined;
7299
+ }
7300
+ async getLocationEntityAt(coords) {
7301
+ const id = coordsToLocationId(coords);
7302
+ return this.getLocationEntity(id);
7303
+ }
7304
+ async getAllLocationEntities() {
7305
+ return this.server.table('location').all();
7306
+ }
7307
+ }
7308
+
7309
+ class EpochsManager extends BaseManager {
7310
+ async getCurrentHeight() {
7311
+ const game = await this.getGame();
7312
+ return getCurrentEpoch(game);
7313
+ }
7314
+ async getCurrent() {
7315
+ const game = await this.getGame();
7316
+ const epoch = await this.getCurrentHeight();
7317
+ return getEpochInfo(game, epoch);
7318
+ }
7319
+ async getByHeight(height) {
7320
+ const game = await this.getGame();
7321
+ return getEpochInfo(game, antelope.UInt64.from(height));
7322
+ }
7323
+ async getTimeRemaining() {
7324
+ const epochInfo = await this.getCurrent();
7325
+ const now = Date.now();
7326
+ const endTime = epochInfo.end.getTime();
7327
+ return Math.max(0, endTime - now);
7328
+ }
7329
+ async getProgress() {
7330
+ const epochInfo = await this.getCurrent();
7331
+ const now = Date.now();
7332
+ const startTime = epochInfo.start.getTime();
7333
+ const endTime = epochInfo.end.getTime();
7334
+ const duration = endTime - startTime;
7335
+ const elapsed = now - startTime;
7336
+ if (elapsed <= 0)
7337
+ return 0;
7338
+ if (elapsed >= duration)
7339
+ return 1;
7340
+ return elapsed / duration;
7341
+ }
7342
+ async fitsInCurrentEpoch(durationMs) {
7343
+ const remaining = await this.getTimeRemaining();
7344
+ return durationMs <= remaining;
7345
+ }
7267
7346
  }
7268
- function getAllCraftableItems() {
7269
- const items = [];
7270
- for (const comp of components) {
7271
- items.push({
7272
- type: 'component',
7273
- id: comp.id,
7274
- name: comp.name,
7275
- description: comp.description,
7276
- color: comp.color,
7347
+
7348
+ class ActionsManager extends BaseManager {
7349
+ travel(shipId, destination, recharge = true) {
7350
+ const x = antelope.Int64.from(destination.x);
7351
+ const y = antelope.Int64.from(destination.y);
7352
+ return this.server.action('travel', {
7353
+ entity_type: EntityType.SHIP,
7354
+ id: antelope.UInt64.from(shipId),
7355
+ x,
7356
+ y,
7357
+ recharge,
7277
7358
  });
7278
7359
  }
7279
- for (const entity of entityRecipes) {
7280
- items.push({
7281
- type: 'entity',
7282
- id: entity.id,
7283
- name: entity.name,
7284
- description: entity.description,
7285
- color: entity.color,
7360
+ grouptravel(entities, destination, recharge = true) {
7361
+ const entityRefs = entities.map((e) => Types.entity_ref.from({
7362
+ entity_type: e.entityType,
7363
+ entity_id: antelope.UInt64.from(e.entityId),
7364
+ }));
7365
+ const x = antelope.Int64.from(destination.x);
7366
+ const y = antelope.Int64.from(destination.y);
7367
+ return this.server.action('grouptravel', {
7368
+ entities: entityRefs,
7369
+ x,
7370
+ y,
7371
+ recharge,
7286
7372
  });
7287
7373
  }
7288
- for (const mod of moduleRecipes) {
7289
- items.push({
7290
- type: 'module',
7291
- id: mod.id,
7292
- name: mod.name,
7293
- description: mod.description,
7294
- color: mod.color,
7374
+ resolve(entityId, entityType = EntityType.SHIP) {
7375
+ return this.server.action('resolve', {
7376
+ entity_type: entityType,
7377
+ id: antelope.UInt64.from(entityId),
7378
+ });
7379
+ }
7380
+ cancel(entityId, count, entityType = EntityType.SHIP) {
7381
+ return this.server.action('cancel', {
7382
+ entity_type: entityType,
7383
+ id: antelope.UInt64.from(entityId),
7384
+ count: antelope.UInt64.from(count),
7385
+ });
7386
+ }
7387
+ recharge(shipId) {
7388
+ return this.server.action('recharge', {
7389
+ entity_type: EntityType.SHIP,
7390
+ id: antelope.UInt64.from(shipId),
7391
+ });
7392
+ }
7393
+ transfer(sourceType, sourceId, destType, destId, goodId, quantity) {
7394
+ return this.server.action('transfer', {
7395
+ source_type: sourceType,
7396
+ source_id: antelope.UInt64.from(sourceId),
7397
+ dest_type: destType,
7398
+ dest_id: antelope.UInt64.from(destId),
7399
+ item_id: antelope.UInt16.from(goodId),
7400
+ quantity: antelope.UInt32.from(quantity),
7401
+ });
7402
+ }
7403
+ foundCompany(account, name) {
7404
+ return this.platform.action('foundcompany', {
7405
+ account: antelope.Name.from(account),
7406
+ name,
7407
+ });
7408
+ }
7409
+ join(account) {
7410
+ return this.server.action('join', {
7411
+ account: antelope.Name.from(account),
7412
+ });
7413
+ }
7414
+ gather(shipId, stratum, quantity) {
7415
+ return this.server.action('gather', {
7416
+ entity_type: EntityType.SHIP,
7417
+ id: antelope.UInt64.from(shipId),
7418
+ stratum: antelope.UInt16.from(stratum),
7419
+ quantity: antelope.UInt32.from(quantity),
7420
+ });
7421
+ }
7422
+ warp(shipId, destination) {
7423
+ const x = antelope.Int64.from(destination.x);
7424
+ const y = antelope.Int64.from(destination.y);
7425
+ return this.server.action('warp', {
7426
+ entity_type: EntityType.SHIP,
7427
+ id: antelope.UInt64.from(shipId),
7428
+ x,
7429
+ y,
7430
+ });
7431
+ }
7432
+ craft(entityType, entityId, recipeId, quantity, inputs) {
7433
+ const cargoInputs = inputs.map((i) => Types.cargo_item.from(i));
7434
+ return this.server.action('craft', {
7435
+ entity_type: entityType,
7436
+ id: antelope.UInt64.from(entityId),
7437
+ recipe_id: antelope.UInt16.from(recipeId),
7438
+ quantity: antelope.UInt32.from(quantity),
7439
+ inputs: cargoInputs,
7440
+ });
7441
+ }
7442
+ blend(entityType, entityId, inputs) {
7443
+ const cargoInputs = inputs.map((i) => Types.cargo_item.from(i));
7444
+ return this.server.action('blend', {
7445
+ entity_type: entityType,
7446
+ id: antelope.UInt64.from(entityId),
7447
+ inputs: cargoInputs,
7448
+ });
7449
+ }
7450
+ deploy(entityType, entityId, packedItemId, seed, entityName) {
7451
+ return this.server.action('deploy', {
7452
+ entity_type: entityType,
7453
+ id: antelope.UInt64.from(entityId),
7454
+ packed_item_id: antelope.UInt16.from(packedItemId),
7455
+ seed: antelope.UInt64.from(seed),
7456
+ entity_name: entityName,
7457
+ });
7458
+ }
7459
+ addmodule(entityType, entityId, moduleIndex, moduleCargoId, targetCargoId = antelope.UInt64.from(0)) {
7460
+ return this.server.action('addmodule', {
7461
+ entity_type: entityType,
7462
+ entity_id: antelope.UInt64.from(entityId),
7463
+ module_index: moduleIndex,
7464
+ module_cargo_id: antelope.UInt64.from(moduleCargoId),
7465
+ target_cargo_id: antelope.UInt64.from(targetCargoId),
7466
+ });
7467
+ }
7468
+ rmmodule(entityType, entityId, moduleIndex, targetCargoId = antelope.UInt64.from(0)) {
7469
+ return this.server.action('rmmodule', {
7470
+ entity_type: entityType,
7471
+ entity_id: antelope.UInt64.from(entityId),
7472
+ module_index: moduleIndex,
7473
+ target_cargo_id: antelope.UInt64.from(targetCargoId),
7474
+ });
7475
+ }
7476
+ joinGame(account, companyName) {
7477
+ return [this.foundCompany(account, companyName), this.join(account)];
7478
+ }
7479
+ }
7480
+
7481
+ class GameContext {
7482
+ constructor(client, server, platform) {
7483
+ this.client = client;
7484
+ this.server = server;
7485
+ this.platform = platform;
7486
+ }
7487
+ get entities() {
7488
+ if (!this._entities) {
7489
+ this._entities = new EntitiesManager(this);
7490
+ }
7491
+ return this._entities;
7492
+ }
7493
+ get players() {
7494
+ if (!this._players) {
7495
+ this._players = new PlayersManager(this);
7496
+ }
7497
+ return this._players;
7498
+ }
7499
+ get locations() {
7500
+ if (!this._locations) {
7501
+ this._locations = new LocationsManager(this);
7502
+ }
7503
+ return this._locations;
7504
+ }
7505
+ get epochs() {
7506
+ if (!this._epochs) {
7507
+ this._epochs = new EpochsManager(this);
7508
+ }
7509
+ return this._epochs;
7510
+ }
7511
+ get actions() {
7512
+ if (!this._actions) {
7513
+ this._actions = new ActionsManager(this);
7514
+ }
7515
+ return this._actions;
7516
+ }
7517
+ async getGame(reload = false) {
7518
+ if (!reload && this._gameCache) {
7519
+ return this._gameCache;
7520
+ }
7521
+ const game = await this.platform.table('games').get();
7522
+ if (!game) {
7523
+ throw new Error('Game not initialized');
7524
+ }
7525
+ this._gameCache = game;
7526
+ return game;
7527
+ }
7528
+ async getState(reload = false) {
7529
+ if (!reload && this._stateCache) {
7530
+ return this._stateCache;
7531
+ }
7532
+ const state = await this.server.table('state').get();
7533
+ if (!state) {
7534
+ throw new Error('Game state not initialized');
7535
+ }
7536
+ const game = this._gameCache;
7537
+ this._stateCache = GameState.from(state, game);
7538
+ return this._stateCache;
7539
+ }
7540
+ get cachedGame() {
7541
+ return this._gameCache;
7542
+ }
7543
+ get cachedState() {
7544
+ return this._stateCache;
7545
+ }
7546
+ }
7547
+
7548
+ class Shipload {
7549
+ constructor(chain, constructorOptions) {
7550
+ const { client, platformContract, serverContract } = constructorOptions || {};
7551
+ const apiClient = client || new antelope.APIClient({ url: chain.url });
7552
+ const platform$1 = platformContract
7553
+ ? platformContract
7554
+ : new Contract$1({ client: apiClient });
7555
+ const server$1 = serverContract
7556
+ ? serverContract
7557
+ : new Contract({ client: apiClient });
7558
+ this._context = new GameContext(apiClient, server$1, platform$1);
7559
+ }
7560
+ static async load(chain, shiploadOptions) {
7561
+ let platform$1 = new Contract$1({
7562
+ client: new antelope.APIClient({ url: chain.url }),
7563
+ });
7564
+ if (shiploadOptions?.platformContractName) {
7565
+ const client = shiploadOptions.client || new antelope.APIClient({ url: chain.url });
7566
+ const contractKit = new ContractKit__default["default"]({ client });
7567
+ platform$1 = await contractKit.load(shiploadOptions.platformContractName);
7568
+ }
7569
+ let server$1 = new Contract({
7570
+ client: new antelope.APIClient({ url: chain.url }),
7571
+ });
7572
+ if (shiploadOptions?.serverContractName) {
7573
+ const client = shiploadOptions.client || new antelope.APIClient({ url: chain.url });
7574
+ const contractKit = new ContractKit__default["default"]({ client });
7575
+ server$1 = await contractKit.load(shiploadOptions.serverContractName);
7576
+ }
7577
+ return new Shipload(chain, {
7578
+ ...shiploadOptions,
7579
+ platformContract: platform$1,
7580
+ serverContract: server$1,
7295
7581
  });
7296
7582
  }
7297
- return items;
7298
- }
7299
- function getComponentsForCategory(category) {
7300
- return components.filter((c) => c.recipe.some((r) => r.category === category));
7301
- }
7302
- function getComponentsForStat(statKey) {
7303
- return components.filter((c) => c.stats.some((s) => s.key === statKey));
7304
- }
7305
-
7306
- function encodeStats(values) {
7307
- let seed = 0n;
7308
- for (let i = 0; i < values.length && i < 6; i++) {
7309
- seed |= BigInt(values[i] & 0x3ff) << BigInt(i * 10);
7310
- }
7311
- return seed;
7312
- }
7313
- function decodeStat(seed, index) {
7314
- return Number((seed >> BigInt(index * 10)) & 0x3ffn);
7315
- }
7316
- function decodeStats(seed, count) {
7317
- const stats = [];
7318
- for (let i = 0; i < count; i++) {
7319
- stats.push(decodeStat(seed, i));
7583
+ get client() {
7584
+ return this._context.client;
7320
7585
  }
7321
- return stats;
7322
- }
7323
- function mapStatsToKeys(seed, statDefs) {
7324
- const values = decodeStats(seed, statDefs.length);
7325
- const result = {};
7326
- for (let i = 0; i < statDefs.length; i++) {
7327
- result[statDefs[i].key] = values[i];
7586
+ get server() {
7587
+ return this._context.server;
7328
7588
  }
7329
- return result;
7330
- }
7331
- function decodeCraftedItemStats(itemId, seed) {
7332
- const comp = getComponentById(itemId);
7333
- if (comp)
7334
- return mapStatsToKeys(seed, comp.stats);
7335
- const entityRecipe = entityRecipes.find((r) => r.packedItemId === itemId);
7336
- if (entityRecipe)
7337
- return mapStatsToKeys(seed, entityRecipe.stats);
7338
- const moduleRecipe = moduleRecipes.find((r) => r.itemId === itemId);
7339
- if (moduleRecipe)
7340
- return mapStatsToKeys(seed, moduleRecipe.stats);
7341
- return {};
7342
- }
7343
- function blendStacks(stacks, statKey) {
7344
- let totalQty = 0;
7345
- let weightedSum = 0;
7346
- for (const stack of stacks) {
7347
- const val = stack.stats[statKey] ?? 0;
7348
- weightedSum += val * stack.quantity;
7349
- totalQty += stack.quantity;
7589
+ get platform() {
7590
+ return this._context.platform;
7350
7591
  }
7351
- if (totalQty === 0)
7352
- return 0;
7353
- return Math.floor(weightedSum / totalQty);
7354
- }
7355
- function computeComponentStats(componentId, categoryStacks) {
7356
- const comp = getComponentById(componentId);
7357
- if (!comp)
7358
- return [];
7359
- return comp.stats.map((statDef) => {
7360
- const matching = categoryStacks.find((cs) => cs.category === statDef.source);
7361
- const value = matching ? blendStacks(matching.stacks, statDef.key) : 0;
7362
- return { key: statDef.key, value: Math.max(1, Math.min(999, value)) };
7363
- });
7364
- }
7365
- function blendComponentStacks(stacks) {
7366
- if (stacks.length === 0)
7367
- return {};
7368
- const allKeys = new Set();
7369
- for (const s of stacks) {
7370
- for (const k of Object.keys(s.stats))
7371
- allKeys.add(k);
7592
+ get entities() {
7593
+ return this._context.entities;
7372
7594
  }
7373
- const result = {};
7374
- for (const key of allKeys) {
7375
- result[key] = blendStacks(stacks.map((s) => ({ quantity: s.quantity, stats: s.stats })), key);
7595
+ get players() {
7596
+ return this._context.players;
7376
7597
  }
7377
- return result;
7378
- }
7379
- function computeEntityStats(entityRecipeId, componentStacks) {
7380
- const recipe = getEntityRecipe(entityRecipeId) ?? getModuleRecipe(entityRecipeId);
7381
- if (!recipe)
7382
- return [];
7383
- const blendedByComponent = {};
7384
- for (const [compId, stacks] of Object.entries(componentStacks)) {
7385
- blendedByComponent[Number(compId)] = blendComponentStacks(stacks);
7598
+ get locations() {
7599
+ return this._context.locations;
7386
7600
  }
7387
- return recipe.stats.map((stat) => {
7388
- const blended = blendedByComponent[stat.sourceComponentId] ?? {};
7389
- const value = blended[stat.sourceStatKey] ?? 0;
7390
- return { key: stat.key, value: Math.max(1, Math.min(999, value)) };
7391
- });
7392
- }
7393
- function decodeStackStats(itemId, seed) {
7394
- if (itemId >= 10000) {
7395
- return decodeCraftedItemStats(itemId, BigInt(seed.toString()));
7601
+ get epochs() {
7602
+ return this._context.epochs;
7396
7603
  }
7397
- const raw = deriveResourceStats(BigInt(seed.toString()));
7398
- return { stat1: raw.stat1, stat2: raw.stat2, stat3: raw.stat3 };
7399
- }
7400
- const categoryItemMass = {
7401
- metal: 30000,
7402
- precious: 40000,
7403
- gas: 15000,
7404
- mineral: 22000,
7405
- organic: 15000,
7406
- };
7407
- function computeInputMass(itemId, itemType) {
7408
- if (itemType === 'component') {
7409
- const comp = getComponentById(itemId);
7410
- if (!comp)
7411
- return 0;
7412
- return comp.recipe.reduce((sum, input) => {
7413
- const mass = input.category ? categoryItemMass[input.category] ?? 0 : 0;
7414
- return sum + mass * input.quantity;
7415
- }, 0);
7604
+ get actions() {
7605
+ return this._context.actions;
7416
7606
  }
7417
- if (itemType === 'module') {
7418
- const mod = getModuleRecipe(itemId);
7419
- if (!mod)
7420
- return 0;
7421
- return mod.recipe.reduce((sum, input) => {
7422
- const comp = input.itemId ? getComponentById(input.itemId) : undefined;
7423
- return sum + (comp?.mass ?? 0) * input.quantity;
7424
- }, 0);
7607
+ async getGame(reload = false) {
7608
+ return this._context.getGame(reload);
7425
7609
  }
7426
- if (itemType === 'entity') {
7427
- const ent = getEntityRecipe(itemId);
7428
- if (!ent)
7429
- return 0;
7430
- return ent.recipe.reduce((sum, input) => {
7431
- const comp = input.itemId ? getComponentById(input.itemId) : undefined;
7432
- return sum + (comp?.mass ?? 0) * input.quantity;
7433
- }, 0);
7610
+ async getState(reload = false) {
7611
+ return this._context.getState(reload);
7434
7612
  }
7435
- return 0;
7436
7613
  }
7437
- function blendCrossGroup(sources) {
7438
- let weightedSum = 0;
7439
- let totalWeight = 0;
7440
- for (const src of sources) {
7441
- weightedSum += src.value * src.weight;
7442
- totalWeight += src.weight;
7443
- }
7444
- if (totalWeight === 0)
7445
- return 1;
7446
- const result = Math.floor(weightedSum / totalWeight);
7447
- return Math.max(1, Math.min(999, result));
7614
+
7615
+ function makeShip(state) {
7616
+ const info = {
7617
+ type: antelope.Name.from('ship'),
7618
+ id: antelope.UInt64.from(state.id),
7619
+ owner: antelope.Name.from(state.owner),
7620
+ entity_name: state.name,
7621
+ coordinates: Types.coordinates.from(state.coordinates),
7622
+ cargomass: antelope.UInt32.from(0),
7623
+ cargo: state.cargo || [],
7624
+ is_idle: !state.schedule,
7625
+ current_task_elapsed: antelope.UInt32.from(0),
7626
+ current_task_remaining: antelope.UInt32.from(0),
7627
+ pending_tasks: [],
7628
+ };
7629
+ if (state.hullmass !== undefined)
7630
+ info.hullmass = antelope.UInt32.from(state.hullmass);
7631
+ if (state.capacity !== undefined)
7632
+ info.capacity = antelope.UInt32.from(state.capacity);
7633
+ if (state.energy !== undefined)
7634
+ info.energy = antelope.UInt16.from(state.energy);
7635
+ if (state.engines)
7636
+ info.engines = state.engines;
7637
+ if (state.generator)
7638
+ info.generator = state.generator;
7639
+ if (state.loaders)
7640
+ info.loaders = state.loaders;
7641
+ if (state.schedule)
7642
+ info.schedule = state.schedule;
7643
+ const entityInfo = Types.entity_info.from(info);
7644
+ return new Ship(entityInfo);
7448
7645
  }
7449
- function blendCargoStacks(itemId, stacks) {
7450
- const decoded = stacks.map((s) => ({
7451
- quantity: s.quantity,
7452
- stats: decodeStackStats(itemId, s.seed),
7453
- }));
7454
- const allKeys = Object.keys(decoded[0]?.stats ?? {});
7455
- const blended = allKeys.map((key) => Math.max(1, Math.min(999, blendStacks(decoded, key))));
7456
- return antelope.UInt64.from(encodeStats(blended));
7646
+ function makeWarehouse(state) {
7647
+ const info = {
7648
+ type: antelope.Name.from('warehouse'),
7649
+ id: antelope.UInt64.from(state.id),
7650
+ owner: antelope.Name.from(state.owner),
7651
+ entity_name: state.name,
7652
+ coordinates: Types.coordinates.from(state.coordinates),
7653
+ capacity: antelope.UInt32.from(state.capacity),
7654
+ cargomass: antelope.UInt32.from(0),
7655
+ cargo: state.cargo || [],
7656
+ is_idle: !state.schedule,
7657
+ current_task_elapsed: antelope.UInt32.from(0),
7658
+ current_task_remaining: antelope.UInt32.from(0),
7659
+ pending_tasks: [],
7660
+ };
7661
+ if (state.hullmass !== undefined)
7662
+ info.hullmass = antelope.UInt32.from(state.hullmass);
7663
+ if (state.loaders)
7664
+ info.loaders = state.loaders;
7665
+ if (state.schedule)
7666
+ info.schedule = state.schedule;
7667
+ const entityInfo = Types.entity_info.from(info);
7668
+ return new Warehouse(entityInfo);
7669
+ }
7670
+ function makeContainer(state) {
7671
+ const entityInfo = Types.entity_info.from({
7672
+ type: antelope.Name.from('container'),
7673
+ id: antelope.UInt64.from(state.id),
7674
+ owner: antelope.Name.from(state.owner),
7675
+ entity_name: state.name,
7676
+ coordinates: Types.coordinates.from(state.coordinates),
7677
+ hullmass: antelope.UInt32.from(state.hullmass),
7678
+ capacity: antelope.UInt32.from(state.capacity),
7679
+ cargomass: antelope.UInt32.from(state.cargomass || 0),
7680
+ cargo: [],
7681
+ is_idle: !state.schedule,
7682
+ current_task_elapsed: antelope.UInt32.from(0),
7683
+ current_task_remaining: antelope.UInt32.from(0),
7684
+ pending_tasks: [],
7685
+ schedule: state.schedule,
7686
+ });
7687
+ return new Container(entityInfo);
7457
7688
  }
7458
7689
 
7459
7690
  function totalCargoMass(cargo) {
@@ -7694,7 +7925,7 @@ const categories = [
7694
7925
  {
7695
7926
  id: 'precious',
7696
7927
  name: 'Precious Metals',
7697
- label: 'Precious',
7928
+ label: 'Precious Metal',
7698
7929
  description: 'Conductive, corrosion-resistant — electronics, energy systems, precision components',
7699
7930
  color: categoryColors.precious,
7700
7931
  },
@@ -8778,6 +9009,7 @@ exports.DEPTH_THRESHOLD_T2 = DEPTH_THRESHOLD_T2;
8778
9009
  exports.DEPTH_THRESHOLD_T3 = DEPTH_THRESHOLD_T3;
8779
9010
  exports.DEPTH_THRESHOLD_T4 = DEPTH_THRESHOLD_T4;
8780
9011
  exports.DEPTH_THRESHOLD_T5 = DEPTH_THRESHOLD_T5;
9012
+ exports.ENTITY_CAPACITY_EXCEEDED = ENTITY_CAPACITY_EXCEEDED;
8781
9013
  exports.EPOCH_NON_ZERO = EPOCH_NON_ZERO;
8782
9014
  exports.EPOCH_NOT_READY = EPOCH_NOT_READY;
8783
9015
  exports.ERROR_SYSTEM_ALREADY_INITIALIZED = ERROR_SYSTEM_ALREADY_INITIALIZED;
@@ -8857,8 +9089,13 @@ exports.PRECISION = PRECISION$1;
8857
9089
  exports.PlatformContract = platform;
8858
9090
  exports.Player = Player;
8859
9091
  exports.PlayersManager = PlayersManager;
9092
+ exports.RECIPE_INPUTS_EXCESS = RECIPE_INPUTS_EXCESS;
9093
+ exports.RECIPE_INPUTS_INSUFFICIENT = RECIPE_INPUTS_INSUFFICIENT;
9094
+ exports.RECIPE_INPUTS_INVALID = RECIPE_INPUTS_INVALID;
9095
+ exports.RECIPE_INPUTS_MIXED = RECIPE_INPUTS_MIXED;
8860
9096
  exports.REQUIRES_MORE_THAN_ONE = REQUIRES_MORE_THAN_ONE;
8861
9097
  exports.REQUIRES_POSITIVE_VALUE = REQUIRES_POSITIVE_VALUE;
9098
+ exports.RESERVE_TIERS = RESERVE_TIERS;
8862
9099
  exports.SHIP_ALREADY_THERE = SHIP_ALREADY_THERE;
8863
9100
  exports.SHIP_ALREADY_TRAVELING = SHIP_ALREADY_TRAVELING;
8864
9101
  exports.SHIP_CANNOT_BUY_TRAVELING = SHIP_CANNOT_BUY_TRAVELING;
@@ -8881,6 +9118,7 @@ exports.ScheduleAccessor = ScheduleAccessor;
8881
9118
  exports.ServerContract = server;
8882
9119
  exports.Ship = Ship;
8883
9120
  exports.Shipload = Shipload;
9121
+ exports.TIER_ROLL_MAX = TIER_ROLL_MAX;
8884
9122
  exports.TRAVEL_MAX_DURATION = TRAVEL_MAX_DURATION;
8885
9123
  exports.WAREHOUSE_ALREADY_AT_LOCATION = WAREHOUSE_ALREADY_AT_LOCATION;
8886
9124
  exports.WAREHOUSE_CAPACITY_EXCEEDED = WAREHOUSE_CAPACITY_EXCEEDED;
@@ -8898,6 +9136,7 @@ exports.calcCargoItemMass = calcCargoItemMass;
8898
9136
  exports.calcCargoMass = calcCargoMass;
8899
9137
  exports.calcEnergyUsage = calcEnergyUsage;
8900
9138
  exports.calcLoadDuration = calcLoadDuration;
9139
+ exports.calcStacksMass = calcStacksMass;
8901
9140
  exports.calc_acceleration = calc_acceleration;
8902
9141
  exports.calc_craft_duration = calc_craft_duration;
8903
9142
  exports.calc_craft_energy = calc_craft_energy;
@@ -8927,6 +9166,7 @@ exports.capsHasLoaders = capsHasLoaders;
8927
9166
  exports.capsHasMass = capsHasMass;
8928
9167
  exports.capsHasMovement = capsHasMovement;
8929
9168
  exports.capsHasStorage = capsHasStorage;
9169
+ exports.cargoItemToStack = cargoItemToStack;
8930
9170
  exports.cargoUtils = cargoUtils;
8931
9171
  exports.categoryColors = categoryColors;
8932
9172
  exports.categoryIcons = categoryIcons;
@@ -8939,6 +9179,7 @@ exports.computeBaseHullmass = computeBaseHullmass;
8939
9179
  exports.computeComponentStats = computeComponentStats;
8940
9180
  exports.computeContainerCapabilities = computeContainerCapabilities;
8941
9181
  exports.computeContainerT2Capabilities = computeContainerT2Capabilities;
9182
+ exports.computeCraftedOutputSeed = computeCraftedOutputSeed;
8942
9183
  exports.computeCrafterDrain = computeCrafterDrain;
8943
9184
  exports.computeCrafterSpeed = computeCrafterSpeed;
8944
9185
  exports.computeEngineCapabilities = computeEngineCapabilities;
@@ -8973,7 +9214,6 @@ exports.decodeCraftedItemStats = decodeCraftedItemStats;
8973
9214
  exports.decodeStat = decodeStat;
8974
9215
  exports.decodeStats = decodeStats;
8975
9216
  exports["default"] = Shipload;
8976
- exports.depthScaleFactor = depthScaleFactor;
8977
9217
  exports.deriveLocation = deriveLocation;
8978
9218
  exports.deriveLocationEpoch = deriveLocationEpoch;
8979
9219
  exports.deriveLocationSize = deriveLocationSize;
@@ -9059,6 +9299,7 @@ exports.makeContainer = makeContainer;
9059
9299
  exports.makeShip = makeShip;
9060
9300
  exports.makeWarehouse = makeWarehouse;
9061
9301
  exports.maxTravelDistance = maxTravelDistance;
9302
+ exports.mergeStacks = mergeStacks;
9062
9303
  exports.moduleAccepts = moduleAccepts;
9063
9304
  exports.moduleDisplayName = moduleDisplayName;
9064
9305
  exports.moduleIcon = moduleIcon;
@@ -9067,11 +9308,18 @@ exports.needsRecharge = needsRecharge;
9067
9308
  exports.projectEntity = projectEntity;
9068
9309
  exports.projectEntityAt = projectEntityAt;
9069
9310
  exports.readCommonBase = readCommonBase;
9311
+ exports.removeFromStacks = removeFromStacks;
9070
9312
  exports.resolveItem = resolveItem;
9071
9313
  exports.resolveStats = resolveStats;
9314
+ exports.rollTier = rollTier;
9315
+ exports.rollWithinTier = rollWithinTier;
9072
9316
  exports.rotation = rotation;
9073
9317
  exports.schedule = schedule;
9318
+ exports.stackKey = stackKey;
9319
+ exports.stackToCargoItem = stackToCargoItem;
9320
+ exports.stacksEqual = stacksEqual;
9074
9321
  exports.statMappings = statMappings;
9075
9322
  exports.tierColors = tierColors;
9076
9323
  exports.toLocation = toLocation;
9324
+ exports.validateSchedule = validateSchedule;
9077
9325
  //# sourceMappingURL=shipload.js.map