Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function fn_returnBestInfantryUnit( i_city )
- local i_plyID = i_city:GetOwner()
- local i_gdr = GameInfo.Units.UNIT_MECH.ID
- local i_inf_mechanized = GameInfo.Units.UNIT_MECHANIZED_INFANTRY.ID
- local i_inf = GameInfo.Units.UNIT_INFANTRY.ID
- local i_inf_gw = GameInfo.Units.UNIT_GREAT_WAR_INFANTRY.ID
- local i_rifleman = GameInfo.Units.UNIT_RIFLEMAN.ID
- local i_musketman = GameInfo.Units.UNIT_MUSKETMAN.ID
- local i_longswordsman = GameInfo.Units.UNIT_LONGSWORDSMAN.ID
- local i_pikeman = GameInfo.Units.UNIT_PIKEMAN.ID
- local i_swordsman = GameInfo.Units.UNIT_SWORDSMAN.ID
- local i_phalanx = GameInfo.Units.UNIT_SPARTAN_PHALANX.ID -- Can I get modded units like this?
- local i_warrior = GameInfo.Units.UNIT_WARRIOR.ID
- if i_city:CanTrain( i_gdr ) then -- Is there a better way than this giant if, then, elseif, else statement?
- return i_gdr
- elseif i_city:CanTrain( i_inf_mechanized ) then
- return i_inf_mechanized
- elseif i_city:CanTrain( i_inf ) then
- return i_inf
- elseif i_city:CanTrain( i_inf_gw ) then
- return i_inf_gw
- elseif i_city:CanTrain( i_rifleman ) then
- return i_rifleman
- elseif i_city:CanTrain( i_musketman ) then
- return i_musketman
- elseif i_city:CanTrain( i_longswordsman ) then
- return i_longswordsman
- elseif i_city:CanTrain( i_pikeman ) then
- return i_pikeman
- elseif i_city:CanTrain( i_swordsman ) then
- return i_swordsman
- elseif i_city:CanTrain( i_phalanx ) then
- return i_phalanx
- else
- return i_warrior
- end
- end
- GameEvents.SetPopulation.Add( function( x_offset, y_offset, f_oldPop, f_newPop )
- local i_plot = Map.GetPlot( x_offset, y_offset )
- local i_city = i_plot:GetPlotCity()
- local i_plyID = i_city:GetOwner()
- local i_unit_mostCurrent = nil
- local n_trait = GameInfo.Traits[i_plyID].UnitPerCapitalGrowths
- local i_unitAIType = GameInfo.UnitAITypes.UNITAI_DEFENSE.ID
- local n_zenith = math.floor( i_city:GetHighestPopulation() )
- if ( n_trait > 0 && -- Gotta be a better way then this if/then bollocks
- ( math.floor( f_newPop ) % n_trait ) == 0 ) && then
- if i_city:IsCapital() then
- if ( f_newPop > f_oldPop ) &&
- iNewPop >= n_zenith then
- i_freeUnit = fn_returnBestInfantryUnit( i_city )
- i_plyID:AddFreeUnit( i_freeUnit, i_unitAIType ) -- What are the implications of this line?
- end
- end
- end
- end )
Advertisement
Add Comment
Please, Sign In to add comment