Changeset 465 for branches/highdpi/AI/StdAI/AI.pas
- Timestamp:
- Nov 30, 2023, 10:16:14 PM (12 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/highdpi/AI/StdAI/AI.pas
r349 r465 23 23 24 24 nResearchOrder = 46; 25 ResearchOrder: array[0..1, 0..nResearchOrder - 1] of integer =25 ResearchOrder: array[0..1, 0..nResearchOrder - 1] of Integer = 26 26 ((adWheel, adWarriorCode, adHorsebackRiding, adCeremonialBurial, adPolytheism, 27 27 adMonarchy, adMysticism, adPoetry, adAstronomy, adMonotheism, … … 76 76 77 77 // mil research 78 BetterQuality: array[0..nModelCat - 1] of integer = (50, 50, 80, 80);78 BetterQuality: array[0..nModelCat - 1] of Integer = (50, 50, 80, 80); 79 79 MaxBuildWorseThanBestModel = 20; 80 80 MaxExistWorseThanBestModel = 50; … … 85 85 nRequestedTechs = 48; 86 86 87 PlayerHash: array[0..nPl - 1] of integer =87 PlayerHash: array[0..nPl - 1] of Integer = 88 88 (7, 6, 0, 2, 10, 8, 12, 14, 4, 1, 3, 5, 9, 11, 13); 89 89 … … 92 92 93 93 TPersistentData = record 94 LastResearchTech, BehaviorFlags, TheologyPartner: integer;94 LastResearchTech, BehaviorFlags, TheologyPartner: Integer; 95 95 RejectTurn: array[Suggestion, 0..15] of smallint; 96 RequestedTechs: array[0..nRequestedTechs - 1] of integer;96 RequestedTechs: array[0..nRequestedTechs - 1] of Integer; 97 97 // ad + p shl 8 + Turn shl 16 98 98 end; 99 99 100 100 TAI = class(TBarbarina) 101 constructor Create(Nation: integer); override;101 constructor Create(Nation: Integer); override; 102 102 103 103 procedure SetDataDefaults; override; … … 106 106 Data: ^TPersistentData; 107 107 WarNations, BombardingNations, mixSettlers, mixCaravan, mixTownGuard, 108 mixSlaves, mixMilitia, mixCruiser, OceanWithShip: integer;108 mixSlaves, mixMilitia, mixCruiser, OceanWithShip: Integer; 109 109 NegoCause: (Routine, CheckBarbarina); 110 SettlerSurplus: array[0..maxCOD - 1] of integer;111 uixPatrol: array[0..maxCOD - 1] of integer;112 113 ContinentPresence: array[0..maxCOD - 1] of integer;114 OceanPresence: array[0..maxCOD - 1] of integer;115 UnitLack: array[0..maxCOD - 1, mctGroundDefender..mctGroundAttacker] of integer;116 117 TotalPopulation: array[0..nPl - 1] of integer;118 ContinentPopulation: array[0..nPl - 1, 0..maxCOD - 1] of integer;110 SettlerSurplus: array[0..maxCOD - 1] of Integer; 111 uixPatrol: array[0..maxCOD - 1] of Integer; 112 113 ContinentPresence: array[0..maxCOD - 1] of Integer; 114 OceanPresence: array[0..maxCOD - 1] of Integer; 115 UnitLack: array[0..maxCOD - 1, mctGroundDefender..mctGroundAttacker] of Integer; 116 117 TotalPopulation: array[0..nPl - 1] of Integer; 118 ContinentPopulation: array[0..nPl - 1, 0..maxCOD - 1] of Integer; 119 119 // 1 means enemy territory spotted but no city 120 DistrictPopulation: array[0..maxCOD - 1] of integer;121 122 ModelCat: array[0..nMmax - 1] of integer;123 ModelQuality: array[0..nMmax - 1] of integer;124 ModelBestQuality: array[0..nModelCat - 1] of integer;125 126 AdvanceValue: array[0..nAdv - 1] of integer;127 AdvanceValuesSet: boolean;120 DistrictPopulation: array[0..maxCOD - 1] of Integer; 121 122 ModelCat: array[0..nMmax - 1] of Integer; 123 ModelQuality: array[0..nMmax - 1] of Integer; 124 ModelBestQuality: array[0..nModelCat - 1] of Integer; 125 126 AdvanceValue: array[0..nAdv - 1] of Integer; 127 AdvanceValuesSet: Boolean; 128 128 129 129 procedure DoTurn; override; 130 130 procedure DoNegotiation; override; 131 function ChooseResearchAdvance: integer; override;132 function ChooseStealAdvance: integer; override;133 function ChooseGovernment: integer; override;134 function WantNegotiation(Nation: integer; NegoTime: TNegoTime): boolean; override;135 function OnNegoRejected_CancelTreaty: boolean; override;136 137 procedure FindBestTrade(Nation: integer; var adWanted, adGiveAway: integer);131 function ChooseResearchAdvance: Integer; override; 132 function ChooseStealAdvance: Integer; override; 133 function ChooseGovernment: Integer; override; 134 function WantNegotiation(Nation: Integer; NegoTime: TNegoTime): Boolean; override; 135 function OnNegoRejected_CancelTreaty: Boolean; override; 136 137 procedure FindBestTrade(Nation: Integer; var adWanted, adGiveAway: Integer); 138 138 procedure CheckGender; 139 139 procedure AnalyzeMap; … … 141 141 procedure AttackAndPatrol; 142 142 procedure MoveUnitsHome; 143 procedure CheckAttack(uix: integer);144 procedure Patrol(uix: integer);143 procedure CheckAttack(uix: Integer); 144 procedure Patrol(uix: Integer); 145 145 procedure SetCityProduction; 146 146 procedure SetAdvanceValues; 147 function HavePort: boolean;148 {$IFDEF DEBUG}procedure TraceAdvanceValues(Nation: integer);{$ENDIF}147 function HavePort: Boolean; 148 {$IFDEF DEBUG}procedure TraceAdvanceValues(Nation: Integer);{$ENDIF} 149 149 150 150 // research 151 procedure RateModel(const mi: TModelInfo; var Category, Quality: integer);152 procedure RateMyModel(mix: integer; var Category, Quality: integer);153 function IsBetterModel(const mi: TModelInfo): boolean;151 procedure RateModel(const mi: TModelInfo; var Category, Quality: Integer); 152 procedure RateMyModel(mix: Integer; var Category, Quality: Integer); 153 function IsBetterModel(const mi: TModelInfo): Boolean; 154 154 155 155 //terraforming 156 procedure TileWorkPlan(Loc, cix: integer; var Value, NextJob, TotalWork: integer);156 procedure TileWorkPlan(Loc, cix: Integer; var Value, NextJob, TotalWork: Integer); 157 157 procedure ProcessSettlers; 158 158 159 159 // diplomacy 160 function MostWanted(Nation, adGiveAway: integer): integer;160 function MostWanted(Nation, adGiveAway: Integer): Integer; 161 161 162 162 end; … … 174 174 175 175 var 176 LeaveOutValue: array[0..nAdv - 1] of integer; 177 178 179 constructor TAI.Create(Nation: integer); 176 LeaveOutValue: array[0..nAdv - 1] of Integer; 177 178 constructor TAI.Create(Nation: Integer); 180 179 begin 181 180 inherited; 182 Data := pointer(RO.Data);181 Data := Pointer(RO.Data); 183 182 {$IFDEF DEBUG} 184 183 if Nation = 1 then … … 193 192 begin 194 193 LastResearchTech := -1; 195 if PlayerHash[ me] > 7 then194 if PlayerHash[Me] > 7 then 196 195 BehaviorFlags := bFemale 197 196 else … … 199 198 DebugMessage(1, 'Gender:=' + char(48 + BehaviorFlags and bGender)); 200 199 TheologyPartner := -1; 201 fillchar(RejectTurn, sizeof(RejectTurn), $FF);202 Fillchar(RequestedTechs, sizeof(RequestedTechs), $FF);200 FillChar(RejectTurn, SizeOf(RejectTurn), $FF); 201 Fillchar(RequestedTechs, SizeOf(RequestedTechs), $FF); 203 202 end; 204 203 end; 205 204 206 function TAI.OnNegoRejected_CancelTreaty: boolean;205 function TAI.OnNegoRejected_CancelTreaty: Boolean; 207 206 begin 208 207 Data.RejectTurn[suContact, Opponent] := RO.Turn; … … 210 209 end; 211 210 212 213 211 //------------------------------- 214 212 // RESEARCH 215 213 //------------------------------- 216 214 217 procedure TAI.RateModel(const mi: TModelInfo; var Category, Quality: integer);215 procedure TAI.RateModel(const mi: TModelInfo; var Category, Quality: Integer); 218 216 var 219 EffectiveTransport: integer;217 EffectiveTransport: Integer; 220 218 begin 221 219 if mi.Kind >= mkScout then 222 220 begin 223 221 Category := mctNone; 224 exit;222 Exit; 225 223 end; 226 224 case mi.Domain of … … 294 292 end; 295 293 296 procedure TAI.RateMyModel(mix: integer; var Category, Quality: integer);294 procedure TAI.RateMyModel(mix: Integer; var Category, Quality: Integer); 297 295 var 298 296 mi: TModelInfo; 299 297 begin 300 MakeModelInfo( me, mix, MyModel[mix], mi);298 MakeModelInfo(Me, mix, MyModel[mix], mi); 301 299 RateModel(mi, Category, Quality); 302 300 end; 303 301 304 function TAI.IsBetterModel(const mi: TModelInfo): boolean;302 function TAI.IsBetterModel(const mi: TModelInfo): Boolean; 305 303 var 306 mix, Cat, Quality, Cat1, Quality1: integer;304 mix, Cat, Quality, Cat1, Quality1: Integer; 307 305 begin 308 306 RateModel(mi, Cat, Quality); … … 314 312 begin 315 313 Result := False; 316 exit;314 Exit; 317 315 end; 318 316 end; … … 320 318 end; 321 319 322 function TAI.ChooseResearchAdvance: integer;320 function TAI.ChooseResearchAdvance: Integer; 323 321 var 324 adNext, iad, i, ad, Count, EarliestNeeded, EarliestNeeded_NoLeaveOut,325 NewResearch, StateOfArt, mix: integer;322 adNext, iad, I, ad, Count, EarliestNeeded, EarliestNeeded_NoLeaveOut, 323 NewResearch, StateOfArt, mix: Integer; 326 324 mi: TModelInfo; 327 Entry: array[0..nAdv - 1] of boolean;328 ok: boolean;329 330 function MarkEntry(ad: integer): boolean;325 Entry: array[0..nAdv - 1] of Boolean; 326 ok: Boolean; 327 328 function MarkEntry(ad: Integer): Boolean; 331 329 begin 332 330 if RO.Tech[ad] >= tsApplicable then … … 375 373 end; 376 374 377 procedure OptimizeDevModel(OptimizeCaps: integer);375 procedure OptimizeDevModel(OptimizeCaps: Integer); 378 376 var 379 f, Cat, OriginalCat, Quality, BestQuality, Best: integer;377 F, Cat, OriginalCat, Quality, BestQuality, Best: Integer; 380 378 mi: TModelInfo; 381 379 begin 382 MakeModelInfo( me, 0, RO.DevModel, mi);380 MakeModelInfo(Me, 0, RO.DevModel, mi); 383 381 RateModel(mi, OriginalCat, BestQuality); 384 382 repeat 385 383 Best := -1; 386 for f:= 0 to nFeature - 1 do387 if (1 shl fand OptimizeCaps <> 0) and388 ((Feature[ f].Preq < 0) or IsResearched(Feature[f].Preq)) // check prerequisite389 and (RO.DevModel.Weight + Feature[ f].Weight <= RO.DevModel.MaxWeight) and390 not (( f >= mcFirstNonCap) and (RO.DevModel.Cap[f] > 0)) then391 begin 392 if SetNewModelFeature( f, RO.DevModel.Cap[f] + 1) >= rExecuted then384 for F := 0 to nFeature - 1 do 385 if (1 shl F and OptimizeCaps <> 0) and 386 ((Feature[F].Preq < 0) or IsResearched(Feature[F].Preq)) // check prerequisite 387 and (RO.DevModel.Weight + Feature[F].Weight <= RO.DevModel.MaxWeight) and 388 not ((F >= mcFirstNonCap) and (RO.DevModel.Cap[F] > 0)) then 389 begin 390 if SetNewModelFeature(F, RO.DevModel.Cap[F] + 1) >= rExecuted then 393 391 begin 394 MakeModelInfo( me, 0, RO.DevModel, mi);392 MakeModelInfo(Me, 0, RO.DevModel, mi); 395 393 RateModel(mi, Cat, Quality); 396 assert(Cat = OriginalCat);394 Assert(Cat = OriginalCat); 397 395 if Quality > BestQuality then 398 396 begin 399 Best := f;397 Best := F; 400 398 BestQuality := Quality; 401 399 end; 402 SetNewModelFeature( f, RO.DevModel.Cap[f] - 1);400 SetNewModelFeature(F, RO.DevModel.Cap[F] - 1); 403 401 end; 404 402 end; … … 408 406 end; 409 407 410 function LeaveOutsMissing(ad: integer): boolean;408 function LeaveOutsMissing(ad: Integer): Boolean; 411 409 var 412 i: integer;410 I: Integer; 413 411 begin 414 412 Result := False; … … 424 422 Result := True 425 423 else 426 for i:= 0 to 1 do427 if AdvPreq[ad, i] >= 0 then428 Result := Result or LeaveOutsMissing(AdvPreq[ad, i]);424 for I := 0 to 1 do 425 if AdvPreq[ad, I] >= 0 then 426 Result := Result or LeaveOutsMissing(AdvPreq[ad, I]); 429 427 end; 430 428 … … 434 432 Result := Barbarina_ChooseResearchAdvance; 435 433 if Result >= 0 then 436 exit;434 Exit; 437 435 end; 438 436 … … 446 444 Result := ad; 447 445 if Result >= 0 then 448 exit;446 Exit; 449 447 450 448 if Data.BehaviorFlags and bBarbarina = 0 then … … 462 460 OptimizeDevModel(1 shl mcOffense + 1 shl mcDefense + 1 shl 463 461 mcMob + 1 shl mcLongRange + 1 shl mcFanatic); 464 MakeModelInfo( me, 0, RO.DevModel, mi);462 MakeModelInfo(Me, 0, RO.DevModel, mi); 465 463 if IsBetterModel(mi) then 466 464 begin 467 465 Result := adMilitary; 468 exit;466 Exit; 469 467 end; 470 468 … … 473 471 SetNewModelFeature(mcOffense, 1); 474 472 OptimizeDevModel(1 shl mcOffense + 1 shl mcDefense + 1 shl mcFanatic); 475 MakeModelInfo( me, 0, RO.DevModel, mi);473 MakeModelInfo(Me, 0, RO.DevModel, mi); 476 474 if IsBetterModel(mi) then 477 475 begin 478 476 Result := adMilitary; 479 exit;477 Exit; 480 478 end; 481 479 end; … … 493 491 SetNewModelFeature(mcWeapons, 0); 494 492 SetNewModelFeature(mcDefense, 3); 495 exit;493 Exit; 496 494 end; 497 495 end; … … 508 506 OptimizeDevModel(1 shl mcDefense+1 shl mcSeaTrans+1 shl mcTurbines 509 507 +1 shl mcAirDef); 510 MakeModelInfo( me,0,RO.DevModel,mi);508 MakeModelInfo(Me,0,RO.DevModel,mi); 511 509 if IsBetterModel(mi) then 512 begin result:=adMilitary; exit end;510 begin Result:=adMilitary; Exit end; 513 511 end; 514 512 … … 521 519 OptimizeDevModel(1 shl mcOffense+1 shl mcDefense 522 520 +1 shl mcLongRange+1 shl mcAirDef+1 shl mcRadar); 523 MakeModelInfo( me,0,RO.DevModel,mi);521 MakeModelInfo(Me,0,RO.DevModel,mi); 524 522 if IsBetterModel(mi) then 525 begin result:=adMilitary; exit end;523 begin Result:=adMilitary; Exit end; 526 524 end 527 525 end; … … 547 545 begin 548 546 ok := True; 549 break;547 Break; 550 548 end; 551 549 if not ok then … … 590 588 begin // 2 of 3 required 591 589 Count := 0; 592 for i:= 0 to 2 do593 if RO.Tech[AdvPreq[ad, i]] >= tsApplicable then590 for I := 0 to 2 do 591 if RO.Tech[AdvPreq[ad, I]] >= tsApplicable then 594 592 Inc(Count); 595 593 if Count >= 2 then 596 594 begin 597 595 Result := ad; 598 exit;596 Exit; 599 597 end; 600 598 end … … 604 602 begin 605 603 Result := ad; 606 exit;604 Exit; 607 605 end; 608 606 end; … … 620 618 begin // go for future techs 621 619 Result := -1; 622 i:= 0;620 I := 0; 623 621 for ad := nAdv - 4 to nAdv - 1 do 624 622 if (RO.Tech[ad] < MaxFutureTech) and (RO.Tech[AdvPreq[ad, 0]] >= 625 623 tsApplicable) then 626 624 begin 627 Inc( i);628 if random( i) = 0 then625 Inc(I); 626 if random(I) = 0 then 629 627 Result := ad; 630 628 end; 631 assert((Result < 0) or AdvanceResearchable(Result));632 exit;633 end; 634 635 assert(NewResearch >= 0);636 fillchar(Entry, sizeof(Entry), False);629 Assert((Result < 0) or AdvanceResearchable(Result)); 630 Exit; 631 end; 632 633 Assert(NewResearch >= 0); 634 FillChar(Entry, SizeOf(Entry), False); 637 635 MarkEntry(NewResearch); 638 636 Result := -1; … … 640 638 if Entry[ad] and ((Result < 0) or (Advancedness[ad] > Advancedness[Result])) then 641 639 Result := ad; 642 assert(Result >= 0);640 Assert(Result >= 0); 643 641 end; 644 642 645 function TAI.ChooseStealAdvance: integer;643 function TAI.ChooseStealAdvance: Integer; 646 644 var 647 ad: integer;645 ad: Integer; 648 646 begin 649 647 Result := -1; … … 654 652 end; 655 653 656 657 654 //------------------------------- 658 655 // TERRAFORMING … … 662 659 twpAllowFarmland = $0001; 663 660 664 procedure TAI.TileWorkPlan(Loc, cix: integer; var Value, NextJob, TotalWork: integer);661 procedure TAI.TileWorkPlan(Loc, cix: Integer; var Value, NextJob, TotalWork: Integer); 665 662 var 666 OldTile, TerrType: cardinal;663 OldTile, TerrType: Cardinal; 667 664 TileInfo: TTileInfo; 668 665 begin … … 672 669 begin 673 670 Value := 3 * 8 - 1; 674 exit;671 Exit; 675 672 end; // better than any tile with 2 food 676 673 … … 693 690 Map[Loc] := Map[Loc] and not fTerrain or fGrass; 694 691 TerrType := fGrass; 695 Map[Loc] := Map[Loc] or cardinal(SpecialTile(Loc, TerrType, G.lx) shl 5);692 Map[Loc] := Map[Loc] or Cardinal(SpecialTile(Loc, TerrType, G.lx) shl 5); 696 693 end 697 694 else if IsResearched(adExplosives) and … … 704 701 Map[Loc] := Map[Loc] and not fTerrain or fGrass; 705 702 TerrType := fGrass; 706 Map[Loc] := Map[Loc] or cardinal(SpecialTile(Loc, TerrType, G.lx) shl 5);703 Map[Loc] := Map[Loc] or Cardinal(SpecialTile(Loc, TerrType, G.lx) shl 5); 707 704 end; 708 705 if (Terrain[TerrType].MineEff > 0) and (RO.Government <> gDespotism) then … … 767 764 end; 768 765 end; 769 Server(sGetTileInfo, me, Loc, TileInfo);766 Server(sGetTileInfo, Me, Loc, TileInfo); 770 767 Value := TileInfo.Food * 8 + TileInfo.Prod * 2 + TileInfo.Trade; 771 768 Map[Loc] := OldTile; … … 775 772 procedure TAI.ProcessSettlers; 776 773 var 777 i, uix, cix, ecix, dtr, Loc, RadiusLoc, Special, Food, Prod, Trade,774 I, uix, cix, ecix, dtr, Loc, RadiusLoc, Special, Food, Prod, Trade, 778 775 CityFood, Happy, TestScore, BestNearCityScore, BestUnusedValue, 779 BestUnusedLoc, Value, NextJob, TotalWork, V21, part, Loc1: integer;780 Tile: cardinal;781 FoodOk, Started: boolean;776 BestUnusedLoc, Value, NextJob, TotalWork, V21, part, Loc1: Integer; 777 Tile: Cardinal; 778 FoodOk, Started: Boolean; 782 779 Radius: TVicinity21Loc; 783 780 CityAreaInfo: TCityAreaInfo; 784 TileFood, ResourceScore, CityScore: array[0..lxmax * lymax - 1] of integer;785 786 procedure AddJob(Loc, Job, Score: integer);781 TileFood, ResourceScore, CityScore: array[0..lxmax * lymax - 1] of Integer; 782 783 procedure AddJob(Loc, Job, Score: Integer); 787 784 // set Score=1 for low-priority jobs 788 785 begin … … 792 789 end; 793 790 794 procedure ReserveCityRadius(Loc: integer);791 procedure ReserveCityRadius(Loc: Integer); 795 792 var 796 V21, RadiusLoc: integer;793 V21, RadiusLoc: Integer; 797 794 Radius: TVicinity21Loc; 798 795 begin … … 811 808 procedure ScoreRoadConnections; 812 809 var 813 V8, nFragments, Loc, Loc1, History, RoadScore, a, b, FullyDeveloped,814 ConnectMask: integer;815 BridgeOk: boolean;810 V8, nFragments, Loc, Loc1, History, RoadScore, A, B, FullyDeveloped, 811 ConnectMask: Integer; 812 BridgeOk: Boolean; 816 813 Adjacent: TVicinity8Loc; 817 814 begin … … 824 821 if ((1 shl (Map[Loc] and fTerrain)) and (1 shl fOcean or 1 shl 825 822 fShore or 1 shl fDesert or 1 shl fArctic or 1 shl fUNKNOWN) = 0) and 826 (RO.Territory[Loc] = me) and (Map[Loc] and FullyDeveloped = 0) and823 (RO.Territory[Loc] = Me) and (Map[Loc] and FullyDeveloped = 0) and 827 824 (BridgeOk or (Map[Loc] and fRiver = 0)) then 828 825 begin … … 838 835 Loc1 := Adjacent[V8 and 7]; 839 836 History := History shl 1; 840 if (Loc1 >= 0) and (RO.Territory[Loc1] = me) and837 if (Loc1 >= 0) and (RO.Territory[Loc1] = Me) and 841 838 (Map[Loc1] and ConnectMask <> 0) then 842 839 begin … … 854 851 else if History and 4 <> 0 then 855 852 begin 856 V8_to_ab((V8 - 1) and 7, a, b);857 ab_to_Loc(Loc, a shl 1, bshl 1, Loc1);853 V8_to_ab((V8 - 1) and 7, A, B); 854 ab_to_Loc(Loc, A shl 1, B shl 1, Loc1); 858 855 if (Loc1 >= 0) and (Map[Loc1] and ConnectMask <> 0) then 859 856 Dec(nFragments); … … 879 876 880 877 begin 881 fillchar(SettlerSurplus, sizeof(SettlerSurplus), 0);878 FillChar(SettlerSurplus, SizeOf(SettlerSurplus), 0); 882 879 JobAssignment_Initialize; 883 880 884 881 if (Data.BehaviorFlags and bBarbarina = 0) or (RO.nCity < 3) then 885 882 begin 886 fillchar(TileFood, sizeof(TileFood), 0);887 fillchar(ResourceScore, sizeof(ResourceScore), 0);883 FillChar(TileFood, SizeOf(TileFood), 0); 884 FillChar(ResourceScore, SizeOf(ResourceScore), 0); 888 885 for Loc := 0 to MapSize - 1 do 889 886 if Map[Loc] and fTerrain <> fUNKNOWN then … … 926 923 927 924 // rate possible new cities 928 fillchar(CityScore, MapSize * sizeof(integer), 0);925 FillChar(CityScore, MapSize * SizeOf(Integer), 0); 929 926 for Loc := 0 to MapSize - 1 do 930 927 begin … … 933 930 ((RO.Government <> gDespotism) or (Map[Loc] and fSpecial = fSpecial1)) or 934 931 (Map[Loc] and (fTerrain or fSpecial) = fPrairie or fSpecial1)); 935 if FoodOk and ((RO.Territory[Loc] < 0) or (RO.Territory[Loc] = me)) then932 if FoodOk and ((RO.Territory[Loc] < 0) or (RO.Territory[Loc] = Me)) then 936 933 begin 937 934 TestScore := 0; … … 953 950 if CityFood >= MinCityFood then // city is worth founding 954 951 begin 955 TestScore := (72 + 2 * TestScore) shl 8 + ((loc xor me) * 4567) mod 251;952 TestScore := (72 + 2 * TestScore) shl 8 + ((loc xor Me) * 4567) mod 251; 956 953 // some unexactness, random but always the same for this tile 957 954 if TestScore > BestNearCityScore then … … 991 988 if not (Map[RadiusLoc] and fTerrain in [fDesert, fArctic]) then 992 989 begin 993 assert(RadiusLoc >= 0);990 Assert(RadiusLoc >= 0); 994 991 TileWorkPlan(RadiusLoc, cix, Value, NextJob, TotalWork); 995 992 if (NextJob = jRoad) and (Built[imPalace] + … … 1003 1000 begin // tile could be exploited 1004 1001 RadiusLoc := Radius[V21]; 1005 assert(RadiusLoc >= 0);1002 Assert(RadiusLoc >= 0); 1006 1003 if not (Map[RadiusLoc] and fTerrain in [fDesert, fArctic]) then 1007 1004 begin … … 1027 1024 if Data.BehaviorFlags and bBarbarina = 0 then // low priority jobs 1028 1025 for Loc := 0 to MapSize - 1 do 1029 if RO.Territory[Loc] = me then1026 if RO.Territory[Loc] = Me then 1030 1027 begin 1031 1028 Tile := Map[Loc]; … … 1051 1048 begin 1052 1049 for part := 0 to nShipPart - 1 do 1053 for i:= 0 to ColonyShipPlan[part].nLocFoundCity - 1 do1054 begin 1055 Loc := ColonyShipPlan[part].LocFoundCity[ i];1050 for I := 0 to ColonyShipPlan[part].nLocFoundCity - 1 do 1051 begin 1052 Loc := ColonyShipPlan[part].LocFoundCity[I]; 1056 1053 Started := False; 1057 1054 for uix := 0 to RO.nUn - 1 do … … 1059 1056 begin 1060 1057 Started := True; 1061 break;1058 Break; 1062 1059 end; 1063 1060 if not Started then … … 1122 1119 begin // settlers could be added to this city 1123 1120 Happy := BasicHappy; 1124 for i:= 0 to nWonder - 1 do1125 if Built[ i] > 0 then1121 for I := 0 to nWonder - 1 do 1122 if Built[I] > 0 then 1126 1123 Inc(Happy); 1127 1124 if Built[imTemple] > 0 then … … 1130 1127 begin 1131 1128 Inc(Happy, 2); 1132 if RO.Wonder[woBach].EffectiveOwner = me then1129 if RO.Wonder[woBach].EffectiveOwner = Me then 1133 1130 Inc(Happy, 1); 1134 1131 end; … … 1145 1142 end; 1146 1143 end; 1147 end; // ProcessSettlers 1148 1144 end; 1149 1145 1150 1146 //------------------------------- … … 1154 1150 procedure TAI.DoTurn; 1155 1151 var 1156 emix, i, p1, TaxSum, ScienceSum, NewTaxRate: integer;1157 AllHateMe: boolean;1152 emix, I, p1, TaxSum, ScienceSum, NewTaxRate: Integer; 1153 AllHateMe: Boolean; 1158 1154 {$IFDEF PERF} 1159 1155 PF, t0, t1, t2, t3, t4, t5, t6, t7, t8, t9: int64; … … 1161 1157 begin 1162 1158 {$IFDEF DEBUG} 1163 fillchar(DebugMap, sizeof(DebugMap), 0);1159 FillChar(DebugMap, SizeOf(DebugMap), 0); 1164 1160 {$ENDIF} 1165 1161 … … 1173 1169 WarNations := PresenceUnknown; 1174 1170 for p1 := 0 to nPl - 1 do 1175 if (p1 <> me) and (1 shl p1 and RO.Alive <> 0) and (RO.Treaty[p1] < trPeace) then1171 if (p1 <> Me) and (1 shl p1 and RO.Alive <> 0) and (RO.Treaty[p1] < trPeace) then 1176 1172 Inc(WarNations, 1 shl p1); 1177 1173 BombardingNations := 0; … … 1189 1185 CheckGender; 1190 1186 1191 if G.Difficulty[ me] < MaxDiff then // not on beginner level1187 if G.Difficulty[Me] < MaxDiff then // not on beginner level 1192 1188 begin 1193 1189 if (Data.LastResearchTech = adHorsebackRiding) and (RO.ResearchTech < 0) and 1194 1190 (random(6) = 0) and (HavePort or (ContinentPresence[0] and not 1195 (1 shl me or PresenceUnknown) <> 0)) then1191 (1 shl Me or PresenceUnknown) <> 0)) then 1196 1192 begin 1197 1193 Data.BehaviorFlags := Data.BehaviorFlags or bBarbarina_Hide; … … 1210 1206 begin 1211 1207 AllHateMe := False; 1212 break;1208 Break; 1213 1209 end; 1214 1210 if AllHateMe then … … 1306 1302 else 1307 1303 begin 1308 if (RO.TaxRate = 0) or (RO.Money < (TotalPopulation[ me] - 4) * 2) then1304 if (RO.TaxRate = 0) or (RO.Money < (TotalPopulation[Me] - 4) * 2) then 1309 1305 NewTaxRate := RO.TaxRate // don't check decreasing tax 1310 1306 else … … 1313 1309 begin 1314 1310 SumCities(NewTaxRate, TaxSum, ScienceSum); 1315 if RO.Money + TaxSum >= (TotalPopulation[ me] - 4) then1316 break; // enough1311 if RO.Money + TaxSum >= (TotalPopulation[Me] - 4) then 1312 Break; // enough 1317 1313 Inc(NewTaxRate, 10); 1318 1314 end; … … 1328 1324 // research completed 1329 1325 for p1 := 0 to nPl - 1 do 1330 if (p1 <> me) and (1 shl p1 and RO.Alive <> 0) and1326 if (p1 <> Me) and (1 shl p1 and RO.Alive <> 0) and 1331 1327 (RO.EnemyReport[p1].TurnOfCivilReport + TechReportOutdated > RO.Turn) and 1332 1328 (RO.EnemyReport[p1].Tech[Data.LastResearchTech] < tsSeen) then 1333 1329 begin // latest researched advance might be of interest to this nation 1334 for i:= 0 to nRequestedTechs - 1 do1335 if (Data.RequestedTechs[ i] >= 0) and1336 (Data.RequestedTechs[ i] shr 8 and $F = p1) then1337 Data.RequestedTechs[ i] := -1;1330 for I := 0 to nRequestedTechs - 1 do 1331 if (Data.RequestedTechs[I] >= 0) and 1332 (Data.RequestedTechs[I] shr 8 and $F = p1) then 1333 Data.RequestedTechs[I] := -1; 1338 1334 end; 1339 1335 if RO.ResearchTech = adMilitary then … … 1341 1337 else 1342 1338 Data.LastResearchTech := RO.ResearchTech; 1343 for i:= 0 to nRequestedTechs - 1 do1344 if (Data.RequestedTechs[ i] >= 0) and1345 (RO.Tech[Data.RequestedTechs[ i] and $FF] >= tsSeen) then1346 Data.RequestedTechs[ i] := -1;1339 for I := 0 to nRequestedTechs - 1 do 1340 if (Data.RequestedTechs[I] >= 0) and 1341 (RO.Tech[Data.RequestedTechs[I] and $FF] >= tsSeen) then 1342 Data.RequestedTechs[I] := -1; 1347 1343 1348 1344 // prepare negotiation … … 1350 1346 SetAdvanceValues; 1351 1347 1352 1353 1348 {$IFDEF DEBUG} 1354 1349 (*for p1:=0 to nPl-1 do 1355 if (p1<> me) and (1 shl p1 and RO.Alive<>0) and (RO.Treaty[p1]>=trPeace)1350 if (p1<>Me) and (1 shl p1 and RO.Alive<>0) and (RO.Treaty[p1]>=trPeace) 1356 1351 and (RO.EnemyReport[p1].TurnOfCivilReport>=0) then 1357 1352 TraceAdvanceValues(p1);*) … … 1368 1363 1369 1364 {$IFDEF DEBUG} 1370 procedure TAI.TraceAdvanceValues(Nation: integer);1365 procedure TAI.TraceAdvanceValues(Nation: Integer); 1371 1366 var 1372 ad: integer;1367 ad: Integer; 1373 1368 begin 1374 1369 for ad := 0 to nAdv - 1 do … … 1380 1375 end; 1381 1376 end; 1382 1383 1377 {$ENDIF} 1384 1385 1378 1386 1379 procedure TAI.CheckGender; 1387 1380 var 1388 p1, NewGender: integer;1381 p1, NewGender: Integer; 1389 1382 begin 1390 1383 NewGender := -1; 1391 1384 for p1 := 0 to nPl - 1 do 1392 if (p1 <> me) and (1 shl p1 and RO.Alive <> 0) and1385 if (p1 <> Me) and (1 shl p1 and RO.Alive <> 0) and 1393 1386 (RO.Treaty[p1] >= trFriendlyContact) then 1394 if PlayerHash[ me] > PlayerHash[p1] then1387 if PlayerHash[Me] > PlayerHash[p1] then 1395 1388 begin 1396 1389 if NewGender = bMale then 1397 1390 begin 1398 1391 NewGender := -2; 1399 break;1392 Break; 1400 1393 end; // ambiguous, don't change gender 1401 1394 NewGender := bFemale; … … 1406 1399 begin 1407 1400 NewGender := -2; 1408 break;1401 Break; 1409 1402 end; // ambiguous, don't change gender 1410 1403 NewGender := bMale; … … 1417 1410 end; 1418 1411 1419 1420 1412 procedure TAI.SetAdvanceValues; 1421 1413 1422 procedure RateResearchAdv(ad, Time: integer);1414 procedure RateResearchAdv(ad, Time: Integer); 1423 1415 var 1424 Value: integer;1416 Value: Integer; 1425 1417 begin 1426 1418 if Time = 0 then … … 1432 1424 end; 1433 1425 1434 procedure SetPreqValues(ad, Value: integer);1426 procedure SetPreqValues(ad, Value: Integer); 1435 1427 begin 1436 1428 if (RO.Tech[ad] < tsSeen) and (ad <> RO.ResearchTech) then … … 1455 1447 end; 1456 1448 1457 procedure RateImpPreq(iix, Value: integer);1449 procedure RateImpPreq(iix, Value: Integer); 1458 1450 begin 1459 1451 if (Value > 0) and (Imp[iix].Preq >= 0) then … … 1462 1454 1463 1455 var 1464 emix, cix, adMissing, iad, ad, Count, i, Time, d, CurrentCost,1465 CurrentStrength, MaxSize, MaxTrade: integer;1466 PreView, Emergency, Bombarded: boolean;1456 emix, cix, adMissing, iad, ad, Count, I, Time, D, CurrentCost, 1457 CurrentStrength, MaxSize, MaxTrade: Integer; 1458 PreView, Emergency, Bombarded: Boolean; 1467 1459 begin 1468 1460 if AdvanceValuesSet then 1469 exit;1461 Exit; 1470 1462 AdvanceValuesSet := True; 1471 1463 1472 fillchar(AdvanceValue, sizeof(AdvanceValue), 0);1464 FillChar(AdvanceValue, SizeOf(AdvanceValue), 0); 1473 1465 1474 1466 // rate techs to ensure research progress … … 1490 1482 begin // 2 of 3 required 1491 1483 Count := 0; 1492 for i:= 0 to 2 do1493 if (AdvPreq[ad, i] = RO.ResearchTech) or1494 (RO.Tech[AdvPreq[ad, i]] >= tsSeen) then1484 for I := 0 to 2 do 1485 if (AdvPreq[ad, I] = RO.ResearchTech) or 1486 (RO.Tech[AdvPreq[ad, I]] >= tsSeen) then 1495 1487 Inc(Count); 1496 1488 if Count >= 2 then … … 1500 1492 if ad <> adMassProduction then // don't score third preq for MP 1501 1493 begin 1502 for i:= 0 to 2 do1503 if (AdvPreq[ad, i] <> RO.ResearchTech) and1504 (RO.Tech[AdvPreq[ad, i]] < tsSeen) then1505 RateResearchAdv(AdvPreq[ad, i], Time);1494 for I := 0 to 2 do 1495 if (AdvPreq[ad, I] <> RO.ResearchTech) and 1496 (RO.Tech[AdvPreq[ad, I]] < tsSeen) then 1497 RateResearchAdv(AdvPreq[ad, I], Time); 1506 1498 end; 1507 1499 Inc(Time, 2 - Count); … … 1511 1503 begin 1512 1504 Count := 0; 1513 for i:= 0 to 1 do1514 if (AdvPreq[ad, i] <> preNone) and (AdvPreq[ad, i] <> RO.ResearchTech) and1515 (RO.Tech[AdvPreq[ad, i]] < tsSeen) then1505 for I := 0 to 1 do 1506 if (AdvPreq[ad, I] <> preNone) and (AdvPreq[ad, I] <> RO.ResearchTech) and 1507 (RO.Tech[AdvPreq[ad, I]] < tsSeen) then 1516 1508 begin 1517 RateResearchAdv(AdvPreq[ad, i], Time);1509 RateResearchAdv(AdvPreq[ad, I], Time); 1518 1510 Inc(Count); 1519 1511 end; … … 1544 1536 1545 1537 // rate military techs 1546 for d:= 0 to nDomains - 1 do1538 for D := 0 to nDomains - 1 do 1547 1539 begin 1548 1540 CurrentCost := 0; 1549 1541 CurrentStrength := 0; 1550 1542 for PreView := True downto False do 1551 for i:= 0 to nUpgrade - 1 do1552 with Upgrade[ d, i] do1543 for I := 0 to nUpgrade - 1 do 1544 with Upgrade[D, I] do 1553 1545 if (Preq >= 0) and not (Preq in FutureTech) then 1554 1546 if ((Ro.ResearchTech = Preq) or (RO.Tech[Preq] >= tsSeen)) = PreView then … … 1561 1553 else 1562 1554 begin // rate 1563 if ( i> 0) and (Trans > 0) then1555 if (I > 0) and (Trans > 0) then 1564 1556 Inc(AdvanceValue[Preq], $400); 1565 1557 if Cost <= CurrentCost then 1566 Inc(AdvanceValue[Preq], (4 - d) * Strength * $400 div1567 (CurrentStrength + Upgrade[ d, 0].Strength))1558 Inc(AdvanceValue[Preq], (4 - D) * Strength * $400 div 1559 (CurrentStrength + Upgrade[D, 0].Strength)) 1568 1560 else 1569 Inc(AdvanceValue[Preq], (4 - d) * Strength * $200 div1570 (CurrentStrength + Upgrade[ d, 0].Strength));1561 Inc(AdvanceValue[Preq], (4 - D) * Strength * $200 div 1562 (CurrentStrength + Upgrade[D, 0].Strength)); 1571 1563 end; 1572 1564 end; … … 1648 1640 procedure TAI.AnalyzeMap; 1649 1641 var 1650 cix, Loc, Loc1, V8, f1, p1: integer;1642 cix, Loc, Loc1, V8, f1, p1: Integer; 1651 1643 Adjacent: TVicinity8Loc; 1652 1644 begin … … 1654 1646 1655 1647 // collect nation presence information for continents and oceans 1656 fillchar(ContinentPresence, sizeof(ContinentPresence), 0);1657 fillchar(OceanPresence, sizeof(OceanPresence), 0);1648 FillChar(ContinentPresence, SizeOf(ContinentPresence), 0); 1649 FillChar(OceanPresence, SizeOf(OceanPresence), 0); 1658 1650 for Loc := 0 to MapSize - 1 do 1659 1651 begin … … 1707 1699 end; 1708 1700 1709 fillchar(TotalPopulation, sizeof(TotalPopulation), 0);1710 fillchar(ContinentPopulation, sizeof(ContinentPopulation), 0);1711 fillchar(DistrictPopulation, 4 * nDistrict, 0);1701 FillChar(TotalPopulation, SizeOf(TotalPopulation), 0); 1702 FillChar(ContinentPopulation, SizeOf(ContinentPopulation), 0); 1703 FillChar(DistrictPopulation, 4 * nDistrict, 0); 1712 1704 1713 1705 // count population … … 1724 1716 if Loc >= 0 then 1725 1717 begin 1726 Inc(TotalPopulation[ me], Size);1727 assert(District[Loc] >= 0);1718 Inc(TotalPopulation[Me], Size); 1719 Assert(District[Loc] >= 0); 1728 1720 if District[Loc] < maxCOD then 1729 1721 Inc(DistrictPopulation[District[Loc]], Size); … … 1733 1725 procedure TAI.CollectModelCatStat; 1734 1726 var 1735 i, uix, Cat, mix, Quality: integer;1727 I, uix, Cat, mix, Quality: Integer; 1736 1728 begin 1737 1729 // categorize models … … 1779 1771 if (Loc >= 0) and (mix = mixCruiser) and (Map[Loc] and fTerrain < fGrass) then 1780 1772 begin 1781 i:= Formation[Loc];1782 if ( i >= 0) and (i< maxCOD) then1783 OceanWithShip := OceanWithShip or (1 shl i);1773 I := Formation[Loc]; 1774 if (I >= 0) and (I < maxCOD) then 1775 OceanWithShip := OceanWithShip or (1 shl I); 1784 1776 end; 1785 1777 end; 1786 1787 1778 1788 1779 procedure TAI.MoveUnitsHome; 1789 1780 const 1790 1781 PatrolDestination = lxmax * lymax; 1791 FirstSurplusLoop: array[mctGroundDefender..mctGroundAttacker] of integer = (2, 1);1782 FirstSurplusLoop: array[mctGroundDefender..mctGroundAttacker] of Integer = (2, 1); 1792 1783 var 1793 Cat, i, mix, cix, uix, Loop, nModelOrder: integer;1784 Cat, I, mix, cix, uix, Loop, nModelOrder: Integer; 1794 1785 Adjacent: TVicinity8Loc; 1795 LocNeed: array[0..lxmax * lymax - 1] of shortint;1796 Destination: array[0..nUmax - 1] of integer;1797 DistrictNeed, DistrictNeed0: array[0..maxCOD - 1] of integer;1798 ModelOrder: array[0..nMmax - 1] of integer;1799 complete, Fortified: boolean;1800 1801 function IsBombarded(cix: integer): boolean;1786 LocNeed: array[0..lxmax * lymax - 1] of ShortInt; 1787 Destination: array[0..nUmax - 1] of Integer; 1788 DistrictNeed, DistrictNeed0: array[0..maxCOD - 1] of Integer; 1789 ModelOrder: array[0..nMmax - 1] of Integer; 1790 complete, Fortified: Boolean; 1791 1792 function IsBombarded(cix: Integer): Boolean; 1802 1793 var 1803 Loc1, V8: integer;1794 Loc1, V8: Integer; 1804 1795 Adjacent: TVicinity8Loc; 1805 1796 begin … … 1818 1809 begin 1819 1810 Result := True; 1820 exit;1811 Exit; 1821 1812 end; 1822 1813 end; … … 1824 1815 end; 1825 1816 1826 procedure TryUtilize(uix: integer);1817 procedure TryUtilize(uix: Integer); 1827 1818 var 1828 cix, ProdCost, UtilizeCost: integer;1819 cix, ProdCost, UtilizeCost: Integer; 1829 1820 begin 1830 1821 if (MyUnit[uix].Health = 100) and (Map[MyUnit[uix].Loc] and … … 1838 1829 UtilizeCost := MyModel[MyUnit[uix].mix].Cost; 1839 1830 if Prod < (ProdCost - UtilizeCost * 2 div 3) * 1840 BuildCostMod[G.Difficulty[ me]] div 12 then1831 BuildCostMod[G.Difficulty[Me]] div 12 then 1841 1832 Unit_Disband(uix); 1842 1833 end; … … 1844 1835 end; 1845 1836 1846 procedure FindDestination(uix: integer);1837 procedure FindDestination(uix: Integer); 1847 1838 var 1848 MoveStyle, V8, Loc1, Time, NextLoc, NextTime, RecoverTurns: integer;1849 Reached: array[0..lxmax * lymax - 1] of boolean;1850 begin 1851 fillchar(Reached, MapSize, False);1839 MoveStyle, V8, Loc1, Time, NextLoc, NextTime, RecoverTurns: Integer; 1840 Reached: array[0..lxmax * lymax - 1] of Boolean; 1841 begin 1842 FillChar(Reached, MapSize, False); 1852 1843 Pile.Create(MapSize); 1853 1844 with MyUnit[uix] do … … 1863 1854 if (District[Loc1] >= 0) and (District[Loc1] < maxCOD) then 1864 1855 begin 1865 assert(DistrictNeed[District[Loc1]] > 0);1856 Assert(DistrictNeed[District[Loc1]] > 0); 1866 1857 Dec(DistrictNeed[District[Loc1]]); 1867 1858 end; 1868 1859 Destination[uix] := Loc1; 1869 break;1860 Break; 1870 1861 end; 1871 1862 Reached[Loc1] := True; … … 1874 1865 begin 1875 1866 NextLoc := Adjacent[V8]; 1876 if (NextLoc >= 0) and not Reached[NextLoc] and (RO.Territory[NextLoc] = me) then1867 if (NextLoc >= 0) and not Reached[NextLoc] and (RO.Territory[NextLoc] = Me) then 1877 1868 case CheckStep(MoveStyle, Time, V8 and 1, NextTime, RecoverTurns, 1878 1869 Map[Loc1], Map[NextLoc], False) of … … 1882 1873 Reached[NextLoc] := True; // don't check moving there again 1883 1874 csCheckTerritory: 1884 assert(False);1875 Assert(False); 1885 1876 end; 1886 1877 end; … … 1896 1887 Unit_Disband(uix); 1897 1888 1898 fillchar(UnitLack, sizeof(UnitLack), 0);1899 fillchar(Destination, 4 * RO.nUn, $FF);1900 for i:= 0 to maxCOD - 1 do1901 if uixPatrol[ i] >= 0 then1902 Destination[uixPatrol[ i]] := PatrolDestination;1889 FillChar(UnitLack, SizeOf(UnitLack), 0); 1890 FillChar(Destination, 4 * RO.nUn, $FF); 1891 for I := 0 to maxCOD - 1 do 1892 if uixPatrol[I] >= 0 then 1893 Destination[uixPatrol[I]] := PatrolDestination; 1903 1894 for uix := 0 to RO.nUn - 1 do 1904 1895 if (MyUnit[uix].mix = mixMilitia) or (MyUnit[uix].mix = mixCruiser) then … … 1912 1903 if ModelCat[mix] = Cat then 1913 1904 begin 1914 i:= nModelOrder;1915 while ( i > 0) and (ModelQuality[mix] < ModelQuality[ModelOrder[i- 1]]) do1916 begin 1917 ModelOrder[ i] := ModelOrder[i- 1];1918 Dec( i);1919 end; 1920 ModelOrder[ i] := mix;1905 I := nModelOrder; 1906 while (I > 0) and (ModelQuality[mix] < ModelQuality[ModelOrder[I - 1]]) do 1907 begin 1908 ModelOrder[I] := ModelOrder[I - 1]; 1909 Dec(I); 1910 end; 1911 ModelOrder[I] := mix; 1921 1912 Inc(nModelOrder); 1922 1913 end; … … 1931 1922 TryUtilize(uix); 1932 1923 1933 fillchar(LocNeed, MapSize, 0);1934 fillchar(DistrictNeed, sizeof(DistrictNeed), 0);1924 FillChar(LocNeed, MapSize, 0); 1925 FillChar(DistrictNeed, SizeOf(DistrictNeed), 0); 1935 1926 1936 1927 for cix := 0 to RO.nCity - 1 do … … 1955 1946 for uix := 0 to RO.nUn - 1 do 1956 1947 with MyUnit[uix] do 1957 if (Loc >= 0) and (Job = jCity) and (RO.Territory[Loc] = me) then1948 if (Loc >= 0) and (Job = jCity) and (RO.Territory[Loc] = Me) then 1958 1949 begin 1959 1950 LocNeed[Loc] := 1; … … 1963 1954 1964 1955 complete := Loop >= FirstSurplusLoop[Cat]; 1965 for i:= nModelOrder - 1 downto 0 do1956 for I := nModelOrder - 1 downto 0 do 1966 1957 begin 1967 1958 for Fortified := True downto False do 1968 1959 for uix := 0 to RO.nUn - 1 do 1969 1960 with MyUnit[uix] do 1970 if (mix = ModelOrder[ i]) and (Loc >= 0) and1961 if (mix = ModelOrder[I]) and (Loc >= 0) and 1971 1962 (Destination[uix] < 0) and (Master < 0) and 1972 1963 ((Flags and unFortified <> 0) = Fortified) and (LocNeed[Loc] > 0) then … … 1981 1972 for uix := 0 to RO.nUn - 1 do 1982 1973 with MyUnit[uix] do 1983 if (mix = ModelOrder[ i]) and (Loc >= 0) and (Destination[uix] < 0) and1974 if (mix = ModelOrder[I]) and (Loc >= 0) and (Destination[uix] < 0) and 1984 1975 (Master < 0) then 1985 1976 if (District[Loc] >= 0) and (District[Loc] < maxCOD) and … … 1998 1989 // distribute obsolete settlers 1999 1990 repeat 2000 fillchar(LocNeed, MapSize, 0);2001 fillchar(DistrictNeed, sizeof(DistrictNeed), 0);1991 FillChar(LocNeed, MapSize, 0); 1992 FillChar(DistrictNeed, SizeOf(DistrictNeed), 0); 2002 1993 2003 1994 for cix := 0 to RO.nCity - 1 do … … 2049 2040 for uix := 0 to RO.nUn - 1 do 2050 2041 with MyUnit[uix] do 2051 if (Loc >= 0) and (RO.Territory[Loc] = me) and (District[Loc] >= 0) and2042 if (Loc >= 0) and (RO.Territory[Loc] = Me) and (District[Loc] >= 0) and 2052 2043 (District[Loc] < maxCOD) and (ModelQuality[mix] > 0) then 2053 2044 case ModelCat[mix] of … … 2055 2046 Dec(UnitLack[District[Loc], ModelCat[mix]]) 2056 2047 end; 2057 end; // MoveUnitsHome 2058 2059 2060 procedure TAI.CheckAttack(uix: integer); 2048 end; 2049 2050 procedure TAI.CheckAttack(uix: Integer); 2061 2051 var 2062 2052 AttackScore, BestCount, AttackLoc, TestLoc, NextLoc, TestTime, V8, 2063 2053 TestScore, euix, MyDamage, EnemyDamage, OldLoc, AttackForecast, 2064 MoveResult, AttackResult, MoveStyle, NextTime, RecoverTurns: integer;2065 Tile: cardinal;2066 Exhausted: boolean;2054 MoveResult, AttackResult, MoveStyle, NextTime, RecoverTurns: Integer; 2055 Tile: Cardinal; 2056 Exhausted: Boolean; 2067 2057 Adjacent: TVicinity8Loc; 2068 Reached: array[0..lxmax * lymax - 1] of boolean;2058 Reached: array[0..lxmax * lymax - 1] of Boolean; 2069 2059 2070 2060 begin … … 2075 2065 AttackScore := -999999; 2076 2066 AttackLoc := -1; 2077 fillchar(Reached, MapSize, False);2067 FillChar(Reached, MapSize, False); 2078 2068 Pile.Create(MapSize); 2079 2069 Pile.Put(Loc, $800 - Movement); … … 2087 2077 if ((Tile and fUnit) <> 0) and ((Tile and fOwned) = 0) then 2088 2078 begin // enemy unit 2089 assert(TestTime < $1000);2079 Assert(TestTime < $1000); 2090 2080 Unit_FindEnemyDefender(TestLoc, euix); 2091 2081 if RO.Treaty[RO.EnemyUn[euix].Owner] < trPeace then … … 2176 2166 until Exhausted; 2177 2167 end; 2178 end; // CheckAttack 2179 2180 2181 procedure TAI.Patrol(uix: integer); 2168 end; 2169 2170 procedure TAI.Patrol(uix: Integer); 2182 2171 const 2183 2172 DistanceScore = 4; 2184 2173 var 2185 2174 PatrolScore, BestCount, PatrolLoc, TestLoc, NextLoc, TestTime, V8, 2186 TestScore, OldLoc, MoveResult, MoveStyle, NextTime, RecoverTurns: integer;2187 Tile: cardinal;2188 Exhausted, CaptureOnly: boolean;2175 TestScore, OldLoc, MoveResult, MoveStyle, NextTime, RecoverTurns: Integer; 2176 Tile: Cardinal; 2177 Exhausted, CaptureOnly: Boolean; 2189 2178 Adjacent: TVicinity8Loc; 2190 AdjacentUnknown: array[0..lxmax * lymax - 1] of shortint;2179 AdjacentUnknown: array[0..lxmax * lymax - 1] of ShortInt; 2191 2180 2192 2181 begin … … 2207 2196 // assume a score of 50 is the best achievable 2208 2197 or CaptureOnly and (TestTime >= $1000) then 2209 break;2198 Break; 2210 2199 2211 2200 TestScore := 0; … … 2282 2271 until Exhausted; 2283 2272 end; 2284 end; // Patrol2273 end; 2285 2274 2286 2275 procedure TAI.AttackAndPatrol; 2287 2276 const 2288 2277 nAttackCatOrder = 3; 2289 AttackCatOrder: array[0..nAttackCatOrder - 1] of integer =2278 AttackCatOrder: array[0..nAttackCatOrder - 1] of Integer = 2290 2279 (mctGroundAttacker, mctCruiser, mctGroundDefender); 2291 2280 var 2292 iCat, uix, uix1: integer;2293 IsPatrolUnit, Fortified: boolean;2281 iCat, uix, uix1: Integer; 2282 IsPatrolUnit, Fortified: Boolean; 2294 2283 begin 2295 2284 for uix := 0 to RO.nUn - 1 do … … 2310 2299 CheckAttack(uix); 2311 2300 2312 fillchar(uixPatrol, sizeof(uixPatrol), $FF);2301 FillChar(uixPatrol, SizeOf(uixPatrol), $FF); 2313 2302 for uix := 0 to RO.nUn - 1 do 2314 2303 with MyUnit[uix], MyModel[mix] do … … 2342 2331 Patrol(uix); 2343 2332 end; 2344 end; // AttackAndPatrol 2345 2346 2347 function TAI.HavePort: boolean; 2333 end; 2334 2335 function TAI.HavePort: Boolean; 2348 2336 var 2349 V8, cix, AdjacentLoc, f: integer;2337 V8, cix, AdjacentLoc, F: Integer; 2350 2338 Adjacent: TVicinity8Loc; 2351 2339 begin … … 2361 2349 if (AdjacentLoc >= 0) and ((Map[AdjacentLoc] and fTerrain) < fGrass) then 2362 2350 begin 2363 f:= Formation[AdjacentLoc];2364 if ( f >= 0) and (f < maxCOD) and (OceanPresence[f] and2365 not (1 shl me) <> 0) then2351 F := Formation[AdjacentLoc]; 2352 if (F >= 0) and (F < maxCOD) and (OceanPresence[F] and 2353 not (1 shl Me) <> 0) then 2366 2354 Result := True; 2367 2355 end; … … 2369 2357 end; 2370 2358 end; 2371 2372 2359 2373 2360 procedure TAI.SetCityProduction; 2374 2361 var 2375 2362 uix, cix, iix, dtr, V8, V21, NewImprovement, AdjacentLoc, MaxSettlers, 2376 maxcount, cixMilAcademy: integer;2377 TerrType: cardinal;2363 maxcount, cixMilAcademy: Integer; 2364 TerrType: Cardinal; 2378 2365 IsPort, IsNavalBase, NeedCruiser, CheckProd, Destructed, ProduceSettlers, 2379 ProduceMil: boolean;2366 ProduceMil: Boolean; 2380 2367 Adjacent: TVicinity8Loc; 2381 2368 Radius: TVicinity21Loc; 2382 2369 Report: TCityReport; 2383 HomeCount, CityProdRep: array[0..nCmax - 1] of integer;2384 MilProdCity: array[0..nCmax - 1] of boolean;2385 2386 procedure TryBuild(Improvement: integer);2370 HomeCount, CityProdRep: array[0..nCmax - 1] of Integer; 2371 MilProdCity: array[0..nCmax - 1] of Boolean; 2372 2373 procedure TryBuild(Improvement: Integer); 2387 2374 begin 2388 2375 if (NewImprovement = imTrGoods) // not already improvement of higher priority found … … 2394 2381 end; 2395 2382 2396 procedure TryDestruct(Improvement: integer);2383 procedure TryDestruct(Improvement: Integer); 2397 2384 begin 2398 2385 if Destructed or (MyCity[cix].Built[Improvement] = 0) then 2399 exit;2386 Exit; 2400 2387 if City_CurrentImprovementProject(cix) >= 0 then 2401 2388 City_RebuildImprovement(cix, Improvement) … … 2405 2392 and (Imp[CurrentImprovementProject].Kind in [ikCommon,ikNatGlobal,ikNatLocal]) 2406 2393 and ((Imp[CurrentImprovementProject].Cost*3-Imp[Improvement].Cost*2) 2407 *BuildCostMod[G.Difficulty[ me]]>MyCity[cix].Prod*(12*3)) then}2394 *BuildCostMod[G.Difficulty[Me]]>MyCity[cix].Prod*(12*3)) then} 2408 2395 Destructed := True; 2409 2396 end; 2410 2397 2411 function ChooseBuildModel(Cat: integer): integer;2398 function ChooseBuildModel(Cat: Integer): Integer; 2412 2399 var 2413 Count, mix: integer;2400 Count, mix: Integer; 2414 2401 begin 2415 2402 Count := 0; … … 2422 2409 Result := mix; 2423 2410 end; 2424 assert(Count > 0);2411 Assert(Count > 0); 2425 2412 end; 2426 2413 … … 2428 2415 // find military production cities 2429 2416 var 2430 cix, Total, d, Threshold, NewThreshold, Share, SharePlus, cixWorst: integer;2431 begin 2432 fillchar(MilProdCity, RO.nCity, 0);2417 cix, Total, D, Threshold, NewThreshold, Share, SharePlus, cixWorst: Integer; 2418 begin 2419 FillChar(MilProdCity, RO.nCity, 0); 2433 2420 GetCityProdPotential; 2434 for d:= 0 to maxCOD - 1 do2421 for D := 0 to maxCOD - 1 do 2435 2422 begin 2436 2423 Total := 0; 2437 2424 for cix := 0 to RO.nCity - 1 do 2438 2425 with MyCity[cix] do 2439 if (Loc >= 0) and (District[Loc] = d) then2426 if (Loc >= 0) and (District[Loc] = D) then 2440 2427 Total := Total + CityResult[cix]; 2441 2428 if Total = 0 then … … 2446 2433 for cix := 0 to RO.nCity - 1 do 2447 2434 with MyCity[cix] do 2448 if (Loc >= 0) and (District[Loc] = d) and2435 if (Loc >= 0) and (District[Loc] = D) and 2449 2436 (Built[imBarracks] + Built[imMilAcademy] > 0) then 2450 2437 begin … … 2461 2448 for cix := 0 to RO.nCity - 1 do 2462 2449 with MyCity[cix] do 2463 if (Loc >= 0) and (District[Loc] = d) and2450 if (Loc >= 0) and (District[Loc] = D) and 2464 2451 (Built[imBarracks] + Built[imMilAcademy] = 0) and 2465 2452 (Built[imObservatory] = 0) and (CityResult[cix] < Threshold) and … … 2478 2465 for cix := 0 to RO.nCity - 1 do 2479 2466 with MyCity[cix] do 2480 if (Loc >= 0) and (District[Loc] = d) and2467 if (Loc >= 0) and (District[Loc] = D) and 2481 2468 (Built[imBarracks] + Built[imMilAcademy] = 0) and 2482 2469 (CityResult[cix] >= Threshold) then … … 2484 2471 { if (cixWorst>=0) 2485 2472 and (Share-CityResult[cixWorst]*2>=Total*MilProdShare div 100) then 2486 MilProdCity[cixWorst]:= false;}2473 MilProdCity[cixWorst]:=False;} 2487 2474 end; 2488 2475 … … 2491 2478 if cixStateImp[imPalace] >= 0 then 2492 2479 begin 2493 d:= District[MyCity[cixStateImp[imPalace]].Loc];2494 if ( d >= 0) and (d< maxCOD) then2480 D := District[MyCity[cixStateImp[imPalace]].Loc]; 2481 if (D >= 0) and (D < maxCOD) then 2495 2482 begin 2496 2483 cixMilAcademy := -1; 2497 2484 for cix := 0 to RO.nCity - 1 do 2498 2485 with MyCity[cix] do 2499 if (Loc >= 0) and (District[Loc] = d) and2486 if (Loc >= 0) and (District[Loc] = D) and 2500 2487 (Built[imObservatory] + Built[imPalace] = 0) and 2501 2488 ((cixMilAcademy < 0) or (CityResult[cix] > CityResult[cixMilAcademy])) then … … 2513 2500 procedure ChangeHomeCities; 2514 2501 var 2515 uix, NewHome, HomeSupport, NewHomeSupport, SingleSupport: integer;2502 uix, NewHome, HomeSupport, NewHomeSupport, SingleSupport: Integer; 2516 2503 begin 2517 2504 if RO.Government in [gAnarchy, gFundamentalism] then 2518 exit;2505 Exit; 2519 2506 for uix := 0 to RO.nUn - 1 do 2520 2507 with MyUnit[uix] do … … 2564 2551 2565 2552 begin 2566 fillchar(HomeCount, 4 * RO.nCity, 0);2553 FillChar(HomeCount, 4 * RO.nCity, 0); 2567 2554 for uix := 0 to RO.nUn - 1 do 2568 2555 with MyUnit[uix] do … … 2757 2744 begin 2758 2745 TryBuild(imHarbor); 2759 break;2746 Break; 2760 2747 end; 2761 2748 end; … … 2775 2762 TryBuild(imRecycling); 2776 2763 if (Report.Trade - Report.Corruption >= 11) and 2777 (RO.Money < TotalPopulation[ me] * 2) then2764 (RO.Money < TotalPopulation[Me] * 2) then 2778 2765 TryBuild(imBank); 2779 2766 if (RO.NatBuilt[imStockEx] = 0) and … … 2812 2799 2813 2800 // rebuild imps no longer needed 2814 if (RO.TaxRate = 0) and (RO.Money >= TotalPopulation[ me] * 4) then2801 if (RO.TaxRate = 0) and (RO.Money >= TotalPopulation[Me] * 4) then 2815 2802 TryDestruct(imBank) 2816 2803 else if Report.Happy * 2 >= Size + 6 then … … 2836 2823 2837 2824 ChangeHomeCities; 2838 end; // SetCityProduction 2839 2840 2841 function TAI.ChooseGovernment: integer; 2825 end; 2826 2827 function TAI.ChooseGovernment: Integer; 2842 2828 begin 2843 2829 if Data.BehaviorFlags and bBarbarina <> 0 then … … 2856 2842 end; 2857 2843 2858 2859 2844 //------------------------------- 2860 2845 // DIPLOMACY 2861 2846 //------------------------------- 2862 2847 2863 function TAI.MostWanted(Nation, adGiveAway: integer): integer;2848 function TAI.MostWanted(Nation, adGiveAway: Integer): Integer; 2864 2849 var 2865 ad: integer;2850 ad: Integer; 2866 2851 begin 2867 2852 Result := -1; … … 2891 2876 end; 2892 2877 2893 procedure TAI.FindBestTrade(Nation: integer; var adWanted, adGiveAway: integer);2878 procedure TAI.FindBestTrade(Nation: Integer; var adWanted, adGiveAway: Integer); 2894 2879 var 2895 i, ad, ead, adTestGiveAway: integer;2880 I, ad, ead, adTestGiveAway: Integer; 2896 2881 begin 2897 2882 adWanted := -1; … … 2903 2888 begin 2904 2889 adTestGiveAway := -1; 2905 for i:= 0 to nRequestedTechs - 1 do2906 if (Data.RequestedTechs[ i] >= 0) and2907 (Data.RequestedTechs[ i] and $FFFF = Nation shl 8 + ead) then2890 for I := 0 to nRequestedTechs - 1 do 2891 if (Data.RequestedTechs[I] >= 0) and 2892 (Data.RequestedTechs[I] and $FFFF = Nation shl 8 + ead) then 2908 2893 adTestGiveAway := -2; // already requested before 2909 2894 if adTestGiveAway = -1 then … … 2928 2913 end; 2929 2914 2930 2931 function TAI.WantNegotiation(Nation: integer; NegoTime: TNegoTime): boolean; 2915 function TAI.WantNegotiation(Nation: Integer; NegoTime: TNegoTime): Boolean; 2932 2916 var 2933 p1, Count, adWanted, adGiveAway: integer;2917 p1, Count, adWanted, adGiveAway: Integer; 2934 2918 begin 2935 2919 if Data.BehaviorFlags and bBarbarina = bBarbarina then 2936 2920 begin 2937 2921 Result := Barbarina_WantNegotiation(Nation, NegoTime); 2938 exit;2922 Exit; 2939 2923 end; 2940 2924 … … 2944 2928 begin 2945 2929 Result := False; 2946 exit;2930 Exit; 2947 2931 end; 2948 2932 Count := 0; 2949 2933 for p1 := 0 to nPl - 1 do 2950 if (p1 <> me) and (1 shl p1 and RO.Alive <> 0) and (RO.Treaty[p1] >= trPeace) then2934 if (p1 <> Me) and (1 shl p1 and RO.Alive <> 0) and (RO.Treaty[p1] >= trPeace) then 2951 2935 Inc(Count); 2952 2936 if Count >= 3 then // enough peace made 2953 2937 begin 2954 2938 Result := False; 2955 exit;2939 Exit; 2956 2940 end; 2957 2941 end; … … 2994 2978 procedure TAI.DoNegotiation; 2995 2979 var 2996 i, adWanted, adGiveAway, adToGet, Slot: integer;2997 BuildFreeOffer: boolean;2980 I, adWanted, adGiveAway, adToGet, Slot: Integer; 2981 BuildFreeOffer: Boolean; 2998 2982 begin 2999 2983 if MyLastAction = scDipOffer then … … 3026 3010 begin 3027 3011 Barbarina_DoNegotiation; 3028 exit;3012 Exit; 3029 3013 end; 3030 3014 … … 3032 3016 begin 3033 3017 Barbarina_DoCheckNegotiation; 3034 exit;3018 Exit; 3035 3019 end; 3036 3020 … … 3047 3031 (OppoOffer.nDeliver + OppoOffer.nCost = 1) and 3048 3032 (OppoOffer.Price[0] and opMask = opTreaty) and 3049 ( integer(OppoOffer.Price[0] - opTreaty) > RO.Treaty[Opponent]) and3033 (Integer(OppoOffer.Price[0] - opTreaty) > RO.Treaty[Opponent]) and 3050 3034 ((OppoOffer.Price[0] - opTreaty < trAlliance) or 3051 3035 (RO.Tech[adScience] >= tsSeen)) then 3052 3036 MyAction := scDipAccept // accept all treaties 3053 3037 else if (RO.Treaty[Opponent] >= trPeace) and (OppoOffer.nDeliver = 1) and 3054 (OppoOffer.Price[0] and $FFFF0000 = opCivilReport + cardinal(Opponent) shl 16) and3038 (OppoOffer.Price[0] and $FFFF0000 = opCivilReport + Cardinal(Opponent) shl 16) and 3055 3039 (OppoOffer.nCost = 1) and (OppoOffer.Price[1] and $FFFF0000 = 3056 opCivilReport + cardinal(me) shl 16) then3040 opCivilReport + Cardinal(Me) shl 16) then 3057 3041 MyAction := scDipAccept // accept exchange of civil reports 3058 3042 else if (OppoOffer.nDeliver = 1) and (OppoOffer.nCost = 1) and … … 3084 3068 adWanted := MostWanted(Opponent, OppoOffer.Price[1] - opTech); 3085 3069 if (OppoOffer.Price[0] and opMask = opTech) and 3086 ( cardinal(adWanted) = OppoOffer.Price[0] - opTech) then3070 (Cardinal(adWanted) = OppoOffer.Price[0] - opTech) then 3087 3071 MyAction := scDipAccept // opponent's offer is already perfect 3088 3072 else if adWanted >= 0 then … … 3140 3124 MyOffer.Price[1] := opTech + adWanted; 3141 3125 MyAction := scDipOffer; 3142 for i:= 0 to nRequestedTechs - 1 do3143 if Data.RequestedTechs[ i] < 0 then3126 for I := 0 to nRequestedTechs - 1 do 3127 if Data.RequestedTechs[I] < 0 then 3144 3128 begin 3145 Slot := i;3146 break;3129 Slot := I; 3130 Break; 3147 3131 end 3148 else if ( i = 0) or (Data.RequestedTechs[i] shr 16 <3132 else if (I = 0) or (Data.RequestedTechs[I] shr 16 < 3149 3133 Data.RequestedTechs[Slot] shr 16) then // find most outdated entry 3150 Slot := i;3134 Slot := I; 3151 3135 Data.RequestedTechs[Slot] := RO.Turn shl 16 + Opponent shl 8 + adWanted; 3152 3136 end; 3153 3137 end; 3154 3138 end; 3155 end; // Negotiation 3156 3139 end; 3157 3140 3158 3141 procedure SetLeaveOutValue; 3159 3142 3160 procedure Process(ad: integer);3143 procedure Process(ad: Integer); 3161 3144 var 3162 i: integer;3145 I: Integer; 3163 3146 begin 3164 3147 if LeaveOutValue[ad] < 0 then 3165 3148 begin 3166 3149 LeaveOutValue[ad] := 0; 3167 for i:= 0 to 1 do3168 if AdvPreq[ad, i] >= 0 then3169 begin 3170 Process(AdvPreq[ad, i]);3171 if AdvPreq[ad, i] in LeaveOutTechs then3172 Inc(LeaveOutValue[ad], LeaveOutValue[AdvPreq[ad, i]] + 1);3150 for I := 0 to 1 do 3151 if AdvPreq[ad, I] >= 0 then 3152 begin 3153 Process(AdvPreq[ad, I]); 3154 if AdvPreq[ad, I] in LeaveOutTechs then 3155 Inc(LeaveOutValue[ad], LeaveOutValue[AdvPreq[ad, I]] + 1); 3173 3156 end; 3174 3157 end; … … 3176 3159 3177 3160 var 3178 ad: integer;3161 ad: Integer; 3179 3162 begin 3180 3163 FillChar(LeaveOutValue, SizeOf(LeaveOutValue), $FF); … … 3185 3168 3186 3169 initialization 3187 RWDataSize := sizeof(TPersistentData);3170 RWDataSize := SizeOf(TPersistentData); 3188 3171 SetLeaveOutValue; 3189 3172
Note:
See TracChangeset
for help on using the changeset viewer.