There are two problems I see in the code:
Maybe the former problem requires a separate ticket. Also, it should be checked if caravan bonus kind (gold and/or science) is correctly accounted by the AI.
EDIT: checked it, we need to handle both problems to make them moving, or a "caravan" that found no ferry will just get stuck in a nearest city. My current solution includes checking that the target and the caravan's current position are adjacent to a same continent navigable by the unit due to its class adv.sea_move/land_move==MOVE_FULL (then no need in a ferry). Probably we need to support a) sea caravans, b) caravans of a partial move kind carried by e.g. land carriers (we have things like this in Alien World), c) caravans that won't go to another continent in a reasonable time. The current algorithm refuses to assess travel time of a caravan if there is a city on another continent to trade, I'll try to fix it for case a) at least before publishing a patch.
Fixed for 3.0. The patch is splitted, the naval part goes to bug #42567 and the caravan bonus value part is here.
EDIT: oww, the patch contained wrong logic (while working in this specific case). We should keep current behaviour in 2.6 for caravans that can ever establish trade route (but hmm what if routes can work only with one city per civ... well, it's another problem). In 3.x we probably should only slightly pessimize entering marketplace since we have a formula that is intended to evaluate both. Patches a bit later.
This is an improved patch. The variant when a caravan pays for itself by one-rime bonus is so rare that I think it can even go like this into 2.6. Maybe the idea itself needs improvement but it's for future patches. Also, probably yet another ticket should be opened to allow AI select between several available caravan types (now it orients on roles and the action, age of Merchant Ships in Aviation is explained by that Zep is obsoleted by a non-caravan unit). Also, the caravan code needs at least one bugfix and other cleanup.
hmm... after a good consideration, we don't need to increase caravan cost due to production time when it is already produced... And for 2.6 we should probably totally keep current behaviour for normal caravans.
3.0-only-marketplace-caravans.patch works for all 3.x branches. Over those two patches, a patch in #42641 is developed.
Oops, newer versions require city for unit cost estimation. I supply src, seems to work.
S3_0 version does not compile.
../../../../src/common/aicore/caravan.c: In function ‘get_discounted_reward’:
../../../../src/common/aicore/caravan.c:546:7: error: suggest parentheses around ‘&&’ within ‘||’ -Werror=parentheses
../../../../src/common/aicore/caravan.c:546:37: error: expected ‘)’ before ‘{’ token
../../../../src/common/aicore/caravan.c:539:6: note: to match this ‘(’
../../../../src/common/aicore/caravan.c:562:1: error: expected expression before ‘}’ token
../../../../src/common/aicore/caravan.c:562:1: error: control reaches end of non-void function -Werror=return-type
Oh yes, did not test after correcting *'_'* Here is the right 3.0 patch.
Merchant Ships in Aviation ruleset are units that can only enter marketplace. The trade routes are established by flying caravans and they do in autogame, but Merchants are seen just sitting in ports.