Scenario creation guide part 9 (Reinforcements Part2)

Post Reply
Paul59
Brigadier-General - Elite Grenadier
Brigadier-General - Elite Grenadier
Posts: 2230
Joined: Tue Jul 21, 2015 11:26 pm

Scenario creation guide part 9 (Reinforcements Part2)

Post by Paul59 » Mon Dec 11, 2017 11:06 am

Now we will look at the Scripted Method of reinforcements.

Firstly, you do exactly the same as what we did for the Editor Method. But this time, after you have placed your units on the map, organized your units into AI Teams, completed the Reinforcement menu, and clicked on the units to add them to the reinforcement group, just click the “Export to File” button:

Image

This will create a REINFORCEMENTS#.BSF file in your My Documents/My Games/FieldOfGlory2/CAMPAIGNS folder:

Image

This file will be numbered automatically from 0 onwards, with the game selecting the lowest available number. As I did not have any previous REINFORCEMENTS#.BSF files sitting in my folder, this one has been numbered 0. If I already had a REINFORCEMENTS0.BSF in my folder, this new file would have been numbered REINFORCEMENTS1.BSF.

This file is a script fragment that contains all the information you will need about the reinforcement units.

Now, delete the reinforcing units from the battle field (see Scenario creation guide part 2). Please note that it is essential to delete the reinforcing units if you are using the Scripted Method, otherwise the units will be on the map at the start of the battle, and then come on again on the reinforcing turn!

Image

Next we have to create the scenario script for our scenario. Go to the main Field of Glory 2 installation folder. It should be C/Program Files (x86)/Slitherine/Field of Glory II. In there you will find a file called SCENARIOTEMPLATE.BSF.

Image

This is a generic template script that can be used in any user made scenarios. Copy the SCENARIOTEMPLATE.BSF and paste it into your scenario folder. For my scenario, that I am using as an example, it is My Documents/My Games/FieldOfGlory2/CAMPAIGNS/ KYNOSKEPHALAI_197BC/ SCENARIOS

Image

Now, rename the SCENARIOTEMPLATE.BSF file to exactly match your scenario .BAM file. So in this example, I have renamed it to Kynoskephalai.BSF.

Image

It is highly recommended to use a Text Editor, such as Notepad++, to edit the .BSF file. Notepad++ can be downloaded for free.

In it’s basic unaltered form the SCENARIOTEMPLATE.BSF file only has two slight effects on your scenario:

It slightly varies the number of men in each unit.

It also activates the Reskin function, so that your units will automatically use the available range of textures in the games texture folders. It will override any texture allocations you have made in the editor. If you do not want this to happen, open the .BSF file and search for the two lines that start with ReSkinArmy, and put two back slash characters in front of the lines, so it looks like this:

// ReSkinArmy(0, 0);
// ReSkinArmy(1, 0);

If you don’t mind this feature just leave the ReSkinArmy lines as they are.

Now open the REINFORCEMENTS.BSF file, and copy all the code from FUNCTION StartTurn(side) to the bottom of the file.

Image

Then, open your SCENARIO.BSF file, highlight the whole of the StartTurn(side) section, and paste in the code from the REINFORCEMENTS.BSF:

Image

It is crucial that you copy the whole section, and paste it over the corresponding whole section in the SCENARIO.BSF file. Every section of code that starts with { must be closed with }. Any stray characters will probably stop the scenario from loading.

Save and close the SCENARIO.BSF file.

That is all there is to it. Please note, that unlike the Editor Method, AI teams and orders can be used in the Scripted Method of reinforcement.

If you want to add a general to a reinforcement unit, you add four lines of code underneath the unit’s line in the script, for example:

Image

SetAttrib(id, "General", 14001);
SetAttrib(id, "GeneralType", 0);
SetAttrib(id, "GeneralQuality", 1);
UpdateDisplayGeneral(id,GetAttrib(id,"General"));

In the first line the number after “General” refers to index number of the name to be used from the text6.txt file in the C/Program Files (x86)/Slitherine/Field of Glory II/Data/Text folder.
In the second line, the number after “General” refers to the type of general, 0 is Sub-General, 1 is C-in-C, and 2 is Ally General.
In the third line, the number after “GeneralType” refers to his quality ranking, 0 is Troop Commander, 1 is Field Commander, and 2 is Great Commander.
The fourth line is just there to tell the game to display the general's banner, you don't change anything in this line.

You can edit the script directly to change aspects of the reinforcement, without having to go through the editor, you just need to know what all the numbers mean. Using the reinforcement script that we have created as an example, here is a brief explanation:

if (GetTurn() == 12)

The number in the brackets is the turn number on which the reinforcement group is set to arrive. Please note that each side has separate turn numbers, so that Side0’s turns are numbered 0,2,4,6,8 and so on. Side1’s turns are numbered 1,3,5,7 and so on.


id = PlaceUnit(32, 16, 0, 0, 0, "LIGHT_JAVELINS")

The first number in the brackets is the X coordinate of the entry square.
The second number is the Y coordinate of the entry square.
The third number is the direction that the unit is facing.
The fourth number is the army that the unit belongs to, this is side 0 for the player side, or side 1 for the AI side (or other player in an MP scenario).
The fifth number is AI team number that you have assigned to the unit in the editor.
The name in quotation marks is the name of the unit from the Squads.csv file.


ShowUIScreenToSide("BattlePop0", "Anim1", "IDS_AUTO_REINF_0", GetWorkString(13), 0)

This is referring to the message that is displayed when the group arrives, all you might need to know is that the very last number indicates which side gets to see the message, so if you want the player to see a message you might have to change the number to 0.


AddVizCam(GetUnitX(id), GetUnitY(id), 0)

This line is about the camera. Again, the very last number indicates which side’s camera moves to view the reinforcement, so you might want to change this number to 0, if you want the player to see the units arrive.
Last edited by Paul59 on Mon Mar 12, 2018 6:17 pm, edited 2 times in total.
Field of Glory 2 Scenario Designer - Age of Belisarius, Rise of Persia, and Wolves at the Gate.

TT Mod Creator

mkrass
Private First Class - Opel Blitz
Private First Class - Opel Blitz
Posts: 4
Joined: Sat Nov 18, 2017 4:47 am

Re: Scenario creation guide part 9 (Reinforcements Part2)

Post by mkrass » Tue Jan 09, 2018 3:15 pm

id = PlaceUnit(32, 16, 0, 0, 0, "LIGHT_JAVELINS") - the third number is "facing". This follows from FUNCTION PlaceUnit(x, y, facing, side, team, type) in Functions.BSF.
Unfortunately to assign team is not working. Whichever number you do not put (0-7) reinforcement always appears on the map with team number "0". And if you have several reinforcements during the scenario all of them will be indicated as one team on the battlefield.

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

Re: Scenario creation guide part 9 (Reinforcements Part2)

Post by rbodleyscott » Tue Jan 09, 2018 4:12 pm

mkrass wrote:id = PlaceUnit(32, 16, 0, 0, 0, "LIGHT_JAVELINS") - the third number is "facing". This follows from FUNCTION PlaceUnit(x, y, facing, side, team, type) in Functions.BSF.
Unfortunately to assign team is not working. Whichever number you do not put (0-7) reinforcement always appears on the map with team number "0". And if you have several reinforcements during the scenario all of them will be indicated as one team on the battlefield.
We will look into it.

Points to note:
AI_Masterplan(), which is used by the AI in random map battles and some Epic Battles, alters all the player side team assignments to suit the AI.

Because of this, group movement, command assignments etc. depend on the unit's "OriginalTeam" attribute, rather than on the assigned Team. The "OriginalTeam" attribute is set automatically for units that are on the battlefield at the start of the battle, but not (currently) for units added later by script.

So for example, if you want your reinforcements to be original team 5, you could use:

id = PlaceUnit(32, 16, 0, 0, 5, "LIGHT_JAVELINS");
SetAttrib(id, "OriginalTeam", 5);

We will need to decide whether adding setting "OriginalTeam" to the functionality of PlaceUnit() would be universally useful, or whether it might cause other issues.
Richard Bodley Scott

Image

mkrass
Private First Class - Opel Blitz
Private First Class - Opel Blitz
Posts: 4
Joined: Sat Nov 18, 2017 4:47 am

Re: Scenario creation guide part 9 (Reinforcements Part2)

Post by mkrass » Tue Jan 09, 2018 4:45 pm

rbodleyscott wrote: ... So for example, if you want your reinforcements to be original team 5, you could use:

id = PlaceUnit(32, 16, 0, 0, 5, "LIGHT_JAVELINS");
SetAttrib(id, "OriginalTeam", 5);
...
Thank you for this quick answer. It works fine for the purpose of having different teams in the scenario reinforcements!

Paul59
Brigadier-General - Elite Grenadier
Brigadier-General - Elite Grenadier
Posts: 2230
Joined: Tue Jul 21, 2015 11:26 pm

Re: Scenario creation guide part 9 (Reinforcements Part2)

Post by Paul59 » Tue Jan 09, 2018 8:12 pm

mkrass wrote:id = PlaceUnit(32, 16, 0, 0, 0, "LIGHT_JAVELINS") - the third number is "facing". This follows from FUNCTION PlaceUnit(x, y, facing, side, team, type) in Functions.BSF.
Unfortunately to assign team is not working. Whichever number you do not put (0-7) reinforcement always appears on the map with team number "0". And if you have several reinforcements during the scenario all of them will be indicated as one team on the battlefield.
Thanks for pointing out that the third number is for facing. I have actually used that in several scenarios in the past, but when it came to writing the Guide I must have completely forgot about it! I will correct the guide above to reflect that info, thanks again.
Field of Glory 2 Scenario Designer - Age of Belisarius, Rise of Persia, and Wolves at the Gate.

TT Mod Creator

Pi-R
Corporal - 5 cm Pak 38
Corporal - 5 cm Pak 38
Posts: 42
Joined: Tue Jun 08, 2010 6:08 pm

Re: Scenario creation guide part 9 (Reinforcements Part2)

Post by Pi-R » Mon Jan 29, 2018 7:53 pm

I'm still strugling with the AI code for the epic battles I'm creating. The AI does not always seems to do what my MoveTeamCoord function calls says it should.
To have a break with this I have tried to include the reinforcements for one of these epic battles. Unfortunately the created file REINFORCEMENTS0.BSF does not contain the units I had in the group that I had selected.

Code: Select all

include "Functions.BSF"
include "Helpers.BSF"

FUNCTION StartTurn(side)
{
int id

	// ...

	// Autogenerated script for reinforcement group 0 on side 0 - Paste this code into your StartTurn function:
	if (GetTurn() == 2)
	{
	}

	// ...

}
I have also tried including the code myself in the StartTurn function of my scenario's BSF file but nothing happens. The reinforcements do not appear.

Code: Select all

// called at the start of every turn.
// You would tend to use this for events
FUNCTION StartTurn(side)
{
	if (GetTurn() == -1)
		{
			// Setup anything that needs setting up at the start of the game
			PreBattleSetup();

			// Use the following code here if you want to use the standard deployment restrictions as outlined in the manual.
//          SetUniversalVar("StandardDeployment", 1);
//          SetStandardDeploymentBounds();
		}
	else
		{
			// Autogenerated script for reinforcement group 7 on side 1 - Paste this code into your StartTurn function:
			if (GetTurn() == 4)
				{
					id = PlaceUnit(33, 68, 0, 0, 0, "HILLMEN")
					SetAttrib(id, "OriginalTeam", 0);
					AddVizFunctionCall("GetHeadImage", , "BP0Image", 13)
					ShowUIScreenToSide("BattlePop0", Änime1", "IDS_AUTO_REINF_0", GetWorkString(13), 0)
					AddVizCam(GetUnitX(id), GetUnitY(id), 0)
					SetAttrib(id,"General", 32208);
					SetAttrib(id,"GeneralType", 2);
					SetAttrib(id,"GeneralQuality", 0);
					id = PlaceUnit(32, 68, 0, 0, 0, "LIGHT_JAVELINS")
					SetAttrib(id, "OriginalTeam", 0);
					AddVizCam(GetUnitX(id), GetUnitY(id), 0)
					id = PlaceUnit(31, 68, 0, 0, 0, "LIGHT_JAVELINS")
					SetAttrib(id, "OriginalTeam", 0);
					AddVizCam(GetUnitX(id), GetUnitY(id), 0)
					id = PlaceUnit(30, 68, 0, 0, 0, "LIGHT_JAVELINS")
					SetAttrib(id, "OriginalTeam", 0);
					AddVizCam(GetUnitX(id), GetUnitY(id), 0)
				}
		}
}
Does anyone maybe have an idea what might be causing this?

Paul59
Brigadier-General - Elite Grenadier
Brigadier-General - Elite Grenadier
Posts: 2230
Joined: Tue Jul 21, 2015 11:26 pm

Re: Scenario creation guide part 9 (Reinforcements Part2)

Post by Paul59 » Mon Jan 29, 2018 8:34 pm

For the first problem, I would guess that you have not clicked on the units on the map to add them to the Reinforcement Group, see Scenario creation guide part 8 (Reinforcements Part1):

http://www.slitherine.com/forum/viewtop ... 91&t=81084

I mention it just above the last screenshot, maybe you did not notice it?

For the second problem, you have made a lot of mistakes in the script.

You don't need all of this:

if (GetTurn() == -1)
{
// Setup anything that needs setting up at the start of the game
PreBattleSetup();

// Use the following code here if you want to use the standard deployment restrictions as outlined in the manual.
// SetUniversalVar("StandardDeployment", 1);
// SetStandardDeploymentBounds();
}
else
{


You also should delete the middle close bracket (})at the bottom.

And you need int id underneath FUNCTION StartTurn(side).

So it should look like this:

FUNCTION StartTurn(side)
{
int id

// Autogenerated script for reinforcement group 7 on side 1 - Paste this code into your StartTurn function:
if (GetTurn() == 4)
{
id = PlaceUnit(33, 68, 0, 0, 0, "HILLMEN")
SetAttrib(id, "OriginalTeam", 0);
AddVizFunctionCall("GetHeadImage", , "BP0Image", 13)
ShowUIScreenToSide("BattlePop0", Änime1", "IDS_AUTO_REINF_0", GetWorkString(13), 0)
AddVizCam(GetUnitX(id), GetUnitY(id), 0)
SetAttrib(id,"General", 32208);
SetAttrib(id,"GeneralType", 2);
SetAttrib(id,"GeneralQuality", 0);
id = PlaceUnit(32, 68, 0, 0, 0, "LIGHT_JAVELINS")
SetAttrib(id, "OriginalTeam", 0);
AddVizCam(GetUnitX(id), GetUnitY(id), 0)
id = PlaceUnit(31, 68, 0, 0, 0, "LIGHT_JAVELINS")
SetAttrib(id, "OriginalTeam", 0);
AddVizCam(GetUnitX(id), GetUnitY(id), 0)
id = PlaceUnit(30, 68, 0, 0, 0, "LIGHT_JAVELINS")
SetAttrib(id, "OriginalTeam", 0);
AddVizCam(GetUnitX(id), GetUnitY(id), 0)
}

}


Unfortunately the spacings have not displayed properly in my post, but hopefully you can get the gist of what I mean.

Hopefully that will work, but it is much easier just to add the units to the Reinforcement Group and then you can just copy and paste the whole script into the .BSF file, in the correct place of course! You will still need to manually add the SetAttrib lines though.
Field of Glory 2 Scenario Designer - Age of Belisarius, Rise of Persia, and Wolves at the Gate.

TT Mod Creator

Pi-R
Corporal - 5 cm Pak 38
Corporal - 5 cm Pak 38
Posts: 42
Joined: Tue Jun 08, 2010 6:08 pm

Re: Scenario creation guide part 9 (Reinforcements Part2)

Post by Pi-R » Tue Jan 30, 2018 8:34 pm

Thanks Paul59

Stupid me. I did not check your other guide about reinforcements anymore, and I also had missed your text
... and clicked on the units to add them to the reinforcement group ...
I assumed that as the units had already been assigned to the group that I wanted to appear as reinforcements the system already new which units were involved.

So now I have added the units before creating the file, it indeed contains the instructions I needed. It is working now.

Is there a way to have the general assigned to a reinforcement unit use a user defined name from the campaing's text9.txt file, instead of a name from C/Program Files (x86)/Slitherine/Field of Glory II/Data/Text folder/text6.txt?

Do you maybe know where the message I have entered can be found so it can be edited?

Paul59
Brigadier-General - Elite Grenadier
Brigadier-General - Elite Grenadier
Posts: 2230
Joined: Tue Jul 21, 2015 11:26 pm

Re: Scenario creation guide part 9 (Reinforcements Part2)

Post by Paul59 » Tue Jan 30, 2018 9:58 pm

Pi-R wrote:Thanks Paul59

Stupid me. I did not check your other guide about reinforcements anymore, and I also had missed your text
... and clicked on the units to add them to the reinforcement group ...
I assumed that as the units had already been assigned to the group that I wanted to appear as reinforcements the system already new which units were involved.

So now I have added the units before creating the file, it indeed contains the instructions I needed. It is working now.

Is there a way to have the general assigned to a reinforcement unit use a user defined name from the campaing's text9.txt file, instead of a name from C/Program Files (x86)/Slitherine/Field of Glory II/Data/Text folder/text6.txt?

Do you maybe know where the message I have entered can be found so it can be edited?
No problem.

To add a user defined general's name is very simple:

In this instance your general's name is determined by the line:

SetAttrib(id,"General", 32208);

Where the number, 32208, refers to the name reference in the C/Program Files (x86)/Slitherine/Field of Glory II/Data/Text folder/text6.txt file.

So to change the name to anything you want, just add the line

IDS_GENERAL32208,"YOUR NAME HERE",

to your scenarios Text9.txt file.

Your reinforcement messages are also saved to the Text9.txt file, and you can edit them there.

Actually, all of the scenarios text entries are saved in Text9.txt, and you can edit them freely.
Field of Glory 2 Scenario Designer - Age of Belisarius, Rise of Persia, and Wolves at the Gate.

TT Mod Creator

Pi-R
Corporal - 5 cm Pak 38
Corporal - 5 cm Pak 38
Posts: 42
Joined: Tue Jun 08, 2010 6:08 pm

Re: Scenario creation guide part 9 (Reinforcements Part2)

Post by Pi-R » Wed Jan 31, 2018 8:58 pm

Thanks again Paul59

I don't know what I would have done without all your help.

Now I can concentrate again on trying to get the AI making proper movements during its first moves, with some alternatives to use at random.

Paul59
Brigadier-General - Elite Grenadier
Brigadier-General - Elite Grenadier
Posts: 2230
Joined: Tue Jul 21, 2015 11:26 pm

Re: Scenario creation guide part 9 (Reinforcements Part2)

Post by Paul59 » Mon Mar 12, 2018 6:20 pm

I have just made a small update to the first post. After the 1.2.5 game update (Legions Triumphant), a new line of code is needed to display the general's banners for reinforcements.

Please note that this update affects my Castulo scenario, if you have the original version the general's banners will now no longer appear. So I have sent an updated version to RBS which corrects the issue, hopefully it will be available for download soon.
Field of Glory 2 Scenario Designer - Age of Belisarius, Rise of Persia, and Wolves at the Gate.

TT Mod Creator

desicat
Administrative Corporal - SdKfz 251/1
Administrative Corporal - SdKfz  251/1
Posts: 131
Joined: Sun Feb 09, 2020 3:02 pm

Re: Scenario creation guide part 9 (Reinforcements Part2)

Post by desicat » Mon Apr 27, 2020 1:34 am

Is there a way to provide a 1-3 turn range for the reinforcements to arrive to add a bit of uncertainty for anyone playing the Scenario a few times?

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

Re: Scenario creation guide part 9 (Reinforcements Part2)

Post by rbodleyscott » Mon Apr 27, 2020 6:03 am

desicat wrote:
Mon Apr 27, 2020 1:34 am
Is there a way to provide a 1-3 turn range for the reinforcements to arrive to add a bit of uncertainty for anyone playing the Scenario a few times?
Yes, using the scripted method. You will need to code a random condition that gives them a chance of appearance on the first two turns, and then if they haven't appeasred by the third turn have them appear anyway. You will need to use a global variable to keep track of whether they have yet appeared (to avoid them appearing more than once), as local variables do not persist outside of a function, and will start with a value of 0 each time a function is called.

Stockwellpete's Assandun scenario uses a similar technique for a command changing sides. (The global variable is defined at the start of the scenario script after the include line(s))
Richard Bodley Scott

Image

Post Reply

Return to “Field of Glory II: Scenario Design”