Greetings everyone! It's been a long time since I was using Hive, and now, i suppose, it's time to provide some stuff in return
This function simply toggles daytime (12:00) or night time (00:00) when need as well as freezes it.
When toggled off, unfreezes time and procceds from the daytime which would be if there was no imitation called (that's the whole purpose of this function)
Change Divider if you have different day length.
Day imitation has higher priority than night imitation.
All needed comments are provided inside
This function simply toggles daytime (12:00) or night time (00:00) when need as well as freezes it.
When toggled off, unfreezes time and procceds from the daytime which would be if there was no imitation called (that's the whole purpose of this function)
Change Divider if you have different day length.
Day imitation has higher priority than night imitation.
All needed comments are provided inside
JASS:
function ImitateDayNightEffectsTimeOperations takes nothing returns nothing
local integer dayCounter=LoadInteger(GlobalHashtable,'DTIM',0)
local integer nightCounter=LoadInteger(GlobalHashtable,'DTIM',1)
local real dayTimeStart
local real timerTimeStart
local real finalTime
if dayCounter==0 and nightCounter==0 then
call SaveBoolean(GlobalHashtable,'DTIM',0,false)
set dayTimeStart=LoadReal(GlobalHashtable,'DTIM',0)
set timerTimeStart=LoadReal(GlobalHashtable,'DTIM',1)
set finalTime=dayTimeStart+((TimerGetElapsed(GlobalTimer)-timerTimeStart)/ 25.0)
// divider 25.0 is related to DayLength = 600.0 in War3mapMisc.txt
if finalTime>= 24. then
set finalTime=finalTime-24.
endif
call SetFloatGameState(GAME_STATE_TIME_OF_DAY,finalTime)
call SuspendTimeOfDay(false)
elseif dayCounter>0 then
if not LoadBoolean(GlobalHashtable,'DTIM',0) then
call SaveBoolean(GlobalHashtable,'DTIM',0,true)
call SaveReal(GlobalHashtable,'DTIM',0,GetFloatGameState(GAME_STATE_TIME_OF_DAY))
call SaveReal(GlobalHashtable,'DTIM',1,TimerGetElapsed(GlobalTimer))
endif
call SetFloatGameState(GAME_STATE_TIME_OF_DAY,12)
call SuspendTimeOfDay(true)
elseif nightCounter>0 then
if not LoadBoolean(GlobalHashtable,'DTIM',0) then
call SaveBoolean(GlobalHashtable,'DTIM',0,true)
call SaveReal(GlobalHashtable,'DTIM',0,GetFloatGameState(GAME_STATE_TIME_OF_DAY))
call SaveReal(GlobalHashtable,'DTIM',1,TimerGetElapsed(GlobalTimer))
endif
call SetFloatGameState(GAME_STATE_TIME_OF_DAY,0)
call SuspendTimeOfDay(true)
endif
endfunction
function ImitateDayNightEffectToggle takes integer i returns nothing
//-1 to start night, -2 to end night, 1 to start day, 2 to end day
if i==-1 then
call SaveInteger(GlobalHashtable,'DTIM',1,LoadInteger(GlobalHashtable,'DTIM',1)+1)
elseif i==-2 then
call SaveInteger(GlobalHashtable,'DTIM',1,LoadInteger(GlobalHashtable,'DTIM',1)-1)
elseif i==1 then
call SaveInteger(GlobalHashtable,'DTIM',0,LoadInteger(GlobalHashtable,'DTIM',0)+1)
elseif i==2 then
call SaveInteger(GlobalHashtable,'DTIM',0,LoadInteger(GlobalHashtable,'DTIM',0)-1)
else
return
endif
call ImitateDayNightEffectsTimeOperations()
endfunction