Looking for a "query"...

Monaldinio

Prince
Joined
Jan 6, 2010
Messages
415
Location
Rostock
If a certain building is finished, a Bunker Unit will be created in the city, but in some cases, it could be that there is already a bunker unit in the City...
In this case, finishing the building should not create another bunker unit.
Any Ideas? :confused:


PHP:
def onBuildingBuilt(self, argsList):
		'Building Completed'
		self.parent.onBuildingBuilt(self, argsList)
		pCity, iBuildingType = argsList
		game = gc.getGame()
		
		player = pCity.getOwner()
		pPlayer = gc.getPlayer(player)
		pPlot = pCity.plot()


		if iBuildingType == gc.getInfoTypeForString('BUILDING_PERIMETER_DEFENSE') or iBuildingType == gc.getInfoTypeForString('BUILDING_PIRATES_SEAWALL'):
			pUnit = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_BUNKER'), pCity.getX(), pCity.getY(), UnitAITypes.UNITAI_IMMOBILE, DirectionTypes.DIRECTION_NORTH)
 
If a certain building is finished, a Bunker Unit will be created in the city, but in some cases, it could be that there is already a bunker unit in the City...
In this case, finishing the building should not create another bunker unit.
Any Ideas? :confused:


PHP:
def onBuildingBuilt(self, argsList):
		'Building Completed'
		self.parent.onBuildingBuilt(self, argsList)
		pCity, iBuildingType = argsList
		game = gc.getGame()
		
		player = pCity.getOwner()
		pPlayer = gc.getPlayer(player)
		pPlot = pCity.plot()


		if iBuildingType == gc.getInfoTypeForString('BUILDING_PERIMETER_DEFENSE') or iBuildingType == gc.getInfoTypeForString('BUILDING_PIRATES_SEAWALL'):
			pUnit = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_BUNKER'), pCity.getX(), pCity.getY(), UnitAITypes.UNITAI_IMMOBILE, DirectionTypes.DIRECTION_NORTH)

Been there, done that... Use the following code:

Code:
def onBuildingBuilt(self, argsList): 
	'Building Completed' 
	self.parent.onBuildingBuilt(self, argsList) 
	pCity, iBuildingType = argsList 
	game = gc.getGame() 
         
	player = pCity.getOwner() 
	pPlayer = gc.getPlayer(player) 
	pPlot = pCity.plot() 

	bHasBunkerUnit = False
	iPERIMETER_DEFENSE = gc.getInfoTypeForString('BUILDING_PERIMETER_DEFENSE')
	iPIRATES_SEAWALL = gc.getInfoTypeForString('BUILDING_PIRATES_SEAWALL')


	if iBuildingType == iPERIMETER_DEFENSE or iBuildingType == iPIRATES_SEAWALL:
		for iUnitLoop in range (pPlot.getNumUnits()):
			if (iUnitLoop != UnitTypes.NO_UNIT):
				xUnit = pPlot.getUnit(iUnitLoop)
				ixUnitType = xUnit.getUnitType()

				if ixUnitType = gc.getInfoTypeForString('UNIT_BUNKER'):	
					bHasBunkerUnit = True

		if not (bHasBunkerUnit):
			pUnit = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_BUNKER'), pCity.getX(), pCity.getY(), UnitAITypes.UNITAI_IMMOBILE, DirectionTypes.DIRECTION_NORTH)
 
Been there, done that... Use the following code:

Code:
def onBuildingBuilt(self, argsList): 
	'Building Completed' 
	self.parent.onBuildingBuilt(self, argsList) 
	pCity, iBuildingType = argsList 
	game = gc.getGame() 
         
	player = pCity.getOwner() 
	pPlayer = gc.getPlayer(player) 
	pPlot = pCity.plot() 

	bHasBunkerUnit = False
	iPERIMETER_DEFENSE = gc.getInfoTypeForString('BUILDING_PERIMETER_DEFENSE')
	iPIRATES_SEAWALL = gc.getInfoTypeForString('BUILDING_PIRATES_SEAWALL')


	if iBuildingType == iPERIMETER_DEFENSE or iBuildingType == iPIRATES_SEAWALL:
		for iUnit in range (pPlot.getNumUnits()):
			if (iUnit != UnitTypes.NO_UNIT):
				if iUnit = gc.getInfoTypeForString('UNIT_BUNKER'):	
					bHasBunkerUnit = True

		if (bHasBunkerUnit):
			pUnit = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_BUNKER'), pCity.getX(), pCity.getY(), UnitAITypes.UNITAI_IMMOBILE, DirectionTypes.DIRECTION_NORTH)





Oh, looks a little bit cleaner than my Code


PHP:
#####Abfrage ob nach fertigstellung des Perimeters schon Bunker vorhanden, wenn vorhanden, keinen weiteren Bunker setzen#####			
			
		if iBuildingType == gc.getInfoTypeForString('BUILDING_PERIMETER_DEFENSE') or iBuildingType == gc.getInfoTypeForString('BUILDING_PIRATES_SEAWALL') or iBuildingType == gc.getInfoTypeForString('BUILDING_WELLEN_SEAWALL'):
			iBunker = gc.getInfoTypeForString('UNIT_BUNKER')
			bBunker = false
			pCityPlot = gc.getMap().plot(pCity.getX(), pCity.getY())
			for iUnit in range (pCityPlot.getNumUnits()):    #####Achte hier daruaf, dass pCityPlot korrekt definiert wird!!!#####
				iUnitType = pCityPlot.getUnit(iUnit).getUnitType()
				if (iUnitType == iBunker):
					bBunker = true
					break
			if (bBunker == false):
				pUnit = pPlayer.initUnit( iBunker , pCity.getX(), pCity.getY(), UnitAITypes.UNITAI_IMMOBILE, DirectionTypes.DIRECTION_NORTH)
#####Abfrage ENDE#####
 
I updated it again. Please refresh the page. You caught me developing the code...


...Error Message in the red line...?!?


Code:
def onBuildingBuilt(self, argsList): 
	'Building Completed' 
	self.parent.onBuildingBuilt(self, argsList) 
	pCity, iBuildingType = argsList 
	game = gc.getGame() 
         
	player = pCity.getOwner() 
	pPlayer = gc.getPlayer(player) 
	pPlot = pCity.plot() 

	bHasBunkerUnit = False
	iPERIMETER_DEFENSE = gc.getInfoTypeForString('BUILDING_PERIMETER_DEFENSE')
	iPIRATES_SEAWALL = gc.getInfoTypeForString('BUILDING_PIRATES_SEAWALL')


	if iBuildingType == iPERIMETER_DEFENSE or iBuildingType == iPIRATES_SEAWALL:
		for iUnit in range (pPlot.getNumUnits()):
			if (iUnit != UnitTypes.NO_UNIT):
				[COLOR="Red"]if iUnit = gc.getInfoTypeForString('UNIT_BUNKER'):[/COLOR]	
					bHasBunkerUnit = True

		if (bHasBunkerUnit):
			pUnit = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_BUNKER'), pCity.getX(), pCity.getY(), UnitAITypes.UNITAI_IMMOBILE, DirectionTypes.DIRECTION_NORTH)

Edit...ou...wait....
 
...Error in red line...Syntax Error.

Code:
#####Abfrage ob nach fertigstellung des Perimeters schon Bunker vorhanden, wenn vorhanden, keinen weiteren Bunker setzen#####			
			
		bHasBunkerUnit = False
		iPERIMETER_DEFENSE = gc.getInfoTypeForString('BUILDING_PERIMETER_DEFENSE')
		iPIRATES_SEAWALL = gc.getInfoTypeForString('BUILDING_PIRATES_SEAWALL')
		iWELLEN_SEAWALL = gc.getInfoTypeForString('BUILDING_WELLEN_SEAWALL')

		if iBuildingType == iPERIMETER_DEFENSE or iBuildingType == iPIRATES_SEAWALL or iBuildingType == iiWELLEN_SEAWALL:
			for iUnitLoop in range (pPlot.getNumUnits()):
				if (iUnitLoop != UnitTypes.NO_UNIT):
					xUnit = pPlot.getUnit(iUnitLoop)
					ixUnitType = xUnit.getUnitType()

					[COLOR="Red"]if ixUnitType = gc.getInfoTypeForString('UNIT_BUNKER'):	[/COLOR]
						bHasBunkerUnit = True

			if not (bHasBunkerUnit):
				pUnit = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_BUNKER'), pCity.getX(), pCity.getY(), UnitAITypes.UNITAI_IMMOBILE, DirectionTypes.DIRECTION_NORTH)
#####Abfrage ENDE#####
 
...Error in red line...Syntax Error.

Code:
#####Abfrage ob nach fertigstellung des Perimeters schon Bunker vorhanden, wenn vorhanden, keinen weiteren Bunker setzen#####			
			
		bHasBunkerUnit = False
		iPERIMETER_DEFENSE = gc.getInfoTypeForString('BUILDING_PERIMETER_DEFENSE')
		iPIRATES_SEAWALL = gc.getInfoTypeForString('BUILDING_PIRATES_SEAWALL')
		iWELLEN_SEAWALL = gc.getInfoTypeForString('BUILDING_WELLEN_SEAWALL')

		if iBuildingType == iPERIMETER_DEFENSE or iBuildingType == iPIRATES_SEAWALL or iBuildingType == iiWELLEN_SEAWALL:
			for iUnitLoop in range (pPlot.getNumUnits()):
				if (iUnitLoop != UnitTypes.NO_UNIT):
					xUnit = pPlot.getUnit(iUnitLoop)
					ixUnitType = xUnit.getUnitType()

					[COLOR="Red"]if ixUnitType = gc.getInfoTypeForString('UNIT_BUNKER'):	[/COLOR]
						bHasBunkerUnit = True

			if not (bHasBunkerUnit):
				pUnit = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_BUNKER'), pCity.getX(), pCity.getY(), UnitAITypes.UNITAI_IMMOBILE, DirectionTypes.DIRECTION_NORTH)
#####Abfrage ENDE#####

It should be "==" not "="

Sorry for the mistake.
 
Top Bottom