Page 1 of 1

Additional Victory Conditions

Posted: Fri Jan 05, 2018 8:52 pm
by Pi-R
In one of the epic battles I'm creating the AI has a baggage train. I want the AI to win if its baggage train reaches the edge of the map at a specific point (or just besides that point).

I use the following adapted version of the function VictoryConditions

Code: Select all

FUNCTION VictoryConditions()
{
	int total;
	int i;
	int id;
	int ret;
	int unitX;
	int unitY;

	total = GetUnitCount(1);
       SetGlobal("victory", 0);
	
	for (i = 0; i < total; i++)
	{
		id = GetUnitID(1,i);
		if (id != -1)
			{
				if ((IsUnitValid(id) == 1) && (GetAttrib(id, "MoraleState") < 3))
					{
						unitX = GetUnitX(id);
						unitY = GetUnitY(id);

						if ((unitX >= 30) && (unitX <= 32) && (unitY == 47) && (IsUnitSquadType(id, "Train") == 1))
							{
								SetGlobal("victory", 1);
								i = total;
								PlayVictoryDefeatSounds(1);
								if (GetShowSide() == 0)
									{
										ShowUIScreenY("BattlePop0", "Anim1", "IDS_SCN_MP_ADJUSTED_DEFEAT");
										AddVizDelay(2);
									}
								gGameScoreData.decisive = 1;
								gGameScoreData.winner =0;
								EndBattle(0);							
							}
					}
			}
	}

    if (GetGlobal("victory") != 1 )
		{
			StandardVictoryConditions(60, 40, 60, 40, 2, IsMultiplayer());
		}
	
	return 1; // VictoryConditions() must return a non-zero value so that the main program knows it exists and therefore not to use the default version.
}
When the baggage train reaches point 31,47 I do hear the sound of defeat and get the message IDS_SCN_MP_ADJUSTED_DEFEAT shown.

However when after this the result is shown together with the difficulty used it states it was a victory for me, i.e. a defeat for the AI.

1) What am I doing wrong? How can I have it show also defeat in the screen stating the difficulty level?

2) How can I have a different text be shown than IDS_SCN_MP_ADJUSTED_DEFEAT by function ShowUIScreenY? I have tried to create my own IDS text in text1.txt of my scenario but that did not seem to work. I believe I had called it IDS_SCN_BAGGAGE.

3) How can I update the default instructions for victory to include also info that it will be a defeat when the baggage train of the AI reaches that specific point at the edge of the map?

Re: Additional Victory Conditions

Posted: Sat Jan 06, 2018 8:53 am
by rbodleyscott
1) What am I doing wrong? How can I have it show also defeat in the screen stating the difficulty level?
EndBattle(0);

means side 0 (the player) has won.

For the AI (side 1) to win it needs to be

EndBattle(1);

Re: Additional Victory Conditions

Posted: Sat Jan 06, 2018 8:59 am
by rbodleyscott
2) How can I have a different text be shown than IDS_SCN_MP_ADJUSTED_DEFEAT by function ShowUIScreenY? I have tried to create my own IDS text in text1.txt of my scenario but that did not seem to work. I believe I had called it IDS_SCN_BAGGAGE.
The BattlePop0 UI screen is slightly weird, in that in order for it to work the actual IDS tag in the text file has to have "_BP0TEXT" at the end.

So, although you would think the tag should be

IDS_SCN_MP_ADJUSTED_DEFEAT

it is in fact

IDS_SCN_MP_ADJUSTED_DEFEAT_BP0TEXT

in the text file.

Yours needs to be

IDS_SCN_BAGGAGE_BP0TEXT

in your text1.txt file, although the parameter you send to the function is

"IDS_SCN_BAGGAGE"

Re: Additional Victory Conditions

Posted: Sat Jan 06, 2018 9:18 am
by rbodleyscott
Pi-R wrote:3) How can I update the default instructions for victory to include also info that it will be a defeat when the baggage train of the AI reaches that specific point at the edge of the map?
The easiest way to do this without having to script a custom script would be to mod

IDS_SCENUI_VC_STANDARD, "Rout the enemy army by:~a) Routing at least 40% of their troops and ",

in your text1.txt file, to say something like:

IDS_SCENUI_VC_STANDARD, "Prevent the enemy baggage from reaching ..... and rout the enemy army by:~a) Routing at least 40% of their troops and ",

Re: Additional Victory Conditions

Posted: Sat Jan 06, 2018 1:45 pm
by Pi-R
Thanks Richard. I have now solved 1 and 2.

For 3 I believe I will have script it. When using IDS_SCENUI_VC_STANDARD in my text1.txt file the updated condition I believe it will be displayed for all other battles as well, as they all use the same file.
Or can you have different text1.txt files for the different scenarios in the same campaign. I guess not.

So can you please direct me to which function(s) I'll have to look into for this?

Re: Additional Victory Conditions

Posted: Sat Jan 06, 2018 1:51 pm
by rbodleyscott
Pi-R wrote:Thanks Richard. I have now solved 1 and 2.

For 3 I believe I will have script it. When using IDS_SCENUI_VC_STANDARD in my text1.txt file the updated condition I believe it will be displayed for all other battles as well, as they all use the same file.
Or can you have different text1.txt files for the different scenarios in the same campaign. I guess not.
You can't, but you can change the string used by the function in the scenario script.

Code: Select all

FUNCTION PrintScenarioUI()
	{
		StandardScenarioUI("IDS_SCENUI_VC_STANDARD", 1);  // You can of course write your own custom UI if you prefer.
		
		return 1; // PrintScenarioUI() must return a non-zero value so that the main program knows it exists and therefore not to use the default version.
	}
Just change "IDS_SCENUI_VC_STANDARD" to something else for this scenario.

e.g.

IDS_SCENUI_AI_BAGGAGE, "Prevent the enemy baggage from reaching ..... and rout the enemy army by:~a) Routing at least 40% of their troops and ",

Code: Select all

FUNCTION PrintScenarioUI()
	{
		StandardScenarioUI("IDS_SCENUI_AI_BAGGAGE", 1);  // You can of course write your own custom UI if you prefer.
		
		return 1; // PrintScenarioUI() must return a non-zero value so that the main program knows it exists and therefore not to use the default version.
	}

Re: Additional Victory Conditions

Posted: Sat Jan 06, 2018 3:33 pm
by Pi-R
Thanks Richard, that was exactly what I needed.