Platyping's Python

Why do you use onLoadGame and onGameStart for the Patent project? onTechAcquired would be enough!?

Edit: To get rid of a while loop?
 
ok seems my post didn't work :rolleyes:

I will definatly be using those traits for fall of Rome and Jamie's Medieval mod! (might even expand the nomadic one a bit to allow a civ to destroy their city and turn back into a settler with an army based on the size of the city (provided they are at one city) to move it :D
 
@cybah
To get rid of the trouble of using loops to find out which team created patent every time any team discover a tech
Since load and start is effectively only used when you start/load a game, it should be better performance wise.

@jamie
Geez, you saved me the trouble of testing haha
 
Hey

I'd like to add a few of these wonders to my tweaked version of Avain's Quot Capita, which he sadly seems to have stopped work on. I confess I'm absolutely clueless about Python, but I was sort of encouraged by the note on page one that says it's mostly a matter of copying and pasting. Clearly for Quot Capita this is not the case. The mod actually includes a few of Platyping's wonders, including the Terracotta Army. The code is in the files 'QuotCapitaCvGameUtils.py' and 'QuotCapitaEventManager.py'. I've tried copying and pasting the individual wonders' code into the relevant files, but nothing has worked. Either the interface is screwed up, or the wonders' Python effects don't show up.

If I'm in over my head, someone tell me. But if there's an easy method for incorporating the code into existing GameUtils and EventManager files, I'd sure appreciate some help. Thanks.

[edit] I don't have any problems with the XML or art side, which almost makes this more frustrating. They show up fine and generate GW points, but they don't do the really cool stuff in the Python code :)
 
Hey . I tried to edit your palm islands as a wonder , but the islands do not appear on the map . You can look , please, where I made ​​a error ?
thanks
Hroch

Spoiler :
PHP:
def onBuildingBuilt(self, argsList):
		'Building Completed'
		pCity, iBuildingType = argsList
		game = gc.getGame()
## Palm Islands Start OSTROVY ##
		if iBuildingType == gc.getInfoTypeForString("BUILDING_OSTROVY"):
			MarineResource = [gc.getInfoTypeForString("BONUS_FISH"), gc.getInfoTypeForString("BONUS_CLAM"), gc.getInfoTypeForString("BONUS_CRAB")]
			PalmResort = [gc.getInfoTypeForString("BUILDING_PALM_JUMEIRAH"), gc.getInfoTypeForString("BUILDING_PALM_JEBEL_ALI"), gc.getInfoTypeForString("BUILDING_PALM_DEIRA")]
			IslandName = ["Palm Jumeirah", "Palm Jebel Ali", "Palm Deira"]
			iPlayer = pCity.getOwner()
			pPlayer = gc.getPlayer(iPlayer)
			iTeam = pPlayer.getTeam()
			pTeam = gc.getTeam(iTeam)
			pLeader = gc.getPlayer(pTeam.getLeaderID())
			PalmPlayer = []
			for iPlayerX in range(gc.getMAX_CIV_PLAYERS()):
				pPlayerX = gc.getPlayer(iPlayerX)
				if pPlayerX.isAlive() and pPlayerX.getTeam() == iTeam:
					PalmPlayer.append(pPlayerX)
			while len(PalmPlayer) < 3:
				PalmPlayer.append(pLeader)

			for PalmIndex in range(3):
			## Select available plots ##
				Islands = []
				for i in range(CyMap().numPlots()):
					pPlot = CyMap().plotByIndex(i)
					if pPlot.getTerrainType() == gc.getInfoTypeForString("TERRAIN_OCEAN"):
						b_island = true
						for x in range(pPlot.getX() - 2, pPlot.getX() + 3):
							for y in range(pPlot.getY() - 2, pPlot.getY() + 3):
								pPlot2 = CyMap().plot(x, y)
								if pPlot2.getOwner() != -1:
									b_island = false
									break
								if pPlot2.isNone() or not pPlot2.isWater():
									b_island = false
									break
							if b_island == false:
								break
						if b_island == true:
							Islands.append(pPlot)
				if len(Islands) > 0:
					pIsland = Islands[CyGame().getSorenRandNum(len(Islands), "New Island")]

				## Shift Naval Units Away ##
					for iUnit in range(pIsland.getNumUnits()):
						pUnit = pIsland.getUnit(iUnit)
						iUnitOwner = pUnit.getOwner()
						pUnitOwner = gc.getPlayer(iUnitOwner)
						(loopCity, iter) = pUnitOwner.firstCity(false)
						while(loopCity):
							if loopCity.isCoastal(10):
								pNewUnit = pUnitOwner.initUnit(pUnit.getUnitType(), loopCity.getX(), loopCity.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.NO_DIRECTION)
								pNewUnit.convert(pUnit)
			## For Springfield Armory ##			pNewUnit.setBaseCombatStr(pUnit.baseCombatStr())	## For Springfield Armory ##
								pNewUnit.finishMoves()
								break
							(loopCity, iter) = pUnitOwner.nextCity(iter, false)

				## Create Island ##
					pIsland.setTerrainType(gc.getInfoTypeForString("TERRAIN_PLAINS"), true, true)
					iX = pIsland.getX()
					iY = pIsland.getY()
					pPlayerX = PalmPlayer[PalmIndex]
					pPlayerX.initCity(iX, iY)
					PalmCity = pIsland.getPlotCity()
					PalmCity.setName(IslandName[PalmIndex], true)
				## Adds Resort ##
					PalmCity.setNumRealBuilding(PalmResort[PalmIndex], 1)
					for x in range(iX - 2, iX + 3):
						for y in range(iY - 2, iY + 3):
							pPlot = CyMap().plot(x, y)
							if (abs(x - iX) != 2 or abs(y - iY) != 2) and pPlot.isWater():
								pPlot.setFeatureType(-1, -1)
								if pPlot.getBonusType(-1) == -1:
									randBonus = CyGame().getSorenRandNum(30, "Freebie")
									if randBonus < 3:
										pPlot.setBonusType(MarineResource[randBonus])
				## Adds Defender ##
					pNewUnit = pPlayerX.initUnit(PalmCity.getConscriptUnit(), iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.NO_DIRECTION )
					PalmCity.addProductionExperience(pNewUnit, true)			
## Palm Islands End OSTROVY ##

In CvGameUtils I cut this two lines:
if pTeam.getNumMembers() > 3:
return True
when islands now are not projekt.
 
About CvPediaProject I´m confused. I made this editation:
PHP:
# Project Help Start ##
 		gc = CyGlobalContext()

		szSpecialText = ""
		if self.iBuilding == gc.getInfoTypeForString("BUILDING_OSTROVY"): szSpecialText = CyTranslator().getText("TXT_KEY_PROJECT_PALM_ISLANDS_HELP",())
		elif self.iProject == gc.getInfoTypeForString("PROJECT_THE_INTERNET"): szSpecialText = CyTranslator().getText("TXT_KEY_PROJECT_THE_INTERNET_HELP",())
		szSpecialText += CyGameTextMgr().getBuildingHelp(self.iBuilding, True, None)[1:]
## Project Help End ##
but I dont know if this will work when islands are now building :(
 
@Sine Nomen
Thanks for the support.
First of all, as you mentioned, you are copying the python codes into a mod that is not really completed. Thus, are the python codes in that mod in working conditions in the first place?

As mentioned, merging of 2 python codes is pretty much copy and paste from one of them to the other one which you want to keep as the merged file.

Big Ben
Code:
	def onEndPlayerTurn(self, argsList):
		'Called at the end of a players turn'
		iGameTurn, iPlayer = argsList
	
## Big Ben Start ##
		pPlayer = gc.getPlayer(iPlayer)
		if pPlayer.getBuildingClassCount(gc.getInfoTypeForString("BUILDINGCLASS_BIG_BEN")) == 1:
			pPlayer.changeGold(CyGame().getGameTurn() / gc.getGameSpeedInfo(CyGame().getGameSpeedType()).getConstructPercent()/ 100)
## Big Ben End ##
	
		if (gc.getGame().getElapsedGameTurns() == 1):
			if (gc.getPlayer(iPlayer).isHuman()):
				if (gc.getPlayer(iPlayer).canRevolution(0)):
					popupInfo = CyPopupInfo()
					popupInfo.setButtonPopupType(ButtonPopupTypes.BUTTONPOPUP_CHANGECIVIC)
					popupInfo.addPopup(iPlayer)
		
		CvAdvisorUtils.resetAdvisorNags()
		CvAdvisorUtils.endTurnFeats(iPlayer)

Brandenburg
Code:
	def onUnitBuilt(self, argsList):
		'Unit Completed'
		city = argsList[0]
		unit = argsList[1]
		player = PyPlayer(city.getOwner())

## Brandenburg Start ##
		pPlayer = gc.getPlayer(city.getOwner())
		iGreatGeneral = city.getAddedFreeSpecialistCount(gc.getInfoTypeForString("SPECIALIST_GREAT_GENERAL"))
		if pPlayer.getBuildingClassCount(gc.getInfoTypeForString("BUILDINGCLASS_BRANDENBURG_GATE")) == 1:
			if unit.getUnitCombatType() != -1:
				unit.changeExperience(iGreatGeneral,100,False,False,False)
## Brandenburg End ##
		CvAdvisorUtils.unitBuiltFeats(city, unit)
		
		if (not self.__LOG_UNITBUILD):
			return
		CvUtil.pyPrint('%s was finished by Player %d Civilization %s' 
			%(PyInfo.UnitInfo(unit.getUnitType()).getDescription(), player.getID(), player.getCivilizationName()))

Big Ben and Brandenburg for instance uses 2 different parts in CvEventManager file, so this is easy. Just copy one of them (Brandenburg for instance) and paste into the other (Big Ben's) file.

Changi Airport
Code:
	def onUnitBuilt(self, argsList):
		'Unit Completed'
		city = argsList[0]
		unit = argsList[1]
		player = PyPlayer(city.getOwner())

## Changi Airport Start ##
		if city.getNumActiveBuilding(gc.getInfoTypeForString("BUILDING_CHANGI_AIRPORT")):
			if unit.getUnitCombatType() == gc.getInfoTypeForString("UNITCOMBAT_AIR"):
				unit.setHasPromotion(gc.getInfoTypeForString("PROMOTION_MORALE"), true)
				unit.setHasPromotion(gc.getInfoTypeForString("PROMOTION_BLITZ"), true)
## Changi Airport End ##

Changi Airport however, uses the same part as Brandenburg, so you have to copy and paste just the relevant part into the same portion.

The results should look like this:
Code:
	def onUnitBuilt(self, argsList):
		'Unit Completed'
		city = argsList[0]
		unit = argsList[1]
		player = PyPlayer(city.getOwner())

		iPlayer = city.getOwner()
		pPlayer = gc.getPlayer(iPlayer)
		iTeam = pPlayer.getTeam()
		pTeam = gc.getTeam(iTeam)
## Brandenburg Start ##
		if pPlayer.getBuildingClassCount(gc.getInfoTypeForString("BUILDINGCLASS_BRANDENBURG_GATE")) == 1:
			if unit.getUnitCombatType() != -1:
				unit.changeExperience(city.getAddedFreeSpecialistCount(gc.getInfoTypeForString("SPECIALIST_GREAT_GENERAL")),100,False,False,False)
## Changi Airport Start ##
		if city.getNumActiveBuilding(gc.getInfoTypeForString("BUILDING_CHANGI_AIRPORT")):
			if unit.getUnitCombatType() == gc.getInfoTypeForString("UNITCOMBAT_AIR"):
				unit.setHasPromotion(gc.getInfoTypeForString("PROMOTION_MORALE"), true)
				unit.setHasPromotion(gc.getInfoTypeForString("PROMOTION_BLITZ"), true)
		CvAdvisorUtils.unitBuiltFeats(city, unit)
		
		if (not self.__LOG_UNITBUILD):
			return
		CvUtil.pyPrint('%s was finished by Player %d Civilization %s' 
			%(PyInfo.UnitInfo(unit.getUnitType()).getDescription(), player.getID(), player.getCivilizationName()))

As mentioned in the first page, it is mostly copy and paste except for a few exceptions where simple copy and paste will work, but give you results that you dont want because certain wonder effects might interfere with one another
 
@Hrochland

@CvGameUtils
Code:
	def cannotCreate(self,argsList):
		pCity = argsList[0]
		eProject = argsList[1]
		bContinue = argsList[2]
		bTestVisible = argsList[3]

## Palm Islands Start ##
		if eProject == gc.getInfoTypeForString("PROJECT_PALM_ISLANDS"):
			pPlayer = gc.getPlayer(pCity.getOwner())
			pTeam = gc.getTeam(pPlayer.getTeam())
			if pTeam.getNumMembers() > 3:
				return True
			if CyMap().getLandPlots() * 100 /CyMap().numPlots() > 70:
				return True
## Palm Islands End ##
		return False
This part was to restrict the building of the project to (A)Teams with less than 4 members(B) Maps with more than 30% water plots.

(A) is required if you are still extending the benefits to the whole team. However, since it is a building now, if you want to restrict the benefits to just the player, then you can remove this part.
As for (B), if you want to keep it, you have to move the whole code to def cannotConstruct, because cannotCreate is for projects, not for buildings.
However, if you are using cannotConstruct, then you have to activate the callback in PythonCallbackDefines file.

It should look like this
Code:
	def cannotConstruct(self,argsList):
		pCity = argsList[0]
		eBuilding = argsList[1]
		bContinue = argsList[2]
		bTestVisible = argsList[3]
		bIgnoreCost = argsList[4]
## Palm Islands Start ##
		if eBuilding == gc.getInfoTypeForString("BUILDING_PALM_ISLANDS"):
			if CyMap().getLandPlots() * 100 /CyMap().numPlots() > 70:
				return True
## Palm Islands End ##
		return False

@CvEventManager
I suppose the only line you have changed is the first line?
That line looks correct.

@CvPediaProject
This file was meant for project usage only, to display the help texts for projects.
Since you are using it as a building, delete the whole file. Not required

Notes:
As it was originally a project, the benefits are applied to the whole team rather than just a player.
Up to you if you want to change it to just the player now that it is a wonder.
Also, since wonder can be captured, you may want to consider what happens if the wonder is captured, or just ignore it
 
@platyping
Thanks :)
After my first attempt at a remake as Wonder , the islands not revealed and after second test not too. I'll try it now and I write , what was the result :)

EDIT: seemed to me that the code is doing more things but I'm primarily interested only in the discovery of the islands .
You know ... I love wonders what changes map :)
I have in my mode all those what you made :)
 
Thanks

What it does is as followed:
1) Select 3 ocean plots far away from land to convert to islands
2) Move naval units away
3) Convert to islands and place cities on them
4) Name the islands and assign them to each member of the team
5) Add the special building to each different island
6) Spawns some marine resources around the islands
7) Adds some units to defend the islands
 
I have a question and sorry if I shouldn't have posted here. I have made it so helicopters can be transported by many ships in my mods. However, I'd like to make it so that the helis can fly around the ships at a max of say 3x3tiles (1 tile in each direction). Is that too much work python or even doable, think it would be easier in sdk?
 
Might be doable with def unitCannotMoveInto(self,argsList):

First, allows helicopters to be able to move into oceans and coasts by default.
Then under unitCannotMoveInto, use a loop to check each tile in the 3x3 around the helicopter.
If there is transport, break the loop and return False.
Else, return true.

Doable, but not performance wise guaranteed

Now the questions is, what happens when the heli is flying around and the transport got destroyed..
Then it is stuck there and cannot move lol
 
4) Name the islands and assign them to each member of the team

There can be no such problem when the islands are now building?
 
Now the questions is, what happens when the heli is flying around and the transport got destroyed..
Then it is stuck there and cannot move lol

Allow Gunships access to the Rebase mission.
 
...that's awful for the performance and for the AI. I wouldn't do it.

I wouldn't either :D

The thing about python is, AI never ever understand what is going on.
All these python benefits you see from these wonders and projects, AI view them as totally NOTHING.
However, wonders and projects are still ok because AI don't have to really understand how they work, they just know, build them will be good for the relative flavour tags.
Big Ben has a gold flavour tag, AI does not have to know exactly how it helps their economy. All they need to know is, build Big Ben will boost their economy. Good enough.

This is why I don't make python civics or promotions. Because when there is a choice, AI will NEVER choose the python ones unless they are forced to.
Traits are still ok, because they are not given the choice lol

@hrochland
It doesn't matter whether it is a wonder or a project.
When you build the wonder/project, then all the codes are activated in that sequence.
 
Back
Top Bottom