Some simple problems

Moderators: rbodleyscott, Slitherine Core, Gothic Labs

edward77
Sergeant - 7.5 cm FK 16 nA
Sergeant - 7.5 cm FK 16 nA
Posts: 231
Joined: Wed Nov 10, 2010 9:11 pm

Some simple problems

Post by edward77 »

Richard, Having difficulty with some simple problems!
1) Using the five parts of the Scenario description in the Editor I can only get the first part to appear when running the scenario. If alternatively I put all the description in the first part it all appears but too high on the screen such that the first three or four lines cannot be seen. I have tried extra spaces with several ~s at the start but to no avail.
2) What is the purpose of the fourth variable in the AI dialog box?
3) I know how to give AI teams a no command status eg Saxons at Brietenfeld but how do you restore it at a later stage depending on proximity of the players units?
rbodleyscott
Field of Glory 2
Field of Glory 2
Posts: 28052
Joined: Sun Dec 04, 2005 6:25 pm

Re: Some simple problems

Post by rbodleyscott »

edward77 wrote:Richard, Having difficulty with some simple problems!
1) Using the five parts of the Scenario description in the Editor I can only get the first part to appear when running the scenario. If alternatively I put all the description in the first part it all appears but too high on the screen such that the first three or four lines cannot be seen. I have tried extra spaces with several ~s at the start but to no avail.
It depends on what is in your SCENUI file and whether it has the correct filename to match the scenario filename.

If your scenario file is WARSAW.BAM, the SCENUI file should be SCENUI_WARSAW.TXT

If there is any discrepancy in the filename it won't work and you will see what you are seeing.
2) What is the purpose of the fourth variable in the AI dialog box?
That is something of a mystery.
3) I know how to give AI teams a no command status eg Saxons at Brietenfeld but how do you restore it at a later stage depending on proximity of the players units?
SetCannotControl(id, 0); restores control to the unit.

You can detect the proximity of player units using:

AI_GetClosestDistanceToClosestEnemyUnit(side, team, ignoreLights)

Enemy light troops will be ignored if ignoreLights is 1.

If you get stuck, tell me exactly what you want to achieve and I can write you a code snippet.

e.g.

Code: Select all

		// Render team 1 controllable if any enemy are within 5 tiles of any of them

side = 1;	
team = 1;

 if (AI_GetClosestDistanceToClosestEnemyUnit(side, team, 0) <= 5)
    {
			for (i = 0; i < GetUnitCount(side); i++)
				{
					id = GetUnitID(side,i);
					if (id != -1)
						{
							if (GetUnitTeam(id) == team)
								{
									SetCannotControl(id, 0);
								}
						}
				}
     }
Richard Bodley Scott

Image
edward77
Sergeant - 7.5 cm FK 16 nA
Sergeant - 7.5 cm FK 16 nA
Posts: 231
Joined: Wed Nov 10, 2010 9:11 pm

Re: Some simple problems

Post by edward77 »

Thanks, solved the description problem. Ha ha, very funny about the mystery ! Can the development team shine any light on it? Here is what I`m trying to do - Battle of Malplaquet 1709 - Keep each of the French AI cavalry ( Teams 2,3 and 4) stationary until the player (Grand Alliance) gets to within say 5 squares of each cavalry team. In effect each team has a seperate test. I have tried various combinations with the AI dialog but to no avail.
edward77
Sergeant - 7.5 cm FK 16 nA
Sergeant - 7.5 cm FK 16 nA
Posts: 231
Joined: Wed Nov 10, 2010 9:11 pm

Re: Some simple problems

Post by edward77 »

Here is the code I tried which failed because the variable side was not defined ??? I have never seen that required in any of the example scripts.

FUNCTION StartTurnPost(side)
{
int i;
int id;
int team;
int j;
int turn;

turn = GetTurn();

if (side == 1)
{
If (turn == 0)
{
for (j = 2; j < 5; j++)
{
team = j;
// Render Side 1 Team 2 to 4 uncontrollable
for (i = 0; i < GetUnitCount(side); i++)
{
id = GetUnitID(side,i);
if (id != -1)
{
if (GetUnitTeam(id) == team)
{
SetCannotControl(id, 1);
}
}
}
}
}

for (j = 2; j < 5; j++)
{
team = j;
// Restore control to Side 1, Teams 2 to 4

if (AI_GetClosestDistanceToClosestEnemyUnit(side, team, 0) <= 5)
{
for (i = 0; i < GetUnitCount(side); i++)
{
id = GetUnitID(side,i);
if (id != -1)
{
if (GetUnitTeam(id) == team)
{
SetCannotControl(id, 0);
}
}
}
}

}
}

}
edward77
Sergeant - 7.5 cm FK 16 nA
Sergeant - 7.5 cm FK 16 nA
Posts: 231
Joined: Wed Nov 10, 2010 9:11 pm

Re: Some simple problems

Post by edward77 »

Sorry did not do it properly

Code: Select all

FUNCTION StartTurnPost(side)
 {
       int i;
       int id;
       int team;
       int j;
       int turn;

       turn = GetTurn();

       if (side == 1)
         {
           If (turn == 0)
           {
             for (j = 2; j < 5; j++)
                  {
                      team = j;   
                      // Render Side 1 Team 2 to 4 uncontrollable
                      for (i = 0; i < GetUnitCount(side); i++)
                          {
                            id = GetUnitID(side,i);
                            if (id != -1)
                               {
                                 if (GetUnitTeam(id) == team)
                                   {
                                      SetCannotControl(id, 1);
                                   }
                               }
                          }
                  }
           }

           for (j = 2; j < 5; j++)
               { 
                  team = j;  
                  // Restore control to Side 1, Teams 2 to 4 

                   if (AI_GetClosestDistanceToClosestEnemyUnit(side, team, 0) <= 5)
                  {
                    for (i = 0; i < GetUnitCount(side); i++)
                      {
                         id = GetUnitID(side,i);
                         if (id != -1)
                            {
                                if (GetUnitTeam(id) == team)
                                 {
                                   SetCannotControl(id, 0);
                                 }
                            }
                      }
                  }

               }
         }

  }
rbodleyscott
Field of Glory 2
Field of Glory 2
Posts: 28052
Joined: Sun Dec 04, 2005 6:25 pm

Re: Some simple problems

Post by rbodleyscott »

I suspect that setting units as uncontrollable will have no effect whatsoever on AI units.

What you want to do is give their teams Aggression 64 orders until the enemy gets close, and then give them aggression 0 orders. (Or various options if you want them to ignore light troops).

Essentially you were looking in the wrong place in the Breitenfeld script.

Instead, look at lines 98 - 118 for an example.

Or

Code: Select all

for (j = 2; j < 5; j++)
{
	team = j;
	stage = GetTeamActivationStage(1, team);
	
	if (stage == 0) // Hold position
		{
			ClearTeamAllDestinations(1, team);
			MoveTeamCoord(1, team, -1, -1, 64);

			if (AI_GetClosestDistanceToClosestEnemyUnit(side, team, 0) <= 5)
				{
					SetTeamActivationStage(1, team, 1);
					stage = 1;
				}
		}

	if (stage == 1) // Advance
		{
			destinationX = -1;  
			destinationY = -1;
			MoveTeamCoord(1, team, destinationX, destinationY, 0); // If you want them to seek and destroy - set the destination parameters to specific destination if you want them to head somewhere specific
		}
}
Richard Bodley Scott

Image
edward77
Sergeant - 7.5 cm FK 16 nA
Sergeant - 7.5 cm FK 16 nA
Posts: 231
Joined: Wed Nov 10, 2010 9:11 pm

Re: Some simple problems

Post by edward77 »

Thank you Richard. Works fine now!
edward77
Sergeant - 7.5 cm FK 16 nA
Sergeant - 7.5 cm FK 16 nA
Posts: 231
Joined: Wed Nov 10, 2010 9:11 pm

Re: Some simple problems

Post by edward77 »

What are the SCENUI commands and codes for text foreground and background colours
rbodleyscott
Field of Glory 2
Field of Glory 2
Posts: 28052
Joined: Sun Dec 04, 2005 6:25 pm

Re: Some simple problems

Post by rbodleyscott »

edward77 wrote:What are the SCENUI commands and codes for text foreground and background colours
https://sites.google.com/site/battleaca ... umentation

Not sure what you mean by text background colours. Normally the background would be created by an image file.
Richard Bodley Scott

Image
edward77
Sergeant - 7.5 cm FK 16 nA
Sergeant - 7.5 cm FK 16 nA
Posts: 231
Joined: Wed Nov 10, 2010 9:11 pm

Re: Some simple problems

Post by edward77 »

Well, the scenario description normally has white text on a black backround. I have a transparent background with a bright picture behind so the words are hard to see. In the SCENUI there is a command <colour ffffffff>. I thought there might be an equivalent for background colour.
rbodleyscott
Field of Glory 2
Field of Glory 2
Posts: 28052
Joined: Sun Dec 04, 2005 6:25 pm

Re: Some simple problems

Post by rbodleyscott »

edward77 wrote:Well, the scenario description normally has white text on a black backround. I have a transparent background with a bright picture behind so the words are hard to see. In the SCENUI there is a command <colour ffffffff>. I thought there might be an equivalent for background colour.
No, you just need to copy the file BACKDROP.DDS from one of the vanilla campaigns into your custom campaign.
Richard Bodley Scott

Image
rbodleyscott
Field of Glory 2
Field of Glory 2
Posts: 28052
Joined: Sun Dec 04, 2005 6:25 pm

Re: Some simple problems

Post by rbodleyscott »

Richard Bodley Scott

Image
edward77
Sergeant - 7.5 cm FK 16 nA
Sergeant - 7.5 cm FK 16 nA
Posts: 231
Joined: Wed Nov 10, 2010 9:11 pm

Re: Some simple problems

Post by edward77 »

Richard, Is there a way of randomising a variable in a script ?
rbodleyscott
Field of Glory 2
Field of Glory 2
Posts: 28052
Joined: Sun Dec 04, 2005 6:25 pm

Re: Some simple problems

Post by rbodleyscott »

edward77 wrote:Richard, Is there a way of randomising a variable in a script ?
Of course.

You use the Rand() function.

All of the functions are listed in

/My Documents/My Games/PSCAMP/AUTODOCS/Battlescript.txt

although not in alphabetical order.

You need to use Rand() rather than FXRand() otherwise multiplayer replays will not work correctly. FXRand() has been used in the Campaign scripts, however, because Rand() (for some reason unknown to me) does not work in UI scripts, which is effectively what the campaign scripts are.
Richard Bodley Scott

Image
edward77
Sergeant - 7.5 cm FK 16 nA
Sergeant - 7.5 cm FK 16 nA
Posts: 231
Joined: Wed Nov 10, 2010 9:11 pm

Re: Some simple problems

Post by edward77 »

Ok Thanks for that. Looking for a clear explanation for commands GetTeamActivationStage & SetTeamActivationStage. Can`t find them in Battlescript or Stub Engine commands.
rbodleyscott
Field of Glory 2
Field of Glory 2
Posts: 28052
Joined: Sun Dec 04, 2005 6:25 pm

Re: Some simple problems

Post by rbodleyscott »

edward77 wrote:Ok Thanks for that. Looking for a clear explanation for commands GetTeamActivationStage & SetTeamActivationStage. Can`t find them in Battlescript or Stub Engine commands.
That is because they aren't engine functions, they are scripted functions. You can find them in AITools.BSF.

They are just used to allow the AI scripts to use different orders for a team in different phases of the battle. Certain scripted conditions will cause the team to go to the next activation stage. But all this is done in scripts - I suggest you look at one of the scenario scripts that uses these functions.
Richard Bodley Scott

Image
edward77
Sergeant - 7.5 cm FK 16 nA
Sergeant - 7.5 cm FK 16 nA
Posts: 231
Joined: Wed Nov 10, 2010 9:11 pm

Re: Some simple problems

Post by edward77 »

In trying to get to grips with scripts I must have examined virtually all of them in the vanilla and historical scenarios. First observation is that although I have learnt a lot the vanilla ones are often extremely complicated whilst not many of the historical scenarios have a script at all. Hardly surprising I suppose. Second observation is that I could not find a single scenario where the SetTeamOrder command (recommended method by P&S) was used. For those of you, like me, who struggle with scripts this method is much easier to understand.
The code below is an example taken from my latest scenario Battle of Soor 1745. Each AI team is given one or more orders which are executed in sequence. ie Once it has completed the first order it then starts to execute the second one and so on ....

The parameters for the command are :-
SetTeamOrder(side,team,Order#,MakeAIOrderCoord(X,Y,aggression code)); Note 1st order is 0 Script Turn is always odd for AI ie 1,3,5,etc 0,2,4,etc for player

SCRIPT SOOR 1745

Code: Select all


    if (turn == 1) 
      {
          for (i = 0; i < 8; i++)
             {
                   MoveTeamCoord(1, i, -1, -1, 4);       //   Start with no team moving
             }
      }

    if (turn == 3)                                                                      //   Script turn 3  =  Scenario turn 2
      { 
          SetTeamOrder(1,0,0,MakeAIOrderCoord(32,38,10));       //  Graner-Koppe Group
          SetTeamOrder(1,1,0,MakeAIOrderCoord(39,37,10));       //  Burkersdorf Group
          SetTeamOrder(1,2,0,MakeAIOrderCoord(45,35,10));       //  Centre Right Inf
          SetTeamOrder(1,3,0,MakeAIOrderCoord(57,40,10));       //  Rearguard Right      1st Move
          SetTeamOrder(1,3,1,MakeAIOrderCoord(46,29,10));       //                                2nd Move 
      }

    if (turn == 5) 
      {  
          SetTeamOrder(1,5,0,MakeAIOrderCoord(59,29,10));       //  RW Cavalry         1st Move
          SetTeamOrder(1,5,1,MakeAIOrderCoord(54,23,10));       //                            2nd Move
          SetTeamOrder(1,5,3,MakeAIOrderCoord(47,25,16));       //                            3rd Move
          SetTeamOrder(1,6,0,MakeAIOrderCoord(34,39,10));       //  Saxons  
          SetTeamOrder(1,7,0,MakeAIOrderCoord(42,43,10));       //  Rearguard Left
          SetTeamOrder(1,4,0,MakeAIOrderCoord(57,33,10));       //  RW Inf                1st Move
          SetTeamOrder(1,4,1,MakeAIOrderCoord(48,27,10));       //                            2nd Move 
      }
As you can see it is quite simple, only requires a few lines of code but works very well especially for cavalry, is much more accurate than the wooly threat code as well as being easy to develop, adjust or check!
Hope this is helpful
edward77
Sergeant - 7.5 cm FK 16 nA
Sergeant - 7.5 cm FK 16 nA
Posts: 231
Joined: Wed Nov 10, 2010 9:11 pm

Re: Some simple problems

Post by edward77 »

Sorry, 4th line in (if turn == 5) should be SetTeamOrder(1,5,2,MakeAIOrderCoord(47,25,16)); // 3rd Move
edward77
Sergeant - 7.5 cm FK 16 nA
Sergeant - 7.5 cm FK 16 nA
Posts: 231
Joined: Wed Nov 10, 2010 9:11 pm

Re: Some simple problems

Post by edward77 »

Richard, I now have PAINT.NET working well but need to know the logic of the layout of a unit texture .dds file? eg MUSKETEERS_RAW@.DDS in the BALACLAVA IW_FRENCH File. I can see the 6 flag icons in the top LH corner (3 FOR SIDE0, 3 FOR SIDE1 ?) with back/side/front views of troops at the bottom but not clear how to apply the rest of the icons to get required results.
rbodleyscott
Field of Glory 2
Field of Glory 2
Posts: 28052
Joined: Sun Dec 04, 2005 6:25 pm

Re: Some simple problems

Post by rbodleyscott »

edward77 wrote:Richard, I now have PAINT.NET working well but need to know the logic of the layout of a unit texture .dds file? eg MUSKETEERS_RAW@.DDS in the BALACLAVA IW_FRENCH File. I can see the 6 flag icons in the top LH corner (3 FOR SIDE0, 3 FOR SIDE1 ?) with back/side/front views of troops at the bottom but not clear how to apply the rest of the icons to get required results.
I am probably the wrong person to ask. Try Paul59 or Odenathus.
Richard Bodley Scott

Image
Post Reply

Return to “Scenario Design”