Creating and swapping Great Works with lua

The_Space_Cows

Chieftain
Joined
Mar 18, 2023
Messages
16
I am making a mod that would allow a player to obtain Great Works from City States via some method (any method I can actually get to work will do).

The current idea is to detect when a Great Merchant is used for a trade mission inside a city states borders, and then to give that player a Great Work of Art, where the creator of that Great Work is the City State and not the player. (This would allow theming bonus requirements to be fulfilled without trading with other players). It is the second part I am having trouble with.

There is virtually no information on the wiki about Lua methods doing anything with Great Works.


I am using whoward69's DLL, "DLL - Various Mod Components," and there are a few methods:
- Game.CreateGreatWork(eGreatWorkType, ePlayer, eEra, sCreator) *returns an int*
-
pPlayer:DoSwapGreatWorks(eFocusYield)

But I don't understand some of these parameters. My understanding (possibly wrong) is the first method's parameters are supposed to be
- a specific Great Work's Type, i.e. GameInfoTypes.GREAT_WORK_*whatever great work*
- the player ID of the owner of the Great Work
- the game Era, i.e. GameInfoTypes.ERA_ANCIENT
- the name of the Great Artist in string format (could I just put "test" in here?)

Regarding the second method, I have no clue what eFocusYield is referencing. Doesn't sound like it has anything to do with Great Works.
 
The function DoSwapGreatWorks just triggers an optimization routine that put a GW open for swap but do not make the swap itself.
Looking at the CultureOverview.lua file that codes how the panel for swapping GW works you can find the function Network.SendSwapGreatWorks that actually does the swap but you don't need it.

In the function CreateGreatWork the first argument is not the type of GW but the ID from the database table GreatWorks where the GW of all types are stored.
The int given as result from the CreateGreatWork function is an index number that you can use to assign the GW to a building that has a free GW slot of the appropriate type.
So the basic gist of the procedure should be:

Code:
local  iGreatWorkIndex = Game.CreateGreatWork(GameInfoTypes.GREAT_WORK_MONALISA, CityStateID, GameInfoTypes.ERA_SOMETHING)
-- you select a city of the merchant player that has a building with an available slot of appropriate type:
pCity:SetBuildingGreatWork(iBuildingClass, iSlot, iGreatWorkIndex)
 
Last edited:
DoSwapGreatWorks(eFocusYield) runs the code to optimise the placement of great works into buildings to maximise the selected yield. In the vanilla game eFocusYield is always culture, but in a modded DLL buildings can support different yields from great works (eg GWs in Universities yield science). The last action of DoSwapGreatWorks() when run for an AI player is to pick the worst GWs that the AI would be willing to swap.
 
Do Great Artists Writers and Musicians hold information about what Great Work they're going to create from the moment they spawn?

Is there an easy way to create a 'random' great work of art or writing?
 
Do Great Artists Writers and Musicians hold information about what Great Work they're going to create from the moment they spawn?
Yes, see Unit_UniqueNames in CIV5Units_Expansion2.xml

IIRC great works don't have to be unique, so you can use SQL to pick one at random
 
Top Bottom