springtime is time to drown

This commit is contained in:
Enno Rehling 2010-10-16 21:35:59 -07:00
parent 561745b356
commit 337dfab982
1 changed files with 22 additions and 9 deletions

View File

@ -5,19 +5,26 @@ local function is_winter(turn)
return season == "calendar::winter" return season == "calendar::winter"
end end
local function freeze(r) 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 for i, rn in ipairs(r.adj) do
-- each region has a chance to freeze -- each region has a chance to freeze
if rn.terrain=="ocean" and math.mod(rng_int(), 100)<20 then if rn.terrain=="ocean" and (chance>=100 or math.mod(rng_int(), 100)<chance) then
rn.terrain = "packice" rn.terrain = "packice"
end end
end end
end end
local function thaw(r) local function thaw(r, chance)
r.terrain = "ocean" if chance>=100 or math.mod(rng_int(), 100)<chance then
for s in r.ships do r.terrain = "ocean"
s.coast = nil for s in r.ships do
s.coast = nil
end
end end
end end
@ -26,13 +33,19 @@ function update()
if is_winter(turn) then if is_winter(turn) then
for r in regions() do for r in regions() do
if r.terrain=="glacier" then if r.terrain=="glacier" then
freeze(r) freeze(r, 20)
end end
end end
elseif is_winter(turn-1) then elseif is_spring(turn) then
for r in regions() do for r in regions() do
if r.terrain=="packice" then if r.terrain=="packice" then
thaw(r) thaw(r, 20)
end
end
elseif is_spring(turn-1) then
for r in regions() do
if r.terrain=="packice" then
thaw(r, 100)
end end
end end
end end