The Modding Q&A Thread

Negative food consumption works fine. Illegal math operations usually make DLL unable to compile. But the main problem is that I'm a programming noob and I don't know how to debug :P (OK, let's say I can make a debug DLL. But I have no idea how to use it).

[EDIT]: Yay! Thanks a lot! AI got negative income (due to costly specialists) and that caused crash :)
 
Does anyone know how it's enabled (in the code, not the game) that you can build an embassy? It would be sweet if it's in python:)
 
Look in CvGameUtils.py, probably under canBuild() or something.

edit: Nope, it turns out that CvGameUtils isn't even used in RFC. The code has probably been moved to the DLL. :p
 
Look in CvGameUtils.py, probably under canBuild() or something.

edit: Nope, it turns out that CvGameUtils isn't even used in RFC. The code has probably been moved to the DLL. :p

*shaking fist at the sky*
Drat.
 
It seems that players don't win games, but rather teams do. So I'd suggest using CyGame.getWinner() which returns the TeamType of the winning team. In RFC this matches the PlayerType of the winning player, which solves your problem. I'm guessing its CvGame.getWinner() in C++ then.
 
Can somebody please post instruction on making minor changes and recompile because nothing i do is working. I have already tried reading Asafs direction but they are not working for me.

Any help would be appreciated.
 
@Baldyr: Thanks a lot! But you are a Python wizard so can you post a line of code checking winner? Are you back home? Because captured() in PyScenario awaits :P

[EDIT]:
Code:
		if iBuildingType == CvUtil.findInfoTypeNum(gc.getBuildingInfo, gc.getNumBuildingInfos(), "BUILDING_ARCOLOGY_SHIELDING"):
			pCity.setNumRealBuilding(CvUtil.findInfoTypeNum(gc.getBuildingInfo, gc.getNumBuildingInfos(), "BUILDING_ARCOLOGY"), False)
		elif iBuildingType == CvUtil.findInfoTypeNum(gc.getBuildingInfo, gc.getNumBuildingInfos(), "BUILDING_DEFLECTOR_SHIELDING"):
			pCity.setNumRealBuilding(CvUtil.findInfoTypeNum(gc.getBuildingInfo, gc.getNumBuildingInfos(), "BUILDING_ARCOLOGY_SHIELDING"), False)

Why the above code (below onBuildingBuilt() at CvEventManager) doesn't work? It's copied from Next War but unluckily doesn't remove arcology (shielding).
 
@Baldyr: Thanks a lot! But you are a Python wizard so can you post a line of code checking winner?
Where/when do you need to run said code? What is the context, so to speak?

Are you back home? Because captured() in PyScenario awaits :P
I'm back home, but somewhat pressed on time, still. But keep bugging me. :lol:

Why the above code (below onBuildingBuilt() at CvEventManager) doesn't work? It's copied from Next War but unluckily doesn't remove arcology (shielding).
Did you try it in CvRFCEventHandler?
 
I want to set winner's stability to 100. Where and what should I place?(
You hack into Stability.py at the end of the beginGameTurn() method (or whatever its called) and put in:
Code:
                        iWinner = gc.getGame().getWinner()
                        if iWinner != -1:
                                self.setStability(iWinner, 100)
You might have to use None instead of -1 in the conditional statement. :dunno:

The above code should override any Stability calculations on that turn for the winner with a 100 value.

It might be more efficient to use the onBeginPlayerTurn() method instead, but then you'd have use iPlayer instead of -1 in the conditional. The potential efficiency would come from putting the script at the top of the method (instead of at the end) and add a return statement. Because then it isn't necessary to go through any of the player specific Stability calculations for the winning player.

Further efficiencies could be gained by adding a new custom stored value, because then the winner would only be checked until this value is set to anything else than -1 (default). Then the actual code would check this value each turn instead of making a call to CyGame.getWinner(). I don't actually know whether this is faster or not however.
 
"def checkTurn(self, iGameTurn):"?
Yeah, that one.

I've pasted there and it worked... once. When I loaded and ended turn my stability had risen to 100 but since then fallen to 80, and less and less to ~25. Python is very strange, indeed.
There is, of course, a logical explanation. Lets add some debug lines:
Code:
                        iWinner = gc.getGame().getWinner()
[COLOR="Red"]                        print "The winner is... player " + str(iWinner)[/COLOR]
                        if iWinner != -1:
                                self.setStability(iWinner, 100)
[COLOR="Red"]                                print "current Stability: " + str(self.getStability(iWinner)) + " (Gameturn " + str(iGameTurn) + ")"[/COLOR]
Now, make sure that logging is enabled in the main INI file and keep an eye on your Python Debug Log. You, of course, have enabled Python exceptions so that is not an issue. Right?

If it turns out that the CyGame.getWinner() method only returns the winning TeamType on the actual game turn of the victory, then we're forced to make our own custom stored value for keeping track of the winner. No big deal, really.
 
You, of course, have enabled Python exceptions so that is not an issue. Right?

:P I was sure I had XD Nevertheless, it's not an issue (but thanks for forcing me to check because you've solved my other problem XD ). What should I set to 1 to enable logging? Just one thing in .ini? (I did it and got nothing interesting, so I guess I need to enable message logging?) I'll check a few things more and hope it works.

BTW: my C++ script works, so I guess winner is working ;)
 
I'm not entirely sure what you should do in the INI file, but I guess there is something that enables logging in there. The Python Debug Log can be found at \Documents\Games\Beyond the Sword\Logs\PythonDbg.log

RFC prints a ton of useful stuff in there, and also note that PyScenario has a debug logging setup (disabled by default, but you can find the boolean controlling this at the start of the PyScenario module). The latter is of course mostly for my own personal use, but anyone can enable it and see what some of the code does from turn to turn.
 
Yeah, I found the log, but I can't find any line that I want to find there:
Spoiler :
PY:Stambul has grown
PY:Saint Domingue has grown
PY:'t Landt Van Carpentarie has grown
PY:Porto Alegre has grown
PY:Coimbra has grown
PY:Tobruk has grown
PY:Oklahoma has grown
PY:Miami has grown
PY:City Texcoco's culture has expanded
PY:City Tampico's culture has expanded
PY:Chich'en Itzá has grown
PY:Yax Mutal has grown
('iGameTurn', 505)

(True, True)

(True, True)

(True, True)

PY:Player 30's alive status set to: 1
PY:Dilli has grown
PY:Guangzhou has grown
PY:Chojbalsan has grown
PY:Team 13 revolts and is no longer a Vassal State of Team 25
PY:Caracas has grown
load_module CvRandomEventInterface

PY:Paris has grown
PY:Grenoble has grown
PY:Amsterdam has grown
PY:Tarija has grown
PY:Lisboa has grown
PY:Santiago has grown
PY:Rio de Janeiro has grown
PY:Manchester has grown
PY:Sydney has grown
PY:OnPreSave
PY:City Acquired Event: Makkah
('embassy deleted on city acquired', u'Makkah')

('embassy deleted on city acquired', u'Makkah')

('embassy deleted on city acquired', u'Makkah')

PY:City Acquired and Kept Event: Makkah
PY:OnPreSave
PY:Kraków has grown
PY:Stambul has grown
PY:City Winburg's culture has expanded
PY:'t Landt Van Quiri has grown
PY:'s-Gravenhage has grown
PY:Team 20 revolts and is no longer a Vassal State of Team 25
PY:Cabinda has grown
PY:Murcia has grown
PY:Washington has grown
PY:Minneapolis has grown
PY:Calgary has grown
PY:Barrow has grown
PY:Texcoco has grown
PY:Ritoru Oosaka has grown
('iGameTurn', 506)

PY:City Masqat's culture has expanded
PY:City Acquired Event: Masqat
('tCityPlot After', (81, 33))

(True, False)

(True, False)

(True, False)

PY:Player 27's alive status set to: 1
PY:Chennai has grown
PY:Cochin has grown
PY:Patna has grown
PY:Beijing has grown
PY:Qingdao has grown
PY:Chongqing has grown
PY:Chengdu has grown
PY:Sanshan has grown
PY:Qara Qorum has grown
PY:Shush has grown
PY:Rasht has grown
PY:Syracusae has grown
PY:Trondheim has grown
PY:Bergen has grown
PY:Team 13 becomes a Vassal State of Team 8
PY:Barcelone has grown
PY:Santiago has grown
PY:City Saõ Paulo's culture has expanded
PY:Vitória has grown
PY:Sydney has grown
PY:OnPreSave
 
That suggests that the code isn't being run, which in turn suggests that something is interupting it, like a return statement, somewhere within the checkTurn() method.

Lets try using checkPlayerTurn() instead?
Code:
        def checkPlayerTurn(self, iPlayer): #writing from memory, obviously you don't replace the default definition line!

                if gc.getGame().getWinner() == iPlayer:
                        self.setStability(iPlayer, 100)
                        return
 
Your right, I actually checked. It seems, instead, that my original code was wrongly indented. This should make more sense (still at the end of the checkTurn() method).
Code:
                iWinner = gc.getGame().getWinner()
                print "The winner is... player " + str(iWinner)
                if iWinner != -1:
                        self.setStability(iWinner, 100)
                        print "current Stability: " + str(self.getStability(iWinner)) + " (Gameturn " + str(iGameTurn) + ")"
 
Back
Top Bottom