Browse Source

..

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

+ 265
- 0
m2_bootstrap.js View File

@@ -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
- 0
m2_build.js View File

@@ -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
- 0
m2_config.js
File diff suppressed because it is too large
View File


+ 145
- 0
m2_creep_basic.js View File

@@ -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
- 0
m2_creep_builder.js View File

@@ -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
- 0
m2_creep_claim.js View File

@@ -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
- 0
m2_creep_energy.js View File

@@ -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
- 0
m2_creep_mineral.js View File

@@ -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
- 0
m2_creep_mover.js
File diff suppressed because it is too large
View File


+ 166
- 0
m2_creep_power.js View File

@@ -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
- 0
m2_creep_trader.js View File

@@ -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) {
for (let iM in m2_creep_trader.rMissions) {
let iCount = 0;
let oMission = m2_creep_trader.rMissions[iM];
for (let iUC in m2_creep_trader.rUnitCount) {
if (m2_creep_trader.rUnitCount[iUC] == oMission.sMissionCode) {
iCount++;
}
}
if (iCount < oMission.iUnitByMission && !oMission.spawnlock) {
let oObserver = Game.getObjectById(oMission.sObserver);
oObserver.observeRoom(
oMission.arrRoad[oMission.arrRoad.length - 1]
);
if (Game.getObjectById(oMission.sTargetId))
{
let iBase = m2.tools.findRoomIndexInMemory(oMission.arrRoad[0]);
for (let iSpawn in Memory.config.oBases[iBase].rSpawn) {
let oSpawn = Game.spawns[Memory.config.oBases[iBase].rSpawn[iSpawn]];
if (!oSpawn.spawning) {
let arrBody = oMission.rCreepModel;
let iBuildRtn = oSpawn.spawnCreep(
arrBody,
'Proute ' +
iBase +
Math.random().toString(36).substr(2, 3)
,
{
memory : {
iMode: 0,
hook: m2_creep_trader.sName,
role: m2_creep_trader.sRole,
home: oMission.arrRoad[0],
iMission: oMission.iMission,
sMissionCode: oMission.sMissionCode,
sMissionName: oMission.sMissionName,
iMineral: oMission.iMineral,
sTargetId: oMission.sTargetId
}
}
);
if (iBuildRtn == OK) {
console.log("m2_creep_trader; Unit built in " + Memory.config.oBases[iBase].sRoom);
} else {
//console.log("m2_creep_trader; Cannot build in " + Memory.config.oBases[iBase].sRoom + " [" + iBuildRtn + "]");
}
break ;
}
}
}
}
}
}

}

module.exports = m2_creep_trader;

+ 114
- 0
m2_creep_updater.js View File

@@ -0,0 +1,114 @@

var m2_creep_updater = {
sName: 'module_creep_updater',
sRole : 'updater',
bSpawnLock : false,
arrUnitsLimits : [0,0,2,2,2,2,1,1,1],
arrBodies: [
[null],
[null],
[WORK, WORK, WORK,MOVE, MOVE, MOVE,CARRY, CARRY],
[WORK, WORK, WORK, WORK, WORK,MOVE, MOVE, MOVE, MOVE,CARRY, CARRY],
[WORK, WORK, WORK, WORK, WORK, WORK, MOVE, MOVE, MOVE, MOVE, MOVE, CARRY, CARRY, CARRY],
[WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK, MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE, CARRY,CARRY,CARRY,CARRY,CARRY,CARRY],
[WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY],
[WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY],
[
WORK,WORK,WORK,WORK,WORK,
MOVE,MOVE,MOVE,MOVE,MOVE,
CARRY,CARRY,CARRY,CARRY
]
],
arrUnitsByRoom : Array(),
fnc : function (creep, preehook, m2) {
let rTarget = [];
let oTarget = null;
let oaction = null;

if(creep.store[RESOURCE_ENERGY] == 0) {
creep.memory.iMode = 0;
}
if(creep.memory.iMode == 0 && creep.store.getFreeCapacity() == 0) {
creep.memory.fe = 0;
creep.memory.iMode = 2;
if (creep.room.controller != undefined) {
if (creep.room.controller.sign != undefined) {
if (creep.room.controller.sign.username != creep.owner.username) {
creep.memory.iMode = 1;
}
}
}
}
switch (creep.memory.iMode) {
case 0:
m2.tools.findEnergy(creep);
break ;
case 1:
let oAction = creep.signController(
creep.room.controller, Memory.config.sRoomSign
);
if(oAction == ERR_NOT_IN_RANGE) {
creep.moveTo(creep.room.controller);
} else {
creep.memory.iMode = 2;
}
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_updater.sRole) {
m2_creep_updater.arrUnitsByRoom.push(creep.memory.home);
m2_creep_updater.fnc(creep, prehook, m2);
}
},
basehook : function (m2, iBase) {
let iCount = 0;
let iLimit = m2_creep_updater.arrUnitsLimits[Memory.config.oBases[iBase].iLvl];
for (let iB in m2_creep_updater.arrUnitsByRoom) {
if (m2_creep_updater.arrUnitsByRoom[iB] == Memory.config.oBases[iBase].sRoom) {
iCount++;
}
}
if (iLimit - iCount > 0 && !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_updater.bSpawnLock) {
let arrBody = m2_creep_updater.arrBodies[Memory.config.oBases[iBase].iLvl];
let iBuildRtn = oSpawn.spawnCreep(
arrBody,
'Luc ' +
iBase +
Math.random().toString(36).substr(2, 3)
,
{
memory : {
iMode: 0,
hook: m2_creep_updater.sName,
role: m2_creep_updater.sRole,
home: Memory.config.oBases[iBase].sRoom
}
}
);
if (iBuildRtn == OK) {
console.log("m2_creep_updater; Unit built in " + Memory.config.oBases[iBase].sRoom);
} else if(iBuildRtn == ERR_NOT_ENOUGH_ENERGY) {
// console.log("m2_creep_updater; No enough energy to build creep in room [" + Memory.config.oBases[iBase].sRoom + "]");
}
break ;
}
}
}
}
};

module.exports = m2_creep_updater;

+ 88
- 0
m2_creeps_status.js View File

@@ -0,0 +1,88 @@
// m2_creep_status

var m2_creeps_status = {
sName : 'm2_creeps_status',
minerals : function(m2, i) {
if (
Memory.config.oBases[i].bMiner == undefined || Memory.config.oBases[i].bMiner == null
) {
Memory.config.oBases[i].bMiner = false;
}
if (
Memory.config.oBases[i].arrMineralSource.length > 0
) {
let oSource = Game.getObjectById(Memory.config.oBases[i].arrMineralSource[0]);
if (
oSource
) {
if (
oSource.density
) {
if (oSource.mineralAmount > 0) {
Memory.config.oBases[i].bMiner = true;
} else {
Memory.config.oBases[i].bMiner = false;
}
}
}
}
},
builders : function (m2, i) {
if
(
Memory.config.oBases[i].bBuilder == undefined || Memory.config.oBases[i].bBuilder == null
) {
Memory.config.oBases[i].bBuilder = false;
}
let rTargets = Game.rooms[Memory.config.oBases[i].sRoom].find(
FIND_CONSTRUCTION_SITES
);
Memory.config.oBases[i].bBuilder = false;
if (rTargets.length > 0) {
Memory.config.oBases[i].bBuilder = true;
} else {
var iCare = Memory.config.oBases[i].buildingHitThreshold - 900;
rTargets = Game.rooms[Memory.config.oBases[i].sRoom].find(FIND_STRUCTURES,
{
filter: (structure) => {
return (
(
structure.structureType ==
STRUCTURE_WALL
) &&
structure.hits < (
iCare
> structure.hitsMax
? structure.hitsMax
: iCare
)
)
}
}
);
if (rTargets.length > 0) {
Memory.config.oBases[i].bBuilder = true;
} else {
if (Game.rooms[Memory.config.oBases[i].sRoom].storage) {
if (Game.rooms[Memory.config.oBases[i].sRoom].storage.store[RESOURCE_ENERGY] > 700000) {
Memory.config.oBases[i].bBuilder = true;
}
}

}
}
},
basehook : function (m2, iBase) {
m2_creeps_status.minerals(m2, iBase);
if (Game.time % 10 === 0) {
m2_creeps_status.builders(m2, iBase);
}
}
};


module.exports = m2_creeps_status;

+ 161
- 0
m2_factory.js View File

@@ -0,0 +1,161 @@
// m2_factory

var m2_factory = {
sName : 'm2_factory',
basehook : function (m2, iBase) {
if (Memory.config.oBases[iBase].sFactoryId == undefined || Memory.config.oBases[iBase].sFactoryId == null) {
let rFactory = Game.rooms[Memory.config.oBases[iBase].sRoom].find(FIND_STRUCTURES, {
filter: (i) => i.structureType == STRUCTURE_FACTORY
});
if (rFactory.length > 0) {
Memory.config.oBases[iBase].sFactoryId = rFactory[0].id;
} else {
Memory.config.oBases[iBase].sFactoryId = "none";
}
}
if (Memory.config.oBases[iBase].iFactoryMode == undefined || Memory.config.oBases[iBase].iFactoryMode == null) {
Memory.config.oBases[iBase].iFactoryMode = 0;
}
switch (Memory.config.oBases[iBase].iFactoryMode) {
case 0: // compress stuff
if (Memory.config.oBases[iBase].sFactoryId !== "none") {
let oFactory = Game.getObjectById(Memory.config.oBases[iBase].sFactoryId);
if (oFactory) {
let iRB = m2.tools.getFactoryBySrc(Memory.config.oBases[iBase].iMineralType);
if (iRB != -1) {
let oRB = Memory.config.rRefineryBase[iRB];
if (
oFactory.store[oRB.src] >= oRB.srcQty &&
oFactory.store[RESOURCE_ENERGY] >= oRB.iEnergy
) {
// enough energy; execute ?
if (oFactory.cooldown == 0) {
let iFactoryRtn = oFactory.produce(oRB.dest);
//console.log("Factory: " + iFactoryRtn);
}
} else {
// not enough ressources
//console.log("Factory: not enough ressources in " + Memory.config.oBases[iBase].sRoom);
}
} else {
//console.log("Factory: No rRefineryBase defined for the specified base mineral");
// No rRefineryBase defined for the specified base mineral
}
} else {
//console.log("Factory: Factory ID in memory is invalid...");
// Factory ID in memory is invalid...
}
} else {
//console.log("Factory: no factory in room...");
// no factory in room...
}
break ;
default:
Memory.config.oBases[iBase].iFactoryMode = 0;
break ;
}
},
init : function (m2) {

if (Memory.config.rRefineryBase == undefined || Memory.config.rRefineryBase == null) {
Memory.config.rRefineryBase = Array();
console.log("m2 -> Refinery : Init base ref index..");
Memory.config.rRefineryBase.push({
dest : RESOURCE_REDUCTANT,
destQty : 100,
src: RESOURCE_HYDROGEN,
srcQty: 500,
iEnergy : 200
});
Memory.config.rRefineryBase.push({
dest : RESOURCE_OXIDANT,
destQty : 100,
src: RESOURCE_OXYGEN,
srcQty: 500,
iEnergy : 200
});
Memory.config.rRefineryBase.push({
dest : RESOURCE_UTRIUM_BAR,
destQty : 100,
src: RESOURCE_UTRIUM,
srcQty: 500,
iEnergy : 200
});
Memory.config.rRefineryBase.push({
dest : RESOURCE_LEMERGIUM_BAR,
destQty : 100,
src: RESOURCE_LEMERGIUM,
srcQty: 500,
iEnergy : 200
});

Memory.config.rRefineryBase.push({
dest : RESOURCE_KEANIUM_BAR,
destQty : 100,
src: RESOURCE_KEANIUM,
srcQty: 500,
iEnergy : 200
});
Memory.config.rRefineryBase.push({
dest : RESOURCE_ZYNTHIUM_BAR,
destQty : 100,
src: RESOURCE_ZYNTHIUM,
srcQty: 500,
iEnergy : 200
});
Memory.config.rRefineryBase.push({
dest : RESOURCE_PURIFIER,
destQty : 100,
src: RESOURCE_CATALYST,
srcQty: 500,
iEnergy : 200
});
Memory.config.rRefineryBase.push({
dest : RESOURCE_GHODIUM_MELT,
destQty : 100,
src: RESOURCE_GHODIUM,
srcQty: 500,
iEnergy : 200
});

console.log("m2 -> Refinery : ..done");
}
},

run : function (m2) {
m2_factory.init(m2);
}
};

module.exports = m2_factory;

/*

RESOURCE_HYDROGEN: "H",
RESOURCE_OXYGEN: "O",
RESOURCE_UTRIUM: "U",
RESOURCE_LEMERGIUM: "L",
RESOURCE_KEANIUM: "K",
RESOURCE_ZYNTHIUM: "Z",
RESOURCE_CATALYST: "X",
RESOURCE_GHODIUM: "G",

RESOURCE_UTRIUM_BAR: 'utrium_bar',
RESOURCE_LEMERGIUM_BAR: 'lemergium_bar',
RESOURCE_ZYNTHIUM_BAR: 'zynthium_bar',
RESOURCE_KEANIUM_BAR: 'keanium_bar',
RESOURCE_GHODIUM_MELT: 'ghodium_melt',
RESOURCE_OXIDANT: 'oxidant',
RESOURCE_REDUCTANT: 'reductant',
RESOURCE_PURIFIER: 'purifier',
RESOURCE_BATTERY: 'battery',

*/

+ 57
- 0
m2_federation.js View File

@@ -0,0 +1,57 @@

var m2_federation = {
basehook : function (m2, iBase) {
},
run : function (m2) {
if (Memory.config.arrFederation == undefined || Memory.config.arrFederation == null) {
Memory.config.arrFederation = Array();
}
if (Memory.config.arrFederation.length == 0) {
let arrFederationTmp = Array();
for (let iBase in Memory.config.oBases) {
let oTerminal = Game.rooms[Memory.config.oBases[iBase].sRoom].terminal;
if (oTerminal) {
for (let iMineral in m2.config.arrMinerals) {
if (oTerminal.store[m2.config.arrMinerals[iMineral]] < 2000) {
arrFederationTmp.push({
iBase: iBase,
iMineral: m2.config.arrMinerals[iMineral],
sRoom: Memory.config.oBases[iBase].sRoom
});
}
}
}
}
if (arrFederationTmp.length > 0) {
Memory.config.arrFederation = arrFederationTmp;
}
}
if(Memory.config.arrFederation.length > 0) {
for (let iBase in Memory.config.oBases) {
if (iBase !== Memory.config.arrFederation[0].iBase) {
let oTerminal = Game.rooms[Memory.config.oBases[iBase].sRoom].terminal;
if (oTerminal) {
if (oTerminal.store[Memory.config.arrFederation[0].iMineral] > 7000) {
Game.rooms[Memory.config.oBases[iBase].sRoom].terminal.send(
Memory.config.arrFederation[0].iMineral,
2500,
Memory.config.arrFederation[0].sRoom,
"Globalisation: Room " + Memory.config.oBases[iBase].sRoom + " give " + Memory.config.arrFederation[0].iMineral + " to " + Memory.config.arrFederation[0].sRoom + " " +
Math.random().toString(36).substr(2, 9)
);
Memory.config.arrFederation = m2.tools.spliceh(Memory.config.arrFederation);
return true;
}
}
}
}
Memory.config.arrFederation = m2.tools.spliceh(Memory.config.arrFederation);
}
}
};
module.exports = m2_federation;


+ 9
- 0
m2_hostility.js View File

@@ -0,0 +1,9 @@

var m2_hostility = {
run : function (m2) {
if (Memory.config.enemyFaction == undefined || Memory.config.enemyFaction == null) {
Memory.config.enemyFaction = Array();
}
}
};
module.exports = m2_hostility;

+ 377
- 0
m2_init.js View File

@@ -0,0 +1,377 @@
// m2_init
// prise 2
var m2_init = {
sName : 'm2_init',
run : function (m2) {
let usid = m2.usages.open("init");
if (Memory.config == null || Memory.config == undefined) {
console.log("Memory init from scratch...");
Memory.config = {
init: true,
oBases: Array(),
masterlock: false,
refresh : null,
sRoomSign: 'c01 was here!. Peaceful player. Love to trade.'
};
}
if (Memory.config.blacklist == undefined || Memory.config.blacklist == null) {
Memory.config.blacklist = Array();
}
if (
Memory.config.refresh == undefined ||
Memory.config.refresh == null
) {
console.log("Memory refresh...");
var arrSpawnsx = Array();
for (let iX in Memory.config.oBases) {
console.log("Validating Existing spawns for ["+ Memory.config.oBases[iX].sName +"]...");

for (let iXX in Memory.config.oBases[iX].rSpawn) {
arrSpawnsx.push(Memory.config.oBases[iX].rSpawn[iXX]);
let oSpawntc = Game.spawns[
Memory.config.oBases[iX].rSpawn[iXX]
];
if (oSpawntc == undefined) {
console.log("REMOVING SPAWN ["+Memory.config.oBases[iX].rSpawn[iXX]+"]");
Memory.config.oBases[iX].rSpawn = m2.tools.splicei(Memory.config.oBases[iX].rSpawn, iXX);
} else {
console.log(
Memory.config.oBases[iX].rSpawn[iXX] +
" ... valid"
);
}
}

console.log("Refreshing static config...");
let oBaseConfig = m2.tools.getStaticConfigByRoom(
m2, Memory.config.oBases[iX].sRoom
);
if (oBaseConfig !== null) {
console.log("Config found. Aligning...");
Memory.config.oBases[iX].sName = oBaseConfig.sName;
Memory.config.oBases[iX].labs = oBaseConfig.labs;
Memory.config.oBases[iX].lreact = oBaseConfig.lreact;
} else {
console.log("[W] (Refresh) m2.init.run => No static config found for room " + Memory.config.oBases[iX].sRoom);
}
console.log("Aligning mineral type (bug correction)");
let oMinerals = Game.rooms[Memory.config.oBases[iX].sRoom].find(FIND_MINERALS);
if (oMinerals) {
for (let iMI in oMinerals) {
console.log("["+ oMinerals[iMI].mineralType +"]");
Memory.config.oBases[iX].iMineralType = oMinerals[iMI].mineralType;
}
}
console.log (Memory.config.oBases[iX].iMineralType + " Found.");
}

console.log("Looking for new spawn...");
for (let iSpawn in Game.spawns) {
if (arrSpawnsx.indexOf(Game.spawns[iSpawn].name) < 0) {
console.log("New spawn ["+Game.spawns[iSpawn].name+"] detected. Addind...");
let iSpawnBase = m2.tools.findRoomIndexInMemory(
Game.spawns[iSpawn].room.name
);
if (iSpawnBase < 0) {
console.log("No previous room. New base. Adding...");
m2_init.add_base(m2, Game.spawns[iSpawn].room.name);
let iNewSpawnBase = m2.tools.findRoomIndexInMemory(
Game.spawns[iSpawn].room.name
);
if (iNewSpawnBase < 0) {
console.log("Adding new spawn to new base");
Memory.config.oBases[iNewSpawnBase].rSpawn.push(
Game.spawns[iSpawn].name
);
} else {
console.log("[E] Unable to push Spawn to new base. Should look into that...");
}

} else {
console.log("Room ["+Memory.config.oBases[iSpawnBase].sRoom+"]found. Adding spawn ["+Game.spawns[iSpawn].name+"] to it.");
Memory.config.oBases[iSpawnBase].rSpawn.push(
Game.spawns[iSpawn].name
);
}