The first block of code you quoted refers exclusively to the effect of bunker gear on fire damage. Damaged bunker gear halves fire damage, while undamaged bunker gear -- regardless of quality -- quarters it.
In the second code block, each total armor point reduces mod2 by 1, damaged gear reduces mod2 by an additional 1. Twice mod2 is subtracted from mod if mod2 is positive -- so armor has no effect on mod if it's so damaged that the effect would be negative. The actual damage is altered based on mod -- if mod is below 0, damage is reduced greatly, and if it's above 0, it's increased greatly. mod is a measure of how "critical" or "glancing" the blow is.
Example:
1. mod starts out at 0 (a glancing blow). You have a first-rate armor 2 item. mod2 becomes 2, mod becomes -4, and the damage inflicted is 1/16 normal.
2. mod starts out at 2 (a well-aimed hit). You have a fourth-rate armor 2 item. mod2 becomes -1 (your armor is shoddy to the point of uselessness), mod is unchanged and remains 2, and the damage inflicted is four times normal.
3. mod starts out at 5 (a vital hit). You have a damaged second-rate armor 7 item. mod2 becomes 5 (-1 for damage, -1 for quality), mod becomes -5 (-[5*2] for mod2), and the damage inflicted is 1/16 normal. Thick armor, even if shoddy, saved you from a good blow. If it's a rifle, you'll probably still take damage and be bleeding, but not be killed.
4. mod starts out at 18, because the attacker is a flippin' ninja. You are an Abrams tank with armor plating of 15. mod2 becomes -15, mod becomes -12, and damage inflicted is 1/64 normal. Have fun hacking that tank apart with your sword.
The base damage coming into this is determined by the weapon; shotguns and assault rifles can do huge damage, while a syringe is likely to have negligible base damage. Obviously, even an empty fist, with a sufficiently high mod value, with do crippling damage, and a katana with a very negative mod value will only shave a few unnoticeable points off the enemy's health (especially because tanks don't bleed out after being cut). The initial value of mod is determined by the health of the target (high health reduces it, low health increases it) and the relative attack and defense rolls (a huge to-hit roll increases it, a glancing blow reduces it). Even if all factors favor the defender, mod will never go below 0 and thus result in less than normal damage unless armor is applied.
Edit: Pardon, as complicated as my explanation is, it's still wrong -- though it's close. mod2 also includes another random amount of armor (0-armor) and subtracts off the armorpenetration value of the weapon. For melee weapons, armorpenetration goes up by 1 for each 4 points of strength you have above the minimum strength needed to use the weapon effectively. So a good ninja will have some armorpenetration against the tank, but is still unlikely to cleave through it. I won't change my examples because I don't have time. I have work to do.