Jump to content

Spawning prefabs on water during worldgen


Malacath

Recommended Posts

Well, this is basically my problem here... I want to spawn prefabs on impassible ground during worldgen which is apparently not possible right now. So in an attempt to find out what causes this issue I went ahead and searched for any clues of where this is happening, and after sifting through ~2000 lines of code I was getting rather tired. I strongly recommend that noone tries that, your sanity is to worthy  ; )

 

So this question is directed more to Cheerio since he has more insight into how worldgen works, but if anyone else has a workaround to it I'd love to hear it of course. Just please don't tell me to spawn every prefab seperately, that already is my last resort. Since there are about 200 such prefabs I would prefer not to do that though.

 

Long story short:

Where is the piece of code that prevents worldgen spawns on water? And can I easily manipulate that?

Link to comment
Share on other sites

I don't think you can do that at worldgen. Prefab spawning is only done in rooms, and the impassible ground is placed at the complement of the union of the rooms. ;P

You could spawn them right after worldgen, though... But what's your goal, here? Are they just aesthetical prefabs?

Link to comment
Share on other sites

I don't think you can do that at worldgen. Prefab spawning is only done in rooms, and the impassible ground is placed at the complement of the union of the rooms. ;P

You could spawn them right after worldgen, though... But what's your goal, here? Are they just aesthetical prefabs?

I have my static layout in made in Tiled and added water there so it is specifically wished for there and not just added where stuff is missing. On these tiles I added prefabs which are basically ambient prefabs, such as lightsources and my tests show that those that are on impassible ground will not be spawned whereas those on normal ground will.

Link to comment
Share on other sites

  • Developer

Unfortunately that part of the code is not as modder friendly as I would like.

 

Did you try removing forest_map.lua lines 499-510? That is where we go though all the entities and remove any that are over the impassible ground type.

 

As for how to modify it in a mod, it might not be so easy.

Link to comment
Share on other sites

Malacath, please don't override forest_map.lua, since that would affect the logic of every mod dealing with worldgen (and it would also affect vanilla survival/adventure/caves).

You could do a temporary swap of forest_map.lua's, though. If you put it in temp_override/map/forest_map.lua, then upon detecting your level being generated within modworldgenmain.lua you could do

_G.package.path = ("%stemp_override/?.lua;"):format(MODROOT) .. _G.package.path
Link to comment
Share on other sites

Unfortunately that part of the code is not as modder friendly as I would like.

 

Did you try removing forest_map.lua lines 499-510? That is where we go though all the entities and remove any that are over the impassible ground type.

 

As for how to modify it in a mod, it might not be so easy.

I've never seen your face  o.o  Nice to meet you ^^

 

Actually I haven't looked into this file. I got stuck at "graphnode.lua" in lines 91-94 in function Node:AddEntity whihc I probably totally misunderstood  xD

 

So, thank you for pointing me in that direction! I see a local function there, the bane of all modders  ^^

I'll try to get something working that isn't gamebreaking, if not I guess I'll really convert my layout to a proper table of prefabs and their coordinates and put them where I want one by one.

 

 

Malacath, please don't override forest_map.lua[...]

How could I  ^^  Seriously, you should know I that I'm beyond the point of overriding any vanilla files, you hurt my feelings... jk  ; P

The only thing I would try is somehow modifying it in a way to make an exception for my prefabs, which will probably not happen since it's a local function, and even a really big one.

Even your idea of swapping the file seems to dangerous for me since I'm not 100% certain I know what it does. So in case I don't find a better solution (I understand) I will go for the table-one as roughly outlined above.

 

EDIT: For anyone who's interested, the following prefab will do the job if placed at the exact center of the Tiled map

local function fn(Sim)	local inst = CreateEntity()	local trans = inst.entity:AddTransform()	local static_layout = require "map/static_layout"	local Get = static_layout.Get	local layout = Get("map/static_layouts/my_layout")	inst:DoTaskInTime(0, function()		local x, y, z = trans:GetWorldPosition()		for prefab, entries in pairs(layout.layout) do			if prefab == "my_prefab" then  --Add any checks here you want for other prefabs				for _, properties in pairs(entries) do					local spawn = SpawnPrefab(prefab)					if spawn then						spawn:DoTaskInTime(0, function()							local newx = x + properties.x * 4							local newz = z + properties.y * 4							spawn.Transform:SetPosition(newx, y, newz)						end)					end				end			end		end	end)	inst:DoTaskInTime(1, inst.Remove)	return instendreturn Prefab("common/on_impassible_spawner", fn)

Alternatively you can of course spawn all things on impassible ground by checking for the ground type at the coordinates of each prefab inside the layout but that wasn't more simple for my needs.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...