Page 1 of 1

After MoveTeamCoord() to a location,how can order the team turn to the opposite direction by default(updated)

Posted: Sun Jul 24, 2022 1:48 am
by locustmustdie
2 Questions
Question1:
Set a location,the AI team marching toward it,then I want it hold there until particular event triggered.
I’ve used the stage==0/stage==1 method. But due to long distance the AI vanguard just kept showing me the butt.
A photo for illustration.
2645F936-7BFF-42E7-8A90-71E410ECCC1E.jpeg
2645F936-7BFF-42E7-8A90-71E410ECCC1E.jpeg (526.79 KiB) Viewed 1038 times
The problem is that the condition of judging whether a team is on location. Furthermore,after that had resolved,can I order a team as a whole to turn to a direction without “for(i=0,getunitcount(1,i),i++)?”
Question2
To order a team of longbowmen installing stakes if possible,failed to find anything like this in tools.bsf and Aitools.bsf. Just some “if removed”judging function,which I think won’t be useful for me.
Need some advice :D

Re: After MoveTeamCoord() to a location,how can order the team turn to the opposite direction by default

Posted: Sun Jul 24, 2022 1:43 pm
by Paul59
locustmustdie wrote: Sun Jul 24, 2022 1:48 am 2 Questions
Question1:
Set a location,the AI team marching toward it,then I want it hold there until particular event triggered.
I’ve used the stage==0/stage==1 method. But due to long distance the AI vanguard just kept showing me the butt.
A photo for illustration.
2645F936-7BFF-42E7-8A90-71E410ECCC1E.jpeg
The problem is that the condition of judging whether a team is on location. Furthermore,after that had resolved,can I order a team as a whole to turn to a direction without “for(i=0,getunitcount(1,i),i++)?”
Question2
To order a team of longbowmen installing stakes if possible,failed to find anything like this in tools.bsf and Aitools.bsf. Just some “if removed”judging function,which I think won’t be useful for me.
Need some advice :D
Maybe using SetUnitFacing(id, 0); might work? The number represents the facing direction that you want.

AI Longbowmen do not use stakes, so the only way to do it is if you knew exactly what turn you wanted the stakes placed, and exactly what tiles to put them in. You could then use something like this;

PlaceObject(24, 40, "NorthernEurope", "Stakes");
SetObjectRotation(id, 157);

Combined with a turn instruction (ie: if (GetTurn() == 8)

I'm not sure how the numbers relate to facing direction on the map, you will have to experiment with that.

Re: After MoveTeamCoord() to a location,how can order the team turn to the opposite direction by default

Posted: Sun Jul 24, 2022 3:02 pm
by Cronos09
locustmustdie wrote: Sun Jul 24, 2022 1:48 am Question2
To order a team of longbowmen installing stakes if possible,failed to find anything like this in tools.bsf and Aitools.bsf. Just some “if removed”judging function,which I think won’t be useful for me.
Need some advice :D
Installation of stakes can be tied to Longbowmen (with stakes) with the following script in (Your scenario name).BSF:

Code: Select all

FUNCTION StartTurnPost(side)
{
    int i;
    int id;
    int team;
	int stakesPossible;
	int tilex;
	int tiley;
  
	if (side == 1)
		{
			if (GetTurn() == 1)
				{
			for (i = 0; i < GetUnitCount(1); i++)
				{
					id = GetUnitID(1,i);
					if (id != -1)
						{
							if (IsUnitValid(id) == 1)
								{
									if (GetAttrib(id, "Stakes") == 1)
										{
										tilex = GetUnitX(id);
										tiley = GetUnitY(id);
										stakesPossible = CallUnitFunctionDirect(id, "CHECK_ALL_PLACE_STAKES", id, tilex, tiley);

										if (stakesPossible >= 0)
											{
												CallUnitFunctionDirect(id, "ALL_PLACE_STAKES", id, tilex, tiley);
											}									
										}

								}
						}
				}					
				}
	}
But all the same I use the turn condition for it: if (GetTurn() == 1)
UPDATE. You can use the condition if (DistanceToNearestEnemy(id, 0, 0, 1) < 6) with your values instead of if (GetTurn() == 1).
FUNCTION DistanceToNearestEnemy(me, excludeFoot, excludeMounted, excludeLights) see in MoreScenarioTools.BSF

Re: After MoveTeamCoord() to a location,how can order the team turn to the opposite direction by default

Posted: Mon Jul 25, 2022 6:02 pm
by Cronos09
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.

Re: After MoveTeamCoord() to a location,how can order the team turn to the opposite direction by default

Posted: Tue Jul 26, 2022 11:18 pm
by locustmustdie
Thanks,Paul! Thanks,Cronos!
I tested the automatic stakes installation last night,Seems not working very well. Perhaps there’re some conflicts with other stuff in my script(team aggr value?) I shall test on a clean map later.
Thanks indeed.

Re: After MoveTeamCoord() to a location,how can order the team turn to the opposite direction by default

Posted: Thu Jul 28, 2022 4:22 pm
by locustmustdie
Well,I tested,instead of the troublesome turn order, Ai effect is acceptable by changing aggr value && using the PlayerUnitIn() function for distance threshold.

Code: Select all

FUNCTION StartTurnPost(side)
{
 int team;
 int turn; 
 int i;
 int id;
 int stage;
 int stakespossible;
 int tilex;
 int tiley;
 int facing;
 int morale_state;
 turn = GetTurn();
if (side == 1)
{
//talbot division
team=1;
stage = GetTeamActivationStage(1, team);
if (stage == 0) 
{                                              
MoveTeamCoord(1, team, 31, 43, 144 );
if ((PlayerUnitIn(21, 31, 41, 63, 0, 0, 1) == 1))
{
SetTeamActivationStage(1, team, 1);
stage = 1;
}
}
if (stage == 1) 
{
ClearTeamAllDestinations(1, team);
//SetTeamAggression(1, team, 16);
if (turn > 8)
{
for (i=0;i<GetUnitCount(1);i++)
{
id=GetUnitID(1,i);
if(id != -1)
{
if (IsUnitValid(id) == 1)
{
if (GetAttrib(id,"stakes") ==1)
{
tilex=GetUnitX(id);
tiley=GetUnitY(id);
stakespossible = CallUnitFunctionDirect(id,"CHECK_ALL_PLACE_STAKES",id,tilex,tiley);
if(stakespossible >= 0)
{
if (PlayerUnitIn((tilex-7), (tiley-7), (tilex+7), (tiley+7), 0, 0, 1) == 1)
{
if (PlayerUnitIn((tilex-2), (tiley-2), (tilex+2), (tiley+2), 0, 0, 1) == 0)
{
facing=GetUnitFacing(id);
if ((facing !=0) && (facing !=1) && (facing !=7))
{
morale_state=GetAttrib(id,"MoraleState");
if (morale_state < 1)
{
CallUnitFunctionDirect(id,"ALL_PLACE_STAKES",id,GetUnitX(id),GetUnitY(id));
}
}
}
}
}
}
}
}
}
}
}

}
A6CA63E4-4FD9-4CC7-B847-28691F94D231.jpeg
A6CA63E4-4FD9-4CC7-B847-28691F94D231.jpeg (880.82 KiB) Viewed 949 times
errors fixed.
I shall test more for turn order, it seems occasionally conflicts with aggr value settings which I thought have the higher priority.