Difference between revisions of "Template:Apparel AP Calculation"

From RimWorld Wiki
Jump to navigation Jump to search
m (Added documentation.)
 
(12 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{#vardefine: effectiveArmor |{{#expr: {{{1|armor}}} - {{{2|ap}}}}}}}<!--
+
{{#vardefine: effectiveArmor1 |{{#expr: {{{armor1|0}}} - {{{ap|0}}}}}}} <!--
 +
-->{{#vardefine: effectiveArmor2 |{{#expr: {{{armor2|0}}} - {{{ap|0}}}}}}} <!--
 +
-->{{#vardefine: effectiveArmor3 |{{#expr: {{{armor3|0}}} - {{{ap|0}}}}}}} <!--
 +
-->{{#vardefine: effectiveArmor4 |{{#expr: {{{armor4|0}}} - {{{ap|0}}}}}}} <!--
 +
-->{{#ifexpr: {{#var: effectiveArmor1}} < 0| {{#vardefine: effectiveArmor1 | 0 }} }} <!--
 +
-->{{#ifexpr: {{#var: effectiveArmor2}} < 0| {{#vardefine: effectiveArmor2 | 0 }} }} <!--
 +
-->{{#ifexpr: {{#var: effectiveArmor3}} < 0| {{#vardefine: effectiveArmor3 | 0 }} }} <!--
 +
-->{{#ifexpr: {{#var: effectiveArmor4}} < 0| {{#vardefine: effectiveArmor4 | 0 }} }} <!--
  
-->{{#vardefine: effectiveArmor | 150 }} <!--
+
-->{{#expr:100*(({{#ifexpr: (100-{{#var: effectiveArmor1}}) > 0 | {{#expr:100-{{#var: effectiveArmor1}}}} | 0}}/100.0) + ({{#ifexpr: ({{#var: effectiveArmor1}}/2.0) < (100.0-{{#var: effectiveArmor1}}/2.0) | {{#expr:{{#var: effectiveArmor1}}/2.0}} | {{#expr:100.0-{{#var: effectiveArmor1}}/2.0}} }}/100)* 0.5)
  
-->{{#ifexpr: {{#var: effectiveArmor}} < 0| {{#vardefine: effectiveArmor | 0 }} }}<!--
+
{{#if: {{{armor2|}}} | * (({{#ifexpr: (100-{{#var: effectiveArmor2}}) > 0 | {{#expr:100-{{#var: effectiveArmor2}}}} | 0}}/100.0) + ({{#ifexpr: ({{#var: effectiveArmor2}}/2.0) < (100.0-{{#var: effectiveArmor2}}/2.0) | {{#expr:{{#var: effectiveArmor2}}/2.0}} | {{#expr:100.0-{{#var: effectiveArmor2}}/2.0}} }}/100)* 0.5) }}
  
 +
{{#if: {{{armor3|}}} | * (({{#ifexpr: (100-{{#var: effectiveArmor3}}) > 0 | {{#expr:100-{{#var: effectiveArmor3}}}} | 0}}/100.0) + ({{#ifexpr: ({{#var: effectiveArmor3}}/2.0) < (100.0-{{#var: effectiveArmor3}}/2.0) | {{#expr:{{#var: effectiveArmor3}}/2.0}} | {{#expr:100.0-{{#var: effectiveArmor3}}/2.0}} }}/100)* 0.5) }}
  
-->{{#expr:({{#ifexpr: (100-{{#var: effectiveArmor}}) > 0 | {{#expr:100-{{#var: effectiveArmor}}}} | 0}}/100.0) + ({{#ifexpr: ({{#var: effectiveArmor}}/2.0) < (100.0-{{#var: effectiveArmor}}/2.0) | {{#expr:{{#var: effectiveArmor}}/2.0}} | {{#expr:100.0-{{#var: effectiveArmor}}/2.0}} }}/100)* 0.5}}
+
{{#if: {{{armor4|}}} | * (({{#ifexpr: (100-{{#var: effectiveArmor4}}) > 0 | {{#expr:100-{{#var: effectiveArmor4}}}} | 0}}/100.0) + ({{#ifexpr: ({{#var: effectiveArmor4}}/2.0) < (100.0-{{#var: effectiveArmor4}}/2.0) | {{#expr:{{#var: effectiveArmor4}}/2.0}} | {{#expr:100.0-{{#var: effectiveArmor4}}/2.0}} }}/100)* 0.5) }}
 +
}}<noinclude>{{Documentation}}</noinclude>

Latest revision as of 16:23, 4 March 2025

100

Documentation icon Template documentation[view] [edit] [history] [purge]

This template calculates the damage multiplier (as a percentage) for a given set of armors against an attacks's armor penetration. This is mainly used by Template:Apparel Protection Chart.

Formula[edit]

{{Apparel AP Calculation|armor1=|armor2=|armor3=|armor4=|ap=}}
  • armor1 = The armor value of the first set of appeal.
  • armor2 = The armor value of the second set of appeal. Ignored if not present.
  • armor3 = The armor value of the third set of appeal. Ignored if not present.
  • armor4 = The armor value of the fourth set of appeal. Ignored if not present.
  • ap = The armor penetration of the attack being tested. Defaults to 0.

Explanation[edit]

This template has 2 stages. First, it calculates the effective armor for the given ap. If no armor value defined, it uses 0 for this calculation. Then, it obtains the maximum value between the calculated number and 0:

effectiveArmor = max(armor - ap, 0)

For armor1 and each of the other armor values present, it multiples the default value 100 by:

 (max(100-effectiveArmor, 0) + min(effectiveArmor/2, 100-effectiveArmor/2) * 0.5)/100

If all armors were defined, the calculation would be:

100 * (max(100-effectiveArmor1, 0) + min(effectiveArmor1/2, 100-effectiveArmor1/2) * 0.5)/100 * (max(100-effectiveArmor2, 0) + min(effectiveArmor2/2, 100-effectiveArmor2/2) * 0.5)/100 * (max(100-effectiveArmor3, 0) + min(effectiveArmor3/2, 100-effectiveArmor3/2) * 0.5)/100 * (max(100-effectiveArmor4, 0) + min(effectiveArmor4/2, 100-effectiveArmor4/2) * 0.5)/100

Examples[edit]

{{Apparel AP Calculation|armor1={{Q|Marine armor|Armor - Sharp}}|ap={{Q|Chain shotgun|Armor Penetration}} }}

       31

{{Apparel AP Calculation|armor1={{Q|Marine armor|Armor - Sharp}}|ap={{Q|Charge rifle|Armor Penetration}} }}

       46.75

{{Apparel AP Calculation|armor1={{Q|Flack Vest|Armor - Sharp}}|armor2=42|ap={{Q|Charge rifle|Armor Penetration}} }}

       94.75