Irkalla

walls.lua

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