Page 1 of 2
Swaping units
Posted: Wed Jun 20, 2012 6:32 am
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.
Re: Swaping units
Posted: Wed Jun 20, 2012 6:42 am
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!
Re: Swaping units
Posted: Wed Jun 20, 2012 7:28 am
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.
Re: Swaping units
Posted: Wed Jun 20, 2012 5:52 pm
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
Re: Swaping units
Posted: Thu Jun 21, 2012 6:42 am
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.
Re: Swaping units
Posted: Thu Jul 26, 2012 6:41 pm
by rf900
Update, the AI gets reaction fire to one of the units swapping.
Re: Swaping units
Posted: Fri Jul 27, 2012 11:59 am
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
Re: Swaping units
Posted: Fri Jul 27, 2012 1:45 pm
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?
Re: Swaping units
Posted: Fri Jul 27, 2012 3:10 pm
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
Re: Swaping units
Posted: Sat Jul 28, 2012 4:56 am
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 (45.19 KiB) Viewed 3650 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...
Re: Swaping units
Posted: Sat Jul 28, 2012 8:07 am
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
Re: Swaping units
Posted: Sat Jul 28, 2012 11:46 am
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?
Re: Swaping units
Posted: Sun Jul 29, 2012 8:58 am
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).
Re: Swaping units
Posted: Sun Jul 29, 2012 9:05 am
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...
Re: Swaping units
Posted: Sun Jul 29, 2012 9:08 am
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?
Re: Swaping units
Posted: Sun Jul 29, 2012 5:12 pm
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.
Re: Swaping units
Posted: Sun Jul 29, 2012 5:31 pm
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

)
Re: Swaping units
Posted: Mon Jul 30, 2012 8:23 am
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.
Re: Swaping units
Posted: Mon Jul 30, 2012 9:11 am
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?
Re: Swaping units
Posted: Mon Jul 30, 2012 10:12 am
by rf900
Looks good, thanks. Will test it this afternoon hopefully and upload if it works.