Restricting unit to road/railroad

zez

Chieftain
Joined
Oct 10, 2010
Messages
6
Working on some mod ideas but as my knowledge of CiV lua etc is quite limited I thought to ask around if anyone would know.

Would it be possible to make a unit only be able to move on roads and/or railroads?

And if so would you any hints how to do this?

Thank you in advance.
 
Others might correct me if wrong, but the closest way that comes to mind is to trigger a check event via the GameEvents.UnitSetXY function.

The only limitation to this is that the event triggers once the unit has moved to another tile which might not contain a road/rail and thus you would need to 'teleport' it back to its original location and then adjust its movement via SetMoves.

Hope this makes sense! I have thought about this many times myself but have put it on the low priority list of things to figure out via LUA.
 
Can't be done without a new game events like Unit:CanEnterPlot(pPlot) or the DLL access. And I'd like a Unit:CanAttackPlot(pPlot) too.
 
You could do it by re-writing the INTERFACEMODE_MOVE_TO handlers in InGame.lua, but
1) it would be a LOT of work
2) it would break almost every other mod out there
3) get it wrong and you'd break the game big time!
 
You could do it by re-writing the INTERFACEMODE_MOVE_TO handlers in InGame.lua, but...

Also, the AI wouldn't be bound by that, as it doesn't use the interface. So any interface override would be restricted solely to the active player.

Honestly, this sort of thing would just be asking for trouble, even if we COULD do it easily. All you'd have to do is pillage one railroad tile (or even just park your unit on the rails) and suddenly your opponent's units can't go anywhere; besides the fact that the AI wouldn't do that to the player, the player could build a few redundant rail spurs to compensate for those rare situations when the AI would sit on the rail lines. AI limitations are the single biggest hurdle for major modding, and this one's especially bad for that as so much of the AI's behavior when creating road networks is handled internally.

Now, if you want it to be less absolute, there's a really easy XML solution: increase the movement costs for all terrain types (so instead of 1/2 MP per hex, it could be soemthing more like 1/5/20), but then go into the Routes table and make roads/railroads give a larger movement discount. This'd allow units to move respectable distances with roads/railroads, but across unimproved land they'd go very slowly.
The downside to this is that it'd be very hard to have it apply only to a small number of units; your only real way around this is to give units that aren't limited to roads the "all terrain costs 1 MP" promotion. And forests/hills would lose their ability to impede early-era movement if you did this.
 
Top Bottom