Files
screepCode/src/modules/util.ts

25 lines
929 B
TypeScript
Raw Normal View History

export function FindCapacity(creep: Creep): AnyStructure[] {
return creep.room.find(FIND_STRUCTURES, {
filter: (structure: StructureSpawn | StructureExtension) => {
let type = structure.structureType;
return (
(type == STRUCTURE_EXTENSION ||
type == STRUCTURE_SPAWN) &&
structure.store.getFreeCapacity(RESOURCE_ENERGY) as number > 0
)
}
})
}
export function GetSource(sourceId: Id<Source> | null): Source {
return Game.getObjectById(sourceId);
}
export function GetConstructureSet(creep: Creep, structureType: string | null = null): ConstructionSite<BuildableStructureConstant>[] {
return creep.room.find(FIND_CONSTRUCTION_SITES, {
filter: (structure: Structure) => {
if (structureType == null) return true;
return structure.structureType == structureType;
}
})
}