Sign in to follow this  

Pathfinding: transporting land units on ships

This topic is 405 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi

Im doing a turn-based, tile-based strategy game (in that sense similar to civilization).

 

I use A* pathfinding. What is the best way to deal with land-units "boarding" transport ships? My idea is to make tile with friendly transport-ships (with free transport slots) mark their tile as a terrain type which both land and sea-units may enter.

 

When switching to the next players turn, the old players ships must mark their tiles as non-walkable for land-units again. Then the new player marks his/hers ship-tiles as walkable. Also when a ship moves it must check the tile it just left if it's still capable of accepting friendly land-units.

 

Good idea? Any better ideas?
Thanks

Erik

Share this post


Link to post
Share on other sites
Sounds a bit fragile to me. Why not have a sea/land tile where the land unit itself checks there is a sea-unit at the tile with space to accept it?
You can cache that information during a turn.

The sea-unit can just visit that special tile as it sees fit without doing anything special.

Share this post


Link to post
Share on other sites

But I need to check all tiles with friendly ships before letting the land-unit do pathfinding, so what's the difference from my solution?

I also dont want to throw in game-specific checks inside the pathfinding itself, that will get messy.

 

Maybe I misunderstand you, but the sea-unit has never a problem in my first solution either.

Share this post


Link to post
Share on other sites

This is sort of a non-answer, but have you thought about changing the gameplay?  Loading units on ships, depending on the game, is usually an incredibly tedious affair.  One way to get around that is to remove the concept of transport ships as playable units.  All land units can take X turns to become a landing craft / transport ship containing the land unit.  This simulates having the land craft come and pick up the unit, but functionally means the player no longer has to fiddle with building enough transports, or ferrying empty transports back and forth between units, and/or dealing with a bunch of empty idle transport ships clogging up the map and the UI.  

Share this post


Link to post
Share on other sites

Your algorithm will fail when the ship is bellow a unit and the unit wants to move upwards by the sea.

 

This doesn't look like a situation that can/should be handled by pathfinding. I think some kind of hierarchical pathfinding that stores connectivity between lands (do we need to use sea transport at all? Will it be more effective to use sea transport here?) and some kind of strategic planning algorithm (sea transports allocation and unit coordination) are needed here. Human player doesn't transport his units over seas in a random fashion. He packs them at some area and then boards them on a ship. He would expect something similar from AI.

Share this post


Link to post
Share on other sites

But I need to check all tiles with friendly ships before letting the land-unit do pathfinding, so what's the difference from my solution?

You change the map all the time. Make one error in it, and a year later a unit may do something weird, and you spend weeks to months of finding where this problem is coming from.

I leave the map untouched, so it can never go bad due to messing up the changes.

I also dont want to throw in game-specific checks inside the pathfinding itself, that will get messy.

It depends on what you think as "pathfinding itself". The pathfinding algorithm needs to ask something for the set of new tiles you can go to. For land units you get an additional test for these sea tiles. While that code is being run as part of path finding, you can easily consider that tile-get routine to be part of the unit that is being moved (since that has the knowledge to decide where it can move to, and how expensive it is).

Share this post


Link to post
Share on other sites
Your algorithm will fail when the ship is bellow a unit and the unit wants to move upwards by the sea.

Why would that fail? The land-unit can not move unto a SEA_TILE. It can only leave the ship like this: from a BOTH_TILE to a LAND_TILE (disembark).

 

Only when a ship moves away from a BOTH_TILE do I need to check the former tile if it should be switched back to a regular SEA_TILE (if no other friendly transports are still there).

 

I already have a system for temporary tiles (used in games where units block units, allowing only one unit per tile). This can be used for transports in games with several units per tile I think.

Edited by suliman

Share this post


Link to post
Share on other sites

This topic is 405 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this