Upgradable Buildings?

Civilicious

Warlord
Joined
Mar 14, 2005
Messages
109
Location
United States of Canada
I was reading an old thread by snaitf about trying to make buildings that were upgradable, or that would be destroyed when the upgrade was built, did anyone ever figure out how to code that? Lopez said it was on his list to do but this was back in March. Could not find any other posts on this topic or mention of it in any of the mods I looked through.

http://forums.civfanatics.com/showthread.php?t=146404

Just curious if anyone had done this yet, I know a way to do it but it dosen't involve anything flashy modding.
 
Civilicious,

I do have some very rough code that I started on using the SDK, but my life kinda changed reciently... anyways, I should have some beta code ready in a couple of weeks.
 
I also have (unless I lost it) some code for Building Upgrading. In the past all python based Building upgrading systems have failed because of the following senario, three buildings with the following upgrade paths.

A-> B -> C

Its trivial to remove A when B is built or B when C is built by doing a loopthrogh existing buildings as the new one is processed. But dis-allowing construction of A once B OR C is in existence has proven difficulte. My solution was to add a Boolean array to the City "DoseUpgradedFormOfExist" which is checked durring canConstruct() bo block construction of earlier forms of an upgrade. When new buildings are added/removed a recursive check is performed to update the array. By putting all the heavy lifting at Processing time the canConstruct function which is called all the time by the AI and UI only has to do an additional boolean check so the performance hit is minimized.

Using this system its even possible to have branching upgrade paths so for example A & B both upgrade to C, once C exists both A and B are removed and unbuildable.

I'm not planning on developing this right now though so if I find that code I'll pass it along here for you too to have a look at, It was just some stuff I jotted down on NotePad at work, its never even been through a spellchecker so be warned.
 
I have no programming knowledge and just got back into civ as I am building a computer that will let me run it but I saw that thread and was interested in the idea as a way to reduce city graphics clutter, get rid of ancient buildings like aqueduct (which are buggy anyway) in the modern eras.

Since I have a complete lack of knowledge about python/xml/sdk I was looking at this from another way...

Use the code provided by snaitf to make a building destroy/remove a previous building. Or write your own code for that, that should be simple for experienced people.

At this point the problem seems to be that the AI will go rebuild the destroyed building, defeating the purpose of the upgrade path.

Make the previous building 'Obsolete with tech' required to build the upgrade.

For example if you want building factory to remove forge, I mean what towns have a forge in the modern world? I forget which tech lets you build factory lets say it is 'industrialism'. Make the factory destroy forge, then make forge building 'obsolete with industrialism'.

The Ai will research industrialism, build a factory, destroying the forge, and they will be unable to build the forge again as it is obsolete.

I got this idea from the religious monasteries, if you dont build them before you get 'scientific method' you can't as they are obsoleted after researching it and removed from the build queue options.
 
Problem - Any OTHER city controled by that player would be unable to build the initial building and would be totaly screweed as you would have no Forge OR factory EVER in that City. Concoured Cities frequently loose many buildings, under your proposal these will be permenantly crippled. I am afraid theirs no XML based means of achiving this it will definatly require SDK work.
 
I am not suggesting making your second building in the upgrade line, in this example factory, require forge as prerequisite.

A second city would have no trouble building a factory one the tech was researched, even if they had no forge.

The only problem as I see it is that a city founded late in the game would not be able to build the primitive low cost buildings like forge, granary, etc that would speed up its growth, thats not really a showstopper for me anyway.

This works for the purpose I want, namely to clear up graphics clutter and get rid of older buildings, this might not meet the needs of others in regards to this issue
 
Ok, after thinking about it I see where you might be coming from.

The code/programming/whatever would have to be written such that the city builds the Factory, then checks for a forge and destroys it if it exists in the city. If it was just set up to automatically build factory and then destroy forge it might have some sort of issue if there wasn't a forge in the town. Altho this seems like a minor issue that could be easily handled, again I don't know anything about the programming.
 
I agree with impaler, it will definately involve SDK work. In fact, I have scrapped my old code since a new solution came to me in my sleep. Basically I plan to add two new tags to the building info XML schema.

Here is an example of how the first tag would work if the building was a forge:
Code:
			<BuildingClassUpgrades>
				<BuildingClassUpgrade>
					<BuildingClassUpgradeType>BUILDINGCLASS_FACTORY</BuildingClassUpgradeType>
					<bBuildingClassUpgrade>1</bBuildingClassUpgrade>
				</BuildingClassUpgrade>
			</BuildingClassUpgrades>

An example of how the second tag would work is:
Code:
			<BuildingsObsoleted>
				<BuildingObsoleted>
					<BuildingClassType>BUILDINGCLASS_FACTORY</BuildingClassType>
					<bBuildingClassObsoleted>1</bBuildingClassObsoleted>
				</BuildingObsoleted>
			</BuildingsObsoleted>

Is is used to remove a building from a city when the new building is built. If the old building isn't removed then it still is in the city but not listed in the city's building list.

How does this solution sound?
 
I think I see ware your going, the City will hold a BuildingClass boolean array for all obsoleted buildings, when new buildings are processed the array is updated and the old building removed but rather then a recursive search it will be upto the person moding the XML to properly list the obsoleted building. The array is then checked in canConstruct check to prevent it being re-built.

Its definatly a simpler solution from the coding perspective, the recursive searching based aproatch would only require the first tag but considering the upgrade chains are likly only going to be 3 buildings long its realy not very difficult to place the data in XML.

One possible issue would be multiple buildings which obsolete the same lower level building being removed, when the first one is unprocessed it would re-allow the building even though theirs still another structure that should prevent its being built. Possible solution would be to use an int array initialized to zeros with each processed building adding or subtracting one. Then simply cast the int to bool and you have your obsolesence.

I couldn't find that recursive code of mine and as your method is looking much simpler/straitforward I'd say go with it.
 
I'll see what I can do... but don't expect much more from me today or tomorrow since we are having an official naming ceremony today for my son today and his first professional baby shoot tomorrow...
 
An update, I am still working on this mod component. I am just making sure that everything is showing up correctly (which has taken me longer than expected)
 
Back
Top Bottom