Add ESLint, Add worker utils

This commit is contained in:
uwap 2025-12-21 09:48:53 +01:00
parent a64f40b6cc
commit c026087af1
29 changed files with 3042 additions and 1734 deletions

View file

@ -1,29 +1,47 @@
export const buildContainers = (room: Room) => {
const controller = room.controller;
if (controller == null) {
return;
}
if (controller.level < 2) {
return;
}
const sources = room.find(FIND_SOURCES);
for (const source of sources) {
room.createConstructionSite(source.pos.x - 2, source.pos.y, STRUCTURE_CONTAINER);
room.createConstructionSite(source.pos.x + 2, source.pos.y, STRUCTURE_CONTAINER);
room.createConstructionSite(source.pos.x, source.pos.y - 2, STRUCTURE_CONTAINER);
room.createConstructionSite(source.pos.x, source.pos.y + 2, STRUCTURE_CONTAINER);
}
if (controller.level < 4) {
return;
}
const terrain = room.getTerrain();
if (terrain.get(controller.pos.x, controller.pos.y - 3) !== TERRAIN_MASK_WALL) {
room.createConstructionSite(controller.pos.x, controller.pos.y - 3, STRUCTURE_STORAGE);
} else if (terrain.get(controller.pos.x, controller.pos.y + 3) !== TERRAIN_MASK_WALL) {
room.createConstructionSite(controller.pos.x, controller.pos.y + 3, STRUCTURE_STORAGE);
} else if (terrain.get(controller.pos.x - 3, controller.pos.y) !== TERRAIN_MASK_WALL) {
room.createConstructionSite(controller.pos.x - 3, controller.pos.y, STRUCTURE_STORAGE);
} else if (terrain.get(controller.pos.x + 3, controller.pos.y) !== TERRAIN_MASK_WALL) {
room.createConstructionSite(controller.pos.x + 3, controller.pos.y, STRUCTURE_STORAGE);
}
}
const controller = room.controller;
if (controller == null) {
return;
}
if (controller.level < 2
&& room.find(FIND_MY_STRUCTURES,
{ filter: STRUCTURE_EXTENSION }).length > 1) {
return;
}
const sources = room.find(FIND_SOURCES);
for (const source of sources) {
const pos = source.pos;
room.createConstructionSite(pos.x - 1, pos.y, STRUCTURE_CONTAINER);
room.createConstructionSite(pos.x + 1, pos.y, STRUCTURE_CONTAINER);
room.createConstructionSite(pos.x, pos.y - 1, STRUCTURE_CONTAINER);
room.createConstructionSite(pos.x, pos.y + 1, STRUCTURE_CONTAINER);
room.createConstructionSite(pos.x - 1, pos.y + 1, STRUCTURE_CONTAINER);
room.createConstructionSite(pos.x + 1, pos.y - 1, STRUCTURE_CONTAINER);
room.createConstructionSite(pos.x - 1, pos.y - 1, STRUCTURE_CONTAINER);
room.createConstructionSite(pos.x + 1, pos.y + 1, STRUCTURE_CONTAINER);
}
if (controller.level < 4) {
return;
}
const terrain = room.getTerrain();
if (terrain.get(controller.pos.x, controller.pos.y - 3)
!== TERRAIN_MASK_WALL) {
room.createConstructionSite(
controller.pos.x, controller.pos.y - 3, STRUCTURE_STORAGE);
}
else if (terrain.get(controller.pos.x, controller.pos.y + 3)
!== TERRAIN_MASK_WALL) {
room.createConstructionSite(
controller.pos.x, controller.pos.y + 3, STRUCTURE_STORAGE);
}
else if (terrain.get(controller.pos.x - 3, controller.pos.y)
!== TERRAIN_MASK_WALL) {
room.createConstructionSite(
controller.pos.x - 3, controller.pos.y, STRUCTURE_STORAGE);
}
else if (terrain.get(controller.pos.x + 3, controller.pos.y)
!== TERRAIN_MASK_WALL) {
room.createConstructionSite(
controller.pos.x + 3, controller.pos.y, STRUCTURE_STORAGE);
}
};

View file

@ -1,26 +1,34 @@
const extentionsAvailable = (roomlevel: number) => {
return roomlevel > 2 ? roomlevel * 10 - 20 : (roomlevel - 1) * 5;
}
return roomlevel > 2 ? roomlevel * 10 - 20 : (roomlevel - 1) * 5;
};
export const buildExtentions = (room: Room) => {
const spawns = room.find(FIND_MY_SPAWNS);
if (spawns.length < 1) return;
const spawn = spawns[0];
const exts = extentionsAvailable(room.controller?.level ?? 0);
const terrain = room.getTerrain();
for (let x = -Math.floor(Math.sqrt(exts) / 2); x < Math.sqrt(exts) / 2; x++) {
for (let y = -Math.floor(Math.sqrt(exts) / 2); y < Math.sqrt(exts) / 2; y++) {
room.visual.circle(spawn.pos.x + x * 2, spawn.pos.y + y * 2);
if (terrain.get(spawn.pos.x + x * 2 - 1, spawn.pos.y + y * 2 - 1) !== TERRAIN_MASK_WALL) {
room.createConstructionSite(spawn.pos.x + x * 2 - 1, spawn.pos.y + y * 2 - 1, STRUCTURE_ROAD);
}
if (terrain.get(spawn.pos.x + x * 2, spawn.pos.y + y * 2 - 1) !== TERRAIN_MASK_WALL) {
room.createConstructionSite(spawn.pos.x + x * 2, spawn.pos.y + y * 2 - 1, STRUCTURE_ROAD);
}
if (terrain.get(spawn.pos.x + x * 2 - 1, spawn.pos.y + y * 2) !== TERRAIN_MASK_WALL) {
room.createConstructionSite(spawn.pos.x + x * 2 - 1, spawn.pos.y + y * 2, STRUCTURE_ROAD);
}
room.createConstructionSite(spawn.pos.x + x * 2, spawn.pos.y + y * 2, STRUCTURE_EXTENSION);
}
const spawns = room.find(FIND_MY_SPAWNS);
if (spawns.length < 1) return;
const spawn = spawns[0];
const exts = extentionsAvailable(room.controller?.level ?? 0);
const terrain = room.getTerrain();
const sqroffset = Math.sqrt(exts) / 2;
for (let x = -Math.floor(sqroffset); x < sqroffset; x++) {
for (let y = -Math.floor(sqroffset); y < sqroffset; y++) {
room.visual.circle(spawn.pos.x + x * 2, spawn.pos.y + y * 2);
if (terrain.get(spawn.pos.x + x * 2 - 1, spawn.pos.y + y * 2 - 1)
!== TERRAIN_MASK_WALL) {
room.createConstructionSite(
spawn.pos.x + x * 2 - 1, spawn.pos.y + y * 2 - 1, STRUCTURE_ROAD);
}
if (terrain.get(spawn.pos.x + x * 2, spawn.pos.y + y * 2 - 1)
!== TERRAIN_MASK_WALL) {
room.createConstructionSite(
spawn.pos.x + x * 2, spawn.pos.y + y * 2 - 1, STRUCTURE_ROAD);
}
if (terrain.get(spawn.pos.x + x * 2 - 1, spawn.pos.y + y * 2)
!== TERRAIN_MASK_WALL) {
room.createConstructionSite(
spawn.pos.x + x * 2 - 1, spawn.pos.y + y * 2, STRUCTURE_ROAD);
}
room.createConstructionSite(
spawn.pos.x + x * 2, spawn.pos.y + y * 2, STRUCTURE_EXTENSION);
}
}
}
};

View file

@ -1,24 +1,27 @@
export const buildRoads = (room: Room) => {
if ((room.controller?.level ?? 0) < 2) {
return;
}
const sources: _HasRoomPosition[] = room.find(FIND_SOURCES);
const sourcesAndSpawns = sources.concat(room.find(FIND_MY_SPAWNS));
const sourcesAndMinerals = sources.concat(room.find(FIND_MINERALS));
room.visual.clear();
for (const source of sourcesAndSpawns) {
for (const source2 of (room.controller?.level ?? 0) > 4 ? sourcesAndMinerals : sources) {
const path = source.pos.findPathTo(source2, {
ignoreCreeps: true,
ignoreRoads: true
});
for (const point of path) {
if ((point.x === source.pos.x && point.y === source.pos.y) || (point.x === source2.pos.x && point.y === source2.pos.y)) {
continue;
}
room.visual.line(point.x, point.y, point.x - point.dx, point.y - point.dy);
room.createConstructionSite(point.x, point.y, STRUCTURE_ROAD);
}
const rc = room.controller?.level ?? 0;
if (rc < 2) {
return;
}
const sources: _HasRoomPosition[] = room.find(FIND_SOURCES);
const sourcesAndSpawns = sources.concat(room.find(FIND_MY_SPAWNS));
const sourcesAndMinerals = sources.concat(room.find(FIND_MINERALS));
room.visual.clear();
for (const source of sourcesAndSpawns) {
for (const source2 of rc > 4 ? sourcesAndMinerals : sources) {
const path = source.pos.findPathTo(source2, {
ignoreCreeps: true,
ignoreRoads: true,
});
for (const point of path) {
if ((point.x === source.pos.x && point.y === source.pos.y)
|| (point.x === source2.pos.x && point.y === source2.pos.y)) {
continue;
}
room.visual.line(point.x, point.y,
point.x - point.dx, point.y - point.dy);
room.createConstructionSite(point.x, point.y, STRUCTURE_ROAD);
}
}
}
}
};