LoneGazebo / Community-Patch-DLL

Community Patch for Civilization V - Brave New World
Other
291 stars 160 forks source link

Adding a Feature to TERRAIN_OCEAN plot allows embarked unit to cross ocean before astronomy #9973

Open Tekamthi opened 1 year ago

Tekamthi commented 1 year ago

1. Mod Version (X.Y.Z). Current Version: 3.7.5

3.7.5

2. DirectX Version

3. List of Other Mods

MB+ v37

4. Describe the Issue

The mod above uses lua to add a storm feature (it adds an invisible feature and visible improvement simultaneously, but the feature is the problem) to ocean and coast plots. Pre-astronomy embarked units are able to enter the feature plot in ocean (featureless ocean still correctly blocked). Generalizing, a feature in an ocean plot should not allow pre-astronomy embarked movement.


5. Save Game From 1 Turn Before (ALWAYS ATTACH THIS IF POSSIBLE)

6. Logs (ALWAYS ATTACH THESE IF POSSIBLE)

7. CvMiniDump.dmp File (ATTACH IF REPORTING A GAME CRASH)

8. Steps to reproduce the Issue (Optional)

9. Screenshots of the Issue (Optional)

Tekamthi commented 1 year ago

Screenshot reference illustrating this issue -- the "storm" plot feature makes ocean unintentionally passable to embarked units: Screenshot (369) Screenshot (368)

TechpriestEnginseer commented 1 year ago

This is because the best of my knowledge, cities can't claim featureless oceans until Astronomy which makes them unable to be moved into if they don't have features as well.

Tekamthi commented 1 year ago

I could write a database restriction for this myself but the necessary fields in UnitPromotions_Features appear to be borked.. opened a separate issue for that, though I'll probably have to fill it out with some more detail to illustrate the problem there.

As for this concern, would be nice if terrain_ocean was always treated as terrain_ocean, feature or not, for pre-astro movement rules. Granted this currently only relevant to modding, but i imagine this will be expected behavior to anyone else that tries to put features in ocean in any other mods as well, if that ever happens (more wonders mod possibly affected by this?). Note that it allows embarked but not naval movement -- beyond just not being desired functionality, the inconsistency strikes me as odd.

All that said its not truly game-breaking, its pretty tough to get anywhere useful using those storms in the screenshot. If it upends the rest of .dll's logic as alluded to, well so be it, i'll try to adapt the mod to this 'feature' somehow. Can probably catch it with .lua or something

ilteroi commented 1 year ago

should be fixed ... but i can't test

Tekamthi commented 1 year ago

should be fixed ... but i can't test

I am trying in 3.7.8, but issue persists... is the tag intended as the next next release?

ilteroi commented 1 year ago

ah yes, bad timing. didn't know a release was in fact imminent

ilteroi commented 1 year ago

finally go around to test it ... fix didn't work.

in fact, i don't understand how it's possible that embarked and naval units behave differently here. the relevant piece of code is (if i'm correct ...)

if(enterPlot.getFeatureType() != NO_FEATURE && isFeatureImpassable(enterPlot.getFeatureType()))
    return false;
else
    return true;

so there is no difference ...

Tekamthi commented 1 year ago

yeah i tested on 3.7.9 just now -- still persists. At the modding level, the naval unit's 'cannot enter ocean' promotion blocks access to these plots, whereas the 'embarkation' promotion controls the embarked unit's access -- the latter does some kind of tech check somewhere and is not controlled via the UnitPromotions_Terrains tables the way most promos restrict terrain. I can only guess what this means in .dll, but the code snippet above doesn't seem to capture this tech-related check by the embark promo. Its possible that when the embark promo code is checking for techs, there's some kind of feature-related exception logic alongside. (edit: this is a red herring, see note on mountains below)

I tried putting the storm feature/improvement in a mountain and the same effect occurs, land unit can access mountain when it shouldn't otherwise be able to. Not relevant to the mod, just a test.

I believe I can workaround this in my mod for now with some kind of promo to control access the same way as naval units, ie will just loop all land units and add this promo, then take it off after astronomy is discovered. Just extra legwork & cpu cylces on the mod side. Not certain this will work, just theorycrafting for now

Anyway thanks for looking into it.

Tekamthi commented 1 year ago

I've just added the following promotion to my mod:

`INSERT INTO UnitPromotions (Type, Description, Help, PortraitIndex, IconAtlas, Sound, CannotBeChosen, LostWithUpgrade, PediaType, PediaEntry, ShowInUnitPanel) VALUES ('PROMOTION_NO_EARLY_OCEAN', 'TXT_KEY_PROMOTION_NO_EARLY_OCEAN', 'TXT_KEY_PROMOTION_NO_EARLY_OCEAN_HELP', 50, 'extraPromo_Atlas', 'AS2D_IF_LEVELUP', 1, 1, 'PEDIA_SHARED', 'TXT_KEY_PEDIA_PROMOTION_NO_EARLY_OCEAN', 1);

INSERT INTO Language_en_US (Tag, Text) VALUES ('TXT_KEY_PROMOTION_NO_EARLY_OCEAN', '[COLOR_NEGATIVE_TEXT]Ocean Impassable before Astronomy[ENDCOLOR]'), ('TXT_KEY_PROMOTION_NO_EARLY_OCEAN_HELP', 'Unit cannot enter ocean until the discovery of astronomy'), ('TXT_KEY_PEDIA_PROMOTION_NO_EARLY_OCEAN', 'Ocean Impassable before Astronomy');

INSERT INTO UnitPromotions_Terrains (PromotionType, TerrainType, Impassable)
VALUES ('PROMOTION_NO_EARLY_OCEAN', 'TERRAIN_OCEAN', true);

INSERT INTO UnitPromotions_Features (PromotionType, FeatureType, Impassable) VALUES ('PROMOTION_NO_EARLY_OCEAN', 'FEATURE_RESTRICTED_VISIBILITY', true);`

I have it set to "Impassable" for both the ocean terrain, as well as the specific feature at issue & assigned this to all embarked units.... no effect! even w/ impassable promo, pre-astro embarked unit can still access ocean with feature :(

TechpriestEnginseer commented 1 year ago

Hmmm this is really weird.

A trireme is unable to access an Ocean with Atoll. An embarked Warrior/Scout is able to access an Ocean tile with an Atoll.

Tekamthi commented 1 year ago

aye, the modmod feature that caught my attention was only implemented a few months ago, thus I only noticed recently and can't say if this was always a problem or the result of some change. Haven't tested in vanilla but I guess that would be one way to check. Btw its not just embarked units nor just ocean: Put a feature in mountain and same problem occurs.

For now I have "solved" this in my modmod (yet unpublished) via a lua function to check all embarked units at end of turn, and move any unit in ocean that shouldn't be back towards capital until its in coast again. My function also deletes the exploited feature (this fits cuz my storms are meant to be temporary anyway, but wouldn't in the case of an ocean atoll). Imperfect fix in any case, and slightly wasteful of resources, but this at least stops players from discovering/attacking far off lands they shouldn't be able to. Creates potential compatibility problems (if another modmod adds unit with special ocean access outside of the regime present in VP, they will be neutered by this fix). Also probably results in AI and auto-pathed units wasting 1-turn of movement towards destinations they'll never reach, allows some units to take shortcuts to get home faster, and creates a lot of otherwise unnecessary end-of-turn unit checks, but I'm otherwise okay with this for the time being.

If possible to track down, would be nice to see it handled as expected, ie impassable terrain always defaults as impassable, feature or not, with access controlled by the relevant promo tables (UnitPromotions_Features & UnitPromotions_Terrains).

azum4roll commented 11 months ago

Ocean is just special. Embarked units don't have any promotions limiting ocean movement otherwise, and ocean isn't impassable terrain. image Removing the feature check is possible. Is there anything that will be affected?

TechpriestEnginseer commented 11 months ago

probably naval units entering natural wonder...

azum4roll commented 11 months ago

Impassable plots are handled in the previous block. It'll affect passable features on ocean tiles only.

Tekamthi commented 11 months ago

just a reminder from above, maybe you guys are on it already -- but its also mountains that have this weird effect, not just oceans: add a feature of some kind to mountain and suddenly units without mountain access can traverse