Tao

hrochland

Prince
Joined
Apr 9, 2006
Messages
2,455
Location
Czech Kingdom
Hey. Hello all Pythonist's. I need your help, please. If I have a civilization with state religion TAO, building_TAO and this civilization was being attacked, building_tao give two units.

If civilization changed religion for next war declare building_TAO give not units.

If left religion_TAO and will next declaration of war, give building two units again.


It can work this code?

PHP:
	def onChangeWar(self, argsList):
		'War Status Changes'
		bIsWar = argsList[0]
		iTeam = argsList[1]
		iRivalTeam = argsList[2]
## TAO start ##
		if bIsWar:
			pTeam2 = gc.getTeam(iRivalTeam)
			if pTeam2.getBuildingClassCount(gc.getInfoTypeForString("BUILDINGCLASS_TAO")) == 1:
				for iPlayerX in xrange(gc.getMAX_CIV_PLAYERS()):
					pPlayerX = gc.getPlayer(iPlayerX)
					if pPlayerX.getTeam() == iTeam:
            if pPlayer.getReligion(gc.getInfoTypeForString('RELIGION_TAOISM')) == 1:
              pPlayer = gc.getPlayer(pCity.plot().getOwner())
              u_bubu = gc.getInfoTypeForString( 'UNIT_AMAZONSWORD' )
              iX = pCity.getX()
              iY = pCity.getY()
              ### unit+promotion ###
              pNewUnit = pPlayer.initUnit( u_bubu, iX, iY, UnitAITypes.UNITAI_SPY, DirectionTypes.NO_DIRECTION )
              pNewUnit.setHasPromotion(gc.getInfoTypeForString( 'PROMOTION_COMBAT1' ), true)
              pNewUnit.setHasPromotion(gc.getInfoTypeForString( 'PROMOTION_COMBAT2' ), true)
              pNewUnit.setName("aaa")
              pNewUnit = pPlayer.initUnit( u_bubu, iX, iY, UnitAITypes.UNITAI_SPY, 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")
              ### message ###
              CyInterface().addMessage(CyGame().getActivePlayer(),false,15,CyTranslator().getText("TXT_KEY_TAO",()),'',0,'Art/Interface/Buttons/Units/Bubu.dds',ColorTypes(44), -1, -1, True,True)
## TAO end ##

thanks and sorry for my English
 
I'm just an apprentice in Python but the answer is no:

if pPlayerX.getTeam() == iTeam: it should be iRivalTeam, like for your pTeam2, the attacked team.

I don't know if there is a better method to get the Players out of the Teams.

You want to getStateReligion not just getReligion: your player needs to have Tao as a State Religion, not just a Religion. This code will work (maybe not the best way):

Code:
	iTao = CvUtil.findInfoTypeNum(gc.getReligionInfo, gc.getNumReligionInfos(),'RELIGION_TAOISM')
	if pPlayerX.getStateReligion() == iTao:

You should not have this (which plot?): pPlayer = gc.getPlayer(pCity.plot().getOwner()). First, you defined pPlayerX and not pPlayer (same goes for your units!), second, I would use this:
Code:
	iX = pPlayerX.getCapitalCity().getX()
	iY = pPlayerX.getCapitalCity().getY()

Now, it should work (except maybe the message, depending on the situation). Note that if you have two Civs in a team, they should both get the units, even if only one Civ has the building.

I did not test a situation of war, peace and war again, but I think it's OK. Test it.

Now, when the mist of the Chinese New Year will fade away, maybe some unicorn from Singapore will come and polish your code...
 
1) If building_Tao is not a world wonder, I will not use == 1 as a check, since the team may have more than 1

2) gc.getInfoTypeForString("RELIGION_TAOISM") is much simpler than the above.

3) If it is only meant for the civ with the building and not each member of the whole team, then there should be a check for the player rather than the team.

4) Makes more sense to spawn it in the city with the building rather than the capital

5) The message is displayed to the active player regardless of who is getting the units.

6) Indentation totally screwed

No longer accepting specific requests anymore unless the idea is fresh and challenging.
 
1) right. > 0 then

2) thanks, I knew there should have been a simpler way...

3) right. We don't need pTeam2 then.

4) I didn't think about that! Not sure yet about how to get the city though.

5) yes, but I don't have the text so didn't bother to look into it. Just saw TXT_KEY_TAO as a message for the active player...

6) oh yeah!

By the way, is there a better way to have the Players that are part of a specific Team?
 
Nope, the only way is to loop through all players to check if they belong to the team.

3) pTeam2 check is still good, since if the team does not even have one building, there is no need to loop through entire player list.

4) If it is a wonder, the exact location could be saved somewhere.
If not, loop through all cities.

Motherland calls has a similar function for reference.
 
Thanks.

Another question:
Code:
iTao = gc.getInfoTypeForString('RELIGION_TAOISM')
if pPlayerX.getStateReligion() == iTao:
works, but not
Code:
if pPlayerX.getStateReligion(gc.getInfoTypeForString('RELIGION_TAOISM')):

It's not the first time that I encounter that. Do you know why?

EDIT: where is Motherland calls (checked your PPPPP)?
EDIT 2: OK, found it in PP.
EDIT 3: Now I know where hrochland got the basis of his code!
 
Because that getstatereligion function is not meant to take in any input
 
Hey . Thank you. I do not know if you as programmers suspect how little I understand you. :(
I folded my code from several others whose parts do what I need .
Unfortunately, I'm not a programmer, so I do not understand completely your advice.
Try to rewrite what I have wrong , please. It will be a big help for me .
I 'll do it for a building , for example :)
Thank you very much.
One more excuse for my English :)
 
Because that getstatereligion function is not meant to take in any input

Of course! grrrr at me :mischief:

@ hrochland: :D

So suppose there are 2 Players in the attacked Team:
1) is the building a world wonder?
2) Does the building provide two units per Player (* 2) or only if built by the civ?
3) Do you want the units to go to the city that built the building or to the capital? If building is world wonder than you cannot have 2 players in the team to receive their units in that city - or rather you can, but is it what you want (both units for Player1 and for Player2 in city with WW)?

EDIT: also the message, what does it say, to whom should it go?

The UNITAI: ATTACK, DEFENSE, CITY_DEFENSE or else?
 
1) Yes , the building is a wonder
2 ) when is wonder built give not units . Every time that someone declares war on civilization . Not when it's a wonder built, but in the case of a declaration of war .
3 ) With the team 's problem . It would be good if the building work for each civlization which has a state religion TAO . ( Then it would be good if the units appearing in the capital . Whether it is a big complication , just wonder ...

All this is part of my plan to distinguish the different religions . All others are unique , just for TAO long time I did not have anything ...
 
When someone declares war , endangered civilization gets 2 units a message:
Temple xy sent two fighters to protect the city

UNITAI: DEFENSE , CITY_DEFENSE
 
Building is World wonder or National Wonder?

If I understand you correctly, it is a World Wonder but you would want every Player who has state religion = Tao and who is attacked (war declaration) to receive two units in their capital city, right? Even if the Civ who has built the building is not attacked?

Also the message, what does it say, to whom should it go?
The UNITAI of the units: ATTACK, DEFENSE, CITY_DEFENSE or else?
EDIT: OK, got the answer for 2 last questions.
 
Just give the init unit no unitai. The proper ai will assigned properly.

Thanks for the info, I've seen that in Platy's work and wondered why. From other modders, I've seen it was assigned.
 
Building is World wonder or National Wonder?

If I understand you correctly, it is a World Wonder but you would want every Player who has state religion = Tao and who is attacked (war declaration) to receive two units in their capital city, right? Even if the Civ who has built the building is not attacked?

Yes
and World wonder. If is possible write so that it work for each civ with tao, is ww ideal solution . Serve anyone who has an active tao :)

Just do not know how difficult it is to write it in this way :blush:
 
Do you need to check the building then?

If they have Tao as a state religion, is it not enough? :)
 
Here it is:
Code:
	def onChangeWar(self, argsList):
		'War Status Changes'
		bIsWar = argsList[0]
		iTeam = argsList[1]
		iRivalTeam = argsList[2]
## TAO start ##
		if bIsWar:
			for iPlayerX in xrange(gc.getMAX_CIV_PLAYERS()):
				pPlayerX = gc.getPlayer(iPlayerX)
				if 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 ##

I guess you can change unit name, unit type etc yourself if you want. The message now should also be changed I guess.

If you want to check if the building Tao has been built, then it is for tomorrow, I'm off for today!
 
Use this if you want the units to spawn in the city with the building:

Code:
		if bIsWar:
			pTeam2 = gc.getTeam(iRivalTeam)
			if pTeam2.getBuildingClassCount(gc.getInfoTypeForString("BUILDINGCLASS_TAO")) > 0:
                                for iPlayer in xrange(gc.getMAX_CIV_PLAYERS()):
                                        pPlayer = gc.getPlayer(iPlayer)
                                        if pPlayer.getBuildingClassCount(gc.getInfoTypeForString("BUILDINGCLASS_TAO")) > 0:
                                                if pPlayer.getStateReligion() == gc.getInfoTypeForString('RELIGION_TAOISM'):
                                                        (loopCity, iter) = pPlayer.firstCity(false)
                                                        while(loopCity):
                                                                if loopCity.getNumRealBuilding(gc.getInfoTypeForString("BUILDING_TAO")) > 0:
                                                                        u_bubu = gc.getInfoTypeForString("UNIT_AMAZONSWORD")
                                                                        pNewUnit1 = pPlayer.initUnit(u_bubu, loopCity.getX(), loopCity.getY(), 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, loopCity.getX(), loopCity.getY(), 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(iPlayer, False, 15, CyTranslator().getText("TXT_KEY_TAO",()), '', 2, 'Art/Interface/Buttons/Units/Bubu.dds', ColorTypes(44), -1, -1, True, True)
                                                                        break
                                                                (loopCity, iter) = pPlayer.nextCity(iter, false)

Note that every player with taoism and the building will get the units, even the attacker if the conditions are met, which I guess is what you wanted?...
 
Back
Top Bottom