Platyping's Python

hmmm problem with the palace moving... would have to look through all cities to find the horses. I guess it's ok though as the code will pretty much never be triggered :p
 
Just make it that Mongols cannot build palace then...
Since Mongols cannot be played by humans, who cares about them :rolleyes:
 
I do :p plus it gives me an oppertunity to do my sophisticated city for loop :lol:

Code:
def vikings(*args):
        "Power of Raiders - More gold from capturing/razing cities and pillaging"
        if len(args) == 3: #doPillageGold
                iImprovement, iOwner, iCurrentGold = args
                if iOwner == eVikings:
                        iGold = int(round((iCurrentGold/100.0) * iVikingPercentMoney))
                        if Game.getActivePlayer() == eVikings:
                                addMessage(sVikingMessage1, (str(iGold),), eGreen)
                        return iGold
                return 0
                        
       else: #onCityAquired
               iNewOwner, pCity, bConquest = args
               if iNewOwner == eVikings and bConquest:
                       iGold = pCity.getPopulation() * iVikingCityGold
                       giveGold(iGold, eVikings)
                       if Game.getActivePlayer() == eVikings:
                               addMessage(sVikingMessage2, (str(iGold), pCity.getName()), eGreen)


def mongols(*args): 
        "Power of the Horde - Horse always present at capital"
        if len(args) == 3: # onCityAcquired
                iPreviousOwner, iNewOwner, pCity = args
                if iPreviousOwner != eMongols != iNewOwner: return
                if iNewOwner == eMongols and pCity.isCapital():
                        lPlots = getCityRadiusTiles(pCity)
                        for pPlot in lPlots: if pPlot.getBonusType(-1) == eHorse: return
                        pPlot = pCity.plot() if pCity.plot().getBonusType(-1) == -1 else getPlot(getRandomCoords([pPlot for pPlot in lPlots if pPlot.getBonusType(-1) == -1 and pPlot.getOwner() == eMongols and pPlot.getFeatureType() != eOasis]))
                        pPlot.setScriptData("Mongol Horse")
                        pPlot.setBonusType(eHorse)

                elif iPreviousOwner == eMongols:
                        for pPlot in getCityRadiusTiles(pCity):
                                if pPlot.getScriptData() == "Mongol Horse":
                                        pPlot.setScriptData("")
                                        pPlot.setBonusType(-1)
                                        pMongols = pointer("Mongolia", CyPlayer)
                        if pMongols.isAlive():
                                lPlots = getCityRadiusTiles(pMongols.getCapitalCity())
                                for pPlot in lPlots: if pPlot.getBonusType(-1) == eHorse: return
                                pPlot = pMongols.getCapitalCity().plot() if pMongols.getCapitalCity().plot().getBonusType(-1) == -1 else getPlot(getRandomCoords([pPlot for pPlot in lPlots if pPlot.getBonusType(-1) == -1 and pPlot.getOwner() == eMongols and pPlot.getFeatureType() != eOasis]))
                                pPlot.setScriptData("Mongol Horse")
                                pPlot.setBonusType(eHorse)
        else:
                pCity, eBuilding = args
                if eBuilding == ePalace and pCity.getOwner() == eMongols:
                        bBreak = False
                        for pOtherCity in (city.GetCy() for city in pointer("Mongolia", PyPlayer).getCityList()):
                                for pPlot in getCityRadiusTiles(pOtherCity):
                                        if pPlot.getScriptData() == "Mongol Horse":
                                                pPlot.setScriptData("")
                                                pPlot.setBonusType(-1)
                                                bBreak = True
                                                break
                                if bBreak: break
                        lPlots = getCityRadiusTiles(pCity)
                        for pPlot in lPlots: if pPlot.getBonusType(-1) == eHorse: return
                                pPlot = pCity.plot() if pCity.plot().getBonusType(-1) == -1 else getPlot(getRandomCoords([pPlot for pPlot in lPlots if pPlot.getBonusType(-1) == -1 and pPlot.getOwner() == eMongols and pPlot.getFeatureType() != eOasis]))
                                pPlot.setScriptData("Mongol Horse")
                                pPlot.setBonusType(eHorse)
 
urg theres a problem. If I put code in onFirstContact, onStateReligionChange and onGameStart. they all clash together for example:

start of game, England gets boost. France meets England, england now at +2.

colony is born, doesn't meet france yet (HIGHLY unlikely), changes state to france's and then meets them +2 attitude.

I think I need code for when a civ becomes alive as opposed to when civs meet
 
@Viking
onPillageGold part looks weird
Who is iOwner? The unit or plot owner?
Now you know why i simply use the default args, makes codes readable :D
Since I dunno what is iCurrentGold, I also dunno what it is about.
If this is onPillageGold where you are returning iGold and 0, does it mean that Vikings get iGold when they pillage while all others get absolutely nothing?
onCityAcquired
Since extra gold is given to Vikings, how about deducting it from the poor victim :D

@Mongol
Getting sleepy, so eyes tired
So just 1 question:
As mentioned, it is possible that when capital is shifted, whether by force or palace, there is already a horse present, so no new source of horse is planted.
However, all you do when you check that there is a horse around the capital, return.
So the horse in the previous capital with script data is removed, and script data removed as well.
But script data is not added to the horse already present in new capital.
Then if this new capital is now captured, you won't detect the script data in the horse plot, and as a result there won't be codes activated
 
@First Contact
Code:
		pTeam = gc.getTeam(iTeamX)
		if pTeam.isVassal(iHasMetTeamY):
			pPlayer = gc.getPlayer(pTeam.getLeaderID())
Only activated when a vassal meets a master.
Only situation is when colony is liberated.
Then just do what is necessary.

Used in most traits, Spiritual, Organized etc

P.S.
Taipei 101 is going to be your good friend for this, since it involves Relationship Bonus
 
this might help:

Code:
	def doPillageGold(self, argsList):
		"controls the gold result of pillaging"
		pPlot = argsList[0]
		pUnit = argsList[1]
		
		iPillageGold = 0
		iPillageGold = CyGame().getSorenRandNum(gc.getImprovementInfo(pPlot.getImprovementType()).getPillageGold(), "Pillage Gold 1")
		iPillageGold += CyGame().getSorenRandNum(gc.getImprovementInfo(pPlot.getImprovementType()).getPillageGold(), "Pillage Gold 2")

		iPillageGold += (pUnit.getPillageChange() * iPillageGold) / 100

		iPillageGold += self.powers.vikings(pPlot.getImprovementType(), pUnit.getOwner(), iPillageGold)

		return iPillageGold

I could deduct the gold, that would be pretty cool!!!

You have a point with that return, originally I thought it wouldn't matter as I don't want natural horses to go. but it will interfer with wether the previous city was the capital... thanks.

also worked out how to fix france :p remove the ongamestart codes and have it so that only if the civ has met france does the state religion affect relations. when they meet france the ongamestart codes are effectively called, making sure it works for everyone (even new players later on)
 
Code:
def mongols(*args): 
        "Power of the Horde - Horse always present at capital"
        if len(args) == 3: # onCityAcquired
                iPreviousOwner, iNewOwner, pCity = args
                if iPreviousOwner != eMongols != iNewOwner: return
                if iNewOwner == eMongols and pCity.isCapital():
                        lPlots = getCityRadiusTiles(pCity)
                        for pPlot in lPlots: if pPlot.getBonusType(-1) == eHorse:
                                pPlot.setScriptData("Natural Horse")
                                return
                        pPlot = pCity.plot() if pCity.plot().getBonusType(-1) == -1 else getPlot(getRandomCoords([pPlot for pPlot in lPlots if pPlot.getBonusType(-1) == -1 and pPlot.getOwner() == eMongols and pPlot.getFeatureType() != eOasis]))
                        pPlot.setScriptData("Mongol Horse")
                        pPlot.setBonusType(eHorse)

                elif iPreviousOwner == eMongols:
                        bCapital = False
                        for pPlot in getCityRadiusTiles(pCity):
                                if pPlot.getScriptData() == "Mongol Horse":
                                        pPlot.setScriptData("")
                                        pPlot.setBonusType(-1)
                                        bCapital = True
                                elif pPlot.getScriptData() == "Natural Horse":
                                        pPlot.setScriptData("")
                                        bCapital = True
                        if bCapital:
                                pMongols = pointer("Mongolia", CyPlayer)
                                if pMongols.isAlive():
                                        lPlots = getCityRadiusTiles(pMongols.getCapitalCity())
                                        for pPlot in lPlots: if pPlot.getBonusType(-1) == eHorse:
                                                pPlot.setScriptData("Natural Horse")
                                                return
                                        pPlot = pMongols.getCapitalCity().plot() if pMongols.getCapitalCity().plot().getBonusType(-1) == -1 else getPlot(getRandomCoords([pPlot for pPlot in lPlots if pPlot.getBonusType(-1) == -1 and pPlot.getOwner() == eMongols and pPlot.getFeatureType() != eOasis]))
                                        pPlot.setScriptData("Mongol Horse")
                                        pPlot.setBonusType(eHorse)
        else:
                pCity, eBuilding = args
                if eBuilding == ePalace and pCity.getOwner() == eMongols:
                        bBreak = False
                        for pOtherCity in (city.GetCy() for city in pointer("Mongolia", PyPlayer).getCityList()):
                                for pPlot in getCityRadiusTiles(pOtherCity):
                                        if pPlot.getScriptData() == "Mongol Horse":
                                                pPlot.setScriptData("")
                                                pPlot.setBonusType(-1)
                                                bBreak = True
                                                break
                                        elif pPlot.getScriptData() == "Natural Horse":
                                                pPlot.setScriptData("")
                                                bBreak = True
                                                break
                                if bBreak: break
                        lPlots = getCityRadiusTiles(pCity)
                        for pPlot in lPlots:
                                if pPlot.getBonusType(-1) == eHorse:
                                        pPlot.setScriptData("Natural Horse")
                                        return
                                pPlot = pCity.plot() if pCity.plot().getBonusType(-1) == -1 else getPlot(getRandomCoords([pPlot for pPlot in lPlots if pPlot.getBonusType(-1) == -1 and pPlot.getOwner() == eMongols and pPlot.getFeatureType() != eOasis]))
                                pPlot.setScriptData("Mongol Horse")
                                pPlot.setBonusType(eHorse)

when a horse is natural it becomes a mongol horse meaning a capital can be detected without killing the horse :p

edit: done. See above again :D

edit edit:

and france:

Code:
def france(*args): 
        "Power of Chivalry - +1 relations with Civs of state religion"
        if len(args) = 3: #onChangeStateReligion
                iPlayer, iNewReligion, iOldReligion = args
                pPlayer = gc.getPlayer(iPlayer)
                if iPlayer != eFrance:
                        pFrance = pointer("France", CyPlayer)
                        if pFrance.canContact(iPlayer):
                                if iNewReligion == pFrance.getStateReligion():
                                        pPlayer.AI_changeAttitudeExtra(eFrance, iFrenchRelations)
                                elif iOldReligion == pFrance.getStateReligion():
                                        pPlayer.AI_changeAttitudeExtra(eFrance, -iFrenchRelations)
                else:
                        for pPlayer in CivPlayer.getPlayers(True, CyPlayer):
                                if pPlayer.canContact(eFrance):
                                        ePlayerReligion = pPlayer.getStateReligion()
                                        if ePlayerReligion == iNewReligion:
                                                pPlayer.AI_changeAttitudeExtra(eFrance, iFrenchRelations)
                                        elif ePlayerReligion == iOldReligion:
                                                pPlayer.AI_changeAttitudeExtra(eFrance, -iFrenchRelations)
                return

        elif len(args) == 2: #onFirstContact
                iPlayerX, iPlayerY = args
                if iPlayerX == eFrance or iPlayerY == eFrance:
                        pFrance = pointer("France", CyPlayer)
                        pPlayer = gc.getPlayer(iPlayerX if iPlayer != eFrance else iPlayerY)
                        if pPlayer.getStateReligion() == pFrance.getStateReligion():
                                pPlayer.AI_changeAttitudeExtra(eFrance, iFrenchRelations)

this should work fine. note the use of the ternary operator (:love:) :lol:
 
Hi,
please, is in python possible write:
When I have in one city Building XY and Unit ABC1 with 5 experience points - unit ABC1 will be replaced by ABC2 unit?
 
:eek::eek: The Ternary operator was added in python 2.5 and civ4 is python 2.4!!! I can't use it :(
 
hmm I have a bug in the french code:

Code:
def france(*args): 
        "Power of Chivalry - +1 relations with Civs of state religion"
        if len(args) == 3: #onChangeStateReligion
                iPlayer, iNewReligion, iOldReligion = args
                pPlayer = gc.getPlayer(iPlayer)
                if iPlayer != eFrance:
                        pFrance = pointer("France", CyPlayer)
                        if pFrance.canContact(iPlayer):
                                if iNewReligion == pFrance.getStateReligion():
                                        pPlayer.AI_changeAttitudeExtra(eFrance, iFrenchRelations)
                                elif iOldReligion == pFrance.getStateReligion():
                                        pPlayer.AI_changeAttitudeExtra(eFrance, -iFrenchRelations)
                else:
                        for pPlayer in CivPlayer.getPlayers(True, CyPlayer):
                                if pPlayer.canContact(eFrance):
                                        ePlayerReligion = pPlayer.getStateReligion()
                                        if ePlayerReligion == iNewReligion:
                                                pPlayer.AI_changeAttitudeExtra(eFrance, iFrenchRelations)
                                        elif ePlayerReligion == iOldReligion:
                                                pPlayer.AI_changeAttitudeExtra(eFrance, -iFrenchRelations)
                return

        elif len(args) == 2: #onFirstContact
                iPlayerX, iPlayerY = args
                if iPlayerX != eFrance != iPlayerY: return
                pFrance = pointer("France", CyPlayer)
                if iPlayerX != eFrance:
                        pPlayer = gc.getPlayer(iPlayerX)
                else:
                        pPlayer = gc.getPlayer(iPlayerY)   
                if pPlayer.getStateReligion() == pFrance.getStateReligion():
                        pPlayer.AI_changeAttitudeExtra(eFrance, iFrenchRelations)

it gives double the relations boost... this is on turn 1 where the apostolic palace causes everyone to meet each other, like the first contact is happening twice... ah! it must be france meets england then england meets france :lol: thanks for the inspiration there :p
 
@Jamie
Since you are pretty much answering your own questions, I guess I can skip the troubles of looking through the codes?
Anyway, since these are codes that you are not familiar with, I seriously suggest you test them in all sorts of possible situations yourself.
Some common ones that I do test myself when doing some new stuff:
City Acquire codes, both due to conquer, as well as due to trade.
Liberalisation of colonies, this is easy, just start a archaepaelogo(god knows the spelling) map
Change of Religion codes, do all sorts of combinations, from no religion to some religion, from religion X to Y, from some religion to no religion. Also, since mine are wonders, I will also do the same test when I am not the wonder owner.

Come to think of it, actually Charismatic Trait is even closer to your French Power than Taipei 101, if you still having problems.

As for your mongol powers, you will have to set mongol as playable, and test all those capital shifting codes.
 
@Hrochland
Code:
	def onUnitBuilt(self, argsList):
		'Unit Completed'
		city = argsList[0]
		unit = argsList[1]
		player = PyPlayer(city.getOwner())
## Flavian Amphitheatre Start ##
		if city.getNumActiveBuilding(gc.getInfoTypeForString("BUILDING_FLAVIAN_AMPHITHEATRE")):
			pPlayer = gc.getPlayer(city.getOwner())
			if unit.getUnitType() == gc.getInfoTypeForString("UNIT_PLATYPING"):
				if unit.getExperience() > 4:
					pNewUnit = pPlayer.initUnit(gc.getInfoTypeForString("UNIT_HROCHLAND"), unit.getX(), unit.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.NO_DIRECTION)
					pNewUnit.convert(unit)
## Flavian Amphitheatre End ##

This code is assuming there is no Unique Unit for both Unit Types, otherwise, more codes.
This works if the unit has 5 or more EXP. If you only want it to be trigger only when exactly 5 EXP, change the experience line to == 5 instead of > 4.
This code assumes that the 2 Units are of the same Unit Class, else experience and promotions may be given wrongly, because it is using convert.
For instance, if you have Protective Trait which gives promotions to archery unit.
If first unit is archery class, promotions are given correctly.
If second unit is NOT archery class, promotions are still transferred to it due to convert function.
 
I can't believe you named a unit after yourself :lol:
 
oh don't worry my first ever mod had me as a leader :D

I like to read others code :p then I can optimise it :mischief: (like when I tell you to use xrange :lol:)

also just noticed that hrochland seems to be a more upgraded version of yourself :lol:
 
Never mention anything about upgrade.
It is just converting a unit of UNITCLASS CODER to UNITCLASS ARTIST :D
 
Version 3.1:

Nanite Defuser

Removed Mahattan and No Uranium Requirements.
Added Bomb Shelter as Requirements.
No longer need callback

Banaue Rice Terrace
Removed City on Hills Requirements
No longer need cannotConstruct Callback, but still need canBuild Callback
Although it is more accurate to require hills, I guess it is better to take it out since not a big deal right, since that is not the main essense of the wonder :D

Hibernia Platform
Changed from checking whether unit requires oil as bonus, to simply mechanical unit.
Since ALL late game mechanical unit needs oil, this is a simpler check.

Crazy Horse Memorial
Removed Peak Requirements

Trans-Siberian Railway
Remake whole thing
Old one: Builds Railroad in 1 turn. Uses onUnitBuildImprovement which is called frequently.
New one: Increases Railroad movement, the benefit taken out from Channel Tunnel.
Now it is simply build and forget project, codes only applied once, that's it.

Panama Canal
1) Randomised choice of directions when > 1 direction are of the same minimum length. (IE if West and South are both of length 1, it will now choose either West or South, rather than always West according to order of codes)
2) Rewrite Relocation of Bonus codes using canHaveBonus.
Now Bonus is randomly relocated to suitable plot in whole empire.
It now chooses according to this order
A) suitable plot which is not city
B) suitable plot which is city
C) if no suitable plot, add it to the capital itself directly
3) Fixed wrong Movie Link

Golden Gate Bridge
1) Randomised choice of directions similar to Panama Canal
2) It now builds the bridge in the nearest direction rather than the furthest direction

Nuclear Non Proliferation Treaty
1) It no longer uses AI Choose Production codes. Now it uses the TechShare method similar to other projects. No more interference with AI decisions.
2) It is now unbuildable if player has uranium. If you have nukes, you wouldn't want to build this project.

Treaty of Versailles
1) It no longer uses AI Choose Production codes. Now it uses the TechShare method similar to other projects. No more interference with AI decisions.
2) It is now buildable only during Wars.

Movie File Error
Oriental Crown's Movie was stored in Movie Pack, when it should be in Gigapack
Movie Link was missing for it as well in Gigapack
1) Took out Oriental Crown 's Movie from Movie Pack
2) Put inside Gigapack
3) Added Movie Link for it


Movie Pack, Megapack, Gigapack updated
Panama Canal Added to Gigapack


Future Plans:
Remake/Edit certain wonders that are still weak in performance, but effects not that outstanding.

Great Mosque of Djenne
Using 2 Callbacks, effects not outstanding to justify

Compass Rose
Uses onUnitMove, effects not outstanding to justify.
Tried to simply give a promotion that provides the coastal movement bonus, but sadly, it does nothing at all...
 
I just found out that xrange is BOTH faster AND more memory efficient. So if I were you I would go and make sure they are used in all your codes.

for the compass rose if you are not too concerned about teams you could use the method I used in the spain power? just say provides movement boost for team :D
 
Actually xrange is already used in all big loops for Megapack and Gigapack.
Small loops like for i in range (3), actually range or xrange does not matter at all.
It is true that xrange is more efficient, but the difference is only slightly significant, when the loops are in the thousands or even hundred thousands.
Standalones, I seriously can't be bothered to upload 200 works just for that.
After all, if you are using standalones, I assume you are using less than 10 of them, so not a big deal :D

@Compass Rose
That benefit already given by Magellan's Voyage
 
Back
Top Bottom