Advertisement
vicevirtuoso

NCRDecisions

Nov 5th, 2015
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.19 KB | None | 0 0
  1. --------------------------------------------------------------------------------------------------------------------------------------------
  2. --NCR's Decisions
  3. --concept by Kramer, code by Vicevirtuoso, original Events & Decisions code by sukritact
  4. --------------------------------------------------------------------------------------------------------------------------------------------
  5.  
  6. local MINT = GameInfoTypes.BUILDING_MINT
  7. local CURRENCY_POLICY = GameInfoTypes.POLICY_DECISIONS_NCR_CURRENCY
  8. --------------------------------------------------------------------------------------------------------------------------------------------
  9. --Decision 1: Implement Paper Currency
  10. --------------------------------------------------------------------------------------------------------------------------------------------
  11. local Decisions_NCRCurrency = {}
  12.     Decisions_NCRCurrency.Name = "TXT_KEY_DECISIONS_FALLOUT_NCR_CURRENCY"
  13.     Decisions_NCRCurrency.Desc = Locale.ConvertTextKey("TXT_KEY_DECISIONS_FALLOUT_NCR_CURRENCY_DESC")
  14.     HookDecisionCivilizationIcon(Decisions_NCRCurrency, "CIVILIZATION_FALLOUT_NCR")
  15.     Decisions_NCRCurrency.CanFunc = (
  16.     function(pPlayer)
  17.         if (pPlayer:GetCivilizationType() ~= GameInfoTypes.CIVILIZATION_FALLOUT_NCR) then
  18.             return false, false
  19.         end
  20.  
  21.         if load(pPlayer, "Decisions_NCRCurrency") then
  22.             Decisions_NCRCurrency.Desc = Locale.ConvertTextKey("TXT_KEY_DECISIONS_FALLOUT_NCR_CURRENCY_ENACTED_DESC")
  23.             return false, false, true
  24.         end
  25.  
  26.         local iGold = math.ceil(500 * iMod)
  27.  
  28.         Decisions_NCRCurrency.Desc = Locale.ConvertTextKey("TXT_KEY_DECISIONS_FALLOUT_NCR_CURRENCY_DESC", iGold)
  29.  
  30.         if pPlayer:GetGold() < iGold then return true, false end
  31.         if (pPlayer:GetNumResourceAvailable(iMagistrate, false) < 2) then return true, false end
  32.  
  33.         local pTeam = Teams[pPlayer:GetTeam()]
  34.         if pTeam:IsHasTech(GameInfoTypes.TECH_PRINTING_PRESS) then
  35.             return true, true
  36.         else
  37.             return true, false
  38.         end
  39.     end
  40.     )
  41.  
  42.     Decisions_NCRCurrency.DoFunc = (
  43.     function(pPlayer)
  44.         local pCapital = pPlayer:GetCapitalCity()
  45.         if pCapital then
  46.             local iGold = math.ceil(500 * iMod)
  47.             pPlayer:ChangeGold(-iGold)
  48.             pPlayer:ChangeNumResourceTotal(iMagistrate, -2)
  49.             pPlayer:SetNumFreePolicies(1)
  50.             pPlayer:SetNumFreePolicies(0)
  51.             pPlayer:SetHasPolicy(CURRENCY_POLICY, true)
  52.             for pCity in pPlayer:Cities() do
  53.                 if pCity:IsHasBuilding(MINT) then
  54.                     local sKey = "Decisions_NCRCurrency" .. CompileCityID(pCity)
  55.                     save(pPlayer, sKey, true)
  56.                     pPlayer:ChangeNumResourceTotal(iMagistrate, 1)
  57.                 end
  58.             end
  59.             save(pPlayer, "Decisions_NCRCurrency", true)
  60.         end
  61.     end
  62.  
  63.     )
  64.     Decisions_NCRCurrency.Monitors = {}
  65.     Decisions_NCRCurrency.Monitors[GameEvents.CityConstructed] =  (
  66.     function(iPlayer, iCity, iBuildingType)
  67.         if iBuildingType == MINT and iPlayer < GameDefines.MAX_MAJOR_CIVS then
  68.             local pPlayer = Players[iPlayer]
  69.             if load(pPlayer, "Decisions_NCRCurrency") == true then
  70.                 local pCity = pPlayer:GetCityByID(iCity)
  71.                 local sKey = "Decisions_NCRCurrency" .. CompileCityID(pCity)
  72.                 if not load(pPlayer, sKey) then
  73.                     save(pPlayer, sKey, true)
  74.                     pPlayer:ChangeNumResourceTotal(iMagistrate, 1)
  75.                 end
  76.             end
  77.         end
  78.     end
  79.     )
  80.    
  81.  
  82. Decisions_AddCivilisationSpecific(GameInfoTypes.CIVILIZATION_FALLOUT_NCR, "Decisions_NCRCurrency", Decisions_NCRCurrency)
  83.  
  84.  
  85. --------------------------------------------------------------------------------------------------------------------------------------------
  86. --Decision 2: Unify With the Desert Rangers
  87. --------------------------------------------------------------------------------------------------------------------------------------------
  88.  
  89. local Decisions_NCRDesertRangers = {}
  90.     Decisions_NCRDesertRangers.Name = "TXT_KEY_DECISIONS_FALLOUT_NCR_RANGERS"
  91.     Decisions_NCRDesertRangers.Desc = "TXT_KEY_DECISIONS_FALLOUT_NCR_RANGERS_DESC"
  92.     HookDecisionCivilizationIcon(Decisions_NCRDesertRangers, "CIVILIZATION_FALLOUT_NCR")
  93.     Decisions_NCRDesertRangers.CanFunc = (
  94.     function(pPlayer)
  95.         if (pPlayer:GetCivilizationType() ~= GameInfoTypes.CIVILIZATION_FALLOUT_NCR) then
  96.             return false, false
  97.         end
  98.  
  99.         if load(pPlayer, "Decisions_NCRDesertRangers") == true then
  100.             Decisions_NCRDesertRangers.Desc = Locale.ConvertTextKey("TXT_KEY_DECISIONS_FALLOUT_NCR_RANGERS_ENACTED_DESC")
  101.             return false, false, true
  102.         end
  103.  
  104.         local iGoldCost = math.ceil(1500  * iMod)
  105.  
  106.         Decisions_NCRDesertRangers.Desc = Locale.ConvertTextKey("TXT_KEY_DECISIONS_FALLOUT_NCR_RANGERS_DESC", iGoldCost)
  107.        
  108.         if pPlayer:GetGold() < iGoldCost then return true, false end
  109.         if (pPlayer:GetNumResourceAvailable(iMagistrate, false) < 2) then return true, false end
  110.  
  111.         local pTeam = Teams[pPlayer:GetTeam()]
  112.         if not pTeam:IsHasTech(GameInfoTypes.TECH_REPLACEABLE_PARTS) then
  113.             return true, false
  114.         end
  115.  
  116.         local pCapital = pPlayer:GetCapitalCity()
  117.         if pCapital then
  118.             local pPlot = pCapital:Plot()
  119.             if pPlot then
  120.                 for c = 0, pPlot:GetNumUnits() - 1 do
  121.                     local pUnit = pPlot:GetUnit(c)
  122.                     if pUnit and pUnit:GetUnitClassType() == GameInfoTypes.UNITCLASS_GREAT_GENERAL then
  123.                         return true, true
  124.                     end
  125.                 end
  126.             end
  127.         end
  128.  
  129.         return true, false
  130.     end
  131.     )
  132.  
  133.     Decisions_NCRDesertRangers.DoFunc = (
  134.     function(pPlayer)
  135.         local pCapital = pPlayer:GetCapitalCity()
  136.         if pCapital then
  137.             local pPlot = pCapital:Plot()
  138.             if not pPlot then return end
  139.            
  140.            
  141.             local iGoldCost = math.ceil(1500  * iMod)
  142.             local iMagistrateCost = 2
  143.             pPlayer:ChangeGold(-iGoldCost)
  144.             pPlayer:ChangeNumResourceTotal(iMagistrate, -iMagistrateCost)
  145.  
  146.             local iUnit;
  147.             local iUnitType;
  148.             if pPlot then
  149.                 for c = 0, pPlot:GetNumUnits() - 1 do
  150.                     local pUnit = pPlot:GetUnit(c)
  151.                     if pUnit and pUnit:GetUnitClassType() == GameInfoTypes.UNITCLASS_GREAT_GENERAL then
  152.                         iUnit = pUnit:GetID()
  153.                         iUnitType = pUnit:GetUnitType()
  154.                     end
  155.                 end
  156.             end
  157.             local bIsDVMC = false
  158.             if GameInfo.CustomModOptions then
  159.                 for row in GameInfo.CustomModOptions() do
  160.                     if row.Name == "EVENTS_GREAT_PEOPLE" and row.Value == 1 then
  161.                         bIsDVMC = true
  162.                         break
  163.                     end
  164.                 end
  165.             end
  166.             if bIsDVMC then
  167.                 GameEvents.GreatPersonExpended.Call(pPlayer:GetID(), iUnit, iUnitType, pPlot:GetX(), pPlot:GetY())
  168.             else
  169.                 GameEvents.GreatPersonExpended.Call(pPlayer:GetID(), iUnitType)
  170.             end
  171.  
  172.             local Unit1 = pPlayer:InitUnit(GameInfoTypes.UNIT_FALLOUT_RANGER, pPlot:GetX(), pPlot:GetY(), UNITAI_ATTACK)
  173.             Unit1:JumpToNearestValidPlot()
  174.             local Unit2 = pPlayer:InitUnit(GameInfoTypes.UNIT_FALLOUT_RANGER, pPlot:GetX(), pPlot:GetY(), UNITAI_ATTACK)
  175.             Unit2:JumpToNearestValidPlot()
  176.             local Unit3 = pPlayer:InitUnit(GameInfoTypes.UNIT_FALLOUT_VET_RANGER, pPlot:GetX(), pPlot:GetY(), UNITAI_ATTACK)
  177.             Unit3:JumpToNearestValidPlot()
  178.             --To figure out how much XP to give it, we'll set it to 4, get the XP it needs to get to 5 from the DLL (it's not in game defines, apparently), set it to have that much XP, then set it back to level 1
  179.             Unit3:SetLevel(4)
  180.             Unit3:SetExperience(Unit3:ExperienceNeeded())
  181.             Unit3:SetLevel(1)
  182.             Unit3:SetPromotionReady(true)
  183.            
  184.             save(pPlayer, "Decisions_NCRDesertRangers", true)
  185.         end
  186.     end
  187.     )
  188. Decisions_AddCivilisationSpecific(GameInfoTypes.CIVILIZATION_FALLOUT_NCR, "Decisions_NCRDesertRangers", Decisions_NCRDesertRangers)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement