SDK Questions "Where is..."

Refar

Deity
Joined
Apr 10, 2005
Messages
4,608
Sorry for the generic topic...
I do not have alot of experience on the SDK, so have great trouble finding stuff... It allways turns out to be not where i was thinking...

1) Where is the code on National Unit limitations ? I would like to change it so the limit does depend on the Map Size (or maybe empire size).
Might want to plug in something else there as well, but need to find it first :lol:

2) Where are the AI functions for the different Unit_AI's ? I want to try to add another AI type(s).

3) Where are the functions writing/reading savegames ? I would need a tutorial or example on how to make stuff go (and be read out again) into a savegame ?

4) A tutorial/hints/example on how to expose a Function to Python ?
 
Sorry for the generic topic...
I do not have alot of experience on the SDK, so have great trouble finding stuff... It allways turns out to be not where i was thinking...
This is one area where using an IDE like Visual Studio Express can be a big help in simply looking at code because it will list all the member functions for a class, let you jump straight to a definition of a function when you happen to see it, create a list of functions which call this one, etc.

continued... said:
1) Where is the code on National Unit limitations ? I would like to change it so the limit does depend on the Map Size (or maybe empire size).
Might want to plug in something else there as well, but need to find it first :lol:
Don't really know but after a quick look I'd say that CvPlayer::isUnitClassMaxedOut() would be a likely candidate. If you change that you'd probably also have to mess with CvGameTextMgr::setUnitHelp() to make sure the hover text gives an accurate count of the maximum allowed or number left.

continued... said:
2) Where are the AI functions for the different Unit_AI's ? I want to try to add another AI type(s).
Take a look at UnitAI::AI_update and you'll see how all manner of different UnitAITypes are farmed out to other functions which deal with their specifics.

continued... said:
3) Where are the functions writing/reading savegames ? I would need a tutorial or example on how to make stuff go (and be read out again) into a savegame ?
They're all over. Most of the major classes have a read() and a write() function which handles saving/loading their particular class data.

continued... said:
4) A tutorial/hints/example on how to expose a Function to Python ?
See jdog's tutorial called (unsurprisingly ;)) Exposing new functions to Python. Along with the first post, Gerikes' example in post #3 is also quite helpful.
 
General tips for finding things in the SDK:

If you set things up with Codeblocks, always open the project instead of individual files. I assume roughly the same applies for all other editing programs.

You can do searches in the entire project, or only the current file, default if any file is open in the project is the file only. If you search the entire project then it lists the results in the bottom box for you and takes you to the first result in the screen.


To find how something is handled by the code, the general strategy is the do a search fo rthe tag in the XML. This will provide you with very few results (since it has the i___ or b____ format typically), but those will point you toward (typically) a "set____" or "change_____" function. You can then search for those as your new keywords to find everywhere in the SDK that changes the relevant attribute. Typically there is also a "get____" function which you can search for to find all sections of the code which use the number (generally without changing it).



Anyway, hopefully that helps a bit, even if it doesn't directly answer any of your questions. I assume the national unit limit is only in the CvInfos file, and is consulted by CvCity during the ::canTrain function. It is during that check that you will want to modify things generally. If you do modify it in the CvInfos file remember to encase it in an IF statement so that the check doesn't include the map size unless the map is defined.


AI is a complicated deal to add a new one and have it used properly. That's about all I have to say on that one :) And on Savegames, that is in every Cv___ file at the end, a ton of ->Read & ->Write functions. It is fairly straightforward on how to add new items to the list of saves, just make sure that the order of Reads are the same as the order of Writes or you cannot ever load your save.

Exposing to Python is all done in the Cy___ files, and I am not certain there is a tutorial on that specifically, but it is probably included in one of the larger tutorials on the forums. Essentially though it is fairly self-consistent. The Cy file will have the same function as the Cv File, but the only thing it will do is pass the input along to the Cv file for processing. You then have to go to the Cy___Interface file and define how it will be called from Python.

EDIT: Yeah, so I leave windows open for 2 hours when I have company call and make cross-posts :) Glad to see someone else came along and was slightly more helpful before me ;)
 
Thanks for the Tips.

This is one area where using an IDE like Visual Studio Express can be a big help in simply looking at code because it will list all the member functions for a class, let you jump straight to a definition of a function when you happen to see it, create a list of functions which call this one, etc.
This is a good tip. Not that i really didn't know, but somehow i allways forgot :lol:
I am used to somewhat "stoneage" solutions here (Emacs and such...). It has it's merits as well, but for getting familiar with a big project the IDE is probably better.
 
Back
Top Bottom