Purchasing unique units/buildings with faith

Tarmont

Empress
Joined
Feb 26, 2014
Messages
1,312
Location
Brazil
I'm trying to make a building that only the holy roman empire can purchase with faith, and cannot be built any other way, similar to those buildings that require a religion belief but only for the HRE. How do I do that? I've obviously tried using xml with Civilization_BuildingClassOverrides, but also using lua with PlayerCanConstruct, but nothing worked. (The building appears, but for everyone)

Note: For some reason this building also seems to be able to be purchased infinite times.
 
Unfortunately, this is a matter of it being hardcoded in the DLL. Unless the building/unit requires a belief, all conditions restricting that building will be ignored; this includes the requirement of a specific civilisation or technology, and usually ends up meaning any player can purchase that building with faith.

I've had many a woeful experience trying to get it working - with my Franks, Armenia and Papal States mods I sought a unique building or unit that could only be purchased with faith, but that didn't end well...
 
Try the attached zipped versions of a test mod. Both introduce the same basic building 'Chapel' and make it specific to America. One is structured as a stand-alone building class that can only be acquired via faith and after researching the Physics tech. The second is a temple replacement that again can only be acquired through faith purchase, and is unlocked at Philosophy (just like the standard Temple) and requires a Shrine (also just like the standard temple).

I tested both versions using IGE to 'force things along', and as both America and Rome. Behavior was exactly as hoped for / expected.

The trick is adding the building class into all of the follower beliefs under the <Belief_BuildingClassFaithPurchase> table. The downside of course would be all those mods that add umpteen jillion new follower beliefs would also have to be taken into account if you wanted to add complete compatibility for your civilization mod.

Also note that since the building is set only to be acquired through faith purchasing it shows in the civilopedia as a 'Religious' building instead of in the normal position within the 'buildings-by-era' headers.

Oh, sorry, forgot to mention: ignore anything showing in the civilopedia etc. coming from the <Language_en_US> table. This test mod is something I've had laying around to test things with, and I never bothered to change anything in the TXT_KEY descriptions, etc. What shows in the civilopedia is at least six versions of tests old.
 

Attachments

  • Chapels as Temples.zip
    2.7 KB · Views: 141
  • Chapels as a Stand-Alone Class.zip
    2.8 KB · Views: 82
The trick is adding the building class into all of the follower beliefs under the <Belief_BuildingClassFaithPurchase> table. The downside of course would be all those mods that add umpteen jillion new follower beliefs would also have to be taken into account if you wanted to add complete compatibility for your civilization mod.

This can actually be solved with a SQL trigger, such that any additions to the Beliefs table automatically add the according entry in Belief_BuildingClassFaithPurchase.

Off the cuff I imagine it'd be something like...
Code:
CREATE TRIGGER AddBuildingClassFaithPurchase AFTER INSERT ON Beliefs FOR EACH ROW BEGIN
INSERT INTO Belief_BuildingClassFaithPurchase (BeliefType, BuildingClassType) VALUES(NEW.Type, "BUILDINGCLASS_CHAPEL");
END
(Note that I didn't proofcheck or test that code)
 
This can actually be solved with a SQL trigger, such that any additions to the Beliefs table automatically add the according entry in Belief_BuildingClassFaithPurchase.

Off the cuff I imagine it'd be something like...
Code:
CREATE TRIGGER AddBuildingClassFaithPurchase AFTER INSERT ON Beliefs FOR EACH ROW BEGIN
INSERT INTO Belief_BuildingClassFaithPurchase (BeliefType, BuildingClassType) VALUES(NEW.Type, "BUILDINGCLASS_CHAPEL");
END
(Note that I didn't proofcheck or test that code)
I'm still a-struggling a bit with using SQL for more than real simple stuff like inserting a new column into a table. That having said, I think the problem is that your code would cause an entry in the Belief_BuildingClassFaithPurchase table for any added new belief, and not just the Follower or Reformation ones. The game ignores any Rows in the Belief_BuildingClassFaithPurchase table that are not Follower or Reformation. I can't remember from when I tested on this whether inclusion of Pantheon (forex) Beliefs within the Belief_BuildingClassFaithPurchase table also cause crash-y or other bizzare behaviors.

So it would be necessary to only add those new beliefs that have columns <Follower> or <Reformation> within the <Beliefs> table set to "true". Not sure how in the world one would try to do that in SQL.

And as a side-note, I'm kind of impressed with myself that even understood what that code was doing. That is, erm, if I did actually understand it correctly. :eek:
 
Indeed I forgot to consider that, but SQLite also supports a WHEN clause for conditional triggers. With that in mind:

Code:
CREATE TRIGGER AddBuildingClassFaithPurchase AFTER INSERT ON Beliefs FOR EACH ROW WHEN Follower <> 0 OR Reformation <> 0
BEGIN
INSERT INTO Belief_BuildingClassFaithPurchase (BeliefType, BuildingClassType) VALUES(NEW.Type, "BUILDINGCLASS_CHAPEL");
END

I used <> 0 because I'm actually not sure if XML-true is 1 in the database. It probably is, though.

Heh, SQL is actually fairly understandable when queries are simple.
 
Top Bottom