refactor 4 space indent
This commit is contained in:
parent
13d37b94f3
commit
98b97cbca6
|
|
@ -13,7 +13,8 @@
|
|||
},
|
||||
"rules": {
|
||||
"prettier/prettier": ["error",{
|
||||
"endOfLine":"auto"
|
||||
"endOfLine":"auto",
|
||||
"tabWidth":4
|
||||
}]
|
||||
},
|
||||
"plugins": [
|
||||
|
|
|
|||
|
|
@ -35,7 +35,9 @@ function upgradeController_job(creep) {
|
|||
);
|
||||
}
|
||||
} else {
|
||||
console.log(`${creep.name} failed to pickup: err ${Re_code_pickup}`);
|
||||
console.log(
|
||||
`${creep.name} failed to pickup: err ${Re_code_pickup}`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -70,7 +72,9 @@ function build_construction(creep) {
|
|||
console.log(`${creep.name} failed to build:err ${Re_code}`);
|
||||
}
|
||||
} else {
|
||||
console.log(`${creep.name} failed to pickup: err ${Re_code_pickup}`);
|
||||
console.log(
|
||||
`${creep.name} failed to pickup: err ${Re_code_pickup}`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,8 +3,10 @@ module.exports = {
|
|||
run(creep) {
|
||||
if (Game.spawns.Spawn1.store.getFreeCapacity(RESOURCE_ENERGY) === 0) {
|
||||
if (
|
||||
creep.transfer(Game.spawns.Spawn1.room.controller, RESOURCE_ENERGY) ===
|
||||
ERR_NOT_IN_RANGE
|
||||
creep.transfer(
|
||||
Game.spawns.Spawn1.room.controller,
|
||||
RESOURCE_ENERGY
|
||||
) === ERR_NOT_IN_RANGE
|
||||
) {
|
||||
creep.moveTo(Game.spawns.Spawn1.room.controller.pos);
|
||||
}
|
||||
|
|
|
|||
39
main.js
39
main.js
|
|
@ -62,11 +62,13 @@ function assign_creeps(opt) {
|
|||
const target_to_add_creep = _.filter(
|
||||
memory,
|
||||
(m) =>
|
||||
m.working_creep_names.length === _.min(working_creeps_of_target_array)
|
||||
m.working_creep_names.length ===
|
||||
_.min(working_creeps_of_target_array)
|
||||
); // 选择目前已有creep最少的,对其添加creep
|
||||
if (target_to_add_creep.length > 0) {
|
||||
target_to_add_creep[0].working_creep_names.push(creep_name); // target记录自己安排的creep
|
||||
Game.creeps[creep_name].working_target_id = target_to_add_creep[0].id; // 将target安排给creep
|
||||
Game.creeps[creep_name].working_target_id =
|
||||
target_to_add_creep[0].id; // 将target安排给creep
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -78,7 +80,8 @@ function assign_transfer(target_memory) {
|
|||
if (target_memory.length > 0) {
|
||||
const idle_transfer = _.filter(
|
||||
Game.creeps,
|
||||
(creep) => !creep.working_target_id && creep.memory.role === "transfer"
|
||||
(creep) =>
|
||||
!creep.working_target_id && creep.memory.role === "transfer"
|
||||
);
|
||||
if (idle_transfer.length > 0) {
|
||||
// 一次只安排一个creep
|
||||
|
|
@ -98,7 +101,8 @@ function assign_transfer_to_harvester() {
|
|||
// 判断有多少个picker的transfer为0
|
||||
const harvester_without_creep = _.filter(Game.creeps, function (creep) {
|
||||
return (
|
||||
!Memory.WorkingTarget[creep.name] && creep.memory.role === "harvester"
|
||||
!Memory.WorkingTarget[creep.name] &&
|
||||
creep.memory.role === "harvester"
|
||||
); // Memory.WorkingTarget中没有这个harvester目标
|
||||
});
|
||||
_.each(harvester_without_creep, function (harvester_creep) {
|
||||
|
|
@ -111,7 +115,8 @@ function assign_transfer_to_harvester() {
|
|||
const harvester_needs_creep_memory = _.filter(
|
||||
Memory.WorkingTarget,
|
||||
(memory) =>
|
||||
memory.working_creep_names.length === 0 && memory.cate === "harvester"
|
||||
memory.working_creep_names.length === 0 &&
|
||||
memory.cate === "harvester"
|
||||
); // 需要安排creep的harvester
|
||||
assign_transfer(harvester_needs_creep_memory);
|
||||
}
|
||||
|
|
@ -141,7 +146,9 @@ function createBuilderCreep() {
|
|||
function assign_transfer_to_builder() {
|
||||
// 判断有多少个builder的transfer为0
|
||||
const builder_without_creep = _.filter(Game.creeps, function (creep) {
|
||||
return !Memory.WorkingTarget[creep.name] && creep.memory.role === "builder"; // Memory.WorkingTarget中没有这个builder目标
|
||||
return (
|
||||
!Memory.WorkingTarget[creep.name] && creep.memory.role === "builder"
|
||||
); // Memory.WorkingTarget中没有这个builder目标
|
||||
});
|
||||
_.each(builder_without_creep, function (builder) {
|
||||
Memory.WorkingTarget[builder.name] = {
|
||||
|
|
@ -231,7 +238,8 @@ function assign_harvester_to_enery_source() {
|
|||
// 找到一个空闲的creep
|
||||
const available_creep_array = _.filter(
|
||||
Game.creeps,
|
||||
(creep) => !creep.working_target_id && creep.memory.role === "harvester"
|
||||
(creep) =>
|
||||
!creep.working_target_id && creep.memory.role === "harvester"
|
||||
);
|
||||
if (available_creep_array.length > 0) {
|
||||
// 每次只安排一个
|
||||
|
|
@ -249,7 +257,8 @@ function assign_builder_to_controller() {
|
|||
if (Game.spawns.Spawn1.room.find(FIND_MY_CONSTRUCTION_SITES).length > 0) {
|
||||
const working_builder = _.filter(
|
||||
Game.creeps,
|
||||
(creep) => creep.memory.role === "builder" && !creep.working_target_id
|
||||
(creep) =>
|
||||
creep.memory.role === "builder" && !creep.working_target_id
|
||||
);
|
||||
if (working_builder.length === 0) {
|
||||
// 没有可以用的builder了
|
||||
|
|
@ -286,12 +295,14 @@ function assign_builder_to_controller() {
|
|||
// 寻找creep为0的room controller
|
||||
const room_controller_need_creep_array = _.filter(
|
||||
room_controller_mem,
|
||||
(m) => m.working_creep_names.length === 0 && m.cate === "ROOM_CONTROLLER"
|
||||
(m) =>
|
||||
m.working_creep_names.length === 0 && m.cate === "ROOM_CONTROLLER"
|
||||
);
|
||||
if (room_controller_need_creep_array.length > 0) {
|
||||
const builder_creep = _.filter(
|
||||
Game.creeps,
|
||||
(creep) => !creep.working_target_id && creep.memory.role === "builder"
|
||||
(creep) =>
|
||||
!creep.working_target_id && creep.memory.role === "builder"
|
||||
);
|
||||
if (builder_creep.length > 0) {
|
||||
const opt = {
|
||||
|
|
@ -351,7 +362,8 @@ module.exports.loop = function _() {
|
|||
const constuction_key = `CONSTRUCTION_${found_construction_site.id}`;
|
||||
if (
|
||||
Memory.WorkingTarget[constuction_key] &&
|
||||
Memory.WorkingTarget[constuction_key].working_creep_names.length === 0
|
||||
Memory.WorkingTarget[constuction_key].working_creep_names.length ===
|
||||
0
|
||||
) {
|
||||
assign_builder_to_construction(found_construction_site.id);
|
||||
}
|
||||
|
|
@ -393,7 +405,10 @@ module.exports.loop = function _() {
|
|||
const transfer_number = _.filter(Game.creeps, {
|
||||
memory: { role: "transfer" },
|
||||
}).length;
|
||||
if (builder_number + harvester_number > transfer_number && !isSpawning) {
|
||||
if (
|
||||
builder_number + harvester_number > transfer_number &&
|
||||
!isSpawning
|
||||
) {
|
||||
isSpawning = true;
|
||||
createTransferCreep();
|
||||
}
|
||||
|
|
|
|||
10
task.js
10
task.js
|
|
@ -1,9 +1,5 @@
|
|||
const { memory } = require("console")
|
||||
const { memory } = require("console");
|
||||
|
||||
module.exports = {
|
||||
upgradeController(){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
upgradeController() {},
|
||||
};
|
||||
|
|
|
|||
4
test.js
4
test.js
|
|
@ -1,3 +1,3 @@
|
|||
a= undefined || {a:'a'}
|
||||
a = undefined || { a: "a" };
|
||||
|
||||
console.log(a)
|
||||
console.log(a);
|
||||
|
|
|
|||
11
transfer.js
11
transfer.js
|
|
@ -45,13 +45,17 @@ module.exports = {
|
|||
path.visualPath(creep.pos, working_target_pos);
|
||||
} else {
|
||||
// find dropped source
|
||||
const found = creep.room.lookForAt(LOOK_ENERGY, working_target_pos);
|
||||
const found = creep.room.lookForAt(
|
||||
LOOK_ENERGY,
|
||||
working_target_pos
|
||||
);
|
||||
if (found.length > 0) {
|
||||
creep.pickup(found[0]);
|
||||
}
|
||||
}
|
||||
} else if (
|
||||
creep.transfer(Game.spawns.Spawn1, RESOURCE_ENERGY) === ERR_NOT_IN_RANGE
|
||||
creep.transfer(Game.spawns.Spawn1, RESOURCE_ENERGY) ===
|
||||
ERR_NOT_IN_RANGE
|
||||
) {
|
||||
creep.moveTo(Game.spawns.Spawn1, {
|
||||
visualizePathStyle: { stroke: "#ffffff" },
|
||||
|
|
@ -71,7 +75,8 @@ module.exports = {
|
|||
creep.drop(RESOURCE_ENERGY);
|
||||
}
|
||||
} else if (
|
||||
creep.withdraw(Game.spawns.Spawn1, RESOURCE_ENERGY) === ERR_NOT_IN_RANGE
|
||||
creep.withdraw(Game.spawns.Spawn1, RESOURCE_ENERGY) ===
|
||||
ERR_NOT_IN_RANGE
|
||||
) {
|
||||
creep.moveTo(Game.spawns.Spawn1, {
|
||||
visualizePathStyle: { stroke: "#ffffff" },
|
||||
|
|
|
|||
Loading…
Reference in New Issue