Euflorium: The Eufloria Community

Eufloria => Eufloria Classic => Eufloria Classic Mods => Topic started by: annikk.exe on January 04, 2011, 10:04:37 AM

Title: GetLeafColour
Post by: annikk.exe on January 04, 2011, 10:04:37 AM
Anyone know about GetLeafColour?

You run it on a tree, and it returns a variable with three properties - .r, .g, and .b

so
Code: [Select]
empirecolour = GetAsteroid(0):GetRandomTree():GetLeafColour(0)
red = empirecolour.r
green = empirecolour.g
blue = empirecolour.b


I am curious about the number that you pass to GetLeafColour()
What does it do?
Does it refer to a particular leaf?
Or does it refer to trees belonging to a particular empire?
Or..?

Any information about this function would be really helpful to me!
Title: Re: GetLeafColour
Post by: annikk.exe on January 04, 2011, 10:45:26 AM
Here's a snippet of code I'm experimenting with.
The aim is to detect the different between the RBG values of the different factions, and if they are too similar, change faction 3 to be faction 4.
It keeps trying until it gets to faction 9, then it stops and gives up.

Code: [Select]
local colourchanged = false
local emp3 = 3
local colourchangetimer = 3

while GameRunning() do

-- *** YOUR LOOPED COMMANDS GO HERE *** --

-- fade in the roids to avoid them spawning on top of each other, and because it looks freaking awesome!

if colourchanged == false then
if GetGameTime() > colourchangetimer then

colourchangetimer = colourchangetimer + 3

-- detect colours of empire 2 and 3
local emp2col = tree1:GetLeafColour(0)
local emp3col = tree2:GetLeafColour(0)

--detect the difference between the different channels
local rdiff = emp2col.r - emp3col.r
rdiff = math.sqrt(rdiff * rdiff)
local gdiff = emp2col.g - emp3col.g
gdiff = math.sqrt(gdiff * gdiff)
local bdiff = emp2col.b - emp3col.b
bdiff = math.sqrt(bdiff * bdiff)


if rdiff < 0.3 and gdiff < 0.3 and bdiff < 0.3 and emp3 < 9 then
-- they are too similar.  Change empire 3 to be the next empire up, for a different colour.
emp3 = emp3 + 1
GetAsteroid(3):ChangeOwner(emp3)
else
colourchanged = true
MessageBox("Assigned to empire " .. emp3)
end

end
end


Currently rdiff, gdiff and bdiff always come back as 0.  :/
But there have been some occasions when it has worked.  But I can't figure out why it works, and upon running the same code a second time, it stops working!
Title: Re: GetLeafColour
Post by: Mihhaelo on January 05, 2011, 02:56:51 AM
It only works if the screen is zoomed in past a certain point, otherwise it will return 0 and it'll also return 0 sometimes on growing trees, so it's advisable you only use it once to get the colours initially and save them as variables.
Title: Re: GetLeafColour
Post by: annikk.exe on January 05, 2011, 03:14:05 AM
Thanks Mihhaelo :>  What an odd command!

GetLeafColour(int)

What does the "int" represent?
Title: Re: GetLeafColour
Post by: Pilchard123 on January 05, 2011, 03:19:01 AM
r,g,bdiff s may come back as 0 because they are too small to not be rounded. Or am I completely off here?
Title: Re: GetLeafColour
Post by: Alex on January 05, 2011, 05:22:07 PM
There are five colours for each team so the passed-in value is an int from 0 to 4 inclusive indexing into the colour array.

You would be better off getting the tree's owner and using Colour = ColonyGame.GetFactionColour(team, index). Get access to ColonyGame by doing ColonyGame = luanet.import_type("Eufloria.ColonyGame"). Then go Colour.R to get the red component for instance.

The team colours used in the game  are in teams.png in the Resources directory.
Title: Re: GetLeafColour
Post by: annikk.exe on January 05, 2011, 06:39:21 PM
Sweet! :>  Thanks again dude.  This solves the problem completely.
Empire Colour Selector function coming soon.  :>
Title: Re: GetLeafColour
Post by: Pilchard123 on January 06, 2011, 02:16:40 AM
I hate you...


















Not really.