Tech Discovery

OrionVeteran

Deity
Joined
Dec 25, 2003
Messages
2,443
Location
Newport News VA
I ran into a problem with the "onTechAcquired" function. I had previously believed that this function would detect each and every tech discovery or acquisition. This turned out to be false, as I ran into a scenario where a religious tech was founded, but the onTechAcquired function failed to detect it. This discovery makes the onTechAcquired function a bad choice for triggering other functions that depend on tech discovery. I badly need a function that will detect the discovery or acquisition of any and all techs a player gets, without exception. Is there a function that can be used instead of the onTechAcquired function? I can build a function to perform a tech check, but I have no function to supply the discovered tech.

Spoiler :

Code:
def ReligiousTechCheck(iPlayer, iTechType):
	# Limited Religions	
	pPlayer = gc.getPlayer(iPlayer)
	TechCheck = False

	for iTech in range(gc.getNumTechInfos()):
		# Is this a religious Tech?
		if isReligiousTech(iTech):
			# Does the player have this tech?						
			if gc.getTeam(pPlayer.getTeam()).isHasTech(iTech):
				[COLOR="Red"][B]if iTech == iTechType:[/B][/COLOR]
					TechCheck = True
					break

	return TechCheck


There are other ways to get a religious tech type, but again, I do not have a reliable source to compare it to (notice bold line). Any ideas would be greatly appreciated, as I have been struggling with this for a long time.

Respectfully,

Orion Veteran :cool:
 
I'm not quite sure I understand your question. Or at least, I don't see how the first half relates to the second half.

You would like to have a function which is guaranteed to trigger when a tech is acquired. Well, onTechAcquired is that function. Can you give some details about why you think it is not always triggered? Is it possible that another mod which you have also integrated (such as revolutions, or one of the limited religion mods) is catching the event before you get it? If you can give a standalone example of the event failing to trigger, that would be very helpful.

The second half of your question with the code and the line in red does not seem to be related. Are you looking for a function which will tell whether a particular tech *might* be the one which triggers a religion to be founded? If that is correct, do you also need to know whether some other team has already founded it? Once you have the integer for your tech, I think you need to loop all the religions and check CvReligionInfo.getTechPrereq to see if it is the tech. I'm not sure how to check if it's founded already, but it isn't clear if you want that.
 
I'm not quite sure I understand your question. Or at least, I don't see how the first half relates to the second half.

You would like to have a function which is guaranteed to trigger when a tech is acquired. Well, onTechAcquired is that function. Can you give some details about why you think it is not always triggered? Is it possible that another mod which you have also integrated (such as revolutions, or one of the limited religion mods) is catching the event before you get it? If you can give a standalone example of the event failing to trigger, that would be very helpful.

The second half of your question with the code and the line in red does not seem to be related. Are you looking for a function which will tell whether a particular tech *might* be the one which triggers a religion to be founded? If that is correct, do you also need to know whether some other team has already founded it? Once you have the integer for your tech, I think you need to loop all the religions and check CvReligionInfo.getTechPrereq to see if it is the tech. I'm not sure how to check if it's founded already, but it isn't clear if you want that.

OK. I will try to be more clear. All is related, top paragraph and the bottom. I am playing a multiplayer game where a Tech, Monotheism, is discovered. This tech is splashed on the screen, but the onTechAcquired function fails to execute a test message. No matter where I placed the test message in the function, it just failed to run. If the onTechAcquired function fails to even run a simple test message, when Monotheism was discovered, there was no way my trigger function to found a religion could possibly run. The plain truth is: the onTechAcquired function did not get called at the time this tech was discovered. However, the tech was discovered at the beginning of the player's turn.

I thought like you did. Perhaps it is because my python is in modular format. Nope! After stripping the code out and placing it in back in the traditional CvEventManager.py file, I had the same result: The onTechAcquired function did not get called, when the tech was discovered and splashed on the screen. I even placed the message to run before anything else ran in the function. It still failed to run. I wondered why this message would run on other techs, but not Monotheism for this player. It does run on almost every other tech acquisition, but for some unknown reason, not in this scenario. This failure of the onTechAcquired function led me to the conclusion that I must develop another function that will detect all tech discoveries, without exception for any given player.

The example function I provided, was just one way of checking to see whether or not the discovered tech is a religious tech. You mentioned the other approach by looping the religions. Either approach will depend upon another function that identifies the tech type discovered or acquired, like you find in the onTechAcquired function. This new function must be reliable to cover every tech discovered for any given player. I think that if I use the onBeginPlayerTurn function, I can be sure my trigger will run on every turn. But I still need to call a function to determine if a tech has been founded and if so identify the tech type. Only then will my trigger work properly. It is this new function that identifies the discovered tech, that I need help in developing.

Respectfully,

Orion Veteran :cool:
 
I don't have the code in front of me, but IIRC the Tech Splash Screen is opened by onTechAcquired. If you saw the splash screen, the function was most definitely called.

I would add some logging statements to the place you want to insert your code to verify that it's called.
 
Yep, the tech splash screen is put up by onTechAcquired.

If you, Orion Veteran, are just adding your code to the end of onTechAcquired you should note that if self.__LOG_TECH is not set to true then the function exits before it gets to the end. False (well, 0) is its default setting.
 
Yep, the tech splash screen is put up by onTechAcquired.

If you, Orion Veteran, are just adding your code to the end of onTechAcquired you should note that if self.__LOG_TECH is not set to true then the function exits before it gets to the end. False (well, 0) is its default setting.

Ran a test with both settings. It made no difference whether self.__LOG_TECH was set to true or false. It did not matter if my test message was at the beginning or the end. It just did not run.

Orion Veteran :cool:
 
In what module are you placing your code? I don't mean the name, CvEventManager, I mean where is it?

  • BTS/Assets
  • CustomAssets
  • Mods/.../Assets
Put a PyPrint message at the beginning of onTechAcquired, or better yet

Code:
CyInterface().addImmediateMessage("onTechAcquired", "")
 
It's time for another Episode of Yet Another Theory.

The tech splash screen is shown by onTechAcquired.
You see the tech splash screen.
Therefore, it absolutely has to be running onTechAcquired...
Unless there is someplace else that will also show the tech splash screen.

So the question is, is it using the file you are editing? Just that file?

Is there, perhaps, some custom event handler, in a different file (of course), that is being used instead of the file you are editing?

Have you searched all the python files in the folder, and sub-folders, for the string "showTechSplash"?

A custom event manager could even run the existing onTechAcquired function in some cases but not others. This sort of thing can explain a lot of weird behavior.

CvEventInterface.py is where the event manager is defined, via the getEventManager function - if this function is not returning, after various aliases are resolved, CvEventManager.CvEventManager() then it is not using the file you are editing.

Todays episode of Yet Another Theory brought to you by the letter W and the Ketchup Advisory Board.
 
In what module are you placing your code? I don't mean the name, CvEventManager, I mean where is it?

  • BTS/Assets
  • CustomAssets
  • Mods/.../Assets
Put a PyPrint message at the beginning of onTechAcquired, or better yet

Code:
CyInterface().addImmediateMessage("onTechAcquired", "")

The onTechAcquired function is in my InquisitionEvents file. All files are in the mod under the BTS mods folder.

Specifically: C:\Program Files\Firaxis Games\Sid Meier's Civilization 4\Beyond the Sword\Mods\Inquisition250D\Assets\Python

The immediate Message works great in single player, as it fired on every tech discovery (sometimes more than once). But in Multiplayer it did not display on the pre-specified tech. Yet, I discovered that my message (with sound) fired between turns but the trigger code failed to found a religion, as it should have (very strange). Neither message was displayed on screen. I'm going to have to tweak this code and insure that it identifies the correct player, when it fires more than once. I now have much to do and test. Looks like I will be busy for a while.

Orion Veteran :cool:
 
Top Bottom