River movement mechanics

Web version of freeciv. Please mention the site you're using, if speaking things other than general freeciv-web codebase.
Lexxie
Veteran
Posts: 127
Joined: Fri Jun 23, 2017 4:18 pm

River movement mechanics

Post by Lexxie »

In back channels I got some interesting complaints (and ideas) about how rivers could be improved, and some ideas from other 4X games.

I try to reduce the complaints into two generalised areas:
1. If a move bonus on a river is presumably because some infrastructural transport is assumed to be there (like a boat), then why would a horsemen on a boat go twice the distance?
2. Rivers historically have marked borders because they are a natural barrier. As in, they are a barrier to movement when crossing, even if a convenience to movement when boating down the river.

The ideas to improve rivers are basically the same as above, but putting in a mechanic to address those points.

FCW is currently working on making rivers a more exciting and meaningful part of freeciv, so, before finalising anything, we welcome all ideas, discussion, and input you may have for rivers, and references to other 4X games you think have good mechanics to learn from.
Ignatus
Elite
Posts: 644
Joined: Mon Nov 06, 2017 12:05 pm
Location: St.Petersburg, Russia
Contact:

Re: River movement mechanics

Post by Ignatus »

Lexxie wrote: Fri Nov 25, 2022 6:48 pm 2. Rivers historically have marked borders because they are a natural barrier. As in, they are a barrier to movement when crossing, even if a convenience to movement when boating down the river.
I thought about rivers as they are in Civ3, and other obstacles like walls. An obstacle is an entity that exists between two adjacent tiles, they can be technically done with a special group of 4 extras (e.g. north-western border of a tile is stored within its extra while south-eastern is in the tile at south-east for which it is north-western). If we keep river streaming in the middle of tiles, there can be some uncertainity about when a unit crosses the river, or some other counter-intuitive effects; they can get used to though.
why would a horsemen on a boat go twice the distance?
The same can be said about railroads. Trains with tanks don't go faster than trains with infantry. If we want to get a bit of realism into the game, some types of roads should get constant speed for units that can't pass the same way faster without the road. It's not obvious though what is "speed" in move points conception, but here we can mostly well use the equation

Code: Select all

(move fragments spent) = ceil[(road move cost) * (unit move rate) / (train or boat move rate)].
Probably the (train or boat move rate) should be a player-dependent effect for technologies available but actually for a simple implementation may be just a constant big enough for granularity.
cazfi
Elite
Posts: 3077
Joined: Tue Jan 29, 2013 6:54 pm

Re: River movement mechanics

Post by cazfi »

Ignatus wrote: Fri Nov 25, 2022 8:28 pmProbably the (train or boat move rate) should be a player-dependent effect for technologies available but actually for a simple implementation may be just a constant big enough for granularity.
On autogames, calculating the move cost between two tiles is one of the functions taking most of the overall CPU time. Very small changes there can have huge impact on performance (a lot of effort has gone to optimize it, short of writing that part in assembler, for the functionality we currently have).
Lexxie
Veteran
Posts: 127
Joined: Fri Jun 23, 2017 4:18 pm

Re: River movement mechanics

Post by Lexxie »

This is useful to know. I assume you refer to tile_move_cost_ptrs() in map.c.
Lexxie
Veteran
Posts: 127
Joined: Fri Jun 23, 2017 4:18 pm

Re: River movement mechanics

Post by Lexxie »

Ignatus wrote: Fri Nov 25, 2022 8:28 pm I thought about rivers as they are in Civ3, and other obstacles like walls. An obstacle is an entity that exists between two adjacent tiles, they can be technically done with a special group of 4 extras (e.g. north-western border of a tile is stored within its extra while south-eastern is in the tile at south-east for which it is north-western). If we keep river streaming in the middle of tiles, there can be some uncertainity about when a unit crosses the river, or some other counter-intuitive effects; they can get used to though.
Putting between tiles, I thought of it but got scared it's too radical or difficult. But I hadn't thought of the 4 different extras, that would work for this. Good idea!
But it raises lots of compatibility issues for things like tile trade bonus and movement system, so we're keeping the legacy system of one tile, one river extra. For forseeable future, but who knows?

Also feel free to look at the EXTRA_WALL tile_extra in MP2D, which performs something similar to what you say but as single extra on single tile. This uses RF_REVERSE_RESTRICT_INFRA flag. Similar to restrictinfra. If you have restrictinfra conditions with the tile owner you lose all moves going onto the tile, otherwise not. https://freeciv.fandom.com/wiki/Terrain ... ain_Walls
Ignatus wrote: Fri Nov 25, 2022 8:28 pm The same can be said about railroads. Trains with tanks don't go faster than trains with infantry. If we want to get a bit of realism into the game, some types of roads should get constant speed for units that can't pass the same way faster without the road. It's not obvious though what is "speed" in move points conception, but here we can mostly well use the equation

Code: Select all

(move fragments spent) = ceil[(road move cost) * (unit move rate) / (train or boat move rate)].
FCW already has this for MP2E ruleset. Though this ruleset isn't released until 2023, you can try it at freecivweb.org to see. We use a road flag called RF_PASSIVE_MOVEMENT. For performance reasons (as cazfi mentioned), any road with this flag no longer measures move_cost in frags. Instead, the move_cost defined in terrain.ruleset becomes a divisor instead. For example, if the ruleset defines the move_cost as 6, it means all units using the road use 1/6 of their moves along the road. Like below:

Code: Select all

if (road_has_flag(proad, RF_PASSIVE_MOVEMENT)) {
   proad_cost = (unit_move_rate) / proad->move_cost;
}
This in combination with granular move_frag, we have achieved making all units go the same distance along rivers, railroads, and maglev, at the cost of an extra if() statement in the tile_move_cost_ptrs() function. In normal play, performance seems unaffected but I'd be curious about an autorun or some test on it.
cazfi
Elite
Posts: 3077
Joined: Tue Jan 29, 2013 6:54 pm

Re: River movement mechanics

Post by cazfi »

Lexxie wrote: Sat Nov 26, 2022 1:00 am

Code: Select all

if (road_has_flag(proad, RF_PASSIVE_MOVEMENT)) {
   proad_cost = (unit_move_rate) / proad->move_cost;
}
Yes, checking road flag is (relatively) fast; just lookup of one bit.

My comment was directed to ihnatus speculating about bringing effects system, and requirement lookups via it, to play.
Ignatus
Elite
Posts: 644
Joined: Mon Nov 06, 2017 12:05 pm
Location: St.Petersburg, Russia
Contact:

Re: River movement mechanics

Post by Ignatus »

cazfi wrote: Sun Nov 27, 2022 2:18 am Yes, checking road flag is (relatively) fast; just lookup of one bit.

My comment was directed to ihnatus speculating about bringing effects system, and requirement lookups via it, to play.
Well, we have an effect dependent move bonus since some version, I don't think one more effect does really much more (especially if it can be cached once in a turn in a player's table per extra).
cazfi
Elite
Posts: 3077
Joined: Tue Jan 29, 2013 6:54 pm

Re: River movement mechanics

Post by cazfi »

Ignatus wrote: Mon Nov 28, 2022 8:25 am
cazfi wrote: Sun Nov 27, 2022 2:18 amMy comment was directed to ihnatus speculating about bringing effects system, and requirement lookups via it, to play.
Well, we have an effect dependent move bonus
That's several orders of magnitude cheaper. It just adds to movement points of the unit in the beginning of the turn. Having effect in on the tile move cost side would affect all the path finding considerations -> easily hundreds of tiles, many processed multiple times (if cheaper route to that tile is found), each time path finding is used for a unit, most importantly in the reverse mode where (AI) cities evaluate danger.
Path finding takes about 40% of the CPU time on a typical autogame.
Ignatus
Elite
Posts: 644
Joined: Mon Nov 06, 2017 12:05 pm
Location: St.Petersburg, Russia
Contact:

Re: River movement mechanics

Post by Ignatus »

cazfi wrote: Mon Nov 28, 2022 12:52 pm
Ignatus wrote: Mon Nov 28, 2022 8:25 am
cazfi wrote: Sun Nov 27, 2022 2:18 amMy comment was directed to ihnatus speculating about bringing effects system, and requirement lookups via it, to play.
Well, we have an effect dependent move bonus
That's several orders of magnitude cheaper. It just adds to movement points of the unit in the beginning of the turn. Having effect in on the tile move cost side would affect all the path finding considerations
I mean "Action_Success_Actor_Move_Cost". We have it for "Unit Move" actions since v.3.1, right? Just, looking at the code, it is considered by pathfinder only for unknown tiles. But yes, move costs are bulk. Actually, looks like worth caching them on the map when possible (something like int[n_directions][N_tiles][N_uclasses], or it's already not enough?)
cazfi
Elite
Posts: 3077
Joined: Tue Jan 29, 2013 6:54 pm

Re: River movement mechanics

Post by cazfi »

Ignatus wrote: Mon Nov 28, 2022 1:35 pmI mean "Action_Success_Actor_Move_Cost". We have it for "Unit Move" actions since v.3.1, right?
Oh, I wonder if that explains https://osdn.net/projects/freeciv/ticket/42598 . There has been other culprits that I've improved and managed to cut something like 20% - 25% of the autogame execution times from what it was at worst point, but 3.1 is still way slower than 3.0.
Post Reply