Python API

jdog5000

Revolutionary
Joined
Nov 25, 2003
Messages
2,601
Location
California
Revolution contains quite a few new SDK functions along with some exposing some existing functions to Python for the first time. I'll try to provide a list of the most interesting ones for those who want to build scenarios or events or extra layers on top of Revolution, though I'm not promising this will be an exhaustive list.

All of the function exposed by Firaxis are still available of course, there's a slightly dated API up here (if anyone knows of a BTS version let me know). If you want to go looking around on your own, all functions available to Python are exposed in their corresponding Cy___Interface.cpp file (city function in CyCityInterface etc). Looking at those files is however not the easiest way to go browsing for what functions are available, I'd recommend scrolling through Cy____.h files, most of the functions you see there will be exposed to Python and you can check the Cy___Interface.cpp to be sure once you've found what you're looking for. If you want to see either what functions exist (but may not be available in Python) or what a function actually does you'll need to check out the corresponding Cv____.h and Cv____.cpp files respectively (Cv's are internal to the SDK, Cy is for the Python interface basically).

This would also of course be a good place to ask about how to use any of these functions from Python etc, there's also the thread for Modders and Mergers. If you have a question about something not specific to Revolution you'll also get good answers usually pretty quickly in the standard Creation & Custimization forum.

CvCity

int getRevolutionIndex();
void setRevolutionIndex( int iNewValue );
void changeRevolutionIndex( int iChange );


Functions for changing the Revolution Index. A value of 1000 indicates a city may consider launching a revolt, a value of 1700 or above means any revolt the city launches will be violent (ie spawn rebels) unless it's the first revolt by the city. Events or other things can change this value, as a reference a 100-200 point jump should only come from a fairly significant event (akin to rejecting rebel requests).

int getLocalRevIndex();

The local revolution index is calculated every turn and indicates whether, all events aside, things are generally improving or worsening in a city. At Epic speed, a value of +10 or higher means things are getting bad pretty quickly, while a city below -3 per turn will be more stable. There are also set and change functions for this, but you shouldn't really use them ... modify updateLocalRevIndices in Revolution.py instead.

int getRevolutionCounter();
void setRevolutionCounter( int iNewValue );
void changeRevolutionCounter( int iChange );

The revolution counter is used to determine whether enough time has passed since a prior event for a city to be able to revolt or make a demand, the counter must be at zero for this to be possible. When you bribe a city or grant a cities request for example this is set to between 3 and 10 and counts down turn by turn.

int getReinforcementCounter();
void setReinforcementCounter( int iNewValue );
void changeReinforcementCounter( int iChange );

The reinforcement counter controls when reinforcements will occur after a revolt, they show up when the counter reaches 1. This should not be changed unless it's already above 0. This is one indication that rebels are still active in a city.

int getRevRequestPercentAnger();
int getRevIndexPercentAnger();




int getRevRequestAngerTimer();
void changeRevRequestAngerTimer(int iChange);
int getRevSuccessTimer();
void changeRevSuccessTimer(int iChange);




int getNumRevolts(int playerIdx);
void changeNumRevolts(int playerIdx, int iChange);




CvEnums

These are not functions but indicators of what components of Revolution are running. If 1 it means it's running, 0 not running. Note that these are not properly initialized until either a game has been started or loaded.

GameOptionTypes.GAMEOPTION_BARBARIAN_CIV
GameOptionTypes.GAMEOPTION_REVOLUTION
GameOptionTypes.GAMEOPTION_DYNAMIC_CIV_NAMES
GameOptionTypes.GAMEOPTION_START_AS_MINORS
GameOptionTypes.GAMEOPTION_TECH_DIFFUSION
 
CvGame

TBA

CvInfo


TBA

CvPlayer

void changeLeader( int /*LeaderHeadTypes*/ eNewLeader );
void changeCiv( int /*CivilizationTypes*/ eNewCiv );

changeLeader works well in all circumstances, changeCiv is more conditional. It will change the civ certainly, but it doesn't correctly change any art that's been drawn already ... for example, unit flags of units visible to the human player will not update correctly.

void setIsHuman( bool bNewValue );

Change whether this player is a human or AI controlled. Needs to used in conjunction with setActivePlayer, I'd recommend you use RevUtils.changeHuman(iNew,iOld) when possible.

void setIsRebel( bool bNewValue );
bool isRebel( );


A civ that's considered a rebel has several advantages, including lower inflation, war weariness, and turns of anarchy when switching civics. Reinforcements and bonuses for capturing rebellious cities are also higher if the player is still considered a rebel. This status is cleared in Python currently after the player captures enough cities and holds their capital for enough turns.

void setName(std::wstring szNewValue);
void setCivName(std::wstring szNewDesc, std::wstring szNewShort, std::wstring szNewAdj);


setName changes the name of the leader (Hannibal), setCivName changes the various forms of the name of the civ (American Empire, America, American).

void setIsMinorCiv( bool bNewValue );
void setFoundedFirstCity(bool bNewValue);


void setAlive(bool bNewValue);
void setNewPlayerAlive(bool bNewValue);


setNewPlayerAlive is my function, copied off the setAlive done by Firaxis which I've exposed. It doesn't make any announcement and doesn't start the player's turn so it's more suitable if you want to set the player to alive before giving them units or cities.

CvTeam

TBA
 
I can't believe I missed this thread for so long. Thanks for "exposing" all this :goodjob:
 
Shouldn't this be stickied?
 
Back
Top Bottom