ID:1410477
 
(See the best response by Super Saiyan X.)
Code:
/proc/holocopy (var/area/from_area, var/area/to_area, delay)
var/fmx = world.maxx
var/fmy = world.maxy
var/tmx = world.maxx
var/tmy = world.maxy
var/fmax = 0
var/fmay = 0
var/fz = 0
var/tz = 0
for (var/turf/T in from_area)
if (T.x < fmx) fmx = T.x
if (T.y < fmy) fmy = T.y
if (T.x > fmax) fmax = T.x
if (T.y > fmay) fmay = T.y
fz = T.z

for (var/turf/T in to_area)
if (T.x < tmx) tmx = T.x
if (T.y < tmy) tmy = T.y
tz = T.z

var/flx = fmax - fmx //Fmax >= fmx, guarented
var/fly = fmay - fmy

//First. We have to copy turfs immediately.
for (var/xx=0,xx<=flx,xx++)
for (var/yy=0,yy<=fly,yy++) //XX, YY - offset from FMX, TMX and FMY, TMY respectively.
var/turf/FT = locate(fmx + xx, fmy + yy, fz) //From_zone Turf
var/turf/TT = locate(tmx + xx, tmy + yy, tz) //To_zone Turf
if (FT && TT) //Sanity
if (FT in from_area && TT in to_area)
var/turf/X = new FT.type(TT)
for(var/V in FT.vars)
if(!(V in list("type","loc","locs","vars", "parent", "parent_type","verbs","ckey","key","x","y","z")))
X.vars[V] = FT.vars[V] //From DuplicateObject


Problem description:
So. I can't understand why it never passes through
if (FT in from_area && TT in to_area)


It must get a turf on coordinates X,Y,Z and check that the turf is inside from_area. But i can't understand why none of them don't pass through this check. Maybe the problem inside locate?

P.S. There's an another similar procedure in that game, but it's the way more laggier. While that procedure should take xl*yl operations, another one takes (xl*yl)^2.
Best response
when using the in operator, you should enclose each statement in it's own parenthesis - the in operator has one of the lowest orders.

so if((bleh in area)&&(bleh2 in area2))
Why are you looping through all the turfs twice? I don't know how this will actually be used in your game, but I would think you only need three points. You need two corners of the original area, and then one corner of the destination. Then copy each one as you loop through the original area:

/proc/holocopy (turf/from1, turf/from2, turf/destination, delay)

var/x_offset = destination.x - from1.x
var/y_offset = destination.y - from1.y
var/turf/cursor = null

for (var/turf/T in block(from1, from2)
cursor = locate(T.x + x_offset, T.y + y_offset, destination.z) //To_zone Turf
if (cursor) //Sanity
var/turf/new_turf = new T.type(cursor)
for(var/V in T.vars)
if(!(V in list("type","loc","locs","vars", "parent", "parent_type","verbs","ckey","key","x","y","z")))
new_turf.vars[V] = T.vars[V] //From DuplicateObject
I've just rewritten that. It starts to pass through.

<quote>when using the in operator, you should enclose each statement in it's own parenthesis - the in operator has one of the lowest orders.</quote>
Thanks. I would never think that the problem caused by that.

Magicsofa, i understood that i just made a bicycle "Block"
Rewritten.

<code>
/proc/DOb(var/atom/alpha, var/turf/place)
if (isturf(place))
var/atom/beta = new alpha.type(place)
for(var/V in beta.vars)
if(!(V in list("type","loc","locs","vars", "parent", "parent_type","verbs","ckey","key","x","y","z", "contents")))
beta.vars[V] = alpha.vars[V]
return beta

/proc/holocopy (var/area/from_area, var/area/to_area, delay)
var/fmx = world.maxx
var/fmy = world.maxy
var/tmx = world.maxx
var/tmy = world.maxy
var/fmax = 0
var/fmay = 0
var/fz = 0
var/tz = 0
for (var/turf/T in from_area)
if (T.x < fmx) fmx = T.x
if (T.y < fmy) fmy = T.y
if (T.x > fmax) fmax = T.x
if (T.y > fmay) fmay = T.y
fz = T.z

for (var/turf/T in to_area)
if (T.x < tmx) tmx = T.x
if (T.y < tmy) tmy = T.y
tz = T.z

var/x_off = tmx - fmx
var/y_off = tmy - fmy

for (var/turf/FT in block(locate(fmx,fmy,fz), locate(fmax,fmay,fz)))
var/turf/TT = locate(FT.x + x_off, FT.y + y_off, tz) //To_zone Turf
if (FT && TT) //Sanity
if ( (FT in from_area) && (TT in to_area) )
DOb(FT, TT)

for (var/turf/FT in block(locate(fmx,fmy,fz), locate(fmax,fmay,fz)))
var/turf/TT = locate(FT.x + x_off, FT.y + y_off, tz) //To_zone Turf
if (FT && TT) //Sanity
if ( (FT in from_area) && (TT in to_area) )
for (var/obj/alpha in FT)
DOb(alpha, TT)

for (var/mob/living/alpha in FT)
DOb(alpha, TT)
sleep(delay)
</code>