AnimationTools.bsf

Post Reply
Spiret3z
Lance Corporal - SdKfz 222
Lance Corporal - SdKfz 222
Posts: 26
Joined: Thu Dec 14, 2017 7:11 pm

AnimationTools.bsf

Post by Spiret3z »

Hallo! I have a problem with the file AnimationTools.bsf with the FUNCTION CasualtiesDie(me) (lines 491-594):

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;
}
If, for example, I have a unit (960 TotalMen, 16 ManCount) and the unit takes losses, then for each 60 men alive there should be 1 man-model alive.
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))
into

Code: Select all

if (GetDeathMaskManDead(me, i) == 0)
and it works fine. I can enjoy all the man-models lying dead in exact proportion to the unit's current_strength and only the last one man-model is despersed (taken away without dead body on the ground).

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!
rbodleyscott
Field of Glory 2
Field of Glory 2
Posts: 28320
Joined: Sun Dec 04, 2005 6:25 pm

Re: AnimationTools.bsf

Post by rbodleyscott »

I have moved this to the Modding subforum.

I assume you are disabling Autobreaks.
If, for example, I have a unit (960 TotalMen, 16 ManCount) and the unit takes losses, then for each 60 men alive there should be 1 man-model alive.
That isn't how it is intended to work. It is intended that there should be 1 man-model dead for each whole 60 men lost. Neither way of doing it is more realistic. Having 15/16 man-models alive when 1 man out of 960 is dead, is no more logical or realistic than having 16/16 alive when 59 out of 960 are dead.

As to the question of why your code does not work for shooting, it is presumably due to something you have changed. I would need to see the whole of your code before I could figure it out. Send me a PM if you want me to do so. You will need to email me your whole mod once you have my email address, as I cannot analyse what the problem might be by only seeing part of your code.
Richard Bodley Scott

Image
Spiret3z
Lance Corporal - SdKfz 222
Lance Corporal - SdKfz 222
Posts: 26
Joined: Thu Dec 14, 2017 7:11 pm

Re: AnimationTools.bsf

Post by Spiret3z »

rbodleyscott wrote: Tue Nov 03, 2020 4:59 pm
If, for example, I have a unit (960 TotalMen, 16 ManCount) and the unit takes losses, then for each 60 men alive there should be 1 man-model alive.
That isn't how it is intended to work. It is intended that there should be 1 man-model dead for each whole 60 men lost. Neither way of doing it is more realistic. Having 15/16 man-models alive when 1 man out of 960 is dead, is no more logical or realistic than having 16/16 alive when 59 out of 960 are dead.
In melee only:
If you want to have 1 man-model dead for each 60 men lost, than you have to keep the original line 527:

Code: Select all

	newFigures = Min(newFigures + 1, manCount);
960/960 men alive (0 /960 men lost) => 16/16 man-models alive (0/16 man-models dead).
900+/960 men alive (60-/960 men lost) => 16/16 man-models alive (0/16 man-models dead).
840+/960 men alive (120-/960 men lost) => 15/16 man-models alive (1/16 man-models dead).
780+/960 men alive (180-/960 men lost) => 14/16 man-models alive (2/16 man-models dead).
720+/960 men alive (240-/960 men lost) => 13/16 man-models alive (3/16 man-models dead)...
...240+/960 men alive (720-/960 men lost) => 5/16 man-models alive (11/16 man-models dead).
180+/960 men alive (780-/960 men lost) => 4/16 man-models alive (12/16 man-models dead).
120+/960 men alive (840-/960 men lost) => 3/16 man-models alive (13/16 man-models dead).
60+/960 men alive (900-/960 men lost) => 2/16 man-models alive (14/16 man-models dead).
And then destroyed if less than 60 men alive.

If you want to have 1 man-model alive for each 60 men alive, than you have to change the line 527 into:

Code: Select all

	newFigures = Min(newFigures, manCount);
960/960 men alive (0 /960 men lost) => 16/16 man-models alive (0/16 man-models dead).
900+/960 men alive (60-/960 men lost) => 15/16 man-models alive (1/16 man-models dead).
840+/960 men alive (120-/960 men lost) => 14/16 man-models alive (2/16 man-models dead).
780+/960 men alive (180-/960 men lost) => 13/16 man-models alive (3/16 man-models dead).
720+/960 men alive (240-/960 men lost) => 12/16 man-models alive (4/16 man-models dead)...
...240+/960 men alive (720-/960 men lost) => 4/16 man-models alive (12/16 man-models dead).
180+/960 men alive (780-/960 men lost) => 3/16 man-models alive (13/16 man-models dead).
120+/960 men alive (840-/960 men lost) => 2/16 man-models alive (14/16 man-models dead).
60+/960 men alive (900-/960 men lost) => 1/16 man-models alive (15/16 man-models dead).
And then destroyed if less than 60 men alive.

The problem is: It works fine and in that exact proportion for melee, but is very random for shooting.
Last edited by Spiret3z on Tue Nov 03, 2020 6:29 pm, edited 1 time in total.
rbodleyscott
Field of Glory 2
Field of Glory 2
Posts: 28320
Joined: Sun Dec 04, 2005 6:25 pm

Re: AnimationTools.bsf

Post by rbodleyscott »

As I say, I would need to see your entire code to work it out.
Richard Bodley Scott

Image
Post Reply

Return to “Field of Glory II: Modding”