[Question] Something unclear about buildings

Hisu

Chieftain
Joined
Nov 6, 2014
Messages
9
I've looked up wiki and several mod guides, as well as searched the forum some, but still, I've got a... problem, one might say. Currently, I want to mod in the Bazaar building for all civilizations, BUT I want it to:
a) show up in the queue only when the Market has been built (that's covered)
b) remove the Market instead of being built alongside.
c) upon removal of the Market, hide that Market from production queue.
So, basically, I want Bazaar to be sorta upgrade to Market.

Is there a way to do it? If yes, how do you instruct a building to destroy its own requirement and hide the latter from production queue?
 
There's a ReplacementBuildingClass column in the Buildings table. No Building uses it in the base game, so it may not be hooked up, and I'm not sure if it refers to the BuildingClass that's being replaced or doing the replacing. I assume you added a new BUILDINGCLASS_BAZAAR that you can put in that field for the BUILDING_MARKET row (or try putting BUILDINGCLASS_MARKET in the BUILDING_BAZAAR row).

If that doesn't work, you'd have to use Lua.
 
It does lock out (or hide?) buildings I apply it to, but doesn't seem to do anything else.
Thanks for lua suggestion; unfortunately, I'm no programmer, so I guess I'll try and ask c++/lua section to make me a script that'll do it...
 
There's a ReplacementBuildingClass column in the Buildings table. No Building uses it in the base game, so it may not be hooked up, and I'm not sure if it refers to the BuildingClass that's being replaced or doing the replacing. I assume you added a new BUILDINGCLASS_BAZAAR that you can put in that field for the BUILDING_MARKET row (or try putting BUILDINGCLASS_MARKET in the BUILDING_BAZAAR row).

If that doesn't work, you'd have to use Lua.

ReplacementBuildingClass is not used anywhere in the stock/vanilla game files, but I can say for certain that it is hooked up, and does indeed work -- I am using it in my mod currently.

The only issue is that there does exist a couple quirks about how it works.

ReplacementBuildingClass must be attached to the source building, as it defines which building class replaces the current building.
Unfortunately, this means that in order to replace a Market, you would need to either edit/update the Market entry globally, or create a unique Market copy for a particular Civ so that you can attach the column to it.

On the specifics of how it works, it only really does half of what you think it would do.

Upon the discovery of the technology which unlocks the replacement building, all existing instances of the to-be-replaced building are not swapped for this new building -- they stay!
However, all currently-under-production* are swapped over to the new building with their construction progress intact, and the old building will no longer show up as available to build.

* There is a caveat with this swapping - it seems the game internally might only look at this along the lines of PlayerDoTurn or something similar, as this "swap" is delayed by one turn in my testing. What this means is that if an "old" building is constructed on the same turn that the "new" building is unlocked by research, the game fails to swap it in time. If there is at least 1 turn remaining on construction, so long as the user does not attempt to reassign construction the building will be swapped, and progress (hammers invested) preserved. If at any point the user reassigns construction manually to the new building, all hammers will be lost.

There exists a secondary caveat!
If the building requires a strategic resource to build, and the Empire no longer has any more available, all versions of the building will appear although they will be unbuildable due to lack of a resource. It appears to be a flaw with the logic the game uses to display buildings which have no available resource -- normally invisible since the game does not replace any buildings!

But as a specific example, if the Market and Bazaar both required Horses, once available Horses were exhausted, both the Market and Bazaar would show up in the city build list, but greyed out, citing lack of horses. Once Horses are acquired, the Market disappears again.

What does all this mean?
Unfortunately, if you want to do upgradeable buildings, you will still need some Lua to actually replace the buildings manually.
I've done this in my Civ/mod, except I have a chain of 3 upgradeable buildings, and I had to resort to a combination of ReplacementBuildingClass and some Lua to get everything working cleanly and seamlessly.

WARNING
There is yet another side effect of using ReplacementBuildingClass -- whatever building you replace will no longer be eligible for construction, as stated above.
However, for buildings which are a prerequisite for another building, such as Shrines and Markets, the replacement building will not count as a valid prerequisite! This can mean that a replaced Shrine will not allow you to build a regular Shrine anymore, and thus block you from ever building a Temple.

You cannot give it a building from the same building class either, as the column is called ReplacementBuildingClass, and the game will refuse to recognize it if it was not specified as a UB for a specific Civ.

(Ask me how many issues I've run into now to know about this...)

I was going to point you to LeeS' advanced building guide here, but upon a quick glace, it appears he does not have a section on this column available yet. I've worked with him already to work out these specifics, but I imagine he hasn't had time to update his guide.

In short, yes, OP, it is possible to do -- I do it with my mod, with a more complicated chain of 3 replacement buildings, but the same logic applies.

Your best bet is to update the Market to have ReplacementBuildingClass pointing to your new Bazaar.
This will take care of hiding the building, as well as allowing the ability to preserve hammers spent building the Market when the Bazaars get unlocked.

In Lua, you will need to come up with a function to actually replace said building, using SetNumRealBuilding(). You'll also need to plan around any buildings which rely on the Market being present (East India Company, I believe.)
 
There's a ReplacementBuildingClass column in the Buildings table. No Building uses it in the base game, so it may not be hooked up, and I'm not sure if it refers to the BuildingClass that's being replaced or doing the replacing. I assume you added a new BUILDINGCLASS_BAZAAR that you can put in that field for the BUILDING_MARKET row (or try putting BUILDINGCLASS_MARKET in the BUILDING_BAZAAR row).

If that doesn't work, you'd have to use Lua.
As DarkScythe mentioned in his description of how it works, <ReplacementBuildingClass> is stated within the Row for the building that will be replaced. So if you add a new BUILDINGCLASS_BAZAAR and have
Code:
<ReplacementBuildingClass>BUILDINGCLASS_BAZAAR</ReplacementBuildingClass>
in the <Buildings> Row for the regular Market building, the new version Building from within the BUILDINGCLASS_BAZAAR will replace the Market (as noted by DarkScythe) when the <PreReqTech> for BUILDINGCLASS_BAZAAR Buildings is researched. This will utterly break the <Building_ClassesNeededInCity> and <Building_PrereqBuildingClasses> Tables. In the case under discussion, in practical terms no player would be able to build Banks, Stock Exchanges, or the East India Company. You cannot get around this issue by adding a row to either <Building_ClassesNeededInCity> or <Building_PrereqBuildingClasses> such as
Code:
	<Building_ClassesNeededInCity>
		<Row>
			<BuildingType>BUILDING_BANK</BuildingType>
			<BuildingClassType>BUILDINGCLASS_BAZAAR </BuildingClassType>
		</Row>
	</Building_ClassesNeededInCity>
because the table acts like an AND Table, with the result that both a Market-Class Building and a New-Bazaar-Class Building would be required. It would be an impossible pre-condition to meet for any city that did not manage to build a Market before the New-Bazaar-Building's unlocking tech was researched.

I cannot urge strongly enough to NOT use <ReplacementBuildingClass> in relation with (or close to relation with) any building that is listed as a prerequisite for any other building in either the <Building_ClassesNeededInCity> or <Building_PrereqBuildingClasses>. I know DarkScythe came up with a method that worked, but I also know he spent an inordinate amount of time tinkering with lua to get it to work.

And no I haven't had time of late to update the guide with what I've learned about ReplacementBuildingClass from my own and DarkScythe's experiments. Real Life got in the way -- and will continue to do so for about the next month. All I have time for nowadays is an hour or so skim and surf on forum until likely sometime late this month, or perhaps even sometime in December.
 
So, basically, the only way to make a reliable system of buildings upgradable through production (meaning, not automatically by reaching certain tech level or completing some other event) is some soft of an extremely intricate lua script? If so, I take it no one will help me on that monkey-way (as in, building a simple example explaining its hows and whys so I could learn by doing and extend it), just because it's too complex while holding little to no interest for experts.

Can't say I'm motivated by that, but thank you for explanations, people. I'm glad this didn't hang on for weeks or months as it usually does when you try to ask an expert on your average internet forum. It's a bit disappointing that the first issue with mods turns out I have to code in some mechanic game doesn't actually have, but oh well (I think I should just get used to it, since trying to mod beam weapons into Freelancer, lol)... They say negative answer is still an answer, and I thank you again, for answering the question instead of just replying to it ^_^

I'll pester you with some silly lua crap in the appropriate subforum somewhere in the near future, I guess. Kudos!
 
Not necessarily.

If I am understanding what you are trying to do correctly, it should still be doable, but yes, it will require some Lua. Probably not overly complicated, though.

The bigger problem is that the Market is a prerequisite for several other buildings, so if you remove it, those buildings will no longer be able to be built, unless you provide an alternate build path for them.

As an example:
In my Civ, I have an "upgrade" building which replaces the Shrine. However, as you noticed from my earlier post, the Shrine is a prerequisite building for the Temple. This meant that any city in which I swapped in my "upgraded Shrine" would be unable to build a Temple.

I got around this issue by creating a new "unique" Temple, which was a carbon copy of the standard Temple sans Shrine requirement, gave it to my Civ as a unique building, then used Lua to fake the Shrine dependency.

This would be far simpler if you were okay with modifying a building which was not used as a prerequisite.

As well, you would also need to specify which edition of the game you would make this compatible with, as BNW added a slew of new Lua methods that probably won't be recognized in G&K or Vanilla.

Off the top of my head, the latest patch to BNW included a new Game Event hook to catch when a city finished constructing a building. You could theoretically use this hook to fire off a Lua function which would check the city for the presence of a Market, and to remove it if found.
 
Anyway, I don't jack about lua and its code is well... odd, to say the least. I'm more or less accustomed to scripting languages like *sh, cmd, vb* and php, but this?.. I just can't figure it out. I never tried languages that have notions like ~= or nil. So yeah, first three hours in attempts to understand how lua works have resulted with nothing.
I'll try and find some step-by-step guide along the lines of "how to port your xml mod to lua" and continue from there. From my scripting experience, the best method to tackle the issue would be hiding the prerequisite and nulling its bonuses, but then again, I don't know how straightforward it is for lua. Might be some really complex haggis, so I can't guess or consider guesses about algorithms. Until I know how to implement them, that is.

Thank you for the answer, but I'm sorry for not being able to follow your recommendations. I guess I just can't do it right now, so no point discussing how should I approach the issue at hand.
 
ReplacementBuildingClass is not used anywhere in the stock/vanilla game files, but I can say for certain that it is hooked up, and does indeed work -- I am using it in my mod currently.

The only issue is that there does exist a couple quirks about how it works.

ReplacementBuildingClass must be attached to the source building, as it defines which building class replaces the current building.
Unfortunately, this means that in order to replace a Market, you would need to either edit/update the Market entry globally, or create a unique Market copy for a particular Civ so that you can attach the column to it.

On the specifics of how it works, it only really does half of what you think it would do.

Upon the discovery of the technology which unlocks the replacement building, all existing instances of the to-be-replaced building are not swapped for this new building -- they stay!
However, all currently-under-production* are swapped over to the new building with their construction progress intact, and the old building will no longer show up as available to build.

* There is a caveat with this swapping - it seems the game internally might only look at this along the lines of PlayerDoTurn or something similar, as this "swap" is delayed by one turn in my testing. What this means is that if an "old" building is constructed on the same turn that the "new" building is unlocked by research, the game fails to swap it in time. If there is at least 1 turn remaining on construction, so long as the user does not attempt to reassign construction the building will be swapped, and progress (hammers invested) preserved. If at any point the user reassigns construction manually to the new building, all hammers will be lost.

There exists a secondary caveat!
If the building requires a strategic resource to build, and the Empire no longer has any more available, all versions of the building will appear although they will be unbuildable due to lack of a resource. It appears to be a flaw with the logic the game uses to display buildings which have no available resource -- normally invisible since the game does not replace any buildings!

But as a specific example, if the Market and Bazaar both required Horses, once available Horses were exhausted, both the Market and Bazaar would show up in the city build list, but greyed out, citing lack of horses. Once Horses are acquired, the Market disappears again.

What does all this mean?
Unfortunately, if you want to do upgradeable buildings, you will still need some Lua to actually replace the buildings manually.
I've done this in my Civ/mod, except I have a chain of 3 upgradeable buildings, and I had to resort to a combination of ReplacementBuildingClass and some Lua to get everything working cleanly and seamlessly.

WARNING
There is yet another side effect of using ReplacementBuildingClass -- whatever building you replace will no longer be eligible for construction, as stated above.
However, for buildings which are a prerequisite for another building, such as Shrines and Markets, the replacement building will not count as a valid prerequisite! This can mean that a replaced Shrine will not allow you to build a regular Shrine anymore, and thus block you from ever building a Temple.

You cannot give it a building from the same building class either, as the column is called ReplacementBuildingClass, and the game will refuse to recognize it if it was not specified as a UB for a specific Civ.

(Ask me how many issues I've run into now to know about this...)

I was going to point you to LeeS' advanced building guide here, but upon a quick glace, it appears he does not have a section on this column available yet. I've worked with him already to work out these specifics, but I imagine he hasn't had time to update his guide.

In short, yes, OP, it is possible to do -- I do it with my mod, with a more complicated chain of 3 replacement buildings, but the same logic applies.

Your best bet is to update the Market to have ReplacementBuildingClass pointing to your new Bazaar.
This will take care of hiding the building, as well as allowing the ability to preserve hammers spent building the Market when the Bazaars get unlocked.

In Lua, you will need to come up with a function to actually replace said building, using SetNumRealBuilding(). You'll also need to plan around any buildings which rely on the Market being present (East India Company, I believe.)

Just for other's who search for a workaround:

- add a "ghostbuilding" which is not buildable
- add a FreeBuildingThisCity "ghostbuilding" and ReplacementBuildingClass "newbuilding" to the building which will be replaced
- add the FreeBuildingThisCity "ghostbuilding" to the "newbuilding"
- update the prerequisite for the other buildings to the "ghostbuilding"
- set the proper Building_LockedBuildingClasses: ghostbuilding in city, replaced not possible (should suppress the old building from showing)

with a little sql, its done very quick and it works for all
 
Just for other's who search for a workaround:

- add a "ghostbuilding" which is not buildable
- add a FreeBuildingThisCity "ghostbuilding" and ReplacementBuildingClass "newbuilding" to the building which will be replaced
- add the FreeBuildingThisCity "ghostbuilding" to the "newbuilding"
- update the prerequisite for the other buildings to the "ghostbuilding"
- set the proper Building_LockedBuildingClasses: ghostbuilding in city, replaced not possible (should suppress the old building from showing)

with a little sql, its done very quick and it works for all
How does it display in the civilopedia for the buildings that are using "ghostbuilding" as their prerequisite under the <Building_ClassesNeededInCity> ?
 
How does it display in the civilopedia for the buildings that are using "ghostbuilding" as their prerequisite under the <Building_ClassesNeededInCity> ?

you will know a 100% solution ... ok :D

- add a nice text for our ghostbuilding or just be lazy and link to your text from the replaced building
 
you will know a 100% solution ... ok :D

- add a nice text for our ghostbuilding or just be lazy and link to your text from the replaced building
Sorry. I was unclear.

In the normal game, when you look at the Civilopedia for the Bank, it will show Market as being a required building in the city. So how well does the civilopedia do at showing the "ghostbuilding" in similar cases?

I have had some ugly results on the Civilopedia with dummy or hidden buildings used as direct uniques for a civ, for example. You can get the ugly yellow "blob" instead of a valid icon showing.

I assume if one were to use the Market's Icon for the "ghostbuilding" it would look okay in the case of the prerequisite building for the Bank's civilopedia page? But it would show that required building's name as whatever you called the "ghostbuilding" for its <Description> tag.
 
Sorry. I was unclear.

In the normal game, when you look at the Civilopedia for the Bank, it will show Market as being a required building in the city. So how well does the civilopedia do at showing the "ghostbuilding" in similar cases?

I have had some ugly results on the Civilopedia with dummy or hidden buildings used as direct uniques for a civ, for example. You can get the ugly yellow "blob" instead of a valid icon showing.

I assume if one were to use the Market's Icon for the "ghostbuilding" it would look okay in the case of the prerequisite building for the Bank's civilopedia page? But it would show that required building's name as whatever you called the "ghostbuilding" for its <Description> tag.

... just be lazy and link to your text from the replaced building
 
Top Bottom