City.SetBuildingGreatWork

LastSword

Prince
Joined
Feb 24, 2013
Messages
1,129
Short: I want to fill building great work slot with LUA.

SetBuildingGreatWork(? ? ?)
I don't know what to put in ? ? ?, I was only creating greatwork of art (+2 culture and tourism), but not in palace slot.
 
SetBuildingGreatWork(BuildingClassType, iSlot, iGreatWorkIndex)
 
The code for that Lua function, DLL-side:

Code:
int CvLuaCity::lSetBuildingGreatWork(lua_State* L)
{
	CvCity* pkCity = GetInstance(L);
	const BuildingClassTypes iIndex = toValue<BuildingClassTypes>(L, 2);
	const int iSlot = lua_tointeger(L, 3);
	const int iGreatWorkIndex = lua_tointeger(L, 4);
	if(iIndex != NO_BUILDING)
	{
		pkCity->GetCityBuildings()->SetBuildingGreatWork(iIndex, iSlot, iGreatWorkIndex);
	}
	return 1;
}

The code that actually sets the work in place:

Code:
void CvCityBuildings::SetBuildingGreatWork(BuildingClassTypes eBuildingClass, int iSlot, int iGreatWorkIndex)
{
	for(std::vector<BuildingGreatWork>::iterator it = m_aBuildingGreatWork.begin(); it != m_aBuildingGreatWork.end(); ++it)
	{
		if((*it).eBuildingClass == eBuildingClass && (*it).iSlot == iSlot)
		{
			int iOldGreatWorkIndex = (*it).iGreatWorkIndex;
			if (iOldGreatWorkIndex != iGreatWorkIndex)
			{
				if (iGreatWorkIndex == -1)
				{
					m_aBuildingGreatWork.erase(it);
				}
				else
				{
					(*it).iGreatWorkIndex = iGreatWorkIndex;
				}
			}

			GC.GetEngineUserInterface()->setDirty(CityInfo_DIRTY_BIT, true);
			return;
		}
	}

	if (iGreatWorkIndex != -1)
	{
		BuildingGreatWork kWork;
		kWork.eBuildingClass = eBuildingClass;
		kWork.iSlot = iSlot;
		kWork.iGreatWorkIndex = iGreatWorkIndex;
		m_aBuildingGreatWork.push_back(kWork);
	}

	GC.GetEngineUserInterface()->setDirty(CityInfo_DIRTY_BIT, true);
}

It looks like the first parameter is the BuildingClass of the building you're putting the work in. (GameInfoTypes.BUILDINGCLASS_OPERA_HOUSE, for example, if I'm not mistaken.) The second one looks like it's the index of the slot you want to use. I haven't looked thoroughly, but I imagine a building that has great works slots has a 0-indexed list, so the first work slot is slot 0, second is 1, etc. The last one is the index of the great work. I haven't done any work with Great Works yet, so this might be completely wrong, but I'd imagine it's also the database ID. So, GameInfoTypes.GREAT_WORK_VETRUVIAN_MAN or whatever the work you want to use.
 
Thank you.

I had tried it (class, slot, art) before and it was devastating for city view (really strange things happened). Back to testing. Thanks once more.

@Edit:
It is not GameInfoTypes.GREAT_WORK(...).
I assume Great Works are indexed after creation, so you can get the GreatWorkType from Game.GetGreatWorkType(iGreatWorkIndex). Since there is no LUA function to create work... it seems SetBuildingGreatWork can be only used to move Great Works.
 
Back
Top Bottom