The Modding Q&A Thread

So, are you saying that I should remove the "has" from the code? Is that what I should do?
Yeah, that. It should look like this:
Code:
		#The Turk: Add Castle to indie/barb Damascus:   
		if iGameTurn == getTurnForYear(1096):
			pPlot = gc.getMap().plot(22,43)
			if pPlot.isCity():
				pCity = pPlot.getPlotCity()
				if pCity.getOwner() >= con.iNumPlayers: 
					pCity.setNumRealBuilding(con.iCastle, 1)
I'm guessing that this snippet of code holds a number of things that would seem puzzling to you. Take the opportunity to learn more once you actually get it to work, by asking. There is a good reason for everything going on here and there is no good reason for not understanding any of it.

edit: Nice illustration, by the way! :D There is no real need for all the frustration though. You could learn all the basics in a matter of hours or days, if you would just commit to it. I'd help you out. In fact, the time already spent on this one task might had been enough. :p
 
I tried it but it didnt work out, any suggestion? (just so u know im trying to this in DOC mod)
I have no handle on DOC but that is how it would be done in proper RFC anyway. Chances are that you made a mistake? Post your edits and we'll see.
 
J. pride, yeah, thats the guide. Can't help you with the compilation though, as I'm yet to take the plunge myself.
 
The code is good, but you need another makefile, because the one you get according to this guide won't work for RFC.

I've uploaded the one I use as an attachment, so you don't have to search for it.
 

Attachments

  • Makefile.rar
    2.1 KB · Views: 54
LuKo, it should be possible to write a Python callback into the SDK, which returns the custom stability value of a given player. How to write one in C++ is currently beyond me though... :p
 
In theory, I guess you should be able to call the Stability.getStability() method, for example. (Identical instances of the method can be found in several modules.) It returns a integer value, so the SDK should be able to handle it for sure.

Someone will be able to explain how to set up the callback, but this is basically how Python works with CivIV; The SDK is making calls to Python modules, but those calls might have to be routed by some default module. (Like some Interface Entry Point thingy.)
 
LuKo:
It's already done through CvScreensInterface.py
Usage from CvDLLWidgetData.cpp:
Code:
	long result = 0;
	CyArgsList argsList;
	argsList.add(ePlayer);
	gDLL->getPythonIFace()->callFunction(PYScreensModule, "getStability", argsList.makeFunctionArgs(), &result);
	int iResult = (int)result;

ePlayer is player type; iResult is the stability.

Mind you, this is slow and should not be performed many times during AI turn.
 
You'd have to cache the value in one way or another, and fetch the cached value instead of making the Python callup. So the call would never be done more than once on any given turn. (I'm not sure how to implement this in C++ and I'm not even sure if "caching" is the correct term.)

I wrote something similar for the Babylon 5 mod-mod of the Final Frontiers mod - in Python. The point was to store values in a data structure instead of making continuous method invocations during a player's turn. (This was a CvGameUtils hack aimed at limiting one type of unit domain type of venturing outside of cultural borders.) edit: link
 
So it would be 1 check per (alive) civ per turn?
Yeah, exactly. So the first time the stability check is done the return value from the Python callback is stored somewhere. The code would know that this hasn't happened yet by resetting the stability value to a invalid default value like 99 at the beginning/end of every turn. So whenever the value is something else than this, then there has already been a Python callback and the code uses that value instead of fetching it anew. Otherwise the Python callback takes place and the return value is stored and thus replaces the default value. (You could of course use a boolean also.)

Whether or not this is a optimal solution? I have no idea - I just made this up myself! :lol: I've never seen any code used for "catching" or anything...

My point it that this should be faster to do in C++ than to make all those calls to Python. So its one potential solution.
 
The simple and efficient way: make a new m_iStability variable for CvPlayer class. This should come with all C++ crap that comes with member vars, i.e. constructor, destructor, data stream load/save and public read/write methods like getStability and setStability - may sound complicated but you simply copy the stuff from other member vars.

Now that you have CvPlayer::getStability and CvPlayer::setStability you just use this in Python, instead of StoredData module (i.e. pPlayer.setStability(iNewStability) ). This way Python saves stability directly into the game core part, so you have always up-to-date stability data for use in the DLL, without a single callback or caching mechanism.
 
embryodead is of course dead right. :king: That would be the optimal solution.
 
Can anybody tell me how I can set or increase the culture of a spawned Independent city. And how do I preplace certain buildings in an Indi city?
 
CyCity.changeCulture() and CyCity.setNumRealBuilding(), respectively. Or do you need the full script for it? (Then it would be necessary to know your exact needs.)
 
Top Bottom