#define DEBUG
icon = 'Grass.dmi'
icon_state = ""
autojoining = 1
icon = 'Grass.dmi'
icon_state = "Grass"
autojoining = 1
set src in oview()
icon = 'Shallows.dmi'
icon_state = ""
autojoining = 1
set src in oview()

var/Generator/g = new()

view = "20x20"

Percent_Water = 70
Mountain_Chance = 80
Grass_Chance = 80
Tiaga_Seeds = 12
Forest_Seeds = 12
Desert_Seeds = 8
Tundra_Seeds = 4
ResizeAndOceanize(var/MaxX=100, var/MaxY=100)
world.maxx = MaxX
world.maxy = MaxY
for(var/turf/t in world)
t = new /turf/Ocean/(locate(t.x, t.y, t.z))
for(var/turf/t in world)
//Seperate file
Generator/proc/ContinentPass(var/PercentSeeds=0.32, var/PercentLand = 32)
var/TotalTurfs = world.maxx * world.maxy //get the total tiles in the world
var/list/SeedTurfs = list() //the list of seed turfs
Seeds = round((TotalTurfs*PercentSeeds)/100) //Gets the percent of the world that are seed turfs
if(Seeds < 1) Seeds = 1 //Minimum of one seed per world generation
var/mob/ContinentMaker = new() //The mob we will be moving around to make the seeds
var/LandCurrent = 0 //Current land tile count
for(var/i = 0, i < Seeds, i++) //For each seed
var/tries = 0//Number of tries before giving up on this paticular seed
Retry: //Retry lable
if(tries < 10) //Check try count
ContinentMaker.loc = locate(rand(1,world.maxx), rand(1,world.maxy), 1) //get a random loc
if(ContinentMaker.loc == typesof("/turf/MGrass/")) //if the loc is already an mgrass
tries++ //increase try count
goto Retry //goto retry
else //Failed try count
continue //Give up on this seed, try the next
var/turf/toEdit = ContinentMaker.loc //Get the tile we will edit
toEdit = new /turf/MGrass/(ContinentMaker.loc) //Edit the tile, turning it into a /turf/MGrass/ tile
SeedTurfs += toEdit //add it to the list of seed turfs
LandCurrent++ //add one to the land count
del(ContinentMaker) //cleanup, removes the continent maker
world << "[LandCurrent] : [Seeds]" //debug purposes only, make sure the landcurrent var equals the seeds var
var/LandMax = 0 //variable declaration for the maximum number of land tiles
var/LandMin = 0 //variable declaration for the minimum number of land tiles
LandMax = round(TotalTurfs * ((PercentLand+1) / 100))-1 //set the maximum number of land tiles to one percent above minus one tile
LandMin = round(TotalTurfs * ((PercentLand-1) / 100))+1 //set the minimum number of land tiles to one percent below pluss one tile
if(LandMax < Seeds) LandMax = Seeds+1 //checks if the landmax is lower then seeds, and sets above if neccessary
if(LandMin < Seeds) LandMin = Seeds+1 //checks if the landmin is lower then seeds, and sets above if neccessary
var/LandReal = rand(LandMin, LandMax) //gets a random amount of land
var/passes = 0 //variable for debugging currently, and to delay so the program does not crash during extremely large land generation
while(LandCurrent < LandReal) //while thel and current does not equal the land we wish it to be
passes++ //add one to passes.
if(passes > 2) //if a certain number of passes
sleep(50) //sleep a bit, let the cpu rest slightly ;p
passes = 0 //set passes back to 0
world << "Generation: [(LandCurrent/LandReal)*100]% complete." //relay amount of land done for debug purposes.
var/list/dirs = list(NORTH, NORTHEAST, EAST, SOUTHEAST, SOUTH, SOUTHWEST, WEST, NORTHWEST) //cardinal directions
var/turf/t = pick(SeedTurfs) //pick a turf in the list seedturfs
var/mob/mbot = new(t) //create the bot to be used
var/instaGrass = 0 //a boolean to be set if regular, not mgrass, is made ONE TIME for this seedturf
for(var/i in dirs) //for each direction
mbot.Move(t) //put the mbot on the original location
//world << "Mbotloc [mbot.loc.x] , [mbot.loc.y], [mbot.loc.z]" //some debug information that was needed before
//world << mbot.loc
//world << "/Mbotloc"
step(mbot, i) //move the mob in the apropriate direction

var/turf/C = locate(mbot.x, mbot.y, mbot.z) //get the turf

world << C //debugging, suppose to show C to world but C doenst always seem to be a /turf/
if(C.type != typesof(/turf/Ocean/)) continue //if its not an ocean, ignore it.
if(instaGrass) //if instagrass, always turn it into grass
C = new /turf/Grass(locate(mbot.x, mbot.y, mbot.z)) //turn turf at C into a /turf/Grass
LandCurrent++ //add one to max land
var/rnd = rand(1,100) //random from 1 to 100
if(rnd < 90) //if less than 90
C = new /turf/MGrass(locate(mbot.x, mbot.y, mbot.z)) //turn it into an MGrass tile
SeedTurfs+=C //Add it to the seed turfs
LandCurrent++ //then increase land count
instaGrass = 1 //turn instagrass on
C = new /turf/Grass(locate(mbot.x, mbot.y, mbot.z)) //turn the tile into a /turf/grass
LandCurrent++ //increase land count
del(mbot) //del the map bot so it doesnt linger longer then it should

Problem description:
The line:

var/turf/C = locate(mbot.x, mbot.y, mbot.z

should always return a turf, but doesn't seem to do so, and in fact does not return a turf more times then it does. I'm not sure what I'm missing, I'm sure I messed up somewhere along the lines. I have been trying for a while now to figure this one out, to no avail.

edit: Every line in the generation proc is commented to state specifically what it is trying to accomplish. :3
What is it returning, if it's not a turf? The only other thing it should be returning (in this case) is null, which means the coordinates are invalid. That is, x,y,z > maxx,maxy,maxz, or x,y,z < 0, or x,y,z are not integers.
They are integers, as it is refering to the mob's built-in location, which is set to the random turf chosen from a list of turfs (and only turfs). Also when the mob is placed on this turf, it has an x, y, and z value (less than 100x100, which is the size of my map) at all times (I even manually checked a few of the locations to make sure they are turfs), but the loc is not returning a turf, even though it is located on a turf.

I'll go check right now what the non-turfs are (c.type should return the atom type right? :) )

Edit: Apparently it is returning a turf, but not showing the turf's icon when using world << C... interesting. Anyone know why this would occur?
In response to KingCold999
KingCold999 wrote:
Edit: Apparently it is returning a turf, but not showing the turf's icon when using world << C... interesting. Anyone know why this would occur?

Sometimes icons take a moment to render in the output control, so if you're displaying a lot of them, maybe some are being discarded. Try adding a sleep(2) before the output and seeing if they all appear.

Also, why are you using locate() instead of mbot.loc?