SHOW:
|
|
- or go back to the newest paste.
1 | --[[----------------------------------------- | |
2 | Name: GetCivSpecificUnit | |
3 | Purpose: Get the UnitType for a specific | |
4 | civ from a UnitClassType. | |
5 | -------------------------------------------]] | |
6 | function fnGetCivSpecificUnit(pPly, sUnitClass) -- Thanks whoward69 | |
7 | ||
8 | -- BEGIN DEFINES | |
9 | local sUnitType = nil | |
10 | - | local sCivType = GameInfo.Civilizations[pPly:GetCivilizationType()].Type |
10 | + | local sCivType = GameInfo.Civilizations[pPly:GetCivilizationType()].Type |
11 | -- END DEFINES | |
12 | ||
13 | - | -- Loop through civilization-specific UnitClass overrides, id est their unique units, and yield to be returned the proper UnitType. |
13 | + | -- Loop through civilization-specific UnitClass overrides, id est their unique units, and |
14 | - | for pOverride in GameInfo.Civilization_UnitClassOverrides{CivilizationType = sCivType, UnitClassType = sUnitClass} do |
14 | + | yield to be returned the proper UnitType. |
15 | for pOverride in GameInfo.Civilization_UnitClassOverrides{CivilizationType = sCivType, | |
16 | UnitClassType = sUnitClass} do | |
17 | sUnitType = pOverride.UnitType | |
18 | break | |
19 | end | |
20 | ||
21 | -- If we didn't get anything, yield to be returned the default UnitType for the UnitClass. | |
22 | if (sUnitType == nil) then | |
23 | sUnitType = GameInfo.UnitClasses[sUnitClass].DefaultUnit | |
24 | end | |
25 | ||
26 | -- Give whatever function called this the UnitType we yielded. | |
27 | return sUnitType | |
28 | end | |
29 | ||
30 | --[[----------------------------------------- | |
31 | Name: ReturnBestInfantryUnit | |
32 | Purpose: Return the best land melee unit | |
33 | that a city can build. | |
34 | -------------------------------------------]] | |
35 | function fnReturnBestInfantryUnit( pCity ) | |
36 | ||
37 | --BEGIN DEFINES | |
38 | local pPly = pCity:GetOwner() | |
39 | ||
40 | local possibleUnitClasses = { | |
41 | GameInfoTypes.UNITCLASS_MECH, | |
42 | GameInfoTypes.UNITCLASS_MECHANIZED_INFANTRY, | |
43 | GameInfoTypes.UNITCLASS_INFANTRY, | |
44 | GameInfotypes.UNITCLASS_GREAT_WAR_INFANTRY, | |
45 | GameInfoTypes.UNITCLASS_RIFLEMAN, | |
46 | GameInfoTypes.UNITCLASS_MUSKETMAN, | |
47 | GameInfoTypes.UNITCLASS_LONGSWORDSMAN, | |
48 | GameInfoTypes.UNITCLASS_PIKEMAN, | |
49 | GameInfoTypes.UNITCLASS_SWORDSMAN, | |
50 | GameInfoTypes.UNITCLASS_SPEARMAN, | |
51 | GameInfoTypes.UNITCLASS_WARRIOR | |
52 | } -- Thanks whoward69 | |
53 | --END DEFINES | |
54 | ||
55 | -- Loop through each UnitClassType in the above defined table, see if the city can | |
56 | -- train it's owner's specific UnitType. Yield to be returned the best land melee | |
57 | -- UnitType the city can build. | |
58 | for _, iUnitClass in ipairs(possibleUnitClasses) do -- Thanks whoward69 | |
59 | if pCity:CanTrain( fn_GetCivSpecificUnit( pPly, iUnitClass ) ) then | |
60 | return fn_GetCivSpecificUnit( pPly, iUnitClass ) | |
61 | end | |
62 | end | |
63 | ||
64 | -- Uh-oh! | |
65 | return -1 | |
66 | end | |
67 | ||
68 | GameEvents.SetPopulation.Add( function( xOffset, yOffset, fOldPop, fNewPop ) | |
69 | - | local pPlot = Map.GetPlot( xOffset, yOffset ) |
69 | + | |
70 | -- BEGIN DEFINES | |
71 | - | local pPly = pCity:GetOwner() |
71 | + | local pPlot = Map.GetPlot( xOffset, yOffset ) |
72 | - | local iUnitMostCurrent = nil |
72 | + | |
73 | local pPly = pCity:GetOwner() | |
74 | local iUnitMostCurrent = nil | |
75 | local nTrait = GameInfo.Traits[pPly].UnitPerCapitalGrowths | |
76 | local sUnitAIType = GameInfo.UnitAITypes.UNITAI_DEFENSE.ID | |
77 | local nZenith = math.floor( pCity:GetHighestPopulation() ) | |
78 | -- END DEFINES | |
79 | - | -- 1: Does the city's owner have the trait, and is its population evenly divisible by the trait? |
79 | + | |
80 | -- On every growth of every city, run through the following list of conditions: | |
81 | - | -- 3: Has the city grown instead of shrinking, and is this the city's highest population? |
81 | + | -- 1: Does the city's owner have the trait, and is its population evenly divisible |
82 | - | -- If all of the above are true, get the best land infantry unit we can, and spawn it at the city. |
82 | + | by the trait? |
83 | -- 2: Is the city a capital? | |
84 | -- 3: Has the city grown instead of shrinking, and is this the city's highest | |
85 | population? | |
86 | -- If all of the above are true, get the best land infantry unit we can, and | |
87 | spawn it at the city. | |
88 | if ( nTrait > 0 && | |
89 | ( math.floor( fNewPop ) % nTrait ) == 0 ) && then | |
90 | - | pPly:AddFreeUnit( iFreeUnit, iUnitAIType ) -- What are the implications of this line? |
90 | + | |
91 | if ( fNewPop > fOldPop ) && | |
92 | fNewPop >= nZenith then | |
93 | iFreeUnit = fnReturnBestInfantryUnit( pCity ) | |
94 | ||
95 | pPly:AddFreeUnit( iFreeUnit, iUnitAIType ) -- What are the | |
96 | implications of this line? | |
97 | end | |
98 | end | |
99 | end | |
100 | end ) |