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.
 

Romek

Super Moderator
Reaction score
963
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?
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
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
 

Laiev

Hey Listen!!
Reaction score
188
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>
    
*/
 

tooltiperror

Super Moderator
Reaction score
231
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
 

tooltiperror

Super Moderator
Reaction score
231
Hasn't been looked at in months.

Graveyarded.
 
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