Is creating new surfaces implemented?
Posted: Mon Jan 04, 2016 1:48 pm
I've looked around and it looks like adding surfaces isn't implemented yet, although the wiki says something about an API. Can I make another surface, and if so how?
https://forums.factorio.com/wiki/inde ... te_surfacememcallen wrote:I've looked around and it looks like adding surfaces isn't implemented yet, although the wiki says something about an API. Can I make another surface, and if so how?
That's currently not possible at surface creation in 0.12. It's something I want to add to 0.13 but we'll see if time allows it.memcallen wrote:How did I miss that? I even looked at merge forces...
How can I change what tiles are used and which ores are created when generating the surface?
There's no non script way to do anything with surfaces at this pointorzelek wrote:Find a mod called underground - it made it work from what I seen. A least a bit - I'm missing some nice non script way to transfer materials to different surface to make it really possible.
Enjoy the most hackiest code i have made for Factorio:Rseding91 wrote:That's currently not possible at surface creation in 0.12. It's something I want to add to 0.13 but we'll see if time allows it.memcallen wrote:How did I miss that? I even looked at merge forces...
How can I change what tiles are used and which ores are created when generating the surface?
For now, you would need to use on_chunk_generated and set entities/tiles to what you want.
Code: Select all
--First place down the markers in as big of an area as possible
distBetween = 30
function placeMarkers()
for x = 1, 200 do
xPos = (x-100) * distBetween
for y = 1, 200 do
game.surfaces["theUnderground"].create_entity({name = "marker", position = {xPos, (y - 100) * distBetween}, force = game.forces.player})
end
end
end
--Find those chests and if its closer than 50 tiles then change all the tiles in its space to the new tiles
searchDist = 150
function changetiles2()
chestsFound = {}
tiles = {}
lamps = {}
found = 0
--Change the tiles
results = game.surfaces["theUnderground"].find_entities_filtered{area = {{game.players[1].position.x -searchDist, game.players[1].position.y -searchDist}, {game.players[1].position.x +searchDist, game.players[1].position.y +searchDist}}, name= "marker"}
for d,ent in pairs(results) do
if ent.position ~= nil then
chestsFound[d] = ent.position
found = found + 1
ent.destroy()
end
end
for n = 1, found do
--if ent ~= nil then
if chestsFound[n] ~= nil then
for x = 1, 30 do
xPos = chestsFound[n].x + x - 2
for y = 1, 30 do
yPos = chestsFound[n].y + y - 2
--If it collides with a player turn it into lava if not turn it to lavaStone
if game.surfaces["theUnderground"].get_tile(xPos, yPos).collides_with("player-layer") then
--game.players[1].print("yes!")
table.insert(tiles, {name = "lava", position = {xPos, yPos}})
if y == 7 and x == 7then
table.insert(lamps, {xPos, yPos})
elseif y == 14 and x == 14then
table.insert(lamps, {xPos, yPos})
elseif y == 21 and x == 21 then
table.insert(lamps, {xPos, yPos})
elseif y == 28 and x == 28 then
table.insert(lamps, {xPos, yPos})
end
else
table.insert(tiles, {name = "lavaStone", position = {xPos, yPos}})
end
end
end
--ent.destroy()
--end
end
end
if found > 0 then
game.surfaces["theUnderground"].set_tiles(tiles)
newLamp(lamps)
end
--Remove the trees and change rocks to
results = game.surfaces["theUnderground"].find_entities_filtered{area = {{game.players[1].position.x -searchDist, game.players[1].position.y -searchDist}, {game.players[1].position.x +searchDist, game.players[1].position.y +searchDist}}, type = "tree"}
for d,ent in pairs(results) do
ent.destroy()
end
results = game.surfaces["theUnderground"].find_entities_filtered{area = {{game.players[1].position.x -searchDist, game.players[1].position.y -searchDist}, {game.players[1].position.x +searchDist, game.players[1].position.y +searchDist}}, name = "stone-rock"}
for d,ent in pairs(results) do
game.surfaces["theUnderground"].create_entity({name = "lava", position = ent.position})
game.surfaces["theUnderground"].create_entity({name = "fake-pole", position = ent.position})
game.surfaces["theUnderground"].create_entity({name = "fake-battery", position = ent.position})
if game.surfaces["theUnderground"].count_entities_filtered{area = {{ent.position.x-25, ent.position.y-25}, {ent.position.x+25, ent.position.y+25}}, name= "opening"} == 0 then
if game.surfaces["theUnderground"].get_tile(ent.position.x+10, ent.position.y+10).name == "lavaStone" then
--game.surfaces["theUnderground"].create_entity({name = "shadow-spawner", position = {ent.position.x+10, ent.position.y+10}})
end
if game.surfaces["theUnderground"].get_tile(ent.position.x+10, ent.position.y).name == "lavaStone" then
--game.surfaces["theUnderground"].create_entity({name = "shadow-spawner", position = {ent.position.x+10, ent.position.y}})
end
end
ent.destroy()
end
end
Code: Select all
{
type = "container",
name = "marker",
icon = "__base__/graphics/icons/iron-chest.png",
flags = {"placeable-neutral", "player-creation"},
minable = {mining_time = 1, result = "marker"},
max_health = 100,
corpse = "small-remnants",
open_sound = { filename = "__base__/sound/metallic-chest-open.ogg", volume=0.65 },
close_sound = { filename = "__base__/sound/metallic-chest-close.ogg", volume = 0.7 },
resistances =
{
{
type = "fire",
percent = 80
}
},
collision_box = {{-0.35, -0.35}, {0.35, 0.35}},
selection_box = {{-0.5, -0.5}, {0.5, 0.5}},
fast_replaceable_group = "container",
inventory_size = 32,
vehicle_impact_sound = { filename = "__base__/sound/car-metal-impact.ogg", volume = 0.65 },
picture =
{
filename = "__base__/graphics/entity/iron-chest/iron-chest.png",
priority = "extra-high",
width = 48,
height = 34,
shift = {0.2, 0}
}
},
Code: Select all
script.on_event(defines.events.on_chunk_generated, function(event)
--local caves = game.surfaces.Caves
local area = event.area
local entitiesSpawned = game.surfaces["nauvis"].find_entities{{area.left_top.x, area.left_top.y}, {area.right_bottom.x, area.right_bottom.y}}
for _,v in pairs(entitiesSpawned) do
message("Found a: "..v.type)
local destroyed = false
if(v.type == "resource" or v.type == "decorative") then
v.destroy()
message("Removed it :P")
destroyed = true
end
if (destroyed == false) then
if(v.type == "tree") then
v.destroy()
end
end
end
end)
Code: Select all
game.surfaces["theUnderground"].create_entity({name = "lava", position = v.position})
Rseding91 wrote:That's currently not possible at surface creation in 0.12. It's something I want to add to 0.13 but we'll see if time allows it.memcallen wrote:How did I miss that? I even looked at merge forces...
How can I change what tiles are used and which ores are created when generating the surface?
For now, you would need to use on_chunk_generated and set entities/tiles to what you want.
Code: Select all
--First place down the markers in as big of an area as possible
function placeMarkers()
local distBetween = 30
local surface = game.surfaces["theUnderground"]
local force = game.forces.player
local xPos
for x = 1, 200 do
xPos = (x-100) * distBetween
for y = 1, 200 do
surface.create_entity({name = "marker", position = {xPos, (y - 100) * distBetween}, force = force})
end
end
end
--Find those chests and if its closer than 50 tiles then change all the tiles in its space to the new tiles
function changetiles2()
local searchDist = 150
local results
local xPos, yPos
local chestsFound = {}
local tiles = {}
local lamps = {}
local found = false
local surface = game.surfaces["theUnderground"]
local position = game.players[1].position
local lampOffsets = {
[7] = {[7] = true},
[14] = {[14] = true},
[21] = {[21] = true},
[28] = {[28] = true}
}
--Change the tiles
results = surface.find_entities_filtered{area = {{position.x -searchDist, position.y -searchDist}, {position.x +searchDist, position.y +searchDist}}, name= "marker"}
for d,ent in pairs(results) do
table.insert(chestsFound, ent.position)
ent.destroy()
found = true
end
for k,chest in pairs(chestsFound) do
for x = 1, 30 do
xPos = chest.x + x - 2
for y = 1, 30 do
yPos = chest.y + y - 2
--If it collides with a player turn it into lava if not turn it to lavaStone
if surface.get_tile(xPos, yPos).collides_with("player-layer") then
--game.players[1].print("yes!")
table.insert(tiles, {name = "lava", position = {xPos, yPos}})
if lampOffsets[x] ~= nil and lampOffsets[x][y] ~= nil then
table.insert(lamps, {xPos, yPos})
end
else
table.insert(tiles, {name = "lavaStone", position = {xPos, yPos}})
end
end
end
end
if found then
surface.set_tiles(tiles)
newLamp(lamps)
end
--Remove the trees and change rocks to
results = surface.find_entities_filtered{area = {{position.x -searchDist, position.y -searchDist}, {position.x +searchDist, position.y +searchDist}}, type = "tree"}
for k,entity in pairs(results) do
entity.destroy()
end
results = surface.find_entities_filtered{area = {{position.x -searchDist, position.y -searchDist}, {position.x +searchDist, position.y +searchDist}}, name = "stone-rock"}
for k,entity in pairs(results) do
local entityPosition = entity.position
entity.destroy()
surface.create_entity({name = "lava", position = entityPosition})
surface.create_entity({name = "fake-pole", position = entityPosition})
surface.create_entity({name = "fake-battery", position = entityPosition})
end
end
Wow i guess that is one really big difference o_0!Rseding91 wrote:This is untested but until 0.13.0 (or when ever we get around to adding support for creation-time tile definitions) this should run orders of magnitude faster in replacing tiles:
On chunk generated would work, but when I created that tile changer code I did not know about it so I used the markers. It should be simple to instead use the on chunk generated eventorzelek wrote:Can one of you post simple explanation why those marker chests are required?
Wouldn't normal on_chunk generated work to replace the tiles ?