Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] compare my branch to master #678

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ global.brain = {
global.roles = {};
global.profiler = {};

try {
global.friends = require('friends'); // eslint-disable-line global-require
} catch (e) {
global.friends = [];
}
global.friends = ["Antagonist", "ceneezer"]

global.config = {
profiler: {
Expand Down Expand Up @@ -46,8 +42,8 @@ global.config = {

info: {
signController: true,
signText: 'Fully automated open source NPC: http://tooangel.github.io/screeps/',
resignInterval: 500,
signText: 'XenoAmesss here. Nice to meat you!',
resignInterval: 5000,
},

// Due to newly introduces via global variable caching this can be removed
Expand Down Expand Up @@ -154,7 +150,7 @@ global.config = {
},

pixel: {
enabled: false,
enabled: true,
minBucketAfter: 2500,
},

Expand Down Expand Up @@ -220,7 +216,7 @@ global.config = {

myRoom: {
underAttackMinAttackTimer: 50,
leastSpawnsToRebuildStructureSpawn: 1,
leastSpawnsToRebuildStructureSpawn: 2,
},

room: {
Expand Down Expand Up @@ -345,6 +341,11 @@ global.config = {
},

maliciousNpcUsernames: ['Invader', 'Source Keeper'],
structureSpawn: {
leastStructureSpawnToDestroyStructureSpawn: 3,
otherRoomCreepComeHelpBuildStructureHelperCount: 5
},

};

try {
Expand Down
1 change: 1 addition & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ global.data.stats = global.data.stats || {
memoryFree: 0,
heapFree: 0,
};
global.maliciousNpcUsernames = ['Invader', 'Source Keeper'];

console.log(`${Game.time} Script reload - Load: ${global.load} tickLimit: ${Game.cpu.tickLimit} limit: ${Game.cpu.limit} Bucket: ${Game.cpu.bucket}`);

Expand Down
7 changes: 6 additions & 1 deletion src/prototype_room_creepbuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ Room.prototype.creepMem = function(role, targetId, targetRoom, level, base) {
*/
Room.prototype.getPriority = function(object) {
const priority = config.priorityQueue;
const target = object.routing && object.routing.targetRoom;
let target = object.routing && object.routing.targetRoom;
if (target && target.name) {
target = target.name;
}
const age = Game.time - (object.role.time || Game.time);
const ageTerm = age / CREEP_LIFE_TIME * 20;
if (target === this.name) {
Expand Down Expand Up @@ -106,6 +109,8 @@ Room.prototype.spawnCheckForCreate = function() {
creep.ttl = creep.ttl || config.creep.queueTtl;
if (this.findSpawnsNotSpawning().length === 0) {
creep.ttl--;
} else if (this.energyAvailable === this.energyCapacityAvailable) {
creep.ttl = 0;
}
return false;
};
Expand Down
28 changes: 24 additions & 4 deletions src/prototype_room_my.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,25 @@ Room.prototype.getUniversalAmount = function() {
return 1;
};

Room.prototype.getUpgraderAmount = function() {
if (!this.controller || !this.controller.my) {
return 0;
}
if (!this.storage) {
return 1;
}
if (!this.storage.my) {
return 0;
}
if (this.controller.level === 8) {
return 1;
}
if (this.storage.isLow()) {
return 1;
}
return 1 + Math.min(1, Math.floor(this.storage.store.energy / config.storage.lowValue / 20));
};

Room.prototype.handleAttackTimerWithoutHostiles = function() {
this.memory.attackTimer = Math.max(this.memory.attackTimer - 5, 0);
if (this.memory.attackTimer <= 0) {
Expand Down Expand Up @@ -565,15 +584,16 @@ Room.prototype.executeRoomHandleHostiles = function() {
};

Room.prototype.executeRoomCheckBasicCreeps = function() {
const amount = this.getUniversalAmount();
this.checkRoleToSpawn('universal', amount);
const universalAmount = this.getUniversalAmount();
this.checkRoleToSpawn('universal', universalAmount);
this.checkAndSpawnSourcer();

if (this.controller.level >= 4 && this.storage && this.storage.my) {
this.checkRoleToSpawn('storagefiller', 1, 'filler');
}
if (this.storage && this.storage.my && this.storage.store.energy > config.room.upgraderMinStorage && !this.memory.misplacedSpawn) {
this.checkRoleToSpawn('upgrader', 1, this.controller.id);
const upgraderAmount = this.getUpgraderAmount();
if (this.storage && this.storage.my && this.storage.store.energy > config.room.upgraderMinStorage && !this.memory.misplacedSpawn && upgraderAmount > 0) {
this.checkRoleToSpawn('upgrader', upgraderAmount, this.controller.id);
}
};

Expand Down
3 changes: 1 addition & 2 deletions src/role_carry.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,7 @@ roles.carry.action = function(creep) {
// End of path, can't harvest, suicide (otherwise the sourcer gets stuck)
if (!reverse && creep.body.filter((part) => part.type === WORK).length === 0) {
// creep.log('Suiciding because end of path, no energy, do not want to get in the way of the sourcer (better recycle?)');
creep.memory.killed = true;
creep.suicide();
creep.moveRandom();
}

return true;
Expand Down
23 changes: 15 additions & 8 deletions src/role_claimer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,21 @@ roles.claimer.settings = {
};

roles.claimer.action = function(creep) {
creep.creepLog('New claimer, in room, claiming');
// TODO just added the targetId to the creep, I hope it works
// const returnCodeMove = creep.moveTo(creep.room.controller.pos);
// console.log(`Move returnCode ${returnCodeMove}`);
const returnCode = creep.claimController(creep.room.controller);
if (returnCode === OK) {
creep.creepLog('New claimer, in room, claimed');
creep.suicide();
let claimerActionCompleted = creep.memory.claimerActionCompleted;
if (!claimerActionCompleted) {
creep.creepLog('New claimer, in room, claiming');
// TODO just added the targetId to the creep, I hope it works
// const returnCodeMove = creep.moveTo(creep.room.controller.pos);
// console.log(`Move returnCode ${returnCodeMove}`);
const returnCode = creep.claimController(creep.room.controller);
if (returnCode === OK) {
creep.creepLog('New claimer, in room, claimed');
creep.memory.claimerActionCompleted = claimerActionCompleted = true;
}
}
if (claimerActionCompleted) {
creep.memory.role = 'scout';
return roles.scout.action(creep);
}
return true;
};
6 changes: 3 additions & 3 deletions src/role_quester.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ roles.quester.settings = {
roles.quester.questLost = function(creep, quest, reason, value) {
creep.log(`Quest lost cs: ${value} ${JSON.stringify(quest)}`);
delete Memory.quests[creep.memory.level];
creep.suicide();
creep.memory.role = 'scout';
};

roles.quester.questWon = function(creep, quest) {
Expand All @@ -33,7 +33,7 @@ roles.quester.questWon = function(creep, quest) {
};
creep.room.terminal.send(RESOURCE_ENERGY, 100, quest.player.room, JSON.stringify(response));
delete Memory.quests[creep.memory.level];
creep.suicide();
creep.memory.role = 'scout';
};

roles.quester.handleBuildConstructionSite = function(creep, quest) {
Expand Down Expand Up @@ -67,7 +67,7 @@ roles.quester.action = function(creep) {
const quest = Memory.quests[creep.memory.level];
if (!quest) {
creep.log(`Quest ${creep.memory.level} not found, suiciding`);
creep.suicide();
creep.memory.role = 'scout';
return;
}
if (quest.quest === 'buildcs') {
Expand Down
2 changes: 1 addition & 1 deletion src/role_signer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ roles.signer.action = function(creep) {
// creep.memory.routing = creep.memory.nextTarget.routing;
// creep.memory.nextTarget = creep.memory.nextTarget.nextTarget;
// } else {
creep.suicide();
creep.memory.role = 'scout';
// }
return true;
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/role_sourcer.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function harvest(creep) {
if (returnCode === ERR_NO_BODYPART) {
creep.room.checkRoleToSpawn('defender', 2, undefined, creep.room.name);
creep.respawnMe();
creep.suicide();
creep.memory.role = 'scout';
return false;
}

Expand Down
33 changes: 26 additions & 7 deletions src/role_upgrader.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,41 @@ roles.upgrader.updateSettings = function(room) {
};
};

roles.upgrader.killPrevious = true;
roles.upgrader.killPrevious = false;
roles.upgrader.boostActions = ['upgradeController'];

roles.upgrader.action = function(creep) {
roles.upgrader.actionUpgrade = function(creep) {
creep.mySignController();
creep.spawnReplacement(1);
if (!creep.room.controller.isAboutToDowngrade()) {
if (creep.room.isUnderAttack()) {
return true;
return false;
}
if (creep.room.storage && creep.room.storage.isLow()) {
return true;
return false;
}
}

const updateResult = creep.upgradeController(creep.room.controller);
const withdrawResult = creep.withdraw(creep.room.storage, RESOURCE_ENERGY);
if (OK !== withdrawResult) {
creep.getEnergyFromStorage();
return false;
}
return updateResult === OK && withdrawResult === OK;
};

roles.upgrader.action = function(creep) {
const upgradeResult = roles.upgrader.actionUpgrade(creep);
if (upgradeResult) {
const roads = creep.pos.findInRangeStructures(FIND_STRUCTURES, 0, [STRUCTURE_ROAD])
if (roads && roads.length) {
creep.moveRandom();
}
}
return upgradeResult;
};

creep.upgradeController(creep.room.controller);
creep.withdraw(creep.room.storage, RESOURCE_ENERGY);
return true;
roles.upgrader.preMove = function(creep) {
roles.upgrader.action(creep);
};
Loading