Page 1 of 1
DeployUnit to Random better Cover
Posted: Sat Sep 18, 2010 4:29 pm
by Merr
Pip,
To follow up on your random deploy code from other thread ... I've got a question about the code.
I need to :
a. Have the unit randomly deploy to a better cover value, ie a building.
b. Loop it so it ensures the unit will deploy to the new tile with better cover.
If you have a moment, what's the best way to code this?
I've seen examples in other files, ie moving to cover, but getting it correctly with deployunit has me puzzled.
Thanks!
Posted: Sat Sep 18, 2010 4:53 pm
by pipfromslitherine
You'd just need to add a loop to check over the area for the best cover, rather than just choose a random x.y. The function CalculateRetreatPath in data\scripts\moraletools.bsf does something similar to it, so that would be a good starting point.
Cheers
Pip
Posted: Sun Sep 19, 2010 8:19 am
by Merr
Pip,
I spent several hours trying different code but to no avail.
I'm going to post some code (from memory, at work) so tell me if I'm in the right ballpark ... or at least on the same planet.
BTW, it doesn't work, but it's a start (I think).
Thanks!
Code: Select all
FUNCTION StartTurn(side)
{
int i ;
int id ;
int x ;
int y ;
int cover ;
if( GetTurn() == 0 )
{
for(i=0;i<GetUnitCount(0);i++)
{
id = GetUnitID(0, i) ;
for(x=GetUnitX(id) - 3 ; x<GetUnitX(id) + 3 ; x++)
{
for(y=GetUnitY(id) -3 ; y<GetUnitY(id) + 3 ; y++)
{
cover = GetTerrainCoverValue(x, y, 1) ;
if( GetTileCost(id, x, y) <= GetBaseAttrib(id, "AP") && cover == 63)
{
UnitDeploy(id, x, y) ;
}
}
}
}
}
}
Posted: Wed Sep 22, 2010 3:16 pm
by pipfromslitherine
It looks pretty valid, if it doesn't work then I would imagine it's the cover == 63 part?
I would add some logging in to let you know how it is scoring the various cover tiles.
Cheers
Pip
Posted: Wed Sep 22, 2010 11:45 pm
by Merr
pipfromslitherine wrote:It looks pretty valid, if it doesn't work then I would imagine it's the cover == 63 part?
I would add some logging in to let you know how it is scoring the various cover tiles.
Good idea about the logging part. I haven't fooled with it since so I'll go back and mess around.
I'm glad PirateJock already asked the question about the logs, that would have been my next question.
BTW, Since I can't check the code above right now, I know that variations of that code does cause it to loop indefinately... ie, the game hangs on turn 0. So, I might need a few breaks in the loop (will have to check). Off hand, would "id = -1" or "cover = 0" be a good breaker?
Thanks for your time.
Posted: Wed Sep 22, 2010 11:55 pm
by pipfromslitherine
If you find any code like that which ends up looping indefinitely, then please zip up the map and script and let me have it so we can check out what is going on. At that point none of the units in the side should be missing.
Cheers
Pip
Posted: Thu Sep 23, 2010 1:19 am
by Merr
pipfromslitherine wrote:If you find any code like that which ends up looping indefinitely, then please zip up the map and script and let me have it so we can check out what is going on. At that point none of the units in the side should be missing.
Ok ... I'll do that, thank you. It might take me a few days to run through it.
Are you telling me that "loops" won't log? Normally I have to crtl-alt-del my way back to DT, since BA isn't "responding". I could always look at the error log and see what gives. I'm assuming loops at that point.
I'll use the template scenario for my testing and PM you a link if it hangs.
Posted: Thu Sep 23, 2010 1:28 am
by LOGAN5
hey Merr what are you working on anyway? some kind of MEGA mod ? heh i saw something about minefields and snipers, something big must be in the works huh?
Posted: Thu Sep 23, 2010 4:18 am
by Merr
LOGAN5 wrote:hey Merr what are you working on anyway? some kind of MEGA mod ? heh i saw something about minefields and snipers, something big must be in the works huh?
Yes sir .... I'm wrapping up my new scenario called .... Rescue the Prisoner (downed British pilot).
It includes minefields, snipers, leaders, and now prisoners.
It's quite a basic scenario ... ; US Rangers must infiltrate enemy lines, get through minefields and past snipers, find the prisoner, capture the prisoner, and carry him back to the command post.
It all works (codewise) ..... I just need to wrap up some DDS's and write some descriptive text. I was hoping to get this done using the new deployment code but it's not required.
I promised Tim1966 the first beta so once he's seen it (I haven't PM'd him yet) I can post the scenario for everyone to try out.
Tim made the minefield and a basic prisoner figure so he needs to see it.
When I'm really close to release (after Tim has had a go), I'll post something with a better ETA.
Posted: Thu Sep 23, 2010 3:43 pm
by pipfromslitherine
Merr wrote:pipfromslitherine wrote:If you find any code like that which ends up looping indefinitely, then please zip up the map and script and let me have it so we can check out what is going on. At that point none of the units in the side should be missing.
Ok ... I'll do that, thank you. It might take me a few days to run through it.
Are you telling me that "loops" won't log? Normally I have to crtl-alt-del my way back to DT, since BA isn't "responding". I could always look at the error log and see what gives. I'm assuming loops at that point.
I'll use the template scenario for my testing and PM you a link if it hangs.
You should see the log output fine, even in loops. I'm just not sure what would cause a hang in that kind of code.
Cheers
Pip
Posted: Thu Sep 23, 2010 3:59 pm
by PirateJock_Wargamer
Thoughts on possible looping/crash ...
1 - What group of units is it checking through - can you get the i value from debugging?
2 - Would brackets around first condition help - code getting confused?
Code: Select all
if( GetTileCost(id, x, y) <= GetBaseAttrib(id, "AP") && cover == 63)
changed to
Code: Select all
if( (GetTileCost(id, x, y) <= GetBaseAttrib(id, "AP")) && cover == 63)
3 - Wondering what's the significance of 63 for cover? Are you sure you'll definitely find a tile to deploy to, i.e. one of the tiles will meet your conditions?