@MightyJannissary What kind of game were you playing? Was it a domination and you started killing off all civs? The issue comes from the fact that the game calls strategies for non-existent players, probably killed civs. If this is true then I will have to add some sort of countermeasure for that.
I've been trying this mod out after I learning about the 'AI only cares about science' craziness, and have been seeing the same nil reference errors at line 1919 of RealStrategy.lua, in RefreshNavalData. As I was trying to make the AI better any sort exceptions here were concerning, so did a bit of investigation. I've not disproved the theory that they're caused by the game making strategy calls for dead civs, but not what's caused the ones I've seen. Quite the opposite in fact!
I added a bit of logging to the function in question and that, combined with the logging from a couple of my mods, revealed what is happening. The problem seems to be new civs coming to life after the game has started: specifically a barbarian camp converting to a city states with the Barbarian Clans gamemode enabled.
See lua.log here:
https://pastebin.com/qsyFwvF1 , theres a lot of clutter in there from other mods I'm afraid, but the sequence of events is fairly clear:
- Line 6: Load of saved game initiated from main menu (autosave from the end of turn 117/start of turn 118)
- Line 23: RealStrategy setups tdata for each of the 27 'players' in the game (IDs 0-24, 62 and 63)
- Line 557: In onLoadComplete tdata is populated for all players
- Line 653: onLoadScreenClose events are fired
- Line 768: LocalPlayer turn activated for turn 118
- Line 778: LocalPlayer turn end for turn turn 118
- Lines 783 - 890: ActiveStrategyNaval called successfully multiple times for each player in turn for IDs 1-24
So far, so boring! But now, the interesting bit:
- Line 891: A city is added to the map by playerID 25!
- Line 1161-1175: ActiveStrategyNaval gets called for playerID 25, and a nil reference would have been thrown in RefreshNavalData (RealStrategy.lua:1919) had I not added a nil check. This repeats three times.
- Line 1176-1183: ActiveStrategyNaval called successfully for playerID 0, eight times
- Line 1184: LocalPlayer turn activated for turn 119
So, how did playerID 25 manage to found a city on turn 118, if there was no player 25 on turn 117!?
The answer is, I think, in the fact that the CivilizationTypeName of the mysterious player 25 is CIVILIZATION_MUSCAT, a city-state, and as I was playing with Barbarian Clans mode it evolved from a camp on turn 118.
The ActiveStrategyNaval calls then fail for player 25 every turn thereafter. But, if I save and reload the game, on load RST will initialise tdata for all 28 players that now exist, and the ActiveStrategyNaval calls are all successful from then on.
I guess a similar situation could arise if a player were to be killed off, the game saved and reloaded while they were dead, in that case they would be missing when tdata was initialised. If they were then resurrected, by one of their cities being liberated, any strategy calls for them would fail - until the next save/reload.
The case of resurrected players could be easily covered by using GetWasEverAliveIDs instead of GetAliveIDs when initialising tdata. But the completely new civs joining the game would seem to need a nil check on every access to tdata, so the new player can be added to tdata when they come into being. Unless there's an onPlayerAdded or similiar event that fires when a civ is spawned?
Anyway, hope that helps in fixing the bug, and thanks for all your excellent Civ6 mods! Looking through that log has reminded me just how much of my Civ6 experience is actually down to you, not to mention the amount I've learnt about Civ6 from reading your code!
