ID:196878
 
(See the best response by DarkCampainger.)
Dream Maker has a map editor feature which allows you to overlay turfs on top of each other. I have been trying to replicate this with code but I can't really figure it out...

turf
base
New(loc)
var/icon/ic = image(loc)
..()
src.underlays += ic

turf
base
New(loc)
src.underlays += loc
..()


Any ideas?
Ever thought of making a new turf?
turf
turf1
icon = 'amg'
New(mob/M)
src.loc = M.loc
turf2
icon = 'amg2'
New(mob/M)
src.loc = M.loc

mob/proc
Createturf(turfz)
if(turfz = "amg")
new /turf/turf1(src)
if(turfz = "amg2")
new /turf/turf2(src)

Only one turf can exist at any given location.
I am trying to take two turfs fit into one location like the map editor does it (technically it takes the old turf, places it as an underlay to the new turf). This is described somewhere in the reference, but there's no way (that I know of) to do it with code.
Best response
By the time New() is called, the new turf has already been placed on the map, replacing the previous turf. You'll have to write a global process to insert it.

proc
// Creates turf of 'type' at loc 'oldTurf', adding 'oldTurf' as underlay
insertTurf(turf/oldTurf, type)
if(!isturf(oldTurf))
CRASH("'[oldTurf]' is not a valid turf to insert over!")
if(!ispath(type, /turf))
CRASH("Bad turf path '[type]'!")

// Create a list of the old turf's image and overlays
var/list/setUnderlays = list()
setUnderlays.Add(
oldTurf.overlays,
image(icon=oldTurf.icon, icon_state=oldTurf.icon_state, dir=oldTurf.dir, layer=oldTurf.layer),
oldTurf.underlays)

// Create the new turf
var/turf/newTurf = new type(oldTurf)

// Add the old turf and its overlays as underlays
newTurf.underlays.Add(setUnderlays)


Note that this example doesn't handle complex layering very well, especially float layering. So long as the layer is defined (or overlays aren't used), it should be fine, though. You could also put the old turf's overlays into the new turf's overlays (right now they go into underlays), if that works for your application (ie you want the old overlays to be above the inserted turf).
I didn't think to do that. Very awesome, Thank you so much!