What is SetRoute exactly for?

Moderator: rbodleyscott

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

What is SetRoute exactly for?

Post by locustmustdie »

I'm writing my own AutomaticMove,same trouble annoyed me when friendly units block the path,so I looking for solution in Loja_C.bsf.There's a SetRoute segment in it.

Code: Select all

if (GetAttrib(id, "MoraleState") == 2)
	{
			if ((IsUnitSquadType(id, "Cavalry") == 1) && (GetUnitFacing(id) == 0))
				{
// Fall back
					if (CallUnitFunctionDirect(id, "CHECK_ALL_FALLBACK", id, GetUnitX(id), GetUnitY(id) - 1) >= 0)
		{
				CallUnitFunctionDirect(id, "ALL_FALLBACK", id, GetUnitX(id), GetUnitY(id) - 1);   							 
                }
				}
				else
				{
				// Retreat
				x = GetUnitX(id);
				limit = GetUnitY(id) - 3;
				for (y = GetUnitY(id) - 1; y > limit; y--)
				{																					 
                                   if (IsTileBlocked(id, x, y) == 0)																								 
                                         {																								 
                                           AddVizFunctionCall("SetRoute",id, x, y, 0);
					 }
					else
					{																							 
                                         y = limit;																								 
                                        }
			       }
		}
			       }
In this case,it was for retreat. It will work fine for attack as well,isn't it?
And in the end there's a AddVizWaitOnMove(id),what's that for?

Code: Select all

if (GetTurn() > 2)
	{
		SetCannotControl(id, 0);
	}	
												
		}
		 AddVizWaitOnMove(id);
likewise AddVizFunctionCall("CallUnitFunctionDirect", id, "UNIT_ASSAULT", id, enemy, 0);
Addviz means animationFunction?
rbodleyscott
Field of Glory 2
Field of Glory 2
Posts: 28401
Joined: Sun Dec 04, 2005 6:25 pm

Re: What is SetRoute exactly for?

Post by rbodleyscott »

locustmustdie wrote: Sat Dec 17, 2022 12:45 am I'm writing my own AutomaticMove,same trouble annoyed me when friendly units block the path,so I looking for solution in Loja_C.bsf.There's a SetRoute segment in it.

Code: Select all

if (GetAttrib(id, "MoraleState") == 2)
	{
			if ((IsUnitSquadType(id, "Cavalry") == 1) && (GetUnitFacing(id) == 0))
				{
// Fall back
					if (CallUnitFunctionDirect(id, "CHECK_ALL_FALLBACK", id, GetUnitX(id), GetUnitY(id) - 1) >= 0)
		{
				CallUnitFunctionDirect(id, "ALL_FALLBACK", id, GetUnitX(id), GetUnitY(id) - 1);   							 
                }
				}
				else
				{
				// Retreat
				x = GetUnitX(id);
				limit = GetUnitY(id) - 3;
				for (y = GetUnitY(id) - 1; y > limit; y--)
				{																					 
                                   if (IsTileBlocked(id, x, y) == 0)																								 
                                         {																								 
                                           AddVizFunctionCall("SetRoute",id, x, y, 0);
					 }
					else
					{																							 
                                         y = limit;																								 
                                        }
			       }
		}
			       }
In this case,it was for retreat. It will work fine for attack as well,isn't it?
Yes.

From /Documents/My Games/FieldOfGloryMedieval/Autodocs/Battlescript.txt (The bible for engine functions):

//Set a squad to route to the designated tile. react denotes whether the move triggers reaction fire (0 - no reaction, 1 - normal reaction (default), 2 - object reaction only).
SetRoute(id, x, y, [react])

And in the end there's a AddVizWaitOnMove(id),what's that for?

Code: Select all

if (GetTurn() > 2)
	{
		SetCannotControl(id, 0);
	}	
												
		}
		 AddVizWaitOnMove(id);
//wait until the denoted unit has finished moving
AddVizWaitOnMove(id)


It means that anything subsequently added to the Viz Queue will not be executed until that move is completed. (See below re Viz Queue)
likewise AddVizFunctionCall("CallUnitFunctionDirect", id, "UNIT_ASSAULT", id, enemy, 0);
Addviz means animationFunction?
No

//call a function from the vizQ. Can ONLY be used to call functions with up to 11 fixed params, as one is used for the name.
AddVizFunctionCall(function, [value, ...])


The Viz Queue is used to allow functions not to be executed immediately the code is run, but to be processed in turn in the order they were added to the queue. This allows events to be shown to the player in proper sequence.

There can be nested layers, if you use AddVizFunctionCall() from a function that has itself been called by AddVizFunctionCall(), so there are pitfalls. Using it successfully requires thought, and sometimes trial and error, to make sure things are executed in the right sequence.
Richard Bodley Scott

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

Re: What is SetRoute exactly for?

Post by locustmustdie »

Thanks Richard! Once more you opened a window for me.
Paul is right,AutomaticMove is such a nightmare that you add 20k script just get dancers evolved from toddlers to drunkers.
Post Reply

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