Started working on classes, everything is borked rn though

This commit is contained in:
ObeseTermite 2025-06-03 21:53:39 -07:00
parent bb03c6d884
commit b5dfb44faf
3 changed files with 26 additions and 5 deletions

15
role.base.js Normal file
View file

@ -0,0 +1,15 @@
class roleBase{
constructor(){
this.body = [ MOVE, WORK, CARRY ];
this.name = 'Creep';
}
/** @param {Creep} creep **/
run(creep) { }
spawn(spawn){
spawn.spawnCreep(this.body, this.name + Game.time,
memory : {role : this.name}
});
}
};
module.exports = roleBase;

View file

@ -37,8 +37,7 @@ function spawnCreeps(spawn){
if(roleCreeps.length < count && !spawn.spawning) { if(roleCreeps.length < count && !spawn.spawning) {
var newName = role + Game.time; var newName = role + Game.time;
console.log(spawn.spawnCreep(roleMap[role].body, newName, roleMap[role].spawn(spawn);
{memory: {role: role}}));
break; break;
} }
} }

View file

@ -5,8 +5,6 @@ const body = [
]; ];
var roleGuard = { var roleGuard = {
body,
/** @param {Creep} creep **/ /** @param {Creep} creep **/
run: function(creep) { run: function(creep) {
const target = creep.pos.findClosestByRange(FIND_HOSTILE_CREEPS); const target = creep.pos.findClosestByRange(FIND_HOSTILE_CREEPS);
@ -16,7 +14,16 @@ var roleGuard = {
} }
} }
else { else {
creep.moveTo(Game.flags.IdleArea); var currentWaypoint = Game.flags[creep.memory.waypoints[creep.memory.currentWaypoint]];
if(getRangeTo(currentWaypoint) > 0){
creep.moveTo(currentWaypoint);
}
else{
creep.memory.currentWaypoint += 1;
if(creep.memory.currentWaypoint > creep.memory.waypoints.length){
creep.memory.currentWaypoint = 0;
}
}
} }
} }
}; };