[Python] How to make a sound play during the Dawn of Man screen?

Maniac

Apolyton Sage
Joined
Nov 27, 2004
Messages
5,588
Location
Gent, Belgium
The unmodded Dawn of Man screen has this rather straightforward code:

Code:
		pActivePlayer = gc.getPlayer(CyGame().getActivePlayer())
		pLeaderHeadInfo = gc.getLeaderHeadInfo(pActivePlayer.getLeaderType())
		screen.setSoundId(CyAudioGame().Play2DSoundWithId(pLeaderHeadInfo.getDiploPeaceMusicScriptIds(0)))

I want another sound than the diplo music to play. Therefore I tested this code:

Code:
		pActivePlayer = gc.getPlayer(CyGame().getActivePlayer())
		pLeaderHeadInfo = gc.getLeaderHeadInfo(pActivePlayer.getLeaderType())
		pLeaderHead = pActivePlayer.getLeaderType()
		if pLeaderHead == gc.getInfoTypeForString('LEADER_PRAVIN_LAL'):
			screen.setSound("AS2D_PEACE")
		elif pLeaderHead == gc.getInfoTypeForString('LEADER_MIRIAM_GODWINSON'):
			screen.setSound("AS2D_DIPLO_JUSTINIANI_LATE")
			##screen.setSoundId(CyAudioGame().Play2DSoundWithId("AS2D_DIPLO_JUSTINIANI_LATE"))
		else:
			screen.setSoundId(CyAudioGame().Play2DSoundWithId(pLeaderHeadInfo.getDiploPeaceMusicScriptIds(0)))

Unfortunately for Lal and Miriam no sound plays at all during Dawn of Man. For the other leaders the diplo sound still plays.

Does anyone have an idea why 'setSound()' doesn't work here? It works in the Era screen for instance.

That commented out Justinian code doesn't work either. It creates a python exception because the content is a string instead of an int. Is it possible to somehow turn that string into an int perhaps?
 
That commented out Justinian code doesn't work either. It creates a python exception because the content is a string instead of an int. Is it possible to somehow turn that string into an int perhaps?
The general method of getting a type ID from a string is
Code:
gc.getInfoTypeForString(String)
Give that a shot.
 
The unmodded Dawn of Man screen has this rather straightforward code:

Code:
		pActivePlayer = gc.getPlayer(CyGame().getActivePlayer())
		pLeaderHeadInfo = gc.getLeaderHeadInfo(pActivePlayer.getLeaderType())
		screen.setSoundId(CyAudioGame().Play2DSoundWithId(pLeaderHeadInfo.getDiploPeaceMusicScriptIds(0)))

I want another sound than the diplo music to play. Therefore I tested this code:

Code:
		pActivePlayer = gc.getPlayer(CyGame().getActivePlayer())
		pLeaderHeadInfo = gc.getLeaderHeadInfo(pActivePlayer.getLeaderType())
		pLeaderHead = pActivePlayer.getLeaderType()
		if pLeaderHead == gc.getInfoTypeForString('LEADER_PRAVIN_LAL'):
			screen.setSound("AS2D_PEACE")
		elif pLeaderHead == gc.getInfoTypeForString('LEADER_MIRIAM_GODWINSON'):
			screen.setSound("AS2D_DIPLO_JUSTINIANI_LATE")
			##screen.setSoundId(CyAudioGame().Play2DSoundWithId("AS2D_DIPLO_JUSTINIANI_LATE"))
		else:
			screen.setSoundId(CyAudioGame().Play2DSoundWithId(pLeaderHeadInfo.getDiploPeaceMusicScriptIds(0)))

Unfortunately for Lal and Miriam no sound plays at all during Dawn of Man. For the other leaders the diplo sound still plays.

Does anyone have an idea why 'setSound()' doesn't work here? It works in the Era screen for instance.

That commented out Justinian code doesn't work either. It creates a python exception because the content is a string instead of an int. Is it possible to somehow turn that string into an int perhaps?

Are you sure that it is setSound() that isn't working? It could also be that your equality tests don't work as expected and so the else condition always prevails. I would start there - make sure it gets there. Or perhaps you already have. Was the commented code erroring at run time or parse-time?
 
The general method of getting a type ID from a string is
Code:
gc.getInfoTypeForString(String)
Give that a shot.

Ah, thanks.
Strangely, there is no python exception now, but the sound still doesn't play.
Code:
screen.setSoundId(CyAudioGame().Play2DSoundWithId(gc.getInfoTypeForString('AS2D_DIPLO_JUSTINIANI_LATE')))

Are you sure that it is setSound() that isn't working? It could also be that your equality tests don't work as expected and so the else condition always prevails. I would start there - make sure it gets there. Or perhaps you already have. Was the commented code erroring at run time or parse-time?

With 'equality test', do you mean "if pLeaderHead == gc.getInfoTypeForString('LEADER_PRAVIN_LAL'):"?
Given that for Lal and Miriam no sound plays instead of their diplo music, I assume that line of code works.

I don't know what runtime or parse-time means. :confused: The python exception with the commented out code occurs during the Dawn of Man screen.
 
I ended up using a work-around: making a sound play from CvEventManager, like this:

Code:
	def onGameStart(self, argsList):
		'Called at the start of the game'
		if (gc.getGame().getGameTurnYear() == gc.getDefineINT("START_YEAR") and not gc.getGame().isOption(GameOptionTypes.GAMEOPTION_ADVANCED_START)):
			for iPlayer in range(gc.getMAX_PLAYERS()):
				player = gc.getPlayer(iPlayer)
				if (player.isAlive() and player.isHuman()):
					popupInfo = CyPopupInfo()
					popupInfo.setButtonPopupType(ButtonPopupTypes.BUTTONPOPUP_PYTHON_SCREEN)
					popupInfo.setText(u"showDawnOfMan")
					popupInfo.addPopup(iPlayer)
					pActivePlayer = gc.getPlayer(CyGame().getActivePlayer())
					pLeaderHead = pActivePlayer.getLeaderType()
					if pLeaderHead == gc.getInfoTypeForString('LEADER_PRAVIN_LAL'):
						CyInterface().playGeneralSound("AS2D_PEACE")

The consequence of this however is that the sound already starts playing when the game is still "Finishing", when the screen is black, a few seconds before the actual Dawn of Man screen pops up. Not ideal. So if anyone can think of a reason why a sound doesn't work in the dawn of man python file, please do tell! :)
 
I changed Dawn of Man music in Colonization with:

screen.setSoundId(CyAudioGame().Play2DSound("AS2D_KING_OLD"))

Don't know if it works in Civ4 too.
 
Top Bottom