companion wrote: ↑Sun Feb 12, 2023 4:22 pm
Wow, much thanks. Devising such complex set of scripts was beyond my competencies.
To add some context, forced pursuit cancellation was a part of a scheme to simulate defeated cavalries reforming behind friendly infantry support.
Such behaviors - quick to retreat but also quick to reform - seem to grow more common as armours are discarded and average horsemanship, along with horse quality, degrades.
The script attributes in the game are universal instrument for scripting various situations. They are used as simple triggers (0 or 1)/counters so weapon, armour, AP indicators. As you see they are very useful things.
I decided to complicate the script, so Cavaliers can leave an enemy unit arc of fire, i.e. they make one (or two in some situations) stage of pursuing after shooting at them. The complete script description:
1) in
Init.BSF I added another Attrib
Code: Select all
AddAttrib("Counter");
SetAttrib(me, "Counter", 0);
AddAttrib("TurnsPursuing");
2) in
CombatTools.BSF I added at the end of
FUNCTION TurnAndFire(me, x, y, unit, volley)
Code: Select all
if (IsUnitSquadType(unit, "Cavaliers") == 1)
{
SetAttrib(unit, "ShotAway", 1);
SetAttrib(unit, "TurnsPursuing", 1);
}
3) in
FUNCTION WillUnitPursue(me, enemy, type)
Code: Select all
// Cavaliers tend to keep pursuing
if (IsUnitSquadType(me, "Cavaliers") == 1)
{
if((GetAttrib(me, "ShotAway") == 1) && (GetAttrib(me, "TurnsPursuing") > 1))
{
stopChance = 100;
}
else
{
stopChance = 25;
}
}
4) in
StartTurn.BSF I added in
FUNCTION StartTurnMoraleUpdate(me, lastTurnShootingDamage)
Code: Select all
if (WillUnitPursue(opponent, me, 1) == 1)
{
AddToREPQueue(me, opponent);
SetAttrib(opponent,"AP",GetBaseAttrib(opponent,"AP"));
if(GetAttrib(opponent, "TurnsPursuing") > 0) //modded
{
turns_pursuing = GetAttrib(opponent, "TurnsPursuing");
if (turns_pursuing > 2)
{
SetAttrib(opponent, "ShotAway", 0);
SetAttrib(opponent, "TurnsPursuing", 0);
}
else
{
turns_pursuing += 1;
SetAttrib(opponent, "TurnsPursuing", turns_pursuing);
}
} //modded
}
It seems to work, but it needs to test more time.
Update 15.02.2022. Item 4 is fixed. In the function header should be written
int turns_pursuing;
Now it works fine. The main feature of the script - a Cavalier unit makes one stage of pursuing after an enemy unit has shot at it. Then it stops if there was not shot at it. If there was a shot at this Cavalier unit, it performes another stage of pursuing.