Global Range Reduction Script
Moderators: Slitherine Core, BA Moderators
-
Old_Warrior
- Major - Jagdpanther

- Posts: 1019
- Joined: Fri Apr 30, 2010 3:13 am
Global Range Reduction Script
Looking to figure out how to script a global range reduction for a mission. We have a fog script in one of the Normandy Missions but the problem is is that Unit A can spot for friendly Unit B, who is out of visibility range. If the Range value for the mission were set to the same length as the Visibility value then the units would not be able to spot for each other.
Here is the Fog script:
FUNCTION StartTurnPost(side)
{
int i ;
int j ;
int id ;
int LOS ;
// Reduce LOS
for(i=0; i<GetSideCount(); i++)
{
for(j=0; j<GetUnitCount(i); j++)
{
id = GetUnitID(i, j) ;
if( GetBaseAttrib(id, "LOS") > 25 )
{
LOS = 25 ;
SetAttrib(id, "LOS", LOS) ;
}
}
}
}
This works fine in reducing the visibility of units but not the range.
There must be script that can be added somewhere in the scenario script that will reduce the range. Can someone help me out with that using simple terms? Thanks!
Here is the Fog script:
FUNCTION StartTurnPost(side)
{
int i ;
int j ;
int id ;
int LOS ;
// Reduce LOS
for(i=0; i<GetSideCount(); i++)
{
for(j=0; j<GetUnitCount(i); j++)
{
id = GetUnitID(i, j) ;
if( GetBaseAttrib(id, "LOS") > 25 )
{
LOS = 25 ;
SetAttrib(id, "LOS", LOS) ;
}
}
}
}
This works fine in reducing the visibility of units but not the range.
There must be script that can be added somewhere in the scenario script that will reduce the range. Can someone help me out with that using simple terms? Thanks!
-
pipfromslitherine
- Site Admin

- Posts: 9929
- Joined: Wed Mar 23, 2005 10:35 pm
Re: Global Range Reduction Script
HERange and APRange would probably do it. I would need to double check the scripts to be sure, but off the top of my head that should work.
You might also want to set the *ReactionRange attribs too, but I think the ranges would prevent them from trying to react anyway.
Cheers
Pip
You might also want to set the *ReactionRange attribs too, but I think the ranges would prevent them from trying to react anyway.
Cheers
Pip
-
Old_Warrior
- Major - Jagdpanther

- Posts: 1019
- Joined: Fri Apr 30, 2010 3:13 am
Re: Global Range Reduction Script
I will search around for the text "HERange" and "APRange" and see if I can come up with the script on my own. Thanks for pointing me in the right direction.
-
GottaLove88s
- Lieutenant-General - Do 217E

- Posts: 3151
- Joined: Fri Apr 06, 2012 6:18 pm
- Location: Palau
Re: Global Range Reduction Script
Unsure, but Pip might mean reducing the HERange and APRange distances and their reaction fire equivalents for the units concerned in squads.csv?
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
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
-
Old_Warrior
- Major - Jagdpanther

- Posts: 1019
- Joined: Fri Apr 30, 2010 3:13 am
Re: Global Range Reduction Script
Here is a script from France5.BSF:
for(i=0; i<=1; i++)
{
id = GetUnitOnTile(18+i, 36) ;
if( id != -1 )
{
if( (GetGlobal("tanks") < 2) && (GetUnitDead(id) == 0) && (IsUnitType(id, "PANHARD_P178") == 1) )
{
SetAttrib(id, "AP", 0) ;
SetAttrib(id, "APRange", 0) ;
SetAttrib(id, "HERange", 0) ;
}
}
}
Is this saying that the range is now "0" ??
Is that "0" value the same as for the LOS script values?
So if
LOS = 25 ;
can I use:
SetAttrib(id, "APRange", 25) ;
Are the values measured in the same type of unit measurement?
???
I also need to know if a global range setting would affect the range for Special Acitons like Artillery and so on.
for(i=0; i<=1; i++)
{
id = GetUnitOnTile(18+i, 36) ;
if( id != -1 )
{
if( (GetGlobal("tanks") < 2) && (GetUnitDead(id) == 0) && (IsUnitType(id, "PANHARD_P178") == 1) )
{
SetAttrib(id, "AP", 0) ;
SetAttrib(id, "APRange", 0) ;
SetAttrib(id, "HERange", 0) ;
}
}
}
Is this saying that the range is now "0" ??
Is that "0" value the same as for the LOS script values?
So if
LOS = 25 ;
can I use:
SetAttrib(id, "APRange", 25) ;
Are the values measured in the same type of unit measurement?
???
I also need to know if a global range setting would affect the range for Special Acitons like Artillery and so on.
-
Old_Warrior
- Major - Jagdpanther

- Posts: 1019
- Joined: Fri Apr 30, 2010 3:13 am
Re: Global Range Reduction Script
How close is this:
if( IsUnitSquadType(id, "TRACKED") == 1 )
SetAttrib(id, "APRange", 25) ;
SetAttrib(id, "HERange", 25) ;
This would set the range for all Tracked types. I just need to know if there exists a value for ALL types. And the above script may need more parts.
if( IsUnitSquadType(id, "TRACKED") == 1 )
SetAttrib(id, "APRange", 25) ;
SetAttrib(id, "HERange", 25) ;
This would set the range for all Tracked types. I just need to know if there exists a value for ALL types. And the above script may need more parts.
Re: Global Range Reduction Script
Am I on - DEF?
-
Old_Warrior
- Major - Jagdpanther

- Posts: 1019
- Joined: Fri Apr 30, 2010 3:13 am
Re: Global Range Reduction Script
Yup, hearing you loud and clear, Buff.
-
Old_Warrior
- Major - Jagdpanther

- Posts: 1019
- Joined: Fri Apr 30, 2010 3:13 am
Re: Global Range Reduction Script
Tried this in mission:
//*****************************************************************************
//StartTurn - Reduce LOS for Fog
//*****************************************************************************
FUNCTION StartTurnPost(side)
{
int i ;
int j ;
int id ;
int LOS ;
// Reduce LOS
for(i=0; i<GetSideCount(); i++)
{
for(j=0; j<GetUnitCount(i); j++)
{
id = GetUnitID(i, j) ;
if( GetBaseAttrib(id, "LOS") > 25 )
{
LOS = 25 ;
SetAttrib(id, "LOS", LOS) ;
}
}
}
// Reduce Range
if( IsUnitSquadType(id, "TRACKED") == 1 )
{
SetAttrib(id, "APRange", 3) ;
SetAttrib(id, "HERange", 3) ;
}
}
It did not work. Maybe needs to be under another FUNCTION? Maybe script is wrong? I didn't get an error message.
If the unit(A) has a helper unit(B) spot the target then the target can still be fired on by Unit A even if out of LOS range.
//*****************************************************************************
//StartTurn - Reduce LOS for Fog
//*****************************************************************************
FUNCTION StartTurnPost(side)
{
int i ;
int j ;
int id ;
int LOS ;
// Reduce LOS
for(i=0; i<GetSideCount(); i++)
{
for(j=0; j<GetUnitCount(i); j++)
{
id = GetUnitID(i, j) ;
if( GetBaseAttrib(id, "LOS") > 25 )
{
LOS = 25 ;
SetAttrib(id, "LOS", LOS) ;
}
}
}
// Reduce Range
if( IsUnitSquadType(id, "TRACKED") == 1 )
{
SetAttrib(id, "APRange", 3) ;
SetAttrib(id, "HERange", 3) ;
}
}
It did not work. Maybe needs to be under another FUNCTION? Maybe script is wrong? I didn't get an error message.
If the unit(A) has a helper unit(B) spot the target then the target can still be fired on by Unit A even if out of LOS range.
-
pipfromslitherine
- Site Admin

- Posts: 9929
- Joined: Wed Mar 23, 2005 10:35 pm
Re: Global Range Reduction Script
Why only for tracked units? I would expect that code to work - the CHECK_ functions for (e.g.) firing AP includes a check on APRange.
Ah - you have also put the reduce range stuff outside of the loop that goes through all the units, so it will only ever get done to the last unit on the 2nd side. It was hard to spot in the above code because the paste has killed off the indenting
Cheers
Pip
Ah - you have also put the reduce range stuff outside of the loop that goes through all the units, so it will only ever get done to the last unit on the 2nd side. It was hard to spot in the above code because the paste has killed off the indenting
Cheers
Pip
-
Old_Warrior
- Major - Jagdpanther

- Posts: 1019
- Joined: Fri Apr 30, 2010 3:13 am
Re: Global Range Reduction Script
How should it look?
No, not only for tracked units. See my comments. I am looking for the statement that is for ALL units. Not just tracked. Is it "ALL" ??
No, not only for tracked units. See my comments. I am looking for the statement that is for ALL units. Not just tracked. Is it "ALL" ??
Last edited by Old_Warrior on Mon Sep 03, 2012 12:20 am, edited 1 time in total.
-
pipfromslitherine
- Site Admin

- Posts: 9929
- Joined: Wed Mar 23, 2005 10:35 pm
Re: Global Range Reduction Script
You have two for( loops, one doing each side (the one with GetSideCount() in it) and one doing each unit in the side (the one with GetUnitCount(i) in it). You need to place the APRange... stuff inside the loop, immediately following the LOS changes. The indentation should help see where the various code blocks are. Indented, the code should look something like below:
//*****************************************************************************
//StartTurn - Reduce LOS for Fog
//*****************************************************************************
FUNCTION StartTurnPost(side)
{
int i ;
int j ;
int id ;
int LOS ;
// Reduce LOS
for(i=0; i<GetSideCount(); i++)
{
for(j=0; j<GetUnitCount(i); j++)
{
id = GetUnitID(i, j) ;
if( GetBaseAttrib(id, "LOS") > 25 )
{
LOS = 25 ;
SetAttrib(id, "LOS", LOS) ;
}
// Reduce Range
if( IsUnitSquadType(id, "TRACKED") == 1 )
{
SetAttrib(id, "APRange", 3) ;
SetAttrib(id, "HERange", 3) ;
}
}
}
}
//*****************************************************************************
//StartTurn - Reduce LOS for Fog
//*****************************************************************************
FUNCTION StartTurnPost(side)
{
int i ;
int j ;
int id ;
int LOS ;
// Reduce LOS
for(i=0; i<GetSideCount(); i++)
{
for(j=0; j<GetUnitCount(i); j++)
{
id = GetUnitID(i, j) ;
if( GetBaseAttrib(id, "LOS") > 25 )
{
LOS = 25 ;
SetAttrib(id, "LOS", LOS) ;
}
// Reduce Range
if( IsUnitSquadType(id, "TRACKED") == 1 )
{
SetAttrib(id, "APRange", 3) ;
SetAttrib(id, "HERange", 3) ;
}
}
}
}
-
Old_Warrior
- Major - Jagdpanther

- Posts: 1019
- Joined: Fri Apr 30, 2010 3:13 am
Re: Global Range Reduction Script
Odd that it would matter. The script was inside of the Function brackets. The Init ID was part of the FUNCTION and not the subscript.
I will try that out and get back to you ...
I will try that out and get back to you ...
-
Old_Warrior
- Major - Jagdpanther

- Posts: 1019
- Joined: Fri Apr 30, 2010 3:13 am
Re: Global Range Reduction Script
Here is the finished/working script:

Here is a screenshot of how it works in the game:

Note how the Sherman can only target ONE Panther even though it can "see" all of them (via the infantry unit in the lower left corner).
Also note that the script is not completely finished. This only affects tracked units. I need to change the expression so that it affects all units.

Here is a screenshot of how it works in the game:

Note how the Sherman can only target ONE Panther even though it can "see" all of them (via the infantry unit in the lower left corner).
Also note that the script is not completely finished. This only affects tracked units. I need to change the expression so that it affects all units.
-
pipfromslitherine
- Site Admin

- Posts: 9929
- Joined: Wed Mar 23, 2005 10:35 pm
Re: Global Range Reduction Script
The unit ID is different for every unit. Without the loop going through each unit, getting it's ID, and then doing things using that ID, then how would the code act on each unit? The variable id is just a name, it doesn't denote anything specific just because it is called id.Old_Warrior wrote:Odd that it would matter. The script was inside of the Function brackets. The Init ID was part of the FUNCTION and not the subscript.
I will try that out and get back to you ...
Cheers
Pip
-
Old_Warrior
- Major - Jagdpanther

- Posts: 1019
- Joined: Fri Apr 30, 2010 3:13 am
Re: Global Range Reduction Script
Here is the updated script:

I tried it out in the mission and it works.
Thanks for helping out, Pip!
Now if I can just write a script that will remove the fog from my brain!

I tried it out in the mission and it works.
Thanks for helping out, Pip!
Now if I can just write a script that will remove the fog from my brain!
