1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

The Modding Q&A Thread

Discussion in 'Rhye's and Fall Modmods' started by Leoreth, Apr 2, 2011.

  1. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    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
     
  2. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    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.
     
  3. J. pride

    J. pride Chieftain

    Joined:
    Feb 23, 2011
    Messages:
    788
    Can some explain to me how im supposed to recompile the dill after ive made a few minor changes in CvRhyes.cpp. And is it necessary for me to recompile if i want the changes to take effect?

    I found this guide but with the amount of work on there I dont if its right:
    http://forums.civfanatics.com/showthread.php?t=405444
     
  4. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    J. pride, yeah, thats the guide. Can't help you with the compilation though, as I'm yet to take the plunge myself.
     
  5. J. pride

    J. pride Chieftain

    Joined:
    Feb 23, 2011
    Messages:
    788
    Thanks for all ur help :D
     
  6. Jarkov

    Jarkov Chieftain

    Joined:
    Oct 23, 2010
    Messages:
    158
    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.
     

    Attached Files:

  7. LuKo

    LuKo The Royal Guard

    Joined:
    Aug 28, 2006
    Messages:
    1,501
    Location:
    Poland
    Is it possible to check stability by SDK? Does AI check soldiers number when deciding about declaration of war?
    Generally, I want to change the power of units according to civ's stability because I don't like current stability system.
     
  8. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    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
     
  9. LuKo

    LuKo The Royal Guard

    Joined:
    Aug 28, 2006
    Messages:
    1,501
    Location:
    Poland
    Generally, most of things I do or I did is beyond me but as long as there are easy workarounds we should use them. If anyone has an idea how to make SDK check the stability I would be grateful.
     
  10. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    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.)
     
  11. embryodead

    embryodead Caliph

    Joined:
    Jan 1, 2003
    Messages:
    5,179
    Location:
    basement
    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.
     
  12. LuKo

    LuKo The Royal Guard

    Joined:
    Aug 28, 2006
    Messages:
    1,501
    Location:
    Poland
    And there is no faster method? I don't know how often statistics are checked but fights are rather common so...
     
  13. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    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
     
  14. LuKo

    LuKo The Royal Guard

    Joined:
    Aug 28, 2006
    Messages:
    1,501
    Location:
    Poland
    So it would be 1 check per (alive) civ per turn? Do anyone know how to do that? And if it's optimal solution?
     
  15. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    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.
     
  16. embryodead

    embryodead Caliph

    Joined:
    Jan 1, 2003
    Messages:
    5,179
    Location:
    basement
    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.
     
  17. LuKo

    LuKo The Royal Guard

    Joined:
    Aug 28, 2006
    Messages:
    1,501
    Location:
    Poland
    @Baldyr: I'm glad that we came to the same solution (separately) because it makes the chance of being optimal. But still anyone who knows anything about DLL should say a word :p

    @embryodead: Thanks! Once I get back to dormitory I would need futher help ;)
     
  18. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    embryodead is of course dead right. :king: That would be the optimal solution.
     
  19. J. pride

    J. pride Chieftain

    Joined:
    Feb 23, 2011
    Messages:
    788
    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?
     
  20. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    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.)
     

Share This Page