Changeset 465 for branches/highdpi/CityProcessing.pas
- Timestamp:
- Nov 30, 2023, 10:16:14 PM (12 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/highdpi/CityProcessing.pas
r349 r465 8 8 9 9 // Reporting 10 procedure GetCityAreaInfo( p, Loc: integer; var CityAreaInfo: TCityAreaInfo);11 function CanCityGrow( p, cix: integer): boolean;12 function GetCityReport( p, cix: integer; var CityReport: TCityReport): integer;13 function GetCityReportNew( p, cix: integer;14 var CityReportNew: TCityReportNew): integer;10 procedure GetCityAreaInfo(P, Loc: Integer; var CityAreaInfo: TCityAreaInfo); 11 function CanCityGrow(P, cix: Integer): Boolean; 12 function GetCityReport(P, cix: Integer; var CityReport: TCityReport): Integer; 13 function GetCityReportNew(P, cix: Integer; 14 var CityReportNew: TCityReportNew): Integer; 15 15 16 16 // Internal Tile Picking 17 function AddBestCityTile( p, cix: integer): boolean;18 procedure CityGrowth( p, cix: integer);19 procedure CityShrink( p, cix: integer);20 procedure Pollute( p, cix: integer);17 function AddBestCityTile(P, cix: Integer): Boolean; 18 procedure CityGrowth(P, cix: Integer); 19 procedure CityShrink(P, cix: Integer); 20 procedure Pollute(P, cix: Integer); 21 21 22 22 // Turn Processing 23 procedure PayCityMaintenance( p, cix: integer);24 procedure CollectCityResources( p, cix: integer);25 function CityTurn( p, cix: integer): boolean;23 procedure PayCityMaintenance(P, cix: Integer); 24 procedure CollectCityResources(P, cix: Integer); 25 function CityTurn(P, cix: Integer): Boolean; 26 26 27 27 // Tile Access 28 function SetCityTiles( p, cix, NewTiles: integer;29 TestOnly: boolean = false): integer;30 procedure GetCityTileAdvice( p, cix: integer; var Advice: TCityTileAdviceData);28 function SetCityTiles(P, cix, NewTiles: Integer; 29 TestOnly: Boolean = False): Integer; 30 procedure GetCityTileAdvice(P, cix: Integer; var Advice: TCityTileAdviceData); 31 31 32 32 // Start/End Game … … 34 34 procedure ReleaseGame; 35 35 36 36 37 implementation 37 38 38 39 type 39 40 TTradeProcessing = record 40 TaxBonus, LuxBonus, ScienceBonus, FutResBonus, ScienceDoubling, 41 HappyBase: integer; 42 RelCorr: single; 43 FlexibleLuxury: boolean; 41 TaxBonus: Integer; 42 LuxBonus: Integer; 43 ScienceBonus: Integer; 44 FutResBonus: Integer; 45 ScienceDoubling: Integer; 46 HappyBase: Integer; 47 RelCorr: Single; 48 FlexibleLuxury: Boolean; 44 49 end; 45 50 46 51 TProdProcessing = record 47 ProdBonus, PollBonus, FutProdBonus, PollThreshold: integer; 52 ProdBonus: Integer; 53 PollBonus: Integer; 54 FutProdBonus: Integer; 55 PollThreshold: Integer; 48 56 end; 49 57 … … 51 59 52 60 TCityReportEx = record 53 BaseHappiness, BaseControl, Material: integer; 61 BaseHappiness: Integer; 62 BaseControl: Integer; 63 Material: Integer; 54 64 ProdProcessing: TProdProcessing; 55 65 TradeProcessing: TTradeProcessing; … … 57 67 58 68 var 59 MaxDist: integer;60 61 62 63 64 65 procedure GetCityAreaInfo( p, Loc: integer; var CityAreaInfo: TCityAreaInfo);66 var 67 V21, Loc1, p1: integer;69 MaxDist: Integer; 70 71 { 72 Reporting 73 ____________________________________________________________________ 74 } 75 procedure GetCityAreaInfo(P, Loc: Integer; var CityAreaInfo: TCityAreaInfo); 76 var 77 V21, Loc1, p1: Integer; 68 78 Radius: TVicinity21Loc; 69 79 begin 70 {$IFOPT O-} assert(1 shl pand InvalidTreatyMap = 0); {$ENDIF}80 {$IFOPT O-}Assert(1 shl P and InvalidTreatyMap = 0); {$ENDIF} 71 81 with CityAreaInfo do 72 82 begin … … 80 90 begin 81 91 p1 := RealMap[Loc1] shr 27; 82 if (p1 < nPl) and (p1 <> p) and (RW[p].Treaty[p1] >= trPeace) then92 if (p1 < nPl) and (p1 <> P) and (RW[P].Treaty[p1] >= trPeace) then 83 93 Available[V21] := faTreaty 84 else if (ZoCMap[Loc1] > 0) and (Occupant[Loc1] <> p) and85 (RW[ p].Treaty[Occupant[Loc1]] < trAlliance) then94 else if (ZoCMap[Loc1] > 0) and (Occupant[Loc1] <> P) and 95 (RW[P].Treaty[Occupant[Loc1]] < trAlliance) then 86 96 Available[V21] := faSiege 87 97 else if (UsedByCity[Loc1] <> -1) and (UsedByCity[Loc1] <> Loc) then 88 98 Available[V21] := faNotAvailable 89 99 else 90 Available[V21] := faAvailable 91 end 92 end; 93 end 94 end; 95 96 function CanCityGrow( p, cix: integer): boolean;97 begin 98 with RW[ p].City[cix] do99 result := (Size < MaxCitySize) and100 Available[V21] := faAvailable; 101 end; 102 end; 103 end; 104 end; 105 106 function CanCityGrow(P, cix: Integer): Boolean; 107 begin 108 with RW[P].City[cix] do 109 Result := (Size < MaxCitySize) and 100 110 ((Size < NeedAqueductSize) or (Built[imAqueduct] = 1) and 101 111 (Size < NeedSewerSize) or (Built[imSewer] = 1)); 102 112 end; 103 113 104 procedure DetermineCityProdProcessing( p, cix: integer;114 procedure DetermineCityProdProcessing(P, cix: Integer; 105 115 var ProdProcessing: TProdProcessing); 106 116 begin 107 with RW[ p].City[cix], ProdProcessing do117 with RW[P].City[cix], ProdProcessing do 108 118 begin 109 119 ProdBonus := 0; 110 120 PollBonus := 0; 111 121 if Built[imFactory] = 1 then 112 inc(ProdBonus);122 Inc(ProdBonus); 113 123 if Built[imMfgPlant] = 1 then 114 inc(ProdBonus);124 Inc(ProdBonus); 115 125 if (Built[imPower] = 1) or (Built[imHydro] = 1) or (Built[imNuclear] = 1) or 116 (GWonder[woHoover].EffectiveOwner = p) then126 (GWonder[woHoover].EffectiveOwner = P) then 117 127 ProdBonus := ProdBonus * 2; 118 128 if Built[imFactory] = 1 then 119 inc(PollBonus);129 Inc(PollBonus); 120 130 if Built[imMfgPlant] = 1 then 121 inc(PollBonus);131 Inc(PollBonus); 122 132 if (Built[imFactory] + Built[imMfgPlant] > 0) then 123 if (Built[imHydro] > 0) or (GWonder[woHoover].EffectiveOwner = p) then124 dec(PollBonus)133 if (Built[imHydro] > 0) or (GWonder[woHoover].EffectiveOwner = P) then 134 Dec(PollBonus) 125 135 else if (Built[imNuclear] = 0) and (Built[imPower] = 1) then 126 inc(PollBonus);127 if (RW[ p].Government <= gDespotism) or (Built[imRecycling] = 1) then136 Inc(PollBonus); 137 if (RW[P].Government <= gDespotism) or (Built[imRecycling] = 1) then 128 138 PollBonus := -2; // no pollution 129 139 PollThreshold := Size; 130 140 FutProdBonus := 0; 131 if RW[ p].Tech[futProductionTechnology] > 0 then141 if RW[P].Tech[futProductionTechnology] > 0 then 132 142 begin // future tech benefits 133 143 if Built[imFactory] = 1 then 134 inc(FutProdBonus, FactoryFutureBonus * RW[p].Tech144 Inc(FutProdBonus, FactoryFutureBonus * RW[P].Tech 135 145 [futProductionTechnology]); 136 146 if Built[imMfgPlant] = 1 then 137 inc(FutProdBonus, MfgPlantFutureBonus * RW[p].Tech147 Inc(FutProdBonus, MfgPlantFutureBonus * RW[P].Tech 138 148 [futProductionTechnology]); 139 149 end; … … 141 151 end; 142 152 143 procedure BoostProd(BaseProd: integer; ProdProcessing: TProdProcessing;144 var Prod, Poll: integer);153 procedure BoostProd(BaseProd: Integer; ProdProcessing: TProdProcessing; 154 var Prod, Poll: Integer); 145 155 begin 146 156 Poll := BaseProd * (2 + ProdProcessing.PollBonus) shr 1; … … 148 158 Poll := 0 149 159 else 150 dec(Poll, ProdProcessing.PollThreshold);160 Dec(Poll, ProdProcessing.PollThreshold); 151 161 if ProdProcessing.FutProdBonus > 0 then 152 162 Prod := BaseProd * (100 + ProdProcessing.ProdBonus * 50 + … … 156 166 end; 157 167 158 procedure DetermineCityTradeProcessing( p, cix, HappinessBeforeLux: integer;168 procedure DetermineCityTradeProcessing(P, cix, HappinessBeforeLux: Integer; 159 169 var TradeProcessing: TTradeProcessing); 160 170 var 161 i, Dist: integer;162 begin 163 with RW[ p].City[cix], TradeProcessing do171 I, Dist: Integer; 172 begin 173 with RW[P].City[cix], TradeProcessing do 164 174 begin 165 175 TaxBonus := 0; 166 176 ScienceBonus := 0; 167 177 if Built[imMarket] = 1 then 168 inc(TaxBonus, 2);178 Inc(TaxBonus, 2); 169 179 if Built[imBank] = 1 then 170 180 begin 171 inc(TaxBonus, 3);172 if RW[ p].NatBuilt[imStockEx] = 1 then173 inc(TaxBonus, 3);181 Inc(TaxBonus, 3); 182 if RW[P].NatBuilt[imStockEx] = 1 then 183 Inc(TaxBonus, 3); 174 184 end; 175 185 LuxBonus := TaxBonus; 176 186 if Built[imLibrary] = 1 then 177 inc(ScienceBonus, 2);187 Inc(ScienceBonus, 2); 178 188 if Built[imUniversity] = 1 then 179 inc(ScienceBonus, 3);189 Inc(ScienceBonus, 3); 180 190 if Built[imResLab] = 1 then 181 inc(ScienceBonus, 3);191 Inc(ScienceBonus, 3); 182 192 ScienceDoubling := 0; 183 193 if Built[imNatObs] > 0 then 184 inc(ScienceDoubling);185 if RW[ p].Government = gFundamentalism then186 dec(ScienceDoubling)187 else if (GWonder[woNewton].EffectiveOwner = p) and188 (RW[ p].Government = gMonarchy) then189 inc(ScienceDoubling);190 FlexibleLuxury := ((ServerVersion[ p] >= $0100F1) and191 (GWonder[woLiberty].EffectiveOwner = p) or (ServerVersion[p] < $0100F1)192 and (GWonder[woMich].EffectiveOwner = p)) and193 (RW[ p].Government <> gAnarchy);194 Inc(ScienceDoubling); 195 if RW[P].Government = gFundamentalism then 196 Dec(ScienceDoubling) 197 else if (GWonder[woNewton].EffectiveOwner = P) and 198 (RW[P].Government = gMonarchy) then 199 Inc(ScienceDoubling); 200 FlexibleLuxury := ((ServerVersion[P] >= $0100F1) and 201 (GWonder[woLiberty].EffectiveOwner = P) or (ServerVersion[P] < $0100F1) 202 and (GWonder[woMich].EffectiveOwner = P)) and 203 (RW[P].Government <> gAnarchy); 194 204 FutResBonus := 0; 195 if RW[ p].Tech[futResearchTechnology] > 0 then205 if RW[P].Tech[futResearchTechnology] > 0 then 196 206 begin // future tech benefits 197 207 if Built[imUniversity] = 1 then 198 inc(FutResBonus, UniversityFutureBonus * RW[p].Tech208 Inc(FutResBonus, UniversityFutureBonus * RW[P].Tech 199 209 [futResearchTechnology]); 200 210 if Built[imResLab] = 1 then 201 inc(FutResBonus, ResLabFutureBonus * RW[p].Tech[futResearchTechnology]);202 end; 203 if (RW[ p].NatBuilt[imPalace] > 0) or (ServerVersion[p] < $010000) then211 Inc(FutResBonus, ResLabFutureBonus * RW[P].Tech[futResearchTechnology]); 212 end; 213 if (RW[P].NatBuilt[imPalace] > 0) or (ServerVersion[P] < $010000) then 204 214 begin // calculate corruption 205 215 Dist := MaxDist; 206 for i := 0 to RW[p].nCity - 1 do207 if (RW[ p].City[i].Loc >= 0) and (RW[p].City[i].Built[imPalace] = 1) then208 Dist := Distance(Loc, RW[ p].City[i].Loc);209 if (Dist = 0) or (CorrLevel[RW[ p].Government] = 0) then216 for I := 0 to RW[P].nCity - 1 do 217 if (RW[P].City[I].Loc >= 0) and (RW[P].City[I].Built[imPalace] = 1) then 218 Dist := Distance(Loc, RW[P].City[I].Loc); 219 if (Dist = 0) or (CorrLevel[RW[P].Government] = 0) then 210 220 RelCorr := 0.0 211 221 else 212 222 begin 213 223 RelCorr := Dist / MaxDist; 214 if CorrLevel[RW[ p].Government] > 1 then215 RelCorr := Exp(ln(RelCorr) / CorrLevel[RW[ p].Government]);224 if CorrLevel[RW[P].Government] > 1 then 225 RelCorr := Exp(ln(RelCorr) / CorrLevel[RW[P].Government]); 216 226 if Built[imCourt] = 1 then 217 227 RelCorr := RelCorr / 2; … … 224 234 RelCorr := 1.0; 225 235 HappyBase := Size + HappinessBeforeLux; 226 end 227 end; 228 229 procedure SplitTrade(Trade, TaxRate, LuxRate, Working: integer;236 end; 237 end; 238 239 procedure SplitTrade(Trade, TaxRate, LuxRate, Working: Integer; 230 240 TradeProcessing: TTradeProcessing; var Corruption, Tax, Lux, 231 Science: integer);232 var 233 plus: integer;241 Science: Integer); 242 var 243 plus: Integer; 234 244 begin 235 245 Corruption := Trunc(Trade * TradeProcessing.RelCorr); … … 266 276 end; 267 277 268 function GetProjectCost( p, cix: integer): integer;269 var 270 i: integer;271 begin 272 with RW[ p].City[cix] do278 function GetProjectCost(P, cix: Integer): Integer; 279 var 280 I: Integer; 281 begin 282 with RW[P].City[cix] do 273 283 begin 274 284 if Project and cpImp = 0 then 275 285 begin 276 result := RW[p].Model[Project and cpIndex].Cost; { unit project }286 Result := RW[P].Model[Project and cpIndex].Cost; { unit project } 277 287 if Project and cpConscripts <> 0 then 278 288 begin 279 i := RW[p].Model[Project and cpIndex].MCost;280 result := result - 3 * i;281 if result <= 0 then282 result := i289 I := RW[P].Model[Project and cpIndex].MCost; 290 Result := Result - 3 * I; 291 if Result <= 0 then 292 Result := I; 283 293 end 284 else if RW[ p].Model[Project and cpIndex].Cap[mcLine] > 0 then294 else if RW[P].Model[Project and cpIndex].Cap[mcLine] > 0 then 285 295 if Project0 and (not cpAuto or cpRepeat) = Project and not cpAuto or cpRepeat 286 296 then 287 result := result shr 1297 Result := Result shr 1 288 298 else 289 result := result * 2299 Result := Result * 2; 290 300 end 291 301 else 292 302 begin { improvement project } 293 result := Imp[Project and cpIndex].Cost;294 if (Project and cpIndex < nWonder) and (GWonder[woColossus].EffectiveOwner = p)303 Result := Imp[Project and cpIndex].Cost; 304 if (Project and cpIndex < nWonder) and (GWonder[woColossus].EffectiveOwner = P) 295 305 then 296 result := result * ColossusEffect div 100;297 end; 298 result := result * BuildCostMod[Difficulty[p]] div 12;299 end 300 end; 301 302 function GetSmallCityReport( p, cix: integer; var CityReport: TCityReport;303 PCityReportEx: PCityReportEx = nil): integer;304 var 305 i, uix, V21, Loc1, ForcedSupport, BaseHappiness, Control: integer;306 Result := Result * ColossusEffect div 100; 307 end; 308 Result := Result * BuildCostMod[Difficulty[P]] div 12; 309 end; 310 end; 311 312 function GetSmallCityReport(P, cix: Integer; var CityReport: TCityReport; 313 PCityReportEx: PCityReportEx = nil): Integer; 314 var 315 I, uix, V21, Loc1, ForcedSupport, BaseHappiness, Control: Integer; 306 316 ProdProcessing: TProdProcessing; 307 317 TradeProcessing: TTradeProcessing; 308 318 Radius: TVicinity21Loc; 309 319 UnitReport: TUnitReport; 310 RareOK: array [0 .. 3] of integer;320 RareOK: array [0 .. 3] of Integer; 311 321 TileInfo: TTileInfo; 312 322 begin 313 with RW[ p].City[cix], CityReport do323 with RW[P].City[cix], CityReport do 314 324 begin 315 325 if HypoTiles <= 0 then 316 326 HypoTiles := Tiles; 317 327 if HypoTax < 0 then 318 HypoTax := RW[ p].TaxRate;328 HypoTax := RW[P].TaxRate; 319 329 if HypoLux < 0 then 320 HypoLux := RW[ p].LuxRate;321 322 if (Flags and chCaptured <> 0) or (RW[ p].Government = gAnarchy) then330 HypoLux := RW[P].LuxRate; 331 332 if (Flags and chCaptured <> 0) or (RW[P].Government = gAnarchy) then 323 333 begin 324 334 Working := 0; 325 335 for V21 := 1 to 26 do 326 336 if HypoTiles and (1 shl V21) <> 0 then 327 inc(Working); // for backward compatibility328 329 if RW[ p].Government = gFundamentalism then337 Inc(Working); // for backward compatibility 338 339 if RW[P].Government = gFundamentalism then 330 340 begin 331 341 Happy := Size; 332 Control := Size 342 Control := Size; 333 343 end // !!! old bug, kept for compatibility 334 344 else 335 345 begin 336 346 Happy := 0; 337 Control := 0 347 Control := 0; 338 348 end; 339 349 … … 370 380 BaseHappiness := Size; 371 381 end; 372 for i:= 0 to nWonder - 1 do373 if Built[ i] = 1 then382 for I := 0 to nWonder - 1 do 383 if Built[I] = 1 then 374 384 begin 375 inc(Happy);376 inc(BaseHappiness, 2)385 Inc(Happy); 386 Inc(BaseHappiness, 2); 377 387 end; 378 388 if Built[imTemple] = 1 then 379 389 begin 380 inc(Happy);381 inc(BaseHappiness, 2)390 Inc(Happy); 391 Inc(BaseHappiness, 2); 382 392 end; 383 393 if Built[imCathedral] = 1 then 384 394 begin 385 inc(Happy, 2);386 inc(BaseHappiness, 4);387 if GWonder[woBach].EffectiveOwner = pthen395 Inc(Happy, 2); 396 Inc(BaseHappiness, 4); 397 if GWonder[woBach].EffectiveOwner = P then 388 398 begin 389 inc(Happy);390 inc(BaseHappiness, 2)399 Inc(Happy); 400 Inc(BaseHappiness, 2); 391 401 end; 392 402 end; 393 403 if Built[imTheater] > 0 then 394 404 begin 395 inc(Happy, 2);396 inc(BaseHappiness, 4)405 Inc(Happy, 2); 406 Inc(BaseHappiness, 4); 397 407 end; 398 408 399 409 // calculate unit support 400 {$IFOPT O-} assert(InvalidTreatyMap = 0); {$ENDIF}410 {$IFOPT O-}Assert(InvalidTreatyMap = 0); {$ENDIF} 401 411 Support := 0; 402 412 ForcedSupport := 0; 403 413 Eaten := Size * 2; 404 414 Deployed := 0; 405 for uix := 0 to RW[ p].nUn - 1 do406 with RW[ p].Un[uix] do415 for uix := 0 to RW[P].nUn - 1 do 416 with RW[P].Un[uix] do 407 417 if (Loc >= 0) and (Home = cix) then 408 418 begin 409 GetUnitReport( p, uix, UnitReport);410 inc(Eaten, UnitReport.FoodSupport);419 GetUnitReport(P, uix, UnitReport); 420 Inc(Eaten, UnitReport.FoodSupport); 411 421 if UnitReport.ReportFlags and urfAlwaysSupport <> 0 then 412 inc(ForcedSupport, UnitReport.ProdSupport)422 Inc(ForcedSupport, UnitReport.ProdSupport) 413 423 else 414 inc(Support, UnitReport.ProdSupport);424 Inc(Support, UnitReport.ProdSupport); 415 425 if UnitReport.ReportFlags and urfDeployed <> 0 then 416 inc(Deployed);426 Inc(Deployed); 417 427 end; 418 428 if Deployed >= Happy then 419 429 Happy := 0 420 430 else 421 dec(Happy, Deployed);422 dec(Support, Size * SupportFree[RW[p].Government] shr 1);431 Dec(Happy, Deployed); 432 Dec(Support, Size * SupportFree[RW[P].Government] shr 1); 423 433 if Support < 0 then 424 434 Support := 0; 425 inc(Support, ForcedSupport);435 Inc(Support, ForcedSupport); 426 436 427 437 { control } 428 case RW[ p].Government of438 case RW[P].Government of 429 439 gDespotism: 430 for uix := 0 to RW[ p].nUn - 1 do431 if (RW[ p].Un[uix].Loc = Loc) and432 (RW[ p].Model[RW[p].Un[uix].mix].Kind = mkSpecial_TownGuard) then440 for uix := 0 to RW[P].nUn - 1 do 441 if (RW[P].Un[uix].Loc = Loc) and 442 (RW[P].Model[RW[P].Un[uix].mix].Kind = mkSpecial_TownGuard) then 433 443 begin 434 inc(Happy);435 inc(Control, 2)444 Inc(Happy); 445 Inc(Control, 2); 436 446 end; 437 447 gFundamentalism: … … 439 449 BaseHappiness := 0; // done by control 440 450 Happy := Size; 441 Control := Size 451 Control := Size; 442 452 end; 443 453 end; 444 454 445 455 // collect processing parameters 446 DetermineCityProdProcessing( p, cix, ProdProcessing);447 DetermineCityTradeProcessing( p, cix, BaseHappiness + Control - 2 *456 DetermineCityProdProcessing(P, cix, ProdProcessing); 457 DetermineCityTradeProcessing(P, cix, BaseHappiness + Control - 2 * 448 458 Deployed, TradeProcessing); 449 459 … … 462 472 // HypoTiles go beyond map border! 463 473 begin 464 result := eInvalid;465 exit474 Result := eInvalid; 475 Exit; 466 476 end; 467 GetTileInfo( p, cix, Loc1, TileInfo);468 inc(FoodRep, TileInfo.Food);469 inc(ProdRep, TileInfo.Prod);470 inc(Trade, TileInfo.Trade);477 GetTileInfo(P, cix, Loc1, TileInfo); 478 Inc(FoodRep, TileInfo.Food); 479 Inc(ProdRep, TileInfo.Prod); 480 Inc(Trade, TileInfo.Trade); 471 481 if (RealMap[Loc1] and fModern <> 0) and 472 (RW[ p].Tech[adMassProduction] >= tsApplicable) then473 inc(RareOK[RealMap[Loc1] shr 25 and 3]);474 inc(Working)482 (RW[P].Tech[adMassProduction] >= tsApplicable) then 483 Inc(RareOK[RealMap[Loc1] shr 25 and 3]); 484 Inc(Working); 475 485 end; 476 486 if Built[imAlgae] = 1 then 477 inc(FoodRep, 12);487 Inc(FoodRep, 12); 478 488 479 489 if PCityReportEx <> nil then … … 500 510 end; 501 511 end; 502 result := eOk;503 end; { GetSmallCityReport }504 505 function GetCityReport( p, cix: integer; var CityReport: TCityReport): integer;506 begin 507 result := GetSmallCityReport(p, cix, CityReport);508 CityReport.Storage := StorageSize[Difficulty[ p]];509 CityReport.ProdCost := GetProjectCost( p, cix);510 end; 511 512 function GetCityReportNew( p, cix: integer;513 var CityReportNew: TCityReportNew): integer;512 Result := eOk; 513 end; 514 515 function GetCityReport(P, cix: Integer; var CityReport: TCityReport): Integer; 516 begin 517 Result := GetSmallCityReport(P, cix, CityReport); 518 CityReport.Storage := StorageSize[Difficulty[P]]; 519 CityReport.ProdCost := GetProjectCost(P, cix); 520 end; 521 522 function GetCityReportNew(P, cix: Integer; 523 var CityReportNew: TCityReportNew): Integer; 514 524 var 515 525 CityReport: TCityReport; … … 521 531 CityReport.HypoTax := HypoTaxRate; 522 532 CityReport.HypoLux := HypoLuxuryRate; 523 result := GetSmallCityReport(p, cix, CityReport, @CityReportEx);524 FoodSupport := CityReport.Eaten - 2 * RW[ p].City[cix].Size;533 Result := GetSmallCityReport(P, cix, CityReport, @CityReportEx); 534 FoodSupport := CityReport.Eaten - 2 * RW[P].City[cix].Size; 525 535 MaterialSupport := CityReport.Support; 526 ProjectCost := GetProjectCost( p, cix);527 Storage := StorageSize[Difficulty[ p]];536 ProjectCost := GetProjectCost(P, cix); 537 Storage := StorageSize[Difficulty[P]]; 528 538 Deployed := CityReport.Deployed; 529 539 Morale := CityReportEx.BaseHappiness; 530 540 CollectedControl := CityReportEx.BaseControl + 531 (RW[ p].City[cix].Size - CityReport.Working) * 2;541 (RW[P].City[cix].Size - CityReport.Working) * 2; 532 542 CollectedFood := CityReport.FoodRep; 533 543 CollectedMaterial := CityReportEx.Material; … … 541 551 Luxury := CityReport.Lux; 542 552 FoodSurplus := CityReport.FoodRep - CityReport.Eaten; 543 HappinessBalance := Morale + Luxury + CollectedControl - RW[ p].City[cix]553 HappinessBalance := Morale + Luxury + CollectedControl - RW[P].City[cix] 544 554 .Size - 2 * Deployed; 545 555 end; … … 550 560 ____________________________________________________________________ 551 561 } 552 procedure NextBest( p, cix: integer; var SelectedLoc, SelectedV21: integer);562 procedure NextBest(P, cix: Integer; var SelectedLoc, SelectedV21: Integer); 553 563 { best tile unused but available by city cix } 554 564 var 555 Resources, Most, Loc1, p1, V21: integer;565 Resources, Most, Loc1, p1, V21: Integer; 556 566 TileInfo: TTileInfo; 557 567 Radius: TVicinity21Loc; 558 568 begin 559 {$IFOPT O-} assert(1 shl pand InvalidTreatyMap = 0); {$ENDIF}569 {$IFOPT O-}Assert(1 shl P and InvalidTreatyMap = 0); {$ENDIF} 560 570 Most := 0; 561 571 SelectedLoc := -1; 562 572 SelectedV21 := -1; 563 with RW[ p].City[cix] do573 with RW[P].City[cix] do 564 574 begin 565 575 V21_to_Loc(Loc, Radius); … … 570 580 begin 571 581 p1 := RealMap[Loc1] shr 27; 572 if ((p1 = nPl) or (p1 = p) or (RW[p].Treaty[p1] < trPeace)) and573 ((ZoCMap[Loc1] = 0) or (Occupant[Loc1] = p) or574 (RW[ p].Treaty[Occupant[Loc1]] = trAlliance)) then582 if ((p1 = nPl) or (p1 = P) or (RW[P].Treaty[p1] < trPeace)) and 583 ((ZoCMap[Loc1] = 0) or (Occupant[Loc1] = P) or 584 (RW[P].Treaty[Occupant[Loc1]] = trAlliance)) then 575 585 begin 576 GetTileInfo( p, cix, Loc1, TileInfo);586 GetTileInfo(P, cix, Loc1, TileInfo); 577 587 Resources := TileInfo.Food shl 16 + TileInfo.Prod shl 8 + 578 588 TileInfo.Trade; … … 582 592 SelectedLoc := Loc1; 583 593 SelectedV21 := V21; 584 Most := Resources 585 end 586 end 587 end 588 end; 589 end; 590 end; 591 592 procedure NextWorst( p, cix: integer; var SelectedLoc, SelectedV21: integer);594 Most := Resources; 595 end; 596 end; 597 end; 598 end; 599 end; 600 end; 601 602 procedure NextWorst(P, cix: Integer; var SelectedLoc, SelectedV21: Integer); 593 603 { worst tile used by city cix } 594 604 var 595 Resources, Least, Loc1, V21: integer;605 Resources, Least, Loc1, V21: Integer; 596 606 Radius: TVicinity21Loc; 597 607 TileInfo: TTileInfo; … … 600 610 SelectedLoc := -1; 601 611 SelectedV21 := -1; 602 with RW[ p].City[cix] do612 with RW[P].City[cix] do 603 613 begin 604 614 V21_to_Loc(Loc, Radius); … … 609 619 if (Loc1 >= 0) and (Loc1 < MapSize) and (1 shl V21 and Tiles <> 0) then 610 620 begin 611 GetTileInfo( p, cix, Loc1, TileInfo);621 GetTileInfo(P, cix, Loc1, TileInfo); 612 622 Resources := TileInfo.Food shl 16 + TileInfo.Prod shl 8 + 613 623 TileInfo.Trade; … … 617 627 SelectedLoc := Loc1; 618 628 SelectedV21 := V21; 619 Least := Resources 620 end 621 end; 622 end 623 end 624 end; 625 626 function NextPoll( p, cix: integer): integer;627 var 628 Resources, Best, dx, dy, Loc1, Dist, BestDist, V21, pTerr: integer;629 Least := Resources; 630 end; 631 end; 632 end; 633 end; 634 end; 635 636 function NextPoll(P, cix: Integer): Integer; 637 var 638 Resources, Best, dx, dy, Loc1, Dist, BestDist, V21, pTerr: Integer; 629 639 Radius: TVicinity21Loc; 630 640 TileInfo: TTileInfo; 631 641 begin 632 642 BestDist := MaxInt; 633 {$IFOPT O-} assert(1 shl pand InvalidTreatyMap = 0); {$ENDIF}643 {$IFOPT O-}Assert(1 shl P and InvalidTreatyMap = 0); {$ENDIF} 634 644 Best := 0; 635 result := -1;636 with RW[ p].City[cix] do645 Result := -1; 646 with RW[P].City[cix] do 637 647 begin 638 648 V21_to_Loc(Loc, Radius); … … 646 656 begin 647 657 pTerr := RealMap[Loc1] shr 27; 648 if (pTerr = nPl) or (pTerr = p) or (RW[p].Treaty[pTerr] < trPeace)658 if (pTerr = nPl) or (pTerr = P) or (RW[P].Treaty[pTerr] < trPeace) 649 659 then 650 660 begin 651 GetTileInfo( p, cix, Loc1, TileInfo);661 GetTileInfo(P, cix, Loc1, TileInfo); 652 662 Resources := TileInfo.Prod shl 16 + TileInfo.Trade shl 8 + 653 663 TileInfo.Food; … … 659 669 then 660 670 begin 661 result := Loc1;671 Result := Loc1; 662 672 Best := Resources; 663 673 BestDist := Dist; … … 669 679 end; 670 680 671 function AddBestCityTile( p, cix: integer): boolean;672 var 673 TileLoc, V21: integer;674 begin 675 NextBest( p, cix, TileLoc, V21);676 result := TileLoc >= 0;677 if result then678 with RW[ p].City[cix] do679 begin 680 assert(1 shl V21 and Tiles = 0);681 function AddBestCityTile(P, cix: Integer): Boolean; 682 var 683 TileLoc, V21: Integer; 684 begin 685 NextBest(P, cix, TileLoc, V21); 686 Result := TileLoc >= 0; 687 if Result then 688 with RW[P].City[cix] do 689 begin 690 Assert(1 shl V21 and Tiles = 0); 681 691 Tiles := Tiles or (1 shl V21); 682 UsedByCity[TileLoc] := Loc 683 end 684 end; 685 686 procedure CityGrowth( p, cix: integer);687 var 688 TileLoc, V21: integer;692 UsedByCity[TileLoc] := Loc; 693 end; 694 end; 695 696 procedure CityGrowth(P, cix: Integer); 697 var 698 TileLoc, V21: Integer; 689 699 AltCityReport: TCityReport; 690 700 begin 691 with RW[ p].City[cix] do701 with RW[P].City[cix] do 692 702 begin 693 inc(Size);694 NextBest( p, cix, TileLoc, V21);703 Inc(Size); 704 NextBest(P, cix, TileLoc, V21); 695 705 if TileLoc >= 0 then 696 706 begin { test whether exploitation of tile would lead to disorder } … … 698 708 AltCityReport.HypoTax := -1; 699 709 AltCityReport.HypoLux := -1; 700 GetSmallCityReport( p, cix, AltCityReport);710 GetSmallCityReport(P, cix, AltCityReport); 701 711 if AltCityReport.Working - AltCityReport.Happy <= Size shr 1 then 702 712 // !!! change to new style disorder 703 713 begin { no disorder -- exploit tile } 704 assert(1 shl V21 and Tiles = 0);714 Assert(1 shl V21 and Tiles = 0); 705 715 Tiles := Tiles or (1 shl V21); 706 UsedByCity[TileLoc] := Loc 707 end 708 end; 709 end 710 end; 711 712 procedure CityShrink( p, cix: integer);713 var 714 TileLoc, V21, Working: integer;716 UsedByCity[TileLoc] := Loc; 717 end; 718 end; 719 end; 720 end; 721 722 procedure CityShrink(P, cix: Integer); 723 var 724 TileLoc, V21, Working: Integer; 715 725 AltCityReport: TCityReport; 716 726 begin 717 with RW[ p].City[cix] do727 with RW[P].City[cix] do 718 728 begin 719 729 Working := 0; 720 730 for V21 := 1 to 26 do 721 731 if Tiles and (1 shl V21) <> 0 then 722 inc(Working);723 dec(Size);724 if Food > StorageSize[Difficulty[ p]] then725 Food := StorageSize[Difficulty[ p]];726 NextWorst( p, cix, TileLoc, V21);732 Inc(Working); 733 Dec(Size); 734 if Food > StorageSize[Difficulty[P]] then 735 Food := StorageSize[Difficulty[P]]; 736 NextWorst(P, cix, TileLoc, V21); 727 737 if Working > Size then 728 738 begin { all citizens were working -- worst tile no longer exploited } 729 assert(1 shl V21 and Tiles <> 0);739 Assert(1 shl V21 and Tiles <> 0); 730 740 Tiles := Tiles and not(1 shl V21); 731 UsedByCity[TileLoc] := -1 741 UsedByCity[TileLoc] := -1; 732 742 end 733 743 else { test whether exploitation of tile would lead to disorder } … … 736 746 AltCityReport.HypoTax := -1; 737 747 AltCityReport.HypoLux := -1; 738 GetSmallCityReport( p, cix, AltCityReport);748 GetSmallCityReport(P, cix, AltCityReport); 739 749 if AltCityReport.Working - AltCityReport.Happy > Size shr 1 then 740 750 // !!! change to new style disorder 741 751 begin { disorder -- don't exploit tile } 742 assert(1 shl V21 and Tiles <> 0);752 Assert(1 shl V21 and Tiles <> 0); 743 753 Tiles := Tiles and not(1 shl V21); 744 UsedByCity[TileLoc] := -1 745 end 746 end; 747 end 748 end; 749 750 procedure Pollute( p, cix: integer);751 var 752 PollutionLoc: integer;753 begin 754 with RW[ p].City[cix] do754 UsedByCity[TileLoc] := -1; 755 end; 756 end; 757 end; 758 end; 759 760 procedure Pollute(P, cix: Integer); 761 var 762 PollutionLoc: Integer; 763 begin 764 with RW[P].City[cix] do 755 765 begin 756 766 Pollution := Pollution - MaxPollution; 757 PollutionLoc := NextPoll( p, cix);767 PollutionLoc := NextPoll(P, cix); 758 768 if PollutionLoc >= 0 then 759 769 begin 760 inc(Flags, chPollution);770 Inc(Flags, chPollution); 761 771 RealMap[PollutionLoc] := RealMap[PollutionLoc] or fPoll; 762 end 772 end; 763 773 end; 764 774 end; … … 768 778 ____________________________________________________________________ 769 779 } 770 procedure PayCityMaintenance( p, cix: integer);771 var 772 i: integer;773 begin 774 with RW[ p], City[cix] do775 for i:= nWonder to nImp - 1 do776 if (Built[ i] > 0) and (Project0 and (cpImp or cpIndex) <> (cpImp or i))780 procedure PayCityMaintenance(P, cix: Integer); 781 var 782 I: Integer; 783 begin 784 with RW[P], City[cix] do 785 for I := nWonder to nImp - 1 do 786 if (Built[I] > 0) and (Project0 and (cpImp or cpIndex) <> (cpImp or I)) 777 787 then // don't pay maintenance when just completed 778 788 begin 779 dec(Money, Imp[i].Maint);789 Dec(Money, Imp[I].Maint); 780 790 if Money < 0 then 781 791 begin { out of money - sell improvement } 782 inc(Money, Imp[i].Cost * BuildCostMod[Difficulty[p]] div 12);783 Built[ i] := 0;784 if Imp[ i].Kind <> ikCommon then792 Inc(Money, Imp[I].Cost * BuildCostMod[Difficulty[P]] div 12); 793 Built[I] := 0; 794 if Imp[I].Kind <> ikCommon then 785 795 begin 786 assert(i<> imSpacePort);796 Assert(I <> imSpacePort); 787 797 // never sell automatically! (solution: no maintenance) 788 NatBuilt[ i] := 0;789 if i= imGrWall then790 GrWallContinent[ p] := -1;798 NatBuilt[I] := 0; 799 if I = imGrWall then 800 GrWallContinent[P] := -1; 791 801 end; 792 inc(Flags, chImprovementLost)793 end 794 end; 795 end; 796 797 procedure CollectCityResources( p, cix: integer);798 var 799 CityStorage, CityProjectCost: integer;802 Inc(Flags, chImprovementLost); 803 end; 804 end; 805 end; 806 807 procedure CollectCityResources(P, cix: Integer); 808 var 809 CityStorage, CityProjectCost: Integer; 800 810 CityReport: TCityReportNew; 801 Disorder: boolean;802 begin 803 with RW[ p], City[cix], CityReport do811 Disorder: Boolean; 812 begin 813 with RW[P], City[cix], CityReport do 804 814 if Flags and chCaptured <> 0 then 805 815 begin 806 816 Flags := Flags and not chDisorder; 807 dec(Flags, $10000);817 Dec(Flags, $10000); 808 818 if Flags and chCaptured = 0 then 809 819 Flags := Flags or chAfterCapture; … … 816 826 HypoTaxRate := -1; 817 827 HypoLuxuryRate := -1; 818 GetCityReportNew( p, cix, CityReport);819 CityStorage := StorageSize[Difficulty[ p]];820 CityProjectCost := GetProjectCost( p, cix);828 GetCityReportNew(P, cix, CityReport); 829 CityStorage := StorageSize[Difficulty[P]]; 830 CityProjectCost := GetProjectCost(P, cix); 821 831 822 832 Disorder := (HappinessBalance < 0); … … 830 840 if not Disorder and ((Government = gFuture) or (Size >= NeedAqueductSize) 831 841 and (FoodSurplus < 2)) and (FoodSurplus > 0) then 832 inc(Money, FoodSurplus)842 Inc(Money, FoodSurplus) 833 843 else if not(Disorder and (FoodSurplus > 0)) then 834 844 begin { calculate new food storage } … … 839 849 (Project and (cpImp + cpIndex) <> cpImp + imAqueduct) and 840 850 (Project and (cpImp + cpIndex) <> cpImp + imSewer) and 841 not CanCityGrow( p, cix) then842 inc(Flags, chNoGrowthWarning);851 not CanCityGrow(P, cix) then 852 Inc(Flags, chNoGrowthWarning); 843 853 end; 844 854 845 855 if Prod > CityProjectCost then 846 856 begin 847 inc(Money, Prod - CityProjectCost);848 Prod := CityProjectCost 857 Inc(Money, Prod - CityProjectCost); 858 Prod := CityProjectCost; 849 859 end; 850 860 if Production < 0 then … … 852 862 else if not Disorder and (Flags and chProductionSabotaged = 0) then 853 863 if Project and (cpImp + cpIndex) = cpImp + imTrGoods then 854 inc(Money, Production)864 Inc(Money, Production) 855 865 else 856 inc(Prod, Production);866 Inc(Prod, Production); 857 867 858 868 if not Disorder then 859 869 begin 860 870 { sum research points and taxes } 861 inc(Research, Science);862 inc(Money, Tax);871 Inc(Research, Science); 872 Inc(Money, Tax); 863 873 Pollution := Pollution + AddPollution; 864 874 end; … … 866 876 end; 867 877 868 function CityTurn( p, cix: integer): boolean;878 function CityTurn(P, cix: Integer): Boolean; 869 879 // return value: whether city keeps existing 870 880 var 871 i, uix, cix2, p1, SizeMod, CityStorage, CityProjectCost, NewImp, Det,872 TestDet: integer;873 LackOfMaterial, CheckGrow, DoProd, IsActive: boolean;874 begin 875 with RW[ p], City[cix] do881 I, uix, cix2, p1, SizeMod, CityStorage, CityProjectCost, NewImp, Det, 882 TestDet: Integer; 883 LackOfMaterial, CheckGrow, DoProd, IsActive: Boolean; 884 begin 885 with RW[P], City[cix] do 876 886 begin 877 887 SizeMod := 0; 878 CityStorage := StorageSize[Difficulty[ p]];879 CityProjectCost := GetProjectCost( p, cix);888 CityStorage := StorageSize[Difficulty[P]]; 889 CityProjectCost := GetProjectCost(P, cix); 880 890 881 891 LackOfMaterial := Flags and chUnitLost <> 0; … … 887 897 if CheckGrow and (GTestFlags and tfImmGrow <> 0) then { fast growth } 888 898 begin 889 if CanCityGrow( p, cix) then890 inc(SizeMod)899 if CanCityGrow(P, cix) then 900 Inc(SizeMod); 891 901 end 892 902 else if CheckGrow and (Food >= CityStorage) then { normal growth } 893 903 begin 894 if CanCityGrow( p, cix) then904 if CanCityGrow(P, cix) then 895 905 begin 896 906 if Built[imGranary] = 1 then 897 dec(Food, CityStorage shr 1)907 Dec(Food, CityStorage shr 1) 898 908 else 899 dec(Food, CityStorage);900 inc(SizeMod)901 end 909 Dec(Food, CityStorage); 910 Inc(SizeMod); 911 end; 902 912 end 903 913 else if Food < 0 then { famine } … … 906 916 // check if settlers or conscripts there to disband 907 917 uix := -1; 908 for i:= 0 to nUn - 1 do909 if (Un[ i].Loc >= 0) and (Un[i].Home = cix) and910 ((Model[Un[ i].mix].Kind = mkSettler)918 for I := 0 to nUn - 1 do 919 if (Un[I].Loc >= 0) and (Un[I].Home = cix) and 920 ((Model[Un[I].mix].Kind = mkSettler) 911 921 { and (GWonder[woFreeSettlers].EffectiveOwner<>p) } 912 or (Un[ i].Flags and unConscripts <> 0)) and913 ((uix = -1) or (Model[Un[ i].mix].Cost < Model[Un[uix].mix].Cost) or914 (Model[Un[ i].mix].Cost = Model[Un[uix].mix].Cost) and915 (Un[ i].Exp < Un[uix].Exp)) then916 uix := i;922 or (Un[I].Flags and unConscripts <> 0)) and 923 ((uix = -1) or (Model[Un[I].mix].Cost < Model[Un[uix].mix].Cost) or 924 (Model[Un[I].mix].Cost = Model[Un[uix].mix].Cost) and 925 (Un[I].Exp < Un[uix].Exp)) then 926 uix := I; 917 927 918 928 if uix >= 0 then 919 929 begin 920 RemoveUnit_UpdateMap( p, uix);921 inc(Flags, chUnitLost);930 RemoveUnit_UpdateMap(P, uix); 931 Inc(Flags, chUnitLost); 922 932 end 923 933 else 924 934 begin 925 dec(SizeMod);926 inc(Flags, chPopDecrease)935 Dec(SizeMod); 936 Inc(Flags, chPopDecrease); 927 937 end 928 938 end; … … 936 946 uix := -1; 937 947 Det := MaxInt; 938 for i:= 0 to nUn - 1 do939 if (Un[ i].Loc >= 0) and (Un[i].Home = cix) then940 with Model[Un[ i].mix] do948 for I := 0 to nUn - 1 do 949 if (Un[I].Loc >= 0) and (Un[I].Home = cix) then 950 with Model[Un[I].mix] do 941 951 begin 942 952 if Kind = mkSpecial_TownGuard then 943 TestDet := Un[ i].Health + Un[i].Exp shl 8953 TestDet := Un[I].Health + Un[I].Exp shl 8 944 954 // disband townguards first 945 955 else 946 956 begin 947 TestDet := Un[ i].Health + Un[i].Exp shl 8 + Cost shl 16;957 TestDet := Un[I].Health + Un[I].Exp shl 8 + Cost shl 16; 948 958 // value of unit 949 959 if Flags and mdDoubleSupport <> 0 then … … 953 963 if TestDet < Det then 954 964 begin 955 uix := i;956 Det := TestDet 965 uix := I; 966 Det := TestDet; 957 967 end; 958 968 end; 959 969 if uix >= 0 then 960 970 begin 961 RemoveUnit_UpdateMap( p, uix);962 inc(Flags, chUnitLost);963 end 964 end 971 RemoveUnit_UpdateMap(P, uix); 972 Inc(Flags, chUnitLost); 973 end; 974 end; 965 975 end; 966 976 … … 974 984 (GWonder[Project and cpIndex].CityID <> WonderNotBuiltYet) then 975 985 begin 976 inc(Flags, chOldWonder);977 DoProd := false;986 Inc(Flags, chOldWonder); 987 DoProd := False; 978 988 end; 979 989 … … 985 995 (Project and cpConscripts <> 0))) then 986 996 begin 987 inc(Flags, chNoSettlerProd);988 DoProd := false;997 Inc(Flags, chNoSettlerProd); 998 DoProd := False; 989 999 end; 990 1000 991 1001 if DoProd then 992 1002 begin { project complete } 993 dec(Prod, CityProjectCost);1003 Dec(Prod, CityProjectCost); 994 1004 if Project and cpImp = 0 then { produce unit } 995 1005 begin 996 1006 if nUn < numax then 997 1007 begin 998 CreateUnit( p, Project and cpIndex);1008 CreateUnit(P, Project and cpIndex); 999 1009 Un[nUn - 1].Loc := Loc; 1000 1010 with Un[nUn - 1] do … … 1008 1018 Exp := ExpCost * 2; { vet } 1009 1019 if Project and cpConscripts <> 0 then 1010 Flags := Flags or unConscripts 1020 Flags := Flags or unConscripts; 1011 1021 end; 1012 PlaceUnit( p, nUn - 1);1022 PlaceUnit(P, nUn - 1); 1013 1023 UpdateUnitMap(Loc); 1014 1024 if Model[Project and cpIndex].Kind = mkSettler then 1015 dec(SizeMod, 2) { settler produced - city shrink }1025 Dec(SizeMod, 2) { settler produced - city shrink } 1016 1026 else if (Model[Project and cpIndex].Kind = mkSlaves) or 1017 1027 (Project and cpConscripts <> 0) then 1018 dec(SizeMod); { slaves/conscripts produced - city shrink }1028 Dec(SizeMod); { slaves/conscripts produced - city shrink } 1019 1029 end; 1020 1030 Project0 := Project or cpRepeat or cpCompleted; … … 1022 1032 else if Imp[Project and cpIndex].Kind = ikShipPart then 1023 1033 begin { produce ship parts } 1024 inc(GShip[p].Parts[Project and cpIndex - imShipComp]);1034 Inc(GShip[P].Parts[Project and cpIndex - imShipComp]); 1025 1035 Project0 := Project or cpCompleted; 1026 1036 end … … 1028 1038 begin 1029 1039 NewImp := Project and cpIndex; 1030 inc(Money, Prod); { change rest to money }1040 Inc(Money, Prod); { change rest to money } 1031 1041 Project0 := Project or cpCompleted; 1032 1042 Project := cpImp + imTrGoods; … … 1035 1045 if Imp[NewImp].Kind in [ikNatLocal, ikNatGlobal] then 1036 1046 begin // nat. project 1037 for i:= 0 to nCity - 1 do1038 if (City[ i].Loc >= 0) and (City[i].Built[NewImp] = 1) then1047 for I := 0 to nCity - 1 do 1048 if (City[I].Loc >= 0) and (City[I].Built[NewImp] = 1) then 1039 1049 begin { allowed only once } 1040 inc(Money, Imp[NewImp].Cost * BuildCostMod[Difficulty[p]] div 12);1041 City[ i].Built[NewImp] := 0;1050 Inc(Money, Imp[NewImp].Cost * BuildCostMod[Difficulty[P]] div 12); 1051 City[I].Built[NewImp] := 0; 1042 1052 end; 1043 1053 NatBuilt[NewImp] := 1; … … 1046 1056 case NewImp of 1047 1057 imGrWall: 1048 GrWallContinent[ p] := Continent[Loc];1058 GrWallContinent[P] := Continent[Loc]; 1049 1059 end; 1050 1060 end; … … 1053 1063 begin // wonder 1054 1064 GWonder[NewImp].CityID := ID; 1055 GWonder[NewImp].EffectiveOwner := p;1065 GWonder[NewImp].EffectiveOwner := P; 1056 1066 CheckExpiration(NewImp); 1057 1067 … … 1060 1070 woEiffel: 1061 1071 begin // reactivate wonders 1062 for i:= 0 to nWonder - 1 do1063 if Imp[ i].Expiration >= 0 then1072 for I := 0 to nWonder - 1 do 1073 if Imp[I].Expiration >= 0 then 1064 1074 for cix2 := 0 to nCity - 1 do 1065 if (City[cix2].Loc >= 0) and (City[cix2].Built[ i] = 1)1075 if (City[cix2].Loc >= 0) and (City[cix2].Built[I] = 1) 1066 1076 then 1067 GWonder[ i].EffectiveOwner := p1077 GWonder[I].EffectiveOwner := P; 1068 1078 end; 1069 1079 woLighthouse: 1070 CheckSpecialModels( p, preLighthouse);1080 CheckSpecialModels(P, preLighthouse); 1071 1081 woLeo: 1072 1082 begin 1073 inc(Research, TechBaseCost(nTech[p], Difficulty[p]) +1074 TechBaseCost(nTech[ p] + 2, Difficulty[p]));1075 CheckSpecialModels( p, preLeo);1083 Inc(Research, TechBaseCost(nTech[P], Difficulty[P]) + 1084 TechBaseCost(nTech[P] + 2, Difficulty[P])); 1085 CheckSpecialModels(P, preLeo); 1076 1086 end; 1077 1087 woPyramids: 1078 CheckSpecialModels( p, preBuilder);1088 CheckSpecialModels(P, preBuilder); 1079 1089 woMir: 1080 1090 begin 1081 1091 for p1 := 0 to nPl - 1 do 1082 if (p1 <> p) and (1 shl p1 and GAlive <> 0) then1092 if (p1 <> P) and (1 shl p1 and GAlive <> 0) then 1083 1093 begin 1084 if RW[ p].Treaty[p1] = trNoContact then1085 IntroduceEnemy( p, p1);1086 GiveCivilReport( p, p1);1087 GiveMilReport( p, p1)1094 if RW[P].Treaty[p1] = trNoContact then 1095 IntroduceEnemy(P, p1); 1096 GiveCivilReport(P, p1); 1097 GiveMilReport(P, p1); 1088 1098 end; 1089 end 1099 end; 1090 1100 end; 1091 1101 end; 1092 1102 1093 for i:= 0 to nImpReplacement - 1 do // sell obsolete buildings1094 if (ImpReplacement[ i].NewImp = NewImp) and1095 (Built[ImpReplacement[ i].OldImp] > 0) then1103 for I := 0 to nImpReplacement - 1 do // sell obsolete buildings 1104 if (ImpReplacement[I].NewImp = NewImp) and 1105 (Built[ImpReplacement[I].OldImp] > 0) then 1096 1106 begin 1097 inc(RW[p].Money, Imp[ImpReplacement[i].OldImp].Cost * BuildCostMod1098 [Difficulty[ p]] div 12);1099 Built[ImpReplacement[ i].OldImp] := 0;1107 Inc(RW[P].Money, Imp[ImpReplacement[I].OldImp].Cost * BuildCostMod 1108 [Difficulty[P]] div 12); 1109 Built[ImpReplacement[I].OldImp] := 0; 1100 1110 end; 1101 1111 1102 1112 if NewImp in [imPower, imHydro, imNuclear] then 1103 for i:= 0 to nImp - 1 do1104 if ( i <> NewImp) and (iin [imPower, imHydro, imNuclear]) and1105 (Built[ i] > 0) then1113 for I := 0 to nImp - 1 do 1114 if (I <> NewImp) and (I in [imPower, imHydro, imNuclear]) and 1115 (Built[I] > 0) then 1106 1116 begin // sell obsolete power plant 1107 inc(RW[p].Money, Imp[i].Cost * BuildCostMod[Difficulty[p]1117 Inc(RW[P].Money, Imp[I].Cost * BuildCostMod[Difficulty[P] 1108 1118 ] div 12); 1109 Built[ i] := 0;1119 Built[I] := 0; 1110 1120 end; 1111 1121 … … 1113 1123 end; 1114 1124 Prod0 := Prod; 1115 inc(Flags, chProduction)1125 Inc(Flags, chProduction); 1116 1126 end 1117 1127 else … … 1125 1135 if SizeMod > 0 then 1126 1136 begin 1127 CityGrowth( p, cix);1128 inc(Flags, chPopIncrease);1129 end; 1130 result := Size + SizeMod >= 2;1131 if result then1137 CityGrowth(P, cix); 1138 Inc(Flags, chPopIncrease); 1139 end; 1140 Result := Size + SizeMod >= 2; 1141 if Result then 1132 1142 while SizeMod < 0 do 1133 1143 begin 1134 CityShrink( p, cix);1135 inc(SizeMod)1136 end; 1137 end 1138 end; // CityTurn1144 CityShrink(P, cix); 1145 Inc(SizeMod); 1146 end; 1147 end; 1148 end; 1139 1149 1140 1150 { … … 1142 1152 ____________________________________________________________________ 1143 1153 } 1144 function SetCityTiles( p, cix, NewTiles: integer;1145 TestOnly: boolean = false): integer;1146 var 1147 V21, Working, ChangeTiles, AddTiles, Loc1: integer;1154 function SetCityTiles(P, cix, NewTiles: Integer; 1155 TestOnly: Boolean = False): Integer; 1156 var 1157 V21, Working, ChangeTiles, AddTiles, Loc1: Integer; 1148 1158 CityAreaInfo: TCityAreaInfo; 1149 1159 Radius: TVicinity21Loc; 1150 1160 begin 1151 with RW[ p].City[cix] do1161 with RW[P].City[cix] do 1152 1162 begin 1153 ChangeTiles := NewTiles xor integer(Tiles);1163 ChangeTiles := NewTiles xor Integer(Tiles); 1154 1164 AddTiles := NewTiles and not Tiles; 1155 1165 if Mode = moPlaying then … … 1157 1167 if NewTiles and not $67F7F76 <> 0 then 1158 1168 begin 1159 result := eInvalid;1160 exit1169 Result := eInvalid; 1170 Exit 1161 1171 end; // invalid tile index included 1162 1172 if NewTiles and (1 shl 13) = 0 then 1163 1173 begin 1164 result := eViolation;1165 exit1174 Result := eViolation; 1175 Exit 1166 1176 end; // city tile must be exploited 1167 1177 if ChangeTiles = 0 then 1168 1178 begin 1169 result := eNotChanged;1170 exit1179 Result := eNotChanged; 1180 Exit 1171 1181 end; 1172 1182 if AddTiles <> 0 then 1173 1183 begin 1174 1184 // check if new tiles possible 1175 GetCityAreaInfo( p, Loc, CityAreaInfo);1185 GetCityAreaInfo(P, Loc, CityAreaInfo); 1176 1186 for V21 := 1 to 26 do 1177 1187 if AddTiles and (1 shl V21) <> 0 then 1178 1188 if CityAreaInfo.Available[V21] <> faAvailable then 1179 1189 begin 1180 result := eTileNotAvailable;1181 exit1190 Result := eTileNotAvailable; 1191 Exit; 1182 1192 end; 1183 1193 // not more tiles than inhabitants … … 1185 1195 for V21 := 1 to 26 do 1186 1196 if NewTiles and (1 shl V21) <> 0 then 1187 inc(Working);1197 Inc(Working); 1188 1198 if Working > Size then 1189 1199 begin 1190 result := eNoWorkerAvailable;1191 exit1192 end; 1193 end; 1194 end; 1195 result := eOk;1200 Result := eNoWorkerAvailable; 1201 Exit; 1202 end; 1203 end; 1204 end; 1205 Result := eOk; 1196 1206 if not TestOnly then 1197 1207 begin … … 1201 1211 begin 1202 1212 Loc1 := Radius[V21]; 1203 assert((Loc1 >= 0) and (Loc1 < MapSize));1213 Assert((Loc1 >= 0) and (Loc1 < MapSize)); 1204 1214 if NewTiles and (1 shl V21) <> 0 then 1205 1215 UsedByCity[Loc1] := Loc // employ tile 1206 1216 else if UsedByCity[Loc1] <> Loc then 1207 assert(Mode < moPlaying)1217 Assert(Mode < moPlaying) 1208 1218 // should only happen during loading, because of wrong sSetCityTiles command order 1209 1219 else 1210 UsedByCity[Loc1] := -1 // unemploy tile1211 end; 1212 Tiles := NewTiles 1213 end 1214 end; 1215 end; 1216 1217 procedure GetCityTileAdvice( p, cix: integer; var Advice: TCityTileAdviceData);1220 UsedByCity[Loc1] := -1; // unemploy tile 1221 end; 1222 Tiles := NewTiles; 1223 end; 1224 end; 1225 end; 1226 1227 procedure GetCityTileAdvice(P, cix: Integer; var Advice: TCityTileAdviceData); 1218 1228 const 1219 1229 oFood = 0; … … 1223 1233 type 1224 1234 TTileData = record 1225 Food, Prod, Trade, SubValue, V21: integer; 1226 end; 1227 var 1228 i, V21, Loc1, nHierarchy, iH, iT, iH_Switch, MinWorking, MaxWorking, 1235 Food: Integer; 1236 Prod: Integer; 1237 Trade: Integer; 1238 SubValue: Integer; 1239 V21: Integer; 1240 end; 1241 var 1242 I, V21, Loc1, nHierarchy, iH, iT, iH_Switch, MinWorking, MaxWorking, 1229 1243 WantedProd, MinFood, MinProd, count, Take, MaxTake, AreaSize, FormulaCode, 1230 1244 NeedRare, RareTiles, cix1, dx, dy, BestTiles, ProdBeforeBoost, TestTiles, 1231 SubPlus, SuperPlus: integer;1232 SuperValue, BestSuperValue, SubValue, BestSubValue: integer;1233 Value, BestValue, ValuePlus: extended;1234 ValueFormula_Weight: array [oFood .. oScience] of extended;1235 ValueFormula_Multiply: array [oFood .. oScience] of boolean;1236 Output: array [oFood .. oScience] of integer;1245 SubPlus, SuperPlus: Integer; 1246 SuperValue, BestSuperValue, SubValue, BestSubValue: Integer; 1247 Value, BestValue, ValuePlus: Extended; 1248 ValueFormula_Weight: array [oFood .. oScience] of Extended; 1249 ValueFormula_Multiply: array [oFood .. oScience] of Boolean; 1250 Output: array [oFood .. oScience] of Integer; 1237 1251 TileInfo, BaseTileInfo: TTileInfo; 1238 1252 Radius, Radius1: TVicinity21Loc; … … 1241 1255 CityAreaInfo: TCityAreaInfo; 1242 1256 Hierarchy: array [0 .. 20, 0 .. 31] of TTileData; 1243 nTile, nSelection: array [0 .. 20] of integer;1244 SubCriterion: array [0 .. 27] of integer;1245 FoodWasted, FoodToTax, ProdToTax, RareOK, NeedStep2, IsBest: boolean;1246 begin 1247 if (RW[ p].Government = gAnarchy) or (RW[p].City[cix].Flags and chCaptured <> 0)1257 nTile, nSelection: array [0 .. 20] of Integer; 1258 SubCriterion: array [0 .. 27] of Integer; 1259 FoodWasted, FoodToTax, ProdToTax, RareOK, NeedStep2, IsBest: Boolean; 1260 begin 1261 if (RW[P].Government = gAnarchy) or (RW[P].City[cix].Flags and chCaptured <> 0) 1248 1262 then 1249 1263 begin … … 1251 1265 Advice.Tiles := 1 shl CityOwnTile; 1252 1266 Advice.CityReport.HypoTiles := 1 shl CityOwnTile; 1253 exit;1254 end; 1255 1256 for i:= oFood to oScience do1267 Exit; 1268 end; 1269 1270 for I := oFood to oScience do 1257 1271 begin // decode evaluation formula from weights parameter 1258 FormulaCode := Advice.ResourceWeights shr (24 - 8 * i) and $FF;1259 ValueFormula_Multiply[ i] := FormulaCode and $80 <> 0;1272 FormulaCode := Advice.ResourceWeights shr (24 - 8 * I) and $FF; 1273 ValueFormula_Multiply[I] := FormulaCode and $80 <> 0; 1260 1274 if FormulaCode and $40 <> 0 then 1261 ValueFormula_Weight[ i] := (FormulaCode and $0F) *1275 ValueFormula_Weight[I] := (FormulaCode and $0F) * 1262 1276 (1 shl (FormulaCode and $30 shr 4)) / 16 1263 1277 else 1264 ValueFormula_Weight[ i] := (FormulaCode and $0F) *1278 ValueFormula_Weight[I] := (FormulaCode and $0F) * 1265 1279 (1 shl (FormulaCode and $30 shr 4)); 1266 1280 end; … … 1269 1283 TestReport.HypoTax := -1; 1270 1284 TestReport.HypoLux := -1; 1271 GetSmallCityReport( p, cix, TestReport, @CityReportEx);1272 with RW[ p].City[cix] do1285 GetSmallCityReport(P, cix, TestReport, @CityReportEx); 1286 with RW[P].City[cix] do 1273 1287 begin 1274 1288 V21_to_Loc(Loc, Radius); 1275 FoodToTax := RW[ p].Government = gFuture;1289 FoodToTax := RW[P].Government = gFuture; 1276 1290 ProdToTax := Project and (cpImp + cpIndex) = cpImp + imTrGoods; 1277 FoodWasted := not FoodToTax and (Food = StorageSize[Difficulty[ p]]) and1278 not CanCityGrow( p, cix);1291 FoodWasted := not FoodToTax and (Food = StorageSize[Difficulty[P]]) and 1292 not CanCityGrow(P, cix); 1279 1293 1280 1294 // sub criteria … … 1286 1300 V21 xor $15; 1287 1301 end; 1288 for cix1 := 0 to RW[ p].nCity - 1 do1302 for cix1 := 0 to RW[P].nCity - 1 do 1289 1303 if cix1 <> cix then 1290 1304 begin 1291 Loc1 := RW[ p].City[cix1].Loc;1305 Loc1 := RW[P].City[cix1].Loc; 1292 1306 if Loc1 >= 0 then 1293 1307 begin … … 1302 1316 begin 1303 1317 dxdy(Loc, Loc1, dx, dy); 1304 dec(SubCriterion[(dy + 3) shl 2 + (dx + 3) shr 1], 160);1318 Dec(SubCriterion[(dy + 3) shl 2 + (dx + 3) shr 1], 160); 1305 1319 end; 1306 1320 end; … … 1309 1323 end; 1310 1324 1311 GetCityAreaInfo( p, Loc, CityAreaInfo);1325 GetCityAreaInfo(P, Loc, CityAreaInfo); 1312 1326 AreaSize := 0; 1313 1327 for V21 := 1 to 26 do 1314 1328 if CityAreaInfo.Available[V21] = faAvailable then 1315 inc(AreaSize);1316 1317 if RW[ p].Government = gFundamentalism then1329 Inc(AreaSize); 1330 1331 if RW[P].Government = gFundamentalism then 1318 1332 begin 1319 1333 MinWorking := Size; … … 1325 1339 if MinWorking > Size then 1326 1340 MinWorking := Size; 1327 if (RW[ p].LuxRate = 0) and not CityReportEx.TradeProcessing.FlexibleLuxury1341 if (RW[P].LuxRate = 0) and not CityReportEx.TradeProcessing.FlexibleLuxury 1328 1342 then 1329 1343 MaxWorking := MinWorking … … 1362 1376 Loc1 := Radius[V21]; 1363 1377 if (Loc1 >= 0) and (Loc1 < MapSize) and 1364 (RealMap[Loc1] and fModern = cardinal(NeedRare)) then1378 (RealMap[Loc1] and fModern = Cardinal(NeedRare)) then 1365 1379 RareTiles := RareTiles or (1 shl V21); 1366 end 1380 end; 1367 1381 end; 1368 1382 … … 1374 1388 begin 1375 1389 Loc1 := Radius[V21]; 1376 assert((Loc1 >= 0) and (Loc1 < MapSize));1377 GetTileInfo( p, cix, Loc1, TileInfo);1390 Assert((Loc1 >= 0) and (Loc1 < MapSize)); 1391 GetTileInfo(P, cix, Loc1, TileInfo); 1378 1392 if V21 = CityOwnTile then 1379 1393 BaseTileInfo := TileInfo … … 1391 1405 (TileInfo.Trade = Hierarchy[iH, iT].Trade) and 1392 1406 (SubCriterion[V21] >= SubCriterion[Hierarchy[iH, iT].V21])) do 1393 inc(iT);1407 Inc(iT); 1394 1408 if (iT = nTile[iH]) // new worst tile in this hierarchy 1395 1409 or ((TileInfo.Food >= Hierarchy[iH, iT].Food) … … 1397 1411 and (TileInfo.Prod >= Hierarchy[iH, iT].Prod) and 1398 1412 (TileInfo.Trade >= Hierarchy[iH, iT].Trade)) then 1399 break; // insert position found!1400 inc(iH);1413 Break; // insert position found! 1414 Inc(iH); 1401 1415 end; 1402 1416 if iH = nHierarchy then 1403 1417 begin // need to start new hierarchy 1404 1418 nTile[iH] := 0; 1405 inc(nHierarchy);1419 Inc(nHierarchy); 1406 1420 iT := 0; 1407 1421 end; 1408 move(Hierarchy[iH, iT], Hierarchy[iH, iT + 1],1422 Move(Hierarchy[iH, iT], Hierarchy[iH, iT + 1], 1409 1423 (nTile[iH] - iT) * SizeOf(TTileData)); 1410 inc(nTile[iH]);1424 Inc(nTile[iH]); 1411 1425 Hierarchy[iH, iT].V21 := V21; 1412 1426 Hierarchy[iH, iT].Food := TileInfo.Food; … … 1424 1438 begin 1425 1439 Loc1 := Radius[V21]; 1426 assert((V21 <> CityOwnTile) and (Loc1 >= 0) and (Loc1 < MapSize));1427 GetTileInfo( p, cix, Loc1, TileInfo);1440 Assert((V21 <> CityOwnTile) and (Loc1 >= 0) and (Loc1 < MapSize)); 1441 GetTileInfo(P, cix, Loc1, TileInfo); 1428 1442 if iH = nHierarchy then 1429 1443 begin // need to start new hierarchy 1430 1444 nTile[iH] := 0; 1431 inc(nHierarchy);1445 Inc(nHierarchy); 1432 1446 iT := 0; 1433 1447 end 1434 1448 else 1435 1449 iT := nTile[iH]; 1436 inc(nTile[iH]);1450 Inc(nTile[iH]); 1437 1451 Hierarchy[iH, iT].V21 := V21; 1438 1452 Hierarchy[iH, iT].Food := TileInfo.Food; // = 0 … … 1443 1457 end; 1444 1458 if Built[imAlgae] > 0 then 1445 inc(BaseTileInfo.Food, 12);1459 Inc(BaseTileInfo.Food, 12); 1446 1460 1447 1461 // step 2: summarize resources 1448 1462 for iH := 0 to nHierarchy - 1 do 1449 1463 begin 1450 move(Hierarchy[iH, 0], Hierarchy[iH, 1], nTile[iH] * SizeOf(TTileData));1464 Move(Hierarchy[iH, 0], Hierarchy[iH, 1], nTile[iH] * SizeOf(TTileData)); 1451 1465 Hierarchy[iH, 0].Food := 0; 1452 1466 Hierarchy[iH, 0].Prod := 0; … … 1456 1470 for iT := 1 to nTile[iH] do 1457 1471 begin 1458 inc(Hierarchy[iH, iT].Food, Hierarchy[iH, iT - 1].Food);1459 inc(Hierarchy[iH, iT].Prod, Hierarchy[iH, iT - 1].Prod);1460 inc(Hierarchy[iH, iT].Trade, Hierarchy[iH, iT - 1].Trade);1461 inc(Hierarchy[iH, iT].SubValue, Hierarchy[iH, iT - 1].SubValue);1472 Inc(Hierarchy[iH, iT].Food, Hierarchy[iH, iT - 1].Food); 1473 Inc(Hierarchy[iH, iT].Prod, Hierarchy[iH, iT - 1].Prod); 1474 Inc(Hierarchy[iH, iT].Trade, Hierarchy[iH, iT - 1].Trade); 1475 Inc(Hierarchy[iH, iT].SubValue, Hierarchy[iH, iT - 1].SubValue); 1462 1476 Hierarchy[iH, iT].V21 := 1 shl Hierarchy[iH, iT].V21 + 1463 1477 Hierarchy[iH, iT - 1].V21; … … 1487 1501 (ProdBeforeBoost < WantedProd)) do 1488 1502 begin 1489 assert(nSelection[iH] = 0);1503 Assert(nSelection[iH] = 0); 1490 1504 Take := MinWorking - TestReport.Working; 1491 1505 if Take > nTile[iH] then … … 1500 1514 while (Take < MaxTake) and 1501 1515 (TestReport.FoodRep + Hierarchy[iH, Take].Food < MinFood) do 1502 inc(Take);1516 Inc(Take); 1503 1517 while (Take < MaxTake) and 1504 1518 (ProdBeforeBoost + Hierarchy[iH, Take].Prod < MinProd) do 1505 inc(Take);1519 Inc(Take); 1506 1520 end; 1507 1521 nSelection[iH] := Take; 1508 inc(TestReport.Working, Take);1522 Inc(TestReport.Working, Take); 1509 1523 with Hierarchy[iH, Take] do 1510 1524 begin 1511 inc(TestReport.FoodRep, Food);1512 inc(ProdBeforeBoost, Prod);1513 inc(TestReport.Trade, Trade);1514 end; 1515 inc(iH);1516 end; 1517 1518 assert((TestReport.Working >= MinWorking) and1525 Inc(TestReport.FoodRep, Food); 1526 Inc(ProdBeforeBoost, Prod); 1527 Inc(TestReport.Trade, Trade); 1528 end; 1529 Inc(iH); 1530 end; 1531 1532 Assert((TestReport.Working >= MinWorking) and 1519 1533 (TestReport.Working <= MaxWorking)); 1520 1534 if (TestReport.FoodRep >= MinFood) and (ProdBeforeBoost >= MinProd) then 1521 1535 begin 1522 SplitTrade(TestReport.Trade, RW[ p].TaxRate, RW[p].LuxRate,1536 SplitTrade(TestReport.Trade, RW[P].TaxRate, RW[P].LuxRate, 1523 1537 TestReport.Working, CityReportEx.TradeProcessing, 1524 1538 TestReport.Corruption, TestReport.Tax, TestReport.Lux, … … 1529 1543 TestReport.Deployed >= Size then 1530 1544 begin // city is not in disorder -- evaluate combination 1531 inc(count);1545 Inc(count); 1532 1546 if (MinProd < WantedProd) and (ProdBeforeBoost > MinProd) then 1533 1547 begin // no combination reached wanted prod yet … … 1577 1591 then 1578 1592 begin 1579 inc(Output[oTax], Output[oFood]);1593 Inc(Output[oTax], Output[oFood]); 1580 1594 Output[oFood] := 0; 1581 1595 end; … … 1589 1603 if NeedRare > 0 then 1590 1604 begin 1591 RareOK := false;1605 RareOK := False; 1592 1606 for iH := 0 to nHierarchy - 1 do 1593 1607 if Hierarchy[iH, nSelection[iH]].V21 and RareTiles <> 0 then 1594 RareOK := true;1608 RareOK := True; 1595 1609 if not RareOK then 1596 1610 TestReport.ProdRep := TestReport.Support; … … 1599 1613 if ProdToTax then 1600 1614 begin 1601 inc(Output[oTax], Output[oProd]);1615 Inc(Output[oTax], Output[oProd]); 1602 1616 Output[oProd] := 0; 1603 1617 end; 1604 1618 end; 1605 1619 1606 NeedStep2 := false;1620 NeedStep2 := False; 1607 1621 Value := 0; 1608 for i:= oFood to oScience do1609 if ValueFormula_Multiply[ i] then1610 NeedStep2 := true1622 for I := oFood to oScience do 1623 if ValueFormula_Multiply[I] then 1624 NeedStep2 := True 1611 1625 else 1612 Value := Value + ValueFormula_Weight[ i] * Output[i];1626 Value := Value + ValueFormula_Weight[I] * Output[I]; 1613 1627 if NeedStep2 then 1614 1628 begin 1615 1629 if Value > 0 then 1616 1630 Value := ln(Value) + 123; 1617 for i:= oFood to oScience do1618 if ValueFormula_Multiply[ i] and (Output[i] > 0) then1619 Value := Value + ValueFormula_Weight[ i] *1620 (ln(Output[ i]) + 123);1631 for I := oFood to oScience do 1632 if ValueFormula_Multiply[I] and (Output[I] > 0) then 1633 Value := Value + ValueFormula_Weight[I] * 1634 (ln(Output[I]) + 123); 1621 1635 end; 1622 1636 … … 1629 1643 for iH := 0 to nHierarchy - 1 do 1630 1644 begin 1631 inc(TestTiles, Hierarchy[iH, nSelection[iH]].V21);1632 inc(SubValue, Hierarchy[iH, nSelection[iH]].SubValue);1645 Inc(TestTiles, Hierarchy[iH, nSelection[iH]].V21); 1646 Inc(SubValue, Hierarchy[iH, nSelection[iH]].SubValue); 1633 1647 end; 1634 IsBest := true;1648 IsBest := True; 1635 1649 if (SuperPlus = 0) and (ValuePlus = 0.0) then 1636 1650 begin 1637 1651 SubPlus := SubValue - BestSubValue; 1638 1652 if SubPlus < 0 then 1639 IsBest := false1653 IsBest := False 1640 1654 else if SubPlus = 0 then 1641 1655 begin 1642 assert(TestTiles <> BestTiles);1656 Assert(TestTiles <> BestTiles); 1643 1657 IsBest := TestTiles > BestTiles 1644 1658 end … … 1654 1668 TestReport.Lux shr 1; 1655 1669 Advice.CityReport := TestReport; 1656 end 1657 end // if (SuperPlus>0) or (ValuePlus>=0.0)1658 end // if SuperPlus>=01659 end 1670 end; 1671 end; // if (SuperPlus>0) or (ValuePlus>=0.0) 1672 end; // if SuperPlus>=0 1673 end; 1660 1674 end; 1661 1675 … … 1665 1679 with Hierarchy[iH_Switch, nSelection[iH_Switch]] do 1666 1680 begin 1667 dec(TestReport.FoodRep, Food);1668 dec(ProdBeforeBoost, Prod);1669 dec(TestReport.Trade, Trade);1670 end; 1671 inc(nSelection[iH_Switch]);1672 inc(TestReport.Working);1681 Dec(TestReport.FoodRep, Food); 1682 Dec(ProdBeforeBoost, Prod); 1683 Dec(TestReport.Trade, Trade); 1684 end; 1685 Inc(nSelection[iH_Switch]); 1686 Inc(TestReport.Working); 1673 1687 if (nSelection[iH_Switch] <= nTile[iH_Switch]) and 1674 1688 (TestReport.Working <= MaxWorking) then … … 1676 1690 with Hierarchy[iH_Switch, nSelection[iH_Switch]] do 1677 1691 begin 1678 inc(TestReport.FoodRep, Food);1679 inc(ProdBeforeBoost, Prod);1680 inc(TestReport.Trade, Trade);1692 Inc(TestReport.FoodRep, Food); 1693 Inc(ProdBeforeBoost, Prod); 1694 Inc(TestReport.Trade, Trade); 1681 1695 end; 1682 break;1683 end; 1684 dec(TestReport.Working, nSelection[iH_Switch]);1696 Break; 1697 end; 1698 Dec(TestReport.Working, nSelection[iH_Switch]); 1685 1699 nSelection[iH_Switch] := 0; 1686 inc(iH_Switch);1700 Inc(iH_Switch); 1687 1701 until iH_Switch = nHierarchy; 1688 1702 until iH_Switch = nHierarchy; // everything tested -- done 1689 1703 end; 1690 assert(BestSuperValue > 0); // advice should always be possible1704 Assert(BestSuperValue > 0); // advice should always be possible 1691 1705 Advice.Tiles := BestTiles; 1692 1706 Advice.CityReport.HypoTiles := BestTiles; 1693 end; // GetCityTileAdvice1707 end; 1694 1708 1695 1709 { … … 1699 1713 procedure InitGame; 1700 1714 var 1701 p, i, mixTownGuard: integer;1715 P, I, mixTownGuard: Integer; 1702 1716 begin 1703 1717 MaxDist := Distance(0, MapSize - lx shr 1); 1704 for p:= 0 to nPl - 1 do1705 if (1 shl pand GAlive <> 0) then1706 with RW[ p] do1718 for P := 0 to nPl - 1 do 1719 if (1 shl P and GAlive <> 0) then 1720 with RW[P] do 1707 1721 begin // initialize capital 1708 1722 mixTownGuard := 0; 1709 1723 while Model[mixTownGuard].Kind <> mkSpecial_TownGuard do 1710 inc(mixTownGuard);1724 Inc(mixTownGuard); 1711 1725 with City[0] do 1712 1726 begin 1713 1727 Built[imPalace] := 1; 1714 1728 Size := 4; 1715 for i:= 2 to Size do1716 AddBestCityTile( p, 0);1729 for I := 2 to Size do 1730 AddBestCityTile(P, 0); 1717 1731 Project := mixTownGuard; 1718 1732 end;
Note:
See TracChangeset
for help on using the changeset viewer.