Trouble making a civ change to another while using same Team Number in WBS!

This was the full message:
Code:
Traceback(most recent call last)

File "CvEventInterface",line 30, in onEvent

File "CvCustomEventManager",line 135, in handleEvent

File "CvCustomEventManager",line 146, in_handleDefaultEvent

File "CvGustavusEventManager",line 58, in onBeginGameTurn

RunTime Error: unidentifiable C++ error




Ups, sorry .
I have also the downloadable API from Zebra9 here, and this says, that the addPlayer function took 4 arguments (last one: teamid) in the sdk version when the API was created.

How would "teamID" be represented as the fourth argument?
What it look like?
 
A team ID is a TeamTypes value ranging from 0 to gc.getMAX_TEAMS()-1. -1 represents NO_TEAM.
 
-> so you need to add before the add function:
PHP:
NewTeamID = -1
for i in range (gc.getMAX_TEAMS()):
    thisTeam = gc.getTeam(i)
    if not thisTeam.isAlive()
        NewTeamID = i
        break
if NewTeamID ==-1:
    return

and after that, just add NewTeamID as the last parameter.
 
Is there a way to just change all the artwork(leaderhead art, flag, colors,
art style,units etc.) and text(civ desc, civ adjective,civ short desc)
for a civ on a turn with python?


Here is what my event infos looks like, this might help!

Code:
from CvPythonExtensions import *
import CvEventManager
import CvUtil
import PyHelpers	
import Popup as PyPopup
import pickle		
import random
import CvTranslator
import sys
import CvAlertManager





# globals
gc = CyGlobalContext()
g = CyGame()
alert = CvAlertManager.CvAlertManager()
		


#the main class

class CvGustavusEventManager:
	def __init__(self, eventManager):
		# initialize base class
		eventManager.addEventHandler("BeginGameTurn", self.onBeginGameTurn)
		

				

	# When a turn begins :
	def onBeginGameTurn(self, argsList):
		iGameTurn, = argsList




                          #TURN 3 : Germany
                          if(iGameTurn == 3):
			#Germany have to start
			iNewPlayer = 7    # Player ID (= player's position in list) in your Map
			self.CreateNewCivGermany(iNewPlayer, 87, 40)    # 87 (X) and 40 (Y) are coordonates of the plot where the unit will be created

                           #TURN 4 : France
		elif(iGameTurn == 4):
			#France have to start
			iNewPlayer = 8    # Player ID (= player's position in list) in your Map
			self.CreateNewCivFrance(iNewPlayer, 90, 17)

                            ###############################################################
		#
		#   END YOUR INFOS HERE
		#
		###############################################################
				
				
	# My function that creates the new unit :
	def CreateNewCivGermany(self, iNewPlayer, iX, iY):
		pNewPlayer = gc.getPlayer(iNewPlayer)
		if(not pNewPlayer.isAlive()):
			#Create new Player
			pNewPlayer.setPlayable(True)
			g.addPlayer(iNewPlayer, pNewPlayer.getTeam(), pNewPlayer.getPersonalityType(), pNewPlayer.getCivilizationType())
			#Create a settler
			pNewPlayer.initUnit(gc.getInfoTypeForString("UNIT_FOUNDER"), iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
                        pNewPlayer.initUnit(gc.getInfoTypeForString("UNIT_SPEARMAN"), iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
                        pNewPlayer.initUnit(gc.getInfoTypeForString("UNIT_SWORDSMAN"), iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
                        #Add a message on screen
			CyInterface().addMessage(g.getActivePlayer(),true,15,"Year %s: A new Civilization (%s) has been created !" %(g.getGameTurnYear(), pNewPlayer.getCivilizationDescription(pNewPlayer.getCivilizationType())),'',0,'',ColorTypes(11), 1, 1, True,True)
			
		return

        def CreateNewCivFrance(self, iNewPlayer, iX, iY):
                pCity = CyMap().plot(87,40).getPlotCity()
		pNewPlayer = gc.getPlayer(iNewPlayer)
		if(not pNewPlayer.isAlive()):
			#Create new Player
			pNewPlayer.setPlayable(True)
			g.addPlayer(iNewPlayer, pNewPlayer.getTeam(), pNewPlayer.getPersonalityType(), pNewPlayer.getCivilizationType())
			#Create a settler
			pNewPlayer.initUnit(gc.getInfoTypeForString("UNIT_FOUNDER"), iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
                        pNewPlayer.initUnit(gc.getInfoTypeForString("UNIT_SPEARMAN"), iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
                        pCity.changeCulture(iNewPlayer, 50, True)
                        pCity.changePopulation(2)
			#Add a message on screen
			CyInterface().addMessage(g.getActivePlayer(),true,15,"Year %s: A new Civilization (%s) has been created !" %(g.getGameTurnYear(), pNewPlayer.getCivilizationDescription(pNewPlayer.getCivilizationType())),'',0,'',ColorTypes(11), 1, 1, True,True)
			
		return
 
Cool Python tip #12: The for loop accepts an else clause that runs only if the for loop terminates normally by reaching the end of the iteration sequence without breaking.

Code:
for iNewTeamID in range(gc.getMAX_TEAMS()):
    thisTeam = gc.getTeam(iNewTeamID)
    if not thisTeam.isAlive():
        break
[B]else:
    return[/B]

CyGame().addPlayer(..., iNewTeamID)

Also, you don't need to initialize iNewTeamID outside the loop because in Python there is no finer-grained scoping for variables than function-level. Once you assign a value to a local variable, it remains in scope until the function exits, unlike C/C++, Java, and many other languages. I simply used iNewTeamID as the loop variable above since there's no reason for a separate i variable.

As for the addPlayer() function, it's possible that passing a -1 (NO_TEAM) for eTeam tells the SDK to find the first non-living team. I can't verify that since my 3.19 sources don't take an eTeam parameter. Are you using 3.17 perhaps? Actually, I haven't updated the online API to 3.19 yet, and it doesn't take an eTeam either. I really have no idea why your DLL is requiring 4 parameters.
 
I get syntax errors and indentation errors with this code:

Code:
#TURN 1 : CIV SWITCHING
                #Vikings Changes Leadership
		if (iGameTurn ==1):
                                iPlayer = 1
			        pPlayer = gc.getPlayer(iPlayer)                                
                                PlayerTeamID = gc.getTeam(pPlayer.getTeam()).getID()
                                iciv = pPlayer.getCivilizationType ()                                
                                leaderid = gc.getInfoTypeForString( 'LEADER_MEHMED' )
                                NewTeamID = -1 
                                for i in range (gc.getMAX_TEAMS()): 
                                    thisTeam = gc.getTeam(i) 
                                if not thisTeam.isAlive() 
                                    NewTeamID = i 
                                    break 
                                if NewTeamID ==-1: 
                                    return
                                CyGame().addPlayer(17,leaderid,iciv,NewTeamID)
                                otherPlayer = gc.getPlayer(17)
                                NumCities = pPlayer.getNumCities ()
                                otherteam = gc.getTeam(gc.getPlayer(17).getTeam())                                                              
                                otherteam.addTeam(PlayerTeamID)                                
                                for i in range (NumCities):
                                        TheCity = pPlayer.getCity(i)
                                        otherPlayer.acquireCity(TheCity,False,False)

Could you please post it again with the NewTeamID added lines.
 
Our code was indented with spaces (easier to type into Firefox), and you will have problems mixing those with tabs.

Code:
		#TURN 1 : CIV SWITCHING
		#Vikings Changes Leadership
		if (iGameTurn ==1):
			iPlayer = 1
			pPlayer = gc.getPlayer(iPlayer)                                
			PlayerTeamID = pPlayer.getTeam()
			iciv = pPlayer.getCivilizationType ()                                
			leaderid = gc.getInfoTypeForString( 'LEADER_MEHMED' )
			for NewTeamID in range(gc.getMAX_TEAMS()):
				thisTeam = gc.getTeam(NewTeamID)
				if not thisTeam.isAlive():
					break
			else:
				return
			CyGame().addPlayer(17,leaderid,iciv,NewTeamID)
			otherPlayer = gc.getPlayer(17)
			NumCities = pPlayer.getNumCities ()
			otherteam = gc.getTeam(otherPlayer.getTeam())                                                              
			otherteam.addTeam(PlayerTeamID)                                
			for i in range (NumCities):
				TheCity = pPlayer.getCity(i)
				otherPlayer.acquireCity(TheCity,False,False)

BTW, it seems odd to create a new player and team, have that new player join player 2's team, and then transfer all cities over to the new player. Are you trying to convert one player into another?
 
Is there a way to just change all the artwork(leaderhead art, flag, colors,
art style,units etc.) and text(civ desc, civ adjective,civ short desc)
for a civ on a turn with python?

I can't see a way :dunno:.

Cool Python tip #12: The for loop accepts an else clause that runs only if the for loop terminates normally by reaching the end of the iteration sequence without breaking.

Your statement sounds a bit sarcastic, but that's really cool :D.

Also, you don't need to initialize iNewTeamID outside the loop because in Python there is no finer-grained scoping for variables than function-level. Once you assign a value to a local variable, it remains in scope until the function exits, unlike C/C++, Java, and many other languages. I simply used iNewTeamID as the loop variable above since there's no reason for a separate i variable.

I guess, i should learn "real python programming", and not just code a bit around.
Thanks for the tip again :goodjob:.


Our code was indented with spaces (easier to type into Firefox)

I've never thought about it, but is there a direct way to type tabs in FF?

BTW, it seems odd to create a new player and team, have that new player join player 2's team, and then transfer all cities over to the new player. Are you trying to convert one player into another?

Yes, that's the goal.
I can't see a direct way to do this, so that seems the only available option.
 
I'm getting syntax errors regarding this line:

Code:
if not thisTeam.isAlive()


Anyways, how is this actually supposed to work?

Can you use this code multiple times to change Leaderhead and CivType
for every civ except human players based on turns?

Example: turn 10= "team 2" in WBS file starts as "CIVILIZATION_YANGHAO"
but later on turn 10 changes to "CIVILIZATION_YANGHAO".
 
Your statement sounds a bit sarcastic.

That was not my intention. Funny, yes, but not sarcastic. I use humor to make my "informative" posts a little less tedious to read or perhaps only less tedious to write. ;)

I guess, i should learn "real python programming", and not just code a bit around.

All programming is real programming. Sure, you can write procedural programs in an object-oriented programming language like all of the Civ4 Python code, but it's still "real." I only post tips like this because I like learning about them myself and sharing them with others. I only learned about the for loop's else clause a few months ago.

I've never thought about it, but is there a direct way to type tabs in FF?

I cannot find a way. TAB navigates links and text fields. CTRL + TAB cycles tabs. And SHIFT works with both of those to go backwards. ALT + TAB is captured by Windows. The TAB key is typically CTRL + I, but that opens the bookmarks sidebar normally and makes text italic in a CFC post edit box. :(

I open up a new document in Notepad++ whenever I write any sizable chunk of code for a post.
 
That was not my intention. Funny, yes, but not sarcastic. I use humor to make my "informative" posts a little less tedious to read or perhaps only less tedious to write. ;)

Okay :D.

All programming is real programming. Sure, you can write procedural programs in an object-oriented programming language like all of the Civ4 Python code, but it's still "real." I only post tips like this because I like learning about them myself and sharing them with others. I only learned about the for loop's else clause a few months ago.

With "real programming" i've meant without civ.
I've never written a real python programm (-> don't know really, how the structure should be, etc), and i'm missing some essential basics in python programming.

I cannot find a way. TAB navigates links and text fields. CTRL + TAB cycles tabs. And SHIFT works with both of those to go backwards. ALT + TAB is captured by Windows. The TAB key is typically CTRL + I, but that opens the bookmarks sidebar normally and makes text italic in a CFC post edit box. :(

I open up a new document in Notepad++ whenever I write any sizable chunk of code for a post.

D***.
I would directly write it in python, but i really don't want to add an exception to my firewall.
 
Perhaps because NewTeamID points to an invalid (never initialized) team? Try passing in PlayerTeamID instead. If that gets past that llne, you'll need to rewrite the code after it to skip looking for a new team ID.
 
Well I'm of no use at this point. I don't have the same SDK as you and have no idea how yours could be different from mine. Thus I can't see what exception could be thrown by it. :confused:

Ah, my last guess is to try passing -1 for the team ID, but i doubt that will work either.
 
My version of Civ 4 BTS is 3.0.0.86.
Would this help you understand the SDK I am using more?

Ah. You haven't installed any of the official patches: 3.03, 3.13, 3.17, 3.19?

What is the version listed as CIV VERSION on the ADVANCED : ABOUT THIS BUILD screen?
 
Back
Top Bottom