Page 1 of 1

AI Bonus Script (example)

Posted: Sun Mar 27, 2011 7:35 pm
by Merr
Some folks were wondering about the script on "how-to" make the AI use a Bonus ...
Note: globals need to be setup beforehand.

- ARTILLERY -
This is a snipet from the D-DAY.BSF ...

Code: Select all

FUNCTION StartTurn(side)
{	
	if(side == 1)
	{	
		if (GetGlobal("gTrigger") == 1)
		{
			if (GetGlobal("gTurn") == 2)  // 2 turns after start of the first turn with a unit over the river
			{
				targetx = Rand (24,28) ;
				targety = Rand (38,42) ;
				SetBonusBaseValue("GermanArtHitWait", 1, 0) ;	
				CallBonusFunction("BONUS_GERMAN_BATTERY", 1, targetx, targety, -1) ;  // Artillery strike after check-point
			}
			
			if (GetGlobal("gTurn") == 4)  // 4 turns after start of the first turn with a unit over the river
			{
				targetx = Rand (25,27) ;
				targety = Rand (46,50) ;
				SetBonusBaseValue("GermanArtHitWait", 1, 0) ;	
				CallBonusFunction("BONUS_GERMAN_BATTERY", 1, targetx, targety, -1) ;  // Artillery strike on main road
			}
		}
	}
}
For airstrikes you can find that yourself ... But, it's probably going to look basically like it does above, except the following change :

Example ... Hurricane Airstrike :

Code: Select all

				SetBonusBaseValue("HurricaneHitWait", 1, 0) ;	
				CallBonusFunction("BONUS_HURRICANE_BATTERY", 1, targetx, targety, -1) ;
Hope that explains it.... All cut-n-paste ... takes a few minutes to do.

Merr

Posted: Sun Mar 27, 2011 7:47 pm
by Merr
Ok ... You'll note that the script included GLOBALS ... So, let's find them in the DDAY.BSF ...

(by the way, this is how I create my crazy scripts, which are actually "PipScripts" ... just all jumbled up)

Now ... There it is ... I found the globals that I need to finish this ...

Code: Select all

FUNCTION PreBattleSetup()
{
	SetGlobal("gTurn", 0) ;
	SetGlobal("gTrigger", 0) ;
}
Ok ... I didn't test this, but it all looks good ... everything has been found, and added(changed).

Hope this help..goodday!

Posted: Sun Mar 27, 2011 7:51 pm
by Merr
Oh ... perhaps there is one more GLOBAL to ensure this all works ... SO, add this to the Prebattle ...

Code: Select all

FUNCTION PreBattleSetup()
{
	SetGlobal("gTurn", 0) ;
	SetGlobal("gTrigger", 0) ;
	SetGlobal("gBombardment", 2);
}
Just to make sure ... because the Bonus needs a value for the "gbombardment" ... If it's missing, I believe it use's a value of 0.

Merr

EDIT .... The reason why I added the gbombardment was mainly because if you "call" a bonus or use a function in your script, you need to ensure the function has all the parameters that the function is calling for ... in this case, the global.

Posted: Sun Mar 27, 2011 8:14 pm
by tim1966
Thanks mate - that will be a great help in my Cambrai campaign :D

Posted: Sun Apr 03, 2011 7:59 pm
by Merr
tim1966 wrote:Thanks mate - that will be a great help in my Cambrai campaign :D
Tim,

The above script won't work ... however, it's a building block for getting a script to work.

Now, the script below WORKS and has been tested by me. This script would go into your scenarioBSF.
Later on I'll continue this thread with variations to the script below.
The important thing to remember about all this is that you have to troubleshoot the initial script to get a working script, that is, if you don't already understand how it all works.

Please note the changes in the working script to the original script from the other posts above :

Code: Select all

// called at the start of every turn.
// You would tend to use this for events
FUNCTION StartTurn(side)
{
	int targetx ;
	int targety ;
	
	if(side == 1)
	{				
		if (GetTurn() == 1)   // side 1 turns will always be odd...
		{
			targetx = Rand (26,30) ;
			targety = Rand (20,25) ;
			SetBonusBaseValue("GermanArtHitWait", 1, 0) ;	
			CallBonusFunction("BONUS_GERMAN_BATTERY", 1, targetx, targety, -1) ;  // Artillery strike
			SetGlobal("gBombardment", 0) ;
		}
		
		if (GetTurn() == 3)   // side 1 turns will always be odd...
		{
			targetx = Rand (32,38) ;
			targety = Rand (19,23) ;
			SetBonusBaseValue("GermanArtHitWait", 1, 0) ;	
			CallBonusFunction("BONUS_GERMAN_BATTERY", 1, targetx, targety, -1) ;  // Artillery strike
			SetGlobal("gBombardment", 1) ;
		}	
	}
}

FUNCTION PreBattleSetup()
{
	SetGlobal("gBombardment", 0);
}


Posted: Mon Apr 04, 2011 7:47 pm
by tim1966
Thanks - your making me work for my AI bonus :lol: