1. Civ6 is released! Order now! (Amazon US | Amazon UK | Amazon CA | Amazon DE | Amazon FR)
    Dismiss Notice
  2. Main site is finally re-opened! We migrated it to a new CMS and gave it a new layout as well.
    Dismiss Notice
  3. Forum account upgrades are available for ad-free browsing.
    Dismiss Notice
  4. Downloads database has been migrated and re-opened! Check it out and post in Site Feedback if any issue. We have done URL re-write so that old links will continue to work.
    Dismiss Notice
  5. A new Civ6 theme forum style is now available and it's made the default forum style! Check it out and comment here.
    Dismiss Notice
  6. We have successfully migrated the forum from vBulletin to Xenforo! Please take a look around and report any issue you see in Site Feedback.
    Dismiss Notice

Restricting unit to road/railroad

Discussion in 'Civ5 - Creation & Customization' started by zez, May 5, 2012.

  1. zez

    zez Chieftain

    Oct 10, 2010
    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.
  2. ww2commander

    ww2commander Chieftain

    Aug 23, 2003
    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.
  3. Gedemon

    Gedemon Modder Staff Member Moderator Super Moderator

    Oct 4, 2004
    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.
  4. whoward69

    whoward69 DLL Minion

    May 30, 2011
    Near Portsmouth, UK
    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!
  5. Spatzimaus

    Spatzimaus Mad Scientist

    Sep 21, 2005
    Los Angeles, CA
    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.

Share This Page