Buildings from Great Works (v.1)

Divine Yuri

Never Closes Chrome
Joined
Oct 28, 2014
Messages
89
Location
Brrrr, USA
So as I have made at least a couple times now a way to add a yield from a Great Work using buildings. I decided to simplify (Well for others) the whole ordeal, and made a mod with a table where you can insert a building, and Great Work into. Which will give a copy of the building for every Great Work, but also allow you to setup functions that'll be tested before the great work is given.

If anything isn't clear about how it works from below. Please reply, and I'll get back to you.

Here's what you'll mostly work with:
Code:
CREATE TABLE IF NOT EXISTS 
GreatWorks_GiveBuildingFromGreatWork (
	GreatWorkType	text	references GreatWorks(Type)		default null,
	BuildingType	text	references Buildings(Type)		default null,
	GiveFunction	text						default null,
	Modifier	text						default null
);

To just have it add a building no matter what you keep GiveFunction, and Modifier as null. Then all you need to do is insert the GreatWorks, and BuildingType for the Great Works into the Table.

Though, that isn't the only point of this. I also worked on what I've called GiveFunction. These are functions that returns a boolean, or a integer value. They are sent the player, city, and the Modifier from the table.

There are a few included with the util made by me:
GiveFunction|ModifierType|Returns|Checks
MOST_ADVANCED||Boolean|Checks if the player is the most advanced Civilization.
IS_CIVILIZATION|CivilizationType|Boolean|Checks if CivType is equal to Modifier.
PLAYER_HAS_TECH|TechType|Boolean|Checks if the player has the tech given as the modifier.
PLAYER_HAS_POLICY|PolicyType|Boolean|Checks if the player has the policy given as the modifier.

You can also create your own functions:
Code:
CREATE TABLE IF NOT EXISTS
GreatWorks_GiveBuildingFromGreatWork_GiveFunctionFiles (
	FileName	text	default null
);
(If you do this please make sure the name avoids conflict by adding your name to the variable!)

Import a lua file, and add that file's name (Make sure it's all of it including the .lua to avoid any import problems.) into the above table. Then in that file create a function. The util will send that function the three variables I spoke of above: player (Owner of the Great Work), city (The city the Great Work is in), and the Modifier from the table (As a String). Though you don't need the function to take everyone of the variables. Then the function has to return either a integer, or a boolean. If you return a integer it'll make that many of the building for every Great Work, and if a boolean it'll add one building. It'll treat anything else as a boolean just checking that it returns something.
Here's a example of one of the pre-made functions:
Code:
--Note: getNumTech was put into another function to make it more readable. It just returns te amount of technology the civ has. 
function IF_MostAdvanced( pPlayer, pCity)
	local playerTech = getNumTech(pPlayer:GetID())
	for i = 0, GameDefines.MAX_MAJOR_CIVS do
		if ( playerTech <  getNumTech(i) ) then
			return false;
		end
	end
	return true;
end
GreatWorks_GiveBuildingFromGreatWork_AddIf("MOST_ADVANCED", IF_MostAdvanced)
This function finds if the player is the most advanced civ, and returns true if they are. So what I needed to do was make the function like above, and run the function as a variable to GreatWorks_GiveBuildingFromGreatWork_AddIf. The first variable is how GiveFunction is defined, and the second variable is the function itself.

So that's pretty much it. I'll leave this template replace BUILDING_TYPE with the building the Great Work gives, and replace UNIT_TYPE with the unit the great works belong to:
Code:
INSERT INTO GreatWorks_GiveBuildingFromGreatWork 
	(	GreatWorkType,	BuildingType	)
SELECT 	Type,			'BUILDING_TYPE'
FROM GreatWorks WHERE Type IN (SELECT GreatWorkType FROM Unit_UniqueNames WHERE UnitType = 'UNIT_TYPE');

Credit:
Divine Yuri, and Vicevirtuoso - I based this originally on his Hatsune Miku mod.

Just some things to clear up:
  • You can give multiple buildings to a single Great Work.
  • You can give the same building twice to the same Great Work.

About Updates:
The way this util is set up the newest version takes priority Mods with older versions will always work with any updates as I won't change anything major.
 

Attachments

Back
Top Bottom