LoneGazebo / Community-Patch-DLL

Community Patch for Civilization V - Brave New World
Other
285 stars 158 forks source link

Feature request: access to NumStackingUnits attribute via promotion #10723

Open Tekamthi opened 6 months ago

Tekamthi commented 6 months ago

There's a field in Units table, 'NumStackingUnits'; if possible, it would be desirable to have access to this attribute via the promotions table. Alternatively, the ability to modify it via Lua directly (eg just increment/decrement an individual unit's value for this field via Lua function).

Relevant problem: the 1 UPT ruleset of civ 5 comes with some headaches that have never really been solved after all these years, particularly with movement of units in later eras. Open borders is particularly egregious in this regard, and has long been a double-edged sword to the player granting it: on the one hand player wants help from its allies, on the other its allies just clog up the open borders tiles as much as they do anything to help.

Proposed use of requested feature: at each player's turn end, will loop through all of that player's units, any that are found in foreign land where open borders agreement exists will be given NumStackingUnits promotion. On turn start, will loop units again and reset any stacking enabled units to 0/default. Effectively player's own units will appear the same to player at all times during their own turn, but other players they may be inadvertently obstructing in their own lands will be able to move freely during their turns

The Lua for this should be relatively trivial once access to NumStackingUnits is made available. Proposed use is potentially a huge improvement to QoL.

ilteroi commented 6 months ago

how to do target selection for attacks when there are 2 or more enemy units in a plot? we do have getBestDefender() but is that the desired behavior?

also, there is already a flag for this behavior: MOVEFLAG_IGNORE_STACKING_NEUTRAL. but it's only used for "hypothetical" enemy moves to estimate danger for a player's own units.

azum4roll commented 6 months ago

This enables multiple players' units to stack and beat up a single unit from the same tile. Even a citadel at a mountain pass is not safe anymore if you're at war with multiple players.

Tekamthi commented 6 months ago

This enables multiple players' units to stack and beat up a single unit from the same tile.

Yes, I've considered this: However it would be more commonly a defensive obstacle, the multiple attacks would have to be coordinated between different players turns, and depending on turn order, defender might get to intervene. More frequently, if you had a pile of stacked units in a defensive choke point, attacker would never get through no matter how powerful... but both of these concerns are moot:

in addition to the general logic described in OP, after each combat, mod will loop through all units in each combat plot and check if their stacking value has been modified; during this loop all will be reset to default, and presumably the game engine will just pop them out to a free tile as it currently handles units in plots where they're not supposed to be, ie any combat in a stacking plot will instantly undo this stacking bonus and return things to normal, albeit with some units shuffled around a little haphazardly. If engine does not pop them out automatically then I can force it via Lua

how to do target selection for attacks when there are 2 or more enemy units in a plot? we do have getBestDefender() but is that the desired behavior?

To me as modder this doesn't matter so much, so long as game doesn't crash/hang. We used to have situations where multiple units would get stacked in city, and game engine would select one of them (I'm guessing via getBestDefender?). Theres a mod out there that allows 2UPT in city, it's been a long time since I tried it but it worked fine last I did, just the AI generally didn't make use of it -- I assume this same logic that dealt with this in the past will apply in the case of the occasional stacked combat.

In the usecase described it probably makes most sense for the defender to be the actual owner of the plot, but again this strikes me as nitpicking, won't be a deal-breaker if an ally is the defender.

I think the biggest "issue" this will face as a mod will be resource use to do all these loops through units -- not sure how this might add up in late game when there's hundreds of units everywhere.

There are probably some other oversights to my plan here, but I think I've identified the big ones. From my point of view standing as an outsider to the .DLL it really comes down to how much heavy lifting you guys would have to do to accomplish it -- the mod I've planned is very much a theorycrafted experiment, who knows what uptake there might, so if it's a big unwinding of Firaxis spaghetti then forget it. If it's moreso a trivial thing that can be accomplished easily, I'd be very interested in putting it to use.

If you are considering this one, note that it would actually be more powerful for my purpose to just increment/decrement this value for an individual unit directly via Lua function. The promotion table option is still good, probably more accessible to most new modders, but it would be better suited to my purpose to just do it all in Lua