//==============================================================================
// Library creates invisible sun and moon units for all players.
// These units are then used as tech requirements for spells.
// If a player has a sun unit in his ownership than he can use sun spells.
// Same goes for moon ofc.
// Sun units are owned by players only during day time.
// Moon units are owned by players only during night time.
//==============================================================================
library Daytime initializer Init uses Trig
globals
private constant player NEUTRAL = Player(13)
private unit array sun
private unit array moon
endglobals
//==============================================================================
// For testing purposes
//==============================================================================
public function Off takes nothing returns nothing
local integer i = 0
loop
exitwhen i>=12
call SetUnitOwner(sun[i], NEUTRAL, false)
call SetUnitOwner(moon[i], NEUTRAL, false)
set i = i + 1
endloop
endfunction
//==============================================================================
private function Dawn takes nothing returns nothing
local integer i = 0
loop
exitwhen i>=12
call SetUnitOwner(sun[i], Player(i), false)
call SetUnitOwner(moon[i], NEUTRAL, false)
set i = i + 1
endloop
endfunction
//==============================================================================
private function Dusk takes nothing returns nothing
local integer i = 0
loop
exitwhen i>=12
call SetUnitOwner(moon[i], Player(i), false)
call SetUnitOwner(sun[i], NEUTRAL, false)
set i = i + 1
endloop
endfunction
//==============================================================================
public function isDay takes nothing returns boolean
return (GetTimeOfDay() >= 6.00) and (GetTimeOfDay() < 18.00)
endfunction
//==============================================================================
private function Actions takes nothing returns nothing
if isDay() then
call Dawn()
else
call Dusk()
endif
endfunction
//==============================================================================
private function Init takes nothing returns nothing
local trigger trig
local item it
local integer i = 0
loop
exitwhen i>=12
set sun[i] = CreateUnit(NEUTRAL, UID_sun, 0-i*100, 0, 0)
set moon[i] = CreateUnit(NEUTRAL, UID_moon, 0+i*100, 0, 0)
call PauseUnit(sun[i], true)
call PauseUnit(moon[i], true)
set i = i + 1
endloop
// empire sun gets all map regen aura, scourge moon gets all map regen aura
call UnitAddAbility(sun[Players_EMPIRE], AID_sun_aura)
call UnitAddAbility(moon[Players_SCOURGE], AID_moon_aura)
call Trig_TimeOfDay(function Dawn, 6.00)
call Trig_TimeOfDay(function Dusk, 18.00)
call Trig_TimerSingle(function Actions, 0.01)
endfunction
endlibrary