Is it possible to randomise the bonus delay?

Modders can post their questions on scripting and more.

Moderators: Slitherine Core, BA Moderators

Post Reply
GottaLove88s
Lieutenant-General - Do 217E
Lieutenant-General - Do 217E
Posts: 3151
Joined: Fri Apr 06, 2012 6:18 pm
Location: Palau

Is it possible to randomise the bonus delay?

Post by GottaLove88s »

Let's say a scenario includes
- Naval Artillery
- Typhoon

Is it possible to randomise either or both of...
- the recharge wait time
- the delay (the number of turns from when it's ordered to when it happens)

I want to make these more random so that both elements can change during the same game.

This would replicate that sometimes the Typhoons are right above and sometimes they're further away, etc.
It would also prevent experienced players simply counting turns between strikes and "knowing" when they're coming...
(although the enemy pulling back would be a big clue prior to naval arty, lol)
SCENARIO LINKS
Seelow'45 -> www.slitherine.com/forum/viewtopic.php?f=313&t=55132
Normandy'44 -> www.slitherine.com/forum/viewtopic.php?f=87&t=42094
Dieppe'42 -> www.slitherine.com/forum/viewtopic.php?f=87&t=42347
pipfromslitherine
Site Admin
Site Admin
Posts: 9929
Joined: Wed Mar 23, 2005 10:35 pm

Re: Is it possible to randomise the bonus delay?

Post by pipfromslitherine »

It should be just a case of tweaking the globals used by the scripts - although the action delay would be trickier, as you don't necessarily know when it is set, but you could work out logic to keep looking and then set it when it got activated and flag to your own code not to keep setting it.

gCounter is the var for the cooldown, while gBombardment is the var for the action delay

Cheers

Pip
GottaLove88s
Lieutenant-General - Do 217E
Lieutenant-General - Do 217E
Posts: 3151
Joined: Fri Apr 06, 2012 6:18 pm
Location: Palau

Re: Is it possible to randomise the bonus delay?

Post by GottaLove88s »

Thanks Pip,

Ok, I can see the base values in CARDS.TXT where it has eg. TyphoonDelay and TyphoonHitWait.

And I can see bonus .BSFs for example, TYPHOON.BSF

But, if I'm understanding you correctly, I should leave these alone and directly set gCounter and gBombardment somewhere else?

Where is the best place to put some code to assign a random value to gCounter and gBombardment, so that it only sets new random values for both* immediately after the previous bombardment?

*Or either one, if setting a random value for both is too complicated
SCENARIO LINKS
Seelow'45 -> www.slitherine.com/forum/viewtopic.php?f=313&t=55132
Normandy'44 -> www.slitherine.com/forum/viewtopic.php?f=87&t=42094
Dieppe'42 -> www.slitherine.com/forum/viewtopic.php?f=87&t=42347
pipfromslitherine
Site Admin
Site Admin
Posts: 9929
Joined: Wed Mar 23, 2005 10:35 pm

Re: Is it possible to randomise the bonus delay?

Post by pipfromslitherine »

We've dealt with this before, but only in terms of setting (e.g.) the delay higher or lower. To set either randomly you could have a small check in the Tick function which looks for the values of the var, and (when it sees it change from 0 to a value) would then know that the bonus has been activated and can then swoop in and change the variable, and set another script var to tell it that it can stop looking for the change.

I've not explained that awfully well :) Basically you need to spot when you need to step in, change the value, and then step out again.

It might be simpler to just put a custom version of the bonus script in your campaign, although that is not as general purpose.

Cheers

Pip
GottaLove88s
Lieutenant-General - Do 217E
Lieutenant-General - Do 217E
Posts: 3151
Joined: Fri Apr 06, 2012 6:18 pm
Location: Palau

Re: Is it possible to randomise the bonus delay?

Post by GottaLove88s »

Hmmm... Thanks Pip... I'm all for simple please.

So, if I work within each of the bonus .BSFs that I want to use, let's use TYPHOON.BSF as an example (attached here as code)

Where is the smartest place to add a randomised gBombardment and gCounter? So that it only changes the value after executing a bombardment. And then keeps those two values until after the next bombardment.

I would just copy whatever we change into GERMANBATTERY.BSF, 25PDRBATTERY.BSF and NAVALBATTERY.BSF, to achieve the same randomisation across a range of bonuses.

Sorry for the foolish questions...
:oops:

Code: Select all

include "Tools.bsf"
include "Airstrike.bsf"

// called to see if we want to use a cancel popup
FUNCTION SHOULD_CANCEL()
{
int ret ;

	if( GetGlobal("gBombardment") > 0)
	{
		ret = 1 ;
	}
	
	return ret ;
}

FUNCTION CANCEL_BONUS()
{
	SetGlobal("gBombardment", 0) ;
	HideEffectMarker(GetBonusValue("MarkerID", GetCurrentSide(), "Typhoon")) ;
}

// Function called when we want to actually call in an bombardment (e.g. when we select from the drop menu)
// can take all the usual x,y,unit,me info that the unit script functions do
function BONUS_TYPHOON_BATTERY(tilex, tiley)
{
	if( GetGlobal("gBombardment") > 0)
	{
		// cancel...
		SetGlobal("gBombardment", 0) ;
		HideEffectMarker(GetBonusValue("MarkerID", GetCurrentSide(), "Typhoon")) ;
	}
	else
	{
		SetGlobal("gBombardment",  GetBonusValue("HitWait", GetCurrentSide(), "Typhoon")) ;
		SetGlobal("gBombX", tilex) ;
		SetGlobal("gBombY", tiley) ;	
		if( GetGlobal("gBombardment") == 0 )
		{
			SetGlobal("gBombardment", 1) ;	// trigger it immediately.
			STARTTURN_BONUS_TYPHOON_BATTERY() ;
		}
		else
		{
			// wait and we will do it later..
			ShowEffectMarker(GetBonusValue("MarkerID", GetCurrentSide(), "Typhoon"), tilex,tiley,"typhoon_marker", -1, GetCurrentSide()) ;
		}
	}
}

// tell us whether the drop menu item should display/be disabled.  Anything >= 0 means show as normal
function CHECK_BONUS_TYPHOON_BATTERY(tilex,tiley,unit)
{
	return BonusCheck(tilex, tiley, unit, "Typhoon") ;

}

// Do any drop menu button drawing etc you want to do after the button is rendered
function UIBUTTON_BONUS_TYPHOON_BATTERY(x,y,width, height)
{
	BonusShowButtonInfo("Typhoon") ;
}

// do any drop menu button stuff you want to do prior to the button being drawn
function UISETUP_BONUS_TYPHOON_BATTERY()
{
	SetUITexture("typhoon_bonus_button.tga", "ffffffff") ;	
	if( GetGlobal("gBombardment") > 0)
	{
		SetUITexture("cross_round_button.tga", "ffffffff") ;		
	}		
	//SetUITexture("FightBig.tga", "ffff0000") ;
}

// NOW WE HAVE THE FUNCTIONS FOR THE ICON ON SCREEN

// EMPTY FUNCTION NEEDED TO MAKE SOME CODE WORK...
// basically you want to mirror the above code, but instead of BONUS use BONUSICON
function BONUSICON_TYPHOON_BATTERY()
{
}

// same as usual, can return -1, -2, or >=0 for disabled, not shown, or normal respectively
function CHECK_BONUSICON_TYPHOON_BATTERY()
{
	return BonusUICheck("Typhoon") ;
}

// draw anything we want to draw on top of the usual rendering.
function UIBUTTON_BONUSICON_TYPHOON_BATTERY(x, y)
{
	BonusIconUI(x, y, "Typhoon") ;
}

// Do anything we want to happen before the icon is rendered
function UISETUP_BONUSICON_TYPHOON_BATTERY()
{
	SetUITexture("typhoon_bonus.tga", "ffffffff") ;
}


// You can now have multiple STARTTURN_* functions all of which are called (don't rely on the order in which
// they are called though!)
function STARTTURN_BONUS_TYPHOON_BATTERY()
{
	if(GetTurn()<=0)
	{
		// we start off ready to go
		SetGlobal("gCounter", 10000) ;
	}
	
	if( GetGlobal("gBombardment") > 0)
	{
		SetGlobal("gBombardment", GetGlobal("gBombardment")-1) ;
		
		if( GetGlobal("gBombardment") == 0)
		{
			// so we will only reset the counter after we execute, so no cost to cancel.
			SetGlobal("gCounter", 0) ;			
			AirStrike(GetGlobal("gBombX"), GetGlobal("gBombY"), "typhoon_attack", "Typhoon", GetBonusValue("MarkerID", GetCurrentSide(), "Typhoon")) ;
		}
	}
	else
	{
		SetGlobal("gCounter", GetGlobal("gCounter")+1 ) ;
	}
}

SCENARIO LINKS
Seelow'45 -> www.slitherine.com/forum/viewtopic.php?f=313&t=55132
Normandy'44 -> www.slitherine.com/forum/viewtopic.php?f=87&t=42094
Dieppe'42 -> www.slitherine.com/forum/viewtopic.php?f=87&t=42347
pipfromslitherine
Site Admin
Site Admin
Posts: 9929
Joined: Wed Mar 23, 2005 10:35 pm

Re: Is it possible to randomise the bonus delay?

Post by pipfromslitherine »

Hmmm - the counter stuff is fiddly, as it works from the bonus values to in BonusTimerCheck. You could try setting gCounter to a negative value - it could work. So subtract a random value on line 119 (typhoon script).

For the bombardment, it counts down (not sure why they work in opposite ways!) so you can just add/sub a random number somewhere after line 35.

Hope that helps

Cheers

Pip
Post Reply

Return to “Battle Academy : Modders Corner ”