hehehe
This commit is contained in:
parent
16bde0b87d
commit
b54f36c0e8
19 changed files with 1768 additions and 422 deletions
|
|
@ -1,7 +1,8 @@
|
|||
import { STARTING_CASH, TURN_SECONDS, FARM_SHUTDOWN_GRACE_SECONDS, BUILD_COSTS, FACILITY_DEFS, GRID, EGG_SPAWN_RANGES } from './config.js';
|
||||
import { BALANCE } from './balance.js';
|
||||
import { createRunSeed, generateBlockedCells } from './mapGen.js';
|
||||
import { randomBetween, key, inGrid } from './utils.js';
|
||||
import { resetOwnedCells } from './gridExpansion.js';
|
||||
import { randomBetween, key, inGrid, directionNameBetweenCells } from './utils.js';
|
||||
|
||||
export function newTurnStats() {
|
||||
return {
|
||||
|
|
@ -96,6 +97,12 @@ export function createGame() {
|
|||
lastTimestamp: 0,
|
||||
nextId: 10,
|
||||
runSeed: createRunSeed(),
|
||||
gridCols: BALANCE.grid.cols,
|
||||
gridRows: BALANCE.grid.rows,
|
||||
gridExpansionPurchases: 0,
|
||||
gridExpansionPurchasesByDirection: { right: 0, up: 0 },
|
||||
gridChunkOriginY: 0,
|
||||
ownedCells: new Set(),
|
||||
blockedCells: new Set(),
|
||||
buildTool: null,
|
||||
buildSession: 0,
|
||||
|
|
@ -106,7 +113,7 @@ export function createGame() {
|
|||
selectionBox: null,
|
||||
groupDrag: null,
|
||||
pan: null,
|
||||
view: { x: 0, y: 0 },
|
||||
view: { x: 0, y: 0, scale: 1 },
|
||||
hover: null,
|
||||
chicks: [],
|
||||
effects: [],
|
||||
|
|
@ -128,12 +135,12 @@ export function createGame() {
|
|||
lastExplodedComponent: new Map(),
|
||||
contractOffer: null,
|
||||
contractActive: null,
|
||||
cardEffects: { bearing: 0, legalWork: 0, fairiesFlatteryNext: 0, crowdedFarming: 0, extraEggOutlet: 0, hatchingFeed: 0, safetyCover: 0, recyclingSubsidy: 0, chemicalWeaponSubsidy: 0, preventiveMaintenance: 0, durabilityCoating: 0, laborExploitation: 0, usedMachineActive: false, rescueLoanCharges: 0, loans: [] },
|
||||
cardEffects: { bearing: 0, legalWork: 0, fairiesFlatteryNext: 0, crowdedFarming: 0, extraEggOutlet: 0, hatchingFeed: 0, safetyCover: 0, recyclingSubsidy: 0, chemicalWeaponSubsidy: 0, preventiveMaintenance: 0, dudFilter: 0, durabilityCoating: 0, laborExploitation: 0, usedMachineActive: false, rescueLoanCharges: 0, loans: [] },
|
||||
cardDraft: { pending: false, choices: [], rerolls: 0, picksRemaining: 0 },
|
||||
cardTargetPick: null,
|
||||
manualCombo: { count: 0, lastBonus: 0 },
|
||||
pendingRepairWorkerWages: 0,
|
||||
repairman: { hiredForNextDay: false, active: false, x: GRID.x + GRID.cell * 0.5, y: GRID.y + GRID.rows * GRID.cell + 84, target: null, repairedToday: 0 },
|
||||
repairman: { hiredForNextDay: false, active: false, x: GRID.x + GRID.cell * 0.5, y: GRID.y + BALANCE.grid.rows * GRID.cell + 84, target: null, repairedToday: 0 },
|
||||
stats: newTurnStats(),
|
||||
lastResult: null,
|
||||
totals: newTotalStats()
|
||||
|
|
@ -165,34 +172,34 @@ function facilityBodyForEntry(id, entry, side) {
|
|||
|
||||
export function defaultFacilities() {
|
||||
return {
|
||||
// Machine bodies sit outside the build grid. Only these receiver cells sit on the grid edge.
|
||||
mixer: facilityBodyForEntry('mixer', { col: 0, row: 5 }, 'left'),
|
||||
trash: facilityBodyForEntry('trash', { col: 10, row: 12 }, 'bottom'),
|
||||
truck: facilityBodyForEntry('truck', { col: 17, row: 12 }, 'bottom')
|
||||
// Initial grid is 20 columns × 10 rows. Machine bodies sit outside the starter grid.
|
||||
mixer: facilityBodyForEntry('mixer', { col: 0, row: 4 }, 'left'),
|
||||
trash: facilityBodyForEntry('trash', { col: 12, row: 9 }, 'bottom'),
|
||||
truck: facilityBodyForEntry('truck', { col: 18, row: 9 }, 'bottom')
|
||||
};
|
||||
}
|
||||
|
||||
const INITIAL_CONVEYOR_BACKBONE = Object.freeze([
|
||||
// Egg Farm -> S1 top input. S1 starts lower so the farm is not pressed against it.
|
||||
[4, 1], [4, 2], [4, 3], [4, 4],
|
||||
// Egg Farm -> S1 top input. The S1/S2 rows were moved down so unrelated
|
||||
// belt streams keep at least one blank tile between side-by-side flows.
|
||||
[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [8, 2], [8, 3],
|
||||
// S1 left output -> Mixer receiver on the left grid edge.
|
||||
[3, 5], [2, 5], [1, 5], [0, 5],
|
||||
[7, 4], [6, 4], [5, 4], [4, 4], [3, 4], [2, 4], [1, 4], [0, 4],
|
||||
// S1 right output -> S2 top input.
|
||||
[5, 5], [6, 5], [7, 5], [8, 5], [9, 5], [10, 5], [11, 5],
|
||||
[11, 6], [11, 7],
|
||||
[9, 4], [10, 4], [11, 4], [12, 4], [13, 4], [14, 4], [15, 4], [15, 5], [15, 6],
|
||||
// S2 left output -> Waste Shredder receiver on bottom grid edge.
|
||||
[10, 8], [10, 9], [10, 10], [10, 11], [10, 12],
|
||||
[14, 7], [13, 7], [12, 7], [12, 8], [12, 9],
|
||||
// S2 right output -> Truck receiver on the bottom grid edge.
|
||||
[12, 8], [13, 8], [14, 8], [15, 8], [16, 8], [17, 8], [17, 9], [17, 10], [17, 11], [17, 12]
|
||||
[16, 7], [17, 7], [18, 7], [18, 8], [18, 9]
|
||||
]);
|
||||
|
||||
const INITIAL_SCANNERS = Object.freeze([
|
||||
{ type: 'scanner', id: 1, kind: 'manual', slot: 0, role: 0, col: 4, row: 5, level: 1, queue: [], cooldown: 0, price: BUILD_COSTS.manualScanner, builtSession: null, autoMode: 'standard', keys: { left: { key: 'a', code: 'KeyA', label: 'A' }, right: { key: 'd', code: 'KeyD', label: 'D' } } },
|
||||
{ type: 'scanner', id: 2, kind: 'manual', slot: 1, role: 1, col: 11, row: 8, level: 1, queue: [], cooldown: 0, price: BUILD_COSTS.manualScanner, builtSession: null, autoMode: 'standard', keys: { left: { key: 'arrowleft', code: 'ArrowLeft', label: 'Left' }, right: { key: 'arrowright', code: 'ArrowRight', label: 'Right' } } }
|
||||
{ type: 'scanner', id: 1, kind: 'manual', slot: 0, role: 0, col: 8, row: 4, level: 1, queue: [], cooldown: 0, price: BUILD_COSTS.manualScanner, builtSession: null, autoMode: 'standard', keys: { left: { key: 'a', code: 'KeyA', label: 'A' }, right: { key: 'd', code: 'KeyD', label: 'D' } } },
|
||||
{ type: 'scanner', id: 2, kind: 'manual', slot: 1, role: 1, col: 15, row: 7, level: 1, queue: [], cooldown: 0, price: BUILD_COSTS.manualScanner, builtSession: null, autoMode: 'standard', keys: { left: { key: 'arrowleft', code: 'ArrowLeft', label: 'Left' }, right: { key: 'arrowright', code: 'ArrowRight', label: 'Right' } } }
|
||||
]);
|
||||
|
||||
const INITIAL_EGG_FARMS = Object.freeze([
|
||||
{ type: 'eggFarm', id: 1, col: 4, row: 0, level: 1, nextSpawn: 2, lastInterval: 2, spawnCounter: 0, price: BUILD_COSTS.eggFarm, builtSession: null }
|
||||
{ type: 'eggFarm', id: 1, col: 1, row: 0, level: 1, extraEggOutlet: 0, nextSpawn: 2, lastInterval: 2, spawnCounter: 0, price: BUILD_COSTS.eggFarm, builtSession: null }
|
||||
]);
|
||||
|
||||
function addConveyorTile(game, col, row, options = {}) {
|
||||
|
|
@ -205,11 +212,34 @@ function addConveyorTile(game, col, row, options = {}) {
|
|||
builtSession: null,
|
||||
uses: 0,
|
||||
durability: BALANCE.maintenance.durability.conveyor,
|
||||
maintenanceType: 'conveyor'
|
||||
maintenanceType: 'conveyor',
|
||||
dir: options.dir || null,
|
||||
outDirs: Array.isArray(options.outDirs) ? [...options.outDirs] : []
|
||||
});
|
||||
} else if (options.dir || options.outDirs) {
|
||||
const meta = game.conveyorMeta.get(k);
|
||||
if (options.dir) meta.dir = options.dir;
|
||||
if (Array.isArray(options.outDirs)) meta.outDirs = [...new Set([...(meta.outDirs || []), ...options.outDirs])];
|
||||
}
|
||||
}
|
||||
|
||||
function ensureConveyorMeta(game, col, row) {
|
||||
const k = key(col, row);
|
||||
if (!game.conveyorMeta.has(k)) addConveyorTile(game, col, row);
|
||||
return game.conveyorMeta.get(k);
|
||||
}
|
||||
|
||||
function markInitialConveyorDirection(game, from, to) {
|
||||
const dir = directionNameBetweenCells(from, to);
|
||||
if (!dir) return;
|
||||
const fromMeta = ensureConveyorMeta(game, from.col, from.row);
|
||||
fromMeta.outDirs = Array.isArray(fromMeta.outDirs) ? fromMeta.outDirs : [];
|
||||
if (!fromMeta.outDirs.includes(dir)) fromMeta.outDirs.push(dir);
|
||||
fromMeta.dir = dir;
|
||||
const toMeta = ensureConveyorMeta(game, to.col, to.row);
|
||||
if (!toMeta.dir) toMeta.dir = dir;
|
||||
}
|
||||
|
||||
function scannerPortCells(scanner) {
|
||||
return [
|
||||
{ col: scanner.col, row: scanner.row - 1 },
|
||||
|
|
@ -243,7 +273,9 @@ function protectedInitialCells(game) {
|
|||
}
|
||||
|
||||
function installInitialConveyorBackbone(game) {
|
||||
for (const [col, row] of INITIAL_CONVEYOR_BACKBONE) addConveyorTile(game, col, row);
|
||||
const cells = INITIAL_CONVEYOR_BACKBONE.map(([col, row]) => ({ col, row }));
|
||||
for (const { col, row } of cells) addConveyorTile(game, col, row);
|
||||
for (let i = 0; i < cells.length - 1; i += 1) markInitialConveyorDirection(game, cells[i], cells[i + 1]);
|
||||
}
|
||||
|
||||
function scrubBlockedCellsFromInitialBackbone(game) {
|
||||
|
|
@ -252,6 +284,21 @@ function scrubBlockedCellsFromInitialBackbone(game) {
|
|||
}
|
||||
|
||||
export function resetLayout(game) {
|
||||
GRID.x = BALANCE.grid.x;
|
||||
GRID.y = BALANCE.grid.y;
|
||||
GRID.cols = BALANCE.grid.cols;
|
||||
GRID.rows = BALANCE.grid.rows;
|
||||
game.gridCols = GRID.cols;
|
||||
game.gridRows = GRID.rows;
|
||||
resetOwnedCells(game);
|
||||
game.gridOwnedCells = game.ownedCells.size;
|
||||
if (game.repairman) {
|
||||
game.repairman.x = GRID.x + GRID.cell * 0.5;
|
||||
game.repairman.y = GRID.y + GRID.rows * GRID.cell + 84;
|
||||
game.repairman.target = null;
|
||||
game.repairman.active = false;
|
||||
game.repairman.hiredForNextDay = false;
|
||||
}
|
||||
game.conveyorTiles.clear();
|
||||
game.conveyorMeta.clear();
|
||||
game.blockedCells = new Set();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue