ExpiredReign
Deity
There are a few functions in CEP that may still, if wanted, need to be ported to here.
I'll try and pinpoint the most obvious ones that we could use. There are however a lot of functions that require CEP's secondary functions such as YieldLibrary.lua. As that entire function should be now obsolete a great many of these could be scrapped or redone if needed.
Where possible I'll post the function in its entirety, along with any 'includes' it calls.
I am not 100% aware of all the new DLL functions or existing modded DLL functions as in W's PNM version, so some of these may already be a given.
I'll update this post with additions/removals/suggestions etc.
------
1) function DoCitystateSurrender(player) -- Used in a custom trait assigned to Genghis. -- added as of 21/07/2014
This next one may be pretty contentious. If I am understanding it correctly, it was used to add extra yields to certain plots that are deemed underwhelming, we have already started this discussion elsewhere and it may have a bearing on that.
------
2) function UpdatePlotYields()
------
Also to do with plots, yields and improvements is:
3) function CreateWorkboats(player, techID, changeID)
I think this was to help CSs work their coasts more efficiently.
------
Next is one that does call on a function from YieldLibrary.
4) function GreatImprovementEraBonus(hexX, hexY, cultureArtID, continentArtID, playerID, engineImprovementTypeDoNotUse, improvementID, engineResourceTypeDoNotUse, resID, eraID, improvementState)
I think the intent of that function is self-evident.
Edit: 19/7/14
------
5) function City_ChangeYieldStored(city, yieldID, amount, checkThreshold) -- added as of 22/07/2014
A number of UBs were setup to use this function. This function is used by another custom function (function BuildingCreated(player, city, buildingID)) to provide an instant YIELD as defined in a new table: Building_YieldInstant. That table is created thus:
I'll try and pinpoint the most obvious ones that we could use. There are however a lot of functions that require CEP's secondary functions such as YieldLibrary.lua. As that entire function should be now obsolete a great many of these could be scrapped or redone if needed.
Where possible I'll post the function in its entirety, along with any 'includes' it calls.
I am not 100% aware of all the new DLL functions or existing modded DLL functions as in W's PNM version, so some of these may already be a given.
I'll update this post with additions/removals/suggestions etc.
------
Spoiler :
Code:
function DoCitystateSurrender(player)
if not player:GetTraitInfo().BullySurrender then
return
end
local playerID = player:GetID()
local activePlayer = Players[Game.GetActivePlayer()]
for csID, cs in pairs(Players) do
if cs:IsAliveCiv() and cs:IsMinorCiv() and cs:CanMajorBullyUnit(playerID) and cs:IsAtPeace(player) then
local capital = cs:GetCapitalCity()
local alertText = string.format("%s surrenders in fear to %s!", cs:GetName(), player:GetName())
log:Info(alertText)
for city in cs:Cities() do
player:AcquireCity(city, true, false)
end
if activePlayer:HasMet(cs) then
Events.GameplayAlertMessage(alertText, player)
end
end
end
end
This next one may be pretty contentious. If I am understanding it correctly, it was used to add extra yields to certain plots that are deemed underwhelming, we have already started this discussion elsewhere and it may have a bearing on that.
------
2) function UpdatePlotYields()
Spoiler :
Code:
function UpdatePlotYields()
print("UpdatePlotYields Start")
--
if UI:IsLoadedGame() then
return
end
--]]
for plotID, plot in Plots() do
local x = plot:GetX()
local y = plot:GetY()
if plot:GetTerrainType() == TerrainTypes.TERRAIN_DESERT and not plot:IsHills() and plot:GetFeatureType() == -1 then
local resInfo = GameInfo.Resources[plot:GetResourceType()]
if plot:IsFreshWater() then
Game.SetPlotExtraYield( x, y, YieldTypes.YIELD_FOOD, 1)
elseif resInfo then
if resInfo.ResourceClassType == "RESOURCECLASS_BONUS" and resInfo.Type ~= "RESOURCE_STONE" then
Game.SetPlotExtraYield( x, y, YieldTypes.YIELD_FOOD, 1)
elseif resInfo.Happiness > 0 then
Game.SetPlotExtraYield( x, y, YieldTypes.YIELD_GOLD, 1)
elseif not resInfo.TechReveal then
Game.SetPlotExtraYield( x, y, YieldTypes.YIELD_PRODUCTION, 1)
end
end
end
end
print("UpdatePlotYields Done")
end
Events.SequenceGameInitComplete.Add(function() return SafeCall(UpdatePlotYields) end)
------
Also to do with plots, yields and improvements is:
3) function CreateWorkboats(player, techID, changeID)
Spoiler :
Code:
function CreateWorkboats(player, techID, changeID)
local playerID = player:GetID()
if player:IsHuman() then
return
end
local techType = GameInfo.Technologies[techID].Type
for buildInfo in GameInfo.Builds(string.format("ImprovementType IS NOT NULL AND ShowInTechTree AND PrereqTech = '%s'", techType)) do
local improveInfo = GameInfo.Improvements[buildInfo.ImprovementType]
if improveInfo.Water then
log:Info("Checking for workboats %s %s %s", player:GetName(), techType, improveInfo.Type)
for city in player:Cities() do
if city:IsCoastal() then
for plot in Plot_GetPlotsInCircle(city:Plot(), 1, 2) do
local resInfo = GameInfo.Resources[plot:GetResourceType()]
if resInfo and plot:GetPlotType() == PlotTypes.PLOT_OCEAN and plot:GetImprovementType() == -1 then
if Game.HasValue( {ImprovementType=improveInfo.Type, ResourceType=resInfo.Type}, GameInfo.Improvement_ResourceTypes ) then
log:Info(" %s spawned for %s", city:GetName(), resInfo.Type)
player:InitUnitClass("UNITCLASS_WORKBOAT", city:Plot())
end
end
end
end
end
end
end
end
LuaEvents.NewTech.Add(CreateWorkboats)
I think this was to help CSs work their coasts more efficiently.
------
Next is one that does call on a function from YieldLibrary.
4) function GreatImprovementEraBonus(hexX, hexY, cultureArtID, continentArtID, playerID, engineImprovementTypeDoNotUse, improvementID, engineResourceTypeDoNotUse, resID, eraID, improvementState)
Spoiler :
Code:
function GreatImprovementEraBonus(hexX, hexY, cultureArtID, continentArtID, playerID, engineImprovementTypeDoNotUse, improvementID, engineResourceTypeDoNotUse, resID, eraID, improvementState)
--print("OnImprovementCreated");
--print("hexX: " .. hexX);
--print("hexY: " .. hexY);
--print("cultureArtID: " .. cultureArtID);
--print("playerID: " .. playerID);
--print("improvementID: " .. improvementID);
--print("resID: " .. resID);
--print("eraID: " .. eraID);
--print("improvementState: " .. improvementState);
--print("------------------");
local impInfo = GameInfo.Improvements[improvementID]
local player = Players[playerID]
local plot = Map.GetPlot(ToGridFromHex(hexX, hexY))
if not impInfo.CreatedByGreatPerson or eraID == 0 then
return
end
for yieldInfo in GameInfo.Yields() do
local extraYield = GetImprovementExtraYield(impInfo.ID, yieldInfo.ID, player)
if extraYield > 0 then
log:Info("%s + %s %s", impInfo.Type, extraYield, yieldInfo.Type)
Plot_ChangeYield(plot, yieldInfo.ID, extraYield)
end
end
end
I think the intent of that function is self-evident.
Edit: 19/7/14
------
Spoiler :
Code:
function City_ChangeYieldStored(city, yieldID, amount, checkThreshold)
if city == nil then
log:Fatal("City_ChangeYieldStored city=nil")
elseif itemTable and not itemID then
log:Fatal("City_ChangeYieldStored itemID=nil")
end
local player = Players[city:GetOwner()]
if yieldID == YieldTypes.YIELD_FOOD then
city:ChangeFood(amount)
local overflow = City_GetYieldStored(city, yieldID) - City_GetYieldNeeded(city, yieldID)
if checkThreshold and overflow >= 0 then
local totalYieldKept = 0
for building in GameInfo.Buildings("FoodKept <> 0") do
if city:IsHasBuilding(building.ID) then
totalYieldKept = totalYieldKept + building.FoodKept / 100
end
end
city:ChangePopulation(1,true)
city:SetFood(0)
if totalYieldKept > 0 then
log:Warn(
"%s add %s food = %s overflow + %s totalYieldKept * %s City_GetYieldNeeded",
city:GetName(),
overflow + totalYieldKept * City_GetYieldNeeded(city, yieldID),
overflow,
totalYieldKept,
City_GetYieldNeeded(city, yieldID)
)
end
City_ChangeYieldStored(city, yieldID, overflow + totalYieldKept * City_GetYieldNeeded(city, yieldID), true)
end
elseif yieldID == YieldTypes.YIELD_PRODUCTION then
city:ChangeProduction(amount)
elseif yieldID == YieldTypes.YIELD_CULTURE then
city:ChangeJONSCultureStored(amount)
player:ChangeYieldStored(YieldTypes.YIELD_CULTURE, amount)
local overflow = City_GetYieldStored(city, yieldID) - City_GetYieldNeeded(city, yieldID)
if checkThreshold and overflow >= 0 then
city:DoJONSCultureLevelIncrease()
city:SetJONSCultureStored(0)
City_ChangeYieldStored(city, yieldID, overflow, true)
end
elseif yieldID == YieldTypes.YIELD_POPULATION then
city:ChangePopulation(amount, true)
else
player:ChangeYieldStored(yieldID, amount)
end
end
A number of UBs were setup to use this function. This function is used by another custom function (function BuildingCreated(player, city, buildingID)) to provide an instant YIELD as defined in a new table: Building_YieldInstant. That table is created thus:
Code:
CREATE TABLE IF NOT EXISTS
Building_YieldInstant (
BuildingType text REFERENCES Buildings(Type),
YieldType text,
Yield integer NOT NULL
);