I currently want to expose CvPlayerAI::AI_bestCivic() to Python. Context is that I want to give the AI some free techs, then let it choose some civics and script it to switch to them for free.
The problem is the Python wrapper in CyPlayer.cpp, which wraps around a CvPlayer instance, not its CvPlayerAI subclass. So if I want to do m_pPlayer->AI_bestCivic(), the code won't compile. So far, so logical.
The thing is, the sources already come with some AI methods exposed to Python. From what I can tell, the only thing missing was to declare the AI method as a virtual method in CvPlayer.h (although I have no clue what that means) and define it as 0, i.e. "virtual CivicTypes AI_bestCivic() = 0".
Now the code will compile, but when I actually launch the game, I get a CTD during runtime, along with a "failed to compress game data" error message (I suppose when the game tries to autosave). Note that this is with only the declaration in CvPlayer.h added, without the method actually being called inside the CyPlayer wrapper.
I assume that my new declaration has now overridden all calls to AI_bestCivic() in CvPlayer with a null pointer, which explains the crash. But then, why does this work for all the methods already defined as virtual ... = 0 in CvPlayer.h, and similar corresponding AI classes? How can I actually correctly expose an AI method to Python?
The problem is the Python wrapper in CyPlayer.cpp, which wraps around a CvPlayer instance, not its CvPlayerAI subclass. So if I want to do m_pPlayer->AI_bestCivic(), the code won't compile. So far, so logical.
The thing is, the sources already come with some AI methods exposed to Python. From what I can tell, the only thing missing was to declare the AI method as a virtual method in CvPlayer.h (although I have no clue what that means) and define it as 0, i.e. "virtual CivicTypes AI_bestCivic() = 0".
Now the code will compile, but when I actually launch the game, I get a CTD during runtime, along with a "failed to compress game data" error message (I suppose when the game tries to autosave). Note that this is with only the declaration in CvPlayer.h added, without the method actually being called inside the CyPlayer wrapper.
I assume that my new declaration has now overridden all calls to AI_bestCivic() in CvPlayer with a null pointer, which explains the crash. But then, why does this work for all the methods already defined as virtual ... = 0 in CvPlayer.h, and similar corresponding AI classes? How can I actually correctly expose an AI method to Python?