The Modding Q&A Thread

Well I think I have no clue to what im doing (or what ur referring to). But I will tell u what I want to do. I have made an Independent Warsaw spawn to counter the German expansion to the east but the problem is that the german culture causes it to flip the city.

This is what i did with the code in Rhyes and fall.py

if (iGameTurn == getTurnForYear(900)):

gc.getMap().plot(65,52).CyCity.changeCulture(100)
 
I suggest you use the
Code:
 tags instead of quotes, so we can see if your indentations are correct.

Anyway, the CyCity Baldyr was referring to represents an object of the type "CyCity" and the expression "CyCity.changeCulture()" means that "changeCulture" is a method of the CyCity object (makes sense, doesn't it? You want to change the culture of a city). So you have to fetch the object representing your city (in this case, Warsaw) and call the changeCulture method on it:
[CODE]if iGameTurn == getTurnForYear(900):

        [COLOR="Red"]gc.getMap().plot(65,52).getPlotCity()[/COLOR].changeCulture(100)
The part marked in red returns the CyCity object representing Warsaw.
 
Code:
		if iGameTurn == getTurnForYear(880):

				gc.getMap().plot(65,52).getPlotCity().changeCulture(100)

		if (iGameTurn <= getTurnForYear(1100) and not gc.getPlayer(iEgypt).isPlayable()):

I think I did what u told but its still not woring; did i do something wrong
 
Try this:

Code:
if (iGameTurn == getTurnForYear(880)):

        gc.getMap().plot(65,52).getPlotCity().changeCulture(100)

Sometimes the parentheses matter. If that doesn't work, have a look at the logs.
 
On an unrelated matter, I need some help with the SDK.

As you know, in Rhyes.h the civilization variables are defined. Would it be possible to somehow add a function that defines the variables according to the scenario (3000 BC or 600 AD) in question?
 
Try this:

Code:
if (iGameTurn == getTurnForYear(880)):

        gc.getMap().plot(65,52).getPlotCity().changeCulture(100)

Sometimes the parentheses matter. If that doesn't work, have a look at the logs.

I dont know what the problem is but it did not work.
 
Well its in DOC, Leoreth had made a few gameturn scirpts for 640 and 650 ad and i just added 880 under there; just so u know i had successfully done this before but that was for adding units not culture. Here is the code:
Code:
		if (iGameTurn == getTurnForYear(650)):
			if (not gc.getPlayer(0).isPlayable()):
				plotBaghdad = gc.getMap().plot(77,40)
				plotCairo = gc.getMap().plot(69,35)

				Baghdad = plotBaghdad.getPlotCity()
				Cairo = plotCairo.getPlotCity()

				bBaghdad = (plotBaghdad.getOwner() == iArabia)
				bCairo = (plotCairo.getOwner() == iArabia)

				if (bBaghdad and bCairo):
					iRand = gc.getGame().getSorenRandNum(2, "Toss Coin")

					if iRand == 0:
						if utils.getHumanID() != iArabia:
							Baghdad.setHasRealBuilding(con.iPalace, True)
							utils.makeUnit(con.iArabiaCamelarcher, iArabia, (77,40), 3)
							utils.makeUnit(con.iSwordsman, iArabia, (77,40), 2)
						utils.makeUnit(con.iArabiaCamelarcher, iArabia, (77,40), 2)
						utils.makeUnit(con.iSwordsman, iArabia, (77,40), 2)
					else:
						if utils.getHumanID() != iArabia:
							Cairo.setHasRealBuilding(con.iPalace, True)
							utils.makeUnit(con.iArabiaCamelarcher, iArabia, (69,35), 3)
							utils.makeUnit(con.iSwordsman, iArabia, (69,35), 2)
						utils.makeUnit(con.iArabiaCamelarcher, iArabia, (69,35), 2)
						utils.makeUnit(con.iSwordsman, iArabia, (69,35), 2)

					utils.makeUnit(con.iSettler, iArabia, (77,40), 1)
					utils.makeUnit(con.iSettler, iArabia, (69,35), 1)
					utils.makeUnit(con.iWorker, iArabia, (77,40), 1)
					utils.makeUnit(con.iWorker, iArabia, (69,35), 1)

				elif (bBaghdad and not bCairo):
					if utils.getHumanID() != iArabia:
						Baghdad.setHasRealBuilding(con.iPalace, True)
						utils.makeUnit(con.iArabiaCamelarcher, iArabia, (77,40), 3)
						utils.makeUnit(con.iSwordsman, iArabia, (77,40), 2)
					utils.makeUnit(con.iSettler, iArabia, (77,40), 1)
					utils.makeUnit(con.iArabiaCamelarcher, iArabia, (77,40), 2)
					utils.makeUnit(con.iSwordsman, iArabia, (77,40), 2)

					utils.makeUnit(con.iSettler, iArabia, (77,40), 1)
					utils.makeUnit(con.iWorker, iArabia, (77,40), 1)
					utils.makeUnit(con.iWorker, iArabia, (75,33), 1)

				elif (not bBaghdad and not bCairo):
					if utils.getHumanID() != iArabia:
						Cairo.setHasRealBuilding(con.iPalace, True)
						utils.makeUnit(con.iArabiaCamelarcher, iArabia, (69,35), 3)
						utils.makeUnit(con.iSwordsman, iArabia, (69,35), 2)
					utils.makeUnit(con.iSettler, iArabia, (69,35), 1)
					utils.makeUnit(con.iArabiaCamelarcher, iArabia, (69,35), 2)
					utils.makeUnit(con.iSwordsman, iArabia, (69,35), 2)

					utils.makeUnit(con.iSettler, iArabia, (69,35), 1)
					utils.makeUnit(con.iWorker, iArabia, (75,33), 1)
					utils.makeUnit(con.iWorker, iArabia, (69,35), 1)

				else:
					utils.makeUnit(con.iSettler, iArabia, (75,33), 2)
					utils.makeUnit(con.iWorker, iArabia, (75,33), 2)
					if utils.getHumanID() != iArabia:
						utils.makeUnit(con.iArabiaCamelarcher, iArabia, (75,33), 3)
						utils.makeUnit(con.iSwordsman, iArabia, (75,33), 2)
					utils.makeUnit(con.iArabiaCamelarcher, iArabia, (75,33), 2)
					utils.makeUnit(con.iSwordsman, iArabia, (75,33), 2)

		if (iGameTurn == getTurnForYear(700)):

				utils.makeUnit(con.iLongbowman, iVikings, (60,55), 1)

		if (iGameTurn == getTurnForYear(880)):

        		gc.getMap().plot(65,52).getPlotCity().changeCulture(100)
The list is long so u can have an idea to where i put it; the stuff that u wanted me to add is at the end
 
On an unrelated matter, I need some help with the SDK.

As you know, in Rhyes.h the civilization variables are defined. Would it be possible to somehow add a function that defines the variables according to the scenario (3000 BC or 600 AD) in question?
Yes you can, the C preprocessor allows you to add conditions as well, you can then check if Egypt is playable as usual to determine the scenario. It should look like this:
Code:
#if GET_PLAYER(0).isPlayable()
#define EGYPT (0)
[...]
#else
[...]
#endif


Well its in DOC, Leoreth had made a few gameturn scirpts for 640 and 650 ad and i just added 880 under there; just so u know i had successfully done this before but that was for adding units not culture. Here is the code:
Code:
		if (iGameTurn == getTurnForYear(650)):
			if (not gc.getPlayer(0).isPlayable()):
				plotBaghdad = gc.getMap().plot(77,40)
				plotCairo = gc.getMap().plot(69,35)

				Baghdad = plotBaghdad.getPlotCity()
				Cairo = plotCairo.getPlotCity()

				bBaghdad = (plotBaghdad.getOwner() == iArabia)
				bCairo = (plotCairo.getOwner() == iArabia)

				if (bBaghdad and bCairo):
					iRand = gc.getGame().getSorenRandNum(2, "Toss Coin")

					if iRand == 0:
						if utils.getHumanID() != iArabia:
							Baghdad.setHasRealBuilding(con.iPalace, True)
							utils.makeUnit(con.iArabiaCamelarcher, iArabia, (77,40), 3)
							utils.makeUnit(con.iSwordsman, iArabia, (77,40), 2)
						utils.makeUnit(con.iArabiaCamelarcher, iArabia, (77,40), 2)
						utils.makeUnit(con.iSwordsman, iArabia, (77,40), 2)
					else:
						if utils.getHumanID() != iArabia:
							Cairo.setHasRealBuilding(con.iPalace, True)
							utils.makeUnit(con.iArabiaCamelarcher, iArabia, (69,35), 3)
							utils.makeUnit(con.iSwordsman, iArabia, (69,35), 2)
						utils.makeUnit(con.iArabiaCamelarcher, iArabia, (69,35), 2)
						utils.makeUnit(con.iSwordsman, iArabia, (69,35), 2)

					utils.makeUnit(con.iSettler, iArabia, (77,40), 1)
					utils.makeUnit(con.iSettler, iArabia, (69,35), 1)
					utils.makeUnit(con.iWorker, iArabia, (77,40), 1)
					utils.makeUnit(con.iWorker, iArabia, (69,35), 1)

				elif (bBaghdad and not bCairo):
					if utils.getHumanID() != iArabia:
						Baghdad.setHasRealBuilding(con.iPalace, True)
						utils.makeUnit(con.iArabiaCamelarcher, iArabia, (77,40), 3)
						utils.makeUnit(con.iSwordsman, iArabia, (77,40), 2)
					utils.makeUnit(con.iSettler, iArabia, (77,40), 1)
					utils.makeUnit(con.iArabiaCamelarcher, iArabia, (77,40), 2)
					utils.makeUnit(con.iSwordsman, iArabia, (77,40), 2)

					utils.makeUnit(con.iSettler, iArabia, (77,40), 1)
					utils.makeUnit(con.iWorker, iArabia, (77,40), 1)
					utils.makeUnit(con.iWorker, iArabia, (75,33), 1)

				elif (not bBaghdad and not bCairo):
					if utils.getHumanID() != iArabia:
						Cairo.setHasRealBuilding(con.iPalace, True)
						utils.makeUnit(con.iArabiaCamelarcher, iArabia, (69,35), 3)
						utils.makeUnit(con.iSwordsman, iArabia, (69,35), 2)
					utils.makeUnit(con.iSettler, iArabia, (69,35), 1)
					utils.makeUnit(con.iArabiaCamelarcher, iArabia, (69,35), 2)
					utils.makeUnit(con.iSwordsman, iArabia, (69,35), 2)

					utils.makeUnit(con.iSettler, iArabia, (69,35), 1)
					utils.makeUnit(con.iWorker, iArabia, (75,33), 1)
					utils.makeUnit(con.iWorker, iArabia, (69,35), 1)

				else:
					utils.makeUnit(con.iSettler, iArabia, (75,33), 2)
					utils.makeUnit(con.iWorker, iArabia, (75,33), 2)
					if utils.getHumanID() != iArabia:
						utils.makeUnit(con.iArabiaCamelarcher, iArabia, (75,33), 3)
						utils.makeUnit(con.iSwordsman, iArabia, (75,33), 2)
					utils.makeUnit(con.iArabiaCamelarcher, iArabia, (75,33), 2)
					utils.makeUnit(con.iSwordsman, iArabia, (75,33), 2)

		if (iGameTurn == getTurnForYear(700)):

				utils.makeUnit(con.iLongbowman, iVikings, (60,55), 1)

		if (iGameTurn == getTurnForYear(880)):

        		gc.getMap().plot(65,52).getPlotCity().changeCulture(100)
The list is long so u can have an idea to where i put it; the stuff that u wanted me to add is at the end
Step 1: please enable Python exceptions, in case of invalid code they can show you the exact line of your mistake.

Step 2: your indentations are off, it looks like the module falls apart in the previous check (the Viking longbowman) because it's too far indented (two tabs instead of one).
 
Sometimes the parentheses matter.
Like when? Please supply a source for your information, or a sample of code where this is true.

Because you never need to put any expression inside parenthesis in Python, unless you're doing complicated and/or expressions with nested expressions, or unless you wanna be able to completely ignore white space and line breaks in an expression.
 
I think it was meant more like a general advice along the lines of "if in doubt, leave comma out".
 
@embryodead: What do I copy and how do I change it? I'm programming noob :P

You need to update CvPlayer.cpp and CvPlayer.h, as well as CyPlayer.cpp, CyPlayer.h and CyPlayerInterface2.cpp

Take an example variable to use as reference, e.g. m_iPower in CvPlayer.h and CvPlayer.cpp. By looking at all instances of "Power" you can see what you have to do to make your new variable work properly.

Things to do:
- declaration in CvPlayer.cpp/h
- getters/setters in both files i.e. getPower and changePower (for convenience you can have getStability, setStability and changeStability)
- pStream->read/write in CvPlayer::read/write
- declaration of getters/setters in CyPlayer.cpp/h and CyPlayerInterface2.cpp (or CyPlayerInterface1.cpp - doesn't really matter)

So you have to add the code in like 20+ places, but every time you just look at code of m_iPower, getPower etc. copy it and rename it so that it's Stability, not Power. i.e. you see:
Code:
pStream->Read(&m_iPower);
you copy it and paste below:
Code:
pStream->Read(&m_iStability); // LuKo

x20

Then compile and pray.
 
@Baldyr: Like Leoreth said, this was just general advice, I should have made that clearer.
 
Lets just say that people who are copying other people's code tend to do things without knowing what they are doing - or why... And wrapping everything inside parenthesis seems to be a habit that C++ programmers have brought to CivIV Python. Because parenthesis in themselves do nothing - at all - this can be interpreted as proper programming procedure. While its not.
 
Lets just say that people who are copying other people's code tend to do things without knowing what they are doing - or why... And wrapping everything inside parenthesis seems to be a habit that C++ programmers have brought to CivIV Python. Because parenthesis in themselves do nothing - at all - this can be interpreted as proper programming procedure. While its not.

Let me clarify that those "extra" parentheses aren't C++ thing - they're not just proper but absolutely obligatory in just about every major language out there, so everyone who touched programming before has this (proper) habit. Interesingly, they've always pissed me off as useless crap and out of 12 or so languages I've used Python is the first one that had the balls to drop them ;) The result is that I now tend to drop those parentheses as well as semicolons while doing work in other stuff and it drives me nuts. Python is really an oddball that defies many established programming conventions.
 
Go Python! :king:
 
Back
Top Bottom