build roads only on certain terrain?

davidlallen

Deity
Joined
Apr 28, 2008
Messages
4,743
Location
California
This is probably an xml question, at least I hope it is, but I will post here.

In Dune Wars, I want to restrict roads from certain terrain. It seems that a worker can build a road, anywhere he can walk. I want to allow workers to move on certain terrains such as shifting sand, without being able to build roads there.

The misc/CIV4RouteInfos.xml file doesn't seem to have any appropriate tags; neither does units/CIV4BuildInfos.xml. For improvements, it works because CIV4ImprovementInfos.xml has a TerrainValid field. But I don't see any way to do it for roads.
 
There isn't. It's in the SDK. CvPlot::canBuild
Planetfall does not allow routes on peaks and fungus for instance.
 
There is a method in CvGameUtils.py called canBuild. That should work also.
 
(EDIT: retract previous) Using canBuild works. The button is removed altogether on invalid terrains. I would prefer to have it greyed out with a red help text. I need to see how bad is the runtime overhead, and also I will try another way to solve my original problem. (The original problem in Dune Wars is, we prefer the "look" of no roads, but infantry move too slowly. The other way is to give infantry a double move promotion when they are in their own cultural borders.)

EDIT2: In general the callbacks which are switched off by PythonCallbackDefines.py, including canBuild, can cause a huge runtime penalty. That is true in this case; using canBuild to prevent roads on certain terrains introduces a 20% (!) decrease in performance. A large, archipelago map, 100 turns takes 53 sec. When I activate canBuild with a very short, efficient function, it takes 62 sec. So I will try the other approach of a double move promotion.
 
mmhh...another thought: Add a second worker unit, which doesn't have the ability to build roads, and let the unit be transformed, when it moves on the invalid terrain.

Not sure, how the AI would take this (not very good, i guess), would need some testing.
 
That would require a callback in onUnitMoved, which is probably almost as time consuming as canBuild. I have gotten my alternate approach mostly working, which is to take all the infantry units inside their own cultural borders, and give them a +1 movement promotion. I can check all the units once per turn, which is less of a runtime problem.
 
In general the SDK is 10x faster than Python.
The SDK should work fine and it should not be very difficult to mod this.
 
That would require a callback in onUnitMoved, which is probably almost as time consuming as canBuild.

I don't think so- onUnitMove isn't naturally disabled in PythonCallbackDefines.xml. The function onUnitSetXY is disabled, but not onUnitMove.

Anyway, python prereq callbacks are called more then python event callbacks, the game checks contantly whether you can build or construct or train, but only triggers the event callbacks when something actually happens.
 
I am sure onUnitMoved is not as time consuming as cannotMoveInto or canBuild. But I have used this before and measured a substantial slowdown, even when the function is small and fast.
 
Top Bottom