[LUA] Transferring a Great Work

Xony

Chieftain
Joined
Mar 9, 2016
Messages
99
Hi all,

I'm trying to transfer a Great Work as part of a mod I'm making. Finding the right place seems to work fine as far as I can tell, but Network.SendMoveGreatWorks doesn't seem to do anything. Any help is very appreciated.

Code:
function GetNextFreeSlot (iBuilding, pCity)
	local pBuilding = GameInfo.Buildings[iBuilding]
	local iAvailableSlots = pBuilding.GreatWorkCount
	for iSlot = 0, iAvailableSlots-1, 1 do
          local iWork = pCity:GetBuildingGreatWork(GameInfoTypes[pBuilding.BuildingClass], iSlot)

          if (iWork == -1) then
            return iSlot
          end
    end
end

function AddArti (playerID, sBuildingArtType) 
	local greatWorkArtID	= GameInfoTypes["GREAT_WORK_SLOT_ART_ARTIFACT"]
	local pPlayer = Players[playerID]
	if (pPlayer:HasAvailableGreatWorkSlot(greatWorkArtID)) then
		local capital = pPlayer:GetCapitalCity()
		local capx = capital:GetX()
		local capy = capital:GetY()
		local dummybuildingID		= GameInfoTypes[sBuildingArtType]
		capital:SetNumRealBuilding(dummybuildingID, 1)
		local iBuilding = pPlayer:GetBuildingOfClosestGreatWorkSlot(capx, capy, greatWorkArtID);
		print ("targetbuilding: ".. iBuilding)
		local pCity = pPlayer:GetCityOfClosestGreatWorkSlot(capx, capy, greatWorkArtID);
		local cityID = pCity:GetID()
		local cityname = pPlayer:GetCityByID(cityID):GetName()
		print ("targetcity " ..cityname)
		local slotID = GetNextFreeSlot (iBuilding, pCity)
		print ("targetslot" ..slotID)
		Network.SendMoveGreatWorks(playerID, capital:GetID(), dummybuildingID, 0, cityID, iBuilding, slotID)
		print ("transfered")

		--capital:SetNumRealBuilding(dummybuildingID, 0)
	end
end
 
Define "doesn't seem to do anything" - as you appear to be swapping the contents of an empty slot with the contents of an empty slot, which won't do anything.
 
Ah, sorry. I set up a dummybuilding that provides a free great work in it that I want to input into the AddArti function. So I assumed it would put the Artifact from this dummybuilding into the next empty slot it can find.
Code:
INSERT INTO Buildings		
		(Type, 					BuildingClass, 		 	FreeGreatWork,	Cost, 	FaithCost,	GreatWorkSlotType,		GreatWorkCount,	GoldMaintenance, PlotCultureCostModifier,	Description, 			ConquestProb,	IconAtlas,	PortraitIndex)
VALUES		('BUILDING_XO_PION', 		'BUILDINGCLASS_XO_PION', 	'GREAT_WORK_XO_PION',	-1, 	-1,		'GREAT_WORK_SLOT_ART_ARTIFACT',	1,	0, 			 -1,			'TXT_KEY_ARTIFACT_XO_PION', 		100,			'UNIT_ATLAS_1',	24);
 
Am I missing anything obvious with whoward's advice :confused: I'm kinda stumped.
 
Am I missing anything obvious ...

CultureOverview.lua

Code:
Network.SendMoveGreatWorks(	activePlayerID, 
	g_CurrentGreatWorkSlot.CityID, g_CurrentGreatWorkSlot.Building[B][COLOR="Red"]Class[/COLOR][/B]ID, g_CurrentGreatWorkSlot.GreatWorkSlotIndex, 
	selectionPoint.CityID, selectionPoint.Building[COLOR="red"][B]Class[/B][/COLOR]ID, selectionPoint.GreatWorkSlotIndex)


Code:
local iGwArtOrArtifactSlot = GameInfoTypes.GREAT_WORK_SLOT_ART_ARTIFACT
 
function GetNextFreeSlot(pCity, iBuilding)
    local pBuilding = GameInfo.Buildings[iBuilding]
    local iAvailableSlots = pBuilding.GreatWorkCount
    
    for iSlot = 0, iAvailableSlots-1, 1 do
          local iWork = pCity:GetBuildingGreatWork(GameInfoTypes[pBuilding.BuildingClass], iSlot)
 
          if (iWork == -1) then
            return iSlot
          end
    end
end
 
function AddArti (iPlayer, sBuildingArtType) 
    local pPlayer = Players[iPlayer]
    
    if (pPlayer:HasAvailableGreatWorkSlot(iGwArtOrArtifactSlot)) then
        local pCapital = pPlayer:GetCapitalCity()
        local iCapX = pCapital:GetX()
        local iCapY = pCapital:GetY()
        
        local pCity = pPlayer:GetCityOfClosestGreatWorkSlot(iCapX, iCapY, iGwArtOrArtifactSlot)
        local iBuilding = pPlayer:GetBuildingOfClosestGreatWorkSlot(iCapX, iCapY, iGwArtOrArtifactSlot)
        local iBuildingClass = GameInfoTypes[GameInfo.Buildings[iBuilding].BuildingClass]
        local iSlot = GetNextFreeSlot(pCity, iBuilding)
        print(string.format("target city = %s, building = %s, slot = %i", pCity:GetName(), GameInfo.Buildings[iBuilding].Type, iSlot))
 
        local iDonorBuildingClass = GameInfoTypes[GameInfo.Buildings[sBuildingArtType].BuildingClass]
        pCapital:SetNumRealBuilding(iDonorBuilding, 1)
        
        Network.SendMoveGreatWorks(iPlayer, pCapital:GetID(), iDonorBuildingClass, 0, pCity:GetID(), iBuildingClass, iSlot)
        print("transfered")
 
        --pCapital:SetNumRealBuilding(iDonorBuilding, 0)
    end
end
 
Wow, thank you so much for the solution! I don't know how I didn't thought about this even after I found out that it was my Network.SendMoveGreatWorks line that was not working :crazyeye:
 
Top Bottom