distance between ships

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

User avatar
HackaLittleBit
Director
Director
Posts: 550
Joined: 10 Dec 2008 16:08
Location: tile 0x0000

distance between ships

Post by HackaLittleBit » 09 Apr 2009 00:03

Hello
A new try :)

Improved ship movement.

Reason:

Try to eliminate ships moving through each other as much as possible.

Workings:

Ship looks on new tile and one further to see if there is ship.
If encountered speed is divided by 4.
Only if plain water tiles are available on new tile, and on next tile if new track would be followed, the ship will change course.
The ship will then turn extra 45º from original course.
If there is no space to move out of the way, normal direction is maintained, albeit with reduced speed.
This forces player to choose placing of buoy's and dock's more carefully.
Very large amounts of ships requires more maneuvering space.
In that case it is advised to create route with buoy's for both directions.
If ships encounter each other in narrow channels (1 tile), or there is no space to turn away (coast or end of map etc.), speed will be reduced and they will glide over each other (old behavior).
This is done to avoid loop situation. (Ships endlessly turning in circle)
3 tiles from destination tile (buoy, dock etc.) ships have "normal" behavior.
This is done for game play.

Some time penalty is a result of all these changes so maybe some tinkering in ships earnings/costs is desirable.

If ship is stopped it will not be detected by other ships. (Avoid sabotage)

When ship has TRACK_BIT_WORMHOLE (Aqua ducts) this patch has no effect.

I had nicest results with NPF but YAPF is best option.

Resolved:

This time no desyncs problems.

Bugs:
Not known.
Path finder is not affected by this patch because rectification to direction are made after the pathfinder is called.
(I may be wrong here so please correct me if so.)

At this moment the new behavior is active when 90º turns are forbidden for trains and ships.
(See _settings_game.pf.forbid_90_deg line in patch)
You can change it in advanced settings, vehicles, routing, Forbid trains and ships to make 90º turns.

Please have fun and report any problems.

Regards

P.S. Wouldn't it be nice to earn some money with ships ;)

EDIT: This post was edited to improve story.
and will be the place to find most up to date patch


Regards HackaLittleBit
Attachments
harbor.png
harbor.png (74.35 KiB) Viewed 8886 times
ships_movement_24115_v5.patch
(2.15 KiB) Downloaded 173 times
Last edited by HackaLittleBit on 12 May 2012 14:33, edited 1 time in total.

User avatar
jonty-comp
Tycoon
Tycoon
Posts: 2544
Joined: 22 Oct 2005 16:05
Location: Chesterfield, England
Contact:

Re: distance between ships

Post by jonty-comp » 09 Apr 2009 08:46

A good idea! I've just patched it into r16000 (woo milestone) and the ships definitely make an effort to not run into each other. Only one ship can dock at a time, and the other ships flit about a bit like they're not quite sure where to go. The larger ships still clip a bit because they cover more than one tile, but I guess that's fairly easily remedied by just increasing the distance they keep apart.

All in all, I'd say it's definitely better than the default behaviour!
Attachments
Frahattan Springs Transport, 1940-03-10.png
These ships are all going to the same place from the same place, but they've spread out into a nice little fleet.
Frahattan Springs Transport, 1940-03-10.png (6.87 KiB) Viewed 8771 times
Frahattan Springs Transport, 1940-06-10.png
As you see they circle around the docks a bit when in a confined space. Perhaps a waiting area or something like that is in order.
Frahattan Springs Transport, 1940-06-10.png (22.36 KiB) Viewed 8774 times

audigex
Tycoon
Tycoon
Posts: 1919
Joined: 09 Dec 2007 21:28
Contact:

Re: distance between ships

Post by audigex » 09 Apr 2009 17:55

I'd suggest removing the behaviour when at a dock otherwise ships are at an even bigger disadvantage over other vehicles.
Jon

Eddi
Tycoon
Tycoon
Posts: 7369
Joined: 17 Jan 2007 00:14

Re: distance between ships

Post by Eddi » 09 Apr 2009 18:00

the proper solution is to give docks a state machine similar to airports. and to give ships significantly higher capacity, so you just won't need as many.

also, i can imagine ships of different width (1/2 tile (similar to road vehicles), 1 tile (what they are now) and 2 tiles (for ocean liners. those probably won't fit into the current locks))
You might not exactly be interested in Ferion, but if you are, have fun :)

User avatar
Bilbo
Tycoon
Tycoon
Posts: 1710
Joined: 06 Jun 2007 21:07
Location: Czech Republic

Re: distance between ships

Post by Bilbo » 09 Apr 2009 18:12

Eddi wrote:the proper solution is to give docks a state machine similar to airports. and to give ships significantly higher capacity, so you just won't need as many.
Hmm ... something like my NewGRF ( http://www.tt-forums.net/viewtopic.php?f=36&t=33030 ) with very large ships?

Slight problem would be - with current ships, the are rarely used. If we decrease their effectivity by disallowing "stacking" ... they won't get more favorite means of transport :)
If you need something, do it yourself or it will be never done.

My patches: Extra large maps (1048576 high, 1048576 wide) (FS#1059), Vehicle + Town + Industry console commands (FS#1060), few minor patches (FS#2820, FS#1521, FS#2837, FS#2843), AI debugging facility

Other: Very large ships NewGRF, Bilbo's multiplayer patch pack v5 (for OpenTTD 0.7.3)

maquinista
Tycoon
Tycoon
Posts: 1808
Joined: 10 Jul 2006 00:43
Location: Spain

Re: distance between ships

Post by maquinista » 09 Apr 2009 18:59

hackalittlebit wrote:Hello

Tried to improve ship behavior a bit.
wanted to have some distance between ship while sailing and tried to avoid collisions between them.
( Head on collision will make them blow their horns.)

Regards HackaLittleBit
Awesome idea, but We will need larger docks.
Sorry if my english is too poor, I want learn it, but it isn't too easy.[/list][/size]

User avatar
Bilbo
Tycoon
Tycoon
Posts: 1710
Joined: 06 Jun 2007 21:07
Location: Czech Republic

Re: distance between ships

Post by Bilbo » 09 Apr 2009 19:14

Currently with ships it is somewhat like with airports - you can have only one dock per station, like with airports.

I think that if we add this patch, allowing more docks to be built in one station would become a must (like you can build more bus or lorry stations). Well, that will require changes in some game logic and probably also ship's pathfinder.
If you need something, do it yourself or it will be never done.

My patches: Extra large maps (1048576 high, 1048576 wide) (FS#1059), Vehicle + Town + Industry console commands (FS#1060), few minor patches (FS#2820, FS#1521, FS#2837, FS#2843), AI debugging facility

Other: Very large ships NewGRF, Bilbo's multiplayer patch pack v5 (for OpenTTD 0.7.3)

Eddi
Tycoon
Tycoon
Posts: 7369
Joined: 17 Jan 2007 00:14

Re: distance between ships

Post by Eddi » 09 Apr 2009 19:34

Bilbo wrote:If we decrease their effectivity by disallowing "stacking" ... they won't get more favorite means of transport :)
IMHO, cargo like coal or oil should have zero dependence on delivery time (i.e. a completely flat payment rate curve). so if some cargos have the only goal to transport lots, not fast, then ships get a lot more interesting for these cargos (especially if you can put several train loads of cargo into one ship)
You might not exactly be interested in Ferion, but if you are, have fun :)

User avatar
Bilbo
Tycoon
Tycoon
Posts: 1710
Joined: 06 Jun 2007 21:07
Location: Czech Republic

Re: distance between ships

Post by Bilbo » 09 Apr 2009 20:52

Eddi wrote:IMHO, cargo like coal or oil should have zero dependence on delivery time (i.e. a completely flat payment rate curve). so if some cargos have the only goal to transport lots, not fast, then ships get a lot more interesting for these cargos (especially if you can put several train loads of cargo into one ship)
Hmm ... I think the payment curve can't be defined as completely flat in NewGRF, but I think you can have it completely flat for 637 days, with slow decrease after that (well, while the coal does not decay, waiting 2 years for your shipment isn't good either)

May be interesting to make some NewGRF with very flat curves, very islandish maps and high capacity ships. I bet most people will then use ships to transport cargo :)
If you need something, do it yourself or it will be never done.

My patches: Extra large maps (1048576 high, 1048576 wide) (FS#1059), Vehicle + Town + Industry console commands (FS#1060), few minor patches (FS#2820, FS#1521, FS#2837, FS#2843), AI debugging facility

Other: Very large ships NewGRF, Bilbo's multiplayer patch pack v5 (for OpenTTD 0.7.3)


Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4718
Joined: 09 Sep 2007 05:03
Location: home

Re: distance between ships

Post by Alberth » 10 Apr 2009 09:59

Nice idea, simple and very effective.

I played with it a little and found a 'new' problem, ships can now deadlock, see pic
The bottom-right ship wants to go to the top-left, while the two top-left ships want to go the to the bottom-right.

Of course this happens as soon as ships cannot move onto each other, so it was to be expected.
In a canal, I don't think it is a problem. A player is (or should be) smart enough not to push ships in two directions through a single tile canal (after taking the picture, I widened the canal to two tiles, and the ships-jam resolved itself).

I haven't tested it, but I expect the problem to also happen in a lock, which is bad as a user cannot widen a lock.
Attachments
boats_deadlock.png
boats trying to pass each other.
boats_deadlock.png (19.84 KiB) Viewed 8366 times

User avatar
HackaLittleBit
Director
Director
Posts: 550
Joined: 10 Dec 2008 16:08
Location: tile 0x0000

Re: distance between ships

Post by HackaLittleBit » 10 Apr 2009 11:23

Alberth

Change

Code: Select all

if (v->direction == ReverseDir(u->direction)) PlayShipSound(v); // imminent frontal collision :)
to

Code: Select all

if (v->direction == ReverseDir(u->direction)) return NULL; // no frontal collision :)


This was just a quick hack.
If you look at the code you will see that ships only will try to move out of the way of each other when trackbit set to 3 way.
If they have the behavior that you describe it is because of bad track bits I guess.
Trackbits I am missing in OpenTTD:

Code: Select all

	TRACK_BIT_FORK_NE = TRACK_BIT_UPPER | TRACK_BIT_RIGHT,					///< "Arrow" to the north-east
	TRACK_BIT_FORK_SE = TRACK_BIT_LOWER | TRACK_BIT_RIGHT,					///< "Arrow" to the south-east
	TRACK_BIT_FORK_SW = TRACK_BIT_LOWER | TRACK_BIT_LEFT,					///< "Arrow" to the south-west
	TRACK_BIT_FORK_NW = TRACK_BIT_UPPER | TRACK_BIT_LEFT,					///< "Arrow" to the north-west

	TRACK_BIT_SWITCH_R_NE = TRACK_BIT_X | TRACK_BIT_RIGHT,					///< "Arrow" to the north-east
	TRACK_BIT_SWITCH_R_SE = TRACK_BIT_Y | TRACK_BIT_RIGHT,					///< "Arrow" to the south-east
	TRACK_BIT_SWITCH_R_SW = TRACK_BIT_X | TRACK_BIT_LEFT,					///< "Arrow" to the south-west
	TRACK_BIT_SWITCH_R_NW = TRACK_BIT_Y | TRACK_BIT_LEFT,					///< "Arrow" to the north-west

	TRACK_BIT_SWITCH_L_NE = TRACK_BIT_X | TRACK_BIT_UPPER,					///< "Arrow" to the north-east
	TRACK_BIT_SWITCH_L_SE = TRACK_BIT_Y | TRACK_BIT_LOWER,					///< "Arrow" to the south-east
	TRACK_BIT_SWITCH_L_SW = TRACK_BIT_X | TRACK_BIT_LOWER,					///< "Arrow" to the south-west
	TRACK_BIT_SWITCH_L_NW = TRACK_BIT_Y | TRACK_BIT_UPPER,					///< "Arrow" to the north-west
Any reason for that developers?

I will submit this code to flyspray soon.
I am not intending to do anything more with it, so if you want to use or change it feel free :)

User avatar
HackaLittleBit
Director
Director
Posts: 550
Joined: 10 Dec 2008 16:08
Location: tile 0x0000

Re: distance between ships

Post by HackaLittleBit » 10 Apr 2009 11:57

Forgot this one
if you want the ships quiet around the dock:

add this code

Code: Select all

	if (v->cur_speed == 0 ) return NULL;
Regards HackaLittleBit

User avatar
Wolf01
Tycoon
Tycoon
Posts: 2013
Joined: 24 Apr 2004 10:43
Location: Venezia - Italia
Contact:

Re: distance between ships

Post by Wolf01 » 10 Apr 2009 12:05

Alberth wrote:Nice idea, simple and very effective.

I played with it a little and found a 'new' problem, ships can now deadlock, see pic
The bottom-right ship wants to go to the top-left, while the two top-left ships want to go the to the bottom-right.

Of course this happens as soon as ships cannot move onto each other, so it was to be expected.
In a canal, I don't think it is a problem. A player is (or should be) smart enough not to push ships in two directions through a single tile canal (after taking the picture, I widened the canal to two tiles, and the ships-jam resolved itself).

I haven't tested it, but I expect the problem to also happen in a lock, which is bad as a user cannot widen a lock.

That's not a problem, that's a feature!
Just build 2 tiles wide canals as you should do if ships sink when crashing on each other
Trains and vehicles can deadlock, why not ships too?
This will make you think on what you are doing instead of just place a line of water
Go ahead hackalittlebit! :D


User avatar
HackaLittleBit
Director
Director
Posts: 550
Joined: 10 Dec 2008 16:08
Location: tile 0x0000

Re: distance between ships

Post by HackaLittleBit » 10 Apr 2009 13:12

By the way;

Forgot to mention JacobD88 it was his suggestion.
Looks like he's got very long docks on there... Maybe supporting multiple ships (that don't overlap) just speculation :wink:
see http://www.tt-forums.net/viewtopic.php?p=760939#p760939
Sorry JacobD88 :wink:

Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4718
Joined: 09 Sep 2007 05:03
Location: home

Re: distance between ships

Post by Alberth » 10 Apr 2009 14:46

I modified the code as you suggested, and had another try. I don't like the result very much, ships avoid each other, except when they run into each other frontally.

While playing, I found another feature, see the picture. The ship at the left is leaving, the ship at the right must go to the docks. However, the latter cannot turn left due to the presence of the left ship, and so they move away from the dock together.... (probably until the left ship turns or so, but I didn't wait for that).

If you want the 'non-colliding_ships_bug.sav' file, send me a PM.


About deadlocking ships in locks: Limiting the number of ships in a lock to 1 may be a big step forward already. It can still break when you have several locks after each other, but that does not happen very often.

Wolf01: I completely agree with your view, except that the player should have the ability to fix the situation. With locks some extra care may be needed.

hackalittlebit: I have not yet studied the track code, so I don't really understand how your patch works. As for the missing combinations, apparently nobody needed them enough to add them.
Attachments
wrong_direction.png
right ship cannot turn
wrong_direction.png (26.51 KiB) Viewed 8158 times

User avatar
HackaLittleBit
Director
Director
Posts: 550
Joined: 10 Dec 2008 16:08
Location: tile 0x0000

Re: distance between ships

Post by HackaLittleBit » 10 Apr 2009 15:11

PLS send me the sav.

How the code works is very simple.
I look 2 tiles ahead (new tile + 1)when ship found on that tile turn to left side to avoid collision.
only works when 3way track bit set. (In theory, you should have space to move).
other track bit combination's are ignored.
The whole thing happens only when entering new tile and after the trackfinder has determined the route.
Anyway thanks for testing.

Regards HackaLittleBit

User avatar
Bilbo
Tycoon
Tycoon
Posts: 1710
Joined: 06 Jun 2007 21:07
Location: Czech Republic

Re: distance between ships

Post by Bilbo » 10 Apr 2009 15:30

I think we'll need some one-way locks and perhaps specifying some routes in the canal to be one-way, otherwise there will be always risk of deadlock - imagine fast ship overtaking a slow ship and from other side, another fast ship. We can have deadlock quite easily ....
If you need something, do it yourself or it will be never done.

My patches: Extra large maps (1048576 high, 1048576 wide) (FS#1059), Vehicle + Town + Industry console commands (FS#1060), few minor patches (FS#2820, FS#1521, FS#2837, FS#2843), AI debugging facility

Other: Very large ships NewGRF, Bilbo's multiplayer patch pack v5 (for OpenTTD 0.7.3)

User avatar
HackaLittleBit
Director
Director
Posts: 550
Joined: 10 Dec 2008 16:08
Location: tile 0x0000

Re: distance between ships

Post by HackaLittleBit » 10 Apr 2009 17:12

Alberth wrote:While playing, I found another feature, see the picture. The ship at the left is leaving, the ship at the right must go to the docks. However, the latter cannot turn left due to the presence of the left ship, and so they move away from the dock together.... (probably until the left ship turns or so, but I didn't wait for that).
This feature has been recognized as bug. :?

insert this code PLS.

Code: Select all

	if (v->cur_speed <= u->cur_speed) v->cur_speed >>= 1; // go half speed to let other ship pass
Regards and Thanks Albert

Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 1 guest