That will give you per player per turn control over harvesting, but obviously you'll need to add some conditionals to control who and on what turns they are allowed to harvest. If you look in the knowledge base, you'll see there is a
Player:IsMajor(). That will return a true or false, depending on if the player is a major or minor civ. City states are minor civs, so the following will prevent city states from ever harvesting.
Code:
function On_PlayerTurnActivated(iPlayer, bFirstTime)
if Players[iPlayer]:IsMajor() then
Players[iPlayer]:GetTechs():SetTech(GameInfo.Technologies["TECH_DUMMY_HARVEST"].Index, true);
end
end
Events.PlayerTurnActivated.Add(On_PlayerTurnActivated);
The issue at this point, is when do you want to allow or disallow major civs to harvest. It takes the AI a turn or two to get their worker to the resource plot, and it might take more than one turn to harvest it. So harvesting needs to be allowed for a few turns at a time, but give it too much time and it will harvest everything too soon. You need more conditionals!
Looking in the knowledge base, I see a few events that might be related, so I ran a test to see which of those are triggered by harvesting a resource. The only one that did anything was
Events.ResourceRemovedFromMap. That event provides the X and Y of the map plot, plus the type of the resource. I tried removing an iron resource and it gave me the X and Y as expected, but for some reason the type was nil.
Back to the knowledge base. There is a
Map.GetPlotXY(). It takes 2 integers for the X and Y and returns the Plot object for that location. There is a
Plot:GetOwner() which will then tell us who removed the resource. There is also a
Game.GetCurrentGameTurn(). Now when a resource is removed, we can keep track of who removed it and on what turn. If you're using my
WhysMod Template, then saving that data is easy!
Code:
function On_ResourceRemovedFromMap(iX, iY, iType)
local pPlot = Map.GetPlotXY(iX, iY);
local iOwner = pPlot:GetOwner();
local iTurn = Game.GetCurrentGameTurn();
-- WhysMod Template function.
SetSave("player "..tostring(iOwner).." harvested resource", iTurn);
-- no more harvesting.
Players[iOwner]:GetTechs():SetTech(GameInfo.Technologies["TECH_DUMMY_HARVEST"].Index, false);
end
Events.ResourceRemovedFromMap.Add(On_ResourceRemovedFromMap);
Now the
On_PlayerTurnActivated() function would look something like...
Code:
function On_PlayerTurnActivated(iPlayer, bFirstTime)
if Players[iPlayer]:IsMajor() then
-- WhysMod Template function.
local iTurn = GetSave("player "..tostring(iPlayer).." harvested resource");
-- can harvest again 25 turns later.
if iTurn == nil or Game.GetCurrentGameTurn() > iTurn + 25 then
Players[iPlayer]:GetTechs():SetTech(GameInfo.Technologies["TECH_DUMMY_HARVEST"].Index, true);
end
end
end
Events.PlayerTurnActivated.Add(On_PlayerTurnActivated);
I haven't tested this specifically, but it looks about right.