Advertisement
vicevirtuoso

LegionDecisions

Nov 5th, 2015
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.11 KB | None | 0 0
  1. --------------------------------------------------------------------------------------------------------------------------------------------
  2. --Legion's Decisions
  3. --concept by Kramer, code by Vicevirtuoso, original Events & Decisions code by sukritact
  4. --------------------------------------------------------------------------------------------------------------------------------------------
  5.  
  6.  
  7. --------------------------------------------------------------------------------------------------------------------------------------------
  8. --Decision 1: Establish the Frumentarii
  9. --------------------------------------------------------------------------------------------------------------------------------------------
  10. local FRUMENTARII_POLICY = GameInfoTypes.POLICY_DECISIONS_LEGION_FRUMENTARII            --for Spy efficacy modifier
  11. local FRUMENTARII_BUILDING = GameInfoTypes.BUILDING_DECISIONS_LEGION_FRUMENTARII        --for free Spy itself
  12.  
  13.  
  14. local Decisions_LegionFrumentarii = {}
  15.     Decisions_LegionFrumentarii.Name = "TXT_KEY_DECISIONS_FALLOUT_LEGION_FRUMENTARII"
  16.     Decisions_LegionFrumentarii.Desc = Locale.ConvertTextKey("TXT_KEY_DECISIONS_FALLOUT_LEGION_FRUMENTARII_DESC")
  17.     HookDecisionCivilizationIcon(Decisions_LegionFrumentarii, "CIVILIZATION_FALLOUT_LEGION")
  18.     Decisions_LegionFrumentarii.CanFunc = (
  19.     function(pPlayer)
  20.         if (pPlayer:GetCivilizationType() ~= GameInfoTypes.CIVILIZATION_FALLOUT_LEGION) then
  21.             return false, false
  22.         end
  23.  
  24.         if load(pPlayer, "Decisions_LegionFrumentarii") then
  25.             Decisions_LegionFrumentarii.Desc = Locale.ConvertTextKey("TXT_KEY_DECISIONS_FALLOUT_LEGION_FRUMENTARII_ENACTED_DESC")
  26.             return false, false, true
  27.         end
  28.  
  29.         Decisions_LegionFrumentarii.Desc = Locale.ConvertTextKey("TXT_KEY_DECISIONS_FALLOUT_LEGION_FRUMENTARII_DESC")
  30.  
  31.         if (pPlayer:GetNumResourceAvailable(iMagistrate, false) < 2) then return true, false end
  32.  
  33.         if pPlayer:GetCurrentEra() >= GameInfoTypes.ERA_RENAISSANCE then
  34.             return true, true
  35.         else
  36.             return true, false
  37.         end
  38.     end
  39.     )
  40.  
  41.     Decisions_LegionFrumentarii.DoFunc = (
  42.     function(pPlayer)
  43.         local pCapital = pPlayer:GetCapitalCity()
  44.         if pCapital then
  45.             pPlayer:ChangeNumResourceTotal(iMagistrate, -2)
  46.             pPlayer:SetNumFreePolicies(1)
  47.             pPlayer:SetNumFreePolicies(0)
  48.             pPlayer:SetHasPolicy(FRUMENTARII_POLICY, true)
  49.             pCapital:SetNumRealBuilding(FRUMENTARII_BUILDING, true)
  50.             save(pPlayer, "Decisions_LegionFrumentarii", true)
  51.         end
  52.     end
  53.  
  54.     )
  55.    
  56.  
  57. Decisions_AddCivilisationSpecific(GameInfoTypes.CIVILIZATION_FALLOUT_LEGION, "Decisions_LegionFrumentarii", Decisions_LegionFrumentarii)
  58.  
  59.  
  60. --------------------------------------------------------------------------------------------------------------------------------------------
  61. --Decision 2: Repair Howitzer Garrison
  62. --------------------------------------------------------------------------------------------------------------------------------------------
  63. local SIEGE = GameInfoTypes.UNITCOMBAT_SIEGE
  64. local SIEGE_PROMO = GameInfoTypes.PROMOTION_FALLOUT_LEGION_HOWITZER
  65. local iMaxCivs = GameDefines.MAX_MAJOR_CIVS
  66.  
  67. local tLegionD2Improvements = {
  68.     [GameInfoTypes.IMPROVEMENT_CITADEL] = true,
  69.     [GameInfoTypes.IMPROVEMENT_FORT] = true,
  70.     [GameInfoTypes.IMPROVEMENT_KASBAH] = true,          --I figure UIs that provide defense should count as forts here
  71.     [GameInfoTypes.IMPROVEMENT_CHATEAU] = true,         --see above
  72.     [GameInfoTypes.IMPROVEMENT_LEGIONARY_FORT] = true   --or whatever its GameInfoType is
  73. }
  74.  
  75. function LegionHowitzerCheck(pUnit)
  76.     if pUnit:GetUnitCombatType() == SIEGE then
  77.         local pPlot = pUnit:GetPlot()
  78.         if pPlot:IsCity() or tLegionD2Improvements[pPlot:GetImprovementType()] then
  79.             pUnit:SetHasPromotion(SIEGE_PROMO, true)
  80.         else
  81.             pUnit:SetHasPromotion(SIEGE_PROMO, false)
  82.         end
  83.     else
  84.         pUnit:SetHasPromotion(SIEGE_PROMO, false)
  85.     end
  86. end
  87.  
  88. local Decisions_LegionHowitzer = {}
  89.     Decisions_LegionHowitzer.Name = "TXT_KEY_DECISIONS_FALLOUT_LEGION_HOWITZER"
  90.     Decisions_LegionHowitzer.Desc = "TXT_KEY_DECISIONS_FALLOUT_LEGION_HOWITZER_DESC"
  91.     HookDecisionCivilizationIcon(Decisions_LegionHowitzer, "CIVILIZATION_FALLOUT_LEGION")
  92.     Decisions_LegionHowitzer.CanFunc = (
  93.     function(pPlayer)
  94.         if (pPlayer:GetCivilizationType() ~= GameInfoTypes.CIVILIZATION_FALLOUT_LEGION) then
  95.             return false, false
  96.         end
  97.  
  98.         if load(pPlayer, "Decisions_LegionHowitzer") == true then
  99.             Decisions_LegionHowitzer.Desc = Locale.ConvertTextKey("TXT_KEY_DECISIONS_FALLOUT_LEGION_HOWITZER_ENACTED_DESC")
  100.             return false, false, true
  101.         end
  102.  
  103.         local iGoldCost = math.ceil(650  * iMod)
  104.  
  105.         Decisions_LegionHowitzer.Desc = Locale.ConvertTextKey("TXT_KEY_DECISIONS_FALLOUT_LEGION_HOWITZER_DESC", iGoldCost)
  106.        
  107.         if pPlayer:GetGold() < iGoldCost then return true, false end
  108.         if (pPlayer:GetNumResourceAvailable(iMagistrate, false) < 1) then return true, false end
  109.  
  110.         local pTeam = Teams[pPlayer:GetTeam()]
  111.         if pTeam:IsHasTech(GameInfoTypes.TECH_MILITARY_SCIENCE) then
  112.             return true, true
  113.         else
  114.             return true, false
  115.         end
  116.     end
  117.     )
  118.  
  119.     Decisions_LegionHowitzer.DoFunc = (
  120.     function(pPlayer)
  121.         local pCapital = pPlayer:GetCapitalCity()
  122.         if pCapital then
  123.             local pPlot = pCapital:Plot()
  124.             if not pPlot then return end
  125.            
  126.             local iGoldCost = math.ceil(650  * iMod)
  127.             local iMagistrateCost = 1
  128.             pPlayer:ChangeGold(-iGoldCost)
  129.             pPlayer:ChangeNumResourceTotal(iMagistrate, -iMagistrateCost)
  130.  
  131.             local pUnit = pPlayer:InitUnit(GameInfoTypes.UNIT_ARTILLERY, pPlot:GetX(), pPlot:GetY(), UNITAI_ATTACK)
  132.             pUnit:JumpToNearestValidPlot()
  133.            
  134.             for pUnit in pPlayer:Units() do
  135.                 LegionHowitzerCheck(pUnit)
  136.             end
  137.            
  138.             save(pPlayer, "Decisions_LegionHowitzer", true)
  139.         end
  140.     end
  141.     )
  142.    
  143.     Decisions_LegionFrumentarii.Monitors = {}
  144.     Decisions_LegionFrumentarii.Monitors[GameEvents.UnitSetXY] =  (
  145.     function(iPlayer, iUnit, iX, iY)
  146.         if iX > 0 and iY > 0 and iPlayer < iMaxCivs then
  147.             local pPlayer = Players[iPlayer]
  148.             if load(pPlayer, "Decisions_LegionHowitzer") == true then
  149.                 local pUnit = pPlayer:GetUnitByID(iUnit)
  150.                 if pUnit then
  151.                     LegionHowitzerCheck(pUnit)
  152.                 end
  153.             end
  154.         end
  155.     end
  156.     )
  157. Decisions_AddCivilisationSpecific(GameInfoTypes.CIVILIZATION_FALLOUT_LEGION, "Decisions_LegionHowitzer", Decisions_LegionHowitzer)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement