Code: Select all
// Removes newly dead men.
// Note, keeps a separate track of the unit's dead men in the "DeathMask" attrib to avoid VizQ issues with multiple calls to CasualtiesDie() before DestroyUnit() gets executed.
FUNCTION CasualtiesDie(me)
{
int manCount;
int baseManCount;
int full_strength;
int current_strength;
int currentFigures;
int newFigures;
int i;
int killed;
int killMask;
int index;
int index2;
int count;
int j;
baseManCount = GetBaseAttrib(me, "ManCount");
manCount = GetAttrib(me, "ManCount");
full_strength = GetBaseAttrib(me, "TotalMen");
current_strength = GetAttrib(me, "TotalMen");
currentFigures = 0;
for (i = 0; i < manCount; i++)
{
// if (GetUnitManDead(me, i) == 0)
if (GetDeathMaskManDead(me, i) == 0)
{
currentFigures += 1;
}
}
newFigures = current_strength * baseManCount;
newFigures /= full_strength;
newFigures = Min(newFigures + 1, manCount); // Can't have more than original number
newFigures = Max(newFigures, 1); // Can't have less than 1
killed = currentFigures - newFigures;
//DebugLogX("unit, baseManCount, manCount", me, baseManCount, manCount, 999);
//DebugLogX("unit, currentFigures, newFigures, killed", me, currentFigures, newFigures, killed);
GetCloseCombatFacingsAndRank(me);
count = 0;
if ((manCount > 1) && (killed > 0))
{
killMask = 0;
for (j = 0; j < killed; j++)
{
index = 0;
index2 = manCount - 1;
for (i = 0; i < manCount; i++)
{
if ((GetDeathMaskManDead(me, i) == 0) && (gFormationManFrontRank[i] == 1))
{
SetArray(index,i,1);
index++;
count++;
}
else
{
SetArray(index2,i,1);
index2--;
}
}
SortArray(count, 1);
index = Rand(0, Min(3,count - 1));
killMask += 1 << GetArray(index, 1);
}
if (killMask > 0)
{
SetAttrib(me, "DeathMask", GetAttrib(me, "DeathMask") | killMask);
AddVizFunctionCall("DestroyUnit", me, killMask); // This must be sent to VizQ otherwise man goes into "Wait" animation before running the death animation.
AddVizAnimNoWait(me,"DIE", killMask);
}
AddVizUnitFormationNoWait(me);
if (IsInCloseCombat(me) == 1)
{
TriggerDifferentialAnimation(me, "MELEEIDLE", "REARMELIDLE", 0, 1);
}
}
// SetAttrib(me, "DisplayTotalMen", GetAttrib(me, "TotalMen"));
AddVizFunctionCall("UpdateDisplayTotalMen", me, GetAttrib(me, "TotalMen")); // v1.2.1 change
}
// Used instead of GetUnitManDead() in CasualtiesDie(), because CasualtiesDie() can be called more than once before DestroyUnit() is executed.
// "DeathMask" attrib is used to keep track of men marked as dead before they have been marked as dead by AddVizFunctionCall("DestroyUnit", me, killMask);
FUNCTION GetDeathMaskManDead(me, man)
{
int ret;
ret = (GetAttrib(me, "DeathMask") >> man) & 1;
return ret;
}
960/960 men alive => 16/16 man-models alive.
900+/960 men alive => 15/16 man-models alive.
840+/960 men alive => 14/16 man-models alive.
780+/960 men alive => 13/16 man-models alive.
720+/960 men alive => 12/16 man-models alive...
...240+/960 men alive => 4/16 man-models alive.
180+/960 men alive => 3/16 man-models alive.
120+/960 men alive => 2/16 man-models alive.
60+/960 men alive => 1/16 man-models alive.
And then destroyed if less than 60 men models alive.
The same applies to the unit with 480 TotalMen and 8 ManCount: 1 man-model per each 60 men alive.
For melee combat I changed the original line 548
Code: Select all
if ((GetDeathMaskManDead(me, i) == 0) && (gFormationManFrontRank[i] == 1))Code: Select all
if (GetDeathMaskManDead(me, i) == 0)But it does not work with shooting.
While shooting the actual number of man-models does not correspond to the current_strength of the unit.
After several shooting rounds on a unit I might get this unit with 120/960 men alive and 10/16 man-models alive. Or some other random correlation.
My question:
What should I change in the AnimationTools.bsf in order to get dead bodies from shooting in exact proportion to the unit's current_strength?
Thanks!

