Snippet Weather

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
Weather v1.0.0
JASS:

/*
    Weather 
    v1.0.0
    by kingking
    
    ===================
    What is Weather?
    ===================
    Weather gives you better APIs for weather.
    
    =======
    API :
    =======
    Static method :
    Weather.create() -> Weather
    - Returns a new instance.
    
    Methods :
    this.type=whichType
    - Set weather type.
    
    this.rect=whichRect
    - Set which rect for weather to be applied.
    
    this.enabled=True/False
    - Enable/Disable weather. (Works even in GetLocalPlayer() block.)
    
    this.destroy()
    - Destroy weather.
    
    Jass :
    SetWorldWeatherForPlayer(player,weather type)
    - Adjust world weather for player.
    
    EnableWorldWeatherForPlayer(player,boolean)
    - Enable/Disable world weather for player.
    
    =======================
    Implementation steps :
    =======================
    1) Copy this trigger to your map.
    2) Enjoy!
    
    ==============
    Requirement :
    ==============
    Jasshelper 0.A.2.B or later.
    
    ===================
    Works well with :
    ===================
    Weather Type : <a href="http://www.thehelper.net/forums/showthread.php/141522-Weather-Type" class="link link--internal">http://www.thehelper.net/forums/showthread.php/141522-Weather-Type</a>
    
*/
library Weather initializer onInit

    globals
        private integer array WorldWeather
    endglobals
    
    struct Weather
        private weathereffect we
        private integer wetype
        private rect re
        
        method operator type= takes integer i returns nothing
            set this.wetype=i
            if this.re!=null then
                call RemoveWeatherEffect(this.we)
                set this.we=AddWeatherEffect(this.re,i)
                call EnableWeatherEffect(this.we,true)
            endif
        endmethod
        
        method operator rect= takes rect r returns nothing
            set this.re=r
            if this.wetype!=0 then
                call RemoveWeatherEffect(this.we)
                set this.we=AddWeatherEffect(r,this.wetype)            
                call EnableWeatherEffect(this.we,true)
            endif
        endmethod
        
        method operator enabled= takes boolean b returns nothing
            call EnableWeatherEffect(this.we,b)
        endmethod
        
        method destroy takes nothing returns nothing
            call RemoveWeatherEffect(we)
            set this.we=null
            set this.re=null
            set this.wetype=0
        endmethod
        
        private static method onInit takes nothing returns nothing
            local integer i=0
            loop
                set WorldWeather<i>=Weather.create()
                set Weather(WorldWeather<i>).rect=GetWorldBounds()
                set i=i+1
            exitwhen i==bj_MAX_PLAYERS
            endloop
        endmethod
    endstruct
    
    function SetWorldWeatherForPlayer takes player p, integer dat returns nothing
        local Weather w=WorldWeather[GetPlayerId(p)]
        set w.type=dat
        set w.enabled=false
        if GetLocalPlayer()==p then
            set w.enabled=true
        endif
    endfunction
    
    function EnableWorldWeatherForPlayer takes player p, boolean boo returns nothing
        local Weather w=WorldWeather[GetPlayerId(p)]
        if GetLocalPlayer()==p then
            set w.enabled=true
        endif
    endfunction

endlibrary
</i></i>

It is basically wrappers for weather, and provides extra functionality. :D

History :
v1.0.0 - First release.
 
JASS:
        set w.enabled=false
        if GetLocalPlayer()==p then
            set w.enabled=true
        endif

->
JASS:
set w.enabled = GetLocalPlayer() == p

Your code doesn't have much going for it in terms of readability anyway.

I'm not too sure about the whole purpose of this. Are the standard weather natives really that bad?
 
It would be cool if it included a list of the weather types. Those are always annoying to lookup:
JASS:
globals
    constant integer ASHENVALE_RAIN_HEAVY    = &#039;RAhr&#039;
    constant integer ASHENVALE_RAIN_LIGHT    = &#039;RAlr&#039;
    constant integer DALARAN_SHIELD          = &#039;MEds&#039;
    constant integer DUNGEON_BLUE_FOG_HEAVY  = &#039;FDbh&#039;
    constant integer DUNGEON_BLUE_FOG_LIGHT  = &#039;FDbl&#039;
    constant integer DUNGEON_GREEN_FOG_HEAVY = &#039;FDgh&#039;
    constant integer DUNGEON_GREEN_FOG_LIGHT = &#039;FDgl&#039;
    constant integer DUNGEON_RED_FOG_HEAVY   = &#039;FDrh&#039;
    constant integer DUNGEON_RED_FOG_LIGHT   = &#039;FDrl&#039;
    constant integer DUNGEON_WHITE_FOG_HEAVY = &#039;FDwh&#039;
    constant integer DUNGEON_WHITE_FOG_LIGHT = &#039;FDwl&#039;
    constant integer LORDAERON_RAIN_HEAVY    = &#039;RLhr&#039; 
    constant integer LORDAERON_RAIN_LIGHT    = &#039;RLlr&#039; 
    constant integer NORTHREND_BLIZZARD      = &#039;SNbs&#039;
    constant integer NORTHREND_SNOW_HEAVY    = &#039;SNhs&#039;
    constant integer NORTHREND_SNOW_LIGHT    = &#039;SNls&#039;
    constant integer OUTLAND_WIND_HEAVY      = &#039;WOcw&#039;
    constant integer OUTLAND_WIND_LIGHT      = &#039;WOlw&#039;
    constant integer RAYS_OF_LIGHT           = &#039;LRaa&#039;
    constant integer RAYS_OF_MOONLIGHT       = &#039;LRma&#039;
    constant integer WIND_HEAVY              = &#039;WNcw&#039;
endglobals
 
JASS:
 /*
   ===================
    Works well with :
    ===================
    Weather Type : <a href="http://www.thehelper.net/forums/showthread.php/141522-Weather-Type" class="link link--internal">http://www.thehelper.net/forums/showthread.php/141522-Weather-Type</a>
    
*/
 
JASS:
// onInit
                set Weather(WorldWeather<i>).rect=GetWorldBounds()
</i>

You're creating [LJASS]bj_MAX_PLAYER_SLOTS[/LJASS] rects when you only need one. I hate to do this, but you should actually use WorldBounds.

>private weathereffect we
>private integer wetype
>private rect re
Turn these into stacks and let us have a lot in one Weather :D
 
Hasn't been looked at in months.

Graveyarded.
 
General chit-chat
Help Users
  • The Helper The Helper:
    Happy Tuesday Night!
    +1
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    News portal has been retired. Main page of site goes to Headline News forum now
  • The Helper The Helper:
    I am working on getting access to the old news portal under a different URL for those that would rather use that for news before we get a different news view.
  • Ghan Ghan:
    Easily done
    +1
  • The Helper The Helper:
    https://www.thehelper.net/pages/news/ is a link to the old news portal - i will integrate it into the interface somewhere when i figure it out
  • Ghan Ghan:
    Need to try something
  • Ghan Ghan:
    Hopefully this won't cause problems.
  • Ghan Ghan:
    Hmm
  • Ghan Ghan:
    I have converted the Headline News forum to an Article type forum. It will now show the top 20 threads with more detail of each thread.
  • Ghan Ghan:
    See how we like that.
  • The Helper The Helper:
    I do not see a way to go past the 1st page of posts on the forum though
  • The Helper The Helper:
    It is OK though for the main page to open up on the forum in the view it was before. As long as the portal has its own URL so it can be viewed that way I do want to try it as a regular forum view for a while
  • Ghan Ghan:
    Yeah I'm not sure what the deal is with the pagination.
  • Ghan Ghan:
    It SHOULD be there so I think it might just be an artifact of having an older style.
  • Ghan Ghan:
    I switched it to a "Standard" article forum. This will show the thread list like normal, but the threads themselves will have the first post set up above the rest of the "comments"
  • The Helper The Helper:
    I don't really get that article forum but I think it is because I have never really seen it used on a multi post thread
  • Ghan Ghan:
    RpNation makes more use of it right now as an example: https://www.rpnation.com/news/
  • The Helper The Helper:
  • The Helper The Helper:
    What do you think Tom?

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top