print( "Loaded." )
--[[-----------------------------------------
Name: GetCivSpecificUnit
Purpose: Get the UnitType for a specific
civ from a UnitClassType.
-------------------------------------------]]
function fnGetCivSpecificUnit( pPly, sUnitClass ) -- Thanks whoward69
-- 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: " .. tostring( sUnitType ) .. ".\n" )
return sUnitType
end
--[[-----------------------------------------
Name: ReturnBestInfantryUnit
Purpose: Return the best land melee unit
that a city can build.
-------------------------------------------]]
function fnReturnBestInfantryUnit( pPly, pCity )
--BEGIN DEFINES
--local iPlyID = pCity:GetOwner()
--local pPly = Players[ iPlyID ]
local possibleUnitClasses = {
UNITCLASS_MECH,
UNITCLASS_MECHANIZED_INFANTRY,
UNITCLASS_INFANTRY,
UNITCLASS_GREAT_WAR_INFANTRY,
UNITCLASS_RIFLEMAN,
UNITCLASS_MUSKETMAN,
UNITCLASS_LONGSWORDSMAN,
NITCLASS_PIKEMAN,
UNITCLASS_SWORDSMAN,
UNITCLASS_SPEARMAN,
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( fn_GetCivSpecificUnit( pPly, iUnitClass ) ) then
print( "Unit to be given: " .. fn_GetCivSpecificUnit( pPly, iUnitClass ) .. "." )
return fn_GetCivSpecificUnit( pPly, iUnitClass )
end
end
-- Uh-oh!
print("ReturnBestInfantryUnit: Irkalla ed up.")
return -1
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 ed up." )
end
end
end
end )