Page 1 of 1

Reverse Movement ... 1 Tile Move

Posted: Sun Oct 17, 2010 8:49 pm
by Merr
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

Posted: Sun Oct 17, 2010 9:17 pm
by pipfromslitherine
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

Posted: Tue Oct 26, 2010 3:52 pm
by Merr
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 ;

Code: Select all

IDS_TT_REVERSEUNIT, "Reverse",
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 ;

Code: Select all

include "reverse.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 ;

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)
{
}

Posted: Wed Oct 27, 2010 12:52 am
by junk2drive
How is this?

oops hang on

Image

Posted: Wed Oct 27, 2010 8:23 am
by IainMcNeil
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

Posted: Thu Oct 28, 2010 5:50 am
by Merr
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
Ian,

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

Posted: Thu Oct 28, 2010 5:55 am
by Merr
junk2drive wrote:How is this?
Looks good junk, nice button.

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")) ;
//				}
That code appears to "spin" the unit back to face the tile it just left ... might prove usefull if you hate seeing units face their butt at the enemy after a retreat.

Merr

Posted: Thu Oct 28, 2010 12:48 pm
by junk2drive
Maybe Iain or Pip will chime in but I'll bet that was // out when they found that it was just a visual and didn't change the armour rating, thereby confusing the player.

Posted: Thu Oct 28, 2010 3:34 pm
by pipfromslitherine
No - if you turn the unit, then it would work correctly. My guess is that it looked wierd, esp for infantry, and just slowed down the whole process of retreats etc. Iain wrote that specific bit, so he can more correctly explain his thinking :)

Cheers

Pip

Posted: Fri Oct 29, 2010 1:46 am
by junk2drive
Rob for the ammo truck we originally had turn to face the unit.

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.

Posted: Sat Oct 30, 2010 5:46 pm
by Merr
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.
Yes, it would be, but it appears all that code is "internal", hence my posts about the SetRoute and FireDirectionOffset.

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 :wink: .

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 :D .

Posted: Sat Oct 30, 2010 6:16 pm
by junk2drive
I have to remind myself of the simple rule of changing a game, can the AI make use of it?

Reversing action is not a big deal at this point but I see what you are saying with helicopters and other units.

Posted: Sat Oct 30, 2010 8:23 pm
by Merr
junk2drive wrote:I have to remind myself of the simple rule of changing a game, can the AI make use of it?
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.

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.

Posted: Sat Dec 18, 2010 7:55 pm
by junk2drive
Teasers

Should I move one more square? Only 8 AP left. Wait till next turn.

Image

OOPS

Image

Well now

Image

Whew! One more and I'll be out of range.

Image

Posted: Sat Dec 18, 2010 10:55 pm
by PirateJock_Wargamer
Show off :lol:

So how are you doing it? Is it Merr's script?

Cheers

Posted: Sun Dec 19, 2010 12:02 am
by junk2drive
"one" of Merr's scripts.

Posted: Sun Dec 19, 2010 6:58 am
by Merr
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!

Posted: Sun Dec 19, 2010 7:10 am
by junk2drive
I'm just showing off my button :wink: