Tao

1) Add alive check
2) If I understand correctly, what he wants is this.
If world wonder x is built, when any player with state religion Taoism is attacked, spawn 2 units at his capital.
Neither solution is the situation then.

@ Unit AI
No unit AI is the safest, because it is easy to copy and paste.
Assigning a specific unit AI may screw things when you assign to units that should not get it.
For instance, assigning attack city to workers.
Sometimes specific ones are assigned because that is the intention.
 
So, he wants this:

Code:
		if bIsWar:
                        if gc.getGame().getBuildingClassCreatedCount(gc.getInfoTypeForString("BUILDINGCLASS_TAO")) > 0:
                                pPlayer = gc.getPlayer(iRivalTeam)
                                if pPlayer.getStateReligion() == gc.getInfoTypeForString("RELIGION_TAOISM"):
                                        iX = pPlayer.getCapitalCity().getX()
                                        iY = pPlayer.getCapitalCity().getY()
                                        u_bubu = gc.getInfoTypeForString("UNIT_AMAZONSWORD")
                                        pNewUnit1 = pPlayer.initUnit(u_bubu, iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.NO_DIRECTION)
                                        pNewUnit1.setHasPromotion(gc.getInfoTypeForString( 'PROMOTION_COMBAT1' ), true)
                                        pNewUnit1.setHasPromotion(gc.getInfoTypeForString( 'PROMOTION_COMBAT2' ), true)
                                        pNewUnit1.setName("I want a drink!")
                                        pNewUnit2 = pPlayer.initUnit(u_bubu, iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.NO_DIRECTION)
                                        pNewUnit2.setHasPromotion(gc.getInfoTypeForString( 'PROMOTION_COMBAT1' ), true)
                                        pNewUnit2.setHasPromotion(gc.getInfoTypeForString( 'PROMOTION_COMBAT2' ), true)
                                        pNewUnit2.setHasPromotion(gc.getInfoTypeForString( 'PROMOTION_COMBAT3' ), true)
                                        pNewUnit2.setName("Miss Meh")
                                        CyInterface().addMessage(iRivalTeam, False, 15, CyTranslator().getText("TXT_KEY_TAO",()), '', 2, 'Art/Interface/Buttons/Units/Bubu.dds', ColorTypes(44), iX, iY, True, True)
 
Nope, you cannot use player id as an input to gc.getTeam().
Screwed when you have multiple members.

And the building check only checks if the wonder was built, but not whether it still exists.
 
Nope, you cannot use player id as an input to gc.getTeam().
Screwed when you have multiple members.

Screwed in what way? Do you mean that he only wants the player that specifically gets the war declaration to get the units? Isn't the whole team being attacked?

And the building check only checks if the wonder was built, but not whether it still exists.

Do you know the API by heart or something?:D
Yeah, yeah count created, bla bla. Well, then I can only come up with a loop, I don't think there's a cygame function for that. Anyway the solution is not hard now. He can figure it out.
 
Player id = team id if and only if all teams consist of 1 member each.
If I have 2 teams of 5 members each, using team id as an input will just give me players 0 and 1, which is obviously not what I want.

Write 400 python works in 2 years and you will know it as well.
 
If you do not specify a unit AI type (or, more accurately, specify UnitAITypes.NO_UNITAI) it will use the one given in the XML in the DefaultUnitAI tag. If the XML is done correctly this will always be a unit AI type that is good for that unit to have.

You should only specify a unit AI if you are creating units for some specific role, and in that case you have to make sure the unit and unit AI combination you are using is a good one. For example: if you are creating some units to go attack a city, they should mostly get the city attack unit AI and they should be units that are allowed to both attack and capture a city. Adding a scout to the stack with that unit AI would be a bad idea.
 
Thank you to all contributors to this thread!

Here is the code now as I see it with my amateur eyes:
Code:
## TAO start ##
		if bIsWar and gc.getGame().getBuildingClassCreatedCount(gc.getInfoTypeForString("BUILDINGCLASS_TAO")) > 0:
			for iPlayerX in xrange(gc.getMAX_CIV_PLAYERS()):
				pPlayerX = gc.getPlayer(iPlayerX)
				bTao = False
				(loopCity, iter) = pPlayerX.firstCity(false)
				while(loopCity):
					if loopCity.getNumRealBuilding(gc.getInfoTypeForString("BUILDING_TAO")) > 0:
						bTao = True
						break
					(loopCity, iter) = pPlayerX.nextCity(iter, false)
				for iPlayerX in xrange(gc.getMAX_CIV_PLAYERS()):
					pPlayerX = gc.getPlayer(iPlayerX)
					if bTao == True and pPlayerX.getTeam() == iRivalTeam and pPlayerX.getStateReligion() == gc.getInfoTypeForString('RELIGION_TAOISM'):
						u_bubu = gc.getInfoTypeForString( 'UNIT_AMAZONSWORD' )
						iX = pPlayerX.getCapitalCity().getX()
						iY = pPlayerX.getCapitalCity().getY()
						### unit+promotion ###
						pNewUnit = pPlayerX.initUnit( u_bubu, iX, iY, UnitAITypes.UNITAI_CITY_DEFENSE, DirectionTypes.DIRECTION_SOUTH )
						pNewUnit.setHasPromotion(gc.getInfoTypeForString( 'PROMOTION_COMBAT1' ), true)
						pNewUnit.setHasPromotion(gc.getInfoTypeForString( 'PROMOTION_COMBAT2' ), true)
						pNewUnit.setName("aaa")
						pNewUnit = pPlayerX.initUnit( u_bubu, iX, iY, UnitAITypes.UNITAI_CITY_DEFENSE, DirectionTypes.DIRECTION_SOUTH )
						pNewUnit.setHasPromotion(gc.getInfoTypeForString( 'PROMOTION_COMBAT1' ), true)
						pNewUnit.setHasPromotion(gc.getInfoTypeForString( 'PROMOTION_COMBAT2' ), true)
						pNewUnit.setHasPromotion(gc.getInfoTypeForString( 'PROMOTION_COMBAT3' ), true)
						pNewUnit.setName("bbb")
						### message ###
						CyInterface().addMessage(iPlayerX,false,15,CyTranslator().getText("TXT_KEY_TAO",()),'',0,'Art/Interface/Buttons/Units/Bubu.dds',ColorTypes(44), -1, -1, True,True)
## TAO end ##

The first check is there as Platy suggested only to start the code or not depending whether the building is created in the first place. Note: is it like the building has to be actually built or could it have been created otherwise?

Then (correct me if I'm wrong) we have two loops, one to check if the building still exists somewhere, then to check if the Civ is attacked and has the state religion as Taoism. I did it in two loops because I was afraid that otherwise the code would only apply to the civ who has the building, which is not what hrochland wants.

About the UNITAI. Since hrochland wants defenders for the city, I assigned the AI. I have no idea about that AMAZONSWORD, I have not met her personally... This is of course easily changeable.

The code works as such. The next step is to improve it!

EDIT: hrochland, do you really have that 'Bubu.dds'?
 
Part with bubu.dds and AMAZONSWORD is from code in my mod . Are existing . On the site AMAZONSWORD will, however, another unit. Many thanks you all .
For three hours I get home, will make model and try everything :) I'll know here how it works :) Thanks again
Hroch

EDIT: if is this idea for somebody interesantas for me, i can release it for all in database as minimod... ( with many authors :) )
 
Check when you give up trying

Spoiler :
Code:
## TAO start ##
		if bIsWar:
			pTeam = gc.getTeam(iTeam)
			pRivalTeam = gc.getTeam(iRivalTeam)
			if not (pTeam.isBarbarian() or pRivalTeam().isBarbarian()):
				for iTeamX in xrange(gc.getMAX_CIV_TEAMS()):
					pTeamX = gc.getTeam(iTeamX)
					if pTeamX.getBuildingClassCount(gc.getInfoTypeForString("BUILDINGCLASS_TAO")):
						u_bubu = gc.getInfoTypeForString("UNIT_AMAZONSWORD")
						for iPlayerX in xrange(gc.getMAX_CIV_PLAYERS()):
							pPlayerX = gc.getPlayer(iPlayerX)
							if pPlayerX.getStateReligion() != gc.getInfoTypeForString("RELIGION_TAOISM"): continue
							if pPlayerX.getTeam() != iRivalTeam: continue
							if pPlayerX.getNumCities() < 1: continue
							if not pPlayerX.isAlive(): continue
							iX = pPlayerX.getCapitalCity().getX()
							iY = pPlayerX.getCapitalCity().getY()
							pNewUnit = pPlayerX.initUnit( u_bubu, iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.NO_DIRECTION)
							pNewUnit.setHasPromotion(gc.getInfoTypeForString( 'PROMOTION_COMBAT1' ), true)
							pNewUnit.setHasPromotion(gc.getInfoTypeForString( 'PROMOTION_COMBAT2' ), true)
							pNewUnit.setName("aaa")
							pNewUnit = pPlayerX.initUnit( u_bubu, iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.NO_DIRECTION)
							pNewUnit.setHasPromotion(gc.getInfoTypeForString( 'PROMOTION_COMBAT1' ), true)
							pNewUnit.setHasPromotion(gc.getInfoTypeForString( 'PROMOTION_COMBAT2' ), true)
							pNewUnit.setHasPromotion(gc.getInfoTypeForString( 'PROMOTION_COMBAT3' ), true)
							pNewUnit.setName("bbb")
							CyInterface().addMessage(iPlayerX,false,15,CyTranslator().getText("TXT_KEY_TAO",()),'',0,pNewUnit.getButton(),ColorTypes(44), -1, -1, True,True)
						break
## TAO end ##
 
OK, thank you Master Platy :king:

A loop for teams instead of players avoid an additional loop for buildings but still you need two loops as I thought.

What I don't really understand is this if:
Code:
if not (pTeam.isBarbarian() or pRivalTeam().isBarbarian()):
: I thought that Barbs could not declare war or be declared war as war with them is permanent from the start of the game anyway.

PS: and you changed the direct reference to the button of the unit to pNewUnit.getButton()...
 
The first loop is to check that the wonder exists somewhere.
You cannot use createdCount as a test as I already stated it only checks that it was built before only. It could have been razed.

@Barbs
This code is actually triggered directly at game start when barbs declare war upon everyone too.
Although generally, nobody will start a game with a state religion, but it is possible in scenarios so it is good habit.

Obviously use getButton() is a better way since you don't have to change the code if you change the button, unless that bubu.dds is not the unit button.

A more advanced method is to declare a variable that stores whether the wonder is already built, so there is no need for the first loop.
 
I understood you about the createdCount but if the building was not even created, then there is no use at all to run the code. I was then checking if the building still existed through a loop on cities with my first loop on players.

Noted for Barbs and for unit button, thanks.
 
Not true, it could have been placed via WB
 
OK, that's why I asked earlier on: "Note: is it like the building has to be actually built or could it have been created otherwise?". I suppose that if a GP builds it, it is still a creation counted.

My answer to WB is "damn cheaters, you don't deserve free warriors!" :D
 
I'm sorry, yesterday I was at home without the Internet.
I tried the code. I provoked Asoka, declared war on me, but no troops appeared :(

EDIT: I tried last code by platy
 
Proves that it is written from memory and not c&p. :D
I would even add a check for vassals so that you don't get 10 units when one team with 4 vassals declare war on you.
 
Sure. I'm very happy to wait. This is an excellent idea with wassal prevention. :)
The problem is that I do not see parentheses to pRivalTeam. It's (iRivalTeam) and there should be, I think. Sorry I do not work with python... I could be wrong
 
In the code posted above, in post #29, the 5th line says "if not (pTeam.isBarbarian() or pRivalTeam().isBarbarian()):". That "pRivalTeam()" should have no parenthesis since it is not a function it is a variable: "pRivalTeam".
 
Wow. The line now looks like this:
if not pTeam.isBarbarian() or pRivalTeam().isBarbarian():
I was attacked by a code assigned two units. I have yet to try a situation where the state is attacked, he has state religion Tao and has not builded Tao_wonder :)
Thank you all very much and I will write how it goes :)
thanks again
 
Back
Top Bottom