Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2014
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.78 KB | None | 0 0
  1. -- BuildingYieldFromGreatWorksInBuilding
  2. -- Author: Sukritact
  3. --------------------------------------------------------------
  4.  
  5. print("loaded")
  6.  
  7. WARN_NOT_SHARED = false; include( "SaveUtils" ); MY_MOD_NAME = "BuildingYieldFromGreatWorksInBuilding";
  8.  
  9. function BuildingYieldFromGreatWorksInBuilding(iPlayer, pPlayer, bIsTurnStart)
  10.     --print(bIsTurnStart)
  11.     for row in GameInfo.Building_YieldFromGreatWorksInBuilding() do
  12.         local iBuilding = GameInfo.Buildings[row.BuildingType].ID
  13.         strName = GameInfo.Buildings[iBuilding].Description
  14.         local iYield = YieldTypes[row.YieldType]
  15.         local iDeltaModifier = row.Yield
  16.         for pCity in pPlayer:Cities() do
  17.             local iCity = pCity:GetID()
  18.             --local strCityName = pCity:GetName()
  19.             local strBuildingClass = GameInfo.Buildings[iBuilding].BuildingClass
  20.             local iBuildingClass = GameInfo.BuildingClasses[strBuildingClass].ID
  21.             local iGreatWorksNum = pCity:GetNumGreatWorksInBuilding(iBuildingClass)
  22.             local iDelta = (iGreatWorksNum*iDeltaModifier)
  23.             --print (iCity .. strCityName .. iGreatWorksNum)
  24.             if pCity:IsHasBuilding(iBuilding) then
  25.             --print("Building: " .. strName .. " exists in city: " .. strCityName)
  26.                 if iYield == 4 then
  27.                     local iOldDelta = load( pPlayer, iCity .. "B" .. iBuilding .. "Y" .. 4)
  28.                     --print (iYield .. "NUM" .. tostring(iOldDelta))
  29.                     save( pPlayer, iCity .. "B" .. iBuilding .. "Y" .. 4, iDelta)
  30.                     if iOldDelta == nil then
  31.                         pCity:ChangeJONSCulturePerTurnFromBuildings(iDelta)
  32.                     else
  33.                         pCity:ChangeJONSCulturePerTurnFromBuildings(iDelta - iOldDelta)
  34.                     end
  35.                 elseif iYield == 5 then
  36.                     if bIsTurnStart == true then
  37.                         pPlayer:ChangeFaith(iDelta)
  38.                     --else
  39.                         --print ("Not Turn Start")
  40.                     end
  41.                 else
  42.                     local iOldDelta = load( pPlayer, iCity .. "B" .. iBuilding .. "Y" .. iYield)
  43.                     --print (iYield .. "NUM" .. tostring(iOldDelta))
  44.                     save (pPlayer, iCity .. "B" .. iBuilding .. "Y" .. iYield, iDelta)
  45.                     if iOldDelta == nil then
  46.                         pCity:ChangeBaseYieldRateFromBuildings(iYield, iDelta)
  47.                     else
  48.                         pCity:ChangeBaseYieldRateFromBuildings(iYield, iDelta - iOldDelta)
  49.                     end
  50.                 end
  51.                
  52.             -- Clear data if Building does not exist --
  53.            
  54.             else
  55.                 --print("Building: " .. strName .. " does not exist in city: " .. strCityName)
  56.                 if iYield == 4 then
  57.                     local iOldDelta = load( pPlayer, iCity .. "B" .. iBuilding .. "Y" .. 4)
  58.                     if iOldDelta == nil then
  59.                         --print("Never existed")
  60.                     elseif iOldDelta > 0 then
  61.                         save (pPlayer, iCity .. "B" .. iBuilding .. "Y" .. 4, 0)
  62.                         pCity:ChangeJONSCulturePerTurnFromBuildings(-iOldDelta)
  63.                         --print("Data Cleared")
  64.                     end
  65.                 elseif iYield == 5 then
  66.                     --print("Faith = Nil")
  67.                 else
  68.                     local iOldDelta = load( pPlayer, iCity .. "B" .. iBuilding .. "Y" .. iYield)
  69.                     if iOldDelta == nil then
  70.                         --print("Never existed")
  71.                     elseif iOldDelta > 0 then
  72.                         save (pPlayer, iCity .. "B" .. iBuilding .. "Y" .. iYield, 0)
  73.                         pCity:ChangeBaseYieldRateFromBuildings(iYield, -iOldDelta)
  74.                         --print("Data Cleared")
  75.                     end
  76.                 end
  77.             end
  78.         end
  79.     end
  80. end
  81.  
  82. -- End of Main Code --
  83.  
  84. function BuildingYieldFromGreatWorksInBuildingTurnStart(iPlayer, pPlayer)
  85.     --print ("Turn Trigger")
  86.     local pPlayer = Players[iPlayer]
  87.     local bIsTurnStart = true
  88.     BuildingYieldFromGreatWorksInBuilding(iPlayer, pPlayer, bIsTurnStart)
  89. end
  90.  
  91. function BuildingYieldFromGreatWorksInBuildingSwap()
  92.     local iPlayer = Game.GetActivePlayer()
  93.     local pPlayer = Players[iPlayer]
  94.     if pPlayer:IsTurnActive() then
  95.         --print ("Swap Trigger")
  96.         local bIsTurnStart = false
  97.         BuildingYieldFromGreatWorksInBuilding(iPlayer, pPlayer, bIsTurnStart)
  98.     end
  99. end
  100.  
  101. GameEvents.PlayerDoTurn.Add(BuildingYieldFromGreatWorksInBuildingTurnStart)
  102. Events.SerialEventCityInfoDirty.Add(BuildingYieldFromGreatWorksInBuildingSwap)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement