dfstorm 1 year ago
parent
commit
f6f9007ce2
  1. 265
      m2_bootstrap.js
  2. 81
      m2_build.js
  3. 1017
      m2_config.js
  4. 145
      m2_creep_basic.js
  5. 254
      m2_creep_builder.js
  6. 71
      m2_creep_claim.js
  7. 240
      m2_creep_energy.js
  8. 143
      m2_creep_mineral.js
  9. 1268
      m2_creep_mover.js
  10. 166
      m2_creep_power.js
  11. 219
      m2_creep_trader.js
  12. 114
      m2_creep_updater.js
  13. 88
      m2_creeps_status.js
  14. 161
      m2_factory.js
  15. 57
      m2_federation.js
  16. 9
      m2_hostility.js
  17. 377
      m2_init.js
  18. 21
      m2_lab.js
  19. 117
      m2_main.js
  20. 206
      m2_market.js
  21. 350
      m2_power.js
  22. 81
      m2_prehooks.js
  23. 562
      m2_prospector.js
  24. 240
      m2_tools.js
  25. 170
      m2_tower.js
  26. 103
      m2_usages.js
  27. 6
      main.js
  28. 166
      powercreep.js

265
m2_bootstrap.js

@ -0,0 +1,265 @@
// m2_bootstrap.js
var m2_bootstrap = {
sName : 'module_bootstrap',
bLock : true,
bSpawnLock : false,
creepModels : [
{
sRole : 'boot_claimer',
iUnitLimit: 1,
rBody : [
CLAIM,CLAIM,CLAIM,CLAIM,
CLAIM,CLAIM, MOVE, MOVE,
MOVE, MOVE, MOVE, MOVE
]
},
{
sRole : 'boot_loaders',
iUnitLimit: 3,
rBody : [
WORK,WORK,WORK,WORK,WORK,
WORK,WORK,WORK,WORK,WORK,
MOVE,MOVE,MOVE,MOVE,MOVE,
WORK,WORK,MOVE,MOVE,MOVE,
CARRY,CARRY,CARRY,CARRY,CARRY,
MOVE,MOVE,MOVE,MOVE,MOVE,
CARRY,CARRY,CARRY,CARRY,CARRY,
MOVE,MOVE,MOVE,MOVE,MOVE,
CARRY,CARRY,CARRY,CARRY,CARRY,
MOVE,MOVE,MOVE,MOVE,MOVE
]
}
],
gcl : function (m2) {
if (Memory.config.oBases.length < Game.gcl.level) {
return (true);
}
},
/*
# Lauch a colony... how do I do that..
*/
fnc_claimer : function (creep, prehook, m2) {
// Claimer
if (creep.room.name == creep.memory.rPath[0]) {
// In the right room
if(creep.room.controller) {
switch (creep.claimController(creep.room.controller)) {
case ERR_NOT_IN_RANGE:
creep.moveTo(creep.room.controller);
break;
case OK:
Memory.config.oBootstrap.iStep =
Memory.config.oBootstrap.iStep + 1;
break ;
default:
//console.log(m2_bootstrap.sName + ": error with claimer " + creep.claimController(creep.room.controller));
break;
}
}
} else {
// find where I am
let iIndex = creep.memory.rPath.indexOf(creep.room.name);
if (iIndex >= 0) {
const exitDir = creep.room.findExitTo(creep.memory.rPath[iIndex - 1]);
const exit = creep.pos.findClosestByRange(exitDir);
creep.moveTo(exit);
} else {
// lost. should try to get home... hmm..
}
}
},
fnc_loaders : function (creep, prehook, m2) {
if (creep.room.name == creep.memory.rPath[0]) {
if (creep.pos.y < 2 || creep.pos.y > 46) {
creep.moveTo(new RoomPosition(25, 25, creep.room.name));
}
if (creep.pos.x < 2 || creep.pos.y > 46) {
creep.moveTo(new RoomPosition(25, 25, creep.room.name));
}
if (creep.room.controller.ticksToDowngrade < 4000) {
m2.arrModules["module_creep_updater"].fnc(creep, prehook, m2);
} else {
m2.arrModules["module_creep_builder"].fnc(creep, prehook, m2);
}
} else {
let iIndex = creep.memory.rPath.indexOf(creep.room.name);
if (iIndex >= 0) {
const exitDir = creep.room.findExitTo(creep.memory.rPath[iIndex - 1]);
const exit = creep.pos.findClosestByRange(exitDir);
creep.moveTo(exit);
}
}
},
creephook : function (creep, prehook, m2) {
if (creep.memory.role == m2_bootstrap.creepModels[0].sRole) {
m2_bootstrap.creepModels[0].iUnitLimit--;
m2_bootstrap.fnc_claimer(creep, prehook, m2);
} else if (creep.memory.role == m2_bootstrap.creepModels[1].sRole) {
m2_bootstrap.creepModels[1].iUnitLimit--;
m2_bootstrap.fnc_loaders(creep, prehook, m2);
}
},
run : function (m2) {
if (m2_bootstrap.bLock)
return false;
if (
Memory.config.oBootstrap == undefined ||
Memory.config.oBootstrap == null
) {
Memory.config.oBootstrap = {
iStep: 0,
sRoom: null,
rPath: Array(),
iX: null,
iY: null
};
}
switch (Memory.config.oBootstrap.iStep) {
case 0: // fin a new place
if (Memory.config.oRouhBase.length > 0) {
Memory.config.oBootstrap.iStep =
Memory.config.oBootstrap.iStep + 1;
} else {
if (m2_bootstrap.gcl) {
if (Memory.config.bRunProspector != true) {
Memory.config.bRunProspector = true;
}
} else {
console.log("Not enough GCL.");
}
}
break ;
case 1: // Take that new place
console.log(
"m2_bootstrap : Adding the potential base to the active base."
);
Memory.config.oBootstrap.sRoom =
Memory.config.oRouhBase[0].sRoom;
Memory.config.oBootstrap.rPath.push(Memory.config.oRouhBase[0].sRoom);
for (let iR in Memory.config.oRouhBase[0].rPath) {
Memory.config.oBootstrap.rPath.push(Memory.config.oRouhBase[0].rPath[iR]);
}
Memory.config.oBootstrap.iX = Memory.config.oRouhBase[0].iX;
Memory.config.oBootstrap.iY =
Memory.config.oRouhBase[0].iY;
Memory.config.oRouhBase =
m2.tools.spliceh(Memory.config.oRouhBase);
Memory.config.oBootstrap.iStep =
Memory.config.oBootstrap.iStep + 1;
case 2: // Send a claimer to the new place !
if (m2_bootstrap.creepModels[0].iUnitLimit > 0) {
// Get the home who found out.
let sHomeRoom = Memory.config.oBootstrap.rPath[
Memory.config.oBootstrap.rPath.length - 1
];
// Get the room spawn.
let oBase = m2.tools.getBaseInMemoryByRoom(sHomeRoom);
if (oBase && !m2_bootstrap.bSpawnLock) {
for (let iSpawn in oBase.rSpawn) {
let oSpawn = Game.spawns[oBase.rSpawn[iSpawn]];
if (!oSpawn.spawning) {
let arrBody = m2_bootstrap.creepModels[0].rBody;
let iBuildRtn = oSpawn.spawnCreep(
arrBody,
'Bootloaders_' +
Math.random().toString(36).substr(2, 9)
,
{
memory : {
hook: m2_bootstrap.sName,
iMode: 0,
role: m2_bootstrap.creepModels[0].sRole,
home: sHomeRoom,
rPath : Memory.config.oBootstrap.rPath
}
}
);
if (iBuildRtn == OK) {
console.log(m2_bootstrap.sName + "; Unit built in " + sHomeRoom);
}
break ;
}
}
}
}
break ;
case 3: // Add new base to the managed list of room (automated building).
if (
Memory.config.oBuildManaged == undefined ||
Memory.config.oBuildManaged == null
) {
Memory.config.oBuildManaged = Array();
}
Memory.config.oBuildManaged.push({
sRoom : Memory.config.oBootstrap.sRoom,
iX : Memory.config.oBootstrap.iX,
iY : Memory.config.oBootstrap.iY
});
Memory.config.oBootstrap.iStep = Memory.config.oBootstrap.iStep + 1;
break ;
case 4: // send in bootloaders until room is lvl 5
if (m2_bootstrap.creepModels[1].iUnitLimit > 0 && Game.cpu.bucket > 5000) {
// Get the home who found out.
let sHomeRoom = Memory.config.oBootstrap.rPath[
Memory.config.oBootstrap.rPath.length - 1
];
// Get the room spawn.
let oBase = m2.tools.getBaseInMemoryByRoom(sHomeRoom);
if (oBase && !m2_bootstrap.bSpawnLock) {
for (let iSpawn in oBase.rSpawn) {
let oSpawn = Game.spawns[oBase.rSpawn[iSpawn]];
if (oSpawn) {
let arrBody = m2_bootstrap.creepModels[1].rBody;
let iBuildRtn = oSpawn.spawnCreep(
arrBody,
'Bootloaders_' +
Math.random().toString(36).substr(2, 9)
,
{
memory : {
hook: m2_bootstrap.sName,
iMode: 0,
role: m2_bootstrap.creepModels[1].sRole,
home: Memory.config.oBootstrap.rPath[0],
rPath : Memory.config.oBootstrap.rPath
}
}
);
if (iBuildRtn == OK) {
console.log(m2_bootstrap.sName + "; Unit built in " + sHomeRoom);
}
break ;
}
}
}
}
if (Game.rooms[Memory.config.oBootstrap.sRoom].controller.level > 3) {
Memory.config.oBootstrap.iStep = Memory.config.oBootstrap.iStep + 1;
}
break ;
case 5:
Memory.config.oBootstrap = null;
break ;
default:
break ;
}
}
};
module.exports = m2_bootstrap;

81
m2_build.js

@ -0,0 +1,81 @@
// m2_build.js
var m2_build = {
sName: 'module_build',
isInGrid : function(m2, creep) {
for (let iBuild in Memory.config.oBuildManaged) {
if (Memory.config.oBuildManaged[iBuild].sRoom == creep.room.name) {
if(
creep.pos.x >= m2_build.getx(
Memory.config.oBuildManaged[iBuild].iX
) &&
creep.pos.x <= m2_build.getx(
Memory.config.oBuildManaged[iBuild].iX
) + 10 &&
creep.pos.y >= m2_build.gety(
Memory.config.oBuildManaged[iBuild].iY
) &&
creep.pos.y <= m2_build.gety(
Memory.config.oBuildManaged[iBuild].iY
) + 12
) {
return (true);
}
}
}
return (false);
},
drawBase : function (m2, iRoomLevel, sRoom, iXRef, iYRef) {
oBaseData = m2.config.arrBaseBuildingModels[iRoomLevel];
for (let iC in oBaseData.arrWiredFrame) {
let ifX = m2_build.getx(iXRef) + oBaseData.arrWiredFrame[iC].x;
let ifY = m2_build.gety(iYRef) + oBaseData.arrWiredFrame[iC].y;
let rFound = Game.rooms[sRoom].lookForAt(LOOK_STRUCTURES, ifX, ifY);
if (rFound.length == 0) {
rFound = Game.rooms[sRoom].lookForAt(LOOK_CONSTRUCTION_SITES, ifX, ifY);
}
if (rFound.length == 0) {
Game.rooms[sRoom].createConstructionSite(
ifX,
ifY,
oBaseData.arrWiredFrame[iC].t
);
}
}
},
getx : function (xRef) {
return (25 - 5 + xRef);
},
gety : function (yRef) {
return (25 - 6 + yRef);
},
run : function (m2) {
for (let iBuild in Memory.config.oBuildManaged) {
let iRoomLevel = -1;
iRoomLevel = Game.rooms[Memory.config.oBuildManaged[iBuild].sRoom].controller.level;
if (iRoomLevel < 0) {
iRoomLevel = 1;
}
if (Game.time % 10 === 0) {
m2_build.drawBase(
m2,
iRoomLevel,
Memory.config.oBuildManaged[iBuild].sRoom,
Memory.config.oBuildManaged[iBuild].iX,
Memory.config.oBuildManaged[iBuild].iY
);
}
}
}
};
module.exports = m2_build;

1017
m2_config.js
File diff suppressed because it is too large
View File

145
m2_creep_basic.js

@ -0,0 +1,145 @@
// m2_creep_basic
var m2_creep_basic = {
sName : 'module_creep_basic',
sRole : 'basic',
bSpawnLock : false,
arrUnitsLimits : [0,2,2,2,2,2,2,2,2],
arrBodies: [
[ null ],
[WORK, MOVE, CARRY], // lvl 1
[WORK, MOVE, CARRY], // lvl 2
[WORK, MOVE, CARRY], // lvl 3
[WORK, MOVE, CARRY], // lvl 4
[WORK, MOVE, CARRY], // lvl 5
[WORK, MOVE, CARRY], // lvl 6
[WORK, MOVE, CARRY], // lvl 7
[WORK, MOVE, CARRY], // lvl 8
[WORK, MOVE, CARRY] // lvl 9 - Powers
],
arrUnitsByRoom : Array(),
fnc : function (creep, prehook, m2) {
let oTarget = null;
let rTagets = [];
let oaction = null;
if(creep.carry.energy == 0) {
creep.memory.iMode = 0;
}
if(creep.memory.iMode == 0 && creep.carryCapacity == creep.carry.energy) {
creep.memory.fe = 0;
rTagets = creep.room.find(FIND_MY_STRUCTURES, {
filter: (structure) => {
return (
structure.structureType ==
STRUCTURE_EXTENSION ||
structure.structureType ==
STRUCTURE_SPAWN
) &&
(structure.energy < structure.energyCapacity);
}
});
if(rTagets.length > 0) {
creep.memory.targetId = rTagets[0].id;
creep.memory.iMode = 1;
} else {
rTagets = creep.room.find(FIND_MY_STRUCTURES, {
filter: (structure) => {
return (
structure.structureType
== STRUCTURE_TOWER) &&
(structure.energy <=
(structure.energyCapacity - 50));
}
});
if(rTagets.length > 0) {
creep.memory.targetId = rTagets[0].id;
creep.memory.iMode = 2;
} else {
creep.memory.iMode = 3;
}
}
}
switch (creep.memory.iMode) {
case 0:
m2.tools.findEnergy(creep);
break;
case 1:
oTarget = Game.getObjectById(creep.memory.targetId);
oaction = creep.transfer(oTarget, RESOURCE_ENERGY);
if(oaction == ERR_NOT_IN_RANGE) {
creep.moveTo(oTarget);
} else if(oaction != OK) {
creep.memory.iMode = 0;
}
case 2:
oTarget = Game.getObjectById(creep.memory.targetId);
oaction = creep.transfer(oTarget, RESOURCE_ENERGY);
if(oaction == ERR_NOT_IN_RANGE) {
creep.moveTo(oTarget);
} else if(oaction != OK) {
creep.memory.iMode = 0;
}
break ;
default:
if(
creep.upgradeController(
creep.room.controller
) == ERR_NOT_IN_RANGE
) {
creep.moveTo(creep.room.controller);
}
break ;
}
},
creephook : function (creep, prehook, m2) {
if (creep.memory.role == m2_creep_basic.sRole) {
m2_creep_basic.arrUnitsByRoom.push(creep.memory.home);
m2_creep_basic.fnc(creep, prehook, m2);
}
},
basehook : function (m2, iBase) {
let iCount = 0;
let iLimit = m2_creep_basic.arrUnitsLimits[Memory.config.oBases[iBase].iLvl];
for (let iB in m2_creep_basic.arrUnitsByRoom) {
if (m2_creep_basic.arrUnitsByRoom[iB] == Memory.config.oBases[iBase].sRoom) {
iCount++;
}
}
if (iLimit - iCount > 0 && (Memory.arrBasicStatus[iBase] || Memory.config.oBases[iBase].iLvl < 4)) {
for (let iSpawn in Memory.config.oBases[iBase].rSpawn) {
let oSpawn = Game.spawns[Memory.config.oBases[iBase].rSpawn[iSpawn]];
if (!oSpawn.spawning && !m2_creep_basic.bSpawnLock) {
let arrBody = m2_creep_basic.arrBodies[Memory.config.oBases[iBase].iLvl];
let iBuildRtn = oSpawn.spawnCreep(
arrBody,
m2_creep_basic.sRole +
'[' +
iBase +
']_' +
Math.random().toString(36).substr(2, 9)
,
{
memory : {
hook: m2_creep_basic.sName,
iMode: 0,
role: m2_creep_basic.sRole,
home: Memory.config.oBases[iBase].sRoom
}
}
);
if (iBuildRtn == OK) {
console.log("m2_creep_basic; Unit built in " + Memory.config.oBases[iBase].sRoom);
} else if(iBuildRtn == ERR_NOT_ENOUGH_ENERGY) {
console.log("m2_creep_basic; No enough energy to build creep in [" + Memory.config.oBases[iBase].sRoom + "]");
}
break ;
}
}
}
}
}
module.exports = m2_creep_basic;

254
m2_creep_builder.js

@ -0,0 +1,254 @@
// m2_creep_builder
var m2_creep_builder = {
sName: 'module_creep_builder',
sRole : 'builder',
bSpawnLock : false,
arrUnitsLimits : [0,2,2,2,1,1,1,1,1],
arrBodies: [
[],
[
WORK, MOVE, CARRY,
],
[ // lvl 2 (550 Max)
WORK, WORK, WORK,
MOVE, MOVE, MOVE,
CARRY, CARRY
], // lvl 3 (800 Max)
[ WORK, WORK, WORK, WORK, WORK,
MOVE, MOVE, MOVE, MOVE,
CARRY, CARRY
],
[ // lvl 4 (1300 Max)
WORK, WORK, WORK, WORK, WORK, WORK,
MOVE, MOVE, MOVE, MOVE, MOVE,
CARRY, CARRY, CARRY
],
[ // lvl 5 (1800 Max)
WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,
MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,
CARRY,CARRY,CARRY,CARRY,CARRY,CARRY
],
[ // lvl 6 (2300 max)
WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,
MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,
CARRY,CARRY,CARRY,CARRY,CARRY,CARRY
],
[ // lvl 7 (5600 max)
WORK,WORK,WORK,WORK,WORK,
WORK,WORK,WORK,WORK,WORK,
//WORK,WORK,MOVE,
MOVE,MOVE,MOVE,MOVE,MOVE,
MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,
CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,
CARRY,CARRY,CARRY,CARRY,CARRY,CARRY
],
[ // lvl 8 (5600 max)
WORK,WORK,WORK,WORK,WORK,
WORK,WORK,WORK,WORK,WORK,
MOVE,MOVE,MOVE,MOVE,MOVE,
WORK,WORK,MOVE,MOVE,MOVE,
CARRY,CARRY,CARRY,CARRY,CARRY,
MOVE,MOVE,MOVE,MOVE,MOVE,
CARRY,CARRY,CARRY,CARRY,CARRY,
MOVE,MOVE,MOVE,MOVE,MOVE,
CARRY,CARRY,CARRY,CARRY,CARRY,
MOVE,MOVE,MOVE,MOVE,MOVE
]
],
arrUnitsByRoom : Array(),
fnc : function (creep, prehook, m2) {
if (!prehook)
return ( true );
let oTarget;
let rTargets;
let oAction;
let bJobFound;
if (creep.memory.iSeek == undefined || creep.memory.iSeek == null) {
creep.memory.iSeek = 0;
}
rTargets = [];
oAction = null;
bJobFound = false;
if(creep.carry.energy === 0) {
creep.memory.iMode = -1;
}
if (
creep.memory.iMode == -1 && creep.carry.energy == creep.carryCapacity
) {
creep.memory.iMode = 0;
creep.memory.iSeek = 0;
}
if (creep.memory.iMode == 0) {
switch(creep.memory.iSeek) {
case 0:
rTargets = creep.pos.findClosestByRange(FIND_MY_STRUCTURES, {
filter: (structure) => {
return (
structure.structureType
=== STRUCTURE_TOWER) &&
(structure.energy <=
(structure.energyCapacity / 2));
}
});
if(rTargets) {
creep.memory.iMode = 1;
creep.memory.targetId = rTargets.id;
bJobFound = true;
}
break ;
case 2:
rTargets = creep.room.find(
FIND_STRUCTURES,
{
filter: structure =>
structure.hits < structure.hitsMax &&
(
structure.structureType === STRUCTURE_RAMPART ||
structure.structureType === STRUCTURE_WALL
)
}
);
rTargets.sort((a,b) => a.hits - b.hits);
if (rTargets.length > 0) {
creep.memory.iMode = 3;
creep.memory.targetId = rTargets[0].id;
bJobFound = true;
}
break ;
case 1:
rTargets = creep.pos.findClosestByRange(
FIND_CONSTRUCTION_SITES
);
if(rTargets) {
creep.memory.iMode = 2;
creep.memory.targetId = rTargets.id;
bJobFound = true;
}
break ;
case 3:
rTargets = creep.pos.findClosestByRange(FIND_MY_STRUCTURES, {
filter: (structure) => {
return (
structure.structureType ===
STRUCTURE_EXTENSION ||
structure.structureType ===
STRUCTURE_SPAWN
) &&
(structure.energy < structure.energyCapacity - creep.carryCapacity || structure.energy === 0);
}
});
if (rTargets) {
creep.memory.iMode = 4;
creep.memory.targetId = rTargets.id;
bJobFound = true;
}
break ;
case 4:
creep.memory.iMode = 5;
bJobFound = true;
break ;
default:
creep.memory.iSeek = -1;
break ;
}
if (!bJobFound) {
creep.memory.iSeek++;
} else {
creep.memory.iSeek = 0;
}
}
switch (creep.memory.iMode) {
case -1: // Find energy
m2.tools.findEnergy(creep);
break ;
case 1: // fill towers
oTarget = Game.getObjectById(creep.memory.targetId);
oAction = creep.transfer(oTarget, RESOURCE_ENERGY);
break ;
case 2: // build construction site
oTarget = Game.getObjectById(creep.memory.targetId);
oAction = creep.build(oTarget);
break ;
case 3: // repair stuff
oTarget = Game.getObjectById(creep.memory.targetId);
if (oTarget) {
if (oTarget.hits === oTarget.hitsMax)
creep.memory.iMode = 0;
oAction = creep.repair(oTarget);
} else {
creep.memory.iMode = 0;
}
break ;
case 4: // fill capacitors
oTarget = Game.getObjectById(creep.memory.targetId);
oAction = creep.transfer(oTarget, RESOURCE_ENERGY);
break ;
default: // upgrade controler
oTarget = creep.room.controller;
oAction = creep.upgradeController(oTarget);
break ;
}
if (creep.memory.iMode > 0) {
if (oAction === ERR_NOT_IN_RANGE)
creep.moveTo(oTarget);
else if (oAction !== OK)
creep.memory.iMode = 0;
}
},
creephook : function (creep, prehook, m2) {
if (creep.memory.role == m2_creep_builder.sRole) {
m2_creep_builder.arrUnitsByRoom.push(creep.memory.home);
m2_creep_builder.fnc(creep, prehook, m2);
}
},
basehook : function (m2, iBase) {
let iCount = 0;
let iLimit = m2_creep_builder.arrUnitsLimits[Memory.config.oBases[iBase].iLvl];
for (let iB in m2_creep_builder.arrUnitsByRoom) {
if (
m2_creep_builder.arrUnitsByRoom[iB] == Memory.config.oBases[iBase].sRoom
) {
iCount++;
}
}
if (iLimit - iCount > 0 && Memory.config.oBases[iBase].bBuilder && !Memory.config.masterlock) {
// should build
for (let iSpawn in Memory.config.oBases[iBase].rSpawn) {
let oSpawn = Game.spawns[Memory.config.oBases[iBase].rSpawn[iSpawn]];
if (!oSpawn.spawning && !m2_creep_builder.bSpawnLock) {
let arrBody = m2_creep_builder.arrBodies[Memory.config.oBases[iBase].iLvl];
let sBuildReturn = oSpawn.spawnCreep(
arrBody,
m2_creep_builder.sRole +
'Arlido ' +
iBase +
Math.random().toString(36).substr(2, 3)
,
{
memory : {
hook: m2_creep_builder.sName,
iMode: 0,
role: m2_creep_builder.sRole,
home: Memory.config.oBases[iBase].sRoom
}
}
);
console.log("m2_creep_builder; Unit built in " + Memory.config.oBases[iBase].sRoom + "[" + sBuildReturn + "]");
break ;
}
}
}
}
}
module.exports = m2_creep_builder;

71
m2_creep_claim.js

@ -0,0 +1,71 @@
// m2_creep_claim
var m2_creep_claim = {
sName : 'module_creep_claim',
rMission : [
{
sHome: "E22N16",
sSpawn: "s03b",
sTarget: "E21N16"
},
{
sHome: "E22N21",
sSpawn: "s10b",
sTarget: "E23N21"
}
],
rBody: [CLAIM,CLAIM,CLAIM,CLAIM,CLAIM,CLAIM, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE],
sCurrentWorker: [],
sRole: 'claimering',
creephook : function (creep, postauth) {
if (creep.memory.role == m2_creep_claim.sRole)
{
m2_creep_claim.sCurrentWorker.push(creep.memory.sTarget);
if (creep.room.name != creep.memory.sTarget)
creep.moveTo(Game.flags[creep.memory.sTarget]);
else
{
switch (creep.reserveController(creep.room.controller)) {
case ERR_NOT_IN_RANGE:
creep.moveTo(creep.room.controller);
break;
case ERR_INVALID_TARGET:
if (creep.attackController(creep.room.controller) == ERR_NOT_IN_RANGE) {
creep.moveTo(creep.room.controller);
}
break;
default:
break;
}
}
}
},
run : function (m2) {
for (var iUnit in m2_creep_claim.rMission)
{
if (m2_creep_claim.sCurrentWorker.indexOf(m2_creep_claim.rMission[iUnit].sTarget) < 0)
{
if (!Game.spawns[m2_creep_claim.rMission[iUnit].sSpawn].spawning) {
let sBuildReturn = Game.spawns[m2_creep_claim.rMission[iUnit].sSpawn].spawnCreep(
m2_creep_claim.rBody,
'Emanuel ' + iUnit +
Math.random().toString(36).substr(2, 3),
{
memory : {
role:m2_creep_claim.sRole,
hook: m2_creep_claim.sName,
sTarget:m2_creep_claim.rMission[iUnit].sTarget,
sSpawn:m2_creep_claim.rMission[iUnit].sSpawn,
sHome:m2_creep_claim.rMission[iUnit].sHome
}
}
);
console.log(m2_creep_claim.sRole + '(m2) Built in ['+m2_creep_claim.rMission[iUnit].sHome+ '] for ['+m2_creep_claim.rMission[iUnit].sTarget+'] : '+sBuildReturn);
}
}
}
}
};
module.exports = m2_creep_claim;

240
m2_creep_energy.js

@ -0,0 +1,240 @@
var m2_creep_energy = {
sName: 'module_creep_energy',
sRole : 'miner',
bSpawnLock : false,
arrUsedRessources : Array(),
arrBodies: [
[null],
[null],
[null],
[WORK, WORK, WORK, WORK, WORK, MOVE, MOVE ,MOVE], // lvl 3
[WORK, WORK, WORK, WORK, WORK, MOVE, MOVE ,MOVE], // lvl 4
[WORK, WORK, WORK, WORK, WORK, MOVE, MOVE ,MOVE], // lvl 5
[WORK, WORK, WORK, WORK, WORK, MOVE, MOVE ,MOVE], // lvl 6
[WORK, WORK, WORK, WORK, WORK, MOVE, MOVE ,MOVE], // lvl 7
[
WORK, WORK, WORK, WORK, WORK,
WORK, WORK, WORK, WORK, WORK,
WORK, WORK, WORK, WORK, WORK,
MOVE, MOVE, MOVE, MOVE, MOVE,
MOVE, MOVE, MOVE
]
],
roomsWithMiners : Array(),
fnc : function (creep, prehook, m2) {
if (!prehook)
return ( true );
if (creep.memory.model == 1) {
var sources = Game.getObjectById(creep.memory.source);
if (sources)
{
if (sources.energy > 0)
{
let iHarvest = creep.harvest(sources);
switch (iHarvest) {
case ERR_NOT_IN_RANGE:
if (!m2.arrModules['module_build'].isInGrid(m2, creep)) {
let rFound = creep.room.lookForAt(
LOOK_STRUCTURES, creep.pos.x, creep.pos.y
);
if (rFound.length == 0) {
rFound = creep.room.lookForAt(
LOOK_CONSTRUCTION_SITES, creep.pos.x, creep.pos.y
);
}
if (rFound.length == 0) {
creep.room.createConstructionSite(
creep.pos.x,
creep.pos.y,
STRUCTURE_ROAD
);
}
}
creep.moveTo(sources, {
ignoreCreeps: true
});
break ;
case OK:
let rFound = creep.room.lookForAt(
LOOK_STRUCTURES, creep.pos.x, creep.pos.y
);
if (rFound.length == 0) {
rFound = creep.room.lookForAt(
LOOK_CONSTRUCTION_SITES, creep.pos.x, creep.pos.y
);
}
if (rFound.length == 0) {
// Probably no container under it. Should build one
creep.room.createConstructionSite(
creep.pos.x,
creep.pos.y,
STRUCTURE_CONTAINER
);
}
break ;
default:
break ;
}
}
}
} else if (creep.memory.model == 2) {
switch (creep.memory.iMode) {
case 0:
// init
creep.memory.iActual = 0;
let oBase = m2.tools.getBaseInMemoryByRoom(creep.room.name);
if (oBase != null) {
creep.memory.ar = Array();
creep.memory.ar = oBase.arrEnergySources;
creep.memory.source = creep.memory.ar[creep.memory.iActual];
creep.memory.iMode = 1;
} else {
console.log("[C] Unable to find room data for " + creep.room.name + "in Memory. Probably off room. Try to get back...");
creep.moveTo(Game.flags[creep.memory.home]);
}
break;
case 1:
let oEnergy = Game.getObjectById(creep.memory.ar[creep.memory.iActual]);
if (oEnergy.energy > 0) {
if (creep.harvest(oEnergy) === ERR_NOT_IN_RANGE)
m2.tools.mv(creep, oEnergy);
} else {
if (creep.memory.ar.length > creep.memory.iActual + 1) {
creep.memory.iActual++;
} else {
creep.memory.iActual = 0;
}
}
break ;
case 2:
break ;
default:
}
} else {
creep.say("I'm born wrong :( no ? :'(");
}
//creep.say("hi...");
},
creephook : function (creep, prehook, m2) {
if (creep.memory.role == m2_creep_energy.sRole || creep.memory.role == "miner_mk2") {
m2_creep_energy.arrUsedRessources.push(creep.memory.source);
m2_creep_energy.roomsWithMiners.push(creep.memory.home);
m2_creep_energy.fnc(creep, prehook, m2);
}
},
populateMemory : function (m2) {
Memory.arrEnergySource = Array();
for (let iBase in Memory.config.oBases) {
for (let iSource in Memory.config.oBases[iBase].arrEnergySources) {
Memory.arrEnergySource.push({
iBase : iBase,
sRoom : Memory.config.oBases[iBase].sRoom,
sSource : Memory.config.oBases[iBase].arrEnergySources[iSource],
bUsed : false
});
}
}
},
run : function (m2) {
if (Game.time % 25 === 0 || Memory.arrEnergySource == undefined)
m2_creep_energy.populateMemory(m2);
for (let i in Memory.arrEnergySource) {
if (m2_creep_energy.arrUsedRessources.indexOf(Memory.arrEnergySource[i].sSource) >= 0) {
Memory.arrEnergySource[i].bUsed = true;
} else {
Memory.arrEnergySource[i].bUsed = false;
}
}
var arrRoomWithMiners = Array();
for (let iMem in Memory.arrEnergySource) {
if(Memory.config.oBases[Memory.arrEnergySource[iMem].iBase].iLvl < 8)
{
if (
!Memory.arrEnergySource[iMem].bUsed &&
!m2_creep_energy.bSpawnLock &&
Memory.config.oBases[Memory.arrEnergySource[iMem].iBase].iLvl > 3
) {
let iBase = Memory.arrEnergySource[iMem].iBase;
for (let iSpawn in Memory.config.oBases[iBase].rSpawn) {
let oSpawn = Game.spawns[Memory.config.oBases[iBase].rSpawn[iSpawn]];
if (!oSpawn.spawning) {
let arrBody = m2_creep_energy.arrBodies[Memory.config.oBases[iBase].iLvl];
let iBuildRtn = oSpawn.spawnCreep(
arrBody,
'Tigrou ' +
iBase +
Math.random().toString(36).substr(2, 3)
,
{
memory : {
iMode: 0,
model: 1,
hook: m2_creep_energy.sName,
source: Memory.arrEnergySource[iMem].sSource,
role: m2_creep_energy.sRole,
home: Memory.config.oBases[iBase].sRoom
}
}
);
if (iBuildRtn == OK) {
console.log("m2_creep_energy; Unit < 8 built in " + Memory.config.oBases[iBase].sRoom);
} else if(iBuildRtn == ERR_NOT_ENOUGH_ENERGY) {
console.log("m2_creep_energy; No enough energy to build creep < 8");
}
break ;
}
}
}
}
}
},
basehook : function (m2, iBase) {
if (Memory.config.oBases[iBase].iLvl >= 8) {
if (m2_creep_energy.roomsWithMiners.indexOf(Memory.config.oBases[iBase].sRoom) < 0) {
if (!m2_creep_energy.bSpawnLock) {
for (let iSpawn in Memory.config.oBases[iBase].rSpawn) {
let oSpawn = Game.spawns[Memory.config.oBases[iBase].rSpawn[iSpawn]];
if (!oSpawn.spawning) {
let arrBody = m2_creep_energy.arrBodies[Memory.config.oBases[iBase].iLvl];
let iBuildRtn = oSpawn.spawnCreep(
arrBody,
'Tigrou ' +
iBase +
Math.random().toString(36).substr(2, 3)
,
{
memory : {
iMode: 0,
model: 2,
hook: m2_creep_energy.sName,
source: null,
role: m2_creep_energy.sRole,
home: Memory.config.oBases[iBase].sRoom
}
}
);
if (iBuildRtn == OK) {
console.log("m2_creep_energy; Unit >= 8 built in " + Memory.config.oBases[iBase].sRoom);
} else if(iBuildRtn == ERR_NOT_ENOUGH_ENERGY) {
console.log("m2_creep_energy; No enough energy to build creep >= 8");
}
break ;
}
}
}
}
}
}
}
module.exports = m2_creep_energy;

143
m2_creep_mineral.js

@ -0,0 +1,143 @@
// m2_creep_mineral
var m2_creep_mineral = {
sName: 'module_creep_mineral',
sRole : 'mineral_harvester',
bSpawnLock : false,
arrUnitsLimits : [0,0,0,0,0,0,1,1,1],
arrBodies: [
[null],
[null],
[null],
[null], // lvl 3
[null], // lvl 4
[WORK, WORK, WORK, WORK, WORK, MOVE, MOVE ,MOVE], // lvl 5
[WORK, WORK, WORK, WORK, WORK, MOVE, MOVE ,MOVE], // lvl 6
[WORK, WORK, WORK, WORK, WORK, MOVE, MOVE ,MOVE], // lvl 7
[
WORK, WORK, WORK ,WORK ,WORK,
WORK, WORK, WORK, WORK, WORK,
WORK, WORK, WORK, WORK, WORK,
WORK, WORK, WORK, WORK, WORK,
WORK, WORK, WORK, WORK, WORK,
WORK, WORK, WORK, WORK, WORK,
WORK, WORK, WORK, MOVE, MOVE,
MOVE, MOVE, MOVE, MOVE, MOVE,
MOVE, MOVE, MOVE, MOVE, MOVE,
MOVE, MOVE, MOVE, MOVE, MOVE
] // lvl 8
],
arrUnitsByRoom : Array(),
fnc : function (creep, prehook, m2) {
if (!prehook)
return true;
if (creep.memory.iMode === 0) {
let obase = m2.tools.getBaseInMemoryByRoom(creep.room.name);
creep.memory.source = obase.arrMineralSource[0];
creep.memory.iMode = 1;
} else if (creep.memory.iMode === 1) {
let sources = Game.getObjectById(creep.memory.source);
if (sources) {
if (sources.mineralAmount > 0) {
let iResponse = creep.harvest(sources);
switch (iResponse) {
case ERR_NOT_IN_RANGE:
if (!m2.arrModules['module_build'].isInGrid(m2, creep)) {
let rFound = creep.room.lookForAt(
LOOK_STRUCTURES, creep.pos.x, creep.pos.y
);
if (rFound.length == 0) {
rFound = creep.room.lookForAt(
LOOK_CONSTRUCTION_SITES, creep.pos.x, creep.pos.y
);
}
if (rFound.length == 0) {
creep.room.createConstructionSite(
creep.pos.x,
creep.pos.y,
STRUCTURE_ROAD
);
}
}
creep.moveTo(sources, {ignoreCreeps: true});
break ;
case OK:
let rFound = creep.room.lookForAt(
LOOK_STRUCTURES, creep.pos.x, creep.pos.y
);
if (rFound.length == 0) {
rFound = creep.room.lookForAt(
LOOK_CONSTRUCTION_SITES, creep.pos.x, creep.pos.y
);
}
if (rFound.length == 0) {
// Probably no container under it. Should build one
creep.room.createConstructionSite(
creep.pos.x,
creep.pos.y,
STRUCTURE_CONTAINER
);
}
break ;
default :
break ;
}
}
}
}
},
creephook : function (creep, prehook, m2) {
if (creep.memory.role == m2_creep_mineral.sRole) {
let iBase = m2.tools.findRoomIndexInMemory(creep.memory.home);
if (m2_creep_mineral.arrUnitsByRoom.indexOf(creep.memory.home) >= 0 || !Memory.config.oBases[iBase].bMiner) {
creep.suicide();
} else {
m2_creep_mineral.arrUnitsByRoom.push(creep.memory.home);
}
m2_creep_mineral.fnc(creep, prehook, m2);
delete(slot);
}
},
basehook : function (m2, iBase) {
let iCount = 0;
let iLimit = m2_creep_mineral.arrUnitsLimits[Memory.config.oBases[iBase].iLvl];
for (let iB in m2_creep_mineral.arrUnitsByRoom) {
if (m2_creep_mineral.arrUnitsByRoom[iB] == Memory.config.oBases[iBase].sRoom) {
iCount++;
}
}
if (iLimit - iCount > 0 && Memory.config.oBases[iBase].bMiner && !Memory.config.masterlock) {
// should build
for (let iSpawn in Memory.config.oBases[iBase].rSpawn) {
let oSpawn = Game.spawns[Memory.config.oBases[iBase].rSpawn[iSpawn]];
if (!oSpawn.spawning && !m2_creep_mineral.bSpawnLock) {
let arrBody = m2_creep_mineral.arrBodies[Memory.config.oBases[iBase].iLvl];
let iBuildRtn = oSpawn.spawnCreep(
arrBody,
'Chipi ' +
iBase +
Math.random().toString(36).substr(2, 3)
,
{
memory : {
iMode: 0,
hook: m2_creep_mineral.sName,
role: m2_creep_mineral.sRole,
home: Memory.config.oBases[iBase].sRoom
}
}
);
if (iBuildRtn == OK) {
console.log("m2_creep_mineral; Unit built in " + Memory.config.oBases[iBase].sRoom);
} else if(iBuildRtn == ERR_NOT_ENOUGH_ENERGY) {
console.log("m2_creep_mineral; No enough energy to build creep");
}
break ;
}
}
}
}
};
module.exports = m2_creep_mineral;

1268
m2_creep_mover.js
File diff suppressed because it is too large
View File

166
m2_creep_power.js

@ -0,0 +1,166 @@
var m2_creep_power = {
sName : 'm2_creep_power',
findpower : function (creep) {
if (creep.room.storage.store[RESOURCE_POWER])
{
if (creep.room.storage.store[RESOURCE_POWER] >= creep.carryCapacity)
{
var storp = creep.withdraw(creep.room.storage, RESOURCE_POWER);
console.log(storp);
if(storp == ERR_NOT_IN_RANGE)
creep.moveTo(creep.room.storage);
}
}
if (creep.room.terminal.store[RESOURCE_POWER])
{
if (creep.room.terminal.store[RESOURCE_POWER] >= creep.carryCapacity)
{
var termp = creep.withdraw(creep.room.terminal, RESOURCE_POWER);
console.log(termp);
if(termp == ERR_NOT_IN_RANGE)
creep.moveTo(creep.room.terminal);
}
}
},
cycle : function () {
var oHappy = Game.powerCreeps['happy'];
var sStartRoom = "";
var missions = [
{
sRoom: "E21N19",
arrSources : ['5bbcae249099fc012e638760','5bbcae249099fc012e638762'],
spowerspawn : '5c879b015c7332130daf6153'
},
{
sRoom: "E21N18",
arrSources : ['5bbcae249099fc012e638765','5bbcae249099fc012e638766'],
spowerspawn : '5cb50a32f10dfb205d9f51f9'
},
{
sRoom: "E22N18",
arrSources : ['5bbcae329099fc012e6388ea','5bbcae329099fc012e6388ec'],
spowerspawn : '5cc97e5e1a3ca4284d56da5e'
}
];
var oAction;
if (oHappy.memory.iCycle == null || oHappy.memory.iCycle == undefined)
{
oHappy.memory.iCycleStep = 0;
oHappy.memory.iCycle = 0;
}
if (oHappy.room.name == missions[oHappy.memory.iCycle].sRoom)
{
if (oHappy.powers[PWR_GENERATE_OPS].cooldown == 0)
oHappy.usePower(PWR_GENERATE_OPS);
var oPSpawn = Game.getObjectById(missions[oHappy.memory.iCycle].spowerspawn);
if (oHappy.ticksToLive < 3000)
{
if (oHappy.renew(oPSpawn) == ERR_NOT_IN_RANGE)
oHappy.moveTo(oPSpawn);
} else {
if (oHappy.memory.iCycleStep == 0 || oHappy.memory.iCycleStep == undefined || oHappy.memory.iCycleStep == null)
{
oAction = oHappy.renew(oPSpawn);
if (oAction == ERR_NOT_IN_RANGE)
oHappy.moveTo(oPSpawn);
else if (oAction == OK)
{
oHappy.memory.iCycleStep = 1;
oHappy.memory.iCycleSource = 0;
}
}
if (oHappy.memory.iCycleStep == 1)
{
if (oHappy.carry[RESOURCE_OPS] > 1000)
{
var rtnp = oHappy.transfer(oHappy.room.storage, RESOURCE_OPS, 750);
if (rtnp == ERR_NOT_IN_RANGE) {
oHappy.moveTo(oHappy.room.storage);
}
}
else if (oHappy.powers[PWR_REGEN_SOURCE].cooldown == 0)
{
var oSource = Game.getObjectById(missions[oHappy.memory.iCycle].arrSources[oHappy.memory.iCycleSource]);
oAction = oHappy.usePower(PWR_REGEN_SOURCE, oSource);
if (oAction == OK) {
oHappy.memory.iCycleSource++;
if (oHappy.memory.iCycleSource >= missions[oHappy.memory.iCycle].arrSources.length)
{
oHappy.memory.iCycleSource = 0;
oHappy.memory.iCycleStep = 2;
}
} else if (oAction == -10)
{
if(oHappy.enableRoom(
oHappy.room.controller
) == ERR_NOT_IN_RANGE)
{
oHappy.moveTo(oHappy.room.controller);
}
} else if (oAction == ERR_NOT_IN_RANGE)
{
oHappy.moveTo(oSource);
}
}
else
{
oHappy.moveTo(Game.flags[oHappy.room.name]);
}
}
if (oHappy.memory.iCycleStep == 2)
{
oAction = oHappy.renew(oPSpawn);
if (oAction == ERR_NOT_IN_RANGE)
oHappy.moveTo(oPSpawn);
else if (oAction == OK)
{
oHappy.memory.iCycleStep = 0;
oHappy.memory.iCycle++;
if (missions.length <= oHappy.memory.iCycle)
{
oHappy.memory.iCycle = 0;
}
}
}
}
} else {
oHappy.moveTo(Game.flags[missions[oHappy.memory.iCycle].sRoom]);
}
},
run : function () {
var oPSpawn = Game.getObjectById('5c879b015c7332130daf6153');
var arrPSpawn = [
'5c879b015c7332130daf6153',
'5ca693dc524cfa55fb2d8b4c',
'5cb50a32f10dfb205d9f51f9',
'5cc97e5e1a3ca4284d56da5e',
'5cdd133187e2ff2131ef3b09'
];
var oHappy = Game.powerCreeps['happy'];
if (oHappy.room)
{
m2_creep_power.cycle();
}
else
{
Game.powerCreeps['happy'].spawn(oPSpawn);
}
for (var iPS in arrPSpawn)
{
var oP = Game.getObjectById(arrPSpawn[iPS]);
if (oP.power > 0)
oP.processPower();
}
}
}
module.exports = m2_creep_power;

219
m2_creep_trader.js

@ -0,0 +1,219 @@
// m2_creep_trader
var m2_creep_trader = {
sName: 'module_creep_traders',
sRole: 'traders',
rMissions : [{
spawnlock: false,
arrRoad: ['E22N19', 'E22N20'],
iMission: 0,
iUnitByMission: 1,
sMissionCode: 'A',
sMissionName: 'Mist',
sObserver: '5d1bd2fb7c50090fe44d76d1',
iMineral: RESOURCE_MIST,
sTargetId: '5dc2ed29903e8d47f0d38493',
rCreepModel : [
WORK, WORK, WORK, WORK, WORK,
WORK, WORK, WORK, WORK, WORK,
WORK, WORK, WORK, WORK, WORK,
WORK, WORK, WORK, WORK, WORK,
WORK, WORK, WORK, WORK, WORK,
CARRY,
MOVE, MOVE, MOVE, MOVE, MOVE,
MOVE, MOVE, MOVE, MOVE, MOVE,
MOVE, MOVE, MOVE, MOVE, MOVE,
MOVE, MOVE
]
},
{
spawnlock: false,
arrRoad: ['E22N18', 'E22N17'],
iMission: 1,
iUnitByMission: 1,
sMissionCode: 'Mdd',
sMissionName: 'Energy',
sObserver: '5cc9bbcff71a733b9e894c43',
iMineral: RESOURCE_ENERGY,
sTargetId: '5bbcae329099fc012e6388ee',
rCreepModel : [
WORK, WORK, WORK, WORK,
CARRY, CARRY, CARRY, CARRY,
CARRY, CARRY, CARRY, CARRY,
CARRY, CARRY, CARRY, CARRY,
MOVE, MOVE, MOVE, MOVE,
MOVE, MOVE, MOVE, MOVE,
MOVE, MOVE, MOVE, MOVE,
MOVE, MOVE, MOVE, MOVE
]
},
{
spawnlock: false,
arrRoad: ['E21N19', 'E20N19', 'E20N20'],
iMission: 2,
iUnitByMission: 1,
sMissionCode: 'Mdd2',
sMissionName: 'Mist 2',
sObserver: '5c86fdf503c0d05f62993904',
iMineral: RESOURCE_MIST,
sTargetId: '5dcb8b1c6292414ac7db8c22',
rCreepModel : [
WORK, WORK, WORK, WORK, WORK,
WORK, WORK, WORK, WORK, WORK,
WORK, WORK, WORK, WORK, WORK,
WORK, WORK, WORK, WORK, WORK,
WORK, WORK, WORK, WORK, WORK,
CARRY,
MOVE, MOVE, MOVE, MOVE, MOVE,
MOVE, MOVE, MOVE, MOVE, MOVE,
MOVE, MOVE, MOVE, MOVE, MOVE,
MOVE, MOVE
]
},
{
spawnlock: false,
arrRoad: ['E21N19', 'E20N19'],
iMission: 3,
iUnitByMission: 1,
sMissionCode: 'Mdd3',
sMissionName: 'Mist 3',
sObserver: '5c86fdf503c0d05f62993904',
iMineral: RESOURCE_MIST,
sTargetId: '5df71c8fd90bdc1919e14dc1',
rCreepModel : [
WORK, WORK, WORK, WORK, WORK,
WORK, WORK, WORK, WORK, WORK,
WORK, WORK, WORK, WORK, WORK,
WORK, WORK, WORK, WORK, WORK,
WORK, WORK, WORK, WORK, WORK,
CARRY,
MOVE, MOVE, MOVE, MOVE, MOVE,
MOVE, MOVE, MOVE, MOVE, MOVE,
MOVE, MOVE, MOVE, MOVE, MOVE,
MOVE, MOVE
]
}
],
rUnitCount: Array(),
fnc : function (creep, preehook, m2) {
let oMission = m2_creep_trader.rMissions[creep.memory.iMission];
let iRoad = oMission.arrRoad.indexOf(creep.room.name);
switch(creep.memory.iMode) {
case 0:
// In route ==>
if (creep.ticksToLive < 100) {
creep.suicide();
}
if (iRoad == oMission.arrRoad.length - 1) {
creep.memory.iMode = 1;
let oTarget = Game.getObjectById(creep.memory.sTargetId);
creep.moveTo(oTarget);
} else {
creep.moveTo(Game.flags[oMission.arrRoad[iRoad + 1]]);
}
break;
case 1:
// Arive. Mine
if (_.sum(creep.carry) == creep.carryCapacity) {
creep.memory.iMode = 2;
} else {
if (creep.ticksToLive < 100 && _.sum(creep.carry) > 0) {
creep.memory.iMode = 2;
}
let oTarget = Game.getObjectById(creep.memory.sTargetId);
if (creep.harvest(oTarget) === ERR_NOT_IN_RANGE) {
creep.moveTo(oTarget);
}
}
break;
case 2:
// Full, go back <==
if (iRoad == 0) {
creep.memory.iMode = 3;
creep.moveTo(creep.room.storage);
} else {
creep.moveTo(Game.flags[oMission.arrRoad[iRoad - 1]]);
}
break ;
case 3:
// unload
if (_.sum(creep.carry) == 0) {
creep.memory.iMode = 0;
} else {
if(creep.transfer(creep.room.storage, creep.memory.iMineral) == ERR_NOT_IN_RANGE) {
creep.moveTo(creep.room.storage);
}
}
break ;
default:
creep.memory.iMode = 0;
break;
}
},
creephook : function (creep, prehook, m2) {
if (creep.memory.role == m2_creep_trader.sRole) {
m2_creep_trader.rUnitCount.push(creep.memory.sMissionCode);
m2_creep_trader.fnc(creep, prehook, m2);
}
},
run : function (m2) {