ID:148299
 
Ive got 6 levels of density for my stars(1 = lightest, 6 = heaviest). Ive got it checking tags in the New() of each turf to determine where centers of density are.


turf
stars
icon = 'stars.dmi'
icon_state = "1"
New()
..()
src.name = "([src.x])([src.y])"
var/T = src.tag
if(T=="1")T=1;if(T=="2")T=2;if(T=="3")T=3
if(T=="4")T=4;if(T=="5")T=5;if(T=="6")T=6
if(src.icon_state == "1")
src.icon_state = "6"
for(var/turf/stars/S in view(6,src))
var/D = get_dist(src,S)
if(T <=5)
if(D == 5) S.icon_state = "1"
if(T <=4)
if(D == 4) S.icon_state = "2"
if(T <=3)
if(D == 3) S.icon_state = "3"
if(T <=2)
if(D == 2) S.icon_state = "4"
if(T <=1)
if(D == 1) S.icon_state = "5"
<dm>

Now heres what that gave me, while the only turf with a tag of anything but null was located at 10,10.
(20x20 map, numbers represent icon_state)
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111 // first 15 lines are all
11111111111111111111 // icon_state 1
11111111111111111111 // even though theres a tag of 5 at 10,10
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
22222222212222122221 // on the last 5 lines of my little diagram
23333333213332133321 // it goes all weird on me, I cant figure out whats messing up
23444443214432144321
23455543215432154321
23456543215432154321
I ran a few tests, and all the turfs had their name set correctly. However, your problem seems to be that tag is null, thus T is null. What, exactly, are you trying to do?
In response to Garthor
The default for tag is null, I was asumming that leaving tag null was not going to effect the outcome.

tag cant be set at compile time(which dm just screamed at me).

I think ill probably have to make my own var to use for this so it will work correctly.
In response to Jotdaniel
What are you trying to do, anyway? Besides, even if it wasn't null, I'm pretty sure it would not be a text string between "1" and "6".
In response to Garthor
tag must be a text string, I dont know why, and it doesnt matter now. I'm taking a different approach to this now.
In response to Jotdaniel
If you told us what you were trying to do, I might be bored enough to just write up the whole thing for you.
In response to Garthor
Oh, just generate random placed and sized star clusters(I know theyre all going to be square, but its not THAT big a part of the game).
In response to Jotdaniel
Circle formation procs aren't all that hard to come by anymore. I think AbyssDragon has one in his BasicMath library, or maybe one of the other ones. Lummox might have a few floating around too. Here are some I whipped up:

<code>// A realistic but jagged circle proc/circle(atom/source, dist) var/list/list = list() for(var/atom/A in range(source, dist)) var/dx = source.x - A.x var/dy = source.y - A.y if(sqrt(dx*dx + dy*dy) <= dist) list += A return list // A realistic but jagged circle, minus the source atom proc/ocircle(atom/source, dist) var/list/list = list() for(var/atom/A in range(source, dist)) var/dx = source.x - A.x var/dy = source.y - A.y if(sqrt(dx*dx + dy*dy) <= dist) list += A return (list - source) // A rounded circle, less realistic but better looking proc/r_circle(atom/source, dist) var/list/list = list() for(var/atom/A in range(source, dist)) var/dx = source.x - A.x var/dy = source.y - A.y if(round(sqrt(dx*dx + dy*dy)) <= dist) list += A return list // A rounded circle, minus the source atom proc/r_ocircle(atom/source, dist) var/list/list = list() for(var/atom/A in range(source, dist)) var/dx = source.x - A.x var/dy = source.y - A.y if(round(sqrt(dx*dx + dy*dy)) <= dist) list += A return (list - source)</code>
In response to Foomer
I would much rather do it myself. I figured it out anyway, I was coming at the problem from the wrong angle.

These are a bit more than I wanted to do with this(and probably not one of the better ways to do it), but they give me some decent results.
turf/stars/proc/addnum()
for(var/turf/stars/ST in oview(5,src))
if(ST.num != 0) return
if(src.num == 0)
var/R1 = rand(1,10)
var/R2 = rand(1,10)
if(R1 == R2)
var/N = rand(1,5)
src.num = N

turf/stars/proc/stargen()
if(src.icon_state == "1")
if(src.num != 0)
if(src.num == 5)
src.icon_state = "6"
for(var/turf/stars/S in view(5,src))
var/D = get_dist(src,S)
if(D == 5) S.icon_state = "1"
if(D == 4) S.icon_state = "2"
if(D == 3) S.icon_state = "3"
if(D == 2) S.icon_state = "4"
if(D == 1) S.icon_state = "5"
if(src.num == 4)
src.icon_state = "5"
for(var/turf/stars/S in view(4,src))
var/D = get_dist(src,S)
if(D == 4) S.icon_state = "1"
if(D == 3) S.icon_state = "2"
if(D == 2) S.icon_state = "3"
if(D == 1) S.icon_state = "4"
if(src.num == 3)
src.icon_state = "4"
for(var/turf/stars/S in view(3,src))
var/D = get_dist(src,S)
if(D == 3) S.icon_state = "1"
if(D == 2) S.icon_state = "2"
if(D == 1) S.icon_state = "3"
if(src.num == 2)
src.icon_state = "3"
for(var/turf/stars/S in view(4,src))
var/D = get_dist(src,S)
if(D == 2) S.icon_state = "1"
if(D == 1) S.icon_state = "2"
if(src.num == 1)
src.icon_state = "2"
for(var/turf/stars/S in view(4,src))
var/D = get_dist(src,S)
if(D == 1) S.icon_state = "1"
In response to Foomer
I actually hadnt looked at it this way before. I'm not all that great with even simple math at times. Thats actually more simple than I thought it would be. I just get so confused when math is in DM form.
In response to Jotdaniel
I'm horrible at math, I just ripped the guts out of a get_exact_dist() proc I got from Spuzzum. :)
In response to Jotdaniel
Yikes! Way too much code there, buddy. =P

<code>turf/stars/proc/stargen() if(src.icon_state == "1" && src.num && src.num<6) src.icon_state=num2text(src.num+1) for (var/turf/stars/S in view(src.num,src)) var/D=get_dist(src,S) S.icon_state=num2text(src.num+1-D)</code>

Thirty-eight lines reduced to six. =)
In response to Foomer
There ya go. Now that I look at those procs you posted, I can tell how they work, but thats how I learn dm, I rip things apart and try to figure out how they work. I can usually figure out how something works pretty quickly.
In response to Crispy
I would have got something like that eventually, but its 4 am, and I'm lucky anything I write right now even works. Thanks anyway, that helps a lot.

EDIT:Actually I needed one more line and that works exactly the same as my first proc did.

turf/stars/proc/stargen()
if(src.icon_state == "1" && src.num && src.num<6)
src.icon_state=num2text(src.num+1)
for (var/turf/stars/S in view(src.num,src))
var/D=get_dist(src,S)
S.icon_state=num2text(src.num+1-D)
src.icon_state=num2text(src.num+1)
In response to Jotdaniel
That shouldn't make any difference. I already have that line before the for() loop, and src.num isn't changing in the loop. So whether or not that bolded line is in should be irrelevant.

If it actually does make a difference, then either something weird is going on or you didn't do something properly. =P
In response to Crispy
I cut and pasted it, all the centers of the star clusters were black. I added that line and they changed to the correct icon. I can see that the first line didnt do its job, I'm not really sure why.


EDIT: Don't mind me now, I need sleep. It wasn't working correctly because I forgot to switch from spaces to 5 space Indentation that I use. I put in correct indentation and took out the line I added, it works just fine. Thanks again.
In response to Jotdaniel
Ok, heres the new proc that I'm using:
turf/stars/proc/stargen()
if(src.icon_state == "1" && src.num && src.num<6 && src.num>=2)
src.icon_state = num2text(src.num+1)
for (var/turf/stars/S in range(src.num,src))
var/dx = src.x - S.x
var/dy = src.y - S.y
if(sqrt(dx*dx + dy*dy) <= src.num)
var/D=get_dist(src,S)
S.icon_state=num2text(src.num+1-D)


It works for the most part, yet the math of it is still slightly confusing me. On the really large star clusters(when num is 5), the center will turn black, because the icon_state isnt 1-6. The smaller ones arent quite round either. Can anyone decipher this?


EDIT:

I fixed it, I changed var/D=get_dist(src,S) tp

var/D=round(sqrt(dx*dx + dy*dy))

This actually made it work perfectly.