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

Moderator: rbodleyscott

Post Reply
locustmustdie
Senior Corporal - Destroyer
Senior Corporal - Destroyer
Posts: 117
Joined: Fri Mar 05, 2021 11:33 am

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

Post 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 1035 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
Last edited by locustmustdie on Sun Jul 31, 2022 1:29 am, edited 2 times in total.
Paul59
General - King Tiger
General - King Tiger
Posts: 3864
Joined: Tue Jul 21, 2015 11:26 pm

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

Post 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.
Field of Glory II Scenario Designer - Age of Belisarius, Rise of Persia, Wolves at the Gate and Swifter than Eagles.

Field of Glory II Medieval Scenario Designer.

FOGII TT Mod Creator

Warhammer 40,000: Sanctus Reach Tournament Scenario Designer.
Cronos09
Staff Sergeant - Kavallerie
Staff Sergeant - Kavallerie
Posts: 337
Joined: Thu Feb 22, 2018 4:28 pm

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

Post 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
Cronos09
Staff Sergeant - Kavallerie
Staff Sergeant - Kavallerie
Posts: 337
Joined: Thu Feb 22, 2018 4:28 pm

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

Post 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.
locustmustdie
Senior Corporal - Destroyer
Senior Corporal - Destroyer
Posts: 117
Joined: Fri Mar 05, 2021 11:33 am

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

Post 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.
locustmustdie
Senior Corporal - Destroyer
Senior Corporal - Destroyer
Posts: 117
Joined: Fri Mar 05, 2021 11:33 am

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

Post 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 946 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.
Last edited by locustmustdie on Sun Jul 31, 2022 12:55 am, edited 1 time in total.
Post Reply

Return to “Field of Glory II: Medieval - Scenario Design”