Page 1 of 1

Average Percentage Attrition

Posted: Sat Jan 01, 2022 3:32 pm
by SeaQueen
Lately I've been fascinated by air interdiction. The problem is that unless it's CAS, they're usually hunting for elements of larger operational level units (brigades or divisions) and not individual platoons. Realistic mission objectives might be stated something like, "Draw down the XXth Guards Motor Rifle Brigade to 25%." That presents a problem when you're dropping bombs on the sections, platoons and batteries that make it up. How does one determine that the brigade a given game unit belongs to has been drawn down to the desired level? It can't be just 25% of the units destroyed, because damaging units ought to count too. They're talking about 25% of the total available combat power. I wrote this function to help answer that question. Destroyed units count as 100% attrition, while damaged units count for something less than that. It then averages over all the constituent units you add to the list.

Code: Select all

-- Returns the average percentage damage of a given set of units.  Intended to be used for calculating the attrition of larger ground forces.
 
 unitOfInterest = {
 -- guids go here
 }
 
 function averageAttrition(units, mySide)
     totalDpPercent = 0
     avgDpPercent = 0        
     for u, unt in ipairs(units) do
         if(ScenEdit_GetUnit( { side=mySide, guid=unt } )  ~= nil) then
             unit = ScenEdit_GetUnit( { side=mySide, guid=unt } )        
             print(unit.name.." Damaged: "..unit["damage"].dp_percent)
             totalDpPercent = totalDpPercent + unit["damage"].dp_percent
         else
             totalDpPercent = totalDpPercent + 100
         end        
     end
     avDpPercent = totalDpPercent / (#units)
     return avDpPercent
 end
 
 print(averageAttrition(unitOfInterest, "RED"))

RE: Average Percentage Attrition

Posted: Mon Jan 03, 2022 11:40 am
by Parel803
nice, thx. Gonna test it out.
regards GJ