server/scripts/e3a/frost.lua

53 lines
1.3 KiB
Lua
Raw Normal View History

module('frost', package.seeall)
local function is_winter(turn)
local season = get_season(turn)
return season == "calendar::winter"
end
2010-10-17 06:35:59 +02:00
local function is_spring(turn)
local season = get_season(turn)
return season == "calendar::spring"
end
local function freeze(r, chance)
for i, rn in ipairs(r.adj) do
-- each region has a chance to freeze
2012-07-10 09:22:51 +02:00
if rn.terrain=="ocean" and (chance>=100 or math.fmod(rng_int(), 100)<chance) then
2010-09-12 04:30:19 +02:00
rn.terrain = "packice"
end
end
end
2010-10-17 06:35:59 +02:00
local function thaw(r, chance)
2012-07-10 09:22:51 +02:00
if chance>=100 or math.fmod(rng_int(), 100)<chance then
2010-10-17 06:35:59 +02:00
r.terrain = "ocean"
for s in r.ships do
s.coast = nil
end
2010-10-17 06:11:03 +02:00
end
end
function update()
local turn = get_turn()
if is_winter(turn) then
for r in regions() do
if r.terrain=="glacier" then
2010-10-17 06:35:59 +02:00
freeze(r, 20)
end
end
elseif is_spring(turn) then
for r in regions() do
if r.terrain=="packice" then
thaw(r, 20)
end
end
2010-10-17 06:35:59 +02:00
elseif is_spring(turn-1) then
for r in regions() do
2010-09-12 04:30:19 +02:00
if r.terrain=="packice" then
2010-10-17 06:35:59 +02:00
thaw(r, 100)
end
end
end
2010-09-12 04:12:04 +02:00
end