[BtS][Python]zRoutes

@ Patriachica:

For you, I reversed the logic in the CvGameUtils attached.

With this file, you should now only fill the Config file with False, all True being the default.

For example, a caravan could be NO_ROUTE = False. Then the caravan will be obliged to use road or railroad. To even restrict it, for example, caravans cannot use railroad, add: ROUTE_RAILROAD = False.

For a freight train unit: NO_ROUTE = False and ROUTE_ROAD = False.

Probably the Civilopedia will be wrong but right now I'm fed up with this code! :D

Edit: added the revised Python/Screens/CvPediaUnit.py file to show "Cannot move along..." in the Civilopedia. Packed the whole new version with instructions.

Have fun!

Not sure, if you are still working on it or interested.
I tried the all 3 versions as mod comp and mod itself, they do not work at all.
The units are unrestricted and can go anywhere..

I looked up the every post here and did everything I could,
even did something failures people already had, for figuring out.

I added a locomotive unit hopefully, only can enter a plot has railroad.
Below is the change I made in zRoutes Config.ini

Code:
;It is very easy to use this. Here is some example code:
[UNIT_LOCOMOTIVE]        ;We want to work with the locomotive
ROUTE_ROAD = True    ;We want the locomotive to require that a road be on the plot

Hope, you still can see this post..
 
@kine100

If you're willing to mod the DLL sources, you can accomplish route restrictions in a rather simple way by modifying CvUnit::canMoveInto. Just add a check for the route being on the plot. For instance, if you wanted to restrict the unit to only travel on railroad, you could add the following line of code under the case DOMAIN_LAND check:

Code:
//Check if the Plot has railroad
if (pPlot->getRouteType() != 1)
{
    return false;
}

(Ok, it may not be exactly like this, I am working on the colonization codebase and I don't have the BTS sources available just now). I can provide a working example if requested.
 
@devolution

Thank you for your answer.
If I do so, do I have to add a new line on Unit XMLs..??
I think, I need to compile the DLL first if it works on BTS, too.
I guess CvUnit:: means CvUnit.cpp.. is that right??

@kine100

If you're willing to mod the DLL sources, you can accomplish route restrictions in a rather simple way by modifying CvUnit::canMoveInto. Just add a check for the route being on the plot. For instance, if you wanted to restrict the unit to only travel on railroad, you could add the following line of code under the case DOMAIN_LAND check:

Code:
//Check if the Plot has railroad
if (pPlot->getRouteType() != 1)
{
    return false;
}

(Ok, it may not be exactly like this, I am working on the colonization codebase and I don't have the BTS sources available just now). I can provide a working example if requested.
 
You'll have to add a new tag, yes. Then you check if a unit has this tag AND that the plot you're considering moving onto has the appropriate route in CvUnit::canMoveInto (or whatever it is called in BTS). Another alternative is to skip the tag and just hard-code a check for a particular UNIT_CLASS (NOT recommended! but it can be used for a quick prototype)

There are many guides for adding new tags, so have a look at them for how to implement them.

As for the AI, it will be able to determine just fine that the unit can only use specific routes while pathing. What the AI will not be able to do is determining how to properly use this unit and when it makes sense to built it. If you add restriced routes, you'll have to be prepared to also update the AI in this regard. Good luck!
 
You'll have to add a new tag, yes. Then you check if a unit has this tag AND that the plot you're considering moving onto has the appropriate route in CvUnit::canMoveInto (or whatever it is called in BTS). Another alternative is to skip the tag and just hard-code a check for a particular UNIT_CLASS (NOT recommended! but it can be used for a quick prototype)

There are many guides for adding new tags, so have a look at them for how to implement them.

As for the AI, it will be able to determine just fine that the unit can only use specific routes while pathing. What the AI will not be able to do is determining how to properly use this unit and when it makes sense to built it. If you add restriced routes, you'll have to be prepared to also update the AI in this regard. Good luck!

Thank you again~~!
 
Back
Top Bottom