ID:1378938
 
(See the best response by Lige.)
Hey guys, I've been trying this for some time now.. I re-wrote this part 2 times now, but it never did work.. I made an asteroid generator some time ago, but the code was lost on a wipe.. Poor me, I don't recall how I did it.

CODE:
world/proc/GenerateField(var/density, var/list/tiles = list(), var/turf/picked)
set background = 1
if(!density) density = 50
spawn(0)
for(var/turf/T in world)
tiles.Add(T)
while(density > 0)
for(var/turf/TU in tiles)
picked = pick(TU)
for(var/turf/O in orange(rand(2, 4), picked))
if(prob(75))
var/turf/asteroid/AS = new(picked.loc)
AS.desc = AS.desc
density--


There's the code I have right now, when I try this, it tells me I'm using a "Bad loc"..

Any idea what I'm doing wrong here?

It could be because the tile has no loc inside the list? Such as the tiles have no defined loc because they haven't been put on the map or had a loc location initilised for that turf?
Remove .loc from picked.

var/turf/asteroid/AS = new(picked)
In response to Lige
Lige wrote:
Remove .loc from picked.

> var/turf/asteroid/AS = new(picked)


Compiles, no more errors.. Althrough no matter howmany times I activate the proc, nothing seems to be happening.
Under the tiles new () did you specify a place for the new object to be placed?
In response to Akando5959
Akando5959 wrote:
Under the tiles new () did you specify a place for the new object to be placed?

That was where the picked.LOC was for, but I think I have misread what that is used for.
In response to Laser50
Best response
The issue:

for(var/turf/TU in tiles)
picked = pick(TU)


It should be:

picked = pick(tiles)
Oh, well that makes a whole lot of sense! Damn it. Coding at 11 PM isn't working out too well for me..

Any way, I got it working, thanks, guys!

So, I'm going to bump up this thread, for a second problem I've been thinking about for a day or so now..
This is how my asteroids look... So far:
http://puu.sh/4wS4X.png

My problem however, is with the one-tile floors, floating about in space, so well, as simple as it is, I'm trying to remove them..

The code, I wrote just now:
world/proc/RemoveBadAstTiles()
set background = 1
world << "Check1"
for(var/turf/asteroid/A in world)
world << "Check2"
for(var/directions in cardinal)
world << "Check3"
var/turf/asteroid/AS
if(locate(AS in get_step(A, directions)))
world << "Check4"
del(AS)


Appears to be the best solution, althrough.. It does not delete.. I'd love some help on this one. I've been trying for quite some time now, and it seems so simple..
(cardinal is a list containing NORTH, WEST, SOUTH, EAST, by the way.)
var/turf/asteroid/AS
world << "Check2"
for(var/directions in cardinal)
AS = locate(get_step(A,directions))
world << "Check3 dir = [directions] AS = [AS?"Found":"Not found"]"
if(istype(AS))
world << "Check4"
del(AS)


You had the right idea. Try this.
world/proc/RemoveBadAstTiles()
set background = 1
world << "Check1"
for(var/turf/asteroid/A in world)
var/turf/asteroid/AS
world << "Check2"
for(var/directions in cardinal)
AS = locate(get_step(A,directions))
world << "Check3 dir = [directions] AS = [AS?"Found":"Not found"]"
if(istype(AS))
world << "Check4"
del(AS)


End up on this, deleting A removes.. Well.. All asteroids, and deleting AS does.. Practically nothing.
Of course, as retarded as I am, I may have mis-implemented your code.
Sorry, I fundamentally misread what you wanted.

world/proc/RemoveBadAstTiles()
RemoveBadAstTiles:
for(var/turf/asteroid/A in world)
var/list/nearbyturfs = block(locate(min(A.x+1,world.maxx),min(A.y+1,world.maxy),A.z),locate(max(A.x-1,world.maxx),max(A.y-1,world.maxy),A.z))
//Version for cardinal directions only
// var/list/nearbyturfs = list()
// for(var/dirs in cardinal)
// nearbytufs += get_step(A,dirs)
//You could then jump right to the istype if you wanted
for(var/turf/asteroid/A2 in nearbyturfs)
if(istype(A2))
continue RemoveBadAstTiles
del(A) //Should only reach this point if we didn't find any neighbors.
Wait, you're trying to kill those asteroid turfs that are off in space alone?

Try something like this maybe.

world/proc/RemoveBadAstTiles()
set background = 1

var/turf/asteroid/current = null
var/turf/asteroid/neighbor = null
var/list/neighborhood = null
var/list/checked = list()
var/neighbors = 0
var/deleted = 0

world << "entered RemoveBadAstTiles()"

for(current in world)
world << "checking [current] at [current.x]-[current.y]-[current.z]"

if (current in checked)
world << "previously saw [current] as neighbor"
continue

neighborhood = orange(1, current)
neighbors = 0

for (neighbor in neighborhood)
world << "found neighbor at [neighbor.x]-[neighbor.y]-[neighbor.z]"
checked += neighbor
neighbors++

world << "[neighbors] neighbor(s). [neighbors ? "Skipping" : "Deleting"].
if (!neighbors)
del(current)
deleted++

world << "exiting RemoveBadAstTiles(), [deleted] deleted"
Your code works perfect, MagicMountain, however it's not quite done yet, orange checks all 8 turfs around it, but I need it to check just the 4 basic ones. Which seems to be the complicated thing right now..
oh, why just the basic? doesn't orange catch all the tiles you wanted?

well, lets see. give me a moment, i'll edit the above post

actually I'll edit here in case someone wants to see the difference

world/proc/RemoveBadAstTiles()
set background = 1

var/turf/asteroid/current = null
var/turf/asteroid/neighbor = null
var/list/checked = list()
var/neighbors = 0
var/deleted = 0
var/direction = 0

world << "entered RemoveBadAstTiles()"

for(current in world)
world << "checking [current] at [current.x]-[current.y]-[current.z]"

if (current in checked)
world << "previously saw [current] as neighbor"
continue

neighbors = 0

for (direction in cardinal)
neighbor = get_step(current, direction)
if (istype(neighbor))
world << "found neighbor at [neighbor.x]-[neighbor.y]-[neighbor.z]"
checked += neighbor
neighbors++

world << "[neighbors] neighbor(s). [neighbors ? "Skipping" : "Deleting"].
if (!neighbors)
del(current)
deleted++

world << "exiting RemoveBadAstTiles(), [deleted] deleted"
Orange also catches the tiles that are only connected by corner, so to speak. And leaves them as OK.. Which, they aren't. Getting only cardinal directions allows me to get rid of every "wrong" tile there is.
Ohh, duh. I'm coder.


edit: okay, i think i got all the bugs out of it. maybe. we'll get you there!
Tried this approach already, a few times.
End result never changes:

http://puu.sh/4xtZI.png

It just won't find anything.
Hmm... try it without the locate() around get_step()?


edit vvv nice! I'll edit my post to fix that error, glad it worked out. Cheers :)
And there we go, it's all functional!
Thanks, man. Now I can continue other stuff, rather than these damn asteroids all day long :)