Build Cities with Buildings

Admiral Armada

The Admiral of Armadas
Joined
Sep 11, 2004
Messages
462
Location
Terra
So im trying to incorporate Navy Seals Settler mod into my current mod setup, and i could not get it to function properly, so i tried to play it alone and it still does not work. I think I've figured out where things are going wrong, i just cant figure out why.

So the function of interest is here (i think)
Code:
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.setHasRealBuilding(iUniqueBuilding, True)

And its being used like this:
Code:
_addBuilding(city, "BUILDINGCLASS_COURTHOUSE")

I just cant figure out where in the function it is doing anything.
Any insights would be appreciated :).

And once i conquer this problem, then i have to try merging the custom event managers, which hasn't worked yet, fun times.
 
If this is supposed to work with BTS, the function on the last line is incorrect. With BTS things were changed so that a single city can have more than one of the same building. You can't set that a city has the building; you must set how many it has.

The last line should be

Code:
pCity.setNumRealBuilding(iUniqueBuilding, 1)

The rest looks okay. It converts the string to the building class ID, then gets the actual building for that class, and finally builds it in the city if the city will accept it.
 
So i need to change the line
pCity.setHasRealBuilding(iUniqueBuilding, True)
to
pCity.setNumRealBuilding(iUniqueBuilding, 1)

Sweet, it works too thanks, been messing with that for a few days now:).
But only on an empty CustomAssets folder, what would affect its working that lives in CustomAssets? Unless i miss my guess, Customasstets overrides other files loaded elsewhere, but i cant see what file would override this one.

Also, now that this works, i need to merge the custom event managers, they are fairly similar, except for these line in the Settlers one
Code:
def beginEvent( self, context, argsList=-1 ):
		"Begin Event"
		if(self.CustomEvents.has_key(context)):
			return self.CustomEvents[context][2](argsList)
		else:
			return CvEventManager.CvEventManager.beginEvent(self, context, argsList)
			
	def applyEvent( self, argsList ):
		'Apply the effects of an event '
		context, playerID, netUserData, popupReturn = argsList
		
		if(self.CustomEvents.has_key(context)):
			entry = self.CustomEvents[context]
			# the apply function
			return entry[1]( playerID, netUserData, popupReturn )   
		else:
			return CvEventManager.CvEventManager.applyEvent(self, argsList)


	def addCustomEventDefinition(self, eventType, eventDefinition):
		self.CustomEvents[eventType] = eventDefinition

	def removeCustomEventDefinition(self, eventType):
		del self.CustomEvents[eventType]

	def setCustomEventDefinition(self, eventType, eventDefinition):
		self.CustomEvents[eventType] = eventDefinition
I tried copying these lines into the main Custom event manager file but, as well as putting the lines importing the mods own event manager in the places with the other ones, the import line and the calling line (i think).
This one has really been driving me bonkers because the settlers don't found with the correct population even.
Thanks again :)
 
Huzzah!
It works!
Tried it without those weird lines from the customeventmanager and it works!

Thanks for your help, couldn't have done it without you
 
I'm trying to do something similar, but I'd rather bypass python if it is possible, and just code directly into the SDK, creating an apropriat unit infos tag along the way. Unfortunately I can't follow how a city is created.

In CvCity there is the function CvCity::Init, however I can't find where this is called, or what triggers it. Does anyone know, or have any ideas how I can trace the functions that are called and executed in the dll when you click the found city button in the unit interface? Is the found city button a python thing? If so where is this controlled so that I can add in a new argument to pass along to the dll if a unit is "special" and has it's XML in the unit infos defined to create specific buildings in the newly founded city?

I'm not looking for specific code to get this to work, I'm looking for the functions I need to work with, as I'd prefer to write my own code, as this way I know how things are working. Plus when I write my own code I generally try to make it as soft coded as possible allowing future modders to utilize and customize the features in the XML, which I'm pretty sure wouldn't be the way any existant code that implements this works.


Edit:
Yeah, searching around the closest thing I could find was the Settlers Mod. And like I remembered, this does not work, as it's entirely hard coded. It functions by adding some code into the function onCityBuilt in CvEventManager. I can't use this for various reasons. So basically, I'm looking for the actual function that gets fired when you click the found city button; I'm fairly certain I can code the rest myself from there, but unfortunatly the only thing I can find with regards to founding a city in the SDK is CvCity::Init, and I can't find where this is triggered, or how we get from clicking the settler button to this function.
 
Try CvUnit::found() in CvUnit.cpp

Thanks, yeah, that looks to be it. It leads to CvPlayer::Found, which looks like the right path.
 
Yeah, that was definitely it. It's working perfectly now, thanks again.
 
Top Bottom