help find error, please

I think i found the bug.
But i'm not sure. Please replace the Python\MercenaryUtils\MercenaryUtils.py with the attached one.


@background:
First, that was not a crash ;). Crash means you suddenly see the desktop.
The game was "waiting for other civilizations", that's a freeze ;).

The game replaces at some points the mercenaries, which you can hire.
In the future era, it could not find enough future mercenaries, but was searching, searching, searching, and did not stop. That was the problem (i think).

I did not really solve the problem. I stopped the searching at some point, but have not really found the reason for the problem.

In case another python coder looks in here:
The problem is in that code part:
Spoiler :
PHP:
		while(len(promotionList) < g_iMinimumStartingMercenaryPromotionCount):
			# Loop until we get a unit that matches the required era
			while(prereqTechEra != iEra):
				promotionList = []
				iCount = iCount+1

				# The random type of unit that will be created
				iUnitType = gc.getGame().getMapRand().get(gc.getNumUnitInfos(), "Random Unit Info")

				# Get the PyUnitInfo for the iUnitType
				pUnitInfo = PyInfo.UnitInfo(iUnitType)

				# If we can't contract out the unit then continue			
				if(not self.canContractOutUnit(pUnitInfo.info)):
					continue

				# Get the list of prereq technologies required for the unit
				unitTechPrereqList = self.getUnitPrereqTechs(pUnitInfo)

				# If the unitTechPrereqList is empty start from the beginning
				if(len(unitTechPrereqList) == 0):
					continue

				# Get the era from the list of prereq. technologies
				prereqTechEra = self.getMaxTechEra(unitTechPrereqList)
			



		

			# Create the mercenary unit if we have a valid iUnitType value
			if(iUnitType != -1):
				# Create the mercenary unit
				#tmpUnit = barbarianPlayer.initUnit(iUnitType, 0, 0, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)

				plot = barbarianPlayer.getStartingPlot()
							
				# Create the mercenary unit
				tmpUnit = barbarianPlayer.initUnit(iUnitType, plot.getX(), plot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)

				# The following two statements can be written as:
				# promotionList = self.getMercenaryPromotions(self.getUnitPromotionList(tmpUnit, iEra))
				# to improve performance. I have provided the code in two lines to improve readability 
				# of the code.
				# Get all of the possible promotions for the mercenary for the give era
				promotionList = self.getEraAppropriateUnitPromotionList(tmpUnit, iEra)

				# Get a random subset of promotions that the mercenary will have.
				promotionList = self.getMercenaryPromotions(promotionList)

				# Set the initial level and experience level for the mercenary
				self.setInitialMercenaryExperience(tmpUnit, promotionList)
								
				# Create the actual mercenary object, we do not pass in the tmpUnit object itself 
				# because we do not want to accidentally set it as the CyUnit in the Mercenary class
				mercenary = Mercenary(MercenaryNameUtils.getRandomMercenaryName(), gc.getUnitInfo(iUnitType), promotionList, tmpUnit.getExperience(), tmpUnit.experienceNeeded())

				# Kill off the tmpUnit since it does not need to exist in the game until someone hires the 
				# mercenary
				tmpUnit.kill(false,PlayerTypes.NO_PLAYER)

I think the inner while loop did not correctly terminate, so i put for testing a counter in there, which just breaks it if it goes >=1000 (which i think should be enough under all circumstances). That "solved" the problem, but not sure what causes it (i'm lazy :blush:).


Edit: Oh, and kudos to The Lopez, good job with commenting and adding debuging text in there. Could not have found the right place without.
 

Attachments

I think i found the bug.
But i'm not sure. Please replace the Python\MercenaryUtils\MercenaryUtils.py with the attached one.

Pasted and after many months I can see my Space Era buildings. Many many thanks, The_J for your 6th help in line. Thanks to you I can release last version.
Spoiler :
attachment.php


@background:
First, that was not a crash ;). Crash means you suddenly see the desktop.
The game was "waiting for other civilizations", that's a freeze ;).

Yes :) "waiting for other civilizations" but after 30 minutes I must restart computer :(

Edit: Oh, and kudos to The Lopez, good job with commenting and adding debuging text in there. Could not have found the right place without.

I wrote to Lopez but without answer. I was hope, he can find why mod read not from restrict list. I´m antipythonist. Maybe is it silly error only.
If somebody can wink on, I be pleased.

P.S. @The_J - your help is for me very important. Thank you very much and write me if I can help to you :goodjob:
Hroch
 
Back
Top Bottom