D-DAY SF Campaign : Sainte-Mere-Eglise

Download scenarios and talk about scenario design.

Moderators: Slitherine Core, BA Moderators

Amaris
Captain - Heavy Cruiser
Captain - Heavy Cruiser
Posts: 929
Joined: Fri Jul 23, 2010 11:08 am
Location: France
Contact:

Post by Amaris »

The function GetUnitLonely(unit) is being called to run in the function MoraleCheck(), MoraleCheck() even called in the function StartTurn(side).

I do that for optimisation : my function MoraleCheck() use a single loop to go through the player's units, or is an officer and call the function OfficerBonus(unit), or I look if the unit is isolated (with function GetUnitLonely(unit)) and call the function AjustMoral(unit).
Merr
Captain - Heavy Cruiser
Captain - Heavy Cruiser
Posts: 903
Joined: Mon Aug 16, 2010 2:00 pm

Post by Merr »

Amaris wrote:The function GetUnitLonely(unit) is being called to run in the function MoraleCheck(), MoraleCheck() even called in the function StartTurn(side).

I do that for optimisation : my function MoraleCheck() use a single loop to go through the player's units, or is an officer and call the function OfficerBonus(unit), or I look if the unit is isolated (with function GetUnitLonely(unit)) and call the function AjustMoral(unit).

hmm ... I'm sorry I haven't ran the scenario to check this ... I can see the check(for lonelyunit) in the MoraleCheck() ....

Code: Select all

		else
		{
			if(GetUnitLonely(unit) == 1)
			{
				AjustMoral(unit);
			}
		}
But, I'm not seeing anywhere that actually calls the function (to return a value of 0 or 1) ... Shouldn't it read like this ;

Code: Select all

		else
		{
			GetUnitLonely(unit) ;
			
			if(GetUnitLonely(unit) == 1)
			{
				AjustMoral(unit);
			}
		}
junk2drive
BA Moderator
BA Moderator
Posts: 1478
Joined: Sun May 23, 2010 4:47 pm
Location: Arizona USA -7GMT

Post by junk2drive »

I have played it and as I recall at the beginning of your turn it pops up text that your unit is isolated or bonus. It appears to work to me.
You can call me junk - and type that with one hand.
Merr
Captain - Heavy Cruiser
Captain - Heavy Cruiser
Posts: 903
Joined: Mon Aug 16, 2010 2:00 pm

Post by Merr »

junk2drive wrote:I have played it and as I recall at the beginning of your turn it pops up text that your unit is isolated or bonus. It appears to work to me.
I'm just puzzled on how the logic works ... :?
Amaris
Captain - Heavy Cruiser
Captain - Heavy Cruiser
Posts: 929
Joined: Fri Jul 23, 2010 11:08 am
Location: France
Contact:

Post by Amaris »

Well I'll try to explain :

Indeed the function GetUnitLonely(unit) return a value of 0 or 1 when it called.

The Syntax of if is :

Code: Select all

if(conditional)
{
  //code
}
else
{
  //code
}
The call of GetUnitLonely(unit) :

Code: Select all

...
			if(GetUnitLonely(unit) == 1)
			{
				AjustMoral(unit);
			}
...
The (conditional) of if is : GetUnitLonely(unit) == 1. So the program call the function GetUnitLonely(unit), return 0 or 1 as follows and finally the (conditional) is 0 == 1 or 1 == 1 as follows.
Merr
Captain - Heavy Cruiser
Captain - Heavy Cruiser
Posts: 903
Joined: Mon Aug 16, 2010 2:00 pm

Post by Merr »

I didn't know that the conditional automatically called the function ... I always thought it(function) had to be called first, then checks against the conditional ... :oops:

Thanks for explaining! I'm just a noob you know :wink:
Post Reply

Return to “Battle Academy : Scenario Design”