Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print( "Loaded." )
- --[[-----------------------------------------
- Name: GetCivSpecificUnit
- Purpose: Get the UnitType for a specific
- civ from a UnitClassType.
- -------------------------------------------]]
- function fnGetCivSpecificUnit( pPly, sUnitClass ) -- Thanks whoward69
- print( "GetCivSpecificUnit: Attempting to get " .. pPly:GetCivilizationDescription() .. "'s specific unit for UnitClassType: " .. sUnitClass .. "." )
- -- BEGIN DEFINES
- local sUnitType = nil
- local sCivType = GameInfo.Civilizations[ pPly:GetCivilizationType() ].Type
- -- END DEFINES
- --[[ Loop through civilization-specific UnitClass overrides, id est their unique units, and
- yield to be returned the proper UnitType. --]]
- for pOverride in GameInfo.Civilization_UnitClassOverrides{ CivilizationType = sCivType,
- UnitClassType = sUnitClass } do
- sUnitType = pOverride.UnitType
- break
- end
- -- If we didn't get anything, yield to be returned the default UnitType for the UnitClass.
- if sUnitType == nil then
- sUnitType = GameInfo.UnitClasses[ sUnitClass ].DefaultUnit
- end
- -- Give whatever function called this the UnitType we yielded.
- print( "Got Civ-Specific UnitType: " .. sUnitType .. ".\n" )
- return sUnitType
- end
- --[[-----------------------------------------
- Name: ReturnBestInfantryUnit
- Purpose: Return the best land melee unit
- that a city can build.
- -------------------------------------------]]
- function fnReturnBestInfantryUnit( pPly, pCity )
- print( "ReturnBestInfantryUnit: Attempting to grab the best unit for " .. pPly:GetCivilizationDescription() .. "." )
- --BEGIN DEFINES
- --local iPlyID = pCity:GetOwner()
- --local pPly = Players[ iPlyID ]
- local possibleUnitClasses = {
- GameInfoTypes.UNITCLASS_MECH,
- GameInfoTypes.UNITCLASS_MECHANIZED_INFANTRY,
- GameInfoTypes.UNITCLASS_INFANTRY,
- GameInfoTypes.UNITCLASS_GREAT_WAR_INFANTRY,
- GameInfoTypes.UNITCLASS_RIFLEMAN,
- GameInfoTypes.UNITCLASS_MUSKETMAN,
- GameInfoTypes.UNITCLASS_LONGSWORDSMAN,
- GameInfoTypes.UNITCLASS_PIKEMAN,
- GameInfoTypes.UNITCLASS_SWORDSMAN,
- GameInfoTypes.UNITCLASS_SPEARMAN,
- GameInfoTypes.UNITCLASS_WARRIOR
- } -- Thanks whoward69
- --END DEFINES
- -- Loop through each UnitClassType in the above defined table, see if the city can
- -- train it's owner's specific UnitType. Yield to be returned the best land melee
- -- UnitType the city can build.
- for _, iUnitClass in ipairs( possibleUnitClasses ) do -- Thanks whoward69
- if pCity:CanTrain( fnGetCivSpecificUnit( pPly, iUnitClass ) ) then
- print( "ReturnBestInfantryUnit: Unit to be given: " .. fnGetCivSpecificUnit( pPly, iUnitClass ) .. "." )
- return fnGetCivSpecificUnit( pPly, iUnitClass )
- end
- end
- -- Uh-oh!
- print("ReturnBestInfantryUnit: Irkalla fucked up...")
- if type( iUnitClass ) ~= "string" then
- print( "ReturnBestInfantryUnit: He's so stupid that he didn\'t give me a string! Wat a noob!" )
- end
- return GameInfoTypes.UNIT_WARRIOR
- end
- GameEvents.SetPopulation.Add( function( xOffset, yOffset, fOldPop, fNewPop )
- print( "SetPopulation was called." )
- print( "Y Offset: " .. yOffset .. "." )
- print( "X Offset: " .. xOffset .. "." )
- print( "Old Population: " .. fOldPop .. "." )
- print( "New Population: " .. fNewPop .. "." )
- -- BEGIN DEFINES
- local pPlot = Map.GetPlot( xOffset, yOffset )
- local pCity = pPlot:GetPlotCity()
- print( "City: " .. pCity:GetName() .. "." )
- local iPlyID = pCity:GetOwner()
- local pPly = Players[ iPlyID ] -- Dat Datatype Mismatch, son
- print( "Player: " .. pPly:GetName() .. "." )
- local iUnitMostCurrent = nil
- local pLeader = GameInfo.Leaders[ pPly:GetLeaderType() ]
- local iLeaderTrait = GameInfo.Leader_Traits("LeaderType ='" .. pLeader.Type .. "'")()
- local pTrait = GameInfo.Traits[ iLeaderTrait.TraitType ]
- local nTrait = pTrait.UnitPerCapitalGrowths
- print( "Capital Growths Needed for Free Unit by " .. pPly:GetName() .. ": " .. nTrait .. "." )
- -- local sUnitAIType = UNITAI_DEFENSE
- local nZenith = math.floor( pCity:GetHighestPopulation() )
- print( "Highest Population: " .. nZenith .. "." )
- local strGrowFallen = "done something"
- -- END DEFINES
- if ( fNewPop < fOldPop ) then
- strGrowFallen = "fallen"
- else
- strGrowFallen = "grown"
- end
- --[[if xOffset then
- print( "Got an X offset" )
- else
- print( "Don't got an X offset" )
- end--]]
- --[[ On every growth of every city, run through the following list of conditions:
- 1: Does the city's owner have the trait, and is its population evenly divisible
- by the trait?
- 2: Is the city a capital?
- 3: Has the city grown instead of shrinking, and is this the city's highest
- population?
- If all of the above are true, get the best land infantry unit we can, and
- spawn it at the city. --]]
- print( "Info: " .. tostring( pCity:GetName() ) .. "'s Population has " .. strGrowFallen .. " from " .. tostring( fOldPop ) .. " to " .. tostring( fNewPop ) .. "! Highest Population: " .. tostring( nZenith ) .. ".\n" )
- if ( ( nTrait > 0 ) and ( math.floor( fNewPop ) % nTrait ) == 0 ) then
- print( pPly:GetName() .. " has the trait, and the population is divisible by the trait.\n" )
- if pCity:IsCapital() then
- print( pCity:GetName() .. " is the capital of " .. pPly:GetName() .. "'s empire.\n" )
- if ( ( fNewPop > fOldPop ) and ( fNewPop >= nZenith ) ) then
- print( pCity:GetName() .. "'s current population is more than its previous population, and its population has reached a new level!" )
- iUnitMostCurrent = fnReturnBestInfantryUnit( pPly, pCity )
- pPly:AddFreeUnit( iUnitMostCurrent, "UNITAI_DEFENSE" ) --[[ What are the
- implications of this line? --]]
- print( "Should have free unit unless Irkalla fucked up." )
- end
- end
- end
- end )
Advertisement
Add Comment
Please, Sign In to add comment