Irkalla

trait_walls.lua

Dec 13th, 2012
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function fn_returnBestInfantryUnit( i_city )
  2.  
  3.     local i_plyID       = i_city:GetOwner()
  4.     local i_gdr     = GameInfo.Units.UNIT_MECH.ID
  5.     local i_inf_mechanized  = GameInfo.Units.UNIT_MECHANIZED_INFANTRY.ID
  6.     local i_inf     = GameInfo.Units.UNIT_INFANTRY.ID
  7.     local i_inf_gw      = GameInfo.Units.UNIT_GREAT_WAR_INFANTRY.ID
  8.     local i_rifleman    = GameInfo.Units.UNIT_RIFLEMAN.ID
  9.     local i_musketman   = GameInfo.Units.UNIT_MUSKETMAN.ID
  10.     local i_longswordsman   = GameInfo.Units.UNIT_LONGSWORDSMAN.ID
  11.     local i_pikeman     = GameInfo.Units.UNIT_PIKEMAN.ID
  12.     local i_swordsman   = GameInfo.Units.UNIT_SWORDSMAN.ID
  13.     local i_phalanx     = GameInfo.Units.UNIT_SPARTAN_PHALANX.ID  -- Can I get modded units like this?
  14.     local i_warrior     = GameInfo.Units.UNIT_WARRIOR.ID
  15.  
  16.     if i_city:CanTrain( i_gdr ) then  -- Is there a better way than this giant if, then, elseif, else statement?
  17.         return i_gdr
  18.     elseif i_city:CanTrain( i_inf_mechanized ) then
  19.         return i_inf_mechanized
  20.     elseif i_city:CanTrain( i_inf ) then
  21.         return i_inf
  22.     elseif i_city:CanTrain( i_inf_gw ) then
  23.         return i_inf_gw
  24.     elseif i_city:CanTrain( i_rifleman ) then
  25.         return i_rifleman
  26.     elseif i_city:CanTrain( i_musketman ) then
  27.         return i_musketman
  28.     elseif i_city:CanTrain( i_longswordsman ) then
  29.         return i_longswordsman
  30.     elseif i_city:CanTrain( i_pikeman ) then
  31.         return i_pikeman
  32.     elseif i_city:CanTrain( i_swordsman ) then
  33.         return i_swordsman
  34.     elseif i_city:CanTrain( i_phalanx ) then
  35.         return i_phalanx
  36.     else
  37.         return i_warrior
  38.     end
  39. end
  40.  
  41. GameEvents.SetPopulation.Add( function( x_offset, y_offset, f_oldPop, f_newPop )
  42.  
  43.     local i_plot            = Map.GetPlot( x_offset, y_offset )
  44.     local i_city            = i_plot:GetPlotCity()
  45.     local i_plyID           = i_city:GetOwner()
  46.     local i_unit_mostCurrent    = nil
  47.     local n_trait           = GameInfo.Traits[i_plyID].UnitPerCapitalGrowths
  48.     local i_unitAIType      = GameInfo.UnitAITypes.UNITAI_DEFENSE.ID
  49.     local n_zenith          = math.floor( i_city:GetHighestPopulation() )
  50.  
  51.     if ( n_trait > 0 &&  -- Gotta be a better way then this if/then bollocks
  52.     ( math.floor( f_newPop ) % n_trait ) == 0 ) && then
  53.         if i_city:IsCapital() then
  54.             if ( f_newPop > f_oldPop ) &&
  55.             iNewPop >= n_zenith then
  56.                 i_freeUnit = fn_returnBestInfantryUnit( i_city )
  57.  
  58.                 i_plyID:AddFreeUnit( i_freeUnit, i_unitAIType ) -- What are the implications of this line?
  59.             end
  60.         end
  61.     end
  62. end )
Advertisement
Add Comment
Please, Sign In to add comment