• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Help me with my indentation.

Status
Not open for further replies.
Level 17
Joined
Jul 17, 2011
Messages
1,863
i had some trouble indenting my code until i read jpag so far i followed all the
conventions but i always miss something so could any 1 point bad
indentation in this code? ill + rep if u help


JASS:
library GetUnitArmorType requires Ln /* v6
******************************************************************************************************************************************************************************************************************
*    
*   An armor detection system which returns a unit's armor amount, damage reduction (%), and the unit's armor type
*   the origina system made by Daelin does not get the armor type and uses a slower logorithm. With this system you can get
*   all of the mentioned by calling 3 different functions.
*
******************************************************************************************************************************************************************************************************************
 *          Credits:
 *          -------------------
 *           BLINKBOY:  NaturalLogarithm
 *          
 *           DAELIN : ORIGINAL armor utils
 *          
 *           RISING_DUSK: Modified Armor Utils
 *
 ******************************************************************************************************************************************************************************************************************
 *
 *              Requires:
 *              ---------------
 *              NaturalLogarithm - [url]http://www.hiveworkshop.com[/url] / forums / jass - resources - 412 / snippet - natural - logarithm - 108059 / 
 *
 *
******************************************************************************************************************************************************************************************************************
 *
 *
 *                SETTINGS
 *
 */
globals     
        private  constant real               ARMORDAMAGE                 = 1000  // amount of damage used to get armor
        private  constant real               ARM                                = 0.06   // armor reduction multiplyer 
        public   constant real               ARMOR_INVULNERABLE        = 999999999
        private  constant attacktype      DMG2                              = ATTACK_TYPE_PIERCE //attack used to get the armor amount
        private  constant attacktype      DMG1                              = ATTACK_TYPE_CHAOS //attack used to get the armor type 
        private  constant real               ACCURACY_FACTOR           = 0.997    
        private  constant integer          GUA_HP_BONUS                 = 'rofl'      //hp bonus ability copy it or make your own
endglobals
/*
 *******************************************************************************************************************************************************************************************************************           
 *              Functions:
 *
 *            function GetUnitArmorValue takes unit u returns real 
 *                  -       returns the amount of your unit's armor with up to 3 decimal figures
 *                  
 *             function GetUnitArmorReduction takes unit u returns real 
 *                  -       returns the % damage reduction your unit has to verify this check the damage reduction text in the armor tooltip, this system does not round the values so it the armor tooltip says 16% the system might have 0.157% *
 *            
 *             function GetUnitArmorType takes unit u returns integer
 *                   -      returns the type (an integer value) of armor your unit has. Refer to example trigger b for more info. 
 *
*******************************************************************************************************************************************************************************************************************
*/
      

function GetUnitArmorValue takes unit u returns real 

    local real life = GetWidgetLife(u)
    local real life2 = life
    local real calc = 0.

    if u != null and life >= 0.405 then
            if GetUnitState(u, UNIT_STATE_MAX_LIFE) <= ARMORDAMAGE then
                call UnitAddAbility(u, GUA_HP_BONUS)
            endif
                    if life <= ARMORDAMAGE - (ARMORDAMAGE * 0.20) then
                        call SetWidgetLife(u, ARMORDAMAGE + (ARMORDAMAGE * 0.50) )
                    endif
    endif
    
    set life2 = GetWidgetLife(u)
    call UnitDamageTarget(u, u, ARMORDAMAGE, false, false, DMG1, DAMAGE_TYPE_NORMAL, null)
    set calc = (ARMORDAMAGE - life2 + GetWidgetLife(u)) / ARMORDAMAGE
    call UnitRemoveAbility(u, GUA_HP_BONUS)
    call SetWidgetLife(u, life)
    
    if calc >= 1. then
        return ARMOR_INVULNERABLE
            elseif calc < 0. then
                return - 1 * logarithm(calc + 1.) / -0.061875
    else
        return calc / (ARM * (1. - calc))
    endif
    return 0.
endfunction


                    

function GetUnitArmorReduction takes unit u returns real
    local real armorAmount = GetUnitArmorValue(u)
        if armorAmount > 0 then
            return ((armorAmount) * ARM) / (1 + ARM * (armorAmount))
        endif
    return 1 - 2 + Pow(0.94, -armorAmount)
endfunction
 

function GetUnitArmorType takes unit u returns integer
    local integer loopz = 0
    local integer loopz1 = 0
    local real reduc = 1
    local real array expected
    local real life = GetWidgetLife(u)
    local real lifeMAX = life
    local real reduction = GetUnitArmorReduction(u)
    local real damage
    local real accurasy = ACCURACY_FACTOR
    local real dmgForThisTrigger
    local real accuracy
    local real accuracy2
    /*
    *higher armor values require higher accuracy due to the decrease in damage, lower armor especially armor which 
    *amplifies damage requires less accuracy
    */
    if reduction > .90 then 
        set accurasy = 0.999
        set dmgForThisTrigger = ((ARMORDAMAGE / 100) - ((ARMORDAMAGE / 100) * reduction) ) * ARMORDAMAGE
        set accuracy = dmgForThisTrigger - (dmgForThisTrigger * accurasy)
        set accuracy2 = -1 * (accuracy)
    endif
    
    if reduction <= -0.10 then
        set accurasy = 0.990
        set dmgForThisTrigger = ((ARMORDAMAGE / 100) - ((ARMORDAMAGE / 100) * reduction) ) * ARMORDAMAGE
        set accuracy = dmgForThisTrigger - (dmgForThisTrigger * accurasy)
        set accuracy2 = -1 * (accuracy)
    endif
    
    if reduction >= 0 and reduction <= .90 then
        set dmgForThisTrigger = ((ARMORDAMAGE / 100) - ((ARMORDAMAGE / 100) * reduction) ) * ARMORDAMAGE
        set accuracy = dmgForThisTrigger - (dmgForThisTrigger * ACCURACY_FACTOR)
        set accuracy2 = -1 * (accuracy)
                
    endif
                
                
    if reduction >= 0 then
        loop
                exitwhen loopz1 > 8
                set loopz1 = loopz1 + 1
                set expected[loopz1] = (dmgForThisTrigger - (dmgForThisTrigger * reduction)) * reduc
                set reduc = reduc - 0.10
        endloop
    endif
    
    if reduction < 0 then
        set loopz1 = 0
        set reduc = 1.0
            loop
                    exitwhen loopz1 > 8
                    set loopz1 = loopz1 + 1
                    set expected[loopz1] = ((dmgForThisTrigger + (dmgForThisTrigger * (reduction * ( -1.0)))) * reduc)
                    set reduc = reduc - 0.10
            endloop
    endif
                
    if u != null and GetWidgetLife(u) >= 0.405 then
            if GetUnitState(u, UNIT_STATE_MAX_LIFE) <= dmgForThisTrigger then
                call UnitAddAbility(u, GUA_HP_BONUS)
                set life = GetWidgetLife(u)
            endif
                    if GetWidgetLife(u) <= dmgForThisTrigger - (dmgForThisTrigger * 0.20) then
                        call SetWidgetLife(u, dmgForThisTrigger + (dmgForThisTrigger * 0.50) )
                    endif
    endif

    set life = GetWidgetLife(u)
    call UnitDamageTarget(u, u, dmgForThisTrigger, false, false, DMG2, DAMAGE_TYPE_NORMAL, null) //dont change this damage type to something else the system will bug
    set damage = life - GetWidgetLife(u)
    call UnitRemoveAbility(u, GUA_HP_BONUS)
    call SetWidgetLife(u, lifeMAX)
    
    loop
            exitwhen loopz > 8
                if damage - expected[loopz] <= accuracy and damage - expected[loopz] >= accuracy2 then
                    return loopz
                endif
            set loopz = loopz + 1
    endloop
    return 0
endfunction
  
endlibrary


//Code indented using The_Witcher's Script Language Aligner
//Download the newest version and report bugs at [url]www.hiveworkshop.com[/url]
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
JASS:
globals     
        private  constant real               ARMORDAMAGE                 = 1000  // amount of damage used to get armor
        private  constant real               ARM                                = 0.06   // armor reduction multiplyer 
        public   constant real               ARMOR_INVULNERABLE        = 999999999
        private  constant attacktype      DMG2                              = ATTACK_TYPE_PIERCE //attack used to get the armor amount
        private  constant attacktype      DMG1                              = ATTACK_TYPE_CHAOS //attack used to get the armor type 
        private  constant real               ACCURACY_FACTOR           = 0.997    
        private  constant integer          GUA_HP_BONUS                 = 'rofl'      //hp bonus ability copy it or make your own
endglobals
Not tabbed correctly (all the names and values should line up)

JASS:
if u != null and life >= 0.405 then
            if GetUnitState(u, UNIT_STATE_MAX_LIFE) <= ARMORDAMAGE then
                call UnitAddAbility(u, GUA_HP_BONUS)
            endif
                    if life <= ARMORDAMAGE - (ARMORDAMAGE * 0.20) then
                        call SetWidgetLife(u, ARMORDAMAGE + (ARMORDAMAGE * 0.50) )
                    endif
    endif
The 2 if's inside the first IF-block should be on the same level.
Like this:
JASS:
if u != null and life >= 0.405 then
    if GetUnitState(u, UNIT_STATE_MAX_LIFE) <= ARMORDAMAGE then
        call UnitAddAbility(u, GUA_HP_BONUS)
    endif
    if life <= ARMORDAMAGE - (ARMORDAMAGE * 0.20) then
        call SetWidgetLife(u, ARMORDAMAGE + (ARMORDAMAGE * 0.50) )
    endif
endif

JASS:
    if calc >= 1. then
        return ARMOR_INVULNERABLE
            elseif calc < 0. then
                return - 1 * logarithm(calc + 1.) / -0.061875
    else
        return calc / (ARM * (1. - calc))
    endif
Personally, I would prefer this:
JASS:
if boolexpr then
    // Actions 1
elseif boolexpr then
    // Actions 2
else
    // Actions 3
endif

The actions inside the IF-block should be indented, not the IF-block itself.
Same goes for loop-blocks (and pretty much everything else) by the way, you do this multiple times.
JASS:
function GetUnitArmorReduction takes unit u returns real
    local real armorAmount = GetUnitArmorValue(u)
    if armorAmount > 0 then
        return ((armorAmount) * ARM) / (1 + ARM * (armorAmount))
    endif
    return 1 - 2 + Pow(0.94, -armorAmount)
endfunction

JASS:
loop
                exitwhen loopz1 > 8
                set loopz1 = loopz1 + 1
                set expected[loopz1] = (dmgForThisTrigger - (dmgForThisTrigger * reduction)) * reduc
                set reduc = reduc - 0.10
endloop
Seems like you tabbed a little too much. Stick to 1 tab:
JASS:
loop
    exitwhen loopz1 > 8
    set loopz1 = loopz1 + 1
    set expected[loopz1] = (dmgForThisTrigger - (dmgForThisTrigger * reduction)) * reduc
    set reduc = reduc - 0.10
endloop

JASS:
if u != null and GetWidgetLife(u) >= 0.405 then
        if GetUnitState(u, UNIT_STATE_MAX_LIFE) <= dmgForThisTrigger then
            call UnitAddAbility(u, GUA_HP_BONUS)
            set life = GetWidgetLife(u)
        endif
                if GetWidgetLife(u) <= dmgForThisTrigger - (dmgForThisTrigger * 0.20) then
                    call SetWidgetLife(u, dmgForThisTrigger + (dmgForThisTrigger * 0.50) )
                endif
endif
Both secondary IF-blocks should be on the same level.


This is all I could find. I hope it's of any use to you (I also hope all of it is correct :p).
 
All blocks of the code(Ex.function,loop and if)should be 4 spaces far from the preceeding and next code.
Ex.
[jass=]
if true then
call DoNothing()
endif

//For many codes:
function Hello takes nothing returns nothing
loop
exitwhen u == null
if u == p then
call BJDebugMsg("Hello World")
endif
endloop
endfunction

//Using libraries scopes and structs
library Hello
function Hello takes nothing returns nothing
loop
exitwhen u == null
if u == p then
call BJDebugMsg("Hello World")
endif
endloop
endfunction
endlibrary[/code]
You should have read this:
http://www.hiveworkshop.com/forums/...80/jpag-jass-proper-application-guide-204383/
 
Status
Not open for further replies.
Top