Craig_Sutter
Deity
I am getting some unexpected print statements from a bit of code I am using. The intent is to check for a religion and check faith cost for a building vrs player's faith and ability to purchase, then to force buy the building if there is enough faith.
And I may get a print statement like...
... repeated over several turns.
Which makes no sense as some of those cities have an Order Chapterhouse installed already and there is no way that enough faith could be acquired in a turn to pay for all those buildings even if none of the cities had a building already.
Which leads me to believed that one of the API functions below is firing unexpectedly...
I have matched each API against its wiki entry... it seems to me that they do not match up as far as how true/false entries match other variables. I did not create the entries, but copied ones that worked. And the functions seem to be working when I play test... but not when I set up autoplay.
There is another possibility in that the purchase restriction is not functioning correctly for religious buildings... maybe there is an unexpected problem in the actual functioning of the lua API, and it is not restricting purchases properly specifically for FAITH due to errors in the lua programming.
Thank-you.
Code:
function BerserkerHallPurchase (iPlayer)
local pPlayer = Players[iPlayer]
if (pPlayer:IsAlive ()) and not pPlayer:IsHuman() then
for pCity in pPlayer:Cities() do
if pCity:GetReligiousMajority() == GameInfoTypes["RELIGION_CONFUCIANISM"] then
local iBuilding = GameInfoTypes.BUILDING_PAGODA
local iBuildingCost = pCity:GetBuildingFaithPurchaseCost(iBuilding)
local currentFaith = pPlayer:GetFaith()
if not pCity:IsHasBuilding( iBuilding ) and pCity:IsCanPurchase(true, true, -1, iBuilding, -1, YieldTypes.YIELD_FAITH) and currentFaith >= iBuildingCost then
Game.CityPurchaseBuilding(pCity, iBuilding, YieldTypes.YIELD_FAITH);
print(pPlayer:GetName(), " is installing Berserker Hall in ", pCity:GetName());
end
end
end
end
end
And I may get a print statement like...
Code:
[15531.927] Cities: Alfred is installing Order Chapterhouse in Winchester
[15531.927] Cities: Alfred is installing Order Chapterhouse in Southampton
[15531.927] Cities: Alfred is installing Order Chapterhouse in Oxford
[15531.927] Cities: Alfred is installing Order Chapterhouse in Dorchester
[15531.943] Cities: Alfred is installing Order Chapterhouse in Glastonbury
[15531.943] Cities: Alfred is installing Order Chapterhouse in Exeter
[15531.943] Cities: Alfred is installing Order Chapterhouse in Llandrindad
[15531.943] Cities: Alfred is installing Order Chapterhouse in Gloucester
[15531.943] Cities: Alfred is installing Order Chapterhouse in Caerwent
[15531.943] Cities: Alfred is installing Order Chapterhouse in Edington
[15531.943] Cities: Alfred is installing Order Chapterhouse in Wroxeter
[15531.943] Cities: Alfred is installing Order Chapterhouse in Wareham
[15531.958] Cities: Alfred is installing Order Chapterhouse in Shaftesbury
[15531.958] Cities: Alfred is installing Order Chapterhouse in Chippenham
... repeated over several turns.
Which makes no sense as some of those cities have an Order Chapterhouse installed already and there is no way that enough faith could be acquired in a turn to pay for all those buildings even if none of the cities had a building already.
Which leads me to believed that one of the API functions below is firing unexpectedly...
I have matched each API against its wiki entry... it seems to me that they do not match up as far as how true/false entries match other variables. I did not create the entries, but copied ones that worked. And the functions seem to be working when I play test... but not when I set up autoplay.
Code:
pCity:IsCanPurchase(true, true, -1, iBuilding, -1, YieldTypes.YIELD_FAITH)
City:IsCanPurchase(UnitType unitType, int buildingType, int projectType, int projectID, int projectID = nil, YieldType yield = nil)
Code:
Game.CityPurchaseBuilding(pCity, iBuilding, YieldTypes.YIELD_FAITH);
Game.CityPurchaseBuilding(City city, UnitType unitType, int buildingType, ProjectType projectTypes)
There is another possibility in that the purchase restriction is not functioning correctly for religious buildings... maybe there is an unexpected problem in the actual functioning of the lua API, and it is not restricting purchases properly specifically for FAITH due to errors in the lua programming.
Thank-you.