screepCode/src/modules/util.ts

37 lines
1.3 KiB
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||
type == STRUCTURE_CONTAINER) &&
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;
}
})
}
export function GetConstructure(creep: Creep, structureType: string, ){
return creep.room.find(FIND_STRUCTURES, {filter:(structure: AnyStructure)=>{
return structure.structureType == structureType;
}})
}
export function GetContainer(creep: Creep): StructureContainer[]{
let target = GetConstructure(creep, STRUCTURE_CONTAINER) as StructureContainer[];
return target
}