Taste the rainbow! + UI BUG/functionality report

Alternate title: Disco Destroyer
Edit: rescalled to look better in the post preview. Click on it to see the full thing if you can’t see anything interesting happening.

Done in the mission script.
The entire code responsible is here. The color cycling logic is quite primitive, but I can’t recall the HSV math without looking it up, so it does it for proof of concept. Credit to I think @Dom2 for pointing out the existence of the required function to me.

3 Likes

Well that’s cool.

Oh man, this is fantastic! Could be huge for anyone and everyone doing Cata-related mods.

Or music festival space stations.

3 Likes

If I remember correctly, the SobGroup_SetTeamColours function was only working in SinglePlayer in the original HW2. Is it working in skirmish/MultiPlayer too in HWR ?

Edit : and why are you talking about HSV ? Is it not only RGB channels with value from 0 to 1 (0 being 0 and 1 being 255) ?

Edit2 : seems so from the old wiki http://hw2bsg.org/wiki.hw2.info/FunctionSobGroup_SetTeamColours.html

Edit3 : @EatThePath ok, understood, make sense ! (and the wiki seems to confirm the SP only thing :confused: )

That was not a potential issue I was aware of. It’d be dissapointing if so, I was hoping to use it for some skirmish things. I’ll have to check and report back.

I mentioned HSV because if I tracked the colors as HSV and just cycled the H, only converting to RGB for feeding into the engine, then I could get a real smooth rainbow cycling effect. That’s harder to do if working with RGB directly.

There’s no such note on http://hw2bsg.org/wiki.hw2.info/FunctionPlayer_SetTeamColours.html, but I’d really like the ability to do it to a group rather than a player.

Clearly more interesting to be able to do it on a ship basis, that’s for sure !

(was reading about HSV, some interesting stuff there)

Yeah, just confirmed that SobGroup_SetTeamColous doesn’t work in MP, but Player_… does.

Guess the eventual Survival v2 is going to need to use five AI slots instead of 1.

You can always use the real dumb but functional solution, to have several copies of ships with team colors in diffuse.

oof. I don’t think the prettiness of wave-specific teamcolors is worth that amount of expansion of mod filesize. One thing I should do is see what happens if I spawn units outside of the selectable player indexes. If I spawn ships to player 9, does the game still work right? I puppeteer their actions via lua anyway, so any issues with the AI not running aren’t a problem. If that works, then all 8 slots could be left open for massive coop.

Still. Questions for later. Need to get back to my other diversion!

@BitVenom : do you think it would be possible to have “SobGroup_SetTeamColours” useable in MP/skirmish as “Player_SetTeamColours” is ?

Well done! That’s exactly what I was planning on doing with that function - you beat me to it! And saved me the work… I wanted it to be able to see what my ships look like with different team/stripe combinations.

Definitely good for screenshots. Just wait to see the color you like, pause, hit F12.

I’m wondering if any of the parameterized shaders that bit venom talked about would accomplish the same thing (really have no idea if there is a hook since all of the new patch stuff is completely undocumented)

I’d be shocked if they couldn’t do at least as much as I’ve done here, but shaders aren’t something I know at the moment.

I was bored during the week-end and made this for you @EatThePath
It should work as intended (I don’t have HW2 installed at the moment).
Base and Stripe colors are managed separately and the rainbow cycle can be inverted for each one easily with Base_Inversion and Stripe_Inversion.
The HSV/RGB conversion is based on this site : http://www.rapidtables.com/convert/color/hsv-to-rgb.htm

Tell me if you have any problem with it.

function OnInit()
    Rule_Add("Rule_Rainbow")
end

Base_Inversion=0 -- if set to 1, the Base will go "red/magenta/blue/cyan/green/yellow/red" instead of "red/yellow/green/cyan/blue/magenta/red"
Base_h=0 -- hue start value from 0° to 360°
Base_s=1 -- saturation from 0 to 100% (1=100%)
Base_v=1 -- value from 0 to 100% (1=100%)

Stripe_Inversion=0 -- if set to 1, the Stripe will go "red/magenta/blue/cyan/green/yellow/red" instead of "red/yellow/green/cyan/blue/magenta/red"
Stripe_h=0 -- hue start value from 0° to 360°
Stripe_s=1 -- saturation from 0 to 100% (1=100%)
Stripe_v=1 -- value from 0 to 100% (1=100%)

function Rule_Rainbow()
    SobGroup_SetTeamColours("Player_Ships0", HSVtoRGB(Base_h,Base_s,Base_v), HSVtoRGB(Stripe_h,Stripe_s,Stripe_v), "DATA:Badges/Soban.tga")
    
    If Base_Inversion == 1 then
        If Base_h == 0 then Base_h = 360 end
        Base_h = Base_h - 1
    else
        If Base_h == 360 then Base_h = 0 end
        Base_h = Base_h + 1
    end
    
    If Stripe_Inversion == 1 then
        If Stripe_h == 0 then Stripe_h = 360 end
        Stripe_h = Stripe_h - 1
    else
        If Stripe_h == 360 then Stripe_h = 0 end
        Stripe_h = Stripe_h + 1
    end
end

function HSVtoRGB(h,s,v)
    local rgb_table = {}
    local c,x,o
    
    -- verify that h, s and v are within correct boundaries
    if (h<0) or (h>=360) then h=0 end
    if s<0 then s=0 end
    if s>1 then s=1 end
    if v<0 then v=0 end
    if v>1 then v=1 end
    
    c = v
    x = v*(1-s*abs(mod(h/60, 2)-1))
    o = v*(1-s)
    
    -- c, x and o should never be <0 or >1 but just in case...
    if c<0 then c=0 end
    if c>1 then c=1 end
    if x<0 then x=0 end
    if x>1 then x=1 end
    if o<0 then o=0 end
    if o>1 then o=1 end
    
    if h<60 then
        rgb_table = {c, x, o}
    elseif h<120 then
        rgb_table = {x, c, o}
    elseif h<180 then
        rgb_table = {o, c, x}
    elseif h<240 then
        rgb_table = {o, x, c}
    elseif h<300 then
        rgb_table = {x, o, c}
    else
        rgb_table = {c, o, x}
    end
    
    return rgb_table
end
2 Likes

Excellent. some of your 'if’s became 'If’s, but with that fixed and one or two tweaks later,


Thanks for doing that legwork

4 Likes

Great ! Sorry for the “if” problem, oups ^^

Edit :
I wanted to add an end value for the hue parameter today but it seems you’ve already done it.
The rainbow effect seems slower than before : is it due to the conversion code or did you use a Rule_AddInterval to slow it ?

nope, no slowing. Keep in mind that my code was cycling from 0-1 with steps of 0.01, and yours is going from 0-360 with steps of 1. Yours should take 3.6 times as long to go through it’s period, and doesn’t have the flicks back to zero to make it more dramatic. If my guesses about rule execution are correct, it should take 18 seconds for your HSV code to do a full cycle, and the cap on a gfycat upload is 15 seconds. Maybe I should put a longer one up on youtube.

As for other cutstomizations, all I did was give a starting value other than 0 to the for the base. I gave it 90, and now that I’m rested and undistracted I realize that the effect I really wanted needs it to be 180. Lets fix that…

Edit: Getting these to embed correctly can be a real pain