Irkalla

Walls.lua

Dec 27th, 2012
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.73 KB | None | 0 0
  1. print( "Loaded." )
  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.     print( "GetCivSpecificUnit: Attempting to get " .. pPly:GetCivilizationDescription() .. "'s specific unit for UnitClassType: " .. sUnitClass .. "." )
  10.  
  11.     -- BEGIN DEFINES
  12.     local sUnitType = nil
  13.     local sCivType  = GameInfo.Civilizations[ pPly:GetCivilizationType() ].Type
  14.     -- END DEFINES
  15.    
  16.     --[[ Loop through civilization-specific UnitClass overrides, id est their unique units, and
  17.     yield to be returned the proper UnitType. --]]
  18.     for pOverride in GameInfo.Civilization_UnitClassOverrides{ CivilizationType = sCivType,
  19.                                                                UnitClassType = sUnitClass } do
  20.         sUnitType = pOverride.UnitType
  21.         break
  22.     end
  23.  
  24.     -- If we didn't get anything, yield to be returned the default UnitType for the UnitClass.
  25.     if sUnitType == nil then
  26.         sUnitType = GameInfo.UnitClasses[ sUnitClass ].DefaultUnit
  27.     end
  28.  
  29.     -- Give whatever function called this the UnitType we yielded.
  30.     print( "Got Civ-Specific UnitType: " .. sUnitType .. ".\n" )
  31.     return sUnitType
  32. end
  33.  
  34. --[[-----------------------------------------
  35. Name:       ReturnBestInfantryUnit
  36. Purpose:    Return the best land melee unit
  37. that a city can build.  
  38. -------------------------------------------]]
  39. function fnReturnBestInfantryUnit( pPly, pCity )
  40.     print( "ReturnBestInfantryUnit: Attempting to grab the best unit for " .. pPly:GetCivilizationDescription() .. "." )
  41.  
  42.     --BEGIN DEFINES
  43.     --local iPlyID  = pCity:GetOwner()
  44.     --local pPly        = Players[ iPlyID ]
  45.    
  46.     local possibleUnitClasses = {
  47.     GameInfoTypes.UNITCLASS_MECH,
  48.     GameInfoTypes.UNITCLASS_MECHANIZED_INFANTRY,
  49.     GameInfoTypes.UNITCLASS_INFANTRY,
  50.     GameInfoTypes.UNITCLASS_GREAT_WAR_INFANTRY,
  51.     GameInfoTypes.UNITCLASS_RIFLEMAN,
  52.     GameInfoTypes.UNITCLASS_MUSKETMAN,
  53.     GameInfoTypes.UNITCLASS_LONGSWORDSMAN,
  54.     GameInfoTypes.UNITCLASS_PIKEMAN,
  55.     GameInfoTypes.UNITCLASS_SWORDSMAN,
  56.     GameInfoTypes.UNITCLASS_SPEARMAN,
  57.     GameInfoTypes.UNITCLASS_WARRIOR
  58.     } -- Thanks whoward69
  59.     --END DEFINES
  60.    
  61.     -- Loop through each UnitClassType in the above defined table, see if the city can
  62.     -- train it's owner's specific UnitType.  Yield to be returned the best land melee
  63.     -- UnitType the city can build.
  64.     for _, iUnitClass in ipairs( possibleUnitClasses ) do -- Thanks whoward69
  65.         if pCity:CanTrain( fnGetCivSpecificUnit( pPly, iUnitClass ) ) then
  66.            
  67.             print( "ReturnBestInfantryUnit: Unit to be given: " .. fnGetCivSpecificUnit( pPly, iUnitClass ) .. "." )
  68.  
  69.             return fnGetCivSpecificUnit( pPly, iUnitClass )
  70.         end
  71.     end
  72.  
  73.     -- Uh-oh!
  74.     print("ReturnBestInfantryUnit: Irkalla fucked up...")
  75.    
  76.     if type( iUnitClass ) ~= "string" then
  77.         print( "ReturnBestInfantryUnit: He's so stupid that he didn\'t give me a string!  Wat a noob!" )
  78.     end
  79.      
  80.     return GameInfoTypes.UNIT_WARRIOR
  81. end
  82.  
  83. GameEvents.SetPopulation.Add( function( xOffset, yOffset, fOldPop, fNewPop )
  84.     print( "SetPopulation was called." )
  85.     print( "Y Offset: " .. yOffset .. "." )
  86.     print( "X Offset: " .. xOffset .. "." )
  87.     print( "Old Population: " .. fOldPop .. "." )
  88.     print( "New Population: " .. fNewPop .. "." )
  89.  
  90.     -- BEGIN DEFINES
  91.     local pPlot             = Map.GetPlot( xOffset, yOffset )
  92.     local pCity             = pPlot:GetPlotCity()
  93.     print( "City: " .. pCity:GetName() .. "." )
  94.     local iPlyID            = pCity:GetOwner()
  95.     local pPly              = Players[ iPlyID ] -- Dat Datatype Mismatch, son
  96.     print( "Player: " .. pPly:GetName() .. "." )
  97.     local iUnitMostCurrent  = nil
  98.     local pLeader           = GameInfo.Leaders[ pPly:GetLeaderType() ]
  99.     local iLeaderTrait      = GameInfo.Leader_Traits("LeaderType ='" .. pLeader.Type .. "'")()
  100.     local pTrait            = GameInfo.Traits[ iLeaderTrait.TraitType ]
  101.     local nTrait            = pTrait.UnitPerCapitalGrowths
  102.     print( "Capital Growths Needed for Free Unit by " .. pPly:GetName() .. ": " .. nTrait .. "." )
  103.     -- local sUnitAIType        = UNITAI_DEFENSE
  104.     local nZenith           = math.floor( pCity:GetHighestPopulation() )
  105.     print( "Highest Population: " .. nZenith .. "." )
  106.     local strGrowFallen     = "done something"
  107.     -- END DEFINES
  108.  
  109.     if ( fNewPop < fOldPop ) then
  110.         strGrowFallen = "fallen"
  111.     else
  112.         strGrowFallen = "grown"
  113.     end
  114.  
  115.     --[[if xOffset then
  116.         print( "Got an X offset" )
  117.     else
  118.         print( "Don't got an X offset" )
  119.     end--]]
  120.    
  121.  
  122.     --[[ On every growth of every city, run through the following list of conditions:
  123.     1:  Does the city's owner have the trait, and is its population evenly divisible
  124.     by the trait?
  125.     2:  Is the city a capital?
  126.     3:  Has the city grown instead of shrinking, and is this the city's highest
  127.     population?
  128.  
  129.     If all of the above are true, get the best land infantry unit we can, and
  130.     spawn it at the city. --]]
  131.  
  132.     print( "Info: " .. tostring( pCity:GetName() ) .. "'s Population has " .. strGrowFallen .. " from " .. tostring( fOldPop ) .. " to " .. tostring( fNewPop ) .. "!  Highest Population: " .. tostring( nZenith ) .. ".\n" )
  133.  
  134.     if ( ( nTrait > 0 ) and ( math.floor( fNewPop ) % nTrait ) == 0 ) then
  135.  
  136.        print( pPly:GetName() .. " has the trait, and the population is divisible by the trait.\n" )
  137.  
  138.         if pCity:IsCapital() then
  139.  
  140.             print( pCity:GetName() .. " is the capital of " .. pPly:GetName() .. "'s empire.\n" )
  141.  
  142.             if ( ( fNewPop > fOldPop ) and ( fNewPop >= nZenith ) ) then
  143.  
  144.                print( pCity:GetName() .. "'s current population is more than its previous population, and its population has reached a new level!" )
  145.  
  146.                 iUnitMostCurrent = fnReturnBestInfantryUnit( pPly, pCity )
  147.  
  148.                 pPly:AddFreeUnit( iUnitMostCurrent, "UNITAI_DEFENSE" ) --[[ What are the
  149.                 implications of this line? --]]
  150.                 print( "Should have free unit unless Irkalla fucked up." )
  151.             end
  152.         end
  153.     end
  154. end )
Advertisement
Add Comment
Please, Sign In to add comment