[SOLVED] Help merging python for settlers

DarkC

Chieftain
Joined
May 8, 2012
Messages
55
there are a few settler mods out there that i want to combine to my mod. so, in my mod's CvEventManager.py, i entered the command

Spoiler :
def onCityBuilt(self, argsList):
'City Built'
city = argsList[0]
pUnit = CyInterface().getHeadSelectedUnit()

if pUnit.getUnitClassType() == gc.getInfoTypeForString("UNITCLASS_SETTLER_WAGON"):
:)city.setPopulation(2)


which works and gives 2pop when the unit settler wagon builts a city. the problem is, i also want this unit to give free buildings when it builts a city. i tried to add


Spoiler :
def onCityBuilt(self, argsList):
'City Built'
city = argsList[0]
pUnit = CyInterface().getHeadSelectedUnit()

if pUnit.getUnitClassType() == gc.getInfoTypeForString("UNITCLASS_SETTLER_WAGON"):
:)city.setPopulation(2)
:)_addBuilding(city, "BUILDINGCLASS_BARRACKS")



but not only it doesn't add anything, it also disables the above 2pop command. is there a way to connect/bridge these two commands?

edit: the smilies were placed there to adjust the command lines in correct place since space didn't seem to work
 
Additional codes needed if you are adding buildings that have UBs.
Else, even for Zulu, you are gonna add regular Barracks instead of its UB.
Worse, they can still build their UB and you end up with Barrack and UB.
 
hi platyping :) ,
you are absolutely right! more code needs to be added for UB's. i was looking at this code that i found in another mod

Spoiler :
for i in range(len(lBuildings)):
iBuilding = lBuildings
iUnique = gc.getCivilizationInfo(pPlayer.getCivilizationType()).getCivilizationBuildings(iBuilding)
# Use UB instead if it exists
if iUnique > -1:
iBuilding = iUnique
# Add building to city
city.setNumRealBuilding(iBuilding, 1)


and was experimenting with it for some hours trying to merge that too but ofcourse with no success :D . any idea what is missing?

the working code in "def onCityBuilt" so far is

Spoiler :
def onCityBuilt(self, argsList):
'City Built'
city = argsList[0]
pUnit = CyInterface().getHeadSelectedUnit()

if (city.getOwner() == CyGame().getActivePlayer()):
self.__eventEditCityNameBegin(city, False)
CvUtil.pyPrint('City Built Event: %s' %(city.getName()))
if pUnit.getUnitClassType() == gc.getInfoTypeForString("UNITCLASS_SETTLER_WAGON"):
city.setPopulation(2)
city.setNumRealBuilding(gc.getInfoTypeForString("BUILDING_BARRACKS"),1)
 
Not at my modding computer, so can't remember for the life of me.
I believe:
pPlayer = gc.getPlayer(city.getOwner())
iUnique = gc.getCivilizationInfo(pPlayer.getCivilizationType()).getCivilizationBuildings(gc.getInfoTypeForString("BUILDINGCLASS_BARRACKS"))
city.setNumRealBuilding(iUnique,1)

For reference, you can see my Tokyo National Museum
 
thanks for the reply platyping :) i'm gonna test it right away and post results.

ps: i was browsing through your thread the other day and i must say the stuff you uploaded there are really awesome (i already added three :) ) !!
 
Hi DarkC,

I´m using the same mod-component for my mod, I´m still merging, and I believe it´s working, but some more friends are still testing it.

I´m using the Better BAT AI as the base, so I´ve added it as a seperated python-file and it´s loaded with this line in the init-file of the config-folder:

Code:
	<!-- SiedlerMOD Start -->
	<events module="SettlersMPEventManager" class="SettlersEventManager"/>
	<!-- SiedlerMOD Ende -->

Unique Buildings are build and I hope it will be working for MP too, because it´s avoiding getActivePlayer and using ModNetMessages.

The red lines are only needed when you want to use platypings new traits like I do.

Code:
from CvPythonExtensions import *
import CvUtil

gc = CyGlobalContext()

class SettlersEventManager:
	def __init__(self, eventManager):
		eventManager.addEventHandler("cityBuilt", self.onCityBuilt)
		eventManager.addEventHandler("ModNetMessage", self.onModNetMessage)

	def onCityBuilt(self, argsList):
		'City Built'
		city = argsList[0]

		if city.getOwner() == gc.getGame().getActivePlayer() :
                        pUnit = CyInterface().getHeadSelectedUnit() # note that if the unit is grouped,headUnit is not forced to be the settler
                        if pUnit:
                                iOwner = city.getOwner()
                                iCityID = city.getID()
                                iUnitClass = pUnit.getUnitClassType()
                                CyMessageControl().sendModNetMessage(167, iOwner, iCityID, iUnitClass, -1) # be sure 167 is not use for another mod net message, the best should be to add an id in CvUtil like for events
                        
	def onModNetMessage(self, argsList):
		'Called whenever CyMessageControl().sendModNetMessage() is called - this is all for you modders!'
		
		iData1, iData2, iData3, iData4, iData5 = argsList
		if iData1 == 167 :
                        addBuildings(iData2, iData3, iData4)

		CvUtil.pyPrint( 'onModNetMessage' )

def addBuildings(iOwner, iCityID, iUnitClass):
        city = gc.getPlayer(iOwner).getCity(iCityID)
        pPlayer = gc.getPlayer(iOwner)
		
        #if iUnitClass == gc.getInfoTypeForString("UNITCLASS_SETTLER"):
        #	## Do Nothing
        #	pass

        if iUnitClass == gc.getInfoTypeForString("UNITCLASS_COLONIST"):
                city.setPopulation(3)
[COLOR="Red"]                if pPlayer.hasTrait(gc.getInfoTypeForString("TRAIT_EXPANSIVE")):
                        city.changePopulation(1)[/COLOR]
                _addBuilding(city, "BUILDINGCLASS_BARRACKS")
                _addBuilding(city, "BUILDINGCLASS_GRANARY")
                _addBuilding(city, "BUILDINGCLASS_FORGE")
                _addBuilding(city, "BUILDINGCLASS_MARKET")
                if city.plot().isCoastalLand():
                        _addBuilding(city, "BUILDINGCLASS_HARBOR")
                        _addBuilding(city, "BUILDINGCLASS_LIGHTHOUSE")

        elif iUnitClass == gc.getInfoTypeForString("UNITCLASS_PIONEER"):
                city.setPopulation(4)
[COLOR="Red"]                if pPlayer.hasTrait(gc.getInfoTypeForString("TRAIT_EXPANSIVE")):
                        city.changePopulation(1)[/COLOR]
                _addBuilding(city, "BUILDINGCLASS_GARRISON")
                _addBuilding(city, "BUILDINGCLASS_GRANARY")
                _addBuilding(city, "BUILDINGCLASS_FORGE")
                _addBuilding(city, "BUILDINGCLASS_COURTHOUSE")
                _addBuilding(city, "BUILDINGCLASS_MARKET")
                _addBuilding(city, "BUILDINGCLASS_STABLE")
                _addBuilding(city, "BUILDINGCLASS_GROCER")
                _addBuilding(city, "BUILDINGCLASS_BANK")
                _addBuilding(city, "BUILDINGCLASS_LIBRARY")
                if city.plot().isCoastalLand():
                        _addBuilding(city, "BUILDINGCLASS_HARBOR")
                        _addBuilding(city, "BUILDINGCLASS_LIGHTHOUSE")

        elif iUnitClass == gc.getInfoTypeForString("UNITCLASS_ARCHITECT"):
[COLOR="Red"]                if pPlayer.hasTrait(gc.getInfoTypeForString("TRAIT_EXPANSIVE")):
                        city.changePopulation(1)[/COLOR]
        	_addBuilding(city, "BUILDINGCLASS_BARRACKS")
        	_addBuilding(city, "BUILDINGCLASS_GRANARY")
        	_addBuilding(city, "BUILDINGCLASS_COURTHOUSE")
        	_addBuilding(city, "BUILDINGCLASS_MARKET")
        	_addBuilding(city, "BUILDINGCLASS_STABLE")
        	_addBuilding(city, "BUILDINGCLASS_GROCER")
        	_addBuilding(city, "BUILDINGCLASS_AQUEDUCT")
        	_addBuilding(city, "BUILDINGCLASS_BANK")
        	_addBuilding(city, "BUILDINGCLASS_FORGE")
        	_addBuilding(city, "BUILDINGCLASS_LIBRARY")
        	_addBuilding(city, "BUILDINGCLASS_JAIL")
        	_addBuilding(city, "BUILDINGCLASS_OBSERVATORY")
        	_addBuilding(city, "BUILDINGCLASS_THEATRE")
        	_addBuilding(city, "BUILDINGCLASS_CUSTOM_HOUSE")
        	_addBuilding(city, "BUILDINGCLASS_INDUSTRIAL_PARK")
        	_addBuilding(city, "BUILDINGCLASS_LEVEE")
        	_addBuilding(city, "BUILDINGCLASS_PUBLIC_TRANSPORTATION")
        	if city.plot().isCoastalLand():
        		_addBuilding(city, "BUILDINGCLASS_HARBOR")
        		_addBuilding(city, "BUILDINGCLASS_LIGHTHOUSE")

def _addBuilding(pCity, szBuilding):
	iBuilding = gc.getInfoTypeForString(szBuilding)
	iUniqueBuilding = gc.getCivilizationInfo(gc.getPlayer(pCity.getOwner()).getCivilizationType()).getCivilizationBuildings(iBuilding)
	if iUniqueBuilding > -1:
		if pCity.canConstruct(iUniqueBuilding, False, True, False):
			pCity.setNumRealBuilding(iUniqueBuilding, pCity.getNumRealBuilding(iUniqueBuilding) + 1)
 
Back
Top Bottom