Page 1 of 1

modding breakoff

Posted: Sun Dec 11, 2022 9:51 pm
by companion
I've added following ("//modded" part)to the CheckBreakOff function in CloseCombatLogic.bsf
It didn't crash the game but also did not seem to change anything during playtest.

Code: Select all

			if (flanked == 0) // Can't break off if fighting to front and flank/rear
				{
					if ((IsFoot(me) == 1) && (all_foot == 1) && (LostCloseCombatBadly(me) == 1) && (foot_shock == 0))
						{
							try_break_off = 1;
						}
					//modded
					if ((IsFoot(me) == 1) && (GetAttrib (me, "Pike") > 0) && (GetAttrib(me,"MoraleState") < 1) && (IsInCloseCombat (me) == 1))
						{
							if ((IsMounted (id) == 1) && (GetAttrib (id, "Impact_Mounted") > 0))
								{
									if (IsCombatInOpen(me,id) == 1)
										{
											try_break_off = 1;
										}
								}
							if ((IsMounted (id) == 1) && (GetAttrib (id, "Impact_Pistol") > 0))
								{
									if (IsCombatInOpen(me,id) == 1)
										{
											try_break_off = 1;
										}
								}
						}
Which part makes it nonfunctional?

My intention was to make a Steady, open terrain P&S unit that is currently in melee with something to automatically fallback when then charged by a battle cavalry

Re: modding breakoff

Posted: Tue Dec 13, 2022 11:41 am
by Cronos09
companion wrote: Sun Dec 11, 2022 9:51 pm I've added following ("//modded" part)to the CheckBreakOff function in CloseCombatLogic.bsf
It didn't crash the game but also did not seem to change anything during playtest.

Code: Select all

			if (flanked == 0) // Can't break off if fighting to front and flank/rear
				{
					if ((IsFoot(me) == 1) && (all_foot == 1) && (LostCloseCombatBadly(me) == 1) && (foot_shock == 0))
						{
							try_break_off = 1;
						}
					//modded
					if ((IsFoot(me) == 1) && (GetAttrib (me, "Pike") > 0) && (GetAttrib(me,"MoraleState") < 1) && (IsInCloseCombat (me) == 1))
						{
							if ((IsMounted (id) == 1) && (GetAttrib (id, "Impact_Mounted") > 0))
								{
									if (IsCombatInOpen(me,id) == 1)
										{
											try_break_off = 1;
										}
								}
							if ((IsMounted (id) == 1) && (GetAttrib (id, "Impact_Pistol") > 0))
								{
									if (IsCombatInOpen(me,id) == 1)
										{
											try_break_off = 1;
										}
								}
						}
Which part makes it nonfunctional?

My intention was to make a Steady, open terrain P&S unit that is currently in melee with something to automatically fallback when then charged by a battle cavalry
I think the logic of this function requires more complex scripting for your purpose.
The 'id' operator does not work properly beyond the previous script cycle. You should use 'all_foot' and other operators how it is used in the next condition if (IsMounted(me) == 1) {}
something like this

Code: Select all

			if (flanked == 0) // Can't break off if fighting to front and flank/rear
				{
					//modded				
					if (IsFoot(me) == 1) 
						{
							if (all_foot == 1) 
								{
									if ((LostCloseCombatBadly(me) == 1) && (foot_shock == 0))
										{
											try_break_off = 1;
										}
								}
							else
								{	
									if ((GetAttrib (me, "Pike") > 0) && (GetAttrib(me,"MoraleState") == 0) && (IsInCloseCombat (me) == 1))
										{
											if (((mounted_shock == 1) && (combat_in_open == 1)) || ((impact_pistol == 1) && (combat_in_open == 1)))
												{
													try_break_off = 1;
												}
										}
								}
						}//modded
					....	
				}
And the previous cycle should be added with

Code: Select all

						if (IsMounted(id) == 1)
							{
								all_foot = 0;
								if (IsShockTroops(id) == 1)
									{
										mounted_shock = 1;
									}
								if (GetAttrib (id, "Impact_Pistol") > 0)
									{
										impact_pistol = 1;
									}									
							}
						...
						if (IsCombatInOpen(me, id) == 1)
							{
								combat_in_open = 1;
							}
Of course, you must write int impact_pistol; int combat_in_open; in the function header and give them zero values.

Re: modding breakoff

Posted: Wed Dec 14, 2022 12:38 pm
by Cronos09
Today I have tested my modded script. In order to achieve the desired effect every time, you also need to add the condition if (IsMounted(me) == 1) {} like this

Code: Select all

					if ((IsMounted(me) == 1))
						{
							if (all_foot == 1)
								{
									if((GetAttrib (me, "Impact_Mounted") == 0) && (GetAttrib (me, "Impact_Pistol") == 0))
										{
											rating = CalculateModifiedCloseCombatRating(me, nastiest_enemy, -1, 1);
											rating *= AdditionalEnemiesModifier(me, 0);
											rating /= 100;

											Log("Shall unit break off? unit, combat rating, enemy rating", me, rating, highest_enemy_rating);

											if (rating < highest_enemy_rating)
												{
													try_break_off = 1;
												}
										}	
								}
							else
								{
								...
								}
						}

Re: modding breakoff

Posted: Tue Dec 20, 2022 5:02 pm
by companion
Thank you!!

It works as intended but there is one unexpected problem:
Say, a horse unit A charges a P&S unit B, B wants to fall back according to the script, but cannot because fallback tile is occupied by another unit.
In this case, A gets stuck in melee, does not fallback as usual, and get destroyed by the pike

Base on your reply about "ismounted" I assume mutual fallback is not permitted by the game?

I may need to rethink this idea...

Edit: on another playtest, foot units are falling back from cavalries even when not currently engaged. Back to drawing board...

Re: modding breakoff

Posted: Wed Dec 21, 2022 3:11 pm
by Cronos09
companion wrote: Tue Dec 20, 2022 5:02 pm Thank you!!

It works as intended but there is one unexpected problem:
Say, a horse unit A charges a P&S unit B, B wants to fall back according to the script, but cannot because fallback tile is occupied by another unit.
In this case, A gets stuck in melee, does not fallback as usual, and get destroyed by the pike

Base on your reply about "ismounted" I assume mutual fallback is not permitted by the game?

I may need to rethink this idea...

Edit: on another playtest, foot units are falling back from cavalries even when not currently engaged. Back to drawing board...
Not at all. I agree there are many nuances in the scripts. It seems that mutual fallback is not permitted.

Re: modding breakoff

Posted: Mon Dec 26, 2022 10:52 am
by companion
So the one of the problems was that a P&S unit will fallback from battle cavalry even when not currently in melee with another unit.

Code: Select all

if ((GetAttrib (me, "Pike") > 0) && (GetAttrib(me,"MoraleState") == 0) && (NumberOfCloseCombatOpponents (me) > 1))
Using "numberofclosecombatopponents" instead of "isinclosecombat" seems to fix that problem.

Re: modding breakoff

Posted: Mon Dec 26, 2022 1:10 pm
by kondi754
System.out.print ("take a break from Java, it's Christmas" ); :)

Re: modding breakoff

Posted: Mon Dec 26, 2022 6:54 pm
by Cronos09
companion wrote: Mon Dec 26, 2022 10:52 am So the one of the problems was that a P&S unit will fallback from battle cavalry even when not currently in melee with another unit.

Code: Select all

if ((GetAttrib (me, "Pike") > 0) && (GetAttrib(me,"MoraleState") == 0) && (NumberOfCloseCombatOpponents (me) > 1))
Using "numberofclosecombatopponents" instead of "isinclosecombat" seems to fix that problem.
Great. Who seeks will find. Now I will know that we have this function.

Re: modding breakoff

Posted: Fri Jan 06, 2023 10:59 am
by Cronos09
companion wrote: Tue Dec 20, 2022 5:02 pm It works as intended but there is one unexpected problem:
Say, a horse unit A charges a P&S unit B, B wants to fall back according to the script, but cannot because fallback tile is occupied by another unit.
In this case, A gets stuck in melee, does not fallback as usual, and get destroyed by the pike

Base on your reply about "ismounted" I assume mutual fallback is not permitted by the game?
I thought over and tested this moment. To improve the situation we should add if (IsFoot(id) == 1) like this

Code: Select all

						if (IsFoot(id) == 1)
							{
								if (IsShockTroops(id) == 1)
									{
										foot_shock = 1;
									}
									
								if (CheckFallBack(id) == 1)
									{
										fallback_possible = 1;
									}
							}	
the condition in if (IsMounted(me) == 1) with

Code: Select all

					if (IsMounted(me) == 1)
						{
							if (all_foot == 1)
								{
									if(((GetAttrib (me, "Impact_Mounted") == 0) && (GetAttrib (me, "Impact_Pistol") == 0)) || (fallback_possible == 0))
									{
write int fallback_possible; in the function header and give it zero value.
You need to copy the next function to CloseCombatLogic.BSF too:

Code: Select all

FUNCTION CheckFallBack(me)
{
int facing;
int direction;
int x;
int y;
int x2;
int y2;
int i;
int ret;

	ret = 0;	
	facing = GetUnitFacing(me);
	direction = facing + 180;
	if (direction > 359)
		{
			direction -= 360;
		}

	x = GetUnitX(me);
	y = GetUnitY(me);
	x2 = AdjacentX(x, direction);
	y2 = AdjacentY(y, direction);

	if (IsTileBlocked(me, x2, y2) == 0)
		{
			ret = 1;
		}							
	return ret;
}

Re: modding breakoff

Posted: Sun Jan 08, 2023 6:02 pm
by companion
Thanks for further refinement! Much appreciated.