ID:141576
 
Code:
#define islist(x) istype(x, /list)

proc
srand(min, max, shade)
if(!shade || shade == 1 || max < min) return min

return round(min + rand(1, shade) * ((max - min) / shade))

color
var
red_min = 0
green_min = 0
blue_min = 0

red_max = 0
green_max = 0
blue_max = 0

red_shades = 0
green_shades = 0
blue_shades = 0

New(rm = 0, rx = 0, rs = 0, gm = 0, gx = 0, gs = 0, bm = 0, bx = 0, bs = 0)
red_min = rm
red_max = rx
red_shades = rs

green_min = gm
green_max = gx
green_shades = gs

blue_min = bm
blue_max = bx
blue_shades = bs

proc
debug()
return "[red_min],[red_max]([red_shades])=[srand(red_min, red_max, red_shades)]; [green_min],[green_max]([green_shades])=[srand(green_min, green_max, green_shades)]; [blue_min],[blue_max]([blue_shades])=[srand(blue_min, blue_max, blue_shades)]"

generateColor()
return rgb(srand(red_min, red_max, red_shades), srand(green_min, green_max, green_shades), srand(blue_min, blue_max, blue_shades))

atom
var
color/foreground = null
color/background = null
display_text = null

New()
..()
refreshDisplay()

proc
generateDisplayText()
if(copytext(display_text, 1, 2) == ":" && copytext(display_text, length(display_text)) == ";")
. = copytext(display_text, 2, length(display_text))

var/rdt = rand(1, length(.))
. = copytext(., rdt, rdt + 1)

else . = display_text

refreshDisplay()
var
fg_color = (foreground) ? (foreground.generateColor()) : (null)
bg_color = (background) ? (background.generateColor()) : (null)
dt = generateDisplayText()

if(fg_color && bg_color) text = "<font bgcolor=[bg_color] color=[fg_color]>[dt]</font>"
else if(fg_color && !bg_color) text = "<font color=[fg_color]>[dt]</font>"
else if(!fg_color && bg_color) text = "<font bgcolor=[bg_color]>[dt]</font>"
else text = "[dt]"

world/mob = /mob/player

turf
text = ""

grass
text = "<font bgcolor=#009900> </font>"

foreground = new/color(0, 0, 0, 150, 200, 3, 0, 0, 0)
display_text = ":` ,;"

mob
player
text = "@"

foreground = new/color(50, 255, 3, 50, 255, 3, 50, 255, 3)
display_text = "@"


Problem description:
Okay I have the foreground and background /colors that are created with the arguments being color and shade numbers. The /color object returns a random color based on what ranges you give it.

The problem is that it does not work on turfs. It works fine on /mobs and /objs, but it just won't work on turfs. I tried this with the turf and it made it work:

turf
text = ""

grass
text = "<font bgcolor=#009900> </font>"

//foreground = new/color(0, 0, 0, 150, 200, 3, 0, 0, 0)
display_text = ":` ,;"

New()
foreground = new/color
foreground.green_min = 150
foreground.green_max = 200
foreground.green_shades = 3

..()


but that's completely retarded. Why do other /atoms BESIDES /turf let me instance the /color object like they do?

Am I missing some secret innerworking of BYOND?!

[edit]
This also makes it correctly set the grass color.

mob
player
text = "@"

foreground = new/color(50, 255, 3, 50, 255, 3, 50, 255, 3)
display_text = "@"

Login()
..()
for(var/turf/A in world)
A.foreground = new/color(0, 0, 0, 150, 200, 3, 0, 0, 0)
A.background = new/color(0, 0, 0, 100, 150, 3, 0, 0, 0)
A.refreshDisplay()

Would this work for you?
world
New()
..()
setupTurfs()
proc
setupTurfs()
for(var/turf/A in world)
A.foreground = new/color(0, 0, 0, 150, 200, 3, 0, 0, 0)
A.background = new/color(0, 0, 0, 100, 150, 3, 0, 0, 0)
A.refreshDisplay()