DeployUnit to Random better Cover
Moderators: Slitherine Core, BA Moderators
DeployUnit to Random better Cover
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!
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!
-
pipfromslitherine
- Site Admin

- Posts: 9928
- Joined: Wed Mar 23, 2005 10:35 pm
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!
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) ;
}
}
}
}
}
}
-
pipfromslitherine
- Site Admin

- Posts: 9928
- Joined: Wed Mar 23, 2005 10:35 pm
Good idea about the logging part. I haven't fooled with it since so I'll go back and mess around.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.
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.
-
pipfromslitherine
- Site Admin

- Posts: 9928
- Joined: Wed Mar 23, 2005 10:35 pm
Ok ... I'll do that, thank you. It might take me a few days to run through it.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.
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.
Yes sir .... I'm wrapping up my new scenario called .... Rescue the Prisoner (downed British pilot).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?
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.
-
pipfromslitherine
- Site Admin

- Posts: 9928
- Joined: Wed Mar 23, 2005 10:35 pm
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.Merr wrote:Ok ... I'll do that, thank you. It might take me a few days to run through it.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.
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.
Cheers
Pip
-
PirateJock_Wargamer
- Staff Sergeant - Kavallerie

- Posts: 325
- Joined: Fri Apr 17, 2009 9:21 pm
- Location: North West, UK
- Contact:
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?
changed to
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?
1 - What group of units is it checking through - can you get the i value from debugging?
Code: Select all
for(i=0;i<GetUnitCount(0);i++)2 - Would brackets around first condition help - code getting confused?
Code: Select all
if( GetTileCost(id, x, y) <= GetBaseAttrib(id, "AP") && cover == 63)Code: Select all
if( (GetTileCost(id, x, y) <= GetBaseAttrib(id, "AP")) && cover == 63)

