Swaping units

Modders can post their questions on scripting and more.

Moderators: Slitherine Core, BA Moderators

rf900
Staff Sergeant - Kavallerie
Staff Sergeant - Kavallerie
Posts: 339
Joined: Fri May 04, 2012 6:59 am

Swaping units

Post by rf900 »

From a post in the other forum I am looking at the ability to swap positions for friendly units. Mainly to avoid blocking for thin passages.

There is a function that will make it very simple, but I am afraid that the AI will not have a reaction fire to that movement and it can be abused by the player. Am I right?

Ok, did the simple ugly version of swap. It works but there is no animation, the AI gets reaction fire to one of them.
Attachments
Swap and Merge.zip
Swap and Merge
(10.47 KiB) Downloaded 135 times
Last edited by rf900 on Thu Aug 02, 2012 9:50 am, edited 6 times in total.
GottaLove88s
Lieutenant-General - Do 217E
Lieutenant-General - Do 217E
Posts: 3151
Joined: Fri Apr 06, 2012 6:18 pm
Location: Palau

Re: Swaping units

Post by GottaLove88s »

If UnitDeploy is the same code that drops things from transports, it doesn't seem to prevent reaction fire. I dropped an AT gun into a house in Winter Village a couple of days ago. My opponent had vision on that house from an adjacent scout that had moved away one square (but kept the vision for that turn). A Panther a few squares away fired in reaction to the deploy and killed the AT immediately. You're doing wonderful things RF. Thanks man!
SCENARIO LINKS
Seelow'45 -> www.slitherine.com/forum/viewtopic.php?f=313&t=55132
Normandy'44 -> www.slitherine.com/forum/viewtopic.php?f=87&t=42094
Dieppe'42 -> www.slitherine.com/forum/viewtopic.php?f=87&t=42347
rf900
Staff Sergeant - Kavallerie
Staff Sergeant - Kavallerie
Posts: 339
Joined: Fri May 04, 2012 6:59 am

Re: Swaping units

Post by rf900 »

UnitDeploy is probably only used in deploy phase, there is another action that unloads from truck. I will need to find a way to move a unit to an occupied tile or somehow temporarily unoccupy that tile.

Still you gave me an idea, I can hack the load function one unit will get "inside/load" the other and then the other will get "outside/unload" to the tile the previous one was in. The AI will only be able to fire on the second movement only, but it may be fair enough.
pipfromslitherine
Site Admin
Site Admin
Posts: 9937
Joined: Wed Mar 23, 2005 10:35 pm

Re: Swaping units

Post by pipfromslitherine »

I think you can tell the system to react to a movement using SetUnitForReaction - although you can only react to one unit at a given time, so you would need to choose one. Perhaps the unit selected?

Cheers

Pip
rf900
Staff Sergeant - Kavallerie
Staff Sergeant - Kavallerie
Posts: 339
Joined: Fri May 04, 2012 6:59 am

Re: Swaping units

Post by rf900 »

Did a first version, not happy with it though. It works but there is no animation and I need to test more because I don't know if the AI gets a reaction fire to the swapping.
rf900
Staff Sergeant - Kavallerie
Staff Sergeant - Kavallerie
Posts: 339
Joined: Fri May 04, 2012 6:59 am

Re: Swaping units

Post by rf900 »

Update, the AI gets reaction fire to one of the units swapping.
GottaLove88s
Lieutenant-General - Do 217E
Lieutenant-General - Do 217E
Posts: 3151
Joined: Fri Apr 06, 2012 6:18 pm
Location: Palau

Re: Swaping units

Post by GottaLove88s »

Wounded Infantry "Merge" and Unit Position "Swap" are now both active in the latest Fast & Sneaky scenario... thanks again RF... nice job!
viewtopic.php?f=87&t=36065
SCENARIO LINKS
Seelow'45 -> www.slitherine.com/forum/viewtopic.php?f=313&t=55132
Normandy'44 -> www.slitherine.com/forum/viewtopic.php?f=87&t=42094
Dieppe'42 -> www.slitherine.com/forum/viewtopic.php?f=87&t=42347
pk867
Sr. Colonel - Battleship
Sr. Colonel - Battleship
Posts: 1602
Joined: Fri May 08, 2009 3:18 pm

Re: Swaping units

Post by pk867 »

Will this function be added to the next update to the regular game? Will beta testing be needed to test for balance. Can the AI use these functions?
pipfromslitherine
Site Admin
Site Admin
Posts: 9937
Joined: Wed Mar 23, 2005 10:35 pm

Re: Swaping units

Post by pipfromslitherine »

If the authors give permission I would love to use them in the next update. The commands are on my task list anyway.

Not sure about AI use - but it is possible.

Cheers

Pip
GottaLove88s
Lieutenant-General - Do 217E
Lieutenant-General - Do 217E
Posts: 3151
Joined: Fri Apr 06, 2012 6:18 pm
Location: Palau

Re: Swaping units

Post by GottaLove88s »

Hi RF, We've been using "swap" in game. It's great code which works well. Thanks again.

There's one small hitch that can happen when an infantry unit (in forest) swaps with a vehicle.
The code doesn't test if the vehicle is allowed to move into the forest square (see screenshot).
SwapInTrees.jpg
SwapInTrees.jpg (45.19 KiB) Viewed 3635 times
It would be great trick to hide King Tigers in trees (no, I haven't tried it yet, but somebody's bound to sooner or later).

Solutions:
1. Easy - Limit swap function to only infantry, mortars, artillery, etc
2. Harder - Test whether the swapper and the swappee are both permitted to be in their destination squares before showing the action icon

Will let you know if we find more...
SCENARIO LINKS
Seelow'45 -> www.slitherine.com/forum/viewtopic.php?f=313&t=55132
Normandy'44 -> www.slitherine.com/forum/viewtopic.php?f=87&t=42094
Dieppe'42 -> www.slitherine.com/forum/viewtopic.php?f=87&t=42347
rf900
Staff Sergeant - Kavallerie
Staff Sergeant - Kavallerie
Posts: 339
Joined: Fri May 04, 2012 6:59 am

Re: Swaping units

Post by rf900 »

Ha ha, I am so bad at testing. should be an easy check to see if the target tile is valid for each unit, I think there is a specific funtion for that. Thanks
pk867
Sr. Colonel - Battleship
Sr. Colonel - Battleship
Posts: 1602
Joined: Fri May 08, 2009 3:18 pm

Re: Swaping units

Post by pk867 »

Hi
I believe you should be able to swap INF on adjacent tile to the contents of the transporting vehicle. So New troops on the vehicle unlod and the troops load onto the truck to escape or move. Or unload the AT or machine gun team to the hex and load up the other item. So if the swap is using the transport to start with then this type of swap occurs otherwise if the unit adjacent to the transport unit initiates the swap it cannot. Makes sense?
GottaLove88s
Lieutenant-General - Do 217E
Lieutenant-General - Do 217E
Posts: 3151
Joined: Fri Apr 06, 2012 6:18 pm
Location: Palau

Re: Swaping units

Post by GottaLove88s »

Interesting idea, thanks PK. That's more ambitious than we were originally intending. I guess we wanted to swap the primary units, for example swapping an infantry with a transport in the open, and leave the transport's contents, perhaps an AT gun, alone. I'm sure RF could code it to give us an extra icon/command... unload/load transport and swap, swap, or turn to face, but I'm happy to play this as three moves, (1) unload, then (2) swap, then (3) load the other unit, if the combination move feels complex (in gameplay or coding).
SCENARIO LINKS
Seelow'45 -> www.slitherine.com/forum/viewtopic.php?f=313&t=55132
Normandy'44 -> www.slitherine.com/forum/viewtopic.php?f=87&t=42094
Dieppe'42 -> www.slitherine.com/forum/viewtopic.php?f=87&t=42347
GottaLove88s
Lieutenant-General - Do 217E
Lieutenant-General - Do 217E
Posts: 3151
Joined: Fri Apr 06, 2012 6:18 pm
Location: Palau

Re: Swaping units

Post by GottaLove88s »

But you raise another interesting point PK, that I hadn't realised or tried yet. RF, does your swap.bsf code check that that it shouldn't permit a swap position between eg. artillery and other units? Or have you just invented a new way of moving a fixed AT gun one space? Should we keep this option or prevent it? Theoretically, if you've got an infantry or an armoured vehicle next door to an AT gun, real world, it's likely possible for this unit to shift the gun one space, right? I'd like to keep this. :-) It's not particularly efficient, but it's effective in emergencies... and rewards players who keep an infantry near to their AT gun...
SCENARIO LINKS
Seelow'45 -> www.slitherine.com/forum/viewtopic.php?f=313&t=55132
Normandy'44 -> www.slitherine.com/forum/viewtopic.php?f=87&t=42094
Dieppe'42 -> www.slitherine.com/forum/viewtopic.php?f=87&t=42347
GottaLove88s
Lieutenant-General - Do 217E
Lieutenant-General - Do 217E
Posts: 3151
Joined: Fri Apr 06, 2012 6:18 pm
Location: Palau

Re: Swaping units

Post by GottaLove88s »

PS. Thanks RF, Don't be modest man. You write awesome code! :-) Did you find a way to prevent swaps putting units into invalid terrain?
SCENARIO LINKS
Seelow'45 -> www.slitherine.com/forum/viewtopic.php?f=313&t=55132
Normandy'44 -> www.slitherine.com/forum/viewtopic.php?f=87&t=42094
Dieppe'42 -> www.slitherine.com/forum/viewtopic.php?f=87&t=42347
rf900
Staff Sergeant - Kavallerie
Staff Sergeant - Kavallerie
Posts: 339
Joined: Fri May 04, 2012 6:59 am

Re: Swaping units

Post by rf900 »

Good catch, I would need to do another check that the unit is not of type artillery, should be easy. Hope to get some time tomorrow to code it.
GottaLove88s
Lieutenant-General - Do 217E
Lieutenant-General - Do 217E
Posts: 3151
Joined: Fri Apr 06, 2012 6:18 pm
Location: Palau

Re: Swaping units

Post by GottaLove88s »

Hey RF, 1. Please do add the check to see if a swap would put a vehicle into forest or rough ground, before offering the swap action icon, but 2. Please DON'T prevent artillery from swapping. Having discovered this accidentally, I really like using your "swap" as a clever way to move an AT gun unit one square. I don't think it's unrealistic that a neighbouring infantry or vehicle could roll an AT gun one square. (If you prefer to prevent AT gun swaps, let me know which lines of code to remove :-))
SCENARIO LINKS
Seelow'45 -> www.slitherine.com/forum/viewtopic.php?f=313&t=55132
Normandy'44 -> www.slitherine.com/forum/viewtopic.php?f=87&t=42094
Dieppe'42 -> www.slitherine.com/forum/viewtopic.php?f=87&t=42347
rf900
Staff Sergeant - Kavallerie
Staff Sergeant - Kavallerie
Posts: 339
Joined: Fri May 04, 2012 6:59 am

Re: Swaping units

Post by rf900 »

Bit harder than I thought. For artillery I will let it move but make it loose all the AP so it cannot fire after swapping, if it fires it may not be able to swap like other units as it needs some spare APs.

Can someone help me to check if a tile is valid for a vehicle? Check it it is a forest/house for example, basically any unpassable/notvalid terrain for vehicles. Notice that the tile will be occupied by a friendly unit when doing the check.

I was looking at GetTileCost, seems the one to be used by moving checks, does it return a very high value when checking a tank for a tile that is a house for example?

Will test this afternoon if this works, if so I will upload an update.
GottaLove88s
Lieutenant-General - Do 217E
Lieutenant-General - Do 217E
Posts: 3151
Joined: Fri Apr 06, 2012 6:18 pm
Location: Palau

Re: Swaping units

Post by GottaLove88s »

Hi RF, I believe you're on the right track with the GetTileCost function. The core Terrain.txt illustrates how many free AP each unit type requires to enter any particular terrain. Slith seem to have coded an AP cost of 100 for impassable terrain. I've attached Open Ground, Rough Ground, Building and Forest below to give you an idea. If GetTileCost for a unit is > remaining AP (or = 100), the move should be invalid. Thanks for looking into this. It's a really useful extra function you've created. GL88

[OpenGround]
INFANTRY 4
TRACKED 4
HALFTRACK 4
ARTILLERY 4
WHEELED 4
BOAT 100
AMPHIBIOUS 4
COVERFLAGS 0 // can infantry hide in this terrain
COVERVALUE0 40 // % damage inflicted if target is stationary
COVERVALUE1 100 // % damage inflicted if target is moving
COVERVALUE2 10 // % chance of getting bogged down when starting turn in this terrain * % chance of bogging so this /5 /10 is about the right amount.
COVERVALUE3 0 // is this a fortification?

[RoughGround]
INFANTRY 4
TRACKED 100
HALFTRACK 100
ARTILLERY 8
WHEELED 100
BOAT 100
AMPHIBIOUS 100
COVERFLAGS 1 // can infantry hide in this terrain
COVERVALUE0 30 // % damage inflicted if target is stationary
COVERVALUE1 75 // % damage inflicted if target is moving
COVERVALUE2 30 // % chance of getting bogged down when starting turn in this terrain * % chance of bogging so this /5 /10 is about the right amount.
COVERVALUE3 0 // is this a fortification?

[Building]
INFANTRY 4
TRACKED 100
HALFTRACK 100
ARTILLERY 4
WHEELED 100
BOAT 100
AMPHIBIOUS 100
COVERFLAGS 1 // can infantry hide in this terrain
COVERVALUE0 25 // % damage inflicted if target is stationary
COVERVALUE1 50 // % damage inflicted if target is moving
COVERVALUE2 50 // % chance of getting bogged down when starting turn in this terrain * % chance of bogging so this /5 /10 is about the right amount.
COVERVALUE3 0 // is this a fortification?

[Forest]
INFANTRY 4
TRACKED 100
HALFTRACK 100
ARTILLERY 8
WHEELED 100
BOAT 100
AMPHIBIOUS 100
COVERFLAGS 1 // can infantry hide in this terrain
COVERVALUE0 30 // % damage inflicted if target is stationary
COVERVALUE1 60 // % damage inflicted if target is moving
COVERVALUE2 30 // % chance of getting bogged down when starting turn in this terrain * % chance of bogging so this /5 /10 is about the right amount.
COVERVALUE3 0 // is this a fortification?
SCENARIO LINKS
Seelow'45 -> www.slitherine.com/forum/viewtopic.php?f=313&t=55132
Normandy'44 -> www.slitherine.com/forum/viewtopic.php?f=87&t=42094
Dieppe'42 -> www.slitherine.com/forum/viewtopic.php?f=87&t=42347
rf900
Staff Sergeant - Kavallerie
Staff Sergeant - Kavallerie
Posts: 339
Joined: Fri May 04, 2012 6:59 am

Re: Swaping units

Post by rf900 »

Looks good, thanks. Will test it this afternoon hopefully and upload if it works.
Post Reply

Return to “Battle Academy : Modders Corner ”