Save m_* variables to a file

ViVa

Chieftain
Joined
Apr 4, 2007
Messages
10
In what way is it possible to have all the m_* variables of the current player to be saved to a text file, in a way like this fx:


"m_IstartingX: " . Write(m_iStartingX);
"m_IstartingY: " . Write(m_iStartingY);
"m_iTotalPopulation: " . Write(m_iTotalPopulation);
...

With the . (dot) I mean the concatination of 2 strings.
I want something like a dump of all the player's variables. I need to know their values for a little research I'm planning to do.

Any help would be greatly appreciated!
 
That would be a rather simple process, we have a handy logging feature logMsg attached to the Global context so it would just be a matter of making a function that performed a file write out as you described, with a few loops to spit out the arrays with some useful names associated with the index's. Then it would just be a matter of establishing some kind of Python call that activates it, combined with a simple Event manager plug-in that would call said function on every press of a specific key you would have a very handy means to repeatedly dump any variables you want to a log file.
 
Impaler[WrG];5417386 said:
That would be a rather simple process, we have a handy logging feature logMsg attached to the Global context so it would just be a matter of making a function that performed a file write out as you described, with a few loops to spit out the arrays with some useful names associated with the index's. Then it would just be a matter of establishing some kind of Python call that activates it, combined with a simple Event manager plug-in that would call said function on every press of a specific key you would have a very handy means to repeatedly dump any variables you want to a log file.

Thank you Impaler[WrG] for your response.

I searched the entire source code, and if I'm not mistaken there is one implementation for the logMsg() function in the entire project. I found it in the file CvXMLLoadUtility.cpp. Looking like this:

Code:
void CvXMLLoadUtility::logMsg(char* format, ... )
{
	static char buf[kBufSize];
	_vsnprintf( buf, kBufSize-4, format, (char*)(&format+1) );
	gDLL->logMsg("xml.log", buf);
}

I'm not that good with C++, so could you tell me a little bit more on how to exactly have the m_* variables from the current CvPlayer object placed in fx xml.log? I understand what you are trying to say, but I really don't have enough experience with this SDK. Thank you in advance. :)
 
Also: I noticed the "CheatCode = chipotle" of the BetterAI mod, which is able to show a lot of information during the game by using Shift, Ctrl and Alt while hovering on things ingame. Could this mod contribute to my goal as well?
 
Alright, I succeeded in having some random string written to a file with a keypress in Python. My only remaining question now is, how do I access certain variables from C++ objects in Python?
 
In the CCCP code you will find a logMsg function at the Global level like I said (its an upgrade to whats in the XMLloadUtility), you will need to get that into your code or a version thats a member of CvPlayer (the global option is way better choice).

Then create your new function with all of the variables you want to dump like so

GC.logMsg("m_somevariable = %i", m_somevariable);

then just set up a Python call in through the PythonInterface files, you'll want to make it a call to either the GlobalContext and just loop and dump the info for every player or if your python skills are good pass an int in and dump just that player, in which case you could bypass the Global context and go directly to the Player object after establishing the linkage in python. Just look at the system used to call other void function through python, you'll see how its done.
 
Thanks for your time Impaler[WrG]. :) I already puzzled it out myself actually:

Code:
# On gcAP functions from CyPlayer can be called
# On game functions from CyGame can be called

gcAP = gc.getActivePlayer()
gameAP = game.getActivePlayer()

file = open("C:\\Users\\ViVa\\Desktop\\variables.log", "a")

file.write("Game::Maximum Turns: " + str(game.getMaxTurns()) + "\n")
file.write("Game::Game Turn: " + str(game.getGameTurn()) + "\n")
file.write("Game::Turns Left: " + str(game.getMaxTurns() - game.getGameTurn()) + "\n")

file.write("\n")

file.write("Game::Year: " + str(game.getGameTurnYear()) + "\n")
file.write("Game::Players Alive: " + str(game.countCivPlayersAlive()) + "\n")
file.write("Game::Total Population: " + str(game.getTotalPopulation()) + "\n")
file.write("Game::NumCities: " + str(game.getNumCities()) + " ?\n")
file.write("Game::NumCivCities: " + str(game.getNumCivCities()) + " ?\n")

file.write("\n")

file.write("Player::Name: " + str(gcAP.getName()) + "\n")
file.write("Player::Rank: " + str(game.getPlayerRank(gameAP)) + " ?\n") # WATCH OUT
file.write("Player::Gold: " + str(gcAP.getGold()) + "\n")
file.write("Player::Units: " + str(gcAP.getNumUnits()) + "\n")
file.write("Player::Time Played: " + str(gcAP.getTotalTimePlayed() / 60) + " minutes\n")
file.write("Player::Power: " + str(gcAP.getPower()) + " ?\n")
file.write("Player::Inflation Rate: " + str(gcAP.calculateInflationRate()) + " ?\n")

file.write("\n")

file.write("Player::Number of Cities: " + str(gcAP.getNumCities()) + "\n")
file.write("Player::Total City Religion: " + str(gcAP.countTotalHasReligion()) + "\n")
file.write("Player::Total City Happiness: " + str(gcAP.calculateTotalCityHappiness()) + "\n")
file.write("Player::Total City Unhappiness: " + str(gcAP.calculateTotalCityUnhappiness()) + "\n")
file.write("Player::Total City Healthiness: " + str(gcAP.calculateTotalCityHealthiness()) + "\n")
file.write("Player::Total City Unhealtiness: " + str(gcAP.calculateTotalCityUnhealthiness()) + "\n")
file.write("Player::Total City Culture: " + str(gcAP.countTotalCulture()) + "\n")

file.write("\n")

file.write("Player::Population Score: ... (" + str(gcAP.getPopScore()) + "/...)\n")
file.write("Player::Land Score: ... (" + str(gcAP.getLandScore()) + "/...)\n")
file.write("Player::Technology Score: ... (" + str(gcAP.getTechScore()) + "/...)\n")
file.write("Player::Wonder Score: ... (" + str(gcAP.getWondersScore()) + "/...)\n")
file.write("Player::Total Score: " + str(game.getPlayerScore(gameAP)) + "\n") # WATCH OUT

file.write("++++++++++++++++++++++++++++++++++++++++++++++++++\n")
file.close()

CyInterface().addImmediateMessage("Variables saved.", "")
 
Top Bottom