diff --git a/section1/images/Energy source.PNG b/section1/images/Energy source.PNG new file mode 100644 index 0000000..194b1f6 Binary files /dev/null and b/section1/images/Energy source.PNG differ diff --git a/section1/images/Harvester1.PNG b/section1/images/Harvester1.PNG new file mode 100644 index 0000000..213e025 Binary files /dev/null and b/section1/images/Harvester1.PNG differ diff --git a/section1/images/UI.PNG b/section1/images/UI.PNG new file mode 100644 index 0000000..0a74c95 Binary files /dev/null and b/section1/images/UI.PNG differ diff --git a/section1/images/View.PNG b/section1/images/View.PNG new file mode 100644 index 0000000..0199b9f Binary files /dev/null and b/section1/images/View.PNG differ diff --git a/section1/images/bodyparts.png b/section1/images/bodyparts.png new file mode 100644 index 0000000..3edcc84 Binary files /dev/null and b/section1/images/bodyparts.png differ diff --git a/section1/images/colony-center.png b/section1/images/colony-center.png new file mode 100644 index 0000000..03c5012 Binary files /dev/null and b/section1/images/colony-center.png differ diff --git a/section1/images/console.PNG b/section1/images/console.PNG new file mode 100644 index 0000000..79fe3ba Binary files /dev/null and b/section1/images/console.PNG differ diff --git a/section1/images/creep_harvesting_energy_mag_script.PNG b/section1/images/creep_harvesting_energy_mag_script.PNG new file mode 100644 index 0000000..b12b6a3 Binary files /dev/null and b/section1/images/creep_harvesting_energy_mag_script.PNG differ diff --git a/section1/images/creep_transfer_energy.PNG b/section1/images/creep_transfer_energy.PNG new file mode 100644 index 0000000..64d6dbf Binary files /dev/null and b/section1/images/creep_transfer_energy.PNG differ diff --git a/section1/images/creepharvestingenergy.PNG b/section1/images/creepharvestingenergy.PNG new file mode 100644 index 0000000..5c2f58e Binary files /dev/null and b/section1/images/creepharvestingenergy.PNG differ diff --git a/section1/images/creepharvestingenergymag.PNG b/section1/images/creepharvestingenergymag.PNG new file mode 100644 index 0000000..cf6fcd5 Binary files /dev/null and b/section1/images/creepharvestingenergymag.PNG differ diff --git a/section1/images/game-loop.png b/section1/images/game-loop.png new file mode 100644 index 0000000..a1ad385 Binary files /dev/null and b/section1/images/game-loop.png differ diff --git a/section1/images/map.png b/section1/images/map.png new file mode 100644 index 0000000..5c276c3 Binary files /dev/null and b/section1/images/map.png differ diff --git a/section1/info/multiple_rooms_advice.txt b/section1/info/multiple_rooms_advice.txt new file mode 100644 index 0000000..b755139 --- /dev/null +++ b/section1/info/multiple_rooms_advice.txt @@ -0,0 +1,42 @@ +As a total beginner myself I found the following things helpful (mostly because that was what I had to change when I invaded the first room): + +Avoid using anything like Game.controllers.MyController, instead loop over the rooms like: + +for(var room_it in Game.rooms) { + var room = Game.rooms[room_it] + var spawn = room.find(FIND_MY_SPAWNS)[0]; // TODO: decide on multi spawn rooms +This is the start of the loop that decides if any creeps need to be spawned. The following code will make decisions mostly based on number of creeps in this room (which I count in a different loop) and room params like energy available. Also there is a global object create where I hard code some tasks for each room that I can't calculate automatically (yet anyway, maybe when my code gets better). + +room_strategy : { + 'W5S7': { + maintenance_area: {ax: 11, ay: 5, bx: 46, by: 30}, + min_wall: 300000, +}, +'W4S7': { + maintenance_area: {ax: 0, ay: 0, bx: 49, by: 49}, + min_wall: 75000, +} +Maintenance area is the area in which the creeps should upgrade walls (a bit specific to my rooms) and min_wall is the level to which they should upgrade (My older room with better walls is at a higher level). That prevents that creeps upgrade one wall to a super high value before going on with the next wall. That way I just adjust the level once a day. There are more such values in this data structure. + +The creeps themselves are just looped like this: + +for(var name in Game.creeps) { +Game.creeps[name].runTask(); +} + +runTask() is a method I added to the Creeps.prototype. + +They will then take their current room object and make all decisions based on that (eg instead of moving energy to Game.spawns.MyFirstSpawn they will use + +creep.room.find(FIND_MY_SPAWNS)[0] +Since by now I have only one spawn in my rooms (and all my rooms have a single energy source) that works good enough. There is no code duplication at all. Just make sure when you calculate any task targets based on the creeps position and room. I use something like + +creep.pos.findClosest(FIND_STRUCTURES... +a lot. Finding targets to get or drop energy for haulers, finding construction sites for builder or whatever, just use those room/position based finders and your code will run the same in all rooms. + +The only type of creep that needs special attention are those that move from one room to the next. Especially in the beginning I found it very helpful to have a permanent stream of creeps moving from room 1 to room 2 and helping with harvesting energy, since without extensions you can only build very small creep that do not fully harvest energy fast enough. + +They start with the second room as target hardcoded and will then move to the exit. Once they reach the exit and are in the next room I just switch the 'role' and 'task' stored in their memory. Then they are simple harvesters and their task assignment code will use above finders to search for the rooms energy source like any other harvester. + +http://support.screeps.com/hc/en-us/community/posts/201379672-How-i-can-control-second-room- +https://screeps.com/a/#!/profile/Jabberwocky diff --git a/tutorial 5-1/main.js b/tutorial 5-1/main.js new file mode 100644 index 0000000..34cd4ee --- /dev/null +++ b/tutorial 5-1/main.js @@ -0,0 +1,47 @@ +var roleHarvester = require('role.harvester'); +var roleUpgrader = require('role.upgrader'); +var roleBuilder = require('role.builder'); + +module.exports.loop = function () { + var harvesters = _.filter(Game.creeps, (creep) => creep.memory.role == 'harvester'); + console.log('Harvesters: ' + harvesters.length); + var builders = _.filter(Game.creeps, (creep) => creep.memory.role == 'builder'); + console.log('builders: ' + builders.length); + var upgraders = _.filter(Game.creeps, (creep) => creep.memory.role == 'upgrader'); + console.log('upgraders: ' + upgraders.length); + + if(harvesters.length < 1) { + var newName = Game.spawns.Spawn1.createCreep([WORK,CARRY,MOVE], undefined, {role: 'harvester'}); + console.log('Spawning new harvester: ' + newName); + } + if(builders.length < 3) { + var newName = Game.spawns.Spawn1.createCreep([WORK,CARRY,MOVE], undefined, {role: 'builder'}); + console.log('Spawning new builder: ' + newName); + } + if(upgraders.length < 1) { + var newName = Game.spawns.Spawn1.createCreep([WORK,CARRY,MOVE], undefined, {role: 'upgrader'}); + console.log('Spawning new upgrader: ' + newName); + } + var tower = Game.getObjectById('id242290'); + if(tower) { + var closestDamagedStructure = tower.pos.findClosestByRange(FIND_STRUCTURES, { + filter: (structure) => structure.hits < structure.hitsMax + }); + if(closestDamagedStructure) { + tower.repair(closestDamagedStructure); + } + + var closestHostile = tower.pos.findClosestByRange(FIND_HOSTILE_CREEPS); + if(closestHostile) { + tower.attack(closestHostile); + } + } + + for(var name in Game.creeps) { + var creep = Game.creeps[name]; + if(creep.memory.role == 'harvester') { + roleHarvester.run(creep); + } + if(creep.memory.role == 'upgrader') { + roleUpgrader.run(creep); + } \ No newline at end of file diff --git a/tutorial 5-1/role.builder.js b/tutorial 5-1/role.builder.js new file mode 100644 index 0000000..3178188 --- /dev/null +++ b/tutorial 5-1/role.builder.js @@ -0,0 +1,30 @@ +var roleBuilder = { + + /** @param {Creep} creep **/ + run: function(creep) { + + if(creep.memory.building && creep.carry.energy == 0) { + creep.memory.building = false; + } + if(!creep.memory.building && creep.carry.energy == creep.carryCapacity) { + creep.memory.building = true; + } + + if(creep.memory.building) { + var targets = creep.room.find(FIND_CONSTRUCTION_SITES); + if(targets.length) { + if(creep.build(targets[0]) == ERR_NOT_IN_RANGE) { + creep.moveTo(targets[0]); + } + } + } + else { + var sources = creep.room.find(FIND_SOURCES); + if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) { + creep.moveTo(sources[0]); + } + } + } +}; + +module.exports = roleBuilder; \ No newline at end of file diff --git a/tutorial 5-1/role.harvester.js b/tutorial 5-1/role.harvester.js new file mode 100644 index 0000000..5dbaddc --- /dev/null +++ b/tutorial 5-1/role.harvester.js @@ -0,0 +1,28 @@ +var roleHarvester = { + + /** @param {Creep} creep **/ + run: function(creep) { + if(creep.carry.energy < creep.carryCapacity) { + var sources = creep.room.find(FIND_SOURCES); + if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) { + creep.moveTo(sources[0]); + } + } + else { + var targets = creep.room.find(FIND_STRUCTURES, { + filter: (structure) => { + return (structure.structureType == STRUCTURE_EXTENSION || + structure.structureType == STRUCTURE_SPAWN || + structure.structureType == STRUCTURE_TOWER) && structure.energy < structure.energyCapacity; + } + }); + if(targets.length > 0) { + if(creep.transfer(targets[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) { + creep.moveTo(targets[0]); + } + } + } + } +}; + +module.exports = roleHarvester; \ No newline at end of file diff --git a/tutorial 5-1/role.upgrader.js b/tutorial 5-1/role.upgrader.js new file mode 100644 index 0000000..ca77c4f --- /dev/null +++ b/tutorial 5-1/role.upgrader.js @@ -0,0 +1,19 @@ +var roleUpgrader = { + + /** @param {Creep} creep **/ + run: function(creep) { + if(creep.carry.energy == 0) { + var sources = creep.room.find(FIND_SOURCES); + if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) { + creep.moveTo(sources[0]); + } + } + else { + if(creep.upgradeController(creep.room.controller) == ERR_NOT_IN_RANGE) { + creep.moveTo(creep.room.controller); + } + } + } +}; + +module.exports = roleUpgrader;