Simple Python Things

Nice to see some stuff out before the holidays, and no problem about my request being @#$@#$%@ hard. :)
 
Could someone provide the code for a unit that, if killed or attacked, gives war-weariness to the attacker?

This would be a non-violent unit that can only be built by pacifist civic-civs. It cannot attack.

During Gandhi's days in India, the Satyagrahi took non-violent action against the colonial rulers, and was willing to die for the cause.

In the game, attacking and eliminating these units should cause the attacking civ to stop the war, either by increased war-weariness or unhappiness at home or some similar mechanism. Maybe the attacking civ's civics could be a mitigating factor, or attacking a Satyagrahi unit would cause other civs to dislike the attacking civ.

Any help is appreciated.
 
Sadly, i'm out of modding until beginning of january :(.

But let's think about the idea:
- Civic as prerequisite: Easy
- War weariness after defeat: Shouldn't be a problem.
- Dependend on civic: That's just boring work, but would need testing.
- AI: Well...AI would have not clue about that, and would just attack. If the unit is not weaker as normal units, then the AI would build it, i guess.

If you don't want to wait, then you could try to do some work on your own/implementing the thing with help from me, it shouldn't be a big problem.
If not, i'll take it on the list, but it will take some time (like said above).
 
Thanks for your honest reply, I certainly can wait. I appreciate any time you can put into it.
 
Attention: The sneak promotion is bugged.
Got today a bug report from a user playing my mod, wo says, that if the sneak promotion works, it resets all the spy points of winner and loser, besides the ones, which are gained through the current combat.
This applies also to the download here.
Like said, i can't fix it at the moment, you if you have the promotion in your mod, you should maybe disable it.
 
^Thanks for telling us; that could be a bit problematic. :( But thanks for telling us, anyways.
 
Hello again, I have a question concerning your SpawnACiv, as I am starting to merge it into the next version of WoL.

Basically, would SpawACiv function the same in a scenario/worldbuilder save?

For example, let's say I have a barbarian civ, the Goths, that appear once 1 civ researches Iron Working. If I have a scenario/worldbuilder save that starts in the Industrial Era, that means that a majority of the civs will already have researched Iron Working. Will the Goths suddenly appear out of the blue and "mess up" my scenario/worldbuilder save, or will they not appear at all?

:)


EDIT: Okay, so I guess I have another request for the SpawnACiv modcomp. Basically, to make the long story short, in WoL, I plan to make civs also get one barbarian hero unit when they spawn (i.e. the Huns will get an Attila the Hun hero who will rampage and destroy everything in its path :D). Anyhow, a slight problem comes up for me - if, say, I want a civ that has more than one city, that means there'd be more than one hero unit.

I have then two requests for you, and if you want to do them, you can choose the one that's easier :D.

1. Make the barb civs also get settlers, besides workers. This one probably is the one other people can find useful too, since it'd also make these guys pretty dangerous.

2. Make an option to somehow limit a unit to only the capital, and not other cities. THis is probably not going to be fun...

Anyhow, you don't need to do this request (and if you do again I'm not rushing you), and thanks for your patience and help! :D
 
Hello again, I have a question concerning your SpawnACiv, as I am starting to merge it into the next version of WoL.

Nice to hear that :D.

Basically, would SpawACiv function the same in a scenario/worldbuilder save?

For example, let's say I have a barbarian civ, the Goths, that appear once 1 civ researches Iron Working. If I have a scenario/worldbuilder save that starts in the Industrial Era, that means that a majority of the civs will already have researched Iron Working. Will the Goths suddenly appear out of the blue and "mess up" my scenario/worldbuilder save, or will they not appear at all?

:)

If there's space for another civ, then the goths will appear, when the next civ researches iron working. If nobody does that, then they'll not appear.

1. Make the barb civs also get settlers, besides workers. This one probably is the one other people can find useful too, since it'd also make these guys pretty dangerous.

Instead of giving them 2 types of combat units, you could also give them settlers instead ;).

2. Make an option to somehow limit a unit to only the capital, and not other cities. THis is probably not going to be fun...

In fact, that's relativly easy ;).

Anyhow, you don't need to do this request (and if you do again I'm not rushing you), and thanks for your patience and help! :D

I'll do it, when i have the time for it.
But it will probably last some time, because there are a few requests, and i want to get my patch out in the next week.
 
If there's space for another civ, then the goths will appear, when the next civ researches iron working. If nobody does that, then they'll not appear.

Alright, so basically I just need to give everybody certain techs. That's a bit of a hassle, but one I'm totally cool with. :D


Instead of giving them 2 types of combat units, you could also give them settlers instead ;).

The problem is that (if I remember correctly, and correct me if I'm wrong) in the xml I can only specify 2 units. In WoL, if I were to have settlers, the "first" unit would be the Barbarian Hero, and then the "second" unit would be the settlers, yes, but then there'd be no space to put in all the humongous barbarian armies that will come rampaging into the other civilizations, so that's why I can't do that.



In fact, that's relativly easy ;).

Really? I'm surprised.



I'll do it, when i have the time for it.
But it will probably last some time, because there are a few requests, and i want to get my patch out in the next week.

Thanks for your patience and willingness to help. Your work is always appreciated. :goodjob:
 
@The J:

Small request: how can I add some culture to all cities of a civ after finishing a project?
For example I'd like to add the Lascaux Cave Painting Project which will add some culture to all cities of the civ that finishes the project.
In CvEventManager.py I found this:
Code:
	def onProjectBuilt(self, argsList):
		'Project Completed'
                etc., etc.

Any idea?
 
That shouldn't be a problem.

PHP:
	def onProjectBuilt(self, argsList):
		'Project Completed'
		pCity, iProjectType = argsList
		game = gc.getGame()
####from here on
		if iProjectType == gc.getInfoTypeForString("PROJECT_WHATEVER"):
			iPlayerID = pCity.getOwner()
			pPlayer = gc.getPlayer(iPlayerID)
			numCities = pPlayer.getNumCities ()
			for i in xrange(numCities):
				CurrentCity = pPlayer.getCity(i)
				if (not CurrentCity.isNone()) and (CurrentCity.getOwner()==iPlayerID):
					pCity.changeCulture(iPlayerID, TheNumberOfCultureWhichShouldBeAdded,True)


Can't test it, i'm still not at my civ pc :(.
 
You should be adjusting the culture for "CurrentCity", not "pCity", on that last line.

Also, you should probably use the player's city iterator for looping over all the players's cities rather than looping over the numCities range.
 
You should be adjusting the culture for "CurrentCity", not "pCity", on that last line.

:blush: oops, right.
That happens, if you're not 100% concentrated.

Also, you should probably use the player's city iterator for looping over all the players's cities rather than looping over the numCities range.

Only a performance difference, i guess?
 
Only a performance difference, i guess?

I'm pretty sure you could miss a one or more cities. The city list can have holes in the ID numbers. The list is resorted (or something like that) from time to time - maybe every turn, maybe not, I'm not sure. But the net result is that for a while you can have, for example, a player with 10 cities numbered 0, 1, 2, 3, 4, 6, 7, 8, 9, 10 (no city number 5). If you loop over range(iNumCities), where iNumCities would be 10, you will loop over the 10 cities numbered 0 through 9 (skipping city 5 due to the isNone check) and not do city 10.

This probably only happens when one (or more) of your cities is lost, whether by being captured via military force, culturally flipped, or by freeing some as a colony. Since this sort of thing doesn't happen very often, looping over the number of cities rarely has a problem. Since you are checking the isNone before trying to manipulate it you shouldn't get a crash when you hit the hole, just not process the cities off the end of your range.

This was brought up in some thread elsewhere - I think it was in the SDK/Python forum. Someone hit a situation where they had a crash caused by trying to manipulate a unit that no longer existed (one of the missing numbers in the unit list, which has the same problem, but it happens more often) - the city version of the situation also came up since they both have iterators. The above info is from my recollection of what was said there by people familiar with the SDK's unit and city management.
 
Ah, yes, i remember, what you mean (this thread).
I thought, that i had catched this errors through the 2 checks, but you're right, that's still wrong.

@Arian: Okay, then instead of the whole part beginning from "for i in xrange" use:

PHP:
		(loopCity, iter) = self.player.firstCity(false)
		while(loopCity):
			cityOwner = loopCity.getOwner()
			if ( not loopCity.isNone() and loopCity.getOwner() == self.getID() ): #only valid cities
				loopCity.changeCulture(iPlayerID, TheNumberOfCultureWhichShouldBeAdded,True) 
			(loopCity, iter) = self.player.nextCity(iter, false)

I've stolen this codepart from TC01, from the above mentioned thread.
 
In combination with BUG 4.2 it doesn't seem to work.

Here the Python:
HTML:
	def onProjectBuilt(self, argsList):
		'Project Completed'
		pCity, iProjectType = argsList
		game = gc.getGame()
		if ((not gc.getGame().isNetworkMultiPlayer()) and (pCity.getOwner() == gc.getGame().getActivePlayer())):
			popupInfo = CyPopupInfo()
			popupInfo.setButtonPopupType(ButtonPopupTypes.BUTTONPOPUP_PYTHON_SCREEN)
			popupInfo.setData1(iProjectType)
			popupInfo.setData2(pCity.getID())
			popupInfo.setData3(2)
			popupInfo.setText(u"showWonderMovie")
			popupInfo.addPopup(pCity.getOwner())

		## LASCAUX CAVE PAINTINGS - START ## 
		if iProjectType == gc.getInfoTypeForString("PROJECT_LASCAUX"): 
			iPlayerID = pCity.getOwner()
			pPlayer = gc.getPlayer(iPlayerID)
			numCities = pPlayer.getNumCities()
			TheNumberOfCultureWhichShouldBeAdded = 20
			(loopCity, iter) = self.player.firstCity(false) ## line 961
			while(loopCity):
				cityOwner = loopCity.getOwner()
				if ( not loopCity.isNone() and loopCity.getOwner() == self.getID() ): #only valid cities
					loopCity.changeCulture(iPlayerID, TheNumberOfCultureWhichShouldBeAdded,True) 
				(loopCity, iter) = self.player.nextCity(iter, false)
		## LASCAUX CAVE PAINTINGS - END ##

and here the PythonErr.log:

Code:
Traceback (most recent call last):
  File "BugEventManager", line 350, in _handleDefaultEvent
  File "CvEventManager", line 961, in onProjectBuilt
AttributeError: BugEventManager instance has no attribute 'player'

and here the BugEventManager:
HTML:
	def _handleDefaultEvent(self, eventType, argsList):
		if self.EventHandlerMap.has_key(eventType):
			for eventHandler in self.EventHandlerMap[eventType]:
				try:
					eventHandler(argsList) ## line 350
				except:
					BugUtil.trace("Error in %s event handler %s", eventType, BugUtil.escapeXml(eventHandler))

What's wrong?? :confused:
 
Reference this:

http://forums.civfanatics.com/showpost.php?p=8634471&postcount=259

wondering if

Code:
castesystem = gc.getInfoTypeForString( "CIVIC_CASTE_SYSTEM" )
                        iPlayer = pPlot.getOwner()
                        pPlayer = gc.getPlayer(iPlayer)
                        if (pPlayer.isCivic(castesystem)==True):
this should be:

Code:
caste_system = gc.getInfoTypeForString( "CIVIC_CASTE_SYSTEM" )
                        iPlayer = pPlot.getOwner()
                        pPlayer = gc.getPlayer(iPlayer)
                        if (pPlayer.isCivic(caste_system)==True):
because for some reason, it used to work this way 1st code, now its not working at all?:confused:
 
Top Bottom