Coding a "semi-unique" building for related civs

isnorden

Amnesiac Modder
Joined
Jul 6, 2012
Messages
608
Location
Madison, Wisconsin, USA
I'm currently working on a mod for a building that any Scandinavian civ can have. Although XML can't directly define which civilizations are Scandinavian or not, I decided to list the ones that qualify (even with modcivs, there are only a few). Will the code I wrote here work as I planned? If not, please tell me what needs editing.

Code:
<!-- Any early Scandinavian civilization may build Runestones in place of the Amphitheater; -->
	<!-- I'm including the official Denmark and Sweden on that list, as well as JFD's versions -->
	<!-- of Iceland and Norway.  If you've coded a Norse civilization and want me to include it -->
	<!-- in a future release of this mod, please let me know! -->
	
	
	<Civilization_BuildingClassOverrides>
	
	
		<Row>
			<CivilizationType>CIVILIZATION_DENMARK</CivilizationType>
			<BuildingClassType>BUILDINGCLASS_AMPHITHEATER</BuildingClassType>
			<BuildingType>BUILDING_RUNESTONE_ISN</BuildingType>
		</Row>
		
		<Row>
			<CivilizationType>CIVILIZATION_SWEDEN</CivilizationType>
			<BuildingClassType>BUILDINGCLASS_AMPHITHEATER</BuildingClassType>
			<BuildingType>BUILDING_RUNESTONE_ISN</BuildingType>
		</Row>
		
		<Row>
			<CivilizationType>CIVILIZATION_JFD_NORWAY</CivilizationType>
			<BuildingClassType>BUILDINGCLASS_AMPHITHEATER</BuildingClassType>
			<BuildingType>BUILDING_RUNESTONE_ISN</BuildingType>
		</Row>
		
		<Row>
			<CivilizationType>CIVILIZATION_JFD_ICELAND</CivilizationType>
			<BuildingClassType>BUILDINGCLASS_AMPHITHEATER</BuildingClassType>
			<BuildingType>BUILDING_RUNESTONE_ISN</BuildingType>
		</Row>
		
	
	</Civilization_BuildingClassOverrides>
 
If you do not want the buildings showing up as unique buildings in the start up screens, another alternative would be lua function playercanbuild. I use that in my mod for "ethnic" buildings and units... otherwise they take up ui slots of truly unique buildings. By the way, I have a fairly good Runestone icon in my mod (located in the scenario forum) which you are welcome to use.

forums.civfanatics.com/showthread.php?t=564543
 
If the game can't find CIVILIZATION_NORWAY or CIVILIZATION_ICELAND (E.g. they're not both enabled), I think the game discards the whole file (and no code is executed from that file), meaning that the UB won't update even for Denmark and Sweden.

How to solve: Set up 3 files; File 1 contains the Denmark and Sweden-update; File 2 contains the Norway update; File 3 contains the Iceland update.

Now, if the player doesn't have the Norway-civ enabled, the Norway-file (file 2) is discarded, but the iceland and DenmarkSweden files (file 1 and 3) are not. This means that the update will fire for Iceland, Denmark and Sweden without problems. (The only problem to this method is that you will get an error in the logs saying that CIVILIZATION_NORWAY doesn't exist (since it's not enabled). You've got to deal with that :smoke:)

Other than that I think it looks fine
 
If you do not want the buildings showing up as unique buildings in the start up screens, another alternative would be lua function playercanbuild. I use that in my mod for "ethnic" buildings and units... otherwise they take up ui slots of truly unique buildings. By the way, I have a fairly good Runestone icon in my mod (located in the scenario forum) which you are welcome to use.

forums.civfanatics.com/showthread.php?t=564543

I have forgotten how to code Lua after 8-9 years out of practice (and my last Lua mod was for a non-Civ game, yet). Could you please point me to your mod so I can grab/tweak the relevant parts? I'll give you credit for them, of course...
 
The page is

forums.civfanatics.com/showthread.php?t=564543

There are a lot of lua files to go through... and most of them have to do with units, not buildings. I will make tge code for you if you are willing to wait a bit.

The Runestone icon is a group of dds files under the art folder within the mod.

There are a lot of Scandanavian related items in the mod.
 
The page is

forums.civfanatics.com/showthread.php?t=564543

There are a lot of lua files to go through... and most of them have to do with units, not buildings. I will make the code for you if you are willing to wait a bit.

The Runestone icon is a group of dds files under the art folder within the mod.

There are a lot of Scandinavian related items in the mod.

Thank you so much; I'm willing to wait a bit longer for something that's likely to work. How soon do you think it will be ready, though?

P.S. Will definitely give those icons a look!
 
Doing a bit of rethinking, and Troller0001's idea might be better despite what I said about using up unique slots in the UI. The lua can work, but there are a couple of problems I've thought of. For one, if you actually want to replace Amphitheater with the Runestone, this cannot be easily done in lua... I can make it so that only Scandinavians can build the Runestone and be unable to build an Amphitheater, but this will cause a problem in that Amphitheater is a prereq building for Museum and Opera House, and the lua method does not take that into account. I am not certain that that problem can be addressed via lua. There is likely a very convoluted method by which this might be done, but XML building classes handle this with no problem.

If you allow the Runestone to be built in addition to the Amphitheater, then it is possible... or if it were replacing a building that was not a building requirement for others.

I can still go ahead on the lua otherwise... but rethinking things might cause a rethink on whether that will accomplish what you wish.
 
If the game can't find CIVILIZATION_NORWAY or CIVILIZATION_ICELAND (E.g. they're not both enabled), I think the game discards the whole file (and no code is executed from that file), meaning that the UB won't update even for Denmark and Sweden.

How to solve: Set up 3 files; File 1 contains the Denmark and Sweden-update; File 2 contains the Norway update; File 3 contains the Iceland update.

Now, if the player doesn't have the Norway-civ enabled, the Norway-file (file 2) is discarded, but the iceland and DenmarkSweden files (file 1 and 3) are not. This means that the update will fire for Iceland, Denmark and Sweden without problems. (The only problem to this method is that you will get an error in the logs saying that CIVILIZATION_NORWAY doesn't exist (since it's not enabled). You've got to deal with that :smoke:)

Other than that I think it looks fine
It should be fine as-is. All that happens is that you get an "Invalid Reference" error in the Database.log file when one of the civilizations listed is not in the game (Ie, does not exist as a Civilization listed under table <Civilizations>).

-------------------------------------------------------

And on a semi-related subject of lua limiting who can build what wonder or building, re the Thermae mod:
Code:
local iRequiredCivilization = GameInfoTypes.CIVILIZATION_ROME
local iBathsOfTrajan = GameInfoTypes.BUILDING_TRAJAN

function PlayerCanBuildTrajan(PlayerID, BuildingType)
	if BuildingType == iBathsOfTrajan then
		local pPlayer = Players[PlayerID]
		return (pPlayer:GetCivilizationType() == iRequiredCivilization)
	end
	return true
end
GameEvents.PlayerCanConstruct.Add(PlayerCanBuildTrajan)

print("BathsOfTrajanScript loaded to end")
The SQL you have in the Thermae V63 doesn't actually work because any civ-mods that load after the SQL executes are not accounted for.

I didn't mention anything on your mod thread while you were on hiatus because well, you had been gone for so long I figured there was no point.

------------------------------------------------------------

For the code of the Scandinavian Civs, you won't be able to use a PlayerCanConstruct lua because such an lua would never execute for BUILDING_RUNESTONE_ISN unless BUILDING_RUNESTONE_ISN is the default building within its class. If it is still inserted into BUILDINGCLASS_AMPHITHEATER no civs can construct BUILDING_RUNESTONE_ISN unless there is a <Civilization_BuildingClassOverrides> to allow it for that civilization, so the game-core never fires the PlayerCanConstruct or CityCanConstruct events for the BUILDING_RUNESTONE_ISN

--------------------------------------------------------------

[edit]

In your mod you will need to add references under the Associations tab in Modbuddy so that JFD's two civilization mods load before yours does. I cannot remember whether Denmark is actually added by one of the DLCs or whether you get it with G&K of BNNW without having to buy any more DLC.
 
It should be fine as-is. All that happens is that you get an "Invalid Reference" error in the Database.log file when one of the civilizations listed is not in the game (Ie, does not exist as a Civilization listed under table <Civilizations>).
[...]

Sometimes a typo/invalid reference will cause a crash, other times it messes up the Civilopedia, and sometimes, as it appears, it doesn't matter at all

Well, at least I learned something today :lol:

Thanks for pointing it out LeeS!
 
So long as you have references to JFD's Civ-mods in your Scandinavian mod, this SQL should work for all cases I think:
Code:
INSERT INTO Civilization_BuildingClassOverrides
		(CivilizationType,		BuildingClassType,		BuildingType) 
VALUES		('CIVILIZATION_DENMARK',	'BUILDINGCLASS_AMPHITHEATER',	'BUILDING_RUNESTONE_ISN'),
		('CIVILIZATION_SWEDEN',		'BUILDINGCLASS_AMPHITHEATER',	'BUILDING_RUNESTONE_ISN'),
		('CIVILIZATION_JFD_NORWAY',	'BUILDINGCLASS_AMPHITHEATER',	'BUILDING_RUNESTONE_ISN'),
		('CIVILIZATION_JFD_ICELAND',	'BUILDINGCLASS_AMPHITHEATER',	'BUILDING_RUNESTONE_ISN');


DELETE FROM Civilization_BuildingClassOverrides WHERE CivilizationType = 'CIVILIZATION_DENMARK' AND BuildingType = 'BUILDING_RUNESTONE_ISN'
AND NOT EXISTS (SELECT 1 FROM Civilizations WHERE Type = 'CIVILIZATION_DENMARK');

DELETE FROM Civilization_BuildingClassOverrides WHERE CivilizationType = 'CIVILIZATION_SWEDEN' AND BuildingType = 'BUILDING_RUNESTONE_ISN'
AND NOT EXISTS (SELECT 1 FROM Civilizations WHERE Type = 'CIVILIZATION_SWEDEN');

DELETE FROM Civilization_BuildingClassOverrides WHERE CivilizationType = 'CIVILIZATION_JFD_NORWAY' AND BuildingType = 'BUILDING_RUNESTONE_ISN'
AND NOT EXISTS (SELECT 1 FROM Civilizations WHERE Type = 'CIVILIZATION_JFD_NORWAY');

DELETE FROM Civilization_BuildingClassOverrides WHERE CivilizationType = 'CIVILIZATION_JFD_ICELAND' AND BuildingType = 'BUILDING_RUNESTONE_ISN'
AND NOT EXISTS (SELECT 1 FROM Civilizations WHERE Type = 'CIVILIZATION_JFD_ICELAND');
There is still a potential in that some other mod that adds a different unique Amphitheater Replacement building for any of these civs could still trample all over your mod. But this potential for clashing is going exist no matter what you do, really.
 
Many thanks to everyone who helped here; you'll all get credit for it. (And a second "thank you" to LeeS for fixing the Baths of Trajan bug; version 64 of the Thermae mod will be coming soon to a computer near you!) :clap:
 
At this stage, I've decided to make the basic Runestone a building-class of its own instead of a substitute within some other class -- and adapted LeeS' Lua script, which he wrote for the Baths of Trajan, to let seven Nordic civs build Runestones. So far, these are the qualified ones:

  1. Denmark from the DLC pack
  2. Sweden from Gods and Kings**
  3. JFD's Commonwealth of Iceland
  4. JFD's Kingdom of Norway
  5. LastSword's Vikings
  6. McKurosu's Iceland
  7. Tryster's Norway

**True, Gustavus Adolphus lived centuries after the Viking Age; but so many runic inscriptions have survived in Sweden that disallowing the Runestone there makes no sense. (With no ancient/medieval Swedish modciv outside a scenario, the default version is the one to include.)

I'm also including two "wonder" runestones allowed only to the civilizations that raised them: the Jelling Stones are Denmark's (they even name Denmark in the inscription), and the Rók Stone is Sweden's (it's a Wonder mainly for being the world's longest surviving runic inscription, written partly in complicated code).

P.S. to Craig Sutter: I'm having a little trouble turning my photos of the Rök Stone into an icon that matches your other two; would you mind giving me a hand? (The close-up of the top front, showing part of the code, is enough to make the icon visually distinct from an "ordinary" runestone.)
 

Attachments

  • rökstenen4.jpg
    rökstenen4.jpg
    16.4 KB · Views: 96
  • rökstenen5.jpg
    rökstenen5.jpg
    14.7 KB · Views: 41
Sure, I will see what I can do. Might be a few days though.

OK, I'm willing to wait; will you need a bigger photo for the Rök Stone's splash screen? I can PM you a zip file if you do...many thanks for helping! :thanx:
 
Gorgeous...keeping the full-length view and the details of the inscription wasn't easy, I bet. Bravissimo! :trophy::thanx: Now I can finish coding this mod..
 
Back
Top Bottom