Skip to content

Commit

Permalink
fix: Catch several cases where data might not be fully initialized.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mirroar committed May 25, 2024
1 parent 3024c95 commit 301e3ab
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/dispatcher/resource-source/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default class FactorySource extends StructureSource<FactorySourceTask> {

getTasks(context: ResourceSourceContext) {
if (!this.room.factory) return [];
if (!this.room.factoryManager) return [];

return this.cacheEmptyTaskListFor(context.resourceType || '', 25, () => {
const options: FactorySourceTask[] = [];
Expand Down
3 changes: 3 additions & 0 deletions src/operation/remote-mining.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,9 @@ export default class RemoteMiningOperation extends Operation {
return cache.inObject(this, 'hasContainer:' + sourceLocation, 0, () => {
if (!this.memory.status[sourceLocation]) return false;

const paths = this.getPaths();
if (!paths[sourceLocation] || !paths[sourceLocation].accessible) return false;

if (!Game.rooms[this.roomName]) {
return Boolean(this.memory.status[sourceLocation].containerId);
}
Expand Down
2 changes: 2 additions & 0 deletions src/process/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ export default class ReportProcess extends Process {
* Generates report email for remote mining.
*/
generateRemoteMiningReport() {
if (!Memory.strategy.remoteHarvesting) return;

let reportText = this.generateHeading('⚒ Remote mining');

reportText += 'Remote mining in ' + Memory.strategy.remoteHarvesting.currentCount + ' rooms';
Expand Down
9 changes: 9 additions & 0 deletions src/process/strategy/intershard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,15 @@ export default class InterShardProcess extends Process {
}

failIntershardExpansion() {
if (!Memory.strategy.expand) {
Memory.strategy.expand = {
failedExpansions: [],
currentTarget: null,
pathBlocked: null,
evacuatingRoom: null,
};
}

if (!Memory.strategy.expand.failedExpansions) {
Memory.strategy.expand.failedExpansions = [];
}
Expand Down
3 changes: 2 additions & 1 deletion src/role/harvester.remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,15 @@ export default class RemoteHarvesterRole extends Role {
const workParts = creep.getActiveBodyparts(CARRY) ? creep.getActiveBodyparts(WORK) : 0;
if (workParts === 0) return false;
if (creep.store.energy < workParts) return false;
if (!creep.operation.hasContainer(creep.memory.source)) return false;

const needsRepair = _.filter(
creep.room.structuresByType[STRUCTURE_CONTAINER],
// Repair if possible so we can save on dedicated builders.
structure =>
structure.hits <= structure.hitsMax - (workParts * REPAIR_POWER)
&& creep.pos.getRangeTo(structure.pos) <= 3
&& creep.operation.getContainerPosition(creep.memory.source).isEqualTo(structure.pos),
&& creep.operation.getContainerPosition(creep.memory.source)?.isEqualTo(structure.pos),
);
if (needsRepair.length > 0) {
const result = creep.repair(needsRepair[0]);
Expand Down
2 changes: 2 additions & 0 deletions src/spawn-role/remote-mining.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ export default class RemoteMiningSpawnRole extends SpawnRole {

// Don't spawn if there is no full path.
const operation = Game.operationsByType.mining['mine:' + roomName];
if (!operation) return;

const paths = operation.getPaths();
const travelTime = _.min(_.map(paths, path => path.travelTime ?? 500));
if (!travelTime) return;
Expand Down

0 comments on commit 301e3ab

Please sign in to comment.