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.
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!