Page 1 of 1

[Request] Make Darkness Writable, Move from Game to Surfaces

Posted: Wed Feb 10, 2016 4:12 am
by Afforess
What it says on the tin. Darkness should be writable, and darkness should be a per-surface property (so underground surfaces are always partial darkness, for example).

Re: [Request] Make Darkness Writable, Move from Game to Surfaces

Posted: Wed Feb 10, 2016 4:17 am
by Supercheese
Definitely, this would also be needed if a user-made mod wanted to implement the Space Platform idea, naturally for solar power there it'd always be full brightness.

Re: [Request] Make Darkness Writable, Move from Game to Surfaces

Posted: Thu Feb 11, 2016 7:07 pm
by Rseding91
daytime, wind_speed, wind_orientation, wind_orientation_change, and peaceful_mode have all been moved to LuaSurface for 0.13.

Darkness is a calculated field based off the daytime and as such isn't writable directly. Simply changing daytime effects darkness.

Re: [Request] Make Darkness Writable, Move from Game to Surfaces

Posted: Thu Feb 11, 2016 9:41 pm
by Afforess
Rseding91 wrote:daytime, wind_speed, wind_orientation, wind_orientation_change, and peaceful_mode have all been moved to LuaSurface for 0.13.

Darkness is a calculated field based off the daytime and as such isn't writable directly.
Fantastic news! You guys rock.
Rseding91 wrote:Simply changing daytime effects darkness.
Simply is an understatement. It took me 160 lines of code. https://github.com/Afforess/Gloom/blob/ ... ght.lua#L4

Also, there is no way to go below 0.14 brightness.

Re: [Request] Make Darkness Writable, Move from Game to Surfaces

Posted: Thu Feb 11, 2016 9:58 pm
by Koub
1) You made a mistake here :

Code: Select all

 elseif light_level <= 0.62 then
        return 0.6225
should be 0.6725

and I would have written that this way :

Code: Select all

 if light_level <= 0.14 then
        return 0.5
elseif light_level > 0.99
        return 0.8
else return =0.2*light_level+0.55
end
It's much shorter :)

Re: [Request] Make Darkness Writable, Move from Game to Surfaces

Posted: Thu Feb 11, 2016 10:58 pm
by Afforess
Koub wrote: and I would have written that this way :

Code: Select all

 if light_level <= 0.14 then
        return 0.5
elseif light_level > 0.99
        return 0.8
else return =0.2*light_level+0.55
end
It's much shorter :)
Is that the official formula? I dug around but the wiki didn't have it documented.

Edit: Rseding91 shared it in IRC: http://pastebin.com/raw/cRaYBrUn

Re: [Request] Make Darkness Writable, Move from Game to Surfaces

Posted: Thu Feb 11, 2016 11:09 pm
by Koub
No I just took your code, noticed that apart from the first and last value, you were just calculating a linear function for every increment of 0.01, so I put that in a formula that basically computes instead of chaining if then elseifs ^^.

Re: [Request] Make Darkness Writable, Move from Game to Surfaces

Posted: Thu Feb 11, 2016 11:19 pm
by Afforess
Koub wrote:No I just took your code, noticed that apart from the first and last value, you were just calculating a linear function for every increment of 0.01, so I put that in a formula that basically computes instead of chaining if then elseifs ^^.
Nice... I got my numbers from sampling. Was not fun. Turns out your formula actually does match the derived formula from the game too. So congrats.

Re: [Request] Make Darkness Writable, Move from Game to Surfaces

Posted: Fri Feb 12, 2016 12:36 am
by ratchetfreak
Afforess wrote:
Koub wrote:No I just took your code, noticed that apart from the first and last value, you were just calculating a linear function for every increment of 0.01, so I put that in a formula that basically computes instead of chaining if then elseifs ^^.
Nice... I got my numbers from sampling. Was not fun. Turns out your formula actually does match the derived formula from the game too. So congrats.
putting the values in a spreadsheet and making a graph out of it will help seeing those things.