# SnippetArmor

#### Dirac

##### 22710180
JASS:
``````library Armor /* v1.0.0

*/uses/*
*/  Damage  /* thehelper.net/forums/showthread.php/168144-Damage-Struct

Useful tool for unit armor reduction and armor amount calculation

**********************************************************************/
globals
//*********************************************************************
//  The gameplay constant that sets how much damage the armor reduces.
private constant real ARMOR_REDUCTION           =   0.06
//*********************************************************************
//  The gameplay constant for ethereal damage modification
private constant real ETHEREAL_ARMOR_REDUCTION  =   1.66
endglobals
/**********************************************************************
*
*   function GetUnitDamageReduction takes unit whichUnit, attacktype attackType, damagetype damageType returns real
*       -   If returns 1.00 means it takes 100% damage.
*   function GetUnitArmor takes unit whichUnit returns real
*       -   Calculates the unit&#039;s armor, as accurate as it gets.
*
**********************************************************************/

private function Ln takes real a returns real
local real sum = 0.0
loop
exitwhen a &lt; bj_E
set a = a/bj_E
set sum = sum + 1.
endloop
return sum + (a-1.)*(1. + 9./(2.+a) + 9./(1.+a*2.) + 1/a)/8.
endfunction

function GetUnitDamageReduction takes unit whichUnit, attacktype attackType, damagetype damageType returns real
local real result
local real prevLife=GetWidgetLife(whichUnit)

//*********************************************************************
//  Deals 100 damage that ignores armor type to the unit, and from the
//  unit&#039;s remaining life we know how much damage was reduced.
//  To prevent the unit from dying from damage dealt this way the life
//  bonus ability is added
set Damage.enabled=false
set result=GetWidgetLife(whichUnit)
call UnitDamageTarget(whichUnit,whichUnit,100,true,false,attackType,damageType,null)
set Damage.enabled=true
set result=result-GetWidgetLife(whichUnit)
call UnitRemoveAbility(whichUnit,ABILITY_LIFE_BONUS)
call SetWidgetLife(whichUnit,prevLife)
return result/100
endfunction

function GetUnitArmor takes unit whichUnit returns real
local real reduction=GetUnitDamageReduction(whichUnit,ATTACK_TYPE_CHAOS,DAMAGE_TYPE_NORMAL)

//*********************************************************************
//  (armor)*0.06/(1+armor*0.06) = reduction
if 0==reduction then
set reduction=GetUnitDamageReduction(whichUnit,ATTACK_TYPE_MAGIC,DAMAGE_TYPE_NORMAL)
return ((1-reduction)/(ARMOR_REDUCTION*(reduction)))/ETHEREAL_ARMOR_REDUCTION
endif
if reduction&lt;=1 then
return (1-reduction)/(ARMOR_REDUCTION*(reduction))
endif

//*********************************************************************
//  Ln of 0.94, w3&#039;s magic number for negative armor.
return -(Ln(2-reduction)/-0.061875)
endfunction
endlibrary``````

#### Dirac

##### 22710180
Please graveyard this as it is no longer required, it's now implemented inside Damage by default.

#### GFreak45

##### I didnt slap you, i high 5'd your face.
if you want it GY'd report it yourself and it wont go negatively for you but it will bring it to the attention of the mods

#### tooltiperror

##### Super Moderator
if you want it GY'd report it yourself and it wont go negatively for you but it will bring it to the attention of the mods
What GFreak said. This will be added to submission rules (eventually).

#### Sim

Staff member
Ungraveyarded as per Dirac's inquiry.

#### Magthridon96

##### Member
Newsflash:
The whole 0 == x is faster than x == 0 is total baloney. (According to recent benchmarks by Anitarf)

#### tooltiperror

##### Super Moderator
You should have posted the link

Regardless of if either was faster, you should not have been doing it anyways. As Anitarf points out, it is probably CPU (processor) specific.

#### Bribe

##### vJass errors are legion
Or another speedfreak myth like that nonsense Increment/Decrement Captain Griffin tried a few months ago.

#### Mabaet.Baet

##### Member
The system deals damage to the unit. Which triggers the
JASS:
``call TriggerRegisterUnitEvent(trigger,whichUnit,EVENT_UNIT_DAMAGED)``
which is used by many spells or other systems. Example, if a hero has a damage reflecting aura(like Spectre's DotA Dispersion), and detects armor, it will deal damage to surrounding units and players would think it is bug(it is). More dangerous if this unit's armor is being detected every period.

I need these system, but it conflicts with spells that I use with damage detect. Please fix D:

#### Magthridon96

##### Member
I know you're going to think I'm crazy for this, but:

JASS:
``return -(Ln(2-reduction)/-0.061875)``

->
JASS:
``return Ln(2-reduction)/0.061875``

General chit-chat
Help Users
• No one is chatting at the moment.
• tom_mai78101:
As for Github, I often frequent there, boasting about my genetic algorithm for tools-assisted speedrunning and such. I'm also pretty active on Discord, with my tag @asperatology.
• tom_mai78101:
Yeah, the whole earthquake + air pollution combo made me completely forget about bringing updates. I'll be sure to keep on top of things after all things are less requiring my attentions.
+2
• The Helper:
I am just glad that you are OK Tom! Thank you for the update!
• Varine:
Glad to hear you're okay! I only knew about your Github cuz I tried to follow some of you when I was learning how to program, but didn't understand any of it so kind of quit paying attention to what anyone does on it
• The Helper:
Freaking storm outside is kicking!
• Blackveiled:
I wouldn't know, I'm in Joliet, Illinois right now working. I left Houston area about 2 weeks ago lol
• Blackveiled:
Not permanently of course, just a temporary job.
+1
• jonas:
Glad you're ok @tom_mai78101
• jonas:
@Blackveiled you know another word for permanent? temporary
+1
• Varine:
Briefly, he'll only be there for the interim. Like a stopgap of sorts, he'll be back home in short time
• O Old Mountain Shadow:
Hurray! Tom has reappeared!
• The Helper:
Happy Thursday!
• Blackveiled:
Yep. Just another fun night at work.
• Varine:
Broke the nozzle on my 3d printer and I don't have another heater block. So... I guess I'm fucked on that this weekend
• The Helper:
that sucks i bet they are expensive
• Varine:
Not really
• Varine:
The entire hot end is like 20 dollars, I just can't get anymore until next week
• Varine:
I ordered like five blocks for 15 dollars. They're just little aluminum blocks with holes drilled into them
• Varine:
They are pretty much disposable. I have shitty nozzles though, and I don't think these were designed for how hot I've run them
• Varine:
I tried to extract it but the thing is pretty stuck. Idk what else I can use this for
• Varine:
I'll throw it into my scrap stuff box, I'm sure can be used for something
• Varine:
I have spare parts for like, everything BUT that block lol. Oh well, I'll print this shit next week I guess. Hopefully it fits