Irkalla

walls.lua

Dec 19th, 2012
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.37 KB | None | 0 0
  1. print( "Loaded Trait_Walls.lua" )
  2.  
  3. --[[-----------------------------------------
  4. Name: GetCivSpecificUnit
  5. Purpose: Get the UnitType for a specific
  6. civ from a UnitClassType.
  7. -------------------------------------------]]
  8. function fnGetCivSpecificUnit( pPly, sUnitClass ) -- Thanks whoward69
  9.  
  10. -- BEGIN DEFINES
  11. local sUnitType = nil
  12. local sCivType = GameInfo.Civilizations[ pPly:GetCivilizationType() ].Type
  13. -- END DEFINES
  14.  
  15. --[[ Loop through civilization-specific UnitClass overrides, id est their unique units, and
  16. yield to be returned the proper UnitType. --]]
  17. for pOverride in GameInfo.Civilization_UnitClassOverrides{ CivilizationType = sCivType,
  18. UnitClassType = sUnitClass } do
  19. sUnitType = pOverride.UnitType
  20. break
  21. end
  22.  
  23. -- If we didn't get anything, yield to be returned the default UnitType for the UnitClass.
  24. if sUnitType == nil then
  25. sUnitType = GameInfo.UnitClasses[ sUnitClass ].DefaultUnit
  26. end
  27.  
  28. -- Give whatever function called this the UnitType we yielded.
  29. print( "Got Civ-Specific UnitType: " .. tostring( sUnitType ) .. ".\n" )
  30. return sUnitType
  31. end
  32.  
  33. --[[-----------------------------------------
  34. Name: ReturnBestInfantryUnit
  35. Purpose: Return the best land melee unit
  36. that a city can build.
  37. -------------------------------------------]]
  38. function fnReturnBestInfantryUnit( pCity )
  39.  
  40. --BEGIN DEFINES
  41. local pPly = pCity:GetOwner()
  42.  
  43. local possibleUnitClasses = {
  44. GameInfoTypes.UNITCLASS_MECH,
  45. GameInfoTypes.UNITCLASS_MECHANIZED_INFANTRY,
  46. GameInfoTypes.UNITCLASS_INFANTRY,
  47. GameInfotypes.UNITCLASS_GREAT_WAR_INFANTRY,
  48. GameInfoTypes.UNITCLASS_RIFLEMAN,
  49. GameInfoTypes.UNITCLASS_MUSKETMAN,
  50. GameInfoTypes.UNITCLASS_LONGSWORDSMAN,
  51. GameInfoTypes.UNITCLASS_PIKEMAN,
  52. GameInfoTypes.UNITCLASS_SWORDSMAN,
  53. GameInfoTypes.UNITCLASS_SPEARMAN,
  54. GameInfoTypes.UNITCLASS_WARRIOR
  55. } -- Thanks whoward69
  56. --END DEFINES
  57.  
  58. -- Loop through each UnitClassType in the above defined table, see if the city can
  59. -- train it's owner's specific UnitType. Yield to be returned the best land melee
  60. -- UnitType the city can build.
  61. for _, iUnitClass in ipairs( possibleUnitClasses ) do -- Thanks whoward69
  62. if pCity:CanTrain( fn_GetCivSpecificUnit( pPly, iUnitClass ) ) then
  63.  
  64. print( "Unit to be given: " .. tostring( fn_GetCivSpecificUnit( pPly, iUnitClass ) ) .. ".\n" )
  65.  
  66. return fn_GetCivSpecificUnit( pPly, iUnitClass )
  67. end
  68. end
  69.  
  70. -- Uh-oh!
  71. return -1
  72. end
  73.  
  74. GameEvents.SetPopulation.Add( function( xOffset, yOffset, fOldPop, fNewPop )
  75. print( "SetPopulation was called." )
  76.  
  77.  
  78. -- BEGIN DEFINES
  79. local pPlot = Map.GetPlot( xOffset, yOffset )
  80. local pCity = pPlot:GetPlotCity()
  81. local pPly = pCity:GetOwner()
  82. local iUnitMostCurrent = nil
  83. local nTrait = GameInfo.Traits[ pPly ].UnitPerCapitalGrowths
  84. local sUnitAIType = GameInfo.UnitAITypes.UNITAI_DEFENSE.ID
  85. local nZenith = math.floor( pCity:GetHighestPopulation() )
  86. local strGrowFallen = "done something"
  87. -- END DEFINES
  88.  
  89. --[[ On every growth of every city, run through the following list of conditions:
  90. 1: Does the city's owner have the trait, and is its population evenly divisible
  91. by the trait?
  92. 2: Is the city a capital?
  93. 3: Has the city grown instead of shrinking, and is this the city's highest
  94. population?
  95.  
  96. If all of the above are true, get the best land infantry unit we can, and
  97. spawn it at the city. --]]
  98.  
  99. if ( fNewPop > fOldPop ) then
  100. strGrowFallen = "grown"
  101. else
  102. strGrowFallen = "fallen"
  103. end
  104.  
  105. print( "Info: " .. tostring( pCity:GetName() ) .. "'s Population has " .. strGrowFallen .. " from " .. tostring( fOldPop ) .. " to " .. tostring( fNewPop ) .. "! Highest Population: " .. tostring( nZenith ) .. ".\n" )
  106.  
  107. if ( ( nTrait > 0 ) and ( math.floor( fNewPop ) % nTrait ) == 0 ) then
  108.  
  109. print( pPly:GetName() .. " has the trait, and the population is divisible by the trait.\n" )
  110.  
  111. if pCity:IsCapital() then
  112.  
  113. print( pCity:GetName() .. " is the capital of " .. pPly:GetName() .. "'s empire.\n" )
  114.  
  115. if ( ( fNewPop > fOldPop ) and ( fNewPop >= nZenith ) ) then
  116.  
  117. print( pCity:GetName() .. "'s current population is more than its previous population, and its population has reached a new level!" )
  118.  
  119. iFreeUnit = fnReturnBestInfantryUnit( pCity )
  120.  
  121. pPly:AddFreeUnit( iFreeUnit, iUnitAIType ) --[[ What are the
  122. implications of this line? --]]
  123. end
  124. end
  125. end
  126. end )
Advertisement
Add Comment
Please, Sign In to add comment