-
Notifications
You must be signed in to change notification settings - Fork 0
/
GoldenAge_Cultivation.lua
340 lines (329 loc) · 18.5 KB
/
GoldenAge_Cultivation.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
--Credit to 'Resource Cultivation' by Zegangani.
ExposedMembers.ResourceCultivation = {};
local NONE = -1;
local GameLoaded = false;
function WriteMyCustomData(TableStringKey, TableValue)
ExposedMembers.ResourceCultivation.WriteMyCustomData(TableStringKey, TableValue)
end
function ReadMyCustomData(TableStringKey)
return ExposedMembers.ResourceCultivation.ReadMyCustomData(TableStringKey)
end
function RefreshResourceAmountProperty(PlayerID)
local pPlayer = Players[PlayerID];
local iNumCities = pPlayer:GetCities():GetCount()
local pPlayerCities = pPlayer:GetCities()
local iCityRadius = 4
local tResourceAmount = {}
local tAllCitiesResourceProperties = "AllPlayer"..tostring(PlayerID).."CitiesResourseProperties"
local tAllCitiesResourceProperties = {}
local PlayerTableStringKey = 'Player'..tostring(PlayerID)..'AllResources';
local PlayerDataTable = ReadMyCustomData(PlayerTableStringKey);
local CivilizationTypeName = PlayerConfigurations[PlayerID]:GetCivilizationTypeName()
print("####################################################################################################");
print("====================================================================================================");
print("#####******************# PlayerID: "..PlayerID.." , CivilizationName: "..CivilizationTypeName.." #******************#####")
print("====================================================================================================");
if GameLoaded then
if pPlayer:IsMajor() then
for k, pCity in pPlayerCities:Members() do
if pCity ~= nil then
local iCityID = pCity:GetID();
local iCityOwner = pCity:GetOwner()
local iCityX, iCityY = pCity:GetX(), pCity:GetY()
for dx = (iCityRadius * -1), iCityRadius do
for dy = (iCityRadius * -1), iCityRadius do
local pPlot = Map.GetPlotXYWithRangeCheck(iCityX, iCityY, dx, dy, iCityRadius);
if pPlot and (pPlot:GetOwner() == iCityOwner) and (pCity == Cities.GetPlotPurchaseCity(pPlot:GetIndex())) then
local pPlotResourceType = pPlot:GetResourceType();
if pPlotResourceType ~= -1 then
local Resource = GameInfo.Resources[pPlotResourceType]
local ResourceType = GameInfo.Resources[pPlotResourceType].ResourceType
for row in GameInfo.GA_Resource_Cultivation() do
local fg_ResourceType = row.ResourceType;
if ResourceType == fg_ResourceType then
--local PlayerDataTable = PlayerDataTable[tResourceAmount][ResourceType];
if row.ResourceClassType == 'RESOURCECLASS_LUXURY' then
if (tResourceAmount[ResourceType] ~= nil) then
tResourceAmount[ResourceType] = tResourceAmount[ResourceType] +1
else
tResourceAmount[ResourceType] = 1
end
end
end
end
-- if ResourceType == 'RESOURCE_HORSES' then
-- if (tResourceAmount[ResourceType] ~= nil) then
-- tResourceAmount[ResourceType] = tResourceAmount[ResourceType] +1
-- else
-- tResourceAmount[ResourceType] = 1
-- end
-- end
end
end
end
end
end
end
for k, pCity in pPlayerCities:Members() do
if pCity ~= nil then
local iCityID = pCity:GetID();
local iCityOwner = pCity:GetOwner()
local iCityX, iCityY = pCity:GetX(), pCity:GetY()
local tCityResources = {}
local tCityResourceProperties = {}
local iCityPlot = Map.GetPlot(pCity:GetX(), pCity:GetY());
print ("City with Id: "..iCityID.." is getting Resource Properties assigned/refreshed")
for dx = (iCityRadius * -1), iCityRadius do
for dy = (iCityRadius * -1), iCityRadius do
local pPlot = Map.GetPlotXYWithRangeCheck(iCityX, iCityY, dx, dy, iCityRadius);
if pPlot and (pPlot:GetOwner() == iCityOwner) and (pCity == Cities.GetPlotPurchaseCity(pPlot:GetIndex())) then
local pPlotResourceType = pPlot:GetResourceType();
if pPlotResourceType ~= -1 then
local Resource = GameInfo.Resources[pPlotResourceType]
local ResourceType = GameInfo.Resources[pPlotResourceType].ResourceType
for row in GameInfo.GA_Resource_Cultivation() do
local fg_ResourceType = row.ResourceType;
if ResourceType == fg_ResourceType then
if row.ResourceClassType == 'RESOURCECLASS_LUXURY' then
if (tCityResources[ResourceType] ~= nil) then
tCityResources[ResourceType] = tCityResources[ResourceType] + 1
else
tCityResources[ResourceType] = 1
end
end
end
end
-- if ResourceType == 'RESOURCE_HORSES' then
-- if (tCityResources[ResourceType] ~= nil) then
-- tCityResources[ResourceType] = tCityResources[ResourceType] + 1
-- else
-- tCityResources[ResourceType] = 1
-- end
-- end
end
end
end
end
local iCityTableName = 'tCity'..tostring(iCityID)..'Resources';
for row in GameInfo.Resources() do
local ResourceType = row.ResourceType;
local ResourceStringOnly = string.gsub(ResourceType, "RESOURCE_", "");
local ResourceName = Locale.Lookup(row.Name);
local iCityResourcePropertyName = 'City'..tostring(iCityID)..tostring(ResourceName)..'Property';
if row.ResourceClassType == 'RESOURCECLASS_LUXURY' then
for resource in GameInfo.GA_Resource_Cultivation() do
if ResourceType == resource.ResourceType then
if (tResourceAmount[ResourceType] ~= nil) and (tResourceAmount[ResourceType] <= 3) and (tCityResources[ResourceType] ~= nil) and (tCityResources[ResourceType] <= 2) then
if (PlayerDataTable == nil) then
iCityPlot:SetProperty("GA_PLAYER_"..ResourceStringOnly.."_MAX_AMOUNT", 1)
tCityResourceProperties[iCityResourcePropertyName] = 1
elseif (PlayerDataTable[1][iCityTableName] == nil) or (PlayerDataTable[1][iCityTableName][iCityResourcePropertyName] == nil) or (PlayerDataTable[1][iCityTableName][iCityResourcePropertyName] == 0) then
iCityPlot:SetProperty("GA_PLAYER_"..ResourceStringOnly.."_MAX_AMOUNT", 1)
tCityResourceProperties[iCityResourcePropertyName] = 1
else
tCityResourceProperties[iCityResourcePropertyName] = 1
end
else
if (PlayerDataTable == nil) then
iCityPlot:SetProperty("GA_PLAYER_"..ResourceStringOnly.."_MAX_AMOUNT", 0)
tCityResourceProperties[iCityResourcePropertyName] = 0
elseif (PlayerDataTable[1][iCityTableName] == nil) or (PlayerDataTable[1][iCityTableName][iCityResourcePropertyName] == nil) or (PlayerDataTable[1][iCityTableName][iCityResourcePropertyName] == 0) then
iCityPlot:SetProperty("GA_PLAYER_"..ResourceStringOnly.."_MAX_AMOUNT", 0)
tCityResourceProperties[iCityResourcePropertyName] = 0
elseif (PlayerDataTable[1][iCityTableName][iCityResourcePropertyName] ~= nil) and (PlayerDataTable[1][iCityTableName][iCityResourcePropertyName] == 0) then
tCityResourceProperties[iCityResourcePropertyName] = 0
end
end
end
end
end
-- if ResourceType == 'RESOURCE_HORSES' then
-- local CivilizationTypeName = PlayerConfigurations[PlayerID]:GetCivilizationTypeName()
-- if (tResourceAmount[ResourceType] ~= nil) and (tResourceAmount[ResourceType] <= 5) and (tCityResources[ResourceType] == nil) then
-- if (PlayerDataTable == nil) then
-- iCityPlot:SetProperty("GA_PLAYER_HORSES_MAX_AMOUNT", 1)
-- tCityResourceProperties[iCityResourcePropertyName] = 1
-- elseif (PlayerDataTable[1][iCityTableName][iCityResourcePropertyName] == nil) or (PlayerDataTable[1][iCityTableName][iCityResourcePropertyName] == 0) then
-- iCityPlot:SetProperty("GA_PLAYER_HORSES_MAX_AMOUNT", 1)
-- tCityResourceProperties[iCityResourcePropertyName] = 1
-- else
-- tCityResourceProperties[iCityResourcePropertyName] = 1
-- end
-- else
-- if (PlayerDataTable == nil) then
-- iCityPlot:SetProperty("GA_PLAYER_HORSES_MAX_AMOUNT", 0)
-- tCityResourceProperties[iCityResourcePropertyName] = 0
-- elseif (PlayerDataTable[1][iCityTableName][iCityResourcePropertyName] == nil) or (PlayerDataTable[1][iCityTableName][iCityResourcePropertyName] == 1) then
-- iCityPlot:SetProperty("GA_PLAYER_HORSES_MAX_AMOUNT", 0)
-- tCityResourceProperties[iCityResourcePropertyName] = 0
-- elseif (PlayerDataTable[1][iCityTableName][iCityResourcePropertyName] ~= nil) and (PlayerDataTable[1][iCityTableName][iCityResourcePropertyName] == 0) then
-- tCityResourceProperties[iCityResourcePropertyName] = 0
-- end
-- end
-- if ((CivilizationTypeName == 'CIVILIZATION_SCYTHIA') or (CivilizationTypeName == 'CIVILIZATION_MONGOLIA')) and (tCityResources[ResourceType] == nil) then
-- if (PlayerDataTable == nil) then
-- iCityPlot:SetProperty("GA_HORSES_CIV_ONE_PER_CITY", 1)
-- tCityResourceProperties[iCityResourcePropertyName] = 1
-- elseif (PlayerDataTable[1][iCityTableName][iCityResourcePropertyName] == nil) or (PlayerDataTable[1][iCityTableName][iCityResourcePropertyName] == 0) then
-- iCityPlot:SetProperty("GA_HORSES_CIV_ONE_PER_CITY", 1)
-- tCityResourceProperties[iCityResourcePropertyName] = 1
-- elseif (PlayerDataTable[1][iCityTableName][iCityResourcePropertyName] ~= nil) or (PlayerDataTable[1][iCityTableName][iCityResourcePropertyName] == 1) then
-- tCityResourceProperties[iCityResourcePropertyName] = 1
-- end
-- else
-- if (PlayerDataTable == nil) then
-- iCityPlot:SetProperty("GA_HORSES_CIV_ONE_PER_CITY", 0)
-- tCityResourceProperties[iCityResourcePropertyName] = 0
-- elseif (PlayerDataTable[1][iCityTableName][iCityResourcePropertyName] == nil) or (PlayerDataTable[1][iCityTableName][iCityResourcePropertyName] == 1) then
-- iCityPlot:SetProperty("GA_HORSES_CIV_ONE_PER_CITY", 0)
-- tCityResourceProperties[iCityResourcePropertyName] = 0
-- elseif (PlayerDataTable[1][iCityTableName][iCityResourcePropertyName] ~= nil) and (PlayerDataTable[1][iCityTableName][iCityResourcePropertyName] == 0) then
-- tCityResourceProperties[iCityResourcePropertyName] = 0
-- end
-- end
-- end
end
-- for row in GameInfo.Resources() do
-- local ResourceType = row.ResourceType;
-- local ResourceStringOnly = string.gsub(ResourceType, "RESOURCE_", "");
-- local ResourceName = Locale.Lookup(row.Name);
-- local iAllianceCityResourcePropertyName = 'AllianceCity'..tostring(iCityID)..tostring(ResourceName)..'Property';
-- if row.ResourceClassType == 'RESOURCECLASS_LUXURY' then
-- for resource in GameInfo.GA_Resource_Cultivation() do
-- if ResourceType == resource.ResourceType then
-- if tResourceAmount[ResourceType] == nil then
-- if (PlayerDataTable == nil) then
-- iCityPlot:SetProperty("GA_ALLIANCE_PLAYER_"..ResourceStringOnly.."_MAX_AMOUNT", 1)
-- tCityResourceProperties[iAllianceCityResourcePropertyName] = 1
-- elseif (PlayerDataTable[1][iCityTableName][iAllianceCityResourcePropertyName] == nil) or (PlayerDataTable[1][iCityTableName][iAllianceCityResourcePropertyName] == 0) then
-- iCityPlot:SetProperty("GA_ALLIANCE_PLAYER_"..ResourceStringOnly.."_MAX_AMOUNT", 1)
-- tCityResourceProperties[iAllianceCityResourcePropertyName] = 1
-- else
-- tCityResourceProperties[iAllianceCityResourcePropertyName] = 1
-- end
-- else
-- if (PlayerDataTable == nil) then
-- iCityPlot:SetProperty("GA_ALLIANCE_PLAYER_"..ResourceStringOnly.."_MAX_AMOUNT", 0)
-- tCityResourceProperties[iAllianceCityResourcePropertyName] = 0
-- elseif (PlayerDataTable[1][iCityTableName][iAllianceCityResourcePropertyName] == nil) or (PlayerDataTable[1][iCityTableName][iAllianceCityResourcePropertyName] == 1) then
-- iCityPlot:SetProperty("GA_ALLIANCE_PLAYER_"..ResourceStringOnly.."_MAX_AMOUNT", 0)
-- tCityResourceProperties[iAllianceCityResourcePropertyName] = 0
-- elseif (PlayerDataTable[1][iCityTableName][iAllianceCityResourcePropertyName] ~= nil) and (PlayerDataTable[1][iCityTableName][iAllianceCityResourcePropertyName] == 0) then
-- tCityResourceProperties[iAllianceCityResourcePropertyName] = 0
-- end
-- end
-- end
-- end
-- end
-- if ResourceType == 'RESOURCE_HORSES' then
-- if tResourceAmount[ResourceType] == nil then
-- if (PlayerDataTable == nil) then
-- iCityPlot:SetProperty("GA_ALLIANCE_PLAYER_"..ResourceStringOnly.."_MAX_AMOUNT", 1)
-- tCityResourceProperties[iAllianceCityResourcePropertyName] = 1
-- elseif (PlayerDataTable[1][iCityTableName][iAllianceCityResourcePropertyName] == nil) or (PlayerDataTable[1][iCityTableName][iAllianceCityResourcePropertyName] == 0) then
-- iCityPlot:SetProperty("GA_ALLIANCE_PLAYER_HORSES_MAX_AMOUNT", 1)
-- tCityResourceProperties[iAllianceCityResourcePropertyName] = 1
-- else
-- tCityResourceProperties[iAllianceCityResourcePropertyName] = 1
-- end
-- else
-- if (PlayerDataTable == nil) then
-- iCityPlot:SetProperty("GA_ALLIANCE_PLAYER_"..ResourceStringOnly.."_MAX_AMOUNT", 0)
-- tCityResourceProperties[iAllianceCityResourcePropertyName] = 0
-- elseif (PlayerDataTable[1][iCityTableName][iAllianceCityResourcePropertyName] == nil) or (PlayerDataTable[1][iCityTableName][iAllianceCityResourcePropertyName] == 1) then
-- iCityPlot:SetProperty("GA_ALLIANCE_PLAYER_HORSES_MAX_AMOUNT", 0)
-- tCityResourceProperties[iAllianceCityResourcePropertyName] = 0
-- elseif (PlayerDataTable[1][iCityTableName][iAllianceCityResourcePropertyName] ~= nil) and (PlayerDataTable[1][iCityTableName][iAllianceCityResourcePropertyName] == 0) then
-- tCityResourceProperties[iAllianceCityResourcePropertyName] = 0
-- end
-- end
-- end
-- end
tAllCitiesResourceProperties[iCityTableName] = tCityResourceProperties
end
end
local tPlayerAllResourcesData = {tAllCitiesResourceProperties}
if iNumCities >= 1 then
WriteMyCustomData(PlayerTableStringKey, tPlayerAllResourcesData)
end
print("####################################################################################################");
end
end
end
function OnResourcePlantedOrBreeded(locationX, locationY, eImprovementType, eImprovementOwnerID, resource, isPillaged, isWorked)
local pPlayer = Players[eImprovementOwnerID];
local plot = Map.GetPlot(locationX,locationY);
local pResourceImprovement = GameInfo.Improvements[eImprovementType];
local pResourceImprovementType = GameInfo.Improvements[eImprovementType].ImprovementType;
if pResourceImprovement ~=nil then
PlantOrBreed(pResourceImprovement,plot);
for row in GameInfo.GA_Resource_Cultivation() do
local pValidResourceImprovement = row.ImprovementType;
local pValidBuildImprovement = row.ValidImprovementType;
if pResourceImprovementType == pValidResourceImprovement then
ImprovementBuilder.SetImprovementType(plot, GameInfo.Improvements[pValidBuildImprovement].Index, plot:GetOwner());
end
end
end
if pPlayer ~= nil and eImprovementOwnerID ~= nil then
RefreshResourceAmountProperty(eImprovementOwnerID);
end
end
function PlantOrBreed(pResourceImprovement,plot)
local found_transplant_type = false;
local transplant_types = {};
table.insert(transplant_types,'RESOURCE');
for i in string.gmatch(pResourceImprovement.ImprovementType, "[^_]+") do
if i == 'CULTIVATE' then
found_transplant_type = true;
elseif found_transplant_type then
table.insert(transplant_types,i);
end
end
if found_transplant_type then
local transplant_resource_type = table.concat(transplant_types,'_');
ResourceBuilder.SetResourceType(plot, GameInfo.Resources[transplant_resource_type].Index, 1);
ImprovementBuilder.SetImprovementType(plot, NONE, NONE);
end
end
function PlotRefreshResourceAmountProperty(iX, iY)
local pPlot = Map.GetPlot(iX,iY);
if pPlot:IsOwned() then
local PlotOwnerID = pPlot:GetOwner();
RefreshResourceAmountProperty(PlotOwnerID);
end
end
function ActivateFarmerGardenerModScript()
GameLoaded = true;
end
Events.LoadScreenClose.Add(ActivateFarmerGardenerModScript)
Events.ImprovementAddedToMap.Add(OnResourcePlantedOrBreeded);
-- Events.AllianceAvailable.Add(RefreshResourceAmountProperty);
-- Events.AllianceEnded.Add(RefreshResourceAmountProperty);
Events.CapitalCityChanged.Add(RefreshResourceAmountProperty);
Events.CityAddedToMap.Add(RefreshResourceAmountProperty);
GameEvents.CityBuilt.Add(RefreshResourceAmountProperty);
GameEvents.CityConquered.Add(RefreshResourceAmountProperty);
--Events.CityInitialized.Add(RefreshResourceAmountProperty);
Events.CityLiberated.Add(RefreshResourceAmountProperty);
Events.CityMadePurchase.Add(RefreshResourceAmountProperty);
Events.CityOccupationChanged.Add(RefreshResourceAmountProperty);
Events.CityRemovedFromMap.Add(RefreshResourceAmountProperty);
Events.CityTileOwnershipChanged.Add(RefreshResourceAmountProperty);
Events.CityTransfered.Add(RefreshResourceAmountProperty);
Events.DistrictAddedToMap.Add(RefreshResourceAmountProperty);
Events.DistrictRemovedFromMap.Add(RefreshResourceAmountProperty);
Events.ImprovementAddedToMap.Add(PlotRefreshResourceAmountProperty);
Events.ImprovementRemovedFromMap.Add(PlotRefreshResourceAmountProperty);
GameEvents.OnDistrictConstructed.Add(RefreshResourceAmountProperty);
Events.PlayerDefeat.Add(RefreshResourceAmountProperty);
--Events.PlayerResourceChanged.Add(RefreshResourceAmountProperty);
Events.PlayerTurnActivated.Add(RefreshResourceAmountProperty);
Events.PlayerTurnDeactivated.Add(RefreshResourceAmountProperty);
GameEvents.PlayerTurnStarted.Add(RefreshResourceAmountProperty);
--Events.PlotPropertyChanged.Add(PlotRefreshResourceAmountProperty);
Events.ResourceAddedToMap.Add(PlotRefreshResourceAmountProperty);
Events.ResourceRemovedFromMap.Add(PlotRefreshResourceAmountProperty);
Events.UnitChargesChanged.Add(RefreshResourceAmountProperty);
--Events.UnitSelectionChanged.Add(RefreshResourceAmountProperty);
print("Gameplay Script loaded.");