UPDATE: I have compiled LUA script that achieves the following:
- Index and track through a table a roster of each player's mountaineer (unit capable of traversing mountains) units;
- Index and track each mountaineer unit's location throughout the game;
- Listen for and identify any instance when a mountaineer unit moves onto a mountain;
- By random chance either:
- allow the mountaineer unit to remain on the mountain, or
- damage the unit and push it back to the location where it started, before moving up the mountain, and
- destroy the unit if it is damaged beyond 100 points;
- all the while maintaining the unit's promotions if any.
Here comes the catch, however. Because I've found no function in CIV 6's LUA that allows me to actually force a unit back from the mountain to the plot from which it moved, I've been forced to improvise and
destroy the old unit while
creating a new one simultaneously to simulate the failed attempt to traverse a mountain. The promotions and damage can persist no problem, so that's less of an issue. I still can't find a way to persist the unit's veteran name, but I might be able to fix it with time. There is a greater problem, however.
With civilian units, like settlers, GPs, etc., there is no issue - because they can't earn experience or promotions. However, with any military unit (like scouts or rangers) that this mod allows to climb the mountain I face a dilemma. I can persist their promotions and damage in the new unit without a problem, but the way the game's experience/promotions system is coded, it produces an unfortunate hiccup. Despite getting x number of promotions up front, the new units are
still treated by the game as brand-new units that received no promotions. That is, the promotion are active, but, instead of having to earn x++ number of experience points for the next x+1 promotion, only 6 points are required. That wouldn't be a game-ending problem in and of itself (although this
is quite ugly, there
are ways to circumvent the problem by delaying the unit's experience progress using LUA), but a strange bug crops up in the game, where a unit that's given too many promotions off the bat has its promotion mechanic lock up. It stops being able to
use its new earned promotions and experience points, but still continues to earn them. This also might be a product of conflicting LUA codes that I am running in several of my active mods, but I doubt it.
So, here is my dilemma. I'd love to be able to code a way to
prevent a unit from climbing the mountain, but I see no way of doing it using in-game scripts (there are ways, it seems, of doing it in the UI context) without the create/destroy process. And the process only works in an elegant way for non-promotion-capable units.
Thus, I have a choice: (1) implement the process as I have done, and keep trying to find a solution, (2) instead of pushing the unit back, only damage it if it climbs the mountain, or destroy it (and perhaps keep the original mechanic for the civilian units); or (3) keep the original mechanic and just live with the fact that the unit will lose all of its promotions (well, I can say that... heh... the unit was so damaged, that it forgot how be a zweihander sword-wielder and everything else it learned
)).
OR, and I just came up with this: on the first go round, the first time a unit is damaged on the mountain, give it a chance of getting a "mountainclimber" free promotion that will keep it
safe from any future mountain failure (so I won't have to ever re-create it again), and make that chance a 100% if a unit has at least one promotion (and keep it on the mountain instead of re-creating it).
Actually, I might just with this
. BUT, please let me know if anyone has any other suggestions, I'd love to hear them!