Need help with finding some bug.

Viikuna

No Marlo no game.
Reaction score
265
edit. Got it working, it was a stupid little mistake. You can stll try to find it for fun, if you like.


Okay, I have this DayNightFog -system for changing terrain fog.
Its not working ( edit. forgot to tell that not working means that fogs not changing..), ( probably due some stupid li´l mistake, but there might be something else too.. )

And I would like to hear some comments about this system, because I might submit it someday.

code:
JASS:
library DayNightFog

globals
    private constant real DAWN_TIME = 6.00
    private constant real DUSK_TIME = 18.00
    private constant real TIMEOUT = .03
    // For initial day time:
    private constant boolean IT_IS_DAY = true
    private constant real INITIAL_FOG_CHANGE_DURATION = 10.
endglobals

//=======================================================================
// Fog System includes:
//                       -struct fog
//                                  - color and z values and change duration
//                                  - method copyValues takes fog source
//
//                       -array struct PlayerFogData
//                                  - fog day
//                                  - fog night
//                                  - fog special
//                                  - boolean useSpecial
//                                  - boolean useFog
//                                  - method refresh takes boolean instant
//
//=======================================================================
//=======================================================================
struct fog
    real red
    real green
    real blue
    real zstart
    real zend
    real changeDuration
    
    static method create takes real red, real green, real blue, real zstart, real zend returns fog
        local fog f=fog.allocate()
        set f.red=red
        set f.green=green
        set f.blue=blue
        set f.zstart=zstart
        set f.zend=zend
        set f.changeDuration=INITIAL_FOG_CHANGE_DURATION
        return f
    endmethod
    
    method copyValues takes fog source returns nothing
        set .red=source.red
        set .green=source.green
        set .blue=source.blue
        set .zstart=source.zstart
        set .zend=source.zend
    endmethod
endstruct
//=======================================================================
struct PlayerFogData extends array
//=======================================================================
    fog day
    fog night
    fog special
    boolean useSpecial
    boolean useFog
    
    private static boolean IsDay=IT_IS_DAY  
   method operator isDay takes nothing returns boolean
      return .IsDay
   endmethod
   
//====================================================== 
//======================================================     
    private integer id
    private fog now
    private fog velocity
    private fog target
    private integer iterations
    private boolean change
    private static timer T=CreateTimer()
    private static boolean timer=false
    private static trigger Dawn=CreateTrigger()
    private static trigger Dusk=CreateTrigger()
    
    method refresh takes boolean instant returns nothing
        local fog f
        local real red
        local real blue
        local real green
        local real zstart
        local real zend
        if .useFog then
            if .useSpecial and integer(.special)!=0 then
                set f=.special
            else
                if .IsDay and integer(.day)!=0 then
                    set f=.day
                else
                    if integer(.night)!=0 then
                        set f=.night 
                    endif
                endif
            endif
            if integer(f)!=0 then
                if instant then
                    call .now.copyValues(f)
                    set red=.now.red
                    set blue=.now.blue
                    set green=.now.green
                    set zstart=.now.zstart
                    set zend=.now.zend
                    if GetLocalPlayer()==Player(.id) then
                        call SetTerrainFogEx(0,zstart,zend,0.0,red,green,blue)
                   endif
                else
                    set .iterations=R2I(f.changeDuration/TIMEOUT)
                    call .target.copyValues(f)
                    set .velocity.red=(.target.red-.now.red)/.iterations
                    set .velocity.green=(.target.green-.now.green)/.iterations
                    set .velocity.blue=(.target.blue-.now.blue)/.iterations
                    set .velocity.zstart=(.target.zstart-.now.zstart)/.iterations
                    set .velocity.zend=(.target.zend-.now.zend)/.iterations
                    set .change=true
                    if not .timer then
                        set .timer=true
                        call TimerStart(.T,TIMEOUT,true,function PlayerFogData.periodic)
                    endif
                endif
            endif
        endif
    endmethod
    
    //! textmacro Limits takes VALUE
        if $VALUE$ > 1. then
           set $VALUE$=1.
        else
           if $VALUE$ < 0. then
              set $VALUE$ = 0.
           endif
        endif
    //! endtextmacro
    
    private static method periodic takes nothing returns nothing
        local integer i=0
        local integer endcount=12
        local PlayerFogData f
        local real red
        local real blue
        local real green
        local real zstart
        local real zend
        loop
           exitwhen i>11
           set f=PlayerFogData<i>
           if f.change and f.useFog then
               if f.iterations&gt;0 then
                   set f.iterations=f.iterations-1
                   set red=f.now.red+f.velocity.red
                   set green=f.now.green+f.velocity.green
                   set blue=f.now.blue+f.velocity.blue
                   set zstart=f.now.zstart+f.velocity.zstart
                   set zend=f.now.zend+f.velocity.zend
               else
                   set f.change=false
                   set red=f.target.red
                   set blue=f.target.blue
                   set green=f.target.green
                   set zstart=f.target.zstart
                   set zend=f.target.zend
               endif
               //! runtextmacro Limits(&quot;red&quot;)
               //! runtextmacro Limits(&quot;green&quot;)
               //! runtextmacro Limits(&quot;blue&quot;)
               if GetLocalPlayer()==Player(i) then
                   call SetTerrainFogEx(0,zstart,zend,0.0,red,green,blue)
               endif
               set f.now.red=red
               set f.now.green=green
               set f.now.blue=blue
               set f.now.zstart=zstart
               set f.now.zend=zend
           else
              if f.change and not f.useFog then
                 set f.change=false
              endif
              set endcount=endcount-1
              if endcount==0 then
                  call PauseTimer(.T)
                  set .timer=false
              endif
           endif
           set i=i+1
         endloop
    endmethod
    
    private static method IsItDawnYet takes nothing returns boolean
        local integer i=0
        set .IsDay=true
        loop
            exitwhen i&gt;11
            call PlayerFogData<i>.refresh(false)
            set i=i+1
        endloop
        return false
    endmethod
    private static method IsItDuskYet takes nothing returns boolean
        local integer i=0
        set .IsDay=false
        loop
            exitwhen i&gt;11
            call PlayerFogData<i>.refresh(false)
            set i=i+1
        endloop
        return false
    endmethod
    
    private static method onInit takes nothing returns nothing
        local integer i=0
        loop
            exitwhen i&gt;11
            set PlayerFogData<i>.useSpecial=false
            set PlayerFogData<i>.change=false
            set PlayerFogData<i>.useFog=false
            set PlayerFogData<i>.iterations=0
            set PlayerFogData<i>.now=fog.create(0.0,0.0,0.0,0.0,0.0)
            set PlayerFogData<i>.velocity=fog.create(0.0,0.0,0.0,0.0,0.0)
            set PlayerFogData<i>.target=fog.create(0.0,0.0,0.0,0.0,0.0)
            set PlayerFogData<i>.id=i
            set i=i+1
        endloop
        call TriggerRegisterGameStateEvent(.Dawn,GAME_STATE_TIME_OF_DAY,EQUAL,DAWN_TIME)
        call TriggerRegisterGameStateEvent(.Dusk,GAME_STATE_TIME_OF_DAY,EQUAL,DUSK_TIME)
        call TriggerAddCondition(.Dawn,Condition(function PlayerFogData.IsItDawnYet))
        call TriggerAddCondition(.Dusk,Condition(function PlayerFogData.IsItDuskYet))
    endmethod
endstruct

endlibrary</i></i></i></i></i></i></i></i></i></i></i>


example of usage:
JASS:
    local fog f1=fog.create(.764,.812,.831,0.0,12000.)
    local fog f2=fog.create(.121,.164,.731,0.0,3500.)
    set PlayerFogData[0].useFog=true
    set PlayerFogData[0].day=f1
    set PlayerFogData[0].night=f1
    call SetTimeOfDay(10.0)
    call PlayerFogData[0].refresh(true)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top