advanced usage of road vs railroad?

davidlallen

Deity
Joined
Apr 28, 2008
Messages
4,743
Location
California
In my Mad Max mod, I want to have two road types: highways, which are pre-apocalypse, and normal roads which can be built easily. The highway can use the railroad route type; I have already changed the graphics so that it looks like modern road.

But, there are two things I cannot quite figure out how to do.

1. All unitclasses, including foot units, get fast movement speed on the railroad. I want to prevent foot unitclasses from using the fast movement speed. This is kind of the reverse of the existing "route restrictor" mod, which lets me limit certain units to only moving on the railroad.

How can I prevent certain unitclasses from using railroads?

2. I want the players to build normal roads and not highways, until they research a late game tech "Highway Repair". But I want them to be able to use the highways from the start. It seems that the ability to *build* railroad and *use* railroad are linked. In WB, build a long railroad outside cultural borders; give one civ the railroad tech; and don't give the other civ the railroad tech. The civ with railroad tech can use the railroad and the other one can't.

The only place I can find for this linkage is in the file units/civ4buildinfo.xml, the "build railroad" command. If I change which technology this requires, say to "NONE", then everybody can use the railroad at the start of the game. But also, everybody can build new railroad at the start of the game, which is not what I want. I want no tech requirement to *use* the railroad, but require "Highway Repair" tech to *build* the railroad.

How can I have different techs to build vs use railroad?
 
Well, you aren't going to be able to do this in xml. I'm sure there is a way in python, but to do this right it would require SDK work.

The only built in mechanic like this I can think of is that units can't use roads/railroads in none open borders cultural. You might want to start by looking at how they handle that.
A good place to start looking would be the CvPlot.cpp file, probly something to do with the movement cost of plots.
 
Hello again in this thread :-)

I would prefer to avoid SDK, but if you have any leads on how to do it in python, that'd be great. I would like road behavior to be different from railroad behavior -- that may be an additional complication.

I did have one hack in mind, but I haven't tried it out yet. It seems that the tech required to use railroads is determined by the tech in the build railroads activity. There might not be a check for whether any unit has this build activity available. So if the tech is none, but the worker does not have this build activity, then anybody can use railroads but *nobody* can build them. I have this working, but it's not quite what I want.

Now I have thought to add another unit, say "highway worker", which is the same as the regular worker but has this additional activity available. Once the repair highways tech is available, then I want all the existing worker units to automatically upgrade to this type, and new workers purchased would be this type.

This is a little indirect and it requires a sort of dummy unit, but I think it could work if there is no better way.
 
Hehe, lucky for us, you got questions and I'm in the mood to answer them. ;)

Changing the required tech in the BuildInfo only controls when that item can be built and has no effect on who can use what is built.

I can totally understand you not wanting to get into the SDK, but if you want roads and railroads to have different behavior, then there is really no other way. As it stands, roads and railroads are just routes with different stats and the same functionality.

If you want to do what you are talking about then I would recommend your first step be getting a unmodded SDK to compile then I can help you get started making the changes you want to do.

Check the tutorials section of the forums, there are some good tuts on compiling the DLL for free.

EDIT: Once you get the unmmodded dll to compile the modding won't be that hard. Just have to add some if statements to a couple functions in the CvUnit.cpp file.
 
Regarding who can use railroads, actually I don't agree. Here's what I tried. Build a long railroad in neutral territory in WB. Give railroad tech to one civ but not the other. Give both of them a unit at one end of the railroad and have a race down the tracks. Now go out, change the build tech for railroads to none, and repeat. In the first case, one guy can use the railroad and the other can't. In the second case, both can use the railroad.

Regarding the SDK, I am an experienced programmer. But I am pretty intimidated by a 20-step procedure, followed by a hundred posts of people commenting that it didn't work for them, followed by a later comment that those tools aren't even available for download anymore. If I can stick with python, I'd like to.
 
If you start the WB and make a railroad, your unit gets the railroad move bonus regardless of whether or not you have the tech that lets your workers build railroads. If you set the req tech of the railroad BuildInfo to None then the only effect is that workers will be able to build railroads as soon as you have coal or iron.

As for doing it in python, look at the GameUtils.py, specificly the unitCannotMoveInto method. This is called a LOT, just remember that it is called for every plot in a path when one is chosen for a unit and if you add that math to the number of units a few hundred turns into a game.. This function has it places, but it can also kill a mod with lag if you arn't carful. Just give it a try and see what happens. :)

Just out of curiousity, how experienced are you with python?

EDIT: O and remember to activate the unitCannotMoveInto method in the PythonCallbackDefines.xml. Can't count how many times I've fought with code and finnally realized I forgot to change the 0 to a 1 in that xml.
 
I have used cannotMoveInto to prevent units from moving into fallout in my mod. But, I do not want to *prevent* units from moving in railroad squares, I just want to prevent them from moving *fast*.

Since there is no convenient way to prevent foot units from moving fast, I will just call it an "unexpected feature" :-)

Although I have only programmed in python for a week or two and my total code output is about 500 lines, I have programmed in Tcl, a similar scripting language, pretty much every day for > 12 years.
 
Ahh, cool, once you know how to program, its all just syntax. :cool:

I've been thinking about it for a bit and I had an idea. If you put some code in CvEventManager.py in onUnitMove method, you could see if its a unit that can't move on rails and, assuming it is moving on a rail, you could do some math and take away an appropriate amount of movement points so that they get no extra bonus from the railroad.

You may then have to put a small amount of code in cannotSelectionListMove to keep the human players from being able to move units farther then their max movement points. It was a trick I used in my chess mod so players could only choose valid postions to move the pieces to. You may also have to put that bit of code in unitCannotMove so the AI will know what to do.

You get what I saying?
 
Back
Top Bottom