View difference between Paste ID: NiECPZQP and BYRAEif7
SHOW: | | - or go back to the newest paste.
1-
function Irkalla_ReturnBestInfantryUnit( city )
1+
function fn_returnBestInfantryUnit( i_city )
2
3-
local plyID	= city:GetOwner()
3+
	local i_plyID		= i_city:GetOwner()
4-
local teamTechs = plyID:GetTeam()
4+
	local i_gdr		= GameInfo.Units.UNIT_MECH.ID
5
	local i_inf_mechanized	= GameInfo.Units.UNIT_MECHANIZED_INFANTRY.ID
6-
if teamTechs:HasTech( GameInfo.Techs.TECH_NUCLEAR_FUSION.ID ) then  -- Should I be shot for this giant if/then bullshit?  Fuck, this thing is ugly.
6+
	local i_inf		= GameInfo.Units.UNIT_INFANTRY.ID
7-
	return GameInfo.Units.UNIT_MECH.ID -- Giant Death Robot
7+
	local i_inf_gw		= GameInfo.Units.UNIT_GREAT_WAR_INFANTRY.ID
8-
elseif teamTechs:HasTech( GameInfo.Techs.TECH_MOBILE_TACTICS ) then
8+
	local i_rifleman	= GameInfo.Units.UNIT_RIFLEMAN.ID
9-
	return GameInfo.Units.UNIT_MECHANIZED_INFANTRY.ID
9+
	local i_musketman	= GameInfo.Units.UNIT_MUSKETMAN.ID
10-
elseif teamTechs:HasTech( GameInfo.Techs.TECH_PLASTIC.ID ) then
10+
	local i_longswordsman	= GameInfo.Units.UNIT_LONGSWORDSMAN.ID
11-
	return GameInfo.Units.UNIT_INFANTRY.ID
11+
	local i_pikeman		= GameInfo.Units.UNIT_PIKEMAN.ID
12-
elseif teamTechs:HasTech( GameInfo.Techs.TECH_REPLACEABLE_PARTS.ID ) then
12+
	local i_swordsman	= GameInfo.Units.UNIT_SWORDSMAN.ID
13-
	return GameInfo.Units.UNIT_GREAT_WAR_INFANTRY.ID
13+
	local i_phalanx		= GameInfo.Units.UNIT_SPARTAN_PHALANX.ID  -- Can I get modded units like this?
14-
elseif teamTechs:HasTech( GameInfo.Techs.TECH_RIFLING.ID ) then
14+
	local i_warrior		= GameInfo.Units.UNIT_WARRIOR.ID
15-
	return GameInfo.Units.UNIT_RIFLEMAN.ID
15+
16-
elseif teamTechs:HasTech( GameInfo.Techs.TECH_GUNPOWDER.ID ) then
16+
	if i_city:CanTrain( i_gdr ) then  -- Is there a better way than this giant if, then, elseif, else statement?
17-
	return GameInfo.Units.UNIT_MUSKETMAN.ID
17+
		return i_gdr
18-
elseif teamTechs:HasTech( GameInfo.Techs.TECH_STEEL.ID ) then
18+
	elseif i_city:CanTrain( i_inf_mechanized ) then
19-
	return GameInfo.Units.UNIT_LONGSWORDSMAN.ID
19+
		return i_inf_mechanized
20-
elseif teamTechs:HasTech( GameInfo.Techs.TECH_CIVIL_SERVICE.ID ) then
20+
	elseif i_city:CanTrain( i_inf ) then
21-
	return GameInfo.Units.UNIT_PIKEMAN.ID
21+
		return i_inf
22-
elseif teamTechs:HasTech( GameInfo.Techs.TECH_IRON_WORKING.ID ) then
22+
	elseif i_city:CanTrain( i_inf_gw ) then
23-
	return GameInfo.Units.UNIT_SWORDSMAN.ID
23+
		return i_inf_gw
24-
elseif teamTechs:HasTech( GameInfo.Techs.TECH_BRONZE_WORKING.ID ) then
24+
	elseif i_city:CanTrain( i_rifleman ) then
25-
	return GameInfo.Units.UNIT_SPARTAN_PHALANX.ID -- May one get modded units like this?
25+
		return i_rifleman
26-
else
26+
	elseif i_city:CanTrain( i_musketman ) then
27-
	return GameInfo.Units.UNIT_WARRIOR.ID
27+
		return i_musketman
28
	elseif i_city:CanTrain( i_longswordsman ) then
29
		return i_longswordsman
30-
GameEvents.SetPopulation.Add( function( iX, iY, oldPop, iNewPop )
30+
	elseif i_city:CanTrain( i_pikeman ) then
31
		return i_pikeman 
32-
local plot		= Map.GetPlot( iX, iY )
32+
	elseif i_city:CanTrain( i_swordsman ) then
33-
local city  		= plot:GetPlotCity()
33+
		return i_swordsman
34-
local plyID 		= city:GetOwner()
34+
	elseif i_city:CanTrain( i_phalanx ) then
35-
local unit_MostCurrent	= nil
35+
		return i_phalanx
36-
local trait		= GameInfo.Traits[PlyID].UnitPerCapitalGrowths
36+
	else
37-
local unitAIType	= GameInfo.UnitAITypes.UNITAI_DEFENSE.ID
37+
		return i_warrior
38
	end
39-
if ( trait > 0 &&  -- Gotta be a better way then this if/then bollocks
39+
40-
( math.floor( iNewPop ) % trait ) == 0 ) then 
40+
41-
	if city:IsCapital() then
41+
GameEvents.SetPopulation.Add( function( x_offset, y_offset, f_oldPop, f_newPop )
42-
		if iNewPop > oldPop then
42+
43-
			freeUnit = Irkalla_ReturnBestInfantryUnit( city )
43+
	local i_plot			= Map.GetPlot( x_offset, y_offset )
44
	local i_city  			= i_plot:GetPlotCity()
45-
			plyID:AddFreeUnit( freeUnit, unitAIType )
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 )