[Python] Help, adding HQ Gold and City number to corp screen

Ekmek

on steam: ekmek_e
Joined
Aug 7, 2002
Messages
6,115
Location
San Diego, California
I like johnny smith's url=http://forums.civfanatics.com/showpost.php?p=6400456&postcount=15]New scrolling corporation screen[/url]

But I feel the firaxis corporation screen could use some more info. So I need help to:

1) Add the total gold value that the HQ generates. CvMainInterface.py has this code, but where do I put in the corporation screen python?

Code:
for i in range(gc.getNumCorporationInfos()):
					xCoord = xResolution - 242 + (i * 34)
					yCoord = 66
					
					bEnable = True
						
					if (pHeadSelectedCity.isHasCorporation(i)):
						if (pHeadSelectedCity.isHeadquartersByType(i)):
							szTempBuffer = u"%c" %(gc.getCorporationInfo(i).getHeadquarterChar())
							szName = "CorporationHeadquarterDDS" + str(i)
							screen.show( szName )
						else:
							szTempBuffer = u"%c" %(gc.getCorporationInfo(i).getChar())
						szBuffer = szBuffer + szTempBuffer

						for j in range(YieldTypes.NUM_YIELD_TYPES):
							iYield = pHeadSelectedCity.getCorporationYieldByCorporation(j, i)

							if (iYield != 0):
								if ( iYield > 0 ):
									szTempBuffer = u",%s%d%c" %("+", iYield, gc.getYieldInfo(j).getChar() )
									szBuffer = szBuffer + szTempBuffer
								else:
									szTempBuffer = u",%s%d%c" %( "", iYield, gc.getYieldInfo(j).getChar() )
									szBuffer = szBuffer + szTempBuffer
						
						for j in range(CommerceTypes.NUM_COMMERCE_TYPES):
							iCommerce = pHeadSelectedCity.getCorporationCommerceByCorporation(j, i)

							if (iCommerce != 0):
								if ( iCommerce > 0 ):
									szTempBuffer = u",%s%d%c" %("+", iCommerce, gc.getCommerceInfo(j).getChar() )
									szBuffer = szBuffer + szTempBuffer
								else:
									szTempBuffer = u",%s%d%c" %( "", iCommerce, gc.getCommerceInfo(j).getChar() )
									szBuffer = szBuffer + szTempBuffer

						szBuffer += " "
						
						szButton = gc.getCorporationInfo(i).getButton()
					
					else:



2) the other thing I want t add is a line that tells how many cities in the world have that corporation. So it'll be a loop of all player cities. So how do I do that?


thx.
 
Zebra is probably the best at python, so I'd wait till he comes along, or PM him. :)
 
Here's a simple python script you can use to loop across all cities:

Code:
                NumPlayers = []
		for i in range(gc.getMAX_CIV_PLAYERS()):
			if (gc.getPlayer(i).isAlive()):
				loopPlayer = PyPlayer(gc.getPlayer(i).getID())
				if (loopPlayer.isNone() or not loopPlayer.isAlive()):
					continue
				else:
                                    if loopPlayer.getTeam() == iTeam:
					NumPlayers.append(loopPlayer.getID())

                for i in range(len(NumPlayers)):					
                    for n in range(gc.getPlayer(NumPlayers[i]).getNumCities()):
                        pCity = gc.getPlayer(NumPlayers[i]).getCity(n)

I don't feel like digging around in the API, but some pseudocode from here on:

Code:
if pCity.hasCorporation(CorpQueried):
    CorpCount += 1
if pCity.isCorporateCapital(CorpQueried):
    CorpCapital = pCity.getName()

I hope this answers your questions.
 
There is a function to get the number of players ever alive, something like getNumPlayersEverAlive() which would save you a step ;)
 
There is a function to get the number of players ever alive, something like getNumPlayersEverAlive() which would save you a step ;)
Players can die and new ones be created (colonies), but the new ones won't take the old ones ID even if they're dead.


This part of the code won't always work properly:
Code:
                    for n in range(gc.getPlayer(NumPlayers[i]).getNumCities()):
                        pCity = gc.getPlayer(NumPlayers[i]).getCity(n)

The problem is what happends if you have 6 cities and lose #4? The ID of the others will remain the same, but getNumCities now return 5. There's a function in PyHelpers.py that'll give you a city list.

Here's how I'd change the code
Code:
                pPlayers = []
		for i in range(gc.getMAX_CIV_PLAYERS()):
			if (gc.getPlayer(i).isAlive()):
				loopPlayer = PyPlayer(i) #Why did you get CyPlayer i, then ask it what it's ID is? It's i. You asked for the player with ID i...
				if (loopPlayer.isNone() or not loopPlayer.isAlive()):
					continue
				else:
                                    if loopPlayer.getTeam() == iTeam:
					pPlayers.append(loopPlayer)

                for pPlayer in pPlayers: #If you think pPlayer is too close to pPlayers rename one of them to something else.					
                    for pCity in pPlayer.getCityList():
                        #some code doing what you want. Keep in mind you have PyCity objects, not CyCity. PyCity is a class in PyHelpers.py (as is the PyPlayer you got earlier)
 
Back
Top Bottom