I made a script composition that allows the AI to turn the team as a whole towards the approaching enemy (less than 7 tiles from the team units -
(GetDistanceBetween(id, id1) < 7)) and , and then the longbowmen place their stakes.
The main script body in
(your Scenario Name).BSF for AI team 1 -
if (GetUnitTeam(id) == 1):
Code: Select all
FUNCTION StartTurnPost(side)
{
int i;
int id;
int stakesPossible;
int total;
int id1;
int k;
if (side == 1)
{
for (i = 0; i < GetUnitCount(1); i++)
{
id = GetUnitID(1,i);
if (id != -1)
{
if (IsUnitValid(id) == 1)
{
if (GetUnitTeam(id) == 1)
{
total = MakeClosestUnitsToUnitList(id, 1);
id1 = -1;
for (k = 0; k < total; k++)
{
id1 = GetClosestUnit(k);
if (id1 != -1)
{
if (GetUnitSide(id1) != side)
{
if ((GetDistanceBetween(id, id1) < 7) && (GetUniversalVar("TurnCounter") == 0))
{
TurnAllTeam(1, 1, GetUnitX(id1), GetUnitY(id1));
SetUniversalVar("TurnCounter", 1);
}
stakesPossible = CallUnitFunctionDirect(id, "CHECK_ALL_PLACE_STAKES", id, GetUnitX(id), GetUnitY(id));
if ((stakesPossible >= 0) && (GetUniversalVar("TurnCounter") == 1))
{
CallUnitFunctionDirect(id, "ALL_PLACE_STAKES", id, GetUnitX(id), GetUnitY(id));
}
}
}
}
}
}
}
}
}
FUNCTION PreBattleSetup() should be added with this line:
SetUniversalVar("TurnCounter", 0);
At the end of
(your Scenario Name).BSF copy this function:
Code: Select all
FUNCTION TurnAllTeam(side, team, x, y)
{
int i;
int id;
for (i = 0; i < GetUnitCount(side); i++)
{
id = GetUnitID(side,i);
if (id != -1)
{
if (IsUnitValid(id) == 1)
{
if (GetUnitTeam(id) == team)
{
CallUnitFunctionDirect(id, "Turn_Individual_Unit", id, x, y);
}
}
}
}
}
This script can be made simpler, but when it is constantly executed, the AI team almost do not react to enemy units after turning. Therefore, I made a script where it is executed once during the scenario. But nuances are possible, it must be tested more.