robotarmyfactorio
robotarmyfactorio copied to clipboard
Bug with ungenerated chunks
Like already mentioned on the forum, there is a bug wth ungenerated chunks and the mod trying to access them. I´ve redone some of the code and now the bots head back towards the middle if they sense an ungenerated chunk and request chunkgeneration if they get to close to them (security code in case of a missing chunk on their way back) here´s the code I added after the charting code
chunkposition = {x=math.floor(position.x/32+0.5), y=math.floor(position.y/32+0.5)}
xp=-4
while xp < 5 do
yp=-4
while yp < 5 do
if not game.surfaces[1].is_chunk_generated(chunkposition) then
if yp < 2 and yp > -2 and xp < 2 and xp > -2 then
game.surfaces[1].request_to_generate_chunks(position, 128)
game.players[1].print("Generated new Chunks at " .. position.x .. ", " .. position.y)
end
local goal = {x=0,y=0}
if position.x > 0 then goal.x = position.x -150 else goal.x = position.x + 150 end
if position.y > 0 then goal.y = position.y -150 else goal.y = position.y + 150 end
squad.unitGroup.set_command({type=defines.command.go_to_location, destination=goal, distraction=defines.distraction.none})
xp=5
yp=5
end
yp=yp+1
end
xp=xp+1
end
Good luck with further development
Hi, thanks for this! I will consider integrating it to the mod. The situation where they try to path into an ungenerated chunk is super rare, and the devs have made it impossible for a "move" command to be successfully issued into an ungenerated chunk too. I suppose it could happen if they are walking around at the edge of the generated map while fighting biters, but it might be different code to handle that.
This part "if not game.surfaces[1].is_chunk_generated(chunkposition)" is the most important, i might use this in other areas of the code if I don't end up using this entire snippet
I´m glad I could help. But be careful if you´re only using them generation code as it might lead to a very big save in a matter of hours.