Jump to content

Code for season and precipitation?

Recommended Posts

I'm trying to write a bit of code that determines if it's winter, if it's snowing, and if there's snow on the ground.

I found all the respective files in DST's component file location, but working it into my code has proven difficult.

>>>This code is used to make it snow at the beginning of winter, but all the variables are only defined inside this one piece of code, so I can't call upon them, or so it would seem.:

if data.season == "winter" and data.elapseddaysinseason == 2 then
            --We really want it to snow in early winter, so that we can get an initial ground cover
            _moisturerateval = 0
            _moisturerateoffset = 50

>>>This code is used to determine if it's cold, and how to calculate insulation/body temperature change rates, but this isn't really what I need..

-- it's cold out
elseif self.delta < 0 then
    -- If the player is cooling, defend using insulation.
    local winterInsulation, summerInsulation = self:GetInsulation()
    self.rate = math.max(self.delta, -TUNING.SEG_TIME / (TUNING.SEG_TIME + winterInsulation))
    -- If they are heating up, do it at full speed, and faster if they're freezing
    self.rate = math.min(self.delta, self.current <= 0 and TUNING.THAW_DEGREES_PER_SEC or TUNING.WARM_DEGREES_PER_SEC)

>>>This code determines how much snow is on the ground, which is great for me, except that I can't seem to call on any of the values..

--Update ground overlays
local snowlevel = _snowlevel:value()
if _preciptype:value() == PRECIP_TYPES.snow then
    --Accumulate snow
    snowlevel = math.min(snowlevel + preciprate * dt * SNOW_ACCUM_RATE, 1)
elseif snowlevel > 0 and _temperature > 0 then
    --Melt snow
    local meltrate = MIN_SNOW_MELT_RATE + SNOW_MELT_RATE * math.min(_temperature / 20, 1)
    snowlevel = math.max(snowlevel - meltrate * dt, 0)
SetWithPeriodicSync(_snowlevel, snowlevel, SNOW_LEVEL_SYNC_PERIOD, _ismastersim)
if _snowlevel:value() > 0 and (_temperature < 0 or _wetness:value() < 5) then
    SetGroundOverlay(GROUND_OVERLAYS.snow, _snowlevel:value() * 3) -- snowlevel goes from 0-1
    SetGroundOverlay(GROUND_OVERLAYS.puddles, _wetness:value() * 3 / 100) -- wetness goes from 0-100

Edited by FurryEskimo
Link to comment
Share on other sites

Figured it out!  Haha!  Finally.  I can check:







>>>It’s not perfect and there’re more features to check, but it’s pretty great all things considered, and super easy to code with!  I’m using this to code apply benefits when it’s winter, extra benefits when it’s snowing, extra weaknesses during the summer (unless in a cave), and a eventually a custom structure that breaks in the rain.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...