Retreat To Cover ... Reverse!

Modders can post their questions on scripting and more.

Moderators: Slitherine Core, BA Moderators

Post Reply
Merr
Captain - Heavy Cruiser
Captain - Heavy Cruiser
Posts: 903
Joined: Mon Aug 16, 2010 2:00 pm

Retreat To Cover ... Reverse!

Post by Merr »

When Reverse came out I jumped all over this ...

Inside the MoraleTools, in the body of FUNCTION RetreatToCover, I made a quick change that does the following ...

:arrow: When an Armored Unit retreats, and the "best" retreat tile is more than 130 degrees from the unit's facing it will "Reverse To Cover".
:arrow: I didn't change anything to help determine the "best" tile ... but this works nicely. 8)

Note ... you must add in the declaration of int mult ;

Original Code

Code: Select all

				//Log("Ret", GetUnitX(me), GetUnitY(me), bestX, bestY) ;
				
				AddVizFunctionCall("SetRoute", me, bestX, bestY, 0 ) ;		
				
				//Log ("Retreat from x1, y1 to x2, y2", GetAttrib (me, "LastX"), GetAttrib (me, "LastY"), GetUnitX(me), GetUnitY(me)) ;				

Change To Read

Code: Select all

				//Log("Ret", GetUnitX(me), GetUnitY(me), bestX, bestY) ;

				if ( GetAttrib(me, "ArmourType") != 1 )
				{
					AddVizFunctionCall("SetRoute", me, bestX, bestY, 0 ) ;
				}
				else
				{
					mult = GetAngleFromTile(bestX, bestY, me) ;
					
					if( mult > 130 )
					{
						AddVizFunctionCall("SetRouteReverse", me, bestX, bestY, 0 ) ;
					}
					else
					{
						AddVizFunctionCall("SetRoute", me, bestX, bestY, 0 ) ;
					}
				}
				
				//Log ("Retreat from x1, y1 to x2, y2", GetAttrib (me, "LastX"), GetAttrib (me, "LastY"), GetUnitX(me), GetUnitY(me)) ;				
pipfromslitherine
Site Admin
Site Admin
Posts: 9937
Joined: Wed Mar 23, 2005 10:35 pm

Post by pipfromslitherine »

Nice. Something that we missed for sure. Not sure we can get it in for the next update, but we'll definitely get it added in.

Cheers

Pip
Merr
Captain - Heavy Cruiser
Captain - Heavy Cruiser
Posts: 903
Joined: Mon Aug 16, 2010 2:00 pm

Post by Merr »

Pip,

My thoughts on why it was missing ... You weren't in the neighborhood :)

If/when you add something, can you accidently be in the neighborhood of the AI.bsf :wink:
It could use some "reverse" logic, pun intended.

Thanks for your work!
IainMcNeil
Site Admin
Site Admin
Posts: 13558
Joined: Fri Apr 01, 2005 10:19 am

Post by IainMcNeil »

Just tried it - had a crash first time as I had to delcare teh mult variable but after that it seems to work :)
Merr
Captain - Heavy Cruiser
Captain - Heavy Cruiser
Posts: 903
Joined: Mon Aug 16, 2010 2:00 pm

Post by Merr »

iainmcneil wrote:Just tried it - had a crash first time as I had to delcare teh mult variable but after that it seems to work :)
Ian,

Thanks for trying it!

You guys definately need to delv' this more ... I noticed that the 130 degrees doesn't always work ... especially if the threat is adjacent!

For example .... If the tank is facing EAST, and an infantry unit is adjacent one tile NORTHEAST, if the tank retreats and the BestX/Y is SOUTH (90 degrees) it will retreat forward :cry: .

So, the if (in this case) needs to be mult > 85 ... Now, in my case above, the BestX/Y could have been WEST (which was an available tile), and the 130 would have worked, so you guys might need to re-write the Threat logic since it appears it selected the first available tile instead of a logical tile.

Of course, when it comes to retreating, a logical tile has many conditions and considering ALL of those would take forever to script!

Anyway, try 85 ... it solves the "adjacent" problem and it may help all around!
Post Reply

Return to “Battle Academy : Modders Corner ”