Changeset 447 for trunk/AI/StdAI/AI.pas
- Timestamp:
- May 19, 2022, 10:39:34 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/AI/StdAI/AI.pas
r442 r447 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 constructor TAI.Create(Nation: integer);176 LeaveOutValue: array[0..nAdv - 1] of Integer; 177 178 constructor TAI.Create(Nation: Integer); 179 179 begin 180 180 inherited; 181 Data := pointer(RO.Data);181 Data := Pointer(RO.Data); 182 182 {$IFDEF DEBUG} 183 183 if Nation = 1 then … … 192 192 begin 193 193 LastResearchTech := -1; 194 if PlayerHash[ me] > 7 then194 if PlayerHash[Me] > 7 then 195 195 BehaviorFlags := bFemale 196 196 else … … 198 198 DebugMessage(1, 'Gender:=' + char(48 + BehaviorFlags and bGender)); 199 199 TheologyPartner := -1; 200 fillchar(RejectTurn, sizeof(RejectTurn), $FF);201 Fillchar(RequestedTechs, sizeof(RequestedTechs), $FF);200 FillChar(RejectTurn, SizeOf(RejectTurn), $FF); 201 Fillchar(RequestedTechs, SizeOf(RequestedTechs), $FF); 202 202 end; 203 203 end; 204 204 205 function TAI.OnNegoRejected_CancelTreaty: boolean;205 function TAI.OnNegoRejected_CancelTreaty: Boolean; 206 206 begin 207 207 Data.RejectTurn[suContact, Opponent] := RO.Turn; … … 213 213 //------------------------------- 214 214 215 procedure TAI.RateModel(const mi: TModelInfo; var Category, Quality: integer);215 procedure TAI.RateModel(const mi: TModelInfo; var Category, Quality: Integer); 216 216 var 217 EffectiveTransport: integer;217 EffectiveTransport: Integer; 218 218 begin 219 219 if mi.Kind >= mkScout then 220 220 begin 221 221 Category := mctNone; 222 exit;222 Exit; 223 223 end; 224 224 case mi.Domain of … … 292 292 end; 293 293 294 procedure TAI.RateMyModel(mix: integer; var Category, Quality: integer);294 procedure TAI.RateMyModel(mix: Integer; var Category, Quality: Integer); 295 295 var 296 296 mi: TModelInfo; 297 297 begin 298 MakeModelInfo( me, mix, MyModel[mix], mi);298 MakeModelInfo(Me, mix, MyModel[mix], mi); 299 299 RateModel(mi, Category, Quality); 300 300 end; 301 301 302 function TAI.IsBetterModel(const mi: TModelInfo): boolean;302 function TAI.IsBetterModel(const mi: TModelInfo): Boolean; 303 303 var 304 mix, Cat, Quality, Cat1, Quality1: integer;304 mix, Cat, Quality, Cat1, Quality1: Integer; 305 305 begin 306 306 RateModel(mi, Cat, Quality); … … 312 312 begin 313 313 Result := False; 314 exit;314 Exit; 315 315 end; 316 316 end; … … 318 318 end; 319 319 320 function TAI.ChooseResearchAdvance: integer;320 function TAI.ChooseResearchAdvance: Integer; 321 321 var 322 adNext, iad, i, ad, Count, EarliestNeeded, EarliestNeeded_NoLeaveOut,323 NewResearch, StateOfArt, mix: integer;322 adNext, iad, I, ad, Count, EarliestNeeded, EarliestNeeded_NoLeaveOut, 323 NewResearch, StateOfArt, mix: Integer; 324 324 mi: TModelInfo; 325 Entry: array[0..nAdv - 1] of boolean;326 ok: boolean;327 328 function MarkEntry(ad: integer): boolean;325 Entry: array[0..nAdv - 1] of Boolean; 326 ok: Boolean; 327 328 function MarkEntry(ad: Integer): Boolean; 329 329 begin 330 330 if RO.Tech[ad] >= tsApplicable then … … 373 373 end; 374 374 375 procedure OptimizeDevModel(OptimizeCaps: integer);375 procedure OptimizeDevModel(OptimizeCaps: Integer); 376 376 var 377 f, Cat, OriginalCat, Quality, BestQuality, Best: integer;377 F, Cat, OriginalCat, Quality, BestQuality, Best: Integer; 378 378 mi: TModelInfo; 379 379 begin 380 MakeModelInfo( me, 0, RO.DevModel, mi);380 MakeModelInfo(Me, 0, RO.DevModel, mi); 381 381 RateModel(mi, OriginalCat, BestQuality); 382 382 repeat 383 383 Best := -1; 384 for f:= 0 to nFeature - 1 do385 if (1 shl fand OptimizeCaps <> 0) and386 ((Feature[ f].Preq < 0) or IsResearched(Feature[f].Preq)) // check prerequisite387 and (RO.DevModel.Weight + Feature[ f].Weight <= RO.DevModel.MaxWeight) and388 not (( f >= mcFirstNonCap) and (RO.DevModel.Cap[f] > 0)) then389 begin 390 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 391 391 begin 392 MakeModelInfo( me, 0, RO.DevModel, mi);392 MakeModelInfo(Me, 0, RO.DevModel, mi); 393 393 RateModel(mi, Cat, Quality); 394 assert(Cat = OriginalCat);394 Assert(Cat = OriginalCat); 395 395 if Quality > BestQuality then 396 396 begin 397 Best := f;397 Best := F; 398 398 BestQuality := Quality; 399 399 end; 400 SetNewModelFeature( f, RO.DevModel.Cap[f] - 1);400 SetNewModelFeature(F, RO.DevModel.Cap[F] - 1); 401 401 end; 402 402 end; … … 406 406 end; 407 407 408 function LeaveOutsMissing(ad: integer): boolean;408 function LeaveOutsMissing(ad: Integer): Boolean; 409 409 var 410 i: integer;410 I: Integer; 411 411 begin 412 412 Result := False; … … 422 422 Result := True 423 423 else 424 for i:= 0 to 1 do425 if AdvPreq[ad, i] >= 0 then426 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]); 427 427 end; 428 428 … … 432 432 Result := Barbarina_ChooseResearchAdvance; 433 433 if Result >= 0 then 434 exit;434 Exit; 435 435 end; 436 436 … … 444 444 Result := ad; 445 445 if Result >= 0 then 446 exit;446 Exit; 447 447 448 448 if Data.BehaviorFlags and bBarbarina = 0 then … … 460 460 OptimizeDevModel(1 shl mcOffense + 1 shl mcDefense + 1 shl 461 461 mcMob + 1 shl mcLongRange + 1 shl mcFanatic); 462 MakeModelInfo( me, 0, RO.DevModel, mi);462 MakeModelInfo(Me, 0, RO.DevModel, mi); 463 463 if IsBetterModel(mi) then 464 464 begin 465 465 Result := adMilitary; 466 exit;466 Exit; 467 467 end; 468 468 … … 471 471 SetNewModelFeature(mcOffense, 1); 472 472 OptimizeDevModel(1 shl mcOffense + 1 shl mcDefense + 1 shl mcFanatic); 473 MakeModelInfo( me, 0, RO.DevModel, mi);473 MakeModelInfo(Me, 0, RO.DevModel, mi); 474 474 if IsBetterModel(mi) then 475 475 begin 476 476 Result := adMilitary; 477 exit;477 Exit; 478 478 end; 479 479 end; … … 491 491 SetNewModelFeature(mcWeapons, 0); 492 492 SetNewModelFeature(mcDefense, 3); 493 exit;493 Exit; 494 494 end; 495 495 end; … … 506 506 OptimizeDevModel(1 shl mcDefense+1 shl mcSeaTrans+1 shl mcTurbines 507 507 +1 shl mcAirDef); 508 MakeModelInfo( me,0,RO.DevModel,mi);508 MakeModelInfo(Me,0,RO.DevModel,mi); 509 509 if IsBetterModel(mi) then 510 begin result:=adMilitary; exit end;510 begin Result:=adMilitary; Exit end; 511 511 end; 512 512 … … 519 519 OptimizeDevModel(1 shl mcOffense+1 shl mcDefense 520 520 +1 shl mcLongRange+1 shl mcAirDef+1 shl mcRadar); 521 MakeModelInfo( me,0,RO.DevModel,mi);521 MakeModelInfo(Me,0,RO.DevModel,mi); 522 522 if IsBetterModel(mi) then 523 begin result:=adMilitary; exit end;523 begin Result:=adMilitary; Exit end; 524 524 end 525 525 end; … … 545 545 begin 546 546 ok := True; 547 break;547 Break; 548 548 end; 549 549 if not ok then … … 588 588 begin // 2 of 3 required 589 589 Count := 0; 590 for i:= 0 to 2 do591 if RO.Tech[AdvPreq[ad, i]] >= tsApplicable then590 for I := 0 to 2 do 591 if RO.Tech[AdvPreq[ad, I]] >= tsApplicable then 592 592 Inc(Count); 593 593 if Count >= 2 then 594 594 begin 595 595 Result := ad; 596 exit;596 Exit; 597 597 end; 598 598 end … … 602 602 begin 603 603 Result := ad; 604 exit;604 Exit; 605 605 end; 606 606 end; … … 618 618 begin // go for future techs 619 619 Result := -1; 620 i:= 0;620 I := 0; 621 621 for ad := nAdv - 4 to nAdv - 1 do 622 622 if (RO.Tech[ad] < MaxFutureTech) and (RO.Tech[AdvPreq[ad, 0]] >= 623 623 tsApplicable) then 624 624 begin 625 Inc( i);626 if random( i) = 0 then625 Inc(I); 626 if random(I) = 0 then 627 627 Result := ad; 628 628 end; 629 assert((Result < 0) or AdvanceResearchable(Result));630 exit;631 end; 632 633 assert(NewResearch >= 0);634 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); 635 635 MarkEntry(NewResearch); 636 636 Result := -1; … … 638 638 if Entry[ad] and ((Result < 0) or (Advancedness[ad] > Advancedness[Result])) then 639 639 Result := ad; 640 assert(Result >= 0);640 Assert(Result >= 0); 641 641 end; 642 642 643 function TAI.ChooseStealAdvance: integer;643 function TAI.ChooseStealAdvance: Integer; 644 644 var 645 ad: integer;645 ad: Integer; 646 646 begin 647 647 Result := -1; … … 659 659 twpAllowFarmland = $0001; 660 660 661 procedure TAI.TileWorkPlan(Loc, cix: integer; var Value, NextJob, TotalWork: integer);661 procedure TAI.TileWorkPlan(Loc, cix: Integer; var Value, NextJob, TotalWork: Integer); 662 662 var 663 OldTile, TerrType: cardinal;663 OldTile, TerrType: Cardinal; 664 664 TileInfo: TTileInfo; 665 665 begin … … 669 669 begin 670 670 Value := 3 * 8 - 1; 671 exit;671 Exit; 672 672 end; // better than any tile with 2 food 673 673 … … 690 690 Map[Loc] := Map[Loc] and not fTerrain or fGrass; 691 691 TerrType := fGrass; 692 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); 693 693 end 694 694 else if IsResearched(adExplosives) and … … 701 701 Map[Loc] := Map[Loc] and not fTerrain or fGrass; 702 702 TerrType := fGrass; 703 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); 704 704 end; 705 705 if (Terrain[TerrType].MineEff > 0) and (RO.Government <> gDespotism) then … … 764 764 end; 765 765 end; 766 Server(sGetTileInfo, me, Loc, TileInfo);766 Server(sGetTileInfo, Me, Loc, TileInfo); 767 767 Value := TileInfo.Food * 8 + TileInfo.Prod * 2 + TileInfo.Trade; 768 768 Map[Loc] := OldTile; … … 772 772 procedure TAI.ProcessSettlers; 773 773 var 774 i, uix, cix, ecix, dtr, Loc, RadiusLoc, Special, Food, Prod, Trade,774 I, uix, cix, ecix, dtr, Loc, RadiusLoc, Special, Food, Prod, Trade, 775 775 CityFood, Happy, TestScore, BestNearCityScore, BestUnusedValue, 776 BestUnusedLoc, Value, NextJob, TotalWork, V21, part, Loc1: integer;777 Tile: cardinal;778 FoodOk, Started: boolean;776 BestUnusedLoc, Value, NextJob, TotalWork, V21, part, Loc1: Integer; 777 Tile: Cardinal; 778 FoodOk, Started: Boolean; 779 779 Radius: TVicinity21Loc; 780 780 CityAreaInfo: TCityAreaInfo; 781 TileFood, ResourceScore, CityScore: array[0..lxmax * lymax - 1] of integer;782 783 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); 784 784 // set Score=1 for low-priority jobs 785 785 begin … … 789 789 end; 790 790 791 procedure ReserveCityRadius(Loc: integer);791 procedure ReserveCityRadius(Loc: Integer); 792 792 var 793 V21, RadiusLoc: integer;793 V21, RadiusLoc: Integer; 794 794 Radius: TVicinity21Loc; 795 795 begin … … 808 808 procedure ScoreRoadConnections; 809 809 var 810 V8, nFragments, Loc, Loc1, History, RoadScore, a, b, FullyDeveloped,811 ConnectMask: integer;812 BridgeOk: boolean;810 V8, nFragments, Loc, Loc1, History, RoadScore, A, B, FullyDeveloped, 811 ConnectMask: Integer; 812 BridgeOk: Boolean; 813 813 Adjacent: TVicinity8Loc; 814 814 begin … … 821 821 if ((1 shl (Map[Loc] and fTerrain)) and (1 shl fOcean or 1 shl 822 822 fShore or 1 shl fDesert or 1 shl fArctic or 1 shl fUNKNOWN) = 0) and 823 (RO.Territory[Loc] = me) and (Map[Loc] and FullyDeveloped = 0) and823 (RO.Territory[Loc] = Me) and (Map[Loc] and FullyDeveloped = 0) and 824 824 (BridgeOk or (Map[Loc] and fRiver = 0)) then 825 825 begin … … 835 835 Loc1 := Adjacent[V8 and 7]; 836 836 History := History shl 1; 837 if (Loc1 >= 0) and (RO.Territory[Loc1] = me) and837 if (Loc1 >= 0) and (RO.Territory[Loc1] = Me) and 838 838 (Map[Loc1] and ConnectMask <> 0) then 839 839 begin … … 851 851 else if History and 4 <> 0 then 852 852 begin 853 V8_to_ab((V8 - 1) and 7, a, b);854 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); 855 855 if (Loc1 >= 0) and (Map[Loc1] and ConnectMask <> 0) then 856 856 Dec(nFragments); … … 876 876 877 877 begin 878 fillchar(SettlerSurplus, sizeof(SettlerSurplus), 0);878 FillChar(SettlerSurplus, SizeOf(SettlerSurplus), 0); 879 879 JobAssignment_Initialize; 880 880 881 881 if (Data.BehaviorFlags and bBarbarina = 0) or (RO.nCity < 3) then 882 882 begin 883 fillchar(TileFood, sizeof(TileFood), 0);884 fillchar(ResourceScore, sizeof(ResourceScore), 0);883 FillChar(TileFood, SizeOf(TileFood), 0); 884 FillChar(ResourceScore, SizeOf(ResourceScore), 0); 885 885 for Loc := 0 to MapSize - 1 do 886 886 if Map[Loc] and fTerrain <> fUNKNOWN then … … 923 923 924 924 // rate possible new cities 925 fillchar(CityScore, MapSize * sizeof(integer), 0);925 FillChar(CityScore, MapSize * SizeOf(Integer), 0); 926 926 for Loc := 0 to MapSize - 1 do 927 927 begin … … 930 930 ((RO.Government <> gDespotism) or (Map[Loc] and fSpecial = fSpecial1)) or 931 931 (Map[Loc] and (fTerrain or fSpecial) = fPrairie or fSpecial1)); 932 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 933 933 begin 934 934 TestScore := 0; … … 950 950 if CityFood >= MinCityFood then // city is worth founding 951 951 begin 952 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; 953 953 // some unexactness, random but always the same for this tile 954 954 if TestScore > BestNearCityScore then … … 988 988 if not (Map[RadiusLoc] and fTerrain in [fDesert, fArctic]) then 989 989 begin 990 assert(RadiusLoc >= 0);990 Assert(RadiusLoc >= 0); 991 991 TileWorkPlan(RadiusLoc, cix, Value, NextJob, TotalWork); 992 992 if (NextJob = jRoad) and (Built[imPalace] + … … 1000 1000 begin // tile could be exploited 1001 1001 RadiusLoc := Radius[V21]; 1002 assert(RadiusLoc >= 0);1002 Assert(RadiusLoc >= 0); 1003 1003 if not (Map[RadiusLoc] and fTerrain in [fDesert, fArctic]) then 1004 1004 begin … … 1024 1024 if Data.BehaviorFlags and bBarbarina = 0 then // low priority jobs 1025 1025 for Loc := 0 to MapSize - 1 do 1026 if RO.Territory[Loc] = me then1026 if RO.Territory[Loc] = Me then 1027 1027 begin 1028 1028 Tile := Map[Loc]; … … 1048 1048 begin 1049 1049 for part := 0 to nShipPart - 1 do 1050 for i:= 0 to ColonyShipPlan[part].nLocFoundCity - 1 do1051 begin 1052 Loc := ColonyShipPlan[part].LocFoundCity[ i];1050 for I := 0 to ColonyShipPlan[part].nLocFoundCity - 1 do 1051 begin 1052 Loc := ColonyShipPlan[part].LocFoundCity[I]; 1053 1053 Started := False; 1054 1054 for uix := 0 to RO.nUn - 1 do … … 1056 1056 begin 1057 1057 Started := True; 1058 break;1058 Break; 1059 1059 end; 1060 1060 if not Started then … … 1119 1119 begin // settlers could be added to this city 1120 1120 Happy := BasicHappy; 1121 for i:= 0 to nWonder - 1 do1122 if Built[ i] > 0 then1121 for I := 0 to nWonder - 1 do 1122 if Built[I] > 0 then 1123 1123 Inc(Happy); 1124 1124 if Built[imTemple] > 0 then … … 1127 1127 begin 1128 1128 Inc(Happy, 2); 1129 if RO.Wonder[woBach].EffectiveOwner = me then1129 if RO.Wonder[woBach].EffectiveOwner = Me then 1130 1130 Inc(Happy, 1); 1131 1131 end; … … 1150 1150 procedure TAI.DoTurn; 1151 1151 var 1152 emix, i, p1, TaxSum, ScienceSum, NewTaxRate: integer;1153 AllHateMe: boolean;1152 emix, I, p1, TaxSum, ScienceSum, NewTaxRate: Integer; 1153 AllHateMe: Boolean; 1154 1154 {$IFDEF PERF} 1155 1155 PF, t0, t1, t2, t3, t4, t5, t6, t7, t8, t9: int64; … … 1157 1157 begin 1158 1158 {$IFDEF DEBUG} 1159 fillchar(DebugMap, sizeof(DebugMap), 0);1159 FillChar(DebugMap, SizeOf(DebugMap), 0); 1160 1160 {$ENDIF} 1161 1161 … … 1169 1169 WarNations := PresenceUnknown; 1170 1170 for p1 := 0 to nPl - 1 do 1171 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 1172 1172 Inc(WarNations, 1 shl p1); 1173 1173 BombardingNations := 0; … … 1185 1185 CheckGender; 1186 1186 1187 if G.Difficulty[ me] < MaxDiff then // not on beginner level1187 if G.Difficulty[Me] < MaxDiff then // not on beginner level 1188 1188 begin 1189 1189 if (Data.LastResearchTech = adHorsebackRiding) and (RO.ResearchTech < 0) and 1190 1190 (random(6) = 0) and (HavePort or (ContinentPresence[0] and not 1191 (1 shl me or PresenceUnknown) <> 0)) then1191 (1 shl Me or PresenceUnknown) <> 0)) then 1192 1192 begin 1193 1193 Data.BehaviorFlags := Data.BehaviorFlags or bBarbarina_Hide; … … 1206 1206 begin 1207 1207 AllHateMe := False; 1208 break;1208 Break; 1209 1209 end; 1210 1210 if AllHateMe then … … 1302 1302 else 1303 1303 begin 1304 if (RO.TaxRate = 0) or (RO.Money < (TotalPopulation[ me] - 4) * 2) then1304 if (RO.TaxRate = 0) or (RO.Money < (TotalPopulation[Me] - 4) * 2) then 1305 1305 NewTaxRate := RO.TaxRate // don't check decreasing tax 1306 1306 else … … 1309 1309 begin 1310 1310 SumCities(NewTaxRate, TaxSum, ScienceSum); 1311 if RO.Money + TaxSum >= (TotalPopulation[ me] - 4) then1312 break; // enough1311 if RO.Money + TaxSum >= (TotalPopulation[Me] - 4) then 1312 Break; // enough 1313 1313 Inc(NewTaxRate, 10); 1314 1314 end; … … 1324 1324 // research completed 1325 1325 for p1 := 0 to nPl - 1 do 1326 if (p1 <> me) and (1 shl p1 and RO.Alive <> 0) and1326 if (p1 <> Me) and (1 shl p1 and RO.Alive <> 0) and 1327 1327 (RO.EnemyReport[p1].TurnOfCivilReport + TechReportOutdated > RO.Turn) and 1328 1328 (RO.EnemyReport[p1].Tech[Data.LastResearchTech] < tsSeen) then 1329 1329 begin // latest researched advance might be of interest to this nation 1330 for i:= 0 to nRequestedTechs - 1 do1331 if (Data.RequestedTechs[ i] >= 0) and1332 (Data.RequestedTechs[ i] shr 8 and $F = p1) then1333 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; 1334 1334 end; 1335 1335 if RO.ResearchTech = adMilitary then … … 1337 1337 else 1338 1338 Data.LastResearchTech := RO.ResearchTech; 1339 for i:= 0 to nRequestedTechs - 1 do1340 if (Data.RequestedTechs[ i] >= 0) and1341 (RO.Tech[Data.RequestedTechs[ i] and $FF] >= tsSeen) then1342 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; 1343 1343 1344 1344 // prepare negotiation … … 1348 1348 {$IFDEF DEBUG} 1349 1349 (*for p1:=0 to nPl-1 do 1350 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) 1351 1351 and (RO.EnemyReport[p1].TurnOfCivilReport>=0) then 1352 1352 TraceAdvanceValues(p1);*) … … 1363 1363 1364 1364 {$IFDEF DEBUG} 1365 procedure TAI.TraceAdvanceValues(Nation: integer);1365 procedure TAI.TraceAdvanceValues(Nation: Integer); 1366 1366 var 1367 ad: integer;1367 ad: Integer; 1368 1368 begin 1369 1369 for ad := 0 to nAdv - 1 do … … 1379 1379 procedure TAI.CheckGender; 1380 1380 var 1381 p1, NewGender: integer;1381 p1, NewGender: Integer; 1382 1382 begin 1383 1383 NewGender := -1; 1384 1384 for p1 := 0 to nPl - 1 do 1385 if (p1 <> me) and (1 shl p1 and RO.Alive <> 0) and1385 if (p1 <> Me) and (1 shl p1 and RO.Alive <> 0) and 1386 1386 (RO.Treaty[p1] >= trFriendlyContact) then 1387 if PlayerHash[ me] > PlayerHash[p1] then1387 if PlayerHash[Me] > PlayerHash[p1] then 1388 1388 begin 1389 1389 if NewGender = bMale then 1390 1390 begin 1391 1391 NewGender := -2; 1392 break;1392 Break; 1393 1393 end; // ambiguous, don't change gender 1394 1394 NewGender := bFemale; … … 1399 1399 begin 1400 1400 NewGender := -2; 1401 break;1401 Break; 1402 1402 end; // ambiguous, don't change gender 1403 1403 NewGender := bMale; … … 1412 1412 procedure TAI.SetAdvanceValues; 1413 1413 1414 procedure RateResearchAdv(ad, Time: integer);1414 procedure RateResearchAdv(ad, Time: Integer); 1415 1415 var 1416 Value: integer;1416 Value: Integer; 1417 1417 begin 1418 1418 if Time = 0 then … … 1424 1424 end; 1425 1425 1426 procedure SetPreqValues(ad, Value: integer);1426 procedure SetPreqValues(ad, Value: Integer); 1427 1427 begin 1428 1428 if (RO.Tech[ad] < tsSeen) and (ad <> RO.ResearchTech) then … … 1447 1447 end; 1448 1448 1449 procedure RateImpPreq(iix, Value: integer);1449 procedure RateImpPreq(iix, Value: Integer); 1450 1450 begin 1451 1451 if (Value > 0) and (Imp[iix].Preq >= 0) then … … 1454 1454 1455 1455 var 1456 emix, cix, adMissing, iad, ad, Count, i, Time, d, CurrentCost,1457 CurrentStrength, MaxSize, MaxTrade: integer;1458 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; 1459 1459 begin 1460 1460 if AdvanceValuesSet then 1461 exit;1461 Exit; 1462 1462 AdvanceValuesSet := True; 1463 1463 1464 fillchar(AdvanceValue, sizeof(AdvanceValue), 0);1464 FillChar(AdvanceValue, SizeOf(AdvanceValue), 0); 1465 1465 1466 1466 // rate techs to ensure research progress … … 1482 1482 begin // 2 of 3 required 1483 1483 Count := 0; 1484 for i:= 0 to 2 do1485 if (AdvPreq[ad, i] = RO.ResearchTech) or1486 (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 1487 1487 Inc(Count); 1488 1488 if Count >= 2 then … … 1492 1492 if ad <> adMassProduction then // don't score third preq for MP 1493 1493 begin 1494 for i:= 0 to 2 do1495 if (AdvPreq[ad, i] <> RO.ResearchTech) and1496 (RO.Tech[AdvPreq[ad, i]] < tsSeen) then1497 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); 1498 1498 end; 1499 1499 Inc(Time, 2 - Count); … … 1503 1503 begin 1504 1504 Count := 0; 1505 for i:= 0 to 1 do1506 if (AdvPreq[ad, i] <> preNone) and (AdvPreq[ad, i] <> RO.ResearchTech) and1507 (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 1508 1508 begin 1509 RateResearchAdv(AdvPreq[ad, i], Time);1509 RateResearchAdv(AdvPreq[ad, I], Time); 1510 1510 Inc(Count); 1511 1511 end; … … 1536 1536 1537 1537 // rate military techs 1538 for d:= 0 to nDomains - 1 do1538 for D := 0 to nDomains - 1 do 1539 1539 begin 1540 1540 CurrentCost := 0; 1541 1541 CurrentStrength := 0; 1542 1542 for PreView := True downto False do 1543 for i:= 0 to nUpgrade - 1 do1544 with Upgrade[ d, i] do1543 for I := 0 to nUpgrade - 1 do 1544 with Upgrade[D, I] do 1545 1545 if (Preq >= 0) and not (Preq in FutureTech) then 1546 1546 if ((Ro.ResearchTech = Preq) or (RO.Tech[Preq] >= tsSeen)) = PreView then … … 1553 1553 else 1554 1554 begin // rate 1555 if ( i> 0) and (Trans > 0) then1555 if (I > 0) and (Trans > 0) then 1556 1556 Inc(AdvanceValue[Preq], $400); 1557 1557 if Cost <= CurrentCost then 1558 Inc(AdvanceValue[Preq], (4 - d) * Strength * $400 div1559 (CurrentStrength + Upgrade[ d, 0].Strength))1558 Inc(AdvanceValue[Preq], (4 - D) * Strength * $400 div 1559 (CurrentStrength + Upgrade[D, 0].Strength)) 1560 1560 else 1561 Inc(AdvanceValue[Preq], (4 - d) * Strength * $200 div1562 (CurrentStrength + Upgrade[ d, 0].Strength));1561 Inc(AdvanceValue[Preq], (4 - D) * Strength * $200 div 1562 (CurrentStrength + Upgrade[D, 0].Strength)); 1563 1563 end; 1564 1564 end; … … 1640 1640 procedure TAI.AnalyzeMap; 1641 1641 var 1642 cix, Loc, Loc1, V8, f1, p1: integer;1642 cix, Loc, Loc1, V8, f1, p1: Integer; 1643 1643 Adjacent: TVicinity8Loc; 1644 1644 begin … … 1646 1646 1647 1647 // collect nation presence information for continents and oceans 1648 fillchar(ContinentPresence, sizeof(ContinentPresence), 0);1649 fillchar(OceanPresence, sizeof(OceanPresence), 0);1648 FillChar(ContinentPresence, SizeOf(ContinentPresence), 0); 1649 FillChar(OceanPresence, SizeOf(OceanPresence), 0); 1650 1650 for Loc := 0 to MapSize - 1 do 1651 1651 begin … … 1699 1699 end; 1700 1700 1701 fillchar(TotalPopulation, sizeof(TotalPopulation), 0);1702 fillchar(ContinentPopulation, sizeof(ContinentPopulation), 0);1703 fillchar(DistrictPopulation, 4 * nDistrict, 0);1701 FillChar(TotalPopulation, SizeOf(TotalPopulation), 0); 1702 FillChar(ContinentPopulation, SizeOf(ContinentPopulation), 0); 1703 FillChar(DistrictPopulation, 4 * nDistrict, 0); 1704 1704 1705 1705 // count population … … 1716 1716 if Loc >= 0 then 1717 1717 begin 1718 Inc(TotalPopulation[ me], Size);1719 assert(District[Loc] >= 0);1718 Inc(TotalPopulation[Me], Size); 1719 Assert(District[Loc] >= 0); 1720 1720 if District[Loc] < maxCOD then 1721 1721 Inc(DistrictPopulation[District[Loc]], Size); … … 1725 1725 procedure TAI.CollectModelCatStat; 1726 1726 var 1727 i, uix, Cat, mix, Quality: integer;1727 I, uix, Cat, mix, Quality: Integer; 1728 1728 begin 1729 1729 // categorize models … … 1771 1771 if (Loc >= 0) and (mix = mixCruiser) and (Map[Loc] and fTerrain < fGrass) then 1772 1772 begin 1773 i:= Formation[Loc];1774 if ( i >= 0) and (i< maxCOD) then1775 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); 1776 1776 end; 1777 1777 end; … … 1780 1780 const 1781 1781 PatrolDestination = lxmax * lymax; 1782 FirstSurplusLoop: array[mctGroundDefender..mctGroundAttacker] of integer = (2, 1);1782 FirstSurplusLoop: array[mctGroundDefender..mctGroundAttacker] of Integer = (2, 1); 1783 1783 var 1784 Cat, i, mix, cix, uix, Loop, nModelOrder: integer;1784 Cat, I, mix, cix, uix, Loop, nModelOrder: Integer; 1785 1785 Adjacent: TVicinity8Loc; 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;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; 1793 1793 var 1794 Loc1, V8: integer;1794 Loc1, V8: Integer; 1795 1795 Adjacent: TVicinity8Loc; 1796 1796 begin … … 1809 1809 begin 1810 1810 Result := True; 1811 exit;1811 Exit; 1812 1812 end; 1813 1813 end; … … 1815 1815 end; 1816 1816 1817 procedure TryUtilize(uix: integer);1817 procedure TryUtilize(uix: Integer); 1818 1818 var 1819 cix, ProdCost, UtilizeCost: integer;1819 cix, ProdCost, UtilizeCost: Integer; 1820 1820 begin 1821 1821 if (MyUnit[uix].Health = 100) and (Map[MyUnit[uix].Loc] and … … 1829 1829 UtilizeCost := MyModel[MyUnit[uix].mix].Cost; 1830 1830 if Prod < (ProdCost - UtilizeCost * 2 div 3) * 1831 BuildCostMod[G.Difficulty[ me]] div 12 then1831 BuildCostMod[G.Difficulty[Me]] div 12 then 1832 1832 Unit_Disband(uix); 1833 1833 end; … … 1835 1835 end; 1836 1836 1837 procedure FindDestination(uix: integer);1837 procedure FindDestination(uix: Integer); 1838 1838 var 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);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); 1843 1843 Pile.Create(MapSize); 1844 1844 with MyUnit[uix] do … … 1854 1854 if (District[Loc1] >= 0) and (District[Loc1] < maxCOD) then 1855 1855 begin 1856 assert(DistrictNeed[District[Loc1]] > 0);1856 Assert(DistrictNeed[District[Loc1]] > 0); 1857 1857 Dec(DistrictNeed[District[Loc1]]); 1858 1858 end; 1859 1859 Destination[uix] := Loc1; 1860 break;1860 Break; 1861 1861 end; 1862 1862 Reached[Loc1] := True; … … 1865 1865 begin 1866 1866 NextLoc := Adjacent[V8]; 1867 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 1868 1868 case CheckStep(MoveStyle, Time, V8 and 1, NextTime, RecoverTurns, 1869 1869 Map[Loc1], Map[NextLoc], False) of … … 1873 1873 Reached[NextLoc] := True; // don't check moving there again 1874 1874 csCheckTerritory: 1875 assert(False);1875 Assert(False); 1876 1876 end; 1877 1877 end; … … 1887 1887 Unit_Disband(uix); 1888 1888 1889 fillchar(UnitLack, sizeof(UnitLack), 0);1890 fillchar(Destination, 4 * RO.nUn, $FF);1891 for i:= 0 to maxCOD - 1 do1892 if uixPatrol[ i] >= 0 then1893 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; 1894 1894 for uix := 0 to RO.nUn - 1 do 1895 1895 if (MyUnit[uix].mix = mixMilitia) or (MyUnit[uix].mix = mixCruiser) then … … 1903 1903 if ModelCat[mix] = Cat then 1904 1904 begin 1905 i:= nModelOrder;1906 while ( i > 0) and (ModelQuality[mix] < ModelQuality[ModelOrder[i- 1]]) do1907 begin 1908 ModelOrder[ i] := ModelOrder[i- 1];1909 Dec( i);1910 end; 1911 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; 1912 1912 Inc(nModelOrder); 1913 1913 end; … … 1922 1922 TryUtilize(uix); 1923 1923 1924 fillchar(LocNeed, MapSize, 0);1925 fillchar(DistrictNeed, sizeof(DistrictNeed), 0);1924 FillChar(LocNeed, MapSize, 0); 1925 FillChar(DistrictNeed, SizeOf(DistrictNeed), 0); 1926 1926 1927 1927 for cix := 0 to RO.nCity - 1 do … … 1946 1946 for uix := 0 to RO.nUn - 1 do 1947 1947 with MyUnit[uix] do 1948 if (Loc >= 0) and (Job = jCity) and (RO.Territory[Loc] = me) then1948 if (Loc >= 0) and (Job = jCity) and (RO.Territory[Loc] = Me) then 1949 1949 begin 1950 1950 LocNeed[Loc] := 1; … … 1954 1954 1955 1955 complete := Loop >= FirstSurplusLoop[Cat]; 1956 for i:= nModelOrder - 1 downto 0 do1956 for I := nModelOrder - 1 downto 0 do 1957 1957 begin 1958 1958 for Fortified := True downto False do 1959 1959 for uix := 0 to RO.nUn - 1 do 1960 1960 with MyUnit[uix] do 1961 if (mix = ModelOrder[ i]) and (Loc >= 0) and1961 if (mix = ModelOrder[I]) and (Loc >= 0) and 1962 1962 (Destination[uix] < 0) and (Master < 0) and 1963 1963 ((Flags and unFortified <> 0) = Fortified) and (LocNeed[Loc] > 0) then … … 1972 1972 for uix := 0 to RO.nUn - 1 do 1973 1973 with MyUnit[uix] do 1974 if (mix = ModelOrder[ i]) and (Loc >= 0) and (Destination[uix] < 0) and1974 if (mix = ModelOrder[I]) and (Loc >= 0) and (Destination[uix] < 0) and 1975 1975 (Master < 0) then 1976 1976 if (District[Loc] >= 0) and (District[Loc] < maxCOD) and … … 1989 1989 // distribute obsolete settlers 1990 1990 repeat 1991 fillchar(LocNeed, MapSize, 0);1992 fillchar(DistrictNeed, sizeof(DistrictNeed), 0);1991 FillChar(LocNeed, MapSize, 0); 1992 FillChar(DistrictNeed, SizeOf(DistrictNeed), 0); 1993 1993 1994 1994 for cix := 0 to RO.nCity - 1 do … … 2040 2040 for uix := 0 to RO.nUn - 1 do 2041 2041 with MyUnit[uix] do 2042 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 2043 2043 (District[Loc] < maxCOD) and (ModelQuality[mix] > 0) then 2044 2044 case ModelCat[mix] of … … 2048 2048 end; 2049 2049 2050 procedure TAI.CheckAttack(uix: integer);2050 procedure TAI.CheckAttack(uix: Integer); 2051 2051 var 2052 2052 AttackScore, BestCount, AttackLoc, TestLoc, NextLoc, TestTime, V8, 2053 2053 TestScore, euix, MyDamage, EnemyDamage, OldLoc, AttackForecast, 2054 MoveResult, AttackResult, MoveStyle, NextTime, RecoverTurns: integer;2055 Tile: cardinal;2056 Exhausted: boolean;2054 MoveResult, AttackResult, MoveStyle, NextTime, RecoverTurns: Integer; 2055 Tile: Cardinal; 2056 Exhausted: Boolean; 2057 2057 Adjacent: TVicinity8Loc; 2058 Reached: array[0..lxmax * lymax - 1] of boolean;2058 Reached: array[0..lxmax * lymax - 1] of Boolean; 2059 2059 2060 2060 begin … … 2065 2065 AttackScore := -999999; 2066 2066 AttackLoc := -1; 2067 fillchar(Reached, MapSize, False);2067 FillChar(Reached, MapSize, False); 2068 2068 Pile.Create(MapSize); 2069 2069 Pile.Put(Loc, $800 - Movement); … … 2077 2077 if ((Tile and fUnit) <> 0) and ((Tile and fOwned) = 0) then 2078 2078 begin // enemy unit 2079 assert(TestTime < $1000);2079 Assert(TestTime < $1000); 2080 2080 Unit_FindEnemyDefender(TestLoc, euix); 2081 2081 if RO.Treaty[RO.EnemyUn[euix].Owner] < trPeace then … … 2168 2168 end; 2169 2169 2170 procedure TAI.Patrol(uix: integer);2170 procedure TAI.Patrol(uix: Integer); 2171 2171 const 2172 2172 DistanceScore = 4; 2173 2173 var 2174 2174 PatrolScore, BestCount, PatrolLoc, TestLoc, NextLoc, TestTime, V8, 2175 TestScore, OldLoc, MoveResult, MoveStyle, NextTime, RecoverTurns: integer;2176 Tile: cardinal;2177 Exhausted, CaptureOnly: boolean;2175 TestScore, OldLoc, MoveResult, MoveStyle, NextTime, RecoverTurns: Integer; 2176 Tile: Cardinal; 2177 Exhausted, CaptureOnly: Boolean; 2178 2178 Adjacent: TVicinity8Loc; 2179 AdjacentUnknown: array[0..lxmax * lymax - 1] of shortint;2179 AdjacentUnknown: array[0..lxmax * lymax - 1] of ShortInt; 2180 2180 2181 2181 begin … … 2196 2196 // assume a score of 50 is the best achievable 2197 2197 or CaptureOnly and (TestTime >= $1000) then 2198 break;2198 Break; 2199 2199 2200 2200 TestScore := 0; … … 2276 2276 const 2277 2277 nAttackCatOrder = 3; 2278 AttackCatOrder: array[0..nAttackCatOrder - 1] of integer =2278 AttackCatOrder: array[0..nAttackCatOrder - 1] of Integer = 2279 2279 (mctGroundAttacker, mctCruiser, mctGroundDefender); 2280 2280 var 2281 iCat, uix, uix1: integer;2282 IsPatrolUnit, Fortified: boolean;2281 iCat, uix, uix1: Integer; 2282 IsPatrolUnit, Fortified: Boolean; 2283 2283 begin 2284 2284 for uix := 0 to RO.nUn - 1 do … … 2299 2299 CheckAttack(uix); 2300 2300 2301 fillchar(uixPatrol, sizeof(uixPatrol), $FF);2301 FillChar(uixPatrol, SizeOf(uixPatrol), $FF); 2302 2302 for uix := 0 to RO.nUn - 1 do 2303 2303 with MyUnit[uix], MyModel[mix] do … … 2333 2333 end; 2334 2334 2335 function TAI.HavePort: boolean;2335 function TAI.HavePort: Boolean; 2336 2336 var 2337 V8, cix, AdjacentLoc, f: integer;2337 V8, cix, AdjacentLoc, F: Integer; 2338 2338 Adjacent: TVicinity8Loc; 2339 2339 begin … … 2349 2349 if (AdjacentLoc >= 0) and ((Map[AdjacentLoc] and fTerrain) < fGrass) then 2350 2350 begin 2351 f:= Formation[AdjacentLoc];2352 if ( f >= 0) and (f < maxCOD) and (OceanPresence[f] and2353 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 2354 2354 Result := True; 2355 2355 end; … … 2361 2361 var 2362 2362 uix, cix, iix, dtr, V8, V21, NewImprovement, AdjacentLoc, MaxSettlers, 2363 maxcount, cixMilAcademy: integer;2364 TerrType: cardinal;2363 maxcount, cixMilAcademy: Integer; 2364 TerrType: Cardinal; 2365 2365 IsPort, IsNavalBase, NeedCruiser, CheckProd, Destructed, ProduceSettlers, 2366 ProduceMil: boolean;2366 ProduceMil: Boolean; 2367 2367 Adjacent: TVicinity8Loc; 2368 2368 Radius: TVicinity21Loc; 2369 2369 Report: TCityReport; 2370 HomeCount, CityProdRep: array[0..nCmax - 1] of integer;2371 MilProdCity: array[0..nCmax - 1] of boolean;2372 2373 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); 2374 2374 begin 2375 2375 if (NewImprovement = imTrGoods) // not already improvement of higher priority found … … 2381 2381 end; 2382 2382 2383 procedure TryDestruct(Improvement: integer);2383 procedure TryDestruct(Improvement: Integer); 2384 2384 begin 2385 2385 if Destructed or (MyCity[cix].Built[Improvement] = 0) then 2386 exit;2386 Exit; 2387 2387 if City_CurrentImprovementProject(cix) >= 0 then 2388 2388 City_RebuildImprovement(cix, Improvement) … … 2392 2392 and (Imp[CurrentImprovementProject].Kind in [ikCommon,ikNatGlobal,ikNatLocal]) 2393 2393 and ((Imp[CurrentImprovementProject].Cost*3-Imp[Improvement].Cost*2) 2394 *BuildCostMod[G.Difficulty[ me]]>MyCity[cix].Prod*(12*3)) then}2394 *BuildCostMod[G.Difficulty[Me]]>MyCity[cix].Prod*(12*3)) then} 2395 2395 Destructed := True; 2396 2396 end; 2397 2397 2398 function ChooseBuildModel(Cat: integer): integer;2398 function ChooseBuildModel(Cat: Integer): Integer; 2399 2399 var 2400 Count, mix: integer;2400 Count, mix: Integer; 2401 2401 begin 2402 2402 Count := 0; … … 2409 2409 Result := mix; 2410 2410 end; 2411 assert(Count > 0);2411 Assert(Count > 0); 2412 2412 end; 2413 2413 … … 2415 2415 // find military production cities 2416 2416 var 2417 cix, Total, d, Threshold, NewThreshold, Share, SharePlus, cixWorst: integer;2418 begin 2419 fillchar(MilProdCity, RO.nCity, 0);2417 cix, Total, D, Threshold, NewThreshold, Share, SharePlus, cixWorst: Integer; 2418 begin 2419 FillChar(MilProdCity, RO.nCity, 0); 2420 2420 GetCityProdPotential; 2421 for d:= 0 to maxCOD - 1 do2421 for D := 0 to maxCOD - 1 do 2422 2422 begin 2423 2423 Total := 0; 2424 2424 for cix := 0 to RO.nCity - 1 do 2425 2425 with MyCity[cix] do 2426 if (Loc >= 0) and (District[Loc] = d) then2426 if (Loc >= 0) and (District[Loc] = D) then 2427 2427 Total := Total + CityResult[cix]; 2428 2428 if Total = 0 then … … 2433 2433 for cix := 0 to RO.nCity - 1 do 2434 2434 with MyCity[cix] do 2435 if (Loc >= 0) and (District[Loc] = d) and2435 if (Loc >= 0) and (District[Loc] = D) and 2436 2436 (Built[imBarracks] + Built[imMilAcademy] > 0) then 2437 2437 begin … … 2448 2448 for cix := 0 to RO.nCity - 1 do 2449 2449 with MyCity[cix] do 2450 if (Loc >= 0) and (District[Loc] = d) and2450 if (Loc >= 0) and (District[Loc] = D) and 2451 2451 (Built[imBarracks] + Built[imMilAcademy] = 0) and 2452 2452 (Built[imObservatory] = 0) and (CityResult[cix] < Threshold) and … … 2465 2465 for cix := 0 to RO.nCity - 1 do 2466 2466 with MyCity[cix] do 2467 if (Loc >= 0) and (District[Loc] = d) and2467 if (Loc >= 0) and (District[Loc] = D) and 2468 2468 (Built[imBarracks] + Built[imMilAcademy] = 0) and 2469 2469 (CityResult[cix] >= Threshold) then … … 2471 2471 { if (cixWorst>=0) 2472 2472 and (Share-CityResult[cixWorst]*2>=Total*MilProdShare div 100) then 2473 MilProdCity[cixWorst]:= false;}2473 MilProdCity[cixWorst]:=False;} 2474 2474 end; 2475 2475 … … 2478 2478 if cixStateImp[imPalace] >= 0 then 2479 2479 begin 2480 d:= District[MyCity[cixStateImp[imPalace]].Loc];2481 if ( d >= 0) and (d< maxCOD) then2480 D := District[MyCity[cixStateImp[imPalace]].Loc]; 2481 if (D >= 0) and (D < maxCOD) then 2482 2482 begin 2483 2483 cixMilAcademy := -1; 2484 2484 for cix := 0 to RO.nCity - 1 do 2485 2485 with MyCity[cix] do 2486 if (Loc >= 0) and (District[Loc] = d) and2486 if (Loc >= 0) and (District[Loc] = D) and 2487 2487 (Built[imObservatory] + Built[imPalace] = 0) and 2488 2488 ((cixMilAcademy < 0) or (CityResult[cix] > CityResult[cixMilAcademy])) then … … 2500 2500 procedure ChangeHomeCities; 2501 2501 var 2502 uix, NewHome, HomeSupport, NewHomeSupport, SingleSupport: integer;2502 uix, NewHome, HomeSupport, NewHomeSupport, SingleSupport: Integer; 2503 2503 begin 2504 2504 if RO.Government in [gAnarchy, gFundamentalism] then 2505 exit;2505 Exit; 2506 2506 for uix := 0 to RO.nUn - 1 do 2507 2507 with MyUnit[uix] do … … 2551 2551 2552 2552 begin 2553 fillchar(HomeCount, 4 * RO.nCity, 0);2553 FillChar(HomeCount, 4 * RO.nCity, 0); 2554 2554 for uix := 0 to RO.nUn - 1 do 2555 2555 with MyUnit[uix] do … … 2744 2744 begin 2745 2745 TryBuild(imHarbor); 2746 break;2746 Break; 2747 2747 end; 2748 2748 end; … … 2762 2762 TryBuild(imRecycling); 2763 2763 if (Report.Trade - Report.Corruption >= 11) and 2764 (RO.Money < TotalPopulation[ me] * 2) then2764 (RO.Money < TotalPopulation[Me] * 2) then 2765 2765 TryBuild(imBank); 2766 2766 if (RO.NatBuilt[imStockEx] = 0) and … … 2799 2799 2800 2800 // rebuild imps no longer needed 2801 if (RO.TaxRate = 0) and (RO.Money >= TotalPopulation[ me] * 4) then2801 if (RO.TaxRate = 0) and (RO.Money >= TotalPopulation[Me] * 4) then 2802 2802 TryDestruct(imBank) 2803 2803 else if Report.Happy * 2 >= Size + 6 then … … 2825 2825 end; 2826 2826 2827 function TAI.ChooseGovernment: integer;2827 function TAI.ChooseGovernment: Integer; 2828 2828 begin 2829 2829 if Data.BehaviorFlags and bBarbarina <> 0 then … … 2846 2846 //------------------------------- 2847 2847 2848 function TAI.MostWanted(Nation, adGiveAway: integer): integer;2848 function TAI.MostWanted(Nation, adGiveAway: Integer): Integer; 2849 2849 var 2850 ad: integer;2850 ad: Integer; 2851 2851 begin 2852 2852 Result := -1; … … 2876 2876 end; 2877 2877 2878 procedure TAI.FindBestTrade(Nation: integer; var adWanted, adGiveAway: integer);2878 procedure TAI.FindBestTrade(Nation: Integer; var adWanted, adGiveAway: Integer); 2879 2879 var 2880 i, ad, ead, adTestGiveAway: integer;2880 I, ad, ead, adTestGiveAway: Integer; 2881 2881 begin 2882 2882 adWanted := -1; … … 2888 2888 begin 2889 2889 adTestGiveAway := -1; 2890 for i:= 0 to nRequestedTechs - 1 do2891 if (Data.RequestedTechs[ i] >= 0) and2892 (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 2893 2893 adTestGiveAway := -2; // already requested before 2894 2894 if adTestGiveAway = -1 then … … 2913 2913 end; 2914 2914 2915 function TAI.WantNegotiation(Nation: integer; NegoTime: TNegoTime): boolean;2915 function TAI.WantNegotiation(Nation: Integer; NegoTime: TNegoTime): Boolean; 2916 2916 var 2917 p1, Count, adWanted, adGiveAway: integer;2917 p1, Count, adWanted, adGiveAway: Integer; 2918 2918 begin 2919 2919 if Data.BehaviorFlags and bBarbarina = bBarbarina then 2920 2920 begin 2921 2921 Result := Barbarina_WantNegotiation(Nation, NegoTime); 2922 exit;2922 Exit; 2923 2923 end; 2924 2924 … … 2928 2928 begin 2929 2929 Result := False; 2930 exit;2930 Exit; 2931 2931 end; 2932 2932 Count := 0; 2933 2933 for p1 := 0 to nPl - 1 do 2934 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 2935 2935 Inc(Count); 2936 2936 if Count >= 3 then // enough peace made 2937 2937 begin 2938 2938 Result := False; 2939 exit;2939 Exit; 2940 2940 end; 2941 2941 end; … … 2978 2978 procedure TAI.DoNegotiation; 2979 2979 var 2980 i, adWanted, adGiveAway, adToGet, Slot: integer;2981 BuildFreeOffer: boolean;2980 I, adWanted, adGiveAway, adToGet, Slot: Integer; 2981 BuildFreeOffer: Boolean; 2982 2982 begin 2983 2983 if MyLastAction = scDipOffer then … … 3010 3010 begin 3011 3011 Barbarina_DoNegotiation; 3012 exit;3012 Exit; 3013 3013 end; 3014 3014 … … 3016 3016 begin 3017 3017 Barbarina_DoCheckNegotiation; 3018 exit;3018 Exit; 3019 3019 end; 3020 3020 … … 3031 3031 (OppoOffer.nDeliver + OppoOffer.nCost = 1) and 3032 3032 (OppoOffer.Price[0] and opMask = opTreaty) and 3033 ( integer(OppoOffer.Price[0] - opTreaty) > RO.Treaty[Opponent]) and3033 (Integer(OppoOffer.Price[0] - opTreaty) > RO.Treaty[Opponent]) and 3034 3034 ((OppoOffer.Price[0] - opTreaty < trAlliance) or 3035 3035 (RO.Tech[adScience] >= tsSeen)) then 3036 3036 MyAction := scDipAccept // accept all treaties 3037 3037 else if (RO.Treaty[Opponent] >= trPeace) and (OppoOffer.nDeliver = 1) and 3038 (OppoOffer.Price[0] and $FFFF0000 = opCivilReport + cardinal(Opponent) shl 16) and3038 (OppoOffer.Price[0] and $FFFF0000 = opCivilReport + Cardinal(Opponent) shl 16) and 3039 3039 (OppoOffer.nCost = 1) and (OppoOffer.Price[1] and $FFFF0000 = 3040 opCivilReport + cardinal(me) shl 16) then3040 opCivilReport + Cardinal(Me) shl 16) then 3041 3041 MyAction := scDipAccept // accept exchange of civil reports 3042 3042 else if (OppoOffer.nDeliver = 1) and (OppoOffer.nCost = 1) and … … 3068 3068 adWanted := MostWanted(Opponent, OppoOffer.Price[1] - opTech); 3069 3069 if (OppoOffer.Price[0] and opMask = opTech) and 3070 ( cardinal(adWanted) = OppoOffer.Price[0] - opTech) then3070 (Cardinal(adWanted) = OppoOffer.Price[0] - opTech) then 3071 3071 MyAction := scDipAccept // opponent's offer is already perfect 3072 3072 else if adWanted >= 0 then … … 3124 3124 MyOffer.Price[1] := opTech + adWanted; 3125 3125 MyAction := scDipOffer; 3126 for i:= 0 to nRequestedTechs - 1 do3127 if Data.RequestedTechs[ i] < 0 then3126 for I := 0 to nRequestedTechs - 1 do 3127 if Data.RequestedTechs[I] < 0 then 3128 3128 begin 3129 Slot := i;3130 break;3129 Slot := I; 3130 Break; 3131 3131 end 3132 else if ( i = 0) or (Data.RequestedTechs[i] shr 16 <3132 else if (I = 0) or (Data.RequestedTechs[I] shr 16 < 3133 3133 Data.RequestedTechs[Slot] shr 16) then // find most outdated entry 3134 Slot := i;3134 Slot := I; 3135 3135 Data.RequestedTechs[Slot] := RO.Turn shl 16 + Opponent shl 8 + adWanted; 3136 3136 end; … … 3141 3141 procedure SetLeaveOutValue; 3142 3142 3143 procedure Process(ad: integer);3143 procedure Process(ad: Integer); 3144 3144 var 3145 i: integer;3145 I: Integer; 3146 3146 begin 3147 3147 if LeaveOutValue[ad] < 0 then 3148 3148 begin 3149 3149 LeaveOutValue[ad] := 0; 3150 for i:= 0 to 1 do3151 if AdvPreq[ad, i] >= 0 then3152 begin 3153 Process(AdvPreq[ad, i]);3154 if AdvPreq[ad, i] in LeaveOutTechs then3155 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); 3156 3156 end; 3157 3157 end; … … 3159 3159 3160 3160 var 3161 ad: integer;3161 ad: Integer; 3162 3162 begin 3163 3163 FillChar(LeaveOutValue, SizeOf(LeaveOutValue), $FF); … … 3168 3168 3169 3169 initialization 3170 RWDataSize := sizeof(TPersistentData);3170 RWDataSize := SizeOf(TPersistentData); 3171 3171 SetLeaveOutValue; 3172 3172
Note:
See TracChangeset
for help on using the changeset viewer.