Reverse Movement ... 1 Tile Move
Moderators: Slitherine Core, BA Moderators
Reverse Movement ... 1 Tile Move
Pip,
Last week I figured out a way to do a 1-Tile reverse movement (all theory, no code yet), however, it's quite ugly since I'll be getting angle info from me/unit, then rotating the unit to face me, then using the DeployUnit to teleport the unit back one tile.
I was wondering ... I know that the ALL_MOVE uses the "SetRoute" function but unfortunately the function isn't available in any of the BSF's for me to modify the body ... I'd like to make a new function like "SetReverseRoute".
I'm thinking it would be easier to tweak the SetRoute ... Can you post the FUNCTION SetRoute() please?
Thanks in advance. No problem if you can't provide the function info. I can use smoke and mirrors.
Merr
Last week I figured out a way to do a 1-Tile reverse movement (all theory, no code yet), however, it's quite ugly since I'll be getting angle info from me/unit, then rotating the unit to face me, then using the DeployUnit to teleport the unit back one tile.
I was wondering ... I know that the ALL_MOVE uses the "SetRoute" function but unfortunately the function isn't available in any of the BSF's for me to modify the body ... I'd like to make a new function like "SetReverseRoute".
I'm thinking it would be easier to tweak the SetRoute ... Can you post the FUNCTION SetRoute() please?
Thanks in advance. No problem if you can't provide the function info. I can use smoke and mirrors.
Merr
-
pipfromslitherine
- Site Admin

- Posts: 9937
- Joined: Wed Mar 23, 2005 10:35 pm
SetRoute is an intrinsic function which uses the internal routefinding. The issue with real reversing would be that you would need to tell the unit to face the 'wrong' way when moving.
You could perhaps hack it using the frontangle attrib, but you'd run into problems when the unit stopped when reversing etc.
I think it might need some code to make it work cleanly.
Cheers
Pip
You could perhaps hack it using the frontangle attrib, but you'd run into problems when the unit stopped when reversing etc.
I think it might need some code to make it work cleanly.
Cheers
Pip
Pip,
I wrote a little script for the Human Player to reverse one tile, costing 2x AP.
Now, before I post that, I noticed in the SQUADDEFs the term "FireDirectionOffset" ... you know, when the Archer fires it rotates the archer 180 degrees (facing rear) then fires. I'm thinking if you use the same idea towards a real reverse then before the unit moves it will rotate the unit to face rear, then perform the "SetRoute".
Anyway, if anyone wants to try out this reverse move, I'll expalin how to add it to your scenario ...
HOW TO : adding the Reverse Move Action to your scenario.
1. Add this line to your text1 file ;
2. Open NotePad++, create a new file, copy/paste the reverse code below(at bottom of post). Save the new BSF as Reverse.BSF, in your Battle/Scripts folder.
3. Open the $DEFAULT.BSF (in your Battle/Scripts folder) ... add this line to include the new bsf ;
HOW TO : reverse your unit.
1. Turn your unit so that the "rear" of the unit faces the tile you want to reverse into.
2. Move your cursor to the tile behind the vehicle, you'll see the new "reverse" action (shown as the "select" action since I have no new button made).
3. Click the reverse button ... viola! The unit will backup and it will be fired on (set for reaction), like a regular move.
REVERSE CODE ;
I wrote a little script for the Human Player to reverse one tile, costing 2x AP.
Now, before I post that, I noticed in the SQUADDEFs the term "FireDirectionOffset" ... you know, when the Archer fires it rotates the archer 180 degrees (facing rear) then fires. I'm thinking if you use the same idea towards a real reverse then before the unit moves it will rotate the unit to face rear, then perform the "SetRoute".
Anyway, if anyone wants to try out this reverse move, I'll expalin how to add it to your scenario ...
HOW TO : adding the Reverse Move Action to your scenario.
1. Add this line to your text1 file ;
Code: Select all
IDS_TT_REVERSEUNIT, "Reverse",3. Open the $DEFAULT.BSF (in your Battle/Scripts folder) ... add this line to include the new bsf ;
Code: Select all
include "reverse.bsf"1. Turn your unit so that the "rear" of the unit faces the tile you want to reverse into.
2. Move your cursor to the tile behind the vehicle, you'll see the new "reverse" action (shown as the "select" action since I have no new button made).
3. Click the reverse button ... viola! The unit will backup and it will be fired on (set for reaction), like a regular move.
REVERSE CODE ;
Code: Select all
// basic reverse functionality
FUNCTION ALL_REVERSE(me, tilex, tiley)
{
int ap ;
UnitDeploy(me, tilex, tiley) ;
AddVizFunctionCall("PlaySFX",tilex, tiley, 16) ;
ap = GetAttrib (me, "AP") ;
// mark unit as moved
SetAttrib (me, "moved", 1) ;
// flag us to show we are not sneaking
SetUnitIconMask(me, 32) ;
// reduce AP (double movecost)
ap -= GetTileCost(me, tilex, tiley) * 2 ;
SetAttrib (me, "AP", ap) ;
SetUnitForReaction(me) ;
}
FUNCTION DEPLOYCHECK_ALL_REVERSE(me, unit, tilex, tiley)
{
int ret ;
ret = 0 ;
return ret ;
}
FUNCTION CHECK_ALL_REVERSE(me, unit, tilex, tiley)
{
int ret ;
int dx ;
int dy ;
int rear ;
int apr ;
int b ;
ret = -2 ;
rear = GetAngleFromTile(tilex, tiley, me) ;
apr = GetTileCost(me, tilex, tiley) * 2 ;
if ( (IsUnitSquadType(me, "infantry") != 1 ) && (IsUnitSquadType(me, "artillery") != 1 ) && ( GetAttrib(me, "AP") >= apr ) && ( rear >= 179 ) )
{
dx = GetUnitX(me) - tilex ;
dy = GetUnitY(me) - tiley ;
if( (dx >= -1) && ( dy >= -1 ) && ( dx <=1 ) && (dy<=1) )
{
b = GetUnitOnTile (tilex, tiley) ;
if ( b == -1 )
{
// if tile is empty
ret = 0 ;
}
else
{
ret = -2 ;
}
}
}
return ret ;
}
FUNCTION UISETUP_ALL_REVERSE()
{
StartString() ;
PrintString("IDS_TT_REVERSEUNIT") ;
SetUITooltip() ;
SetUITexture("action_select", "ffffffff") ;
}
FUNCTION UIBUTTON_ALL_REVERSE(me, x,y,width, height, tilex, tiley)
{
}
-
junk2drive
- BA Moderator

- Posts: 1478
- Joined: Sun May 23, 2010 4:47 pm
- Location: Arizona USA -7GMT
-
IainMcNeil
- Site Admin

- Posts: 13558
- Joined: Fri Apr 01, 2005 10:19 am
Hi guys
nice work. I think you'll find that if you do this it only visually changes the rotation so it looks like it is reversing but the stats think the armour is the rear armour facing forwards. I'll let Phil check as its internal to teh code and we can't see how that bit works. If this is true you could overcomeit by a flag set in the units data while it is reversing, then in the fire code check if this is set, and swap the front & rear armour values. It's pretty messy to be honest but might just work!
Cheers
Iain
nice work. I think you'll find that if you do this it only visually changes the rotation so it looks like it is reversing but the stats think the armour is the rear armour facing forwards. I'll let Phil check as its internal to teh code and we can't see how that bit works. If this is true you could overcomeit by a flag set in the units data while it is reversing, then in the fire code check if this is set, and swap the front & rear armour values. It's pretty messy to be honest but might just work!
Cheers
Iain
Ian,iainmcneil wrote:Hi guys
nice work. I think you'll find that if you do this it only visually changes the rotation so it looks like it is reversing but the stats think the armour is the rear armour facing forwards. I'll let Phil check as its internal to teh code and we can't see how that bit works. If this is true you could overcomeit by a flag set in the units data while it is reversing, then in the fire code check if this is set, and swap the front & rear armour values. It's pretty messy to be honest but might just work!
Cheers
Iain
I assume you're talking about the "FireDirectionOffset" which I only commented on, and it's not in the code above. All the internal code limits what modders can do and that's ok. For now, smoke and mirrors with the "UnitDeploy" doesn't hurt too much, although it makes it difficult for the AI to use it.
I think (eventually) some kind of "move offset" code would help because we all know helicopter's aren't limited to moving in the direction they're facing. By then, a Modern Module would have all the neat code available for tweaking!
Thanks for looking into the matter.
Rob
Looks good junk, nice button.junk2drive wrote:How is this?
You know, if you're up for more tweaks, look at the code in the MoraleTools.BSF, under the FUNCTION RetreatToCover .... it's dormant code, looks like this below ;
// face back teh way you came so you do not present your rear
Code: Select all
// AddVizUnitTurnToFace(me, GetAttrib (me, "LastX"), GetAttrib (me, "LastY")) ;
// if(GetUnitTurret(me) == 1)
// {
// // turn the turret to face the target as well.
// AddVizUnitTurnToFire(me, GetAttrib (me, "LastX"), GetAttrib (me, "LastY")) ;
// }Merr
-
junk2drive
- BA Moderator

- Posts: 1478
- Joined: Sun May 23, 2010 4:47 pm
- Location: Arizona USA -7GMT
-
pipfromslitherine
- Site Admin

- Posts: 9937
- Joined: Wed Mar 23, 2005 10:35 pm
-
junk2drive
- BA Moderator

- Posts: 1478
- Joined: Sun May 23, 2010 4:47 pm
- Location: Arizona USA -7GMT
Yes, it would be, but it appears all that code is "internal", hence my posts about the SetRoute and FireDirectionOffset.junk2drive wrote: It would be much more believable to have the unit actually move back. Right click the unit, right click the reverse button over the target hex, the unit turns its front opposite the target hex and moves backwards.
I'm just a noob, but it looks like they would have to take the SetRoute function and create a new one called "SetReverseRoute" with code that does what you suggested above. This way, you can back-up along a visible route and all the other code will do it's work when setting for reaction, rotating, etc. Picture a normal move but in reverse
With all that said and done, I don't want them to stop there ... I think for a Modern era module later down the road they would definately need some code that allows units to move irregardless of facing, ie Helictopters. So, it's something I would expect next year or later if/when there is a BA2 or BA3 ... maybe by then we would have hexes too
-
junk2drive
- BA Moderator

- Posts: 1478
- Joined: Sun May 23, 2010 4:47 pm
- Location: Arizona USA -7GMT
No sir, the AI is unable to use it. The AI scripts all need to be changed to make the AI understand and use it properly, that's a big task for me. I'd rather keep it as a human action because someone might create a MP scenario and want to add this to their scenario.junk2drive wrote:I have to remind myself of the simple rule of changing a game, can the AI make use of it?
I wish I could make a true reverse but it opens a whole new can-of-worms and code changes that could take 300 years for me to do.
-
junk2drive
- BA Moderator

- Posts: 1478
- Joined: Sun May 23, 2010 4:47 pm
- Location: Arizona USA -7GMT
-
PirateJock_Wargamer
- Staff Sergeant - Kavallerie

- Posts: 325
- Joined: Fri Apr 17, 2009 9:21 pm
- Location: North West, UK
- Contact:
-
junk2drive
- BA Moderator

- Posts: 1478
- Joined: Sun May 23, 2010 4:47 pm
- Location: Arizona USA -7GMT
Junk,
Thanks for the show off .... You know, I need to update the script above. The script that Junk is using is an updated version.
I had to add a conditional for deployment mode because you can "reverse" move while deploying and that opened up the LOS range which allowed you to inch your way around the map in areas you weren't suppose to deploy in!
Thanks for the show off .... You know, I need to update the script above. The script that Junk is using is an updated version.
I had to add a conditional for deployment mode because you can "reverse" move while deploying and that opened up the LOS range which allowed you to inch your way around the map in areas you weren't suppose to deploy in!
-
junk2drive
- BA Moderator

- Posts: 1478
- Joined: Sun May 23, 2010 4:47 pm
- Location: Arizona USA -7GMT




