Platyping's Python

@Hrochland
Ah you are using Jamie's version, then you should ask him lol
Anyway, looking at Jamie's codes:
True means it must be XXX
False means it must not be XXX
None means I don't care.

As such, if you don't want it to be peak, it should be False, not None
 
@Jamie
Oh yeah, since this is going to be just a scenario, for the HRE:
Why not just set the courthouse as its Unique Building as well, then just adjust the cost, since its power is going to affect just that ONE building.
Then no python codes needed, and no callbacks required as well
 
That would make sense :lol: maybe I should find some other effect :p
 
Extra Notes beside the ones I already mentioned:

@Turkey Power
Since I never use that countTotalCultureTimes100 function before, I am just suggesting this based on what I guess it should do.
Let's say City has 3 cultures:
Turkey 100
England 200
France 200

So I guess countTotalCultureTimes100 will give 50000? (A)
If so, pCity.getCultureTimes100(eTurkey) will give 10000 right? (B)
So (A) - (B) will give you total sum of foreign culture right? (If so, I can adjust my Helsinki codes too :D)
Then what is next is pretty obvious, I doubt I need to elaborate
Edit:
On hindsight, I guess I do NEED to elaborate.
It depends on what you really want by "converting foreign culture"
If you mean 75% of England and France culture will be added to Turkey, then yes you can just use setCulture.
If you mean 75% of EnF will be added to Turkey, and at the same time, that amount is DEDUCTED from EnF respectively, then no, use the loop method I use in Helsinki.


@Italy Power
Since yours is just a scenario, I guess Italy is always present at Game Start?
If so, then there is no need for First Contact part.
First Contact part was suggested assuming yours can play custom games, where Italy does not appear at game start, but appear later due to liberalisation of colonies

@Mongol
Even if the Mongol does not build a palace to shift the capital themselves, it is always possible that their capital is captured by others, which forces them to shift the capital automatically.
Now you know why I have not bothered to attempt the wonder suggested to fix vision at rivals' capitals :D

@France
I haven't bothered to read the codes, due to the other problems of it I mentioned :D
 
1) though it doesn't say, france is also called onGameStart.

2) The mongol code accounts for if the mongol capital is taken:
Code:
        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 = getPlot(getRandomCoords([pPlot for pPlot in lPlots if pPlot.getBonusType(-1) == -1]))
                        pPlot.setScriptData("Mongol Horse")
                        pPlot.setBonusType(eHorse)

I will check out the loop you mentioned.
 
btw when you use the for x in range(iX - 1, iX + 2) loop you do realise it's first ring only? you need to use my index loop to get all 21
plots!

edit:

Code:
TurkishCulture = (((pCity.countTotalCultureTimes100() - pCity.getCultureTimes100(eTurkey))/100) * iTurkekyConvertPercent) + pCity.getCultureTimes100(eTurkey)

that good enough? I don't really mind about the foreigners losing the culture aswell

edit: edit:

on the Byzantine power, I was not successful in creating a border pop without physically adding 10 culture. Any ideas? took a look at the creative codes and I got it now thanks!
 
I know, it was MEANT to be first ring, because when you captured a new city, chances are, you only start with a first ring culture.

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

        for iPlayer in CivPlayer.getPlayers(False, playerID):
                if iPlayer != eFrance:
                        pFrance = pointer("France", CyPlayer)
                        pPlayer = gc.getPlayer(iPlayer)
                        if pPlayer.getStateReligion() == pFrance.getStateReligion():
                                pPlayer.AI_setAttitudeExtra(eFrance, iFrenchRelations)

Why do you use "set" rather than "change"
Using set will cause problems if there are random events, or other python wonders for instance that change the extra relationships.
For instance, when one of those default BTS events that change relationship occurs, and England has +1 relationship with France as a result.
Now your France codes take place, and this will be messed up as if the event never occur because you use SET

Anyway, when you use change rather than set, then it can just be +1 and -1 and everything works fine.
There is no need for all those max or get functions.
You may refer to Taipei 101 and look at the onCityAcquire codes to see how it works when Taipei switches hands.

As for the last for loop posted, I have no idea what it supposed to do. It supposed to be under onReligionChanges as well?
 
it is called on game start :p you can see that if there are args supplied it does the top code then returns, if it hasn't returned does the for... basically me cheating and not writing else :lol:

the reason I used set instead of change was to stop it going to -1 (thinking it would cause errors, as I was probably tired when I wrote that :rolleyes:) when of course -1 would be unhappy with civ :lol:
 
@Turkey
Since I never tried that function, I can't guarantee that it will give the outcome I assume it does.
Although once again, why not use changeCulture rather than setCulture.
Then you can just add the difference directly, without the need of adding the Turkey culture to the difference, then set the culture to the result.

@Mongol codes
For the first loop, you are checking whether the special horse is in the city radius of the captured city.
But 1) Your script data failed in the Natural Wonder mod, so have you tested this?
2) Is it possible that the special horse is in one of the outer plots of the city?
If yes, then is it possible that another city was built near to that city and the special horse is now also in the city radius of THAT new city?
If yes again, then when that new city is captured, then even though it is NOT the mongol capital, but because the horse is in the city radius of that city, then the codes are going to activate wrongly...

As for the second part:
Code:
for pPlot in lPlots:
                                if pPlot.getBonusType(-1) == eHorse: return
This only checks if there is a horse, but whether it is the special horse, no idea.
This means that if the capital is captured, and the capital is shifted to a new city where there is already a horse, then they don't get a free horse.
Code:
 pPlot = getPlot(getRandomCoords([pPlot for pPlot in lPlots if pPlot.getBonusType(-1) == -1]))
This only checks if the plot has a bonus or not?
It does not check if it is a water plot, peak, or some other weirdos like oasis or ice terrain?

Edits:
@France for loop
Yeah I know, the thing is, a player is either France or not France.
What is the for loop for?

Helsinki Cathedral functions a bit differently.
It only converts the culture of the previous owner to the new owner.
It does not converts the culture of other foreign sources to the new owner, although a for loop will solve that.
However, it does decrease the culture of the previous owner, whereas the method you use will not
 
basically it worked fien untill I added into the wbs the state religions of each civ. so they don't convert on the first turn and the codes are not triggered. so It does it at the start of game so that the power works.

as for mongols: If the city already has a natural horse, it doesn't need a special horse. The power is to make sure mongolia has a horse at the capital. The script data does work for the power, I don't know why it didn't in natural wonders :confused:

(probably as it wasn't plot script data but instead city script data. When I tested my new SDK methods I found that something wasn't right there. The Cy methods all do a check to see that the appropriate Cv pointer is not null. if it is the method returns a default value. I suspect that both my methods and the getScriptData methods are returning their defaults of False and "" because the city is invalidated by the callback? :crazyeye:)

I did a lot of testing when first made the power code :p and it only checks for city radius horses. You are right it would could incorrect activation of the codes because there is no way (other than script data) to check whether the city used to be a capital. However because it is still a mongol city the power does still work as the horse is just moved to a different plot at the capital)

Code:
def getCityRadiusTiles(pCity, bNaval = False):
        lPlots = list()
        if type(pCity) == type((0, 0)):
                pCity = getPlotCity(pCity)
        for iIndex in xrange(21):
                pPlot = pCity.getCityIndexPlot(iIndex)
                if not bNaval:
                        if [B]isSpawnValid(pPlot)[/B] == False or pPlot.isCity(): continue
                        lPlots.append(pPlot)
                else:
                        if pPlot.isWater(): lPlots.append(pPlot)
        return lPlots

checks to see that it isn't a peak :p
 
I hope that isSpawnValid checks for terrain, features as well, else you get a Snow Horse :D
Anyway, 1 thing obvious is it does not check for plot ownership.

So now my horse is taken away from me, and tada, it still spawns around my capital, but in enemy's land...

Actually, another option is just add the Horse directly to the city itself, changeFreeBonus, so the Horse is added to the city like Hit Movies, rather than on the map itself.
The downside is you will have to use some methods to store where the capital is to adjust accordingly.
Since your script data failed for cities somehow, another method which I used is something like Matsumoto, World Trade Center or Willis Tower, where the location of the City is stored

@France
Is it possible for colonies to be liberated in your scenario?
If yes, then you still need codes for onFirstContact, otherwise the newly liberated ones have no Bonus Relationship towards France

Not sure whether you have read the part about Egypt as well, to use onUnitCreated for drafted units
 
hmmm I could be boring and just add the horse to the city plot :p cuts down on some code but less pretty :p at least enemies can't get it...

that method stops the problems with adding bonus directly to the city (like the musicals)...

Code:
def isSpawnValid(pPlot):
        """"
        Returns False if the CyPlot instance referenced by the pPlot argument is a water or
        a mountain tile. Otherwise returns True.
        """
        return not ( pPlot.isWater() or pPlot.isPeak() )

isSpawnValid was originally used for unit and city spawning codes so doesn't check features and stuff :p
 
So I guess you know my reply to that.
You may end up with Horses freezing in the snow, or Horses drinking at the oasis.
Or even on your Natural Wonders themselves if you are merging that mod too lol

Copied this part down if you have not seen:
@France
Is it possible for colonies to be liberated in your scenario?
If yes, then you still need codes for onFirstContact, otherwise the newly liberated ones have no Bonus Relationship towards France

Not sure whether you have read the part about Egypt as well, to use onUnitCreated for drafted units
 
ok how about this:

Code:
def mongols(*args): #onCityAcquired
        "Power of the Horde - Horse always present at capital"
        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]))
                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 = 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]))
                        pPlot.setScriptData("Mongol Horse")
                        pPlot.setBonusType(eHorse)

makes use of the ternary operator (:love:) and list comprehension (:love:) to assign the plot. if the city plot has a bonus then picks a random city radius plot owned by mongols. Note: when faced with conditonal assignment always use the ternary operator, I didn't think python had one till the other day (in C++ it's like this: condition ? conditon true : condition false, in python: condition true if conditon else condition false. though sometimes it can end up like this:
Code:
 bWorking = !isCity() ? !(bWorking) : (!(bWorking) ? !(bWorking) : bWorking);
(this is simulating a if elif else ternary :p))
 
and yes I did see the drafting notes and I will move them soon ish. as for france, surely a new colony will still have to adopt a state religion thus triggering the codes? the code still works for civs france hasn't met yet, when they do the correct boost is applied)
 
@Mongol
It still does not solve some problems
1) Spawning of Horses in weird plots like I mentioned. Undesirable Terrain where Horses are NOT supposed to spawn, SNOW and DESERT. Others like OASIS as well.
2) Shifting of Capital due to building of palace not taken care of.
Although the Horse still remains with the ex-capital, the new capital may not be connected to the ex-capital, although it is rare, but routes may be pillaged or blockaged etc.
As such, Horse is no longer available at the capital itself.

@France
What if a new colony, Greece is liberated when France is having no state religion?
Then Greece has no bonus although they have same religion.
Then now Greece changes religion to Hindu.
Then codes are activated and Greece ends up with -1 relationship to France, when it should just be 0.
And who said that a new colony must adopt new religion?
Sometimes they are happy with free religion
 
hmmm... I guess I will need something on contact then, not sure if colonies are actually able to be created yet but I will add some code anyway...

I don't actually mind if horsies are on desert or snow, after all in real life some horses do live in snow and deserts :p. oasis could be a problem however as improvements can't be built there... I can edit it to include oasis checks as cities shouldn't be able to spawn on oasis :p

gotta fix the building problem aswell whoops.
 
quick question: the pOldCity in doCityCapturedGold(), if I do pOldCity.getOwner() will it be the vikings if they took it (kept or razed)?
 
It will refer to previous owner.
But the gold will of course, be given to the new owner.
So yeah, come to think of it, that may not be helpful for your Viking Trait, although the PillageGold one does.

This function canHaveBonus under CyPlot may be helpful and simpler to decide if the plot can have Horses.
By right, it should check whether the plot can have that bonus, but I remember ages ago when I tested it for Silk, it doesn't give me the right results when there are features and improvements...
You may want to test it yourself to see how it goes.
Come to think of it, I have not excluded oasis myself for some works :D
 
Back
Top Bottom