Script for adding extensions to Spawn
-
Hello, I am new to this forum and to Screeps. And I was not sure if this post belongs to the Help catagory or not.
Anyway I want my creeps to be able to add extensions to any spawn. My idea was to make a method that I can add to all spawns called 'addExtension'. So when I call
Game.spawns['Spawn1'].addExtension
a construction site would be placed. But I am not sure how to program this. I want the extensions to be placed in a checker pattern around the spawn. I guess the method should just go over all tiles in that checker pattern till it finds an empty space.I hope somebody can help me with this or tell me how else I should do it
Edit: http://rein.ga/i/jHgW4.png Kind of how it should look but made from the inside out
-
Structures placement is a hot and hard topic. A lot of players just do it manually, other have complex algorithms spreading over several ticks to find the best "room layout".
My tip for a generic placement:
- List the potentials positions (ie: all plain or swamp tiles of the room).
- Remove tiles which don't fit some arbitrary rules (ie: in your case, filter all tiles where
(x + y) % 2 === 0
which will create a checker pattern) - Score the remaining tile based, for example, on distance and keep the best one (ie: use
(pos) => spawn.pos.getRangeTo(pos)
function to score and keep the minimum).
-
@hiryus After some trial and effort I got my spawns happily adding extensions if there aren't enough yet. Can't thank you enough.