ID:147798
 
Let's start off with a little background. I have a an object grid of 5x10. These are in a list where the objects are in no particular order. The bottom left object's location is x1, y1. I'm lookng for a procedure that when I input a tx and ty value. This will move that object's location to x1+tx,y1+ty . Now I can perform this task easily but I have another problem. The objects that are being relocated can't EVER overlap. This means that I must go through the list in a specific order. This is because when this object moves it moves all other objects on its square with it. overlap could easily cause strange translocations.

Also how would I rotate this 5x10 grid 90 degrees into a 10x5 grid. Also a way to rotate it again and again would be nice :/

Also is there a way I could do this so that instead of just a 5x10 grid it would work for an arbitrarily sized grid?
Simple, check to see if the tile can be entered.

ex:

var/turf/T=locate(X,Y,Z)//Replace the X,Y,Z with the coords you want.
if(T.loc)//Checks to see if that location is accessible
src<<"<b>YEE!</b>"//If it is, you get a yee
else
src<<"<b>NEE!</b>"//If not, you get a nee
In response to Goku72 (#1)
Uh... Goku... that will always return true. =P Unless it's possible for turfs to not be inside an area, which I don't think it is. Either way, it won't work correctly.

I'd suggest looping through the list and seeing if there's already an object at the given location.

As for the rotating, this shouldn't be too hard given a little thought. Set each object's X location to its Y location, then set each object's Y location to the X size of the grid, minus its old X location (and add 1 if the minimum X location is 1 rather than 0). This should work for any size grid.
In response to Crispy (#2)
I was able to do the movement but I need to work on the rotating a bit. I understand what your saying though... Although the fact the grid is rectangular will make problems. :/

Ack having major problems. I'll have to scrap 180 degree movement and then convert it to 2 90 degrees movements. For now its not going to work because of object rtation problems :/
(parts are the parts that are being rotated. note the extra translocation to prevent ovverlap. Also however you must note that the objects are not rotsting properly. They look disjoined.)

proc/rotate(direct)
var/obj/move/origin = pick(parts) //lowerleft
for(var/obj/move/M in parts)
if((M.x<origin.x)||(M.y<origin.y))
origin = M
switch(direct)
if(90)//needs work and also the windows don't rotate properly.
var/tx = origin.x
var/ty = origin.y
var/ry
var/rx
for(var/obj/move/M in parts)
ry = M.y - ty
rx = M.x - tx
var/tz = M.z
var/turf/T = locate(rx+1,ry+1,2)
rx = -rx
for(var/atom/movable/O in M.loc)
O.dir = turn(O.dir,90)
O.loc = T
var/t = ry
ry = rx
rx = t
T = locate(rx+ty,ry+tx,tz)
for(var/atom/movable/O in M.loc)
O.loc = T
if(180)
var/ty = origin.y
var/ry
for(var/obj/move/M in parts)
ry = M.y - ty
ry = -ry
var/turf/T = locate(M.x,ty+ry,M.z)
for(var/atom/movable/O in M.loc)
O.dir = turn(O.dir,180)
O.loc = T
if(270)
var/tx = origin.x
var/ty = origin.y
var/ry
var/rx
for(var/obj/move/M in parts)
ry = M.y - ty
rx = M.x - tx
var/tz = M.z
var/turf/T = locate(rx+1,ry+1,2)
rx = -rx
for(var/atom/movable/O in M.loc)
O.dir = turn(O.dir,90)
O.loc = T
var/t = ry
ry = rx
rx = t
T = locate(rx+ty,ry+tx,tz)
for(var/atom/movable/O in M.loc)
O.loc = T
If you translate or rotate the objects, they will never end up overlapping each other unless they were overlapping each other to begin with. For each object in the list, you should first check to see if it can be moved to its destination ignoring other objects in that same list, and only being concerned about other objects that would block its movement. If each object can be moved, then go ahead and move all of them. You shoudl just mark the objects at a given tile so they know what object in the grid they are assigned to. That way it doesn't matter what order you move them in. I think it'd be easier and more efficient to do that than to find a way to move the objects so that no two of them ever overlap.