ID:1890933
 
(See the best response by MisterPerson.)
Code:


Problem description:

What i need is an algorithm to select an area based on two points ( Ex.. Northeast, southwest corner, of a box) and make a copy of every atom inside those two points, then place the copies elsewhere on the map.

Example, if i selected a plot of land with a structure on my map, and copied it, i would then be able to paste an exact copy of that house, somewhere of my choosing on the map.

The problem i face is that i cannot think up a way to execute this, would anybody be willing to make a sample, or show me how to write code that would be able to perform such commands?


Thank you for your time.

Best response
You can use block() to grab all the turfs. Then for each turf, copy the turf and everything on it, set nearly all the vars of the copies to the same as the old, and then put the copies where they need to go.

The var copying is the most advanced part, but you'll want to do something like

for(var/allvars in original.vars)
if(issaved(original.vars[allvars])
copy.vars[allvars] = original.vars[allvars]
Hey, how are u?

So I think u want something like this:
mob/Player/var/tmp/list/Copied = list()

mob/Player/var/tmp/list/POSITION_X = list()
mob/Player/var/tmp/list/POSITION_Y = list()


mob/Player/proc/Copy(radius as num)
for(var/obj/a in orange(radius))

Copied.Add(a)
POSITION_X.Add(a:x - src.x)
POSITION_Y.Add(a:y - src.y)



mob/Player/proc/Paste()
var/LENGTH = length(POSITION_X)
if(LENGTH <> 0)
for(var/i =1, i<= LENGTH, i++)

var/A =Copied[i]

var/X = src.x + POSITION_X[i]
var/Y= src.y + POSITION_Y[i]

new A:type(locate(X,Y,src.z))


Copied = list()
POSITION_X = list()
POSITION_Y = list()


Now lets discuss the code that I wrote:

the first question that u may come up with is "Why the heck did he wrote a for loop that only goes through objects (in the copy proc)?" Well, you can change that if u want but i strongly advise u to be careful. Because if you paste turfs on top of turfs then the older turf will be deleted. Also copying mobs won't bring any good (specially client mobs).

So the copy proc will simply store all the objs that are in a radius of X . The position_x and position_y lists will store the distance that the object if from the player.

The paste proc will instantiate each object that you copied and will adjust its position (this is when the position_X and position_y lists join the party). So the position of the copied object will correspond to the player position on the x/y axis plus the position_X/Y list value that corresponds to the initial difference between the position of the client and the object being copied.

Any questions?
Hug,
,Misty
You know to me it sounds,
That the function you need is bounds()
In so many words
Use 2 sets of coords
And boom, copy everything on those grounds.

In response to Lugia319
Nice shortcut but I think his biggest issue is creating a copy of the atoms rather than a reference to pre-existing atoms.

Unfortunately BYOND to my knowledge doesn't come with a built in method for cloning datums.
I think the SwapMaps library can greatly help you here.
In response to Lugia319
Lugia319 wrote:
You know to me it sounds,
That the function you need is bounds()
In so many words
Use 2 sets of coords
And boom, copy everything on those grounds.

Mmm, try "all" instead of "everything". Fits the meter better.